LCOV - code coverage report
Current view: top level - src/functions - TwoPhaseNCGPartialPressureFunction.C (source / functions) Hit Total Coverage
Test: idaholab/moose fluid_properties: #31405 (292dce) with base fef103 Lines: 42 44 95.5 %
Date: 2025-09-04 07:53:14 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #include "TwoPhaseNCGPartialPressureFunction.h"
      11             : #include "TwoPhaseNCGPartialPressureFluidProperties.h"
      12             : #include "MooseUtils.h"
      13             : 
      14             : registerMooseObject("FluidPropertiesApp", TwoPhaseNCGPartialPressureFunction);
      15             : 
      16             : const std::map<std::string, unsigned int> TwoPhaseNCGPartialPressureFunction::_n_expected_args{
      17             :     {"p_sat", 1}, {"x_sat_ncg_from_p_T", 2}};
      18             : 
      19             : InputParameters
      20          86 : TwoPhaseNCGPartialPressureFunction::validParams()
      21             : {
      22          86 :   InputParameters params = Function::validParams();
      23          86 :   params.addClassDescription(
      24             :       "Computes a property from a TwoPhaseNCGPartialPressureFluidProperties object.");
      25             : 
      26         172 :   params.addRequiredParam<UserObjectName>("fluid_properties",
      27             :                                           "The TwoPhaseNCGPartialPressureFluidProperties object");
      28             : 
      29         172 :   MooseEnum property_call("p_sat x_sat_ncg_from_p_T");
      30         172 :   params.addRequiredParam<MooseEnum>("property_call", property_call, "Which function to call");
      31             : 
      32         172 :   params.addParam<FunctionName>("arg1", 0, "The first argument for the property call, if any");
      33         172 :   params.addParam<FunctionName>("arg2", 0, "The second argument for the property call, if any");
      34             : 
      35          86 :   return params;
      36          86 : }
      37             : 
      38          46 : TwoPhaseNCGPartialPressureFunction::TwoPhaseNCGPartialPressureFunction(
      39          46 :     const InputParameters & parameters)
      40             :   : Function(parameters),
      41             :     FunctionInterface(this),
      42          46 :     _property_call(getParam<MooseEnum>("property_call")),
      43          46 :     _arg1_fn(getFunction("arg1")),
      44          92 :     _arg2_fn(getFunction("arg2"))
      45             : {
      46             :   // Check that the provided arguments matches the expected number
      47          92 :   if (_n_expected_args.find(_property_call) != _n_expected_args.end())
      48             :   {
      49             :     bool args_are_valid = true;
      50             :     const unsigned int n_arg_params = 2;
      51          46 :     const auto n_expected_args = _n_expected_args.at(_property_call);
      52             :     std::vector<std::string> expected_args, provided_args;
      53         138 :     for (unsigned int i = 0; i < n_arg_params; i++)
      54             :     {
      55          92 :       const std::string arg_param = "arg" + std::to_string(i + 1);
      56          92 :       const std::string arg_str = "'" + arg_param + "'";
      57             : 
      58             :       const bool arg_is_expected = i + 1 <= n_expected_args;
      59          92 :       if (arg_is_expected)
      60          68 :         expected_args.push_back(arg_str);
      61             : 
      62          92 :       if (isParamSetByUser(arg_param))
      63             :       {
      64          70 :         provided_args.push_back(arg_str);
      65          70 :         if (!arg_is_expected)
      66             :           args_are_valid = false;
      67             :       }
      68             :       else
      69             :       {
      70          22 :         if (arg_is_expected)
      71             :           args_are_valid = false;
      72             :       }
      73             :     }
      74             : 
      75          46 :     if (!args_are_valid)
      76           2 :       mooseError("The property call '",
      77             :                  _property_call,
      78             :                  "' expects the parameter(s) {",
      79           2 :                  MooseUtils::join(expected_args, ", "),
      80             :                  "} to be provided, but the provided argument(s) were {",
      81           2 :                  MooseUtils::join(provided_args, ", "),
      82             :                  "}.");
      83          44 :   }
      84             :   else
      85           0 :     mooseError("Property call in MooseEnum but not _n_expected_args.");
      86          44 : }
      87             : 
      88             : void
      89          44 : TwoPhaseNCGPartialPressureFunction::initialSetup()
      90             : {
      91          44 :   _fp = &getUserObject<TwoPhaseNCGPartialPressureFluidProperties>("fluid_properties");
      92          44 : }
      93             : 
      94             : Real
      95          28 : TwoPhaseNCGPartialPressureFunction::value(Real t, const Point & point) const
      96             : {
      97          28 :   const Real arg1 = _arg1_fn.value(t, point);
      98          28 :   const Real arg2 = _arg2_fn.value(t, point);
      99             : 
     100          28 :   if (_property_call == "p_sat")
     101          14 :     return _fp->p_sat(arg1);
     102          14 :   else if (_property_call == "x_sat_ncg_from_p_T")
     103          14 :     return _fp->x_sat_ncg_from_p_T(arg1, arg2);
     104             :   else
     105           0 :     mooseError("Unimplemented property call.");
     106             : }

Generated by: LCOV version 1.14