LCOV - code coverage report
Current view: top level - src/physics - WCNSLinearFVTurbulencePhysics.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: #32971 (54bef8) with base c6cf66 Lines: 155 183 84.7 %
Date: 2026-05-29 20:37:52 Functions: 11 13 84.6 %
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 "WCNSLinearFVTurbulencePhysics.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             : 
      19             : registerWCNSFVTurbulenceBaseTasks("NavierStokesApp", WCNSLinearFVTurbulencePhysics);
      20             : registerMooseAction("NavierStokesApp", WCNSLinearFVTurbulencePhysics, "add_functor_material");
      21             : 
      22             : InputParameters
      23          24 : WCNSLinearFVTurbulencePhysics::validParams()
      24             : {
      25          24 :   InputParameters params = WCNSFVTurbulencePhysicsBase::validParams();
      26          24 :   params.addClassDescription(
      27             :       "Define a turbulence model for an incompressible or weakly-compressible Navier Stokes "
      28             :       "flow with a linear finite volume discretization");
      29             : 
      30         120 :   params.addParam<std::vector<SolverSystemName>>(
      31             :       "system_names",
      32             :       {"TKE_system", "TKED_system"},
      33             :       "Names of the linear solver systems for each equation. Default is set for K-Epsilon and "
      34             :       "should be adapted for other models");
      35             : 
      36             :   // Not an option
      37          48 :   params.addParam<bool>("mu_t_as_aux_variable",
      38          48 :                         true,
      39             :                         "Whether to use an auxiliary variable instead of a functor material "
      40             :                         "property for the turbulent viscosity");
      41          24 :   params.suppressParameter<bool>("mu_t_as_aux_variable");
      42          24 :   params.suppressParameter<bool>("turbulent_viscosity_two_term_bc_expansion");
      43             : 
      44             :   // Could be implemented when boundary conditions are implemented in turbulence physics
      45          24 :   params.suppressParameter<bool>("tke_two_term_bc_expansion");
      46          24 :   params.suppressParameter<bool>("tked_two_term_bc_expansion");
      47             : 
      48             :   // Not implemented
      49          24 :   params.suppressParameter<MooseEnum>("wall_treatment_T");
      50          24 :   params.suppressParameter<MooseEnum>("tke_face_interpolation");
      51          24 :   params.suppressParameter<MooseEnum>("tked_face_interpolation");
      52             : 
      53             :   // LinearFV-specific parameters
      54          48 :   params.addParam<bool>(
      55             :       "use_nonorthogonal_correction",
      56          48 :       true,
      57             :       "Whether to use a non-orthogonal correction. This can potentially slow down convergence "
      58             :       ", but reduces numerical dispersion on non-orthogonal meshes. Can be safely turned off on "
      59             :       "orthogonal meshes.");
      60          48 :   params.addParamNamesToGroup("use_nonorthogonal_correction", "Numerical scheme");
      61          24 :   return params;
      62           0 : }
      63             : 
      64          24 : WCNSLinearFVTurbulencePhysics::WCNSLinearFVTurbulencePhysics(const InputParameters & parameters)
      65          24 :   : WCNSFVTurbulencePhysicsBase(parameters)
      66             : {
      67          24 :   if (_turbulence_model != "k-epsilon")
      68           0 :     errorDependentParameter("turbulence_handling", "k-epsilon", {"use_nonorthogonal_correction"});
      69          24 :   if (_turbulence_model == "mixing-length")
      70           0 :     paramError("turbulence_handling",
      71             :                "Mixing length is not implemented for the linear finite volume discretization");
      72          24 : }
      73             : 
      74             : void
      75          24 : WCNSLinearFVTurbulencePhysics::initializePhysicsAdditional()
      76             : {
      77          24 :   if (_turbulence_model == "k-epsilon")
      78          24 :     getProblem().needSolutionState(1, Moose::SolutionIterationType::Nonlinear);
      79          24 : }
      80             : 
      81             : void
      82           0 : WCNSLinearFVTurbulencePhysics::checkIntegrity() const
      83             : {
      84             :   WCNSFVTurbulencePhysicsBase::checkIntegrity();
      85             : 
      86           0 :   if (_flow_equations_physics &&
      87           0 :       !_flow_equations_physics->getParam<bool>("include_deviatoric_stress"))
      88           0 :     _flow_equations_physics->paramWarning(
      89             :         "include_deviatoric_stress", "This should be set to true when using a turbulence model");
      90           0 : }
      91             : 
      92             : void
      93          24 : WCNSLinearFVTurbulencePhysics::addSolverVariables()
      94             : {
      95          24 :   if (_turbulence_model == "mixing-length" || _turbulence_model == "none")
      96           0 :     return;
      97          24 :   else if (_turbulence_model == "k-epsilon")
      98             :   {
      99             :     // Dont add if the user already defined the variable
     100             :     // Add turbulent kinetic energy variable
     101          24 :     if (!shouldCreateVariable(_tke_name, _blocks, /*error if aux*/ true))
     102           0 :       reportPotentiallyMissedParameters({"system_names"}, "MooseLinearVariableFVReal");
     103          24 :     else if (_define_variables)
     104             :     {
     105          24 :       std::string variable_type = "MooseLinearVariableFVReal";
     106             : 
     107          24 :       auto params = getFactory().getValidParams(variable_type);
     108          24 :       assignBlocks(params, _blocks);
     109          48 :       params.set<SolverSystemName>("solver_sys") = getSolverSystem(_tke_name);
     110             : 
     111          24 :       getProblem().addVariable(variable_type, _tke_name, params);
     112          24 :     }
     113             :     else
     114           0 :       paramError("turbulence_kinetic_energy_variable",
     115           0 :                  "Variable (" + _tke_name +
     116             :                      ") supplied to the WCNSLinearFVTurbulencePhysics does not exist!");
     117             : 
     118             :     // Add turbulent kinetic energy dissipation variable
     119          24 :     if (!shouldCreateVariable(_tked_name, _blocks, /*error if aux*/ true))
     120           0 :       reportPotentiallyMissedParameters({"system_names"}, "MooseLinearVariableFVReal");
     121          24 :     else if (_define_variables)
     122             :     {
     123          24 :       std::string variable_type = "MooseLinearVariableFVReal";
     124             : 
     125          24 :       auto params = getFactory().getValidParams(variable_type);
     126          24 :       assignBlocks(params, _blocks);
     127          48 :       params.set<SolverSystemName>("solver_sys") = getSolverSystem(_tked_name);
     128             : 
     129          24 :       getProblem().addVariable(variable_type, _tked_name, params);
     130          24 :     }
     131             :     else
     132           0 :       paramError("turbulence_kinetic_energy_dissipation_variable",
     133           0 :                  "Variable (" + _tked_name +
     134             :                      ") supplied to the WCNSLinearFVTurbulencePhysics does not exist!");
     135             :   }
     136             : }
     137             : 
     138             : void
     139          24 : WCNSLinearFVTurbulencePhysics::addFVKernels()
     140             : {
     141          24 :   if (_turbulence_model == "none")
     142             :     return;
     143             : 
     144             :   // For linear FV discretization:
     145             :   // We have to add the kernel in the flow/heat/scalar physics with mu_eff instead of two kernels
     146             :   // one with mu, one with mu_turb, and chose one of the two to NOT have the advective term
     147             :   // Also, flux boundary conditions would be executed twice with two kernels
     148             : 
     149             :   // Turbulence models with their own set of equations
     150          24 :   if (_turbulence_model == "k-epsilon")
     151             :   {
     152          24 :     if (isTransient())
     153           0 :       addKEpsilonTimeDerivatives();
     154          24 :     addKEpsilonAdvection();
     155          24 :     addKEpsilonDiffusion();
     156          24 :     addKEpsilonSink();
     157             :   }
     158             : }
     159             : 
     160             : void
     161           0 : WCNSLinearFVTurbulencePhysics::addKEpsilonTimeDerivatives()
     162             : {
     163           0 :   const std::string kernel_type = "LinearFVTimeDerivative";
     164           0 :   InputParameters params = getFactory().getValidParams(kernel_type);
     165           0 :   assignBlocks(params, _blocks);
     166             : 
     167           0 :   params.set<LinearVariableName>("variable") = _tke_name;
     168           0 :   params.set<MooseFunctorName>("factor") = _flow_equations_physics->densityName();
     169           0 :   if (shouldCreateTimeDerivative(_tke_name, _blocks, /*error if already defined*/ false))
     170           0 :     getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_time", params);
     171           0 :   params.set<LinearVariableName>("variable") = _tked_name;
     172           0 :   if (shouldCreateTimeDerivative(_tked_name, _blocks, /*error if already defined*/ false))
     173           0 :     getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_time", params);
     174           0 : }
     175             : 
     176             : void
     177          24 : WCNSLinearFVTurbulencePhysics::addKEpsilonAdvection()
     178             : {
     179          24 :   const std::string kernel_type = "LinearFVTurbulentAdvection";
     180          24 :   InputParameters params = getFactory().getValidParams(kernel_type);
     181             : 
     182          24 :   assignBlocks(params, _blocks);
     183             : 
     184          24 :   params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName();
     185          48 :   params.set<MooseEnum>("advected_interp_method") =
     186          48 :       getParam<MooseEnum>("tke_advection_interpolation");
     187          48 :   params.set<LinearVariableName>("variable") = _tke_name;
     188          48 :   getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_advection", params);
     189          48 :   params.set<LinearVariableName>("variable") = _tked_name;
     190          24 :   params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
     191          48 :   params.set<MooseEnum>("advected_interp_method") =
     192          72 :       getParam<MooseEnum>("tked_advection_interpolation");
     193          48 :   getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_advection", params);
     194          48 : }
     195             : 
     196             : void
     197          24 : WCNSLinearFVTurbulencePhysics::addKEpsilonDiffusion()
     198             : {
     199             :   {
     200          24 :     const std::string kernel_type = "LinearFVTurbulentDiffusion";
     201          24 :     InputParameters params = getFactory().getValidParams(kernel_type);
     202          24 :     assignBlocks(params, _blocks);
     203          24 :     params.set<bool>("use_nonorthogonal_correction") =
     204          48 :         getParam<bool>("use_nonorthogonal_correction");
     205             : 
     206             :     // Note: we have to use a single diffusion kernel in case we have a flux BC so it is not applied
     207             :     // twice
     208          48 :     params.set<LinearVariableName>("variable") = _tke_name;
     209          48 :     params.set<MooseFunctorName>("diffusion_coeff") = "mu_eff_tke";
     210          48 :     getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_diffusion_mu", params);
     211             : 
     212          24 :     params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
     213          48 :     params.set<LinearVariableName>("variable") = _tked_name;
     214          48 :     params.set<MooseFunctorName>("diffusion_coeff") = "mu_eff_tked";
     215          48 :     getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_diffusion_mu", params);
     216          24 :   }
     217          24 : }
     218             : 
     219             : void
     220          24 : WCNSLinearFVTurbulencePhysics::addKEpsilonSink()
     221             : {
     222          96 :   const std::string u_names[3] = {"u", "v", "w"};
     223             :   {
     224          24 :     const std::string kernel_type = "LinearFVTKESourceSink";
     225          24 :     InputParameters params = getFactory().getValidParams(kernel_type);
     226          24 :     assignBlocks(params, _blocks);
     227          48 :     params.set<LinearVariableName>("variable") = _tke_name;
     228          24 :     params.set<MooseFunctorName>(NS::TKED) = _tked_name;
     229          24 :     params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
     230          24 :     params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
     231          24 :     params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
     232          48 :     params.set<Real>("C_mu") = getParam<Real>("C_mu");
     233          48 :     params.set<Real>("C_pl") = getParam<Real>("C_pl");
     234          24 :     params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
     235          24 :     params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
     236          96 :     for (const auto d : make_range(dimension()))
     237          96 :       params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
     238          48 :     getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_source_sink", params);
     239          24 :   }
     240             : 
     241             :   {
     242          24 :     const std::string kernel_type = "LinearFVTKEDSourceSink";
     243          24 :     InputParameters params = getFactory().getValidParams(kernel_type);
     244          24 :     assignBlocks(params, _blocks);
     245          48 :     params.set<LinearVariableName>("variable") = _tked_name;
     246          24 :     params.set<MooseFunctorName>(NS::TKE) = _tke_name;
     247          24 :     params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
     248          24 :     params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
     249          24 :     params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
     250          24 :     params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
     251          24 :     params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
     252          72 :     params.set<MooseFunctorName>("C1_eps") = getParam<MooseFunctorName>("C1_eps");
     253          72 :     params.set<MooseFunctorName>("C2_eps") = getParam<MooseFunctorName>("C2_eps");
     254          48 :     params.set<Real>("C_mu") = getParam<Real>("C_mu");
     255          48 :     params.set<Real>("C_pl") = getParam<Real>("C_pl");
     256          96 :     for (const auto d : make_range(dimension()))
     257          96 :       params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
     258          48 :     getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_source_sink", params);
     259          24 :   }
     260         120 : }
     261             : 
     262             : void
     263          24 : WCNSLinearFVTurbulencePhysics::addFVBCs()
     264             : {
     265          96 :   const std::string u_names[3] = {"u", "v", "w"};
     266             : 
     267          72 :   if (_turbulence_model == "k-epsilon" && getParam<bool>("mu_t_as_aux_variable"))
     268             :   {
     269             :     mooseAssert(_flow_equations_physics, "Should have a flow equation physics");
     270          24 :     const std::string bc_type = "LinearFVTurbulentViscosityWallFunctionBC";
     271          24 :     InputParameters params = getFactory().getValidParams(bc_type);
     272          24 :     params.set<std::vector<BoundaryName>>("boundary") = _turbulence_walls;
     273          48 :     params.set<LinearVariableName>("variable") = _turbulent_viscosity_name;
     274          24 :     params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
     275          24 :     params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
     276          24 :     params.set<MooseFunctorName>(NS::TKE) = _tke_name;
     277          48 :     params.set<Real>("C_mu") = getParam<Real>("C_mu");
     278          24 :     params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
     279          96 :     for (const auto d : make_range(dimension()))
     280          96 :       params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
     281             : 
     282          48 :     getProblem().addLinearFVBC(bc_type, prefix() + "turbulence_walls", params);
     283             :     // Energy wall function boundary conditions are added in the WCNSFVFluidEnergyPhysics
     284             :     // because it facilitates counting the number of walls, specifying energy wall functors
     285             :     // the same way as for boundary conditions
     286          24 :   }
     287         120 : }
     288             : 
     289             : void
     290          24 : WCNSLinearFVTurbulencePhysics::addFunctorMaterials()
     291             : {
     292             :   // Functor materials for the diffusion coefficients
     293          24 :   if (_turbulence_model == "k-epsilon")
     294             :   {
     295             :     // Since sigma_k = 1 in the standard k-epsilon, this is often unnecessary
     296          24 :     const std::string mat_type = "FunctorEffectiveDynamicViscosity";
     297          24 :     InputParameters params = getFactory().getValidParams(mat_type);
     298          24 :     assignBlocks(params, _blocks);
     299          48 :     params.set<MooseFunctorName>("property_name") = "mu_eff_tke";
     300          24 :     params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
     301          24 :     params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
     302          48 :     params.set<MooseFunctorName>(NS::mu_t + "_inverse_factor") =
     303          48 :         getParam<MooseFunctorName>("sigma_k");
     304          72 :     getProblem().addMaterial(mat_type, prefix() + "mu_eff_tke", params);
     305             : 
     306          48 :     params.set<MooseFunctorName>("property_name") = "mu_eff_tked";
     307          48 :     params.set<MooseFunctorName>(NS::mu_t + "_inverse_factor") =
     308          48 :         getParam<MooseFunctorName>("sigma_eps");
     309          48 :     getProblem().addMaterial(mat_type, prefix() + "mu_eff_tked", params);
     310          24 :   }
     311          24 : }
     312             : 
     313             : unsigned short
     314          72 : WCNSLinearFVTurbulencePhysics::getNumberAlgebraicGhostingLayersNeeded() const
     315             : {
     316          72 :   return _flow_equations_physics->getNumberAlgebraicGhostingLayersNeeded();
     317             : }

Generated by: LCOV version 1.14