Problems with compute stress/atom using the LAMMPS library: Per-atom virial was not tallied on needed time step

Hi,

I have some problems with invoking computes in my own code when using the LAMMPS library. After reading the input script, I define a compute command as follows:

lmp -> input -> one (“compute per_atom_stress all stress/atom\n”);

and after running my simulation every 5 timesteps, I invoke the compute using the following command

stressList = (double**) lammps_extract_compute (lmp, (char*) “per_atom_stress”, 1, 2);

but I get the following error:

ERROR: Per-atom virial was not tallied on needed timestep (compute_stress_atom.cpp:98)

I went to LAMMPS documentation and found the following explanation:

But this simply does make no sense since I am calculating a per-atom quantity and not a global variable for which thermo is used. Nevertheless, I added the command “thermo 5” and even “thermo 1” to my scrip but the problem was unresolved. I asked one of my friends, and he independently reproduced the same error with his own code:

#include “mpi.h”
#include “library.h”
#include “lammps.h”
#include “atom.h”
#include “input.h”
#include “memory.h”

using namespace std;
using namespace LAMMPS_NS;

int main(int argc, char** argv)
{
int procs, me;

MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &procs);
MPI_Comm_rank(MPI_COMM_WORLD, &me);

LAMMPS* lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);

char command[256];
lmp->input->one(“units lj\n”);
lmp->input->one(“atom_style atomic\n”);
lmp->input->one(“lattice fcc 0.8442\n”);
lmp->input->one(“region box block 0 10 0 10 0 10\n”);
lmp->input->one(“create_box 1 box\n”);
lmp->input->one(“create_atoms 1 box\n”);
lmp->input->one(“mass 1 1.0\n”);
lmp->input->one(“velocity all create 3.0 87287\n”);
lmp->input->one(“pair_style lj/cut 2.5\n”);
lmp->input->one(“pair_coeff 1 1 1.0 1.0 2.5\n”);

lmp->input->one(“neighbor 0.5 bin\n”);
lmp->input->one(“neigh_modify every 1 delay 0 check yes\n”);
lmp->input->one(“thermo 1\n”);
lmp->input->one(“fix 1 all nve\n”);
lmp->input->one(“compute 1 all stress/atom\n”);
lmp->input->one(“run 250\n”);

double** stressList = (double**) lammps_extract_compute (lmp, (char*) “1”, 1, 2);

delete lmp;

MPI_Finalize();
return 0;
}

My own code is too big and has a lot of unrelated stuff, so including it will be more of a burden than a help.

Regards

Amir

But this simply does make no sense since I am calculating a per-atom quantity and not a global variable for which thermo is used. >Nevertheless, I added the command "thermo 5" and even "thermo 1" to my scrip but the problem was unresolved

Replace "thermo keyword" with "compute" in the error message and that
is your problem.
The compute cannot be evaluated unless the simulation tallied per-atom
virials on
the timestep you are asking for it. You can trigger this by doing some thermo
output on the right timestep(s) that invoke that compute, b/c then LAMMPS will
know it is needed. If you simply request it after the fact, LAMMPS didn't know
you needed it and so didn't compute the virial info.

Simply using thermo 5 is not enough - you have to do some
output that uses the per-atom stress compute you have defined and are
requesting.
The variable doc page explains all of this - see the Variable Accuracy section.

Steve