LCOV - code coverage report
Current view: top level - src/components - FlowChannel1Phase.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #32971 (54bef8) with base c6cf66 Lines: 100 101 99.0 %
Date: 2026-05-29 20:41:18 Functions: 11 11 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 "FlowChannel1Phase.h"
      11             : #include "FlowModelSinglePhase.h"
      12             : #include "SinglePhaseFluidProperties.h"
      13             : #include "THMNames.h"
      14             : #include "MooseUtils.h"
      15             : #include "ComponentsConvergence.h"
      16             : 
      17             : registerMooseObject("ThermalHydraulicsApp", FlowChannel1Phase);
      18             : 
      19             : InputParameters
      20        4314 : FlowChannel1Phase::validParams()
      21             : {
      22        4314 :   InputParameters params = FlowChannel1PhaseBase::validParams();
      23             : 
      24        8628 :   params.addParam<std::vector<FunctionName>>(
      25             :       "initial_passives",
      26             :       {},
      27             :       "Initial passive transport variable values in the flow channel, if any (units are "
      28             :       "[amount/m^3], where 'amount' may be mass (kg) or a number (molecules, moles, etc.))");
      29        8628 :   params.addParam<std::vector<VariableName>>(
      30             :       "passives_names",
      31             :       {},
      32             :       "Names for each passive transport variable [amount/m^3]. Note that the conserved (solution) "
      33             :       "variables will be an amount per unit volume multiplied by the channel cross-sectional area, "
      34             :       "yielding an amount per unit length; these solution variable names will append '_times_area' "
      35             :       "to the names given in this parameter.");
      36             : 
      37        8628 :   MooseEnum wave_speed_formulation("einfeldt davis", "einfeldt");
      38        8628 :   params.addParam<MooseEnum>(
      39             :       "wave_speed_formulation", wave_speed_formulation, "Method for computing wave speeds");
      40             : 
      41        4314 :   std::vector<Real> sf_1phase(3, 1.0);
      42        8628 :   params.addParam<std::vector<Real>>(
      43             :       "scaling_factor_1phase",
      44             :       sf_1phase,
      45             :       "Scaling factors for each single phase variable (rhoA, rhouA, rhoEA)");
      46        8628 :   params.addParam<std::vector<Real>>("scaling_factor_passives",
      47             :                                      "Scaling factor for each passive transport variable");
      48        8628 :   params.addParam<bool>(
      49             :       "create_flux_vpp",
      50        8628 :       false,
      51             :       "If true, create a VectorPostprocessor with the the mass, momentum, and energy side fluxes");
      52             : 
      53        8628 :   params.addParam<Real>("p_rel_step_tol", 1e-5, "Pressure relative step tolerance");
      54        8628 :   params.addParam<Real>("T_rel_step_tol", 1e-5, "Temperature relative step tolerance");
      55        8628 :   params.addParam<Real>("vel_rel_step_tol", 1e-5, "Velocity relative step tolerance");
      56        8628 :   params.addParam<Real>("mass_res_tol", 1e-5, "Mass equation normalized residual tolerance");
      57        8628 :   params.addParam<Real>(
      58        8628 :       "momentum_res_tol", 1e-5, "Momentum equation normalized residual tolerance");
      59        8628 :   params.addParam<Real>("energy_res_tol", 1e-5, "Energy equation normalized residual tolerance");
      60             : 
      61        8628 :   params.addParamNamesToGroup("scaling_factor_1phase", "Numerical scheme");
      62        4314 :   params.addClassDescription("1-phase 1D flow channel");
      63             : 
      64        4314 :   return params;
      65        4314 : }
      66             : 
      67        2156 : FlowChannel1Phase::FlowChannel1Phase(const InputParameters & params) : FlowChannel1PhaseBase(params)
      68             : {
      69        2156 : }
      70             : 
      71             : void
      72        2079 : FlowChannel1Phase::check() const
      73             : {
      74        2079 :   FlowChannel1PhaseBase::check();
      75             : 
      76        4158 :   checkEqualSize<VariableName, FunctionName>("passives_names", "initial_passives");
      77        4158 :   if (isParamValid("scaling_factor_passives"))
      78           0 :     checkEqualSize<VariableName, Real>("passives_names", "scaling_factor_passives");
      79        2079 : }
      80             : 
      81             : void
      82        2079 : FlowChannel1Phase::checkFluidProperties() const
      83             : {
      84        2079 :   const UserObject & fp = getTHMProblem().getUserObject<UserObject>(_fp_name);
      85        2079 :   if (dynamic_cast<const SinglePhaseFluidProperties *>(&fp) == nullptr)
      86           2 :     logError("Supplied fluid properties must be for 1-phase fluids.");
      87        2079 : }
      88             : 
      89             : std::string
      90        2133 : FlowChannel1Phase::flowModelClassName() const
      91             : {
      92        2133 :   return "FlowModelSinglePhase";
      93             : }
      94             : 
      95             : std::vector<std::string>
      96        4116 : FlowChannel1Phase::ICParameters() const
      97             : {
      98        4116 :   return {"initial_p", "initial_T", "initial_vel"};
      99             : }
     100             : 
     101             : void
     102        2037 : FlowChannel1Phase::addMooseObjects()
     103             : {
     104        2037 :   FlowChannel1PhaseBase::addMooseObjects();
     105             : 
     106        4074 :   if (getParam<bool>("create_flux_vpp"))
     107          45 :     addNumericalFluxVectorPostprocessor();
     108             : 
     109        2037 :   addFlowChannel1PhaseFunctorMaterial();
     110             : 
     111             :   const std::vector<std::pair<std::string, Real>> var_norm_pairs{
     112             :       {THM::PRESSURE, getParam<Real>("p_ref")},
     113             :       {THM::TEMPERATURE, getParam<Real>("T_ref")},
     114        8148 :       {THM::VELOCITY, getParam<Real>("vel_ref")}};
     115        8148 :   for (const auto & [var, norm] : var_norm_pairs)
     116             :   {
     117        6111 :     addNonlinearStepFunctorMaterial(
     118       12222 :         THM::functorMaterialPropertyName<false>(var), var + "_change", false);
     119        6111 :     addMaximumFunctorPostprocessor(
     120       18333 :         var + "_change", genName(name(), var + "_rel_step"), norm, getSubdomainNames());
     121             :   }
     122             : 
     123             :   const std::vector<std::pair<std::string, std::string>> var_eq_pairs{
     124        8148 :       {THM::RHOA, "mass"}, {THM::RHOUA, "momentum"}, {THM::RHOEA, "energy"}};
     125        8148 :   for (const auto & [var, eq] : var_eq_pairs)
     126       12222 :     addNormalized1PhaseResidualNorm(var, eq);
     127             : 
     128       18333 :   addMultiPostprocessorConvergence(
     129        4074 :       {genName(name(), "p_rel_step"),
     130        4074 :        genName(name(), "T_rel_step"),
     131        4074 :        genName(name(), "vel_rel_step"),
     132        4074 :        genName(name(), "mass_res"),
     133        4074 :        genName(name(), "momentum_res"),
     134        4074 :        genName(name(), "energy_res")},
     135             :       {"step: p", "step: T", "step: vel", "res: mass", "res: momentum", "res: energy"},
     136        2037 :       {getParam<Real>("p_rel_step_tol"),
     137        4074 :        getParam<Real>("T_rel_step_tol"),
     138        4074 :        getParam<Real>("vel_rel_step_tol"),
     139        4074 :        getParam<Real>("mass_res_tol"),
     140        4074 :        getParam<Real>("momentum_res_tol"),
     141        6111 :        getParam<Real>("energy_res_tol")});
     142       12222 : }
     143             : 
     144             : void
     145          45 : FlowChannel1Phase::addNumericalFluxVectorPostprocessor()
     146             : {
     147          45 :   const std::string class_name = "NumericalFlux3EqnInternalValues";
     148          45 :   InputParameters params = _factory.getValidParams(class_name);
     149          45 :   params.set<std::vector<SubdomainName>>("block") = getSubdomainNames();
     150          90 :   params.set<UserObjectName>("numerical_flux") = _numerical_flux_name;
     151         135 :   params.set<std::vector<VariableName>>("A_linear") = {THM::AREA_LINEAR};
     152          90 :   params.set<std::string>("sort_by") = sortBy();
     153         180 :   params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
     154          45 :   getTHMProblem().addVectorPostprocessor(class_name, name() + "_flux_vpp", params);
     155         135 : }
     156             : 
     157             : void
     158        2037 : FlowChannel1Phase::addFlowChannel1PhaseFunctorMaterial()
     159             : {
     160        2037 :   const std::string class_name = "FlowModel1PhaseFunctorMaterial";
     161        4074 :   const std::string obj_name = genName(name(), "fm1phase_fmat");
     162        2037 :   InputParameters params = _factory.getValidParams(class_name);
     163        2037 :   params.set<std::vector<SubdomainName>>("block") = getSubdomainNames();
     164        2037 :   params.set<UserObjectName>("fluid_properties") = _fp_name;
     165        2037 :   getTHMProblem().addFunctorMaterial(class_name, obj_name, params);
     166        4074 : }
     167             : 
     168             : void
     169        6111 : FlowChannel1Phase::addNormalized1PhaseResidualNorm(const VariableName & variable,
     170             :                                                    const std::string & equation)
     171             : {
     172        6111 :   const std::string class_name = "Normalized1PhaseResidualNorm";
     173        6111 :   InputParameters params = _factory.getValidParams(class_name);
     174        6111 :   params.applyParameters(parameters());
     175        6111 :   params.set<VariableName>("variable") = variable;
     176        6111 :   params.set<std::vector<SubdomainName>>("block") = getSubdomainNames();
     177       12222 :   params.set<MooseEnum>("norm_type") = "l_inf";
     178             :   const Point mid_point = 0.5 * (getStartPoint() + getEndPoint());
     179        6111 :   params.set<Point>("point") = mid_point;
     180       12222 :   params.set<UserObjectName>("fluid_properties") = _fp_name;
     181        6111 :   params.set<Real>("min_elem_size") = getMinimumElemSize();
     182       12222 :   params.set<ExecFlagEnum>("execute_on") = EXEC_NONLINEAR_CONVERGENCE;
     183       18333 :   params.set<std::vector<OutputName>>("outputs") = {"none"};
     184       12222 :   getTHMProblem().addPostprocessor(class_name, genName(name(), equation + "_res"), params);
     185       12222 : }
     186             : 
     187             : Convergence *
     188          10 : FlowChannel1Phase::getNonlinearConvergence() const
     189             : {
     190          20 :   return &getTHMProblem().getConvergence(nonlinearConvergenceName());
     191             : }

Generated by: LCOV version 1.14