How to correctly output virial tensor

Hi Lammps Users,

I am trying to output the microscopic virial tensor in order to calculate the normal stress, but when I do a compute and output the components of the vector using thermo_style I think that I get some funny results. I need to output the xx, yy and zz components of the vector. Is it correct to use c_ID[1] c_ID[2] c_ID[3]? I looked in the compute_pressure.cpp file and there is an element vector[0], but variable.cpp does not allow for 0 as an index.

Yours

Sam Edgecombe
Theoretical Chemistry, Lund University

Hi Lammps Users,

I am trying to output the microscopic virial tensor in order to calculate
the normal stress, but when I do a compute and output the components of the
vector using thermo_style I think that I get some funny results. I need to
output the xx, yy and zz components of the vector. Is it correct to use
c_ID[1] c_ID[2] c_ID[3]? I looked in the compute_pressure.cpp file and there
is an element vector[0], but variable.cpp does not allow for 0 as an index.

ahhh. another victim of LAMMPS' legacy of starting out as a fortran code.
arrays in LAMMPS' input scripts are 1-based (like fortran), but internally
arrays are 0-based (like C).

you can save yourself some trouble, by just using the pressure tensor
components. pxx,pyy,pzz,pxy,pxz,pyz. apart from a scaling factor
(volume dependent), they are the same as the stress tensor.

cheers,
    axel.

This isn't a Fortran idea, it's a user-interface idea.
In an input script if you want to print/access the 6 components
of the virial tensor, they are numbered 1 thru 6. Ditto
for columns of an array, 1 to N. The atoms are likewise
numbered 1 to N, e.g. in an atom-style variable.

The code underneath uses C indices. I don't think users
want/need to remember to ask for atom 0, when they
want the coords of the 1st atom.

Steve

Hi,

But this is an error in the code is it not. Using the current code a user cannot access the first element of the vector since in compute_pressure is is called vector[0] but outputting using thermo_style One can only access non zero vector indices.

Should be maybe put on list of bug fixes for next issue.

Cheers

Sam

It is not a bug. As Steve mentioned, what are 0-based indices internally become 1-based indices externally. Axel.