LCOV - code coverage report
Current view: top level - src/physics - WCNSFVTurbulencePhysics.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: #32971 (54bef8) with base c6cf66 Lines: 335 376 89.1 %
Date: 2026-05-29 20:37:52 Functions: 17 18 94.4 %
Legend: Lines: hit not hit

          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 "WCNSFVTurbulencePhysics.h"
      11             : #include "WCNSFVFlowPhysics.h"
      12             : #include "WCNSFVFluidHeatTransferPhysics.h"
      13             : #include "WCNSFVScalarTransportPhysics.h"
      14             : #include "WCNSFVCoupledAdvectionPhysicsHelper.h"
      15             : #include "INSFVTurbulentViscosityWallFunction.h"
      16             : #include "INSFVTKESourceSink.h"
      17             : #include "NSFVBase.h"
      18             : #include "MooseMesh.h"
      19             : 
      20             : registerWCNSFVTurbulenceBaseTasks("NavierStokesApp", WCNSFVTurbulencePhysics);
      21             : 
      22             : InputParameters
      23         598 : WCNSFVTurbulencePhysics::validParams()
      24             : {
      25         598 :   InputParameters params = WCNSFVTurbulencePhysicsBase::validParams();
      26         598 :   params.addClassDescription(
      27             :       "Define a turbulence model for a incompressible or weakly-compressible Navier Stokes "
      28             :       "flow with a finite volume discretization");
      29             : 
      30             :   // TODO Added to facilitate transition, remove default once NavierStokesFV action is removed
      31        1196 :   params.addParam<AuxVariableName>(
      32             :       "mixing_length_name", "mixing_length", "Name of the mixing length auxiliary variable");
      33         598 :   params.transferParam<bool>(NSFVBase::validParams(), "mixing_length_two_term_bc_expansion");
      34             : 
      35             :   // K-Epsilon numerical scheme parameters
      36        1794 :   params.addRangeCheckedParam<Real>(
      37             :       "tke_scaling",
      38        1196 :       1.0,
      39             :       "tke_scaling > 0.0",
      40             :       "The scaling factor for the turbulent kinetic energy equation.");
      41        1794 :   params.addRangeCheckedParam<Real>(
      42             :       "tked_scaling",
      43        1196 :       1.0,
      44             :       "tked_scaling > 0.0",
      45             :       "The scaling factor for the turbulent kinetic energy dissipation equation.");
      46             : 
      47             :   // Better Jacobian if not linearizing sink and sources
      48        1196 :   params.addParam<bool>("linearize_sink_sources", false, "Whether to linearize the source term");
      49             :   // Better convergence on some cases when neglecting advection derivatives
      50        1196 :   params.addParam<bool>(
      51             :       "neglect_advection_derivatives",
      52        1196 :       false,
      53             :       "Whether to remove the off-diagonal velocity term in the TKE and TKED advection term");
      54        1196 :   MooseEnum coeff_interp_method("average harmonic", "harmonic");
      55        1196 :   params.addParam<MooseEnum>("turbulent_viscosity_interp_method",
      56             :                              coeff_interp_method,
      57             :                              "Face interpolation method for the turbulent viscosity");
      58             : 
      59        1196 :   params.addParamNamesToGroup("tke_scaling tked_scaling "
      60             :                               "turbulent_viscosity_interp_method linearize_sink_sources",
      61             :                               "K-Epsilon model numerical");
      62             : 
      63         598 :   return params;
      64         598 : }
      65             : 
      66         598 : WCNSFVTurbulencePhysics::WCNSFVTurbulencePhysics(const InputParameters & parameters)
      67             :   : WCNSFVTurbulencePhysicsBase(parameters),
      68        1196 :     _mixing_length_name(getParam<AuxVariableName>("mixing_length_name"))
      69             : {
      70             :   // Keep track of the variable names, for loading variables from files notably
      71         598 :   if (_turbulence_model == "mixing-length")
      72          37 :     saveAuxVariableName(_mixing_length_name);
      73             : 
      74             :   // Parameter checks
      75         598 :   if (_turbulence_model != "mixing-length")
      76        1122 :     errorDependentParameter("turbulence_handling",
      77             :                             "mixing-length",
      78             :                             {"mixing_length_delta",
      79             :                              "mixing_length_aux_execute_on",
      80             :                              "von_karman_const",
      81             :                              "von_karman_const_0",
      82             :                              "mixing_length_two_term_bc_expansion"});
      83         598 : }
      84             : 
      85             : void
      86         598 : WCNSFVTurbulencePhysics::initializePhysicsAdditional()
      87             : {
      88         598 :   if (_turbulence_model == "k-epsilon")
      89          60 :     getProblem().needSolutionState(2, Moose::SolutionIterationType::Nonlinear);
      90         598 : }
      91             : 
      92             : void
      93         590 : WCNSFVTurbulencePhysics::addSolverVariables()
      94             : {
      95         590 :   if (_turbulence_model == "mixing-length" || _turbulence_model == "none")
      96         530 :     return;
      97          60 :   else if (_turbulence_model == "k-epsilon")
      98             :   {
      99             :     // Dont add if the user already defined the variable
     100             :     // Add turbulent kinetic energy variable
     101          60 :     if (!shouldCreateVariable(_tke_name, _blocks, /*error if aux*/ true))
     102           0 :       reportPotentiallyMissedParameters(
     103             :           {"system_names", "tke_scaling", "tke_face_interpolation", "tke_two_term_bc_expansion"},
     104             :           "INSFVEnergyVariable");
     105          60 :     else if (_define_variables)
     106             :     {
     107          60 :       auto params = getFactory().getValidParams("INSFVEnergyVariable");
     108          60 :       assignBlocks(params, _blocks);
     109         180 :       params.set<std::vector<Real>>("scaling") = {getParam<Real>("tke_scaling")};
     110         180 :       params.set<MooseEnum>("face_interp_method") = getParam<MooseEnum>("tke_face_interpolation");
     111         120 :       params.set<bool>("two_term_boundary_expansion") = getParam<bool>("tke_two_term_bc_expansion");
     112         120 :       params.set<SolverSystemName>("solver_sys") = getSolverSystem(_tke_name);
     113             : 
     114          60 :       getProblem().addVariable("INSFVEnergyVariable", _tke_name, params);
     115          60 :     }
     116             :     else
     117           0 :       paramError("turbulence_kinetic_energy_variable",
     118           0 :                  "Variable (" + _tke_name +
     119             :                      ") supplied to the WCNSFVTurbulencePhysics does not exist!");
     120             : 
     121             :     // Add turbulent kinetic energy dissipation variable
     122          60 :     if (!shouldCreateVariable(_tked_name, _blocks, /*error if aux*/ true))
     123           0 :       reportPotentiallyMissedParameters(
     124             :           {"system_names", "tked_scaling", "tked_face_interpolation", "tked_two_term_bc_expansion"},
     125             :           "INSFVEnergyVariable");
     126          60 :     else if (_define_variables)
     127             :     {
     128          60 :       auto params = getFactory().getValidParams("INSFVEnergyVariable");
     129          60 :       assignBlocks(params, _blocks);
     130         180 :       params.set<std::vector<Real>>("scaling") = {getParam<Real>("tked_scaling")};
     131         180 :       params.set<MooseEnum>("face_interp_method") = getParam<MooseEnum>("tked_face_interpolation");
     132          60 :       params.set<bool>("two_term_boundary_expansion") =
     133         120 :           getParam<bool>("tked_two_term_bc_expansion");
     134         120 :       params.set<SolverSystemName>("solver_sys") = getSolverSystem(_tked_name);
     135          60 :       getProblem().addVariable("INSFVEnergyVariable", _tked_name, params);
     136          60 :     }
     137             :     else
     138           0 :       paramError("turbulence_kinetic_energy_dissipation_variable",
     139           0 :                  "Variable (" + _tked_name +
     140             :                      ") supplied to the WCNSFVTurbulencePhysics does not exist!");
     141             :   }
     142             : }
     143             : 
     144             : void
     145         598 : WCNSFVTurbulencePhysics::addAuxiliaryVariables()
     146             : {
     147         598 :   if (_turbulence_model == "mixing-length" && _define_variables)
     148             :   {
     149          37 :     auto params = getFactory().getValidParams("MooseVariableFVReal");
     150          37 :     assignBlocks(params, _blocks);
     151          74 :     if (isParamValid("mixing_length_two_term_bc_expansion"))
     152          37 :       params.set<bool>("two_term_boundary_expansion") =
     153         111 :           getParam<bool>("mixing_length_two_term_bc_expansion");
     154          37 :     if (!shouldCreateVariable(_tke_name, _blocks, /*error if aux*/ false))
     155           0 :       reportPotentiallyMissedParameters({"mixing_length_two_term_bc_expansion"},
     156             :                                         "MooseVariableFVReal");
     157             :     else
     158          74 :       getProblem().addAuxVariable("MooseVariableFVReal", _mixing_length_name, params);
     159          37 :   }
     160         598 :   WCNSFVTurbulencePhysicsBase::addAuxiliaryVariables();
     161         598 : }
     162             : 
     163             : void
     164         570 : WCNSFVTurbulencePhysics::addFVKernels()
     165             : {
     166         570 :   if (_turbulence_model == "none")
     167             :     return;
     168             : 
     169             :   // Turbulence terms in other equations
     170          97 :   if (_has_flow_equations)
     171          97 :     addFlowTurbulenceKernels();
     172          97 :   if (_has_energy_equation)
     173          58 :     addFluidEnergyTurbulenceKernels();
     174          97 :   if (_has_scalar_equations)
     175          52 :     addScalarAdvectionTurbulenceKernels();
     176             : 
     177             :   // Turbulence models with their own set of equations
     178          95 :   if (_turbulence_model == "k-epsilon")
     179             :   {
     180          60 :     if (isTransient())
     181           0 :       addKEpsilonTimeDerivatives();
     182          60 :     addKEpsilonAdvection();
     183          60 :     addKEpsilonDiffusion();
     184          60 :     addKEpsilonSink();
     185             :   }
     186             : }
     187             : 
     188             : void
     189          97 : WCNSFVTurbulencePhysics::addFlowTurbulenceKernels()
     190             : {
     191          97 :   if (_turbulence_model == "mixing-length")
     192             :   {
     193         148 :     const std::string u_names[3] = {"u", "v", "w"};
     194          37 :     const std::string kernel_type = "INSFVMixingLengthReynoldsStress";
     195          37 :     InputParameters params = getFactory().getValidParams(kernel_type);
     196          37 :     assignBlocks(params, _blocks);
     197          37 :     params.set<MooseFunctorName>(NS::density) = _density_name;
     198          74 :     params.set<MooseFunctorName>(NS::mixing_length) = _mixing_length_name;
     199             : 
     200          37 :     std::string kernel_name = prefix() + "ins_momentum_mixing_length_reynolds_stress_";
     201          37 :     if (_porous_medium_treatment)
     202           0 :       kernel_name = prefix() + "pins_momentum_mixing_length_reynolds_stress_";
     203             : 
     204          37 :     params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName();
     205         111 :     for (const auto dim_i : make_range(dimension()))
     206         148 :       params.set<MooseFunctorName>(u_names[dim_i]) = _velocity_names[dim_i];
     207             : 
     208         111 :     for (const auto d : make_range(dimension()))
     209             :     {
     210         148 :       params.set<NonlinearVariableName>("variable") = _velocity_names[d];
     211         148 :       params.set<MooseEnum>("momentum_component") = NS::directions[d];
     212             : 
     213         148 :       getProblem().addFVKernel(kernel_type, kernel_name + NS::directions[d], params);
     214             :     }
     215         185 :   }
     216          60 :   else if (_turbulence_model == "k-epsilon")
     217             :   {
     218             :     // We rely on using the turbulent viscosity in the flow equation
     219             :     // This check is rudimentary, we should think of a better way
     220             :     // We could also check for the use of 'mu_t' with the right parameters already
     221         120 :     if (_flow_equations_physics->dynamicViscosityName() != "mu" &&
     222          60 :         !MooseUtils::isFloat(_flow_equations_physics->dynamicViscosityName()))
     223           0 :       mooseError(
     224             :           "Regular fluid viscosity 'mu' should be used for the momentum diffusion term. You are "
     225           0 :           "currently using: " +
     226           0 :           _flow_equations_physics->dynamicViscosityName());
     227             : 
     228         240 :     const std::string u_names[3] = {"u", "v", "w"};
     229          60 :     const std::string kernel_type = "INSFVMomentumDiffusion";
     230          60 :     InputParameters params = getFactory().getValidParams(kernel_type);
     231          60 :     assignBlocks(params, _blocks);
     232         120 :     params.set<MooseFunctorName>("mu") = _turbulent_viscosity_name;
     233         120 :     params.set<MooseEnum>("mu_interp_method") =
     234         120 :         getParam<MooseEnum>("turbulent_viscosity_interp_method");
     235          60 :     params.set<MooseEnum>("variable_interp_method") =
     236         120 :         _flow_equations_physics->getMomentumFaceInterpolationMethod();
     237          60 :     params.set<bool>("complete_expansion") = true;
     238          60 :     if (_flow_equations_physics->includeIsotropicStress())
     239           0 :       params.set<bool>("include_isotropic_viscous_stress") = true;
     240             : 
     241          60 :     std::string kernel_name = prefix() + "ins_momentum_k_epsilon_reynolds_stress_";
     242          60 :     if (_porous_medium_treatment)
     243           0 :       kernel_name = prefix() + "pins_momentum_k_epsilon_reynolds_stress_";
     244             : 
     245          60 :     params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName();
     246         180 :     for (const auto dim_i : make_range(dimension()))
     247         240 :       params.set<MooseFunctorName>(u_names[dim_i]) = _velocity_names[dim_i];
     248             : 
     249         180 :     for (const auto d : make_range(dimension()))
     250             :     {
     251         240 :       params.set<NonlinearVariableName>("variable") = _velocity_names[d];
     252         240 :       params.set<MooseEnum>("momentum_component") = NS::directions[d];
     253             : 
     254         240 :       getProblem().addFVKernel(kernel_type, kernel_name + NS::directions[d], params);
     255             :     }
     256             : 
     257             :     // We only add it here because the mixing length kernels deal with this
     258             :     // withn the kernel. For mixing length see issue: #32112
     259          60 :     if (_flow_equations_physics && _flow_equations_physics->hasFlowEquations())
     260          60 :       addAxisymmetricTurbulentViscousSource();
     261         300 :   }
     262          97 : }
     263             : 
     264             : void
     265          60 : WCNSFVTurbulencePhysics::addAxisymmetricTurbulentViscousSource()
     266             : {
     267          60 :   if (_turbulence_model == "none")
     268          60 :     return;
     269          60 :   if (!_flow_equations_physics)
     270             :     return;
     271          60 :   if (!_flow_equations_physics->addAxisymmetricViscousSourceEnabled())
     272             :     return;
     273             : 
     274          60 :   const auto rz_blocks = _flow_equations_physics->getAxisymmetricRZBlocks();
     275          60 :   if (rz_blocks.empty())
     276             :     return;
     277             : 
     278             :   const auto radial_index =
     279           0 :       _flow_equations_physics->getProblem().mesh().getAxisymmetricRadialCoord();
     280             : 
     281           0 :   InputParameters params = getFactory().getValidParams("INSFVMomentumViscousSourceRZ");
     282           0 :   assignBlocks(params, rz_blocks);
     283           0 :   params.set<MooseFunctorName>(NS::mu) = _turbulent_viscosity_name;
     284           0 :   params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName();
     285           0 :   params.set<MooseEnum>("momentum_component") = NS::directions[radial_index];
     286           0 :   params.set<bool>("complete_expansion") =
     287           0 :       _flow_equations_physics->includeSymmetrizedViscousStress();
     288           0 :   params.set<NonlinearVariableName>("variable") =
     289           0 :       _flow_equations_physics->getVelocityNames()[radial_index];
     290             : 
     291           0 :   getProblem().addFVKernel("INSFVMomentumViscousSourceRZ",
     292           0 :                            prefix() + "ins_momentum_turbulent_viscous_source_rz_" +
     293             :                                NS::directions[radial_index],
     294             :                            params);
     295          60 : }
     296             : 
     297             : void
     298          58 : WCNSFVTurbulencePhysics::addFluidEnergyTurbulenceKernels()
     299             : {
     300          58 :   if (_turbulence_model == "mixing-length")
     301             :   {
     302          28 :     const std::string u_names[3] = {"u", "v", "w"};
     303           7 :     const std::string kernel_type = "WCNSFVMixingLengthEnergyDiffusion";
     304           7 :     InputParameters params = getFactory().getValidParams(kernel_type);
     305           7 :     assignBlocks(params, _blocks);
     306           7 :     params.set<MooseFunctorName>(NS::density) = _density_name;
     307           7 :     params.set<MooseFunctorName>(NS::cp) = _fluid_energy_physics->getSpecificHeatName();
     308           7 :     params.set<MooseFunctorName>(NS::mixing_length) = _mixing_length_name;
     309          14 :     params.set<Real>("schmidt_number") = getParam<Real>("turbulent_prandtl");
     310           7 :     params.set<NonlinearVariableName>("variable") =
     311           7 :         _flow_equations_physics->getFluidTemperatureName();
     312             : 
     313          28 :     for (const auto dim_i : make_range(dimension()))
     314          28 :       params.set<MooseFunctorName>(u_names[dim_i]) = _velocity_names[dim_i];
     315             : 
     316           7 :     if (_porous_medium_treatment)
     317           0 :       getProblem().addFVKernel(
     318           0 :           kernel_type, prefix() + "pins_energy_mixing_length_diffusion", params);
     319             :     else
     320          14 :       getProblem().addFVKernel(
     321           7 :           kernel_type, prefix() + "ins_energy_mixing_length_diffusion", params);
     322          35 :   }
     323          51 :   else if (_turbulence_model == "k-epsilon")
     324             :   {
     325          51 :     const std::string kernel_type = "FVDiffusion";
     326          51 :     const auto T_fluid_name = _flow_equations_physics->getFluidTemperatureName();
     327          51 :     InputParameters params = getFactory().getValidParams(kernel_type);
     328          51 :     assignBlocks(params, _blocks);
     329         102 :     params.set<NonlinearVariableName>("variable") = T_fluid_name;
     330         102 :     params.set<MooseFunctorName>("coeff") = NS::k_t;
     331         102 :     getProblem().addFVKernel(kernel_type, prefix() + T_fluid_name + "_turbulent_diffusion", params);
     332          51 :   }
     333          58 : }
     334             : 
     335             : void
     336          52 : WCNSFVTurbulencePhysics::addScalarAdvectionTurbulenceKernels()
     337             : {
     338          52 :   const auto & passive_scalar_names = _scalar_transport_physics->getAdvectedScalarNames();
     339         104 :   const auto & passive_scalar_schmidt_number = getParam<std::vector<Real>>("Sc_t");
     340          52 :   if (passive_scalar_schmidt_number.size() != passive_scalar_names.size() &&
     341             :       passive_scalar_schmidt_number.size() != 1)
     342           2 :     paramError(
     343             :         "Sc_t",
     344             :         "The number of turbulent Schmidt numbers defined is not equal to the number of passive "
     345             :         "scalar fields!");
     346             : 
     347          50 :   if (_turbulence_model == "mixing-length")
     348             :   {
     349          56 :     const std::string u_names[3] = {"u", "v", "w"};
     350          14 :     const std::string kernel_type = "INSFVMixingLengthScalarDiffusion";
     351          14 :     InputParameters params = getFactory().getValidParams(kernel_type);
     352          14 :     assignBlocks(params, _blocks);
     353          14 :     params.set<MooseFunctorName>(NS::mixing_length) = _mixing_length_name;
     354          56 :     for (const auto dim_i : make_range(dimension()))
     355          56 :       params.set<MooseFunctorName>(u_names[dim_i]) = _velocity_names[dim_i];
     356             : 
     357          28 :     for (const auto & name_i : index_range(passive_scalar_names))
     358             :     {
     359          28 :       params.set<NonlinearVariableName>("variable") = passive_scalar_names[name_i];
     360          14 :       if (passive_scalar_schmidt_number.size() > 1)
     361           0 :         params.set<Real>("schmidt_number") = passive_scalar_schmidt_number[name_i];
     362          14 :       else if (passive_scalar_schmidt_number.size() == 1)
     363          14 :         params.set<Real>("schmidt_number") = passive_scalar_schmidt_number[0];
     364             :       else
     365           0 :         params.set<Real>("schmidt_number") = 1.0;
     366             : 
     367          28 :       getProblem().addFVKernel(
     368          28 :           kernel_type, prefix() + passive_scalar_names[name_i] + "_mixing_length", params);
     369             :     }
     370          70 :   }
     371          36 :   else if (_turbulence_model == "k-epsilon")
     372             :   {
     373          36 :     const std::string kernel_type = "FVDiffusion";
     374          36 :     InputParameters params = getFactory().getValidParams(kernel_type);
     375          36 :     assignBlocks(params, _blocks);
     376             : 
     377         108 :     for (const auto & name_i : index_range(passive_scalar_names))
     378             :     {
     379         144 :       params.set<NonlinearVariableName>("variable") = passive_scalar_names[name_i];
     380         144 :       params.set<MooseFunctorName>("coeff") = NS::mu_t_passive_scalar;
     381         144 :       getProblem().addFVKernel(
     382         144 :           kernel_type, prefix() + passive_scalar_names[name_i] + "_turbulent_diffusion", params);
     383             :     }
     384          36 :   }
     385          50 : }
     386             : 
     387             : void
     388           0 : WCNSFVTurbulencePhysics::addKEpsilonTimeDerivatives()
     389             : {
     390           0 :   const std::string kernel_type = "FVFunctorTimeKernel";
     391           0 :   InputParameters params = getFactory().getValidParams(kernel_type);
     392           0 :   assignBlocks(params, _blocks);
     393             : 
     394           0 :   params.set<NonlinearVariableName>("variable") = _tke_name;
     395           0 :   if (shouldCreateTimeDerivative(_tke_name, _blocks, /*error if already defined*/ false))
     396           0 :     getProblem().addFVKernel(kernel_type, prefix() + "tke_time", params);
     397           0 :   params.set<NonlinearVariableName>("variable") = _tked_name;
     398           0 :   if (shouldCreateTimeDerivative(_tked_name, _blocks, /*error if already defined*/ false))
     399           0 :     getProblem().addFVKernel(kernel_type, prefix() + "tked_time", params);
     400           0 : }
     401             : 
     402             : void
     403          60 : WCNSFVTurbulencePhysics::addKEpsilonAdvection()
     404             : {
     405          60 :   const std::string kernel_type = "INSFVTurbulentAdvection";
     406          60 :   InputParameters params = getFactory().getValidParams(kernel_type);
     407             : 
     408          60 :   assignBlocks(params, _blocks);
     409             : 
     410          60 :   params.set<MooseEnum>("velocity_interp_method") = _velocity_interpolation;
     411          60 :   params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName();
     412          60 :   params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
     413          60 :   params.set<bool>("neglect_advection_derivatives") =
     414         120 :       getParam<bool>("neglect_advection_derivatives");
     415             : 
     416         120 :   params.set<MooseEnum>("advected_interp_method") =
     417         120 :       getParam<MooseEnum>("tke_advection_interpolation");
     418         120 :   params.set<NonlinearVariableName>("variable") = _tke_name;
     419         120 :   getProblem().addFVKernel(kernel_type, prefix() + "tke_advection", params);
     420         120 :   params.set<NonlinearVariableName>("variable") = _tked_name;
     421          60 :   params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
     422         120 :   params.set<MooseEnum>("advected_interp_method") =
     423         180 :       getParam<MooseEnum>("tked_advection_interpolation");
     424         120 :   getProblem().addFVKernel(kernel_type, prefix() + "tked_advection", params);
     425         120 : }
     426             : 
     427             : void
     428          60 : WCNSFVTurbulencePhysics::addKEpsilonDiffusion()
     429             : {
     430             :   {
     431          60 :     const std::string kernel_type = "INSFVTurbulentDiffusion";
     432          60 :     InputParameters params = getFactory().getValidParams(kernel_type);
     433          60 :     assignBlocks(params, _blocks);
     434             : 
     435         120 :     params.set<NonlinearVariableName>("variable") = _tke_name;
     436         120 :     params.set<MooseFunctorName>("coeff") = _flow_equations_physics->dynamicViscosityName();
     437         120 :     getProblem().addFVKernel(kernel_type, prefix() + "tke_diffusion_mu", params);
     438             : 
     439          60 :     params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
     440         120 :     params.set<NonlinearVariableName>("variable") = _tked_name;
     441         120 :     getProblem().addFVKernel(kernel_type, prefix() + "tked_diffusion_mu", params);
     442          60 :   }
     443             : 
     444             :   {
     445          60 :     const std::string kernel_type = "INSFVTurbulentDiffusion";
     446          60 :     InputParameters params = getFactory().getValidParams(kernel_type);
     447          60 :     assignBlocks(params, _blocks);
     448             : 
     449         120 :     params.set<NonlinearVariableName>("variable") = _tke_name;
     450         120 :     params.set<MooseFunctorName>("coeff") = _turbulent_viscosity_name;
     451         180 :     params.set<MooseFunctorName>("scaling_coef") = getParam<MooseFunctorName>("sigma_k");
     452         120 :     params.set<MooseEnum>("coeff_interp_method") =
     453         180 :         getParam<MooseEnum>("turbulent_viscosity_interp_method");
     454         120 :     getProblem().addFVKernel(kernel_type, prefix() + "tke_diffusion_mu_turb", params);
     455             : 
     456         120 :     params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
     457         120 :     params.set<NonlinearVariableName>("variable") = _tked_name;
     458         180 :     params.set<MooseFunctorName>("scaling_coef") = getParam<MooseFunctorName>("sigma_eps");
     459         120 :     getProblem().addFVKernel(kernel_type, prefix() + "tked_diffusion_mu_turb", params);
     460          60 :   }
     461          60 : }
     462             : 
     463             : void
     464          60 : WCNSFVTurbulencePhysics::addKEpsilonSink()
     465             : {
     466         240 :   const std::string u_names[3] = {"u", "v", "w"};
     467             :   {
     468          60 :     const std::string kernel_type = "INSFVTKESourceSink";
     469          60 :     InputParameters params = getFactory().getValidParams(kernel_type);
     470          60 :     assignBlocks(params, _blocks);
     471         120 :     params.set<NonlinearVariableName>("variable") = _tke_name;
     472          60 :     params.set<MooseFunctorName>(NS::TKED) = _tked_name;
     473          60 :     params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
     474          60 :     params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
     475          60 :     params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
     476         120 :     params.set<Real>("C_mu") = getParam<Real>("C_mu");
     477         120 :     params.set<Real>("C_pl") = getParam<Real>("C_pl");
     478         120 :     params.set<bool>("linearized_model") = getParam<bool>("linearize_sink_sources");
     479          60 :     params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
     480          60 :     params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
     481             :     // Currently only Newton method for WCNSFVTurbulencePhysics
     482          60 :     params.set<bool>("newton_solve") = true;
     483         240 :     for (const auto d : make_range(dimension()))
     484         240 :       params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
     485         120 :     getProblem().addFVKernel(kernel_type, prefix() + "tke_source_sink", params);
     486          60 :   }
     487             : 
     488             :   {
     489          60 :     const std::string kernel_type = "INSFVTKEDSourceSink";
     490          60 :     InputParameters params = getFactory().getValidParams(kernel_type);
     491          60 :     assignBlocks(params, _blocks);
     492         120 :     params.set<NonlinearVariableName>("variable") = _tked_name;
     493          60 :     params.set<MooseFunctorName>(NS::TKE) = _tke_name;
     494          60 :     params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
     495          60 :     params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
     496          60 :     params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
     497         120 :     params.set<Real>("C_mu") = getParam<Real>("C_mu");
     498         120 :     params.set<Real>("C_pl") = getParam<Real>("C_pl");
     499         120 :     params.set<bool>("linearized_model") = getParam<bool>("linearize_sink_sources");
     500          60 :     params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
     501          60 :     params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
     502         180 :     params.set<MooseFunctorName>("C1_eps") = getParam<MooseFunctorName>("C1_eps");
     503         180 :     params.set<MooseFunctorName>("C2_eps") = getParam<MooseFunctorName>("C2_eps");
     504             :     // Currently only Newton method for WCNSFVTurbulencePhysics
     505          60 :     params.set<bool>("newton_solve") = true;
     506         240 :     for (const auto d : make_range(dimension()))
     507         240 :       params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
     508         120 :     getProblem().addFVKernel(kernel_type, prefix() + "tked_source_sink", params);
     509          60 :   }
     510         300 : }
     511             : 
     512             : void
     513         576 : WCNSFVTurbulencePhysics::addAuxiliaryKernels()
     514             : {
     515         576 :   WCNSFVTurbulencePhysicsBase::addAuxiliaryKernels();
     516             : 
     517             :   // Note that if we are restarting this will overwrite the restarted mixing-length
     518         576 :   if (_turbulence_model == "mixing-length")
     519             :   {
     520          37 :     const std::string ml_kernel_type = "WallDistanceMixingLengthAux";
     521          37 :     InputParameters ml_params = getFactory().getValidParams(ml_kernel_type);
     522          37 :     assignBlocks(ml_params, _blocks);
     523          74 :     ml_params.set<AuxVariableName>("variable") = _mixing_length_name;
     524          74 :     ml_params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
     525          74 :     if (parameters().isParamValid("mixing_length_aux_execute_on"))
     526          58 :       ml_params.set<ExecFlagEnum>("execute_on") =
     527          58 :           getParam<ExecFlagEnum>("mixing_length_aux_execute_on");
     528             :     else
     529          32 :       ml_params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
     530          74 :     ml_params.set<MooseFunctorName>("von_karman_const") =
     531          37 :         getParam<MooseFunctorName>("von_karman_const");
     532          74 :     ml_params.set<MooseFunctorName>("von_karman_const_0") =
     533          37 :         getParam<MooseFunctorName>("von_karman_const_0");
     534         111 :     ml_params.set<MooseFunctorName>("delta") = getParam<MooseFunctorName>("mixing_length_delta");
     535             : 
     536          74 :     getProblem().addAuxKernel(ml_kernel_type, prefix() + "mixing_length_aux ", ml_params);
     537          37 :   }
     538         584 : }
     539             : 
     540             : void
     541         562 : WCNSFVTurbulencePhysics::addFVBCs()
     542             : {
     543        2248 :   const std::string u_names[3] = {"u", "v", "w"};
     544             : 
     545         682 :   if (_turbulence_model == "k-epsilon" && getParam<bool>("mu_t_as_aux_variable"))
     546             :   {
     547             :     mooseAssert(_flow_equations_physics, "Should have a flow equation physics");
     548          42 :     const std::string bc_type = "INSFVTurbulentViscosityWallFunction";
     549          42 :     InputParameters params = getFactory().getValidParams(bc_type);
     550          42 :     params.set<std::vector<BoundaryName>>("boundary") = _turbulence_walls;
     551          84 :     params.set<NonlinearVariableName>("variable") = _turbulent_viscosity_name;
     552          42 :     params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
     553          42 :     params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
     554          42 :     params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
     555          42 :     params.set<MooseFunctorName>(NS::TKE) = _tke_name;
     556          84 :     params.set<Real>("C_mu") = getParam<Real>("C_mu");
     557          42 :     params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
     558         168 :     for (const auto d : make_range(dimension()))
     559         168 :       params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
     560             : 
     561          84 :     getProblem().addFVBC(bc_type, prefix() + "turbulence_walls", params);
     562             :     // Energy wall function boundary conditions are added in the WCNSFVFluidEnergyPhysics
     563             :     // because it facilitates counting the number of walls, specifying energy wall functors
     564             :     // the same way as for boundary conditions
     565          42 :   }
     566        2810 : }
     567             : 
     568             : void
     569         576 : WCNSFVTurbulencePhysics::addMaterials()
     570             : {
     571         576 :   if (_turbulence_model == "mixing-length")
     572             :   {
     573         148 :     const std::string u_names[3] = {"u", "v", "w"};
     574             :     InputParameters params =
     575          37 :         getFactory().getValidParams("MixingLengthTurbulentViscosityFunctorMaterial");
     576          37 :     assignBlocks(params, _blocks);
     577             : 
     578         148 :     for (const auto d : make_range(dimension()))
     579         148 :       params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
     580             : 
     581          37 :     params.set<MooseFunctorName>(NS::mixing_length) = _mixing_length_name;
     582          37 :     params.set<MooseFunctorName>(NS::density) = _density_name;
     583          37 :     params.set<MooseFunctorName>(NS::mu) = _dynamic_viscosity_name;
     584             : 
     585         111 :     getProblem().addMaterial("MixingLengthTurbulentViscosityFunctorMaterial",
     586          37 :                              prefix() + "mixing_length_material",
     587             :                              params);
     588         148 :   }
     589         576 :   WCNSFVTurbulencePhysicsBase::addMaterials();
     590         576 : }
     591             : 
     592             : unsigned short
     593        1722 : WCNSFVTurbulencePhysics::getNumberAlgebraicGhostingLayersNeeded() const
     594             : {
     595        1722 :   unsigned short ghost_layers = _flow_equations_physics->getNumberAlgebraicGhostingLayersNeeded();
     596             :   // due to the computation of the eddy-diffusivity from the strain tensor
     597        1722 :   if (_turbulence_model == "mixing-length")
     598         214 :     ghost_layers = std::max(ghost_layers, (unsigned short)3);
     599        1722 :   return ghost_layers;
     600             : }

Generated by: LCOV version 1.14