https://mooseframework.inl.gov
Loading...
Searching...
No Matches
WCNSLinearFVFluidHeatTransferPhysics.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
11#include "WCNSFVFlowPhysics.h"
13#include "NSFVBase.h"
14
18registerMooseAction("NavierStokesApp", WCNSLinearFVFluidHeatTransferPhysics, "add_aux_variable");
19registerMooseAction("NavierStokesApp", WCNSLinearFVFluidHeatTransferPhysics, "add_aux_kernel");
20
23{
25 params.addParam<bool>(
26 "use_nonorthogonal_correction",
27 true,
28 "Whether to use a non-orthogonal correction. This can potentially slow down convergence "
29 ", but reduces numerical dispersion on non-orthogonal meshes. Can be safely turned off on "
30 "orthogonal meshes.");
31 params.set<std::vector<SolverSystemName>>("system_names") = {"energy_system"};
32
33 // We could split between discretization and solver here.
34 params.addParamNamesToGroup("use_nonorthogonal_correction", "Numerical scheme");
35
36 // Not needed
37 params.suppressParameter<bool>("add_energy_equation");
38 params.suppressParameter<MooseEnum>("preconditioning");
39
40 return params;
41}
42
44 const InputParameters & parameters)
46{
48 if (!_porous_medium_treatment && isParamSetByUser("effective_conductivity"))
49 paramError("effective_conductivity",
50 "Only applies with the porous medium treatment of the flow physics");
51}
52
53void
55{
56 // For compatibility with Modules/NavierStokesFV syntax
58 return;
59
61
62 // Dont add if the user already defined the variable
63 if (!shouldCreateVariable(variable_name, _blocks, /*error if aux*/ true))
64 reportPotentiallyMissedParameters({"system_names"}, "MooseLinearVariableFVReal");
65 else if (_define_variables)
66 {
67 const auto var_type = "MooseLinearVariableFVReal";
68 auto params = getFactory().getValidParams(var_type);
69 addSharedSolverVariable(var_type, variable_name, params);
70 }
71 else
72 paramError(_solve_for_enthalpy ? "solve_for_enthalpy" : "fluid_temperature_variable",
73 "Variable (" + variable_name +
74 ") supplied to the WCNSLinearFVFluidHeatTransferPhysics does not exist!");
75}
76
77void
79{
80 std::string kernel_type = "LinearFVTimeDerivative";
81 std::string kernel_name = prefix() + "ins_energy_time";
82
83 InputParameters params = getFactory().getValidParams(kernel_type);
84 params.set<LinearVariableName>("variable") =
86 assignBlocks(params, _blocks);
87 const MooseFunctorName factor = _solve_for_enthalpy ? _density_name : "rho_cp";
88 // Only the fluid fraction of the volume stores energy
89 params.set<MooseFunctorName>("factor") =
92 _flow_equations_physics->getPorosityFunctorName(/*smoothed=*/false), factor)
93 : factor;
94
95 getProblem().addLinearFVKernel(kernel_type, kernel_name, params);
96}
97
98void
100{
101 std::string kernel_type = "LinearFVEnergyAdvection";
102 std::string kernel_name = prefix() + "ins_energy_advection";
103
104 InputParameters params = getFactory().getValidParams(kernel_type);
105 assignBlocks(params, _blocks);
106 if (!getParam<bool>("solve_for_enthalpy"))
107 {
108 params.set<LinearVariableName>("variable") = _fluid_temperature_name;
109 params.set<MooseEnum>("advected_quantity") = "temperature";
110 if (!MooseUtils::isFloat(_specific_heat_name))
111 paramError("specific_heat", "Must be a Real number. Functors not supported at this time");
112 params.set<Real>("cp") = std::atof(_specific_heat_name.c_str());
113 }
114 else
115 params.set<LinearVariableName>("variable") = _fluid_enthalpy_name;
116 params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName();
117 params.set<MooseEnum>("advected_interp_method") =
118 getParam<MooseEnum>("energy_advection_interpolation");
119
120 getProblem().addLinearFVKernel(kernel_type, kernel_name, params);
121}
122
123void
125{
126 const auto num_blocks = _thermal_conductivity_blocks.size();
127 const auto num_used_blocks = num_blocks ? num_blocks : 1;
128
129 for (const auto block_i : make_range(num_used_blocks))
130 {
131 std::string block_name = "";
132 if (num_blocks)
133 block_name = Moose::stringify(_thermal_conductivity_blocks[block_i]);
134 else
135 block_name = "all";
136
137 const std::string kernel_type = "LinearFVDiffusion";
138 InputParameters params = getFactory().getValidParams(kernel_type);
139 const auto th_cond_name =
141 params.set<LinearVariableName>("variable") =
143 const MooseFunctorName diffusion_coeff = th_cond_name + (_solve_for_enthalpy ? "_by_cp" : "");
144 // Unless the conductivity is an effective one, only the fluid fraction conducts
145 params.set<MooseFunctorName>("diffusion_coeff") =
146 (_porous_medium_treatment && !getParam<bool>("effective_conductivity"))
149 diffusion_coeff)
150 : diffusion_coeff;
151 std::vector<SubdomainName> block_names =
152 num_blocks ? _thermal_conductivity_blocks[block_i] : _blocks;
153 assignBlocks(params, block_names);
154 // NOTE: vector conductivities not supported at this time
155 bool has_vector = processThermalConductivity();
156 if (has_vector)
157 paramError("thermal_conductivity",
158 "Vector thermal conductivities not currently supported with the linear finite "
159 "volume discretization");
160
161 params.set<bool>("use_nonorthogonal_correction") =
162 getParam<bool>("use_nonorthogonal_correction");
163
165 kernel_type, prefix() + "ins_energy_diffusion_" + block_name, params);
166 }
167}
168
169void
171{
172 unsigned int num_convection_blocks = _ambient_convection_blocks.size();
173 unsigned int num_used_blocks = num_convection_blocks ? num_convection_blocks : 1;
174
175 // When solving for enthalpy, the fluid temperature in the exchange term is linearized with
176 // dT/dh = 1/cp so the term stays implicit in the solved variable
177 const std::string kernel_type = _solve_for_enthalpy ? "LinearFVEnthalpyVolumetricHeatTransfer"
178 : "LinearFVVolumetricHeatTransfer";
179 InputParameters params = getFactory().getValidParams(kernel_type);
180 params.set<LinearVariableName>("variable") =
182 params.set<VariableName>(NS::T_fluid) = _fluid_temperature_name;
183 params.set<bool>("is_solid") = false;
185 params.set<MooseFunctorName>(NS::cp) = _specific_heat_name;
186
187 for (unsigned int block_i = 0; block_i < num_used_blocks; ++block_i)
188 {
189 std::string block_name = "";
190 if (num_convection_blocks)
191 {
192 params.set<std::vector<SubdomainName>>("block") = _ambient_convection_blocks[block_i];
193 block_name = Moose::stringify(_ambient_convection_blocks[block_i]);
194 }
195 else
196 {
197 assignBlocks(params, _blocks);
198 block_name = std::to_string(block_i);
199 }
200
201 params.set<MooseFunctorName>("h_solid_fluid") = _ambient_convection_alpha[block_i];
202 params.set<VariableName>(NS::T_solid) = _ambient_temperature[block_i];
203
205 kernel_type, prefix() + "ambient_convection_" + block_name, params);
206 }
207}
208
209void
211{
212 const std::string kernel_type = "LinearFVSource";
213 InputParameters params = getFactory().getValidParams(kernel_type);
214 params.set<LinearVariableName>("variable") =
216 assignBlocks(params, _blocks);
217 params.set<MooseFunctorName>("source_density") =
218 getParam<MooseFunctorName>("external_heat_source");
219 params.set<MooseFunctorName>("scaling_factor") =
220 std::to_string(getParam<Real>("external_heat_source_coeff"));
221
222 getProblem().addLinearFVKernel(kernel_type, prefix() + "external_heat_source", params);
223}
224
225void
227{
229 {
230 // Dont add if the user already defined the variable
232 /*error_if_aux=*/false))
234 getProblem().getVariable(0, _fluid_temperature_name).blocks());
235 else if (_define_variables)
236 {
237 const auto var_type = "MooseLinearVariableFVReal";
238 auto params = getFactory().getValidParams(var_type);
240 }
241 else
242 paramError("fluid_temperature_variable",
243 "Variable (" + _fluid_temperature_name +
244 ") supplied to the WCNSLinearFVFluidHeatTransferPhysics does not exist!");
245 }
246}
247
248void
250{
252 {
253 // Keep temperature updated
254 const std::string kernel_type = "FunctorAux";
255 InputParameters params = getFactory().getValidParams(kernel_type);
256 params.set<AuxVariableName>("variable") = _fluid_temperature_name;
257 assignBlocks(params, _blocks);
258 params.set<MooseFunctorName>("functor") = "T_from_p_h";
259 params.set<ExecFlagEnum>("execute_on") = {EXEC_NONLINEAR};
260 getProblem().addAuxKernel(kernel_type, prefix() + "update_temperature", params);
261 }
262}
263
264void
266{
267 const auto & inlet_boundaries = _flow_equations_physics->getInletBoundaries();
268 // These are parameter errors for now. If Components add boundaries to Physics, the error
269 // may not be due to parameters anymore.
270 if (inlet_boundaries.size() != _energy_inlet_types.size())
271 paramError("energy_inlet_types",
272 "Energy inlet types (size " + std::to_string(_energy_inlet_types.size()) +
273 ") should be the same size as inlet_boundaries (size " +
274 std::to_string(inlet_boundaries.size()) + ")");
275 if (inlet_boundaries.size() != _energy_inlet_functors.size())
276 paramError("energy_inlet_functors",
277 "Energy inlet functors (size " + std::to_string(_energy_inlet_functors.size()) +
278 ") should be the same size as inlet_boundaries (size " +
279 std::to_string(inlet_boundaries.size()) + ")");
280
281 for (const auto bc_ind : index_range(_energy_inlet_types))
282 {
283 if (_energy_inlet_types[bc_ind] == "fixed-temperature")
284 {
285 const std::string bc_type = "LinearFVAdvectionDiffusionFunctorDirichletBC";
286 InputParameters params = getFactory().getValidParams(bc_type);
287 params.set<LinearVariableName>("variable") = _fluid_temperature_name;
288 params.set<MooseFunctorName>("functor") = _energy_inlet_functors[bc_ind];
289 params.set<std::vector<BoundaryName>>("boundary") = {inlet_boundaries[bc_ind]};
290
292 bc_type, _fluid_temperature_name + "_" + inlet_boundaries[bc_ind], params);
293
294 // Boundary condition on temperature must be forwarded to enthalpy
296 {
297 params.set<LinearVariableName>("variable") = _fluid_enthalpy_name;
298 params.set<MooseFunctorName>("functor") = "h_from_p_T";
300 bc_type, _fluid_enthalpy_name + "_" + inlet_boundaries[bc_ind], params);
301 }
302 }
303 else if (_energy_inlet_types[bc_ind] == "heatflux")
304 paramError("energy_inlet_types", "Heat flux inlet boundary conditions not yet supported");
305 else if (_energy_inlet_types[bc_ind] == "flux-mass" ||
306 _energy_inlet_types[bc_ind] == "flux-velocity")
307 paramError("energy_inlet_types", "Flux inlet boundary conditions not yet supported");
308 }
309}
310
311void
313{
314 const auto & wall_boundaries = isParamSetByUser("energy_wall_boundaries")
315 ? getParam<std::vector<BoundaryName>>("energy_wall_boundaries")
317 if (wall_boundaries.size() != _energy_wall_types.size())
318 paramError("energy_wall_types",
319 "Energy wall types (size " + std::to_string(_energy_wall_types.size()) +
320 ") should be the same size as wall_boundaries (size " +
321 std::to_string(wall_boundaries.size()) + ")");
322 if (wall_boundaries.size() != _energy_wall_functors.size())
323 paramError("energy_wall_functors",
324 "Energy wall functors (size " + std::to_string(_energy_wall_functors.size()) +
325 ") should be the same size as wall_boundaries (size " +
326 std::to_string(wall_boundaries.size()) + ")");
327
328 for (unsigned int bc_ind = 0; bc_ind < _energy_wall_types.size(); ++bc_ind)
329 {
330 if (_energy_wall_types[bc_ind] == "fixed-temperature")
331 {
332 const std::string bc_type = "LinearFVAdvectionDiffusionFunctorDirichletBC";
333 InputParameters params = getFactory().getValidParams(bc_type);
334 params.set<LinearVariableName>("variable") = _fluid_temperature_name;
335 params.set<MooseFunctorName>("functor") = _energy_wall_functors[bc_ind];
336 params.set<std::vector<BoundaryName>>("boundary") = {wall_boundaries[bc_ind]};
337
339 bc_type, _fluid_temperature_name + "_" + wall_boundaries[bc_ind], params);
340
341 // Boundary condition on temperature must be forwarded to enthalpy
343 {
344 params.set<LinearVariableName>("variable") = _fluid_enthalpy_name;
345 params.set<MooseFunctorName>("functor") = "h_from_p_T";
347 bc_type, _fluid_enthalpy_name + "_" + wall_boundaries[bc_ind], params);
348 }
349 }
350 else if (_energy_wall_types[bc_ind] == "heatflux")
351 {
352 const std::string bc_type = "LinearFVAdvectionDiffusionFunctorNeumannBC";
353 InputParameters params = getFactory().getValidParams(bc_type);
355 params.set<LinearVariableName>("variable") = var_name;
356 params.set<MooseFunctorName>("functor") = _energy_wall_functors[bc_ind];
357 params.set<std::vector<BoundaryName>>("boundary") = {wall_boundaries[bc_ind]};
358
360 bc_type, var_name + "_heatflux_" + wall_boundaries[bc_ind], params);
361 }
362 else if (_energy_wall_types[bc_ind] == "convection")
363 {
364 const std::string bc_type = "LinearFVConvectiveHeatTransferBC";
365 InputParameters params = getFactory().getValidParams(bc_type);
366 params.set<LinearVariableName>("variable") =
368 params.set<MooseFunctorName>(NS::T_fluid) = _fluid_temperature_name;
369 const auto Tinf_htc_functors =
370 MooseUtils::split(_energy_wall_functors[bc_ind], /*delimiter=*/":", /*max_count=*/1);
371 if (Tinf_htc_functors.size() != 2)
372 paramError("energy_wall_functors",
373 "'convection' wall types require two functors specified as "
374 "<Tinf_functor>:<htc_functor>.");
375 params.set<MooseFunctorName>(NS::T_solid) = Tinf_htc_functors[0];
376 params.set<MooseFunctorName>("h") = Tinf_htc_functors[1];
377 params.set<std::vector<BoundaryName>>("boundary") = {wall_boundaries[bc_ind]};
378
380 bc_type,
382 wall_boundaries[bc_ind],
383 params);
384 }
385 else
387 "energy_wall_types", _energy_wall_types[bc_ind], " wall type is currently unsupported.");
388 }
389}
390
391void
393{
394 const auto & outlet_boundaries = _flow_equations_physics->getOutletBoundaries();
395 if (outlet_boundaries.empty())
396 return;
397
398 for (const auto & outlet_bdy : outlet_boundaries)
399 {
400 const std::string bc_type = "LinearFVAdvectionDiffusionOutflowBC";
402 InputParameters params = getFactory().getValidParams(bc_type);
403 params.set<std::vector<BoundaryName>>("boundary") = {outlet_bdy};
404 params.set<bool>("use_two_term_expansion") = getParam<bool>("energy_two_term_bc_expansion");
405
406 params.set<LinearVariableName>("variable") = variable_name;
407 getProblem().addLinearFVBC(bc_type, variable_name + "_" + outlet_bdy, params);
408 }
409}
410
411void
413{
414 // For compatibility with Modules/NavierStokesFV syntax
416 return;
417
418 // Note that this material choice would not work for Newton-INSFV + solve_for_enthalpy
419 const auto object_type = "LinearFVEnthalpyFunctorMaterial";
420
421 InputParameters params = getFactory().getValidParams(object_type);
422 assignBlocks(params, _blocks);
423 params.set<MooseFunctorName>(NS::pressure) = _flow_equations_physics->getPressureName();
424 params.set<MooseFunctorName>(NS::T_fluid) = _fluid_temperature_name;
425 params.set<MooseFunctorName>(NS::specific_enthalpy) = _fluid_enthalpy_name;
427 params.set<UserObjectName>(NS::fluid) = getParam<UserObjectName>(NS::fluid);
428
430 {
432 {
433 if (!getProblem().hasFunctor("h_from_p_T_functor", 0) ||
434 !getProblem().hasFunctor("T_from_p_h_functor", 0))
436 "Either 'fp' must be specified or the 'h_from_p_T_functor' and "
437 "'T_from_p_h_functor' must be defined outside the Physics");
438 // Note: we could define those in the Physics if cp is constant
439 params.set<MooseFunctorName>("h_from_p_T_functor") = "h_from_p_T_functor";
440 params.set<MooseFunctorName>("T_from_p_h_functor") = "T_from_p_h_functor";
441 }
442 }
443 // If we are solving for enthalpy, we need this to compute temperature from p & h
444 // Else we don't really need it
446 getProblem().addMaterial(object_type, prefix() + "enthalpy_material", params);
447
450 /*use ad*/ false);
451}
const ExecFlagType EXEC_NONLINEAR
registerNavierStokesPhysicsBaseTasks("NavierStokesApp", WCNSLinearFVFluidHeatTransferPhysics)
registerMooseAction("NavierStokesApp", WCNSLinearFVFluidHeatTransferPhysics, "add_aux_variable")
registerWCNSFVFluidHeatTransferPhysicsBaseTasks("NavierStokesApp", WCNSLinearFVFluidHeatTransferPhysics)
virtual void addLinearFVKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
virtual void addMaterial(const std::string &material_name, const std::string &name, InputParameters &parameters)
virtual void addAuxKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
virtual void addLinearFVBC(const std::string &fv_bc_name, const std::string &name, InputParameters &parameters)
InputParameters getValidParams(const std::string &name) const
void checkSecondParamSetOnlyIfFirstOneTrue(const std::string &param1, const std::string &param2) const
void suppressParameter(const std::string &name)
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
void paramError(const std::string &param, Args... args) const
bool isParamSetByUser(const std::string &name) const
bool isParamValid(const std::string &name) const
unsigned int size() const
bool _define_variables
Whether to define variables if they do not exist.
MooseFunctorName addPorosityScaledFunctor(const MooseFunctorName &porosity, const MooseFunctorName &functor)
Add, if absent, a non-AD functor material defining the product of a porosity and another functor on t...
void addSharedAuxVariable(const std::string &var_type, const VariableName &var_name, const InputParameters &params)
virtual FEProblemBase & getProblem()
Factory & getFactory()
bool checkBlockRestrictionIdentical(const std::string &object_name, const std::vector< SubdomainName > &blocks, const bool error_if_not_identical=true) const
void assignBlocks(InputParameters &params, const std::vector< SubdomainName > &blocks) const
void reportPotentiallyMissedParameters(const std::vector< std::string > &param_names, const std::string &object_type, const std::string &object_name="") const
std::string prefix() const
bool variableExists(const VariableName &var_name, bool error_if_aux) const
void addSharedSolverVariable(const std::string &var_type, const VariableName &var_name, InputParameters params)
bool shouldCreateVariable(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool error_if_aux)
std::vector< SubdomainName > _blocks
const std::vector< SubdomainName > & blocks() const
const WCNSFVFlowPhysicsBase * _flow_equations_physics
Flow physics.
bool _has_turbulence_model
Because of the Modules/navierStokesFV syntax, a turbulence physics often exists without a model we sa...
const bool _porous_medium_treatment
Switch to show if porous medium treatment is requested or not.
const MooseFunctorName _density_name
Name of the density material property.
const NonlinearVariableName & getPressureName() const
const std::vector< BoundaryName > & getWallBoundaries() const
Get the wall boundaries.
const UserObjectName & rhieChowUOName() const
Return the name of the Rhie Chow user object.
const std::vector< BoundaryName > & getOutletBoundaries() const
Get the outlet boundaries.
const std::vector< BoundaryName > & getInletBoundaries() const
Get the inlet boundaries.
MooseFunctorName getPorosityFunctorName(const bool smoothed) const
Creates all the objects needed to solve the Navier Stokes energy equation.
std::vector< MooseFunctorName > _energy_inlet_functors
Functors describing the inlet boundary values. See energy_inlet_types for what the functors actually ...
std::vector< MooseFunctorName > _energy_wall_functors
Functors describing the wall boundary values. See energy_wall_types for what the functors actually re...
MooseFunctorName _specific_heat_name
Name of the specific heat material property.
std::vector< MooseFunctorName > _ambient_convection_alpha
Name of the ambient convection heat transfer coefficients for each block-group.
const VariableName _fluid_enthalpy_name
Name of the fluid specific enthalpy.
bool processThermalConductivity()
Process thermal conductivity (multiple functor input options are available).
std::vector< std::vector< SubdomainName > > _ambient_convection_blocks
Vector of subdomain groups where we want to have different ambient convection.
VariableName _fluid_temperature_name
Fluid temperature name.
void defineEffectiveThermalDiffusionCoeffFunctors(const bool use_ad)
Define the effective diffusion coefficient when:
const bool _has_energy_equation
A boolean to help compatibility with the old Modules/NavierStokesFV syntax.
const bool _solve_for_enthalpy
User-selected option to solve for enthalpy.
std::vector< MooseFunctorName > _thermal_conductivity_name
Name of the thermal conductivity functor for each block-group.
std::vector< std::vector< SubdomainName > > _thermal_conductivity_blocks
Vector of subdomain groups where we want to have different thermal conduction.
MultiMooseEnum _energy_wall_types
Energy wall boundary types.
MultiMooseEnum _energy_inlet_types
Energy inlet boundary types.
std::vector< MooseFunctorName > _ambient_temperature
Name of the solid domain temperature for each block-group.
Creates all the objects needed to solve the Navier Stokes energy equation using a linear finite volum...
void addEnergyInletBC() override
Functions adding boundary conditions for the incompressible / weakly compressible energy equation.
void addEnergyTimeKernels() override
Functions adding kernels for the incompressible / weakly compressible energy equation.
WCNSLinearFVFluidHeatTransferPhysics(const InputParameters &parameters)
std::vector< std::string > split(const std::string &str, const std::string &delimiter, std::size_t max_count)
std::string stringify(const T &t)
static const std::string T_fluid
Definition NS.h:110
static const std::string cp
Definition NS.h:125
static const std::string k_eff_t
Definition NS.h:137
static const std::string T_solid
Definition NS.h:111
static const std::string specific_enthalpy
Definition NS.h:69
static const std::string fluid
Definition NS.h:88
static const std::string pressure
Definition NS.h:57