refactor expand_types to return int
This commit is contained in:
@ -58,12 +58,8 @@ FixMolSwap::FixMolSwap(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
|
|
||||||
nevery = utils::inumeric(FLERR, arg[3], false, lmp);
|
nevery = utils::inumeric(FLERR, arg[3], false, lmp);
|
||||||
ncycles = utils::inumeric(FLERR, arg[4], false, lmp);
|
ncycles = utils::inumeric(FLERR, arg[4], false, lmp);
|
||||||
char *typestr = utils::expand_type(FLERR, arg[5], Atom::ATOM, lmp);
|
itype = utils::expand_type_int(FLERR, arg[5], Atom::ATOM, lmp);
|
||||||
itype = utils::inumeric(FLERR, typestr?typestr:arg[5], false, lmp);
|
jtype = utils::expand_type_int(FLERR, arg[6], Atom::ATOM, lmp);
|
||||||
delete[] typestr;
|
|
||||||
typestr = utils::expand_type(FLERR, arg[6], Atom::ATOM, lmp);
|
|
||||||
jtype = utils::inumeric(FLERR, typestr?typestr:arg[6], false, lmp);
|
|
||||||
delete[] typestr;
|
|
||||||
seed = utils::inumeric(FLERR,arg[7],false,lmp);
|
seed = utils::inumeric(FLERR,arg[7],false,lmp);
|
||||||
double temperature = utils::numeric(FLERR,arg[8],false,lmp);
|
double temperature = utils::numeric(FLERR,arg[8],false,lmp);
|
||||||
|
|
||||||
|
|||||||
@ -89,9 +89,7 @@ void CreateAtoms::command(int narg, char **arg)
|
|||||||
// parse arguments
|
// parse arguments
|
||||||
|
|
||||||
if (narg < 2) utils::missing_cmd_args(FLERR, "create_atoms", error);
|
if (narg < 2) utils::missing_cmd_args(FLERR, "create_atoms", error);
|
||||||
char *typestr = utils::expand_type(FLERR, arg[0], Atom::ATOM, lmp);
|
ntype = utils::expand_type_int(FLERR, arg[0], Atom::ATOM, lmp);
|
||||||
ntype = utils::inumeric(FLERR, typestr?typestr:arg[0], false, lmp);
|
|
||||||
delete[] typestr;
|
|
||||||
|
|
||||||
const char *meshfile;
|
const char *meshfile;
|
||||||
int iarg;
|
int iarg;
|
||||||
@ -165,9 +163,7 @@ void CreateAtoms::command(int narg, char **arg)
|
|||||||
if (strcmp(arg[iarg], "basis") == 0) {
|
if (strcmp(arg[iarg], "basis") == 0) {
|
||||||
if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "create_atoms basis", error);
|
if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "create_atoms basis", error);
|
||||||
int ibasis = utils::inumeric(FLERR, arg[iarg + 1], false, lmp);
|
int ibasis = utils::inumeric(FLERR, arg[iarg + 1], false, lmp);
|
||||||
char *typestr = utils::expand_type(FLERR, arg[iarg + 2], Atom::ATOM, lmp);
|
int itype = utils::expand_type_int(FLERR, arg[iarg + 2], Atom::ATOM, lmp);
|
||||||
int itype = utils::inumeric(FLERR, typestr?typestr:arg[iarg + 2], false, lmp);
|
|
||||||
delete[] typestr;
|
|
||||||
if (ibasis <= 0 || ibasis > nbasis || itype <= 0 || itype > atom->ntypes)
|
if (ibasis <= 0 || ibasis > nbasis || itype <= 0 || itype > atom->ntypes)
|
||||||
error->all(FLERR, "Out of range basis setting '{} {}' in create_atoms command", ibasis,
|
error->all(FLERR, "Out of range basis setting '{} {}' in create_atoms command", ibasis,
|
||||||
itype);
|
itype);
|
||||||
|
|||||||
@ -60,9 +60,7 @@ FixDeposit::FixDeposit(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
// required args
|
// required args
|
||||||
|
|
||||||
ninsert = utils::inumeric(FLERR, arg[3], false, lmp);
|
ninsert = utils::inumeric(FLERR, arg[3], false, lmp);
|
||||||
char *typestr = utils::expand_type(FLERR, arg[4], Atom::ATOM, lmp);
|
ntype = utils::expand_type_int(FLERR, arg[4], Atom::ATOM, lmp);
|
||||||
ntype = utils::inumeric(FLERR, typestr?typestr:arg[4], false, lmp);
|
|
||||||
delete[] typestr;
|
|
||||||
nfreq = utils::inumeric(FLERR, arg[5], false, lmp);
|
nfreq = utils::inumeric(FLERR, arg[5], false, lmp);
|
||||||
seed = utils::inumeric(FLERR, arg[6], false, lmp);
|
seed = utils::inumeric(FLERR, arg[6], false, lmp);
|
||||||
|
|
||||||
|
|||||||
@ -915,6 +915,20 @@ char *utils::expand_type(const char *file, int line, const std::string &str, int
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------
|
||||||
|
Expand type string to integer-valued numeric type from labelmap.
|
||||||
|
Not guaranteed to return a valid type.
|
||||||
|
For example, type <= 0 or type > Ntypes is checked in calling routine.
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int utils::expand_type_int(const char *file, int line, const std::string &str, int mode, LAMMPS *lmp)
|
||||||
|
{
|
||||||
|
char *typestr = expand_type(file, line, str, mode, lmp);
|
||||||
|
int out = inumeric(FLERR, typestr?typestr:str, false, lmp);
|
||||||
|
delete[] typestr;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
Check grid reference for valid Compute or Fix which produces per-grid data
|
Check grid reference for valid Compute or Fix which produces per-grid data
|
||||||
errstr = name of calling command used if error is generated
|
errstr = name of calling command used if error is generated
|
||||||
|
|||||||
@ -379,6 +379,12 @@ namespace utils {
|
|||||||
|
|
||||||
char *expand_type(const char *file, int line, const std::string &str, int mode, LAMMPS *lmp);
|
char *expand_type(const char *file, int line, const std::string &str, int mode, LAMMPS *lmp);
|
||||||
|
|
||||||
|
/*! Expand type label string into its equivalent integer-valued numeric type
|
||||||
|
*
|
||||||
|
* This function has the same arguments as expand_type() but returns an integer value */
|
||||||
|
|
||||||
|
int expand_type_int(const char *file, int line, const std::string &str, int mode, LAMMPS *lmp);
|
||||||
|
|
||||||
/*! Check grid reference for valid Compute or Fix which produces per-grid data
|
/*! Check grid reference for valid Compute or Fix which produces per-grid data
|
||||||
*
|
*
|
||||||
* This function checks if a command argument in the input script
|
* This function checks if a command argument in the input script
|
||||||
|
|||||||
Reference in New Issue
Block a user