Bug report| Hooomd V3 **hoomd.md.force.Custom**

149 views
Skip to first unread message

Ye Zhang

unread,
Apr 13, 2022, 10:33:25 PM4/13/22
to hoomd-users

I'm using hoomd.md.force.Custom integration with Brownian integration.

I test it with 2 particles  put in the same position while applying opposition forces to them.

(forces between 2 particles is zero)

I found that the 2 particles oscillate.

The Jupiter Notebook was appended.

Thanks foryour help~


图片1.png

bug of custom forces.ipynb

tom...@umich.edu

unread,
Apr 14, 2022, 10:18:58 AM4/14/22
to hoomd-users
Hi,

Please remember that hoomd resorts particles every timestep to improve simulation performance. Remember to use the local snapshot's reverse lookup tag (`snap.particles.rtag`) to properly index the force array as particle indices in the force array are subject to change.  In your case I believe hoomd is changing the particle index in the force array and therefore the force you are setting for your particle is flipping every timestep. There is an example of how to use the reverse lookup tag here (https://hoomd-blue.readthedocs.io/en/v3.0.1/tutorial/04-Custom-Actions-In-Python/06-Improving-Performance.html) and a brief description of what the reverse lookup tag is here (https://hoomd-blue.readthedocs.io/en/v3.0.1/module-hoomd-data.html#hoomd.data.ParticleLocalAccessBase).

Please either remove the `ParticleSorter` updater from your hoomd simulation or use the `rtag` in your `set_forces` method properly to confirm what I believe to be the problem. If you do this and the problem still persists, feel free to let us know.

- Tommy

Joshua Anderson

unread,
Apr 14, 2022, 10:26:27 AM4/14/22
to hoomd...@googlegroups.com
This message is a duplicate of #1304: https://github.com/glotzerlab/hoomd-blue/issues/1304

Please don't cross post or double post. It wastes our time.

Regarding Tommy's suggestion, removing the ParticleSorter is not a general solution. Particles still can and will appear in any order (e.g. in MPI simulations). Removing the ParticleSorter will also severely limit your simulation's performance.
------
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan
> --
> You received this message because you are subscribed to the Google Groups "hoomd-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hoomd-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/hoomd-users/881a152a-d672-4c94-b1ea-bdf97629e17cn%40googlegroups.com.

Ye Zhang

unread,
Apr 14, 2022, 9:06:56 PM4/14/22
to hoomd-users
I'm sorry, I thought it is a bug before..
Thanks for you help~

Ye Zhang

unread,
Apr 14, 2022, 10:59:04 PM4/14/22
to hoomd-users
I'm now using rtag to rearrange forces, but I still can't get the right result.
It means that forces were still applied to false particles.

class CustomActiveForce_2D(hoomd.md.force.Custom):
    def __init__(self):
        super().__init__(aniso=True)
        self.ori_forces = np.array([[1,0,0],[-1,0,0],[0,1,0]])
       
    def re_Arrange_force(self):
        with sim.state.cpu_local_snapshot as data:
            ori_tag = data.particles.rtag[:].copy()
            self.rearrange_forces = self.ori_forces[ori_tag]
    def set_forces(self,timestep):
        self.re_Arrange_force()
        with self.cpu_local_force_arrays as arrays:
            arrays.force[:] = 0
            arrays.force[:] = self.rearrange_forces

Joshua Anderson

unread,
Apr 15, 2022, 6:28:00 AM4/15/22
to hoomd...@googlegroups.com
Carefully review the documentation for `tag` and `rtag` and adjust your script to obtain the result you expect.
------
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan

> --
> You received this message because you are subscribed to the Google Groups "hoomd-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hoomd-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/hoomd-users/bfbed571-35fc-44cd-9b8c-eeeaa443989bn%40googlegroups.com.

Ye Zhang

unread,
Apr 17, 2022, 7:09:39 AM4/17/22
to hoomd-users
thanks for your help
Reply all
Reply to author
Forward
0 new messages