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{
64 return cp_mole() - GasConstant;
65}
66
68{
69 m_Pcurrent = p;
72}
73
75{
76 double v_mol = mean_X(getStandardVolumes());
77 // Set the density in the parent object directly
79}
80
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
91{
92 checkArraySize("IdealSolnGasVPSS::getActivityConcentrations", c.size(), m_kk);
93 auto vss = getStandardVolumes();
94 switch (m_formGC) {
95 case 0:
96 for (size_t k = 0; k < m_kk; k++) {
97 c[k] = moleFraction(k);
98 }
99 break;
100 case 1:
101 for (size_t k = 0; k < m_kk; k++) {
102 c[k] = moleFraction(k) / vss[k];
103 }
104 break;
105 case 2:
106 for (size_t k = 0; k < m_kk; k++) {
107 c[k] = moleFraction(k) / vss[0];
108 }
109 break;
110 }
111}
112
114{
115 auto vss = getStandardVolumes();
116 switch (m_formGC) {
117 case 0:
118 return 1.0;
119 case 1:
120 return 1.0 / vss[k];
121 case 2:
122 return 1.0/ vss[0];
123 }
124 return 0.0;
125}
126
128{
129 checkArraySize("IdealSolnGasVPSS::getActivityCoefficients", ac.size(), m_kk);
130 for (size_t k = 0; k < m_kk; k++) {
131 ac[k] = 1.0;
132 }
133}
134
135// ---- Partial Molar Properties of the Solution -----------------
136
137void IdealSolnGasVPSS::getChemPotentials(span<double> mu) const
138{
140 for (size_t k = 0; k < m_kk; k++) {
141 double xx = std::max(SmallNumber, moleFraction(k));
142 mu[k] += RT() * log(xx);
143 }
144}
145
147{
148 getEnthalpy_RT(hbar);
149 scale(hbar.begin(), hbar.end(), hbar.begin(), RT());
150}
151
153{
154 getEntropy_R(sbar);
155 scale(sbar.begin(), sbar.end(), sbar.begin(), GasConstant);
156 for (size_t k = 0; k < m_kk; k++) {
157 double xx = std::max(SmallNumber, moleFraction(k));
158 sbar[k] += GasConstant * (- log(xx));
159 }
160}
161
163{
164 getIntEnergy_RT(ubar);
165 scale(ubar.begin(), ubar.end(), ubar.begin(), RT());
166}
167
168void IdealSolnGasVPSS::getPartialMolarCp(span<double> cpbar) const
169{
170 getCp_R(cpbar);
171 scale(cpbar.begin(), cpbar.end(), cpbar.begin(), GasConstant);
172}
173
174void IdealSolnGasVPSS::getPartialMolarVolumes(span<double> vbar) const
175{
176 getStandardVolumes(vbar);
177}
178
179void IdealSolnGasVPSS::setToEquilState(span<const double> mu_RT)
180{
181 checkArraySize("IdealSolnGasVPSS::setToEquilState", mu_RT.size(), m_kk);
183
184 // Within the method, we protect against inf results if the exponent is too
185 // high.
186 //
187 // If it is too low, we set the partial pressure to zero. This capability is
188 // needed by the elemental potential method.
189 double pres = 0.0;
190 double m_p0 = refPressure();
191 for (size_t k = 0; k < m_kk; k++) {
192 double tmp = -m_g0_RT[k] + mu_RT[k];
193 if (tmp < -600.) {
194 m_pp[k] = 0.0;
195 } else if (tmp > 500.0) {
196 double tmp2 = tmp / 500.;
197 tmp2 *= tmp2;
198 m_pp[k] = m_p0 * exp(500.) * tmp2;
199 } else {
200 m_pp[k] = m_p0 * exp(tmp);
201 }
202 pres += m_pp[k];
203 }
204 // set state
206 setPressure(pres);
207}
208
209bool IdealSolnGasVPSS::addSpecies(shared_ptr<Species> spec)
210{
211 bool added = VPStandardStateTP::addSpecies(spec);
212 if (added) {
213 m_pp.push_back(0.0);
214 }
215 return added;
216}
217
219{
221 if (m_input.hasKey("standard-concentration-basis")) {
222 setStandardConcentrationModel(m_input["standard-concentration-basis"].asString());
223 }
224}
225
227{
229 // "unity" (m_formGC == 0) is the default, and can be omitted
230 if (m_formGC == 1) {
231 phaseNode["standard-concentration-basis"] = "species-molar-volume";
232 } else if (m_formGC == 2) {
233 phaseNode["standard-concentration-basis"] = "solvent-molar-volume";
234 }
235}
236
237}
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.
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 and composition [J/kmol/K].
void setStandardConcentrationModel(const string &model)
Set the standard concentration model.
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.
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition Phase.cpp:608
size_t m_kk
Number of species in the phase.
Definition Phase.h:875
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:676
double sum_xlogx() const
Evaluate .
Definition Phase.cpp:633
double mean_X(span< const double > Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition Phase.cpp:627
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition Phase.cpp:447
virtual void setMoleFractions(span< const double > x)
Set the mole fractions to the specified values.
Definition Phase.cpp:283
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...