[lammps-users] bugs in fix_line_force.cpp & fix_plane_force.cpp

Hi,

I think there is a bug in fix_line_force.cpp. According to the manual webpage (http://lammps.sandia.gov/doc/fix_lineforce.html), an example of using fix lineforce command is as following:

fix hold boundary lineforce 0.0 1.0 1.0

Here the direction vector (0.0, 1.0, 1.0) is not normalized. If we give (0.0, 2.0, 2.0), I think it should work as the same as (0.0, 1.0, 1.0) because only the direction matters.

However, the code (fix_line_force.cpp) doesn’t normalize the direction vector after reading it or before applying it to force caculation:

FixLineForce::FixLineForce(LAMMPS *lmp, int narg, char **arg) :
Fix(lmp, narg, arg)
{
if (narg != 6) error->all(“Illegal fix lineforce command”);
xdir = atof(arg[3]);
ydir = atof(arg[4]);
zdir = atof(arg[5]);
}

void FixLineForce::post_force(int vflag)
{
double **f = atom->f;
int *mask = atom->mask;
int nlocal = atom->nlocal;

double dot;
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
dot = f[i][0]*xdir + f[i][1]*ydir + f[i][2]*zdir;
f[i][0] = dot * xdir;
f[i][1] = dot * ydir;
f[i][2] = dot * zdir;
}
}

So vectors (0.0, 1.0, 1.0) and (0.0, 2.0, 2.0) would generate forces with different magnitudes. I think this is wrong.

The same problem exists in fix_plane_force.cpp.

Please check the attached patch file which I think can fix the bug.

Xibing He
Univ. of Pennsylvania

patch_fix_line_plane.txt (1.35 KB)

Xibing He,

Why restrict users to normalized vectors? There is nothing inherently incorrect about imposing a non-normalized force vector.

Paul

Xibing He,

Why restrict users to normalized vectors? There is nothing
inherently incorrect about imposing a non-normalized force vector.

however, this would inconsistent with the documentation.
the documentation states that force components get
removed. if the direction vector is not normalized
it would also constitute a rescaling, which i would
consider unexpected (not to mention that the scaling
is done with the square of the vector length). it
would be cleaner to have a "fix scaleforce" for that.

cheers,
   axel.

You're right - the specified vector should be normalized to a unit
vector before taking dot products with it - I'll post a patch.

Steve