move MDI C style library calls to separate files

This commit is contained in:
Axel Kohlmeyer
2021-05-13 11:37:05 -04:00
parent 7d7781373c
commit 8d9465ccdb
5 changed files with 136 additions and 106 deletions

View File

@ -4978,103 +4978,6 @@ int lammps_get_last_error_message(void *handle, char *buffer, int buf_size) {
return 0;
}
// ----------------------------------------------------------------------
// MolSSI Drive Interface functions
// ----------------------------------------------------------------------
/** Initialize an instance of LAMMPS as an MDI plugin
*
\verbatim embed:rst
This function is called by the MolSSI Driver Interface library (MDI)
when LAMMPS is run as a plugin, and should not otherwise be used.
The function initializes MDI, then creates and initializes an instance
of LAMMPS. The command-line arguments ``argc`` and ``argv`` used to
initialize LAMMPS are recieved from MDI. The LAMMPS instance runs an
input file, which must include the ``mdi/engine`` command; when LAMMPS
executes this command, it will begin listening for commands from the
driver. The name of the input file is obtained from the ``-in``
command-line argument, which must be provided by the MDI driver.
\endverbatim
* \param command string buffer corresponding to the command to be executed
* \param comm MDI communicator that can be used to communicated with the driver.
* \param class_obj pointer to an instance of an mdi/engine fix cast to ``void *``.
* \return 0 on no error. */
int MDI_Plugin_init_lammps()
{
// initialize MDI
int mdi_argc;
char **mdi_argv;
if (MDI_Plugin_get_argc(&mdi_argc))
MPI_Abort(MPI_COMM_WORLD, 1);
if (MDI_Plugin_get_argv(&mdi_argv))
MPI_Abort(MPI_COMM_WORLD, 1);
if (MDI_Init(&mdi_argc, &mdi_argv))
MPI_Abort(MPI_COMM_WORLD, 1);
// get the MPI intra-communicator for this code
MPI_Comm mpi_world_comm = MPI_COMM_WORLD;
if (MDI_MPI_get_world_comm(&mpi_world_comm))
MPI_Abort(MPI_COMM_WORLD, 1);
// find the -in argument
int iarg = 0;
char *filename;
bool found_filename = false;
while(iarg < mdi_argc && !found_filename) {
if ((strcmp(mdi_argv[iarg],"-in") == 0)
|| (strcmp(mdi_argv[iarg],"-i") == 0)) {
if (iarg+2 > mdi_argc)
MPI_Abort(MPI_COMM_WORLD, 1);
filename = mdi_argv[iarg+1];
found_filename = true;
// remove -in argument from the command list
mdi_argc -= 2;
for (int jarg=iarg; jarg < mdi_argc; jarg++)
mdi_argv[jarg] = mdi_argv[jarg+2];
}
iarg++;
}
if (!found_filename)
MPI_Abort(MPI_COMM_WORLD, 1);
// create and run a LAMMPS instance
LAMMPS *lmp = (LAMMPS*) lammps_open(mdi_argc, mdi_argv, mpi_world_comm, NULL);
lammps_file(lmp, filename);
lammps_close(lmp);
return 0;
}
/** Execute an MDI command
*
\verbatim embed:rst
This function is called by the MolSSI Driver Interface Library (MDI)
when LAMMPS is run as a plugin, and should not otherwise be used. The
function executes a single command from an external MDI driver. If the
LAMMPS library was compiled without ``-DLMP_USER_MDI``, the function
will fail and return a "1".
\endverbatim
* \param command string buffer corresponding to the command to be executed
* \param comm MDI communicator that can be used to communicated with the driver.
* \param class_obj pointer to an instance of an mdi/engine fix cast to ``void *``.
* \return 0 on no error, 1 on error. */
int lammps_execute_mdi_command(const char *command, MDI_Comm comm, void *class_obj)
{
#if defined(LMP_USER_MDI)
FixMDIEngine *mdi_fix = (FixMDIEngine *) class_obj;
return mdi_fix->execute_command(command, comm);
#else
return 1;
#endif
}
// Local Variables:
// fill-column: 72
// End: