https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
28public:
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 ADReal rho_from_p_T(const ADReal & pressure, const ADReal & temperature) const override;
43
44 virtual void rho_from_p_T(
45 Real pressure, Real temperature, Real & rho, Real & drho_dp, Real & drho_dT) const override;
46 virtual void rho_from_p_T(const ADReal & pressure,
47 const ADReal & temperature,
48 ADReal & rho,
49 ADReal & drho_dp,
50 ADReal & drho_dT) const override;
51
52 virtual Real rho_from_p_s(Real p, Real s) const override;
53 virtual void
54 rho_from_p_s(Real p, Real s, Real & rho, Real & drho_dp, Real & drho_ds) const override;
55
56 virtual Real v_from_p_T(Real pressure, Real temperature) const override;
57
58 virtual ADReal v_from_p_T(const ADReal & pressure, const ADReal & temperature) const override;
59
60 virtual void
61 v_from_p_T(Real pressure, Real temperature, Real & v, Real & dv_dp, Real & dv_dT) const override;
62
63 virtual Real e_from_p_T(Real pressure, Real temperature) const override;
64
65 virtual ADReal e_from_p_T(const ADReal & pressure, const ADReal & temperature) const override;
66
67 virtual void
68 e_from_p_T(Real pressure, Real temperature, Real & e, Real & de_dp, Real & de_dT) const override;
69
70 virtual Real e_from_p_rho(Real pressure, Real rho) const override;
71
72 virtual ADReal e_from_p_rho(const ADReal & pressure, const ADReal & rho) const override;
73
74 virtual void
75 e_from_p_rho(Real pressure, Real rho, Real & e, Real & de_dp, Real & de_drho) const override;
76
77 virtual Real T_from_p_rho(Real pressure, Real rho) const;
78
79 virtual ADReal T_from_p_rho(const ADReal & pressure, const ADReal & rho) const;
80
81 virtual void T_from_p_rho(Real pressure, Real rho, Real & T, Real & dT_dp, Real & dT_drho) const;
82
83 virtual Real h_from_p_T(Real p, Real T) const override;
84
85 virtual ADReal h_from_p_T(const ADReal & pressure, const ADReal & temperature) const override;
86
87 virtual void
88 h_from_p_T(Real pressure, Real temperature, Real & h, Real & dh_dp, Real & dh_dT) const override;
89
90 virtual Real mu_from_p_T(Real pressure, Real temperature) const override;
91
92 virtual void mu_from_p_T(
93 Real pressure, Real temperature, Real & mu, Real & dmu_dp, Real & dmu_dT) const override;
94
95 virtual Real cp_from_p_T(Real pressure, Real temperature) const override;
96
97 virtual void cp_from_p_T(
98 Real pressure, Real temperature, Real & cp, Real & dcp_dp, Real & dcp_dT) const override;
99
100 using SinglePhaseFluidProperties::cp_from_p_T;
101
102 virtual Real cv_from_p_T(Real pressure, Real temperature) const override;
103 virtual void cv_from_p_T(
104 Real pressure, Real temperature, Real & cv, Real & dcv_dp, Real & dcv_dT) const override;
105
106 virtual Real c_from_p_T(Real pressure, Real temperature) const override;
107 virtual void
108 c_from_p_T(Real pressure, Real temperature, Real & c, Real & dc_dp, Real & dc_dT) const override;
109
110 virtual Real k_from_p_T(Real pressure, Real temperature) const override;
111
112 virtual void
113 k_from_p_T(Real pressure, Real temperature, Real & k, Real & dk_dp, Real & dk_dT) const override;
114
115 virtual Real s_from_p_T(Real pressure, Real temperature) const override;
116
117 virtual void s_from_p_T(Real p, Real T, Real & s, Real & ds_dp, Real & ds_dT) const override;
118
123 virtual std::vector<Real> henryCoefficients() const override;
124
125 virtual Real vaporPressure(Real temperature) const override;
126
127 virtual void vaporPressure(Real temperature, Real & psat, Real & dpsat_dT) const override;
128
129 virtual Real vaporTemperature(Real pressure) const override;
130 virtual void vaporTemperature(Real pressure, Real & Tsat, Real & dTsat_dp) const override;
131
132 virtual Real T_from_p_h(Real pressure, Real enthalpy) const override;
133 virtual ADReal T_from_p_h(const ADReal & pressure, const ADReal & enthalpy) const override;
134
135 virtual Real triplePointPressure() const override;
136 virtual Real triplePointTemperature() const override;
137 virtual Real criticalPressure() const override;
138 virtual Real criticalTemperature() const override;
139 virtual Real criticalDensity() const override;
140
146 virtual Real p_from_v_e(Real v, Real e) const override;
147 virtual void p_from_v_e(Real v, Real e, Real & p, Real & dp_dv, Real & dp_de) const override;
148 virtual void p_from_v_e(const ADReal & v,
149 const ADReal & e,
150 ADReal & p,
151 ADReal & dp_dv,
152 ADReal & dp_de) const override;
153 virtual Real T_from_v_e(Real v, Real e) const override;
154 virtual void T_from_v_e(Real v, Real e, Real & T, Real & dT_dv, Real & dT_de) const override;
155 virtual void T_from_v_e(const ADReal & v,
156 const ADReal & e,
157 ADReal & p,
158 ADReal & dp_dv,
159 ADReal & dp_de) const override;
160 virtual Real c_from_v_e(Real v, Real e) const override;
161 virtual void c_from_v_e(Real v, Real e, Real & c, Real & dc_dv, Real & dc_de) const override;
162 virtual Real cp_from_v_e(Real v, Real e) const override;
163 virtual void cp_from_v_e(Real v, Real e, Real & cp, Real & dcp_dv, Real & dcp_de) const override;
164 virtual Real cv_from_v_e(Real v, Real e) const override;
165 virtual void cv_from_v_e(Real v, Real e, Real & cv, Real & dcv_dv, Real & dcv_de) const override;
166 virtual Real mu_from_v_e(Real v, Real e) const override;
167 virtual void mu_from_v_e(Real v, Real e, Real & mu, Real & dmu_dv, Real & dmu_de) const override;
168 virtual Real k_from_v_e(Real v, Real e) const override;
169 virtual void k_from_v_e(Real v, Real e, Real & k, Real & dk_dv, Real & dk_de) const override;
170 virtual Real g_from_v_e(Real v, Real e) const override;
171 virtual Real e_from_v_h(Real v, Real h) const override;
172 virtual void e_from_v_h(Real v, Real h, Real & e, Real & de_dv, Real & de_dh) const override;
173 virtual Real T_from_h_s(Real h, Real s) const;
174 virtual Real T_from_p_s(Real p, Real s) const;
175 virtual void T_from_p_s(Real p, Real s, Real & T, Real & dT_dp, Real & dT_ds) const;
176 virtual Real s_from_v_e(Real v, Real e) const override;
177 virtual void s_from_v_e(Real v, Real e, Real & s, Real & ds_dv, Real & ds_de) const override;
178 virtual Real s_from_h_p(Real h, Real pressure) const override;
179 virtual void
180 s_from_h_p(Real h, Real pressure, Real & s, Real & ds_dh, Real & ds_dp) const override;
181
183 using SinglePhaseFluidProperties::c_from_v_e;
184 using SinglePhaseFluidProperties::p_from_v_e;
185 using SinglePhaseFluidProperties::T_from_v_e;
186
187protected:
192 void writeTabulatedData(std::string file_name);
193
200 template <typename T>
201 void checkInputVariables(T & pressure, T & temperature) const;
202
209 template <typename T>
210 void checkInputVariablesVE(T & v, T & e) const;
211
217 virtual void checkInitialGuess(bool post_reading_tabulation) const;
218
220 void readFileTabulationData(bool use_pT);
221
226 void checkFileTabulationGrids(std::vector<Real> & v1,
227 std::vector<Real> & v2,
228 const std::string & file_name,
229 const std::string & v1_name,
230 const std::string & v2_name);
231
236 virtual void generateTabulatedData();
237
242 virtual void generateVETabulatedData();
243
246
252 void createVGridVector();
253 void createVEGridVectors();
260 void createVHGridVectors();
261
263 void missingVEInterpolationError(const std::string & function_name) const;
264
266 [[noreturn]] void TabulationNotImplementedError(const std::string & desired_routine) const;
269 [[noreturn]] void NeedTabulationOrFPError(const std::string & desired_routine,
270 const std::string & needed_property) const;
273 [[noreturn]] void NeedTabulationError(const std::string & needed_property) const;
274
284 const bool _save_file;
285
287 std::vector<Real> _pressure;
289 std::vector<Real> _temperature;
291 std::vector<Real> _specific_volume;
293 std::vector<Real> _internal_energy;
295 std::vector<Real> _enthalpy;
296
301
303 std::vector<std::vector<Real>> _properties;
305 std::vector<std::vector<Real>> _properties_ve;
306
308 std::vector<std::unique_ptr<BidimensionalInterpolation>> _property_ipol;
310 std::vector<std::unique_ptr<BidimensionalInterpolation>> _property_ve_ipol;
311
321 unsigned int _num_T;
323 unsigned int _num_p;
324
329
333 std::vector<std::string> _interpolated_properties;
346
348 unsigned int _density_idx;
349 unsigned int _enthalpy_idx;
351 unsigned int _viscosity_idx;
352 unsigned int _k_idx;
353 unsigned int _c_idx;
354 unsigned int _cp_idx;
355 unsigned int _cv_idx;
356 unsigned int _entropy_idx;
357 unsigned int _p_idx;
358 unsigned int _T_idx;
359
362
370 unsigned int _num_v;
372 unsigned int _num_e;
379
391
393 std::unique_ptr<BidimensionalInterpolation> _T_from_v_e_ipol;
394
396 std::unique_ptr<BidimensionalInterpolation> _p_from_v_e_ipol;
397
399 std::unique_ptr<BidimensionalInterpolation> _T_from_v_h_ipol;
400
402 std::unique_ptr<BidimensionalInterpolation> _p_from_v_h_ipol;
403
409 Real _e_min;
411 Real _e_max;
413 Real _v_min;
415 Real _v_max;
417 Real _h_min;
419 Real _h_max;
420};
421
422#pragma GCC diagnostic pop
DualNumber< Real, DNDerivativeType, true > ADReal
const double mu
const InputParameters & parameters() const
Common class for single phase fluid properties.
e e e e s T T T T T rho v v T e h
Class for fluid properties read from a tabulation in a file.
FileName _file_name_out
File name of output tabulated data file.
std::unique_ptr< BidimensionalInterpolation > _T_from_v_e_ipol
Bi-dimensional interpolation of temperature from (v,e)
virtual Real v_from_p_T(Real pressure, Real temperature) const override
unsigned int _num_T
Number of temperature points in the tabulated data.
const bool _save_file
Whether to save a generated fluid properties file to disk.
bool _initial_setup_done
keeps track of whether initialSetup has been performed
const SinglePhaseFluidProperties *const _fp
SinglePhaseFluidPropertiesPT UserObject.
FileName _file_name_ve_out
File name of output (v,e) tabulated data file.
std::vector< std::string > _interpolated_properties
List of properties to be interpolated.
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...
std::vector< Real > _internal_energy
Specific internal energy vector.
void readFileTabulationData(bool use_pT)
Read tabulation data from file.
Real _v_min
Minimum specific volume in tabulated data (can be user-specified)
virtual Real s_from_v_e(Real v, Real e) const override
virtual Real triplePointTemperature() const override
Triple point temperature.
std::vector< std::vector< Real > > _properties_ve
Tabulated fluid properties in (v,e) (read from file OR computed from _fp)
void computePropertyIndicesInInterpolationVectors()
Retrieves the index for each property in the vector of interpolations.
virtual Real e_from_v_h(Real v, Real h) const override
unsigned int _num_v
Number of specific volume points in the tabulated data.
Real _v_max
Maximum specific volume in tabulated data (can be user-specified)
Real _h_min
Minimum specific enthalpy in tabulated data.
FileName _file_name_ve_in
File name of input (v,e) tabulated data file.
virtual Real T_from_p_h(Real pressure, Real enthalpy) const override
void missingVEInterpolationError(const std::string &function_name) const
Standardized error message for missing interpolation.
virtual void constructInterpolation()=0
virtual Real rho_from_p_s(Real p, Real s) const override
std::vector< Real > _temperature
Temperature vector.
const bool _create_direct_ve_interpolations
Whether the object has direct (v,e) interpolations (whether created from file or from _fp)
virtual Real g_from_v_e(Real v, Real e) const override
void writeTabulatedData(std::string file_name)
Writes tabulated data to a file.
void NeedTabulationError(const std::string &needed_property) const
Utility to forward errors related to properties being requested for tabulation, but no tabulation is ...
virtual void generateTabulatedData()
Generates a table of fluid properties by looping over pressure and temperature and calculating proper...
virtual Real cp_from_p_T(Real pressure, Real temperature) const override
std::unique_ptr< BidimensionalInterpolation > _p_from_v_h_ipol
Bidimensional interpolation of pressure from (v,h)
virtual void generateVETabulatedData()
Generates a table of fluid properties by looping over specific volume and internal energy and calcula...
Real _temperature_max
Maximum temperature in tabulated data.
static InputParameters validParams()
Real _e_min
Minimum internal energy in tabulated data (can be user-specified)
virtual Real T_from_p_rho(Real pressure, Real rho) const
const bool _create_direct_pT_interpolations
Whether the object has direct (p,T) interpolations (whether created from file or from _fp)
Real _e_max
Maximum internal energy in tabulated data (can be user-specified)
virtual Real triplePointPressure() const override
Triple point pressure.
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)
std::vector< Real > _enthalpy
Specific enthalpy vector.
virtual Real cp_from_v_e(Real v, Real e) const override
void TabulationNotImplementedError(const std::string &desired_routine) const
Utility to forward errors related to fluid properties methods not implemented.
virtual Real cv_from_v_e(Real v, Real e) const override
void createVHGridVectors()
Create (or reset) the grid vectors for the specific volume and enthalpy interpolation The order of pr...
virtual Real T_from_h_s(Real h, Real s) const
bool _log_space_v
log-space the specific volume interpolation grid axis instead of linear
unsigned int _num_p
Number of pressure points in the tabulated data.
OOBBehavior
Enum specifying all the behavior on out of bounds data options.
MooseUtils::DelimitedFileReader _csv_reader
The MOOSE delimited file reader.
FileName _file_name_in
File name of input tabulated data file.
bool _v_bounds_specified
Whether the specific volume bounds were set by the user.
std::vector< std::unique_ptr< BidimensionalInterpolation > > _property_ve_ipol
Vector of bi-dimensional interpolation of fluid properties directly in (v,e)
bool _construct_pT_from_vh
if the lookup table p(v, h) and T(v, h) should be constructed
virtual void checkInitialGuess(bool post_reading_tabulation) const
Checks initial guess for Newton Method.
MultiMooseEnum _interpolated_properties_enum
Properties to be interpolated entered in the input file.
std::unique_ptr< BidimensionalInterpolation > _p_from_v_e_ipol
Bi-dimensional interpolation of pressure from (v,e)
void createVGridVector()
Create (or reset) the grid vectors for the specific volume and internal energy interpolations The ord...
virtual Real criticalTemperature() const override
Critical temperature.
virtual Real h_from_p_T(Real p, Real T) const override
unsigned int _num_e
Number of internal energy points in tabulated data.
void NeedTabulationOrFPError(const std::string &desired_routine, const std::string &needed_property) const
Utility to forward errors related to fluid properties needing more data for their computation This sh...
std::vector< Real > _specific_volume
Specific volume vector.
virtual Real rho_from_p_T(Real pressure, Real temperature) const override
virtual void initialSetup() override
virtual Real e_from_p_rho(Real pressure, Real rho) const override
virtual Real cv_from_p_T(Real pressure, Real temperature) const override
MooseEnum _OOBBehavior
User-selected out-of-bounds behavior.
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 *...
bool _log_space_e
log-space the internal energy interpolation grid axis instead of linear
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...
virtual Real mu_from_p_T(Real pressure, Real temperature) const override
virtual Real mu_from_v_e(Real v, Real e) const override
virtual Real k_from_p_T(Real pressure, Real temperature) const override
virtual std::vector< Real > henryCoefficients() const override
The following routines are simply forwarded to the 'fp' companion FluidProperties as they are not inc...
virtual Real T_from_p_s(Real p, Real s) const
virtual Real s_from_h_p(Real h, Real pressure) const override
virtual Real vaporTemperature(Real pressure) const override
Vapor temperature.
Real _pressure_max
Maximum pressure in tabulated data.
virtual Real vaporPressure(Real temperature) const override
Vapor pressure.
Real _h_max
Maximum specific enthalpy in tabulated data.
std::vector< std::unique_ptr< BidimensionalInterpolation > > _property_ipol
Vector of bi-dimensional interpolation of fluid properties.
virtual Real criticalDensity() const override
Critical density.
virtual Real molarMass() const override
Molar mass [kg/mol].
virtual Real T_from_v_e(Real v, Real e) const override
unsigned int _density_idx
Index of each property.
virtual Real k_from_v_e(Real v, Real e) const override
std::unique_ptr< BidimensionalInterpolation > _T_from_v_h_ipol
Bi-dimensional interpolation of temperature from (v,h)
virtual Real s_from_p_T(Real pressure, Real temperature) const override
Real _temperature_min
Minimum temperature in tabulated data.
virtual std::string fluidName() const override
Fluid name.
Real _pressure_min
Minimum pressure in tabulated data.
const bool _allow_fp_and_tabulation
Whether to allow a fp object when a tabulation is in use.
virtual Real c_from_v_e(Real v, Real e) const override
std::vector< std::vector< Real > > _properties
Tabulated fluid properties (read from file OR computed from _fp)
bool _construct_pT_from_ve
if the lookup table p(v, e) and T(v, e) should be constructed
std::vector< Real > _pressure
Pressure vector.
bool _log_space_h
log-space the enthalpy interpolation grid axis instead of linear
bool _e_bounds_specified
Whether the specific internal energy bounds were set by the user.
virtual Real e_from_p_T(Real pressure, Real temperature) const override
virtual Real c_from_p_T(Real pressure, Real temperature) const override
bool _interpolate_density
Set of flags to note whether a property is to be interpolated.
virtual Real criticalPressure() const override
Critical pressure.