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