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