add support for command plugins with example
This commit is contained in:
@ -2,7 +2,10 @@ CXX=mpicxx
|
||||
CXXFLAGS=-I../../src -Wall -Wextra -O3 -fPIC -I../../src/USER-OMP -fopenmp
|
||||
LD=$(CXX) -shared -rdynamic -fopenmp
|
||||
|
||||
default: morse2plugin.so nve2plugin.so
|
||||
default: morse2plugin.so nve2plugin.so helloplugin.so
|
||||
|
||||
helloplugin.so: helloplugin.o
|
||||
$(LD) -o $@ $^
|
||||
|
||||
morse2plugin.so: morse2plugin.o pair_morse2.o pair_morse2_omp.o
|
||||
$(LD) -o $@ $^
|
||||
@ -13,6 +16,8 @@ nve2plugin.so: nve2plugin.o fix_nve2.o
|
||||
.cpp.o:
|
||||
$(CXX) -o $@ $(CXXFLAGS) -c $<
|
||||
|
||||
helloplugin.o: helloplugin.cpp
|
||||
|
||||
pair_morse2.o: pair_morse2.cpp pair_morse2.h
|
||||
pair_morse2_omp.o: pair_morse2_omp.cpp pair_morse2_omp.h pair_morse2.h
|
||||
morse2plugin.o: morse2plugin.cpp pair_morse2.h pair_morse2_omp.h
|
||||
@ -23,4 +28,3 @@ nve2plugin.o: nve2plugin.cpp fix_nve2.h
|
||||
clean:
|
||||
rm -f *~ *.so *.o log.lammps
|
||||
|
||||
|
||||
|
||||
49
examples/plugins/helloplugin.cpp
Normal file
49
examples/plugins/helloplugin.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
#include "lammpsplugin.h"
|
||||
|
||||
#include "comm.h"
|
||||
#include "error.h"
|
||||
#include "pointers.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
class Hello : protected Pointers {
|
||||
public:
|
||||
Hello(class LAMMPS *lmp) : Pointers(lmp) {};
|
||||
void command(int, char **);
|
||||
};
|
||||
}
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
void Hello::command(int argc, char **argv)
|
||||
{
|
||||
if (argc != 1) error->all(FLERR,"Illegal hello command");
|
||||
if (comm->me == 0)
|
||||
utils::logmesg(lmp,fmt::format("Hello, {}!\n",argv[0]));
|
||||
}
|
||||
|
||||
static void hellocreator(LAMMPS *lmp, int argc, char **argv)
|
||||
{
|
||||
Hello hello(lmp);
|
||||
hello.command(argc,argv);
|
||||
}
|
||||
|
||||
extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc)
|
||||
{
|
||||
lammpsplugin_t plugin;
|
||||
lammpsplugin_regfunc register_plugin = (lammpsplugin_regfunc) regfunc;
|
||||
|
||||
plugin.version = LAMMPS_VERSION;
|
||||
plugin.style = "command";
|
||||
plugin.name = "hello";
|
||||
plugin.info = "Hello world command v1.0";
|
||||
plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)";
|
||||
plugin.creator1 = nullptr;
|
||||
plugin.creator2 = nullptr;
|
||||
plugin.creator3 = (lammpsplugin_factory3 *) &hellocreator;
|
||||
plugin.handle = handle;
|
||||
(*register_plugin)(&plugin,lmp);
|
||||
}
|
||||
@ -33,6 +33,7 @@ extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc)
|
||||
plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)";
|
||||
plugin.creator1 = (lammpsplugin_factory1 *) &morse2creator;
|
||||
plugin.creator2 = nullptr;
|
||||
plugin.creator3 = nullptr;
|
||||
plugin.handle = handle;
|
||||
(*register_plugin)(&plugin,lmp);
|
||||
|
||||
|
||||
@ -24,7 +24,9 @@ extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc)
|
||||
plugin.name = "nve2";
|
||||
plugin.info = "NVE2 variant fix style v1.0";
|
||||
plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)";
|
||||
plugin.creator1 = nullptr;
|
||||
plugin.creator2 = (lammpsplugin_factory2 *) &nve2creator;
|
||||
plugin.creator3 = nullptr;
|
||||
plugin.handle = handle;
|
||||
(*register_plugin)(&plugin,lmp);
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ extern "C" {
|
||||
|
||||
typedef void *(lammpsplugin_factory1)(void *);
|
||||
typedef void *(lammpsplugin_factory2)(void *, int, char **);
|
||||
typedef void (lammpsplugin_factory3)(void *, int, char **);
|
||||
|
||||
typedef struct {
|
||||
const char *version;
|
||||
@ -29,6 +30,7 @@ extern "C" {
|
||||
const char *author;
|
||||
lammpsplugin_factory1 *creator1;
|
||||
lammpsplugin_factory2 *creator2;
|
||||
lammpsplugin_factory3 *creator3;
|
||||
void *handle;
|
||||
} lammpsplugin_t;
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
|
||||
#include "comm.h"
|
||||
#include "error.h"
|
||||
#include "input.h"
|
||||
#include "force.h"
|
||||
#include "lammps.h"
|
||||
#include "modify.h"
|
||||
@ -128,8 +129,8 @@ namespace LAMMPS_NS
|
||||
"style {} from plugin",
|
||||
plugin->name));
|
||||
}
|
||||
|
||||
(*pair_map)[plugin->name] = (Force::PairCreator)plugin->creator1;
|
||||
|
||||
} else if (pstyle == "fix") {
|
||||
auto fix_map = lmp->modify->fix_map;
|
||||
if (fix_map->find(plugin->name) != fix_map->end()) {
|
||||
@ -138,8 +139,18 @@ namespace LAMMPS_NS
|
||||
"style {} from plugin",
|
||||
plugin->name));
|
||||
}
|
||||
|
||||
(*fix_map)[plugin->name] = (Modify::FixCreator)plugin->creator2;
|
||||
|
||||
} else if (pstyle == "command") {
|
||||
auto command_map = lmp->input->command_map;
|
||||
if (command_map->find(plugin->name) != command_map->end()) {
|
||||
if (lmp->comm->me == 0)
|
||||
lmp->error->warning(FLERR,fmt::format("Overriding built-in fix "
|
||||
"style {} from plugin",
|
||||
plugin->name));
|
||||
}
|
||||
(*command_map)[plugin->name] = (Input::CommandCreator)plugin->creator3;
|
||||
|
||||
} else {
|
||||
utils::logmesg(lmp,fmt::format("Loading plugin for {} styles not "
|
||||
"yet implemented\n",pstyle));
|
||||
|
||||
Reference in New Issue
Block a user