Create KIM_LAMMPS_PlugIn.h & related changes

This commit is contained in:
Ryan S. Elliott
2018-04-02 09:38:30 -05:00
parent f089d8d247
commit 3f3bab4e71
7 changed files with 295 additions and 311 deletions

View File

@ -21,7 +21,7 @@ Syntax from lib dir: python Install.py -b -v version -a kim-name
specify one or more options, order does not matter
-v = version of KIM API library to use
default = kim-api-v1.9.4 (current as of Mar 2018)
default = kim-api-v1.9.4 (current as of Apr 2018)
-b = download and build base KIM API library with example Models
this will delete any previous installation in the current folder
-n = do NOT download and build base KIM API library.
@ -166,9 +166,6 @@ if pathflag:
mkfile.write("print_dir:\n")
mkfile.write(" @printf $(KIM_INSTALL_DIR)\n")
with open("%s/Makefile.KIM_Config" % thisdir, 'w') as cfgfile:
cfgfile.write("include %s/lib/kim-api/Makefile.KIM_Config" % kimdir)
print("Created %s/Makefile.KIM_DIR\n using %s" % (thisdir,kimdir))
else:
kimdir = os.path.join(os.path.abspath(thisdir), "installed-" + version)
@ -191,9 +188,6 @@ if buildflag:
mkfile.write("print_dir:\n")
mkfile.write(" @printf $(KIM_INSTALL_DIR)\n")
with open("%s/Makefile.KIM_Config" % thisdir, 'w') as cfgfile:
cfgfile.write("include %s/lib/kim-api/Makefile.KIM_Config" % kimdir)
print("Created %s/Makefile.KIM_DIR\n using %s" % (thisdir,kimdir))
# download entire kim-api tarball
@ -247,8 +241,9 @@ if buildflag:
# add single OpenKIM model
if addflag:
if os.path.isfile(os.path.join(thisdir, "Makefile.KIM_DIR")):
cmd = 'make -f Makefile.KIM_DIR print_dir'
makefile_path = os.path.join(thisdir, "Makefile.KIM_DIR")
if os.path.isfile(makefile_path):
cmd = 'make --no-print-directory -f %s print_dir' % makefile_path
kimdir = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
if not os.path.isdir(kimdir):

210
lib/kim/KIM_LAMMPS_PlugIn.h Normal file
View File

