Cantera  2.5.1
PureFluidPhase.h
Go to the documentation of this file.
1 /**
2  * @file PureFluidPhase.h
3  *
4  * Header for a ThermoPhase class for a pure fluid phase consisting of
5  * gas, liquid, mixed-gas-liquid and supercrit fluid (see \ref thermoprops
6  * and class \link Cantera::PureFluidPhase PureFluidPhase\endlink).
7  *
8  * It inherits from ThermoPhase, but is built on top of the tpx package.
9  */
10 
11 // This file is part of Cantera. See License.txt in the top-level directory or
12 // at https://cantera.org/license.txt for license and copyright information.
13 
14 #ifndef CT_EOS_TPX_H
15 #define CT_EOS_TPX_H
16 
17 #include "ThermoPhase.h"
18 #include "cantera/tpx/Sub.h"
19 
20 namespace Cantera
21 {
22 //! This phase object consists of a single component that can be a gas, a
23 //! liquid, a mixed gas-liquid fluid, or a fluid beyond its critical point
24 /*!
25  * The object inherits from ThermoPhase. However, it's built on top of the tpx
26  * package.
27  *
28  * @ingroup thermoprops
29  */
31 {
32 public:
33  //! Empty Base Constructor
35 
36  virtual std::string type() const {
37  return "PureFluid";
38  }
39 
40  //! String indicating the mechanical phase of the matter in this Phase.
41  /*!
42  * Options for the string are:
43  * * `supercritical`
44  * * `gas`
45  * * `liquid`
46  * * `liquid-gas-mix`
47  *
48  * If the temperature or pressure are greater than the critical temperature or
49  * pressure, respectively, the mechanical phase is `supercritical`. If the
50  * underlying tpx::TwoPhase() returns `True`, the mechanical phase is
51  * `liquid-gas-mix`. If the temperature is greater than the saturation temperature
52  * at the current pressure, the mechanical phase is `gas`. Otherwise, the mechanical
53  * phase is `liquid`.
54  */
55  virtual std::string phaseOfMatter() const;
56 
57  //! Set the name of the TPX substance to use for the equation of state. This
58  //! function should be called before initThermo().
59  void setSubstance(const std::string& name) {
60  m_tpx_name = name;
61  }
62 
63  virtual bool isPure() const {
64  return true;
65  }
66 
67  virtual bool hasPhaseTransition() const {
68  return true;
69  }
70 
71  virtual std::vector<std::string> fullStates() const;
72  virtual std::vector<std::string> partialStates() const;
73 
74  virtual double minTemp(size_t k=npos) const;
75  virtual double maxTemp(size_t k=npos) const;
76 
77  virtual doublereal enthalpy_mole() const;
78  virtual doublereal intEnergy_mole() const;
79  virtual doublereal entropy_mole() const;
80  virtual doublereal gibbs_mole() const;
81  virtual doublereal cp_mole() const;
82  virtual doublereal cv_mole() const;
83 
84  //! Return the thermodynamic pressure (Pa).
85  /*!
86  * This method calculates the current pressure consistent with the
87  * independent variables, T, rho.
88  */
89  virtual doublereal pressure() const;
90 
91  //! sets the thermodynamic pressure (Pa).
92  /*!
93  * This method calculates the density that is consistent with the
94  * desired pressure, given the temperature.
95  *
96  * @param p Pressure (Pa)
97  */
98  virtual void setPressure(doublereal p);
99  virtual void setTemperature(const double T);
100  virtual void setDensity(const double rho);
101 
102  virtual void getChemPotentials(doublereal* mu) const {
103  mu[0] = gibbs_mole();
104  }
105 
106  virtual void getPartialMolarEnthalpies(doublereal* hbar) const;
107  virtual void getPartialMolarEntropies(doublereal* sbar) const;
108  virtual void getPartialMolarIntEnergies(doublereal* ubar) const;
109  virtual void getPartialMolarCp(doublereal* cpbar) const;
110  virtual void getPartialMolarVolumes(doublereal* vbar) const;
111 
112  virtual Units standardConcentrationUnits() const;
113  virtual void getActivityConcentrations(doublereal* c) const;
114  virtual doublereal standardConcentration(size_t k=0) const;
115 
116  virtual void getActivities(doublereal* a) const;
117 
118  virtual doublereal isothermalCompressibility() const;
119  virtual doublereal thermalExpansionCoeff() const;
120 
121  //! Returns a reference to the substance object
123 
124  //@}
125  /// @name Properties of the Standard State of the Species in the Solution
126  /*!
127  * The standard state of the pure fluid is defined as the real properties
128  * of the pure fluid at the most stable state of the fluid at the current
129  * temperature and pressure of the solution. With this definition, the
130  * activity of the fluid is always then defined to be equal to one.
131  */
132  //@{
133 
134  virtual void getStandardChemPotentials(doublereal* mu) const;
135  virtual void getEnthalpy_RT(doublereal* hrt) const;
136  virtual void getEntropy_R(doublereal* sr) const;
137  virtual void getGibbs_RT(doublereal* grt) const;
138 
139  //@}
140 
141  /// @name Thermodynamic Values for the Species Reference States
142  /*!
143  * The species reference state for pure fluids is defined as an ideal gas at
144  * the reference pressure and current temperature of the fluid.
145  */
146  //@{
147 
148  virtual void getEnthalpy_RT_ref(doublereal* hrt) const;
149  virtual void getGibbs_RT_ref(doublereal* grt) const;
150  virtual void getGibbs_ref(doublereal* g) const;
151  virtual void getEntropy_R_ref(doublereal* er) const;
152 
153  /**
154  * @name Setting the State
155  *
156  * These methods set all or part of the thermodynamic state.
157  * @{
158  */
159 
160  virtual void setState_HP(double h, double p, double tol=1e-9);
161  virtual void setState_UV(double u, double v, double tol=1e-9);
162  virtual void setState_SV(double s, double v, double tol=1e-9);
163  virtual void setState_SP(double s, double p, double tol=1e-9);
164  virtual void setState_ST(double s, double t, double tol=1e-9);
165  virtual void setState_TV(double t, double v, double tol=1e-9);
166  virtual void setState_PV(double p, double v, double tol=1e-9);
167  virtual void setState_UP(double u, double p, double tol=1e-9);
168  virtual void setState_VH(double v, double h, double tol=1e-9);
169  virtual void setState_TH(double t, double h, double tol=1e-9);
170  virtual void setState_SH(double s, double h, double tol=1e-9);
171  //@}
172 
173  //! @name Critical State Properties
174  //@{
175 
176  virtual doublereal critTemperature() const;
177  virtual doublereal critPressure() const;
178  virtual doublereal critDensity() const;
179 
180  //@}
181 
182  //! @name Saturation properties.
183  //@{
184 
185  virtual doublereal satTemperature(doublereal p) const;
186  virtual doublereal satPressure(doublereal t);
187  virtual doublereal vaporFraction() const;
188 
189  virtual void setState_Tsat(doublereal t, doublereal x);
190  virtual void setState_Psat(doublereal p, doublereal x);
191  //@}
192 
193  virtual void initThermo();
194  virtual void setParametersFromXML(const XML_Node& eosdata);
195 
196  virtual std::string report(bool show_thermo=true,
197  doublereal threshold=1e-14) const;
198 
199  virtual bool compatibleWithMultiPhase() const {
200  return false;
201  }
202 
203 protected:
204  //! Main call to the tpx level to set the state of the system
205  /*!
206  * @param n Integer indicating which 2 thermo components are held constant
207  * @param x Value of the first component
208  * @param y Value of the second component
209  */
210  void Set(tpx::PropertyPair::type n, double x, double y) const;
211 
212 private:
213  //! Pointer to the underlying tpx object Substance that does the work
214  mutable std::unique_ptr<tpx::Substance> m_sub;
215 
216  //! Int indicating the type of the fluid
217  /*!
218  * The tpx package uses an int to indicate what fluid is being sought. Used
219  * only if #m_tpx_name is not set.
220  */
222 
223  //! Name for this substance used by the TPX package. If this is not set,
224  //! #m_subflag is used instead.
225  std::string m_tpx_name;
226 
227  //! Molecular weight of the substance (kg kmol-1)
228  doublereal m_mw;
229 
230  //! flag to turn on some printing.
231  bool m_verbose;
232 };
233 
234 }
235 
236 #endif
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
std::string name() const
Return the name of the phase.
Definition: Phase.cpp:84
This phase object consists of a single component that can be a gas, a liquid, a mixed gas-liquid flui...
virtual void setState_PV(double p, double v, double tol=1e-9)
Set the pressure (Pa) and specific volume (m^3/kg).
void Set(tpx::PropertyPair::type n, double x, double y) const
Main call to the tpx level to set the state of the system.
virtual void setState_HP(double h, double p, double tol=1e-9)
Set the internally stored specific enthalpy (J/kg) and pressure (Pa) of the phase.
virtual void setState_UV(double u, double v, double tol=1e-9)
Set the specific internal energy (J/kg) and specific volume (m^3/kg).
virtual void setState_VH(double v, double h, double tol=1e-9)
Set the specific volume (m^3/kg) and the specific enthalpy (J/kg)
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
std::string m_tpx_name
Name for this substance used by the TPX package.
virtual void getActivities(doublereal *a) const
Get the array of non-dimensional activities at the current solution temperature, pressure,...
virtual std::string report(bool show_thermo=true, doublereal threshold=1e-14) const
returns a summary of the state of the phase as a string
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Return an array of partial molar internal energies for the species in the mixture.
virtual void setState_UP(double u, double p, double tol=1e-9)
Set the specific internal energy (J/kg) and pressure (Pa).
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
virtual doublereal critPressure() const
Critical pressure (Pa).
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
virtual doublereal vaporFraction() const
Return the fraction of vapor at the current conditions.
virtual bool compatibleWithMultiPhase() const
Indicates whether this phase type can be used with class MultiPhase for equilibrium calculations.
virtual void setState_SH(double s, double h, double tol=1e-9)
Set the specific entropy (J/kg/K) and the specific enthalpy (J/kg)
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
PureFluidPhase()
Empty Base Constructor.
virtual doublereal satTemperature(doublereal p) const
Return the saturation temperature given the pressure.
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
virtual std::vector< std::string > partialStates() const
Return a vector of settable partial property sets within a phase.
virtual void setPressure(doublereal p)
sets the thermodynamic pressure (Pa).
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
virtual bool hasPhaseTransition() const
Return whether phase represents a substance with phase transitions.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
virtual doublereal critTemperature() const
Critical temperature (K).
virtual double minTemp(size_t k=npos) const
Minimum temperature for which the thermodynamic data for the species or phase are valid.
virtual void setState_SP(double s, double p, double tol=1e-9)
Set the specific entropy (J/kg/K) and pressure (Pa).
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
virtual std::string type() const
String indicating the thermodynamic model implemented.
virtual void setState_Tsat(doublereal t, doublereal x)
Set the state to a saturated system at a particular temperature.
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
virtual bool isPure() const
Return whether phase represents a pure (single species) substance.
virtual Units standardConcentrationUnits() const
Returns the units of the "standard concentration" for this phase.
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
doublereal m_mw
Molecular weight of the substance (kg kmol-1)
virtual void setDensity(const double rho)
Set the internally stored density (kg/m^3) of the phase.
std::unique_ptr< tpx::Substance > m_sub
Pointer to the underlying tpx object Substance that does the work.
void setSubstance(const std::string &name)
Set the name of the TPX substance to use for the equation of state.
virtual void getStandardChemPotentials(doublereal *mu) const
virtual void setState_Psat(doublereal p, doublereal x)
Set the state to a saturated system at a particular pressure.
virtual double maxTemp(size_t k=npos) const
Maximum temperature for which the thermodynamic data for the species are valid.
virtual doublereal satPressure(doublereal t)
Return the saturation pressure given the temperature.
virtual std::vector< std::string > fullStates() const
Return a vector containing full states defining a phase.
virtual void setTemperature(const double T)
Set the internally stored temperature of the phase (K).
tpx::Substance & TPX_Substance()
Returns a reference to the substance object.
virtual void getGibbs_ref(doublereal *g) const
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
virtual doublereal critDensity() const
Critical density (kg/m3).
virtual std::string phaseOfMatter() const
String indicating the mechanical phase of the matter in this Phase.
int m_subflag
Int indicating the type of the fluid.
virtual void setState_TV(double t, double v, double tol=1e-9)
Set the temperature (K) and specific volume (m^3/kg).
virtual void setState_SV(double s, double v, double tol=1e-9)
Set the specific entropy (J/kg/K) and specific volume (m^3/kg).
virtual doublereal intEnergy_mole() const
Molar internal energy. Units: J/kmol.
bool m_verbose
flag to turn on some printing.
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
virtual void setState_ST(double s, double t, double tol=1e-9)
Set the specific entropy (J/kg/K) and temperature (K).
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
virtual void setState_TH(double t, double h, double tol=1e-9)
Set the temperature (K) and the specific enthalpy (J/kg)
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
A representation of the units associated with a dimensional quantity.
Definition: Units.h:30
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:104
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:188
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264