PhreeqcRM
BMIPhreeqcRM.h
Go to the documentation of this file.
1
4#if !defined(BMIPHREEQCRM_H_INCLUDED)
5#define BMIPHREEQCRM_H_INCLUDED
6#include <map>
7
8#if defined(WITH_PYBIND11)
9#include <pybind11/pybind11.h>
10#include <pybind11/numpy.h>
11#include <pybind11/stl.h>
12#include <pybind11/stl_bind.h>
13
14namespace py = pybind11;
15
16class NotIntialized : public std::runtime_error {
17public:
18 NotIntialized() : std::runtime_error("must call initialize first") { };
19};
20#endif
21
22#include "PhreeqcRM.h"
23#include "BMIVariant.h"
24#include "bmi.hxx"
25#include "VarManager.h"
32class NotImplemented : public std::logic_error {
33public:
34 NotImplemented() : std::logic_error("Not Implemented") { };
35};
43class IRM_DLL_EXPORT BMIPhreeqcRM : public bmi::Bmi, public PhreeqcRM
44{
45public:
46 static void CleanupBMIModuleInstances(void);
47 static int CreateBMIModule();
48 static int CreateBMIModule(int nxyz, MP_TYPE nthreads);
50 static BMIPhreeqcRM* GetInstance(int n);
75 BMIPhreeqcRM(int ngrid = PhreeqcRM::default_nxyz, MP_TYPE nthreads = PhreeqcRM::default_data_for_parallel_processing);
76
77 ~BMIPhreeqcRM() override;
78
79 // Model control functions.
212 void Initialize(std::string config_file = "") override;
249 void Update() override;
250
285 void UpdateUntil(double end_time) override;
299 void Finalize() override;
300
301 // Model information functions.
302
322#if defined(_MSC_VER)
323#if defined(_WIN64)
324 std::string GetComponentName() override {
325 char buffer[400];
326 sprintf(buffer, "BMI PhreeqcRM [MSC v.%d 64 bit (AMD64)]", _MSC_VER);
327 return buffer;
328 };
329#elif defined(_WIN32)
330 std::string GetComponentName() override {
331 char buffer[400];
332 sprintf(buffer, "BMI PhreeqcRM [MSC v.%d 32 bit (Intel)]", _MSC_VER);
333 return buffer;
334 };
335#else
336 std::string GetComponentName() override {
337 char buffer[400];
338 sprintf(buffer, "BMI PhreeqcRM [MSC v.%d Unknown]", _MSC_VER);
339 return buffer;
340 };
341#endif
342#else
343 std::string GetComponentName() override { return "BMI PhreeqcRM"; };
344#endif
345
380 int GetInputItemCount() override;
381
417 int GetOutputItemCount() override;
457
494 std::vector<std::string> GetInputVarNames() override;
495
532 std::vector<std::string> GetOutputVarNames() override;
533
570 std::vector<std::string> GetPointableVarNames();
571
575 std::vector<std::string> GetReadOnlyVarNames();
576
577 // Variable information functions
588 int GetVarGrid(const std::string name) override { return 0; }
589
626 std::string GetVarType(const std::string name) override;
661 std::string GetVarUnits(const std::string name) override;
662
697 int GetVarItemsize(const std::string name) override;
698
733 int GetVarNbytes(const std::string name) override;
734
741 std::string GetVarLocation(const std::string name) override { return "Unknown"; }
742
743 // Time functions
744
768 double GetCurrentTime() override;
769
775 double GetStartTime() override;
776
799 double GetEndTime() override;
800
825 std::string GetTimeUnits() override { return "seconds"; };
826 double GetTimeStep() override
827 {
828 return PhreeqcRM::GetTimeStep();
829 };
830
831 // Variable getters
890 //Add NEW_VARIABLE to GetValue Documentation
891 void GetValue(const std::string name, void* dest) override;
895 void GetValue(const std::string name, bool& OUTPUT);
899 void GetValue(const std::string name, bool* OUTPUT);
903 void GetValue(const std::string name, double& OUTPUT);
907 void GetValue(const std::string name, double* OUTPUT);
911 void GetValue(const std::string name, int& OUTPUT);
915 void GetValue(const std::string name, int* OUTPUT);
919 void GetValue(const std::string name, std::string& OUTPUT);
923 void GetValue(const std::string name, std::vector<double>& OUTPUT);
927 void GetValue(const std::string name, std::vector<int>& OUTPUT);
931 void GetValue(const std::string name, std::vector<std::string>& OUTPUT);
957 //Add NEW_VARIABLE to GetValuePtr Documentation
958 void* GetValuePtr(std::string name) override;
962 void GetValueAtIndices(std::string name, void* dest, int* inds, int count) override
963 {
964 throw NotImplemented();
965 };
966
967 // Variable setters
1015 void SetValue(const std::string name, void* src) override;
1019 void SetValue(const std::string name, bool src);
1023 void SetValue(const std::string name, const char* src);
1027 void SetValue(const std::string name, double src);
1031 void SetValue(const std::string name, int src);
1035 void SetValue(const std::string name, const std::string src);
1039 void SetValue(const std::string name, std::vector<double> src);
1043 void SetValue(const std::string name, std::vector<int> src);
1047 void SetValue(const std::string name, std::vector<std::string> src);
1051 void SetValueAtIndices(std::string name, int* inds, int count, void* src) override
1052 {
1053 throw NotImplemented();
1054 };
1055 // Grid information functions
1065 int GetGridRank(const int grid) override;
1073 int GetGridSize(const int grid) override;
1083 std::string GetGridType(const int grid) override;
1087 void GetGridShape(const int grid, int* shape) override
1088 {
1089 throw NotImplemented();
1090 }
1094 void GetGridSpacing(const int grid, double* spacing) override
1095 {
1096 throw NotImplemented();
1097 }
1101 void GetGridOrigin(const int grid, double* origin) override
1102 {
1103 throw NotImplemented();
1104 }
1108 void GetGridX(const int grid, double* x) override
1109 {
1110 throw NotImplemented();
1111 }
1115 void GetGridY(const int grid, double* y) override
1116 {
1117 throw NotImplemented();
1118 }
1122 void GetGridZ(const int grid, double* z) override
1123 {
1124 throw NotImplemented();
1125 }
1129 int GetGridNodeCount(const int grid) override
1130 {
1131 throw NotImplemented();
1132 }
1136 int GetGridEdgeCount(const int grid) override
1137 {
1138 throw NotImplemented();
1139 }
1143 int GetGridFaceCount(const int grid) override
1144 {
1145 throw NotImplemented();
1146 }
1150 void GetGridEdgeNodes(const int grid, int* edge_nodes) override
1151 {
1152 throw NotImplemented();
1153 }
1157 void GetGridFaceEdges(const int grid, int* face_edges) override
1158 {
1159 throw NotImplemented();
1160 }
1164 void GetGridFaceNodes(const int grid, int* face_nodes) override
1165 {
1166 throw NotImplemented();
1167 }
1171 void GetGridNodesPerFace(const int grid, int* nodes_per_face) override
1172 {
1173 throw NotImplemented();
1174 }
1256 void AddOutputVars(std::string option, std::string def) override;
1257
1258 IRM_RESULT SetLanguage(const char* string) { this->language = string; return IRM_OK; };
1259 // data
1260 std::string language;
1261 // typedef void (*VarFunction)(BMIPhreeqcRM* brm_ptr); // function pointer type
1262 // typedef std::map<std::string, VarFunction> VarFunction_map;
1263 // VarFunction_map varfn_map;
1264 // VarFunction GetFn(const std::string name);
1265 // std::set<std::string> UpdateMap;
1266 // std::set<std::string>& GetUpdateMap() { return UpdateMap; }
1267
1268 IRM_RESULT LoadDatabase(const std::string& database) override;
1269
1270#if defined(WITH_PYBIND11)
1271
1272 py::array BMIPhreeqcRM::get_value(std::string name, py::array arr);
1273
1274 //py::array get_value_test(std::string arg, py::array dest/* = py::none()*/);
1275 //py::array BMIPhreeqcRM::get_value_test(std::string name, py::array_t<double> dest = py::none());
1276 py::array get_value_ptr(std::string name);
1277
1278 void set_value(std::string name, py::array src);
1279
1280 py::array get_value_at_indices(std::string name, py::array dest, py::array indices);
1281
1282 void set_value_at_indices(std::string name, py::array indices, py::array src);
1283
1284 py::sequence process_sequence(py::sequence seq);
1285
1286 bool _initialized; // { var_man != nullptr }
1287#endif
1288
1289#if defined(SWIG) || defined(swig_python_EXPORTS)
1290 void get_value_ptr_double(std::string var, double** ARGOUTVIEW_ARRAY1, int* DIM1);
1291 void get_value_ptr_int(std::string var, int** ARGOUTVIEW_ARRAY1, int* DIM1);
1292 std::vector<std::string>& get_value_ptr_vector_strings(std::string var);
1293#endif
1294
1295protected:
1296 void Construct(void) override;
1297
1298private:
1299 //friend class RM_interface;
1300 VarManager* var_man;
1301 bool constructed;
1302
1303 void ClearBMISelectedOutput() override;
1304 void GenerateAutoOutputVars() override;
1305 void UpdateBMI(RMVARS v_enum) override;
1306 void UpdateVariables();
1307 RMVARS GetEnum(const std::string name);
1308};
1309#endif //BMIPHREEQCRM_H_INCLUDED
IRM_RESULT
Enumeration for PhreeqcRM function return codes.
Definition IrmResult.h:8
@ IRM_OK
Definition IrmResult.h:9
C++ header file for PhreeqcRM. PhreeqcRM is deprecated and included for backward compatibility....
#define MP_TYPE
Definition PhreeqcRM.h:17
Basic Model Interface implementation of the geochemical reaction module PhreeqcRM.
Definition BMIPhreeqcRM.h:44
double GetCurrentTime() override
std::vector< std::string > GetInputVarNames() override
int GetGridEdgeCount(const int grid) override
Definition BMIPhreeqcRM.h:1136
std::string GetVarUnits(const std::string name) override
void SetValue(const std::string name, const char *src)
int GetVarNbytes(const std::string name) override
void GetGridFaceNodes(const int grid, int *face_nodes) override
Definition BMIPhreeqcRM.h:1164
std::string GetVarLocation(const std::string name) override
Definition BMIPhreeqcRM.h:741
void SetValue(const std::string name, double src)
IRM_RESULT SetLanguage(const char *string)
Definition BMIPhreeqcRM.h:1258
std::vector< std::string > GetPointableVarNames()
void SetValue(const std::string name, int src)
void GetValue(const std::string name, std::vector< int > &OUTPUT)
static void CleanupBMIModuleInstances(void)
int GetGridSize(const int grid) override
void Update() override
~BMIPhreeqcRM() override
void GetValue(const std::string name, double *OUTPUT)
void GetGridShape(const int grid, int *shape) override
Definition BMIPhreeqcRM.h:1087
void GetValue(const std::string name, std::vector< std::string > &OUTPUT)
void Construct(void) override
int GetVarGrid(const std::string name) override
Definition BMIPhreeqcRM.h:588
void SetValue(const std::string name, std::vector< std::string > src)
void GetValue(const std::string name, bool *OUTPUT)
std::string GetTimeUnits() override
Definition BMIPhreeqcRM.h:825
double GetTimeStep() override
Definition BMIPhreeqcRM.h:826
static int CreateBMIModule(int nxyz, int nthreads)
void SetValue(const std::string name, bool src)
void SetValueAtIndices(std::string name, int *inds, int count, void *src) override
Definition BMIPhreeqcRM.h:1051
void AddOutputVars(std::string option, std::string def) override
std::string language
Definition BMIPhreeqcRM.h:1260
void GetValue(const std::string name, std::vector< double > &OUTPUT)
double GetEndTime() override
void GetGridY(const int grid, double *y) override
Definition BMIPhreeqcRM.h:1115
static IRM_RESULT DestroyBMIModule(int n)
std::string GetVarType(const std::string name) override
void GetValue(const std::string name, bool &OUTPUT)
void Finalize() override
void GetGridFaceEdges(const int grid, int *face_edges) override
Definition BMIPhreeqcRM.h:1157
double GetStartTime() override
static BMIPhreeqcRM * GetInstance(int n)
int GetPointableItemCount()
void * GetValuePtr(std::string name) override
void GetValue(const std::string name, void *dest) override
void GetGridSpacing(const int grid, double *spacing) override
Definition BMIPhreeqcRM.h:1094
void GetValue(const std::string name, int &OUTPUT)
BMIPhreeqcRM(int ngrid=PhreeqcRM::default_nxyz, int nthreads=PhreeqcRM::default_data_for_parallel_processing)
static int CreateBMIModule()
std::vector< std::string > GetReadOnlyVarNames()
std::string GetGridType(const int grid) override
void GetValue(const std::string name, int *OUTPUT)
void GetGridX(const int grid, double *x) override
Definition BMIPhreeqcRM.h:1108
int GetOutputItemCount() override
IRM_RESULT LoadDatabase(const std::string &database) override
void SetValue(const std::string name, std::vector< int > src)
int GetGridRank(const int grid) override
void Initialize(std::string config_file="") override
void GetValueAtIndices(std::string name, void *dest, int *inds, int count) override
Definition BMIPhreeqcRM.h:962
std::vector< std::string > GetOutputVarNames() override
int GetGridFaceCount(const int grid) override
Definition BMIPhreeqcRM.h:1143
void GetValue(const std::string name, std::string &OUTPUT)
std::string GetComponentName() override
Definition BMIPhreeqcRM.h:343
void UpdateUntil(double end_time) override
int GetGridNodeCount(const int grid) override
Definition BMIPhreeqcRM.h:1129
void SetValue(const std::string name, const std::string src)
void SetValue(const std::string name, void *src) override
int GetVarItemsize(const std::string name) override
void SetValue(const std::string name, std::vector< double > src)
void GetGridZ(const int grid, double *z) override
Definition BMIPhreeqcRM.h:1122
void GetGridOrigin(const int grid, double *origin) override
Definition BMIPhreeqcRM.h:1101
void GetGridEdgeNodes(const int grid, int *edge_nodes) override
Definition BMIPhreeqcRM.h:1150
void GetGridNodesPerFace(const int grid, int *nodes_per_face) override
Definition BMIPhreeqcRM.h:1171
int GetInputItemCount() override
void GetValue(const std::string name, double &OUTPUT)
Throws an exception for Basic Model Interface methods that are not implemented in BMIPhreeqcRM.
Definition BMIPhreeqcRM.h:32
NotImplemented()
Definition BMIPhreeqcRM.h:34
Geochemical reaction module.
Definition PhreeqcRM.h:279
double GetTimeStep(void)
Definition PhreeqcRM.h:3034