git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@1193 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
@ -11,60 +11,54 @@
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "compute_stress_atom.h"
|
||||
#include "atom.h"
|
||||
#include "neighbor.h"
|
||||
#include "neigh_list.h"
|
||||
#include "neigh_request.h"
|
||||
#include "modify.h"
|
||||
#include "comm.h"
|
||||
#include "update.h"
|
||||
#include "force.h"
|
||||
#include "bond.h"
|
||||
#include "pair.h"
|
||||
#include "domain.h"
|
||||
#include "bond.h"
|
||||
#include "angle.h"
|
||||
#include "dihedral.h"
|
||||
#include "improper.h"
|
||||
#include "memory.h"
|
||||
#include "error.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
ComputeStressAtom::ComputeStressAtom(LAMMPS *lmp, int narg, char **arg) :
|
||||
ComputeStressAtom::ComputeStressAtom(LAMMPS *lmp, int narg, char **arg) :
|
||||
Compute(lmp, narg, arg)
|
||||
{
|
||||
if (narg < 3) error->all("Illegal compute stress/atom command");
|
||||
|
||||
peratom_flag = 1;
|
||||
size_peratom = 6;
|
||||
pressatomflag = 1;
|
||||
timeflag = 1;
|
||||
comm_reverse = 6;
|
||||
|
||||
// process args
|
||||
|
||||
kerequest = pairrequest = bondrequest = 1;
|
||||
|
||||
int iarg = 3;
|
||||
while (iarg < narg) {
|
||||
if (strcmp(arg[iarg],"ke") == 0) {
|
||||
if (iarg+2 > narg) error->all("Illegal compute ebond/atom command");
|
||||
if (strcmp(arg[iarg+1],"yes") == 0) kerequest = 1;
|
||||
else if (strcmp(arg[iarg+1],"no") == 0) kerequest = 0;
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"pair") == 0) {
|
||||
if (iarg+2 > narg) error->all("Illegal compute ebond/atom command");
|
||||
if (strcmp(arg[iarg+1],"yes") == 0) pairrequest = 1;
|
||||
else if (strcmp(arg[iarg+1],"no") == 0) pairrequest = 0;
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"bond") == 0) {
|
||||
if (iarg+2 > narg) error->all("Illegal compute ebond/atom command");
|
||||
if (strcmp(arg[iarg+1],"yes") == 0) bondrequest = 1;
|
||||
else if (strcmp(arg[iarg+1],"no") == 0) bondrequest = 0;
|
||||
iarg += 2;
|
||||
} else error->all("Illegal compute ebond/atom command");
|
||||
if (narg == 3) {
|
||||
keflag = 1;
|
||||
pairflag = 1;
|
||||
bondflag = angleflag = dihedralflag = improperflag = 1;
|
||||
} else {
|
||||
keflag = 0;
|
||||
pairflag = 0;
|
||||
bondflag = angleflag = dihedralflag = improperflag = 0;
|
||||
int iarg = 3;
|
||||
while (iarg < narg) {
|
||||
if (strcmp(arg[iarg],"ke") == 0) keflag = 1;
|
||||
else if (strcmp(arg[iarg],"pair") == 0) pairflag = 1;
|
||||
else if (strcmp(arg[iarg],"bond") == 0) bondflag = 1;
|
||||
else if (strcmp(arg[iarg],"angle") == 0) angleflag = 1;
|
||||
else if (strcmp(arg[iarg],"dihedral") == 0) dihedralflag = 1;
|
||||
else if (strcmp(arg[iarg],"improper") == 0) improperflag = 1;
|
||||
else error->all("Illegal compute stress/atom command");
|
||||
iarg++;
|
||||
}
|
||||
}
|
||||
|
||||
nmax = 0;
|
||||
@ -80,50 +74,13 @@ ComputeStressAtom::~ComputeStressAtom()
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void ComputeStressAtom::init()
|
||||
{
|
||||
if (pairrequest) {
|
||||
if (force->pair == NULL || force->pair->single_enable == 0)
|
||||
error->all("Pair style does not support computing per-atom stress");
|
||||
pairflag = 1;
|
||||
|
||||
// need an occasional half neighbor list
|
||||
|
||||
int irequest = neighbor->request((void *) this);
|
||||
neighbor->requests[irequest]->pair = 0;
|
||||
neighbor->requests[irequest]->compute = 1;
|
||||
neighbor->requests[irequest]->occasional = 1;
|
||||
|
||||
} else pairflag = 0;
|
||||
|
||||
if (bondrequest && force->bond) bondflag = 1;
|
||||
else bondflag = 0;
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0; i < modify->ncompute; i++)
|
||||
if (strcmp(modify->compute[i]->style,"stress/atom") == 0) count++;
|
||||
if (count > 1 && comm->me == 0)
|
||||
error->warning("More than one compute stress/atom");
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void ComputeStressAtom::init_list(int id, NeighList *ptr)
|
||||
{
|
||||
list = ptr;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void ComputeStressAtom::compute_peratom()
|
||||
{
|
||||
int i,j,ii,jj,n,i1,i2,inum,jnum,itype,jtype,iflag,jflag;
|
||||
double xtmp,ytmp,ztmp,delx,dely,delz,rsq,eng;
|
||||
double factor_coul,factor_lj,fforce,rmass;
|
||||
int *ilist,*jlist,*numneigh,**firstneigh;
|
||||
Pair::One one;
|
||||
int i,j;
|
||||
|
||||
// grow stress array if necessary
|
||||
invoked = 1;
|
||||
|
||||
// grow local stress array if necessary
|
||||
|
||||
if (atom->nmax > nmax) {
|
||||
memory->destroy_2d_double_array(stress);
|
||||
@ -133,199 +90,115 @@ void ComputeStressAtom::compute_peratom()
|
||||
vector_atom = stress;
|
||||
}
|
||||
|
||||
// clear stress array
|
||||
// n includes ghosts only if newton flag is set
|
||||
// npair includes ghosts if either newton flag is set
|
||||
// b/c some bonds/dihedrals call pair::ev_tally with pairwise info
|
||||
// nbond includes ghosts if newton_bond is set
|
||||
// ntotal includes ghosts if either newton flag is set
|
||||
|
||||
int nlocal = atom->nlocal;
|
||||
int npair = nlocal;
|
||||
int nbond = nlocal;
|
||||
int ntotal = nlocal;
|
||||
if (force->newton) npair += atom->nghost;
|
||||
if (force->newton_bond) nbond += atom->nghost;
|
||||
if (force->newton) ntotal += atom->nghost;
|
||||
|
||||
if (force->newton) n = nlocal + atom->nghost;
|
||||
else n = nlocal;
|
||||
// clear local stress array
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
stress[i][0] = 0.0;
|
||||
stress[i][1] = 0.0;
|
||||
stress[i][2] = 0.0;
|
||||
stress[i][3] = 0.0;
|
||||
stress[i][4] = 0.0;
|
||||
stress[i][5] = 0.0;
|
||||
for (i = 0; i < ntotal; i++)
|
||||
for (j = 0; j < 6; j++)
|
||||
stress[i][j] = 0.0;
|
||||
|
||||
// add in per-atom contributions from each force
|
||||
|
||||
if (pairflag && force->pair) {
|
||||
double **vatom = force->pair->vatom;
|
||||
for (i = 0; i < npair; i++)
|
||||
for (j = 0; j < 6; j++)
|
||||
stress[i][j] += vatom[i][j];
|
||||
}
|
||||
|
||||
// compute pairwise stress for atoms via pair->single()
|
||||
// if neither atom is in compute group, skip that pair
|
||||
// only add stress to atoms in group
|
||||
|
||||
if (pairflag) {
|
||||
|
||||
// invoke half neighbor list (will copy or build if necessary)
|
||||
|
||||
neighbor->build_one(list->index);
|
||||
|
||||
inum = list->inum;
|
||||
ilist = list->ilist;
|
||||
numneigh = list->numneigh;
|
||||
firstneigh = list->firstneigh;
|
||||
|
||||
double *special_coul = force->special_coul;
|
||||
double *special_lj = force->special_lj;
|
||||
double **cutsq = force->pair->cutsq;
|
||||
int newton_pair = force->newton_pair;
|
||||
|
||||
double **x = atom->x;
|
||||
int *mask = atom->mask;
|
||||
int *type = atom->type;
|
||||
int nall = nlocal + atom->nghost;
|
||||
|
||||
for (ii = 0; ii < inum; ii++) {
|
||||
i = ilist[ii];
|
||||
xtmp = x[i][0];
|
||||
ytmp = x[i][1];
|
||||
ztmp = x[i][2];
|
||||
itype = type[i];
|
||||
iflag = mask[i] & groupbit;
|
||||
jlist = firstneigh[i];
|
||||
jnum = numneigh[i];
|
||||
|
||||
for (jj = 0; jj < jnum; jj++) {
|
||||
j = jlist[jj];
|
||||
jflag = mask[j] & groupbit;
|
||||
if (iflag == 0 && jflag == 0) continue;
|
||||
|
||||
if (j < nall) factor_coul = factor_lj = 1.0;
|
||||
else {
|
||||
factor_coul = special_coul[j/nall];
|
||||
factor_lj = special_lj[j/nall];
|
||||
j %= nall;
|
||||
}
|
||||
|
||||
delx = xtmp - x[j][0];
|
||||
dely = ytmp - x[j][1];
|
||||
delz = ztmp - x[j][2];
|
||||
rsq = delx*delx + dely*dely + delz*delz;
|
||||
jtype = type[j];
|
||||
|
||||
if (rsq < cutsq[itype][jtype]) {
|
||||
force->pair->single(i,j,itype,jtype,rsq,factor_coul,factor_lj,0,one);
|
||||
fforce = one.fforce;
|
||||
|
||||
if (iflag) {
|
||||
stress[i][0] -= delx*delx*fforce;
|
||||
stress[i][1] -= dely*dely*fforce;
|
||||
stress[i][2] -= delz*delz*fforce;
|
||||
stress[i][3] -= delx*dely*fforce;
|
||||
stress[i][4] -= delx*delz*fforce;
|
||||
stress[i][5] -= dely*delz*fforce;
|
||||
}
|
||||
if (jflag && (newton_pair || j < nlocal)) {
|
||||
stress[j][0] -= delx*delx*fforce;
|
||||
stress[j][1] -= dely*dely*fforce;
|
||||
stress[j][2] -= delz*delz*fforce;
|
||||
stress[j][3] -= delx*dely*fforce;
|
||||
stress[j][4] -= delx*delz*fforce;
|
||||
stress[j][5] -= dely*delz*fforce;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bondflag && force->bond) {
|
||||
double **vatom = force->bond->vatom;
|
||||
for (i = 0; i < nbond; i++)
|
||||
for (j = 0; j < 6; j++)
|
||||
stress[i][j] += vatom[i][j];
|
||||
}
|
||||
|
||||
// compute bond stress for atoms via bond->single()
|
||||
// if neither atom is in compute group, skip that bond
|
||||
// only add stress to atoms in group
|
||||
|
||||
if (bondflag) {
|
||||
double **x = atom->x;
|
||||
int *mask = atom->mask;
|
||||
int **bondlist = neighbor->bondlist;
|
||||
int nbondlist = neighbor->nbondlist;
|
||||
int newton_bond = force->newton_bond;
|
||||
int type;
|
||||
|
||||
for (n = 0; n < nbondlist; n++) {
|
||||
i1 = bondlist[n][0];
|
||||
i2 = bondlist[n][1];
|
||||
type = bondlist[n][2];
|
||||
iflag = mask[i1] & groupbit;
|
||||
jflag = mask[i2] & groupbit;
|
||||
if (iflag == 0 && jflag == 0) continue;
|
||||
|
||||
delx = x[i1][0] - x[i2][0];
|
||||
dely = x[i1][1] - x[i2][1];
|
||||
delz = x[i1][2] - x[i2][2];
|
||||
domain->minimum_image(delx,dely,delz);
|
||||
|
||||
rsq = delx*delx + dely*dely + delz*delz;
|
||||
force->bond->single(type,rsq,i1,i2,0,fforce,eng);
|
||||
|
||||
if (iflag) {
|
||||
stress[i1][0] -= delx*delx*fforce;
|
||||
stress[i1][1] -= dely*dely*fforce;
|
||||
stress[i1][2] -= delz*delz*fforce;
|
||||
stress[i1][3] -= delx*dely*fforce;
|
||||
stress[i1][4] -= delx*delz*fforce;
|
||||
stress[i1][5] -= dely*delz*fforce;
|
||||
}
|
||||
|
||||
if (jflag && (newton_bond || i2 < nlocal)) {
|
||||
stress[i2][0] -= delx*delx*fforce;
|
||||
stress[i2][1] -= dely*dely*fforce;
|
||||
stress[i2][2] -= delz*delz*fforce;
|
||||
stress[i2][3] -= delx*dely*fforce;
|
||||
stress[i2][4] -= delx*delz*fforce;
|
||||
stress[i2][5] -= dely*delz*fforce;
|
||||
}
|
||||
}
|
||||
if (angleflag && force->angle) {
|
||||
double **vatom = force->angle->vatom;
|
||||
for (i = 0; i < nbond; i++)
|
||||
for (j = 0; j < 6; j++)
|
||||
stress[i][j] += vatom[i][j];
|
||||
}
|
||||
|
||||
// communicate stress between neighbor procs
|
||||
if (dihedralflag && force->dihedral) {
|
||||
double **vatom = force->dihedral->vatom;
|
||||
for (i = 0; i < nbond; i++)
|
||||
for (j = 0; j < 6; j++)
|
||||
stress[i][j] += vatom[i][j];
|
||||
}
|
||||
|
||||
if (improperflag && force->improper) {
|
||||
double **vatom = force->improper->vatom;
|
||||
for (i = 0; i < nbond; i++)
|
||||
for (j = 0; j < 6; j++)
|
||||
stress[i][j] += vatom[i][j];
|
||||
}
|
||||
|
||||
// communicate ghost energy between neighbor procs
|
||||
|
||||
if (force->newton) comm->reverse_comm_compute(this);
|
||||
|
||||
// remove double counting
|
||||
// zero virial of atoms not in group
|
||||
// only do this after comm since ghost contributions must be included
|
||||
|
||||
for (i = 0; i < nlocal; i++) {
|
||||
stress[i][0] *= 0.5;
|
||||
stress[i][1] *= 0.5;
|
||||
stress[i][2] *= 0.5;
|
||||
stress[i][3] *= 0.5;
|
||||
stress[i][4] *= 0.5;
|
||||
stress[i][5] *= 0.5;
|
||||
}
|
||||
int *mask = atom->mask;
|
||||
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (!(mask[i] & groupbit)) {
|
||||
stress[i][0] = 0.0;
|
||||
stress[i][1] = 0.0;
|
||||
stress[i][2] = 0.0;
|
||||
stress[i][3] = 0.0;
|
||||
stress[i][4] = 0.0;
|
||||
stress[i][5] = 0.0;
|
||||
}
|
||||
|
||||
// include kinetic energy term for each atom in group
|
||||
// mvv2e converts mv^2 to energy
|
||||
|
||||
if (kerequest) {
|
||||
if (keflag) {
|
||||
double **v = atom->v;
|
||||
double *mass = atom->mass;
|
||||
int *mask = atom->mask;
|
||||
int *type = atom->type;
|
||||
double mvv2e = force->mvv2e;
|
||||
|
||||
for (i = 0; i < nlocal; i++) {
|
||||
double rmass;
|
||||
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) {
|
||||
rmass = mvv2e * mass[type[i]];
|
||||
stress[i][0] -= rmass*v[i][0]*v[i][0];
|
||||
stress[i][1] -= rmass*v[i][1]*v[i][1];
|
||||
stress[i][2] -= rmass*v[i][2]*v[i][2];
|
||||
stress[i][3] -= rmass*v[i][0]*v[i][1];
|
||||
stress[i][4] -= rmass*v[i][0]*v[i][2];
|
||||
stress[i][5] -= rmass*v[i][1]*v[i][2];
|
||||
stress[i][0] += rmass*v[i][0]*v[i][0];
|
||||
stress[i][1] += rmass*v[i][1]*v[i][1];
|
||||
stress[i][2] += rmass*v[i][2]*v[i][2];
|
||||
stress[i][3] += rmass*v[i][0]*v[i][1];
|
||||
stress[i][4] += rmass*v[i][0]*v[i][2];
|
||||
stress[i][5] += rmass*v[i][1]*v[i][2];
|
||||
}
|
||||
}
|
||||
|
||||
// convert to pressure units (actually stress/volume = -pressure)
|
||||
|
||||
double nktv2p = -force->nktv2p;
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) {
|
||||
stress[i][0] *= nktv2p;
|
||||
stress[i][1] *= nktv2p;
|
||||
stress[i][2] *= nktv2p;
|
||||
stress[i][3] *= nktv2p;
|
||||
stress[i][4] *= nktv2p;
|
||||
stress[i][5] *= nktv2p;
|
||||
}
|
||||
}
|
||||
|
||||
// convert to pressure units (actually stress/volume = pressure)
|
||||
|
||||
double nktv2p = force->nktv2p;
|
||||
for (i = 0; i < nlocal; i++) {
|
||||
stress[i][0] *= nktv2p;
|
||||
stress[i][1] *= nktv2p;
|
||||
stress[i][2] *= nktv2p;
|
||||
stress[i][3] *= nktv2p;
|
||||
stress[i][4] *= nktv2p;
|
||||
stress[i][5] *= nktv2p;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user