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

View File

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