LCOV - code coverage report
Current view: top level - src/components - HeatSourceFromTotalPower.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #32971 (54bef8) with base c6cf66 Lines: 72 73 98.6 %
Date: 2026-05-29 20:41:18 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 "HeatSourceFromTotalPower.h"
      11             : #include "HeatStructureCylindricalBase.h"
      12             : #include "HeatStructurePlate.h"
      13             : #include "TotalPowerBase.h"
      14             : 
      15             : registerMooseObject("ThermalHydraulicsApp", HeatSourceFromTotalPower);
      16             : 
      17             : InputParameters
      18         188 : HeatSourceFromTotalPower::validParams()
      19             : {
      20         188 :   InputParameters params = HeatSourceBase::validParams();
      21         376 :   params.addRequiredParam<std::string>("power", "Component that provides total power");
      22         376 :   params.addParam<Real>(
      23         376 :       "power_fraction", 1., "Fraction of the total power that goes into the heat structure [-]");
      24         376 :   params.addParam<FunctionName>("power_shape_function", "Axial power shape [-]");
      25         376 :   params.declareControllable("power_fraction");
      26         188 :   params.addClassDescription("Heat generation from total power");
      27         188 :   return params;
      28           0 : }
      29             : 
      30          94 : HeatSourceFromTotalPower::HeatSourceFromTotalPower(const InputParameters & parameters)
      31             :   : HeatSourceBase(parameters),
      32         188 :     _power_fraction(getParam<Real>("power_fraction")),
      33         188 :     _has_psf(isParamValid("power_shape_function")),
      34         188 :     _power_shape_func(_has_psf ? getParam<FunctionName>("power_shape_function") : "")
      35             : {
      36          94 :   checkSizeGreaterThan<std::string>("regions", 0);
      37          94 : }
      38             : 
      39             : void
      40          94 : HeatSourceFromTotalPower::init()
      41             : {
      42             :   HeatSourceBase::init();
      43             : 
      44         188 :   if (hasComponent<TotalPowerBase>("power"))
      45             :   {
      46          92 :     const TotalPowerBase & rp = getComponent<TotalPowerBase>("power");
      47          92 :     _power_var_name = rp.getPowerVariableName();
      48             :   }
      49          94 : }
      50             : 
      51             : void
      52          94 : HeatSourceFromTotalPower::check() const
      53             : {
      54          94 :   HeatSourceBase::check();
      55             : 
      56          94 :   checkComponentOfTypeExists<TotalPowerBase>("power");
      57          94 : }
      58             : 
      59             : void
      60          86 : HeatSourceFromTotalPower::addMooseObjects()
      61             : {
      62             :   /// The heat structure component we work with
      63          86 :   const HeatStructureInterface & hs = getComponent<HeatStructureInterface>("hs");
      64          86 :   const HeatStructureBase * hs_base = dynamic_cast<const HeatStructureBase *>(&hs);
      65             : 
      66             :   Real n_units, length;
      67          86 :   if (hs_base)
      68             :   {
      69             :     n_units = hs_base->getNumberOfUnits();
      70          80 :     length = hs_base->getLength();
      71             :   }
      72             :   else // HeatStructureFromFile3D
      73             :   {
      74             :     n_units = 1.0;
      75             :     length = 1.0;
      76             :   }
      77             : 
      78             :   const HeatStructureCylindricalBase * hs_cyl =
      79          86 :       dynamic_cast<const HeatStructureCylindricalBase *>(&hs);
      80             :   const bool is_cylindrical = hs_cyl != nullptr;
      81             : 
      82          86 :   const HeatStructurePlate * hs_plate = dynamic_cast<const HeatStructurePlate *>(&hs);
      83             :   const bool is_plate = hs_plate != nullptr;
      84             : 
      85          86 :   if (!_has_psf)
      86             :   {
      87          84 :     _power_shape_func = genName(name(), "power_shape_fn");
      88          42 :     std::string class_name = "ConstantFunction";
      89          42 :     InputParameters pars = _factory.getValidParams(class_name);
      90          42 :     pars.set<Real>("value") = 1. / length;
      91          42 :     getTHMProblem().addFunction(class_name, _power_shape_func, pars);
      92          42 :   }
      93             : 
      94          86 :   const std::string power_shape_integral_name = _has_psf
      95          86 :                                                     ? genName(name(), _power_shape_func, "integral")
      96         170 :                                                     : genName(_power_shape_func, "integral");
      97             : 
      98             :   {
      99             :     const std::string class_name =
     100         106 :         is_cylindrical ? "FunctionElementIntegralRZ" : "FunctionElementIntegral";
     101          86 :     InputParameters pars = _factory.getValidParams(class_name);
     102          86 :     pars.set<std::vector<SubdomainName>>("block") = _subdomain_names;
     103          86 :     pars.set<FunctionName>("function") = _power_shape_func;
     104          86 :     if (is_cylindrical)
     105             :     {
     106          66 :       pars.set<Point>("axis_point") = hs_cyl->getPosition();
     107          66 :       pars.set<RealVectorValue>("axis_dir") = hs_cyl->getDirection();
     108             :     }
     109         258 :     pars.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL};
     110         258 :     pars.set<std::vector<OutputName>>("outputs") = {"none"};
     111          86 :     getTHMProblem().addPostprocessor(class_name, power_shape_integral_name, pars);
     112          86 :   }
     113             : 
     114             :   {
     115             :     const std::string class_name =
     116         106 :         is_cylindrical ? "ADHeatStructureHeatSourceRZ" : "ADHeatStructureHeatSource";
     117          86 :     InputParameters pars = _factory.getValidParams(class_name);
     118         172 :     pars.set<NonlinearVariableName>("variable") = HeatConductionModel::TEMPERATURE;
     119          86 :     pars.set<std::vector<SubdomainName>>("block") = _subdomain_names;
     120          86 :     pars.set<Real>("num_units") = n_units;
     121          86 :     pars.set<Real>("power_fraction") = _power_fraction;
     122          86 :     pars.set<FunctionName>("power_shape_function") = _power_shape_func;
     123          86 :     pars.set<std::vector<VariableName>>("total_power") =
     124         172 :         std::vector<VariableName>(1, _power_var_name);
     125          86 :     if (is_cylindrical)
     126             :     {
     127          66 :       pars.set<Point>("axis_point") = hs_cyl->getPosition();
     128          66 :       pars.set<RealVectorValue>("axis_dir") = hs_cyl->getDirection();
     129             :     }
     130          20 :     else if (is_plate)
     131             :     {
     132             :       // For plate heat structure, the element integral of the power shape only
     133             :       // integrates over x and y, not z, so the depth still needs to be applied.
     134          14 :       pars.set<Real>("scale") = 1.0 / hs_plate->getDepth();
     135             :     }
     136         172 :     pars.set<PostprocessorName>("power_shape_integral_pp") = power_shape_integral_name;
     137         172 :     std::string mon = genName(name(), "heat_src");
     138          86 :     getTHMProblem().addKernel(class_name, mon, pars);
     139         172 :     connectObject(pars, mon, "power_fraction");
     140          86 :   }
     141         172 : }

Generated by: LCOV version 1.14