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