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 "WCNSFVFluidHeatTransferPhysics.h"
11 : #include "WCNSFVFlowPhysics.h"
12 : #include "NSFVBase.h"
13 :
14 : registerNavierStokesPhysicsBaseTasks("NavierStokesApp", WCNSFVFluidHeatTransferPhysics);
15 : registerWCNSFVFluidHeatTransferPhysicsBaseTasks("NavierStokesApp", WCNSFVFluidHeatTransferPhysics);
16 :
17 : InputParameters
18 1249 : WCNSFVFluidHeatTransferPhysics::validParams()
19 : {
20 1249 : InputParameters params = WCNSFVFluidHeatTransferPhysicsBase::validParams();
21 1249 : params.transferParam<MooseEnum>(NSFVBase::validParams(), "energy_face_interpolation");
22 1249 : params.transferParam<Real>(NSFVBase::validParams(), "energy_scaling");
23 :
24 2498 : params.addParamNamesToGroup("energy_face_interpolation energy_scaling", "Numerical scheme");
25 1249 : return params;
26 0 : }
27 :
28 1249 : WCNSFVFluidHeatTransferPhysics::WCNSFVFluidHeatTransferPhysics(const InputParameters & parameters)
29 1249 : : WCNSFVFluidHeatTransferPhysicsBase(parameters)
30 : {
31 1247 : if (_solve_for_enthalpy)
32 0 : paramError("solve_for_enthalpy", "Enthalpy solve not supported at this time with Physics");
33 1247 : }
34 :
35 : void
36 1223 : WCNSFVFluidHeatTransferPhysics::addSolverVariables()
37 : {
38 : // For compatibility with Modules/NavierStokesFV syntax
39 1223 : if (!_has_energy_equation)
40 : return;
41 :
42 : // Dont add if the user already defined the variable
43 650 : if (!shouldCreateVariable(_fluid_temperature_name, _blocks, /*error if aux*/ true))
44 27 : reportPotentiallyMissedParameters({"system_names",
45 : "energy_scaling",
46 : "energy_face_interpolation",
47 : "energy_two_term_bc_expansion"},
48 : "INSFVEnergyVariable");
49 623 : else if (_define_variables)
50 : {
51 621 : auto params = getFactory().getValidParams("INSFVEnergyVariable");
52 621 : assignBlocks(params, _blocks);
53 1863 : params.set<std::vector<Real>>("scaling") = {getParam<Real>("energy_scaling")};
54 1863 : params.set<MooseEnum>("face_interp_method") = getParam<MooseEnum>("energy_face_interpolation");
55 621 : params.set<bool>("two_term_boundary_expansion") =
56 1242 : getParam<bool>("energy_two_term_bc_expansion");
57 1242 : params.set<SolverSystemName>("solver_sys") = getSolverSystem(_fluid_temperature_name);
58 621 : getProblem().addVariable("INSFVEnergyVariable", _fluid_temperature_name, params);
59 621 : }
60 : else
61 2 : paramError("fluid_temperature_variable",
62 2 : "Variable (" + _fluid_temperature_name +
63 : ") supplied to the WCNSFVFluidHeatTransferPhysics does not exist!");
64 : }
65 :
66 : void
67 163 : WCNSFVFluidHeatTransferPhysics::addEnergyTimeKernels()
68 : {
69 : std::string kernel_type =
70 163 : ((_compressibility == "weakly-compressible") ? "WCNSFVEnergyTimeDerivative"
71 239 : : "INSFVEnergyTimeDerivative");
72 : std::string kernel_name =
73 239 : prefix() + ((_compressibility == "weakly-compressible") ? "wcns" : "ins") + "_energy_time";
74 163 : if (_porous_medium_treatment)
75 : {
76 : kernel_type = "PINSFVEnergyTimeDerivative";
77 206 : kernel_name = prefix() + ((_compressibility == "weakly-compressible") ? "pwcns" : "pins") +
78 84 : "_energy_time";
79 : }
80 :
81 163 : InputParameters params = getFactory().getValidParams(kernel_type);
82 163 : assignBlocks(params, _blocks);
83 326 : params.set<NonlinearVariableName>("variable") = _fluid_temperature_name;
84 163 : params.set<MooseFunctorName>(NS::density) = _density_name;
85 326 : params.set<MooseFunctorName>(NS::time_deriv(NS::specific_enthalpy)) =
86 163 : NS::time_deriv(NS::specific_enthalpy);
87 163 : if (_compressibility == "weakly-compressible")
88 : {
89 348 : params.set<MooseFunctorName>(NS::time_deriv(NS::density)) = NS::time_deriv(_density_name);
90 174 : params.set<MooseFunctorName>(NS::specific_enthalpy) = NS::specific_enthalpy;
91 : }
92 163 : if (_porous_medium_treatment)
93 : {
94 84 : params.set<MooseFunctorName>(NS::porosity) =
95 168 : _flow_equations_physics->getPorosityFunctorName(/*smoothed=*/false);
96 168 : if (getProblem().hasFunctor(NS::time_deriv(_density_name),
97 : /*thread_id=*/0))
98 : {
99 252 : params.set<MooseFunctorName>(NS::time_deriv(NS::density)) = NS::time_deriv(_density_name);
100 168 : params.set<MooseFunctorName>(NS::specific_enthalpy) = NS::specific_enthalpy;
101 : }
102 :
103 84 : params.set<bool>("is_solid") = false;
104 : }
105 :
106 163 : getProblem().addFVKernel(kernel_type, kernel_name, params);
107 326 : }
108 :
109 : void
110 638 : WCNSFVFluidHeatTransferPhysics::addEnergyAdvectionKernels()
111 : {
112 638 : std::string kernel_type = "INSFVEnergyAdvection";
113 638 : std::string kernel_name = prefix() + "ins_energy_advection";
114 638 : if (_porous_medium_treatment)
115 : {
116 : kernel_type = "PINSFVEnergyAdvection";
117 657 : kernel_name = prefix() + "pins_energy_advection";
118 : }
119 :
120 638 : InputParameters params = getFactory().getValidParams(kernel_type);
121 1276 : params.set<NonlinearVariableName>("variable") = _fluid_temperature_name;
122 638 : assignBlocks(params, _blocks);
123 638 : params.set<MooseEnum>("velocity_interp_method") = _velocity_interpolation;
124 1276 : params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName();
125 1276 : params.set<MooseEnum>("advected_interp_method") =
126 1914 : getParam<MooseEnum>("energy_advection_interpolation");
127 :
128 638 : getProblem().addFVKernel(kernel_type, kernel_name, params);
129 1276 : }
130 :
131 : void
132 638 : WCNSFVFluidHeatTransferPhysics::addEnergyHeatConductionKernels()
133 : {
134 638 : const auto vector_conductivity = processThermalConductivity();
135 : const auto num_blocks = _thermal_conductivity_blocks.size();
136 : const auto num_used_blocks = num_blocks ? num_blocks : 1;
137 :
138 1283 : for (const auto block_i : make_range(num_used_blocks))
139 : {
140 651 : std::string block_name = "";
141 651 : if (num_blocks)
142 76 : block_name = Moose::stringify(_thermal_conductivity_blocks[block_i]);
143 : else
144 : block_name = "all";
145 :
146 651 : if (_porous_medium_treatment)
147 : {
148 : const auto kernel_type =
149 236 : vector_conductivity ? "PINSFVEnergyAnisotropicDiffusion" : "PINSFVEnergyDiffusion";
150 :
151 236 : InputParameters params = getFactory().getValidParams(kernel_type);
152 472 : params.set<NonlinearVariableName>("variable") = _fluid_temperature_name;
153 274 : const auto block_names = num_blocks ? _thermal_conductivity_blocks[block_i] : _blocks;
154 236 : assignBlocks(params, block_names);
155 434 : const auto conductivity_name = vector_conductivity ? NS::kappa : NS::k;
156 236 : params.set<MooseFunctorName>(conductivity_name) = _thermal_conductivity_name[block_i];
157 236 : params.set<MooseFunctorName>(NS::porosity) =
158 236 : _flow_equations_physics->getPorosityFunctorName(true);
159 472 : params.set<bool>("effective_conductivity") = getParam<bool>("effective_conductivity");
160 :
161 472 : getProblem().addFVKernel(
162 708 : kernel_type, prefix() + "pins_energy_diffusion_" + block_name, params);
163 236 : }
164 : else
165 : {
166 415 : const std::string kernel_type = "FVDiffusion";
167 415 : InputParameters params = getFactory().getValidParams(kernel_type);
168 830 : params.set<NonlinearVariableName>("variable") = _fluid_temperature_name;
169 : std::vector<SubdomainName> block_names =
170 415 : num_blocks ? _thermal_conductivity_blocks[block_i] : _blocks;
171 415 : assignBlocks(params, block_names);
172 830 : params.set<MooseFunctorName>("coeff") = _thermal_conductivity_name[block_i];
173 :
174 415 : getProblem().addFVKernel(
175 830 : kernel_type, prefix() + "ins_energy_diffusion_" + block_name, params);
176 415 : }
177 : }
178 632 : }
179 :
180 : void
181 225 : WCNSFVFluidHeatTransferPhysics::addEnergyAmbientConvection()
182 : {
183 225 : unsigned int num_convection_blocks = _ambient_convection_blocks.size();
184 : unsigned int num_used_blocks = num_convection_blocks ? num_convection_blocks : 1;
185 :
186 225 : const std::string kernel_type = "PINSFVEnergyAmbientConvection";
187 225 : InputParameters params = getFactory().getValidParams(kernel_type);
188 450 : params.set<NonlinearVariableName>("variable") = _fluid_temperature_name;
189 225 : params.set<MooseFunctorName>(NS::T_fluid) = _fluid_temperature_name;
190 225 : params.set<bool>("is_solid") = false;
191 :
192 450 : for (unsigned int block_i = 0; block_i < num_used_blocks; ++block_i)
193 : {
194 225 : std::string block_name = "";
195 225 : if (num_convection_blocks)
196 : {
197 19 : params.set<std::vector<SubdomainName>>("block") = _ambient_convection_blocks[block_i];
198 38 : block_name = Moose::stringify(_ambient_convection_blocks[block_i]);
199 : }
200 : else
201 : {
202 206 : assignBlocks(params, _blocks);
203 412 : block_name = std::to_string(block_i);
204 : }
205 :
206 450 : params.set<MooseFunctorName>("h_solid_fluid") = _ambient_convection_alpha[block_i];
207 225 : params.set<MooseFunctorName>(NS::T_solid) = _ambient_temperature[block_i];
208 :
209 675 : getProblem().addFVKernel(kernel_type, prefix() + "ambient_convection_" + block_name, params);
210 : }
211 450 : }
212 :
213 : void
214 124 : WCNSFVFluidHeatTransferPhysics::addEnergyExternalHeatSource()
215 : {
216 124 : const std::string kernel_type = "FVCoupledForce";
217 124 : InputParameters params = getFactory().getValidParams(kernel_type);
218 248 : params.set<NonlinearVariableName>("variable") = _fluid_temperature_name;
219 124 : assignBlocks(params, _blocks);
220 372 : params.set<MooseFunctorName>("v") = getParam<MooseFunctorName>("external_heat_source");
221 248 : params.set<Real>("coef") = getParam<Real>("external_heat_source_coeff");
222 :
223 248 : getProblem().addFVKernel(kernel_type, prefix() + "external_heat_source", params);
224 248 : }
225 :
226 : void
227 628 : WCNSFVFluidHeatTransferPhysics::addEnergyInletBC()
228 : {
229 628 : const auto & inlet_boundaries = _flow_equations_physics->getInletBoundaries();
230 : // These are parameter errors for now. If Components add boundaries to Physics, the error
231 : // may not be due to parameters anymore.
232 628 : if (inlet_boundaries.size() != _energy_inlet_types.size())
233 4 : paramError("energy_inlet_types",
234 2 : "Energy inlet types (size " + std::to_string(_energy_inlet_types.size()) +
235 2 : ") should be the same size as inlet_boundaries (size " +
236 2 : std::to_string(inlet_boundaries.size()) + ")");
237 626 : if (inlet_boundaries.size() != _energy_inlet_functors.size())
238 0 : paramError("energy_inlet_functors",
239 0 : "Energy inlet functors (size " + std::to_string(_energy_inlet_functors.size()) +
240 0 : ") should be the same size as inlet_boundaries (size " +
241 0 : std::to_string(inlet_boundaries.size()) + ")");
242 :
243 : unsigned int flux_bc_counter = 0;
244 1225 : for (const auto bc_ind : index_range(_energy_inlet_types))
245 : {
246 599 : if (_energy_inlet_types[bc_ind] == "fixed-temperature")
247 : {
248 356 : const std::string bc_type = "FVADFunctorDirichletBC";
249 356 : InputParameters params = getFactory().getValidParams(bc_type);
250 712 : params.set<NonlinearVariableName>("variable") = _fluid_temperature_name;
251 712 : params.set<MooseFunctorName>("functor") = _energy_inlet_functors[bc_ind];
252 1068 : params.set<std::vector<BoundaryName>>("boundary") = {inlet_boundaries[bc_ind]};
253 :
254 712 : getProblem().addFVBC(
255 356 : bc_type, _fluid_temperature_name + "_" + inlet_boundaries[bc_ind], params);
256 356 : }
257 243 : else if (_energy_inlet_types[bc_ind] == "heatflux")
258 : {
259 180 : const std::string bc_type = "FVFunctionNeumannBC";
260 180 : InputParameters params = getFactory().getValidParams(bc_type);
261 360 : params.set<NonlinearVariableName>("variable") = _fluid_temperature_name;
262 360 : params.set<FunctionName>("function") = _energy_inlet_functors[bc_ind];
263 540 : params.set<std::vector<BoundaryName>>("boundary") = {inlet_boundaries[bc_ind]};
264 :
265 360 : getProblem().addFVBC(
266 180 : bc_type, _fluid_temperature_name + "_" + inlet_boundaries[bc_ind], params);
267 180 : }
268 63 : else if (_energy_inlet_types[bc_ind] == "flux-mass" ||
269 27 : _energy_inlet_types[bc_ind] == "flux-velocity")
270 : {
271 63 : const std::string bc_type = "WCNSFVEnergyFluxBC";
272 63 : InputParameters params = getFactory().getValidParams(bc_type);
273 126 : params.set<NonlinearVariableName>("variable") = _fluid_temperature_name;
274 63 : const auto flux_inlet_directions = _flow_equations_physics->getFluxInletDirections();
275 63 : const auto flux_inlet_pps = _flow_equations_physics->getFluxInletPPs();
276 :
277 63 : if (flux_inlet_directions.size())
278 18 : params.set<Point>("direction") = flux_inlet_directions[flux_bc_counter];
279 63 : if (_energy_inlet_types[bc_ind] == "flux-mass")
280 : {
281 36 : params.set<PostprocessorName>("mdot_pp") = flux_inlet_pps[flux_bc_counter];
282 144 : params.set<PostprocessorName>("area_pp") = "area_pp_" + inlet_boundaries[bc_ind];
283 : }
284 : else
285 54 : params.set<PostprocessorName>("velocity_pp") = flux_inlet_pps[flux_bc_counter];
286 :
287 126 : params.set<PostprocessorName>("temperature_pp") = _energy_inlet_functors[bc_ind];
288 63 : params.set<MooseFunctorName>(NS::density) = _density_name;
289 63 : params.set<MooseFunctorName>(NS::cp) = _specific_heat_name;
290 63 : params.set<MooseFunctorName>(NS::T_fluid) = _fluid_temperature_name;
291 :
292 189 : for (const auto d : make_range(dimension()))
293 252 : params.set<MooseFunctorName>(NS::velocity_vector[d]) = _velocity_names[d];
294 :
295 189 : params.set<std::vector<BoundaryName>>("boundary") = {inlet_boundaries[bc_ind]};
296 :
297 126 : getProblem().addFVBC(
298 63 : bc_type, _fluid_temperature_name + "_" + inlet_boundaries[bc_ind], params);
299 63 : flux_bc_counter += 1;
300 63 : }
301 : }
302 626 : }
303 :
304 : void
305 626 : WCNSFVFluidHeatTransferPhysics::addEnergyWallBC()
306 : {
307 1252 : const auto & wall_boundaries = isParamSetByUser("energy_wall_boundaries")
308 1252 : ? getParam<std::vector<BoundaryName>>("energy_wall_boundaries")
309 626 : : _flow_equations_physics->getWallBoundaries();
310 626 : if (wall_boundaries.size() != _energy_wall_types.size())
311 4 : paramError("energy_wall_types",
312 2 : "Energy wall types (size " + std::to_string(_energy_wall_types.size()) +
313 2 : ") should be the same size as wall_boundaries (size " +
314 2 : std::to_string(wall_boundaries.size()) + ")");
315 624 : if (wall_boundaries.size() != _energy_wall_functors.size())
316 0 : paramError("energy_wall_functors",
317 0 : "Energy wall functors (size " + std::to_string(_energy_wall_functors.size()) +
318 0 : ") should be the same size as wall_boundaries (size " +
319 0 : std::to_string(wall_boundaries.size()) + ")");
320 :
321 1992 : for (unsigned int bc_ind = 0; bc_ind < _energy_wall_types.size(); ++bc_ind)
322 : {
323 1368 : if (_energy_wall_types[bc_ind] == "fixed-temperature")
324 : {
325 94 : const std::string bc_type = "FVADFunctorDirichletBC";
326 94 : InputParameters params = getFactory().getValidParams(bc_type);
327 188 : params.set<NonlinearVariableName>("variable") = _fluid_temperature_name;
328 188 : params.set<MooseFunctorName>("functor") = _energy_wall_functors[bc_ind];
329 282 : params.set<std::vector<BoundaryName>>("boundary") = {wall_boundaries[bc_ind]};
330 :
331 188 : getProblem().addFVBC(
332 94 : bc_type, _fluid_temperature_name + "_" + wall_boundaries[bc_ind], params);
333 94 : }
334 1274 : else if (_energy_wall_types[bc_ind] == "heatflux")
335 : {
336 1220 : const std::string bc_type = "FVFunctorNeumannBC";
337 1220 : InputParameters params = getFactory().getValidParams(bc_type);
338 2440 : params.set<NonlinearVariableName>("variable") = _fluid_temperature_name;
339 2440 : params.set<MooseFunctorName>("functor") = _energy_wall_functors[bc_ind];
340 3660 : params.set<std::vector<BoundaryName>>("boundary") = {wall_boundaries[bc_ind]};
341 :
342 2440 : getProblem().addFVBC(
343 1220 : bc_type, _fluid_temperature_name + "_" + wall_boundaries[bc_ind], params);
344 1220 : }
345 54 : else if (_energy_wall_types[bc_ind] == "convection")
346 : {
347 0 : const std::string bc_type = "FVFunctorConvectiveHeatFluxBC";
348 0 : InputParameters params = getFactory().getValidParams(bc_type);
349 0 : params.set<NonlinearVariableName>("variable") = _fluid_temperature_name;
350 0 : params.set<MooseFunctorName>("T_bulk") = _fluid_temperature_name;
351 0 : params.set<std::vector<BoundaryName>>("boundary") = {wall_boundaries[bc_ind]};
352 0 : params.set<bool>("is_solid") = false;
353 : const auto Tinf_htc_functors =
354 0 : MooseUtils::split(_energy_wall_functors[bc_ind], /*delimiter=*/":", /*max_count=*/1);
355 0 : if (Tinf_htc_functors.size() != 2)
356 0 : paramError("energy_wall_functors",
357 : "'convective' wall types require two functors specified as "
358 : "<Tinf_functor>:<htc_functor>.");
359 0 : params.set<MooseFunctorName>("T_solid") = Tinf_htc_functors[0];
360 0 : params.set<MooseFunctorName>("heat_transfer_coefficient") = Tinf_htc_functors[1];
361 :
362 0 : getProblem().addFVBC(
363 0 : bc_type, _fluid_temperature_name + "_" + wall_boundaries[bc_ind], params);
364 0 : }
365 : // We add this boundary condition here to facilitate the input of wall boundaries / functors for
366 : // energy. If there are too many turbulence options and this gets out of hand we will have to
367 : // move this to the turbulence Physics
368 54 : else if (_energy_wall_types[bc_ind] == "wallfunction")
369 : {
370 54 : if (!_turbulence_physics)
371 0 : paramError("coupled_turbulence_physics",
372 : "A coupled turbulence Physics was not found for defining the wall function "
373 0 : "boundary condition on boundary: " +
374 0 : wall_boundaries[bc_ind]);
375 54 : const std::string bc_type = "INSFVTurbulentTemperatureWallFunction";
376 54 : InputParameters params = getFactory().getValidParams(bc_type);
377 108 : params.set<NonlinearVariableName>("variable") = _fluid_temperature_name;
378 162 : params.set<std::vector<BoundaryName>>("boundary") = {wall_boundaries[bc_ind]};
379 54 : params.set<MooseEnum>("wall_treatment") =
380 162 : _turbulence_physics->turbulenceTemperatureWallTreatment();
381 54 : params.set<MooseFunctorName>("T_w") = _energy_wall_functors[bc_ind];
382 54 : params.set<MooseFunctorName>(NS::density) = _density_name;
383 54 : params.set<MooseFunctorName>(NS::mu) = _dynamic_viscosity_name;
384 162 : params.set<MooseFunctorName>(NS::TKE) = _turbulence_physics->tkeName();
385 54 : if (_thermal_conductivity_name.size() != 1)
386 0 : mooseError("Several anisotropic thermal conductivity (kappa) regions have been specified. "
387 : "Selecting the right kappa coefficient for the turbulence boundaries is not "
388 0 : "currently implemented.\nBoundaries:\n" +
389 0 : Moose::stringify(_turbulence_physics->turbulenceWalls()) +
390 0 : "\nKappa(s) specified:\n" + Moose::stringify(_thermal_conductivity_name));
391 54 : params.set<MooseFunctorName>(NS::kappa) = _thermal_conductivity_name[0];
392 54 : params.set<MooseFunctorName>(NS::cp) = _specific_heat_name;
393 216 : const std::string u_names[3] = {"u", "v", "w"};
394 162 : for (const auto d : make_range(dimension()))
395 216 : params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
396 : // Currently only Newton method for WCNSFVFluidHeatTransferPhysics
397 54 : params.set<bool>("newton_solve") = true;
398 162 : getProblem().addFVBC(bc_type, prefix() + "wallfunction_" + wall_boundaries[bc_ind], params);
399 270 : }
400 : else
401 0 : paramError(
402 0 : "energy_wall_types", _energy_wall_types[bc_ind], " wall type is currently unsupported.");
403 : }
404 624 : }
405 :
406 : void
407 624 : WCNSFVFluidHeatTransferPhysics::addEnergySeparatorBC()
408 : {
409 624 : if (_flow_equations_physics->getHydraulicSeparators().size())
410 : {
411 19 : const std::string bc_type = "INSFVScalarFieldSeparatorBC";
412 19 : InputParameters params = getFactory().getValidParams(bc_type);
413 38 : params.set<NonlinearVariableName>("variable") = _fluid_temperature_name;
414 38 : params.set<std::vector<BoundaryName>>("boundary") =
415 38 : _flow_equations_physics->getHydraulicSeparators();
416 38 : getProblem().addFVBC(bc_type, prefix() + _fluid_temperature_name + "_separators", params);
417 19 : }
418 624 : }
|