23 InputParameters params = validParams<GeneralUserObject>();
24 params.addRequiredParam<UserObjectName>(
"fp",
25 "The name of the fluid properties object to query.");
26 params.addParam<
bool>(
"json",
false,
"Output in JSON format");
27 params.addParam<Real>(
"rho",
"Density");
28 params.addParam<Real>(
"rhou",
"Momentum density; rho * u");
29 params.addParam<Real>(
"rhoE",
"Total energy density; rho * E");
30 params.addParam<Real>(
"e",
"Specific internal energy");
31 params.addParam<Real>(
"p",
"Pressure");
32 params.addParam<Real>(
"T",
"Temperature");
33 params.addParam<Real>(
"vel",
"Velocity");
34 params.addParam<std::vector<Real>>(
"x_ncg",
"Mass fractions of NCGs");
35 params.addRequiredParam<
unsigned int>(
"precision",
"Precision for printing values");
37 params.addClassDescription(
38 "User object for querying a single-phase or two-phase fluid properties object");
44 : GeneralUserObject(parameters),
45 _json(getParam<bool>(
"json")),
50 _has_1phase(_fp_1phase),
52 _has_2phase(_fp_2phase),
53 _has_2phase_ncg(_fp_2phase_ncg),
54 _fp_liquid(_has_2phase
60 _fp_vapor_mixture(_has_vapor_mixture
63 _fp_2phase_ncg->getVaporMixtureName())
65 _nan_encountered(false),
66 _precision(getParam<unsigned int>(
"precision"))
70 "The type of the parameter 'fp' must be derived from type 'SinglePhaseFluidProperties', "
71 "'VaporMixtureFluidProperties', or 'TwoPhaseFluidProperties'.");
90 moosecontrib::Json::Value json;
92 auto & json_2phase = json[
"2-phase"];
94 auto & json_liquid = json[
"liquid"];
96 auto & json_mixture = json[
"vapor-mixture"];
99 Moose::out <<
"**START JSON DATA**\n";
100 Moose::out << json <<
"\n";
101 Moose::out <<
"**END JSON DATA**\n";
118 moosecontrib::Json::Value json;
120 auto & json_2phase = json[
"2-phase"];
122 if (pars_liquid.have_parameter<
bool>(
"specified"))
124 auto & json_liquid = json[
"liquid"];
127 if (pars_vapor.have_parameter<
bool>(
"specified"))
129 auto & json_vapor = json[
"vapor"];
133 Moose::out <<
"**START JSON DATA**\n";
134 Moose::out << json <<
"\n";
135 Moose::out <<
"**END JSON DATA**\n";
140 if (pars_liquid.have_parameter<
bool>(
"specified"))
142 if (pars_vapor.have_parameter<
bool>(
"specified"))
151 moosecontrib::Json::Value json;
154 Moose::out <<
"**START JSON DATA**\n";
155 Moose::out << json <<
"\n";
156 Moose::out <<
"**END JSON DATA**\n";
167 moosecontrib::Json::Value json;
171 Moose::out <<
"**START JSON DATA**\n";
172 Moose::out << json <<
"\n";
173 Moose::out <<
"**END JSON DATA**\n";
187 bool throw_error_if_no_match)
189 InputParameters params = emptyInputParameters();
195 std::vector<std::vector<std::string>> parameter_sets = {{
"p",
"T"}, {
"rho",
"e"}, {
"rho",
"p"}};
197 parameter_sets.push_back({
"rho",
"rhou",
"rhoE"});
198 auto specified =
getSpecifiedSetMap(parameter_sets,
"one-phase", throw_error_if_no_match);
202 Real rho, e, p, T, vel = 0;
203 bool specified_a_set =
false;
204 if (specified[
"rho,e"])
206 rho = getParam<Real>(
"rho");
207 e = getParam<Real>(
"e");
208 const Real v = 1.0 / rho;
209 p = fp_1phase->p_from_v_e(v, e);
210 T = fp_1phase->T_from_v_e(v, e);
211 if (isParamValid(
"vel"))
212 vel = getParam<Real>(
"vel");
214 specified_a_set =
true;
216 else if (specified[
"rho,p"])
218 rho = getParam<Real>(
"rho");
219 p = getParam<Real>(
"p");
220 const Real v = 1.0 / rho;
221 e = fp_1phase->e_from_p_rho(p, rho);
222 T = fp_1phase->T_from_v_e(v, e);
223 if (isParamValid(
"vel"))
224 vel = getParam<Real>(
"vel");
226 specified_a_set =
true;
228 else if (specified[
"p,T"])
230 p = getParam<Real>(
"p");
231 T = getParam<Real>(
"T");
232 rho = fp_1phase->rho_from_p_T(p, T);
233 e = fp_1phase->e_from_p_rho(p, rho);
234 if (isParamValid(
"vel"))
235 vel = getParam<Real>(
"vel");
237 specified_a_set =
true;
239 else if (specified[
"rho,rhou,rhoE"])
241 rho = getParam<Real>(
"rho");
242 const Real rhou = getParam<Real>(
"rhou");
243 const Real rhoE = getParam<Real>(
"rhoE");
246 const Real E = rhoE / rho;
247 e = E - 0.5 * vel * vel;
249 const Real v = 1.0 / rho;
250 p = fp_1phase->p_from_v_e(v, e);
251 T = fp_1phase->T_from_v_e(v, e);
253 specified_a_set =
true;
258 params.set<
bool>(
"specified") =
true;
260 const Real v = 1.0 / rho;
262 params.set<Real>(
"rho") = rho;
263 params.set<Real>(
"e") = e;
264 params.set<Real>(
"p") = p;
265 params.set<Real>(
"T") = T;
266 params.set<Real>(
"v") = v;
267 params.set<Real>(
"h") = fp_1phase->h_from_p_T(p, T);
268 params.set<Real>(
"s") = fp_1phase->s_from_v_e(v, e);
269 params.set<Real>(
"c") = fp_1phase->c_from_v_e(v, e);
270 params.set<Real>(
"mu") = fp_1phase->mu_from_v_e(v, e);
271 params.set<Real>(
"cp") = fp_1phase->cp_from_v_e(v, e);
272 params.set<Real>(
"cv") = fp_1phase->cv_from_v_e(v, e);
273 params.set<Real>(
"k") = fp_1phase->k_from_v_e(v, e);
274 params.set<Real>(
"beta") = fp_1phase->beta_from_p_T(p, T);
276 if (isParamValid(
"vel") || specified[
"rho,rhou,rhoE"])
278 const Real s = fp_1phase->s_from_v_e(v, e);
280 const Real h = fp_1phase->h_from_p_T(p, T);
281 const Real h0 = h + 0.5 * vel * vel;
282 const Real p0 = fp_1phase->p_from_h_s(h0, s0);
283 const Real rho0 = fp_1phase->rho_from_p_s(p0, s0);
284 const Real e0 = fp_1phase->e_from_p_rho(p0, rho0);
285 const Real v0 = 1.0 / rho0;
286 const Real T0 = fp_1phase->T_from_v_e(v0, e0);
287 const Real c0 = fp_1phase->c_from_v_e(v0, e0);
288 const Real mu0 = fp_1phase->mu_from_v_e(v0, e0);
289 const Real cp0 = fp_1phase->cp_from_v_e(v0, e0);
290 const Real cv0 = fp_1phase->cv_from_v_e(v0, e0);
291 const Real k0 = fp_1phase->k_from_v_e(v0, e0);
292 const Real beta0 = fp_1phase->beta_from_p_T(p0, T0);
294 params.set<Real>(
"vel") = vel;
295 params.set<Real>(
"rho0") = rho0;
296 params.set<Real>(
"s0") = s0;
297 params.set<Real>(
"v0") = v0;
298 params.set<Real>(
"e0") = e0;
299 params.set<Real>(
"h0") = h0;
300 params.set<Real>(
"p0") = p0;
301 params.set<Real>(
"T0") = T0;
302 params.set<Real>(
"c0") = c0;
303 params.set<Real>(
"mu0") = mu0;
304 params.set<Real>(
"cp0") = cp0;
305 params.set<Real>(
"cv0") = cv0;
306 params.set<Real>(
"k0") = k0;
307 params.set<Real>(
"beta0") = beta0;
313 "At least one NaN was encountered. This implies one of the following:\n",
314 " 1. The specified thermodynamic state is inconsistent with the equation of state\n",
315 " (for example, the state corresponds to a different phase of the fluid).\n",
316 " 2. There is a problem with the equation of state package at this state\n",
317 " (for example, the supplied state is outside of the valid state space\n",
318 " that was programmed in the package).");
327 InputParameters params = emptyInputParameters();
333 std::vector<std::vector<std::string>> parameter_sets = {{
"p",
"T"}, {
"p"}, {
"T"}};
337 params.set<Real>(
"p_critical") = p_critical;
340 const Real p = getParam<Real>(
"p");
344 params.set<Real>(
"p") = p;
345 params.set<Real>(
"T_sat") = T_sat;
346 params.set<Real>(
"h_lat") = h_lat;
348 else if (specified[
"T"])
350 const Real T = getParam<Real>(
"T");
355 params.set<Real>(
"T") = T;
356 params.set<Real>(
"p_sat") = p_sat;
357 params.set<Real>(
"h_lat") = h_lat;
358 params.set<Real>(
"sigma") = sigma;
360 else if (specified[
"p,T"])
362 const Real p = getParam<Real>(
"p");
363 const Real T = getParam<Real>(
"T");
366 params.set<Real>(
"p") = p;
367 params.set<Real>(
"T") = T;
368 params.set<Real>(
"h_lat") = h_lat;
373 mooseWarning(
"At least one NaN was encountered.");
381 InputParameters params = emptyInputParameters();
387 std::vector<std::vector<std::string>> parameter_sets = {
388 {
"p",
"T",
"x_ncg"}, {
"rho",
"e",
"x_ncg"}, {
"rho",
"rhou",
"rhoE",
"x_ncg"}};
389 auto specified =
getSpecifiedSetMap(parameter_sets,
"vapor mixture", throw_error_if_no_match);
391 const auto x_ncg = getParam<std::vector<Real>>(
"x_ncg");
395 Real rho, e, p, T, vel = 0;
396 bool specified_a_set =
false;
397 if (specified[
"rho,e,x_ncg"])
399 rho = getParam<Real>(
"rho");
400 e = getParam<Real>(
"e");
401 const Real v = 1.0 / rho;
404 if (isParamValid(
"vel"))
405 vel = getParam<Real>(
"vel");
407 specified_a_set =
true;
409 else if (specified[
"p,T,x_ncg"])
411 p = getParam<Real>(
"p");
412 T = getParam<Real>(
"T");
415 if (isParamValid(
"vel"))
416 vel = getParam<Real>(
"vel");
418 specified_a_set =
true;
420 else if (specified[
"rho,rhou,rhoE,x_ncg"])
422 rho = getParam<Real>(
"rho");
423 const Real rhou = getParam<Real>(
"rhou");
424 const Real rhoE = getParam<Real>(
"rhoE");
427 const Real E = rhoE / rho;
428 e = E - 0.5 * vel * vel;
430 const Real v = 1.0 / rho;
434 specified_a_set =
true;
439 params.set<
bool>(
"specified") =
true;
441 const Real v = 1.0 / rho;
442 const Real h = e + p / rho;
449 params.set<Real>(
"p") = p;
450 params.set<Real>(
"T") = T;
451 params.set<Real>(
"rho") = rho;
452 params.set<Real>(
"e") = e;
453 params.set<Real>(
"v") = v;
454 params.set<Real>(
"h") = h;
455 params.set<Real>(
"c") = c;
456 params.set<Real>(
"mu") = mu;
457 params.set<Real>(
"cp") = cp;
458 params.set<Real>(
"cv") = cv;
459 params.set<Real>(
"k") = k;
461 if (isParamValid(
"vel") || specified[
"rho,rhou,rhoE,x_ncg"])
463 const Real h = e + p / rho;
464 const Real h0 = h + 0.5 * vel * vel;
466 params.set<Real>(
"h0") = h0;
472 "At least one NaN was encountered. This implies one of the following:\n",
473 " 1. The specified thermodynamic state is inconsistent with the equation of state\n",
474 " (for example, the state corresponds to a different phase of the fluid).\n",
475 " 2. There is a problem with the equation of state package at this state\n",
476 " (for example, the supplied state is outside of the valid state space\n",
477 " that was programmed in the package).");
485 const InputParameters & params)
487 for (
auto p : {
"rho",
"e",
"p",
"T",
"v",
"h",
"s",
"c",
"mu",
"cp",
"cv",
"k",
"beta"})
488 json[
"static"][p] = params.get<Real>(p);
490 if (params.have_parameter<Real>(
"vel"))
491 for (
auto p : {
"vel",
505 json[
"stagnation"][p] = params.get<Real>(p);
510 const InputParameters & params)
512 json[
"p_critical"] = params.get<Real>(
"p_critical");
513 for (
auto p : {
"T_sat",
"p_sat",
"h_lat",
"sigma"})
514 if (params.have_parameter<Real>(p))
515 json[p] = params.get<Real>(p);
520 const InputParameters & params)
522 for (
auto p : {
"p",
"T",
"rho",
"e",
"v",
"h",
"c",
"mu",
"cp",
"cv",
"k"})
523 if (params.have_parameter<Real>(p))
524 json[
"static"][p] = params.get<Real>(p);
526 if (params.have_parameter<Real>(
"vel"))
527 json[
"stagnation"][
"h0"] = params.get<Real>(
"h0");
532 const InputParameters & params)
539 if (params.have_parameter<Real>(
"vel"))
550 outputProperty(
"Critical pressure", params.get<Real>(
"p_critical"),
"Pa");
551 if (params.have_parameter<Real>(
"T_sat"))
552 outputProperty(
"Saturation temperature", params.get<Real>(
"T_sat"),
"K");
553 if (params.have_parameter<Real>(
"p_sat"))
554 outputProperty(
"Saturation pressure", params.get<Real>(
"p_sat"),
"Pa");
555 if (params.have_parameter<Real>(
"h_lat"))
556 outputProperty(
"Latent heat of vaporization", params.get<Real>(
"h_lat"),
"J/kg");
557 if (params.have_parameter<Real>(
"sigma"))
558 outputProperty(
"Surface tension", params.get<Real>(
"sigma"),
"N/m");
559 _console << std::endl;
570 if (params.have_parameter<Real>(
"vel"))
577 std::map<std::string, bool>
579 const std::vector<std::vector<std::string>> & parameter_sets,
580 const std::string & fp_type,
581 bool throw_error_if_no_match)
const
584 std::vector<std::string> parameter_union;
585 for (
auto & parameter_set : parameter_sets)
586 parameter_union.insert(parameter_union.end(), parameter_set.begin(), parameter_set.end());
587 std::sort(parameter_union.begin(), parameter_union.end());
588 parameter_union.erase(std::unique(parameter_union.begin(), parameter_union.end()),
589 parameter_union.end());
591 std::vector<std::string> parameter_set_names;
592 std::map<std::string, bool> specified;
593 bool specified_a_set =
false;
594 for (
const auto & parameter_set : parameter_sets)
597 std::stringstream ss;
598 for (
unsigned int i = 0; i < parameter_set.size(); i++)
600 ss << parameter_set[i];
602 ss <<
"," << parameter_set[i];
603 const std::string parameter_set_name = ss.str();
604 parameter_set_names.push_back(parameter_set_name);
607 bool all_parameters_provided =
true;
608 for (
const auto & parameter : parameter_set)
609 if (!isParamValid(parameter))
610 all_parameters_provided =
false;
612 if (all_parameters_provided)
615 if (!specified_a_set)
617 specified[parameter_set_name] =
true;
620 std::vector<std::string> parameter_set_sorted(parameter_set);
621 std::sort(parameter_set_sorted.begin(), parameter_set_sorted.end());
622 std::vector<std::string> extraneous_parameters;
623 std::set_difference(parameter_union.begin(),
624 parameter_union.end(),
625 parameter_set_sorted.begin(),
626 parameter_set_sorted.end(),
627 std::inserter(extraneous_parameters, extraneous_parameters.end()));
628 for (
const auto & parameter : extraneous_parameters)
629 if (isParamValid(parameter))
633 ") has been specified; ",
635 " cannot be specified.");
638 specified_a_set =
true;
641 specified[parameter_set_name] =
false;
644 if (!specified_a_set && throw_error_if_no_match)
646 std::stringstream ss;
647 ss <<
name() <<
": For " << fp_type
648 <<
" fluid properties, you must provide one of the following\n"
649 "combinations of thermodynamic properties:\n";
650 for (
const auto & parameter_set_name : parameter_set_names)
651 ss <<
" * (" << parameter_set_name <<
")\n";
652 mooseError(ss.str());
661 _console << std::endl
663 << header <<
":" << std::endl
664 << std::setfill(
'-') << std::setw(80) <<
"-" << std::setfill(
' ') << std::endl;
670 const std::string & units)
672 const bool use_scientific_notation = ((value < 0.001) || (value >= 10000.0));
675 const bool is_nan = value != value;
679 const std::string units_printed = is_nan ?
"" : units;
685 std::stringstream ss;
687 if (use_scientific_notation)
688 ss << std::setw(35) << std::left <<
name +
":" << std::setw(
_precision + 10) << std::right
689 << std::setprecision(
_precision) << std::scientific << value <<
" " << units_printed
692 ss << std::setw(35) << std::left <<
name +
":" << std::setw(
_precision + 10) << std::right
693 << std::setprecision(
_precision) << value <<
" " << units_printed << std::endl;
695 _console << ss.str();
704 outputProperty(
"Specific volume", params.get<Real>(
"v"),
"m^3/kg");
705 outputProperty(
"Specific internal energy", params.get<Real>(
"e"),
"J/kg");
706 outputProperty(
"Specific enthalpy", params.get<Real>(
"h"),
"J/kg");
707 outputProperty(
"Specific entropy", params.get<Real>(
"s"),
"J/kg");
708 _console << std::endl;
710 outputProperty(
"Dynamic viscosity", params.get<Real>(
"mu"),
"Pa-s");
711 outputProperty(
"Specific heat at constant pressure", params.get<Real>(
"cp"),
"J/(kg-K)");
712 outputProperty(
"Specific heat at constant volume", params.get<Real>(
"cv"),
"J/(kg-K)");
713 outputProperty(
"Thermal conductivity", params.get<Real>(
"k"),
"W/(m-K)");
714 outputProperty(
"Volumetric expansion coefficient", params.get<Real>(
"beta"),
"1/K");
715 _console << std::endl;
724 outputProperty(
"Specific volume", params.get<Real>(
"v0"),
"m^3/kg");
725 outputProperty(
"Specific internal energy", params.get<Real>(
"e0"),
"J/kg");
726 outputProperty(
"Specific enthalpy", params.get<Real>(
"h0"),
"J/kg");
727 outputProperty(
"Specific entropy", params.get<Real>(
"s0"),
"J/kg");
728 _console << std::endl;
730 outputProperty(
"Dynamic viscosity", params.get<Real>(
"mu0"),
"Pa-s");
731 outputProperty(
"Specific heat at constant pressure", params.get<Real>(
"cp0"),
"J/(kg-K)");
732 outputProperty(
"Specific heat at constant volume", params.get<Real>(
"cv0"),
"J/(kg-K)");
733 outputProperty(
"Thermal conductivity", params.get<Real>(
"k0"),
"W/(m-K)");
734 outputProperty(
"Volumetric expansion coefficient", params.get<Real>(
"beta0"),
"1/K");
735 _console << std::endl;
744 outputProperty(
"Specific volume", params.get<Real>(
"v"),
"m^3/kg");
745 outputProperty(
"Specific internal energy", params.get<Real>(
"e"),
"J/kg");
746 outputProperty(
"Specific enthalpy", params.get<Real>(
"h"),
"J/kg");
747 _console << std::endl;
749 outputProperty(
"Dynamic viscosity", params.get<Real>(
"mu"),
"Pa-s");
750 outputProperty(
"Specific heat at constant pressure", params.get<Real>(
"cp"),
"J/(kg-K)");
751 outputProperty(
"Specific heat at constant volume", params.get<Real>(
"cv"),
"J/(kg-K)");
752 outputProperty(
"Thermal conductivity", params.get<Real>(
"k"),
"W/(m-K)");
753 _console << std::endl;
759 outputProperty(
"Specific enthalpy", params.get<Real>(
"h0"),
"J/kg");
760 _console << std::endl;