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);
80 BMIPhreeqcRM(int ngrid, MP_TYPE nthreads);
81
82 ~BMIPhreeqcRM() override;
83
84 // Model control functions.
213 void Initialize(std::string config_file = "") override;
250 void Update() override;
251
286 void UpdateUntil(double end_time) override;
300 void Finalize() override;
301
302 // Model information functions.
303
323 std::string GetComponentName() override { return "BMI PhreeqcRM"; };
324
359 int GetInputItemCount() override;
360
396 int GetOutputItemCount() override;
436
473 std::vector<std::string> GetInputVarNames() override;
474
511 std::vector<std::string> GetOutputVarNames() override;
512
549 std::vector<std::string> GetPointableVarNames();
550
554 std::vector<std::string> GetReadOnlyVarNames();
555
556 // Variable information functions
567 int GetVarGrid(const std::string name) override { return 0; }
568
605 std::string GetVarType(const std::string name) override;
640 std::string GetVarUnits(const std::string name) override;
641
676 int GetVarItemsize(const std::string name) override;
677
712 int GetVarNbytes(const std::string name) override;
713
720 std::string GetVarLocation(const std::string name) override { return "Unknown"; }
721
722 // Time functions
723
747 double GetCurrentTime() override;
748
754 double GetStartTime() override;
755
778 double GetEndTime() override;
779
804 std::string GetTimeUnits() override { return "seconds"; };
805 double GetTimeStep() override
806 {
807 return PhreeqcRM::GetTimeStep();
808 };
809
810 // Variable getters
869 //Add NEW_VARIABLE to GetValue Documentation
870 void GetValue(const std::string name, void* dest) override;
874 void GetValue(const std::string name, bool& OUTPUT);
878 void GetValue(const std::string name, bool* OUTPUT);
882 void GetValue(const std::string name, double& OUTPUT);
886 void GetValue(const std::string name, double* OUTPUT);
890 void GetValue(const std::string name, int& OUTPUT);
894 void GetValue(const std::string name, int* OUTPUT);
898 void GetValue(const std::string name, std::string& OUTPUT);
902 void GetValue(const std::string name, std::vector<double>& OUTPUT);
906 void GetValue(const std::string name, std::vector<int>& OUTPUT);
910 void GetValue(const std::string name, std::vector<std::string>& OUTPUT);
936 //Add NEW_VARIABLE to GetValuePtr Documentation
937 void* GetValuePtr(std::string name) override;
941 void GetValueAtIndices(std::string name, void* dest, int* inds, int count) override
942 {
943 throw NotImplemented();
944 };
945
946 // Variable setters
994 void SetValue(const std::string name, void* src) override;
998 void SetValue(const std::string name, bool src);
1002 void SetValue(const std::string name, const char* src);
1006 void SetValue(const std::string name, double src);
1010 void SetValue(const std::string name, int src);
1014 void SetValue(const std::string name, const std::string src);
1018 void SetValue(const std::string name, std::vector<double> src);
1022 void SetValue(const std::string name, std::vector<int> src);
1026 void SetValue(const std::string name, std::vector<std::string> src);
1030 void SetValueAtIndices(std::string name, int* inds, int count, void* src) override
1031 {
1032 throw NotImplemented();
1033 };
1034 // Grid information functions
1044 int GetGridRank(const int grid) override;
1052 int GetGridSize(const int grid) override;
1062 std::string GetGridType(const int grid) override;
1066 void GetGridShape(const int grid, int* shape) override
1067 {
1068 throw NotImplemented();
1069 }
1073 void GetGridSpacing(const int grid, double* spacing) override
1074 {
1075 throw NotImplemented();
1076 }
1080 void GetGridOrigin(const int grid, double* origin) override
1081 {
1082 throw NotImplemented();
1083 }
1087 void GetGridX(const int grid, double* x) override
1088 {
1089 throw NotImplemented();
1090 }
1094 void GetGridY(const int grid, double* y) override
1095 {
1096 throw NotImplemented();
1097 }
1101 void GetGridZ(const int grid, double* z) override
1102 {
1103 throw NotImplemented();
1104 }
1108 int GetGridNodeCount(const int grid) override
1109 {
1110 throw NotImplemented();
1111 }
1115 int GetGridEdgeCount(const int grid) override
1116 {
1117 throw NotImplemented();
1118 }
1122 int GetGridFaceCount(const int grid) override
1123 {
1124 throw NotImplemented();
1125 }
1129 void GetGridEdgeNodes(const int grid, int* edge_nodes) override
1130 {
1131 throw NotImplemented();
1132 }
1136 void GetGridFaceEdges(const int grid, int* face_edges) override
1137 {
1138 throw NotImplemented();
1139 }
1143 void GetGridFaceNodes(const int grid, int* face_nodes) override
1144 {
1145 throw NotImplemented();
1146 }
1150 void GetGridNodesPerFace(const int grid, int* nodes_per_face) override
1151 {
1152 throw NotImplemented();
1153 }
1235 void AddOutputVars(std::string option, std::string def) override;
1236
1237 IRM_RESULT SetLanguage(const char* string) { this->language = string; return IRM_OK; };
1238 // data
1239 std::string language;
1240 // typedef void (*VarFunction)(BMIPhreeqcRM* brm_ptr); // function pointer type
1241 // typedef std::map<std::string, VarFunction> VarFunction_map;
1242 // VarFunction_map varfn_map;
1243 // VarFunction GetFn(const std::string name);
1244 // std::set<std::string> UpdateMap;
1245 // std::set<std::string>& GetUpdateMap() { return UpdateMap; }
1246
1247#if defined(WITH_PYBIND11)
1248
1249 py::array BMIPhreeqcRM::get_value(std::string name, py::array arr);
1250
1251 //py::array get_value_test(std::string arg, py::array dest/* = py::none()*/);
1252 //py::array BMIPhreeqcRM::get_value_test(std::string name, py::array_t<double> dest = py::none());
1253 py::array get_value_ptr(std::string name);
1254
1255 void set_value(std::string name, py::array src);
1256
1257 py::array get_value_at_indices(std::string name, py::array dest, py::array indices);
1258
1259 void set_value_at_indices(std::string name, py::array indices, py::array src);
1260
1261 py::sequence process_sequence(py::sequence seq);
1262
1263 bool _initialized; // { var_man != nullptr }
1264#endif
1265
1266#if defined(SWIG) || defined(swig_python_EXPORTS)
1267 void get_value_ptr_double(std::string var, double** ARGOUTVIEW_ARRAY1, int* DIM1);
1268 void get_value_ptr_int(std::string var, int** ARGOUTVIEW_ARRAY1, int* DIM1);
1269 std::vector<std::string>& get_value_ptr_vector_strings(std::string var);
1270#endif
1271
1272protected:
1273 void Construct(Initializer initializer) override;
1274
1275private:
1276 //friend class RM_interface;
1277 VarManager* var_man;
1278 bool constructed = false;
1279
1280 void ClearBMISelectedOutput() override;
1281 void GenerateAutoOutputVars() override;
1282 void UpdateBMI(RMVARS v_enum) override;
1283 void UpdateVariables();
1284 RMVARS GetEnum(const std::string name);
1285};
1286#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.
#define MP_TYPE
Definition PhreeqcRM.h:15
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:1115
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:1143
std::string GetVarLocation(const std::string name) override
Definition BMIPhreeqcRM.h:720
void SetValue(const std::string name, double src)
IRM_RESULT SetLanguage(const char *string)
Definition BMIPhreeqcRM.h:1237
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:1066
void GetValue(const std::string name, std::vector< std::string > &OUTPUT)
int GetVarGrid(const std::string name) override
Definition BMIPhreeqcRM.h:567
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:804
double GetTimeStep() override
Definition BMIPhreeqcRM.h:805
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:1030
void AddOutputVars(std::string option, std::string def) override
std::string language
Definition BMIPhreeqcRM.h:1239
void GetValue(const std::string name, std::vector< double > &OUTPUT)
double GetEndTime() override
void GetGridY(const int grid, double *y) override
Definition BMIPhreeqcRM.h:1094
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:1136
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:1073
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:1087
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:941
std::vector< std::string > GetOutputVarNames() override
int GetGridFaceCount(const int grid) override
Definition BMIPhreeqcRM.h:1122
void GetValue(const std::string name, std::string &OUTPUT)
BMIPhreeqcRM(int ngrid, int nthreads)
std::string GetComponentName() override
Definition BMIPhreeqcRM.h:323
void UpdateUntil(double end_time) override
int GetGridNodeCount(const int grid) override
Definition BMIPhreeqcRM.h:1108
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:1101
void GetGridOrigin(const int grid, double *origin) override
Definition BMIPhreeqcRM.h:1080
void GetGridEdgeNodes(const int grid, int *edge_nodes) override
Definition BMIPhreeqcRM.h:1129
void GetGridNodesPerFace(const int grid, int *nodes_per_face) override
Definition BMIPhreeqcRM.h:1150
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:267
double GetTimeStep(void)
Definition PhreeqcRM.h:3022