Cantera  2.1.2
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 /*
9  * Copyright (2005) Sandia Corporation. Under the terms of
10  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
11  * U.S. Government retains certain rights in this software.
12  *
13  * Copyright 2001 California Institute of Technology
14  */
15 #include "cantera/base/ct_defs.h"
19 
22 
23 using namespace std;
24 
25 namespace Cantera
26 {
27 
28 /*
29  * ---- Constructors -------
30  */
31 
32 MineralEQ3::MineralEQ3():
34 {
35 }
36 
37 MineralEQ3::MineralEQ3(const std::string& infile, std::string id_) :
39 {
40  XML_Node* root = get_XML_File(infile);
41  if (id_ == "-") {
42  id_ = "";
43  }
44  XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
45  if (!xphase) {
46  throw CanteraError("MineralEQ3::MineralEQ3",
47  "Couldn't find phase name in file:" + id_);
48  }
49  // Check the model name to ensure we have compatibility
50  const XML_Node& th = xphase->child("thermo");
51  std::string model = th["model"];
52  if (model != "StoichSubstance" && model != "MineralEQ3") {
53  throw CanteraError("MineralEQ3::MineralEQ3",
54  "thermo model attribute must be StoichSubstance");
55  }
56  importPhase(*xphase, this);
57 }
58 
59 MineralEQ3::MineralEQ3(XML_Node& xmlphase, const std::string& id_) :
61 {
62  if (id_ != "") {
63  std::string idxml = xmlphase["id"];
64  if (id_ != idxml) {
65  throw CanteraError("MineralEQ3::MineralEQ3",
66  "id's don't match");
67  }
68  }
69  const XML_Node& th = xmlphase.child("thermo");
70  std::string model = th["model"];
71  if (model != "StoichSubstance" && model != "MineralEQ3") {
72  throw CanteraError("MineralEQ3::MineralEQ3",
73  "thermo model attribute must be StoichSubstance");
74  }
75  importPhase(xmlphase, this);
76 }
77 
80 {
81  *this = operator=(right);
82 }
83 
86 {
87  if (&right == this) {
88  return *this;
89  }
91  m_Mu0_pr_tr = right.m_Mu0_pr_tr;
95  m_V0_pr_tr = right.m_V0_pr_tr;
96  m_a = right.m_a;
97  m_b = right.m_b;
98  m_c = right.m_c;
99 
100  return *this;
101 }
102 
104 {
105  return new MineralEQ3(*this);
106 }
107 
108 /*
109  * ---- Utilities -----
110  */
111 
113 {
114  return cStoichSubstance;
115 }
116 
117 /*
118  * ----- Mechanical Equation of State ------
119  */
120 
121 doublereal MineralEQ3::pressure() const
122 {
123  return m_press;
124 }
125 
126 void MineralEQ3::setPressure(doublereal p)
127 {
128  m_press = p;
129 }
130 
132 {
133  return 0.0;
134 }
135 
137 {
138  return 0.0;
139 }
140 
141 /*
142  * ---- Chemical Potentials and Activities ----
143  */
144 
145 void MineralEQ3::
146 getActivityConcentrations(doublereal* c) const
147 {
148  c[0] = 1.0;
149 }
150 
151 doublereal MineralEQ3::standardConcentration(size_t k) const
152 {
153  return 1.0;
154 }
155 
156 doublereal MineralEQ3::logStandardConc(size_t k) const
157 {
158  return 0.0;
159 }
160 
161 void MineralEQ3::
162 getUnitsStandardConc(doublereal* uA, int k, int sizeUA) const
163 {
164  for (int i = 0; i < 6; i++) {
165  uA[i] = 0;
166  }
167 }
168 
169 /*
170  * Properties of the Standard State of the Species in the Solution
171  */
172 
173 void MineralEQ3::
174 getStandardChemPotentials(doublereal* mu0) const
175 {
176  getGibbs_RT(mu0);
177  mu0[0] *= GasConstant * temperature();
178 }
179 
180 void MineralEQ3::getEnthalpy_RT(doublereal* hrt) const
181 {
182  getEnthalpy_RT_ref(hrt);
183  doublereal RT = GasConstant * temperature();
184  doublereal presCorrect = (m_press - m_p0) / molarDensity();
185  hrt[0] += presCorrect / RT;
186 }
187 
188 void MineralEQ3::getEntropy_R(doublereal* sr) const
189 {
190  getEntropy_R_ref(sr);
191 }
192 
193 void MineralEQ3::getGibbs_RT(doublereal* grt) const
194 {
195  getEnthalpy_RT(grt);
196  grt[0] -= m_s0_R[0];
197 }
198 
199 void MineralEQ3::getCp_R(doublereal* cpr) const
200 {
201  _updateThermo();
202  cpr[0] = m_cp0_R[0];
203 }
204 
205 void MineralEQ3::getIntEnergy_RT(doublereal* urt) const
206 {
207  _updateThermo();
208  doublereal RT = GasConstant * temperature();
209  urt[0] = m_h0_RT[0] - m_p0 / molarDensity() / RT;
210 }
211 
212 /*
213  * ---- Thermodynamic Values for the Species Reference States ----
214  */
215 
216 void MineralEQ3::getIntEnergy_RT_ref(doublereal* urt) const
217 {
218  _updateThermo();
219  doublereal RT = GasConstant * temperature();
220  urt[0] = m_h0_RT[0] - m_p0 / molarDensity() / RT;
221 }
222 
223 /*
224  * ---- Initialization and Internal functions
225  */
226 
228 {
229  /*
230  * Call the base class thermo initializer
231  */
233 }
234 
235 void MineralEQ3::setParameters(int n, doublereal* const c)
236 {
237  warn_deprecated("MineralEQ3::setParameters");
238  doublereal rho = c[0];
239  setDensity(rho);
240 }
241 
242 void MineralEQ3::getParameters(int& n, doublereal* const c) const
243 {
244  warn_deprecated("MineralEQ3::getParameters");
245  doublereal rho = density();
246  n = 1;
247  c[0] = rho;
248 }
249 
250 void MineralEQ3::initThermoXML(XML_Node& phaseNode, const std::string& id_)
251 {
252  /*
253  * Find the Thermo XML node
254  */
255  if (!phaseNode.hasChild("thermo")) {
256  throw CanteraError("HMWSoln::initThermoXML",
257  "no thermo XML node");
258  }
259 
260  std::vector<const XML_Node*> xspecies = speciesData();
261  const XML_Node* xsp = xspecies[0];
262 
263  XML_Node* aStandardState = 0;
264  if (xsp->hasChild("standardState")) {
265  aStandardState = &xsp->child("standardState");
266  } else {
267  throw CanteraError("MineralEQ3::initThermoXML",
268  "no standard state mode");
269  }
270  doublereal volVal = 0.0;
271  string smodel = (*aStandardState)["model"];
272  if (smodel != "constantVolume") {
273  throw CanteraError("MineralEQ3::initThermoXML",
274  "wrong standard state mode");
275  }
276  if (aStandardState->hasChild("V0_Pr_Tr")) {
277  XML_Node& aV = aStandardState->child("V0_Pr_Tr");
278  string Aunits = "";
279  double Afactor = toSI("cm3/gmol");
280  if (aV.hasAttrib("units")) {
281  Aunits = aV.attrib("units");
282  Afactor = toSI(Aunits);
283  }
284  volVal = ctml::getFloat(*aStandardState, "V0_Pr_Tr");
285  m_V0_pr_tr= volVal;
286  volVal *= Afactor;
287  m_speciesSize[0] = volVal;
288  } else {
289  throw CanteraError("MineralEQ3::initThermoXML",
290  "wrong standard state mode");
291  }
292  doublereal rho = molecularWeight(0) / volVal;
293  setDensity(rho);
294 
295  const XML_Node& sThermo = xsp->child("thermo");
296  const XML_Node& MinEQ3node = sThermo.child("MinEQ3");
297 
298 
300  ctml::getFloatDefaultUnits(MinEQ3node, "DG0_f_Pr_Tr", "cal/gmol", "actEnergy");
302  ctml::getFloatDefaultUnits(MinEQ3node, "DH0_f_Pr_Tr", "cal/gmol", "actEnergy");
303  m_Entrop_pr_tr = ctml::getFloatDefaultUnits(MinEQ3node, "S0_Pr_Tr", "cal/gmol/K");
304  m_a = ctml::getFloatDefaultUnits(MinEQ3node, "a", "cal/gmol/K");
305  m_b = ctml::getFloatDefaultUnits(MinEQ3node, "b", "cal/gmol/K2");
306  m_c = ctml::getFloatDefaultUnits(MinEQ3node, "c", "cal-K/gmol");
307 
308  convertDGFormation();
309 }
310 
312 {
313  std::string model = eosdata["model"];
314  if (model != "MineralEQ3") {
315  throw CanteraError("MineralEQ3::MineralEQ3",
316  "thermo model attribute must be MineralEQ3");
317  }
318 }
319 
320 doublereal MineralEQ3::LookupGe(const std::string& elemName)
321 {
322  size_t iE = elementIndex(elemName);
323  if (iE == npos) {
324  throw CanteraError("PDSS_HKFT::LookupGe", "element " + elemName + " not found");
325  }
326  doublereal geValue = entropyElement298(iE);
327  if (geValue == ENTROPY298_UNKNOWN) {
328  throw CanteraError("PDSS_HKFT::LookupGe",
329  "element " + elemName + " does not have a supplied entropy298");
330  }
331  geValue *= (-298.15);
332  return geValue;
333 }
334 
335 void MineralEQ3::convertDGFormation()
336 {
337  /*
338  * Ok let's get the element compositions and conversion factors.
339  */
340  doublereal na;
341  doublereal ge;
342  string ename;
343 
344  doublereal totalSum = 0.0;
345  for (size_t m = 0; m < nElements(); m++) {
346  na = nAtoms(0, m);
347  if (na > 0.0) {
348  ename = elementName(m);
349  ge = LookupGe(ename);
350  totalSum += na * ge;
351  }
352  }
353  // Add in the charge
354  // if (m_charge_j != 0.0) {
355  // ename = "H";
356  // ge = LookupGe(ename);
357  // totalSum -= m_charge_j * ge;
358  //}
359  // Ok, now do the calculation. Convert to joules kmol-1
360  doublereal dg = m_deltaG_formation_pr_tr * 4.184 * 1.0E3;
361  //! Store the result into an internal variable.
362  m_Mu0_pr_tr = dg + totalSum;
363 }
364 
365 }
doublereal m_Entrop_pr_tr
Input value of S_j at Tr and Pr (cal gmol-1 K-1)
Definition: MineralEQ3.h:450
doublereal nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
Definition: Phase.cpp:215
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:484
doublereal m_deltaH_formation_pr_tr
Input Value of deltaH of Formation at Tr and Pr (cal gmol-1)
Definition: MineralEQ3.h:468
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:534
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Definition: MineralEQ3.cpp:146
XML_Node * get_XML_File(const std::string &file, int debug)
Return a pointer to the XML tree for a Cantera input file.
Definition: global.cpp:144
virtual void initThermo()
Internal initialization required after all species have been added.
Definition: MineralEQ3.cpp:227
size_t nElements() const
Number of elements.
Definition: Phase.cpp:139
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
Definition: MineralEQ3.cpp:156
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:534
doublereal toSI(const std::string &unit)
Return the conversion factor to convert unit std::string 'unit' to SI units.
Definition: global.cpp:196
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:173
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Definition: MineralEQ3.cpp:188
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
Definition: MineralEQ3.cpp:193
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
StoichSubstanceSSTP & operator=(const StoichSubstanceSSTP &right)
Assignment operator.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
Definition: MineralEQ3.cpp:242
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:76
Virtual base class for the calculation of multiple-species thermodynamic reference-state property man...
vector_fp m_speciesSize
Vector of species sizes.
Definition: Phase.h:729
doublereal getFloat(const Cantera::XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
Definition: ctml.cpp:267
virtual void getEntropy_R_ref(doublereal *er) const
doublereal m_deltaG_formation_pr_tr
Input Value of deltaG of Formation at Tr and Pr (cal gmol-1)
Definition: MineralEQ3.h:459
virtual void setPressure(doublereal p)
Set the pressure at constant temperature. Units: Pa.
Definition: MineralEQ3.cpp:126
doublereal molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:597
virtual void getUnitsStandardConc(doublereal *uA, int k=0, int sizeUA=6) const
Returns the units of the standard and generalized concentrations.
Definition: MineralEQ3.cpp:162
ThermoPhase * duplMyselfAsThermoPhase() const
Duplication function.
Definition: MineralEQ3.cpp:103
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:584
virtual void getStandardChemPotentials(doublereal *mu0) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Definition: MineralEQ3.cpp:174
vector_fp m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
doublereal entropyElement298(size_t m) const
Entropy of the element in its standard state at 298 K and 1 bar.
Definition: Phase.cpp:184
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
Class StoichSubstanceSSTP represents a stoichiometric (fixed composition) incompressible substance...
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
Definition: MineralEQ3.cpp:151
doublereal m_c
c coefficient (cal K gmol-1 K) x 10^-5
Definition: MineralEQ3.h:483
MineralEQ3()
Default constructor for the StoichSubstanceSSTP class.
Definition: MineralEQ3.cpp:32
bool importPhase(XML_Node &phase, ThermoPhase *th, SpeciesThermoFactory *spfactory)
Import a phase information into an empty thermophase object.
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters.
Definition: MineralEQ3.cpp:235
doublereal m_a
a coefficient (cal gmol-1 K-1)
Definition: MineralEQ3.h:477
virtual int eosType() const
Equation of state flag.
Definition: MineralEQ3.cpp:112
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
Definition: MineralEQ3.cpp:199
MineralEQ3 & operator=(const MineralEQ3 &right)
Assignment operator.
Definition: MineralEQ3.cpp:85
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
vector_fp m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
vector_fp m_cp0_R
Dimensionless heat capacity at the (mtlast, m_p0)
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:574
#define ENTROPY298_UNKNOWN
Number indicating we don't know the entropy of the element in its most stable state at 298...
Definition: Elements.h:84
doublereal m_V0_pr_tr
Input Value of the molar volume at T_r and P_r.
Definition: MineralEQ3.h:474
doublereal m_b
b coefficient (cal gmol-1 K-2) x 10^3
Definition: MineralEQ3.h:480
doublereal temperature() const
Temperature (K).
Definition: Phase.h:528
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
Definition: MineralEQ3.cpp:180
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
Definition: MineralEQ3.cpp:311
doublereal getFloatDefaultUnits(const Cantera::XML_Node &parent, const std::string &name, const std::string &defaultUnits, const std::string &type)
Get a floating-point value from a child element with a defined units field.
Definition: ctml.cpp:347
size_t elementIndex(const std::string &name) const
Return the index of element named 'name'.
Definition: Phase.cpp:164
Header file for the MineralEQ3 class, which represents a fixed-composition incompressible substance b...
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
const std::vector< const XML_Node * > & speciesData() const
Return a pointer to the vector of XML nodes containing the species data for this phase.
doublereal m_press
The current pressure of the solution (Pa)
std::string elementName(size_t m) const
Name of the element with index m.
Definition: Phase.cpp:158
virtual doublereal pressure() const
Report the Pressure. Units: Pa.
Definition: MineralEQ3.cpp:121
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition: MineralEQ3.cpp:136
Class MineralEQ3 represents a stoichiometric (fixed composition) incompressible substance based on EQ...
Definition: MineralEQ3.h:97
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: MineralEQ3.cpp:131
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
Definition: MineralEQ3.cpp:205
XML_Node * get_XML_NameID(const std::string &nameTarget, const std::string &file_ID, XML_Node *root)
This routine will locate an XML node in either the input XML tree or in another input file specified ...
Definition: global.cpp:271
virtual void setDensity(const doublereal density_)
Set the internally stored density (kg/m^3) of the phase Note the density of a phase is an independent...
Definition: Phase.h:549
bool hasAttrib(const std::string &a) const
Tests whether the current node has an attribute with a particular name.
Definition: xml.cpp:579
virtual void getIntEnergy_RT_ref(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the reference state at the current temperat...
Definition: MineralEQ3.cpp:216
doublereal m_Mu0_pr_tr
Value of the Absolute Gibbs Free Energy NIST scale at T_r and P_r.
Definition: MineralEQ3.h:444
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Initialize the phase parameters from an XML file.
Definition: MineralEQ3.cpp:250