git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@10310 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
@ -71,7 +71,7 @@ if (test $1 = "style") then
|
||||
style INTEGRATE_CLASS "" integrate update
|
||||
style KSPACE_CLASS "" kspace force
|
||||
style MINIMIZE_CLASS min_ minimize update
|
||||
style PAIR_CLASS pair_ pair force pair_hybrid
|
||||
style PAIR_CLASS pair_ pair force
|
||||
style READER_CLASS reader_ reader read_dump
|
||||
style REGION_CLASS region_ region domain
|
||||
|
||||
|
||||
@ -73,6 +73,17 @@ Force::Force(LAMMPS *lmp) : Pointers(lmp)
|
||||
strcpy(improper_style,str);
|
||||
kspace_style = new char[n];
|
||||
strcpy(kspace_style,str);
|
||||
|
||||
// fill pair map with fixes listed in style_pair.h
|
||||
|
||||
pair_map = new std::map<std::string,PairCreator>();
|
||||
|
||||
#define PAIR_CLASS
|
||||
#define PairStyle(key,Class) \
|
||||
(*pair_map)[#key] = &pair_creator<Class>;
|
||||
#include "style_pair.h"
|
||||
#undef PairStyle
|
||||
#undef PAIR_CLASS
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -134,7 +145,8 @@ void Force::create_pair(const char *style, const char *suffix)
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
generate a pair class, first with suffix appended
|
||||
generate a pair class
|
||||
try first with suffix appended
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Pair *Force::new_pair(const char *style, const char *suffix, int &sflag)
|
||||
@ -144,31 +156,34 @@ Pair *Force::new_pair(const char *style, const char *suffix, int &sflag)
|
||||
char estyle[256];
|
||||
sprintf(estyle,"%s/%s",style,suffix);
|
||||
|
||||
if (0) return NULL;
|
||||
|
||||
#define PAIR_CLASS
|
||||
#define PairStyle(key,Class) \
|
||||
else if (strcmp(estyle,#key) == 0) return new Class(lmp);
|
||||
#include "style_pair.h"
|
||||
#undef PairStyle
|
||||
#undef PAIR_CLASS
|
||||
|
||||
if (pair_map->find(estyle) != pair_map->end()) {
|
||||
PairCreator pair_creator = (*pair_map)[estyle];
|
||||
return pair_creator(lmp);
|
||||
}
|
||||
}
|
||||
|
||||
sflag = 0;
|
||||
|
||||
if (strcmp(style,"none") == 0) return NULL;
|
||||
if (pair_map->find(style) != pair_map->end()) {
|
||||
PairCreator pair_creator = (*pair_map)[style];
|
||||
return pair_creator(lmp);
|
||||
}
|
||||
|
||||
#define PAIR_CLASS
|
||||
#define PairStyle(key,Class) \
|
||||
else if (strcmp(style,#key) == 0) return new Class(lmp);
|
||||
#include "style_pair.h"
|
||||
#undef PAIR_CLASS
|
||||
|
||||
else error->all(FLERR,"Invalid pair style");
|
||||
error->all(FLERR,"Invalid pair style");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
one instance per pair style in style_pair.h
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
template <typename T>
|
||||
Pair *Force::pair_creator(LAMMPS *lmp)
|
||||
{
|
||||
return new T(lmp);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
return ptr to Pair class if matches word or matches hybrid sub-style
|
||||
if exact, then style name must be exact match to word
|
||||
|
||||
@ -15,6 +15,8 @@
|
||||
#define LMP_FORCE_H
|
||||
|
||||
#include "pointers.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
@ -45,6 +47,9 @@ class Force : protected Pointers {
|
||||
class Pair *pair;
|
||||
char *pair_style;
|
||||
|
||||
typedef Pair *(*PairCreator)(LAMMPS *);
|
||||
std::map<std::string,PairCreator> *pair_map;
|
||||
|
||||
class Bond *bond;
|
||||
char *bond_style;
|
||||
|
||||
@ -98,6 +103,9 @@ class Force : protected Pointers {
|
||||
double numeric(const char *, int, char *);
|
||||
int inumeric(const char *, int, char *);
|
||||
bigint memory_usage();
|
||||
|
||||
private:
|
||||
template <typename T> static Pair *pair_creator(LAMMPS *);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -82,6 +82,17 @@ Input::Input(LAMMPS *lmp, int argc, char **argv) : Pointers(lmp)
|
||||
|
||||
variable = new Variable(lmp);
|
||||
|
||||
// fill map with commands listed in style_command.h
|
||||
|
||||
command_map = new std::map<std::string,CommandCreator>();
|
||||
|
||||
#define COMMAND_CLASS
|
||||
#define CommandStyle(key,Class) \
|
||||
(*command_map)[#key] = &command_creator<Class>;
|
||||
#include "style_command.h"
|
||||
#undef CommandStyle
|
||||
#undef COMMAND_CLASS
|
||||
|
||||
// process command-line args
|
||||
// check for args "-var" and "-echo"
|
||||
// caller has already checked that sufficient arguments exist
|
||||
@ -581,25 +592,30 @@ int Input::execute_command()
|
||||
|
||||
if (flag) return 0;
|
||||
|
||||
// check if command is added via style.h
|
||||
// invoke commands added via style_command.h
|
||||
|
||||
if (0) return 0; // dummy line to enable else-if macro expansion
|
||||
|
||||
#define COMMAND_CLASS
|
||||
#define CommandStyle(key,Class) \
|
||||
else if (strcmp(command,#key) == 0) { \
|
||||
Class key(lmp); \
|
||||
key.command(narg,arg); \
|
||||
return 0; \
|
||||
if (command_map->find(command) != command_map->end()) {
|
||||
CommandCreator command_creator = (*command_map)[command];
|
||||
command_creator(lmp,narg,arg);
|
||||
return 0;
|
||||
}
|
||||
#include "style_command.h"
|
||||
#undef COMMAND_CLASS
|
||||
|
||||
// unrecognized command
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
one instance per command in style_command.h
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
template <typename T>
|
||||
void Input::command_creator(LAMMPS *lmp, int narg, char **arg)
|
||||
{
|
||||
T cmd(lmp);
|
||||
cmd.command(narg,arg);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
|
||||
#include "stdio.h"
|
||||
#include "pointers.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
@ -49,6 +51,11 @@ class Input : protected Pointers {
|
||||
|
||||
FILE **infiles; // list of open input files
|
||||
|
||||
typedef void (*CommandCreator)(LAMMPS *, int, char **);
|
||||
std::map<std::string,CommandCreator> *command_map;
|
||||
|
||||
template <typename T> static void command_creator(LAMMPS *, int, char **);
|
||||
|
||||
void parse(); // parse an input text line
|
||||
char *nextword(char *, char **); // find next word in string with quotes
|
||||
void reallocate(char *&, int &, int); // reallocate a char string
|
||||
|
||||
119
src/modify.cpp
119
src/modify.cpp
@ -72,6 +72,28 @@ Modify::Modify(LAMMPS *lmp) : Pointers(lmp)
|
||||
|
||||
ncompute = maxcompute = 0;
|
||||
compute = NULL;
|
||||
|
||||
// fill map with fixes listed in style_fix.h
|
||||
|
||||
fix_map = new std::map<std::string,FixCreator>();
|
||||
|
||||
#define FIX_CLASS
|
||||
#define FixStyle(key,Class) \
|
||||
(*fix_map)[#key] = &fix_creator<Class>;
|
||||
#include "style_fix.h"
|
||||
#undef FixStyle
|
||||
#undef FIX_CLASS
|
||||
|
||||
// fill map with computes listed in style_compute.h
|
||||
|
||||
compute_map = new std::map<std::string,ComputeCreator>();
|
||||
|
||||
#define COMPUTE_CLASS
|
||||
#define ComputeStyle(key,Class) \
|
||||
(*compute_map)[#key] = &compute_creator<Class>;
|
||||
#include "style_compute.h"
|
||||
#undef ComputeStyle
|
||||
#undef COMPUTE_CLASS
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -666,40 +688,27 @@ void Modify::add_fix(int narg, char **arg, char *suffix)
|
||||
}
|
||||
}
|
||||
|
||||
// create the Fix, first with suffix appended
|
||||
// create the Fix
|
||||
// try first with suffix appended
|
||||
|
||||
int success = 0;
|
||||
fix[ifix] = NULL;
|
||||
|
||||
if (suffix && lmp->suffix_enable) {
|
||||
char estyle[256];
|
||||
sprintf(estyle,"%s/%s",arg[2],suffix);
|
||||
success = 1;
|
||||
|
||||
if (0) return;
|
||||
|
||||
#define FIX_CLASS
|
||||
#define FixStyle(key,Class) \
|
||||
else if (strcmp(estyle,#key) == 0) fix[ifix] = new Class(lmp,narg,arg);
|
||||
#include "style_fix.h"
|
||||
#undef FixStyle
|
||||
#undef FIX_CLASS
|
||||
|
||||
else success = 0;
|
||||
if (fix_map->find(estyle) != fix_map->end()) {
|
||||
FixCreator fix_creator = (*fix_map)[estyle];
|
||||
fix[ifix] = fix_creator(lmp,narg,arg);
|
||||
}
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
if (0) return;
|
||||
|
||||
#define FIX_CLASS
|
||||
#define FixStyle(key,Class) \
|
||||
else if (strcmp(arg[2],#key) == 0) fix[ifix] = new Class(lmp,narg,arg);
|
||||
#include "style_fix.h"
|
||||
#undef FixStyle
|
||||
#undef FIX_CLASS
|
||||
|
||||
else error->all(FLERR,"Invalid fix style");
|
||||
if (fix[ifix] == NULL && fix_map->find(arg[2]) != fix_map->end()) {
|
||||
FixCreator fix_creator = (*fix_map)[arg[2]];
|
||||
fix[ifix] = fix_creator(lmp,narg,arg);
|
||||
}
|
||||
|
||||
if (fix[ifix] == NULL) error->all(FLERR,"Invalid fix style");
|
||||
|
||||
// set fix mask values and increment nfix (if new)
|
||||
|
||||
fmask[ifix] = fix[ifix]->setmask();
|
||||
@ -738,6 +747,16 @@ void Modify::add_fix(int narg, char **arg, char *suffix)
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
one instance per fix in style_fix.h
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
template <typename T>
|
||||
Fix *Modify::fix_creator(LAMMPS *lmp, int narg, char **arg)
|
||||
{
|
||||
return new T(lmp,narg,arg);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
modify a Fix's parameters
|
||||
------------------------------------------------------------------------- */
|
||||
@ -811,45 +830,41 @@ void Modify::add_compute(int narg, char **arg, char *suffix)
|
||||
memory->srealloc(compute,maxcompute*sizeof(Compute *),"modify:compute");
|
||||
}
|
||||
|
||||
// create the Compute, first with suffix appended
|
||||
// create the Compute
|
||||
// try first with suffix appended
|
||||
|
||||
int success = 0;
|
||||
compute[ncompute] = NULL;
|
||||
|
||||
if (suffix && lmp->suffix_enable) {
|
||||
char estyle[256];
|
||||
sprintf(estyle,"%s/%s",arg[2],suffix);
|
||||
success = 1;
|
||||
|
||||
if (0) return;
|
||||
|
||||
#define COMPUTE_CLASS
|
||||
#define ComputeStyle(key,Class) \
|
||||
else if (strcmp(estyle,#key) == 0) \
|
||||
compute[ncompute] = new Class(lmp,narg,arg);
|
||||
#include "style_compute.h"
|
||||
#undef ComputeStyle
|
||||
#undef COMPUTE_CLASS
|
||||
|
||||
else success = 0;
|
||||
if (compute_map->find(estyle) != compute_map->end()) {
|
||||
ComputeCreator compute_creator = (*compute_map)[estyle];
|
||||
compute[ncompute] = compute_creator(lmp,narg,arg);
|
||||
}
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
if (0) return;
|
||||
|
||||
#define COMPUTE_CLASS
|
||||
#define ComputeStyle(key,Class) \
|
||||
else if (strcmp(arg[2],#key) == 0) \
|
||||
compute[ncompute] = new Class(lmp,narg,arg);
|
||||
#include "style_compute.h"
|
||||
#undef ComputeStyle
|
||||
#undef COMPUTE_CLASS
|
||||
|
||||
else error->all(FLERR,"Invalid compute style");
|
||||
if (compute[ncompute] == NULL &&
|
||||
compute_map->find(arg[2]) != compute_map->end()) {
|
||||
ComputeCreator compute_creator = (*compute_map)[arg[2]];
|
||||
compute[ncompute] = compute_creator(lmp,narg,arg);
|
||||
}
|
||||
|
||||
if (compute[ncompute] == NULL) error->all(FLERR,"Invalid compute style");
|
||||
|
||||
ncompute++;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
one instance per compute in style_compute.h
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
template <typename T>
|
||||
Compute *Modify::compute_creator(LAMMPS *lmp, int narg, char **arg)
|
||||
{
|
||||
return new T(lmp,narg,arg);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
modify a Compute's parameters
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
12
src/modify.h
12
src/modify.h
@ -16,6 +16,8 @@
|
||||
|
||||
#include "stdio.h"
|
||||
#include "pointers.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
@ -135,6 +137,16 @@ class Modify : protected Pointers {
|
||||
void list_init_end_of_step(int, int &, int *&);
|
||||
void list_init_thermo_energy(int, int &, int *&);
|
||||
void list_init_compute();
|
||||
|
||||
private:
|
||||
typedef Compute *(*ComputeCreator)(LAMMPS *, int, char **);
|
||||
std::map<std::string,ComputeCreator> *compute_map;
|
||||
|
||||
typedef Fix *(*FixCreator)(LAMMPS *, int, char **);
|
||||
std::map<std::string,FixCreator> *fix_map;
|
||||
|
||||
template <typename T> static Compute *compute_creator(LAMMPS *, int, char **);
|
||||
template <typename T> static Fix *fix_creator(LAMMPS *, int, char **);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
#include "string.h"
|
||||
#include "ctype.h"
|
||||
#include "pair_hybrid.h"
|
||||
#include "style_pair.h"
|
||||
#include "atom.h"
|
||||
#include "force.h"
|
||||
#include "pair.h"
|
||||
@ -211,10 +210,6 @@ void PairHybrid::settings(int narg, char **arg)
|
||||
}
|
||||
allocated = 0;
|
||||
|
||||
// build list of all known pair styles
|
||||
|
||||
build_styles();
|
||||
|
||||
// allocate list of sub-styles as big as possibly needed if no extra args
|
||||
|
||||
styles = new Pair*[narg];
|
||||
@ -223,7 +218,7 @@ void PairHybrid::settings(int narg, char **arg)
|
||||
|
||||
// allocate each sub-style
|
||||
// call settings() with set of args that are not pair style names
|
||||
// use known_style() to determine which args these are
|
||||
// use force->pair_map to determine which args these are
|
||||
|
||||
int iarg,jarg,dummy;
|
||||
|
||||
@ -239,17 +234,12 @@ void PairHybrid::settings(int narg, char **arg)
|
||||
keywords[nstyles] = new char[n];
|
||||
strcpy(keywords[nstyles],arg[iarg]);
|
||||
jarg = iarg + 1;
|
||||
while (jarg < narg && !known_style(arg[jarg])) jarg++;
|
||||
while (jarg < narg && !force->pair_map->count(arg[jarg])) jarg++;
|
||||
styles[nstyles]->settings(jarg-iarg-1,&arg[iarg+1]);
|
||||
iarg = jarg;
|
||||
nstyles++;
|
||||
}
|
||||
|
||||
// free allstyles created by build_styles()
|
||||
|
||||
for (int i = 0; i < nallstyles; i++) delete [] allstyles[i];
|
||||
delete [] allstyles;
|
||||
|
||||
// multiple[i] = 1 to M if sub-style used multiple times, else 0
|
||||
|
||||
for (int i = 0; i < nstyles; i++) {
|
||||
@ -762,45 +752,6 @@ int PairHybrid::check_ijtype(int itype, int jtype, char *substyle)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
allstyles = list of all pair styles in this LAMMPS executable
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void PairHybrid::build_styles()
|
||||
{
|
||||
nallstyles = 0;
|
||||
#define PAIR_CLASS
|
||||
#define PairStyle(key,Class) nallstyles++;
|
||||
#include "style_pair.h"
|
||||
#undef PairStyle
|
||||
#undef PAIR_CLASS
|
||||
|
||||
allstyles = new char*[nallstyles];
|
||||
|
||||
int n;
|
||||
nallstyles = 0;
|
||||
#define PAIR_CLASS
|
||||
#define PairStyle(key,Class) \
|
||||
n = strlen(#key) + 1; \
|
||||
allstyles[nallstyles] = new char[n]; \
|
||||
strcpy(allstyles[nallstyles],#key); \
|
||||
nallstyles++;
|
||||
#include "style_pair.h"
|
||||
#undef PairStyle
|
||||
#undef PAIR_CLASS
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
allstyles = list of all known pair styles
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
int PairHybrid::known_style(char *str)
|
||||
{
|
||||
for (int i = 0; i < nallstyles; i++)
|
||||
if (strcmp(str,allstyles[i]) == 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
memory usage of each sub-style
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
@ -59,14 +59,9 @@ class PairHybrid : public Pair {
|
||||
int **nmap; // # of sub-styles itype,jtype points to
|
||||
int ***map; // list of sub-styles itype,jtype points to
|
||||
|
||||
char **allstyles;
|
||||
int nallstyles;
|
||||
|
||||
void allocate();
|
||||
void flags();
|
||||
virtual void modify_requests();
|
||||
void build_styles();
|
||||
int known_style(char *);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user