Cantera  4.0.0a1
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
14#include "cantera/thermo/PDSS.h"
17
18namespace Cantera
19{
20
21IdealSolnGasVPSS::IdealSolnGasVPSS(const string& infile, string id_)
22{
23 initThermoFile(infile, id_);
24}
25
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
45{
47 return RT() * mean_X(m_hss_RT);
48}
49
51{
53 return GasConstant * (mean_X(m_sss_R) - sum_xlogx());
54}
55
57{
59 return GasConstant * mean_X(m_cpss_R);
60}
61
63{
65 double sum_xk_dVkdT = 0.0;
66 double sum_xk_dVkdP = 0.0;
67 for (size_t k = 0; k < m_kk; k++) {
68 double Xk = moleFraction(k);
69 sum_xk_dVkdT += Xk * providePDSS(k)->dVdT();
70 sum_xk_dVkdP += Xk * providePDSS(k)->dVdP();
71 }
72 if (sum_xk_dVkdP == 0.0) {
73 return cp_mole();
74 }
75 // cv = cp - T*V*beta^2/kappa_T, using mixture beta and kappa_T from PDSS
76 return cp_mole() - temperature() * sum_xk_dVkdT * sum_xk_dVkdT / (-sum_xk_dVkdP);
77}
78
80{
82 double sum_xk_dVkdP = 0.0;
83 for (size_t k = 0; k < m_kk; k++) {
84 sum_xk_dVkdP += moleFraction(k) * providePDSS(k)->dVdP();
85 }
86 return -sum_xk_dVkdP / molarVolume();
87}
88
90{
92 double sum_xk_dVkdT = 0.0;
93 for (size_t k = 0; k < m_kk; k++) {
94 sum_xk_dVkdT += moleFraction(k) * providePDSS(k)->dVdT();
95 }
96 return sum_xk_dVkdT / molarVolume();
97}
98
100{
101 m_Pcurrent = p;
103 calcDensity();
104}
105
107{
108 double v_mol = mean_X(getStandardVolumes());
109 // Set the density in the parent object directly
111}
112
114{
115 if (m_formGC != 0) {
116 return Units(1.0, 0, -3, 0, 0, 0, 1);
117 } else {
118 return Units(1.0);
119 }
120}
121
123{
124 checkArraySize("IdealSolnGasVPSS::getActivityConcentrations", c.size(), m_kk);
125 auto vss = getStandardVolumes();
126 switch (m_formGC) {
127 case 0:
128 for (size_t k = 0; k < m_kk; k++) {
129 c[k] = moleFraction(k);
130 }
131 break;
132 case 1:
133 for (size_t k = 0; k < m_kk; k++) {
134 c[k] = moleFraction(k) / vss[k];
135 }
136 break;
137 case 2:
138 for (size_t k = 0; k < m_kk; k++) {
139 c[k] = moleFraction(k) / vss[0];
140 }
141 break;
142 }
143}
144
146{
147 auto vss = getStandardVolumes();
148 switch (m_formGC) {
149 case 0:
150 return 1.0;
151 case 1:
152 return 1.0 / vss[k];
153 case 2:
154 return 1.0/ vss[0];
155 }
156 return 0.0;
157}
158
160{
161 checkArraySize("IdealSolnGasVPSS::getActivityCoefficients", ac.size(), m_kk);
162 for (size_t k = 0; k < m_kk; k++) {
163 ac[k] = 1.0;
164 }
165}
166
167// ---- Partial Molar Properties of the Solution -----------------
168
169void IdealSolnGasVPSS::getChemPotentials(span<double> mu) const
170{
172 for (size_t k = 0; k < m_kk; k++) {
173 double xx = std::max(SmallNumber, moleFraction(k));
174 mu[k] += RT() * log(xx);
175 }
176}
177
179{
180 getEnthalpy_RT(hbar);
181 scale(hbar.begin(), hbar.end(), hbar.begin(), RT());
182}
183
185{
186 getEntropy_R(sbar);
187 scale(sbar.begin(), sbar.end(), sbar.begin(), GasConstant);
188 for (size_t k = 0; k < m_kk; k++) {
189 double xx = std::max(SmallNumber, moleFraction(k));
190 sbar[k] += GasConstant * (- log(xx));
191 }
192}
193
195{
196 getIntEnergy_RT(ubar);
197 scale(ubar.begin(), ubar.end(), ubar.begin(), RT());
198}
199
200void IdealSolnGasVPSS::getPartialMolarCp(span<double> cpbar) const
201{
202 getCp_R(cpbar);
203 scale(cpbar.begin(), cpbar.end(), cpbar.begin(), GasConstant);
204}
205
206void IdealSolnGasVPSS::getPartialMolarVolumes(span<double> vbar) const
207{
208 getStandardVolumes(vbar);
209}
210
211void IdealSolnGasVPSS::setToEquilState(span<const double> mu_RT)
212{
213 checkArraySize("IdealSolnGasVPSS::setToEquilState", mu_RT.size(), m_kk);
215
216 // Within the method, we protect against inf results if the exponent is too
217 // high.
218 //
219 // If it is too low, we set the partial pressure to zero. This capability is
220 // needed by the elemental potential method.
221 double pres = 0.0;
222 double m_p0 = refPressure();
223 for (size_t k = 0; k < m_kk; k++) {
224 double tmp = -m_g0_RT[k] + mu_RT[k];
225 if (tmp < -600.) {
226 m_pp[k] = 0.0;
227 } else if (tmp > 500.0) {
228 double tmp2 = tmp / 500.;
229 tmp2 *= tmp2;
230 m_pp[k] = m_p0 * exp(500.) * tmp2;
231 } else {
232 m_pp[k] = m_p0 * exp(tmp);
233 }
234 pres += m_pp[k];
235 }
236 // set state
238 setPressure(pres);
239}
240
241bool IdealSolnGasVPSS::addSpecies(shared_ptr<Species> spec)
242{
243 bool added = VPStandardStateTP::addSpecies(spec);
244 if (added) {
245 m_pp.push_back(0.0);
246 }
247 return added;
248}
249
251{
253 if (m_input.hasKey("standard-concentration-basis")) {
254 setStandardConcentrationModel(m_input["standard-concentration-basis"].asString());
255 }
256}
257
259{
261 // "unity" (m_formGC == 0) is the default, and can be omitted
262 if (m_formGC == 1) {
263 phaseNode["standard-concentration-basis"] = "species-molar-volume";
264 } else if (m_formGC == 2) {
265 phaseNode["standard-concentration-basis"] = "solvent-molar-volume";
266 }
267}
268
269}
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:431
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
Definition AnyMap.cpp:1477
Base class for exceptions thrown by Cantera classes.
double enthalpy_mole() const override
Molar enthalpy. Units: J/kmol.
double thermalExpansionCoeff() const override
Thermal expansion coefficient of the mixture.
void getPartialMolarEnthalpies(span< double > hbar) const override
Returns an array of partial molar enthalpies for the species in the mixture.
void getPartialMolarCp(span< double > cpbar) const override
Return an array of partial molar heat capacities for the species in the mixture.
vector< double > m_pp
Temporary storage - length = m_kk.
void getActivityCoefficients(span< double > ac) const override
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
void getParameters(AnyMap &phaseNode) const override
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
IdealSolnGasVPSS(const string &infile="", string id="")
Create an object from an input file.
void setPressure(double p) override
Set the internally stored pressure (Pa) at constant temperature and composition.
double cv_mole() const override
Molar heat capacity at constant volume.
void setStandardConcentrationModel(const string &model)
Set the standard concentration model.
double isothermalCompressibility() const override
Isothermal compressibility of the mixture.
double entropy_mole() const override
Molar entropy. Units: J/kmol/K.
void calcDensity() override
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
int m_formGC
form of the generalized concentrations
double cp_mole() const override
Molar heat capacity at constant pressure and composition [J/kmol/K].
void setToEquilState(span< const double > lambda_RT) override
This method is used by the ChemEquil equilibrium solver.
void getPartialMolarVolumes(span< double > vbar) const override
Return an array of partial molar volumes for the species in the mixture.
Units standardConcentrationUnits() const override
Returns the units of the "standard concentration" for this phase.
void getPartialMolarEntropies(span< double > sbar) const override
Returns an array of partial molar entropies of the species in the solution.
double standardConcentration(size_t k=0) const override
Returns the standard concentration , which is used to normalize the generalized concentration.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
void getChemPotentials(span< double > mu) const override
Get the species chemical potentials. Units: J/kmol.
void getActivityConcentrations(span< double > c) const override
This method returns an array of generalized concentrations.
void getPartialMolarIntEnergies(span< double > ubar) const override
Return an array of partial molar internal energies for the species in the mixture.
virtual double dVdT() const
Return the temperature derivative of the standard state molar volume at constant pressure [m³/kmol/K]...
Definition PDSS.cpp:73
virtual double dVdP() const
Return the pressure derivative of the standard state molar volume at constant temperature [m³/kmol/Pa...
Definition PDSS.cpp:78
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition Phase.cpp:618
size_t m_kk
Number of species in the phase.
Definition Phase.h:882
double temperature() const
Temperature (K).
Definition Phase.h:586
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:677
double sum_xlogx() const
Evaluate .
Definition Phase.cpp:643
double mean_X(span< const double > Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition Phase.cpp:637
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition Phase.cpp:457
virtual void setMoleFractions(span< const double > x)
Set the mole fractions to the specified values.
Definition Phase.cpp:283
virtual double molarVolume() const
Molar volume (m^3/kmol).
Definition Phase.cpp:602
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
double RT() const
Return the Gas Constant multiplied by the current temperature.
void initThermoFile(const string &inputFile, const string &id)
Initialize a ThermoPhase object using an input file.
virtual double refPressure() const
Returns the reference pressure in Pa.
AnyMap m_input
Data supplied via setParameters.
A representation of the units associated with a dimensional quantity.
Definition Units.h:35
void getCp_R(span< double > cpr) const override
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
vector< double > m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
void getIntEnergy_RT(span< double > urt) const override
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
vector< double > m_sss_R
Vector containing the species Standard State entropies at T = m_tlast and P = m_plast.
void getStandardChemPotentials(span< double > mu) const override
Get the array of chemical potentials at unit activity for the species at their standard states at the...
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
void getEnthalpy_RT(span< double > hrt) const override
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
void getEntropy_R(span< double > sr) const override
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
vector< double > m_cpss_R
Vector containing the species Standard State constant pressure heat capacities at T = m_tlast and P =...
void getStandardVolumes(span< double > vol) const override
Get the molar volumes of the species standard states at the current T and P of the solution.
virtual void updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
vector< double > m_hss_RT
Vector containing the species Standard State enthalpies at T = m_tlast and P = m_plast.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
double m_Pcurrent
Current value of the pressure - state variable.
bool caseInsensitiveEquals(const string &input, const string &test)
Case insensitive equality predicate.
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition utilities.h:118
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:123
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
const double SmallNumber
smallest number to compare to zero.
Definition ct_defs.h:161
void checkArraySize(const char *procedure, size_t available, size_t required)
Wrapper for throwing ArraySizeError.
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...