convert more style_creators to use local static functions
This commit is contained in:
19
src/atom.cpp
19
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 <typename T> 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 <typename T>
|
||||
AtomVec *Atom::avec_creator(LAMMPS *lmp)
|
||||
{
|
||||
return new T(lmp);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void Atom::init()
|
||||
|
||||
@ -416,9 +416,6 @@ class Atom : protected Pointers {
|
||||
void set_atomflag_defaults();
|
||||
void setup_sort_bins();
|
||||
int next_prime(int);
|
||||
|
||||
private:
|
||||
template <typename T> static AtomVec *avec_creator(LAMMPS *);
|
||||
};
|
||||
|
||||
} // namespace LAMMPS_NS
|
||||
|
||||
@ -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 <typename T> 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 <typename T>
|
||||
Region *Domain::region_creator(LAMMPS *lmp, int narg, char ** arg)
|
||||
{
|
||||
return new T(lmp, narg, arg);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
delete a region
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
@ -175,9 +175,6 @@ class Domain : protected Pointers {
|
||||
|
||||
protected:
|
||||
double small[3]; // fractions of box lengths
|
||||
|
||||
private:
|
||||
template <typename T> static Region *region_creator(LAMMPS *, int, char **);
|
||||
};
|
||||
|
||||
} // namespace LAMMPS_NS
|
||||
|
||||
@ -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 <typename S, typename T> 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<Class>; \
|
||||
binclass[nbclass] = &style_creator<NBin, Class>; \
|
||||
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<Class>; \
|
||||
stencilclass[nsclass] = &style_creator<NStencil, Class>; \
|
||||
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<Class>; \
|
||||
pairclass[npclass] = &style_creator<NPair, Class>; \
|
||||
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 <typename T>
|
||||
NBin *Neighbor::bin_creator(LAMMPS *lmp)
|
||||
{
|
||||
return new T(lmp);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
one instance per entry in style_neigh_stencil.h
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
template <typename T>
|
||||
NStencil *Neighbor::stencil_creator(LAMMPS *lmp)
|
||||
{
|
||||
return new T(lmp);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
one instance per entry in style_neigh_pair.h
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
template <typename T>
|
||||
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
|
||||
|
||||
@ -231,10 +231,6 @@ class Neighbor : protected Pointers {
|
||||
int choose_stencil(class NeighRequest *);
|
||||
int choose_pair(class NeighRequest *);
|
||||
|
||||
template <typename T> static NBin *bin_creator(class LAMMPS *);
|
||||
template <typename T> static NStencil *stencil_creator(class LAMMPS *);
|
||||
template <typename T> static NPair *pair_creator(class LAMMPS *);
|
||||
|
||||
// dummy functions provided by NeighborKokkos, called in init()
|
||||
// otherwise NeighborKokkos would have to overwrite init()
|
||||
|
||||
|
||||
@ -43,6 +43,15 @@ using namespace LAMMPS_NS;
|
||||
|
||||
enum {SETUP, WRITE, RESET_DT};
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
one instance per dump style in style_dump.h
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
template <typename T> 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 <typename T>
|
||||
Dump *Output::dump_creator(LAMMPS *lmp, int narg, char ** arg)
|
||||
{
|
||||
return new T(lmp, narg, arg);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
modify parameters of a Dump
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
@ -93,7 +93,6 @@ class Output : protected Pointers {
|
||||
void memory_usage(); // print out memory usage
|
||||
|
||||
private:
|
||||
template <typename T> static Dump *dump_creator(LAMMPS *, int, char **);
|
||||
void calculate_next_dump(int, int, bigint);
|
||||
};
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// clang-format off
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
@ -19,10 +18,10 @@
|
||||
|
||||
#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 <typename T> static Integrate *integrate_creator(LAMMPS *lmp, int narg, char **arg)
|
||||
{
|
||||
return new T(lmp, narg, arg);
|
||||
}
|
||||
|
||||
template <typename T> static Min *minimize_creator(LAMMPS *lmp)
|
||||
{
|
||||
return new T(lmp);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
Update::Update(LAMMPS *lmp) : Pointers(lmp)
|
||||
@ -67,8 +79,7 @@ Update::Update(LAMMPS *lmp) : Pointers(lmp)
|
||||
integrate_map = new IntegrateCreatorMap();
|
||||
|
||||
#define INTEGRATE_CLASS
|
||||
#define IntegrateStyle(key,Class) \
|
||||
(*integrate_map)[#key] = &integrate_creator<Class>;
|
||||
#define IntegrateStyle(key, Class) (*integrate_map)[#key] = &integrate_creator<Class>;
|
||||
#include "style_integrate.h" // IWYU pragma: keep
|
||||
#undef IntegrateStyle
|
||||
#undef INTEGRATE_CLASS
|
||||
@ -76,8 +87,7 @@ Update::Update(LAMMPS *lmp) : Pointers(lmp)
|
||||
minimize_map = new MinimizeCreatorMap();
|
||||
|
||||
#define MINIMIZE_CLASS
|
||||
#define MinimizeStyle(key,Class) \
|
||||
(*minimize_map)[#key] = &minimize_creator<Class>;
|
||||
#define MinimizeStyle(key, Class) (*minimize_map)[#key] = &minimize_creator<Class>;
|
||||
#include "style_minimize.h" // IWYU pragma: keep
|
||||
#undef MinimizeStyle
|
||||
#undef MINIMIZE_CLASS
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
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;
|
||||
}
|
||||
@ -332,8 +345,10 @@ void Update::create_integrate(int narg, char **arg, int trysuffix)
|
||||
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) {
|
||||
@ -377,16 +391,6 @@ void Update::new_integrate(char *style, int narg, char **arg,
|
||||
error->all(FLERR, "Illegal integrate style");
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
one instance per integrate style in style_integrate.h
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
template <typename T>
|
||||
Integrate *Update::integrate_creator(LAMMPS *lmp, int narg, char ** arg)
|
||||
{
|
||||
return new T(lmp, narg, arg);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void Update::create_minimize(int narg, char **arg, int trysuffix)
|
||||
@ -402,8 +406,10 @@ void Update::create_minimize(int narg, char **arg, int trysuffix)
|
||||
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) {
|
||||
@ -447,16 +452,6 @@ void Update::new_minimize(char *style, int /* narg */, char ** /* arg */,
|
||||
error->all(FLERR, "Illegal minimize style");
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
one instance per minimize style in style_minimize.h
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
template <typename T>
|
||||
Min *Update::minimize_creator(LAMMPS *lmp)
|
||||
{
|
||||
return new T(lmp);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
reset timestep called from input script
|
||||
------------------------------------------------------------------------- */
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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 <typename T> static Integrate *integrate_creator(LAMMPS *, int, char **);
|
||||
template <typename T> static Min *minimize_creator(LAMMPS *);
|
||||
};
|
||||
|
||||
} // namespace LAMMPS_NS
|
||||
|
||||
Reference in New Issue
Block a user