Cantera  3.1.0b1
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 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
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
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
136{
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
145{
146 getEnthalpy_RT(hbar);
147 scale(hbar, hbar+m_kk, hbar, RT());
148}
149
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
161{
162 getIntEnergy_RT(ubar);
163 scale(ubar, ubar+m_kk, ubar, RT());
164}
165
166void IdealSolnGasVPSS::getPartialMolarCp(double* cpbar) const
167{
168 getCp_R(cpbar);
169 scale(cpbar, cpbar+m_kk, cpbar, GasConstant);
170}
171
173{
174 getStandardVolumes(vbar);
175}
176
177void IdealSolnGasVPSS::setToEquilState(const double* mu_RT)
178{
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
206bool 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
216{
218 if (m_input.hasKey("standard-concentration-basis")) {
219 setStandardConcentrationModel(m_input["standard-concentration-basis"].asString());
220 }
221}
222
224{
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}
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(double *hbar) const override
Returns an array of partial molar enthalpies for the species in the mixture.
void getChemPotentials(double *mu) const override
Get the species chemical potentials. Units: J/kmol.
vector< double > m_pp
Temporary storage - length = m_kk.
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 getActivityConcentrations(double *c) const override
This method returns an array of generalized concentrations.
void setPressure(double p) override
Set the internally stored pressure (Pa) at constant temperature and composition.
void getPartialMolarVolumes(double *vbar) const override
Return an array of partial molar volumes for the species in the mixture.
double cv_mole() const override
Molar heat capacity at constant volume. Units: 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
void setToEquilState(const double *lambda_RT) override
This method is used by the ChemEquil equilibrium solver.
void getPartialMolarIntEnergies(double *ubar) const override
Return an array of partial molar internal energies for the species in the mixture.
double cp_mole() const override
Molar heat capacity at constant pressure. Units: J/kmol/K.
Units standardConcentrationUnits() const override
Returns the units of the "standard concentration" for this phase.
void getPartialMolarCp(double *cpbar) const override
Return an array of partial molar heat capacities for the species in the mixture.
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 getActivityCoefficients(double *ac) const override
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
void getPartialMolarEntropies(double *sbar) const override
Returns an array of partial molar entropies of the species in the solution.
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition Phase.cpp:597
virtual void setMoleFractions(const double *const x)
Set the mole fractions to the specified values.
Definition Phase.cpp:289
size_t m_kk
Number of species in the phase.
Definition Phase.h:854
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:655
double sum_xlogx() const
Evaluate .
Definition Phase.cpp:626
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition Phase.cpp:439
double mean_X(const double *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition Phase.cpp:616
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
vector< double > m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
vector< double > m_sss_R
Vector containing the species Standard State entropies at T = m_tlast and P = m_plast.
void getEntropy_R(double *sr) const override
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
void getStandardChemPotentials(double *mu) const override
Get the array of chemical potentials at unit activity for the species at their standard states at the...
void getCp_R(double *cpr) const override
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
void getEnthalpy_RT(double *hrt) const override
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
vector< double > m_cpss_R
Vector containing the species Standard State constant pressure heat capacities at T = m_tlast and P =...
void getStandardVolumes(double *vol) const override
Get the molar volumes of the species standard states at the current T and P of the solution.
void getIntEnergy_RT(double *urt) const override
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
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:104
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:120
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
const double SmallNumber
smallest number to compare to zero.
Definition ct_defs.h:158
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...