git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@711 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
@ -19,7 +19,9 @@
|
||||
#include "comm.h"
|
||||
#include "update.h"
|
||||
#include "force.h"
|
||||
#include "bond.h"
|
||||
#include "pair.h"
|
||||
#include "domain.h"
|
||||
#include "memory.h"
|
||||
#include "error.h"
|
||||
|
||||
@ -33,13 +35,37 @@ using namespace LAMMPS_NS;
|
||||
ComputeStressAtom::ComputeStressAtom(LAMMPS *lmp, int narg, char **arg) :
|
||||
Compute(lmp, narg, arg)
|
||||
{
|
||||
if (narg != 3) error->all("Illegal compute stress/atom command");
|
||||
if (narg < 3) error->all("Illegal compute stress/atom command");
|
||||
|
||||
peratom_flag = 1;
|
||||
size_peratom = 6;
|
||||
comm_reverse = 6;
|
||||
neigh_half_once = 1;
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
nmax = 0;
|
||||
stress = NULL;
|
||||
}
|
||||
@ -55,8 +81,14 @@ ComputeStressAtom::~ComputeStressAtom()
|
||||
|
||||
void ComputeStressAtom::init()
|
||||
{
|
||||
if (force->pair == NULL || force->pair->single_enable == 0)
|
||||
error->all("Pair style does not support computing per-atom stress");
|
||||
if (pairrequest) {
|
||||
if (force->pair == NULL || force->pair->single_enable == 0)
|
||||
error->all("Pair style does not support computing per-atom stress");
|
||||
pairflag = 1;
|
||||
} else pairflag = 0;
|
||||
|
||||
if (bondrequest && force->bond) bondflag = 1;
|
||||
else bondflag = 0;
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0; i < modify->ncompute; i++)
|
||||
@ -69,8 +101,8 @@ void ComputeStressAtom::init()
|
||||
|
||||
void ComputeStressAtom::compute_peratom()
|
||||
{
|
||||
int i,j,k,n,itype,jtype,numneigh;
|
||||
double xtmp,ytmp,ztmp,delx,dely,delz,rsq;
|
||||
int i,j,k,n,i1,i2,itype,jtype,numneigh,iflag;
|
||||
double xtmp,ytmp,ztmp,delx,dely,delz,rsq,eng;
|
||||
double factor_coul,factor_lj,fforce,rmass;
|
||||
int *neighs;
|
||||
Pair::One one;
|
||||
@ -86,10 +118,12 @@ void ComputeStressAtom::compute_peratom()
|
||||
}
|
||||
|
||||
// clear stress array
|
||||
// n includes ghosts only if newton_pair flag is set
|
||||
// n includes ghosts only if newton flag is set
|
||||
|
||||
if (force->newton_pair) n = atom->nlocal + atom->nghost;
|
||||
else n = atom->nlocal;
|
||||
int nlocal = atom->nlocal;
|
||||
|
||||
if (force->newton) n = nlocal + atom->nghost;
|
||||
else n = nlocal;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
stress[i][0] = 0.0;
|
||||
@ -100,73 +134,123 @@ void ComputeStressAtom::compute_peratom()
|
||||
stress[i][5] = 0.0;
|
||||
}
|
||||
|
||||
// if needed, build a half neighbor list
|
||||
// compute pairwise stress for atoms via pair->single()
|
||||
// if neither atom is in compute group, skip that pair
|
||||
|
||||
if (!neighbor->half_every) neighbor->build_half();
|
||||
if (pairflag) {
|
||||
|
||||
// compute pairwise stress for all atoms via pair->single()
|
||||
// use half neighbor list
|
||||
// if needed, build a half neighbor list
|
||||
|
||||
double *special_coul = force->special_coul;
|
||||
double *special_lj = force->special_lj;
|
||||
double **cutsq = force->pair->cutsq;
|
||||
if (!neighbor->half_every) neighbor->build_half();
|
||||
|
||||
double **x = atom->x;
|
||||
int *type = atom->type;
|
||||
int nlocal = atom->nlocal;
|
||||
int nall = atom->nlocal + atom->nghost;
|
||||
double *special_coul = force->special_coul;
|
||||
double *special_lj = force->special_lj;
|
||||
double **cutsq = force->pair->cutsq;
|
||||
int newton_pair = force->newton_pair;
|
||||
|
||||
for (i = 0; i < nlocal; i++) {
|
||||
xtmp = x[i][0];
|
||||
ytmp = x[i][1];
|
||||
ztmp = x[i][2];
|
||||
itype = type[i];
|
||||
neighs = neighbor->firstneigh[i];
|
||||
numneigh = neighbor->numneigh[i];
|
||||
|
||||
for (k = 0; k < numneigh; k++) {
|
||||
j = neighs[k];
|
||||
double **x = atom->x;
|
||||
int *mask = atom->mask;
|
||||
int *type = atom->type;
|
||||
int nall = nlocal + atom->nghost;
|
||||
|
||||
if (j < nall) factor_coul = factor_lj = 1.0;
|
||||
else {
|
||||
factor_coul = special_coul[j/nall];
|
||||
factor_lj = special_lj[j/nall];
|
||||
j %= nall;
|
||||
}
|
||||
for (i = 0; i < nlocal; i++) {
|
||||
xtmp = x[i][0];
|
||||
ytmp = x[i][1];
|
||||
ztmp = x[i][2];
|
||||
itype = type[i];
|
||||
iflag = mask[i] & groupbit;
|
||||
neighs = neighbor->firstneigh[i];
|
||||
numneigh = neighbor->numneigh[i];
|
||||
|
||||
for (k = 0; k < numneigh; k++) {
|
||||
j = neighs[k];
|
||||
if (iflag == 0 && (mask[j] & groupbit) == 0) continue;
|
||||
|
||||
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;
|
||||
|
||||
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 (force->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 (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;
|
||||
|
||||
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 (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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// compute bond stress for atoms via bond->single()
|
||||
// if neither atom is in compute group, skip that bond
|
||||
|
||||
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];
|
||||
if ((mask[i1] & groupbit) == 0 && (mask[i2] & groupbit) == 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);
|
||||
|
||||
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 (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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// communicate stress between neighbor procs
|
||||
|
||||
if (force->newton_pair) comm->reverse_comm_compute(this);
|
||||
if (force->newton) comm->reverse_comm_compute(this);
|
||||
|
||||
// remove double counting of per-atom stress
|
||||
// remove double counting
|
||||
|
||||
for (i = 0; i < nlocal; i++) {
|
||||
stress[i][0] *= 0.5;
|
||||
@ -177,21 +261,27 @@ void ComputeStressAtom::compute_peratom()
|
||||
stress[i][5] *= 0.5;
|
||||
}
|
||||
|
||||
// include kinetic energy term for each atom
|
||||
// include kinetic energy term for each atom in group
|
||||
// mvv2e converts mv^2 to energy
|
||||
|
||||
double **v = atom->v;
|
||||
double *mass = atom->mass;
|
||||
double mvv2e = force->mvv2e;
|
||||
|
||||
for (i = 0; i < nlocal; i++) {
|
||||
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];
|
||||
if (kerequest) {
|
||||
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++) {
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// convert to pressure units (actually stress/volume = pressure)
|
||||
|
||||
Reference in New Issue
Block a user