LCOV - code coverage report
Current view: top level - src/postprocessors - Normalized1PhaseResidualNorm.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #31039 (75bfb3) with base bb0a08 Lines: 41 43 95.3 %
Date: 2025-11-03 14:57:48 Functions: 5 5 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 "Normalized1PhaseResidualNorm.h"
      11             : #include "SinglePhaseFluidProperties.h"
      12             : 
      13             : registerMooseObject("ThermalHydraulicsApp", Normalized1PhaseResidualNorm);
      14             : 
      15             : InputParameters
      16       26754 : Normalized1PhaseResidualNorm::validParams()
      17             : {
      18       26754 :   InputParameters params = DiscreteVariableResidualNorm::validParams();
      19             : 
      20       26754 :   params.addClassDescription(
      21             :       "Computes a normalized residual norm for the single-phase flow model.");
      22             : 
      23       53508 :   params.addRequiredParam<Real>("p_ref", "Reference pressure [Pa]");
      24       53508 :   params.addRequiredParam<Real>("T_ref", "Reference temperature [K]");
      25       53508 :   params.addRequiredParam<Real>("vel_ref", "Reference velocity [m/s]");
      26       53508 :   params.addRequiredParam<FunctionName>("A", "Cross-sectional area function [m^2]");
      27       53508 :   params.addRequiredParam<Point>("point",
      28             :                                  "Point at which to evaluate cross-sectional area function [m]");
      29       53508 :   params.addRequiredParam<UserObjectName>("fluid_properties",
      30             :                                           "Single-phase fluid properties object");
      31       53508 :   params.addRequiredParam<Real>("min_elem_size", "Minimum element size on block [m]");
      32             : 
      33       26754 :   return params;
      34           0 : }
      35             : 
      36       14610 : Normalized1PhaseResidualNorm::Normalized1PhaseResidualNorm(const InputParameters & parameters)
      37       14610 :   : DiscreteVariableResidualNorm(parameters), _initialized(false)
      38             : {
      39       14610 : }
      40             : 
      41             : void
      42      428346 : Normalized1PhaseResidualNorm::initialize()
      43             : {
      44      428346 :   DiscreteVariableResidualNorm::initialize();
      45             : 
      46             :   // This cannot be done in constructor or initialSetup() due to some fluid
      47             :   // properties not being initialized yet.
      48      428346 :   if (!_initialized)
      49             :   {
      50       12363 :     _normalization = computeNormalization();
      51       12363 :     _initialized = true;
      52             :   }
      53      428346 : }
      54             : 
      55             : Real
      56       12363 : Normalized1PhaseResidualNorm::computeNormalization() const
      57             : {
      58       24726 :   const auto h_min = getParam<Real>("min_elem_size");
      59             : 
      60       12363 :   const auto & A_fn = getFunction("A");
      61       12363 :   const auto & point = getParam<Point>("point");
      62       12363 :   const auto A_ref = A_fn.value(0.0, point);
      63             : 
      64       24726 :   const auto p_ref = getParam<Real>("p_ref");
      65       24726 :   const auto T_ref = getParam<Real>("T_ref");
      66       24726 :   const auto vel_ref = getParam<Real>("vel_ref");
      67             : 
      68       12363 :   const auto & fp = getUserObject<SinglePhaseFluidProperties>("fluid_properties");
      69       12363 :   const auto rho_ref = fp.rho_from_p_T(p_ref, T_ref);
      70             : 
      71       12363 :   const auto variable = getParam<VariableName>("variable");
      72       12363 :   if (variable == "rhoA")
      73        4121 :     return rho_ref * A_ref * h_min;
      74        8242 :   else if (variable == "rhouA")
      75        4121 :     return rho_ref * vel_ref * A_ref * h_min;
      76        4121 :   else if (variable == "rhoEA")
      77             :   {
      78        4121 :     const auto e_ref = fp.e_from_p_T(p_ref, T_ref);
      79        4121 :     const auto E_ref = e_ref + 0.5 * vel_ref * vel_ref;
      80        4121 :     return rho_ref * E_ref * A_ref * h_min;
      81             :   }
      82             :   else
      83           0 :     mooseError("The 'variable' parameter must be one of the following: {rhoA, rhouA, rhoEA}.");
      84             : }
      85             : 
      86             : Real
      87      342732 : Normalized1PhaseResidualNorm::getValue() const
      88             : {
      89      342732 :   return DiscreteVariableResidualNorm::getValue() / _normalization;
      90             : }

Generated by: LCOV version 1.14