https://mooseframework.inl.gov
WallFunctionYPlusAux.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 
10 #include "WallFunctionYPlusAux.h"
11 #include "NavierStokesMethods.h"
12 
13 registerMooseObject("NavierStokesApp", WallFunctionYPlusAux);
14 
17 {
19  params.addClassDescription(
20  "Calculates y+ value according to the algebraic velocity standard wall function.");
21  params.addRequiredCoupledVar("u", "The velocity in the x direction.");
22  params.addCoupledVar("v", "The velocity in the y direction.");
23  params.addCoupledVar("w", "The velocity in the z direction.");
24  params.addRequiredParam<MooseFunctorName>("rho", "fluid density");
25  params.addRequiredParam<MooseFunctorName>("mu", "Dynamic viscosity");
26  params.addRequiredParam<std::vector<BoundaryName>>("walls",
27  "Boundaries that correspond to solid walls");
28  return params;
29 }
30 
32  : AuxKernel(params),
33  _dim(_subproblem.mesh().dimension()),
34  _u_var(dynamic_cast<const INSFVVelocityVariable *>(getFieldVar("u", 0))),
35  _v_var(params.isParamValid("v")
36  ? dynamic_cast<const INSFVVelocityVariable *>(getFieldVar("v", 0))
37  : nullptr),
38  _w_var(params.isParamValid("w")
39  ? dynamic_cast<const INSFVVelocityVariable *>(getFieldVar("w", 0))
40  : nullptr),
41  _rho(getFunctor<ADReal>("rho")),
42  _mu(getFunctor<ADReal>("mu")),
43  _wall_boundary_names(getParam<std::vector<BoundaryName>>("walls"))
44 {
45  if (!_u_var)
46  paramError("u", "the u velocity must be an INSFVVelocityVariable.");
47 
48  if (_dim >= 2 && !_v_var)
49  paramError("v",
50  "In two or more dimensions, the v velocity must be supplied and it must be an "
51  "INSFVVelocityVariable.");
52 
53  if (_dim >= 3 && !params.isParamValid("w"))
54  paramError("w",
55  "In three-dimensions, the w velocity must be supplied and it must be an "
56  "INSFVVelocityVariable.");
57 }
58 
59 Real
61 {
62  const Elem & elem = *_current_elem;
63 
64  bool wall_bounded = false;
65  Real min_wall_dist = 1e10;
66  Point wall_vec;
67  Point normal;
68  for (unsigned int i_side = 0; i_side < elem.n_sides(); ++i_side)
69  {
70  const std::vector<BoundaryID> side_bnds =
72  for (const BoundaryName & name : _wall_boundary_names)
73  {
75  for (BoundaryID side_id : side_bnds)
76  {
77  if (side_id == wall_id)
78  {
79  const FaceInfo * const fi = _mesh.faceInfo(&elem, i_side);
80  const Point & this_normal = fi->normal();
81  Point this_wall_vec = (elem.vertex_average() - fi->faceCentroid());
82  Real dist = std::abs(this_wall_vec * normal);
83  if (dist < min_wall_dist)
84  {
85  min_wall_dist = dist;
86  wall_vec = this_wall_vec;
87  normal = this_normal;
88  }
89  wall_bounded = true;
90  }
91  }
92  }
93  }
94 
95  if (!wall_bounded)
96  return 0;
97 
98  const auto state = determineState();
99 
100  // Get the velocity vector
102  if (_v_var)
103  velocity(1) = _v_var->getElemValue(&elem, state);
104  if (_w_var)
105  velocity(2) = _w_var->getElemValue(&elem, state);
106 
107  // Compute the velocity and direction of the velocity component that is parallel to the wall
108  Real dist = std::abs(wall_vec * normal);
109  ADReal perpendicular_speed = velocity * normal;
110  ADRealVectorValue parallel_velocity = velocity - perpendicular_speed * normal;
111  ADReal parallel_speed = parallel_velocity.norm();
112  ADRealVectorValue parallel_dir = parallel_velocity / parallel_speed;
113 
114  if (parallel_speed.value() < 1e-6)
115  return 0;
116 
117  if (!std::isfinite(parallel_speed.value()))
118  return parallel_speed.value();
119 
120  // Compute the friction velocity and the wall shear stress
121  const auto elem_arg = makeElemArg(_current_elem);
122  const auto rho = _rho(elem_arg, state);
123  const auto mu = _mu(elem_arg, state);
124  ADReal u_star = NS::findUStar(mu.value(), rho.value(), parallel_speed, dist);
125  ADReal tau = u_star * u_star * rho;
126 
127  return (dist * u_star * rho / mu).value();
128 }
virtual MooseMesh & mesh()=0
const std::vector< BoundaryName > & _wall_boundary_names
Wall boundaries.
auto norm() const -> decltype(std::norm(T()))
Moose::StateArg determineState() const
const boundary_id_type side_id
const Point & faceCentroid() const
virtual Real computeValue() override
MeshBase & mesh
DualNumber< Real, DNDerivativeType, true > ADReal
virtual const std::string & name() const
ADReal getElemValue(const Elem *elem, const StateArg &state) const
void addRequiredParam(const std::string &name, const std::string &doc_string)
const INSFVVelocityVariable *const _v_var
y-velocity
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
const std::vector< const FaceInfo *> & faceInfo() const
WallFunctionYPlusAux(const InputParameters &parameters)
static const std::string mu
Definition: NS.h:123
boundary_id_type BoundaryID
static InputParameters validParams()
const INSFVVelocityVariable *const _u_var
x-velocity
const Moose::Functor< ADReal > & _mu
Dynamic viscosity.
const Point & normal() const
void paramError(const std::string &param, Args... args) const
void addCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
registerMooseObject("NavierStokesApp", WallFunctionYPlusAux)
const Moose::Functor< ADReal > & _rho
Density.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
SubProblem & _subproblem
const Elem *const & _current_elem
const INSFVVelocityVariable *const _w_var
z-velocity
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()
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
Computes wall y+ based on wall functions.
const unsigned int _dim
the dimension of the simulation
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
bool isParamValid(const std::string &name) const