https://mooseframework.inl.gov
Loading...
Searching...
No Matches
TwoPhaseNCGPartialPressureFunction.C
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
12#include "MooseUtils.h"
13
15
16const std::map<std::string, unsigned int> TwoPhaseNCGPartialPressureFunction::_n_expected_args{
17 {"p_sat", 1}, {"x_sat_ncg_from_p_T", 2}};
18
21{
24 "Computes a property from a TwoPhaseNCGPartialPressureFluidProperties object.");
25
26 params.addRequiredParam<UserObjectName>("fluid_properties",
27 "The TwoPhaseNCGPartialPressureFluidProperties object");
28
29 MooseEnum property_call("p_sat x_sat_ncg_from_p_T");
30 params.addRequiredParam<MooseEnum>("property_call", property_call, "Which function to call");
31
32 params.addParam<FunctionName>("arg1", 0, "The first argument for the property call, if any");
33 params.addParam<FunctionName>("arg2", 0, "The second argument for the property call, if any");
34
35 return params;
36}
37
39 const InputParameters & parameters)
40 : Function(parameters),
42 _property_call(getParam<MooseEnum>("property_call")),
43 _arg1_fn(getFunction("arg1")),
44 _arg2_fn(getFunction("arg2"))
45{
46 // Check that the provided arguments matches the expected number
48 {
49 bool args_are_valid = true;
50 const unsigned int n_arg_params = 2;
51 const auto n_expected_args = _n_expected_args.at(_property_call);
52 std::vector<std::string> expected_args, provided_args;
53 for (unsigned int i = 0; i < n_arg_params; i++)
54 {
55 const std::string arg_param = "arg" + std::to_string(i + 1);
56 const std::string arg_str = "'" + arg_param + "'";
57
58 const bool arg_is_expected = i + 1 <= n_expected_args;
59 if (arg_is_expected)
60 expected_args.push_back(arg_str);
61
62 if (isParamSetByUser(arg_param))
63 {
64 provided_args.push_back(arg_str);
65 if (!arg_is_expected)
66 args_are_valid = false;
67 }
68 else
69 {
70 if (arg_is_expected)
71 args_are_valid = false;
72 }
73 }
74
75 if (!args_are_valid)
76 mooseError("The property call '",
78 "' expects the parameter(s) {",
79 MooseUtils::join(expected_args, ", "),
80 "} to be provided, but the provided argument(s) were {",
81 MooseUtils::join(provided_args, ", "),
82 "}.");
83 }
84 else
85 mooseError("Property call in MooseEnum but not _n_expected_args.");
86}
87
88void
90{
91 _fp = &getUserObject<TwoPhaseNCGPartialPressureFluidProperties>("fluid_properties");
92}
93
94Real
95TwoPhaseNCGPartialPressureFunction::value(Real t, const Point & point) const
96{
97 const Real arg1 = _arg1_fn.value(t, point);
98 const Real arg2 = _arg2_fn.value(t, point);
99
100 if (_property_call == "p_sat")
101 return _fp->p_sat(arg1);
102 else if (_property_call == "x_sat_ncg_from_p_T")
103 return _fp->x_sat_ncg_from_p_T(arg1, arg2);
104 else
105 mooseError("Unimplemented property call.");
106}
registerMooseObject("FluidPropertiesApp", TwoPhaseNCGPartialPressureFunction)
static InputParameters validParams()
virtual Real value(Real t, const Point &p) const
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
bool isParamSetByUser(const std::string &name) const
void mooseError(Args &&... args) const
virtual Real p_sat(Real T) const override
Computes the saturation pressure at a temperature.
Real x_sat_ncg_from_p_T(Real p, Real T) const
Computes the NCG mass fraction with the CG saturated at the given temperature.
Computes a property from a TwoPhaseNCGPartialPressureFluidProperties object.
virtual Real value(Real t, const Point &p) const override
static const std::map< std::string, unsigned int > _n_expected_args
Number of expected arguments for each property call.
const Function & _arg1_fn
Argument 1 function.
const Function & _arg2_fn
Argument 2 function.
const TwoPhaseNCGPartialPressureFluidProperties * _fp
Fluid properties object.
TwoPhaseNCGPartialPressureFunction(const InputParameters &parameters)