expand pair_only_flag processing to also apply to other suffix handlers
This commit is contained in:
@ -680,7 +680,8 @@ void Atom::create_avec(const std::string &style, int narg, char **arg, int trysu
|
||||
if (sflag) {
|
||||
std::string estyle = style + "/";
|
||||
if (sflag == 1) estyle += lmp->suffix;
|
||||
else estyle += lmp->suffix2;
|
||||
else if (sflag == 2) estyle += lmp->suffix2;
|
||||
else if (sflag == 3) estyle += lmp->non_pair_suffix();
|
||||
atom_style = utils::strdup(estyle);
|
||||
} else {
|
||||
atom_style = utils::strdup(style);
|
||||
@ -704,9 +705,9 @@ void Atom::create_avec(const std::string &style, int narg, char **arg, int trysu
|
||||
AtomVec *Atom::new_avec(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
sflag = 1;
|
||||
std::string estyle = style + "/" + lmp->suffix;
|
||||
if (lmp->non_pair_suffix()) {
|
||||
sflag = 1 + 2*lmp->pair_only_flag;
|
||||
std::string estyle = style + "/" + lmp->non_pair_suffix();
|
||||
if (avec_map->find(estyle) != avec_map->end()) {
|
||||
AtomVecCreator &avec_creator = (*avec_map)[estyle];
|
||||
return avec_creator(lmp);
|
||||
|
||||
@ -1760,8 +1760,8 @@ void Domain::add_region(int narg, char **arg)
|
||||
Region *newregion = nullptr;
|
||||
|
||||
if (lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
std::string estyle = std::string(arg[1]) + "/" + lmp->suffix;
|
||||
if (lmp->non_pair_suffix()) {
|
||||
std::string estyle = std::string(arg[1]) + "/" + lmp->non_pair_suffix();
|
||||
if (region_map->find(estyle) != region_map->end()) {
|
||||
RegionCreator ®ion_creator = (*region_map)[estyle];
|
||||
newregion = region_creator(lmp, narg, arg);
|
||||
|
||||
@ -338,24 +338,6 @@ void Force::create_bond(const std::string &style, int trysuffix)
|
||||
bond_style = store_style(style, sflag);
|
||||
}
|
||||
|
||||
// helper function to reduce redundant code.
|
||||
|
||||
static const char *pair_only_suffix(const char *suffix, int flag)
|
||||
{
|
||||
const char *mysuffix;
|
||||
if (flag) {
|
||||
#ifdef LMP_KOKKOS_GPU
|
||||
if strmatch(suffix,"^kk") mysuffix = "kk/host";
|
||||
else mysuffix = nullptr;
|
||||
#else
|
||||
mysuffix = nullptr;
|
||||
#endif
|
||||
} else {
|
||||
mysuffix = suffix;
|
||||
}
|
||||
return mysuffix;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
generate a bond class, fist with suffix appended
|
||||
------------------------------------------------------------------------- */
|
||||
@ -363,10 +345,9 @@ static const char *pair_only_suffix(const char *suffix, int flag)
|
||||
Bond *Force::new_bond(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
auto mysuffix = pair_only_suffix(lmp->suffix, lmp->pair_only_flag);
|
||||
if (mysuffix) {
|
||||
sflag = 1;
|
||||
std::string estyle = style + "/" + mysuffix;
|
||||
if (lmp->non_pair_suffix()) {
|
||||
sflag = 1 + 2*lmp->pair_only_flag;
|
||||
std::string estyle = style + "/" + lmp->non_pair_suffix();
|
||||
if (bond_map->find(estyle) != bond_map->end()) {
|
||||
BondCreator &bond_creator = (*bond_map)[estyle];
|
||||
return bond_creator(lmp);
|
||||
@ -432,10 +413,9 @@ void Force::create_angle(const std::string &style, int trysuffix)
|
||||
Angle *Force::new_angle(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
auto mysuffix = pair_only_suffix(lmp->suffix, lmp->pair_only_flag);
|
||||
if (mysuffix) {
|
||||
sflag = 1;
|
||||
std::string estyle = style + "/" + mysuffix;
|
||||
if (lmp->non_pair_suffix()) {
|
||||
sflag = 1 + 2*lmp->pair_only_flag;
|
||||
std::string estyle = style + "/" + lmp->non_pair_suffix();
|
||||
if (angle_map->find(estyle) != angle_map->end()) {
|
||||
AngleCreator &angle_creator = (*angle_map)[estyle];
|
||||
return angle_creator(lmp);
|
||||
@ -501,10 +481,9 @@ void Force::create_dihedral(const std::string &style, int trysuffix)
|
||||
Dihedral *Force::new_dihedral(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
auto mysuffix = pair_only_suffix(lmp->suffix, lmp->pair_only_flag);
|
||||
if (mysuffix) {
|
||||
sflag = 1;
|
||||
std::string estyle = style + "/" + mysuffix;
|
||||
if (lmp->non_pair_suffix()) {
|
||||
sflag = 1 + 2*lmp->pair_only_flag;
|
||||
std::string estyle = style + "/" + lmp->non_pair_suffix();
|
||||
if (dihedral_map->find(estyle) != dihedral_map->end()) {
|
||||
DihedralCreator &dihedral_creator = (*dihedral_map)[estyle];
|
||||
return dihedral_creator(lmp);
|
||||
@ -570,10 +549,9 @@ void Force::create_improper(const std::string &style, int trysuffix)
|
||||
Improper *Force::new_improper(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
auto mysuffix = pair_only_suffix(lmp->suffix, lmp->pair_only_flag);
|
||||
if (mysuffix) {
|
||||
sflag = 1;
|
||||
std::string estyle = style + "/" + mysuffix;
|
||||
if (lmp->non_pair_suffix()) {
|
||||
sflag = 1 + 2*lmp->pair_only_flag;
|
||||
std::string estyle = style + "/" + lmp->non_pair_suffix();
|
||||
if (improper_map->find(estyle) != improper_map->end()) {
|
||||
ImproperCreator &improper_creator = (*improper_map)[estyle];
|
||||
return improper_creator(lmp);
|
||||
@ -639,10 +617,9 @@ void Force::create_kspace(const std::string &style, int trysuffix)
|
||||
KSpace *Force::new_kspace(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
auto mysuffix = pair_only_suffix(lmp->suffix, lmp->pair_only_flag);
|
||||
if (mysuffix) {
|
||||
sflag = 1;
|
||||
std::string estyle = style + "/" + mysuffix;
|
||||
if (lmp->non_pair_suffix()) {
|
||||
sflag = 1 + 2*lmp->pair_only_flag;
|
||||
std::string estyle = style + "/" + lmp->non_pair_suffix();
|
||||
if (kspace_map->find(estyle) != kspace_map->end()) {
|
||||
KSpaceCreator &kspace_creator = (*kspace_map)[estyle];
|
||||
return kspace_creator(lmp);
|
||||
@ -696,12 +673,13 @@ KSpace *Force::kspace_match(const std::string &word, int exact)
|
||||
char *Force::store_style(const std::string &style, int sflag)
|
||||
{
|
||||
std::string estyle = style;
|
||||
auto mystyle = pair_only_suffix(lmp->suffix, lmp->pair_only_flag);
|
||||
|
||||
if ((sflag == 1) && mystyle)
|
||||
estyle += std::string("/") + mystyle;
|
||||
if (sflag == 1)
|
||||
estyle += std::string("/") + lmp->suffix;
|
||||
else if (sflag == 2)
|
||||
estyle += std::string("/") + lmp->suffix2;
|
||||
else if ((sflag == 3) && lmp->non_pair_suffix())
|
||||
estyle += std::string("/") + lmp->non_pair_suffix();
|
||||
return utils::strdup(estyle);
|
||||
}
|
||||
|
||||
|
||||
@ -831,8 +831,8 @@ int Input::execute_command()
|
||||
// try suffixed version first
|
||||
|
||||
std::string mycmd = command;
|
||||
if (lmp->suffix_enable && lmp->suffix) {
|
||||
mycmd = command + std::string("/") + lmp->suffix;
|
||||
if (lmp->suffix_enable && lmp->non_pair_suffix()) {
|
||||
mycmd = command + std::string("/") + lmp->non_pair_suffix();
|
||||
if (command_map->find(mycmd) == command_map->end()) {
|
||||
if (lmp->suffix2) {
|
||||
mycmd = command + std::string("/") + lmp->suffix2;
|
||||
|
||||
@ -1153,6 +1153,26 @@ const char *LAMMPS::match_style(const char *style, const char *name)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/** \brief Return suffix for non-pair styles depending on pair_only_flag
|
||||
*
|
||||
* \return suffix or null pointer
|
||||
*/
|
||||
const char *LAMMPS::non_pair_suffix() const
|
||||
{
|
||||
const char *mysuffix;
|
||||
if (pair_only_flag) {
|
||||
#ifdef LMP_KOKKOS_GPU
|
||||
if (utils::strmatch(suffix,"^kk")) mysuffix = "kk/host";
|
||||
else mysuffix = nullptr;
|
||||
#else
|
||||
mysuffix = nullptr;
|
||||
#endif
|
||||
} else {
|
||||
mysuffix = suffix;
|
||||
}
|
||||
return mysuffix;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
help message for command line options and styles present in executable
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
@ -61,6 +61,7 @@ class LAMMPS {
|
||||
char *suffix, *suffix2; // suffixes to add to input script style names
|
||||
int suffix_enable; // 1 if suffixes are enabled, 0 if disabled
|
||||
int pair_only_flag; // 1 if only force field pair styles are accelerated, 0 if all
|
||||
const char *non_pair_suffix() const;
|
||||
char *exename; // pointer to argv[0]
|
||||
|
||||
char ***packargs; // arguments for cmdline package commands
|
||||
|
||||
@ -848,8 +848,8 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix)
|
||||
int match = 0;
|
||||
if (strcmp(arg[2], fix[ifix]->style) == 0) match = 1;
|
||||
if (!match && trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
std::string estyle = arg[2] + std::string("/") + lmp->suffix;
|
||||
if (lmp->non_pair_suffix()) {
|
||||
std::string estyle = arg[2] + std::string("/") + lmp->non_pair_suffix();
|
||||
if (estyle == fix[ifix]->style) match = 1;
|
||||
}
|
||||
if (lmp->suffix2) {
|
||||
@ -879,8 +879,8 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix)
|
||||
fix[ifix] = nullptr;
|
||||
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
std::string estyle = arg[2] + std::string("/") + lmp->suffix;
|
||||
if (lmp->non_pair_suffix()) {
|
||||
std::string estyle = arg[2] + std::string("/") + lmp->non_pair_suffix();
|
||||
if (fix_map->find(estyle) != fix_map->end()) {
|
||||
FixCreator &fix_creator = (*fix_map)[estyle];
|
||||
fix[ifix] = fix_creator(lmp, narg, arg);
|
||||
@ -1243,8 +1243,8 @@ Compute *Modify::add_compute(int narg, char **arg, int trysuffix)
|
||||
compute[ncompute] = nullptr;
|
||||
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
std::string estyle = arg[2] + std::string("/") + lmp->suffix;
|
||||
if (lmp->non_pair_suffix()) {
|
||||
std::string estyle = arg[2] + std::string("/") + lmp->non_pair_suffix();
|
||||
if (compute_map->find(estyle) != compute_map->end()) {
|
||||
ComputeCreator &compute_creator = (*compute_map)[estyle];
|
||||
compute[ncompute] = compute_creator(lmp, narg, arg);
|
||||
|
||||
@ -346,8 +346,10 @@ void Update::create_integrate(int narg, char **arg, int trysuffix)
|
||||
estyle += "/";
|
||||
if (sflag == 1)
|
||||
estyle += lmp->suffix;
|
||||
else
|
||||
else if (sflag == 2)
|
||||
estyle += lmp->suffix2;
|
||||
else if ((sflag == 3) && lmp->non_pair_suffix())
|
||||
estyle += lmp->non_pair_suffix();
|
||||
}
|
||||
integrate_style = utils::strdup(estyle);
|
||||
}
|
||||
@ -359,9 +361,9 @@ void Update::create_integrate(int narg, char **arg, int trysuffix)
|
||||
void Update::new_integrate(char *style, int narg, char **arg, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
sflag = 1;
|
||||
std::string estyle = style + std::string("/") + lmp->suffix;
|
||||
if (lmp->non_pair_suffix()) {
|
||||
sflag = 1 + 2*lmp->pair_only_flag;
|
||||
std::string estyle = style + std::string("/") + lmp->non_pair_suffix();
|
||||
if (integrate_map->find(estyle) != integrate_map->end()) {
|
||||
IntegrateCreator &integrate_creator = (*integrate_map)[estyle];
|
||||
integrate = integrate_creator(lmp, narg, arg);
|
||||
@ -407,8 +409,10 @@ void Update::create_minimize(int narg, char **arg, int trysuffix)
|
||||
estyle += "/";
|
||||
if (sflag == 1)
|
||||
estyle += lmp->suffix;
|
||||
else
|
||||
else if (sflag == 2)
|
||||
estyle += lmp->suffix2;
|
||||
else if ((sflag == 3) && lmp->non_pair_suffix())
|
||||
estyle += lmp->non_pair_suffix();
|
||||
}
|
||||
minimize_style = utils::strdup(estyle);
|
||||
}
|
||||
@ -420,9 +424,9 @@ void Update::create_minimize(int narg, char **arg, int trysuffix)
|
||||
void Update::new_minimize(char *style, int /* narg */, char ** /* arg */, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
sflag = 1;
|
||||
std::string estyle = style + std::string("/") + lmp->suffix;
|
||||
if (lmp->non_pair_suffix()) {
|
||||
sflag = 1 + 2*lmp->pair_only_flag;
|
||||
std::string estyle = style + std::string("/") + lmp->non_pair_suffix();
|
||||
if (minimize_map->find(estyle) != minimize_map->end()) {
|
||||
MinimizeCreator &minimize_creator = (*minimize_map)[estyle];
|
||||
minimize = minimize_creator(lmp);
|
||||
|
||||
Reference in New Issue
Block a user