Fix addforce check for region after computing variables

Hello,

I’m trying to optimize my LAMMPS computation and found that a lot of time is spent in variables computation in “fix addforce” (by the way, I found it by using Intel Vtune Amplifier). Here is the piece of input script:

variable fStokesx atom 0.022608*(0.0-vx)

variable fStokesy atom 0.022608*(0.0-vy)

variable fStokesz atom 0.022608*(0.15-vz)

fix fStokes particlesGroup addforce v_fStokesx v_fStokesy v_fStokesz region coreCylinderExt

I want to add force to particles only in specific region so I add the keyword region to fix addforce. However looking in the source codes fix_addforce.cpp it appears that force components are computed BEFORE the region check, so they are computed for all particles in the group including particles that are not in the specified region. If it was implemented intentionally can you explain the reason for that? Otherwise, I think it would be more correct to check for region before the force components computation.

Nikita Tropin | Scientist

Hello,

I’m trying to optimize my LAMMPS computation and found that a lot of time is
spent in variables computation in “fix addforce” (by the way, I found it by
using Intel Vtune Amplifier). Here is the piece of input script:

variable fStokesx atom 0.022608*(0.0-vx)

variable fStokesy atom 0.022608*(0.0-vy)

variable fStokesz atom 0.022608*(0.15-vz)

fix fStokes particlesGroup addforce v_fStokesx v_fStokesy
v_fStokesz region coreCylinderExt

I want to add force to particles only in specific region so I add the
keyword region to fix addforce. However looking in the source codes
fix_addforce.cpp it appears that force components are computed BEFORE the
region check, so they are computed for all particles in the group including
particles that are not in the specified region. If it was implemented
intentionally can you explain the reason for that? Otherwise, I think it
would be more correct to check for region before the force components
computation.

if you define an atom style variable, it computes the
its value for all atoms. that is how it is defined and
expected to work. if you need to worry about efficiency,
you should not use a variable based computation, but
rather write/modify a fix of your own. that will beat
a variable based computation at any time. for a piece
of software, you always have to trade off between
efficiency, simplicity, and convenience. you can at
best have two of the three. :wink:

cheers,
    axel.