Merge pull request #3218 from lammps/mdi-new-functions
MDI new functions
This commit is contained in:
@ -29,7 +29,7 @@ enum { NATIVE, REAL, METAL }; // LAMMPS units which MDI supports
|
||||
|
||||
FixMDIAimd::FixMDIAimd(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
|
||||
{
|
||||
if (narg > 4) error->all(FLERR, "Illegal fix mdi/aimd command");
|
||||
if (narg != 3) error->all(FLERR, "Illegal fix mdi/aimd command");
|
||||
|
||||
scalar_flag = 1;
|
||||
global_freq = 1;
|
||||
@ -38,16 +38,6 @@ FixMDIAimd::FixMDIAimd(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
|
||||
virial_global_flag = 1;
|
||||
thermo_energy = thermo_virial = 1;
|
||||
|
||||
// check for plugin arg
|
||||
|
||||
plugin = 0;
|
||||
if (narg == 4) {
|
||||
if (strcmp(arg[3], "plugin") == 0)
|
||||
plugin = 1;
|
||||
else
|
||||
error->all(FLERR, "Illegal fix mdi/aimd command");
|
||||
}
|
||||
|
||||
// check requirements for LAMMPS to work with MDI as an engine
|
||||
|
||||
if (atom->tag_enable == 0) error->all(FLERR, "Cannot use MDI engine without atom IDs");
|
||||
@ -62,6 +52,11 @@ FixMDIAimd::FixMDIAimd(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
|
||||
if (role != MDI_DRIVER)
|
||||
error->all(FLERR, "Must invoke LAMMPS as an MDI driver to use fix mdi/aimd");
|
||||
|
||||
// mdicomm will be one-time initialized in init()
|
||||
// cannot be done here for a plugin library, b/c mdi plugin command is later
|
||||
|
||||
mdicomm = MDI_COMM_NULL;
|
||||
|
||||
// storage for all atoms
|
||||
|
||||
buf3 = buf3all = nullptr;
|
||||
@ -78,13 +73,6 @@ FixMDIAimd::FixMDIAimd(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
|
||||
|
||||
unit_conversions();
|
||||
|
||||
// connect to MDI engine, only if engine is stand-alone code
|
||||
|
||||
if (!plugin) {
|
||||
MDI_Accept_communicator(&mdicomm);
|
||||
if (mdicomm <= 0) error->all(FLERR, "Unable to connect to MDI engine");
|
||||
}
|
||||
|
||||
nprocs = comm->nprocs;
|
||||
}
|
||||
|
||||
@ -92,7 +80,8 @@ FixMDIAimd::FixMDIAimd(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
|
||||
|
||||
FixMDIAimd::~FixMDIAimd()
|
||||
{
|
||||
// send exit command to engine, only if engine is stand-alone code
|
||||
// send exit command to engine if it is a stand-alone code
|
||||
// for plugin, this happens in MDIPlugin::plugin_wrapper()
|
||||
|
||||
if (!plugin) {
|
||||
int ierr = MDI_Send_command("EXIT", mdicomm);
|
||||
@ -118,6 +107,30 @@ int FixMDIAimd::setmask()
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixMDIAimd::init()
|
||||
{
|
||||
if (mdicomm != MDI_COMM_NULL) return;
|
||||
|
||||
// one-time auto-detect whether engine is stand-alone code or plugin library
|
||||
// also initializes mdicomm
|
||||
// plugin = 0/1 for engine = stand-alone code vs plugin library
|
||||
|
||||
MDI_Get_communicator(&mdicomm, 0);
|
||||
|
||||
if (mdicomm == MDI_COMM_NULL) {
|
||||
plugin = 0;
|
||||
MDI_Accept_communicator(&mdicomm);
|
||||
if (mdicomm == MDI_COMM_NULL) error->all(FLERR, "MDI unable to connect to stand-alone engine");
|
||||
} else {
|
||||
plugin = 1;
|
||||
int method;
|
||||
MDI_Get_method(&method, mdicomm);
|
||||
if (method != MDI_PLUGIN) error->all(FLERR, "MDI internal error for plugin engine");
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixMDIAimd::setup(int vflag)
|
||||
{
|
||||
post_force(vflag);
|
||||
|
||||
@ -27,14 +27,11 @@ namespace LAMMPS_NS {
|
||||
|
||||
class FixMDIAimd : public Fix {
|
||||
public:
|
||||
// MDI communicator, public so that LAMMPS can work with a plugin
|
||||
|
||||
MDI_Comm mdicomm;
|
||||
|
||||
FixMDIAimd(class LAMMPS *, int, char **);
|
||||
~FixMDIAimd();
|
||||
int setmask();
|
||||
|
||||
void init();
|
||||
void setup(int);
|
||||
void setup_pre_reverse(int, int);
|
||||
void pre_reverse(int, int);
|
||||
@ -46,6 +43,8 @@ class FixMDIAimd : public Fix {
|
||||
int nprocs;
|
||||
int plugin;
|
||||
|
||||
MDI_Comm mdicomm;
|
||||
|
||||
int eflag_caller;
|
||||
double engine_energy;
|
||||
int lmpunits;
|
||||
|
||||
@ -601,7 +601,8 @@ void MDIEngine::mdi_md()
|
||||
// delete the instance before this method returns
|
||||
|
||||
modify->add_fix("MDI_ENGINE_INTERNAL all MDI/ENGINE");
|
||||
FixMDIEngine *mdi_fix = dynamic_cast<FixMDIEngine *>( modify->get_fix_by_id("MDI_ENGINE_INTERNAL"));
|
||||
FixMDIEngine *mdi_fix =
|
||||
dynamic_cast<FixMDIEngine *>(modify->get_fix_by_id("MDI_ENGINE_INTERNAL"));
|
||||
mdi_fix->mdi_engine = this;
|
||||
|
||||
// initialize LAMMPS and setup() the simulation
|
||||
@ -723,7 +724,8 @@ void MDIEngine::mdi_optg()
|
||||
// delete the instance before this method returns
|
||||
|
||||
modify->add_fix("MDI_ENGINE_INTERNAL all MDI/ENGINE");
|
||||
FixMDIEngine *mdi_fix = dynamic_cast<FixMDIEngine *>( modify->get_fix_by_id("MDI_ENGINE_INTERNAL"));
|
||||
FixMDIEngine *mdi_fix =
|
||||
dynamic_cast<FixMDIEngine *>(modify->get_fix_by_id("MDI_ENGINE_INTERNAL"));
|
||||
mdi_fix->mdi_engine = this;
|
||||
|
||||
// initialize LAMMPS and setup() the simulation
|
||||
@ -956,7 +958,8 @@ void MDIEngine::create_system()
|
||||
// optionally set charges if specified by ">CHARGES"
|
||||
|
||||
if (flag_velocities)
|
||||
lammps_create_atoms(lmp, sys_natoms, nullptr, sys_types, sys_coords, sys_velocities, nullptr, 1);
|
||||
lammps_create_atoms(lmp, sys_natoms, nullptr, sys_types, sys_coords, sys_velocities, nullptr,
|
||||
1);
|
||||
else
|
||||
lammps_create_atoms(lmp, sys_natoms, nullptr, sys_types, sys_coords, nullptr, nullptr, 1);
|
||||
|
||||
|
||||
@ -92,11 +92,6 @@ MDIPlugin::MDIPlugin(LAMMPS *_lmp, int narg, char **arg) : Pointers(_lmp)
|
||||
strcat(plugin_args, extra_arg);
|
||||
}
|
||||
|
||||
// find FixMDIAimd instance so can reset its mdicomm
|
||||
// NOTE: this is a kludge - need better way to handle this
|
||||
|
||||
fixptr = modify->get_fix_by_style("mdi/aimd")[0];
|
||||
|
||||
// launch the MDI plugin library
|
||||
// path for lib was specified in -mdi command-line arg when LAMMPS started
|
||||
// this calls back to plugin_wrapper, which must issue MDI EXIT at end
|
||||
@ -108,8 +103,7 @@ MDIPlugin::MDIPlugin(LAMMPS *_lmp, int narg, char **arg) : Pointers(_lmp)
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
callback function from MDI_Launch_plugin()
|
||||
this function must wrap entire interaction of LAMMPS as a driver
|
||||
with the plugin
|
||||
this function wraps entire interaction of LAMMPS driver with the plugin
|
||||
---------------------------------------------------------------------- */
|
||||
|
||||
int MDIPlugin::plugin_wrapper(void * /*pmpicomm*/, MDI_Comm mdicomm, void *vptr)
|
||||
@ -118,11 +112,6 @@ int MDIPlugin::plugin_wrapper(void * /*pmpicomm*/, MDI_Comm mdicomm, void *vptr)
|
||||
LAMMPS *lammps = ptr->lmp;
|
||||
char *lammps_command = ptr->lammps_command;
|
||||
|
||||
// set FixMDIAimd mdicomm to driver's mdicomm passed to this callback
|
||||
|
||||
auto aimdptr = dynamic_cast<FixMDIAimd *> (ptr->fixptr);
|
||||
aimdptr->mdicomm = mdicomm;
|
||||
|
||||
// invoke the specified LAMMPS command
|
||||
// that operation will issue MDI commands to the plugin engine
|
||||
|
||||
|
||||
@ -25,7 +25,6 @@ class MDIPlugin : protected Pointers {
|
||||
|
||||
private:
|
||||
char *lammps_command;
|
||||
class Fix *fixptr;
|
||||
|
||||
static int plugin_wrapper(void *, MDI_Comm, void *);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user