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