Calculate net x force component for all atoms or group

Hello everyone,

I am using LAMMPS window version 19 March 2020. I want to calculate the net x force component for all atoms. I was using dump command that gives fx fy fz component force for all individual atoms.

In thermo style command fmax and fnorm, where fnorm is the net force (x, y, z component) for all atoms.

Any help if I can get a net x force component for all atoms and could print it using thermo style custom command for each timestep.

Thanks and best regards,
Ankit

You cou use compute reduce with the sum option.
Axel.

Thanks, Axel.

In compute reduce, we have mode = sum or min or max or ave or sumsq or avesq

Lets take 3 atom system, using dump command I got fx fy fz component of each atom as below.

Atom fx fy fz
1 f1x f1y f1z
2 f2x f2y f2z
1 f3x f3y f3z

compute allforce all reduce min fx fy fz
compute allforce all reduce max fx fy fz

using thermo style custom c_allforce[1] c_allforce[2] c_allforce[3]
min and max will give smallest and largest force component of an atom [ f1x or f2x or f3x] , [f1y or f2y or f3y] , [f1z or f2z or f3z] corrspond to c_allforce[1], c_allforce[2], c_allforce[3].

compute allforce all reduce sumsq fx fy fz
compute allforce all reduce avesq fx fy fz

using thermo style custom c_allforce[1] c_allforce[2] c_allforce[3]
sumsq will give [f1x^2 + f2x^2 + f3x^2 ], [f1x^2 + f2x^2 + f3x^2 ], [f1x^2 + f2x^2 + f3x^2 ] correspond to c_allforce[1], c_allforce[2], c_allforce[3].
avesq will give [(f1x^2 + f2x^2 + f3x^2)/3 ], [(f1x^2 + f2x^2 + f3x^2)/3 ], [(f1x^2 + f2x^2 + f3x^2)/3 ] correspond to c_allforce[1], c_allforce[2], c_allforce[3].

All is working fine in same way as above when i checked the calculation for 576 atoms in excel file but when I used
compute allforce all reduce sum fx fy fz

to get net force in x, y, z direction
using thermo style custom c_allforce[1] c_allforce[2] c_allforce[3]
sum doesn’t work in this way [ f1x + f2x + f3x] , [f1y + f2y + f3y] , [f1z + f2z + f3z] corrspond to c_allforce[1], c_allforce[2], c_allforce[3].

Does sum command work in different way ?

How to get net x component force for all atoms?

Thanks,
Ankit

Hey ankit, I think you are trying to calculate forces per atom at each timestep. If this is the case then you may use compute property/atom and then use fix command to output your computer vector. Thermo style will always print global quantities and not per atom values.
Thanks and regards
Syed S.H.Zaid
IIT Jodhpur, India

What is your point?

What you are saying is that compute reduce sum is computing the sum, which is what it should.

Either you have a different understanding of a “net force” is (and need to explain that) or you don’t get the sum and for that you need to provide a complete minimal working example.

Axel

I want to calculate net x force component if I use “compute allforce all reduce sum fx fy fz”

then
using thermo style custom c_allforce[1] c_allforce[2] c_allforce[3]
c_allforce[1] means [fx1 + fx2 + fx3 … fxn],

Here, c_allforce[1] is equal to net x force component. Is it right?

But for my system, using reduce sum fx fy fz , I got values 4.12e-12 1.76e-12 -5.506e-13 correspond to c_allforce[1] c_allforce[2] c_allforce[3]. But when I calculated considering fx fy fz values from dump command. I got value

7.51E-05 -3.72E-06 -0.00118444

which is different. Please see attached file.

I did the calculation of Fnorm which represents length of force vector for all atoms.
In starting, I thought that Fnorm would be = sqrt (Fnetx^2 + Fnety^2 +Fnetz^2)
where Fnetx = f1x + f2x + f3x + … + fnx,
Fnety = f1y + f2y + f3y + … + fny,
Fnetz = f1z + f2z + f3z + … + fnz

but when i did calculation as attached excel file, I found that it is calculated in this way:

