replace string compare with enums, fix memory leak, formatting cleanup
This commit is contained in:
@ -36,16 +36,15 @@ using namespace LAMMPS_NS;
|
|||||||
|
|
||||||
ComputeCoordAtom::ComputeCoordAtom(LAMMPS *lmp, int narg, char **arg) :
|
ComputeCoordAtom::ComputeCoordAtom(LAMMPS *lmp, int narg, char **arg) :
|
||||||
Compute(lmp, narg, arg),
|
Compute(lmp, narg, arg),
|
||||||
cstyle(NULL), id_orientorder(NULL), typelo(NULL), typehi(NULL), cvec(NULL), carray(NULL)
|
typelo(NULL), typehi(NULL), cvec(NULL), carray(NULL),
|
||||||
|
id_orientorder(NULL), normv(NULL)
|
||||||
{
|
{
|
||||||
if (narg < 5) error->all(FLERR,"Illegal compute coord/atom command");
|
if (narg < 5) error->all(FLERR,"Illegal compute coord/atom command");
|
||||||
|
|
||||||
int n = strlen(arg[3]) + 1;
|
cstyle = NONE;
|
||||||
cstyle = new char[n];
|
|
||||||
strcpy(cstyle,arg[3]);
|
|
||||||
|
|
||||||
if (strcmp(cstyle,"cutoff") == 0) {
|
|
||||||
|
|
||||||
|
if (strcmp(arg[3],"cutoff") == 0) {
|
||||||
|
cstyle = CUTOFF;
|
||||||
double cutoff = force->numeric(FLERR,arg[4]);
|
double cutoff = force->numeric(FLERR,arg[4]);
|
||||||
cutsq = cutoff*cutoff;
|
cutsq = cutoff*cutoff;
|
||||||
|
|
||||||
@ -68,14 +67,13 @@ ComputeCoordAtom::ComputeCoordAtom(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
ncol++;
|
ncol++;
|
||||||
iarg++;
|
iarg++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (strcmp(cstyle,"orientorder") == 0) {
|
} else if (strcmp(arg[3],"orientorder") == 0) {
|
||||||
|
cstyle = ORIENT;
|
||||||
if (narg != 6) error->all(FLERR,"Illegal compute coord/atom command");
|
if (narg != 6) error->all(FLERR,"Illegal compute coord/atom command");
|
||||||
|
|
||||||
n = strlen(arg[4]) + 1;
|
int n = strlen(arg[4]) + 1;
|
||||||
id_orientorder = new char[n];
|
id_orientorder = new char[n];
|
||||||
strcpy(id_orientorder,arg[4]);
|
strcpy(id_orientorder,arg[4]);
|
||||||
|
|
||||||
@ -112,13 +110,14 @@ ComputeCoordAtom::~ComputeCoordAtom()
|
|||||||
delete [] typehi;
|
delete [] typehi;
|
||||||
memory->destroy(cvec);
|
memory->destroy(cvec);
|
||||||
memory->destroy(carray);
|
memory->destroy(carray);
|
||||||
|
delete [] id_orientorder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void ComputeCoordAtom::init()
|
void ComputeCoordAtom::init()
|
||||||
{
|
{
|
||||||
if (strcmp(cstyle,"orientorder") == 0) {
|
if (cstyle == ORIENT) {
|
||||||
int iorientorder = modify->find_compute(id_orientorder);
|
int iorientorder = modify->find_compute(id_orientorder);
|
||||||
c_orientorder = (ComputeOrientOrderAtom*)(modify->compute[iorientorder]);
|
c_orientorder = (ComputeOrientOrderAtom*)(modify->compute[iorientorder]);
|
||||||
cutsq = c_orientorder->cutsq;
|
cutsq = c_orientorder->cutsq;
|
||||||
@ -126,7 +125,8 @@ void ComputeCoordAtom::init()
|
|||||||
// communicate real and imaginary 2*l+1 components of the normalized vector
|
// communicate real and imaginary 2*l+1 components of the normalized vector
|
||||||
comm_forward = 2*(2*l+1);
|
comm_forward = 2*(2*l+1);
|
||||||
if (c_orientorder->iqlcomp < 0)
|
if (c_orientorder->iqlcomp < 0)
|
||||||
error->all(FLERR,"Compute coord/atom requires components option in compute orientorder/atom be defined");
|
error->all(FLERR,"Compute coord/atom requires components "
|
||||||
|
"option in compute orientorder/atom be defined");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (force->pair == NULL)
|
if (force->pair == NULL)
|
||||||
@ -188,7 +188,7 @@ void ComputeCoordAtom::compute_peratom()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(cstyle,"orientorder") == 0) {
|
if (cstyle == ORIENT) {
|
||||||
if (!(c_orientorder->invoked_flag & INVOKED_PERATOM)) {
|
if (!(c_orientorder->invoked_flag & INVOKED_PERATOM)) {
|
||||||
c_orientorder->compute_peratom();
|
c_orientorder->compute_peratom();
|
||||||
c_orientorder->invoked_flag |= INVOKED_PERATOM;
|
c_orientorder->invoked_flag |= INVOKED_PERATOM;
|
||||||
@ -217,7 +217,7 @@ void ComputeCoordAtom::compute_peratom()
|
|||||||
int *type = atom->type;
|
int *type = atom->type;
|
||||||
int *mask = atom->mask;
|
int *mask = atom->mask;
|
||||||
|
|
||||||
if (strcmp(cstyle,"cutoff") == 0) {
|
if (cstyle == CUTOFF) {
|
||||||
|
|
||||||
if (ncol == 1) {
|
if (ncol == 1) {
|
||||||
|
|
||||||
@ -281,7 +281,7 @@ void ComputeCoordAtom::compute_peratom()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (strcmp(cstyle,"orientorder") == 0) {
|
} else if (cstyle == ORIENT) {
|
||||||
|
|
||||||
for (ii = 0; ii < inum; ii++) {
|
for (ii = 0; ii < inum; ii++) {
|
||||||
i = ilist[ii];
|
i = ilist[ii];
|
||||||
@ -296,7 +296,6 @@ void ComputeCoordAtom::compute_peratom()
|
|||||||
for (jj = 0; jj < jnum; jj++) {
|
for (jj = 0; jj < jnum; jj++) {
|
||||||
j = jlist[jj];
|
j = jlist[jj];
|
||||||
j &= NEIGHMASK;
|
j &= NEIGHMASK;
|
||||||
|
|
||||||
delx = xtmp - x[j][0];
|
delx = xtmp - x[j][0];
|
||||||
dely = ytmp - x[j][1];
|
dely = ytmp - x[j][1];
|
||||||
delz = ztmp - x[j][2];
|
delz = ztmp - x[j][2];
|
||||||
|
|||||||
@ -34,6 +34,7 @@ class ComputeCoordAtom : public Compute {
|
|||||||
int pack_forward_comm(int, int *, double *, int, int *);
|
int pack_forward_comm(int, int *, double *, int, int *);
|
||||||
void unpack_forward_comm(int, int, double *);
|
void unpack_forward_comm(int, int, double *);
|
||||||
double memory_usage();
|
double memory_usage();
|
||||||
|
enum {NONE,CUTOFF,ORIENT};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int nmax,ncol;
|
int nmax,ncol;
|
||||||
@ -45,10 +46,10 @@ class ComputeCoordAtom : public Compute {
|
|||||||
double **carray;
|
double **carray;
|
||||||
|
|
||||||
class ComputeOrientOrderAtom *c_orientorder;
|
class ComputeOrientOrderAtom *c_orientorder;
|
||||||
char *cstyle,*id_orientorder;
|
char *id_orientorder;
|
||||||
double threshold;
|
double threshold;
|
||||||
double **normv;
|
double **normv;
|
||||||
int nqlist,l;
|
int cstyle,nqlist,l;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,7 +46,8 @@ using namespace std;
|
|||||||
|
|
||||||
ComputeOrientOrderAtom::ComputeOrientOrderAtom(LAMMPS *lmp, int narg, char **arg) :
|
ComputeOrientOrderAtom::ComputeOrientOrderAtom(LAMMPS *lmp, int narg, char **arg) :
|
||||||
Compute(lmp, narg, arg),
|
Compute(lmp, narg, arg),
|
||||||
distsq(NULL), nearest(NULL), rlist(NULL), qlist(NULL), qnarray(NULL), qnm_r(NULL), qnm_i(NULL)
|
qlist(NULL), distsq(NULL), nearest(NULL), rlist(NULL),
|
||||||
|
qnarray(NULL), qnm_r(NULL), qnm_i(NULL)
|
||||||
{
|
{
|
||||||
if (narg < 3 ) error->all(FLERR,"Illegal compute orientorder/atom command");
|
if (narg < 3 ) error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||||
|
|
||||||
@ -73,18 +74,20 @@ ComputeOrientOrderAtom::ComputeOrientOrderAtom(LAMMPS *lmp, int narg, char **arg
|
|||||||
while (iarg < narg) {
|
while (iarg < narg) {
|
||||||
if (strcmp(arg[iarg],"nnn") == 0) {
|
if (strcmp(arg[iarg],"nnn") == 0) {
|
||||||
if (iarg+2 > narg) error->all(FLERR,"Illegal compute orientorder/atom command");
|
if (iarg+2 > narg) error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||||
if (strcmp(arg[iarg+1],"NULL") == 0)
|
if (strcmp(arg[iarg+1],"NULL") == 0) {
|
||||||
nnn = 0;
|
nnn = 0;
|
||||||
else {
|
} else {
|
||||||
nnn = force->numeric(FLERR,arg[iarg+1]);
|
nnn = force->numeric(FLERR,arg[iarg+1]);
|
||||||
if (nnn <= 0)
|
if (nnn <= 0)
|
||||||
error->all(FLERR,"Illegal compute orientorder/atom command");
|
error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||||
}
|
}
|
||||||
iarg += 2;
|
iarg += 2;
|
||||||
} else if (strcmp(arg[iarg],"degrees") == 0) {
|
} else if (strcmp(arg[iarg],"degrees") == 0) {
|
||||||
if (iarg+2 > narg) error->all(FLERR,"Illegal compute orientorder/atom command");
|
if (iarg+2 > narg)
|
||||||
|
error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||||
nqlist = force->numeric(FLERR,arg[iarg+1]);
|
nqlist = force->numeric(FLERR,arg[iarg+1]);
|
||||||
if (nqlist <= 0) error->all(FLERR,"Illegal compute orientorder/atom command");
|
if (nqlist <= 0)
|
||||||
|
error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||||
memory->destroy(qlist);
|
memory->destroy(qlist);
|
||||||
memory->create(qlist,nqlist,"orientorder/atom:qlist");
|
memory->create(qlist,nqlist,"orientorder/atom:qlist");
|
||||||
iarg += 2;
|
iarg += 2;
|
||||||
@ -99,22 +102,27 @@ ComputeOrientOrderAtom::ComputeOrientOrderAtom(LAMMPS *lmp, int narg, char **arg
|
|||||||
iarg += nqlist;
|
iarg += nqlist;
|
||||||
if (strcmp(arg[iarg],"components") == 0) {
|
if (strcmp(arg[iarg],"components") == 0) {
|
||||||
qlcompflag = 1;
|
qlcompflag = 1;
|
||||||
if (iarg+2 > narg) error->all(FLERR,"Illegal compute orientorder/atom command");
|
if (iarg+2 > narg)
|
||||||
|
error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||||
qlcomp = force->numeric(FLERR,arg[iarg+1]);
|
qlcomp = force->numeric(FLERR,arg[iarg+1]);
|
||||||
if (qlcomp <= 0) error->all(FLERR,"Illegal compute orientorder/atom command");
|
if (qlcomp <= 0)
|
||||||
|
error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||||
iqlcomp = -1;
|
iqlcomp = -1;
|
||||||
for (int iw = 0; iw < nqlist; iw++)
|
for (int iw = 0; iw < nqlist; iw++)
|
||||||
if (qlcomp == qlist[iw]) {
|
if (qlcomp == qlist[iw]) {
|
||||||
iqlcomp = iw;
|
iqlcomp = iw;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (iqlcomp < 0) error->all(FLERR,"Illegal compute orientorder/atom command");
|
if (iqlcomp < 0)
|
||||||
|
error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||||
iarg += 2;
|
iarg += 2;
|
||||||
}
|
}
|
||||||
} else if (strcmp(arg[iarg],"cutoff") == 0) {
|
} else if (strcmp(arg[iarg],"cutoff") == 0) {
|
||||||
if (iarg+2 > narg) error->all(FLERR,"Illegal compute orientorder/atom command");
|
if (iarg+2 > narg)
|
||||||
|
error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||||
double cutoff = force->numeric(FLERR,arg[iarg+1]);
|
double cutoff = force->numeric(FLERR,arg[iarg+1]);
|
||||||
if (cutoff <= 0.0) error->all(FLERR,"Illegal compute orientorder/atom command");
|
if (cutoff <= 0.0)
|
||||||
|
error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||||
cutsq = cutoff*cutoff;
|
cutsq = cutoff*cutoff;
|
||||||
iarg += 2;
|
iarg += 2;
|
||||||
} else error->all(FLERR,"Illegal compute orientorder/atom command");
|
} else error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||||
|
|||||||
Reference in New Issue
Block a user