https://mooseframework.inl.gov
Loading...
Searching...
No Matches
WCNSLinearFVFlowPhysics.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
12#include "NSFVBase.h"
14#include "RhieChowMassFlux.h"
17#include "INSFVTimeKernel.h"
18#include "MapConversionUtils.h"
19#include "NSFVUtils.h"
20#include "NS.h"
21
23registerMooseAction("NavierStokesApp", WCNSLinearFVFlowPhysics, "add_interpolation_method_physics");
24registerMooseAction("NavierStokesApp", WCNSLinearFVFlowPhysics, "add_gradient_method");
25registerMooseAction("NavierStokesApp", WCNSLinearFVFlowPhysics, "add_linear_fv_kernel");
26registerMooseAction("NavierStokesApp", WCNSLinearFVFlowPhysics, "add_linear_fv_bc");
27registerMooseAction("NavierStokesApp", WCNSLinearFVFlowPhysics, "add_functor_material");
28
31{
34 "Define the Navier Stokes weakly-compressible equations with the linear "
35 "solver implementation of the SIMPLE scheme");
36 params.set<MooseEnum>("momentum_advection_interpolation") = NS::fvAdvectedInterpolationMethods();
37 params.addParam<InterpolationMethodName>(
38 "momentum_advection_interpolation_method_name",
39 "Name of an externally defined FVInterpolationMethod to use for momentum advection. When "
40 "provided, this overrides 'momentum_advection_interpolation'.");
41
42 params.addParam<bool>(
43 "orthogonality_correction", false, "Whether to use orthogonality correction");
44 params.renameParam("orthogonality_correction", "use_nonorthogonal_correction", "");
45 params.addParam<MooseEnum>(
46 "pressure_diffusion_interpolation",
48 "The face interpolation method for Ainv in the pressure correction diffusion term.");
49 params.addParamNamesToGroup("pressure_diffusion_interpolation", "Numerical scheme");
50 params.set<unsigned short>("ghost_layers") = 1;
51
52 // This will be adapted based on the dimension
53 params.set<std::vector<SolverSystemName>>("system_names") = {
54 "u_system", "v_system", "w_system", "pressure_system"};
55
56 // Implemented in the executioner
57 params.suppressParameter<MooseEnum>("pinned_pressure_type");
58 params.suppressParameter<Point>("pinned_pressure_point");
59 params.suppressParameter<PostprocessorName>("pinned_pressure_value");
60
61 // Porous medium pressure baffles
62 params.transferParam<MooseEnum>(NSFVBase::validParams(), "porosity_interface_pressure_treatment");
63 params.addParam<std::vector<BoundaryName>>(
64 "pressure_drop_sidesets",
65 {},
66 "Internal sidesets carrying a pressure-jump baffle with the Bernoulli pressure jump and an "
67 "optional irreversible form loss. Used when 'porosity_interface_pressure_treatment' is "
68 "'bernoulli'.");
69 params.transferParam<std::vector<Real>>(NSFVBase::validParams(), "pressure_drop_form_factors");
71 "reference_velocity_side",
72 "pressure_drop_reference_velocity_side");
73 params.transferParam<Real>(PorousRhieChowMassFlux::validParams(), "pressure_jump_relaxation");
74 params.addParam<bool>(
75 "use_reconstructed_pressure_gradient",
76 true,
77 "Whether the momentum pressure kernels use the FVReconstructedPressureGradient built on the "
78 "jump-aware pressure gradient when pressure-jump baffles are present.");
79 // Same default and range as the gradient_relaxation parameter of FVReconstructedPressureGradient
80 params.addRangeCheckedParam<Real>(
81 "pressure_gradient_relaxation",
82 0.1,
83 "0.0<pressure_gradient_relaxation<=1.0",
84 "Relaxation factor applied when updating the reconstructed pressure-coupling gradient.");
86 "porosity_interface_pressure_treatment pressure_drop_sidesets pressure_drop_form_factors "
87 "pressure_drop_reference_velocity_side pressure_jump_relaxation "
88 "use_reconstructed_pressure_gradient pressure_gradient_relaxation",
89 "Flow medium discontinuity treatment");
90
91 // Not supported
92 params.suppressParameter<bool>("add_flow_equations");
93 params.suppressParameter<MooseEnum>("mu_interp_method");
94 // Not needed
95 params.suppressParameter<bool>("add_flow_equations");
96 params.suppressParameter<MooseEnum>("preconditioning");
97
98 // No other options so far
99 params.set<MooseEnum>("velocity_interpolation") = "rc";
100 params.suppressParameter<MooseEnum>("velocity_interpolation");
101
102 // Rhie-Chow
103 params.transferParam<MooseEnum>(RhieChowMassFlux::validParams(), "pressure_projection_method");
104 params.addParamNamesToGroup("momentum_advection_interpolation_method_name", "Numerical scheme");
105
106 return params;
107}
108
110 : WCNSFVFlowPhysicsBase(parameters),
111 _non_orthogonal_correction(getParam<bool>("orthogonality_correction")),
112 _baffle_sidesets(getParam<std::vector<BoundaryName>>("pressure_drop_sidesets")),
113 _has_baffles(!_baffle_sidesets.empty()),
114 _use_reconstructed_pressure_gradient(_has_baffles &&
115 getParam<bool>("use_reconstructed_pressure_gradient"))
116{
117 addRequiredPhysicsTask("add_interpolation_method_physics");
118 addRequiredPhysicsTask("add_gradient_method");
119
120 checkSecondParamSetOnlyIfFirstOneTrue("porous_medium_treatment",
121 "porosity_interface_pressure_treatment");
122 const bool bernoulli =
123 getParam<MooseEnum>("porosity_interface_pressure_treatment") == "bernoulli";
124 if (!bernoulli)
125 errorDependentParameter("porosity_interface_pressure_treatment",
126 "bernoulli",
127 {"pressure_drop_sidesets",
128 "pressure_drop_form_factors",
129 "pressure_drop_reference_velocity_side",
130 "pressure_jump_relaxation",
131 "use_reconstructed_pressure_gradient",
132 "pressure_gradient_relaxation"});
133 if (bernoulli && !_has_baffles)
134 paramError("pressure_drop_sidesets",
135 "The Bernoulli porosity interface treatment requires the sidesets of the pressure "
136 "baffles.");
137 if (!getParam<bool>("use_reconstructed_pressure_gradient"))
139 "use_reconstructed_pressure_gradient", "true", {"pressure_gradient_relaxation"});
141 mooseError("Not supported");
142
143 if (_hydraulic_separators.size())
144 paramError("hydraulic_separator_sidesets",
145 "Flow separators are not supported yet for linearFV!");
146 if (getParam<bool>("pin_pressure"))
147 paramError("pin_pressure",
148 "Pressure pinning is implemented in the executioner for the linear finite volume "
149 "segregated solves");
150}
151
152void
154{
156 if (_current_task == "add_gradient_method" && !getParam<bool>("dont_create_kernels"))
158}
159
160void
162{
164 return;
165
166 // The pressure and velocity gradients exclude the jumps across the baffles. Their names are
167 // assigned to the variables in addSolverVariables.
168 {
169 InputParameters params = getFactory().getValidParams("FVPressureJumpGreenGaussGradient");
171 "FVPressureJumpGreenGaussGradient", prefix() + "pressure_jump_gradient", params);
172 }
173 {
174 InputParameters params = getFactory().getValidParams("FVVelocityJumpGreenGaussGradient");
176 "FVVelocityJumpGreenGaussGradient", prefix() + "velocity_jump_gradient", params);
177 }
179 {
180 InputParameters params = getFactory().getValidParams("FVReconstructedPressureGradient");
181 params.set<GradientMethodName>("base_gradient_method") = prefix() + "pressure_jump_gradient";
182 params.set<Real>("gradient_relaxation") = getParam<Real>("pressure_gradient_relaxation");
184 "FVReconstructedPressureGradient", prefix() + "reconstructed_pressure_gradient", params);
185 }
186}
187
188void
190{
191 if (!_has_flow_equations || isParamValid("momentum_advection_interpolation_method_name"))
192 return;
193
194 addFVAdvectedInterpolationMethod(getParam<MooseEnum>("momentum_advection_interpolation"));
195}
196
197void
199{
201 // TODO Add support for multi-system by either:
202 // - creating the problem in the Physics or,
203 // - checking that the right systems are being created
204 getProblem().needSolutionState(2, Moose::SolutionIterationType::Nonlinear);
205 // TODO Ban all other nonlinear Physics for now
206
207 // Fix the default system names if using a different dimension
208 if (!isParamSetByUser("system_name"))
209 {
210 if (dimension() == 1)
211 _system_names = {"u_system", "pressure_system"};
212 else if (dimension() == 2)
213 _system_names = {"u_system", "v_system", "pressure_system"};
214 }
215}
216
217void
219{
221 return;
222
223 for (const auto d : make_range(dimension()))
226
227 const std::vector<std::string> v_short = {"u", "v", "w"};
228
229 // Check number of variables
230 if (_velocity_names.size() != dimension() && _velocity_names.size() != 3)
231 paramError("velocity_variable",
232 "The number of velocity variable names supplied to the NSFVAction is not " +
233 Moose::stringify(dimension()) + " (mesh dimension)" +
234 ((dimension() == 3) ? "" : " or 3!") + "\nVelocity variables " +
236
237 // Velocities
238 for (const auto d : make_range(dimension()))
239 {
240 if (!shouldCreateVariable(_velocity_names[d], _blocks, /*error if aux*/ true))
241 reportPotentiallyMissedParameters({"system_names"}, "MooseLinearVariableFVReal");
242 else if (_define_variables)
243 {
244 std::string variable_type = "MooseLinearVariableFVReal";
245
246 auto params = getFactory().getValidParams(variable_type);
247 if (_has_baffles)
248 params.set<GradientMethodName>("gradient_method") = prefix() + "velocity_jump_gradient";
249
250 addSharedSolverVariable(variable_type, _velocity_names[d], params);
251 }
252 else
253 paramError("velocity_variable",
254 "Variable (" + _velocity_names[d] +
255 ") supplied to the WCNSLinearFVFlowPhysics does not exist!");
256 }
257
258 // Pressure
259 if (!shouldCreateVariable(_pressure_name, _blocks, /*error if aux*/ true))
260 reportPotentiallyMissedParameters({"system_names"}, "MooseLinearVariableFVReal");
261 else if (_define_variables)
262 {
263 const auto pressure_type = "MooseLinearVariableFVReal";
264
265 auto params = getFactory().getValidParams(pressure_type);
266 if (_has_baffles)
267 params.set<GradientMethodName>("gradient_method") = prefix() + "pressure_jump_gradient";
268
269 addSharedSolverVariable(pressure_type, _pressure_name, params);
270 }
271 else
272 paramError("pressure_variable",
273 "Variable (" + _pressure_name +
274 ") supplied to the WCNSLinearFVFlowPhysics does not exist!");
275}
276
277void
279{
281 return;
282
283 // Pressure correction equation: divergence of momentum
285
286 // Momentum equation: time derivative
287 if (isTransient())
289
290 // Momentum equation: flux terms
292
293 // Momentum equation: pressure term
295
296 // Momentum equation: friction term
297 if (_friction_types.size())
299
300 // Momentum equation: gravity source term
302
303 // Momentum equation: boussinesq approximation
304 if (getParam<bool>("boussinesq_approximation"))
306}
307
308void
310{
311 {
312 // The baffle faces need the jump contribution to the pressure correction
313 std::string kernel_type = _has_baffles ? "LinearFVPressureCorrectionDiffusionJump"
314 : "LinearFVPressureCorrectionDiffusion";
315 std::string kernel_name = prefix() + "p_diffusion";
316
317 InputParameters params = getFactory().getValidParams(kernel_type);
318 assignBlocks(params, _blocks);
319 params.set<LinearVariableName>("variable") = _pressure_name;
320 if (_has_baffles)
321 params.set<UserObjectName>("rhie_chow_user_object") = rhieChowUOName();
322 else
323 params.set<MooseFunctorName>("diffusion_tensor") = "Ainv";
324 params.set<bool>("use_nonorthogonal_correction") = _non_orthogonal_correction;
325
326 getProblem().addLinearFVKernel(kernel_type, kernel_name, params);
327 }
328 {
329 std::string kernel_type = "LinearFVDivergence";
330 std::string kernel_name = prefix() + "HbyA_divergence";
331
332 InputParameters params = getFactory().getValidParams(kernel_type);
333 assignBlocks(params, _blocks);
334 params.set<LinearVariableName>("variable") = _pressure_name;
335 params.set<MooseFunctorName>("face_flux") = "HbyA";
336 params.set<bool>("force_boundary_execution") = true;
337
338 getProblem().addLinearFVKernel(kernel_type, kernel_name, params);
339 }
340}
341
342void
344{
345 std::string kernel_type = "LinearFVTimeDerivative";
346 std::string kernel_name = prefix() + "ins_momentum_time";
347
348 InputParameters params = getFactory().getValidParams(kernel_type);
349 assignBlocks(params, _blocks);
350 params.set<MooseFunctorName>("factor") = _density_name;
351
352 for (const auto d : make_range(dimension()))
353 {
354 params.set<LinearVariableName>("variable") = _velocity_names[d];
355 if (shouldCreateTimeDerivative(_velocity_names[d], _blocks, /*error if already defined*/ false))
356 getProblem().addLinearFVKernel(kernel_type, kernel_name + "_" + NS::directions[d], params);
357 }
358}
359
360void
362{
363 const auto momentum_advection_method_name =
364 isParamValid("momentum_advection_interpolation_method_name")
365 ? getParam<InterpolationMethodName>("momentum_advection_interpolation_method_name")
366 : InterpolationMethodName(
367 std::string(getParam<MooseEnum>("momentum_advection_interpolation")));
368
369 const std::string u_names[3] = {"u", "v", "w"};
370 std::string kernel_type =
371 _porous_medium_treatment ? "LinearPWCNSFVMomentumFlux" : "LinearWCNSFVMomentumFlux";
372 std::string kernel_name =
373 prefix() + (_porous_medium_treatment ? "pins" : "ins") + "_momentum_flux_";
374
375 InputParameters params = getFactory().getValidParams(kernel_type);
376 assignBlocks(params, _blocks);
378 params.set<MooseFunctorName>(NS::mu) = _dynamic_viscosity_name;
379 else
380 params.set<MooseFunctorName>(NS::mu) = NS::mu_eff;
381
382 params.set<UserObjectName>("rhie_chow_user_object") = rhieChowUOName();
383 params.set<InterpolationMethodName>("advected_interp_method_name") =
384 momentum_advection_method_name;
385 params.set<bool>("use_nonorthogonal_correction") = _non_orthogonal_correction;
386 params.set<bool>("use_deviatoric_terms") = includeSymmetrizedViscousStress();
387
388 for (unsigned int i = 0; i < dimension(); ++i)
389 params.set<SolverVariableName>(u_names[i]) = _velocity_names[i];
390
391 for (const auto d : make_range(dimension()))
392 {
393 params.set<LinearVariableName>("variable") = _velocity_names[d];
394 params.set<MooseEnum>("momentum_component") = NS::directions[d];
395
396 getProblem().addLinearFVKernel(kernel_type, kernel_name + NS::directions[d], params);
397 }
398}
399
400void
402{
403 std::string kernel_type =
404 _porous_medium_treatment ? "LinearPWCNSFVMomentumPressure" : "LinearFVMomentumPressure";
405 std::string kernel_name =
406 prefix() + (_porous_medium_treatment ? "pins" : "ins") + "_momentum_pressure_";
407
408 InputParameters params = getFactory().getValidParams(kernel_type);
409 assignBlocks(params, _blocks);
410 params.set<VariableName>("pressure") = _pressure_name;
412 params.set<MooseFunctorName>(NS::porosity) = _flow_porosity_functor_name;
414 params.set<GradientMethodName>("gradient_method") =
415 prefix() + "reconstructed_pressure_gradient";
416
417 for (const auto d : make_range(dimension()))
418 {
419 params.set<MooseEnum>("momentum_component") = NS::directions[d];
420 params.set<LinearVariableName>("variable") = _velocity_names[d];
421 getProblem().addLinearFVKernel(kernel_type, kernel_name + NS::directions[d], params);
422 }
423}
424
425void
427{
428 unsigned int num_friction_blocks = _friction_blocks.size();
429 unsigned int num_used_blocks = num_friction_blocks ? num_friction_blocks : 1;
430
431 const std::string kernel_type = "LinearFVMomentumFriction";
432 const std::string u_names[3] = {"u", "v", "w"};
433
434 for (const auto block_i : make_range(num_used_blocks))
435 {
436 // Fresh parameters so that a friction type of one block does not carry over to the next
437 InputParameters params = getFactory().getValidParams(kernel_type);
439 params.set<MooseFunctorName>(NS::porosity) = _flow_porosity_functor_name;
440 std::string block_name = "";
441 if (num_friction_blocks)
442 {
443 params.set<std::vector<SubdomainName>>("block") = _friction_blocks[block_i];
444 block_name = Moose::stringify(_friction_blocks[block_i]);
445 }
446 else
447 {
448 assignBlocks(params, _blocks);
449 block_name = std::to_string(block_i);
450 }
451
452 for (const auto d : make_range(dimension()))
453 {
454 params.set<LinearVariableName>("variable") = _velocity_names[d];
455 params.set<MooseEnum>("momentum_component") = NS::directions[d];
456 for (unsigned int type_i = 0; type_i < _friction_types[block_i].size(); ++type_i)
457 {
458 const auto upper_name = MooseUtils::toUpper(_friction_types[block_i][type_i]);
459 if (upper_name == "DARCY")
460 {
461 params.set<MooseFunctorName>(NS::mu) = _dynamic_viscosity_name;
462 params.set<MooseFunctorName>("Darcy_name") = _friction_coeffs[block_i][type_i];
463 }
464 else if (upper_name == "FORCHHEIMER")
465 {
466 params.set<MooseFunctorName>(NS::density) = _density_name;
467 params.set<MooseFunctorName>("Forchheimer_name") = _friction_coeffs[block_i][type_i];
468 for (const auto j : make_range(dimension()))
469 params.set<MooseFunctorName>(u_names[j]) = _velocity_names[j];
470 }
471 else
472 paramError("friction_types",
473 "Friction type '",
474 _friction_types[block_i][type_i],
475 "' is not implemented");
476 }
477
478 getProblem().addLinearFVKernel(kernel_type,
479 prefix() + "momentum_friction_" + block_name + "_" +
481 params);
482 }
483 }
484}
485
486void
488{
490 {
491 std::string kernel_type = "LinearFVSource";
492 std::string kernel_name = prefix() + "ins_momentum_gravity_";
493
494 InputParameters params = getFactory().getValidParams(kernel_type);
495 assignBlocks(params, _blocks);
496 const auto gravity_vector = getParam<RealVectorValue>("gravity");
497 const std::vector<std::string> comp_axis({"x", "y", "z"});
498
499 for (const auto d : make_range(dimension()))
500 if (gravity_vector(d) != 0)
501 {
502 params.set<MooseFunctorName>("source_density") = "rho_g_" + comp_axis[d];
503 // The momentum equation of superficial velocity carries eps rho g
505 params.set<MooseFunctorName>("scaling_factor") = _flow_porosity_functor_name;
506 params.set<LinearVariableName>("variable") = _velocity_names[d];
507
508 getProblem().addLinearFVKernel(kernel_type, kernel_name + NS::directions[d], params);
509 }
510 }
511}
512
513void
515{
516 if (_compressibility == "weakly-compressible")
517 paramError("boussinesq_approximation",
518 "We cannot use boussinesq approximation while running in weakly-compressible mode!");
519
520 std::string kernel_type = "LinearFVMomentumBoussinesq";
521 std::string kernel_name = prefix() + "ins_momentum_boussinesq_";
522
523 InputParameters params = getFactory().getValidParams(kernel_type);
524 assignBlocks(params, _blocks);
525 params.set<VariableName>(NS::T_fluid) = _fluid_temperature_name;
526 params.set<MooseFunctorName>(NS::density) = _density_gravity_name;
527 params.set<RealVectorValue>("gravity") = getParam<RealVectorValue>("gravity");
528 params.set<Real>("ref_temperature") = getParam<Real>("ref_temperature");
529 params.set<MooseFunctorName>("alpha_name") = getParam<MooseFunctorName>("thermal_expansion");
531 params.set<MooseFunctorName>(NS::porosity) = _flow_porosity_functor_name;
532
533 for (const auto d : make_range(dimension()))
534 {
535 params.set<MooseEnum>("momentum_component") = NS::directions[d];
536 params.set<LinearVariableName>("variable") = _velocity_names[d];
537
538 getProblem().addLinearFVKernel(kernel_type, kernel_name + NS::directions[d], params);
539 }
540}
541
542void
544{
545 // Check the size of the BC parameters
546 unsigned int num_velocity_functor_inlets = 0;
547 for (const auto & [bdy, momentum_inlet_type] : _momentum_inlet_types)
548 if (momentum_inlet_type == "fixed-velocity" || momentum_inlet_type == "fixed-pressure")
549 num_velocity_functor_inlets++;
550
551 if (num_velocity_functor_inlets != _momentum_inlet_functors.size())
552 paramError("momentum_inlet_functors",
553 "Size (" + std::to_string(_momentum_inlet_functors.size()) +
554 ") is not the same as the number of entries in the momentum_inlet_types "
555 "subvector for fixed-velocities/pressures functors (size " +
556 std::to_string(num_velocity_functor_inlets) + ")");
557
558 unsigned int velocity_pressure_counter = 0;
559 for (const auto & [inlet_bdy, momentum_inlet_type] : _momentum_inlet_types)
560 {
561 if (momentum_inlet_type == "fixed-velocity")
562 {
563 const std::string bc_type = "LinearFVAdvectionDiffusionFunctorDirichletBC";
564 InputParameters params = getFactory().getValidParams(bc_type);
565 params.set<std::vector<BoundaryName>>("boundary") = {inlet_bdy};
566 if (_momentum_inlet_functors.size() < velocity_pressure_counter + 1)
567 paramError("momentum_inlet_functors",
568 "More non-flux inlets than inlet functors (" +
569 std::to_string(_momentum_inlet_functors.size()) + ")");
570
571 // Check that enough functors have been provided for the dimension of the problem
572 const auto momentum_functors = libmesh_map_find(_momentum_inlet_functors, inlet_bdy);
573 if (momentum_functors.size() < dimension())
574 paramError("momentum_inlet_functors",
575 "Subvector for boundary '" + inlet_bdy + "' (size " +
576 std::to_string(momentum_functors.size()) +
577 ") is not the same size as the number of dimensions of the physics (" +
578 std::to_string(dimension()) + ")");
579
580 for (const auto d : make_range(dimension()))
581 {
582 params.set<LinearVariableName>("variable") = _velocity_names[d];
583 params.set<MooseFunctorName>("functor") = momentum_functors[d];
584
585 getProblem().addLinearFVBC(bc_type, _velocity_names[d] + "_" + inlet_bdy, params);
586 }
587 ++velocity_pressure_counter;
588
589 // Add the two term BC expansion for pressure if requested
590 if (getParam<bool>("pressure_two_term_bc_expansion"))
591 {
592 const std::string bc_type = "LinearFVExtrapolatedPressureBC";
593 InputParameters params = getFactory().getValidParams(bc_type);
594 params.set<std::vector<BoundaryName>>("boundary") = {inlet_bdy};
595 params.set<LinearVariableName>("variable") = _pressure_name;
596 params.set<bool>("use_two_term_expansion") = true;
597 getProblem().addLinearFVBC(bc_type,
598 _pressure_name + "_extrapolation_inlet_" +
599 Moose::stringify(inlet_bdy),
600 params);
601 }
602 }
603 else if (momentum_inlet_type == "fixed-pressure")
604 {
605 const std::string bc_type = "LinearFVAdvectionDiffusionFunctorDirichletBC";
606 InputParameters params = getFactory().getValidParams(bc_type);
607 params.set<LinearVariableName>("variable") = _pressure_name;
608 if (_momentum_inlet_functors.size() < velocity_pressure_counter + 1)
609 paramError("momentum_inlet_functors",
610 "More non-flux inlets than inlet functors (" +
611 std::to_string(_momentum_inlet_functors.size()) + ")");
612
613 params.set<MooseFunctorName>("functor") =
614 libmesh_map_find(_momentum_inlet_functors, inlet_bdy)[0];
615 params.set<std::vector<BoundaryName>>("boundary") = {inlet_bdy};
616
617 getProblem().addLinearFVBC(bc_type, _pressure_name + "_" + inlet_bdy, params);
618 ++velocity_pressure_counter;
619 }
620 else
621 mooseError("Unsupported inlet boundary condition type: ", momentum_inlet_type);
622 }
623}
624
625void
627{
628 // Check the BCs size
629 unsigned int num_pressure_outlets = 0;
630 for (const auto & [bdy, momentum_outlet_type] : _momentum_outlet_types)
631 if (momentum_outlet_type == "fixed-pressure" ||
632 momentum_outlet_type == "fixed-pressure-zero-gradient")
633 num_pressure_outlets++;
634
635 if (num_pressure_outlets != _pressure_functors.size())
636 paramError("pressure_functors",
637 "Size (" + std::to_string(_pressure_functors.size()) +
638 ") is not the same as the number of pressure outlet boundaries in "
639 "'fixed-pressure/fixed-pressure-zero-gradient' (size " +
640 std::to_string(num_pressure_outlets) + ")");
641
642 const std::string u_names[3] = {"u", "v", "w"};
643 for (const auto & [outlet_bdy, momentum_outlet_type] : _momentum_outlet_types)
644 {
645 // Zero tangeantial gradient condition on velocity
646 if (momentum_outlet_type == "zero-gradient" || momentum_outlet_type == "fixed-pressure" ||
647 momentum_outlet_type == "fixed-pressure-zero-gradient")
648 {
649 const std::string bc_type = "LinearFVAdvectionDiffusionOutflowBC";
650 InputParameters params = getFactory().getValidParams(bc_type);
651 params.set<std::vector<BoundaryName>>("boundary") = {outlet_bdy};
652 params.set<bool>("use_two_term_expansion") = getParam<bool>("momentum_two_term_bc_expansion");
653
654 for (const auto d : make_range(dimension()))
655 {
656 params.set<LinearVariableName>("variable") = _velocity_names[d];
657 getProblem().addLinearFVBC(bc_type, _velocity_names[d] + "_" + outlet_bdy, params);
658 }
659 }
660
661 // Fixed pressure condition, coming in the pressure correction equation
662 if (momentum_outlet_type == "fixed-pressure" ||
663 momentum_outlet_type == "fixed-pressure-zero-gradient")
664 {
665 const std::string bc_type = "LinearFVAdvectionDiffusionFunctorDirichletBC";
666 InputParameters params = getFactory().getValidParams(bc_type);
667 params.set<LinearVariableName>("variable") = _pressure_name;
668 params.set<MooseFunctorName>("functor") = libmesh_map_find(_pressure_functors, outlet_bdy);
669 params.set<std::vector<BoundaryName>>("boundary") = {outlet_bdy};
670
671 getProblem().addLinearFVBC(bc_type, _pressure_name + "_" + outlet_bdy, params);
672 }
673 }
674}
675
676void
678{
679 const std::string u_names[3] = {"u", "v", "w"};
680 bool has_symmetry_bc = false;
681
682 for (const auto & [boundary_name, momentum_wall_type] : _momentum_wall_types)
683 {
684 if (momentum_wall_type == "noslip")
685 {
686 const std::string bc_type = "LinearFVAdvectionDiffusionFunctorDirichletBC";
687 InputParameters params = getFactory().getValidParams(bc_type);
688 params.set<std::vector<BoundaryName>>("boundary") = {boundary_name};
689
690 for (const auto d : make_range(dimension()))
691 {
692 params.set<LinearVariableName>("variable") = _velocity_names[d];
693 if (_momentum_wall_functors.count(boundary_name) == 0)
694 params.set<MooseFunctorName>("functor") = "0";
695 else
696 params.set<MooseFunctorName>("functor") = _momentum_wall_functors[boundary_name][d];
697
698 getProblem().addLinearFVBC(bc_type, _velocity_names[d] + "_" + boundary_name, params);
699 }
700 }
701 else if (momentum_wall_type == "symmetry")
702 {
703 has_symmetry_bc = true;
704 {
705 const std::string bc_type = "LinearFVVelocitySymmetryBC";
706 InputParameters params = getFactory().getValidParams(bc_type);
707 params.set<std::vector<BoundaryName>>("boundary") = {boundary_name};
708 for (unsigned int d = 0; d < dimension(); ++d)
709 params.set<SolverVariableName>(u_names[d]) = _velocity_names[d];
710
711 for (const auto d : make_range(dimension()))
712 {
713 params.set<LinearVariableName>("variable") = _velocity_names[d];
714 params.set<MooseEnum>("momentum_component") = NS::directions[d];
715
716 getProblem().addLinearFVBC(bc_type, _velocity_names[d] + "_" + boundary_name, params);
717 }
718 }
719 // Porous walls receive a pressure flux boundary condition below
721 {
722 const std::string bc_type = "LinearFVPressureSymmetryBC";
723 InputParameters params = getFactory().getValidParams(bc_type);
724 params.set<std::vector<BoundaryName>>("boundary") = {boundary_name};
725 params.set<LinearVariableName>("variable") = _pressure_name;
726 params.set<MooseFunctorName>("HbyA_flux") = "HbyA";
727 getProblem().addLinearFVBC(bc_type, _pressure_name + "_" + boundary_name, params);
728 }
729 }
730 else
731 mooseError("Unsupported wall boundary condition type: " + std::string(momentum_wall_type));
732 }
733
735 {
736 // The pressure flux is set by the wall velocity and the H/A flux, so the boundary pressure
737 // stays consistent with the momentum balance of the adjacent porous cell
738 if (_wall_boundaries.empty())
739 return;
740 const std::string bc_type = "LinearFVPressureFluxBC";
741 InputParameters params = getFactory().getValidParams(bc_type);
742 params.set<std::vector<BoundaryName>>("boundary") = _wall_boundaries;
743 params.set<LinearVariableName>("variable") = _pressure_name;
744 params.set<MooseFunctorName>("HbyA_flux") = "HbyA";
745 params.set<MooseFunctorName>("Ainv") = "Ainv";
746 params.set<MooseFunctorName>(NS::density) = _density_name;
747 for (const auto d : make_range(dimension()))
748 params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
749 params.set<bool>("use_two_term_expansion") = getParam<bool>("pressure_two_term_bc_expansion");
750 getProblem().addLinearFVBC(bc_type, prefix() + _pressure_name + "_walls", params);
751 }
752 else if (getParam<bool>("pressure_two_term_bc_expansion"))
753 {
754 if (!has_symmetry_bc)
755 {
756 const std::string bc_type = "LinearFVExtrapolatedPressureBC";
757 InputParameters params = getFactory().getValidParams(bc_type);
758 params.set<std::vector<BoundaryName>>("boundary") = _wall_boundaries;
759 params.set<LinearVariableName>("variable") = _pressure_name;
760 params.set<bool>("use_two_term_expansion") = true;
762 bc_type, _pressure_name + "_extrapolation_" + Moose::stringify(_wall_boundaries), params);
763 }
764 else
765 for (const auto & [boundary_name, momentum_wall_type] : _momentum_wall_types)
766 if (momentum_wall_type != "symmetry")
767 {
768 const std::string bc_type = "LinearFVExtrapolatedPressureBC";
769 InputParameters params = getFactory().getValidParams(bc_type);
770 params.set<std::vector<BoundaryName>>("boundary") = {boundary_name};
771 params.set<LinearVariableName>("variable") = _pressure_name;
772 params.set<bool>("use_two_term_expansion") = true;
774 bc_type, _pressure_name + "_extrapolation_" + boundary_name, params);
775 }
776 }
777}
778
779void
781{
782 // The Rhie-Chow object looks up the pressure-jump model at construction
783 if (_has_baffles)
785 // Rhie Chow user object for interpolation velocities
787}
788
789void
791{
792 const std::string object_type = "BernoulliFormLossPressureJump";
793 auto params = getFactory().getValidParams(object_type);
794 params.set<std::vector<BoundaryName>>("boundary") = _baffle_sidesets;
795 params.set<MooseFunctorName>("porosity") = _flow_porosity_functor_name;
796 params.set<MooseFunctorName>("density") = _density_name;
797 params.set<std::vector<Real>>("form_loss") =
798 getParam<std::vector<Real>>("pressure_drop_form_factors");
799 // Only forward the reference sides when given so the model applies its default otherwise
800 if (isParamSetByUser("pressure_drop_reference_velocity_side"))
801 params.set<MultiMooseEnum>("reference_velocity_side") =
802 getParam<MultiMooseEnum>("pressure_drop_reference_velocity_side");
803
804 addUserObject(object_type, prefix() + "pressure_jump", params);
805}
806
807void
809{
810 mooseAssert(dimension(), "0-dimension not supported");
811
812 // First make sure that we only add this object once
813 // Potential cases:
814 // - there is a flow physics, and an advection one (UO should be added by one)
815 // - there is only an advection physics (UO should be created)
816 // - there are two advection physics on different blocks with set velocities (first one picks)
817 // Counting RC UOs defined on the same blocks seems to be the most fool proof option
818 std::vector<UserObject *> objs;
819 getProblem()
820 .theWarehouse()
821 .query()
822 .condition<AttribSystem>("UserObject")
823 .condition<AttribThread>(0)
824 .queryInto(objs);
825 unsigned int num_rc_uo = 0;
826 for (const auto & obj : objs)
827 if (dynamic_cast<RhieChowMassFlux *>(obj))
828 {
829 const auto rc_obj = dynamic_cast<RhieChowMassFlux *>(obj);
830 if (rc_obj->blocks() == _blocks)
831 num_rc_uo++;
832 // one of the RC user object is defined everywhere
833 else if (rc_obj->blocks().size() == 0 || _blocks.size() == 0)
834 num_rc_uo++;
835 }
836
837 if (num_rc_uo)
838 return;
839
840 const std::string u_names[3] = {"u", "v", "w"};
841 const auto object_type = _porous_medium_treatment ? "PorousRhieChowMassFlux" : "RhieChowMassFlux";
842
843 auto params = getFactory().getValidParams(object_type);
845 {
846 params.set<MooseFunctorName>(NS::porosity) = _flow_porosity_functor_name;
847 if (_has_baffles)
848 {
849 params.set<std::vector<UserObjectName>>("pressure_jump_models") = {prefix() +
850 "pressure_jump"};
851 params.set<Real>("pressure_jump_relaxation") = getParam<Real>("pressure_jump_relaxation");
852 }
853 }
854 assignBlocks(params, _blocks);
855 for (unsigned int d = 0; d < dimension(); ++d)
856 params.set<VariableName>(u_names[d]) = _velocity_names[d];
857
858 params.set<VariableName>("pressure") = _pressure_name;
859 params.set<std::string>("p_diffusion_kernel") = prefix() + "p_diffusion";
860 params.set<MooseFunctorName>(NS::density) = _density_name;
861 params.set<MooseEnum>("pressure_projection_method") =
862 getParam<MooseEnum>("pressure_projection_method");
863 params.set<MooseEnum>("pressure_diffusion_interpolation") =
864 getParam<MooseEnum>("pressure_diffusion_interpolation");
865
866 addUserObject(object_type, rhieChowUOName(), params);
867}
868
869std::vector<UserObjectName>
871{
872 std::vector<UserObjectName> supplied = {rhieChowUOName()};
873 if (_has_baffles)
874 supplied.push_back(prefix() + "pressure_jump");
875 return supplied;
876}
877
878void
880{
881 if (parameters().isParamValid("gravity"))
882 {
883 const auto gravity_vector = getParam<RealVectorValue>("gravity");
884 const std::vector<std::string> comp_axis({"x", "y", "z"});
885 for (const auto d : make_range(dimension()))
886 if (gravity_vector(d) != 0)
887 {
888 // Add rho * g functor for each relevant direction
889 // TODO: we could avoid using an AD functor material for non-AD density functor
890 auto params = getFactory().getValidParams("ADParsedFunctorMaterial");
891 assignBlocks(params, _blocks);
892 params.set<std::string>("expression") =
893 _density_gravity_name + " * " + std::to_string(gravity_vector(d));
895 params.set<std::vector<std::string>>("functor_names") = {_density_gravity_name};
896 params.set<std::string>("property_name") = "rho_g_" + comp_axis[d];
897 // We don't output this helper material
899 "ADParsedFunctorMaterial", prefix() + "gravity_helper_" + comp_axis[d], params);
900 }
901 }
902}
903
904bool
906{
907 for (const auto & block_types : _friction_types)
908 for (const auto & type : block_types)
909 if (MooseUtils::toUpper(type) == "FORCHHEIMER")
910 return true;
911 return false;
912}
913
914unsigned short
registerMooseAction("NavierStokesApp", WCNSLinearFVFlowPhysics, "add_interpolation_method_physics")
registerWCNSFVFlowPhysicsBaseTasks("NavierStokesApp", WCNSLinearFVFlowPhysics)
const std::string & _current_task
static InputParameters validParams()
Return the input parameters for this pressure-jump model.
void needSolutionState(unsigned int oldest_needed, Moose::SolutionIterationType iteration_type)
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 addFVGradientMethod(const std::string &method_type, const std::string &name, InputParameters &parameters)
virtual void addLinearFVBC(const std::string &fv_bc_name, const std::string &name, InputParameters &parameters)
TheWarehouse & theWarehouse() const
InputParameters getValidParams(const std::string &name) const
void errorDependentParameter(const std::string &param1, const std::string &value_not_set, const std::vector< std::string > &dependent_params) 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 renameParam(const std::string &old_name, const std::string &new_name, const std::string &new_docstring)
void transferParam(const InputParameters &source_param, const std::string &name, const std::string &new_name="", const std::string &new_description="")
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
const InputParameters & parameters() const
const std::string & type() const
void paramError(const std::string &param, Args... args) const
bool isParamSetByUser(const std::string &name) const
void mooseError(Args &&... args) const
const T & getParam(const std::string &name) const
bool isParamValid(const std::string &name) const
static InputParameters validParams()
Definition NSFVBase.C:378
bool _define_variables
Whether to define variables if they do not exist.
void addFVAdvectedInterpolationMethod(const MooseEnum &interpolation_method)
Add the FVInterpolationMethod object for an advected interpolation method if absent.
virtual FEProblemBase & getProblem()
std::vector< SolverSystemName > _system_names
void addUserObject(const std::string &uo_type, const std::string &uo_name, InputParameters &params)
Factory & getFactory()
bool shouldCreateTimeDerivative(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool error_if_already_defined) const
void assignBlocks(InputParameters &params, const std::vector< SubdomainName > &blocks) const
unsigned int dimension() const
void reportPotentiallyMissedParameters(const std::vector< std::string > &param_names, const std::string &object_type, const std::string &object_name="") const
void saveSolverVariableName(const VariableName &var_name)
std::string prefix() 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)
bool isTransient() const
std::vector< SubdomainName > _blocks
void addRequiredPhysicsTask(const std::string &task)
static InputParameters validParams()
User object responsible for determining the face fluxes using the Rhie-Chow interpolation in a segreg...
static InputParameters validParams()
Query query()
Base class for Physics which create the Navier Stokes flow equations.
std::map< BoundaryName, MooseEnum > _momentum_outlet_types
Momentum outlet boundary types.
std::vector< std::vector< SubdomainName > > _friction_blocks
Subdomains where we want to have volumetric friction.
static InputParameters validParams()
std::map< BoundaryName, std::vector< MooseFunctorName > > _momentum_wall_functors
Functors describing the momentum for each wall boundary.
std::map< BoundaryName, MooseEnum > _momentum_inlet_types
Momentum inlet boundary types.
std::map< BoundaryName, MooseFunctorName > _pressure_functors
Functors describing the outlet pressure on each boundary.
std::vector< std::vector< std::string > > _friction_types
The friction correlation types used for each block.
const MooseEnum _compressibility
Compressibility type, can be compressible, incompressible or weakly-compressible.
const std::vector< std::string > _velocity_names
Velocity names.
const std::vector< BoundaryName > _wall_boundaries
Boundaries which define a wall (slip/noslip/etc.)
MooseFunctorName _flow_porosity_functor_name
Name of the porosity functor for the flow equations (if smoothed)
virtual void actOnAdditionalTasks() override
const NonlinearVariableName _pressure_name
Pressure name.
const bool _has_flow_equations
Boolean to keep track of whether the flow equations should be created.
const NonlinearVariableName _fluid_temperature_name
Fluid temperature name.
const bool _porous_medium_treatment
Whether to use the porous medium treatment.
std::map< BoundaryName, std::vector< MooseFunctorName > > _momentum_inlet_functors
Functors describing the momentum inlet for each boundary.
virtual void initializePhysicsAdditional() override
const UserObjectName & rhieChowUOName() const
Return the name of the Rhie Chow user object.
const MooseFunctorName _dynamic_viscosity_name
Name of the dynamic viscosity material property.
std::map< BoundaryName, MooseEnum > _momentum_wall_types
Momentum wall boundary types.
const std::vector< BoundaryName > _hydraulic_separators
Hydraulic separator boundaries.
const bool _solve_for_dynamic_pressure
Whether we are solving for the total or dynamic pressure.
const MooseFunctorName _density_name
Name of the density material property.
const WCNSFVTurbulencePhysicsBase * _turbulence_physics
Can be set to a coupled turbulence physics.
std::vector< std::vector< std::string > > _friction_coeffs
The coefficients used for each item if friction type.
bool includeSymmetrizedViscousStress() const
Whether to include the symmetrized contribution in the viscous stress.
const MooseFunctorName _density_gravity_name
Name of the density material property used for gravity and Boussinesq terms.
Creates all the objects needed to solve the Navier-Stokes equations with the SIMPLE algorithm using t...
virtual void addUserObjects() override
const bool _has_baffles
Whether pressure-jump baffles are present.
const bool _use_reconstructed_pressure_gradient
Whether the momentum pressure kernels use the reconstructed pressure gradient.
virtual void addSolverVariables() override
virtual void addMomentumPressureKernels() override
virtual void addRhieChowUserObjects() override
Function which adds the RhieChow interpolator user objects for weakly and incompressible formulations...
virtual void actOnAdditionalTasks() override
void addMomentumTimeKernels() override
Functions adding kernels for the incompressible momentum equation If the material properties are not ...
virtual void initializePhysicsAdditional() override
unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of algebraic ghosting layers needed.
virtual void addMomentumBoussinesqKernels() override
WCNSLinearFVFlowPhysics(const InputParameters &parameters)
void addFVGradientMethods()
Add the jump-aware and reconstructed gradient methods required by pressure baffles.
virtual void addInletBC() override
Functions adding boundary conditions for the flow simulation.
virtual void addFVKernels() override
virtual bool hasForchheimerFriction() const override
Return whether a Forchheimer friction model is in use.
static InputParameters validParams()
void addPressureJumpModel()
Add the pressure-jump model acting on the baffle sidesets.
virtual void addMomentumFrictionKernels() override
virtual std::vector< UserObjectName > getSuppliedUserObjects() const override
virtual void addOutletBC() override
virtual void addFVInterpolationMethods() override
virtual void addMomentumGravityKernels() override
virtual void addWallsBC() override
void addPressureCorrectionKernels()
Function adding kernels for the incompressible pressure correction equation.
const bool _non_orthogonal_correction
Whether to use the correction term for non-orthogonality.
const std::vector< BoundaryName > _baffle_sidesets
Sidesets carrying Bernoulli pressure-jump baffles (porous medium treatment only)
virtual void addFunctorMaterials() override
std::string toUpper(std::string name)
bool parsesToReal(const std::string &input, Real *parsed_real)
std::string stringify(const T &t)
static const std::string density
Definition NS.h:34
static const std::string T_fluid
Definition NS.h:110
MooseEnum fvFaceInterpolationMethods()
Enum of the interpolation methods supported by FVInterpolationMethod objects.
Definition NSFVUtils.C:85
static const std::string mu
Definition NS.h:127
static const std::string porosity
Definition NS.h:108
static const std::string directions[3]
Definition NS.h:23
static const std::string mu_eff
Definition NS.h:133
MooseEnum fvAdvectedInterpolationMethods()
Enum of the advected interpolation methods supported by FVInterpolationMethod objects.
Definition NSFVUtils.C:61