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.addRequiredParam<std::vector<BoundaryName>>("walls", 23 : "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 (_var.feType() != FEType(CONSTANT, MONOMIAL)) 45 0 : 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 106 : } 53 : 54 : Real 55 58024 : WallDistanceMixingLengthAux::computeValue() 56 : { 57 : // Get reference to the libMesh mesh object 58 58024 : const MeshBase & l_mesh = _mesh.getMesh(); 59 : 60 : // Get the ids of the wall boundaries 61 58024 : std::vector<BoundaryID> vec_ids = _mesh.getBoundaryIDs(_wall_boundary_names, true); 62 : 63 : // Loop over all boundaries 64 58024 : Real min_dist2 = 1e9; 65 58024 : const auto & bnd_to_elem_map = _mesh.getBoundariesToActiveSemiLocalElemIds(); 66 119660 : 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 61636 : if (search == bnd_to_elem_map.end()) 71 0 : 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 10797708 : for (dof_id_type elem_id : bnd_elems) 76 : { 77 10736072 : const Elem & elem = l_mesh.elem_ref(elem_id); 78 10736072 : const auto side = _mesh.sideWithBoundaryID(&elem, bid); 79 10736072 : const auto bnd_pos = elem.side_ptr(side)->vertex_average(); 80 10736072 : const auto distance = bnd_pos - _q_point[_qp]; 81 10736072 : const auto dist2 = distance * distance; 82 : mooseAssert(dist2 != 0, "This distance should never be 0"); 83 10736072 : min_dist2 = std::min(min_dist2, dist2); 84 : } 85 : } 86 : 87 58024 : const Moose::ElemArg elem_arg = {_current_elem, false}; 88 58024 : const Moose::StateArg state_arg = Moose::currentState(); 89 : 90 58024 : const auto delta = _delta(elem_arg, state_arg); 91 58024 : const auto von_karman_const = _von_karman_const(elem_arg, state_arg); 92 58024 : const auto von_karman_const_0 = _von_karman_const_0(elem_arg, state_arg); 93 : 94 58024 : if (std::sqrt(min_dist2) / delta <= von_karman_const_0 / von_karman_const) 95 12956 : return von_karman_const * std::sqrt(min_dist2); 96 : else 97 45068 : return von_karman_const_0 * delta; 98 58024 : }