https://mooseframework.inl.gov
HeatSourceFromTotalPower.C
Go to the documentation of this file.
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 
12 #include "HeatStructurePlate.h"
13 #include "TotalPowerBase.h"
14 
15 registerMooseObject("ThermalHydraulicsApp", HeatSourceFromTotalPower);
16 
19 {
21  params.addRequiredParam<std::string>("power", "Component that provides total power");
22  params.addParam<Real>(
23  "power_fraction", 1., "Fraction of the total power that goes into the heat structure [-]");
24  params.addParam<FunctionName>("power_shape_function", "Axial power shape [-]");
25  params.declareControllable("power_fraction");
26  params.addClassDescription("Heat generation from total power");
27  return params;
28 }
29 
31  : HeatSourceBase(parameters),
32  _power_fraction(getParam<Real>("power_fraction")),
33  _has_psf(isParamValid("power_shape_function")),
34  _power_shape_func(_has_psf ? getParam<FunctionName>("power_shape_function") : "")
35 {
36  checkSizeGreaterThan<std::string>("regions", 0);
37 }
38 
39 void
41 {
43 
44  if (hasComponent<TotalPowerBase>("power"))
45  {
46  const TotalPowerBase & rp = getComponent<TotalPowerBase>("power");
48  }
49 }
50 
51 void
53 {
55 
56  checkComponentOfTypeExists<TotalPowerBase>("power");
57 }
58 
59 void
61 {
63  const HeatStructureInterface & hs = getComponent<HeatStructureInterface>("hs");
64  const HeatStructureBase * hs_base = dynamic_cast<const HeatStructureBase *>(&hs);
65 
66  Real n_units, length;
67  if (hs_base)
68  {
69  n_units = hs_base->getNumberOfUnits();
70  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  dynamic_cast<const HeatStructureCylindricalBase *>(&hs);
80  const bool is_cylindrical = hs_cyl != nullptr;
81 
82  const HeatStructurePlate * hs_plate = dynamic_cast<const HeatStructurePlate *>(&hs);
83  const bool is_plate = hs_plate != nullptr;
84 
85  if (!_has_psf)
86  {
87  _power_shape_func = genName(name(), "power_shape_fn");
88  std::string class_name = "ConstantFunction";
89  InputParameters pars = _factory.getValidParams(class_name);
90  pars.set<Real>("value") = 1. / length;
91  getTHMProblem().addFunction(class_name, _power_shape_func, pars);
92  }
93 
94  const std::string power_shape_integral_name = _has_psf
95  ? genName(name(), _power_shape_func, "integral")
96  : genName(_power_shape_func, "integral");
97 
98  {
99  const std::string class_name =
100  is_cylindrical ? "FunctionElementIntegralRZ" : "FunctionElementIntegral";
101  InputParameters pars = _factory.getValidParams(class_name);
102  pars.set<std::vector<SubdomainName>>("block") = _subdomain_names;
103  pars.set<FunctionName>("function") = _power_shape_func;
104  if (is_cylindrical)
105  {
106  pars.set<Point>("axis_point") = hs_cyl->getPosition();
107  pars.set<RealVectorValue>("axis_dir") = hs_cyl->getDirection();
108  }
109  pars.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL};
110  // TODO: This seems to produce incorrect output files, even though this is the line
111  // that should be here, becuase we don't want this PPS to be in any output. The effect
112  // of this line is correct, but for some reason, MOOSE will start output scalar variables
113  // even though we did not ask it to do so. Refs idaholab/thm#
114  // pars.set<std::vector<OutputName>>("outputs") = getTHMProblem().getOutputsVector("none");
115  getTHMProblem().addPostprocessor(class_name, power_shape_integral_name, pars);
116  }
117 
118  {
119  const std::string class_name =
120  is_cylindrical ? "ADHeatStructureHeatSourceRZ" : "ADHeatStructureHeatSource";
121  InputParameters pars = _factory.getValidParams(class_name);
122  pars.set<NonlinearVariableName>("variable") = HeatConductionModel::TEMPERATURE;
123  pars.set<std::vector<SubdomainName>>("block") = _subdomain_names;
124  pars.set<Real>("num_units") = n_units;
125  pars.set<Real>("power_fraction") = _power_fraction;
126  pars.set<FunctionName>("power_shape_function") = _power_shape_func;
127  pars.set<std::vector<VariableName>>("total_power") =
128  std::vector<VariableName>(1, _power_var_name);
129  if (is_cylindrical)
130  {
131  pars.set<Point>("axis_point") = hs_cyl->getPosition();
132  pars.set<RealVectorValue>("axis_dir") = hs_cyl->getDirection();
133  }
134  else if (is_plate)
135  {
136  // For plate heat structure, the element integral of the power shape only
137  // integrates over x and y, not z, so the depth still needs to be applied.
138  pars.set<Real>("scale") = 1.0 / hs_plate->getDepth();
139  }
140  pars.set<PostprocessorName>("power_shape_integral_pp") = power_shape_integral_name;
141  std::string mon = genName(name(), "heat_src");
142  getTHMProblem().addKernel(class_name, mon, pars);
143  connectObject(pars, mon, "power_fraction");
144  }
145 }
std::string genName(const std::string &prefix, unsigned int id, const std::string &suffix="") const
Build a name from a prefix, number and possible suffix.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
HeatSourceFromTotalPower(const InputParameters &parameters)
THMProblem & getTHMProblem() const
Gets the THM problem.
Definition: Component.C:135
static InputParameters validParams()
T & set(const std::string &name, bool quiet_mode=false)
virtual RealVectorValue getDirection() const
InputParameters getValidParams(const std::string &name) const
virtual void addMooseObjects() override
virtual void check() const override
Check the component integrity.
const Real & getDepth() const
Gets the depth of the plate.
virtual void addKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
virtual const std::string & name() const
void addRequiredParam(const std::string &name, const std::string &doc_string)
virtual void init() override
Initializes the component.
static InputParameters validParams()
const Real & _power_fraction
The fraction of the power that goes into the heat structure.
virtual void addPostprocessor(const std::string &pp_name, const std::string &name, InputParameters &parameters)
Base class for cylindrical heat structure components.
Base class for components that provide total power.
const bool _has_psf
true if power shape function is being used
static const std::string TEMPERATURE
virtual void addFunction(const std::string &type, const std::string &name, InputParameters &parameters)
virtual void init()
Initializes the component.
Definition: Component.h:290
Interface class for heat structure components.
Base class for heat source components.
virtual const VariableName & getPowerVariableName() const
VariableName _power_var_name
The name of the variable that represents total power.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void check() const override
Check the component integrity.
Factory & _factory
The Factory associated with the MooseApp.
Definition: Component.h:446
void connectObject(const InputParameters &params, const std::string &mooseName, const std::string &name) const
Connect with control logic.
Definition: Component.C:98
Component to model plate heat structure.
Base class for 2D generated heat structures.
void addClassDescription(const std::string &doc_string)
FunctionName _power_shape_func
The name of the power shape function.
std::vector< SubdomainName > _subdomain_names
Names of the heat structure subdomains corresponding to the given regions.
registerMooseObject("ThermalHydraulicsApp", HeatSourceFromTotalPower)
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
Heat generation from total power.
const ExecFlagType EXEC_INITIAL