more use of ArgInfo class

This commit is contained in:
Axel Kohlmeyer
2021-02-03 17:43:39 -05:00
parent 2f7d6672df
commit 4b15ffcf14
2 changed files with 43 additions and 72 deletions

View File

@ -23,6 +23,7 @@
#include "fix_ave_correlate_long.h"
#include "arg_info.h"
#include "citeme.h"
#include "compute.h"
#include "error.h"
@ -39,10 +40,8 @@
using namespace LAMMPS_NS;
using namespace FixConst;
enum{COMPUTE,FIX,VARIABLE};
enum{AUTO,UPPER,LOWER,AUTOUPPER,AUTOLOWER,FULL};
static const char cite_fix_ave_correlate_long[] =
"fix ave/correlate/long command:\n\n"
"@Article{Ramirez10,\n"
@ -82,33 +81,18 @@ FixAveCorrelateLong::FixAveCorrelateLong(LAMMPS * lmp, int narg, char **arg):
int iarg = 5;
while (iarg < narg) {
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]);
char *suffix = new char[n];
strcpy(suffix,&arg[iarg][2]);
char *ptr = strchr(suffix,'[');
if (ptr) {
if (suffix[strlen(suffix)-1] != ']')
ArgInfo argi(arg[iarg]);
if (argi.get_type() == ArgInfo::NONE) break;
if ((argi.get_type() == ArgInfo::UNKNOWN) || (argi.get_dim() > 1))
error->all(FLERR,"Illegal fix ave/correlate/long 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);
delete [] suffix;
which[nvalues] = argi.get_type();
argindex[nvalues] = argi.get_index1();
ids[nvalues] = argi.copy_name();
nvalues++;
iarg++;
} else break;
}
// optional args
@ -204,7 +188,7 @@ FixAveCorrelateLong::FixAveCorrelateLong(LAMMPS * lmp, int narg, char **arg):
error->all(FLERR,"Illegal fix ave/correlate/long command");
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 fix ave/correlate/long does not exist");
@ -218,7 +202,7 @@ FixAveCorrelateLong::FixAveCorrelateLong(LAMMPS * lmp, int narg, char **arg):
error->all(FLERR,"Fix ave/correlate/long compute vector "
"is 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 fix ave/correlate/long does not exist");
@ -233,7 +217,7 @@ FixAveCorrelateLong::FixAveCorrelateLong(LAMMPS * lmp, int narg, char **arg):
error->all(FLERR,"Fix for fix ave/correlate/long "
"not computed at compatible time");
} 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 fix ave/correlate/long does not exist");
@ -377,19 +361,19 @@ void FixAveCorrelateLong::init()
// set current indices for all computes,fixes,variables
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 fix ave/correlate/long does not exist");
value2index[i] = icompute;
} 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 fix ave/correlate/long does not exist");
value2index[i] = ifix;
} 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 fix ave/correlate/long does not exist");
@ -441,7 +425,7 @@ void FixAveCorrelateLong::end_of_step()
// invoke compute if not previously invoked
if (which[i] == COMPUTE) {
if (which[i] == ArgInfo::COMPUTE) {
Compute *compute = modify->compute[m];
if (argindex[i] == 0) {
@ -460,7 +444,7 @@ void FixAveCorrelateLong::end_of_step()
// access fix fields, guaranteed to be ready
} else if (which[i] == FIX) {
} else if (which[i] == ArgInfo::FIX) {
if (argindex[i] == 0)
scalar = modify->fix[m]->compute_scalar();
else
@ -468,7 +452,7 @@ void FixAveCorrelateLong::end_of_step()
// evaluate equal-style variable
} else if (which[i] == VARIABLE)
} else if (which[i] == ArgInfo::VARIABLE)
scalar = input->variable->compute_equal(m);
values[i] = scalar;

View File

@ -18,6 +18,7 @@
#include "thermo.h"
#include "angle.h"
#include "arg_info.h"
#include "atom.h"
#include "bond.h"
#include "comm.h"
@ -880,32 +881,22 @@ void Thermo::parse_fields(char *str)
// compute value = c_ID, fix value = f_ID, variable value = v_ID
// count trailing [] and store int arguments
} else if ((word.substr(0, 2) == "c_") || (word.substr(0, 2) == "f_") ||
(word.substr(0, 2) == "v_")) {
} else {
ArgInfo argi(word);
int n = word.length() - 1;
char *id = new char[n];
strcpy(id, &word.c_str()[2]);
if ((argi.get_type() == ArgInfo::UNKNOWN)
|| (argi.get_type() == ArgInfo::NONE)
|| (argi.get_dim() > 2))
error->all(FLERR,"Unknown keyword in thermo_style custom command");
// parse zero or one or two trailing brackets from ID
// process zero or one or two trailing brackets
// argindex1,argindex2 = int inside each bracket pair, 0 if no bracket
char *ptr = strchr(id,'[');
if (ptr == nullptr) argindex1[nfield] = argindex2[nfield] = 0;
else {
*ptr = '\0';
argindex1[nfield] =
(int) input->variable->int_between_brackets(ptr,0);
ptr++;
if (*ptr == '[') {
argindex2[nfield] =
(int) input->variable->int_between_brackets(ptr,0);
ptr++;
} else argindex2[nfield] = 0;
}
argindex1[nfield] = argi.get_index1();
argindex2[nfield] = (argi.get_dim() > 1) ? argi.get_index2() : 0;
if (word[0] == 'c') {
n = modify->find_compute(id);
if (argi.get_type() == ArgInfo::COMPUTE) {
int n = modify->find_compute(argi.get_name());
if (n < 0) error->all(FLERR,"Could not find thermo custom compute ID");
if (argindex1[nfield] == 0 && modify->compute[n]->scalar_flag == 0)
error->all(FLERR,"Thermo compute does not compute scalar");
@ -927,15 +918,15 @@ void Thermo::parse_fields(char *str)
}
if (argindex1[nfield] == 0)
field2index[nfield] = add_compute(id, SCALAR);
field2index[nfield] = add_compute(argi.get_name(), SCALAR);
else if (argindex2[nfield] == 0)
field2index[nfield] = add_compute(id, VECTOR);
field2index[nfield] = add_compute(argi.get_name(), VECTOR);
else
field2index[nfield] = add_compute(id, ARRAY);
field2index[nfield] = add_compute(argi.get_name(), ARRAY);
addfield(word.c_str(), &Thermo::compute_compute, FLOAT);
} else if (word[0] == 'f') {
n = modify->find_fix(id);
} else if (argi.get_type() == ArgInfo::FIX) {
int n = modify->find_fix(argi.get_name());
if (n < 0) error->all(FLERR,"Could not find thermo custom fix ID");
if (argindex1[nfield] == 0 && modify->fix[n]->scalar_flag == 0)
error->all(FLERR,"Thermo fix does not compute scalar");
@ -956,11 +947,11 @@ void Thermo::parse_fields(char *str)
error->all(FLERR,"Thermo fix array is accessed out-of-range");
}
field2index[nfield] = add_fix(id);
field2index[nfield] = add_fix(argi.get_name());
addfield(word.c_str(), &Thermo::compute_fix, FLOAT);
} else if (word[0] == 'v') {
n = input->variable->find(id);
} else if (argi.get_type() == ArgInfo::VARIABLE) {
int n = input->variable->find(argi.get_name());
if (n < 0)
error->all(FLERR,"Could not find thermo custom variable name");
if (argindex1[nfield] == 0 && input->variable->equalstyle(n) == 0)
@ -972,14 +963,10 @@ void Thermo::parse_fields(char *str)
if (argindex2[nfield])
error->all(FLERR,"Thermo custom variable cannot have two indices");
field2index[nfield] = add_variable(id);
field2index[nfield] = add_variable(argi.get_name());
addfield(word.c_str(), &Thermo::compute_variable, FLOAT);
}
delete [] id;
} else error->all(FLERR,"Unknown keyword in thermo_style custom command");
}
}
}