Extend lib interface to set fix external callback

This allows creating a callback in Python and attaching it to
a fix external instance.
This commit is contained in:
Richard Berger
2019-08-20 14:04:49 -06:00
parent 8cfdf4fad5
commit 2b42428d28
5 changed files with 141 additions and 2 deletions

View File

@ -37,6 +37,7 @@
#include "error.h"
#include "force.h"
#include "info.h"
#include "fix_external.h"
#if defined(LAMMPS_EXCEPTIONS)
#include "exceptions.h"
@ -1605,6 +1606,35 @@ void lammps_create_atoms(void *ptr, int n, tagint *id, int *type,
END_CAPTURE
}
void lammps_set_fix_external_callback(void *ptr, char *id, FixExternalFnPtr callback_ptr, void * caller)
{
LAMMPS *lmp = (LAMMPS *) ptr;
FixExternal::FnPtr callback = (FixExternal::FnPtr) callback_ptr;
BEGIN_CAPTURE
{
int ifix = lmp->modify->find_fix(id);
if (ifix < 0) {
char str[50];
sprintf(str, "Can not find fix with ID '%s'!", id);
lmp->error->all(FLERR,str);
}
Fix *fix = lmp->modify->fix[ifix];
if (strcmp("external",fix->style) != 0){
char str[50];
sprintf(str, "Fix '%s' is not of style external!", id);
lmp->error->all(FLERR,str);
}
FixExternal * fext = (FixExternal*) fix;
fext->set_callback(callback, caller);
}
END_CAPTURE
}
// ----------------------------------------------------------------------
// library API functions for accessing LAMMPS configuration
// ----------------------------------------------------------------------