@ -0,0 +1,210 @@
// Copyright 2018 Regents of the University of Minnesota
// All rights reserved.
//
// Contributing authors: Ryan S. Elliott
#define KIM_STATUS_OK 1
#define KIM_STATUS_NEIGH_ITER_PAST_END 2
#define KIM_STATUS_NEIGH_ITER_INIT_OK 3
#define KIM_STATUS_NEIGH_INVALID_REQUEST -11
#define KIM_STATUS_NEIGH_INVALID_MODE -6
#define KIM_COMPUTE_FALSE 0
#define KIM_COMPUTE_TRUE 1
#define KIM_STATUS_FAIL 0
#include "dlfcn.h"
#include "error.h"
namespace LAMMPS_NS {
class KIM_LAMMPS_PlugIn {
public:
~KIM_LAMMPS_PlugIn() {};
KIM_LAMMPS_PlugIn() : library(NULL) {};
bool setup_kim_api_library(Error * const error);
bool is_strictly_between_1_5_and_2_0;
// KIM symbols
void* library;
int (*report_error)(int line, const char *, const char *, int);
void (*setm_compute_by_index)(void *, int *, ...);
int (*model_compute)(void *);
int (*model_init)(void *);
int (*model_reinit)(void *);
void * (*get_sim_buffer)(void *, int *);
void * (*get_data_by_index)(void *, int, int *);
int (*model_destroy)(void *);
void (*free)(void *, int *);
int (*string_init)(void *, const char *, const char *);
int (*is_half_neighbors)(void *, int *);
int (*get_NBC_method)(void *, const char **);
int (*get_index)(void *, const char *, int *);
int (*getm_index)(void *, int *, int, ...);
int (*get_species_code)(void *, const char *, int *);
void (*setm_data_by_index)(void *, int *, int, ...);
int (*set_method_by_index)(void *, int, intptr_t, void (*)());
void (*set_sim_buffer)(void *, void *, int *);
int (*set_data_by_index)(void *, int, intptr_t, void *);
void (*set_compute_by_index)(void *, int, int, int*);
int (*get_num_params)(void *, int *, int *);
int (*get_free_parameter)(void *, const int, const char **);
void * (*get_data)(void *, const char *, int *);
intptr_t (*get_rank)(void *, const char *, int *);
intptr_t (*get_shape)(void *, const char *, int *, int *);
int (*model_info)(void *, const char *);
};
bool KIM_LAMMPS_PlugIn::setup_kim_api_library(Error * error)
{
if (library == NULL)
{
#ifdef KIM_INSTALL_DIR
library = dlopen(KIM_INSTALL_DIR "/lib/libkim-api-v1.so", RTLD_NOW);
#endif
if (library == NULL)
library = dlopen("kim-api-v1.so", RTLD_NOW);
if (library == NULL)
{
error->all(FLERR,"KIM API library cannot be found");
return false;
}
else
{
// check for version and set is_strictly_between_1_5_and_2_0
void * ver = dlsym(library, "KIM_API_get_version");
if (ver == NULL)
is_strictly_between_1_5_and_2_0 = false;
else
is_strictly_between_1_5_and_2_0 = true;
std::string error_prefix("KIM API library error: ");
// get symbols
if (NULL == (report_error =
(int (*)(int, const char *, const char *, int))
dlsym(library, "KIM_API_report_error")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (setm_compute_by_index =
(void (*)(void *, int *, ...))
dlsym(library, "KIM_API_setm_compute_by_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (model_compute = (int (*)(void *))
dlsym(library, "KIM_API_model_compute")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (model_init = (int (*)(void *))
dlsym(library, "KIM_API_model_init")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (model_reinit = (int (*)(void *))
dlsym(library, "KIM_API_model_reinit")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (get_sim_buffer = (void * (*)(void *, int *))
dlsym(library, "KIM_API_get_sim_buffer")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (get_data_by_index = (void * (*)(void *, int, int *))
dlsym(library, "KIM_API_get_data_by_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (model_destroy = (int (*)(void *))
dlsym(library, "KIM_API_model_destroy")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (free = (void (*)(void *, int *))
dlsym(library, "KIM_API_free")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (string_init =
(int (*)(void *, const char *, const char *))
dlsym(library, "KIM_API_string_init")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (is_half_neighbors = (int (*)(void *, int *))
dlsym(library, "KIM_API_is_half_neighbors")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (get_NBC_method = (int (*)(void *, const char **))
dlsym(library, "KIM_API_get_NBC_method")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (get_index = (int (*)(void *, const char *, int *))
dlsym(library, "KIM_API_get_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (getm_index = (int (*)(void *, int *, int, ...))
dlsym(library, "KIM_API_getm_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (get_species_code =
(int (*)(void *, const char *, int *))
dlsym(library, "KIM_API_get_species_code")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (setm_data_by_index =
(void (*)(void *, int *, int, ...))
dlsym(library, "KIM_API_setm_data_by_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (set_method_by_index =
(int (*)(void *, int, intptr_t, void (*)()))
dlsym(library, "KIM_API_set_method_by_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (set_sim_buffer = (void (*)(void *, void *, int *))
dlsym(library, "KIM_API_set_sim_buffer")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (set_data_by_index =
(int (*)(void *, int, intptr_t, void *))
dlsym(library, "KIM_API_set_data_by_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (set_compute_by_index =
(void (*)(void *, int, int, int*))
dlsym(library, "KIM_API_set_compute_by_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (get_num_params = (int (*)(void *, int *, int *))
dlsym(library, "KIM_API_get_num_params")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (get_free_parameter =
(int (*)(void *, const int, const char **))
dlsym(library, "KIM_API_get_free_parameter")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (get_data = (void * (*)(void *, const char *, int *))
dlsym(library, "KIM_API_get_data")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (get_rank =
(intptr_t (*)(void *, const char *, int *))
dlsym(library, "KIM_API_get_rank")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (get_shape =
(intptr_t (*)(void *, const char *, int *, int *))
dlsym(library, "KIM_API_get_shape")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (model_info = (int (*)(void *, const char *))
dlsym(library, "KIM_API_model_info")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
return true;
}
}
else
{
return true;
}
}
} // namespace LAMMPS_NS

View File

@ -18,6 +18,6 @@
include ../../lib/kim/Makefile.KIM_DIR
kim_SYSINC = -DKIM_INSTALL_DIR=\"${KIM_INSTALL_DIR}\"
kim_SYSLIB =
kim_SYSINC = -I../../lib/kim -DKIM_INSTALL_DIR=\"$(KIM_INSTALL_DIR)\"
kim_SYSLIB = -ldl
kim_SYSPATH =

View File

@ -20,11 +20,11 @@ Instructions:
1. Configure lammps for use with the kim-api library installed in this directory
$ printf "KIM_INSTALL_DIR=${PWD}\n" > ./Makefile.KIM_DIR
# replace X.Y.Z as appropriate here and below
$ printf "KIM_INSTALL_DIR=${PWD}/installed-kim-api-vX.Y.Z\n" > ./Makefile.KIM_DIR
2. Download and unpack the kim-api
# replace X.Y.Z as appropriate here and below
$ wget http://s3.openkim.org/kim-api/kim-api-vX.Y.Z.txz
$ tar zxvf kim-api-vX.Y.Z.txz
@ -36,6 +36,7 @@ $ ./configure --prefix=${PWD}/../installed-kim-api-vX.Y.Z
$ make
$ make install
$ cd ..
4. Remove source and build files
@ -45,7 +46,7 @@ $ rm -rf kim-api-vX.Y.Z.txz
5. To add items do the following (replace the kim item name with your
desired value)
$ source ${PWD}/../kim-api-vX.Y.Z/bin/kim-api-v1-activate
$ source ${PWD}/kim-api-vX.Y.Z/bin/kim-api-v1-activate
$ kim-api-v1-collections-management install system Pair_Johnson_Fe__MO_857282754307_002
@ -60,4 +61,4 @@ $ make g++ (or whatever target you wish)
Note that the Makefile.lammps and Makefile.KIM_DIR files in this directory
are required to allow the LAMMPS build to find the necessary KIM files.
You should not normally need to edit this file.
You should not normally need to edit these files.

View File

@ -1,6 +0,0 @@
This package (pair-kim-v1.7.2+1) created from commit
ced1275c5fd5b382cb9bd39e44ed1324c7c85e99
of the pair-kim git repository
By Ryan S. Elliott (relliott@umn.edu) on Mon Feb 22 14:59:53 CST 2016.

View File

@ -27,7 +27,6 @@
// includes from LAMMPS
#include "pair_kim.h"
#include "pair_kim_version.h"
#include "atom.h"
#include "comm.h"
#include "force.h"
@ -39,201 +38,13 @@
#include "domain.h"
#include "error.h"
// includes from KIM
#include "dlfcn.h"
#define KIM_STATUS_OK 1
#define KIM_STATUS_NEIGH_ITER_PAST_END 2
#define KIM_STATUS_NEIGH_ITER_INIT_OK 3
#define KIM_STATUS_NEIGH_INVALID_REQUEST -11
#define KIM_STATUS_NEIGH_INVALID_MODE -6
#define KIM_COMPUTE_FALSE 0
#define KIM_COMPUTE_TRUE 1
#define KIM_STATUS_FAIL 0
#include "KIM_LAMMPS_PlugIn.h"
using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
void * PairKIM::kim_api_library = NULL;
bool PairKIM::kim_api_is_strictly_between_1_5_and_2_0;
int (*PairKIM::report_error)(int line, const char *, const char *, int) = NULL;
void (*PairKIM::kim_api_setm_compute_by_index)(void *, int *, ...) = NULL;
int (*PairKIM::kim_api_model_compute)(void *);
int (*PairKIM::kim_api_model_init)(void *);
int (*PairKIM::kim_api_model_reinit)(void *);
void * (*PairKIM::kim_api_get_sim_buffer)(void *, int *);
void * (*PairKIM::kim_api_get_data_by_index)(void *, int, int *);
int (*PairKIM::kim_api_model_destroy)(void *);
void (*PairKIM::kim_api_free)(void *, int *);
int (*PairKIM::kim_api_string_init)(void *, const char *, const char *);
int (*PairKIM::kim_api_is_half_neighbors)(void *, int *);
int (*PairKIM::kim_api_get_NBC_method)(void *, const char **);
int (*PairKIM::kim_api_get_index)(void *, const char *, int *);
int (*PairKIM::kim_api_getm_index)(void *, int *, int, ...);
int (*PairKIM::kim_api_get_species_code)(void *, const char *, int *);
void (*PairKIM::kim_api_setm_data_by_index)(void *, int *, int, ...);
int (*PairKIM::kim_api_set_method_by_index)(void *, int, intptr_t, void (*)());
void (*PairKIM::kim_api_set_sim_buffer)(void *, void *, int *);
int (*PairKIM::kim_api_set_data_by_index)(void *, int, intptr_t, void *);
void (*PairKIM::kim_api_set_compute_by_index)(void *, int, int, int*);
int (*PairKIM::kim_api_get_num_params)(void *, int *, int *);
int (*PairKIM::kim_api_get_free_parameter)(void *, const int, const char **);
void * (*PairKIM::kim_api_get_data)(void *, const char *, int *);
intptr_t (*PairKIM::kim_api_get_rank)(void *, const char *, int *);
intptr_t (*PairKIM::kim_api_get_shape)(void *, const char *, int *, int *);
int (*PairKIM::kim_api_model_info)(void *, const char *);
bool PairKIM::setup_kim_api_library()
{
if (kim_api_library == NULL)
{
#ifdef KIM_INSTALL_DIR
kim_api_library = dlopen(KIM_INSTALL_DIR "/lib/libkim-api-v1.so", RTLD_NOW);
#endif
if (kim_api_library == NULL)
kim_api_library = dlopen("kim-api-v1.so", RTLD_NOW);
if (kim_api_library == NULL)
{
error->all(FLERR,"KIM API library cannot be found");
return false;
}
else
{
// check for version and set kim_api_is_strictly_between_1_5_and_2_0
void * ver = dlsym(kim_api_library, "KIM_API_get_version");
if (ver == NULL)
kim_api_is_strictly_between_1_5_and_2_0 = false;
else
kim_api_is_strictly_between_1_5_and_2_0 = true;
std::string error_prefix("KIM API library error: ");
// get symbols
if (NULL == (report_error =
(int (*)(int, const char *, const char *, int))
dlsym(kim_api_library, "KIM_API_report_error")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_setm_compute_by_index =
(void (*)(void *, int *, ...))
dlsym(kim_api_library, "KIM_API_setm_compute_by_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_model_compute = (int (*)(void *))
dlsym(kim_api_library, "KIM_API_model_compute")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_model_init = (int (*)(void *))
dlsym(kim_api_library, "KIM_API_model_init")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_model_reinit = (int (*)(void *))
dlsym(kim_api_library, "KIM_API_model_reinit")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_get_sim_buffer = (void * (*)(void *, int *))
dlsym(kim_api_library, "KIM_API_get_sim_buffer")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_get_data_by_index = (void * (*)(void *, int, int *))
dlsym(kim_api_library, "KIM_API_get_data_by_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_model_destroy = (int (*)(void *))
dlsym(kim_api_library, "KIM_API_model_destroy")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_free = (void (*)(void *, int *))
dlsym(kim_api_library, "KIM_API_free")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_string_init =
(int (*)(void *, const char *, const char *))
dlsym(kim_api_library, "KIM_API_string_init")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_is_half_neighbors = (int (*)(void *, int *))
dlsym(kim_api_library, "KIM_API_is_half_neighbors")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_get_NBC_method = (int (*)(void *, const char **))
dlsym(kim_api_library, "KIM_API_get_NBC_method")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_get_index = (int (*)(void *, const char *, int *))
dlsym(kim_api_library, "KIM_API_get_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_getm_index = (int (*)(void *, int *, int, ...))
dlsym(kim_api_library, "KIM_API_getm_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_get_species_code =
(int (*)(void *, const char *, int *))
dlsym(kim_api_library, "KIM_API_get_species_code")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_setm_data_by_index =
(void (*)(void *, int *, int, ...))
dlsym(kim_api_library, "KIM_API_setm_data_by_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_set_method_by_index =
(int (*)(void *, int, intptr_t, void (*)()))
dlsym(kim_api_library, "KIM_API_set_method_by_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_set_sim_buffer = (void (*)(void *, void *, int *))
dlsym(kim_api_library, "KIM_API_set_sim_buffer")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_set_data_by_index =
(int (*)(void *, int, intptr_t, void *))
dlsym(kim_api_library, "KIM_API_set_data_by_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_set_compute_by_index =
(void (*)(void *, int, int, int*))
dlsym(kim_api_library, "KIM_API_set_compute_by_index")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_get_num_params = (int (*)(void *, int *, int *))
dlsym(kim_api_library, "KIM_API_get_num_params")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_get_free_parameter =
(int (*)(void *, const int, const char **))
dlsym(kim_api_library, "KIM_API_get_free_parameter")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_get_data = (void * (*)(void *, const char *, int *))
dlsym(kim_api_library, "KIM_API_get_data")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_get_rank =
(intptr_t (*)(void *, const char *, int *))
dlsym(kim_api_library, "KIM_API_get_rank")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_get_shape =
(intptr_t (*)(void *, const char *, int *, int *))
dlsym(kim_api_library, "KIM_API_get_shape")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
if (NULL == (kim_api_model_info = (int (*)(void *, const char *))
dlsym(kim_api_library, "KIM_API_model_info")))
error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());
return true;
}
}
else
{
return true;
}
}
void * (*PairKIM::kim_get_sim_buffer)(void *, int *);
PairKIM::PairKIM(LAMMPS *lmp) :
Pair(lmp),
@ -244,6 +55,7 @@ PairKIM::PairKIM(LAMMPS *lmp) :
lmps_unique_elements(0),
lmps_num_unique_elements(0),
lmps_units(METAL),
kim(new KIM_LAMMPS_PlugIn),
pkim(0),
kim_ind_coordinates(-1),
kim_ind_numberOfParticles(-1),
@ -286,7 +98,7 @@ PairKIM::PairKIM(LAMMPS *lmp) :
PairKIM::~PairKIM()
{
if (kim_api_library != NULL)
if (kim->library != NULL)
{
// clean up kim_modelname
if (kim_modelname != 0) delete [] kim_modelname;
@ -316,9 +128,11 @@ PairKIM::~PairKIM()
// clean up KIM interface (if necessary)
kim_free();
dlclose(kim_api_library);
dlclose(kim->library);
}
delete kim;
return;
}
@ -365,17 +179,17 @@ void PairKIM::compute(int eflag , int vflag)
// pass current atom pointers to KIM
set_volatiles();
kim_api_setm_compute_by_index(pkim, &kimerror,3*3,
kim_ind_particleEnergy, eflag_atom,
(int) kim_model_has_particleEnergy,
kim_ind_particleVirial, vflag_atom,
(int) kim_model_has_particleVirial,
kim_ind_virial, vflag_global!=0,
no_virial_fdotr_compute);
kim->setm_compute_by_index(pkim, &kimerror,3*3,
kim_ind_particleEnergy, eflag_atom,
(int) kim_model_has_particleEnergy,
kim_ind_particleVirial, vflag_atom,
(int) kim_model_has_particleVirial,
kim_ind_virial, vflag_global!=0,
no_virial_fdotr_compute);
kim_error(__LINE__,"setm_compute_by_index",kimerror);
// compute via KIM model
kimerror = kim_api_model_compute(pkim);
kimerror = kim->model_compute(pkim);
kim_error(__LINE__,"PairKIM::pkim->model_compute() error",kimerror);
// assemble force and particleVirial if needed
if (!lmps_using_newton) comm->reverse_comm_pair(this);
@ -452,7 +266,8 @@ void PairKIM::settings(int narg, char **arg)
// This is called when "pair_style kim ..." is read from input
// may be called multiple times
setup_kim_api_library(); // exits on failure
kim->setup_kim_api_library(error); // exits on failure
kim_get_sim_buffer = kim->get_sim_buffer;
++settings_call_count;
init_style_call_count = 0;
@ -603,7 +418,7 @@ void PairKIM::init_style()
if (!kim_init_ok)
{
kim_init();
kimerror = kim_api_model_init(pkim);
kimerror = kim->model_init(pkim);
if (kimerror != KIM_STATUS_OK)
kim_error(__LINE__, "KIM API:model_init() failed", kimerror);
else
@ -675,7 +490,7 @@ void PairKIM::reinit()
// Then reinit KIM model
int kimerror;
kimerror = kim_api_model_reinit(pkim);
kimerror = kim->model_reinit(pkim);
kim_error(__LINE__,"model_reinit unsuccessful", kimerror);
}
@ -817,7 +632,7 @@ double PairKIM::memory_usage()
void PairKIM::kim_error(int ln, const char* msg, int errcode)
{
if (errcode == KIM_STATUS_OK) return;
report_error(ln,(char *) __FILE__, (char *) msg,errcode);
kim->report_error(ln,(char *) __FILE__, (char *) msg,errcode);
error->all(__FILE__,ln,"Internal KIM error");
return;
@ -831,7 +646,7 @@ int PairKIM::get_neigh(void **kimmdl,int *mode,int *request,
void * pkim = *kimmdl;
int kimerror;
PairKIM *self = (PairKIM *) kim_api_get_sim_buffer(pkim, &kimerror);
PairKIM *self = (PairKIM *) kim_get_sim_buffer(pkim, &kimerror);
if (self->kim_model_using_Rij) {
*pRij = &(self->Rij[0]);
@ -882,8 +697,8 @@ int PairKIM::get_neigh(void **kimmdl,int *mode,int *request,
// set Rij if needed
if (self->kim_model_using_Rij) {
double* x = (double *)
kim_api_get_data_by_index(pkim, self->kim_ind_coordinates,
&kimerror);
self->kim->get_data_by_index(pkim, self->kim_ind_coordinates,
&kimerror);
for (jj=0; jj < *numnei; jj++) {
int i = *atom;
j = (*nei1atom)[jj];
@ -930,8 +745,8 @@ int PairKIM::get_neigh(void **kimmdl,int *mode,int *request,
// set Rij if needed
if (self->kim_model_using_Rij){
double* x = (double *)
kim_api_get_data_by_index(pkim, self->kim_ind_coordinates,
&kimerror);
self->kim->get_data_by_index(pkim, self->kim_ind_coordinates,
&kimerror);
for(int jj=0; jj < *numnei; jj++){
int i = *atom;
int j = (*nei1atom)[jj];
@ -962,12 +777,12 @@ void PairKIM::kim_free()
if (kim_model_init_ok)
{
kimerror = kim_api_model_destroy(pkim);
kimerror = kim->model_destroy(pkim);
kim_model_init_ok = false;
}
if (kim_init_ok)
{
kim_api_free(&pkim, &kimerror);
kim->free(&pkim, &kimerror);
kim_init_ok = false;
}
if (pkim != 0)
@ -1006,7 +821,7 @@ void PairKIM::kim_init()
}
// initialize KIM model
kimerror = kim_api_string_init(&pkim, test_descriptor_string, kim_modelname);
kimerror = kim->string_init(&pkim, test_descriptor_string, kim_modelname);
if (kimerror != KIM_STATUS_OK)
kim_error(__LINE__,"KIM initialization failed", kimerror);
else
@ -1019,10 +834,10 @@ void PairKIM::kim_init()
// determine kim_model_using_* true/false values
//
// check for half or full list
kim_model_using_half = kim_api_is_half_neighbors(pkim, &kimerror);
kim_model_using_half = kim->is_half_neighbors(pkim, &kimerror);
//
const char* NBC_method;
kimerror = kim_api_get_NBC_method(pkim, &NBC_method);
kimerror = kim->get_NBC_method(pkim, &NBC_method);
kim_error(__LINE__,"NBC method not set",kimerror);
// check for CLUSTER mode
kim_model_using_cluster = (strcmp(NBC_method,"CLUSTER")==0);
@ -1031,18 +846,18 @@ void PairKIM::kim_init()
(strcmp(NBC_method,"NEIGH_RVEC_F")==0));
// get correct index of each variable in kim_api object
kim_api_getm_index(pkim, &kimerror, 3*15,
kim->getm_index(pkim, &kimerror, 3*15,
"coordinates", &kim_ind_coordinates, 1,
"cutoff", &kim_ind_cutoff, 1,
"numberOfParticles", &kim_ind_numberOfParticles, 1,
"numberParticleTypes", &kim_ind_numberOfSpecies,
! kim_api_is_strictly_between_1_5_and_2_0,
! kim->is_strictly_between_1_5_and_2_0,
"particleTypes", &kim_ind_particleSpecies,
! kim_api_is_strictly_between_1_5_and_2_0,
! kim->is_strictly_between_1_5_and_2_0,
"numberOfSpecies", &kim_ind_numberOfSpecies,
kim_api_is_strictly_between_1_5_and_2_0,
kim->is_strictly_between_1_5_and_2_0,
"particleSpecies", &kim_ind_particleSpecies,
kim_api_is_strictly_between_1_5_and_2_0,
kim->is_strictly_between_1_5_and_2_0,
"numberContributingParticles", &kim_ind_numberContributingParticles,
kim_model_using_half,
"particleEnergy", &kim_ind_particleEnergy,
@ -1062,7 +877,7 @@ void PairKIM::kim_init()
for(int i = 0; i < lmps_num_unique_elements; i++){
int kimerror;
kim_particle_codes[i]
= kim_api_get_species_code(pkim, lmps_unique_elements[i], &kimerror);
= kim->get_species_code(pkim, lmps_unique_elements[i], &kimerror);
kim_error(__LINE__, "create_kim_particle_codes: symbol not found ",
kimerror);
}
@ -1081,7 +896,7 @@ void PairKIM::set_statics()
lmps_local_tot_num_atoms = (int) (atom->nghost + atom->nlocal);
int kimerror;
kim_api_setm_data_by_index(pkim, &kimerror, 4*6,
kim->setm_data_by_index(pkim, &kimerror, 4*6,
kim_ind_numberOfSpecies, 1, (void *) &(atom->ntypes), 1,
kim_ind_cutoff, 1, (void *) &(kim_global_cutoff), 1,
kim_ind_numberOfParticles, 1, (void *) &lmps_local_tot_num_atoms, 1,
@ -1092,13 +907,12 @@ void PairKIM::set_statics()
kim_error(__LINE__, "setm_data_by_index", kimerror);
if (!kim_model_using_cluster)
{
kimerror = kim_api_set_method_by_index(pkim, kim_ind_get_neigh, 1,
(void (*)()) &get_neigh);
kimerror = kim->set_method_by_index(pkim, kim_ind_get_neigh, 1,
(void (*)()) &get_neigh);
kim_error(__LINE__, "set_method_by_index", kimerror);
}
kim_api_set_sim_buffer(pkim, (void *)this, &kimerror);
kim->set_sim_buffer(pkim, (void *)this, &kimerror);
kim_error(__LINE__, "set_sim_buffer", kimerror);
return;
@ -1112,33 +926,33 @@ void PairKIM::set_volatiles()
lmps_local_tot_num_atoms = (int) (atom->nghost + atom->nlocal);
intptr_t nall = (intptr_t) lmps_local_tot_num_atoms;
kim_api_setm_data_by_index(pkim, &kimerror, 4*2,
kim->setm_data_by_index(pkim, &kimerror, 4*2,
kim_ind_coordinates, 3*nall, (void*) &(atom->x[0][0]), 1,
kim_ind_particleSpecies, nall, (void*) kim_particleSpecies, 1);
kim_error(__LINE__, "setm_data_by_index", kimerror);
if (kim_model_has_particleEnergy && (eflag_atom == 1))
{
kimerror = kim_api_set_data_by_index(pkim, kim_ind_particleEnergy, nall,
(void*) eatom);
kimerror = kim->set_data_by_index(pkim, kim_ind_particleEnergy, nall,
(void*) eatom);
kim_error(__LINE__, "set_data_by_index", kimerror);
}
if (kim_model_has_particleVirial && (vflag_atom == 1))
{
kimerror = kim_api_set_data_by_index(pkim, kim_ind_particleVirial, 6*nall,
(void*) &(vatom[0][0]));
kimerror = kim->set_data_by_index(pkim, kim_ind_particleVirial, 6*nall,
(void*) &(vatom[0][0]));
kim_error(__LINE__, "set_data_by_index", kimerror);
}
if (kim_model_has_forces)
{
if (lmps_hybrid)
kimerror = kim_api_set_data_by_index(pkim, kim_ind_forces, nall*3,
(void*) &(lmps_force_tmp[0][0]));
kimerror = kim->set_data_by_index(pkim, kim_ind_forces, nall*3,
(void*) &(lmps_force_tmp[0][0]));
else
kimerror = kim_api_set_data_by_index(pkim, kim_ind_forces, nall*3,
(void*) &(atom->f[0][0]));
kimerror = kim->set_data_by_index(pkim, kim_ind_forces, nall*3,
(void*) &(atom->f[0][0]));
kim_error(__LINE__, "setm_data_by_index", kimerror);
}
@ -1151,17 +965,17 @@ void PairKIM::set_volatiles()
if (kim_model_has_particleVirial)
{
if(vflag_atom != 1) {
kim_api_set_compute_by_index(pkim, kim_ind_particleVirial,
KIM_COMPUTE_FALSE, &kimerror);
kim->set_compute_by_index(pkim, kim_ind_particleVirial,
KIM_COMPUTE_FALSE, &kimerror);
} else {
kim_api_set_compute_by_index(pkim, kim_ind_particleVirial,
KIM_COMPUTE_TRUE, &kimerror);
kim->set_compute_by_index(pkim, kim_ind_particleVirial,
KIM_COMPUTE_TRUE, &kimerror);
}
}
if (no_virial_fdotr_compute == 1)
{
kim_api_set_compute_by_index(pkim, kim_ind_virial,
kim->set_compute_by_index(pkim, kim_ind_virial,
((vflag_global != 1) ? KIM_COMPUTE_FALSE : KIM_COMPUTE_TRUE),
&kimerror);
}
@ -1222,34 +1036,34 @@ void PairKIM::set_kim_model_has_flags()
int kimerror;
// get KIM API object representing the KIM Model only
kimerror = kim_api_model_info(&pkim, kim_modelname);
kimerror = kim->model_info(&pkim, kim_modelname);
kim_error(__LINE__,"KIM initialization failed", kimerror);
// determine if the KIM Model can compute the total energy
kim_api_get_index(pkim, (char*) "energy", &kimerror);
kim->get_index(pkim, (char*) "energy", &kimerror);
kim_model_has_energy = (kimerror == KIM_STATUS_OK);
if (!kim_model_has_energy)
error->warning(FLERR,"KIM Model does not provide `energy'; "
"Potential energy will be zero");
// determine if the KIM Model can compute the forces
kim_api_get_index(pkim, (char*) "forces", &kimerror);
kim->get_index(pkim, (char*) "forces", &kimerror);
kim_model_has_forces = (kimerror == KIM_STATUS_OK);
if (!kim_model_has_forces)
error->warning(FLERR,"KIM Model does not provide `forces'; "
"Forces will be zero");
// determine if the KIM Model can compute the particleEnergy
kim_api_get_index(pkim, (char*) "particleEnergy", &kimerror);
kim->get_index(pkim, (char*) "particleEnergy", &kimerror);
kim_model_has_particleEnergy = (kimerror == KIM_STATUS_OK);
if (!kim_model_has_particleEnergy)
error->warning(FLERR,"KIM Model does not provide `particleEnergy'; "
"energy per atom will be zero");
// determine if the KIM Model can compute the particleVerial
kim_api_get_index(pkim, (char*) "particleVirial", &kimerror);
kim->get_index(pkim, (char*) "particleVirial", &kimerror);
kim_model_has_particleVirial = (kimerror == KIM_STATUS_OK);
kim_api_get_index(pkim, (char*) "process_dEdr", &kimerror);
kim->get_index(pkim, (char*) "process_dEdr", &kimerror);
kim_model_has_particleVirial = kim_model_has_particleVirial ||
(kimerror == KIM_STATUS_OK);
if (!kim_model_has_particleVirial)
@ -1257,7 +1071,7 @@ void PairKIM::set_kim_model_has_flags()
"virial per atom will be zero");
// tear down KIM API object
kim_api_free(&pkim, &kimerror);
kim->free(&pkim, &kimerror);
// now destructor will do the remaining tear down for mdl
return;
@ -1293,7 +1107,7 @@ void PairKIM::write_descriptor(char** test_descriptor_string)
"#\n"
"\n");
if (kim_api_is_strictly_between_1_5_and_2_0)
if (kim->is_strictly_between_1_5_and_2_0)
strcat(*test_descriptor_string,
"KIM_API_Version := 1.6.0\n\n");
@ -1344,7 +1158,7 @@ void PairKIM::write_descriptor(char** test_descriptor_string)
}
// Write Supported species section
if (kim_api_is_strictly_between_1_5_and_2_0)
if (kim->is_strictly_between_1_5_and_2_0)
strcat(*test_descriptor_string,
"\n"
"PARTICLE_SPECIES:\n");
@ -1403,7 +1217,7 @@ void PairKIM::write_descriptor(char** test_descriptor_string)
"# Name Type Unit Shape\n"
"numberOfParticles integer none []\n"
"numberContributingParticles integer none []\n");
if (kim_api_is_strictly_between_1_5_and_2_0)
if (kim->is_strictly_between_1_5_and_2_0)
strcat(*test_descriptor_string,
"numberOfSpecies integer none []\n"
"particleSpecies integer none ");
@ -1510,13 +1324,13 @@ void *PairKIM::extract(const char *str, int &dim)
// check to make sure that the requested parameter is a valid free parameter
kimerror = kim_api_get_num_params(pkim, &numParams, &dummyint);
kimerror = kim->get_num_params(pkim, &numParams, &dummyint);
kim_error(__LINE__, "get_num_free_params", kimerror);
char **freeParamNames = new char*[numParams];
for (int k = 0; k < numParams; k++)
{
kimerror = kim_api_get_free_parameter(pkim, k,
(const char**) &freeParamNames[k]);
kimerror = kim->get_free_parameter(pkim, k,
(const char**) &freeParamNames[k]);
kim_error(__LINE__, "get_free_parameter", kimerror);
if (0 == strcmp(paramName, freeParamNames[k]))
{
@ -1534,7 +1348,7 @@ void *PairKIM::extract(const char *str, int &dim)
}
// get the parameter arry from pkim object
paramData = kim_api_get_data(pkim, paramName, &kimerror);
paramData = kim->get_data(pkim, paramName, &kimerror);
if (kimerror == KIM_STATUS_FAIL)
{
delete [] speciesIndex, speciesIndex = 0;
@ -1543,7 +1357,7 @@ void *PairKIM::extract(const char *str, int &dim)
kim_error(__LINE__,"get_data",kimerror);
// get rank and shape of parameter
rank = kim_api_get_rank(pkim, paramName, &kimerror);
rank = kim->get_rank(pkim, paramName, &kimerror);
if (kimerror == KIM_STATUS_FAIL)
{
delete [] speciesIndex, speciesIndex = 0;
@ -1552,7 +1366,7 @@ void *PairKIM::extract(const char *str, int &dim)
kim_error(__LINE__,"get_rank",kimerror);
int *shape = new int[maxLine];
dummyint = kim_api_get_shape(pkim, paramName, shape, &kimerror);
dummyint = kim->get_shape(pkim, paramName, shape, &kimerror);
if (kimerror == KIM_STATUS_FAIL)
{
delete [] speciesIndex, speciesIndex = 0;

View File

@ -31,12 +31,11 @@ PairStyle(kim,PairKIM)
#ifndef LMP_PAIR_KIM_H
#define LMP_PAIR_KIM_H
// includes from KIM & LAMMPS
//class KIM_API_model;
#include "pair.h"
namespace LAMMPS_NS {
// Forward declare KIM_LAMMPS_PlugIn
class KIM_LAMMPS_PlugIn;
class PairKIM : public Pair {
public:
@ -87,6 +86,7 @@ namespace LAMMPS_NS {
unit_sys lmps_units;
// values set in set_kim_model_has_flags(), called by kim_init()
KIM_LAMMPS_PlugIn * kim;
void * pkim;
bool kim_model_has_energy;
bool kim_model_has_forces;
@ -145,40 +145,10 @@ namespace LAMMPS_NS {
void set_kim_model_has_flags();
void write_descriptor(char** test_descriptor_string);
// static methods used as callbacks from KIM
static void * (*kim_get_sim_buffer)(void *, int *);
static int get_neigh(void** kimmdl, int* mode, int* request,
int* atom, int* numnei, int** nei1atom,
double** pRij);
bool setup_kim_api_library();
static bool kim_api_is_strictly_between_1_5_and_2_0;
// KIM symbols
static void* kim_api_library;
static int (*report_error)(int line, const char *, const char *, int);
static void (*kim_api_setm_compute_by_index)(void *, int *, ...);
static int (*kim_api_model_compute)(void *);
static int (*kim_api_model_init)(void *);
static int (*kim_api_model_reinit)(void *);
static void * (*kim_api_get_sim_buffer)(void *, int *);
static void * (*kim_api_get_data_by_index)(void *, int, int *);
static int (*kim_api_model_destroy)(void *);
static void (*kim_api_free)(void *, int *);
static int (*kim_api_string_init)(void *, const char *, const char *);
static int (*kim_api_is_half_neighbors)(void *, int *);
static int (*kim_api_get_NBC_method)(void *, const char **);
static int (*kim_api_get_index)(void *, const char *, int *);
static int (*kim_api_getm_index)(void *, int *, int, ...);
static int (*kim_api_get_species_code)(void *, const char *, int *);
static void (*kim_api_setm_data_by_index)(void *, int *, int, ...);
static int (*kim_api_set_method_by_index)(void *, int, intptr_t, void (*)());
static void (*kim_api_set_sim_buffer)(void *, void *, int *);
static int (*kim_api_set_data_by_index)(void *, int, intptr_t, void *);
static void (*kim_api_set_compute_by_index)(void *, int, int, int*);
static int (*kim_api_get_num_params)(void *, int *, int *);
static int (*kim_api_get_free_parameter)(void *, const int, const char **);
static void * (*kim_api_get_data)(void *, const char *, int *);
static intptr_t (*kim_api_get_rank)(void *, const char *, int *);
static intptr_t (*kim_api_get_shape)(void *, const char *, int *, int *);
static int (*kim_api_model_info)(void *, const char *);
};
}