altering how plugin mode works

This commit is contained in:
Steve Plimpton
2022-04-06 15:24:02 -06:00
parent 4fadf4c830
commit 4bd28cf920
10 changed files with 344 additions and 195 deletions

View File

@ -29,6 +29,6 @@ fix_modify 2 energy yes virial yes
thermo_style custom step temp pe etotal press vol
thermo 1
mdi/plugin lammps mdi "-role ENGINE -name lammps -method LINK" &
mdi plugin lammps mdi "-role ENGINE -name lammps -method LINK" &
infile in.aimd.engine extra "-log log.aimd.engine.plugin" &
command "run 5"

View File

@ -137,20 +137,14 @@ def perform_tasks(world,mdicomm,dummy):
if mode == "eval":
pass
elif mode == "run":
print("SENDING INIT_MD")
mdi.MDI_Send_command("@INIT_MD",mdicomm)
print("SENDING NITERATE")
mdi.MDI_Send_command(">NITERATE",mdicomm)
print("SENDING NITERATE data nsteps")
mdi.MDI_Send_command(">NSTEPS",mdicomm)
mdi.MDI_Send(nsteps,1,mdi.MDI_INT,mdicomm)
print("SENDING DEFAULT")
mdi.MDI_Send_command("@DEFAULT",mdicomm)
mdi.MDI_Send_command("MD",mdicomm)
elif mode == "min":
mdi.MDI_Send_command("@INIT_OPTG",mdicomm)
mdi.MDI_Send_command(">TOLERANCE",mdicomm)
params = [tol,tol,1000.0,1000.0]
mdi.MDI_Send(params,4,mdi.MDI_DOUBLE,mdicomm)
mdi.MDI_Send_command("@DEFAULT",mdicomm)
mdi.MDI_Send_command("OPTG",mdicomm)
# request potential energy
@ -311,7 +305,6 @@ if not plugin:
# MDI will call back to perform_tasks()
if plugin:
#error("Cannot yet run in plugin mode")
mdi.MDI_Init(mdiarg)
world = MPI.COMM_WORLD
plugin_args += " -mdi \"-role ENGINE -name lammps -method LINK\""

View File

@ -131,7 +131,6 @@ The function executes a single command from an external MDI driver.
int lammps_execute_mdi_command(const char *command, MDI_Comm comm, void *class_obj)
{
printf("LIB wrapper command %s\n",command);
MDIEngine *mdi_engine = (MDIEngine *) class_obj;
return mdi_engine->execute_command(command,comm);
}

36
src/MDI/mdi_command.cpp Normal file
View File

@ -0,0 +1,36 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/ Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "mdi_command.h"
#include <cstring>
#include "mdi_engine.h"
#include "mdi_plugin.h"
#include "error.h"
using namespace LAMMPS_NS;
/* ----------------------------------------------------------------------
mdi command: engine or plugin
---------------------------------------------------------------------- */
void MDICommand::command(int narg, char **arg)
{
if (narg < 1) error->all(FLERR,"Illegal mdi command");
if (strcmp(arg[0],"engine") == 0) {
MDIEngine(lmp,narg-1,&arg[1]);
} else if (strcmp(arg[0],"plugin") == 0) {
MDIPlugin(lmp,narg-1,&arg[1]);
} else error->all(FLERR,"Illegal mdi command");
}

48
src/MDI/mdi_command.h Normal file
View File

@ -0,0 +1,48 @@
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/ Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifdef COMMAND_CLASS
// clang-format off
CommandStyle(mdi,MDICommand);
// clang-format on
#else
#ifndef LMP_MDI_COMMAND_H
#define LMP_MDI_COMMAND_H
#include "command.h"
#include "mdi.h"
namespace LAMMPS_NS {
class MDICommand : public Command {
public:
MDICommand(LAMMPS *lmp) : Command(lmp) {}
void command(int, char **) override;
};
}
#endif
#endif
/* ERROR/WARNING messages:
E: Illegal ... command
Self-explanatory. Check the input script syntax and compare to the
documentation for the command. You can use -echo screen as a
command-line option when running LAMMPS to see the offending line.
*/

