Skip to content

Commit

Permalink
rotation - fix -interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
christophlohrmann committed Aug 8, 2022
1 parent c06f911 commit 285aac0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/core/thermostats/brownian_inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ bd_drag_rot(Thermostat::GammaType const &brownian_gamma_rotation, Particle &p,

Utils::Vector3d dphi = {};
for (int j = 0; j < 3; j++) {
if (!p.is_fixed_along(j)) {
if (p.can_rotate_around(j)) {
// only a conservative part of the torque is used here
#ifndef PARTICLE_ANISOTROPY
dphi[j] = p.torque()[j] * dt / gamma;
Expand Down Expand Up @@ -304,12 +304,11 @@ bd_drag_vel_rot(Thermostat::GammaType const &brownian_gamma_rotation,

Utils::Vector3d omega = {};
for (int j = 0; j < 3; j++) {
if (!p.is_fixed_along(j)) {
// only conservative part of the force is used here
#ifndef PARTICLE_ANISOTROPY
omega[j] = p.torque()[j] / gamma;
#else
if (p.can_rotate_around(j)) {
#ifdef PARTICLE_ANISOTROPY
omega[j] = p.torque()[j] / gamma[j];
#else
omega[j] = p.torque()[j] / gamma;
#endif // PARTICLE_ANISOTROPY
}
}
Expand Down Expand Up @@ -343,7 +342,7 @@ bd_random_walk_rot(BrownianThermostat const &brownian, Particle const &p,
auto const noise = Random::noise_gaussian<RNGSalt::BROWNIAN_ROT_INC>(
brownian.rng_counter(), brownian.rng_seed(), p.id());
for (int j = 0; j < 3; j++) {
if (!p.is_fixed_along(j)) {
if (p.can_rotate_around(j)) {
#ifndef PARTICLE_ANISOTROPY
if (sigma_pos > 0.0) {
dphi[j] = noise[j] * sigma_pos * sqrt(dt);
Expand Down Expand Up @@ -378,7 +377,7 @@ bd_random_walk_vel_rot(BrownianThermostat const &brownian, Particle const &p) {
auto const noise = Random::noise_gaussian<RNGSalt::BROWNIAN_ROT_WALK>(
brownian.rng_counter(), brownian.rng_seed(), p.id());
for (int j = 0; j < 3; j++) {
if (!p.is_fixed_along(j)) {
if (p.can_rotate_around(j)) {
domega[j] = sigma_vel * noise[j] / sqrt(p.rinertia()[j]);
}
}
Expand Down
26 changes: 26 additions & 0 deletions testsuite/python/brownian_dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,32 @@ def test_07__virtual(self):
np.testing.assert_almost_equal(np.copy(virtual.v), [0, 0, 0])
np.testing.assert_almost_equal(np.copy(physical.v), [0, 0, 0])

@utx.skipIfMissingFeatures(["ROTATION", "EXTERNAL_FORCES"])
def test_fix_rotation(self):
system = self.system
system.time_step = 0.01
part = system.part.add(
pos=3 * [0.],
fix=3 * [True],
rotation=3 * [True])

# torque only
part.ext_torque = [0, 0, 1.3]
system.thermostat.set_brownian(
kT=0, gamma=1, gamma_rotation=1.5, act_on_virtual=False, seed=41)
system.integrator.set_brownian_dynamics()
system.integrator.run(3)
np.testing.assert_allclose(
part.omega_lab, [
0, 0, 1.3 / 1.5], atol=1e-14)

# noise only
part.ext_torque = 3 * [0.]
system.thermostat.set_brownian(
kT=1, gamma=1, gamma_rotation=1.5, act_on_virtual=False, seed=41)
system.integrator.run(3)
self.assertGreater(np.linalg.norm(part.omega_lab), 0.)


if __name__ == "__main__":
ut.main()

0 comments on commit 285aac0

Please sign in to comment.