# Velocity in the code

Hi all,

I am going to calculate the heat flux vector based on contribution from atoms in the computational domain (something like compute heat/flux) in Tersoff. For example, for two body term, I multiplied 0.5*fpair by velocity of each atom(Please see the highlighted lines). However, the results that I get from LAMMPS is not similar to the code I wrote in Fortran. I finally realized that atom i velocity components (V[i], V[i],V[i]) and some of atoms j velocity components (V[j], V[j],V[j]) is exactly similar to the results of my code but the velocity for some of j atoms (maybe 20%) is zero in lammps but non-zero in my code. I have no idea why the velocity of some j atoms (V[j], V[j], V[j]) is zero in lammps.

Please note that for calculation of convective term of heat flux vector ( sum of eiVi over all atoms). The results of my code is exactly similar to lammps results meaning that velocity calculation for both code is same. However, when it comes to calculation of second term of heat flux (sum of fijrijvi). I have this problem.

Thank you very much
Hossein

for (ii = 0; ii < inum; ii++) {
i = ilist[ii];
itag = tag[i];
itype = map[type[i]];
xtmp = x[i];
ytmp = x[i];
ztmp = x[i];

// two-body interactions, skip half of them

jlist = firstneigh[i];
jnum = numneigh[i];

for (jj = 0; jj < jnum; jj++) {
j = jlist[jj];
jtag = tag[j];

if (itag > jtag) {
if ((itag+jtag) 2 == 0) continue; } else if (itag < jtag) { if ((itag+jtag) 2 == 1) continue;
} else {
if (x[j] < x[i]) continue;
if (x[j] == ztmp && x[j] < ytmp) continue;
if (x[j] == ztmp && x[j] == ytmp && x[j] < xtmp) continue;
}

jtype = map[type[j]];

delx = xtmp - x[j];
dely = ytmp - x[j];
delz = ztmp - x[j];
rsq = delxdelx + delydely + delz*delz;

iparam_ij = elem2param[itype][jtype][jtype];
if (rsq > params[iparam_ij].cutsq) continue;

repulsive(&params[iparam_ij],rsq,fpair,eflag,evdwl);

f[i] += delxfpair;
f[i] += dely
fpair;
f[i] += delzfpair;
f[j] -= delx
fpair;
f[j] -= delyfpair;
f[j] -= delz
fpair;

if (evflag) ev_tally(i,j,nlocal,newton_pair,
evdwl,0.0,fpair,delx,dely,delz);

double **v = atom->v;
energyBit = evdwl;
atomE[i] += 0.5energyBit;
qdpi = 0.5
fpair*(delxv[i]+delyv[i]+delzv[i]);
q[i] += qdpi
delx;
q[i] += qdpidely;
q[i] += qdpi
delz;
atomE[j] += 0.5energyBit;
qdpj = -0.5
fpair*(delxv[j]+delyv[j]+delzv[j]);
q[j] -= qdpj
delx;
q[j] -= qdpjdely;
q[j] -= qdpj
delz;

Hi all,
I am going to calculate the heat flux vector based on contribution from
atoms in the computational domain (something like compute heat/flux) in
Tersoff. For example, for two body term, I multiplied 0.5*fpair by velocity
of each atom(Please see the highlighted lines). However, the results that I
get from LAMMPS is not similar to the code I wrote in Fortran. I finally
realized that atom i velocity components (V[i], V[i],V[i]) and some
of atoms j velocity components (V[j], V[j],V[j]) is exactly similar
to the results of my code but the velocity for some of j atoms (maybe 20%)
is zero in lammps but non-zero in my code. I have no idea why the velocity
of some j atoms (V[j], V[j], V[j]) is zero in lammps.

you do this calculation in the wrong place. it would be better to do
this as a compute (or fix).
what you are discarding with your code is the fact that some of the
"j" atoms in your calculation
are "ghost atoms". please also note that the i,j loop is not over all
pairs of atoms but over all i,j pairs within the neighborlist cutoff.

to have the velocity of ghost atoms available, you also have to use the command
comm_modify vel yes

if you need all pairs, and not just the neighbor list, you need to do
some programming with a ring buffer to have all information of atoms,
that are on other processors pass by each processor.
otherwise, you can probably save some computational effort by using a
half neighbor list.

axel.

You do know that compute heat/flux works fine
already with many-body potentials such as Tersoff?
It includes the energy contribution from the 2-body
and 3-body terms. If you are trying to get only
the 2-body contribution, then I suggest you use
the “rerun” command, to read a dump file
(of positions and velocities), comment out the
3-body energy tallying in pair_tersoff.cpp, then
use compute heat/flux in the rerun script.

Steve