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

View File

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