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