Cantera
Loading...
Searching...
No Matches
Sub.h
Go to the documentation of this file.
1//! @file Sub.h
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at https://cantera.org/license.txt for license and copyright information.
5
6#ifndef TPX_SUB_H
7#define TPX_SUB_H
8
10
11namespace tpx
12{
13
14namespace PropertyPair
15{
16enum type {
17 TV = 12, HP = 34, SP = 54, PV = 42, TP = 14, UV = 62, ST = 51,
18 SV = 52, UP = 64, VH = 23, TH = 13, SH = 53, PX = 47, TX = 17,
19 VT = -12, PH = -34, PS = -54, VP = -42, PT = -14, VU = -62, TS = -51,
20 VS = -52, PU = -64, HV = -23, HT = -13, HS = -53, XP = -47, XT = -17
21};
22}
23
24const int Pgiven = 0, Tgiven = 1;
25
26namespace propertyFlag
27{
28enum type { H, S, U, V, P, T };
29}
30
31const double Undef = 999.1234;
32
33/**
34 * Base class from which all pure substances are derived
35 */
36class Substance
37{
38public:
39 Substance() = default;
40
41 virtual ~Substance() = default;
42
43 void setStdState(double h0 = 0.0, double s0 = 0.0,
44 double t0 = 298.15, double p0 = 1.01325e5);
45
46 //! @name Information about a substance
47 //! @{
48
49 //! Molecular weight [kg/kmol]
50 virtual double MolWt()=0;
51
52 //! Critical temperature [K]
53 virtual double Tcrit()=0;
54
55 //! Critical pressure [Pa]
56 virtual double Pcrit()=0;
57
58 //! Critical specific volume [m^3/kg]
59 virtual double Vcrit()=0;
60
61 //! Minimum temperature for which the equation of state is valid
62 virtual double Tmin()=0;
63
64 //! Maximum temperature for which the equation of state is valid
65 virtual double Tmax()=0;
66
67 //! Name of the substance
68 const char* name() {
69 return m_name.c_str();
70 }
71
72 //! Chemical formula for the substance
73 const char* formula() {
74 return m_formula.c_str();
75 }
76
77 //! @}
78
79 //! @name Properties
80 //! @{
81
82 //! Pressure [Pa]. If two phases are present, return the saturation
83 //! pressure; otherwise return the pressure computed directly from the
84 //! underlying eos.
85 double P();
86
87 //! Temperature [K]
88 double Temp() {
89 return T;
90 }
91
92 //! Specific volume [m^3/kg]
93 double v() {
94 return prop(propertyFlag::V);
95 }
96
97 //! Internal energy [J/kg]
98 double u() {
99 return prop(propertyFlag::U);
100 }
101
102 //! Enthalpy [J/kg]
103 double h() {
104 return prop(propertyFlag::H);
105 }
106
107 //! Entropy [J/kg/K]
108 double s() {
109 return prop(propertyFlag::S);
110 }
111
112 //! Helmholtz function [J/kg]
113 double f() {
114 return u() - T*s();
115 }
116
117 //! Gibbs function [J/kg]
118 double g() {
119 return h() - T*s();
120 }
121
122 //! Specific heat at constant volume [J/kg/K]
123 virtual double cv();
124
125 //! Specific heat at constant pressure [J/kg/K]
126 virtual double cp();
127
128 virtual double thermalExpansionCoeff();
129
130 virtual double isothermalCompressibility();
131
132 //! Internal pressure [Pa], evaluated as
133 //! @f$ \pi_T = (\partial U / \partial V)_T @f$.
134 virtual double internalPressure();
135
136 //! @}
137 //! @name Saturation Properties
138 //! @{
139
140 double Ps();
141
142 //! The derivative of the saturation pressure with respect to temperature.
143 virtual double dPsdT();
144
145 //! Saturation temperature at pressure *p*.
146 double Tsat(double p);
147
148 //! Vapor mass fraction. If T >= Tcrit, 0 is returned for v < Vcrit, and 1
149 //! is returned if v > Vcrit.
150 double x();
151
152 //! Returns 1 if the current state is a liquid/vapor mixture, 0 otherwise.
153 //! By default, saturated vapor and saturated liquid are included; setting
154 //! the flag *strict* to true will exclude the boundaries.
155 int TwoPhase(bool strict=false);
156 //! @}
157
158 virtual double Pp()=0;
159
160 //! Enthalpy of a single-phase state
161 double hp() {
162 return up() + Pp()/Rho;
163 }
164
165 //! Gibbs function of a single-phase state
166 double gp() {
167 return hp() - T*sp();
168 }
169
170 double prop(propertyFlag::type ijob);
171
172 //! set T and P
173 void set_TPp(double t0, double p0);
174
175 //! Function to set or change the state for a property pair *XY* where
176 //! *x0* is the value of first property and *y0* is the value of the
177 //! second property.
178 void Set(PropertyPair::type XY, double x0, double y0);
179
180protected:
181 double T = Undef;
182 double Rho = Undef;
183 double Tslast = Undef;
184 double Rhf = Undef;
185 double Rhv = Undef;
186 double Pst = Undef;
187 double m_energy_offset = 0.0;
188 double m_entropy_offset = 0.0;
189 std::string m_name;
190 std::string m_formula;
191
192 virtual double ldens()=0;
193
194 //! Saturation pressure, Pa
195 virtual double Psat()=0;
196
197 //! Internal energy of a single-phase state
198 virtual double up()=0;
199
200 //! Entropy of a single-phase state
201 virtual double sp()=0;
202
203 virtual int ideal() {
204 return 0;
205 }
206
207 double vp() {
208 return 1.0/Rho;
209 }
210
211 //! Uses the lever rule to set state in the dome. Returns 1 if in dome,
212 //! 0 if not, in which case state not set.
213 int Lever(int itp, double sat, double val, propertyFlag::type ifunc);
214
215 //! Update saturated liquid and vapor densities and saturation pressure
216 void update_sat();
217
218private:
219 void set_Rho(double r0);
220 void set_T(double t0);
221 void set_v(double v0);
222 void BracketSlope(double p);
223 double vprop(propertyFlag::type ijob);
224 void set_xy(propertyFlag::type if1, propertyFlag::type if2,
225 double X, double Y,
226 double atx, double aty, double rtx, double rty);
227
228 int kbr = 0;
229 double Vmin, Vmax;
230 double Pmin, Pmax;
231 double dvbf, dv;
232 double v_here, P_here;
233};
234
235}
236
237#endif
virtual double up()=0
Internal energy of a single-phase state.
const char * formula()
Chemical formula for the substance.
Definition Sub.h:73
virtual double Vcrit()=0
Critical specific volume [m^3/kg].
double hp()
Enthalpy of a single-phase state.
Definition Sub.h:161
int TwoPhase(bool strict=false)
Returns 1 if the current state is a liquid/vapor mixture, 0 otherwise.
Definition Sub.cpp:271
virtual double internalPressure()
Internal pressure [Pa], evaluated as .
Definition Sub.cpp:235
virtual double cp()
Specific heat at constant pressure [J/kg/K].
Definition Sub.cpp:82
double gp()
Gibbs function of a single-phase state.
Definition Sub.h:166
double x()
Vapor mass fraction.
Definition Sub.cpp:283
virtual double Tmax()=0
Maximum temperature for which the equation of state is valid.
double u()
Internal energy [J/kg].
Definition Sub.h:98
virtual double MolWt()=0
Molecular weight [kg/kmol].
double h()
Enthalpy [J/kg].
Definition Sub.h:103
virtual double cv()
Specific heat at constant volume [J/kg/K].
Definition Sub.cpp:44
double Temp()
Temperature [K].
Definition Sub.h:88
virtual double Tmin()=0
Minimum temperature for which the equation of state is valid.
int Lever(int itp, double sat, double val, propertyFlag::type ifunc)
Uses the lever rule to set state in the dome.
Definition Sub.cpp:596
double g()
Gibbs function [J/kg].
Definition Sub.h:118
double P()
Pressure [Pa].
Definition Sub.cpp:37
const char * name()
Name of the substance.
Definition Sub.h:68
virtual double sp()=0
Entropy of a single-phase state.
virtual double Psat()=0
Saturation pressure, Pa.
double f()
Helmholtz function [J/kg].
Definition Sub.h:113
double v()
Specific volume [m^3/kg].
Definition Sub.h:93
virtual double Tcrit()=0
Critical temperature [K].
void Set(PropertyPair::type XY, double x0, double y0)
Function to set or change the state for a property pair XY where x0 is the value of first property an...
Definition Sub.cpp:352
virtual double Pcrit()=0
Critical pressure [Pa].
virtual double dPsdT()
The derivative of the saturation pressure with respect to temperature.
Definition Sub.cpp:254
double Tsat(double p)
Saturation temperature at pressure p.
Definition Sub.cpp:301
void update_sat()
Update saturated liquid and vapor densities and saturation pressure.
Definition Sub.cpp:514
void set_TPp(double t0, double p0)
set T and P
Definition Sub.cpp:787
double s()
Entropy [J/kg/K].
Definition Sub.h:108
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...