diff --git a/src/atom.cpp b/src/atom.cpp index 0b448a5433..3a3d537ce3 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -54,6 +54,15 @@ using namespace MathConst; #define DELTA_PERATOM 64 #define EPSILON 1.0e-6 +/* ---------------------------------------------------------------------- + one instance per AtomVec style in style_atom.h +------------------------------------------------------------------------- */ + +template static AtomVec *avec_creator(LAMMPS *lmp) +{ + return new T(lmp); +} + /* ---------------------------------------------------------------------- */ /** \class LAMMPS_NS::Atom @@ -743,16 +752,6 @@ AtomVec *Atom::new_avec(const std::string &style, int trysuffix, int &sflag) return nullptr; } -/* ---------------------------------------------------------------------- - one instance per AtomVec style in style_atom.h -------------------------------------------------------------------------- */ - -template -AtomVec *Atom::avec_creator(LAMMPS *lmp) -{ - return new T(lmp); -} - /* ---------------------------------------------------------------------- */ void Atom::init() diff --git a/src/atom.h b/src/atom.h index ad8349d11c..2c1acb7805 100644 --- a/src/atom.h +++ b/src/atom.h @@ -416,9 +416,6 @@ class Atom : protected Pointers { void set_atomflag_defaults(); void setup_sort_bins(); int next_prime(int); - - private: - template static AtomVec *avec_creator(LAMMPS *); }; } // namespace LAMMPS_NS diff --git a/src/domain.cpp b/src/domain.cpp index 22c38c977a..29244dff6a 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -47,6 +47,15 @@ using namespace LAMMPS_NS; #define DELTAREGION 4 #define BONDSTRETCH 1.1 +/* ---------------------------------------------------------------------- + one instance per region style in style_region.h +------------------------------------------------------------------------- */ + +template static Region *region_creator(LAMMPS *lmp, int narg, char ** arg) +{ + return new T(lmp, narg, arg); +} + /* ---------------------------------------------------------------------- default is periodic ------------------------------------------------------------------------- */ @@ -1797,16 +1806,6 @@ void Domain::add_region(int narg, char **arg) nregion++; } -/* ---------------------------------------------------------------------- - one instance per region style in style_region.h -------------------------------------------------------------------------- */ - -template -Region *Domain::region_creator(LAMMPS *lmp, int narg, char ** arg) -{ - return new T(lmp, narg, arg); -} - /* ---------------------------------------------------------------------- delete a region ------------------------------------------------------------------------- */ diff --git a/src/domain.h b/src/domain.h index a3a526610e..68ff5aece5 100644 --- a/src/domain.h +++ b/src/domain.h @@ -175,9 +175,6 @@ class Domain : protected Pointers { protected: double small[3]; // fractions of box lengths - - private: - template static Region *region_creator(LAMMPS *, int, char **); }; } // namespace LAMMPS_NS diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 74bb3bf762..489d76eaed 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -100,6 +100,14 @@ static const char cite_neigh_multi[] = " year = {2020}\n" "}\n\n"; +// template for factory functions: +// there will be one instance for each style keyword in the respective style_xxx.h files + +template static S *style_creator(LAMMPS *lmp) +{ + return new T(lmp); +} + //#define NEIGH_LIST_DEBUG 1 /* ---------------------------------------------------------------------- */ @@ -693,7 +701,7 @@ void Neighbor::init_styles() #define NBIN_CLASS #define NBinStyle(key,Class,bitmasks) \ binnames[nbclass] = (char *) #key; \ - binclass[nbclass] = &bin_creator; \ + binclass[nbclass] = &style_creator; \ binmasks[nbclass++] = bitmasks; #include "style_nbin.h" // IWYU pragma: keep #undef NBinStyle @@ -717,7 +725,7 @@ void Neighbor::init_styles() #define NSTENCIL_CLASS #define NStencilStyle(key,Class,bitmasks) \ stencilnames[nsclass] = (char *) #key; \ - stencilclass[nsclass] = &stencil_creator; \ + stencilclass[nsclass] = &style_creator; \ stencilmasks[nsclass++] = bitmasks; #include "style_nstencil.h" // IWYU pragma: keep #undef NStencilStyle @@ -741,7 +749,7 @@ void Neighbor::init_styles() #define NPAIR_CLASS #define NPairStyle(key,Class,bitmasks) \ pairnames[npclass] = (char *) #key; \ - pairclass[npclass] = &pair_creator; \ + pairclass[npclass] = &style_creator; \ pairmasks[npclass++] = bitmasks; #include "style_npair.h" // IWYU pragma: keep #undef NPairStyle @@ -2028,36 +2036,6 @@ int Neighbor::request(void *requestor, int instance) return nrequest-1; } -/* ---------------------------------------------------------------------- - one instance per entry in style_neigh_bin.h -------------------------------------------------------------------------- */ - -template -NBin *Neighbor::bin_creator(LAMMPS *lmp) -{ - return new T(lmp); -} - -/* ---------------------------------------------------------------------- - one instance per entry in style_neigh_stencil.h -------------------------------------------------------------------------- */ - -template -NStencil *Neighbor::stencil_creator(LAMMPS *lmp) -{ - return new T(lmp); -} - -/* ---------------------------------------------------------------------- - one instance per entry in style_neigh_pair.h -------------------------------------------------------------------------- */ - -template -NPair *Neighbor::pair_creator(LAMMPS *lmp) -{ - return new T(lmp); -} - /* ---------------------------------------------------------------------- setup neighbor binning and neighbor stencils called before run and every reneighbor if box size/shape changes diff --git a/src/neighbor.h b/src/neighbor.h index 60687525a3..45468c0c9b 100644 --- a/src/neighbor.h +++ b/src/neighbor.h @@ -231,10 +231,6 @@ class Neighbor : protected Pointers { int choose_stencil(class NeighRequest *); int choose_pair(class NeighRequest *); - template static NBin *bin_creator(class LAMMPS *); - template static NStencil *stencil_creator(class LAMMPS *); - template static NPair *pair_creator(class LAMMPS *); - // dummy functions provided by NeighborKokkos, called in init() // otherwise NeighborKokkos would have to overwrite init() diff --git a/src/output.cpp b/src/output.cpp index 1376d365d8..a3c79d4cda 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -43,6 +43,15 @@ using namespace LAMMPS_NS; enum {SETUP, WRITE, RESET_DT}; +/* ---------------------------------------------------------------------- + one instance per dump style in style_dump.h +------------------------------------------------------------------------- */ + +template static Dump *dump_creator(LAMMPS *lmp, int narg, char ** arg) +{ + return new T(lmp, narg, arg); +} + /* ---------------------------------------------------------------------- initialize all output ------------------------------------------------------------------------- */ @@ -784,16 +793,6 @@ void Output::add_dump(int narg, char **arg) ndump++; } -/* ---------------------------------------------------------------------- - one instance per dump style in style_dump.h -------------------------------------------------------------------------- */ - -template -Dump *Output::dump_creator(LAMMPS *lmp, int narg, char ** arg) -{ - return new T(lmp, narg, arg); -} - /* ---------------------------------------------------------------------- modify parameters of a Dump ------------------------------------------------------------------------- */ diff --git a/src/output.h b/src/output.h index 14c1de6522..54fc83c380 100644 --- a/src/output.h +++ b/src/output.h @@ -93,7 +93,6 @@ class Output : protected Pointers { void memory_usage(); // print out memory usage private: - template static Dump *dump_creator(LAMMPS *, int, char **); void calculate_next_dump(int, int, bigint); }; diff --git a/src/update.cpp b/src/update.cpp index da412ee89e..c82a1ddc18 100644 --- a/src/update.cpp +++ b/src/update.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -14,15 +13,15 @@ #include "update.h" -#include "style_integrate.h" // IWYU pragma: keep -#include "style_minimize.h" // IWYU pragma: keep +#include "style_integrate.h" // IWYU pragma: keep +#include "style_minimize.h" // IWYU pragma: keep #include "comm.h" #include "compute.h" -#include "integrate.h" #include "error.h" #include "fix.h" #include "force.h" +#include "integrate.h" #include "min.h" #include "modify.h" #include "neighbor.h" @@ -32,6 +31,19 @@ using namespace LAMMPS_NS; +// template for factory functions: +// there will be one instance for each style keyword in the respective style_xxx.h files + +template static Integrate *integrate_creator(LAMMPS *lmp, int narg, char **arg) +{ + return new T(lmp, narg, arg); +} + +template static Min *minimize_creator(LAMMPS *lmp) +{ + return new T(lmp); +} + /* ---------------------------------------------------------------------- */ Update::Update(LAMMPS *lmp) : Pointers(lmp) @@ -67,38 +79,36 @@ Update::Update(LAMMPS *lmp) : Pointers(lmp) integrate_map = new IntegrateCreatorMap(); #define INTEGRATE_CLASS -#define IntegrateStyle(key,Class) \ - (*integrate_map)[#key] = &integrate_creator; -#include "style_integrate.h" // IWYU pragma: keep +#define IntegrateStyle(key, Class) (*integrate_map)[#key] = &integrate_creator; +#include "style_integrate.h" // IWYU pragma: keep #undef IntegrateStyle #undef INTEGRATE_CLASS minimize_map = new MinimizeCreatorMap(); #define MINIMIZE_CLASS -#define MinimizeStyle(key,Class) \ - (*minimize_map)[#key] = &minimize_creator; +#define MinimizeStyle(key, Class) (*minimize_map)[#key] = &minimize_creator; #include "style_minimize.h" // IWYU pragma: keep #undef MinimizeStyle #undef MINIMIZE_CLASS str = (char *) "verlet"; - create_integrate(1,&str,1); + create_integrate(1, &str, 1); str = (char *) "cg"; - create_minimize(1,&str,1); + create_minimize(1, &str, 1); } /* ---------------------------------------------------------------------- */ Update::~Update() { - delete [] unit_style; + delete[] unit_style; - delete [] integrate_style; + delete[] integrate_style; delete integrate; - delete [] minimize_style; + delete[] minimize_style; delete minimize; delete integrate_map; @@ -113,8 +123,10 @@ void Update::init() // if neither (e.g. from write_restart) then just return if (whichflag == 0) return; - if (whichflag == 1) integrate->init(); - else if (whichflag == 2) minimize->init(); + if (whichflag == 1) + integrate->init(); + else if (whichflag == 2) + minimize->init(); // only set first_update if a run or minimize is being performed @@ -131,7 +143,7 @@ void Update::set_units(const char *style) double dt_old = dt; - if (strcmp(style,"lj") == 0) { + if (strcmp(style, "lj") == 0) { force->boltz = 1.0; force->hplanck = 1.0; force->mvv2e = 1.0; @@ -152,18 +164,18 @@ void Update::set_units(const char *style) dt = 0.005; neighbor->skin = 0.3; - } else if (strcmp(style,"real") == 0) { + } else if (strcmp(style, "real") == 0) { force->boltz = 0.0019872067; force->hplanck = 95.306976368; force->mvv2e = 48.88821291 * 48.88821291; force->ftm2v = 1.0 / 48.88821291 / 48.88821291; force->mv2d = 1.0 / 0.602214129; force->nktv2p = 68568.415; - force->qqr2e = 332.06371; // see also force->qqr2d_lammps_real + force->qqr2e = 332.06371; // see also force->qqr2d_lammps_real force->qe2f = 23.060549; force->vxmu2f = 1.4393264316e4; force->xxt2kmu = 0.1; - force->e_mass = 1.0/1836.1527556560675; + force->e_mass = 1.0 / 1836.1527556560675; force->hhmrr2e = 0.0957018663603261; force->mvh2r = 1.5339009481951; force->angstrom = 1.0; @@ -173,7 +185,7 @@ void Update::set_units(const char *style) dt = 1.0; neighbor->skin = 2.0; - } else if (strcmp(style,"metal") == 0) { + } else if (strcmp(style, "metal") == 0) { force->boltz = 8.617343e-5; force->hplanck = 4.135667403e-3; force->mvv2e = 1.0364269e-4; @@ -194,7 +206,7 @@ void Update::set_units(const char *style) dt = 0.001; neighbor->skin = 2.0; - } else if (strcmp(style,"si") == 0) { + } else if (strcmp(style, "si") == 0) { force->boltz = 1.3806504e-23; force->hplanck = 6.62606896e-34; force->mvv2e = 1.0; @@ -215,7 +227,7 @@ void Update::set_units(const char *style) dt = 1.0e-8; neighbor->skin = 0.001; - } else if (strcmp(style,"cgs") == 0) { + } else if (strcmp(style, "cgs") == 0) { force->boltz = 1.3806504e-16; force->hplanck = 6.62606896e-27; force->mvv2e = 1.0; @@ -236,7 +248,7 @@ void Update::set_units(const char *style) dt = 1.0e-8; neighbor->skin = 0.1; - } else if (strcmp(style,"electron") == 0) { + } else if (strcmp(style, "electron") == 0) { force->boltz = 3.16681534e-6; force->hplanck = 0.1519829846; force->mvv2e = 1.06657236; @@ -257,7 +269,7 @@ void Update::set_units(const char *style) dt = 0.001; neighbor->skin = 2.0; - } else if (strcmp(style,"micro") == 0) { + } else if (strcmp(style, "micro") == 0) { force->boltz = 1.3806504e-8; force->hplanck = 6.62606896e-13; force->mvv2e = 1.0; @@ -278,7 +290,7 @@ void Update::set_units(const char *style) dt = 2.0; neighbor->skin = 0.1; - } else if (strcmp(style,"nano") == 0) { + } else if (strcmp(style, "nano") == 0) { force->boltz = 0.013806504; force->hplanck = 6.62606896e-4; force->mvv2e = 1.0; @@ -299,15 +311,16 @@ void Update::set_units(const char *style) dt = 0.00045; neighbor->skin = 0.1; - } else error->all(FLERR,"Illegal units command"); + } else + error->all(FLERR, "Illegal units command"); - delete [] unit_style; + delete[] unit_style; unit_style = utils::strdup(style); // check if timestep was changed from default value if (!dt_default && (comm->me == 0)) { - error->warning(FLERR,"Changing timestep from {:.6} to {:.6} due to " - "changing units to {}", dt_old, dt, unit_style); + error->warning(FLERR, "Changing timestep from {:.6} to {:.6} due to changing units to {}", + dt_old, dt, unit_style); } dt_default = 1; } @@ -316,24 +329,26 @@ void Update::set_units(const char *style) void Update::create_integrate(int narg, char **arg, int trysuffix) { - if (narg < 1) error->all(FLERR,"Illegal run_style command"); + if (narg < 1) error->all(FLERR, "Illegal run_style command"); - delete [] integrate_style; + delete[] integrate_style; delete integrate; int sflag; - if (narg-1 > 0) { - new_integrate(arg[0],narg-1,&arg[1],trysuffix,sflag); + if (narg - 1 > 0) { + new_integrate(arg[0], narg - 1, &arg[1], trysuffix, sflag); } else { - new_integrate(arg[0],0,nullptr,trysuffix,sflag); + new_integrate(arg[0], 0, nullptr, trysuffix, sflag); } std::string estyle = arg[0]; if (sflag) { estyle += "/"; - if (sflag == 1) estyle += lmp->suffix; - else estyle += lmp->suffix2; + if (sflag == 1) + estyle += lmp->suffix; + else + estyle += lmp->suffix2; } integrate_style = utils::strdup(estyle); } @@ -342,8 +357,7 @@ void Update::create_integrate(int narg, char **arg, int trysuffix) create the Integrate style, first with suffix appended ------------------------------------------------------------------------- */ -void Update::new_integrate(char *style, int narg, char **arg, - int trysuffix, int &sflag) +void Update::new_integrate(char *style, int narg, char **arg, int trysuffix, int &sflag) { if (trysuffix && lmp->suffix_enable) { if (lmp->suffix) { @@ -374,36 +388,28 @@ void Update::new_integrate(char *style, int narg, char **arg, return; } - error->all(FLERR,"Illegal integrate style"); -} - -/* ---------------------------------------------------------------------- - one instance per integrate style in style_integrate.h -------------------------------------------------------------------------- */ - -template -Integrate *Update::integrate_creator(LAMMPS *lmp, int narg, char ** arg) -{ - return new T(lmp, narg, arg); + error->all(FLERR, "Illegal integrate style"); } /* ---------------------------------------------------------------------- */ void Update::create_minimize(int narg, char **arg, int trysuffix) { - if (narg < 1) error->all(FLERR,"Illegal run_style command"); + if (narg < 1) error->all(FLERR, "Illegal run_style command"); - delete [] minimize_style; + delete[] minimize_style; delete minimize; int sflag; - new_minimize(arg[0],narg-1,&arg[1],trysuffix,sflag); + new_minimize(arg[0], narg - 1, &arg[1], trysuffix, sflag); std::string estyle = arg[0]; if (sflag) { estyle += "/"; - if (sflag == 1) estyle += lmp->suffix; - else estyle += lmp->suffix2; + if (sflag == 1) + estyle += lmp->suffix; + else + estyle += lmp->suffix2; } minimize_style = utils::strdup(estyle); } @@ -412,8 +418,7 @@ void Update::create_minimize(int narg, char **arg, int trysuffix) create the Minimize style, first with suffix appended ------------------------------------------------------------------------- */ -void Update::new_minimize(char *style, int /* narg */, char ** /* arg */, - int trysuffix, int &sflag) +void Update::new_minimize(char *style, int /* narg */, char ** /* arg */, int trysuffix, int &sflag) { if (trysuffix && lmp->suffix_enable) { if (lmp->suffix) { @@ -444,17 +449,7 @@ void Update::new_minimize(char *style, int /* narg */, char ** /* arg */, return; } - error->all(FLERR,"Illegal minimize style"); -} - -/* ---------------------------------------------------------------------- - one instance per minimize style in style_minimize.h -------------------------------------------------------------------------- */ - -template -Min *Update::minimize_creator(LAMMPS *lmp) -{ - return new T(lmp); + error->all(FLERR, "Illegal minimize style"); } /* ---------------------------------------------------------------------- @@ -463,8 +458,8 @@ Min *Update::minimize_creator(LAMMPS *lmp) void Update::reset_timestep(int narg, char **arg) { - if (narg != 1) error->all(FLERR,"Illegal reset_timestep command"); - bigint newstep = utils::bnumeric(FLERR,arg[0],false,lmp); + if (narg != 1) error->all(FLERR, "Illegal reset_timestep command"); + bigint newstep = utils::bnumeric(FLERR, arg[0], false, lmp); reset_timestep(newstep); } @@ -475,7 +470,7 @@ void Update::reset_timestep(int narg, char **arg) void Update::reset_timestep(bigint newstep) { - if (newstep < 0) error->all(FLERR,"Timestep must be >= 0"); + if (newstep < 0) error->all(FLERR, "Timestep must be >= 0"); bigint oldstep = ntimestep; ntimestep = newstep; @@ -499,7 +494,7 @@ void Update::reset_timestep(bigint newstep) for (const auto &ifix : modify->get_fix_list()) if (ifix->time_depend) - error->all(FLERR, "Cannot reset timestep with time-dependent fix {} defined",ifix->style); + error->all(FLERR, "Cannot reset timestep with time-dependent fix {} defined", ifix->style); // reset eflag/vflag global so no commands will think eng/virial are current @@ -529,7 +524,7 @@ void Update::reset_timestep(bigint newstep) void Update::update_time() { - atime += (ntimestep-atimestep) * dt; + atime += (ntimestep - atimestep) * dt; atimestep = ntimestep; } @@ -540,7 +535,9 @@ void Update::update_time() double Update::memory_usage() { double bytes = 0; - if (whichflag == 1) bytes += integrate->memory_usage(); - else if (whichflag == 2) bytes += minimize->memory_usage(); + if (whichflag == 1) + bytes += integrate->memory_usage(); + else if (whichflag == 2) + bytes += minimize->memory_usage(); return bytes; } diff --git a/src/update.h b/src/update.h index 25af895bf3..f763dfa559 100644 --- a/src/update.h +++ b/src/update.h @@ -73,9 +73,6 @@ class Update : protected Pointers { private: void new_integrate(char *, int, char **, int, int &); void new_minimize(char *, int, char **, int, int &); - - template static Integrate *integrate_creator(LAMMPS *, int, char **); - template static Min *minimize_creator(LAMMPS *); }; } // namespace LAMMPS_NS