11 #include "BicubicInterpolation.h"
12 #include "MooseUtils.h"
13 #include "Conversion.h"
26 params.addParam<FileName>(
27 "fluid_property_file",
28 "fluid_properties.csv",
29 "Name of the csv file containing the tabulated fluid property data. If "
30 "no file exists and save_file = true, then one will be written to "
31 "fluid_properties.csv using the temperature and pressure range specified.");
32 params.addRangeCheckedParam<Real>(
"temperature_min",
34 "temperature_min > 0",
35 "Minimum temperature for tabulated data. Default is 300 K)");
36 params.addParam<Real>(
37 "temperature_max", 500.0,
"Maximum temperature for tabulated data. Default is 500 K");
38 params.addRangeCheckedParam<Real>(
"pressure_min",
41 "Minimum pressure for tabulated data. Default is 0.1 MPa)");
42 params.addParam<Real>(
43 "pressure_max", 50.0e6,
"Maximum pressure for tabulated data. Default is 50 MPa");
44 params.addRangeCheckedParam<
unsigned int>(
45 "num_T", 100,
"num_T > 0",
"Number of points to divide temperature range. Default is 100");
46 params.addRangeCheckedParam<
unsigned int>(
47 "num_p", 100,
"num_p > 0",
"Number of points to divide pressure range. Default is 100");
48 params.addRequiredParam<UserObjectName>(
"fp",
"The name of the FluidProperties UserObject");
49 MultiMooseEnum properties(
"density enthalpy internal_energy viscosity k cv cp entropy",
50 "density enthalpy internal_energy viscosity");
51 params.addParam<MultiMooseEnum>(
"interpolated_properties",
53 "Properties to interpolate if no data file is provided");
54 params.addParam<
bool>(
"save_file",
true,
"Whether to save the csv fluid properties file");
55 params.addClassDescription(
56 "Fluid properties using bicubic interpolation on tabulated values provided");
62 _file_name(getParam<FileName>(
"fluid_property_file")),
63 _temperature_min(getParam<Real>(
"temperature_min")),
64 _temperature_max(getParam<Real>(
"temperature_max")),
65 _pressure_min(getParam<Real>(
"pressure_min")),
66 _pressure_max(getParam<Real>(
"pressure_max")),
67 _num_T(getParam<unsigned int>(
"num_T")),
68 _num_p(getParam<unsigned int>(
"num_p")),
69 _save_file(getParam<bool>(
"save_file")),
71 _interpolated_properties_enum(getParam<MultiMooseEnum>(
"interpolated_properties")),
72 _interpolated_properties(),
73 _interpolate_density(false),
74 _interpolate_enthalpy(false),
75 _interpolate_internal_energy(false),
76 _interpolate_viscosity(false),
77 _interpolate_k(false),
78 _interpolate_cp(false),
79 _interpolate_cv(false),
80 _interpolate_entropy(false),
83 _internal_energy_idx(0),
89 _csv_reader(_file_name, &_communicator)
93 mooseError(
name(),
": temperature_max must be greater than temperature_min");
95 mooseError(
name(),
": pressure_max must be greater than pressure_min");
112 _console <<
name() +
": Reading tabulated properties from " <<
_file_name <<
"\n";
115 const std::vector<std::string> & column_names =
_csv_reader.getNames();
134 for (std::size_t i = 0; i < column_names.size(); ++i)
147 " is not one of the properties that TabulatedFluidProperties understands");
153 std::map<std::string, unsigned int> data_index;
154 for (std::size_t i = 0; i < column_names.size(); ++i)
156 auto it = std::find(column_names.begin(), column_names.end(), column_names[i]);
157 data_index[column_names[i]] = std::distance(column_names.begin(), it);
160 const std::vector<std::vector<Real>> & column_data =
_csv_reader.getData();
163 _pressure = column_data[data_index.find(
"pressure")->second];
164 _temperature = column_data[data_index.find(
"temperature")->second];
170 name(),
": the column data for pressure is not monotonically increasing in ",
_file_name);
182 if (column_data[0].size() !=
_num_p * static_cast<unsigned int>(num_T))
184 ": the number of rows in ",
186 " is not equal to the number of unique pressure values ",
188 " multiplied by the number of unique temperature values ",
194 if (!std::is_sorted(temp0.begin(), temp0.end()))
196 ": the column data for temperature is not monotonically increasing in ",
200 for (std::size_t i = 1; i <
_pressure.size(); ++i)
202 std::vector<Real> temp(it_temp, it_temp + num_T);
205 ": temperature values for pressure ",
207 " are not identical to values for ",
210 std::advance(it_temp, num_T);
231 _console <<
name() +
": No tabulated properties file named " <<
_file_name <<
" exists.\n";
232 _console <<
name() +
": Generating tabulated data\n";
235 _console <<
name() +
": Writing tabulated data to " <<
_file_name <<
"\n";
292 std::vector<std::vector<Real>> data_matrix;
306 return _fp.fluidName();
490 SinglePhaseFluidProperties::s_from_p_T(
p,
T, s, ds_dp, ds_dT);
514 if (processor_id() == 0)
516 MooseUtils::checkFileWriteable(file_name);
518 std::ofstream file_out(file_name.c_str());
521 time_t now = time(&now);
522 file_out <<
"# " <<
_fp.fluidName() <<
" properties created by TabulatedFluidProperties on "
523 << ctime(&now) <<
"\n";
526 file_out <<
"pressure, temperature";
532 for (
unsigned int p = 0;
p <
_num_p; ++
p)
533 for (
unsigned int t = 0; t <
_num_T; ++t)
536 for (std::size_t i = 0; i <
_properties.size(); ++i)
556 for (std::size_t i = 0; i <
_properties.size(); ++i)
562 for (
unsigned int j = 0; j <
_num_T; ++j)
568 for (
unsigned int i = 0; i <
_num_p; ++i)
572 for (std::size_t i = 0; i <
_properties.size(); ++i)
575 for (
unsigned int p = 0;
p <
_num_p; ++
p)
576 for (
unsigned int t = 0; t <
_num_T; ++t)
580 for (
unsigned int p = 0;
p <
_num_p; ++
p)
581 for (
unsigned int t = 0; t <
_num_T; ++t)
585 for (
unsigned int p = 0;
p <
_num_p; ++
p)
586 for (
unsigned int t = 0; t <
_num_T; ++t)
590 for (
unsigned int p = 0;
p <
_num_p; ++
p)
591 for (
unsigned int t = 0; t <
_num_T; ++t)
595 for (
unsigned int p = 0;
p <
_num_p; ++
p)
596 for (
unsigned int t = 0; t <
_num_T; ++t)
600 for (
unsigned int p = 0;
p <
_num_p; ++
p)
601 for (
unsigned int t = 0; t <
_num_T; ++t)
605 for (
unsigned int p = 0;
p <
_num_p; ++
p)
606 for (
unsigned int t = 0; t <
_num_T; ++t)
610 for (
unsigned int p = 0;
p <
_num_p; ++
p)
611 for (
unsigned int t = 0; t <
_num_T; ++t)
619 const std::vector<Real> & vec,
620 std::vector<std::vector<Real>> & mat)
625 for (
unsigned int i = 0; i < nrow; ++i)
628 for (
unsigned int i = 0; i < nrow; ++i)
629 for (
unsigned int j = 0; j < ncol; ++j)
630 mat[i][j] = vec[i * ncol + j];
638 throw MooseException(
639 "Pressure " + Moose::stringify(
pressure) +
" is outside the range of tabulated pressure (" +
643 throw MooseException(
"Temperature " + Moose::stringify(
temperature) +
644 " is outside the range of tabulated temperature (" +