View File

@ -53,19 +53,6 @@ enum{DEFAULT,MD,OPT}; // top-level MDI engine modes
enum{TYPE,CHARGE,MASS,COORD,VELOCITY,FORCE,ADDFORCE};
/* ----------------------------------------------------------------------
mdi command: engine
may later have other MDI command variants
---------------------------------------------------------------------- */
void MDIEngine::command(int narg, char **arg)
{
if (narg < 1) error->all(FLERR,"Illegal mdi command");
if (strcmp(arg[0],"engine") == 0) mdi_engine(narg-1,&arg[1]);
else error->all(FLERR,"Illegal mdi command");
}
/* ----------------------------------------------------------------------
trigger LAMMPS to start acting as an MDI engine
either in standalone mode or plugin mode
@ -75,8 +62,8 @@ void MDIEngine::command(int narg, char **arg)
when EXIT command is received, mdi engine command exits
---------------------------------------------------------------------- */
void MDIEngine::mdi_engine(int narg, char **arg)
{
MDIEngine::MDIEngine(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
{
if (narg) error->all(FLERR,"Illegal mdi engine command");
// check requirements for LAMMPS to work with MDI as an engine
@ -159,8 +146,16 @@ void MDIEngine::mdi_engine(int narg, char **arg)
sys_natoms = atom->natoms;
reallocate();
nsteps = 0;
etol = ftol = 1.0e-6;
niterate = -1;
max_eval = std::numeric_limits<int>::max();
nbytes = -1;
actionflag = 0;
// define MDI commands that LAMMPS engine recognizes
mdi_commands();
@ -186,16 +181,12 @@ void MDIEngine::mdi_engine(int narg, char **arg)
// top-level mdi engine only recognizes three nodes
// DEFAULT, INIT_MD, INIT_OPTG
printf("MAIN LOOP pre engine_node DEF\n");
engine_node("@DEFAULT");
printf("MAIN LOOP post engine_node DEF\n");
// MDI commands for dynamics or minimization
if (strcmp(mdicmd,"@INIT_MD") == 0) {
printf("MAIN LOOP pre mdi_md\n");
mdi_md();
printf("MAIN LOOP post mdi_md\n");
if (exit_command) break;
} else if (strcmp(mdicmd,"@INIT_OPTG") == 0) {
@ -255,8 +246,6 @@ void MDIEngine::engine_node(const char *node)
// read the next command from the driver
// all procs call this, but only proc 0 receives the command
printf("PRE MDI RECV_command: node eng/drv: %s/%s\n",node_engine,node_driver);
ierr = MDI_Recv_command(mdicmd,mdicomm);
if (ierr) error->all(FLERR,"MDI: Unable to receive command from driver");
@ -264,8 +253,6 @@ void MDIEngine::engine_node(const char *node)
MPI_Bcast(mdicmd,MDI_COMMAND_LENGTH,MPI_CHAR,0,world);
printf("POST MDI RECV_command: node eng/drv: %s/%s\n",mdicmd);
// execute the command
execute_command(mdicmd,mdicomm);
@ -314,8 +301,6 @@ int MDIEngine::execute_command(const char *command, MDI_Comm mdicomm)
// receives first, sends second, node commands third
// ---------------------------------------
printf("ABOUT to process command %s\n",command);
if (strcmp(command,">CELL") == 0) {
receive_cell();
@ -337,6 +322,12 @@ int MDIEngine::execute_command(const char *command, MDI_Comm mdicomm)
} else if (strcmp(command,">NATOMS") == 0) {
receive_natoms();
} else if (strcmp(command,">NSTEPS") == 0) {
receive_nsteps();
} else if (strcmp(command,">TOLERANCE") == 0) {
receive_tolerance();
} else if (strcmp(command,">TYPES") == 0) {
receive_types();
@ -363,11 +354,11 @@ int MDIEngine::execute_command(const char *command, MDI_Comm mdicomm)
send_double3(COORD);
} else if (strcmp(command,"<ENERGY") == 0) {
if (strcmp(node_engine,"@DEFAULT") == 0) evaluate();
if (!actionflag && strcmp(node_engine,"@DEFAULT") == 0) evaluate();
send_total_energy();
} else if (strcmp(command,"<FORCES") == 0) {
if (strcmp(node_engine,"@DEFAULT") == 0) evaluate();
if (!actionflag && strcmp(node_engine,"@DEFAULT") == 0) evaluate();
send_double3(FORCE);
} else if (strcmp(command,"<LABELS") == 0) {
@ -380,11 +371,11 @@ int MDIEngine::execute_command(const char *command, MDI_Comm mdicomm)
send_natoms();
} else if (strcmp(command,"<PE") == 0) {
if (strcmp(node_engine,"@DEFAULT") == 0) evaluate();
if (!actionflag && strcmp(node_engine,"@DEFAULT") == 0) evaluate();
send_pe();
} else if (strcmp(command,"<STRESS") == 0) {
if (strcmp(node_engine,"@DEFAULT") == 0) evaluate();
if (!actionflag && strcmp(node_engine,"@DEFAULT") == 0) evaluate();
send_stress();
} else if (strcmp(command,"<TYPES") == 0) {
@ -393,6 +384,18 @@ int MDIEngine::execute_command(const char *command, MDI_Comm mdicomm)
} else if (strcmp(command,"<VELOCITIES") == 0) {
send_double3(VELOCITY);
// -----------------------------------------------
// MDI action commands at @DEFAULT node
} else if (strcmp(command,"MD") == 0) {
md();
} else if (strcmp(command,"OPTG") == 0) {
optg();
// -----------------------------------------------
// MDI node commands
} else if (strcmp(command,"@INIT_MD") == 0) {
@ -447,10 +450,6 @@ int MDIEngine::execute_command(const char *command, MDI_Comm mdicomm)
many_commands();
} else if (strcmp(command,"INFILE") == 0) {
infile();
} else if (strcmp(command,">NITERATE") == 0) {
receive_niterate();
} else if (strcmp(command,">TOLERANCE") == 0) {
receive_tolerance();
} else if (strcmp(command,"<KE") == 0) {
send_ke();
@ -495,8 +494,12 @@ void MDIEngine::mdi_commands()
MDI_Register_command("@DEFAULT",">CHARGES");
MDI_Register_command("@DEFAULT",">COORDS");
MDI_Register_command("@DEFAULT",">NATOMS");
MDI_Register_command("@DEFAULT",">NSTEPS");
MDI_Register_command("@DEFAULT",">TOLERANCE");
MDI_Register_command("@DEFAULT",">TYPES");
MDI_Register_command("@DEFAULT",">VELOCITIES");
MDI_Register_command("@DEFAULT","MD");
MDI_Register_command("@DEFAULT","OPTG");
MDI_Register_command("@DEFAULT","@INIT_MD");
MDI_Register_command("@DEFAULT","@INIT_OPTG");
MDI_Register_command("@DEFAULT","EXIT");
@ -513,7 +516,6 @@ void MDIEngine::mdi_commands()
MDI_Register_node("@INIT_MD");
MDI_Register_command("@INIT_MD","<@");
MDI_Register_command("@INIT_MD",">NITERATE");
MDI_Register_command("@INIT_MD","@");
MDI_Register_command("@INIT_MD","@DEFAULT");
MDI_Register_command("@INIT_MD","@COORDS");
@ -525,7 +527,6 @@ void MDIEngine::mdi_commands()
MDI_Register_node("@INIT_OPTG");
MDI_Register_command("@INIT_OPTG","<@");
MDI_Register_command("@INIT_OPTG",">TOLERANCE");
MDI_Register_command("@INIT_OPTG","@");
MDI_Register_command("@INIT_OPTG","@DEFAULT");
MDI_Register_command("@INIT_OPTG","@COORDS");
@ -593,9 +594,7 @@ void MDIEngine::mdi_commands()
}
/* ----------------------------------------------------------------------
run MD simulation
either for NITERATE steps or one step at a time
latter is controlled by driver
run MD simulation one step at a time, controlled by driver
---------------------------------------------------------------------- */
void MDIEngine::mdi_md()
@ -611,17 +610,6 @@ void MDIEngine::mdi_md()
if (flag_velocities) adjust_velocities();
}
// engine is now at @INIT_MD node
// receive >NITERATE command if driver sends, else niterate = -1
// any @ command from driver will start the simulation
niterate = -1;
printf("PRE @INIT_MD\n");
engine_node("@INIT_MD");
printf("POST @INIT_MD %s\n",mdicmd);
if (strcmp(mdicmd,"EXIT") == 0) return;
// add an instance of fix MDI/ENGINE
// delete the instance before this method returns
@ -631,47 +619,45 @@ void MDIEngine::mdi_md()
mdi_fix->mdi_engine = this;
// initialize LAMMPS and setup() the simulation
// set nsteps to niterate if >= 0, else set to 1
update->whichflag = 1;
timer->init_timeout();
update->nsteps = (niterate >= 0) ? niterate : 1;
update->nsteps = 1;
update->beginstep = update->firststep = update->ntimestep;
update->endstep = update->laststep = update->ntimestep + update->nsteps;
lmp->init();
update->integrate->setup(1);
// engine is now at @INIT_MD node
// any @ command from driver will start the simulation
engine_node("@INIT_MD");
if (strcmp(mdicmd,"EXIT") == 0) return;
// run one step at a time forever
// driver triggers exit with @ command other than @COORDS,@FORCES,@ENDSTEP
timer->init();
timer->barrier_start();
// if niterate >= 0, run for niterate steps
// else if niterate < 0:
// run one step at a time forever
// driver triggers exit with @ command other than @COORDS,@FORCES,@ENDSTEP
if (niterate >= 0) {
update->integrate->run(niterate);
} else {
while (true) {
update->nsteps += 1;
update->laststep += 1;
update->endstep = update->laststep;
output->next = update->ntimestep + 1;
update->integrate->run(1);
if (strcmp(mdicmd,"@COORDS") != 0 &&
strcmp(mdicmd,"@FORCES") != 0 &&
strcmp(mdicmd,"@ENDSTEP") != 0) break;
}
while (true) {
update->nsteps += 1;
update->laststep += 1;
update->endstep = update->laststep;
output->next = update->ntimestep + 1;
update->integrate->run(1);
if (strcmp(mdicmd,"@COORDS") != 0 &&
strcmp(mdicmd,"@FORCES") != 0 &&
strcmp(mdicmd,"@ENDSTEP") != 0) break;
}
timer->barrier_stop();
update->integrate->cleanup();
modify->delete_fix("MDI_ENGINE_INTERNAL");
// clear flags
@ -681,9 +667,54 @@ void MDIEngine::mdi_md()
}
/* ----------------------------------------------------------------------
perform minimization
either to convergence using >TOLERANCE settings or one iteration at a time
latter is controlled by driver
run MD simulation for >NSTEPS
---------------------------------------------------------------------- */
void MDIEngine::md()
{
// create or update system if requested prior to MD command
int flag_create = flag_natoms | flag_types;
if (flag_create) create_system();
else {
if (flag_cell || flag_cell_displ) adjust_box();
if (flag_charges) adjust_charges();
if (flag_coords) adjust_coords();
if (flag_velocities) adjust_velocities();
}
// initialize LAMMPS and setup() the simulation
// run the simulation for nsteps
// clean up
update->whichflag = 1;
timer->init_timeout();
update->nsteps = nsteps;
update->beginstep = update->firststep = update->ntimestep;
update->endstep = update->laststep = update->ntimestep + update->nsteps;
lmp->init();
update->integrate->setup(1);
timer->init();
timer->barrier_start();
update->integrate->run(nsteps);
timer->barrier_stop();
update->integrate->cleanup();
// clear flags
flag_natoms = flag_types = 0;
flag_cell = flag_cell_displ = flag_charges = flag_coords = flag_velocities = 0;
actionflag = 1;
}
/* ----------------------------------------------------------------------
perform minimization one iteration at a time, controlled by driver
---------------------------------------------------------------------- */
void MDIEngine::mdi_optg()
@ -699,16 +730,6 @@ void MDIEngine::mdi_optg()
if (flag_velocities) adjust_velocities();
}
// engine is now at @INIT_OPTG node
// receive >TOLERANCE if driver sends
etol = ftol = 1.0e-6;
niterate = -1;
max_eval = std::numeric_limits<int>::max();
engine_node("@INIT_OPTG");
if (strcmp(mdicmd,"EXIT") == 0) return;
// add an instance of fix MDI/ENGINE
// delete the instance before this method returns
@ -718,7 +739,76 @@ void MDIEngine::mdi_optg()
mdi_fix->mdi_engine = this;
// initialize LAMMPS and setup() the simulation
// set nsteps to niterate if >= 0 via >TOLERANCE, else set to huge value
update->whichflag = 2;
timer->init_timeout();
update->nsteps = (niterate >= 0) ? niterate : max_eval;
update->beginstep = update->firststep = update->ntimestep;
update->endstep = update->laststep = update->firststep + update->nsteps;
update->etol = 0.0;
update->ftol = 0.0;
update->max_eval = std::numeric_limits<int>::max();
lmp->init();
update->minimize->setup();
// engine is now at @INIT_OPTG node
// any @ command from driver will start the minimization
engine_node("@INIT_OPTG");
if (strcmp(mdicmd,"EXIT") == 0) return;
// run one iteration at a time forever
// driver triggers exit with @ command other than @COORDS,@FORCES
// two issues with running in this mode:
// @COORDS and @FORCES are not just triggered per min iteration
// but also for line search eng/force evals
// if driver triggers exit on step that is not multiple of thermo output
// then energy/virial not computed, and <PE, <STRESS will fail
timer->init();
timer->barrier_start();
while (1) {
update->minimize->run(1);
if (strcmp(mdicmd,"@COORDS") != 0 &&
strcmp(mdicmd,"@FORCES") != 0) break;
}
timer->barrier_stop();
update->minimize->cleanup();
modify->delete_fix("MDI_ENGINE_INTERNAL");
// clear flags
flag_natoms = flag_types = 0;
flag_cell = flag_cell_displ = flag_charges = flag_coords = flag_velocities = 0;
}
/* ----------------------------------------------------------------------
perform minimization to convergence using >TOLERANCE settings
---------------------------------------------------------------------- */
void MDIEngine::optg()
{
// create or update system if requested prior to OPTG command
int flag_create = flag_natoms | flag_types;
if (flag_create) create_system();
else {
if (flag_cell || flag_cell_displ) adjust_box();
if (flag_charges) adjust_charges();
if (flag_coords) adjust_coords();
if (flag_velocities) adjust_velocities();
}
// initialize LAMMPS and setup() the simulation
// run the minimization using 4 >TOLERANCE parameters
// clean up
update->whichflag = 2;
timer->init_timeout();
@ -737,40 +827,17 @@ void MDIEngine::mdi_optg()
timer->init();
timer->barrier_start();
// if niterate >= 0, minimize for at most niterate iterations
// else if niterate < 0:
// run one iteration at a time forever
// driver triggers exit with @ command other than @COORDS,@FORCES
// two issues with running in this mode:
// @COORDS and @FORCES are not triggered per min iteration
// but also for line search evals
// if driver triggers exit on step that is not multiple of thermo output
// then energy/virial not computed, and <PE, <STRESS will fail
if (niterate >= 0) {
update->minimize->run(niterate);
} else {
niterate = std::numeric_limits<int>::max();
update->etol = 0.0;
update->ftol = 0.0;
while (1) {
update->minimize->run(1);
if (strcmp(mdicmd,"@COORDS") != 0 &&
strcmp(mdicmd,"@FORCES") != 0) break;
}
}
update->minimize->run(niterate);
timer->barrier_stop();
update->minimize->cleanup();
modify->delete_fix("MDI_ENGINE_INTERNAL");
// clear flags
flag_natoms = flag_types = 0;
flag_cell = flag_cell_displ = flag_charges = flag_coords = flag_velocities = 0;
actionflag = 1;
}
/* ----------------------------------------------------------------------
@ -1036,6 +1103,7 @@ void MDIEngine::adjust_velocities()
void MDIEngine::receive_cell()
{
actionflag = 0;
flag_cell = 1;
int ierr = MDI_Recv(sys_cell,9,MDI_DOUBLE,mdicomm);
if (ierr) error->all(FLERR, "MDI: >CELL data");
@ -1060,6 +1128,7 @@ void MDIEngine::receive_cell()
void MDIEngine::receive_cell_displ()
{
actionflag = 0;
flag_cell_displ = 1;
int ierr = MDI_Recv(sys_cell_displ,3,MDI_DOUBLE,mdicomm);
if (ierr) error->all(FLERR,"MDI: >CELL_DISPLS data");
@ -1075,6 +1144,7 @@ void MDIEngine::receive_cell_displ()
void MDIEngine::receive_charges()
{
actionflag = 0;
flag_charges = 1;
int ierr = MDI_Recv(sys_charges,sys_natoms,MDI_DOUBLE,mdicomm);
if (ierr) error->all(FLERR,"MDI: >CHARGES data");
@ -1087,6 +1157,7 @@ void MDIEngine::receive_charges()
void MDIEngine::receive_coords()
{
actionflag = 0;
flag_coords = 1;
int n = 3*sys_natoms;
int ierr = MDI_Recv(sys_coords,n,MDI_DOUBLE,mdicomm);
@ -1103,6 +1174,7 @@ void MDIEngine::receive_coords()
void MDIEngine::receive_natoms()
{
actionflag = 0;
flag_natoms = 1;
int ierr = MDI_Recv(&sys_natoms,1,MDI_INT,mdicomm);
if (ierr) error->all(FLERR,"MDI: >NATOMS data");
@ -1111,12 +1183,47 @@ void MDIEngine::receive_natoms()
reallocate();
}
/* ----------------------------------------------------------------------
>NSTEPS command
receive nsteps for timestepping
---------------------------------------------------------------------- */
void MDIEngine::receive_nsteps()
{
int ierr = MDI_Recv(&nsteps,1,MDI_INT,mdicomm);
if (ierr) error->all(FLERR,"MDI: >NSTEPS data");
MPI_Bcast(&nsteps,1,MPI_INT,0,world);
if (nsteps < 0) error->all(FLERR,"MDI received nsteps < 0");
}
/* ----------------------------------------------------------------------
>TOLERANCE command
receive 4 minimization tolerance params
---------------------------------------------------------------------- */
void MDIEngine::receive_tolerance()
{
double params[4];
int ierr = MDI_Recv(params,4,MDI_DOUBLE,mdicomm);
if (ierr) error->all(FLERR,"MDI: >TOLERANCE data");
MPI_Bcast(params,4,MPI_INT,0,world);
etol = params[0];
ftol = params[1];
niterate = static_cast<int> (params[2]);
max_eval = static_cast<int> (params[3]);
if (etol < 0.0 || ftol < 0.0 || niterate < 0 || max_eval < 0)
error->all(FLERR,"MDI received invalid toleranace parameters");
}
/* ----------------------------------------------------------------------
>TYPES command
---------------------------------------------------------------------- */
void MDIEngine::receive_types()
{
actionflag = 0;
flag_types = 1;
int ierr = MDI_Recv(sys_types,sys_natoms,MDI_INT,mdicomm);
if (ierr) error->all(FLERR,"MDI: >TYPES data");
@ -1129,6 +1236,7 @@ void MDIEngine::receive_types()
void MDIEngine::receive_velocities()
{
actionflag = 0;
flag_velocities = 1;
int n = 3*sys_natoms;
int ierr = MDI_Recv(sys_velocities,n,MDI_DOUBLE,mdicomm);
@ -1139,9 +1247,9 @@ void MDIEngine::receive_velocities()
}
/* ----------------------------------------------------------------------
>FORCES command
receive vector of 3 doubles for all atoms
atoms are ordered by atomID, 1 to Natoms
used by >FORCES command
---------------------------------------------------------------------- */
void MDIEngine::receive_double3(int which)
@ -1545,36 +1653,6 @@ void MDIEngine::infile()
delete [] infile;
}
/* ----------------------------------------------------------------------
>NITERATE command
receive number of iterations for timestepping
---------------------------------------------------------------------- */
void MDIEngine::receive_niterate()
{
int ierr = MDI_Recv(&niterate,1,MDI_INT,mdicomm);
if (ierr) error->all(FLERR,"MDI: >NITERATE data");
MPI_Bcast(&niterate,1,MPI_INT,0,world);
}
/* ----------------------------------------------------------------------
>TOLERANCE command
receive 4 minimization tolerance params
---------------------------------------------------------------------- */
void MDIEngine::receive_tolerance()
{
double params[4];
int ierr = MDI_Recv(params,4,MDI_DOUBLE,mdicomm);
if (ierr) error->all(FLERR,"MDI: >TOLERANCE data");
MPI_Bcast(params,4,MPI_INT,0,world);
etol = params[0];
ftol = params[1];
niterate = static_cast<int> (params[2]);
max_eval = static_cast<int> (params[3]);
}
/* ----------------------------------------------------------------------
<KE command
send kinetic energy

View File

@ -11,25 +11,17 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifdef COMMAND_CLASS
// clang-format off
CommandStyle(mdi,MDIEngine);
// clang-format on
#else
#ifndef LMP_MDI_ENGINE_H
#define LMP_MDI_ENGINE_H
#include "command.h"
#include "pointers.h"
#include "mdi.h"
namespace LAMMPS_NS {
class MDIEngine : public Command {
class MDIEngine : protected Pointers {
public:
MDIEngine(LAMMPS *lmp) : Command(lmp) {}
void command(int, char **) override;
MDIEngine(class LAMMPS *, int, char **);
int execute_command(const char *command, MDI_Comm mdicomm);
void engine_node(const char *node);
@ -70,12 +62,14 @@ class MDIEngine : public Command {
double *sys_charges,*sys_coords,*sys_velocities;
double sys_cell[9],sys_cell_displ[3];
int niterate; // settings for MD and OPTG
int max_eval;
double etol,ftol;
int nsteps; // timesteps for MD
double etol,ftol; // 4 minimization params for OPTG
int niterate,max_eval;
int nbytes; // NBYTES command value used for length by other commands
int actionflag; // 1 if MD or OPTG just completed, else 0
// buffers for MDI comm
int maxatom;
@ -97,7 +91,9 @@ class MDIEngine : public Command {
void mdi_commands();
void mdi_md();
void md();
void mdi_optg();
void optg();
void evaluate();
void create_system();
@ -111,6 +107,8 @@ class MDIEngine : public Command {
void receive_charges();
void receive_coords();
void receive_natoms();
void receive_nsteps();
void receive_tolerance();
void receive_types();
void receive_velocities();
@ -132,8 +130,6 @@ class MDIEngine : public Command {
void single_command();
void many_commands();
void infile();
void receive_niterate();
void receive_tolerance();
void send_ke();
void unit_conversions();
@ -144,7 +140,6 @@ class MDIEngine : public Command {
}
#endif
#endif
/* ERROR/WARNING messages:

View File

@ -18,23 +18,28 @@
#include "mdi_plugin.h"
#include <cstring>
#include "error.h"
#include "fix_mdi_aimd.h"
#include "input.h"
#include "modify.h"
#include <cstring>
#include <mdi.h>
using namespace LAMMPS_NS;
/* ----------------------------------------------------------------------
mdi command: plugin
may later have other MDI command variants
trigger LAMMPS to load an MDI plugin engine
after loading the plugin library, it executes a LAMMPS command such as "run"
the command will use other LAMMPS commands, such as fix mdi/aimd
which act as an MDI driver, issuing MDI commands to the engine
when MDI_Launch_plugin() exits, the engine is shut down and
this class is destroyed
---------------------------------------------------------------------- */
void MDIPlugin::command(int narg, char **arg)
MDIPlugin::MDIPlugin(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
{
if (narg < 1) error->all(FLERR,"Illegal mdi/plugin command");
if (narg < 1) error->all(FLERR,"Illegal mdi plugin command");
char *plugin_name = arg[0];
@ -46,35 +51,36 @@ void MDIPlugin::command(int narg, char **arg)
int iarg = 1;
while (iarg < narg) {
if (strcmp(arg[iarg],"mdi") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal mdi/plugin command");
if (iarg+2 > narg) error->all(FLERR,"Illegal mdi plugin command");
mdi_arg = arg[iarg+1];
iarg += 2;
} else if (strcmp(arg[iarg],"infile") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal mdi/plugin command");
if (iarg+2 > narg) error->all(FLERR,"Illegal mdi plugin command");
infile_arg = arg[iarg+1];
iarg += 2;
} else if (strcmp(arg[iarg],"extra") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal mdi/plugin command");
if (iarg+2 > narg) error->all(FLERR,"Illegal mdi plugin command");
extra_arg = arg[iarg+1];
iarg += 2;
} else if (strcmp(arg[iarg],"command") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal mdi/plugin command");
if (iarg+2 > narg) error->all(FLERR,"Illegal mdi plugin command");
int n = strlen(arg[iarg+1]) + 1;
lammps_command = new char[n];
strcpy(lammps_command,arg[iarg+1]);
iarg += 2;
} else error->all(FLERR,"Illegal mdi/plugin command");
} else error->all(FLERR,"Illegal mdi plugin command");
}
// error checks
if (!mdi_arg || !infile_arg || !lammps_command)
error->all(FLERR,"MDI/plugin must specify mdi, infile, command keywords");
error->all(FLERR,"MDI plugin must specify mdi, infile, command keywords");
// build full plugin_args string for args to plugin library
int n = strlen(mdi_arg) + strlen(infile_arg) + strlen(extra_arg) + 16;
char *plugin_args = new char[n];
plugin_args[0] = 0;
strcat(plugin_args,"-mdi \"");
strcat(plugin_args,mdi_arg);
strcat(plugin_args,"\" -in ");

View File

@ -11,24 +11,17 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifdef COMMAND_CLASS
// clang-format off
CommandStyle(mdi/plugin,MDIPlugin);
// clang-format on
#else
#ifndef LMP_MDI_PLUGIN_H
#define LMP_MDI_PLUGIN_H
#include "command.h"
#include "pointers.h"
#include "mdi.h"
namespace LAMMPS_NS {
class MDIPlugin : public Command {
class MDIPlugin : protected Pointers {
public:
MDIPlugin(LAMMPS *lmp) : Command(lmp) {}
void command(int, char **) override;
MDIPlugin(class LAMMPS *, int, char **);
private:
char *lammps_command;
@ -39,7 +32,6 @@ class MDIPlugin : public Command {
}
#endif
#endif
/* ERROR/WARNING messages:

View File

@ -122,6 +122,8 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
modify(nullptr), group(nullptr), output(nullptr), timer(nullptr), kokkos(nullptr),
atomKK(nullptr), memoryKK(nullptr), python(nullptr), citeme(nullptr)
{
printf("LAMMPS init %d %s %s\n",narg,arg[1],arg[2]);
memory = new Memory(this);
error = new Error(this);
universe = new Universe(this,communicator);