LCOV - code coverage report
Current view: top level - src/auxkernels - WallDistanceMixingLengthAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: 9fc4b0 Lines: 43 50 86.0 %
Date: 2025-08-14 10:14:56 Functions: 3 3 100.0 %
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 "WallDistanceMixingLengthAux.h"
      11             : 
      12             : registerMooseObject("NavierStokesApp", WallDistanceMixingLengthAux);
      13             : 
      14             : InputParameters
      15         197 : WallDistanceMixingLengthAux::validParams()
      16             : {
      17         197 :   InputParameters params = AuxKernel::validParams();
      18         197 :   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         394 :   params.addParam<std::vector<BoundaryName>>(
      23             :       "walls", {}, "Boundaries that correspond to solid walls.");
      24         394 :   params.addParam<MooseFunctorName>("von_karman_const", 0.41, "");   // Von Karman constant
      25         394 :   params.addParam<MooseFunctorName>("von_karman_const_0", 0.09, ""); // Escudier' model parameter
      26         394 :   params.addParam<MooseFunctorName>(
      27             :       "delta",
      28         394 :       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         197 :   return params;
      32           0 : }
      33             : 
      34         106 : WallDistanceMixingLengthAux::WallDistanceMixingLengthAux(const InputParameters & parameters)
      35             :   : AuxKernel(parameters),
      36         106 :     _wall_boundary_names(getParam<std::vector<BoundaryName>>("walls")),
      37         212 :     _von_karman_const(getFunctor<Real>("von_karman_const")),
      38         212 :     _von_karman_const_0(getFunctor<Real>("von_karman_const_0")),
      39         318 :     _delta(getFunctor<Real>("delta"))
      40             : {
      41         106 :   const MeshBase & mesh = _subproblem.mesh().getMesh();
      42         106 :   if (!mesh.is_replicated())
      43           0 :     mooseError("WallDistanceMixingLengthAux only supports replicated meshes");
      44         106 :   if (!dynamic_cast<MooseVariableFV<Real> *>(&_var))
      45           0 :     paramError("variable",
      46             :                "'",
      47             :                name(),
      48             :                "' is currently programmed to use finite volume machinery, so make sure that '",
      49           0 :                _var.name(),
      50             :                "' is a finite volume variable.");
      51         106 : }
      52             : 
      53             : Real
      54       58024 : WallDistanceMixingLengthAux::computeValue()
      55             : {
      56             :   // Get reference to the libMesh mesh object
      57       58024 :   const MeshBase & l_mesh = _mesh.getMesh();
      58             : 
      59             :   // Get the ids of the wall boundaries
      60       58024 :   std::vector<BoundaryID> vec_ids = _mesh.getBoundaryIDs(_wall_boundary_names, true);
      61             : 
      62             :   // Loop over all boundaries
      63       58024 :   Real min_dist2 = 1e9;
      64       58024 :   const auto & bnd_to_elem_map = _mesh.getBoundariesToActiveSemiLocalElemIds();
      65      119660 :   for (BoundaryID bid : vec_ids)
      66             :   {
      67             :     // Get the set of elements on this boundary
      68             :     auto search = bnd_to_elem_map.find(bid);
      69       61636 :     if (search == bnd_to_elem_map.end())
      70           0 :       mooseError("Error computing wall distance; the boundary id ", bid, " is invalid");
      71             :     const auto & bnd_elems = search->second;
      72             : 
      73             :     // Loop over all boundary elements and find the distance to the closest one
      74    10797708 :     for (dof_id_type elem_id : bnd_elems)
      75             :     {
      76    10736072 :       const Elem & elem{l_mesh.elem_ref(elem_id)};
      77    10736072 :       const auto side = _mesh.sideWithBoundaryID(&elem, bid);
      78    10736072 :       const FaceInfo * fi = _mesh.faceInfo(&elem, side);
      79             :       // It's possible that we are on an internal boundary
      80    10736072 :       if (!fi)
      81             :       {
      82             :         const Elem * const neigh = elem.neighbor_ptr(side);
      83             :         mooseAssert(
      84             :             neigh,
      85             :             "In WallDistanceMixingLengthAux, we could not find a face information object with elem "
      86             :             "and side, and we are on an external boundary. This shouldn't happen.");
      87           0 :         const auto neigh_side = neigh->which_neighbor_am_i(&elem);
      88           0 :         fi = _mesh.faceInfo(neigh, neigh_side);
      89             :         mooseAssert(fi, "We should have a face info for either the elem or neigh side");
      90             :       }
      91    10736072 :       Point bnd_pos = fi->faceCentroid();
      92    10736072 :       const auto distance = bnd_pos - _q_point[_qp];
      93    10736072 :       const auto dist2 = distance * distance;
      94             :       mooseAssert(dist2 != 0, "This distance should never be 0");
      95    10736072 :       min_dist2 = std::min(min_dist2, dist2);
      96             :     }
      97             :   }
      98             : 
      99       58024 :   const Moose::ElemArg elem_arg = {_current_elem, false};
     100       58024 :   const Moose::StateArg state_arg = Moose::currentState();
     101             : 
     102       58024 :   const auto delta = _delta(elem_arg, state_arg);
     103       58024 :   const auto von_karman_const = _von_karman_const(elem_arg, state_arg);
     104       58024 :   const auto von_karman_const_0 = _von_karman_const_0(elem_arg, state_arg);
     105             : 
     106       58024 :   if (std::sqrt(min_dist2) / delta <= von_karman_const_0 / von_karman_const)
     107       12956 :     return von_karman_const * std::sqrt(min_dist2);
     108             :   else
     109       45068 :     return von_karman_const_0 * delta;
     110       58024 : }

Generated by: LCOV version 1.14