https://mooseframework.inl.gov
WallDistanceMixingLengthAux.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 
13 
16 {
18  params.addClassDescription(
19  "Computes the turbulent mixing length by assuming that it is "
20  "proportional to the distance from the nearest wall. The mixing"
21  "length is capped at a distance proportional to inputted parameter delta.");
22  params.addRequiredParam<std::vector<BoundaryName>>("walls",
23  "Boundaries that correspond to solid walls.");
24  params.addParam<MooseFunctorName>("von_karman_const", 0.41, ""); // Von Karman constant
25  params.addParam<MooseFunctorName>("von_karman_const_0", 0.09, ""); // Escudier' model parameter
26  params.addParam<MooseFunctorName>(
27  "delta",
28  1e9,
29  ""); // Tunable parameter related to the thickness of the boundary layer.
30  // When it is not specified, Prandtl's original mixing length model is retrieved.
31  return params;
32 }
33 
35  : AuxKernel(parameters),
36  _wall_boundary_names(getParam<std::vector<BoundaryName>>("walls")),
37  _von_karman_const(getFunctor<Real>("von_karman_const")),
38  _von_karman_const_0(getFunctor<Real>("von_karman_const_0")),
39  _delta(getFunctor<Real>("delta"))
40 {
41  const MeshBase & mesh = _subproblem.mesh().getMesh();
42  if (!mesh.is_replicated())
43  mooseError("WallDistanceMixingLengthAux only supports replicated meshes");
44  if (_var.feType() != FEType(CONSTANT, MONOMIAL))
45  paramError("variable",
46  "'",
47  name(),
48  "' computes the distance from the closest wall to an approximation of the element "
49  "centroid; only a single dof is required to hold this value. Consequently users "
50  "should always use a constant monomial finite element type (this is what finite "
51  "volume variables implicitly use) for the auxiliary variables.");
52 }
53 
54 Real
56 {
57  // Get reference to the libMesh mesh object
58  const MeshBase & l_mesh = _mesh.getMesh();
59 
60  // Get the ids of the wall boundaries
61  std::vector<BoundaryID> vec_ids = _mesh.getBoundaryIDs(_wall_boundary_names, true);
62 
63  // Loop over all boundaries
64  Real min_dist2 = 1e9;
65  const auto & bnd_to_elem_map = _mesh.getBoundariesToActiveSemiLocalElemIds();
66  for (BoundaryID bid : vec_ids)
67  {
68  // Get the set of elements on this boundary
69  auto search = bnd_to_elem_map.find(bid);
70  if (search == bnd_to_elem_map.end())
71  mooseError("Error computing wall distance; the boundary id ", bid, " is invalid");
72  const auto & bnd_elems = search->second;
73 
74  // Loop over all boundary elements and find the distance to the closest one
75  for (dof_id_type elem_id : bnd_elems)
76  {
77  const Elem & elem = l_mesh.elem_ref(elem_id);
78  const auto side = _mesh.sideWithBoundaryID(&elem, bid);
79  const auto bnd_pos = elem.side_ptr(side)->vertex_average();
80  const auto distance = bnd_pos - _q_point[_qp];
81  const auto dist2 = distance * distance;
82  mooseAssert(dist2 != 0, "This distance should never be 0");
83  min_dist2 = std::min(min_dist2, dist2);
84  }
85  }
86 
87  const Moose::ElemArg elem_arg = {_current_elem, false};
88  const Moose::StateArg state_arg = Moose::currentState();
89 
90  const auto delta = _delta(elem_arg, state_arg);
91  const auto von_karman_const = _von_karman_const(elem_arg, state_arg);
92  const auto von_karman_const_0 = _von_karman_const_0(elem_arg, state_arg);
93 
94  if (std::sqrt(min_dist2) / delta <= von_karman_const_0 / von_karman_const)
95  return von_karman_const * std::sqrt(min_dist2);
96  else
97  return von_karman_const_0 * delta;
98 }
virtual MooseMesh & mesh()=0
const libMesh::FEType & feType() const
const std::vector< BoundaryName > & _wall_boundary_names
const Moose::Functor< Real > & _von_karman_const_0
void paramError(const std::string &param, Args... args) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
MeshBase & mesh
static InputParameters validParams()
int delta(unsigned int i, unsigned int j)
Delta function, which returns zero if $i j$ and unity if $i=j$.
Real distance(const Point &p)
void addRequiredParam(const std::string &name, const std::string &doc_string)
const Moose::Functor< Real > & _von_karman_const
CONSTANT
const std::string & name() const
MeshBase & getMesh()
WallDistanceMixingLengthAux(const InputParameters &parameters)
boundary_id_type BoundaryID
unsigned int sideWithBoundaryID(const Elem *const elem, const BoundaryID boundary_id) const
MONOMIAL
MooseVariableField< Real > & _var
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
registerMooseObject("NavierStokesApp", WallDistanceMixingLengthAux)
void mooseError(Args &&... args) const
SubProblem & _subproblem
const Elem *const & _current_elem
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
const Moose::Functor< Real > & _delta
const MooseArray< Point > & _q_point
const std::unordered_map< boundary_id_type, std::unordered_set< dof_id_type > > & getBoundariesToActiveSemiLocalElemIds() const
StateArg currentState()
uint8_t dof_id_type