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
13#include "cantera/thermo/IdealSolnGasVPSS.h"
14#include "cantera/thermo/PDSS.h"
15#include "cantera/base/stringUtils.h"
16#include "cantera/base/utilities.h"
17#include "cantera/base/xml.h"
18
19 using namespace std;
20
21 namespace Cantera
22{
23
24 IdealSolnGasVPSS::IdealSolnGasVPSS(const std::string& infile, std::string id_) :
25 m_formGC(0)
26{
27 initThermoFile(infile, id_);
28}
29
30 void IdealSolnGasVPSS::setStandardConcentrationModel(const std::string& model)
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
48doublereal IdealSolnGasVPSS::enthalpy_mole() const
49{
50 updateStandardStateThermo();
51 return RT() * mean_X(m_hss_RT);
52}
53
54doublereal IdealSolnGasVPSS::entropy_mole() const
55{
56 updateStandardStateThermo();
57 return GasConstant * (mean_X(m_sss_R) - sum_xlogx());
58}
59
60doublereal IdealSolnGasVPSS::cp_mole() const
61{
62 updateStandardStateThermo();
63 return GasConstant * mean_X(m_cpss_R);
64}
65
66doublereal IdealSolnGasVPSS::cv_mole() const
67{
68 return cp_mole() - GasConstant;
69}
70
71 void IdealSolnGasVPSS::setPressure(doublereal p)
72{
73 m_Pcurrent = p;
74 updateStandardStateThermo();
75 calcDensity();
76}
77
78 void IdealSolnGasVPSS::calcDensity()
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
85 Phase::assignDensity(dens);
86}
87
88 Units IdealSolnGasVPSS::standardConcentrationUnits() const
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
97 void IdealSolnGasVPSS::getActivityConcentrations(doublereal* c) const
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
119doublereal IdealSolnGasVPSS::standardConcentration(size_t k) const
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
133 void IdealSolnGasVPSS::getActivityCoefficients(doublereal* ac) const
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
142 void IdealSolnGasVPSS::getChemPotentials(doublereal* mu) const
143{
144 getStandardChemPotentials(mu);
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
151 void IdealSolnGasVPSS::getPartialMolarEnthalpies(doublereal* hbar) const
152{
153 getEnthalpy_RT(hbar);
154 scale(hbar, hbar+m_kk, hbar, RT());
155}
156
157 void IdealSolnGasVPSS::getPartialMolarEntropies(doublereal* sbar) const
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
167 void IdealSolnGasVPSS::getPartialMolarIntEnergies(doublereal* ubar) const
168{
169 getIntEnergy_RT(ubar);
170 scale(ubar, ubar+m_kk, ubar, RT());
171}
172
173 void IdealSolnGasVPSS::getPartialMolarCp(doublereal* cpbar) const
174{
175 getCp_R(cpbar);
176 scale(cpbar, cpbar+m_kk, cpbar, GasConstant);
177}
178
179 void IdealSolnGasVPSS::getPartialMolarVolumes(doublereal* vbar) const
180{
181 getStandardVolumes(vbar);
182}
183
184 void IdealSolnGasVPSS::setToEquilState(const doublereal* mu_RT)
185{
186 updateStandardStateThermo();
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
212 bool 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
221 void IdealSolnGasVPSS::initThermo()
222{
223 VPStandardStateTP::initThermo();
224 if (m_input.hasKey("standard-concentration-basis")) {
225 setStandardConcentrationModel(m_input["standard-concentration-basis"].asString());
226 }
227}
228
229 void IdealSolnGasVPSS::getParameters(AnyMap& phaseNode) const
230{
231 VPStandardStateTP::getParameters(phaseNode);
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
240 void 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}
IdealSolnGasVPSS.h
Definition file for a derived class of ThermoPhase that assumes an ideal solution approximation and h...
PDSS.h
Declarations for the virtual base class PDSS (pressure dependent standard state) which handles calcul...
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
Cantera::AnyMap::hasKey
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:1406
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Cantera::IdealSolnGasVPSS::setToEquilState
virtual void setToEquilState(const doublereal *lambda_RT)
This method is used by the ChemEquil equilibrium solver.
Definition: IdealSolnGasVPSS.cpp:184
Cantera::IdealSolnGasVPSS::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: IdealSolnGasVPSS.cpp:212
Cantera::IdealSolnGasVPSS::getParameters
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
Definition: IdealSolnGasVPSS.cpp:229
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:133
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:167
Cantera::IdealSolnGasVPSS::cp_mole
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
Definition: IdealSolnGasVPSS.cpp:60
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:151
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:157
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:240
Cantera::IdealSolnGasVPSS::enthalpy_mole
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
Definition: IdealSolnGasVPSS.cpp:48
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:179
Cantera::IdealSolnGasVPSS::m_pp
vector_fp m_pp
Temporary storage - length = m_kk.
Definition: IdealSolnGasVPSS.h:152
Cantera::IdealSolnGasVPSS::cv_mole
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition: IdealSolnGasVPSS.cpp:66
Cantera::IdealSolnGasVPSS::getActivityConcentrations
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Definition: IdealSolnGasVPSS.cpp:97
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:173
Cantera::IdealSolnGasVPSS::setPressure
void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition: IdealSolnGasVPSS.cpp:71
Cantera::IdealSolnGasVPSS::entropy_mole
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
Definition: IdealSolnGasVPSS.cpp:54
Cantera::IdealSolnGasVPSS::initThermo
virtual void initThermo()
Definition: IdealSolnGasVPSS.cpp:221
Cantera::IdealSolnGasVPSS::m_formGC
int m_formGC
form of the generalized concentrations
Definition: IdealSolnGasVPSS.h:149
Cantera::IdealSolnGasVPSS::standardConcentrationUnits
virtual Units standardConcentrationUnits() const
Returns the units of the "standard concentration" for this phase.
Definition: IdealSolnGasVPSS.cpp:88
Cantera::IdealSolnGasVPSS::setStandardConcentrationModel
void setStandardConcentrationModel(const std::string &model)
Set the standard concentration model.
Definition: IdealSolnGasVPSS.cpp:30
Cantera::IdealSolnGasVPSS::IdealSolnGasVPSS
IdealSolnGasVPSS(const std::string &infile="", std::string id="")
Create an object from an input file.
Definition: IdealSolnGasVPSS.cpp:24
Cantera::IdealSolnGasVPSS::getChemPotentials
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: IdealSolnGasVPSS.cpp:142
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:78
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:119
Cantera::Phase::assignDensity
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition: Phase.cpp:698
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:717
Cantera::Phase::moleFractdivMMW
const double * moleFractdivMMW() const
Returns a const pointer to the start of the moleFraction/MW array.
Definition: Phase.cpp:564
Cantera::Phase::m_kk
size_t m_kk
Number of species in the phase.
Definition: Phase.h:943
Cantera::Phase::moleFraction
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition: Phase.cpp:548
Cantera::Phase::sum_xlogx
doublereal sum_xlogx() const
Evaluate .
Definition: Phase.cpp:727
Cantera::ThermoPhase::RT
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:782
Cantera::ThermoPhase::initThermoFile
void initThermoFile(const std::string &inputFile, const std::string &id)
Definition: ThermoPhase.cpp:1066
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:1095
Cantera::ThermoPhase::setState_PX
virtual void setState_PX(doublereal p, doublereal *x)
Set the pressure (Pa) and mole fractions.
Definition: ThermoPhase.cpp:187
Cantera::ThermoPhase::refPressure
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
Definition: ThermoPhase.h:150
Cantera::ThermoPhase::m_input
AnyMap m_input
Data supplied via setParameters.
Definition: ThermoPhase.h:1898
Cantera::ThermoPhase::getParameters
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
Definition: ThermoPhase.cpp:1193
Cantera::Units
A representation of the units associated with a dimensional quantity.
Definition: Units.h:30
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:306
Cantera::VPStandardStateTP::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: VPStandardStateTP.cpp:176
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::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::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::VPStandardStateTP::initThermo
virtual void initThermo()
Definition: VPStandardStateTP.cpp:154
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:329
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:321
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::VPStandardStateTP::m_Pcurrent
doublereal m_Pcurrent
Current value of the pressure - state variable.
Definition: VPStandardStateTP.h:273
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::VPStandardStateTP::updateStandardStateThermo
virtual void updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
Definition: VPStandardStateTP.cpp:297
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:317
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
Cantera::XML_Node
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Cantera::XML_Node::attrib
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:493
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:529
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:547
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::dot
doublereal dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
Definition: utilities.h:77
Cantera::caseInsensitiveEquals
bool caseInsensitiveEquals(const std::string &input, const std::string &test)
Case insensitive equality predicate.
Definition: stringUtils.cpp:266
Cantera::SmallNumber
const double SmallNumber
smallest number to compare to zero.
Definition: ct_defs.h:153
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:184
Cantera::GasConstant
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:113
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:100
stringUtils.h
Contains declarations for string manipulation functions within Cantera.
utilities.h
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
xml.h
Classes providing support for XML data files.