two example cases of using the ArgInfo class

This commit is contained in:
Axel Kohlmeyer
2021-01-30 00:51:06 -05:00
parent c1742aa3d1
commit 03136ed3e3
2 changed files with 93 additions and 122 deletions

View File

@ -13,6 +13,7 @@
#include "fix_ave_atom.h"
#include "arg_info.h"
#include "atom.h"
#include "compute.h"
#include "error.h"
@ -27,8 +28,6 @@
using namespace LAMMPS_NS;
using namespace FixConst;
enum{X,V,F,COMPUTE,FIX,VARIABLE};
#define INVOKED_PERATOM 8
/* ---------------------------------------------------------------------- */
@ -67,60 +66,46 @@ FixAveAtom::FixAveAtom(LAMMPS *lmp, int narg, char **arg) :
ids[i] = nullptr;
if (strcmp(arg[i],"x") == 0) {
which[i] = X;
which[i] = ArgInfo::X;
argindex[i] = 0;
} else if (strcmp(arg[i],"y") == 0) {
which[i] = X;
which[i] = ArgInfo::X;
argindex[i] = 1;
} else if (strcmp(arg[i],"z") == 0) {
which[i] = X;
which[i] = ArgInfo::X;
argindex[i] = 2;
} else if (strcmp(arg[i],"vx") == 0) {
which[i] = V;
which[i] = ArgInfo::V;
argindex[i] = 0;
} else if (strcmp(arg[i],"vy") == 0) {
which[i] = V;
which[i] = ArgInfo::V;
argindex[i] = 1;
} else if (strcmp(arg[i],"vz") == 0) {
which[i] = V;
which[i] = ArgInfo::V;
argindex[i] = 2;
} else if (strcmp(arg[i],"fx") == 0) {
which[i] = F;
which[i] = ArgInfo::F;
argindex[i] = 0;
} else if (strcmp(arg[i],"fy") == 0) {
which[i] = F;
which[i] = ArgInfo::F;
argindex[i] = 1;
} else if (strcmp(arg[i],"fz") == 0) {
which[i] = F;
which[i] = ArgInfo::F;
argindex[i] = 2;
} else if (strncmp(arg[i],"c_",2) == 0 ||
strncmp(arg[i],"f_",2) == 0 ||
strncmp(arg[i],"v_",2) == 0) {
if (arg[i][0] == 'c') which[i] = COMPUTE;
else if (arg[i][0] == 'f') which[i] = FIX;
else if (arg[i][0] == 'v') which[i] = VARIABLE;
} else {
ArgInfo argi(arg[i]);
int n = strlen(arg[i]);
char *suffix = new char[n];
strcpy(suffix,&arg[i][2]);
which[i] = argi.get_type();
argindex[i] = argi.get_dim();
ids[i] = argi.copy_name();
char *ptr = strchr(suffix,'[');
if (ptr) {
if (suffix[strlen(suffix)-1] != ']')
error->all(FLERR,"Illegal fix ave/atom command");
argindex[i] = atoi(ptr+1);
*ptr = '\0';
} else argindex[i] = 0;
n = strlen(suffix) + 1;
ids[i] = new char[n];
strcpy(ids[i],suffix);
delete [] suffix;
} else error->all(FLERR,"Illegal fix ave/atom command");
if ((which[i] == ArgInfo::UNKNOWN) || (which[i] == ArgInfo::NONE)
|| (argindex[i] > 1))
error->all(FLERR,"Illegal fix ave/atom command");
}
}
// if wildcard expansion occurred, free earg memory from exapnd_args()
@ -139,7 +124,7 @@ FixAveAtom::FixAveAtom(LAMMPS *lmp, int narg, char **arg) :
error->all(FLERR,"Illegal fix ave/atom command");
for (int i = 0; i < nvalues; i++) {
if (which[i] == COMPUTE) {
if (which[i] == ArgInfo::COMPUTE) {
int icompute = modify->find_compute(ids[i]);
if (icompute < 0)
error->all(FLERR,"Compute ID for fix ave/atom does not exist");
@ -157,7 +142,7 @@ FixAveAtom::FixAveAtom(LAMMPS *lmp, int narg, char **arg) :
argindex[i] > modify->compute[icompute]->size_peratom_cols)
error->all(FLERR,"Fix ave/atom compute array is accessed out-of-range");
} else if (which[i] == FIX) {
} else if (which[i] == ArgInfo::FIX) {
int ifix = modify->find_fix(ids[i]);
if (ifix < 0)
error->all(FLERR,"Fix ID for fix ave/atom does not exist");
@ -175,7 +160,7 @@ FixAveAtom::FixAveAtom(LAMMPS *lmp, int narg, char **arg) :
error->all(FLERR,
"Fix for fix ave/atom not computed at compatible time");
} else if (which[i] == VARIABLE) {
} else if (which[i] == ArgInfo::VARIABLE) {
int ivariable = input->variable->find(ids[i]);
if (ivariable < 0)
error->all(FLERR,"Variable name for fix ave/atom does not exist");
@ -248,19 +233,19 @@ void FixAveAtom::init()
// set indices and check validity of all computes,fixes,variables
for (int m = 0; m < nvalues; m++) {
if (which[m] == COMPUTE) {
if (which[m] == ArgInfo::COMPUTE) {
int icompute = modify->find_compute(ids[m]);
if (icompute < 0)
error->all(FLERR,"Compute ID for fix ave/atom does not exist");
value2index[m] = icompute;
} else if (which[m] == FIX) {
} else if (which[m] == ArgInfo::FIX) {
int ifix = modify->find_fix(ids[m]);
if (ifix < 0)
error->all(FLERR,"Fix ID for fix ave/atom does not exist");
value2index[m] = ifix;
} else if (which[m] == VARIABLE) {
} else if (which[m] == ArgInfo::VARIABLE) {
int ivariable = input->variable->find(ids[m]);
if (ivariable < 0)
error->all(FLERR,"Variable name for fix ave/atom does not exist");
@ -322,24 +307,24 @@ void FixAveAtom::end_of_step()
n = value2index[m];
j = argindex[m];
if (which[m] == X) {
if (which[m] == ArgInfo::X) {
double **x = atom->x;
for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit) array[i][m] += x[i][j];
} else if (which[m] == V) {
} else if (which[m] == ArgInfo::V) {
double **v = atom->v;
for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit) array[i][m] += v[i][j];
} else if (which[m] == F) {
} else if (which[m] == ArgInfo::F) {
double **f = atom->f;
for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit) array[i][m] += f[i][j];
// invoke compute if not previously invoked
} else if (which[m] == COMPUTE) {
} else if (which[m] == ArgInfo::COMPUTE) {
Compute *compute = modify->compute[n];
if (!(compute->invoked_flag & INVOKED_PERATOM)) {
compute->compute_peratom();
@ -359,7 +344,7 @@ void FixAveAtom::end_of_step()
// access fix fields, guaranteed to be ready
} else if (which[m] == FIX) {
} else if (which[m] == ArgInfo::FIX) {
if (j == 0) {
double *fix_vector = modify->fix[n]->vector_atom;
for (i = 0; i < nlocal; i++)
@ -374,7 +359,7 @@ void FixAveAtom::end_of_step()
// evaluate atom-style variable
// final argument = 1 sums result to array
} else if (which[m] == VARIABLE) {
} else if (which[m] == ArgInfo::VARIABLE) {
if (array) input->variable->compute_atom(n,igroup,&array[0][m],nvalues,1);
else input->variable->compute_atom(n,igroup,nullptr,nvalues,1);
}