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);
81 BMIPhreeqcRM(int ngrid, MP_TYPE nthreads);
82
83 ~BMIPhreeqcRM() override;
84
85 // Model control functions.
218 void Initialize(std::string config_file = "") override;
255 void Update() override;
256
291 void UpdateUntil(double end_time) override;
305 void Finalize() override;
306
307 // Model information functions.
308
328#if defined(_MSC_VER)
329#if defined(_WIN64)
330 std::string GetComponentName() override {
331 char buffer[400];
332 sprintf(buffer, "BMI PhreeqcRM [MSC v.%d 64 bit (AMD64)]", _MSC_VER);
333 return buffer;
334 };
335#elif defined(_WIN32)
336 std::string GetComponentName() override {
337 char buffer[400];
338 sprintf(buffer, "BMI PhreeqcRM [MSC v.%d 32 bit (Intel)]", _MSC_VER);
339 return buffer;
340 };
341#else
342 std::string GetComponentName() override {
343 char buffer[400];
344 sprintf(buffer, "BMI PhreeqcRM [MSC v.%d Unknown]", _MSC_VER);
345 return buffer;
346 };
347#endif
348#else
349 std::string GetComponentName() override { return "BMI PhreeqcRM"; };
350#endif
351
386 int GetInputItemCount() override;
387
423 int GetOutputItemCount() override;
463
500 std::vector<std::string> GetInputVarNames() override;
501
538 std::vector<std::string> GetOutputVarNames() override;
539
576 std::vector<std::string> GetPointableVarNames();
577
581 std::vector<std::string> GetReadOnlyVarNames();
582
583 // Variable information functions
594 int GetVarGrid(const std::string name) override { return 0; }
595
632 std::string GetVarType(const std::string name) override;
667 std::string GetVarUnits(const std::string name) override;
668
703 int GetVarItemsize(const std::string name) override;
704
739 int GetVarNbytes(const std::string name) override;
740
747 std::string GetVarLocation(const std::string name) override { return "Unknown"; }
748
749 // Time functions
750
774 double GetCurrentTime() override;
775
781 double GetStartTime() override;
782
805 double GetEndTime() override;
806
831 std::string GetTimeUnits() override { return "seconds"; };
832 double GetTimeStep() override
833 {
834 return PhreeqcRM::GetTimeStep();
835 };
836
837 // Variable getters
896 //Add NEW_VARIABLE to GetValue Documentation
897 void GetValue(const std::string name, void* dest) override;
901 void GetValue(const std::string name, bool& OUTPUT);
905 void GetValue(const std::string name, bool* OUTPUT);
909 void GetValue(const std::string name, double& OUTPUT);
913 void GetValue(const std::string name, double* OUTPUT);
917 void GetValue(const std::string name, int& OUTPUT);
921 void GetValue(const std::string name, int* OUTPUT);
925 void GetValue(const std::string name, std::string& OUTPUT);
929 void GetValue(const std::string name, std::vector<double>& OUTPUT);
933 void GetValue(const std::string name, std::vector<int>& OUTPUT);
937 void GetValue(const std::string name, std::vector<std::string>& OUTPUT);
963 //Add NEW_VARIABLE to GetValuePtr Documentation
964 void* GetValuePtr(std::string name) override;
968 void GetValueAtIndices(std::string name, void* dest, int* inds, int count) override
969 {
970 throw NotImplemented();
971 };
972
973 // Variable setters
1021 void SetValue(const std::string name, void* src) override;
1025 void SetValue(const std::string name, bool src);
1029 void SetValue(const std::string name, const char* src);
1033 void SetValue(const std::string name, double src);
1037 void SetValue(const std::string name, int src);
1041 void SetValue(const std::string name, const std::string src);
1045 void SetValue(const std::string name, std::vector<double> src);
1049 void SetValue(const std::string name, std::vector<int> src);
1053 void SetValue(const std::string name, std::vector<std::string> src);
1057 void SetValueAtIndices(std::string name, int* inds, int count, void* src) override
1058 {
1059 throw NotImplemented();
1060 };
1061 // Grid information functions
1071 int GetGridRank(const int grid) override;
1079 int GetGridSize(const int grid) override;
1089 std::string GetGridType(const int grid) override;
1093 void GetGridShape(const int grid, int* shape) override
1094 {
1095 throw NotImplemented();
1096 }
1100 void GetGridSpacing(const int grid, double* spacing) override
1101 {
1102 throw NotImplemented();
1103 }
1107 void GetGridOrigin(const int grid, double* origin) override
1108 {
1109 throw NotImplemented();
1110 }
1114 void GetGridX(const int grid, double* x) override
1115 {
1116 throw NotImplemented();
1117 }
1121 void GetGridY(const int grid, double* y) override
1122 {
1123 throw NotImplemented();
1124 }
1128 void GetGridZ(const int grid, double* z) override
1129 {
1130 throw NotImplemented();
1131 }
1135 int GetGridNodeCount(const int grid) override
1136 {
1137 throw NotImplemented();
1138 }
1142 int GetGridEdgeCount(const int grid) override
1143 {
1144 throw NotImplemented();
1145 }
1149 int GetGridFaceCount(const int grid) override
1150 {
1151 throw NotImplemented();
1152 }
1156 void GetGridEdgeNodes(const int grid, int* edge_nodes) override
1157 {
1158 throw NotImplemented();
1159 }
1163 void GetGridFaceEdges(const int grid, int* face_edges) override
1164 {
1165 throw NotImplemented();
1166 }
1170 void GetGridFaceNodes(const int grid, int* face_nodes) override
1171 {
1172 throw NotImplemented();
1173 }
1177 void GetGridNodesPerFace(const int grid, int* nodes_per_face) override
1178 {
1179 throw NotImplemented();
1180 }
1262 void AddOutputVars(std::string option, std::string def) override;
1263
1264 IRM_RESULT SetLanguage(const char* string) { this->language = string; return IRM_OK; };
1265 // data
1266 std::string language;
1267 // typedef void (*VarFunction)(BMIPhreeqcRM* brm_ptr); // function pointer type
1268 // typedef std::map<std::string, VarFunction> VarFunction_map;
1269 // VarFunction_map varfn_map;
1270 // VarFunction GetFn(const std::string name);
1271 // std::set<std::string> UpdateMap;
1272 // std::set<std::string>& GetUpdateMap() { return UpdateMap; }
1273
1274#if defined(WITH_PYBIND11)
1275
1276 py::array BMIPhreeqcRM::get_value(std::string name, py::array arr);
1277
1278 //py::array get_value_test(std::string arg, py::array dest/* = py::none()*/);
1279 //py::array BMIPhreeqcRM::get_value_test(std::string name, py::array_t<double> dest = py::none());
1280 py::array get_value_ptr(std::string name);
1281
1282 void set_value(std::string name, py::array src);
1283
1284 py::array get_value_at_indices(std::string name, py::array dest, py::array indices);
1285
1286 void set_value_at_indices(std::string name, py::array indices, py::array src);
1287
1288 py::sequence process_sequence(py::sequence seq);
1289
1290 bool _initialized; // { var_man != nullptr }
1291#endif
1292
1293#if defined(SWIG) || defined(swig_python_EXPORTS)
1294 void get_value_ptr_double(std::string var, double** ARGOUTVIEW_ARRAY1, int* DIM1);
1295 void get_value_ptr_int(std::string var, int** ARGOUTVIEW_ARRAY1, int* DIM1);
1296 std::vector<std::string>& get_value_ptr_vector_strings(std::string var);
1297#endif
1298
1299protected:
1300 void Construct(Initializer initializer) override;
1301
1302private:
1303 //friend class RM_interface;
1304 VarManager* var_man;
1305 bool constructed;
1306
1307 void ClearBMISelectedOutput() override;
1308 void GenerateAutoOutputVars() override;
1309 void UpdateBMI(RMVARS v_enum) override;
1310 void UpdateVariables();
1311 RMVARS GetEnum(const std::string name);
1312};
1313#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:1142
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:1170
std::string GetVarLocation(const std::string name) override
Definition BMIPhreeqcRM.h:747
void SetValue(const std::string name, double src)
IRM_RESULT SetLanguage(const char *string)
Definition BMIPhreeqcRM.h:1264
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:1093
void GetValue(const std::string name, std::vector< std::string > &OUTPUT)
int GetVarGrid(const std::string name) override
Definition BMIPhreeqcRM.h:594
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:831
double GetTimeStep() override
Definition BMIPhreeqcRM.h:832
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:1057
void AddOutputVars(std::string option, std::string def) override
std::string language
Definition BMIPhreeqcRM.h:1266
void GetValue(const std::string name, std::vector< double > &OUTPUT)
double GetEndTime() override
void GetGridY(const int grid, double *y) override
Definition BMIPhreeqcRM.h:1121
void Construct(Initializer initializer) override
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:1163
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:1100
void GetValue(const std::string name, int &OUTPUT)
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:1114
int GetOutputItemCount() 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:968
std::vector< std::string > GetOutputVarNames() override
int GetGridFaceCount(const int grid) override
Definition BMIPhreeqcRM.h:1149
void GetValue(const std::string name, std::string &OUTPUT)
BMIPhreeqcRM(int ngrid, int nthreads)
std::string GetComponentName() override
Definition BMIPhreeqcRM.h:349
void UpdateUntil(double end_time) override
int GetGridNodeCount(const int grid) override
Definition BMIPhreeqcRM.h:1135
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:1128
void GetGridOrigin(const int grid, double *origin) override
Definition BMIPhreeqcRM.h:1107
void GetGridEdgeNodes(const int grid, int *edge_nodes) override
Definition BMIPhreeqcRM.h:1156
void GetGridNodesPerFace(const int grid, int *nodes_per_face) override
Definition BMIPhreeqcRM.h:1177
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:269
double GetTimeStep(void)
Definition PhreeqcRM.h:3024