Cantera 2.6.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
4 * an 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/xml.h"
18
19using namespace std;
20
21namespace Cantera
22{
23
24IdealSolnGasVPSS::IdealSolnGasVPSS(const std::string& infile, std::string id_) :
25 m_formGC(0)
26{
27 initThermoFile(infile, id_);
28}
29
31{
32 if (caseInsensitiveEquals(model, "unity")) {
33 m_formGC = 0;
34 } else if (caseInsensitiveEquals(model, "species-molar-volume")
35 || caseInsensitiveEquals(model, "molar_volume")) {
36 m_formGC = 1;
37 } else if (caseInsensitiveEquals(model, "solvent-molar-volume")
38 || caseInsensitiveEquals(model, "solvent_volume")) {
39 m_formGC = 2;
40 } else {
41 throw CanteraError("IdealSolnGasVPSS::setStandardConcentrationModel",
42 "Unknown standard concentration model '{}'", model);
43 }
44}
45
46// ------------Molar Thermodynamic Properties -------------------------
47
49{
51 return RT() * mean_X(m_hss_RT);
52}
53
55{
57 return GasConstant * (mean_X(m_sss_R) - sum_xlogx());
58}
59
60doublereal IdealSolnGasVPSS::cp_mole() const
61{
63 return GasConstant * mean_X(m_cpss_R);
64}
65
66doublereal IdealSolnGasVPSS::cv_mole() const
67{
68 return cp_mole() - GasConstant;
69}
70
72{
73 m_Pcurrent = p;
76}
77
79{
80 const doublereal* const dtmp = moleFractdivMMW();
81 const vector_fp& vss = getStandardVolumes();
82 double dens = 1.0 / dot(vss.begin(), vss.end(), dtmp);
83
84 // Set the density in the parent State object directly
86}
87
89{
90 if (m_formGC != 0) {
91 return Units(1.0, 0, -3, 0, 0, 0, 1);
92 } else {
93 return Units(1.0);
94 }
95}
96
98{
99 const vector_fp& vss = getStandardVolumes();
100 switch (m_formGC) {
101 case 0:
102 for (size_t k = 0; k < m_kk; k++) {
103 c[k] = moleFraction(k);
104 }
105 break;
106 case 1:
107 for (size_t k = 0; k < m_kk; k++) {
108 c[k] = moleFraction(k) / vss[k];
109 }
110 break;
111 case 2:
112 for (size_t k = 0; k < m_kk; k++) {
113 c[k] = moleFraction(k) / vss[0];
114 }
115 break;
116 }
117}
118
120{
121 const vector_fp& vss = getStandardVolumes();
122 switch (m_formGC) {
123 case 0:
124 return 1.0;
125 case 1:
126 return 1.0 / vss[k];
127 case 2:
128 return 1.0/ vss[0];
129 }
130 return 0.0;
131}
132
134{
135 for (size_t k = 0; k < m_kk; k++) {
136 ac[k] = 1.0;
137 }
138}
139
140// ---- Partial Molar Properties of the Solution -----------------
141
142void IdealSolnGasVPSS::getChemPotentials(doublereal* mu) const
143{
145 for (size_t k = 0; k < m_kk; k++) {
146 double xx = std::max(SmallNumber, moleFraction(k));
147 mu[k] += RT() * log(xx);
148 }
149}
150
152{
153 getEnthalpy_RT(hbar);
154 scale(hbar, hbar+m_kk, hbar, RT());
155}
156
158{
159 getEntropy_R(sbar);
160 scale(sbar, sbar+m_kk, sbar, GasConstant);
161 for (size_t k = 0; k < m_kk; k++) {
162 doublereal xx = std::max(SmallNumber, moleFraction(k));
163 sbar[k] += GasConstant * (- log(xx));
164 }
165}
166
168{
169 getIntEnergy_RT(ubar);
170 scale(ubar, ubar+m_kk, ubar, RT());
171}
172
173void IdealSolnGasVPSS::getPartialMolarCp(doublereal* cpbar) const
174{
175 getCp_R(cpbar);
176 scale(cpbar, cpbar+m_kk, cpbar, GasConstant);
177}
178
180{
181 getStandardVolumes(vbar);
182}
183
184void IdealSolnGasVPSS::setToEquilState(const doublereal* mu_RT)
185{
187
188 // Within the method, we protect against inf results if the exponent is too
189 // high.
190 //
191 // If it is too low, we set the partial pressure to zero. This capability is
192 // needed by the elemental potential method.
193 doublereal pres = 0.0;
194 double m_p0 = refPressure();
195 for (size_t k = 0; k < m_kk; k++) {
196 double tmp = -m_g0_RT[k] + mu_RT[k];
197 if (tmp < -600.) {
198 m_pp[k] = 0.0;
199 } else if (tmp > 500.0) {
200 double tmp2 = tmp / 500.;
201 tmp2 *= tmp2;
202 m_pp[k] = m_p0 * exp(500.) * tmp2;
203 } else {
204 m_pp[k] = m_p0 * exp(tmp);
205 }
206 pres += m_pp[k];
207 }
208 // set state
209 setState_PX(pres, &m_pp[0]);
210}
211
212bool IdealSolnGasVPSS::addSpecies(shared_ptr<Species> spec)
213{
214 bool added = VPStandardStateTP::addSpecies(spec);
215 if (added) {
216 m_pp.push_back(0.0);
217 }
218 return added;
219}
220
222{
224 if (m_input.hasKey("standard-concentration-basis")) {
225 setStandardConcentrationModel(m_input["standard-concentration-basis"].asString());
226 }
227}
228
230{
232 // "unity" (m_formGC == 0) is the default, and can be omitted
233 if (m_formGC == 1) {
234 phaseNode["standard-concentration-basis"] = "species-molar-volume";
235 } else if (m_formGC == 2) {
236 phaseNode["standard-concentration-basis"] = "solvent-molar-volume";
237 }
238}
239
240void IdealSolnGasVPSS::initThermoXML(XML_Node& phaseNode, const std::string& id_)
241{
242 // Form of the standard concentrations. Must have one of:
243 //
244 // <standardConc model="unity" />
245 // <standardConc model="molar_volume" />
246 // <standardConc model="solvent_volume" />
247 if (phaseNode.hasChild("standardConc")) {
248 XML_Node& scNode = phaseNode.child("standardConc");
249 setStandardConcentrationModel(scNode.attrib("model"));
250 } else {
251 throw CanteraError("IdealSolnGasVPSS::initThermoXML",
252 "Unspecified standardConc model");
253 }
254
255 VPStandardStateTP::initThermoXML(phaseNode, id_);
256}
257
258}
Definition file for a derived class of ThermoPhase that assumes an ideal solution approximation and h...
Declarations for the virtual base class PDSS (pressure dependent standard state) which handles calcul...
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:1406
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
virtual void setToEquilState(const doublereal *lambda_RT)
This method is used by the ChemEquil equilibrium solver.
virtual bool addSpecies(shared_ptr< Species > spec)
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional activity coefficients at the current solution temperature,...
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Return an array of partial molar internal energies for the species in the mixture.
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
vector_fp m_pp
Temporary storage - length = m_kk.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
int m_formGC
form of the generalized concentrations
virtual Units standardConcentrationUnits() const
Returns the units of the "standard concentration" for this phase.
void setStandardConcentrationModel(const std::string &model)
Set the standard concentration model.
IdealSolnGasVPSS(const std::string &infile="", std::string id="")
Create an object from an input file.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
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.
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition: Phase.cpp:698
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition: Phase.cpp:717
const double * moleFractdivMMW() const
Returns a const pointer to the start of the moleFraction/MW array.
Definition: Phase.cpp:564
size_t m_kk
Number of species in the phase.
Definition: Phase.h:943
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition: Phase.cpp:548
doublereal sum_xlogx() const
Evaluate .
Definition: Phase.cpp:727
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:782
void initThermoFile(const std::string &inputFile, const std::string &id)
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.
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
Definition: ThermoPhase.h:150
AnyMap m_input
Data supplied via setParameters.
Definition: ThermoPhase.h:1898
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
A representation of the units associated with a dimensional quantity.
Definition: Units.h:30
vector_fp m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
virtual bool addSpecies(shared_ptr< Species > spec)
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 getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
vector_fp m_sss_R
Vector containing the species Standard State entropies at T = m_tlast and P = m_plast.
vector_fp m_cpss_R
Vector containing the species Standard State constant pressure heat capacities at T = m_tlast and P =...
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
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 for the species at their standard states at the...
virtual void updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
vector_fp m_hss_RT
Vector containing the species Standard State enthalpies at T = m_tlast and P = m_plast.
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:493
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:529
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:547
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
doublereal dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
Definition: utilities.h:77
bool caseInsensitiveEquals(const std::string &input, const std::string &test)
Case insensitive equality predicate.
const double SmallNumber
smallest number to compare to zero.
Definition: ct_defs.h:153
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:100
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:184
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:113
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
Classes providing support for XML data files.