https://mooseframework.inl.gov
TabulatedFluidProperties.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
13 #include "DelimitedFileReader.h"
14 
15 #include "libmesh/utility.h"
16 
19 
20 #pragma GCC diagnostic push
21 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
22 
27 {
28 public:
30 
32 
33  virtual void initialSetup() override;
34  virtual void constructInterpolation() = 0;
35 
36  virtual std::string fluidName() const override;
37 
38  virtual Real molarMass() const override;
39 
40  virtual Real rho_from_p_T(Real pressure, Real temperature) const override;
41 
42  virtual void rho_from_p_T(
43  Real pressure, Real temperature, Real & rho, Real & drho_dp, Real & drho_dT) const override;
44  virtual void rho_from_p_T(const ADReal & pressure,
45  const ADReal & temperature,
46  ADReal & rho,
47  ADReal & drho_dp,
48  ADReal & drho_dT) const override;
49 
50  virtual Real rho_from_p_s(Real p, Real s) const override;
51  virtual void
52  rho_from_p_s(Real p, Real s, Real & rho, Real & drho_dp, Real & drho_ds) const override;
53 
54  virtual Real v_from_p_T(Real pressure, Real temperature) const override;
55 
56  virtual void
57  v_from_p_T(Real pressure, Real temperature, Real & v, Real & dv_dp, Real & dv_dT) const override;
58 
59  virtual Real e_from_p_T(Real pressure, Real temperature) const override;
60 
61  virtual void
62  e_from_p_T(Real pressure, Real temperature, Real & e, Real & de_dp, Real & de_dT) const override;
63 
64  virtual Real e_from_p_rho(Real pressure, Real rho) const override;
65 
66  virtual void
67  e_from_p_rho(Real pressure, Real rho, Real & e, Real & de_dp, Real & de_drho) const override;
68 
69  virtual Real T_from_p_rho(Real pressure, Real rho) const;
70 
71  virtual void T_from_p_rho(Real pressure, Real rho, Real & T, Real & dT_dp, Real & dT_drho) const;
72 
73  virtual Real h_from_p_T(Real p, Real T) const override;
74 
75  virtual ADReal h_from_p_T(const ADReal & pressure, const ADReal & temperature) const override;
76 
77  virtual void
78  h_from_p_T(Real pressure, Real temperature, Real & h, Real & dh_dp, Real & dh_dT) const override;
79 
80  virtual Real mu_from_p_T(Real pressure, Real temperature) const override;
81 
82  virtual void mu_from_p_T(
83  Real pressure, Real temperature, Real & mu, Real & dmu_dp, Real & dmu_dT) const override;
84 
85  virtual Real cp_from_p_T(Real pressure, Real temperature) const override;
86 
87  virtual void cp_from_p_T(
88  Real pressure, Real temperature, Real & cp, Real & dcp_dp, Real & dcp_dT) const override;
89 
90  using SinglePhaseFluidProperties::cp_from_p_T;
91 
92  virtual Real cv_from_p_T(Real pressure, Real temperature) const override;
93  virtual void cv_from_p_T(
94  Real pressure, Real temperature, Real & cv, Real & dcv_dp, Real & dcv_dT) const override;
95 
96  virtual Real c_from_p_T(Real pressure, Real temperature) const override;
97  virtual void
98  c_from_p_T(Real pressure, Real temperature, Real & c, Real & dc_dp, Real & dc_dT) const override;
99 
100  virtual Real k_from_p_T(Real pressure, Real temperature) const override;
101 
102  virtual void
103  k_from_p_T(Real pressure, Real temperature, Real & k, Real & dk_dp, Real & dk_dT) const override;
104 
105  virtual Real s_from_p_T(Real pressure, Real temperature) const override;
106 
107  virtual void s_from_p_T(Real p, Real T, Real & s, Real & ds_dp, Real & ds_dT) const override;
108 
113  virtual std::vector<Real> henryCoefficients() const override;
114 
115  virtual Real vaporPressure(Real temperature) const override;
116 
117  virtual void vaporPressure(Real temperature, Real & psat, Real & dpsat_dT) const override;
118 
119  virtual Real vaporTemperature(Real pressure) const override;
120  virtual void vaporTemperature(Real pressure, Real & Tsat, Real & dTsat_dp) const override;
121 
122  virtual Real T_from_p_h(Real pressure, Real enthalpy) const override;
123  virtual ADReal T_from_p_h(const ADReal & pressure, const ADReal & enthalpy) const override;
124 
125  virtual Real triplePointPressure() const override;
126  virtual Real triplePointTemperature() const override;
127  virtual Real criticalPressure() const override;
128  virtual Real criticalTemperature() const override;
129  virtual Real criticalDensity() const override;
130 
136  virtual Real p_from_v_e(Real v, Real e) const override;
137  virtual void p_from_v_e(Real v, Real e, Real & p, Real & dp_dv, Real & dp_de) const override;
138  virtual Real T_from_v_e(Real v, Real e) const override;
139  virtual void T_from_v_e(Real v, Real e, Real & T, Real & dT_dv, Real & dT_de) const override;
140  virtual Real c_from_v_e(Real v, Real e) const override;
141  virtual void c_from_v_e(Real v, Real e, Real & c, Real & dc_dv, Real & dc_de) const override;
142  virtual Real cp_from_v_e(Real v, Real e) const override;
143  virtual void cp_from_v_e(Real v, Real e, Real & cp, Real & dcp_dv, Real & dcp_de) const override;
144  virtual Real cv_from_v_e(Real v, Real e) const override;
145  virtual void cv_from_v_e(Real v, Real e, Real & cv, Real & dcv_dv, Real & dcv_de) const override;
146  virtual Real mu_from_v_e(Real v, Real e) const override;
147  virtual void mu_from_v_e(Real v, Real e, Real & mu, Real & dmu_dv, Real & dmu_de) const override;
148  virtual Real k_from_v_e(Real v, Real e) const override;
149  virtual void k_from_v_e(Real v, Real e, Real & k, Real & dk_dv, Real & dk_de) const override;
150  virtual Real g_from_v_e(Real v, Real e) const override;
151  virtual Real e_from_v_h(Real v, Real h) const override;
152  virtual void e_from_v_h(Real v, Real h, Real & e, Real & de_dv, Real & de_dh) const override;
153  virtual Real T_from_h_s(Real h, Real s) const;
154  virtual Real T_from_p_s(Real p, Real s) const;
155  virtual void T_from_p_s(Real p, Real s, Real & T, Real & dT_dp, Real & dT_ds) const;
156  virtual Real s_from_v_e(Real v, Real e) const override;
157  virtual Real s_from_h_p(Real h, Real pressure) const override;
158  virtual void
159  s_from_h_p(Real h, Real pressure, Real & s, Real & ds_dh, Real & ds_dp) const override;
160 
162  using SinglePhaseFluidProperties::c_from_v_e;
163  using SinglePhaseFluidProperties::p_from_v_e;
164  using SinglePhaseFluidProperties::T_from_v_e;
165 
166 protected:
171  void writeTabulatedData(std::string file_name);
172 
179  template <typename T>
180  void checkInputVariables(T & pressure, T & temperature) const;
181 
188  template <typename T>
189  void checkInputVariablesVE(T & v, T & e) const;
190 
194  virtual void checkInitialGuess() const;
195 
197  void readFileTabulationData(bool use_pT);
198 
203  void checkFileTabulationGrids(std::vector<Real> & v1,
204  std::vector<Real> & v2,
205  const std::string & file_name,
206  const std::string & v1_name,
207  const std::string & v2_name);
208 
213  virtual void generateTabulatedData();
214 
219  virtual void generateVETabulatedData();
220 
223 
229  void createVGridVector();
230  void createVEGridVectors();
237  void createVHGridVectors();
238 
240  void missingVEInterpolationError(const std::string & function_name) const;
241 
242  // Utility to forward errors related to fluid properties methods not implemented
243  [[noreturn]] void FluidPropertiesForwardError(const std::string & desired_routine) const;
244 
246  FileName _file_name_in;
250  FileName _file_name_out;
254  const bool _save_file;
255 
257  std::vector<Real> _pressure;
259  std::vector<Real> _temperature;
261  std::vector<Real> _specific_volume;
263  std::vector<Real> _internal_energy;
265  std::vector<Real> _enthalpy;
266 
271 
273  std::vector<std::vector<Real>> _properties;
275  std::vector<std::vector<Real>> _properties_ve;
276 
278  std::vector<std::unique_ptr<BidimensionalInterpolation>> _property_ipol;
280  std::vector<std::unique_ptr<BidimensionalInterpolation>> _property_ve_ipol;
281 
291  unsigned int _num_T;
293  unsigned int _num_p;
294 
299 
303  std::vector<std::string> _interpolated_properties;
316 
318  unsigned int _density_idx;
319  unsigned int _enthalpy_idx;
320  unsigned int _internal_energy_idx;
321  unsigned int _viscosity_idx;
322  unsigned int _k_idx;
323  unsigned int _c_idx;
324  unsigned int _cp_idx;
325  unsigned int _cv_idx;
326  unsigned int _entropy_idx;
327  unsigned int _p_idx;
328  unsigned int _T_idx;
329 
332 
340  unsigned int _num_v;
342  unsigned int _num_e;
349 
354  {
360  };
361 
363  std::unique_ptr<BidimensionalInterpolation> _T_from_v_e_ipol;
364 
366  std::unique_ptr<BidimensionalInterpolation> _p_from_v_e_ipol;
367 
369  std::unique_ptr<BidimensionalInterpolation> _T_from_v_h_ipol;
370 
372  std::unique_ptr<BidimensionalInterpolation> _p_from_v_h_ipol;
373 
390 };
391 
392 #pragma GCC diagnostic pop
virtual Real k_from_p_T(Real pressure, Real temperature) const override
bool _log_space_v
log-space the specific volume interpolation grid axis instead of linear
FileName _file_name_ve_in
File name of input (v,e) tabulated data file.
void readFileTabulationData(bool use_pT)
Read tabulation data from file.
virtual void initialSetup() override
virtual Real rho_from_p_s(Real p, Real s) const override
virtual Real triplePointTemperature() const override
Triple point temperature.
virtual Real v_from_p_T(Real pressure, Real temperature) const override
const bool _create_direct_ve_interpolations
Whether to create direct (v,e) interpolations.
static const std::string cv
Definition: NS.h:122
void checkFileTabulationGrids(std::vector< Real > &v1, std::vector< Real > &v2, const std::string &file_name, const std::string &v1_name, const std::string &v2_name)
Check that the tabulation grids in the file are correct (no repeats etc)
Class for fluid properties read from a tabulation in a file.
virtual Real criticalDensity() const override
Critical density.
std::unique_ptr< BidimensionalInterpolation > _p_from_v_h_ipol
Bidimensional interpolation of pressure from (v,h)
const bool _create_direct_pT_interpolations
Whether to create direct (p,T) interpolations.
virtual Real e_from_v_h(Real v, Real h) const override
Real _temperature_max
Maximum temperature in tabulated data.
Real _h_max
Maximum specific enthalpy in tabulated data.
Real _e_max
Maximum internal energy in tabulated data (can be user-specified)
virtual Real T_from_p_s(Real p, Real s) const
virtual Real T_from_v_e(Real v, Real e) const override
virtual void checkInitialGuess() const
Checks initial guess for Newton Method.
Real _e_min
Minimum internal energy in tabulated data (can be user-specified)
Real _pressure_max
Maximum pressure in tabulated data.
bool _e_bounds_specified
Whether the specific internal energy bounds were set by the user.
MooseUtils::DelimitedFileReader _csv_reader
The MOOSE delimited file reader.
static const std::string temperature
Definition: NS.h:59
bool _log_space_e
log-space the internal energy interpolation grid axis instead of linear
virtual Real s_from_p_T(Real pressure, Real temperature) const override
MooseEnum _OOBBehavior
User-selected out-of-bounds behavior.
MultiMooseEnum _interpolated_properties_enum
Properties to be interpolated entered in the input file.
void computePropertyIndicesInInterpolationVectors()
Retrieves the index for each property in the vector of interpolations.
bool _v_bounds_specified
Whether the specific volume bounds were set by the user.
DualNumber< Real, DNDerivativeType, true > ADReal
std::vector< std::unique_ptr< BidimensionalInterpolation > > _property_ve_ipol
Vector of bi-dimensional interpolation of fluid properties directly in (v,e)
std::unique_ptr< BidimensionalInterpolation > _p_from_v_e_ipol
Bi-dimensional interpolation of pressure from (v,e)
Real _h_min
Minimum specific enthalpy in tabulated data.
virtual Real s_from_h_p(Real h, Real pressure) const override
virtual Real vaporTemperature(Real pressure) const override
Vapor temperature.
std::unique_ptr< BidimensionalInterpolation > _T_from_v_e_ipol
Bi-dimensional interpolation of temperature from (v,e)
FileName _file_name_ve_out
File name of output (v,e) tabulated data file.
std::vector< Real > _enthalpy
Specific enthalpy vector.
unsigned int _num_v
Number of specific volume points in the tabulated data.
static const std::string cp
Definition: NS.h:121
bool _construct_pT_from_ve
if the lookup table p(v, e) and T(v, e) should be constructed
Real _temperature_min
Minimum temperature in tabulated data.
e e e e s T T T T T rho v v T e h
void createVHGridVectors()
Create (or reset) the grid vectors for the specific volume and enthalpy interpolation The order of pr...
void FluidPropertiesForwardError(const std::string &desired_routine) const
bool _construct_pT_from_vh
if the lookup table p(v, h) and T(v, h) should be constructed
virtual Real molarMass() const override
Molar mass [kg/mol].
FileName _file_name_out
File name of output tabulated data file.
virtual Real h_from_p_T(Real p, Real T) const override
virtual Real e_from_p_rho(Real pressure, Real rho) const override
virtual Real vaporPressure(Real temperature) const override
Vapor pressure.
void checkInputVariablesVE(T &v, T &e) const
Checks that the inputs are within the range of the tabulated data, and throws an error if they are no...
static InputParameters validParams()
virtual Real k_from_v_e(Real v, Real e) const override
static const std::string mu
Definition: NS.h:123
virtual void generateVETabulatedData()
Generates a table of fluid properties by looping over specific volume and internal energy and calcula...
virtual Real cv_from_v_e(Real v, Real e) const override
virtual Real c_from_p_T(Real pressure, Real temperature) const override
Common class for single phase fluid properties.
bool _log_space_h
log-space the enthalpy interpolation grid axis instead of linear
Real _v_min
Minimum specific volume in tabulated data (can be user-specified)
virtual Real triplePointPressure() const override
Triple point pressure.
std::vector< std::string > _interpolated_properties
List of properties to be interpolated.
virtual Real g_from_v_e(Real v, Real e) const override
virtual Real e_from_p_T(Real pressure, Real temperature) const override
virtual Real c_from_v_e(Real v, Real e) const override
TabulatedFluidProperties(const InputParameters &parameters)
std::vector< Real > _pressure
Pressure vector.
std::vector< Real > _temperature
Temperature vector.
virtual Real rho_from_p_T(Real pressure, Real temperature) const override
virtual Real criticalTemperature() const override
Critical temperature.
unsigned int _num_T
Number of temperature points in the tabulated data.
bool _initial_setup_done
keeps track of whether initialSetup has been performed
void checkInputVariables(T &pressure, T &temperature) const
Checks that the inputs are within the range of the tabulated data, and throws an error if they are no...
virtual Real criticalPressure() const override
Critical pressure.
virtual std::string fluidName() const override
Fluid name.
const SinglePhaseFluidProperties *const _fp
SinglePhaseFluidPropertiesPT UserObject.
void missingVEInterpolationError(const std::string &function_name) const
Standardized error message for missing interpolation.
virtual Real s_from_v_e(Real v, Real e) const override
Real _pressure_min
Minimum pressure in tabulated data.
std::vector< std::vector< Real > > _properties
Tabulated fluid properties (read from file OR computed from _fp)
virtual Real mu_from_p_T(Real pressure, Real temperature) const override
virtual Real cp_from_p_T(Real pressure, Real temperature) const override
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int _num_p
Number of pressure points in the tabulated data.
virtual Real T_from_p_h(Real pressure, Real enthalpy) const override
const bool _allow_fp_and_tabulation
Whether to allow a fp object when a tabulation is in use.
virtual Real cv_from_p_T(Real pressure, Real temperature) const override
std::vector< std::vector< Real > > _properties_ve
Tabulated fluid properties in (v,e) (read from file OR computed from _fp)
Real _v_max
Maximum specific volume in tabulated data (can be user-specified)
static const std::string pressure
Definition: NS.h:56
virtual Real T_from_h_s(Real h, Real s) const
std::vector< Real > _specific_volume
Specific volume vector.
virtual Real p_from_v_e(Real v, Real e) const override
Derivatives like dc_dv & dc_de are computed using the chain rule dy/dx(p,T) = dy/dp * dp/dx + dy/dT *...
virtual Real cp_from_v_e(Real v, Real e) const override
unsigned int _density_idx
Index of each property.
const InputParameters & parameters() const
std::vector< Real > _internal_energy
Specific internal energy vector.
std::unique_ptr< BidimensionalInterpolation > _T_from_v_h_ipol
Bi-dimensional interpolation of temperature from (v,h)
bool _interpolate_density
Set of flags to note whether a property is to be interpolated.
virtual std::vector< Real > henryCoefficients() const override
The following routines are simply forwarded to the &#39;fp&#39; companion FluidProperties as they are not inc...
void createVGridVector()
Create (or reset) the grid vectors for the specific volume and internal energy interpolations The ord...
std::vector< std::unique_ptr< BidimensionalInterpolation > > _property_ipol
Vector of bi-dimensional interpolation of fluid properties.
const bool _save_file
Whether to save a generated fluid properties file to disk.
virtual Real mu_from_v_e(Real v, Real e) const override
OOBBehavior
Enum specifying all the behavior on out of bounds data options.
virtual void generateTabulatedData()
Generates a table of fluid properties by looping over pressure and temperature and calculating proper...
virtual void constructInterpolation()=0
static const std::string k
Definition: NS.h:130
void writeTabulatedData(std::string file_name)
Writes tabulated data to a file.
virtual Real T_from_p_rho(Real pressure, Real rho) const
FileName _file_name_in
File name of input tabulated data file.
unsigned int _num_e
Number of internal energy points in tabulated data.