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  params.set<NonlinearVariableName>("variable") = _temperature_name;
82  params.set<MooseFunctorName>("v") = getParam<VariableName>("heat_source_var");
83  if (isParamValid("heat_source_blocks"))
84  params.set<std::vector<SubdomainName>>("block") =
85  getParam<std::vector<SubdomainName>>("heat_source_blocks");
86  else
87  assignBlocks(params, _blocks);
88  getProblem().addFVKernel(kernel_type, prefix() + _temperature_name + "_source", params);
89  }
90  if (isParamValid("heat_source_functor"))
91  {
92  const std::string kernel_type = "FVBodyForce";
93  InputParameters params = getFactory().getValidParams(kernel_type);
94  if (isParamValid("heat_source_blocks"))
95  params.set<std::vector<SubdomainName>>("block") =
96  getParam<std::vector<SubdomainName>>("heat_source_blocks");
97  else
98  assignBlocks(params, _blocks);
99  params.set<NonlinearVariableName>("variable") = _temperature_name;
100  const auto & functor_name = getParam<MooseFunctorName>("heat_source_functor");
101  if (MooseUtils::parsesToReal(functor_name))
102  params.set<Real>("value") = std::stod(functor_name);
103  else if (getProblem().hasFunction(functor_name))
104  params.set<FunctionName>("function") = functor_name;
105  else if (getProblem().hasPostprocessorValueByName(functor_name))
106  params.set<PostprocessorName>("postprocessor") = functor_name;
107  else
108  paramError("heat_source_functor",
109  "Unsupported functor type. Consider using 'heat_source_var'.");
110  getProblem().addFVKernel(kernel_type, prefix() + _temperature_name + "_source_functor", params);
111  }
112  if (shouldCreateTimeDerivative(_temperature_name, _blocks, /*error if already defined*/ false))
113  {
114  const bool use_functors =
115  isParamValid("density_functor") || isParamValid("specific_heat_functor");
116  const std::string kernel_type =
117  use_functors ? "FVFunctorHeatConductionTimeDerivative" : "FVHeatConductionTimeDerivative";
118  InputParameters params = getFactory().getValidParams(kernel_type);
119  assignBlocks(params, _blocks);
120  params.set<NonlinearVariableName>("variable") = _temperature_name;
121  if (use_functors)
122  {
123  params.set<MooseFunctorName>("specific_heat") =
124  getParam<MooseFunctorName>("specific_heat_functor");
125  params.set<MooseFunctorName>("density") = getParam<MooseFunctorName>("density_functor");
126  }
127  else
128  {
129  params.applyParameter(parameters(), "specific_heat");
130  params.set<MaterialPropertyName>("density_name") = getParam<MaterialPropertyName>("density");
131  }
132  getProblem().addFVKernel(kernel_type, prefix() + _temperature_name + "_time", params);
133  }
134 }
135 
136 void
138 {
139  // We dont need to add anything for insulated boundaries, 0 flux is the default boundary condition
140  if (isParamValid("heat_flux_boundaries"))
141  {
142  const std::string bc_type = "FVFunctorNeumannBC";
143  InputParameters params = getFactory().getValidParams(bc_type);
144  params.set<NonlinearVariableName>("variable") = _temperature_name;
145 
146  const auto & heat_flux_boundaries = getParam<std::vector<BoundaryName>>("heat_flux_boundaries");
147  const auto & boundary_heat_fluxes =
148  getParam<std::vector<MooseFunctorName>>("boundary_heat_fluxes");
149  // Optimization if all the same
150  if (std::set<MooseFunctorName>(boundary_heat_fluxes.begin(), boundary_heat_fluxes.end())
151  .size() == 1 &&
152  heat_flux_boundaries.size() > 1)
153  {
154  params.set<std::vector<BoundaryName>>("boundary") = heat_flux_boundaries;
155  params.set<MooseFunctorName>("functor") = boundary_heat_fluxes[0];
156  getProblem().addFVBC(bc_type, prefix() + _temperature_name + "_heat_flux_bc_all", params);
157  }
158  else
159  {
160  for (const auto i : index_range(heat_flux_boundaries))
161  {
162  params.set<std::vector<BoundaryName>>("boundary") = {heat_flux_boundaries[i]};
163  params.set<MooseFunctorName>("functor") = boundary_heat_fluxes[i];
164  getProblem().addFVBC(bc_type,
165  prefix() + _temperature_name + "_heat_flux_bc_" +
166  heat_flux_boundaries[i],
167  params);
168  }
169  }
170  }
171  if (isParamValid("fixed_temperature_boundaries"))
172  {
173  const std::string bc_type = "FVFunctorDirichletBC";
174  InputParameters params = getFactory().getValidParams(bc_type);
175  params.set<NonlinearVariableName>("variable") = _temperature_name;
176 
177  const auto & temperature_boundaries =
178  getParam<std::vector<BoundaryName>>("fixed_temperature_boundaries");
179  const auto & boundary_temperatures =
180  getParam<std::vector<MooseFunctorName>>("boundary_temperatures");
181  // Optimization if all the same
182  if (std::set<MooseFunctorName>(boundary_temperatures.begin(), boundary_temperatures.end())
183  .size() == 1 &&
184  temperature_boundaries.size() > 1)
185  {
186  params.set<std::vector<BoundaryName>>("boundary") = temperature_boundaries;
187  params.set<MooseFunctorName>("functor") = boundary_temperatures[0];
188  getProblem().addFVBC(bc_type, prefix() + _temperature_name + "_dirichlet_bc_all", params);
189  }
190  else
191  {
192  for (const auto i : index_range(temperature_boundaries))
193  {
194  params.set<std::vector<BoundaryName>>("boundary") = {temperature_boundaries[i]};
195  params.set<MooseFunctorName>("functor") = boundary_temperatures[i];
196  getProblem().addFVBC(bc_type,
197  prefix() + _temperature_name + "_dirichlet_bc_" +
198  temperature_boundaries[i],
199  params);
200  }
201  }
202  }
203  if (isParamValid("fixed_convection_boundaries"))
204  {
205  const std::string bc_type = "FVFunctorConvectiveHeatFluxBC";
206  InputParameters params = getFactory().getValidParams(bc_type);
207  params.set<NonlinearVariableName>("variable") = _temperature_name;
208  params.set<bool>("is_solid") = true;
209  params.set<MooseFunctorName>("T_solid") = _temperature_name;
210 
211  const auto & convective_boundaries =
212  getParam<std::vector<BoundaryName>>("fixed_convection_boundaries");
213  const auto & boundary_T_fluid =
214  getParam<std::vector<MooseFunctorName>>("fixed_convection_T_fluid");
215  const auto & boundary_htc = getParam<std::vector<MooseFunctorName>>("fixed_convection_htc");
216  // Optimization if all the same
217  if (std::set<MooseFunctorName>(boundary_T_fluid.begin(), boundary_T_fluid.end()).size() == 1 &&
218  std::set<MooseFunctorName>(boundary_htc.begin(), boundary_htc.end()).size() == 1 &&
219  convective_boundaries.size() > 1)
220  {
221  params.set<std::vector<BoundaryName>>("boundary") = convective_boundaries;
222  params.set<MooseFunctorName>("T_bulk") = boundary_T_fluid[0];
223  params.set<MooseFunctorName>("heat_transfer_coefficient") = boundary_htc[0];
225  bc_type, prefix() + _temperature_name + "_fixed_convection_bc_all", params);
226  }
227  else
228  {
229  for (const auto i : index_range(convective_boundaries))
230  {
231  params.set<std::vector<BoundaryName>>("boundary") = {convective_boundaries[i]};
232  params.set<MooseFunctorName>("T_bulk") = boundary_T_fluid[i];
233  params.set<MooseFunctorName>("heat_transfer_coefficient") = boundary_htc[i];
234  getProblem().addFVBC(bc_type,
235  prefix() + _temperature_name + "_fixed_convection_bc_" +
236  convective_boundaries[i],
237  params);
238  }
239  }
240  }
241 }
242 
243 void
245 {
246  if (!shouldCreateVariable(_temperature_name, _blocks, /*error if aux*/ true))
247  {
248  reportPotentiallyMissedParameters({"system_names", "temperature_scaling"},
249  "MooseVariableFVReal");
250  return;
251  }
252 
253  const std::string variable_type = "MooseVariableFVReal";
254  InputParameters params = getFactory().getValidParams(variable_type);
255  assignBlocks(params, _blocks);
256  params.set<std::vector<Real>>("scaling") = {getParam<Real>("temperature_scaling")};
257  params.set<SolverSystemName>("solver_sys") = getSolverSystem(_temperature_name);
258 
259  getProblem().addVariable(variable_type, _temperature_name, params);
260 }
std::string prefix() const
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 paramError(const std::string &param, Args... args) const
const T & getParam(const std::string &name) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
virtual void needFV() override
const InputParameters & parameters() const
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...
void reportPotentiallyMissedParameters(const std::vector< std::string > &param_names, const std::string &object_type, const std::string &object_name="") const
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)
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
void applyParameter(const InputParameters &common, const std::string &common_name, bool allow_private=false)
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)
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
bool isParamValid(const std::string &name) const
const VariableName & _temperature_name
Name of the temperature variable.
void checkSecondParamNotSetIfFirstOneSet(const std::string &param1, const std::string &param2) const
bool parsesToReal(const std::string &input, Real *parsed_real)
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)