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

@ -15,6 +15,7 @@
#include "compute_chunk_atom.h"
#include "arg_info.h"
#include "atom.h"
#include "comm.h"
#include "domain.h"
@ -39,8 +40,6 @@
using namespace LAMMPS_NS;
using namespace MathConst;
enum{BIN1D,BIN2D,BIN3D,BINSPHERE,BINCYLINDER,
TYPE,MOLECULE,COMPUTE,FIX,VARIABLE};
enum{LOWER,CENTER,UPPER,COORD};
enum{BOX,LATTICE,REDUCED};
enum{NODISCARD,MIXED,YESDISCARD};
@ -77,14 +76,14 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
if (strcmp(arg[3],"bin/1d") == 0) {
binflag = 1;
which = BIN1D;
which = ArgInfo::BIN1D;
ncoord = 1;
iarg = 4;
readdim(narg,arg,iarg,0);
iarg += 3;
} else if (strcmp(arg[3],"bin/2d") == 0) {
binflag = 1;
which = BIN2D;
which = ArgInfo::BIN2D;
ncoord = 2;
iarg = 4;
readdim(narg,arg,iarg,0);
@ -92,7 +91,7 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
iarg += 6;
} else if (strcmp(arg[3],"bin/3d") == 0) {
binflag = 1;
which = BIN3D;
which = ArgInfo::BIN3D;
ncoord = 3;
iarg = 4;
readdim(narg,arg,iarg,0);
@ -102,7 +101,7 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
} else if (strcmp(arg[3],"bin/sphere") == 0) {
binflag = 1;
which = BINSPHERE;
which = ArgInfo::BINSPHERE;
ncoord = 1;
iarg = 4;
if (iarg+6 > narg) error->all(FLERR,"Illegal compute chunk/atom command");
@ -115,7 +114,7 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
iarg += 6;
} else if (strcmp(arg[3],"bin/cylinder") == 0) {
binflag = 1;
which = BINCYLINDER;
which = ArgInfo::BINCYLINDER;
ncoord = 2;
iarg = 4;
readdim(narg,arg,iarg,0);
@ -141,38 +140,23 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
iarg += 5;
} else if (strcmp(arg[3],"type") == 0) {
which = TYPE;
which = ArgInfo::TYPE;
iarg = 4;
} else if (strcmp(arg[3],"molecule") == 0) {
which = MOLECULE;
which = ArgInfo::MOLECULE;
iarg = 4;
} else if (strstr(arg[3],"c_") == arg[3] ||
strstr(arg[3],"f_") == arg[3] ||
strstr(arg[3],"v_") == arg[3]) {
if (arg[3][0] == 'c') which = COMPUTE;
else if (arg[3][0] == 'f') which = FIX;
else if (arg[3][0] == 'v') which = VARIABLE;
iarg = 4;
} else {
ArgInfo argi(arg[3]);
int n = strlen(arg[3]);
char *suffix = new char[n];
strcpy(suffix,&arg[3][2]);
which = argi.get_type();
argindex = argi.get_dim();
cfvid = argi.copy_name();
char *ptr = strchr(suffix,'[');
if (ptr) {
if (suffix[strlen(suffix)-1] != ']')
error->all(FLERR,"Illegal compute chunk/atom command");
argindex = atoi(ptr+1);
*ptr = '\0';
} else argindex = 0;
n = strlen(suffix) + 1;
cfvid = new char[n];
strcpy(cfvid,suffix);
delete [] suffix;
} else error->all(FLERR,"Illegal compute chunk/atom command");
if ((which == ArgInfo::UNKNOWN) || (which == ArgInfo::NONE)
|| (argindex > 1))
error->all(FLERR,"Illegal compute chunk/atom command");
}
// optional args
@ -291,8 +275,8 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
if (scaleflag == REDUCED) nchunkflag = ONCE;
else nchunkflag = EVERY;
}
if (which == TYPE) nchunkflag = ONCE;
if (which == MOLECULE) {
if (which == ArgInfo::TYPE) nchunkflag = ONCE;
if (which == ArgInfo::MOLECULE) {
if (regionflag) nchunkflag = EVERY;
else nchunkflag = ONCE;
}
@ -306,31 +290,31 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
// error checks
if (which == MOLECULE && !atom->molecule_flag)
if (which == ArgInfo::MOLECULE && !atom->molecule_flag)
error->all(FLERR,"Compute chunk/atom molecule for non-molecular system");
if (!binflag && discard == MIXED)
error->all(FLERR,"Compute chunk/atom without bins "
"cannot use discard mixed");
if (which == BIN1D && delta[0] <= 0.0)
if (which == ArgInfo::BIN1D && delta[0] <= 0.0)
error->all(FLERR,"Illegal compute chunk/atom command");
if (which == BIN2D && (delta[0] <= 0.0 || delta[1] <= 0.0))
if (which == ArgInfo::BIN2D && (delta[0] <= 0.0 || delta[1] <= 0.0))
error->all(FLERR,"Illegal compute chunk/atom command");
if (which == BIN2D && (dim[0] == dim[1]))
if (which == ArgInfo::BIN2D && (dim[0] == dim[1]))
error->all(FLERR,"Illegal compute chunk/atom command");
if (which == BIN3D &&
if (which == ArgInfo::BIN3D &&
(delta[0] <= 0.0 || delta[1] <= 0.0 || delta[2] <= 0.0))
error->all(FLERR,"Illegal compute chunk/atom command");
if (which == BIN3D &&
if (which == ArgInfo::BIN3D &&
(dim[0] == dim[1] || dim[1] == dim[2] || dim[0] == dim[2]))
error->all(FLERR,"Illegal compute chunk/atom command");
if (which == BINSPHERE) {
if (which == ArgInfo::BINSPHERE) {
if (domain->dimension == 2 && sorigin_user[2] != 0.0)
error->all(FLERR,"Compute chunk/atom sphere z origin must be 0.0 for 2d");
if (sradmin_user < 0.0 || sradmin_user >= sradmax_user || nsbin < 1)
error->all(FLERR,"Illegal compute chunk/atom command");
}
if (which == BINCYLINDER) {
if (which == ArgInfo::BINCYLINDER) {
if (delta[0] <= 0.0)
error->all(FLERR,"Illegal compute chunk/atom command");
if (domain->dimension == 2 && dim[0] != 2)
@ -339,7 +323,7 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
error->all(FLERR,"Illegal compute chunk/atom command");
}
if (which == COMPUTE) {
if (which == ArgInfo::COMPUTE) {
int icompute = modify->find_compute(cfvid);
if (icompute < 0)
error->all(FLERR,"Compute ID for compute chunk /atom does not exist");
@ -360,7 +344,7 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
"accessed out-of-range");
}
if (which == FIX) {
if (which == ArgInfo::FIX) {
int ifix = modify->find_fix(cfvid);
if (ifix < 0)
error->all(FLERR,"Fix ID for compute chunk/atom does not exist");
@ -377,7 +361,7 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
error->all(FLERR,"Compute chunk/atom fix array is accessed out-of-range");
}
if (which == VARIABLE) {
if (which == ArgInfo::VARIABLE) {
int ivariable = input->variable->find(cfvid);
if (ivariable < 0)
error->all(FLERR,"Variable name for compute chunk/atom does not exist");
@ -404,11 +388,11 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
if (binflag) {
double scale;
if (which == BIN1D || which == BIN2D || which == BIN3D ||
which == BINCYLINDER) {
if (which == BIN1D || which == BINCYLINDER) ndim = 1;
if (which == BIN2D) ndim = 2;
if (which == BIN3D) ndim = 3;
if (which == ArgInfo::BIN1D || which == ArgInfo::BIN2D
|| which == ArgInfo::BIN3D || which == ArgInfo::BINCYLINDER) {
if (which == ArgInfo::BIN1D || which == ArgInfo::BINCYLINDER) ndim = 1;
if (which == ArgInfo::BIN2D) ndim = 2;
if (which == ArgInfo::BIN3D) ndim = 3;
for (int idim = 0; idim < ndim; idim++) {
if (dim[idim] == 0) scale = xscale;
else if (dim[idim] == 1) scale = yscale;
@ -419,13 +403,13 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
if (minflag[idim] == COORD) minvalue[idim] *= scale;
if (maxflag[idim] == COORD) maxvalue[idim] *= scale;
}
} else if (which == BINSPHERE) {
} else if (which == ArgInfo::BINSPHERE) {
sorigin_user[0] *= xscale;
sorigin_user[1] *= yscale;
sorigin_user[2] *= zscale;
sradmin_user *= xscale; // radii are scaled by xscale
sradmax_user *= xscale;
} else if (which == BINCYLINDER) {
} else if (which == ArgInfo::BINCYLINDER) {
if (dim[0] == 0) {
corigin_user[cdim1] *= yscale;
corigin_user[cdim2] *= zscale;
@ -462,7 +446,7 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
// computeflag = 1 if this compute might invoke another compute
// during assign_chunk_ids()
if (which == COMPUTE || which == FIX || which == VARIABLE) computeflag = 1;
if (which == ArgInfo::COMPUTE || which == ArgInfo::FIX || which == ArgInfo::VARIABLE) computeflag = 1;
else computeflag = 0;
// other initializations
@ -482,7 +466,7 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
lockcount = 0;
lockfix = nullptr;
if (which == MOLECULE) molcheck = 1;
if (which == ArgInfo::MOLECULE) molcheck = 1;
else molcheck = 0;
}
@ -524,17 +508,17 @@ void ComputeChunkAtom::init()
// set compute,fix,variable
if (which == COMPUTE) {
if (which == ArgInfo::COMPUTE) {
int icompute = modify->find_compute(cfvid);
if (icompute < 0)
error->all(FLERR,"Compute ID for compute chunk/atom does not exist");
cchunk = modify->compute[icompute];
} else if (which == FIX) {
} else if (which == ArgInfo::FIX) {
int ifix = modify->find_fix(cfvid);
if (ifix < 0)
error->all(FLERR,"Fix ID for compute chunk/atom does not exist");
fchunk = modify->fix[ifix];
} else if (which == VARIABLE) {
} else if (which == ArgInfo::VARIABLE) {
int ivariable = input->variable->find(cfvid);
if (ivariable < 0)
error->all(FLERR,"Variable name for compute chunk/atom does not exist");
@ -544,7 +528,7 @@ void ComputeChunkAtom::init()
// for style MOLECULE, check that no mol IDs exceed MAXSMALLINT
// don't worry about group or optional region
if (which == MOLECULE) {
if (which == ArgInfo::MOLECULE) {
tagint *molecule = atom->molecule;
int nlocal = atom->nlocal;
tagint maxone = -1;
@ -835,10 +819,11 @@ int ComputeChunkAtom::setup_chunks()
// IDs are needed to scan for max ID and for compress()
if (binflag) {
if (which == BIN1D || which == BIN2D || which == BIN3D)
if (which == ArgInfo::BIN1D || which == ArgInfo::BIN2D
|| which == ArgInfo::BIN3D)
nchunk = setup_xyz_bins();
else if (which == BINSPHERE) nchunk = setup_sphere_bins();
else if (which == BINCYLINDER) nchunk = setup_cylinder_bins();
else if (which == ArgInfo::BINSPHERE) nchunk = setup_sphere_bins();
else if (which == ArgInfo::BINCYLINDER) nchunk = setup_cylinder_bins();
bin_volumes();
} else {
chunk_volume_scalar = domain->xprd * domain->yprd;
@ -850,7 +835,7 @@ int ComputeChunkAtom::setup_chunks()
// set nchunk for chunk styles other than binning
// for styles other than TYPE, scan for max ID
if (which == TYPE) nchunk = atom->ntypes;
if (which == ArgInfo::TYPE) nchunk = atom->ntypes;
else if (!binflag) {
int nlocal = atom->nlocal;
@ -937,27 +922,27 @@ void ComputeChunkAtom::assign_chunk_ids()
// binning styles apply discard rule, others do not yet
if (binflag) {
if (which == BIN1D) atom2bin1d();
else if (which == BIN2D) atom2bin2d();
else if (which == BIN3D) atom2bin3d();
else if (which == BINSPHERE) atom2binsphere();
else if (which == BINCYLINDER) atom2bincylinder();
if (which == ArgInfo::BIN1D) atom2bin1d();
else if (which == ArgInfo::BIN2D) atom2bin2d();
else if (which == ArgInfo::BIN3D) atom2bin3d();
else if (which == ArgInfo::BINSPHERE) atom2binsphere();
else if (which == ArgInfo::BINCYLINDER) atom2bincylinder();
} else if (which == TYPE) {
} else if (which == ArgInfo::TYPE) {
int *type = atom->type;
for (i = 0; i < nlocal; i++) {
if (exclude[i]) continue;
ichunk[i] = type[i];
}
} else if (which == MOLECULE) {
} else if (which == ArgInfo::MOLECULE) {
tagint *molecule = atom->molecule;
for (i = 0; i < nlocal; i++) {
if (exclude[i]) continue;
ichunk[i] = static_cast<int> (molecule[i]);
}
} else if (which == COMPUTE) {
} else if (which == ArgInfo::COMPUTE) {
if (!(cchunk->invoked_flag & INVOKED_PERATOM)) {
cchunk->compute_peratom();
cchunk->invoked_flag |= INVOKED_PERATOM;
@ -978,7 +963,7 @@ void ComputeChunkAtom::assign_chunk_ids()
}
}
} else if (which == FIX) {
} else if (which == ArgInfo::FIX) {
if (update->ntimestep % fchunk->peratom_freq)
error->all(FLERR,"Fix used in compute chunk/atom not "
"computed at compatible time");
@ -998,7 +983,7 @@ void ComputeChunkAtom::assign_chunk_ids()
}
}
} else if (which == VARIABLE) {
} else if (which == ArgInfo::VARIABLE) {
if (atom->nmax > maxvar) {
maxvar = atom->nmax;
memory->destroy(varatom);
@ -1428,7 +1413,8 @@ int ComputeChunkAtom::setup_cylinder_bins()
void ComputeChunkAtom::bin_volumes()
{
if (which == BIN1D || which == BIN2D || which == BIN3D) {
if (which == ArgInfo::BIN1D || which == ArgInfo::BIN2D
|| which == ArgInfo::BIN3D) {
if (domain->dimension == 3)
chunk_volume_scalar = domain->xprd * domain->yprd * domain->zprd;
else chunk_volume_scalar = domain->xprd * domain->yprd;
@ -1438,7 +1424,7 @@ void ComputeChunkAtom::bin_volumes()
for (int m = 0; m < ndim; m++)
chunk_volume_scalar *= delta[m]/prd[dim[m]];
} else if (which == BINSPHERE) {
} else if (which == ArgInfo::BINSPHERE) {
memory->destroy(chunk_volume_vec);
memory->create(chunk_volume_vec,nchunk,"chunk/atom:chunk_volume_vec");
double rlo,rhi,vollo,volhi;
@ -1451,7 +1437,7 @@ void ComputeChunkAtom::bin_volumes()
chunk_volume_vec[i] = volhi - vollo;
}
} else if (which == BINCYLINDER) {
} else if (which == ArgInfo::BINCYLINDER) {
memory->destroy(chunk_volume_vec);
memory->create(chunk_volume_vec,nchunk,"chunk/atom:chunk_volume_vec");