HOOMD-V3
I'm using `md.force.Active and md.force.custom_force to simulate active matter system with brownian integrater
md.force.active_force
active = hoomd.md.force.Active(filter=hoomd.filter.All())
active.active_force['A'] = (10,0,0)
integrator.forces.append(active)
rotational_diffusion_updater = active.create_diffusion_updater(rotational_diffusion=1,trigger=1)
sim.operations+=rotational_diffusion_updater
I want to change the active force during the simulation, so according to the document on active force,
md.force.custom_force
class CustomActiveForce_2D(hoomd.md.force.Custom):
def __init__(self,f_array,theta_array,rotation_diff):
super().__init__(aniso=True)
self.f_array = f_array.reshape((-1,1))
self.theta_array = theta_array.reshape((-1,1))
self.rotation_diff = rotation_diff
def update_force(self):
self.theta_array+=np.random.normal(0,1,self.theta_array.shape)*(
2*self.rotation_diff*integrator.dt)**0.5
self.active_f = self.f_array*np.column_stack([np.cos(self.theta_array),
np.sin(self.theta_array),
np.zeros(self.theta_array.shape)])
def set_forces(self,timestep):
self.update_force()
with self.cpu_local_force_arrays as arrays:
arrays.force[:] =self.active_f
pass
active_N = snapshot.particles.N
f_array = 10*np.ones((active_N,1))
custom_active =CustomActiveForce_2D(f_array = f_array,
theta_array= 2*np.pi*(np.random.random((snapshot.particles.N,1))-0.5),
rotation_diff=1)
integrator.forces.append(custom_active)
integrator.integrate_rotational_dof = True
But the result of the two methods is different when keeping the constants the same.
It's there anything wrong with my code?
Thanks for your help~