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
13#include "cantera/base/global.h"
14
15namespace Cantera
16{
17
18// ------------ Molar Thermodynamic Properties --------------------
19
21{
22 double hbar;
24 return hbar;
25}
26
28{
29 double ubar;
31 return ubar;
32}
33
35{
36 double sbar;
38 return sbar;
39}
40
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
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
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
85{
87}
88
90{
91 warn_deprecated("SingleSpeciesTP::getChemPotentials_RT",
92 "To be removed after Cantera 3.0. Use getChemPotentials instead.");
94 murt[0] /= RT();
95}
96
98{
99 getEnthalpy_RT(hbar);
100 hbar[0] *= RT();
101}
102
104{
105 getIntEnergy_RT(ubar);
106 ubar[0] *= RT();
107}
108
110{
111 getEntropy_R(sbar);
112 sbar[0] *= GasConstant;
113}
114
115void SingleSpeciesTP::getPartialMolarCp(double* cpbar) const
116{
117 getCp_R(cpbar);
118 cpbar[0] *= GasConstant;
119}
120
122{
123 vbar[0] = molecularWeight(0) / density();
124}
125
126// Properties of the Standard State of the Species in the Solution
127
128void SingleSpeciesTP::getPureGibbs(double* gpure) const
129{
130 getGibbs_RT(gpure);
131 gpure[0] *= RT();
132}
133
135{
136 vbar[0] = molecularWeight(0) / density();
137}
138
139// ---- Thermodynamic Values for the Species Reference States -------
140
142{
144 hrt[0] = m_h0_RT;
145}
146
147void SingleSpeciesTP::getGibbs_RT_ref(double* grt) const
148{
150 grt[0] = m_h0_RT - m_s0_R;
151}
152
153void SingleSpeciesTP::getGibbs_ref(double* g) const
154{
156 g[0] *= RT();
157}
158
160{
162 er[0] = m_s0_R;
163}
164
165void SingleSpeciesTP::getCp_R_ref(double* cpr) const
166{
168 cpr[0] = m_cp0_R;
169}
170
171// ------------------ Setting the State ------------------------
172
173void 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
188void 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);
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
207void 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
222void 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);
233 if (fabs(dt / temperature()) < tol) {
234 return;
235 }
236 }
237 throw CanteraError("SingleSpeciesTP::setState_SV",
238 "no convergence. dt = {}", dt);
239}
240
241bool 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
251{
252 double tnow = temperature();
253 if (m_tlast != tnow) {
255 m_tlast = tnow;
256 }
257}
258
259}
Header for the SingleSpeciesTP class, which is a filter class for ThermoPhase, that eases the constru...
Base class for exceptions thrown by Cantera classes.
virtual void update(double T, double *cp_R, double *h_RT, double *s_R) const
Compute the reference-state properties for all species.
size_t m_kk
Number of species in the phase.
Definition Phase.h:947
double temperature() const
Temperature (K).
Definition Phase.h:662
virtual void setPressure(double p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition Phase.h:721
virtual void setDensity(const double density_)
Set the internally stored density (kg/m^3) of the phase.
Definition Phase.cpp:707
virtual double density() const
Density (kg/m^3).
Definition Phase.h:687
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition Phase.h:728
double molecularWeight(size_t k) const
Molecular weight of species k.
Definition Phase.cpp:482
double enthalpy_mole() const override
Molar enthalpy. Units: J/kmol.
void getChemPotentials_RT(double *murt) const override
Get the array of non-dimensional species chemical potentials.
void getPartialMolarEnthalpies(double *hbar) const override
Get the species partial molar enthalpies. Units: J/kmol.
void getChemPotentials(double *mu) const override
Get the array of chemical potentials.
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...
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.
void getPartialMolarVolumes(double *vbar) const override
Get the species partial molar volumes. Units: m^3/kmol.
double cv_mole() const override
Molar heat capacity at constant volume. Units: J/kmol/K.
double m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
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.
double m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
void getEntropy_R_ref(double *er) const override
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
double intEnergy_mole() const override
Molar internal energy. Units: J/kmol.
double entropy_mole() const override
Molar entropy. Units: J/kmol/K.
void getCp_R_ref(double *cprt) const override
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
void getPartialMolarIntEnergies(double *ubar) const override
Get the species partial molar internal energies. Units: J/kmol.
double m_cp0_R
Dimensionless heat capacity at the (mtlast, m_p0)
double cp_mole() const override
Molar heat capacity at constant pressure. Units: J/kmol/K.
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).
void getPartialMolarCp(double *cpbar) const override
Get the species partial molar Heat Capacities. Units: J/ kmol /K.
double gibbs_mole() const override
Molar Gibbs function. Units: J/kmol.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
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...
void _updateThermo() const
This internal routine calculates new species Cp0, H0, and S0 whenever the temperature has changed.
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).
void getGibbs_RT_ref(double *grt) const override
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
void setState_SP(double s, double p, double tol=1e-9) override
Set the specific entropy (J/kg/K) and pressure (Pa).
void getPartialMolarEntropies(double *sbar) const override
Get the species partial molar entropy. Units: J/kmol K.
void getEnthalpy_RT_ref(double *hrt) const override
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
virtual void getEntropy_R(double *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
virtual double thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
virtual void setState_TP(double t, double p)
Set the temperature (K) and pressure (Pa)
double RT() const
Return the Gas Constant multiplied by the current temperature.
double m_tlast
last value of the temperature processed by reference state
virtual void getIntEnergy_RT(double *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
virtual void getCp_R(double *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
virtual double isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
virtual void getGibbs_RT(double *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
double cv_mass() const
Specific heat at constant volume. Units: J/kg/K.
double entropy_mass() const
Specific entropy. Units: J/kg/K.
virtual void getStandardChemPotentials(double *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
virtual void getEnthalpy_RT(double *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
double cp_mass() const
Specific heat at constant pressure. Units: J/kg/K.
double intEnergy_mass() const
Specific internal energy. Units: J/kg.
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
double enthalpy_mass() const
Specific enthalpy. Units: J/kg.
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
T clip(const T &value, const T &lower, const T &upper)
Clip value such that lower <= value <= upper.
Definition global.h:329
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:120
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
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
Contains declarations for string manipulation functions within Cantera.