Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  * Copyright (2005) Sandia Corporation. Under the terms of
11  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
12  * U.S. Government retains certain rights in this software.
13  */
14 
16 #include "cantera/thermo/PDSS.h"
20 
21 using namespace std;
22 
23 namespace Cantera
24 {
25 
26 IdealSolnGasVPSS::IdealSolnGasVPSS() :
27  m_idealGas(0),
28  m_formGC(0)
29 {
30 }
31 
32 IdealSolnGasVPSS::IdealSolnGasVPSS(const std::string& infile, std::string id_) :
33  m_idealGas(0),
34  m_formGC(0)
35 {
36  XML_Node* root = get_XML_File(infile);
37  if (id_ == "-") {
38  id_ = "";
39  }
40  XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
41  if (!xphase) {
42  throw CanteraError("newPhase",
43  "Couldn't find phase named \"" + id_ + "\" in file, " + infile);
44  }
45  importPhase(*xphase, this);
46 }
47 
49  m_idealGas(0),
50  m_formGC(0)
51 {
52  *this = b;
53 }
54 
56 {
57  if (&b != this) {
58  /*
59  * Mostly, this is a passthrough to the underlying
60  * assignment operator for the ThermoPhae parent object.
61  */
63  /*
64  * However, we have to handle data that we own.
65  */
67  m_formGC = b.m_formGC;
68  }
69  return *this;
70 }
71 
73 {
74  return new IdealSolnGasVPSS(*this);
75 }
76 
78 {
79  if (m_idealGas) {
80  return cIdealSolnGasVPSS;
81  }
82  return cIdealSolnGasVPSS_iscv;
83 }
84 
85 /*
86  * ------------Molar Thermodynamic Properties -------------------------
87  */
88 
90 {
93 }
94 
96 {
98  return GasConstant * (mean_X(m_VPSS_ptr->entropy_R()) - sum_xlogx());
99 
100 }
101 
102 doublereal IdealSolnGasVPSS::cp_mole() const
103 {
105  return GasConstant * mean_X(m_VPSS_ptr->cp_R());
106 }
107 
108 doublereal IdealSolnGasVPSS::cv_mole() const
109 {
110  return cp_mole() - GasConstant;
111 }
112 
114 {
115  m_Pcurrent = p;
117  calcDensity();
118 }
119 
121 {
122  /*
123  * Calculate the molarVolume of the solution (m**3 kmol-1)
124  */
125  if (m_idealGas) {
126  double dens = (m_Pcurrent * meanMolecularWeight()
127  /(GasConstant * temperature()));
128  Phase::setDensity(dens);
129  } else {
130  const doublereal* const dtmp = moleFractdivMMW();
131  const vector_fp& vss = m_VPSS_ptr->getStandardVolumes();
132  double dens = 1.0 / dot(vss.begin(), vss.end(), dtmp);
133  /*
134  * Set the density in the parent State object directly,
135  * by calling the Phase::setDensity() function.
136  */
137  Phase::setDensity(dens);
138  }
139 }
140 
142 {
143  if (m_idealGas) {
144  return 1.0 / m_Pcurrent;
145  } else {
146  throw CanteraError("IdealSolnGasVPSS::isothermalCompressibility() ",
147  "not implemented");
148  }
149  return 0.0;
150 }
151 
153 {
154  if (m_idealGas) {
156  } else {
157  const vector_fp& vss = m_VPSS_ptr->getStandardVolumes();
158  switch (m_formGC) {
159  case 0:
160  for (size_t k = 0; k < m_kk; k++) {
161  c[k] = moleFraction(k);
162  }
163  break;
164  case 1:
165  for (size_t k = 0; k < m_kk; k++) {
166  c[k] = moleFraction(k) / vss[k];
167  }
168  break;
169  case 2:
170  for (size_t k = 0; k < m_kk; k++) {
171  c[k] = moleFraction(k) / vss[0];
172  }
173  break;
174  }
175  }
176 }
177 
178 doublereal IdealSolnGasVPSS::standardConcentration(size_t k) const
179 {
180  if (m_idealGas) {
181  double p = pressure();
182  return p/(GasConstant * temperature());
183  } else {
184  const vector_fp& vss = m_VPSS_ptr->getStandardVolumes();
185  switch (m_formGC) {
186  case 0:
187  return 1.0;
188  case 1:
189  return 1.0 / vss[k];
190  case 2:
191  return 1.0/ vss[0];
192  }
193  return 0.0;
194 
195  }
196 }
197 
198 void IdealSolnGasVPSS::getUnitsStandardConc(double* uA, int, int sizeUA) const
199 {
200  warn_deprecated("IdealSolnGasVPSS::getUnitsStandardConc",
201  "To be removed after Cantera 2.2.");
202 
203  if (eosType() == cIdealSolnGasPhase0) {
204  for (int i = 0; i < sizeUA; i++) {
205  uA[i] = 0.0;
206  }
207  } else {
208  for (int i = 0; i < sizeUA; i++) {
209  if (i == 0) {
210  uA[0] = 1.0;
211  }
212  if (i == 1) {
213  uA[1] = -int(nDim());
214  }
215  if (i == 2) {
216  uA[2] = 0.0;
217  }
218  if (i == 3) {
219  uA[3] = 0.0;
220  }
221  if (i == 4) {
222  uA[4] = 0.0;
223  }
224  if (i == 5) {
225  uA[5] = 0.0;
226  }
227  }
228  }
229 }
230 
232 {
233  for (size_t k = 0; k < m_kk; k++) {
234  ac[k] = 1.0;
235  }
236 }
237 
238 /*
239  * ---- Partial Molar Properties of the Solution -----------------
240  */
241 
242 void IdealSolnGasVPSS::getChemPotentials_RT(doublereal* muRT) const
243 {
244  getChemPotentials(muRT);
245  doublereal invRT = 1.0 / _RT();
246  for (size_t k = 0; k < m_kk; k++) {
247  muRT[k] *= invRT;
248  }
249 }
250 
251 void IdealSolnGasVPSS::getChemPotentials(doublereal* mu) const
252 {
254  doublereal rt = temperature() * GasConstant;
255  for (size_t k = 0; k < m_kk; k++) {
256  double xx = std::max(SmallNumber, moleFraction(k));
257  mu[k] += rt*(log(xx));
258  }
259 }
260 
262 {
263  getEnthalpy_RT(hbar);
264  scale(hbar, hbar+m_kk, hbar, GasConstant * temperature());
265 }
266 
267 void IdealSolnGasVPSS::getPartialMolarEntropies(doublereal* sbar) const
268 {
269  getEntropy_R(sbar);
270  scale(sbar, sbar+m_kk, sbar, GasConstant);
271  for (size_t k = 0; k < m_kk; k++) {
272  doublereal xx = std::max(SmallNumber, moleFraction(k));
273  sbar[k] += GasConstant * (- log(xx));
274  }
275 }
276 
278 {
279  getIntEnergy_RT(ubar);
280  scale(ubar, ubar+m_kk, ubar, GasConstant * temperature());
281 }
282 
283 void IdealSolnGasVPSS::getPartialMolarCp(doublereal* cpbar) const
284 {
285  getCp_R(cpbar);
286  scale(cpbar, cpbar+m_kk, cpbar, GasConstant);
287 }
288 
289 void IdealSolnGasVPSS::getPartialMolarVolumes(doublereal* vbar) const
290 {
291  getStandardVolumes(vbar);
292 }
293 
295 {
296  initLengths();
298 }
299 
300 void IdealSolnGasVPSS::setToEquilState(const doublereal* mu_RT)
301 {
303  const vector_fp& grt = m_VPSS_ptr->Gibbs_RT_ref();
304 
305  /*
306  * Within the method, we protect against inf results if the
307  * exponent is too high.
308  *
309  * If it is too low, we set
310  * the partial pressure to zero. This capability is needed
311  * by the elemental potential method.
312  */
313  doublereal pres = 0.0;
314  double m_p0 = m_VPSS_ptr->refPressure();
315  for (size_t k = 0; k < m_kk; k++) {
316  double tmp = -grt[k] + mu_RT[k];
317  if (tmp < -600.) {
318  m_pp[k] = 0.0;
319  } else if (tmp > 500.0) {
320  double tmp2 = tmp / 500.;
321  tmp2 *= tmp2;
322  m_pp[k] = m_p0 * exp(500.) * tmp2;
323  } else {
324  m_pp[k] = m_p0 * exp(tmp);
325  }
326  pres += m_pp[k];
327  }
328  // set state
329  setState_PX(pres, &m_pp[0]);
330 }
331 
333 {
334  m_pp.resize(m_kk, 0.0);
335 }
336 
337 void IdealSolnGasVPSS::initThermoXML(XML_Node& phaseNode, const std::string& id_)
338 {
340 
341  if (phaseNode.hasChild("thermo")) {
342  XML_Node& thermoNode = phaseNode.child("thermo");
343  std::string model = thermoNode["model"];
344  if (model == "IdealGasVPSS") {
345  m_idealGas = 1;
346  } else if (model == "IdealSolnVPSS") {
347  m_idealGas = 0;
348  } else {
349  throw CanteraError("IdealSolnGasVPSS::initThermoXML",
350  "Unknown thermo model : " + model);
351  }
352  }
353 
354  /*
355  * Form of the standard concentrations. Must have one of:
356  *
357  * <standardConc model="unity" />
358  * <standardConc model="molar_volume" />
359  * <standardConc model="solvent_volume" />
360  */
361  if (phaseNode.hasChild("standardConc")) {
362  if (m_idealGas) {
363  throw CanteraError("IdealSolnGasVPSS::initThermoXML",
364  "standardConc node for ideal gas");
365  }
366  XML_Node& scNode = phaseNode.child("standardConc");
367  string formStringa = scNode.attrib("model");
368  string formString = lowercase(formStringa);
369  if (formString == "unity") {
370  m_formGC = 0;
371  } else if (formString == "molar_volume") {
372  m_formGC = 1;
373  } else if (formString == "solvent_volume") {
374  m_formGC = 2;
375  } else {
376  throw CanteraError("initThermoXML",
377  "Unknown standardConc model: " + formStringa);
378  }
379  } else {
380  if (!m_idealGas) {
381  throw CanteraError("initThermoXML",
382  "Unspecified standardConc model");
383  }
384  }
385 
386  VPStandardStateTP::initThermoXML(phaseNode, id_);
387 }
388 
390 {
392  std::string model = thermoNode["model"];
393  if (model == "IdealGasVPSS") {
394  m_idealGas = 1;
395  } else if (model == "IdealSolnVPSS") {
396  m_idealGas = 0;
397  } else {
398  throw CanteraError("IdealSolnGasVPSS::initThermoXML",
399  "Unknown thermo model : " + model);
400  }
401 }
402 
403 }
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Get the species partial molar enthalpies. Units: J/kmol.
const vector_fp & Gibbs_RT_ref() const
Return a reference to the vector of Gibbs free energies of the species.
Definition: VPSSMgr.h:404
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:105
virtual void getPartialMolarEntropies(doublereal *sbar) const
Get the species partial molar entropies. Units: J/kmol/K.
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:527
doublereal _RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:936
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of each species in their standard states at the current T and P of the solution...
Definition file for a derived class of ThermoPhase that assumes either an ideal gas or ideal solution...
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the standard state of the species at ...
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:100
virtual void updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:78
doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine.
const vector_fp & cp_R() const
Return a reference to a vector of the constant pressure heat capacities of the species.
Definition: VPSSMgr.h:345
std::string lowercase(const std::string &s)
Cast a copy of a string to lower case.
Definition: stringUtils.cpp:73
VPSSMgr * m_VPSS_ptr
Pointer to the VPSS manager that calculates all of the standard state info efficiently.
void getConcentrations(doublereal *const c) const
Get the species concentrations (kmol/m^3).
Definition: Phase.cpp:609
vector_fp m_pp
Temporary storage - length = m_kk.
doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:573
const vector_fp & enthalpy_RT() const
Return a reference to a vector of the molar enthalpies of the species in their standard states...
Definition: VPSSMgr.h:297
VPStandardStateTP & operator=(const VPStandardStateTP &b)
Assignment operator.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition: Phase.cpp:687
virtual void getPartialMolarCp(doublereal *cpbar) const
Get the partial molar heat capacities Units: J/kmol/K.
bool importPhase(XML_Node &phase, ThermoPhase *th, SpeciesThermoFactory *spfactory)
Import a phase information into an empty ThermoPhase object.
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...
doublereal pressure() const
Returns the current pressure of the phase.
doublereal sum_xlogx() const
Evaluate .
Definition: Phase.cpp:703
virtual doublereal standardConcentration(size_t k=0) const
Returns the standard concentration , which is used to normalize the generalized concentration.
doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
int m_formGC
form of the generalized concentrations
virtual doublereal refPressure(size_t k=npos) const
The reference-state pressure for the standard state.
Definition: VPSSMgr.cpp:428
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
IdealSolnGasVPSS & operator=(const IdealSolnGasVPSS &)
Assignment operator.
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:563
virtual void getPartialMolarVolumes(doublereal *vbar) const
Get the species partial molar volumes. Units: m^3/kmol.
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:135
const vector_fp & entropy_R() const
Return a reference to a vector of the entropies of the species.
Definition: VPSSMgr.h:311
void setPressure(doublereal p)
Set the pressure in the fluid.
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the standard state at the current temperatu...
virtual void setParametersFromXML(const XML_Node &thermoNode)
Set equation of state parameter values from XML entries.
doublereal moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition: Phase.cpp:561
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Enthalpy functions for the standard state species at the current T an...
doublereal temperature() const
Temperature (K).
Definition: Phase.h:602
size_t nDim() const
Returns the number of spatial dimensions (1, 2, or 3)
Definition: Phase.h:586
const doublereal SmallNumber
smallest number to compare to zero.
Definition: ct_defs.h:126
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
Templates for operations on vector-like objects.
virtual int eosType() const
Equation of state type flag.
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:158
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 getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
Definition: ThermoPhase.h:1470
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:669
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Initialize a ThermoPhase object, potentially reading activity coefficient information from an XML dat...
virtual void setState_PX(doublereal p, doublereal *x)
Set the pressure (Pa) and mole fractions.
virtual void getUnitsStandardConc(double *uA, int k=0, int sizeUA=6) const
Returns the units of the standard and generalized concentrations.
Contains declarations for string manipulation functions within Cantera.
doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Initialize a ThermoPhase object, potentially reading activity coefficient information from an XML dat...
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of each species in their standard states at the current T and P of the solution...
Definition: VPSSMgr.cpp:209
size_t m_kk
Number of species in the phase.
Definition: Phase.h:843
doublereal m_Pcurrent
Current value of the pressure - state variable.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity.
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Get the species partial molar enthalpies. Units: J/kmol.
const doublereal * moleFractdivMMW() const
Returns a const pointer to the start of the moleFraction/MW array.
Definition: Phase.cpp:577
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
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 Note the density of a phase is an independent...
Definition: Phase.h:623
An ideal solution or an ideal gas approximation of a phase.
void getChemPotentials_RT(doublereal *mu) const
Get the array of non-dimensional species chemical potentials These are partial molar Gibbs free energ...