Add call to MDI_Set_execute_command
This commit is contained in:
@ -25,7 +25,7 @@
|
||||
#include "error.h"
|
||||
#include "force.h"
|
||||
#include "irregular.h"
|
||||
#include "mdi.h"
|
||||
#include "library.h"
|
||||
#include "memory.h"
|
||||
#include "modify.h"
|
||||
#include "update.h"
|
||||
@ -261,37 +261,8 @@ void FixMDIEngine::post_force(int vflag)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
char *FixMDIEngine::engine_mode(const char *node)
|
||||
int FixMDIEngine::execute_command(const char *command, MDI_Comm driver_socket)
|
||||
{
|
||||
/*
|
||||
if (screen)
|
||||
fprintf(screen,"MDI ENGINE MODE: %i\n",node);
|
||||
if (logfile)
|
||||
fprintf(logfile,"MDI ENGINE MODE: %i\n",node);
|
||||
*/
|
||||
|
||||
// flag to indicate whether the engine should continue listening for commands at this node
|
||||
strncpy(current_node, node, MDI_COMMAND_LENGTH);
|
||||
if ( strcmp(target_node,"\0") != 0 and strcmp(target_node, current_node) != 0 ) {
|
||||
local_exit_flag = true;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------- */
|
||||
// Answer commands from the driver
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
while (not exit_flag and not local_exit_flag) {
|
||||
|
||||
if (master) {
|
||||
// read the next command from the driver
|
||||
ierr = MDI_Recv_Command(command, driver_socket);
|
||||
if (ierr != 0)
|
||||
error->all(FLERR,"Unable to receive command from driver");
|
||||
command[MDI_COMMAND_LENGTH]=0;
|
||||
}
|
||||
// broadcast the command to the other tasks
|
||||
MPI_Bcast(command,MDI_COMMAND_LENGTH,MPI_CHAR,0,world);
|
||||
|
||||
/*
|
||||
if (screen)
|
||||
fprintf(screen,"MDI command: %s\n",command);
|
||||
@ -470,6 +441,46 @@ char *FixMDIEngine::engine_mode(const char *node)
|
||||
error->all(FLERR,"Unknown command from driver");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
char *FixMDIEngine::engine_mode(const char *node)
|
||||
{
|
||||
/*
|
||||
if (screen)
|
||||
fprintf(screen,"MDI ENGINE MODE: %i\n",node);
|
||||
if (logfile)
|
||||
fprintf(logfile,"MDI ENGINE MODE: %i\n",node);
|
||||
*/
|
||||
|
||||
// flag to indicate whether the engine should continue listening for commands at this node
|
||||
strncpy(current_node, node, MDI_COMMAND_LENGTH);
|
||||
if ( strcmp(target_node,"\0") != 0 and strcmp(target_node, current_node) != 0 ) {
|
||||
local_exit_flag = true;
|
||||
}
|
||||
|
||||
// register the execute_command function with MDI
|
||||
MDI_Set_execute_command_func(lammps_execute_mdi_command, this);
|
||||
|
||||
/* ----------------------------------------------------------------- */
|
||||
// Answer commands from the driver
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
while (not exit_flag and not local_exit_flag) {
|
||||
|
||||
// read the next command from the driver
|
||||
ierr = MDI_Recv_Command(command, driver_socket);
|
||||
if (ierr != 0)
|
||||
error->all(FLERR,"Unable to receive command from driver");
|
||||
|
||||
// broadcast the command to the other tasks
|
||||
MPI_Bcast(command,MDI_COMMAND_LENGTH,MPI_CHAR,0,world);
|
||||
|
||||
// execute the command
|
||||
this->execute_command(command, driver_socket);
|
||||
|
||||
// check if the target node is something other than the current node
|
||||
if ( strcmp(target_node,"\0") != 0 and strcmp(target_node, current_node) != 0 ) {
|
||||
local_exit_flag = true;
|
||||
|
||||
@ -22,6 +22,7 @@ FixStyle(mdi/engine,FixMDIEngine)
|
||||
#define LMP_FIX_MDI_ENGINE_H
|
||||
|
||||
#include "fix.h"
|
||||
#include "mdi.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
@ -32,6 +33,7 @@ class FixMDIEngine : public Fix {
|
||||
int setmask();
|
||||
void init();
|
||||
|
||||
int execute_command(const char *command, MDI_Comm driver_socket);
|
||||
char *engine_mode(const char *node);
|
||||
|
||||
// receive and update forces
|
||||
|
||||
@ -27,11 +27,13 @@
|
||||
#include "error.h"
|
||||
#include "fix.h"
|
||||
#include "fix_external.h"
|
||||
#if defined(LMP_USER_MDI)
|
||||
#include "fix_mdi_engine.h"
|
||||
#endif
|
||||
#include "force.h"
|
||||
#include "group.h"
|
||||
#include "info.h"
|
||||
#include "input.h"
|
||||
#include "mdi_interface.h"
|
||||
#include "memory.h"
|
||||
#include "modify.h"
|
||||
#include "molecule.h"
|
||||
@ -4979,7 +4981,8 @@ int lammps_get_last_error_message(void *handle, char *buffer, int buf_size) {
|
||||
// ----------------------------------------------------------------------
|
||||
// MDI functions
|
||||
// ----------------------------------------------------------------------
|
||||
int MDI_Plugin_init_lammps() {
|
||||
int MDI_Plugin_init_lammps()
|
||||
{
|
||||
// initialize MDI
|
||||
int mdi_argc;
|
||||
char** mdi_argv;
|
||||
@ -5026,6 +5029,18 @@ int MDI_Plugin_init_lammps() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
mdi_fix->execute_command(command, comm);
|
||||
return 0;
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// fill-column: 72
|
||||
// End:
|
||||
|
||||
@ -40,6 +40,8 @@
|
||||
#include <inttypes.h> /* for int64_t */
|
||||
#endif
|
||||
|
||||
#include "mdi_interface.h"
|
||||
|
||||
/** Data type constants for extracting data from atoms, computes and fixes
|
||||
*
|
||||
* Must be kept in sync with the equivalent constants in lammps/constants.py */
|
||||
@ -247,6 +249,7 @@ int lammps_get_last_error_message(void *handle, char *buffer, int buf_size);
|
||||
* MDI functions
|
||||
* ---------------------------------------------------------------------- */
|
||||
int MDI_Plugin_init_lammps();
|
||||
int lammps_execute_mdi_command(const char* command, MDI_Comm comm, void* class_obj);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user