apply new utility function to most places creating new styles

This commit is contained in:
Axel Kohlmeyer
2019-04-07 20:55:39 -04:00
parent 9166001041
commit d640c712f8
9 changed files with 26 additions and 38 deletions

View File

@ -39,6 +39,7 @@
#include "math_const.h" #include "math_const.h"
#include "memory.h" #include "memory.h"
#include "error.h" #include "error.h"
#include "utils.h"
#ifdef LMP_USER_INTEL #ifdef LMP_USER_INTEL
#include "neigh_request.h" #include "neigh_request.h"
@ -509,7 +510,7 @@ AtomVec *Atom::new_avec(const char *style, int trysuffix, int &sflag)
return avec_creator(lmp); return avec_creator(lmp);
} }
error->all(FLERR,"Unknown atom style"); error->all(FLERR,utils::check_packages_for_style("atom",style,lmp).c_str());
return NULL; return NULL;
} }

View File

@ -25,6 +25,7 @@
#include "fix.h" #include "fix.h"
#include "memory.h" #include "memory.h"
#include "error.h" #include "error.h"
#include "utils.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
@ -96,7 +97,7 @@ void AtomVecBody::process_args(int narg, char **arg)
#undef BodyStyle #undef BodyStyle
#undef BODY_CLASS #undef BODY_CLASS
else error->all(FLERR,"Unknown body style"); else error->all(FLERR,utils::check_packages_for_style("body",arg[0],lmp).c_str());
bptr->avec = this; bptr->avec = this;
icp = bptr->icp; icp = bptr->icp;

View File

@ -40,6 +40,7 @@
#include "math_const.h" #include "math_const.h"
#include "memory.h" #include "memory.h"
#include "error.h" #include "error.h"
#include "utils.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace MathConst; using namespace MathConst;
@ -1714,6 +1715,9 @@ void Domain::add_region(int narg, char **arg)
return; return;
} }
if (strcmp(arg[1],"none") == 0)
error->all(FLERR,"Unrecognized region style 'none'");
if (find_region(arg[0]) >= 0) error->all(FLERR,"Reuse of region ID"); if (find_region(arg[0]) >= 0) error->all(FLERR,"Reuse of region ID");
// extend Region list if necessary // extend Region list if necessary
@ -1752,12 +1756,10 @@ void Domain::add_region(int narg, char **arg)
} }
} }
if (strcmp(arg[1],"none") == 0) error->all(FLERR,"Unknown region style");
if (region_map->find(arg[1]) != region_map->end()) { if (region_map->find(arg[1]) != region_map->end()) {
RegionCreator region_creator = (*region_map)[arg[1]]; RegionCreator region_creator = (*region_map)[arg[1]];
regions[nregion] = region_creator(lmp, narg, arg); regions[nregion] = region_creator(lmp, narg, arg);
} } else error->all(FLERR,utils::check_packages_for_style("region",arg[1],lmp).c_str());
else error->all(FLERR,"Unknown region style");
// initialize any region variables via init() // initialize any region variables via init()
// in case region is used between runs, e.g. to print a variable // in case region is used between runs, e.g. to print a variable

View File

@ -258,9 +258,7 @@ Pair *Force::new_pair(const char *style, int trysuffix, int &sflag)
return pair_creator(lmp); return pair_creator(lmp);
} }
char str[128]; error->all(FLERR,utils::check_packages_for_style("pair",style,lmp).c_str());
sprintf(str,"Unknown pair style %s",style);
error->all(FLERR,str);
return NULL; return NULL;
} }
@ -373,9 +371,7 @@ Bond *Force::new_bond(const char *style, int trysuffix, int &sflag)
return bond_creator(lmp); return bond_creator(lmp);
} }
char str[128]; error->all(FLERR,utils::check_packages_for_style("bond",style,lmp).c_str());
sprintf(str,"Unknown bond style %s",style);
error->all(FLERR,str);
return NULL; return NULL;
} }
@ -454,9 +450,7 @@ Angle *Force::new_angle(const char *style, int trysuffix, int &sflag)
return angle_creator(lmp); return angle_creator(lmp);
} }
char str[128]; error->all(FLERR,utils::check_packages_for_style("angle",style,lmp).c_str());
sprintf(str,"Unknown angle style %s",style);
error->all(FLERR,str);
return NULL; return NULL;
} }
@ -536,9 +530,7 @@ Dihedral *Force::new_dihedral(const char *style, int trysuffix, int &sflag)
return dihedral_creator(lmp); return dihedral_creator(lmp);
} }
char str[128]; error->all(FLERR,utils::check_packages_for_style("dihedral",style,lmp).c_str());
sprintf(str,"Unknown dihedral style %s",style);
error->all(FLERR,str);
return NULL; return NULL;
} }
@ -617,9 +609,7 @@ Improper *Force::new_improper(const char *style, int trysuffix, int &sflag)
return improper_creator(lmp); return improper_creator(lmp);
} }
char str[128]; error->all(FLERR,utils::check_packages_for_style("improper",style,lmp).c_str());
sprintf(str,"Unknown improper style %s",style);
error->all(FLERR,str);
return NULL; return NULL;
} }
@ -702,9 +692,7 @@ KSpace *Force::new_kspace(const char *style, int trysuffix, int &sflag)
return kspace_creator(lmp); return kspace_creator(lmp);
} }
char str[128]; error->all(FLERR,utils::check_packages_for_style("kspace",style,lmp).c_str());
sprintf(str,"Unknown kspace style %s",style);
error->all(FLERR,str);
return NULL; return NULL;
} }

View File

@ -893,11 +893,8 @@ void Modify::add_fix(int narg, char **arg, int trysuffix)
fix[ifix] = fix_creator(lmp,narg,arg); fix[ifix] = fix_creator(lmp,narg,arg);
} }
if (fix[ifix] == NULL) { if (fix[ifix] == NULL)
char str[128]; error->all(FLERR,utils::check_packages_for_style("fix",arg[2],lmp).c_str());
snprintf(str,128,"Unknown fix style %s",arg[2]);
error->all(FLERR,str);
}
// check if Fix is in restart_global list // check if Fix is in restart_global list
// if yes, pass state info to the Fix so it can reset itself // if yes, pass state info to the Fix so it can reset itself
@ -1195,11 +1192,8 @@ void Modify::add_compute(int narg, char **arg, int trysuffix)
compute[ncompute] = compute_creator(lmp,narg,arg); compute[ncompute] = compute_creator(lmp,narg,arg);
} }
if (compute[ncompute] == NULL) { if (compute[ncompute] == NULL)
char str[128]; error->all(FLERR,utils::check_packages_for_style("compute",arg[2],lmp).c_str());
snprintf(str,128,"Unknown compute style %s",arg[2]);
error->all(FLERR,str);
}
ncompute++; ncompute++;
} }

View File

@ -32,6 +32,7 @@
#include "write_restart.h" #include "write_restart.h"
#include "memory.h" #include "memory.h"
#include "error.h" #include "error.h"
#include "utils.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
@ -585,8 +586,7 @@ void Output::add_dump(int narg, char **arg)
if (dump_map->find(arg[2]) != dump_map->end()) { if (dump_map->find(arg[2]) != dump_map->end()) {
DumpCreator dump_creator = (*dump_map)[arg[2]]; DumpCreator dump_creator = (*dump_map)[arg[2]];
dump[ndump] = dump_creator(lmp, narg, arg); dump[ndump] = dump_creator(lmp, narg, arg);
} } else error->all(FLERR,utils::check_packages_for_style("dump",arg[2],lmp).c_str());
else error->all(FLERR,"Unknown dump style");
every_dump[ndump] = force->inumeric(FLERR,arg[3]); every_dump[ndump] = force->inumeric(FLERR,arg[3]);
if (every_dump[ndump] <= 0) error->all(FLERR,"Illegal dump command"); if (every_dump[ndump] <= 0) error->all(FLERR,"Illegal dump command");

View File

@ -40,6 +40,7 @@
#include "variable.h" #include "variable.h"
#include "error.h" #include "error.h"
#include "memory.h" #include "memory.h"
#include "utils.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
@ -266,7 +267,7 @@ void ReadDump::setup_reader(int narg, char **arg)
// unrecognized style // unrecognized style
else error->all(FLERR,"Unknown dump reader style"); else error->all(FLERR,utils::check_packages_for_style("reader",readerstyle,lmp).c_str());
// pass any arguments to readers // pass any arguments to readers

View File

@ -128,7 +128,7 @@ void utils::sfgets(const char *srcname, int srcline, char *s, int size,
std::string utils::check_packages_for_style(std::string style, std::string utils::check_packages_for_style(std::string style,
std::string name, LAMMPS *lmp) std::string name, LAMMPS *lmp)
{ {
std::string errmsg = "Unrecognized " + style + " style " + name; std::string errmsg = "Unrecognized " + style + " style '" + name + "'";
const char *pkg = lmp->match_style(style.c_str(),name.c_str()); const char *pkg = lmp->match_style(style.c_str(),name.c_str());
if (pkg) { if (pkg) {

View File

@ -26,6 +26,7 @@
#include "input.h" #include "input.h"
#include "update.h" #include "update.h"
#include "error.h" #include "error.h"
#include "utils.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
@ -64,7 +65,7 @@ void WriteDump::command(int narg, char **arg)
#include "style_dump.h" #include "style_dump.h"
#undef DUMP_CLASS #undef DUMP_CLASS
else error->all(FLERR,"Unknown dump style"); else error->all(FLERR,utils::check_packages_for_style("dump",arg[1],lmp).c_str());
if (modindex < narg) dump->modify_params(narg-modindex-1,&arg[modindex+1]); if (modindex < narg) dump->modify_params(narg-modindex-1,&arg[modindex+1]);