Cantera  2.4.0
MineralEQ3.cpp
Go to the documentation of this file.
1 /**
2  * @file MineralEQ3.cpp
3  * Definition file for the MineralEQ3 class, which represents a fixed-composition
4  * incompressible substance (see \ref thermoprops and
5  * class \link Cantera::MineralEQ3 MineralEQ3\endlink)
6  */
7 
8 // This file is part of Cantera. See License.txt in the top-level directory or
9 // at http://www.cantera.org/license.txt for license and copyright information.
10 
11 #include "cantera/base/ctml.h"
15 
16 using namespace std;
17 
18 namespace Cantera
19 {
20 
21 // ---- Constructors -------
22 
23 MineralEQ3::MineralEQ3(const std::string& infile, const std::string& id_)
24 {
25  warn_deprecated("Class MineralEQ3", "To be removed after Cantera 2.4");
26  initThermoFile(infile, id_);
27 }
28 
29 MineralEQ3::MineralEQ3(XML_Node& xmlphase, const std::string& id_)
30 {
31  warn_deprecated("Class MineralEQ3", "To be removed after Cantera 2.4");
32  importPhase(xmlphase, this);
33 }
34 
35 // ----- Mechanical Equation of State ------
36 
37 doublereal MineralEQ3::pressure() const
38 {
39  return m_press;
40 }
41 
42 void MineralEQ3::setPressure(doublereal p)
43 {
44  m_press = p;
45 }
46 
47 doublereal MineralEQ3::isothermalCompressibility() const
48 {
49  return 0.0;
50 }
51 
52 doublereal MineralEQ3::thermalExpansionCoeff() const
53 {
54  return 0.0;
55 }
56 
57 // ---- Chemical Potentials and Activities ----
58 
59 void MineralEQ3::getActivityConcentrations(doublereal* c) const
60 {
61  c[0] = 1.0;
62 }
63 
64 doublereal MineralEQ3::standardConcentration(size_t k) const
65 {
66  return 1.0;
67 }
68 
69 doublereal MineralEQ3::logStandardConc(size_t k) const
70 {
71  return 0.0;
72 }
73 
74 // Properties of the Standard State of the Species in the Solution
75 
76 void MineralEQ3::getStandardChemPotentials(doublereal* mu0) const
77 {
78  getGibbs_RT(mu0);
79  mu0[0] *= RT();
80 }
81 
82 void MineralEQ3::getEnthalpy_RT(doublereal* hrt) const
83 {
84  getEnthalpy_RT_ref(hrt);
85  doublereal presCorrect = (m_press - m_p0) / molarDensity();
86  hrt[0] += presCorrect / RT();
87 }
88 
89 void MineralEQ3::getEntropy_R(doublereal* sr) const
90 {
91  getEntropy_R_ref(sr);
92 }
93 
94 void MineralEQ3::getGibbs_RT(doublereal* grt) const
95 {
96  getEnthalpy_RT(grt);
97  grt[0] -= m_s0_R;
98 }
99 
100 void MineralEQ3::getCp_R(doublereal* cpr) const
101 {
102  _updateThermo();
103  cpr[0] = m_cp0_R;
104 }
105 
106 void MineralEQ3::getIntEnergy_RT(doublereal* urt) const
107 {
108  _updateThermo();
109  urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
110 }
111 
112 // ---- Thermodynamic Values for the Species Reference States ----
113 
114 void MineralEQ3::getIntEnergy_RT_ref(doublereal* urt) const
115 {
116  _updateThermo();
117  urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
118 }
119 
120 // ---- Initialization and Internal functions
121 
122 void MineralEQ3::setParameters(int n, doublereal* const c)
123 {
124  setDensity(c[0]);
125 }
126 
127 void MineralEQ3::getParameters(int& n, doublereal* const c) const
128 {
129  n = 1;
130  c[0] = density();
131 }
132 
133 void MineralEQ3::initThermoXML(XML_Node& phaseNode, const std::string& id_)
134 {
135  // Find the Thermo XML node
136  if (!phaseNode.hasChild("thermo")) {
137  throw CanteraError("HMWSoln::initThermoXML",
138  "no thermo XML node");
139  }
140 
141  const XML_Node* xsp = speciesData()[0];
142 
143  XML_Node* aStandardState = 0;
144  if (xsp->hasChild("standardState")) {
145  aStandardState = &xsp->child("standardState");
146  } else {
147  throw CanteraError("MineralEQ3::initThermoXML",
148  "no standard state mode");
149  }
150  doublereal volVal = 0.0;
151  if (aStandardState->attrib("model") != "constantVolume") {
152  throw CanteraError("MineralEQ3::initThermoXML",
153  "wrong standard state mode");
154  }
155  if (aStandardState->hasChild("V0_Pr_Tr")) {
156  XML_Node& aV = aStandardState->child("V0_Pr_Tr");
157  double Afactor = toSI("cm3/gmol");
158  if (aV.hasAttrib("units")) {
159  Afactor = toSI(aV.attrib("units"));
160  }
161  volVal = getFloat(*aStandardState, "V0_Pr_Tr");
162  m_V0_pr_tr= volVal;
163  volVal *= Afactor;
164  } else {
165  throw CanteraError("MineralEQ3::initThermoXML",
166  "wrong standard state mode");
167  }
168  setDensity(molecularWeight(0) / volVal);
169 
170  const XML_Node& MinEQ3node = xsp->child("thermo").child("MinEQ3");
171 
172  m_deltaG_formation_pr_tr =
173  getFloat(MinEQ3node, "DG0_f_Pr_Tr", "actEnergy") / actEnergyToSI("cal/gmol");
174  m_deltaH_formation_pr_tr =
175  getFloat(MinEQ3node, "DH0_f_Pr_Tr", "actEnergy") / actEnergyToSI("cal/gmol");
176  m_Entrop_pr_tr = getFloat(MinEQ3node, "S0_Pr_Tr", "toSI") / toSI("cal/gmol/K");
177  m_a = getFloat(MinEQ3node, "a", "toSI") / toSI("cal/gmol/K");
178  m_b = getFloat(MinEQ3node, "b", "toSI") / toSI("cal/gmol/K2");
179  m_c = getFloat(MinEQ3node, "c", "toSI") / toSI("cal-K/gmol");
180 
181  convertDGFormation();
182 }
183 
184 void MineralEQ3::setParametersFromXML(const XML_Node& eosdata)
185 {
186  if (eosdata["model"] != "MineralEQ3") {
187  throw CanteraError("MineralEQ3::MineralEQ3",
188  "thermo model attribute must be MineralEQ3");
189  }
190 }
191 
192 doublereal MineralEQ3::LookupGe(const std::string& elemName)
193 {
194  size_t iE = elementIndex(elemName);
195  if (iE == npos) {
196  throw CanteraError("PDSS_HKFT::LookupGe", "element " + elemName + " not found");
197  }
198  doublereal geValue = entropyElement298(iE);
199  if (geValue == ENTROPY298_UNKNOWN) {
200  throw CanteraError("PDSS_HKFT::LookupGe",
201  "element " + elemName + " does not have a supplied entropy298");
202  }
203  geValue *= (-298.15);
204  return geValue;
205 }
206 
207 void MineralEQ3::convertDGFormation()
208 {
209  // Ok let's get the element compositions and conversion factors.
210  doublereal totalSum = 0.0;
211  for (size_t m = 0; m < nElements(); m++) {
212  double na = nAtoms(0, m);
213  if (na > 0.0) {
214  totalSum += na * LookupGe(elementName(m));
215  }
216  }
217  // Ok, now do the calculation. Convert to joules kmol-1
218  doublereal dg = m_deltaG_formation_pr_tr * toSI("cal/gmol");
219  //! Store the result into an internal variable.
220  m_Mu0_pr_tr = dg + totalSum;
221 
222  double Hcalc = m_Mu0_pr_tr + 298.15 * m_Entrop_pr_tr * toSI("cal/gmol");
223  double DHjmol = m_deltaH_formation_pr_tr * toSI("kal/gmol");
224 
225  // If the discrepancy is greater than 100 cal gmol-1, print an error
226  if (fabs(Hcalc -DHjmol) > 100 * toSI("cal/gmol")) {
227  throw CanteraError("installMinEQ3asShomateThermoFromXML()",
228  "DHjmol is not consistent with G and S: {} vs {}",
229  Hcalc, DHjmol);
230  }
231 }
232 
233 }
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
doublereal actEnergyToSI(const std::string &unit)
Return the conversion factor to convert activation energy unit std::string &#39;unit&#39; to Kelvin...
Definition: global.cpp:146
doublereal toSI(const std::string &unit)
Return the conversion factor to convert unit std::string &#39;unit&#39; to SI units.
Definition: global.cpp:135
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:165
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
STL namespace.
bool hasAttrib(const std::string &a) const
Tests whether the current node has an attribute with a particular name.
Definition: xml.cpp:541
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
#define ENTROPY298_UNKNOWN
Number indicating we don&#39;t know the entropy of the element in its most stable state at 298...
Definition: Elements.h:87
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:536
XML_Node & child(const size_t n) const
Return a changeable reference to the n&#39;th child of the current node.
Definition: xml.cpp:546
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:500
Header file for the MineralEQ3 class, which represents a fixed-composition incompressible substance b...
Contains declarations for string manipulation functions within Cantera.
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
Definition: ctml.cpp:164
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8