Cantera  2.4.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 http://www.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 
12 namespace tpx
13 {
14 
15 namespace PropertyPair
16 {
17 enum 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 
25 const int Pgiven = 0, Tgiven = 1;
26 
27 namespace propertyFlag
28 {
29 enum type { H, S, U, V, P, T };
30 }
31 
32 const double Undef = 999.1234;
33 
34 /*!
35  * Base class from which all pure substances are derived
36  */
37 class Substance
38 {
39 public:
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  int TwoPhase();
151  //! @}
152 
153  virtual double Pp()=0;
154 
155  //! Enthaply of a single-phase state
156  double hp() {
157  return up() + Pp()/Rho;
158  }
159 
160  //! Gibbs function of a single-phase state
161  double gp() {
162  return hp() - T*sp();
163  }
164 
165  double prop(propertyFlag::type ijob);
166 
167  //! set T and P
168  void set_TPp(double t0, double p0);
169 
170  //! Function to set or change the state for a property pair *XY* where
171  //! *x0* is the value of first property and *y0* is the value of the
172  //! second property.
173  void Set(PropertyPair::type XY, double x0, double y0);
174 
175 protected:
176  double T, Rho;
177  double Tslast, Rhf, Rhv;
178  double Pst;
179  double m_energy_offset;
180  double m_entropy_offset;
181  std::string m_name;
182  std::string m_formula;
183 
184  virtual double ldens()=0;
185 
186  //! Saturation pressure, Pa
187  virtual double Psat()=0;
188 
189  //! Internal energy of a single-phase state
190  virtual double up()=0;
191 
192  //! Entropy of a single-phase state
193  virtual double sp()=0;
194 
195  virtual int ideal() {
196  return 0;
197  }
198 
199  double vp() {
200  return 1.0/Rho;
201  }
202 
203  //! Uses the lever rule to set state in the dome. Returns 1 if in dome,
204  //! 0 if not, in which case state not set.
205  int Lever(int itp, double sat, double val, propertyFlag::type ifunc);
206 
207  //! Update saturated liquid and vapor densities and saturation pressure
208  void update_sat();
209 
210 private:
211  void set_Rho(double r0);
212  void set_T(double t0);
213  void set_v(double v0);
214  void BracketSlope(double p);
215  double vprop(propertyFlag::type ijob);
216  void set_xy(propertyFlag::type if1, propertyFlag::type if2,
217  double X, double Y,
218  double atx, double aty, double rtx, double rty);
219 
220  int kbr;
221  double Vmin, Vmax;
222  double Pmin, Pmax;
223  double dvbf, dv;
224  double v_here, P_here;
225 };
226 
227 }
228 
229 #endif
virtual double MolWt()=0
Molecular weight [kg/kmol].
virtual double Vcrit()=0
Critical specific volume [m^3/kg].
virtual double dPsdT()
The derivative of the saturation pressure with respect to temperature.
Definition: Sub.cpp:198
virtual double sp()=0
Entropy of a single-phase state.
double x()
Vapor mass fraction.
Definition: Sub.cpp:217
int TwoPhase()
Returns 1 if the current state is a liquid/vapor mixture, 0 otherwise.
Definition: Sub.cpp:208
double Tsat(double p)
Saturation temperature at pressure p.
Definition: Sub.cpp:235
const char * name()
Name of the substance.
Definition: Sub.h:69
double gp()
Gibbs function of a single-phase state.
Definition: Sub.h:161
virtual double Tmin()=0
Minimum temperature for which the equation of state is valid.
virtual double cp()
Specific heat at constant pressure [J/kg/K].
Definition: Sub.cpp:86
double s()
Entropy [J/kg/K].
Definition: Sub.h:109
double v()
Specific volume [m^3/kg].
Definition: Sub.h:94
double f()
Helmholtz function [J/kg].
Definition: Sub.h:114
const doublereal Undef
Fairly random number to be used to initialize variables against to see if they are subsequently defin...
Definition: ct_defs.h:134
void update_sat()
Update saturated liquid and vapor densities and saturation pressure.
Definition: Sub.cpp:441
void set_TPp(double t0, double p0)
set T and P
Definition: Sub.cpp:718
virtual double up()=0
Internal energy of a single-phase state.
double Temp()
Temperature [K].
Definition: Sub.h:89
virtual double cv()
Specific heat at constant volume [J/kg/K].
Definition: Sub.cpp:55
double hp()
Enthaply of a single-phase state.
Definition: Sub.h:156
double g()
Gibbs function [J/kg].
Definition: Sub.h:119
virtual double Tmax()=0
Maximum temperature for which the equation of state is valid.
virtual double Tcrit()=0
Critical temperature [K].
virtual double Psat()=0
Saturation pressure, Pa.
double h()
Enthalpy [J/kg].
Definition: Sub.h:104
double u()
Internal energy [J/kg].
Definition: Sub.h:99
const char * formula()
Chemical formula for the substance.
Definition: Sub.h:74
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:285
virtual double Pcrit()=0
Critical pressure [Pa].
double P()
Pressure [Pa].
Definition: Sub.cpp:48
int Lever(int itp, double sat, double val, propertyFlag::type ifunc)
Uses the lever rule to set state in the dome.
Definition: Sub.cpp:527
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...