replace string compare with enums, fix memory leak, formatting cleanup
This commit is contained in:
@ -46,7 +46,8 @@ using namespace std;
|
||||
|
||||
ComputeOrientOrderAtom::ComputeOrientOrderAtom(LAMMPS *lmp, int narg, char **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");
|
||||
|
||||
@ -57,7 +58,7 @@ ComputeOrientOrderAtom::ComputeOrientOrderAtom(LAMMPS *lmp, int narg, char **arg
|
||||
qlcompflag = 0;
|
||||
|
||||
// specify which orders to request
|
||||
|
||||
|
||||
nqlist = 5;
|
||||
memory->create(qlist,nqlist,"orientorder/atom:qlist");
|
||||
qlist[0] = 4;
|
||||
@ -73,48 +74,55 @@ ComputeOrientOrderAtom::ComputeOrientOrderAtom(LAMMPS *lmp, int narg, char **arg
|
||||
while (iarg < narg) {
|
||||
if (strcmp(arg[iarg],"nnn") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||
if (strcmp(arg[iarg+1],"NULL") == 0)
|
||||
nnn = 0;
|
||||
else {
|
||||
nnn = force->numeric(FLERR,arg[iarg+1]);
|
||||
if (nnn <= 0)
|
||||
error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||
if (strcmp(arg[iarg+1],"NULL") == 0) {
|
||||
nnn = 0;
|
||||
} else {
|
||||
nnn = force->numeric(FLERR,arg[iarg+1]);
|
||||
if (nnn <= 0)
|
||||
error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||
}
|
||||
iarg += 2;
|
||||
} 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]);
|
||||
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->create(qlist,nqlist,"orientorder/atom:qlist");
|
||||
iarg += 2;
|
||||
if (iarg+nqlist > narg) error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||
qmax = 0;
|
||||
for (int iw = 0; iw < nqlist; iw++) {
|
||||
qlist[iw] = force->numeric(FLERR,arg[iarg+iw]);
|
||||
if (qlist[iw] < 0)
|
||||
error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||
if (qlist[iw] > qmax) qmax = qlist[iw];
|
||||
qlist[iw] = force->numeric(FLERR,arg[iarg+iw]);
|
||||
if (qlist[iw] < 0)
|
||||
error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||
if (qlist[iw] > qmax) qmax = qlist[iw];
|
||||
}
|
||||
iarg += nqlist;
|
||||
if (strcmp(arg[iarg],"components") == 0) {
|
||||
qlcompflag = 1;
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||
qlcompflag = 1;
|
||||
if (iarg+2 > narg)
|
||||
error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||
qlcomp = force->numeric(FLERR,arg[iarg+1]);
|
||||
if (qlcomp <= 0) error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||
iqlcomp = -1;
|
||||
if (qlcomp <= 0)
|
||||
error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||
iqlcomp = -1;
|
||||
for (int iw = 0; iw < nqlist; iw++)
|
||||
if (qlcomp == qlist[iw]) {
|
||||
iqlcomp = iw;
|
||||
break;
|
||||
}
|
||||
if (iqlcomp < 0) error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||
iqlcomp = iw;
|
||||
break;
|
||||
}
|
||||
if (iqlcomp < 0)
|
||||
error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||
iarg += 2;
|
||||
}
|
||||
} 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]);
|
||||
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;
|
||||
iarg += 2;
|
||||
} else error->all(FLERR,"Illegal compute orientorder/atom command");
|
||||
@ -141,7 +149,7 @@ ComputeOrientOrderAtom::~ComputeOrientOrderAtom()
|
||||
memory->destroy(qlist);
|
||||
memory->destroy(qnm_r);
|
||||
memory->destroy(qnm_i);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -224,7 +232,7 @@ void ComputeOrientOrderAtom::compute_peratom()
|
||||
ztmp = x[i][2];
|
||||
jlist = firstneigh[i];
|
||||
jnum = numneigh[i];
|
||||
|
||||
|
||||
// insure distsq and nearest arrays are long enough
|
||||
|
||||
if (jnum > maxneigh) {
|
||||
@ -253,9 +261,9 @@ void ComputeOrientOrderAtom::compute_peratom()
|
||||
rsq = delx*delx + dely*dely + delz*delz;
|
||||
if (rsq < cutsq) {
|
||||
distsq[ncount] = rsq;
|
||||
rlist[ncount][0] = delx;
|
||||
rlist[ncount][1] = dely;
|
||||
rlist[ncount][2] = delz;
|
||||
rlist[ncount][0] = delx;
|
||||
rlist[ncount][1] = dely;
|
||||
rlist[ncount][2] = delz;
|
||||
nearest[ncount++] = j;
|
||||
}
|
||||
}
|
||||
@ -263,16 +271,16 @@ void ComputeOrientOrderAtom::compute_peratom()
|
||||
// if not nnn neighbors, order parameter = 0;
|
||||
|
||||
if ((ncount == 0) || (ncount < nnn)) {
|
||||
for (int iw = 0; iw < nqlist; iw++)
|
||||
qn[iw] = 0.0;
|
||||
for (int iw = 0; iw < nqlist; iw++)
|
||||
qn[iw] = 0.0;
|
||||
continue;
|
||||
}
|
||||
|
||||
// if nnn > 0, use only nearest nnn neighbors
|
||||
|
||||
if (nnn > 0) {
|
||||
select3(nnn,ncount,distsq,nearest,rlist);
|
||||
ncount = nnn;
|
||||
select3(nnn,ncount,distsq,nearest,rlist);
|
||||
ncount = nnn;
|
||||
}
|
||||
|
||||
calc_boop(rlist, ncount, qn, qlist, nqlist);
|
||||
@ -287,8 +295,8 @@ void ComputeOrientOrderAtom::compute_peratom()
|
||||
double ComputeOrientOrderAtom::memory_usage()
|
||||
{
|
||||
double bytes = ncol*nmax * sizeof(double);
|
||||
bytes += (qmax*(2*qmax+1)+maxneigh*4) * sizeof(double);
|
||||
bytes += (nqlist+maxneigh) * sizeof(int);
|
||||
bytes += (qmax*(2*qmax+1)+maxneigh*4) * sizeof(double);
|
||||
bytes += (nqlist+maxneigh) * sizeof(int);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@ -300,18 +308,18 @@ double ComputeOrientOrderAtom::memory_usage()
|
||||
|
||||
// Use no-op do while to create single statement
|
||||
|
||||
#define SWAP(a,b) do { \
|
||||
tmp = a; a = b; b = tmp; \
|
||||
#define SWAP(a,b) do { \
|
||||
tmp = a; a = b; b = tmp; \
|
||||
} while(0)
|
||||
|
||||
#define ISWAP(a,b) do { \
|
||||
itmp = a; a = b; b = itmp; \
|
||||
#define ISWAP(a,b) do { \
|
||||
itmp = a; a = b; b = itmp; \
|
||||
} while(0)
|
||||
|
||||
#define SWAP3(a,b) do { \
|
||||
tmp = a[0]; a[0] = b[0]; b[0] = tmp; \
|
||||
tmp = a[1]; a[1] = b[1]; b[1] = tmp; \
|
||||
tmp = a[2]; a[2] = b[2]; b[2] = tmp; \
|
||||
#define SWAP3(a,b) do { \
|
||||
tmp = a[0]; a[0] = b[0]; b[0] = tmp; \
|
||||
tmp = a[1]; a[1] = b[1]; b[1] = tmp; \
|
||||
tmp = a[2]; a[2] = b[2]; b[2] = tmp; \
|
||||
} while(0)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -330,7 +338,7 @@ void ComputeOrientOrderAtom::select3(int k, int n, double *arr, int *iarr, doubl
|
||||
if (ir <= l+1) {
|
||||
if (ir == l+1 && arr[ir] < arr[l]) {
|
||||
SWAP(arr[l],arr[ir]);
|
||||
ISWAP(iarr[l],iarr[ir]);
|
||||
ISWAP(iarr[l],iarr[ir]);
|
||||
SWAP3(arr3[l],arr3[ir]);
|
||||
}
|
||||
return;
|
||||
@ -342,17 +350,17 @@ void ComputeOrientOrderAtom::select3(int k, int n, double *arr, int *iarr, doubl
|
||||
if (arr[l] > arr[ir]) {
|
||||
SWAP(arr[l],arr[ir]);
|
||||
ISWAP(iarr[l],iarr[ir]);
|
||||
SWAP3(arr3[l],arr3[ir]);
|
||||
SWAP3(arr3[l],arr3[ir]);
|
||||
}
|
||||
if (arr[l+1] > arr[ir]) {
|
||||
SWAP(arr[l+1],arr[ir]);
|
||||
ISWAP(iarr[l+1],iarr[ir]);
|
||||
SWAP3(arr3[l+1],arr3[ir]);
|
||||
SWAP3(arr3[l+1],arr3[ir]);
|
||||
}
|
||||
if (arr[l] > arr[l+1]) {
|
||||
SWAP(arr[l],arr[l+1]);
|
||||
ISWAP(iarr[l],iarr[l+1]);
|
||||
SWAP3(arr3[l],arr3[l+1]);
|
||||
SWAP3(arr3[l],arr3[l+1]);
|
||||
}
|
||||
i = l+1;
|
||||
j = ir;
|
||||
@ -367,7 +375,7 @@ void ComputeOrientOrderAtom::select3(int k, int n, double *arr, int *iarr, doubl
|
||||
if (j < i) break;
|
||||
SWAP(arr[i],arr[j]);
|
||||
ISWAP(iarr[i],iarr[j]);
|
||||
SWAP3(arr3[i],arr3[j]);
|
||||
SWAP3(arr3[i],arr3[j]);
|
||||
}
|
||||
arr[l+1] = arr[j];
|
||||
arr[j] = a;
|
||||
@ -389,9 +397,9 @@ void ComputeOrientOrderAtom::select3(int k, int n, double *arr, int *iarr, doubl
|
||||
calculate the bond orientational order parameters
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void ComputeOrientOrderAtom::calc_boop(double **rlist,
|
||||
int ncount, double qn[],
|
||||
int qlist[], int nqlist) {
|
||||
void ComputeOrientOrderAtom::calc_boop(double **rlist,
|
||||
int ncount, double qn[],
|
||||
int qlist[], int nqlist) {
|
||||
for (int iw = 0; iw < nqlist; iw++) {
|
||||
int n = qlist[iw];
|
||||
|
||||
@ -429,22 +437,22 @@ void ComputeOrientOrderAtom::calc_boop(double **rlist,
|
||||
double expphim_r = expphi_r;
|
||||
double expphim_i = expphi_i;
|
||||
for(int m = 1; m <= +n; m++) {
|
||||
double prefactor = polar_prefactor(n, m, costheta);
|
||||
double c_r = prefactor * expphim_r;
|
||||
double c_i = prefactor * expphim_i;
|
||||
qnm_r[iw][m+n] += c_r;
|
||||
qnm_i[iw][m+n] += c_i;
|
||||
if(m & 1) {
|
||||
qnm_r[iw][-m+n] -= c_r;
|
||||
qnm_i[iw][-m+n] += c_i;
|
||||
} else {
|
||||
qnm_r[iw][-m+n] += c_r;
|
||||
qnm_i[iw][-m+n] -= c_i;
|
||||
}
|
||||
double tmp_r = expphim_r*expphi_r - expphim_i*expphi_i;
|
||||
double tmp_i = expphim_r*expphi_i + expphim_i*expphi_r;
|
||||
expphim_r = tmp_r;
|
||||
expphim_i = tmp_i;
|
||||
double prefactor = polar_prefactor(n, m, costheta);
|
||||
double c_r = prefactor * expphim_r;
|
||||
double c_i = prefactor * expphim_i;
|
||||
qnm_r[iw][m+n] += c_r;
|
||||
qnm_i[iw][m+n] += c_i;
|
||||
if(m & 1) {
|
||||
qnm_r[iw][-m+n] -= c_r;
|
||||
qnm_i[iw][-m+n] += c_i;
|
||||
} else {
|
||||
qnm_r[iw][-m+n] += c_r;
|
||||
qnm_i[iw][-m+n] -= c_i;
|
||||
}
|
||||
double tmp_r = expphim_r*expphi_r - expphim_i*expphi_i;
|
||||
double tmp_i = expphim_r*expphi_i + expphim_i*expphi_r;
|
||||
expphim_r = tmp_r;
|
||||
expphim_i = tmp_i;
|
||||
}
|
||||
|
||||
}
|
||||
@ -458,15 +466,15 @@ void ComputeOrientOrderAtom::calc_boop(double **rlist,
|
||||
for(int m = 0; m < 2*n+1; m++) {
|
||||
qm_sum += qnm_r[iw][m]*qnm_r[iw][m] + qnm_i[iw][m]*qnm_i[iw][m];
|
||||
// printf("Ylm^2 = %d %d %g\n",n,m,
|
||||
// qnm_r[iw][m]*qnm_r[iw][m] + qnm_i[iw][m]*qnm_i[iw][m]);
|
||||
// qnm_r[iw][m]*qnm_r[iw][m] + qnm_i[iw][m]*qnm_i[iw][m]);
|
||||
}
|
||||
qn[iw] = fac * sqrt(qm_sum / (2*n+1));
|
||||
if (qlcompflag && iqlcomp == iw) normfac = 1.0/sqrt(qm_sum);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// output of the complex vector
|
||||
|
||||
|
||||
if (qlcompflag) {
|
||||
int j = nqlist;
|
||||
for(int m = 0; m < 2*qlcomp+1; m++) {
|
||||
@ -485,7 +493,7 @@ double ComputeOrientOrderAtom::dist(const double r[]) {
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
polar prefactor for spherical harmonic Y_l^m, where
|
||||
polar prefactor for spherical harmonic Y_l^m, where
|
||||
Y_l^m (theta, phi) = prefactor(l, m, cos(theta)) * exp(i*m*phi)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user