| Cantera 3.0.0

Loading...
Searching...
No Matches
SingleSpeciesTP.cpp
Go to the documentation of this file.
1/**
2 * @file SingleSpeciesTP.cpp
3 * Definitions for the SingleSpeciesTP class, which is a filter class for ThermoPhase,
4 * that eases the construction of single species phases
5 * ( see @ref thermoprops and class @link Cantera::SingleSpeciesTP SingleSpeciesTP@endlink).
6 */
7
8// This file is part of Cantera. See License.txt in the top-level directory or
9// at https://cantera.org/license.txt for license and copyright information.
10
11#include "cantera/thermo/SingleSpeciesTP.h"
12#include "cantera/base/stringUtils.h"
13#include "cantera/base/global.h"
14
15 namespace Cantera
16{
17
18// ------------ Molar Thermodynamic Properties --------------------
19
20 double SingleSpeciesTP::enthalpy_mole() const
21{
22 double hbar;
23 getPartialMolarEnthalpies(&hbar);
24 return hbar;
25}
26
27 double SingleSpeciesTP::intEnergy_mole() const
28{
29 double ubar;
30 getPartialMolarIntEnergies(&ubar);
31 return ubar;
32}
33
34 double SingleSpeciesTP::entropy_mole() const
35{
36 double sbar;
37 getPartialMolarEntropies(&sbar);
38 return sbar;
39}
40
41 double SingleSpeciesTP::gibbs_mole() const
42{
43 double gbar;
44
45 // Get the chemical potential of the first species. This is the same as the
46 // partial molar Gibbs free energy.
47 getChemPotentials(&gbar);
48 return gbar;
49}
50
51 double SingleSpeciesTP::cp_mole() const
52{
53 double cpbar;
54
55 // Really should have a partial molar heat capacity function in ThermoPhase.
56 // However, the standard state heat capacity will do fine here for now.
57 getCp_R(&cpbar);
58 cpbar *= GasConstant;
59 return cpbar;
60}
61
62 double SingleSpeciesTP::cv_mole() const
63{
64 // For single species, we go directory to the general Cp - Cv relation
65 //
66 // Cp = Cv + alpha**2 * V * T / beta
67 //
68 // where
69 // alpha = volume thermal expansion coefficient
70 // beta = isothermal compressibility
71 double cvbar = cp_mole();
72 double alpha = thermalExpansionCoeff();
73 double beta = isothermalCompressibility();
74 double V = molecularWeight(0)/density();
75 double T = temperature();
76 if (beta != 0.0) {
77 cvbar -= alpha * alpha * V * T / beta;
78 }
79 return cvbar;
80}
81
82// ----------- Partial Molar Properties of the Solution -----------------
83
84 void SingleSpeciesTP::getChemPotentials(double* mu) const
85{
86 getStandardChemPotentials(mu);
87}
88
89 void SingleSpeciesTP::getChemPotentials_RT(double* murt) const
90{
91 warn_deprecated("SingleSpeciesTP::getChemPotentials_RT",
92 "To be removed after Cantera 3.0. Use getChemPotentials instead.");
93 getStandardChemPotentials(murt);
94 murt[0] /= RT();
95}
96
97 void SingleSpeciesTP::getPartialMolarEnthalpies(double* hbar) const
98{
99 getEnthalpy_RT(hbar);
100 hbar[0] *= RT();
101}
102
103 void SingleSpeciesTP::getPartialMolarIntEnergies(double* ubar) const
104{
105 getIntEnergy_RT(ubar);
106 ubar[0] *= RT();
107}
108
109 void SingleSpeciesTP::getPartialMolarEntropies(double* sbar) const
110{
111 getEntropy_R(sbar);
112 sbar[0] *= GasConstant;
113}
114
115 void SingleSpeciesTP::getPartialMolarCp(double* cpbar) const
116{
117 getCp_R(cpbar);
118 cpbar[0] *= GasConstant;
119}
120
121 void SingleSpeciesTP::getPartialMolarVolumes(double* vbar) const
122{
123 vbar[0] = molecularWeight(0) / density();
124}
125
126// Properties of the Standard State of the Species in the Solution
127
128 void SingleSpeciesTP::getPureGibbs(double* gpure) const
129{
130 getGibbs_RT(gpure);
131 gpure[0] *= RT();
132}
133
134 void SingleSpeciesTP::getStandardVolumes(double* vbar) const
135{
136 vbar[0] = molecularWeight(0) / density();
137}
138
139// ---- Thermodynamic Values for the Species Reference States -------
140
141 void SingleSpeciesTP::getEnthalpy_RT_ref(double* hrt) const
142{
143 _updateThermo();
144 hrt[0] = m_h0_RT;
145}
146
147 void SingleSpeciesTP::getGibbs_RT_ref(double* grt) const
148{
149 _updateThermo();
150 grt[0] = m_h0_RT - m_s0_R;
151}
152
153 void SingleSpeciesTP::getGibbs_ref(double* g) const
154{
155 getGibbs_RT_ref(g);
156 g[0] *= RT();
157}
158
159 void SingleSpeciesTP::getEntropy_R_ref(double* er) const
160{
161 _updateThermo();
162 er[0] = m_s0_R;
163}
164
165 void SingleSpeciesTP::getCp_R_ref(double* cpr) const
166{
167 _updateThermo();
168 cpr[0] = m_cp0_R;
169}
170
171// ------------------ Setting the State ------------------------
172
173 void SingleSpeciesTP::setState_HP(double h, double p, double tol)
174{
175 double dt;
176 setPressure(p);
177 for (int n = 0; n < 50; n++) {
178 dt = clip((h - enthalpy_mass())/cp_mass(), -100.0, 100.0);
179 setState_TP(temperature() + dt, p);
180 if (fabs(dt / temperature()) < tol) {
181 return;
182 }
183 }
184 throw CanteraError("SingleSpeciesTP::setState_HP",
185 "no convergence. dt = {}", dt);
186}
187
188 void SingleSpeciesTP::setState_UV(double u, double v, double tol)
189{
190 double dt;
191 if (v == 0.0) {
192 setDensity(1.0E100);
193 } else {
194 setDensity(1.0/v);
195 }
196 for (int n = 0; n < 50; n++) {
197 dt = clip((u - intEnergy_mass())/cv_mass(), -100.0, 100.0);
198 setTemperature(temperature() + dt);
199 if (fabs(dt / temperature()) < tol) {
200 return;
201 }
202 }
203 throw CanteraError("SingleSpeciesTP::setState_UV",
204 "no convergence. dt = {}\nu = {} v = {}", dt, u, v);
205}
206
207 void SingleSpeciesTP::setState_SP(double s, double p, double tol)
208{
209 double dt;
210 setPressure(p);
211 for (int n = 0; n < 50; n++) {
212 dt = clip((s - entropy_mass())*temperature()/cp_mass(), -100.0, 100.0);
213 setState_TP(temperature() + dt, p);
214 if (fabs(dt / temperature()) < tol) {
215 return;
216 }
217 }
218 throw CanteraError("SingleSpeciesTP::setState_SP",
219 "no convergence. dt = {}", dt);
220}
221
222 void SingleSpeciesTP::setState_SV(double s, double v, double tol)
223{
224 double dt;
225 if (v == 0.0) {
226 setDensity(1.0E100);
227 } else {
228 setDensity(1.0/v);
229 }
230 for (int n = 0; n < 50; n++) {
231 dt = clip((s - entropy_mass())*temperature()/cv_mass(), -100.0, 100.0);
232 setTemperature(temperature() + dt);
233 if (fabs(dt / temperature()) < tol) {
234 return;
235 }
236 }
237 throw CanteraError("SingleSpeciesTP::setState_SV",
238 "no convergence. dt = {}", dt);
239}
240
241 bool SingleSpeciesTP::addSpecies(shared_ptr<Species> spec)
242{
243 if (m_kk != 0) {
244 throw CanteraError("SingleSpeciesTP::addSpecies",
245 "Stoichiometric substances may only contain one species.");
246 }
247 return ThermoPhase::addSpecies(spec);
248}
249
250 void SingleSpeciesTP::_updateThermo() const
251{
252 double tnow = temperature();
253 if (m_tlast != tnow) {
254 m_spthermo.update(tnow, &m_cp0_R, &m_h0_RT, &m_s0_R);
255 m_tlast = tnow;
256 }
257}
258
259}
SingleSpeciesTP.h
Header for the SingleSpeciesTP class, which is a filter class for ThermoPhase, that eases the constru...
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::MultiSpeciesThermo::update
virtual void update(double T, double *cp_R, double *h_RT, double *s_R) const
Compute the reference-state properties for all species.
Definition MultiSpeciesThermo.cpp:94
Cantera::Phase::m_kk
size_t m_kk
Number of species in the phase.
Definition Phase.h:947
Cantera::Phase::temperature
double temperature() const
Temperature (K).
Definition Phase.h:662
Cantera::Phase::setPressure
virtual void setPressure(double p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition Phase.h:721
Cantera::Phase::setDensity
virtual void setDensity(const double density_)
Set the internally stored density (kg/m^3) of the phase.
Definition Phase.cpp:707
Cantera::Phase::density
virtual double density() const
Density (kg/m^3).
Definition Phase.h:687
Cantera::Phase::setTemperature
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition Phase.h:728
Cantera::Phase::molecularWeight
double molecularWeight(size_t k) const
Molecular weight of species k.
Definition Phase.cpp:482
Cantera::SingleSpeciesTP::enthalpy_mole
double enthalpy_mole() const override
Molar enthalpy. Units: J/kmol.
Definition SingleSpeciesTP.cpp:20
Cantera::SingleSpeciesTP::getChemPotentials_RT
void getChemPotentials_RT(double *murt) const override
Get the array of non-dimensional species chemical potentials.
Definition SingleSpeciesTP.cpp:89
Cantera::SingleSpeciesTP::getPartialMolarEnthalpies
void getPartialMolarEnthalpies(double *hbar) const override
Get the species partial molar enthalpies. Units: J/kmol.
Definition SingleSpeciesTP.cpp:97
Cantera::SingleSpeciesTP::getChemPotentials
void getChemPotentials(double *mu) const override
Get the array of chemical potentials.
Definition SingleSpeciesTP.cpp:84
Cantera::SingleSpeciesTP::getGibbs_ref
void getGibbs_ref(double *g) const override
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
Definition SingleSpeciesTP.cpp:153
Cantera::SingleSpeciesTP::setState_HP
void setState_HP(double h, double p, double tol=1e-9) override
Set the internally stored specific enthalpy (J/kg) and pressure (Pa) of the phase.
Definition SingleSpeciesTP.cpp:173
Cantera::SingleSpeciesTP::getPartialMolarVolumes
void getPartialMolarVolumes(double *vbar) const override
Get the species partial molar volumes. Units: m^3/kmol.
Definition SingleSpeciesTP.cpp:121
Cantera::SingleSpeciesTP::cv_mole
double cv_mole() const override
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition SingleSpeciesTP.cpp:62
Cantera::SingleSpeciesTP::m_h0_RT
double m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
Definition SingleSpeciesTP.h:255
Cantera::SingleSpeciesTP::getPureGibbs
void getPureGibbs(double *gpure) const override
Get the Gibbs functions for the standard state of the species at the current T and P of the solution.
Definition SingleSpeciesTP.cpp:128
Cantera::SingleSpeciesTP::m_s0_R
double m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
Definition SingleSpeciesTP.h:259
Cantera::SingleSpeciesTP::getEntropy_R_ref
void getEntropy_R_ref(double *er) const override
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
Definition SingleSpeciesTP.cpp:159
Cantera::SingleSpeciesTP::intEnergy_mole
double intEnergy_mole() const override
Molar internal energy. Units: J/kmol.
Definition SingleSpeciesTP.cpp:27
Cantera::SingleSpeciesTP::entropy_mole
double entropy_mole() const override
Molar entropy. Units: J/kmol/K.
Definition SingleSpeciesTP.cpp:34
Cantera::SingleSpeciesTP::getCp_R_ref
void getCp_R_ref(double *cprt) const override
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
Definition SingleSpeciesTP.cpp:165
Cantera::SingleSpeciesTP::getPartialMolarIntEnergies
void getPartialMolarIntEnergies(double *ubar) const override
Get the species partial molar internal energies. Units: J/kmol.
Definition SingleSpeciesTP.cpp:103
Cantera::SingleSpeciesTP::m_cp0_R
double m_cp0_R
Dimensionless heat capacity at the (mtlast, m_p0)
Definition SingleSpeciesTP.h:257
Cantera::SingleSpeciesTP::cp_mole
double cp_mole() const override
Molar heat capacity at constant pressure. Units: J/kmol/K.
Definition SingleSpeciesTP.cpp:51
Cantera::SingleSpeciesTP::setState_SV
void setState_SV(double s, double v, double tol=1e-9) override
Set the specific entropy (J/kg/K) and specific volume (m^3/kg).
Definition SingleSpeciesTP.cpp:222
Cantera::SingleSpeciesTP::getPartialMolarCp
void getPartialMolarCp(double *cpbar) const override
Get the species partial molar Heat Capacities. Units: J/ kmol /K.
Definition SingleSpeciesTP.cpp:115
Cantera::SingleSpeciesTP::gibbs_mole
double gibbs_mole() const override
Molar Gibbs function. Units: J/kmol.
Definition SingleSpeciesTP.cpp:41
Cantera::SingleSpeciesTP::addSpecies
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
Definition SingleSpeciesTP.cpp:241
Cantera::SingleSpeciesTP::getStandardVolumes
void getStandardVolumes(double *vbar) const override
Get the molar volumes of each species in their standard states at the current T and P of the solution...
Definition SingleSpeciesTP.cpp:134
Cantera::SingleSpeciesTP::_updateThermo
void _updateThermo() const
This internal routine calculates new species Cp0, H0, and S0 whenever the temperature has changed.
Definition SingleSpeciesTP.cpp:250
Cantera::SingleSpeciesTP::setState_UV
void setState_UV(double u, double v, double tol=1e-9) override
Set the specific internal energy (J/kg) and specific volume (m^3/kg).
Definition SingleSpeciesTP.cpp:188
Cantera::SingleSpeciesTP::getGibbs_RT_ref
void getGibbs_RT_ref(double *grt) const override
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
Definition SingleSpeciesTP.cpp:147
Cantera::SingleSpeciesTP::setState_SP
void setState_SP(double s, double p, double tol=1e-9) override
Set the specific entropy (J/kg/K) and pressure (Pa).
Definition SingleSpeciesTP.cpp:207
Cantera::SingleSpeciesTP::getPartialMolarEntropies
void getPartialMolarEntropies(double *sbar) const override
Get the species partial molar entropy. Units: J/kmol K.
Definition SingleSpeciesTP.cpp:109
Cantera::SingleSpeciesTP::getEnthalpy_RT_ref
void getEnthalpy_RT_ref(double *hrt) const override
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
Definition SingleSpeciesTP.cpp:141
Cantera::ThermoPhase::getEntropy_R
virtual void getEntropy_R(double *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Definition ThermoPhase.h:895
Cantera::ThermoPhase::thermalExpansionCoeff
virtual double thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition ThermoPhase.h:580
Cantera::ThermoPhase::setState_TP
virtual void setState_TP(double t, double p)
Set the temperature (K) and pressure (Pa)
Definition ThermoPhase.cpp:121
Cantera::ThermoPhase::RT
double RT() const
Return the Gas Constant multiplied by the current temperature.
Definition ThermoPhase.h:1077
Cantera::ThermoPhase::m_tlast
double m_tlast
last value of the temperature processed by reference state
Definition ThermoPhase.h:2149
Cantera::ThermoPhase::getIntEnergy_RT
virtual void getIntEnergy_RT(double *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
Definition ThermoPhase.h:926
Cantera::ThermoPhase::getCp_R
virtual void getCp_R(double *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
Definition ThermoPhase.h:937
Cantera::ThermoPhase::isothermalCompressibility
virtual double isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition ThermoPhase.h:569
Cantera::ThermoPhase::getGibbs_RT
virtual void getGibbs_RT(double *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
Definition ThermoPhase.h:905
Cantera::ThermoPhase::cv_mass
double cv_mass() const
Specific heat at constant volume. Units: J/kg/K.
Definition ThermoPhase.h:1068
Cantera::ThermoPhase::entropy_mass
double entropy_mass() const
Specific entropy. Units: J/kg/K.
Definition ThermoPhase.h:1053
Cantera::ThermoPhase::getStandardChemPotentials
virtual void getStandardChemPotentials(double *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Definition ThermoPhase.h:875
Cantera::ThermoPhase::getEnthalpy_RT
virtual void getEnthalpy_RT(double *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
Definition ThermoPhase.h:885
Cantera::ThermoPhase::cp_mass
double cp_mass() const
Specific heat at constant pressure. Units: J/kg/K.
Definition ThermoPhase.h:1063
Cantera::ThermoPhase::intEnergy_mass
double intEnergy_mass() const
Specific internal energy. Units: J/kg.
Definition ThermoPhase.h:1048
Cantera::ThermoPhase::m_spthermo
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition ThermoPhase.h:2126
Cantera::ThermoPhase::addSpecies
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
Definition ThermoPhase.cpp:1131
Cantera::ThermoPhase::enthalpy_mass
double enthalpy_mass() const
Specific enthalpy. Units: J/kg.
Definition ThermoPhase.h:1043
global.h
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
Cantera::clip
T clip(const T &value, const T &lower, const T &upper)
Clip value such that lower <= value <= upper.
Definition global.h:329
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::warn_deprecated
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1926
stringUtils.h
Contains declarations for string manipulation functions within Cantera.