ChemicalFemPhysics
The GeMA Standard Chemical FEM Physics Plugin
Loading...
Searching...
No Matches
gmpIphreeqcReaction.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
26#ifndef _GEMA_PLUGIN_IPHREEQC_REACTION_H_
27#define _GEMA_PLUGIN_IPHREEQC_REACTION_H_
28
30#include <gmSimulationData.h>
31
32#pragma warning( push ) // Phreeqc messes with warning 4251 and ends-up re-enabling it
33#include <IPhreeqc.hpp>
34#pragma warning( pop )
35
36
38class GMP_CHEMICAL_FEM_PHYSICS_API_EXPORT GmpIphreeqcReaction : public GmpChemicalFemPhysics
39{
40public:
41 GmpIphreeqcReaction(GmSimulationData* simulation, QString id, QString description, const GmLogCategory& logger);
42 virtual ~GmpIphreeqcReaction();
43
44 // Comments on the base class
45 virtual const char* pluginType() const { return "iphreeqc"; }
46
47 // Comments on the base class
48 virtual const QVariantMap* physicsMetaDataMap();
49
50 // Comments on the base class
51 virtual bool checkLoadedData();
52
53 // Checks required nodal accessors based on the phreeqc input file
54 bool checksNodalAccessors();
55
56 // Comments on the base class
57 virtual bool beforeElementStiffnessLoop(const GmpFemMatrixSet& elemMatrices, const GmpFemVectorSet& elemVectors);
58
59 bool createIPhreeqcInput(IPhreeqc& R, const char* dump, int node);
60
61 // Function to Run IPhreeqc
62 bool runIPhreeqc(IPhreeqc& R);
63
64 // funtion to run Iphreeqc to calculate initial condition to mesh
65 bool evaluateInitialConditions(QString& input);
66
67 // save IPhreeqc Results value to node mesh attributes for Initial Conditions
68 virtual bool setsInitialConditions(IPhreeqc& R, int node);
69
70 // Gets selected phreeqc output values
71 bool getSelectedPhreeqcOutputs(IPhreeqc& phreeqc, GmVector& data, int node);
72
73 // save IPhreeqc value to node mesh attributes
74 bool saveIPhreeqcValuesToNode(IPhreeqc& R, int node);
75
76 // Updates solution ions of each especies for the next Phreeqc simulation
77 bool updatesSolution(IPhreeqc& R, GmValueAccessor* ionAcc, int node);
78
79 // Updates kinetic reaction of each mineral for the next Phreeqc simulation
80 bool updatesKinetics(IPhreeqc& R, GmValueAccessor* ionAcc, int node);
81
82 // UpdatesEquilibrium reaction of each mineral for the next Phreeqc simulation
83 bool updatesEquilibrium(IPhreeqc& R, GmValueAccessor* ionAcc, int node);
84
85 // Loads chemical parameters from phreeqc input file
86 bool loadsChemicalParameters(QString& inputPhreeqc);
87
88 // Loads selected output data from phreeqc input file
89 bool loadsOutputData(const QString& line, QString& Keyword, QList<QPair<QString, int>>& data, int offset=1);
90
91 // Extracts segment of string between two words
92 QString extractSegment(const QString& input, const QString& startWord, const QString& endWord);
93
94 // Get results after convergence
95 virtual bool calcDerivedResults(bool nonLinearSolver);
96
97 // method to run Iphreeqc at every node fo the mesh
98 bool runIphreeqcNodes();
99
100 // read node reaction values
101 void getReactionValues(const GmElement* e, const GmVector& Rg, GmVector& Re, int pos) const;
102
103 // Fill vector for element data
104 virtual void FillElementalReaction(const GmElement* e, GmVector& elemFe, const GmVector& Fr, int pos) const;
105
106 // Read node mineral values
107 void getMineralValues(const GmElement* e, GmVector& Rg, GmVector & Re, int pos) const;
108
109protected:
110 // See comments on the base class
111 virtual bool checkAndLoadPrivateData(LuaTable& table);
112 // Fills reaction rate contribution
113 virtual bool reactionRate(const GmElement* e, const GmVector* ip, int ipIndex, const GmVector& N,
114 const GmVector& C, double wtJ, GmVector& elemFe, GmMatrix& elemK,
115 bool needsFe, bool needsK);
116 // fill elemental mass
117 bool fillElementalMass();
118
121 {
123 INPUT_A_ID, // Id for retrieving the phreeqc input file
124 POROS_A_ID,
125
126 // --- NO ADDING BELOW THIS LINE
128 };
129
132 {
139 poroMOld_NA_ID,
140
141 // ------ NO ADDING BELOW THIS LINE
143 };
144
146 {
148
149
150 // --- NO ADDING BELOW THIS LINE
152 };
153
154private:
155 bool _isKinetics; // Flags to identify kinetics reaction in phreeqc input file
156 bool _isEquilibrium; // Flags to identify Equilibrium reaction in phreeqc input file
157 bool _isSaturation; // Flags to identify saturation indices in the phreeqc input file
158 int _nOut; // Size of phreeqc output data
159 IPhreeqc _iphreeqc; // IPhreeqc reaction
160 QByteArray _dumpData; // variable to store compressing all dump data
161 QList<QPair<QString, int>> _solution; // List containing the name and output position of solution ions
162 QList<QPair<QString, int>> _kiMineral; // List containing the name and output position of kinetic minerals
163 QList<QPair<QString, int>> _eqMineral; // List containing the name and output position of equilibium minerals
164 QList<QPair<QString, int>> _siMineral; // List containing the name and output position of mineral saturation index
165 QString _selectedOutput; // String containing the selected output of the phreeqc input file
166
167};
168
169#endif
Basic class for chemical fem physics. Treats the diffusion and convective terms of the transport equa...
Definition gmpChemicalFemPhysics.h:35
virtual const QVariantMap * physicsMetaDataMap()
Returns a pointer to the basic chemical physics attribute map, built when the function is called for ...
Definition gmpChemicalFemPhysics.cpp:95
virtual bool reactionRate(const GmElement *e, const GmVector *ip, int ipIndex, const GmVector &N, const GmVector &C, double wtJ, GmVector &elemFe, GmMatrix &elemK, bool needsFe, bool needsK)=0
Virtual function called by fillElementData() for each integration point so that derived classes can a...
@ NUM_ATTRIBUTE_IDS
The number of attribute ids above.
Definition gmpChemicalFemPhysics.h:84
virtual bool calcDerivedResults(bool nonLinearSolver)
Calc velocity and flow on nodes and/or Gauss points.
Definition gmpChemicalFemPhysics.cpp:1030
virtual bool checkLoadedData()
Checks the existance of the velocity accessor, and also sizes for the dispersion and retardation coef...
Definition gmpChemicalFemPhysics.cpp:176
@ NUM_GA_IDS
The number of gauss attribute ids above.
Definition gmpChemicalFemPhysics.h:107
@ NUM_NA_IDS
The number of node attribute ids above.
Definition gmpChemicalFemPhysics.h:97
Extends the basic chemical physics transport equation by providing reaction rates based on the Iphree...
Definition gmpIphreeqcReaction.h:39
GaussAttributeIds
Definition gmpIphreeqcReaction.h:146
@ NUM_GA_IDS
The number of gauss attributes.
Definition gmpIphreeqcReaction.h:151
NodeAttributeIds
IDs for physics node attributes.
Definition gmpIphreeqcReaction.h:132
@ IonSolOld_NA_ID
Base Id for history of Ion transport node attribute(s)
Definition gmpIphreeqcReaction.h:134
@ EqM_NA_ID
Base Id for Reaction in equillibrium.
Definition gmpIphreeqcReaction.h:136
@ poroM_NA_ID
Base Id for porosity variation.
Definition gmpIphreeqcReaction.h:138
@ NUM_NA_IDS
The number of node attribute ids above.
Definition gmpIphreeqcReaction.h:142
@ KiM_NA_ID
Base Id for mineral for reaction.
Definition gmpIphreeqcReaction.h:137
@ SIndex_NA_ID
Base Id for Saturation index.
Definition gmpIphreeqcReaction.h:135
iPhreeqcReactionPhysicsAttributeIds
Additional IDs for physics attributes.
Definition gmpIphreeqcReaction.h:121
@ NUM_ATTRIBUTE_IDS
The number of attribute ids above.
Definition gmpIphreeqcReaction.h:127
arma::mat GmMatrix
arma::vec GmVector
Declaration of the GmpChemicalFemPhysics classes.