LCOV - code coverage report
Current view: top level - src/components - HSBoundaryExternalAppHeatFlux.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #30301 (3b550b) with base 2ad78d Lines: 63 65 96.9 %
Date: 2025-07-30 13:02: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 "HSBoundaryExternalAppHeatFlux.h"
      11             : #include "HeatStructureCylindricalBase.h"
      12             : #include "HeatConductionModel.h"
      13             : 
      14             : registerMooseObject("ThermalHydraulicsApp", HSBoundaryExternalAppHeatFlux);
      15             : 
      16             : InputParameters
      17          18 : HSBoundaryExternalAppHeatFlux::validParams()
      18             : {
      19          18 :   InputParameters params = HSBoundary::validParams();
      20             : 
      21          36 :   params.addRequiredParam<VariableName>(
      22             :       "heat_flux_name",
      23             :       "Name to give the heat flux variable transferred from the external application");
      24          36 :   params.addParam<bool>(
      25             :       "heat_flux_is_monomial",
      26          36 :       true,
      27             :       "If true, makes the heat flux variable transferred from the external application to have the "
      28             :       "FE type 'CONSTANT MONOMIAL'. Else, the FE type is 'FIRST LAGRANGE'.");
      29          36 :   params.addRequiredParam<PostprocessorName>(
      30             :       "perimeter_ext", "Name to give the external application perimeter post-processor");
      31          36 :   params.addRequiredParam<bool>(
      32             :       "heat_flux_is_inward",
      33             :       "Set to true if the transferred heat flux corresponds to the inward direction on the heat "
      34             :       "structure boundary; else the outward direction");
      35             : 
      36          18 :   params.addClassDescription("Heat structure boundary condition to apply a heat flux transferred "
      37             :                              "from another application.");
      38             : 
      39          18 :   return params;
      40           0 : }
      41             : 
      42           9 : HSBoundaryExternalAppHeatFlux::HSBoundaryExternalAppHeatFlux(const InputParameters & params)
      43             :   : HSBoundary(params),
      44           9 :     _heat_flux_name(getParam<VariableName>("heat_flux_name")),
      45          27 :     _perimeter_ext_pp_name(getParam<PostprocessorName>("perimeter_ext"))
      46             : {
      47           9 : }
      48             : 
      49             : void
      50           9 : HSBoundaryExternalAppHeatFlux::check() const
      51             : {
      52           9 :   HSBoundary::check();
      53             : 
      54             :   // HeatStructurePlate and HeatStructureFromFile3D are not yet supported
      55           9 :   checkComponentOfTypeExistsByName<HeatStructureCylindricalBase>(_hs_name);
      56             : 
      57             :   // Check that all boundaries are of type INNER or OUTER
      58           9 :   if (hasComponentByName<Component2D>(_hs_name))
      59             :   {
      60           9 :     checkAllComponent2DBoundariesAreExternal();
      61           9 :     if (allComponent2DBoundariesAreExternal())
      62           9 :       if (hasCommonComponent2DExternalBoundaryType())
      63             :       {
      64           9 :         const auto boundary_type = getCommonComponent2DExternalBoundaryType();
      65           9 :         if (boundary_type != Component2D::ExternalBoundaryType::INNER &&
      66             :             boundary_type != Component2D::ExternalBoundaryType::OUTER)
      67           2 :           logError("The boundaries in 'boundary' must be of an inner/outer type, not of a "
      68             :                    "start/end type.");
      69             :       }
      70             :   }
      71           9 : }
      72             : 
      73             : void
      74           5 : HSBoundaryExternalAppHeatFlux::addVariables()
      75             : {
      76           5 :   const HeatStructureInterface & hs = getComponentByName<HeatStructureInterface>(_hs_name);
      77             :   const std::vector<SubdomainName> & subdomain_names =
      78           5 :       hs.getGeometricalComponent().getSubdomainNames();
      79             : 
      80          10 :   const auto fe_type = getParam<bool>("heat_flux_is_monomial") ? libMesh::FEType(CONSTANT, MONOMIAL)
      81             :                                                                : libMesh::FEType(FIRST, LAGRANGE);
      82           5 :   getTHMProblem().addSimVariable(false, _heat_flux_name, fe_type, subdomain_names);
      83           5 : }
      84             : 
      85             : void
      86           5 : HSBoundaryExternalAppHeatFlux::addMooseObjects()
      87             : {
      88             :   // Add external perimeter PP
      89             :   {
      90           5 :     const std::string class_name = "Receiver";
      91           5 :     InputParameters params = _factory.getValidParams(class_name);
      92           5 :     getTHMProblem().addPostprocessor(class_name, _perimeter_ext_pp_name, params);
      93           5 :   }
      94             : 
      95             :   // Add BC
      96             :   {
      97           5 :     const std::string class_name = "FunctorNeumannBC";
      98           5 :     InputParameters params = _factory.getValidParams(class_name);
      99          10 :     params.set<std::vector<BoundaryName>>("boundary") = _boundary;
     100          10 :     params.set<NonlinearVariableName>("variable") = HeatConductionModel::TEMPERATURE;
     101          10 :     params.set<MooseFunctorName>("functor") = _heat_flux_name;
     102          10 :     params.set<MooseFunctorName>("coefficient") = _perimeter_ext_pp_name;
     103          10 :     params.set<bool>("flux_is_inward") = getParam<bool>("heat_flux_is_inward");
     104          10 :     getTHMProblem().addBoundaryCondition(class_name, genName(name(), "bc"), params);
     105           5 :   }
     106             : 
     107             :   // Add scale function to use as 'prefactor' in heat rate PP
     108          10 :   const FunctionName scale_fn_name = genName(name(), "scale_fn");
     109             :   {
     110           5 :     const std::string class_name = "ParsedFunction";
     111           5 :     InputParameters params = _factory.getValidParams(class_name);
     112           5 :     params.set<std::string>("expression") = "sign * P";
     113          20 :     params.set<std::vector<std::string>>("symbol_names") = {"sign", "P"};
     114           5 :     if (getParam<bool>("heat_flux_is_inward"))
     115          20 :       params.set<std::vector<std::string>>("symbol_values") = {"1", _perimeter_ext_pp_name};
     116             :     else
     117           0 :       params.set<std::vector<std::string>>("symbol_values") = {"-1", _perimeter_ext_pp_name};
     118           5 :     getTHMProblem().addFunction(class_name, scale_fn_name, params);
     119           5 :   }
     120             : 
     121             :   // Add heat rate PP
     122             :   {
     123           5 :     const std::string class_name = "SideIntegralFunctorPostprocessor";
     124           5 :     InputParameters params = _factory.getValidParams(class_name);
     125           5 :     params.set<std::vector<BoundaryName>>("boundary") = _boundary;
     126          10 :     params.set<MooseFunctorName>("functor") = _heat_flux_name;
     127          10 :     params.set<MooseFunctorName>("prefactor") = scale_fn_name;
     128          10 :     params.set<MooseEnum>("functor_argument") = "qp";
     129          20 :     params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
     130          10 :     getTHMProblem().addPostprocessor(class_name, genSafeName(name(), "integral"), params);
     131           5 :   }
     132          30 : }

Generated by: LCOV version 1.14