convert some more files

This commit is contained in:
Axel Kohlmeyer
2021-01-31 21:47:55 -05:00
parent 03136ed3e3
commit 0f49ce81c7
6 changed files with 134 additions and 212 deletions

View File

@ -13,6 +13,7 @@
#include "compute_chunk_spread_atom.h" #include "compute_chunk_spread_atom.h"
#include "arg_info.h"
#include "atom.h" #include "atom.h"
#include "compute.h" #include "compute.h"
#include "compute_chunk_atom.h" #include "compute_chunk_atom.h"
@ -22,12 +23,8 @@
#include "modify.h" #include "modify.h"
#include "update.h" #include "update.h"
#include <cstring>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
enum{COMPUTE,FIX};
#define INVOKED_VECTOR 2 #define INVOKED_VECTOR 2
#define INVOKED_ARRAY 4 #define INVOKED_ARRAY 4
#define INVOKED_PERATOM 8 #define INVOKED_PERATOM 8
@ -66,36 +63,20 @@ ComputeChunkSpreadAtom(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) {
ids[nvalues] = nullptr; ids[nvalues] = nullptr;
if (strncmp(arg[iarg],"c_",2) == 0 || ArgInfo argi(arg[iarg], ArgInfo::COMPUTE|ArgInfo::FIX);
strncmp(arg[iarg],"f_",2) == 0) {
if (arg[iarg][0] == 'c') which[nvalues] = COMPUTE;
else if (arg[iarg][0] == 'f') which[nvalues] = FIX;
int n = strlen(arg[iarg]); which[nvalues] = argi.get_type();
char *suffix = new char[n]; argindex[nvalues] = argi.get_dim();
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) { || (argindex[nvalues] > 1))
if (suffix[strlen(suffix)-1] != ']') error->all(FLERR,"Illegal compute chunk/spread/atom command");
error->all(FLERR,"Illegal compute chunk/spread/atom command");
argindex[nvalues] = atoi(ptr+1);
*ptr = '\0';
} else argindex[nvalues] = 0;
n = strlen(suffix) + 1; nvalues++;
ids[nvalues] = new char[n];
strcpy(ids[nvalues],suffix);
nvalues++;
delete [] suffix;
} else error->all(FLERR,"Illegal compute chunk/spread/atom command");
iarg++;
} }
// if wildcard expansion occurred, free earg memory from expand_args() // if wildcard expansion occurred, free earg memory from expand_args()
@ -110,7 +91,7 @@ ComputeChunkSpreadAtom(LAMMPS *lmp, int narg, char **arg) :
// for fix, assume a global vector or array is per-chunk data // for fix, assume a global vector or array is per-chunk data
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 chunk/spread/atom " error->all(FLERR,"Compute ID for compute chunk/spread/atom "
@ -133,7 +114,7 @@ ComputeChunkSpreadAtom(LAMMPS *lmp, int narg, char **arg) :
"is accessed out-of-range"); "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 compute chunk/spread/atom does not exist"); error->all(FLERR,"Fix ID for compute chunk/spread/atom does not exist");
@ -190,14 +171,14 @@ void ComputeChunkSpreadAtom::init()
// set indices of all computes,fixes,variables // set indices 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 compute chunk/spread/atom " error->all(FLERR,"Compute ID for compute chunk/spread/atom "
"does not exist"); "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 chunk/spread/atom does not exist"); error->all(FLERR,"Fix ID for compute chunk/spread/atom does not exist");
@ -271,7 +252,7 @@ void ComputeChunkSpreadAtom::compute_peratom()
// invoke compute if not previously invoked // invoke compute if not previously invoked
if (which[m] == COMPUTE) { if (which[m] == ArgInfo::COMPUTE) {
Compute *compute = modify->compute[n]; Compute *compute = modify->compute[n];
if (argindex[m] == 0) { if (argindex[m] == 0) {
@ -308,7 +289,7 @@ void ComputeChunkSpreadAtom::compute_peratom()
// are assuming the fix global vector/array is per-chunk data // are assuming the fix global vector/array is per-chunk data
// check if index exceeds fix output length/rows // check if index exceeds fix output length/rows
} else if (which[m] == FIX) { } else if (which[m] == ArgInfo::FIX) {
Fix *fix = modify->fix[n]; Fix *fix = modify->fix[n];
if (update->ntimestep % fix->global_freq) if (update->ntimestep % fix->global_freq)
error->all(FLERR,"Fix used in compute chunk/spread/atom not " error->all(FLERR,"Fix used in compute chunk/spread/atom not "

View File

@ -13,26 +13,20 @@
#include "compute_reduce.h" #include "compute_reduce.h"
#include <cstring> #include "arg_info.h"
#include "atom.h" #include "atom.h"
#include "update.h"
#include "domain.h" #include "domain.h"
#include "modify.h" #include "error.h"
#include "fix.h" #include "fix.h"
#include "group.h" #include "group.h"
#include "input.h" #include "input.h"
#include "variable.h"
#include "memory.h" #include "memory.h"
#include "error.h" #include "modify.h"
#include "update.h"
#include "variable.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
enum{SUM,SUMSQ,MINN,MAXX,AVE,AVESQ}; // also in ComputeReduceRegion
enum{UNKNOWN=-1,X,V,F,COMPUTE,FIX,VARIABLE};
enum{PERATOM,LOCAL};
#define INVOKED_VECTOR 2 #define INVOKED_VECTOR 2
#define INVOKED_ARRAY 4 #define INVOKED_ARRAY 4
#define INVOKED_PERATOM 8 #define INVOKED_PERATOM 8
@ -92,7 +86,7 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) :
ids = new char*[nargnew]; ids = new char*[nargnew];
value2index = new int[nargnew]; value2index = new int[nargnew];
for (int i=0; i < nargnew; ++i) { for (int i=0; i < nargnew; ++i) {
which[i] = argindex[i] = flavor[i] = value2index[i] = UNKNOWN; which[i] = argindex[i] = flavor[i] = value2index[i] = ArgInfo::UNKNOWN;
ids[i] = nullptr; ids[i] = nullptr;
} }
nvalues = 0; nvalues = 0;
@ -102,61 +96,49 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) :
ids[nvalues] = nullptr; ids[nvalues] = nullptr;
if (strcmp(arg[iarg],"x") == 0) { if (strcmp(arg[iarg],"x") == 0) {
which[nvalues] = X; which[nvalues] = ArgInfo::X;
argindex[nvalues++] = 0; argindex[nvalues++] = 0;
} else if (strcmp(arg[iarg],"y") == 0) { } else if (strcmp(arg[iarg],"y") == 0) {
which[nvalues] = X; which[nvalues] = ArgInfo::X;
argindex[nvalues++] = 1; argindex[nvalues++] = 1;
} else if (strcmp(arg[iarg],"z") == 0) { } else if (strcmp(arg[iarg],"z") == 0) {
which[nvalues] = X; which[nvalues] = ArgInfo::X;
argindex[nvalues++] = 2; argindex[nvalues++] = 2;
} else if (strcmp(arg[iarg],"vx") == 0) { } else if (strcmp(arg[iarg],"vx") == 0) {
which[nvalues] = V; which[nvalues] = ArgInfo::V;
argindex[nvalues++] = 0; argindex[nvalues++] = 0;
} else if (strcmp(arg[iarg],"vy") == 0) { } else if (strcmp(arg[iarg],"vy") == 0) {
which[nvalues] = V; which[nvalues] = ArgInfo::V;
argindex[nvalues++] = 1; argindex[nvalues++] = 1;
} else if (strcmp(arg[iarg],"vz") == 0) { } else if (strcmp(arg[iarg],"vz") == 0) {
which[nvalues] = V; which[nvalues] = ArgInfo::V;
argindex[nvalues++] = 2; argindex[nvalues++] = 2;
} else if (strcmp(arg[iarg],"fx") == 0) { } else if (strcmp(arg[iarg],"fx") == 0) {
which[nvalues] = F; which[nvalues] = ArgInfo::F;
argindex[nvalues++] = 0; argindex[nvalues++] = 0;
} else if (strcmp(arg[iarg],"fy") == 0) { } else if (strcmp(arg[iarg],"fy") == 0) {
which[nvalues] = F; which[nvalues] = ArgInfo::F;
argindex[nvalues++] = 1; argindex[nvalues++] = 1;
} else if (strcmp(arg[iarg],"fz") == 0) { } else if (strcmp(arg[iarg],"fz") == 0) {
which[nvalues] = F; which[nvalues] = ArgInfo::F;
argindex[nvalues++] = 2; argindex[nvalues++] = 2;
} else if (strncmp(arg[iarg],"c_",2) == 0 || } else {
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]); ArgInfo argi(arg[iarg]);
char *suffix = new char[n];
strcpy(suffix,&arg[iarg][2]);
char *ptr = strchr(suffix,'['); which[nvalues] = argi.get_type();
if (ptr) { argindex[nvalues] = argi.get_dim();
if (suffix[strlen(suffix)-1] != ']') ids[nvalues] = argi.copy_name();
error->all(FLERR,"Illegal compute reduce command");
argindex[nvalues] = atoi(ptr+1);
*ptr = '\0';
} else argindex[nvalues] = 0;
n = strlen(suffix) + 1; if ((which[nvalues] == ArgInfo::UNKNOWN) || (argindex[nvalues] > 1))
ids[nvalues] = new char[n]; error->all(FLERR,"Illegal compute reduce command");
strcpy(ids[nvalues],suffix);
if (which[nvalues] == ArgInfo::NONE) break;
nvalues++; nvalues++;
delete [] suffix; }
} else break;
iarg++; iarg++;
} }
@ -203,10 +185,10 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) :
// setup and error check // setup and error check
for (int i = 0; i < nvalues; i++) { for (int i = 0; i < nvalues; i++) {
if (which[i] == X || which[i] == V || which[i] == F) if (which[i] == ArgInfo::X || which[i] == ArgInfo::V || which[i] == ArgInfo::F)
flavor[i] = PERATOM; flavor[i] = PERATOM;
else if (which[i] == COMPUTE) { else 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 reduce does not exist"); error->all(FLERR,"Compute ID for compute reduce does not exist");
@ -239,7 +221,7 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) :
} else error->all(FLERR, } else error->all(FLERR,
"Compute reduce compute calculates global values"); "Compute reduce compute calculates global values");
} 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 reduce does not exist"); error->all(FLERR,"Fix ID for compute reduce does not exist");
@ -269,7 +251,7 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) :
error->all(FLERR,"Compute reduce fix array is accessed out-of-range"); error->all(FLERR,"Compute reduce fix array is accessed out-of-range");
} else error->all(FLERR,"Compute reduce fix calculates global values"); } else error->all(FLERR,"Compute reduce fix calculates global values");
} 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 reduce does not exist"); error->all(FLERR,"Variable name for compute reduce does not exist");
@ -330,25 +312,25 @@ void ComputeReduce::init()
// set indices of all computes,fixes,variables // set indices 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 compute reduce does not exist"); error->all(FLERR,"Compute ID for compute reduce 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 reduce does not exist"); error->all(FLERR,"Fix ID for compute reduce 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 reduce does not exist"); error->all(FLERR,"Variable name for compute reduce does not exist");
value2index[m] = ivariable; value2index[m] = ivariable;
} else value2index[m] = UNKNOWN; } else value2index[m] = ArgInfo::UNKNOWN;
} }
// set index and check validity of region // set index and check validity of region
@ -475,7 +457,7 @@ double ComputeReduce::compute_one(int m, int flag)
// initialization in case it has not yet been run, e.g. when // initialization in case it has not yet been run, e.g. when
// the compute was invoked right after it has been created // the compute was invoked right after it has been created
if (vidx == UNKNOWN) { if (vidx == ArgInfo::UNKNOWN) {
init(); init();
vidx = value2index[m]; vidx = value2index[m];
} }
@ -488,19 +470,19 @@ double ComputeReduce::compute_one(int m, int flag)
if (mode == MINN) one = BIG; if (mode == MINN) one = BIG;
if (mode == MAXX) one = -BIG; if (mode == MAXX) one = -BIG;
if (which[m] == X) { if (which[m] == ArgInfo::X) {
double **x = atom->x; double **x = atom->x;
if (flag < 0) { if (flag < 0) {
for (i = 0; i < nlocal; i++) for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit) combine(one,x[i][aidx],i); if (mask[i] & groupbit) combine(one,x[i][aidx],i);
} else one = x[flag][aidx]; } else one = x[flag][aidx];
} else if (which[m] == V) { } else if (which[m] == ArgInfo::V) {
double **v = atom->v; double **v = atom->v;
if (flag < 0) { if (flag < 0) {
for (i = 0; i < nlocal; i++) for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit) combine(one,v[i][aidx],i); if (mask[i] & groupbit) combine(one,v[i][aidx],i);
} else one = v[flag][aidx]; } else one = v[flag][aidx];
} else if (which[m] == F) { } else if (which[m] == ArgInfo::F) {
double **f = atom->f; double **f = atom->f;
if (flag < 0) { if (flag < 0) {
for (i = 0; i < nlocal; i++) for (i = 0; i < nlocal; i++)
@ -509,7 +491,7 @@ double ComputeReduce::compute_one(int m, int flag)
// 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[vidx]; Compute *compute = modify->compute[vidx];
if (flavor[m] == PERATOM) { if (flavor[m] == PERATOM) {
@ -561,7 +543,7 @@ double ComputeReduce::compute_one(int m, int flag)
// access fix fields, check if fix frequency is a match // access fix fields, check if fix frequency is a match
} else if (which[m] == FIX) { } else if (which[m] == ArgInfo::FIX) {
if (update->ntimestep % modify->fix[vidx]->peratom_freq) if (update->ntimestep % modify->fix[vidx]->peratom_freq)
error->all(FLERR,"Fix used in compute reduce not " error->all(FLERR,"Fix used in compute reduce not "
"computed at compatible time"); "computed at compatible time");
@ -605,7 +587,7 @@ double ComputeReduce::compute_one(int m, int flag)
// evaluate atom-style variable // evaluate atom-style variable
} else if (which[m] == VARIABLE) { } else if (which[m] == ArgInfo::VARIABLE) {
if (atom->nmax > maxatom) { if (atom->nmax > maxatom) {
maxatom = atom->nmax; maxatom = atom->nmax;
memory->destroy(varatom); memory->destroy(varatom);
@ -628,9 +610,9 @@ bigint ComputeReduce::count(int m)
{ {
int vidx = value2index[m]; int vidx = value2index[m];
if (which[m] == X || which[m] == V || which[m] == F) if (which[m] == ArgInfo::X || which[m] == ArgInfo::V || which[m] == ArgInfo::F)
return group->count(igroup); return group->count(igroup);
else if (which[m] == COMPUTE) { else if (which[m] == ArgInfo::COMPUTE) {
Compute *compute = modify->compute[vidx]; Compute *compute = modify->compute[vidx];
if (flavor[m] == PERATOM) { if (flavor[m] == PERATOM) {
return group->count(igroup); return group->count(igroup);
@ -640,7 +622,7 @@ bigint ComputeReduce::count(int m)
MPI_Allreduce(&ncount,&ncountall,1,MPI_LMP_BIGINT,MPI_SUM,world); MPI_Allreduce(&ncount,&ncountall,1,MPI_LMP_BIGINT,MPI_SUM,world);
return ncountall; return ncountall;
} }
} else if (which[m] == FIX) { } else if (which[m] == ArgInfo::FIX) {
Fix *fix = modify->fix[vidx]; Fix *fix = modify->fix[vidx];
if (flavor[m] == PERATOM) { if (flavor[m] == PERATOM) {
return group->count(igroup); return group->count(igroup);
@ -650,7 +632,7 @@ bigint ComputeReduce::count(int m)
MPI_Allreduce(&ncount,&ncountall,1,MPI_LMP_BIGINT,MPI_SUM,world); MPI_Allreduce(&ncount,&ncountall,1,MPI_LMP_BIGINT,MPI_SUM,world);
return ncountall; return ncountall;
} }
} else if (which[m] == VARIABLE) } else if (which[m] == ArgInfo::VARIABLE)
return group->count(igroup); return group->count(igroup);
bigint dummy = 0; bigint dummy = 0;

View File

@ -26,6 +26,9 @@ namespace LAMMPS_NS {
class ComputeReduce : public Compute { class ComputeReduce : public Compute {
public: public:
enum {SUM,SUMSQ,MINN,MAXX,AVE,AVESQ};
enum {PERATOM,LOCAL};
ComputeReduce(class LAMMPS *, int, char **); ComputeReduce(class LAMMPS *, int, char **);
virtual ~ComputeReduce(); virtual ~ComputeReduce();
void init(); void init();

View File

@ -13,24 +13,23 @@
#include "compute_reduce_chunk.h" #include "compute_reduce_chunk.h"
#include <cstring> #include "arg_info.h"
#include "atom.h" #include "atom.h"
#include "update.h"
#include "modify.h"
#include "fix.h"
#include "compute.h" #include "compute.h"
#include "compute_chunk_atom.h" #include "compute_chunk_atom.h"
#include "input.h"
#include "variable.h"
#include "memory.h"
#include "error.h" #include "error.h"
#include "fix.h"
#include "input.h"
#include "memory.h"
#include "modify.h"
#include "update.h"
#include "variable.h"
#include <cstring>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
enum{SUM,MINN,MAXX}; enum{SUM,MINN,MAXX};
enum{UNKNOWN=-1,COMPUTE,FIX,VARIABLE};
#define INVOKED_PERATOM 8 #define INVOKED_PERATOM 8
@ -77,43 +76,23 @@ ComputeReduceChunk::ComputeReduceChunk(LAMMPS *lmp, int narg, char **arg) :
ids = new char*[nargnew]; ids = new char*[nargnew];
value2index = new int[nargnew]; value2index = new int[nargnew];
for (int i=0; i < nargnew; ++i) { for (int i=0; i < nargnew; ++i) {
which[i] = argindex[i] = value2index[i] = UNKNOWN; which[i] = argindex[i] = value2index[i] = ArgInfo::UNKNOWN;
ids[i] = nullptr; ids[i] = nullptr;
} }
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 || which[nvalues] = argi.get_type();
strncmp(arg[iarg],"f_",2) == 0 || argindex[nvalues] = argi.get_dim();
strncmp(arg[iarg],"v_",2) == 0) { ids[nvalues] = argi.copy_name();
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]); if ((which[nvalues] == ArgInfo::UNKNOWN) || (which[nvalues] == ArgInfo::NONE)
char *suffix = new char[n]; || (argindex[nvalues] > 1))
strcpy(suffix,&arg[iarg][2]); error->all(FLERR,"Illegal compute reduce/chunk command");
char *ptr = strchr(suffix,'['); nvalues++;
if (ptr) {
if (suffix[strlen(suffix)-1] != ']')
error->all(FLERR,"Illegal compute reduce/chunk 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++;
delete [] suffix;
} else error->all(FLERR,"Illegal compute reduce/chunk command");
iarg++;
} }
// if wildcard expansion occurred, free earg memory from expand_args() // if wildcard expansion occurred, free earg memory from expand_args()
@ -126,7 +105,7 @@ ComputeReduceChunk::ComputeReduceChunk(LAMMPS *lmp, int narg, char **arg) :
// error check // error check
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 reduce/chunk does not exist"); error->all(FLERR,"Compute ID for compute reduce/chunk does not exist");
@ -145,7 +124,7 @@ ComputeReduceChunk::ComputeReduceChunk(LAMMPS *lmp, int narg, char **arg) :
error->all(FLERR, error->all(FLERR,
"Compute reduce/chunk compute array is accessed out-of-range"); "Compute reduce/chunk 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 compute reduce/chunk does not exist"); error->all(FLERR,"Fix ID for compute reduce/chunk does not exist");
@ -163,7 +142,7 @@ ComputeReduceChunk::ComputeReduceChunk(LAMMPS *lmp, int narg, char **arg) :
error->all(FLERR,"Compute reduce/chunk fix array is " error->all(FLERR,"Compute reduce/chunk fix array is "
"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 reduce/chunk does not exist"); error->all(FLERR,"Variable name for compute reduce/chunk does not exist");
@ -229,19 +208,19 @@ void ComputeReduceChunk::init()
// set indices of all computes,fixes,variables // set indices 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 compute reduce/chunk does not exist"); error->all(FLERR,"Compute ID for compute reduce/chunk 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 reduce/chunk does not exist"); error->all(FLERR,"Fix ID for compute reduce/chunk 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 reduce/chunk does not exist"); error->all(FLERR,"Variable name for compute reduce/chunk does not exist");
@ -366,12 +345,12 @@ void ComputeReduceChunk::compute_one(int m, double *vchunk, int nstride)
// initialization in case it has not yet been run, e.g. when // initialization in case it has not yet been run, e.g. when
// the compute was invoked right after it has been created // the compute was invoked right after it has been created
if (vidx == UNKNOWN) { if (vidx == ArgInfo::UNKNOWN) {
init(); init();
vidx = value2index[m]; vidx = value2index[m];
} }
if (which[m] == COMPUTE) { if (which[m] == ArgInfo::COMPUTE) {
Compute *compute = modify->compute[vidx]; Compute *compute = modify->compute[vidx];
if (!(compute->invoked_flag & INVOKED_PERATOM)) { if (!(compute->invoked_flag & INVOKED_PERATOM)) {
@ -400,7 +379,7 @@ void ComputeReduceChunk::compute_one(int m, double *vchunk, int nstride)
// access fix fields, check if fix frequency is a match // access fix fields, check if fix frequency is a match
} else if (which[m] == FIX) { } else if (which[m] == ArgInfo::FIX) {
Fix *fix = modify->fix[vidx]; Fix *fix = modify->fix[vidx];
if (update->ntimestep % fix->peratom_freq) if (update->ntimestep % fix->peratom_freq)
error->all(FLERR,"Fix used in compute reduce/chunk not " error->all(FLERR,"Fix used in compute reduce/chunk not "
@ -427,7 +406,7 @@ void ComputeReduceChunk::compute_one(int m, double *vchunk, int nstride)
// evaluate atom-style variable // evaluate atom-style variable
} else if (which[m] == VARIABLE) { } else if (which[m] == ArgInfo::VARIABLE) {
if (atom->nmax > maxatom) { if (atom->nmax > maxatom) {
memory->destroy(varatom); memory->destroy(varatom);
maxatom = atom->nmax; maxatom = atom->nmax;

View File

@ -13,24 +13,21 @@
#include "compute_reduce_region.h" #include "compute_reduce_region.h"
#include "arg_info.h"
#include "atom.h" #include "atom.h"
#include "update.h"
#include "modify.h"
#include "domain.h" #include "domain.h"
#include "group.h"
#include "region.h"
#include "fix.h"
#include "input.h"
#include "variable.h"
#include "memory.h"
#include "error.h" #include "error.h"
#include "fix.h"
#include "group.h"
#include "input.h"
#include "memory.h"
#include "modify.h"
#include "region.h"
#include "update.h"
#include "variable.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
enum{SUM,SUMSQ,MINN,MAXX,AVE,AVESQ}; // also in ComputeReduce
enum{UNKNOWN=-1,X,V,F,COMPUTE,FIX,VARIABLE};
enum{PERATOM,LOCAL};
#define INVOKED_VECTOR 2 #define INVOKED_VECTOR 2
#define INVOKED_ARRAY 4 #define INVOKED_ARRAY 4
#define INVOKED_PERATOM 8 #define INVOKED_PERATOM 8
@ -72,7 +69,7 @@ double ComputeReduceRegion::compute_one(int m, int flag)
// initialization in case it has not yet been run, // initialization in case it has not yet been run,
// e.g. when invoked // e.g. when invoked
if (n == UNKNOWN) { if (n == ArgInfo::UNKNOWN) {
init(); init();
n = value2index[m]; n = value2index[m];
} }
@ -83,20 +80,20 @@ double ComputeReduceRegion::compute_one(int m, int flag)
if (mode == MINN) one = BIG; if (mode == MINN) one = BIG;
if (mode == MAXX) one = -BIG; if (mode == MAXX) one = -BIG;
if (which[m] == X) { if (which[m] == ArgInfo::X) {
if (flag < 0) { if (flag < 0) {
for (i = 0; i < nlocal; i++) for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2]))
combine(one,x[i][j],i); combine(one,x[i][j],i);
} else one = x[flag][j]; } else one = x[flag][j];
} else if (which[m] == V) { } else if (which[m] == ArgInfo::V) {
double **v = atom->v; double **v = atom->v;
if (flag < 0) { if (flag < 0) {
for (i = 0; i < nlocal; i++) for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2]))
combine(one,v[i][j],i); combine(one,v[i][j],i);
} else one = v[flag][j]; } else one = v[flag][j];
} else if (which[m] == F) { } else if (which[m] == ArgInfo::F) {
double **f = atom->f; double **f = atom->f;
if (flag < 0) { if (flag < 0) {
for (i = 0; i < nlocal; i++) for (i = 0; i < nlocal; i++)
@ -106,7 +103,7 @@ double ComputeReduceRegion::compute_one(int m, int flag)
// 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 (flavor[m] == PERATOM) { if (flavor[m] == PERATOM) {
@ -160,7 +157,7 @@ double ComputeReduceRegion::compute_one(int m, int flag)
// check if fix frequency is a match // check if fix frequency is a match
} else if (which[m] == FIX) { } else if (which[m] == ArgInfo::FIX) {
if (update->ntimestep % modify->fix[n]->peratom_freq) if (update->ntimestep % modify->fix[n]->peratom_freq)
error->all(FLERR,"Fix used in compute reduce not computed at " error->all(FLERR,"Fix used in compute reduce not computed at "
"compatible time"); "compatible time");
@ -206,7 +203,7 @@ double ComputeReduceRegion::compute_one(int m, int flag)
// evaluate atom-style variable // evaluate atom-style variable
} else if (which[m] == VARIABLE) { } else if (which[m] == ArgInfo::VARIABLE) {
if (atom->nmax > maxatom) { if (atom->nmax > maxatom) {
maxatom = atom->nmax; maxatom = atom->nmax;
memory->destroy(varatom); memory->destroy(varatom);
@ -230,9 +227,9 @@ bigint ComputeReduceRegion::count(int m)
{ {
int n = value2index[m]; int n = value2index[m];
if (which[m] == X || which[m] == V || which[m] == F) if (which[m] == ArgInfo::X || which[m] == ArgInfo::V || which[m] == ArgInfo::F)
return group->count(igroup,iregion); return group->count(igroup,iregion);
else if (which[m] == COMPUTE) { else if (which[m] == ArgInfo::COMPUTE) {
Compute *compute = modify->compute[n]; Compute *compute = modify->compute[n];
if (flavor[m] == PERATOM) { if (flavor[m] == PERATOM) {
return group->count(igroup,iregion); return group->count(igroup,iregion);
@ -242,7 +239,7 @@ bigint ComputeReduceRegion::count(int m)
MPI_Allreduce(&ncount,&ncountall,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&ncount,&ncountall,1,MPI_DOUBLE,MPI_SUM,world);
return ncountall; return ncountall;
} }
} else if (which[m] == FIX) { } else if (which[m] == ArgInfo::FIX) {
Fix *fix = modify->fix[n]; Fix *fix = modify->fix[n];
if (flavor[m] == PERATOM) { if (flavor[m] == PERATOM) {
return group->count(igroup,iregion); return group->count(igroup,iregion);
@ -252,7 +249,7 @@ bigint ComputeReduceRegion::count(int m)
MPI_Allreduce(&ncount,&ncountall,1,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&ncount,&ncountall,1,MPI_DOUBLE,MPI_SUM,world);
return ncountall; return ncountall;
} }
} else if (which[m] == VARIABLE) } else if (which[m] == ArgInfo::VARIABLE)
return group->count(igroup,iregion); return group->count(igroup,iregion);
bigint dummy = 0; bigint dummy = 0;

View File

@ -13,6 +13,7 @@
#include "compute_slice.h" #include "compute_slice.h"
#include "arg_info.h"
#include "error.h" #include "error.h"
#include "fix.h" #include "fix.h"
#include "input.h" #include "input.h"
@ -21,12 +22,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};
#define INVOKED_VECTOR 2 #define INVOKED_VECTOR 2
#define INVOKED_ARRAY 4 #define INVOKED_ARRAY 4
@ -56,38 +53,21 @@ ComputeSlice::ComputeSlice(LAMMPS *lmp, int narg, char **arg) :
nvalues = 0; nvalues = 0;
for (int iarg = 6; iarg < narg; iarg++) { for (int iarg = 6; iarg < narg; iarg++) {
if (strncmp(arg[iarg],"c_",2) == 0 || ArgInfo argi(arg[iarg]);
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_dim();
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) { || (argindex[nvalues] > 1))
if (suffix[strlen(suffix)-1] != ']') error->all(FLERR,"Illegal compute slice command");
error->all(FLERR,"Illegal compute slice 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++;
delete [] suffix;
} else error->all(FLERR,"Illegal compute slice command");
} }
// setup and error check // setup and error check
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 slice does not exist"); error->all(FLERR,"Compute ID for compute slice does not exist");
@ -111,7 +91,7 @@ ComputeSlice::ComputeSlice(LAMMPS *lmp, int narg, char **arg) :
} else error->all(FLERR,"Compute slice compute does not calculate " } else error->all(FLERR,"Compute slice compute does not calculate "
"global vector or array"); "global vector or array");
} 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 slice does not exist"); error->all(FLERR,"Fix ID for compute slice does not exist");
@ -132,7 +112,7 @@ ComputeSlice::ComputeSlice(LAMMPS *lmp, int narg, char **arg) :
} else error->all(FLERR,"Compute slice fix does not calculate " } else error->all(FLERR,"Compute slice fix does not calculate "
"global vector or array"); "global vector or array");
} 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 slice does not exist"); error->all(FLERR,"Variable name for compute slice does not exist");
@ -152,7 +132,7 @@ ComputeSlice::ComputeSlice(LAMMPS *lmp, int narg, char **arg) :
size_vector = (nstop-nstart) / nskip; size_vector = (nstop-nstart) / nskip;
memory->create(vector,size_vector,"slice:vector"); memory->create(vector,size_vector,"slice:vector");
if (which[0] == COMPUTE) { if (which[0] == ArgInfo::COMPUTE) {
int icompute = modify->find_compute(ids[0]); int icompute = modify->find_compute(ids[0]);
if (argindex[0] == 0) { if (argindex[0] == 0) {
extvector = modify->compute[icompute]->extvector; extvector = modify->compute[icompute]->extvector;
@ -163,7 +143,7 @@ ComputeSlice::ComputeSlice(LAMMPS *lmp, int narg, char **arg) :
extlist[j++] = modify->compute[icompute]->extlist[i-1]; extlist[j++] = modify->compute[icompute]->extlist[i-1];
} }
} else extvector = modify->compute[icompute]->extarray; } else extvector = modify->compute[icompute]->extarray;
} else if (which[0] == FIX) { } else if (which[0] == ArgInfo::FIX) {
int ifix = modify->find_fix(ids[0]); int ifix = modify->find_fix(ids[0]);
if (argindex[0] == 0) { if (argindex[0] == 0) {
extvector = modify->fix[ifix]->extvector; extvector = modify->fix[ifix]->extvector;
@ -174,7 +154,7 @@ ComputeSlice::ComputeSlice(LAMMPS *lmp, int narg, char **arg) :
extlist[j++] = modify->fix[ifix]->extlist[i-1]; extlist[j++] = modify->fix[ifix]->extlist[i-1];
} }
} else extvector = modify->fix[ifix]->extarray; } else extvector = modify->fix[ifix]->extarray;
} else if (which[0] == VARIABLE) { } else if (which[0] == ArgInfo::VARIABLE) {
extvector = 0; extvector = 0;
} }
@ -186,7 +166,7 @@ ComputeSlice::ComputeSlice(LAMMPS *lmp, int narg, char **arg) :
extarray = 0; extarray = 0;
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 (argindex[i] == 0) { if (argindex[i] == 0) {
if (modify->compute[icompute]->extvector == 1) extarray = 1; if (modify->compute[icompute]->extvector == 1) extarray = 1;
@ -197,7 +177,7 @@ ComputeSlice::ComputeSlice(LAMMPS *lmp, int narg, char **arg) :
} else { } else {
if (modify->compute[icompute]->extarray) extarray = 1; if (modify->compute[icompute]->extarray) extarray = 1;
} }
} 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 (argindex[i] == 0) { if (argindex[i] == 0) {
if (modify->fix[ifix]->extvector == 1) extarray = 1; if (modify->fix[ifix]->extvector == 1) extarray = 1;
@ -208,7 +188,7 @@ ComputeSlice::ComputeSlice(LAMMPS *lmp, int narg, char **arg) :
} else { } else {
if (modify->fix[ifix]->extarray) extarray = 1; if (modify->fix[ifix]->extarray) extarray = 1;
} }
} else if (which[i] == VARIABLE) { } else if (which[i] == ArgInfo::VARIABLE) {
// variable is always intensive, does not change extarray // variable is always intensive, does not change extarray
} }
} }
@ -237,17 +217,17 @@ void ComputeSlice::init()
// set indices and check validity of all computes,fixes // set indices and check validity of all computes,fixes
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 slice does not exist"); error->all(FLERR,"Compute ID for compute slice 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 slice does not exist"); error->all(FLERR,"Fix ID for compute slice 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 slice does not exist"); error->all(FLERR,"Variable name for compute slice does not exist");
@ -286,7 +266,7 @@ void ComputeSlice::extract_one(int m, double *vec, int stride)
// invoke the appropriate compute if needed // invoke the appropriate compute if needed
if (which[m] == COMPUTE) { if (which[m] == ArgInfo::COMPUTE) {
Compute *compute = modify->compute[value2index[m]]; Compute *compute = modify->compute[value2index[m]];
if (argindex[m] == 0) { if (argindex[m] == 0) {
@ -317,7 +297,7 @@ void ComputeSlice::extract_one(int m, double *vec, int stride)
// access fix fields, check if fix frequency is a match // access fix fields, check if fix frequency is a match
} else if (which[m] == FIX) { } else if (which[m] == ArgInfo::FIX) {
if (update->ntimestep % modify->fix[value2index[m]]->global_freq) if (update->ntimestep % modify->fix[value2index[m]]->global_freq)
error->all(FLERR,"Fix used in compute slice not " error->all(FLERR,"Fix used in compute slice not "
"computed at compatible time"); "computed at compatible time");
@ -340,7 +320,7 @@ void ComputeSlice::extract_one(int m, double *vec, int stride)
// invoke vector-style variable // invoke vector-style variable
} else if (which[m] == VARIABLE) { } else if (which[m] == ArgInfo::VARIABLE) {
double *varvec; double *varvec;
int nvec = input->variable->compute_vector(value2index[m],&varvec); int nvec = input->variable->compute_vector(value2index[m],&varvec);
if (nvec < nstop) if (nvec < nstop)