| Cantera 3.0.0

Loading...
Searching...
No Matches
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
18 namespace Cantera
19{
20
21 IdealSolnGasVPSS::IdealSolnGasVPSS(const string& infile, string id_)
22{
23 initThermoFile(infile, id_);
24}
25
26 void IdealSolnGasVPSS::setStandardConcentrationModel(const string& model)
27{
28 if (caseInsensitiveEquals(model, "unity")) {
29 m_formGC = 0;
30 } else if (caseInsensitiveEquals(model, "species-molar-volume")
31 || caseInsensitiveEquals(model, "molar_volume")) {
32 m_formGC = 1;
33 } else if (caseInsensitiveEquals(model, "solvent-molar-volume")
34 || caseInsensitiveEquals(model, "solvent_volume")) {
35 m_formGC = 2;
36 } else {
37 throw CanteraError("IdealSolnGasVPSS::setStandardConcentrationModel",
38 "Unknown standard concentration model '{}'", model);
39 }
40}
41
42// ------------Molar Thermodynamic Properties -------------------------
43
44 double IdealSolnGasVPSS::enthalpy_mole() const
45{
46 updateStandardStateThermo();
47 return RT() * mean_X(m_hss_RT);
48}
49
50 double IdealSolnGasVPSS::entropy_mole() const
51{
52 updateStandardStateThermo();
53 return GasConstant * (mean_X(m_sss_R) - sum_xlogx());
54}
55
56 double IdealSolnGasVPSS::cp_mole() const
57{
58 updateStandardStateThermo();
59 return GasConstant * mean_X(m_cpss_R);
60}
61
62 double IdealSolnGasVPSS::cv_mole() const
63{
64 return cp_mole() - GasConstant;
65}
66
67 void IdealSolnGasVPSS::setPressure(double p)
68{
69 m_Pcurrent = p;
70 updateStandardStateThermo();
71 calcDensity();
72}
73
74 void IdealSolnGasVPSS::calcDensity()
75{
76 double v_mol = mean_X(getStandardVolumes());
77 // Set the density in the parent object directly
78 Phase::assignDensity(meanMolecularWeight() / v_mol);
79}
80
81 Units IdealSolnGasVPSS::standardConcentrationUnits() const
82{
83 if (m_formGC != 0) {
84 return Units(1.0, 0, -3, 0, 0, 0, 1);
85 } else {
86 return Units(1.0);
87 }
88}
89
90 void IdealSolnGasVPSS::getActivityConcentrations(double* c) const
91{
92 const vector<double>& vss = getStandardVolumes();
93 switch (m_formGC) {
94 case 0:
95 for (size_t k = 0; k < m_kk; k++) {
96 c[k] = moleFraction(k);
97 }
98 break;
99 case 1:
100 for (size_t k = 0; k < m_kk; k++) {
101 c[k] = moleFraction(k) / vss[k];
102 }
103 break;
104 case 2:
105 for (size_t k = 0; k < m_kk; k++) {
106 c[k] = moleFraction(k) / vss[0];
107 }
108 break;
109 }
110}
111
112 double IdealSolnGasVPSS::standardConcentration(size_t k) const
113{
114 const vector<double>& vss = getStandardVolumes();
115 switch (m_formGC) {
116 case 0:
117 return 1.0;
118 case 1:
119 return 1.0 / vss[k];
120 case 2:
121 return 1.0/ vss[0];
122 }
123 return 0.0;
124}
125
126 void IdealSolnGasVPSS::getActivityCoefficients(double* ac) const
127{
128 for (size_t k = 0; k < m_kk; k++) {
129 ac[k] = 1.0;
130 }
131}
132
133// ---- Partial Molar Properties of the Solution -----------------
134
135 void IdealSolnGasVPSS::getChemPotentials(double* mu) const
136{
137 getStandardChemPotentials(mu);
138 for (size_t k = 0; k < m_kk; k++) {
139 double xx = std::max(SmallNumber, moleFraction(k));
140 mu[k] += RT() * log(xx);
141 }
142}
143
144 void IdealSolnGasVPSS::getPartialMolarEnthalpies(double* hbar) const
145{
146 getEnthalpy_RT(hbar);
147 scale(hbar, hbar+m_kk, hbar, RT());
148}
149
150 void IdealSolnGasVPSS::getPartialMolarEntropies(double* sbar) const
151{
152 getEntropy_R(sbar);
153 scale(sbar, sbar+m_kk, sbar, GasConstant);
154 for (size_t k = 0; k < m_kk; k++) {
155 double xx = std::max(SmallNumber, moleFraction(k));
156 sbar[k] += GasConstant * (- log(xx));
157 }
158}
159
160 void IdealSolnGasVPSS::getPartialMolarIntEnergies(double* ubar) const
161{
162 getIntEnergy_RT(ubar);
163 scale(ubar, ubar+m_kk, ubar, RT());
164}
165
166 void IdealSolnGasVPSS::getPartialMolarCp(double* cpbar) const
167{
168 getCp_R(cpbar);
169 scale(cpbar, cpbar+m_kk, cpbar, GasConstant);
170}
171
172 void IdealSolnGasVPSS::getPartialMolarVolumes(double* vbar) const
173{
174 getStandardVolumes(vbar);
175}
176
177 void IdealSolnGasVPSS::setToEquilState(const double* mu_RT)
178{
179 updateStandardStateThermo();
180
181 // Within the method, we protect against inf results if the exponent is too
182 // high.
183 //
184 // If it is too low, we set the partial pressure to zero. This capability is
185 // needed by the elemental potential method.
186 double pres = 0.0;
187 double m_p0 = refPressure();
188 for (size_t k = 0; k < m_kk; k++) {
189 double tmp = -m_g0_RT[k] + mu_RT[k];
190 if (tmp < -600.) {
191 m_pp[k] = 0.0;
192 } else if (tmp > 500.0) {
193 double tmp2 = tmp / 500.;
194 tmp2 *= tmp2;
195 m_pp[k] = m_p0 * exp(500.) * tmp2;
196 } else {
197 m_pp[k] = m_p0 * exp(tmp);
198 }
199 pres += m_pp[k];
200 }
201 // set state
202 setMoleFractions(m_pp.data());
203 setPressure(pres);
204}
205
206 bool IdealSolnGasVPSS::addSpecies(shared_ptr<Species> spec)
207{
208 bool added = VPStandardStateTP::addSpecies(spec);
209 if (added) {
210 m_pp.push_back(0.0);
211 }
212 return added;
213}
214
215 void IdealSolnGasVPSS::initThermo()
216{
217 VPStandardStateTP::initThermo();
218 if (m_input.hasKey("standard-concentration-basis")) {
219 setStandardConcentrationModel(m_input["standard-concentration-basis"].asString());
220 }
221}
222
223 void IdealSolnGasVPSS::getParameters(AnyMap& phaseNode) const
224{
225 VPStandardStateTP::getParameters(phaseNode);
226 // "unity" (m_formGC == 0) is the default, and can be omitted
227 if (m_formGC == 1) {
228 phaseNode["standard-concentration-basis"] = "species-molar-volume";
229 } else if (m_formGC == 2) {
230 phaseNode["standard-concentration-basis"] = "solvent-molar-volume";
231 }
232}
233
234}
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:427
Cantera::AnyMap::hasKey
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
Definition AnyMap.cpp:1423
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::IdealSolnGasVPSS::enthalpy_mole
double enthalpy_mole() const override
Molar enthalpy. Units: J/kmol.
Definition IdealSolnGasVPSS.cpp:44
Cantera::IdealSolnGasVPSS::getPartialMolarEnthalpies
void getPartialMolarEnthalpies(double *hbar) const override
Returns an array of partial molar enthalpies for the species in the mixture.
Definition IdealSolnGasVPSS.cpp:144
Cantera::IdealSolnGasVPSS::getChemPotentials
void getChemPotentials(double *mu) const override
Get the species chemical potentials. Units: J/kmol.
Definition IdealSolnGasVPSS.cpp:135
Cantera::IdealSolnGasVPSS::m_pp
vector< double > m_pp
Temporary storage - length = m_kk.
Definition IdealSolnGasVPSS.h:127
Cantera::IdealSolnGasVPSS::getParameters
void getParameters(AnyMap &phaseNode) const override
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
Definition IdealSolnGasVPSS.cpp:223
Cantera::IdealSolnGasVPSS::initThermo
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
Definition IdealSolnGasVPSS.cpp:215
Cantera::IdealSolnGasVPSS::IdealSolnGasVPSS
IdealSolnGasVPSS(const string &infile="", string id="")
Create an object from an input file.
Definition IdealSolnGasVPSS.cpp:21
Cantera::IdealSolnGasVPSS::getActivityConcentrations
void getActivityConcentrations(double *c) const override
This method returns an array of generalized concentrations.
Definition IdealSolnGasVPSS.cpp:90
Cantera::IdealSolnGasVPSS::setPressure
void setPressure(double p) override
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition IdealSolnGasVPSS.cpp:67
Cantera::IdealSolnGasVPSS::getPartialMolarVolumes
void getPartialMolarVolumes(double *vbar) const override
Return an array of partial molar volumes for the species in the mixture.
Definition IdealSolnGasVPSS.cpp:172
Cantera::IdealSolnGasVPSS::cv_mole
double cv_mole() const override
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition IdealSolnGasVPSS.cpp:62
Cantera::IdealSolnGasVPSS::setStandardConcentrationModel
void setStandardConcentrationModel(const string &model)
Set the standard concentration model.
Definition IdealSolnGasVPSS.cpp:26
Cantera::IdealSolnGasVPSS::entropy_mole
double entropy_mole() const override
Molar entropy. Units: J/kmol/K.
Definition IdealSolnGasVPSS.cpp:50
Cantera::IdealSolnGasVPSS::calcDensity
void calcDensity() override
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
Definition IdealSolnGasVPSS.cpp:74
Cantera::IdealSolnGasVPSS::m_formGC
int m_formGC
form of the generalized concentrations
Definition IdealSolnGasVPSS.h:124
Cantera::IdealSolnGasVPSS::setToEquilState
void setToEquilState(const double *lambda_RT) override
This method is used by the ChemEquil equilibrium solver.
Definition IdealSolnGasVPSS.cpp:177
Cantera::IdealSolnGasVPSS::getPartialMolarIntEnergies
void getPartialMolarIntEnergies(double *ubar) const override
Return an array of partial molar internal energies for the species in the mixture.
Definition IdealSolnGasVPSS.cpp:160
Cantera::IdealSolnGasVPSS::cp_mole
double cp_mole() const override
Molar heat capacity at constant pressure. Units: J/kmol/K.
Definition IdealSolnGasVPSS.cpp:56
Cantera::IdealSolnGasVPSS::standardConcentrationUnits
Units standardConcentrationUnits() const override
Returns the units of the "standard concentration" for this phase.
Definition IdealSolnGasVPSS.cpp:81
Cantera::IdealSolnGasVPSS::getPartialMolarCp
void getPartialMolarCp(double *cpbar) const override
Return an array of partial molar heat capacities for the species in the mixture.
Definition IdealSolnGasVPSS.cpp:166
Cantera::IdealSolnGasVPSS::standardConcentration
double standardConcentration(size_t k=0) const override
Returns the standard concentration , which is used to normalize the generalized concentration.
Definition IdealSolnGasVPSS.cpp:112
Cantera::IdealSolnGasVPSS::addSpecies
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
Definition IdealSolnGasVPSS.cpp:206
Cantera::IdealSolnGasVPSS::getActivityCoefficients
void getActivityCoefficients(double *ac) const override
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
Definition IdealSolnGasVPSS.cpp:126
Cantera::IdealSolnGasVPSS::getPartialMolarEntropies
void getPartialMolarEntropies(double *sbar) const override
Returns an array of partial molar entropies of the species in the solution.
Definition IdealSolnGasVPSS.cpp:150
Cantera::Phase::assignDensity
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition Phase.cpp:718
Cantera::Phase::setMoleFractions
virtual void setMoleFractions(const double *const x)
Set the mole fractions to the specified values.
Definition Phase.cpp:304
Cantera::Phase::m_kk
size_t m_kk
Number of species in the phase.
Definition Phase.h:947
Cantera::Phase::meanMolecularWeight
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:760
Cantera::Phase::sum_xlogx
double sum_xlogx() const
Evaluate .
Definition Phase.cpp:747
Cantera::Phase::moleFraction
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition Phase.cpp:545
Cantera::Phase::mean_X
double mean_X(const double *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition Phase.cpp:737
Cantera::ThermoPhase::getParameters
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
Definition ThermoPhase.cpp:1176
Cantera::ThermoPhase::RT
double RT() const
Return the Gas Constant multiplied by the current temperature.
Definition ThermoPhase.h:1077
Cantera::ThermoPhase::initThermoFile
void initThermoFile(const string &inputFile, const string &id)
Initialize a ThermoPhase object using an input file.
Definition ThermoPhase.cpp:1072
Cantera::ThermoPhase::refPressure
virtual double refPressure() const
Returns the reference pressure in Pa.
Definition ThermoPhase.h:436
Cantera::ThermoPhase::m_input
AnyMap m_input
Data supplied via setParameters.
Definition ThermoPhase.h:2130
Cantera::Units
A representation of the units associated with a dimensional quantity.
Definition Units.h:35
Cantera::VPStandardStateTP::m_g0_RT
vector< double > m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
Definition VPStandardStateTP.h:286
Cantera::VPStandardStateTP::m_sss_R
vector< double > m_sss_R
Vector containing the species Standard State entropies at T = m_tlast and P = m_plast.
Definition VPStandardStateTP.h:309
Cantera::VPStandardStateTP::getEntropy_R
void getEntropy_R(double *sr) const override
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Definition VPStandardStateTP.cpp:62
Cantera::VPStandardStateTP::getStandardChemPotentials
void getStandardChemPotentials(double *mu) const override
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Definition VPStandardStateTP.cpp:48
Cantera::VPStandardStateTP::getCp_R
void getCp_R(double *cpr) const override
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
Definition VPStandardStateTP.cpp:90
Cantera::VPStandardStateTP::initThermo
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
Definition VPStandardStateTP.cpp:152
Cantera::VPStandardStateTP::getEnthalpy_RT
void getEnthalpy_RT(double *hrt) const override
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
Definition VPStandardStateTP.cpp:56
Cantera::VPStandardStateTP::m_cpss_R
vector< double > m_cpss_R
Vector containing the species Standard State constant pressure heat capacities at T = m_tlast and P =...
Definition VPStandardStateTP.h:301
Cantera::VPStandardStateTP::getStandardVolumes
void getStandardVolumes(double *vol) const override
Get the molar volumes of the species standard states at the current T and P of the solution.
Definition VPStandardStateTP.cpp:96
Cantera::VPStandardStateTP::getIntEnergy_RT
void getIntEnergy_RT(double *urt) const override
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
Definition VPStandardStateTP.cpp:81
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:295
Cantera::VPStandardStateTP::m_hss_RT
vector< double > m_hss_RT
Vector containing the species Standard State enthalpies at T = m_tlast and P = m_plast.
Definition VPStandardStateTP.h:297
Cantera::VPStandardStateTP::addSpecies
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
Definition VPStandardStateTP.cpp:174
Cantera::VPStandardStateTP::m_Pcurrent
double m_Pcurrent
Current value of the pressure - state variable.
Definition VPStandardStateTP.h:253
Cantera::caseInsensitiveEquals
bool caseInsensitiveEquals(const string &input, const string &test)
Case insensitive equality predicate.
Definition stringUtils.cpp:223
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:104
Cantera::GasConstant
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:120
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::SmallNumber
const double SmallNumber
smallest number to compare to zero.
Definition ct_defs.h:158
stringUtils.h
Contains declarations for string manipulation functions within Cantera.
utilities.h
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...