Cantera  2.5.1
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 https://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(-1),
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("IdealSolnGasVPSS::IdealSolnGasVPSS",
41  "Couldn't find phase named '{} in file '{}'",
42  id_, infile);
43  }
44  importPhase(*xphase, this);
45 }
46 
48 {
49  if (m_idealGas) {
50  throw CanteraError("IdealSolnGasVPSS::setStandardConcentrationModel",
51  "Standard concentration model not applicable for ideal gas");
52  }
53 
54  if (caseInsensitiveEquals(model, "unity")) {
55  m_formGC = 0;
56  } else if (caseInsensitiveEquals(model, "species-molar-volume")
57  || caseInsensitiveEquals(model, "molar_volume")) {
58  m_formGC = 1;
59  } else if (caseInsensitiveEquals(model, "solvent-molar-volume")
60  || caseInsensitiveEquals(model, "solvent_volume")) {
61  m_formGC = 2;
62  } else {
63  throw CanteraError("IdealSolnGasVPSS::setStandardConcentrationModel",
64  "Unknown standard concentration model '{}'", model);
65  }
66 }
67 
68 // ------------Molar Thermodynamic Properties -------------------------
69 
71 {
73  return RT() * mean_X(m_hss_RT);
74 }
75 
77 {
79  return GasConstant * (mean_X(m_sss_R) - sum_xlogx());
80 }
81 
82 doublereal IdealSolnGasVPSS::cp_mole() const
83 {
85  return GasConstant * mean_X(m_cpss_R);
86 }
87 
88 doublereal IdealSolnGasVPSS::cv_mole() const
89 {
90  return cp_mole() - GasConstant;
91 }
92 
94 {
95  m_Pcurrent = p;
97  calcDensity();
98 }
99 
101 {
102  // Calculate the molarVolume of the solution (m**3 kmol-1)
103  if (m_idealGas) {
104  double dens = m_Pcurrent * meanMolecularWeight() / RT();
105  Phase::assignDensity(dens);
106  } else {
107  const doublereal* const dtmp = moleFractdivMMW();
108  const vector_fp& vss = getStandardVolumes();
109  double dens = 1.0 / dot(vss.begin(), vss.end(), dtmp);
110 
111  // Set the density in the parent State object directly
112  Phase::assignDensity(dens);
113  }
114 }
115 
117 {
118  if (m_idealGas) {
119  return 1.0 / m_Pcurrent;
120  } else {
121  throw NotImplementedError("IdealSolnGasVPSS::isothermalCompressibility");
122  }
123 }
124 
126 {
127  if (m_idealGas || m_formGC != 0) {
128  return Units(1.0, 0, -3, 0, 0, 0, 1);
129  } else {
130  return Units(1.0);
131  }
132 }
133 
135 {
136  if (m_idealGas) {
138  } else {
139  const vector_fp& vss = getStandardVolumes();
140  switch (m_formGC) {
141  case 0:
142  for (size_t k = 0; k < m_kk; k++) {
143  c[k] = moleFraction(k);
144  }
145  break;
146  case 1:
147  for (size_t k = 0; k < m_kk; k++) {
148  c[k] = moleFraction(k) / vss[k];
149  }
150  break;
151  case 2:
152  for (size_t k = 0; k < m_kk; k++) {
153  c[k] = moleFraction(k) / vss[0];
154  }
155  break;
156  }
157  }
158 }
159 
160 doublereal IdealSolnGasVPSS::standardConcentration(size_t k) const
161 {
162  if (m_idealGas) {
163  return pressure() / RT();
164  } else {
165  const vector_fp& vss = getStandardVolumes();
166  switch (m_formGC) {
167  case 0:
168  return 1.0;
169  case 1:
170  return 1.0 / vss[k];
171  case 2:
172  return 1.0/ vss[0];
173  }
174  return 0.0;
175  }
176 }
177 
179 {
180  for (size_t k = 0; k < m_kk; k++) {
181  ac[k] = 1.0;
182  }
183 }
184 
185 // ---- Partial Molar Properties of the Solution -----------------
186 
187 void IdealSolnGasVPSS::getChemPotentials(doublereal* mu) const
188 {
190  for (size_t k = 0; k < m_kk; k++) {
191  double xx = std::max(SmallNumber, moleFraction(k));
192  mu[k] += RT() * log(xx);
193  }
194 }
195 
197 {
198  getEnthalpy_RT(hbar);
199  scale(hbar, hbar+m_kk, hbar, RT());
200 }
201 
202 void IdealSolnGasVPSS::getPartialMolarEntropies(doublereal* sbar) const
203 {
204  getEntropy_R(sbar);
205  scale(sbar, sbar+m_kk, sbar, GasConstant);
206  for (size_t k = 0; k < m_kk; k++) {
207  doublereal xx = std::max(SmallNumber, moleFraction(k));
208  sbar[k] += GasConstant * (- log(xx));
209  }
210 }
211 
213 {
214  getIntEnergy_RT(ubar);
215  scale(ubar, ubar+m_kk, ubar, RT());
216 }
217 
218 void IdealSolnGasVPSS::getPartialMolarCp(doublereal* cpbar) const
219 {
220  getCp_R(cpbar);
221  scale(cpbar, cpbar+m_kk, cpbar, GasConstant);
222 }
223 
224 void IdealSolnGasVPSS::getPartialMolarVolumes(doublereal* vbar) const
225 {
226  getStandardVolumes(vbar);
227 }
228 
229 void IdealSolnGasVPSS::setToEquilState(const doublereal* mu_RT)
230 {
232 
233  // Within the method, we protect against inf results if the exponent is too
234  // high.
235  //
236  // If it is too low, we set the partial pressure to zero. This capability is
237  // needed by the elemental potential method.
238  doublereal pres = 0.0;
239  double m_p0 = refPressure();
240  for (size_t k = 0; k < m_kk; k++) {
241  double tmp = -m_g0_RT[k] + mu_RT[k];
242  if (tmp < -600.) {
243  m_pp[k] = 0.0;
244  } else if (tmp > 500.0) {
245  double tmp2 = tmp / 500.;
246  tmp2 *= tmp2;
247  m_pp[k] = m_p0 * exp(500.) * tmp2;
248  } else {
249  m_pp[k] = m_p0 * exp(tmp);
250  }
251  pres += m_pp[k];
252  }
253  // set state
254  setState_PX(pres, &m_pp[0]);
255 }
256 
257 bool IdealSolnGasVPSS::addSpecies(shared_ptr<Species> spec)
258 {
259  bool added = VPStandardStateTP::addSpecies(spec);
260  if (added) {
261  m_pp.push_back(0.0);
262  }
263  return added;
264 }
265 
267 {
269  if (m_input.hasKey("thermo")) {
270  const string& model = m_input["thermo"].asString();
271  if (model == "ideal-solution-VPSS") {
272  setSolnMode();
273  } else if (model == "ideal-gas-VPSS") {
274  setGasMode();
275  }
276  }
277  if (m_input.hasKey("standard-concentration-basis")) {
278  setStandardConcentrationModel(m_input["standard-concentration-basis"].asString());
279  }
280 
281  if (m_idealGas == -1) {
282  throw CanteraError("IdealSolnGasVPSS::initThermo",
283  "solution / gas mode not set");
284  }
285 }
286 
287 void IdealSolnGasVPSS::initThermoXML(XML_Node& phaseNode, const std::string& id_)
288 {
289  if (phaseNode.hasChild("thermo")) {
290  XML_Node& thermoNode = phaseNode.child("thermo");
291  std::string model = thermoNode["model"];
292  if (model == "IdealGasVPSS") {
293  setGasMode();
294  } else if (model == "IdealSolnVPSS") {
295  setSolnMode();
296  } else {
297  throw CanteraError("IdealSolnGasVPSS::initThermoXML",
298  "Unknown thermo model : " + model);
299  }
300  }
301 
302  // Form of the standard concentrations. Must have one of:
303  //
304  // <standardConc model="unity" />
305  // <standardConc model="molar_volume" />
306  // <standardConc model="solvent_volume" />
307  if (phaseNode.hasChild("standardConc")) {
308  XML_Node& scNode = phaseNode.child("standardConc");
309  setStandardConcentrationModel(scNode.attrib("model"));
310  } else if (!m_idealGas) {
311  throw CanteraError("IdealSolnGasVPSS::initThermoXML",
312  "Unspecified standardConc model");
313  }
314 
315  VPStandardStateTP::initThermoXML(phaseNode, id_);
316 }
317 
319 {
321  std::string model = thermoNode["model"];
322  if (model == "IdealGasVPSS") {
323  setGasMode();
324  } else if (model == "IdealSolnVPSS") {
325  setSolnMode();
326  } else {
327  throw CanteraError("IdealSolnGasVPSS::setParametersFromXML",
328  "Unknown thermo model : " + model);
329  }
330 }
331 
332 }
Cantera::VPStandardStateTP::m_Pcurrent
doublereal m_Pcurrent
Current value of the pressure - state variable.
Definition: VPStandardStateTP.h:269
Cantera::VPStandardStateTP::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: VPStandardStateTP.cpp:167
Cantera::ThermoPhase::initThermoXML
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
Definition: ThermoPhase.cpp:1089
Cantera::VPStandardStateTP::pressure
virtual doublereal pressure() const
Returns the current pressure of the phase.
Definition: VPStandardStateTP.h:138
Cantera::IdealSolnGasVPSS::setToEquilState
virtual void setToEquilState(const doublereal *lambda_RT)
This method is used by the ChemEquil equilibrium solver.
Definition: IdealSolnGasVPSS.cpp:229
Cantera::IdealSolnGasVPSS::m_formGC
int m_formGC
form of the generalized concentrations
Definition: IdealSolnGasVPSS.h:194
Cantera::ThermoPhase::setParametersFromXML
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
Definition: ThermoPhase.h:1728
Cantera::IdealSolnGasVPSS::standardConcentrationUnits
virtual Units standardConcentrationUnits() const
Returns the units of the "standard concentration" for this phase.
Definition: IdealSolnGasVPSS.cpp:125
Cantera::VPStandardStateTP::m_g0_RT
vector_fp m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
Definition: VPStandardStateTP.h:302
Cantera::ThermoPhase::setState_PX
virtual void setState_PX(doublereal p, doublereal *x)
Set the pressure (Pa) and mole fractions.
Definition: ThermoPhase.cpp:185
Cantera::get_XML_File
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:110
Cantera::IdealSolnGasVPSS::m_idealGas
int m_idealGas
boolean indicating what ideal solution this is
Definition: IdealSolnGasVPSS.h:186
Cantera::SmallNumber
const double SmallNumber
smallest number to compare to zero.
Definition: ct_defs.h:149
Cantera::ThermoPhase::refPressure
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
Definition: ThermoPhase.h:145
Cantera::VPStandardStateTP::m_hss_RT
vector_fp m_hss_RT
Vector containing the species Standard State enthalpies at T = m_tlast and P = m_plast.
Definition: VPStandardStateTP.h:313
Cantera::IdealSolnGasVPSS::getActivityConcentrations
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Definition: IdealSolnGasVPSS.cpp:134
Cantera::NotImplementedError
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:186
Cantera::Phase::meanMolecularWeight
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:748
Cantera::XML_Node::hasChild
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:528
Cantera::VPStandardStateTP::getEntropy_R
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: VPStandardStateTP.cpp:64
Cantera::AnyMap::hasKey
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:984
Cantera::IdealSolnGasVPSS::standardConcentration
virtual doublereal standardConcentration(size_t k=0) const
Returns the standard concentration , which is used to normalize the generalized concentration.
Definition: IdealSolnGasVPSS.cpp:160
Cantera::Phase::assignDensity
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition: Phase.cpp:727
Cantera::IdealSolnGasVPSS::getPartialMolarEnthalpies
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
Definition: IdealSolnGasVPSS.cpp:196
Cantera::IdealSolnGasVPSS::setParametersFromXML
virtual void setParametersFromXML(const XML_Node &thermoNode)
Set equation of state parameter values from XML entries.
Definition: IdealSolnGasVPSS.cpp:318
Cantera::IdealSolnGasVPSS::getPartialMolarVolumes
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
Definition: IdealSolnGasVPSS.cpp:224
Cantera::XML_Node::attrib
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:492
Cantera::IdealSolnGasVPSS::isothermalCompressibility
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: IdealSolnGasVPSS.cpp:116
Cantera::IdealSolnGasVPSS::setSolnMode
void setSolnMode()
Set this phase to represent an ideal liquid or solid solution.
Definition: IdealSolnGasVPSS.h:75
ThermoFactory.h
Cantera::vector_fp
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:180
Cantera::VPStandardStateTP::m_sss_R
vector_fp m_sss_R
Vector containing the species Standard State entropies at T = m_tlast and P = m_plast.
Definition: VPStandardStateTP.h:325
Cantera::Phase::getConcentrations
void getConcentrations(double *const c) const
Get the species concentrations (kmol/m^3).
Definition: Phase.cpp:625
Cantera::VPStandardStateTP::m_cpss_R
vector_fp m_cpss_R
Vector containing the species Standard State constant pressure heat capacities at T = m_tlast and P =...
Definition: VPStandardStateTP.h:317
Cantera::Phase::moleFraction
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition: Phase.cpp:577
Cantera::VPStandardStateTP::getCp_R
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
Definition: VPStandardStateTP.cpp:92
Cantera::IdealSolnGasVPSS::setGasMode
void setGasMode()
Set this phase to represent an ideal gas.
Definition: IdealSolnGasVPSS.h:68
Cantera::IdealSolnGasVPSS::entropy_mole
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
Definition: IdealSolnGasVPSS.cpp:76
Cantera::IdealSolnGasVPSS::getPartialMolarIntEnergies
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Return an array of partial molar internal energies for the species in the mixture.
Definition: IdealSolnGasVPSS.cpp:212
Cantera::IdealSolnGasVPSS::calcDensity
virtual void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
Definition: IdealSolnGasVPSS.cpp:100
Cantera::Phase::m_kk
size_t m_kk
Number of species in the phase.
Definition: Phase.h:942
Cantera::ThermoPhase::m_input
AnyMap m_input
Data supplied via setParameters.
Definition: ThermoPhase.h:1874
Cantera::IdealSolnGasVPSS::getChemPotentials
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: IdealSolnGasVPSS.cpp:187
Cantera::IdealSolnGasVPSS::getActivityCoefficients
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional activity coefficients at the current solution temperature,...
Definition: IdealSolnGasVPSS.cpp:178
Cantera::XML_Node
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Cantera::caseInsensitiveEquals
bool caseInsensitiveEquals(const std::string &input, const std::string &test)
Case insensitive equality predicate.
Definition: stringUtils.cpp:268
Cantera::get_XML_NameID
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:232
Cantera::ThermoPhase::RT
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:776
Cantera::VPStandardStateTP::getEnthalpy_RT
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: VPStandardStateTP.cpp:58
utilities.h
Cantera::Phase::sum_xlogx
doublereal sum_xlogx() const
Evaluate .
Definition: Phase.cpp:756
Cantera::IdealSolnGasVPSS::initThermo
virtual void initThermo()
Definition: IdealSolnGasVPSS.cpp:266
stringUtils.h
Cantera::dot
doublereal dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
Definition: utilities.h:112
Cantera::IdealSolnGasVPSS::enthalpy_mole
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
Definition: IdealSolnGasVPSS.cpp:70
Cantera::VPStandardStateTP::initThermo
virtual void initThermo()
Definition: VPStandardStateTP.cpp:154
Cantera::scale
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:135
Cantera::Phase::moleFractdivMMW
const double * moleFractdivMMW() const
Returns a const pointer to the start of the moleFraction/MW array.
Definition: Phase.cpp:593
Cantera::VPStandardStateTP::getIntEnergy_RT
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
Definition: VPStandardStateTP.cpp:83
Cantera::IdealSolnGasVPSS::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: IdealSolnGasVPSS.cpp:257
Cantera::IdealSolnGasVPSS::getPartialMolarCp
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
Definition: IdealSolnGasVPSS.cpp:218
Cantera::IdealSolnGasVPSS::setPressure
void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition: IdealSolnGasVPSS.cpp:93
PDSS.h
Cantera::IdealSolnGasVPSS::cp_mole
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
Definition: IdealSolnGasVPSS.cpp:82
Cantera::Phase::mean_X
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition: Phase.cpp:746
Cantera::Units
A representation of the units associated with a dimensional quantity.
Definition: Units.h:29
IdealSolnGasVPSS.h
Cantera::IdealSolnGasVPSS::getPartialMolarEntropies
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
Definition: IdealSolnGasVPSS.cpp:202
Cantera::GasConstant
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:109
Cantera::VPStandardStateTP::getStandardVolumes
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of the species standard states at the current T and P of the solution.
Definition: VPStandardStateTP.cpp:98
Cantera::IdealSolnGasVPSS::setStandardConcentrationModel
void setStandardConcentrationModel(const std::string &model)
Set the standard concentration model.
Definition: IdealSolnGasVPSS.cpp:47
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:60
Cantera::importPhase
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
Definition: ThermoFactory.cpp:237
Cantera::VPStandardStateTP::updateStandardStateThermo
virtual void updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
Definition: VPStandardStateTP.cpp:288
Cantera::IdealSolnGasVPSS::cv_mole
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition: IdealSolnGasVPSS.cpp:88
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:263
Cantera::VPStandardStateTP::getStandardChemPotentials
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Definition: VPStandardStateTP.cpp:50
Cantera::IdealSolnGasVPSS::initThermoXML
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
Definition: IdealSolnGasVPSS.cpp:287
Cantera::IdealSolnGasVPSS::m_pp
vector_fp m_pp
Temporary storage - length = m_kk.
Definition: IdealSolnGasVPSS.h:197
Cantera::XML_Node::child
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:546