Skip to content

Commit

Permalink
Merge pull request #28021 from GiudGiud/PR_loge
Browse files Browse the repository at this point in the history
Facilitate use of TFPs with (v,e) variable set
  • Loading branch information
GiudGiud authored Jul 5, 2024
2 parents 10c4f77 + 812f01e commit a419bff
Show file tree
Hide file tree
Showing 22 changed files with 535 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ With a (specific volume, specific energy) variable set, the syntax shown in the

### Writing data file

If no tabulated fluid property data file exists, then data for the properties specified in the
input file parameter *interpolated_properties* will be generated using the pressure and temperature
The `TabulatedFluidProperties`-derived classes can write a file containing the data for the properties specified in the
input file parameter *interpolated_properties*. It will use the pressure and temperature
ranges specified in the input file at the beginning of the simulation.

For example, if we wish to generate a file containing tabulated properties for CO$_2$ density, enthalpy
Expand All @@ -106,7 +106,7 @@ divided into 50 and 100 equal points, respectively, then the input file syntax n
[tabulated]
type = TabulatedBicubicFluidProperties
fp = co2
fluid_property_file = fluid_properties.csv
fluid_property_output_file = fluid_properties.csv
interpolated_properties = 'density enthalpy viscosity'
# Bounds of interpolation
Expand All @@ -131,6 +131,11 @@ times the property members in the FluidProperties object are used, the initial t
the data and the subsequent interpolation time can be much less than using the original
FluidProperties object.

Using the [!param](/FluidProperties/TabulatedFluidProperties/construct_pT_from_ve) parameter and the
[!param](/FluidProperties/TabulatedFluidProperties/fluid_property_output_file) parameters, a tabulation
using the (specific volume, specific internal energy) variables can be generated. The output file name
for this additional tabulation will be suffixed with `_ve.csv`.

!alert note
All fluid properties read from a file or specified in the input file (and their derivatives with
respect to pressure and temperature) will be calculated through interpolation, while all
Expand Down Expand Up @@ -179,6 +184,7 @@ alternative variable sets. This is done in several sets, described for the $(v,e
the specified bounds on pressure and temperature : $e_{min/max} = e(p_{min/max}, T_{min/max})$, else the bounds
are chosen from the tabulated data. The number of points in the grid in both dimensions are user-selected parameters.
The v grid may be created using base-10 log-spacing by setting [!param](/FluidProperties/TabulatedFluidProperties/use_log_grid_v).
The e grid may be created using base-10 log-spacing by setting [!param](/FluidProperties/TabulatedFluidProperties/use_log_grid_e).

- These bounds may not be physically realizable simultaneously. It could be that the fluid may not have both $v=v_{min}$
and $e=e_{min}$. Part of the grid may not be physical.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ class TabulatedFluidProperties : public SinglePhaseFluidProperties
*/
virtual void generateTabulatedData();

/// File name of tabulated data file
FileName _file_name;
/// File name of input tabulated data file
FileName _file_name_in;
/// File name of output tabulated data file
FileName _file_name_out;
/// Pressure vector
std::vector<Real> _pressure;
/// Temperature vector
Expand Down Expand Up @@ -199,6 +201,8 @@ class TabulatedFluidProperties : public SinglePhaseFluidProperties

/// SinglePhaseFluidPropertiesPT UserObject
const SinglePhaseFluidProperties * const _fp;
/// Whether to allow a fp object when a tabulation is in use
const bool _allow_fp_and_tabulation;

/// List of required column names to be read
const std::vector<std::string> _required_columns{"pressure", "temperature"};
Expand Down Expand Up @@ -246,8 +250,10 @@ class TabulatedFluidProperties : public SinglePhaseFluidProperties
unsigned int _num_e;
/// to error or not on out-of-bounds check
bool _error_on_out_of_bounds;
/// log-space the specific volume instead of linear
/// log-space the specific volume interpolation grid axis instead of linear
bool _log_space_v;
/// log-space the internal energy interpolation grid axis instead of linear
bool _log_space_e;

/// Bi-dimensional interpolation of temperature from (v,e)
std::unique_ptr<BidimensionalInterpolation> _T_from_v_e_ipol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,28 @@ TabulatedBicubicFluidProperties::constructInterpolation()
_e_min = *min_element(_properties[_internal_energy_idx].begin(),
_properties[_internal_energy_idx].end());
}
Real de = (_e_max - _e_min) / ((Real)_num_e - 1);

// Create e grid for interpolation
_internal_energy.resize(_num_e);
for (unsigned int j = 0; j < _num_e; ++j)
_internal_energy[j] = _e_min + j * de;
if (_log_space_e)
{
// incrementing the exponent linearly will yield a log-spaced grid after taking the value to
// the power of 10
if (_e_min < 0)
mooseError("Logarithmic grid in specific energy can only be used with a positive specific "
"energy. Current minimum: " +
std::to_string(_e_min));
Real de = (std::log10(_e_max) - std::log10(_e_min)) / ((Real)_num_e - 1);
Real log_e_min = std::log10(_e_min);
for (const auto j : make_range(_num_e))
_internal_energy[j] = std::pow(10, log_e_min + j * de);
}
else
{
Real de = (_e_max - _e_min) / ((Real)_num_e - 1);
for (const auto j : make_range(_num_e))
_internal_energy[j] = _e_min + j * de;
}

// initialize vectors for interpolation
std::vector<std::vector<Real>> p_from_v_e(_num_v);
Expand Down Expand Up @@ -404,13 +420,15 @@ TabulatedBicubicFluidProperties::outputWarnings(unsigned int num_nans_p,
std::string T_nans = "- " + std::to_string(num_nans_T) + " nans generated out of " +
std::to_string(number_points) + " points for temperature\n";
std::string p_oob = "- " + std::to_string(num_out_bounds_p) + " of " +
std::to_string(number_points) +
" pressure values were out of user defined bounds\n";
std::to_string(number_points) + " pressure values were out of bounds\n";
std::string T_oob = "- " + std::to_string(num_out_bounds_T) + " of " +
std::to_string(number_points) +
" temperature values were out of user defined bounds\n";
std::to_string(number_points) + " temperature values were out of bounds\n";
std::string outcome = "The pressure and temperature values were replaced with their respective "
"user-defined min and max values.\n";
"min and max values.\n";

// bounds are different depending on how the object is used
std::string source = (_fp ? "from input parameters" : "from tabulation file");

// if any of these do not exist, do not want to print them
if (convergence_failures)
warning_message += converge_fails;
Expand All @@ -419,9 +437,17 @@ TabulatedBicubicFluidProperties::outputWarnings(unsigned int num_nans_p,
if (num_nans_T)
warning_message += T_nans;
if (num_out_bounds_p)
{
warning_message += p_oob;
warning_message += ("Pressure bounds " + source + ": [" + std::to_string(_pressure_min) + ", " +
std::to_string(_pressure_max) + "]\n");
}
if (num_out_bounds_T)
{
warning_message += T_oob;
warning_message += ("Temperature bounds " + source + ": [" + std::to_string(_temperature_min) +
", " + std::to_string(_temperature_max) + "]\n");
}
// print warning
if (num_nans_p || num_nans_T || num_out_bounds_p || num_out_bounds_T || convergence_failures)
mooseWarning(warning_message + outcome);
Expand Down
Loading

0 comments on commit a419bff

Please sign in to comment.