translated the final compute style to use ArgInfo

This commit is contained in:
Axel Kohlmeyer
2021-02-01 08:01:11 -05:00
parent 26ea789834
commit 6d2d3cc33b

View File

@ -13,6 +13,7 @@
#include "compute_global_atom.h" #include "compute_global_atom.h"
#include "arg_info.h"
#include "atom.h" #include "atom.h"
#include "error.h" #include "error.h"
#include "fix.h" #include "fix.h"
@ -22,11 +23,8 @@
#include "update.h" #include "update.h"
#include "variable.h" #include "variable.h"
#include <cstring>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
enum{COMPUTE,FIX,VARIABLE};
enum{VECTOR,ARRAY}; enum{VECTOR,ARRAY};
#define INVOKED_VECTOR 2 #define INVOKED_VECTOR 2
@ -49,31 +47,15 @@ ComputeGlobalAtom::ComputeGlobalAtom(LAMMPS *lmp, int narg, char **arg) :
// process index arg // process index arg
int iarg = 3; int iarg = 3;
ArgInfo argi(arg[iarg]);
if (strncmp(arg[iarg],"c_",2) == 0 || whichref = argi.get_type();
strncmp(arg[iarg],"f_",2) == 0 || indexref = argi.get_index1();
strncmp(arg[iarg],"v_",2) == 0) { idref = argi.copy_name();
if (arg[iarg][0] == 'c') whichref = COMPUTE;
else if (arg[iarg][0] == 'f') whichref = FIX;
else if (arg[iarg][0] == 'v') whichref = VARIABLE;
int n = strlen(arg[iarg]); if ((whichref == ArgInfo::UNKNOWN) || (which[nvalues] == ArgInfo::NONE)
char *suffix = new char[n]; || (argi.get_dim() > 1))
strcpy(suffix,&arg[iarg][2]);
char *ptr = strchr(suffix,'[');
if (ptr) {
if (suffix[strlen(suffix)-1] != ']')
error->all(FLERR,"Illegal compute global/atom command"); error->all(FLERR,"Illegal compute global/atom command");
indexref = atoi(ptr+1);
*ptr = '\0';
} else indexref = 0;
n = strlen(suffix) + 1;
idref = new char[n];
strcpy(idref,suffix);
delete [] suffix;
} else error->all(FLERR,"Illegal compute global/atom command");
iarg++; iarg++;
@ -94,37 +76,18 @@ ComputeGlobalAtom::ComputeGlobalAtom(LAMMPS *lmp, int narg, char **arg) :
value2index = new int[nargnew]; value2index = new int[nargnew];
nvalues = 0; nvalues = 0;
iarg = 0; for (iarg = 0; iarg < nargnew; iarg++) {
while (iarg < nargnew) { ArgInfo argi(arg[iarg]);
ids[nvalues] = nullptr;
if (strncmp(arg[iarg],"c_",2) == 0 ||
strncmp(arg[iarg],"f_",2) == 0 ||
strncmp(arg[iarg],"v_",2) == 0) {
if (arg[iarg][0] == 'c') which[nvalues] = COMPUTE;
else if (arg[iarg][0] == 'f') which[nvalues] = FIX;
else if (arg[iarg][0] == 'v') which[nvalues] = VARIABLE;
int n = strlen(arg[iarg]); which[nvalues] = argi.get_type();
char *suffix = new char[n]; argindex[nvalues] = argi.get_index1();
strcpy(suffix,&arg[iarg][2]); ids[nvalues] = argi.copy_name();
char *ptr = strchr(suffix,'['); if ((which[nvalues] == ArgInfo::UNKNOWN) || (which[nvalues] == ArgInfo::NONE)
if (ptr) { || (argi.get_dim() > 1))
if (suffix[strlen(suffix)-1] != ']') error->all(FLERR,"Illegal compute slice command");
error->all(FLERR,"Illegal compute global/atom command");
argindex[nvalues] = atoi(ptr+1);
*ptr = '\0';
} else argindex[nvalues] = 0;
n = strlen(suffix) + 1;
ids[nvalues] = new char[n];
strcpy(ids[nvalues],suffix);
nvalues++; nvalues++;
delete [] suffix;
} else error->all(FLERR,"Illegal compute global/atom command");
iarg++;
} }
// if wildcard expansion occurred, free earg memory from expand_args() // if wildcard expansion occurred, free earg memory from expand_args()
@ -136,7 +99,7 @@ ComputeGlobalAtom::ComputeGlobalAtom(LAMMPS *lmp, int narg, char **arg) :
// setup and error check both index arg and values // setup and error check both index arg and values
if (whichref == COMPUTE) { if (whichref == ArgInfo::COMPUTE) {
int icompute = modify->find_compute(idref); int icompute = modify->find_compute(idref);
if (icompute < 0) if (icompute < 0)
error->all(FLERR,"Compute ID for compute global/atom does not exist"); error->all(FLERR,"Compute ID for compute global/atom does not exist");
@ -155,7 +118,7 @@ ComputeGlobalAtom::ComputeGlobalAtom(LAMMPS *lmp, int narg, char **arg) :
error->all(FLERR, error->all(FLERR,
"Compute global/atom compute array is accessed out-of-range"); "Compute global/atom compute array is accessed out-of-range");
} else if (whichref == FIX) { } else if (whichref == ArgInfo::FIX) {
int ifix = modify->find_fix(idref); int ifix = modify->find_fix(idref);
if (ifix < 0) if (ifix < 0)
error->all(FLERR,"Fix ID for compute global/atom does not exist"); error->all(FLERR,"Fix ID for compute global/atom does not exist");
@ -173,7 +136,7 @@ ComputeGlobalAtom::ComputeGlobalAtom(LAMMPS *lmp, int narg, char **arg) :
error->all(FLERR, error->all(FLERR,
"Compute global/atom fix array is accessed out-of-range"); "Compute global/atom fix array is accessed out-of-range");
} else if (whichref == VARIABLE) { } else if (whichref == ArgInfo::VARIABLE) {
int ivariable = input->variable->find(idref); int ivariable = input->variable->find(idref);
if (ivariable < 0) if (ivariable < 0)
error->all(FLERR,"Variable name for compute global/atom does not exist"); error->all(FLERR,"Variable name for compute global/atom does not exist");
@ -183,7 +146,7 @@ ComputeGlobalAtom::ComputeGlobalAtom(LAMMPS *lmp, int narg, char **arg) :
} }
for (int i = 0; i < nvalues; i++) { for (int i = 0; i < nvalues; i++) {
if (which[i] == COMPUTE) { if (which[i] == ArgInfo::COMPUTE) {
int icompute = modify->find_compute(ids[i]); int icompute = modify->find_compute(ids[i]);
if (icompute < 0) if (icompute < 0)
error->all(FLERR,"Compute ID for compute global/atom does not exist"); error->all(FLERR,"Compute ID for compute global/atom does not exist");
@ -200,7 +163,7 @@ ComputeGlobalAtom::ComputeGlobalAtom(LAMMPS *lmp, int narg, char **arg) :
"accessed out-of-range"); "accessed out-of-range");
} }
} else if (which[i] == FIX) { } else if (which[i] == ArgInfo::FIX) {
int ifix = modify->find_fix(ids[i]); int ifix = modify->find_fix(ids[i]);
if (ifix < 0) if (ifix < 0)
error->all(FLERR,"Fix ID for compute global/atom does not exist"); error->all(FLERR,"Fix ID for compute global/atom does not exist");
@ -217,7 +180,7 @@ ComputeGlobalAtom::ComputeGlobalAtom(LAMMPS *lmp, int narg, char **arg) :
"accessed out-of-range"); "accessed out-of-range");
} }
} else if (which[i] == VARIABLE) { } else if (which[i] == ArgInfo::VARIABLE) {
int ivariable = input->variable->find(ids[i]); int ivariable = input->variable->find(ids[i]);
if (ivariable < 0) if (ivariable < 0)
error->all(FLERR,"Variable name for compute global/atom " error->all(FLERR,"Variable name for compute global/atom "
@ -263,17 +226,17 @@ void ComputeGlobalAtom::init()
{ {
// set indices of all computes,fixes,variables // set indices of all computes,fixes,variables
if (whichref == COMPUTE) { if (whichref == ArgInfo::COMPUTE) {
int icompute = modify->find_compute(idref); int icompute = modify->find_compute(idref);
if (icompute < 0) if (icompute < 0)
error->all(FLERR,"Compute ID for compute global/atom does not exist"); error->all(FLERR,"Compute ID for compute global/atom does not exist");
ref2index = icompute; ref2index = icompute;
} else if (whichref == FIX) { } else if (whichref == ArgInfo::FIX) {
int ifix = modify->find_fix(idref); int ifix = modify->find_fix(idref);
if (ifix < 0) if (ifix < 0)
error->all(FLERR,"Fix ID for compute global/atom does not exist"); error->all(FLERR,"Fix ID for compute global/atom does not exist");
ref2index = ifix; ref2index = ifix;
} else if (whichref == VARIABLE) { } else if (whichref == ArgInfo::VARIABLE) {
int ivariable = input->variable->find(idref); int ivariable = input->variable->find(idref);
if (ivariable < 0) if (ivariable < 0)
error->all(FLERR,"Variable name for compute global/atom does not exist"); error->all(FLERR,"Variable name for compute global/atom does not exist");
@ -281,19 +244,19 @@ void ComputeGlobalAtom::init()
} }
for (int m = 0; m < nvalues; m++) { for (int m = 0; m < nvalues; m++) {
if (which[m] == COMPUTE) { if (which[m] == ArgInfo::COMPUTE) {
int icompute = modify->find_compute(ids[m]); int icompute = modify->find_compute(ids[m]);
if (icompute < 0) if (icompute < 0)
error->all(FLERR,"Compute ID for compute global/atom does not exist"); error->all(FLERR,"Compute ID for compute global/atom does not exist");
value2index[m] = icompute; value2index[m] = icompute;
} else if (which[m] == FIX) { } else if (which[m] == ArgInfo::FIX) {
int ifix = modify->find_fix(ids[m]); int ifix = modify->find_fix(ids[m]);
if (ifix < 0) if (ifix < 0)
error->all(FLERR,"Fix ID for compute global/atom does not exist"); error->all(FLERR,"Fix ID for compute global/atom does not exist");
value2index[m] = ifix; value2index[m] = ifix;
} else if (which[m] == VARIABLE) { } else if (which[m] == ArgInfo::VARIABLE) {
int ivariable = input->variable->find(ids[m]); int ivariable = input->variable->find(ids[m]);
if (ivariable < 0) if (ivariable < 0)
error->all(FLERR,"Variable name for compute global/atom " error->all(FLERR,"Variable name for compute global/atom "
@ -317,7 +280,7 @@ void ComputeGlobalAtom::compute_peratom()
nmax = atom->nmax; nmax = atom->nmax;
memory->destroy(indices); memory->destroy(indices);
memory->create(indices,nmax,"global/atom:indices"); memory->create(indices,nmax,"global/atom:indices");
if (whichref == VARIABLE) { if (whichref == ArgInfo::VARIABLE) {
memory->destroy(varatom); memory->destroy(varatom);
memory->create(varatom,nmax,"global/atom:varatom"); memory->create(varatom,nmax,"global/atom:varatom");
} }
@ -337,7 +300,7 @@ void ComputeGlobalAtom::compute_peratom()
int *mask = atom->mask; int *mask = atom->mask;
int nlocal = atom->nlocal; int nlocal = atom->nlocal;
if (whichref == COMPUTE) { if (whichref == ArgInfo::COMPUTE) {
Compute *compute = modify->compute[ref2index]; Compute *compute = modify->compute[ref2index];
if (!(compute->invoked_flag & INVOKED_PERATOM)) { if (!(compute->invoked_flag & INVOKED_PERATOM)) {
@ -358,7 +321,7 @@ void ComputeGlobalAtom::compute_peratom()
indices[i] = static_cast<int> (compute_array[i][im1]) - 1; indices[i] = static_cast<int> (compute_array[i][im1]) - 1;
} }
} else if (whichref == FIX) { } else if (whichref == ArgInfo::FIX) {
if (update->ntimestep % modify->fix[ref2index]->peratom_freq) if (update->ntimestep % modify->fix[ref2index]->peratom_freq)
error->all(FLERR,"Fix used in compute global/atom not " error->all(FLERR,"Fix used in compute global/atom not "
"computed at compatible time"); "computed at compatible time");
@ -377,7 +340,7 @@ void ComputeGlobalAtom::compute_peratom()
indices[i] = static_cast<int> (fix_array[i][im1]) - 1; indices[i] = static_cast<int> (fix_array[i][im1]) - 1;
} }
} else if (whichref == VARIABLE) { } else if (whichref == ArgInfo::VARIABLE) {
input->variable->compute_atom(ref2index,igroup,varatom,1,0); input->variable->compute_atom(ref2index,igroup,varatom,1,0);
for (i = 0; i < nlocal; i++) for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit) if (mask[i] & groupbit)
@ -394,7 +357,7 @@ void ComputeGlobalAtom::compute_peratom()
int vmax; int vmax;
double *source; double *source;
if (which[m] == COMPUTE) { if (which[m] == ArgInfo::COMPUTE) {
Compute *compute = modify->compute[value2index[m]]; Compute *compute = modify->compute[value2index[m]];
if (!(compute->invoked_flag & INVOKED_VECTOR)) { if (!(compute->invoked_flag & INVOKED_VECTOR)) {
@ -405,7 +368,7 @@ void ComputeGlobalAtom::compute_peratom()
source = compute->vector; source = compute->vector;
vmax = compute->size_vector; vmax = compute->size_vector;
} else if (which[m] == FIX) { } else if (which[m] == ArgInfo::FIX) {
if (update->ntimestep % modify->fix[value2index[m]]->peratom_freq) if (update->ntimestep % modify->fix[value2index[m]]->peratom_freq)
error->all(FLERR,"Fix used in compute global/atom not " error->all(FLERR,"Fix used in compute global/atom not "
"computed at compatible time"); "computed at compatible time");
@ -423,7 +386,7 @@ void ComputeGlobalAtom::compute_peratom()
source = vecglobal; source = vecglobal;
} else if (which[m] == VARIABLE) { } else if (which[m] == ArgInfo::VARIABLE) {
vmax = input->variable->compute_vector(value2index[m],&source); vmax = input->variable->compute_vector(value2index[m],&source);
} }
@ -452,7 +415,7 @@ void ComputeGlobalAtom::compute_peratom()
double *source; double *source;
int col = argindex[m] - 1; int col = argindex[m] - 1;
if (which[m] == COMPUTE) { if (which[m] == ArgInfo::COMPUTE) {
Compute *compute = modify->compute[value2index[m]]; Compute *compute = modify->compute[value2index[m]];
if (!(compute->invoked_flag & INVOKED_ARRAY)) { if (!(compute->invoked_flag & INVOKED_ARRAY)) {
@ -474,7 +437,7 @@ void ComputeGlobalAtom::compute_peratom()
source = vecglobal; source = vecglobal;
} else if (which[m] == FIX) { } else if (which[m] == ArgInfo::FIX) {
if (update->ntimestep % modify->fix[value2index[m]]->peratom_freq) if (update->ntimestep % modify->fix[value2index[m]]->peratom_freq)
error->all(FLERR,"Fix used in compute global/atom not " error->all(FLERR,"Fix used in compute global/atom not "
"computed at compatible time"); "computed at compatible time");
@ -492,7 +455,7 @@ void ComputeGlobalAtom::compute_peratom()
source = vecglobal; source = vecglobal;
} else if (which[m] == VARIABLE) { } else if (which[m] == ArgInfo::VARIABLE) {
vmax = input->variable->compute_vector(value2index[m],&source); vmax = input->variable->compute_vector(value2index[m],&source);
} }