some small programming style updates

This commit is contained in:
Axel Kohlmeyer
2022-12-09 16:56:50 -05:00
parent b0accb4ebf
commit 34f44daef5
2 changed files with 45 additions and 83 deletions

View File

@ -155,11 +155,9 @@ void KimParam::command(int narg, char **arg)
std::string kim_param_get_set(arg[0]); std::string kim_param_get_set(arg[0]);
if ((kim_param_get_set != "get") && (kim_param_get_set != "set")) { if ((kim_param_get_set != "get") && (kim_param_get_set != "set"))
std::string msg("Incorrect arguments in 'kim param' command.\n"); error->all(FLERR, "Incorrect arguments in 'kim param' command.\n"
msg += "'kim param get/set' is mandatory"; "'kim param get/set' is mandatory");
error->all(FLERR, msg);
}
int const ifix = modify->find_fix("KIM_MODEL_STORE"); int const ifix = modify->find_fix("KIM_MODEL_STORE");
if (ifix >= 0) { if (ifix >= 0) {
@ -170,8 +168,7 @@ void KimParam::command(int narg, char **arg)
fix_store->getptr("simulator_model")); fix_store->getptr("simulator_model"));
if (simulatorModel) if (simulatorModel)
error->all(FLERR, error->all(FLERR, "'kim param' can only be used with a KIM Portable Model");
"'kim param' can only be used with a KIM Portable Model");
} }
input->write_echo(fmt::format("#=== BEGIN kim param {} ===================" input->write_echo(fmt::format("#=== BEGIN kim param {} ==================="
@ -196,13 +193,10 @@ void KimParam::command(int narg, char **arg)
} else } else
error->all(FLERR, "Pair style is defined, but there is " error->all(FLERR, "Pair style is defined, but there is "
"no match for kim style in lammps"); "no match for kim style in lammps");
} else { } else
auto msg = fmt::format("Illegal 'kim param {0}' command.\nTo {0} the new " error->all(FLERR, "Illegal 'kim param {0}' command.\nTo {0} the new parameter values, "
"parameter values, pair style must be assigned.\n" "pair style must be assigned.\nMust use 'kim interactions' or 'pair_style kim' "
"Must use 'kim interactions' or 'pair_style kim' " "before 'kim param {0}'", kim_param_get_set);
"before 'kim param {0}'", kim_param_get_set);
error->all(FLERR, msg);
}
// Get the number of mutable parameters in the kim model // Get the number of mutable parameters in the kim model
int numberOfParameters(0); int numberOfParameters(0);
@ -243,12 +237,9 @@ void KimParam::command(int narg, char **arg)
if (paramname == str_name_str) break; if (paramname == str_name_str) break;
} }
if (param_index >= numberOfParameters) { if (param_index >= numberOfParameters)
auto msg = fmt::format("Wrong argument in 'kim param get' command.\n" error->all(FLERR, "Wrong argument in 'kim param get' command.\n"
"This Model does not have the requested '{}' " "This Model does not have the requested '{}' parameter", paramname);
"parameter", paramname);
error->all(FLERR, msg);
}
// Get the index_range for the requested parameter // Get the index_range for the requested parameter
int nlbound(0); int nlbound(0);
@ -259,12 +250,9 @@ void KimParam::command(int narg, char **arg)
// Check to see if the indices range contains // Check to see if the indices range contains
// only integer numbers and/or range : // only integer numbers and/or range :
if (argtostr.find_first_not_of("0123456789:") != std::string::npos) { if (argtostr.find_first_not_of("0123456789:") != std::string::npos)
auto msg = fmt::format("Illegal index_range.\nExpected integer " error->all(FLERR, "Illegal index_range.\nExpected integer parameter(s) instead "
"parameter(s) instead of '{}' in " "of '{}' in index_range", argtostr);
"index_range", argtostr);
error->all(FLERR, msg);
}
std::string::size_type npos = argtostr.find(':'); std::string::size_type npos = argtostr.find(':');
if (npos != std::string::npos) { if (npos != std::string::npos) {
@ -273,30 +261,20 @@ void KimParam::command(int narg, char **arg)
nlbound = atoi(words[0].c_str()); nlbound = atoi(words[0].c_str());
nubound = atoi(words[1].c_str()); nubound = atoi(words[1].c_str());
if (nubound < 1 || nubound > extent || if ((nubound < 1) || (nubound > extent) || (nlbound < 1) || (nlbound > nubound))
nlbound < 1 || nlbound > nubound) { error->all(FLERR, "Illegal index_range '{}-{}' for '{}' parameter with the "
auto msg = fmt::format("Illegal index_range '{}-{}' for '{}' " "extent of '{}'",nlbound, nubound, paramname, extent);
"parameter with the extent of '{}'",
nlbound, nubound, paramname, extent);
error->all(FLERR, msg);
}
} else { } else {
nlbound = atoi(argtostr.c_str()); nlbound = atoi(argtostr.c_str());
if (nlbound < 1 || nlbound > extent) { if (nlbound < 1 || nlbound > extent)
auto msg = fmt::format("Illegal index '{}' for '{}' parameter " error->all(FLERR, "Illegal index '{}' for '{}' parameter with the extent of '{}'",
"with the extent of '{}'", nlbound, nlbound, paramname, extent);
paramname, extent);
error->all(FLERR, msg);
}
nubound = nlbound; nubound = nlbound;
} }
} else { } else
std::string msg("Wrong number of arguments in 'kim param get' "); error->all(FLERR, "Wrong number of arguments in 'kim param get' command.\n"
msg += "command.\nIndex range after parameter name is mandatory"; "Index range after parameter name is mandatory");
error->all(FLERR, msg);
}
int const nvars = nubound - nlbound + 1; int const nvars = nubound - nlbound + 1;
std::vector<std::string> varsname; std::vector<std::string> varsname;
@ -304,15 +282,11 @@ void KimParam::command(int narg, char **arg)
if (i < narg) { if (i < narg) {
// Get the variable/variable_base name // Get the variable/variable_base name
varname = std::string(arg[i++]); varname = std::string(arg[i++]);
if ((varname == "split") || if ((varname == "split") || (varname == "list") || (varname == "explicit"))
(varname == "list") || error->all(FLERR, "Illegal variable name {} in 'kim param get'", varname);
(varname == "explicit")) } else
error->all(FLERR, "Illegal variable name in 'kim param get'"); error->all(FLERR, "Wrong number of arguments in 'kim param get' command.\n"
} else { "The LAMMPS variable name is mandatory");
std::string msg("Wrong number of arguments in 'kim param get' ");
msg += "command.\nThe LAMMPS variable name is mandatory";
error->all(FLERR, msg);
}
// indicator flag for list request // indicator flag for list request
bool list_requested(false); bool list_requested(false);
@ -337,28 +311,22 @@ void KimParam::command(int narg, char **arg)
--i; --i;
for (int j = 0; j < nvars; ++j, ++i) { for (int j = 0; j < nvars; ++j, ++i) {
varsname[j] = std::string(arg[i]); varsname[j] = std::string(arg[i]);
if (varsname[j] == "split" || varsname[j] == "list" || if (varsname[j] == "split" || varsname[j] == "list" || varsname[j] == "explicit")
varsname[j] == "explicit") error->all(FLERR, "Illegal variable name {} in 'kim param get'", varsname[j]);
error->all(FLERR, "Illegal variable name in 'kim param get'");
} }
if (i < narg) { if (i < narg) {
formatarg = std::string(arg[i]); formatarg = std::string(arg[i]);
if (formatarg == "explicit") ++i; if (formatarg == "explicit") ++i;
} }
} else { } else {
auto msg = error->all(FLERR, "Wrong number of arguments in 'kim param get' command.\n"
fmt::format("Wrong number of arguments in 'kim param get' " "The LAMMPS '{}' variable names or '{} split' is mandatory",
"command.\nThe LAMMPS '{}' variable names or " nvars, varname);
"'{} split' is mandatory", nvars, varname);
error->all(FLERR, msg);
} }
} else { } else
auto msg = error->all(FLERR, "Wrong number of arguments in 'kim param get' command.\n"
fmt::format("Wrong number of arguments in 'kim param get' " "The LAMMPS '{}' variable names or '{} split/list' is mandatory",
"command.\nThe LAMMPS '{}' variable names or " nvars, varname);
"'{} split/list' is mandatory", nvars, varname);
error->all(FLERR, msg);
}
} else { } else {
varsname.resize(1); varsname.resize(1);
if (i < narg) { if (i < narg) {

View File

@ -483,15 +483,13 @@ void PairKIM::coeff(int narg, char **arg)
nlbound = atoi(words[0].c_str()); nlbound = atoi(words[0].c_str());
nubound = atoi(words[1].c_str()); nubound = atoi(words[1].c_str());
if (nubound < 1 || nubound > extent || if ((nubound < 1) || (nubound > extent) || (nlbound < 1) || (nlbound > nubound))
nlbound < 1 || nlbound > nubound) error->all(FLERR,"Illegal index_range '{}-{}' for '{}' parameter with the extent of '{}'",
error->all(FLERR,"Illegal index_range '{}-{}' for '{}' "
"parameter with the extent of '{}'",
nlbound, nubound, paramname, extent); nlbound, nubound, paramname, extent);
} else { } else {
nlbound = atoi(argtostr.c_str()); nlbound = atoi(argtostr.c_str());
if (nlbound < 1 || nlbound > extent) if ((nlbound < 1) || (nlbound > extent))
error->all(FLERR,"Illegal index '{}' for '{}' parameter with the extent of '{}'", error->all(FLERR,"Illegal index '{}' for '{}' parameter with the extent of '{}'",
nlbound, paramname, extent); nlbound, paramname, extent);
@ -1081,8 +1079,7 @@ void PairKIM::set_kim_model_has_flags()
KIM_ComputeArguments_GetArgumentSupportStatus( KIM_ComputeArguments_GetArgumentSupportStatus(
pargs, computeArgumentName, &supportStatus); pargs, computeArgumentName, &supportStatus);
if (KIM_ComputeArgumentName_Equal(computeArgumentName, if (KIM_ComputeArgumentName_Equal(computeArgumentName, KIM_COMPUTE_ARGUMENT_NAME_partialEnergy))
KIM_COMPUTE_ARGUMENT_NAME_partialEnergy))
kim_model_support_for_energy = supportStatus; kim_model_support_for_energy = supportStatus;
else if (KIM_ComputeArgumentName_Equal( else if (KIM_ComputeArgumentName_Equal(
computeArgumentName, KIM_COMPUTE_ARGUMENT_NAME_partialForces)) computeArgumentName, KIM_COMPUTE_ARGUMENT_NAME_partialForces))
@ -1095,17 +1092,14 @@ void PairKIM::set_kim_model_has_flags()
computeArgumentName, computeArgumentName,
KIM_COMPUTE_ARGUMENT_NAME_partialParticleVirial)) KIM_COMPUTE_ARGUMENT_NAME_partialParticleVirial))
kim_model_support_for_particleVirial = supportStatus; kim_model_support_for_particleVirial = supportStatus;
else if (KIM_SupportStatus_Equal(supportStatus, else if (KIM_SupportStatus_Equal(supportStatus, KIM_SUPPORT_STATUS_required)) {
KIM_SUPPORT_STATUS_required)) { error->all(FLERR, "KIM Model requires unsupported compute argument: {}",
std::string msg("KIM Model requires unsupported compute argument: "); KIM_ComputeArgumentName_ToString(computeArgumentName));
msg += KIM_ComputeArgumentName_ToString(computeArgumentName);
error->all(FLERR,msg);
} }
} }
if (comm->me == 0) { if (comm->me == 0) {
if (KIM_SupportStatus_Equal(kim_model_support_for_energy, if (KIM_SupportStatus_Equal(kim_model_support_for_energy, KIM_SUPPORT_STATUS_notSupported))
KIM_SUPPORT_STATUS_notSupported))
error->warning(FLERR,"KIM Model does not provide 'partialEnergy'; Potential energy will be zero"); error->warning(FLERR,"KIM Model does not provide 'partialEnergy'; Potential energy will be zero");
if (KIM_SupportStatus_Equal(kim_model_support_for_forces, if (KIM_SupportStatus_Equal(kim_model_support_for_forces,