https://mooseframework.inl.gov
HeatConductionFV.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 
10 #include "HeatConductionFV.h"
11 
12 // Register the actions for the objects actually used
13 registerPhysicsBaseTasks("HeatTransferApp", HeatConductionFV);
14 registerMooseAction("HeatTransferApp", HeatConductionFV, "add_fv_kernel");
15 registerMooseAction("HeatTransferApp", HeatConductionFV, "add_fv_bc");
16 registerMooseAction("HeatTransferApp", HeatConductionFV, "add_variable");
17 registerMooseAction("HeatTransferApp", HeatConductionFV, "add_ic");
18 registerMooseAction("HeatTransferApp", HeatConductionFV, "add_preconditioning");
19 
22 {
24  params.addClassDescription(
25  "Creates the heat conduction equation discretized with nonlinear finite volume");
26 
27  // Material properties
28  params.addRequiredParam<MooseFunctorName>("thermal_conductivity_functor",
29  "Thermal conductivity functor material property");
30  params.addParam<MaterialPropertyName>("specific_heat", "Specific heat material property");
31  params.addParam<MooseFunctorName>("specific_heat_functor", "Specific heat functor");
32  params.addParam<MaterialPropertyName>("density", "Density material property");
33  params.addParam<MooseFunctorName>("density_functor", "Density functor");
34  params.addParamNamesToGroup(
35  "thermal_conductivity_functor specific_heat specific_heat_functor density density_functor",
36  "Thermal properties");
37 
38  params.addRangeCheckedParam<Real>("temperature_scaling",
39  1,
40  "temperature_scaling > 0",
41  "Scaling factor for the heat conduction equation");
42 
43  return params;
44 }
45 
47  : HeatConductionPhysicsBase(parameters)
48 {
49  // Not compatible
50  // TODO: we could bake this into a single call
51  checkParamsBothSetOrNotSet("specific_heat_functor", "density_functor");
52  checkParamsBothSetOrNotSet("specific_heat", "density");
53  checkSecondParamNotSetIfFirstOneSet("specific_heat", "density_functor");
54  checkSecondParamNotSetIfFirstOneSet("specific_heat", "specific_heat_functor");
55  checkSecondParamNotSetIfFirstOneSet("specific_heat_functor", "specific_heat");
56  checkSecondParamNotSetIfFirstOneSet("specific_heat_functor", "density");
57 }
58 
59 void
61 {
62  getProblem().needFV();
63 }
64 
65 void
67 {
68  {
69  const std::string kernel_type = "FVDiffusion";
70  InputParameters params = getFactory().getValidParams(kernel_type);
71  assignBlocks(params, _blocks);
72  params.set<NonlinearVariableName>("variable") = _temperature_name;
73  params.set<MooseFunctorName>("coeff") =
74  getParam<MooseFunctorName>("thermal_conductivity_functor");
75  getProblem().addFVKernel(kernel_type, prefix() + _temperature_name + "_conduction", params);
76  }
77  if (isParamValid("heat_source_var"))
78  {
79  const std::string kernel_type = "FVCoupledForce";
80  InputParameters params = getFactory().getValidParams(kernel_type);
81  assignBlocks(params, _blocks);
82  params.set<NonlinearVariableName>("variable") = _temperature_name;
83  params.set<MooseFunctorName>("v") = getParam<VariableName>("heat_source_var");
84  if (isParamValid("heat_source_blocks"))
85  params.set<std::vector<SubdomainName>>("block") =
86  getParam<std::vector<SubdomainName>>("heat_source_blocks");
87  getProblem().addFVKernel(kernel_type, prefix() + _temperature_name + "_source", params);
88  }
89  if (isParamValid("heat_source_functor"))
90  {
91  const std::string kernel_type = "FVBodyForce";
92  InputParameters params = getFactory().getValidParams(kernel_type);
93  assignBlocks(params, _blocks);
94  params.set<NonlinearVariableName>("variable") = _temperature_name;
95  const auto & functor_name = getParam<MooseFunctorName>("heat_source_functor");
96  if (MooseUtils::parsesToReal(functor_name))
97  params.set<Real>("value") = std::stod(functor_name);
98  else if (getProblem().hasFunction(functor_name))
99  params.set<FunctionName>("function") = functor_name;
100  else if (getProblem().hasPostprocessorValueByName(functor_name))
101  params.set<PostprocessorName>("postprocessor") = functor_name;
102  else
103  paramError("heat_source_functor",
104  "Unsupported functor type. Consider using 'heat_source_var'.");
105  getProblem().addFVKernel(kernel_type, prefix() + _temperature_name + "_source_functor", params);
106  }
107  if (shouldCreateTimeDerivative(_temperature_name, _blocks, /*error if already defined*/ false))
108  {
109  const bool use_functors =
110  isParamValid("density_functor") || isParamValid("specific_heat_functor");
111  const std::string kernel_type =
112  use_functors ? "FVFunctorHeatConductionTimeDerivative" : "FVHeatConductionTimeDerivative";
113  InputParameters params = getFactory().getValidParams(kernel_type);
114  assignBlocks(params, _blocks);
115  params.set<NonlinearVariableName>("variable") = _temperature_name;
116  if (use_functors)
117  {
118  params.set<MooseFunctorName>("specific_heat") =
119  getParam<MooseFunctorName>("specific_heat_functor");
120  params.set<MooseFunctorName>("density") = getParam<MooseFunctorName>("density_functor");
121  }
122  else
123  {
124  params.applyParameter(parameters(), "specific_heat");
125  params.set<MaterialPropertyName>("density_name") = getParam<MaterialPropertyName>("density");
126  }
127  getProblem().addFVKernel(kernel_type, prefix() + _temperature_name + "_time", params);
128  }
129 }
130 
131 void
133 {
134  // We dont need to add anything for insulated boundaries, 0 flux is the default boundary condition
135  if (isParamValid("heat_flux_boundaries"))
136  {
137  const std::string bc_type = "FVFunctorNeumannBC";
138  InputParameters params = getFactory().getValidParams(bc_type);
139  params.set<NonlinearVariableName>("variable") = _temperature_name;
140 
141  const auto & heat_flux_boundaries = getParam<std::vector<BoundaryName>>("heat_flux_boundaries");
142  const auto & boundary_heat_fluxes =
143  getParam<std::vector<MooseFunctorName>>("boundary_heat_fluxes");
144  // Optimization if all the same
145  if (std::set<MooseFunctorName>(boundary_heat_fluxes.begin(), boundary_heat_fluxes.end())
146  .size() == 1 &&
147  heat_flux_boundaries.size() > 1)
148  {
149  params.set<std::vector<BoundaryName>>("boundary") = heat_flux_boundaries;
150  params.set<MooseFunctorName>("functor") = boundary_heat_fluxes[0];
151  getProblem().addFVBC(bc_type, prefix() + _temperature_name + "_heat_flux_bc_all", params);
152  }
153  else
154  {
155  for (const auto i : index_range(heat_flux_boundaries))
156  {
157  params.set<std::vector<BoundaryName>>("boundary") = {heat_flux_boundaries[i]};
158  params.set<MooseFunctorName>("functor") = boundary_heat_fluxes[i];
159  getProblem().addFVBC(bc_type,
160  prefix() + _temperature_name + "_heat_flux_bc_" +
161  heat_flux_boundaries[i],
162  params);
163  }
164  }
165  }
166  if (isParamValid("fixed_temperature_boundaries"))
167  {
168  const std::string bc_type = "FVFunctorDirichletBC";
169  InputParameters params = getFactory().getValidParams(bc_type);
170  params.set<NonlinearVariableName>("variable") = _temperature_name;
171 
172  const auto & temperature_boundaries =
173  getParam<std::vector<BoundaryName>>("fixed_temperature_boundaries");
174  const auto & boundary_temperatures =
175  getParam<std::vector<MooseFunctorName>>("boundary_temperatures");
176  // Optimization if all the same
177  if (std::set<MooseFunctorName>(boundary_temperatures.begin(), boundary_temperatures.end())
178  .size() == 1 &&
179  temperature_boundaries.size() > 1)
180  {
181  params.set<std::vector<BoundaryName>>("boundary") = temperature_boundaries;
182  params.set<MooseFunctorName>("functor") = boundary_temperatures[0];
183  getProblem().addFVBC(bc_type, prefix() + _temperature_name + "_dirichlet_bc_all", params);
184  }
185  else
186  {
187  for (const auto i : index_range(temperature_boundaries))
188  {
189  params.set<std::vector<BoundaryName>>("boundary") = {temperature_boundaries[i]};
190  params.set<MooseFunctorName>("functor") = boundary_temperatures[i];
191  getProblem().addFVBC(bc_type,
192  prefix() + _temperature_name + "_dirichlet_bc_" +
193  temperature_boundaries[i],
194  params);
195  }
196  }
197  }
198  if (isParamValid("fixed_convection_boundaries"))
199  {
200  const std::string bc_type = "FVFunctorConvectiveHeatFluxBC";
201  InputParameters params = getFactory().getValidParams(bc_type);
202  params.set<NonlinearVariableName>("variable") = _temperature_name;
203  params.set<bool>("is_solid") = true;
204  params.set<MooseFunctorName>("T_solid") = _temperature_name;
205 
206  const auto & convective_boundaries =
207  getParam<std::vector<BoundaryName>>("fixed_convection_boundaries");
208  const auto & boundary_T_fluid =
209  getParam<std::vector<MooseFunctorName>>("fixed_convection_T_fluid");
210  const auto & boundary_htc = getParam<std::vector<MooseFunctorName>>("fixed_convection_htc");
211  // Optimization if all the same
212  if (std::set<MooseFunctorName>(boundary_T_fluid.begin(), boundary_T_fluid.end()).size() == 1 &&
213  std::set<MooseFunctorName>(boundary_htc.begin(), boundary_htc.end()).size() == 1 &&
214  convective_boundaries.size() > 1)
215  {
216  params.set<std::vector<BoundaryName>>("boundary") = convective_boundaries;
217  params.set<MooseFunctorName>("T_bulk") = boundary_T_fluid[0];
218  params.set<MooseFunctorName>("heat_transfer_coefficient") = boundary_htc[0];
220  bc_type, prefix() + _temperature_name + "_fixed_convection_bc_all", params);
221  }
222  else
223  {
224  for (const auto i : index_range(convective_boundaries))
225  {
226  params.set<std::vector<BoundaryName>>("boundary") = {convective_boundaries[i]};
227  params.set<MooseFunctorName>("T_bulk") = boundary_T_fluid[i];
228  params.set<MooseFunctorName>("heat_transfer_coefficient") = boundary_htc[i];
229  getProblem().addFVBC(bc_type,
230  prefix() + _temperature_name + "_fixed_convection_bc_" +
231  convective_boundaries[i],
232  params);
233  }
234  }
235  }
236 }
237 
238 void
240 {
241  if (!shouldCreateVariable(_temperature_name, _blocks, /*error if aux*/ true))
242  {
243  reportPotentiallyMissedParameters({"system_names", "temperature_scaling"},
244  "MooseVariableFVReal");
245  return;
246  }
247 
248  const std::string variable_type = "MooseVariableFVReal";
249  InputParameters params = getFactory().getValidParams(variable_type);
250  assignBlocks(params, _blocks);
251  params.set<std::vector<Real>>("scaling") = {getParam<Real>("temperature_scaling")};
252  params.set<SolverSystemName>("solver_sys") = getSolverSystem(_temperature_name);
253 
254  getProblem().addVariable(variable_type, _temperature_name, params);
255 }
std::string prefix() const
bool parsesToReal(const std::string &input)
virtual void initializePhysicsAdditional() override
void assignBlocks(InputParameters &params, const std::vector< SubdomainName > &blocks) const
bool shouldCreateVariable(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool error_if_aux)
Factory & getFactory()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
virtual void needFV() override
T & set(const std::string &name, bool quiet_mode=false)
static InputParameters validParams()
InputParameters getValidParams(const std::string &name) const
Base class to host common parameters and attributes to all Physics solving the heat conduction equati...
bool shouldCreateTimeDerivative(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool error_if_already_defined) const
std::vector< SubdomainName > _blocks
void checkParamsBothSetOrNotSet(const std::string &param1, const std::string &param2) const
void addRequiredParam(const std::string &name, const std::string &doc_string)
bool isParamValid(const std::string &name) const
virtual void addFVKernels() override
virtual FEProblemBase & getProblem()
const SolverSystemName & getSolverSystem(unsigned int variable_index) const
virtual void addFVBCs() override
virtual void addSolverVariables() override
bool hasPostprocessorValueByName(const PostprocessorName &name) const
const T & getParam(const std::string &name) const
void paramError(const std::string &param, Args... args) const
registerPhysicsBaseTasks("HeatTransferApp", HeatConductionFV)
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters &params)
HeatConductionFV(const InputParameters &parameters)
static InputParameters validParams()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
registerMooseAction("HeatTransferApp", HeatConductionFV, "add_fv_kernel")
void addClassDescription(const std::string &doc_string)
const InputParameters & parameters() const
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
void reportPotentiallyMissedParameters(const std::vector< std::string > &param_names, const std::string &object_type) const
const VariableName & _temperature_name
Name of the temperature variable.
void applyParameter(const InputParameters &common, const std::string &common_name, bool allow_private=false, bool override_default=false)
void checkSecondParamNotSetIfFirstOneSet(const std::string &param1, const std::string &param2) const
virtual void addFVKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
virtual void addFVBC(const std::string &fv_bc_name, const std::string &name, InputParameters &parameters)
auto index_range(const T &sizable)
Creates all the objects needed to solve the heat conduction equations with a finite volume discretiza...
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)