changes to use new MDI library functions

This commit is contained in:
Steve Plimpton
2022-04-13 16:26:48 -06:00
parent 0946d41c3f
commit bc2b600f09
6 changed files with 37 additions and 38 deletions

View File

@ -23,7 +23,7 @@ fix 1 all nve
# NPT
#fix 1 all npt temp 1.0 1.0 0.1 iso 1.0 1.0 1.0
fix 2 all mdi/aimd plugin
fix 2 all mdi/aimd
fix_modify 2 energy yes virial yes
thermo_style custom step temp pe etotal press vol

View File

@ -34,7 +34,7 @@ make lib-meam args="-m ifort" # build MEAM lib with custom Makefile.ifort (usi
# settings
version = "1.3.0"
version = "1.3.1"
url = "https://github.com/MolSSI-MDI/MDI_Library/archive/v%s.tar.gz" % version
# known checksums for different MDI versions. used to validate the download.

View File

@ -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,29 @@ int FixMDIAimd::setmask()
/* ---------------------------------------------------------------------- */
void FixMDIAimd::init()
{
if (mdicomm != MDI_COMM_NULL) return;
// one-time initialization of mdicomm
// plugin = 0/1 if MDI engine is a stand-alone code vs plugin library
MDI_Get_communicator(&mdicomm,0);
if (mdicomm == MDI_COMM_NULL) {
plugin = 0;
MDI_Accept_communicator(&mdicomm);
if (mdicomm <= 0) error->all(FLERR,"Unable to connect to MDI engine");
} else {
plugin = 1;
int method;
MDI_Get_method(&method,mdicomm);
if (method != MDI_PLUGIN) error->all(FLERR,"MDI internal error");
}
}
/* ---------------------------------------------------------------------- */
void FixMDIAimd::setup(int vflag)
{
post_force(vflag);

View File

@ -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;

View File

@ -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

View File

@ -25,7 +25,6 @@ class MDIPlugin : protected Pointers {
private:
char *lammps_command;
class Fix *fixptr;
static int plugin_wrapper(void *, MDI_Comm, void *);
};