Cantera  2.3.0
IdealSolnGasVPSS.cpp
Go to the documentation of this file.
1 /**
2  * @file IdealSolnGasVPSS.cpp
3  * Definition file for a derived class of ThermoPhase that assumes either
4  * an ideal gas or ideal solution approximation and handles
5  * variable pressure standard state methods for calculating
6  * thermodynamic properties (see \ref thermoprops and
7  * class \link Cantera::IdealSolnGasVPSS IdealSolnGasVPSS\endlink).
8  */
9 
10 // This file is part of Cantera. See License.txt in the top-level directory or
11 // at http://www.cantera.org/license.txt for license and copyright information.
12 
14 #include "cantera/thermo/PDSS.h"
17 #include "cantera/base/utilities.h"
18 
19 using namespace std;
20 
21 namespace Cantera
22 {
23 
24 IdealSolnGasVPSS::IdealSolnGasVPSS() :
25  m_idealGas(0),
26  m_formGC(0)
27 {
28 }
29 
30 IdealSolnGasVPSS::IdealSolnGasVPSS(const std::string& infile, std::string id_) :
31  m_idealGas(0),
32  m_formGC(0)
33 {
34  XML_Node* root = get_XML_File(infile);
35  if (id_ == "-") {
36  id_ = "";
37  }
38  XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
39  if (!xphase) {
40  throw CanteraError("newPhase",
41  "Couldn't find phase named \"" + id_ + "\" in file, " + infile);
42  }
43  importPhase(*xphase, this);
44 }
45 
46 IdealSolnGasVPSS::IdealSolnGasVPSS(const IdealSolnGasVPSS& b) :
47  m_idealGas(0),
48  m_formGC(0)
49 {
50  *this = b;
51 }
52 
53 IdealSolnGasVPSS& IdealSolnGasVPSS::operator=(const IdealSolnGasVPSS& b)
54 {
55  if (&b != this) {
56  // Mostly, this is a passthrough to the underlying assignment operator
57  // for the ThermoPhae parent object.
58  VPStandardStateTP::operator=(b);
59 
60  // However, we have to handle data that we own.
61  m_idealGas = b.m_idealGas;
62  m_formGC = b.m_formGC;
63  }
64  return *this;
65 }
66 
68 {
69  return new IdealSolnGasVPSS(*this);
70 }
71 
73 {
74  warn_deprecated("EdgePhase::IdealSolnGasVPSS",
75  "To be removed after Cantera 2.3.");
76  if (m_idealGas) {
77  return cIdealSolnGasVPSS;
78  }
79  return cIdealSolnGasVPSS_iscv;
80 }
81 
82 // ------------Molar Thermodynamic Properties -------------------------
83 
85 {
87  return RT() * mean_X(m_VPSS_ptr->enthalpy_RT());
88 }
89 
91 {
93  return GasConstant * (mean_X(m_VPSS_ptr->entropy_R()) - sum_xlogx());
94 }
95 
96 doublereal IdealSolnGasVPSS::cp_mole() const
97 {
99  return GasConstant * mean_X(m_VPSS_ptr->cp_R());
100 }
101 
102 doublereal IdealSolnGasVPSS::cv_mole() const
103 {
104  return cp_mole() - GasConstant;
105 }
106 
108 {
109  m_Pcurrent = p;
111  calcDensity();
112 }
113 
115 {
116  // Calculate the molarVolume of the solution (m**3 kmol-1)
117  if (m_idealGas) {
118  double dens = m_Pcurrent * meanMolecularWeight() / RT();
119  Phase::setDensity(dens);
120  } else {
121  const doublereal* const dtmp = moleFractdivMMW();
122  const vector_fp& vss = m_VPSS_ptr->getStandardVolumes();
123  double dens = 1.0 / dot(vss.begin(), vss.end(), dtmp);
124 
125  // Set the density in the parent State object directly
126  Phase::setDensity(dens);
127  }
128 }
129 
131 {
132  if (m_idealGas) {
133  return 1.0 / m_Pcurrent;
134  } else {
135  throw CanteraError("IdealSolnGasVPSS::isothermalCompressibility() ",
136  "not implemented");
137  }
138  return 0.0;
139 }
140 
142 {
143  if (m_idealGas) {
145  } else {
146  const vector_fp& vss = m_VPSS_ptr->getStandardVolumes();
147  switch (m_formGC) {
148  case 0:
149  for (size_t k = 0; k < m_kk; k++) {
150  c[k] = moleFraction(k);
151  }
152  break;
153  case 1:
154  for (size_t k = 0; k < m_kk; k++) {
155  c[k] = moleFraction(k) / vss[k];
156  }
157  break;
158  case 2:
159  for (size_t k = 0; k < m_kk; k++) {
160  c[k] = moleFraction(k) / vss[0];
161  }
162  break;
163  }
164  }
165 }
166 
167 doublereal IdealSolnGasVPSS::standardConcentration(size_t k) const
168 {
169  if (m_idealGas) {
170  return pressure() / RT();
171  } else {
172  const vector_fp& vss = m_VPSS_ptr->getStandardVolumes();
173  switch (m_formGC) {
174  case 0:
175  return 1.0;
176  case 1:
177  return 1.0 / vss[k];
178  case 2:
179  return 1.0/ vss[0];
180  }
181  return 0.0;
182  }
183 }
184 
186 {
187  for (size_t k = 0; k < m_kk; k++) {
188  ac[k] = 1.0;
189  }
190 }
191 
192 // ---- Partial Molar Properties of the Solution -----------------
193 
194 void IdealSolnGasVPSS::getChemPotentials(doublereal* mu) const
195 {
197  for (size_t k = 0; k < m_kk; k++) {
198  double xx = std::max(SmallNumber, moleFraction(k));
199  mu[k] += RT() * log(xx);
200  }
201 }
202 
204 {
205  getEnthalpy_RT(hbar);
206  scale(hbar, hbar+m_kk, hbar, RT());
207 }
208 
209 void IdealSolnGasVPSS::getPartialMolarEntropies(doublereal* sbar) const
210 {
211  getEntropy_R(sbar);
212  scale(sbar, sbar+m_kk, sbar, GasConstant);
213  for (size_t k = 0; k < m_kk; k++) {
214  doublereal xx = std::max(SmallNumber, moleFraction(k));
215  sbar[k] += GasConstant * (- log(xx));
216  }
217 }
218 
220 {
221  getIntEnergy_RT(ubar);
222  scale(ubar, ubar+m_kk, ubar, RT());
223 }
224 
225 void IdealSolnGasVPSS::getPartialMolarCp(doublereal* cpbar) const
226 {
227  getCp_R(cpbar);
228  scale(cpbar, cpbar+m_kk, cpbar, GasConstant);
229 }
230 
231 void IdealSolnGasVPSS::getPartialMolarVolumes(doublereal* vbar) const
232 {
233  getStandardVolumes(vbar);
234 }
235 
236 void IdealSolnGasVPSS::setToEquilState(const doublereal* mu_RT)
237 {
239  const vector_fp& grt = m_VPSS_ptr->Gibbs_RT_ref();
240 
241  // Within the method, we protect against inf results if the exponent is too
242  // high.
243  //
244  // If it is too low, we set the partial pressure to zero. This capability is
245  // needed by the elemental potential method.
246  doublereal pres = 0.0;
247  double m_p0 = m_VPSS_ptr->refPressure();
248  for (size_t k = 0; k < m_kk; k++) {
249  double tmp = -grt[k] + mu_RT[k];
250  if (tmp < -600.) {
251  m_pp[k] = 0.0;
252  } else if (tmp > 500.0) {
253  double tmp2 = tmp / 500.;
254  tmp2 *= tmp2;
255  m_pp[k] = m_p0 * exp(500.) * tmp2;
256  } else {
257  m_pp[k] = m_p0 * exp(tmp);
258  }
259  pres += m_pp[k];
260  }
261  // set state
262  setState_PX(pres, &m_pp[0]);
263 }
264 
265 bool IdealSolnGasVPSS::addSpecies(shared_ptr<Species> spec)
266 {
267  bool added = VPStandardStateTP::addSpecies(spec);
268  if (added) {
269  m_pp.push_back(0.0);
270  }
271  return added;
272 }
273 
274 void IdealSolnGasVPSS::initThermoXML(XML_Node& phaseNode, const std::string& id_)
275 {
276  if (phaseNode.hasChild("thermo")) {
277  XML_Node& thermoNode = phaseNode.child("thermo");
278  std::string model = thermoNode["model"];
279  if (model == "IdealGasVPSS") {
280  m_idealGas = 1;
281  } else if (model == "IdealSolnVPSS") {
282  m_idealGas = 0;
283  } else {
284  throw CanteraError("IdealSolnGasVPSS::initThermoXML",
285  "Unknown thermo model : " + model);
286  }
287  }
288 
289  // Form of the standard concentrations. Must have one of:
290  //
291  // <standardConc model="unity" />
292  // <standardConc model="molar_volume" />
293  // <standardConc model="solvent_volume" />
294  if (phaseNode.hasChild("standardConc")) {
295  if (m_idealGas) {
296  throw CanteraError("IdealSolnGasVPSS::initThermoXML",
297  "standardConc node for ideal gas");
298  }
299  XML_Node& scNode = phaseNode.child("standardConc");
300  string formString = scNode.attrib("model");
301  if (ba::iequals(formString, "unity")) {
302  m_formGC = 0;
303  } else if (ba::iequals(formString, "molar_volume")) {
304  m_formGC = 1;
305  } else if (ba::iequals(formString, "solvent_volume")) {
306  m_formGC = 2;
307  } else {
308  throw CanteraError("initThermoXML",
309  "Unknown standardConc model: " + formString);
310  }
311  } else {
312  if (!m_idealGas) {
313  throw CanteraError("initThermoXML",
314  "Unspecified standardConc model");
315  }
316  }
317 
318  VPStandardStateTP::initThermoXML(phaseNode, id_);
319 }
320 
322 {
324  std::string model = thermoNode["model"];
325  if (model == "IdealGasVPSS") {
326  m_idealGas = 1;
327  } else if (model == "IdealSolnVPSS") {
328  m_idealGas = 0;
329  } else {
330  throw CanteraError("IdealSolnGasVPSS::initThermoXML",
331  "Unknown thermo model : " + model);
332  }
333 }
334 
335 }
virtual void updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
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:96
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
doublereal moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition: Phase.cpp:547
Definition file for a derived class of ThermoPhase that assumes either an ideal gas or ideal solution...
doublereal sum_xlogx() const
Evaluate .
Definition: Phase.cpp:700
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
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
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.
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Return an array of partial molar internal energies for the species in the mixture.
virtual bool addSpecies(shared_ptr< Species > spec)
vector_fp m_pp
Temporary storage - length = m_kk.
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition: Phase.cpp:690
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:809
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
virtual bool addSpecies(shared_ptr< Species > spec)
Declarations for the virtual base class PDSS (pressure dependent standard state) which handles calcul...
virtual void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input...
virtual doublereal standardConcentration(size_t k=0) const
Returns the standard concentration , which is used to normalize the generalized concentration.
const doublereal * moleFractdivMMW() const
Returns a const pointer to the start of the moleFraction/MW array.
Definition: Phase.cpp:563
int m_formGC
form of the generalized concentrations
virtual int eosType() const
Equation of state type flag.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
int m_idealGas
boolean indicating what ideal solution this is
doublereal dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
Definition: utilities.h:107
virtual doublereal pressure() const
Returns the current pressure of the phase.
void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
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
virtual void setParametersFromXML(const XML_Node &thermoNode)
Set equation of state parameter values from XML entries.
std::unique_ptr< VPSSMgr > m_VPSS_ptr
Pointer to the VPSS manager that calculates all of the standard state info efficiently.
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
const doublereal SmallNumber
smallest number to compare to zero.
Definition: ct_defs.h:126
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:500
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:157
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:661
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:130
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
Definition: ThermoPhase.h:1554
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
virtual void setState_PX(doublereal p, doublereal *x)
Set the pressure (Pa) and mole fractions.
Contains declarations for string manipulation functions within Cantera.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional activity coefficients at the current solution temperature, pressure, and solution concentration.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
size_t m_kk
Number of species in the phase.
Definition: Phase.h:784
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
doublereal m_Pcurrent
Current value of the pressure - state variable.
Namespace for the Cantera kernel.
Definition: application.cpp:29
void getConcentrations(doublereal *const c) const
Get the species concentrations (kmol/m^3).
Definition: Phase.cpp:595
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
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:252
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of the species standard states at the current T and P of the solution...
virtual void setToEquilState(const doublereal *lambda_RT)
This method is used by the ChemEquil equilibrium solver.
virtual void setDensity(const doublereal density_)
Set the internally stored density (kg/m^3) of the phase.
Definition: Phase.h:622
An ideal solution or an ideal gas approximation of a phase.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.