https://mooseframework.inl.gov
INSFVTKEDWallFunctionBC.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 #include "Function.h"
12 #include "NavierStokesMethods.h"
13 #include "NS.h"
14 
16 
19 {
21  params.addClassDescription("Adds Reichardt extrapolated wall values to set up directly the"
22  "Dirichlet BC for the turbulent kinetic energy dissipation rate.");
23  params.addRequiredParam<MooseFunctorName>("u", "The velocity in the x direction.");
24  params.addParam<MooseFunctorName>("v", "The velocity in the y direction.");
25  params.addParam<MooseFunctorName>("w", "The velocity in the z direction.");
26  params.addRequiredParam<MooseFunctorName>(NS::density, "Density");
27  params.addRequiredParam<MooseFunctorName>(NS::mu, "Dynamic viscosity.");
28  params.addRequiredParam<MooseFunctorName>(NS::mu_t, "The turbulent viscosity.");
29  params.addRequiredParam<MooseFunctorName>("k", "The turbulent kinetic energy.");
30  params.deprecateParam("k", NS::TKE, "01/01/2025");
31  params.addParam<MooseFunctorName>("C_mu", 0.09, "Coupled turbulent kinetic energy closure.");
32  params.addParam<bool>("newton_solve", false, "Whether a Newton nonlinear solve is being used");
33  params.addParamNamesToGroup("newton_solve", "Advanced");
34  return params;
35 }
36 
38  : FVDirichletBCBase(params),
39  _dim(_subproblem.mesh().dimension()),
40  _u_var(getFunctor<ADReal>("u")),
41  _v_var(params.isParamValid("v") ? &(getFunctor<ADReal>("v")) : nullptr),
42  _w_var(params.isParamValid("w") ? &(getFunctor<ADReal>("w")) : nullptr),
43  _rho(getFunctor<ADReal>(NS::density)),
44  _mu(getFunctor<ADReal>(NS::mu)),
45  _mu_t(getFunctor<ADReal>(NS::mu_t)),
46  _k(getFunctor<ADReal>(NS::TKE)),
47  _C_mu(getFunctor<ADReal>("C_mu")),
48  _newton_solve(getParam<bool>("newton_solve"))
49 {
50 }
51 
52 ADReal
54 {
55  const Real dist = std::abs((fi.elemCentroid() - fi.faceCentroid()) * fi.normal());
56  const Elem & _current_elem = fi.elem();
57  const auto mu = _mu(makeElemArg(&_current_elem), state);
58  const auto rho = _rho(makeElemArg(&_current_elem), state);
59 
60  // Assign boundary weights to element
61  // This is based on the theory of linear TKE development for each boundary
62  // This is, it assumes no interaction across turbulence production from boundaries
63  Real weight = 0.0;
64  for (unsigned int i_side = 0; i_side < _current_elem.n_sides(); ++i_side)
65  weight += static_cast<Real>(_subproblem.mesh().getBoundaryIDs(&_current_elem, i_side).size());
66 
67  // Get the velocity vector
68  ADRealVectorValue velocity(_u_var(makeElemArg(&_current_elem), state));
69  if (_v_var)
70  velocity(1) = (*_v_var)(makeElemArg(&_current_elem), state);
71  if (_w_var)
72  velocity(2) = (*_w_var)(makeElemArg(&_current_elem), state);
73 
74  // Compute the velocity and direction of the velocity component that is parallel to the wall
75  const ADReal parallel_speed =
76  NS::computeSpeed(velocity - velocity * (fi.normal()) * (fi.normal()));
77 
78  // Get friction velocity
79  const ADReal u_star = NS::findUStar(mu, rho, parallel_speed, dist);
80 
81  // Get associated non-dimensional wall distance
82  const ADReal y_plus = dist * u_star * rho / mu;
83 
84  const auto TKE = _k(makeElemArg(&_current_elem), state);
85 
86  if (y_plus <= 5.0) // sub-laminar layer
87  {
88  const auto laminar_value = 2.0 * weight * TKE * mu / std::pow(dist, 2);
89  if (!_newton_solve)
90  return laminar_value;
91  else
92  // Additional zero term to make sure new derivatives are not introduced as y_plus
93  // changes
94  return laminar_value + 0 * _mu_t(makeElemArg(&_current_elem), state);
95  }
96  else if (y_plus >= 30.0) // log-layer
97  {
98  const auto turbulent_value = weight * _C_mu(makeElemArg(&_current_elem), state) *
99  std::pow(std::abs(TKE), 1.5) /
100  (_mu_t(makeElemArg(&_current_elem), state) * dist);
101  if (!_newton_solve)
102  return turbulent_value;
103  else
104  // Additional zero term to make sure new derivatives are not introduced as y_plus changes
105  return turbulent_value + 0 * mu;
106  }
107  else // blending function
108  {
109  const auto laminar_value = 2.0 * weight * TKE * mu / std::pow(dist, 2);
110  const auto turbulent_value = weight * _C_mu(makeElemArg(&_current_elem), state) *
111  std::pow(std::abs(TKE), 1.5) /
112  (_mu_t(makeElemArg(&_current_elem), state) * dist);
113  const auto interpolation_coef = (y_plus - 5.0) / 25.0;
114  return (interpolation_coef * (turbulent_value - laminar_value) + laminar_value);
115  }
116 }
const Moose::Functor< ADReal > & _rho
Density.
virtual MooseMesh & mesh()=0
ADReal boundaryValue(const FaceInfo &fi, const Moose::StateArg &state) const override
const Moose::Functor< ADReal > & _mu
Dynamic viscosity.
static const std::string mu_t
Definition: NS.h:125
const Moose::Functor< ADReal > & _mu_t
Turbulent dynamic viscosity.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const Elem & elem() const
const Point & faceCentroid() const
MeshBase & mesh
static const std::string density
Definition: NS.h:33
static const std::string TKE
Definition: NS.h:176
const Moose::Functor< ADReal > & _C_mu
C_mu turbulent coefficient.
static InputParameters validParams()
const Moose::Functor< ADReal > * _v_var
y-velocity
DualNumber< Real, DNDerivativeType, true > ADReal
const Moose::Functor< ADReal > & _k
Turbulent kinetic energy.
void addRequiredParam(const std::string &name, const std::string &doc_string)
const Moose::Functor< ADReal > & _u_var
x-velocity
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
const Point & elemCentroid() const
static InputParameters validParams()
void deprecateParam(const std::string &old_name, const std::string &new_name, const std::string &removal_date)
dof_id_type weight(const MeshBase &mesh, const processor_id_type pid)
static const std::string mu
Definition: NS.h:123
SubProblem & _subproblem
const Point & normal() const
const Moose::Functor< ADReal > * _w_var
z-velocity
registerMooseObject("NavierStokesApp", INSFVTKEDWallFunctionBC)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const bool _newton_solve
Whether we are using a newton solve.
Applies a wall function to the turbulent kinetic energy dissipation rate.
void addClassDescription(const std::string &doc_string)
static const std::string velocity
Definition: NS.h:45
ADReal findUStar(const ADReal &mu, const ADReal &rho, const ADReal &u, Real dist)
Finds the friction velocity using standard velocity wall functions formulation.
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
ADReal computeSpeed(const ADRealVectorValue &velocity)
Compute the speed (velocity norm) given the supplied velocity.
MooseUnits pow(const MooseUnits &, int)
INSFVTKEDWallFunctionBC(const InputParameters &parameters)
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)