fix: Boltzmann Constant units
This commit is contained in:
parent
f47c3609e7
commit
1c024647ac
|
@ -88,7 +88,7 @@ def energy(position, box_size):
|
||||||
# enforce expected shape
|
# enforce expected shape
|
||||||
# (`scipy.optimize.minimize` drops shape information)
|
# (`scipy.optimize.minimize` drops shape information)
|
||||||
if len(position.shape) == 1:
|
if len(position.shape) == 1:
|
||||||
position = position.reshape((position.shape[0] // 3, 3))
|
position = position.reshape((-1, 3))
|
||||||
# compute all pairwise position differences (all!)
|
# compute all pairwise position differences (all!)
|
||||||
diff = position[:, jnp.newaxis, :] - position
|
diff = position[:, jnp.newaxis, :] - position
|
||||||
# extract only one of two distance combinations of non-equal particles
|
# extract only one of two distance combinations of non-equal particles
|
||||||
|
@ -122,16 +122,16 @@ def kinetic(velocity):
|
||||||
return (mass / 2.0) * (velocity**2).sum()
|
return (mass / 2.0) * (velocity**2).sum()
|
||||||
|
|
||||||
@jit
|
@jit
|
||||||
def step(position, velocity, acceleration, box_size, step_size):
|
def step(position, velocity, acceleration, box_size, delta_t):
|
||||||
"""
|
"""
|
||||||
Performs a single Newton time step with `step_size` given system state
|
Performs a single Newton time step with `delta_t` given system state
|
||||||
through the current particle `position`, `velocity` and `acceleration`.
|
through the current particle `position`, `velocity` and `acceleration`.
|
||||||
"""
|
"""
|
||||||
# update position with a second order Taylor expantion
|
# update position with a second order Taylor expantion
|
||||||
position += step_size * velocity + (0.5 * step_size**2) * acceleration
|
position += delta_t * velocity + (0.5 * delta_t**2) * acceleration
|
||||||
# compute new particle acceleration through Newton’s second law of motion
|
# compute new particle acceleration through Newton’s second law of motion
|
||||||
acceleration_next = force(position, box_size) / mass
|
acceleration_next = force(position, box_size) / mass
|
||||||
# update velocity with a finite mean approximation
|
# update velocity with a finite mean approximation
|
||||||
velocity += (0.5 * step_size) * (acceleration + acceleration_next)
|
velocity += (0.5 * delta_t) * (acceleration + acceleration_next)
|
||||||
# updated state
|
# updated state
|
||||||
return position, velocity, acceleration_next
|
return position, velocity, acceleration_next
|
||||||
|
|
|
@ -59,7 +59,8 @@ from molecular_dynamics import dump, energy, force, mass
|
||||||
position = np.random.uniform(0.0, config.box_size, (config.nr_particles, 3))
|
position = np.random.uniform(0.0, config.box_size, (config.nr_particles, 3))
|
||||||
|
|
||||||
# Sample particle velocities
|
# Sample particle velocities
|
||||||
sd = np.sqrt(scipy.constants.Boltzmann * config.temperature / mass)
|
K_b = scipy.constants.Boltzmann / scipy.constants.eV # [eV / K]
|
||||||
|
sd = np.sqrt(K_b * config.temperature / mass)
|
||||||
velocity = np.random.normal(0.0, sd, (config.nr_particles, 3))
|
velocity = np.random.normal(0.0, sd, (config.nr_particles, 3))
|
||||||
# center velocities
|
# center velocities
|
||||||
velocity -= velocity.mean(axis = 0)
|
velocity -= velocity.mean(axis = 0)
|
||||||
|
|
Loading…
Reference in New Issue