import contributed code for computes coord/atom and orientorder/atom
This commit is contained in:
@ -15,6 +15,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "compute_coord_atom.h"
|
||||
#include "compute_orientorder_atom.h"
|
||||
#include "atom.h"
|
||||
#include "update.h"
|
||||
#include "modify.h"
|
||||
@ -29,37 +30,72 @@
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
#define INVOKED_PERATOM 8
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
ComputeCoordAtom::ComputeCoordAtom(LAMMPS *lmp, int narg, char **arg) :
|
||||
Compute(lmp, narg, arg),
|
||||
typelo(NULL), typehi(NULL), cvec(NULL), carray(NULL)
|
||||
cstyle(NULL), id_orientorder(NULL), typelo(NULL), typehi(NULL), cvec(NULL), carray(NULL)
|
||||
{
|
||||
if (narg < 4) error->all(FLERR,"Illegal compute coord/atom command");
|
||||
if (narg < 5) error->all(FLERR,"Illegal compute coord/atom command");
|
||||
|
||||
double cutoff = force->numeric(FLERR,arg[3]);
|
||||
cutsq = cutoff*cutoff;
|
||||
int n = strlen(arg[3]) + 1;
|
||||
cstyle = new char[n];
|
||||
strcpy(cstyle,arg[3]);
|
||||
|
||||
ncol = narg-4 + 1;
|
||||
int ntypes = atom->ntypes;
|
||||
typelo = new int[ncol];
|
||||
typehi = new int[ncol];
|
||||
if (strcmp(cstyle,"cutoff") == 0) {
|
||||
|
||||
double cutoff = force->numeric(FLERR,arg[4]);
|
||||
cutsq = cutoff*cutoff;
|
||||
|
||||
ncol = narg-5 + 1;
|
||||
int ntypes = atom->ntypes;
|
||||
typelo = new int[ncol];
|
||||
typehi = new int[ncol];
|
||||
|
||||
if (narg == 5) {
|
||||
ncol = 1;
|
||||
typelo[0] = 1;
|
||||
typehi[0] = ntypes;
|
||||
} else {
|
||||
ncol = 0;
|
||||
int iarg = 5;
|
||||
while (iarg < narg) {
|
||||
force->bounds(FLERR,arg[iarg],ntypes,typelo[ncol],typehi[ncol]);
|
||||
if (typelo[ncol] > typehi[ncol])
|
||||
error->all(FLERR,"Illegal compute coord/atom command");
|
||||
ncol++;
|
||||
iarg++;
|
||||
}
|
||||
|
||||
if (narg == 4) {
|
||||
ncol = 1;
|
||||
typelo[0] = 1;
|
||||
typehi[0] = ntypes;
|
||||
} else {
|
||||
ncol = 0;
|
||||
int iarg = 4;
|
||||
while (iarg < narg) {
|
||||
force->bounds(FLERR,arg[iarg],ntypes,typelo[ncol],typehi[ncol]);
|
||||
if (typelo[ncol] > typehi[ncol])
|
||||
error->all(FLERR,"Illegal compute coord/atom command");
|
||||
ncol++;
|
||||
iarg++;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (strcmp(cstyle,"orientorder") == 0) {
|
||||
|
||||
if (narg != 6) error->all(FLERR,"Illegal compute coord/atom command");
|
||||
|
||||
n = strlen(arg[4]) + 1;
|
||||
id_orientorder = new char[n];
|
||||
strcpy(id_orientorder,arg[4]);
|
||||
|
||||
int iorientorder = modify->find_compute(id_orientorder);
|
||||
if (iorientorder < 0)
|
||||
error->all(FLERR,"Could not find compute coord/atom compute ID");
|
||||
if (strcmp(modify->compute[iorientorder]->style,"orientorder/atom") != 0)
|
||||
error->all(FLERR,"Compute coord/atom compute ID does not compute orientorder/atom");
|
||||
|
||||
threshold = force->numeric(FLERR,arg[5]);
|
||||
if (threshold <= -1.0 || threshold >= 1.0)
|
||||
error->all(FLERR,"Compute coord/atom threshold value must lie between -1 and 1");
|
||||
|
||||
ncol = 1;
|
||||
typelo = new int[ncol];
|
||||
typehi = new int[ncol];
|
||||
typelo[0] = 1;
|
||||
typehi[0] = atom->ntypes;
|
||||
|
||||
} else error->all(FLERR,"Invalid cstyle in compute coord/atom");
|
||||
|
||||
peratom_flag = 1;
|
||||
if (ncol == 1) size_peratom_cols = 0;
|
||||
@ -82,6 +118,17 @@ ComputeCoordAtom::~ComputeCoordAtom()
|
||||
|
||||
void ComputeCoordAtom::init()
|
||||
{
|
||||
if (strcmp(cstyle,"orientorder") == 0) {
|
||||
int iorientorder = modify->find_compute(id_orientorder);
|
||||
c_orientorder = (ComputeOrientOrderAtom*)(modify->compute[iorientorder]);
|
||||
cutsq = c_orientorder->cutsq;
|
||||
l = c_orientorder->qlcomp;
|
||||
// communicate real and imaginary 2*l+1 components of the normalized vector
|
||||
comm_forward = 2*(2*l+1);
|
||||
if (c_orientorder->iqlcomp < 0)
|
||||
error->all(FLERR,"Compute coord/atom requires components option in compute orientorder/atom be defined");
|
||||
}
|
||||
|
||||
if (force->pair == NULL)
|
||||
error->all(FLERR,"Compute coord/atom requires a pair style be defined");
|
||||
if (sqrt(cutsq) > force->pair->cutforce)
|
||||
@ -122,6 +169,9 @@ void ComputeCoordAtom::compute_peratom()
|
||||
|
||||
invoked_peratom = update->ntimestep;
|
||||
|
||||
// printf("Number of degrees %i components degree %i",nqlist,l);
|
||||
// printf("Particle \t %i \t Norm \t %g \n",0,norm[0][0]);
|
||||
|
||||
// grow coordination array if necessary
|
||||
|
||||
if (atom->nmax > nmax) {
|
||||
@ -138,6 +188,19 @@ void ComputeCoordAtom::compute_peratom()
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(cstyle,"orientorder") == 0) {
|
||||
if (!(c_orientorder->invoked_flag & INVOKED_PERATOM)) {
|
||||
c_orientorder->compute_peratom();
|
||||
c_orientorder->invoked_flag |= INVOKED_PERATOM;
|
||||
}
|
||||
nqlist = c_orientorder->nqlist;
|
||||
int ltmp = l;
|
||||
// l = c_orientorder->qlcomp;
|
||||
if (ltmp != l) error->all(FLERR,"Debug error, ltmp != l\n");
|
||||
normv = c_orientorder->array_atom;
|
||||
comm->forward_comm_compute(this);
|
||||
}
|
||||
|
||||
// invoke full neighbor list (will copy or build if necessary)
|
||||
|
||||
neighbor->build_one(list);
|
||||
@ -154,65 +217,131 @@ void ComputeCoordAtom::compute_peratom()
|
||||
int *type = atom->type;
|
||||
int *mask = atom->mask;
|
||||
|
||||
if (ncol == 1) {
|
||||
for (ii = 0; ii < inum; ii++) {
|
||||
i = ilist[ii];
|
||||
if (mask[i] & groupbit) {
|
||||
xtmp = x[i][0];
|
||||
ytmp = x[i][1];
|
||||
ztmp = x[i][2];
|
||||
jlist = firstneigh[i];
|
||||
jnum = numneigh[i];
|
||||
if (strcmp(cstyle,"cutoff") == 0) {
|
||||
|
||||
n = 0;
|
||||
for (jj = 0; jj < jnum; jj++) {
|
||||
j = jlist[jj];
|
||||
j &= NEIGHMASK;
|
||||
if (ncol == 1) {
|
||||
|
||||
jtype = type[j];
|
||||
delx = xtmp - x[j][0];
|
||||
dely = ytmp - x[j][1];
|
||||
delz = ztmp - x[j][2];
|
||||
rsq = delx*delx + dely*dely + delz*delz;
|
||||
if (rsq < cutsq && jtype >= typelo[0] && jtype <= typehi[0]) n++;
|
||||
}
|
||||
for (ii = 0; ii < inum; ii++) {
|
||||
i = ilist[ii];
|
||||
if (mask[i] & groupbit) {
|
||||
xtmp = x[i][0];
|
||||
ytmp = x[i][1];
|
||||
ztmp = x[i][2];
|
||||
jlist = firstneigh[i];
|
||||
jnum = numneigh[i];
|
||||
|
||||
cvec[i] = n;
|
||||
} else cvec[i] = 0.0;
|
||||
}
|
||||
n = 0;
|
||||
for (jj = 0; jj < jnum; jj++) {
|
||||
j = jlist[jj];
|
||||
j &= NEIGHMASK;
|
||||
|
||||
} else {
|
||||
for (ii = 0; ii < inum; ii++) {
|
||||
i = ilist[ii];
|
||||
count = carray[i];
|
||||
for (m = 0; m < ncol; m++) count[m] = 0.0;
|
||||
jtype = type[j];
|
||||
delx = xtmp - x[j][0];
|
||||
dely = ytmp - x[j][1];
|
||||
delz = ztmp - x[j][2];
|
||||
rsq = delx*delx + dely*dely + delz*delz;
|
||||
if (rsq < cutsq && jtype >= typelo[0] && jtype <= typehi[0])
|
||||
n++;
|
||||
}
|
||||
|
||||
if (mask[i] & groupbit) {
|
||||
xtmp = x[i][0];
|
||||
ytmp = x[i][1];
|
||||
ztmp = x[i][2];
|
||||
jlist = firstneigh[i];
|
||||
jnum = numneigh[i];
|
||||
cvec[i] = n;
|
||||
} else cvec[i] = 0.0;
|
||||
}
|
||||
|
||||
} else {
|
||||
for (ii = 0; ii < inum; ii++) {
|
||||
i = ilist[ii];
|
||||
count = carray[i];
|
||||
for (m = 0; m < ncol; m++) count[m] = 0.0;
|
||||
|
||||
if (mask[i] & groupbit) {
|
||||
xtmp = x[i][0];
|
||||
ytmp = x[i][1];
|
||||
ztmp = x[i][2];
|
||||
jlist = firstneigh[i];
|
||||
jnum = numneigh[i];
|
||||
|
||||
|
||||
for (jj = 0; jj < jnum; jj++) {
|
||||
j = jlist[jj];
|
||||
j &= NEIGHMASK;
|
||||
for (jj = 0; jj < jnum; jj++) {
|
||||
j = jlist[jj];
|
||||
j &= NEIGHMASK;
|
||||
|
||||
jtype = type[j];
|
||||
delx = xtmp - x[j][0];
|
||||
dely = ytmp - x[j][1];
|
||||
delz = ztmp - x[j][2];
|
||||
rsq = delx*delx + dely*dely + delz*delz;
|
||||
if (rsq < cutsq) {
|
||||
for (m = 0; m < ncol; m++)
|
||||
if (jtype >= typelo[m] && jtype <= typehi[m])
|
||||
count[m] += 1.0;
|
||||
jtype = type[j];
|
||||
delx = xtmp - x[j][0];
|
||||
dely = ytmp - x[j][1];
|
||||
delz = ztmp - x[j][2];
|
||||
rsq = delx*delx + dely*dely + delz*delz;
|
||||
if (rsq < cutsq) {
|
||||
for (m = 0; m < ncol; m++)
|
||||
if (jtype >= typelo[m] && jtype <= typehi[m])
|
||||
count[m] += 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (strcmp(cstyle,"orientorder") == 0) {
|
||||
|
||||
for (ii = 0; ii < inum; ii++) {
|
||||
i = ilist[ii];
|
||||
if (mask[i] & groupbit) {
|
||||
xtmp = x[i][0];
|
||||
ytmp = x[i][1];
|
||||
ztmp = x[i][2];
|
||||
jlist = firstneigh[i];
|
||||
jnum = numneigh[i];
|
||||
|
||||
n = 0;
|
||||
for (jj = 0; jj < jnum; jj++) {
|
||||
j = jlist[jj];
|
||||
j &= NEIGHMASK;
|
||||
|
||||
delx = xtmp - x[j][0];
|
||||
dely = ytmp - x[j][1];
|
||||
delz = ztmp - x[j][2];
|
||||
rsq = delx*delx + dely*dely + delz*delz;
|
||||
if (rsq < cutsq) {
|
||||
double dot_product = 0.0;
|
||||
for (int m=0; m < 2*(2*l+1); m++) {
|
||||
dot_product += normv[i][nqlist+m]*normv[j][nqlist+m];
|
||||
}
|
||||
if (dot_product > threshold) n++;
|
||||
}
|
||||
}
|
||||
cvec[i] = n;
|
||||
} else cvec[i] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
int ComputeCoordAtom::pack_forward_comm(int n, int *list, double *buf,
|
||||
int pbc_flag, int *pbc)
|
||||
{
|
||||
int i,m=0,j;
|
||||
for (i = 0; i < n; ++i) {
|
||||
for (j = nqlist; j < nqlist + 2*(2*l+1); ++j) {
|
||||
buf[m++] = normv[list[i]][j];
|
||||
}
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void ComputeCoordAtom::unpack_forward_comm(int n, int first, double *buf)
|
||||
{
|
||||
int i,last,m=0,j;
|
||||
last = first + n;
|
||||
for (i = first; i < last; ++i) {
|
||||
for (j = nqlist; j < nqlist + 2*(2*l+1); ++j) {
|
||||
normv[i][j] = buf[m++];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user