Fnetx^2 = f1x^2 + f2x^2 + f3x^2 + … + fnx^2,
Fnety^2 = f1y^2 + f2y^2 + f3y^2 + … + fny^2,
Fnetz^2 = f1z^2 + f2z^2 + f3z^2 + … + fnz^2

What is the correct way to find the total force on all atoms along x direction?

Thanks,
Ankit

basic.txt (1.96 KB)

ffield.Reax.latest (32.3 KB)

npt1.txt (102 KB)

force.xlsx (107 KB)

you are still sending confusing and mixed messages. you have still not explained what your understanding of how to compute the net force is.

compute reduce works as advertised. it has been used a lot and we are using it in our unittesting in many places. if the sum would not be the sum, it would show.

since you have sums of small magnitude, have you considered that your manual computation may be affected by the output in the dump file being written out with less precision while compute reduce sum will work with floating point numbers. your outputs are consistent with forces where the sum is “almost zero”.

I still don’t get why you keep bringing up Fnorm and other squared properties? what do they have to do with computing the net force in x direction?

axel.

Thank you, Axel.

I checked “compute allforce all reduce sum fx fy fz”
using thermo style custom c_allforce[1] c_allforce[2] c_allforce[3]
and compared it with fx, fy, fz component using dump command with high precision. Yes, it matches c_allforce[1] means [fx1 + fx2 + fx3 … fxn],

In order to find net force along x direction, I am using c_allforce[1] which would give net force along x direction at each timestep. This is I understand.

Is it correct that Fnorm is the net force on all atoms?

Fnorm is given by = sqrt (Fnetx^2 + Fnety^2 +Fnetz^2)
but Fnetx, Fnety, Fnetz is not calculated as given below:
where Fnetx = f1x + f2x + f3x + … + fnx,
Fnety = f1y + f2y + f3y + … + fny,
Fnetz = f1z + f2z + f3z + … + fnz

It uses:

Fnetx^2 = f1x^2 + f2x^2 + f3x^2 + … + fnx^2,
Fnety^2 = f1y^2 + f2y^2 + f3y^2 + … + fny^2,
Fnetz^2 = f1z^2 + f2z^2 + f3z^2 + … + fnz^2

Thanks,
Ankit

Thank you, Axel.

I checked “compute allforce all reduce sum fx fy fz”
using thermo style custom c_allforce[1] c_allforce[2] c_allforce[3]
and compared it with fx, fy, fz component using dump command with high precision. Yes, it matches c_allforce[1] means [fx1 + fx2 + fx3 … fxn],

In order to find net force along x direction, I am using c_allforce[1] which would give net force along x direction at each timestep. This is I understand.

Is it correct that Fnorm is the net force on all atoms?

why should it be? the keyword is explained in the documentation:

The fnorm keyword calculates the 2-norm or length of the force vector.

does that sound like it is computing the “net force”? if you have difficulties sorting out what is mean by “2-norm” a look at wikipedia can help: https://en.wikipedia.org/wiki/Norm_(mathematics)

Fnorm is given by = sqrt (Fnetx^2 + Fnety^2 +Fnetz^2)
but Fnetx, Fnety, Fnetz is not calculated as given below:
where Fnetx = f1x + f2x + f3x + … + fnx,
Fnety = f1y + f2y + f3y + … + fny,
Fnetz = f1z + f2z + f3z + … + fnz

It uses:

Fnetx^2 = f1x^2 + f2x^2 + f3x^2 + … + fnx^2,
Fnety^2 = f1y^2 + f2y^2 + f3y^2 + … + fny^2,
Fnetz^2 = f1z^2 + f2z^2 + f3z^2 + … + fnz^2

so it is different, but that is how it is defined and documented.

if you want the length of the net force vector, you can simply define an equal style variable that computes

sqrt(c_allforce[0]*c_allforce[0]+c_allforce[1]*c_allforce[1]+c_allforce[2]*c_allforce[2])

you just made your life needlessly miserable by assuming things that are not the way they are described to be.

axel.

Yes, it does. Thanks, Axel.