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 "INSFVWallFunctionBC.h" 11 : #include "NavierStokesMethods.h" 12 : #include "NS.h" 13 : 14 : registerMooseObject("NavierStokesApp", INSFVWallFunctionBC); 15 : 16 : InputParameters 17 122 : INSFVWallFunctionBC::validParams() 18 : { 19 122 : InputParameters params = INSFVNaturalFreeSlipBC::validParams(); 20 122 : params.addClassDescription("Implements a wall shear BC for the momentum equation based on " 21 : "algebraic standard velocity wall functions."); 22 244 : params.addRequiredParam<MooseFunctorName>("u", "The velocity in the x direction."); 23 244 : params.addParam<MooseFunctorName>("v", "The velocity in the y direction."); 24 244 : params.addParam<MooseFunctorName>("w", "The velocity in the z direction."); 25 122 : params.addRequiredParam<MooseFunctorName>(NS::density, "fluid density"); 26 244 : params.addRequiredParam<MooseFunctorName>("mu", "Dynamic viscosity"); 27 122 : return params; 28 0 : } 29 : 30 72 : INSFVWallFunctionBC::INSFVWallFunctionBC(const InputParameters & params) 31 : : INSFVNaturalFreeSlipBC(params), 32 72 : _dim(_subproblem.mesh().dimension()), 33 144 : _u(getFunctor<ADReal>("u")), 34 288 : _v(isParamValid("v") ? &getFunctor<ADReal>("v") : nullptr), 35 144 : _w(isParamValid("w") ? &getFunctor<ADReal>("w") : nullptr), 36 72 : _rho(getFunctor<ADReal>(NS::density)), 37 216 : _mu(getFunctor<ADReal>("mu")) 38 : { 39 72 : if (_rc_uo.segregated()) 40 0 : mooseError("Wall sheer stress enforcement based wall functions are not supported with " 41 : "segregated solution approaches!"); 42 72 : } 43 : 44 : ADReal 45 0 : INSFVWallFunctionBC::computeSegregatedContribution() 46 : { 47 0 : mooseError("Sheer-stress-based wall function enforcement not supported for segregated solvers."); 48 : return 0.0; 49 : } 50 : 51 : ADReal 52 166400 : INSFVWallFunctionBC::computeStrongResidual() 53 : { 54 : using std::abs; 55 : 56 : // Get the velocity vector 57 166400 : const FaceInfo & fi = *_face_info; 58 : const Elem & elem = fi.elem(); 59 166400 : const Moose::ElemArg elem_arg{&elem, false}; 60 166400 : const auto state = determineState(); 61 332800 : ADRealVectorValue velocity(_u(elem_arg, state)); 62 166400 : if (_v) 63 166400 : velocity(1) = (*_v)(elem_arg, state); 64 166400 : if (_w) 65 0 : velocity(2) = (*_w)(elem_arg, state); 66 : 67 : // Compute the velocity magnitude (parallel_speed) and 68 : // direction of the tangential velocity component (parallel_dir) 69 166400 : ADReal dist = abs((fi.elemCentroid() - fi.faceCentroid()) * _normal); 70 166400 : ADReal perpendicular_speed = velocity * _normal; 71 166400 : ADRealVectorValue parallel_velocity = velocity - perpendicular_speed * _normal; 72 166400 : ADReal parallel_speed = parallel_velocity.norm(); 73 332800 : _a = 1 / parallel_speed; 74 : 75 166400 : if (parallel_speed.value() < 1e-7) 76 0 : return 0; 77 : 78 166400 : if (!std::isfinite(parallel_speed.value())) 79 0 : return parallel_speed; 80 : 81 : // Compute the friction velocity and the wall shear stress 82 166400 : const auto rho = _rho(makeElemArg(&elem), state); 83 : ADReal u_star = 84 166400 : NS::findUStar<ADReal>(_mu(makeElemArg(&elem), state), rho, parallel_speed, dist.value()); 85 166400 : ADReal tau = u_star * u_star * rho; 86 166400 : _a *= tau; 87 : 88 : // Compute the shear stress component for this momentum equation 89 166400 : if (_index == 0) 90 : return _a * parallel_velocity(0); 91 83200 : else if (_index == 1) 92 : return _a * parallel_velocity(1); 93 : else 94 : return _a * parallel_velocity(2); 95 : } 96 : 97 : void 98 166400 : INSFVWallFunctionBC::gatherRCData(const FaceInfo & fi) 99 : { 100 166400 : _face_info = &fi; 101 166400 : _face_type = fi.faceType(std::make_pair(_var.number(), _var.sys().number())); 102 166400 : _normal = fi.normal(); 103 : 104 : // Fill-in the coefficient _a (but without multiplication by A) 105 166400 : const auto strong_resid = computeStrongResidual(); 106 : 107 332800 : _rc_uo.addToA((_face_type == FaceInfo::VarFaceNeighbors::ELEM) ? &fi.elem() : fi.neighborPtr(), 108 166400 : _index, 109 166400 : _a * (fi.faceArea() * fi.faceCoord())); 110 : 111 332800 : addResidualAndJacobian(strong_resid * (fi.faceArea() * fi.faceCoord())); 112 166400 : }