LCOV - code coverage report
Current view: top level - include/base - NavierStokesMethods.h (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: 9fc4b0 Lines: 6 7 85.7 %
Date: 2025-08-14 10:14:56 Functions: 2 3 66.7 %
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             : #pragma once
      11             : 
      12             : #include <vector>
      13             : #include "Moose.h"
      14             : #include "MooseUtils.h"
      15             : #include "ADReal.h"
      16             : #include "metaphysicl/raw_type.h"
      17             : #include "FEProblemBase.h"
      18             : #include "SubProblem.h"
      19             : 
      20             : namespace NS
      21             : {
      22             : /**
      23             :  * Delta function, which returns zero if $i\ne j$ and unity if $i=j$
      24             :  * @param[in] i   integer number
      25             :  * @param[in] j   integer number
      26             :  * @return delta function
      27             :  */
      28             : int delta(unsigned int i, unsigned int j);
      29             : 
      30             : /**
      31             :  * Sign function, returns $+1$ if $a$ is positive and $-1$ if $a$ is negative
      32             :  * @param[in] a   number
      33             :  * @return the sign of the input
      34             :  */
      35             : int computeSign(const Real & a);
      36             : 
      37             : /**
      38             :  * Determines the index $i$ in a sorted array such that the input point is within
      39             :  * the $i$-th and $i+1$-th entries in the array.
      40             :  * @param[in] p      input point
      41             :  * @param[in] bounds sorted array
      42             :  * @return index of point
      43             :  */
      44             : unsigned int getIndex(const Real & p, const std::vector<Real> & bounds);
      45             : 
      46             : /**
      47             :  * Computes the derivative of the Reynolds number, $Re\equiv \frac{\rho Vd}{\mu}$,
      48             :  * with respect to an arbitrary variable $\zeta$, where it is assumed that only the
      49             :  * material properties of density $\rho$ and dynamic viscosity $\mu$ have nonzero
      50             :  * derivatives with respect to $\zeta$. To eliminate the need to pass in the velocity $V$ and
      51             :  * characteristic length $d$, the derivative is rewritten in terms of the Reynolds
      52             :  * number such that the partial derivative of $Re$ with respect to an aritrary
      53             :  * parameter $\zeta$ is
      54             :  *
      55             :  * $\frac{\partial Re}{\partial\zeta}=Re\left(\frac{1}{\rho}\frac{\partial\rho}{\partial
      56             :  * x}-\frac{1}{\mu}\frac{\partial\mu}{\partial x}$
      57             :  *
      58             :  * @param[in] Re   Reynolds number
      59             :  * @param[in] rho  density
      60             :  * @param[in] mu   dynamic viscosity
      61             :  * @param[in] drho partial derivative of density with respect to arbitrary variable $\zeta$
      62             :  * @param[in] dmu  partial derivative of dynamic viscosity with respect to arbitrary variable
      63             :  * $\zeta$
      64             :  * @return derivative of Reynolds number with respect to $\zeta$
      65             :  */
      66             : Real reynoldsPropertyDerivative(
      67             :     const Real & Re, const Real & rho, const Real & mu, const Real & drho, const Real & dmu);
      68             : 
      69             : /**
      70             :  * Computes the derivative of the Prandtl number, $Pr\equiv\frac{\mu C_p}{k}$, with respect
      71             :  * to an arbitrary variale $\zeta$. This derivative is
      72             :  *
      73             :  * $\frac{\partial Pr}{\partial \zeta}=\frac{k\left(\mu\frac{\partial
      74             :  * C_p}{\partial\zeta}+C_p\frac{\partial mu}{\partial\zeta}\right)-\mu C_p\frac{\partial
      75             :  * k}{\partial\zeta}}{k^2}$
      76             :  *
      77             :  * @param[in] mu  dynamic viscosity
      78             :  * @param[in] cp  isobaric specific heat
      79             :  * @param[in] k   thermal conductivity
      80             :  * @param[in] dmu derivative of dynamic viscosity with respect to $\zeta$
      81             :  * @param[in] dcp derivative of isobaric specific heat with respect to $\zeta$
      82             :  * @param[in] dk  derivative of thermal conductivity with respect to $\zeta$
      83             :  * @return derivative of Prandtl number with respect to $\zeta$
      84             :  */
      85             : Real prandtlPropertyDerivative(const Real & mu,
      86             :                                const Real & cp,
      87             :                                const Real & k,
      88             :                                const Real & dmu,
      89             :                                const Real & dcp,
      90             :                                const Real & dk);
      91             : 
      92             : /**
      93             :  * Finds the friction velocity using standard velocity wall functions formulation.
      94             :  * It is used in WallFunctionWallShearStressAux, WallFunctionYPlusAux and
      95             :  * INSFVWallFunctionBC.
      96             :  * @param mu the dynamic viscosity
      97             :  * @param rho the density
      98             :  * @param u the centroid velocity
      99             :  * @param dist the element centroid distance to the wall
     100             :  * @return the velocity at the wall
     101             :  */
     102             : template <typename T>
     103             : T findUStar(const T & mu, const T & rho, const T & u, Real dist);
     104             : 
     105             : /**
     106             :  * Finds the non-dimensional wall distance normalized with the friction velocity
     107             :  * Implements a fixed-point iteration in the wall function to get this velocity
     108             :  * @param mu the dynamic viscosity
     109             :  * @param rho the density
     110             :  * @param u the centroid velocity
     111             :  * @param dist the element centroid distance to the wall
     112             :  * @return the non-dimensional wall distance
     113             :  */
     114             : template <typename T>
     115             : T findyPlus(const T & mu, const T & rho, const T & u, Real dist);
     116             : 
     117             : using MooseUtils::isZero;
     118             : 
     119             : /**
     120             :  * Compute the speed (velocity norm) given the supplied velocity
     121             :  */
     122             : template <typename T>
     123             : T computeSpeed(const libMesh::VectorValue<T> & velocity);
     124             : 
     125             : /**
     126             :  * Utility function to compute the shear strain rate
     127             :  */
     128             : template <typename T>
     129             : T computeShearStrainRateNormSquared(const Moose::Functor<T> & u,
     130             :                                     const Moose::Functor<T> * v,
     131             :                                     const Moose::Functor<T> * w,
     132             :                                     const Moose::ElemArg & elem_arg,
     133             :                                     const Moose::StateArg & state);
     134             : 
     135             : /**
     136             :  * Map marking wall bounded elements
     137             :  * The map passed in \p wall_bounded_map gets cleared and re-populated
     138             :  */
     139             : void getWallBoundedElements(const std::vector<BoundaryName> & wall_boundary_name,
     140             :                             const FEProblemBase & fe_problem,
     141             :                             const SubProblem & subproblem,
     142             :                             const std::set<SubdomainID> & block_ids,
     143             :                             std::unordered_set<const Elem *> & wall_bounded);
     144             : 
     145             : /**
     146             :  * Map storing wall ditance for near-wall marked elements
     147             :  * The map passed in \p dist_map gets cleared and re-populated
     148             :  */
     149             : void getWallDistance(const std::vector<BoundaryName> & wall_boundary_name,
     150             :                      const FEProblemBase & fe_problem,
     151             :                      const SubProblem & subproblem,
     152             :                      const std::set<SubdomainID> & block_ids,
     153             :                      std::map<const Elem *, std::vector<Real>> & dist_map);
     154             : 
     155             : /**
     156             :  * Map storing face arguments to wall bounded faces
     157             :  * The map passed in \p face_info_map gets cleared and re-populated
     158             :  */
     159             : void getElementFaceArgs(const std::vector<BoundaryName> & wall_boundary_name,
     160             :                         const FEProblemBase & fe_problem,
     161             :                         const SubProblem & subproblem,
     162             :                         const std::set<SubdomainID> & block_ids,
     163             :                         std::map<const Elem *, std::vector<const FaceInfo *>> & face_info_map);
     164             : 
     165             : /**
     166             :  * Compute the divergence of a vector given its matrix of derivatives
     167             :  */
     168             : template <typename T, typename VectorType, typename PointType>
     169             : T
     170    35788507 : divergence(const TensorValue<T> & gradient,
     171             :            const VectorType & value,
     172             :            const PointType & point,
     173             :            const Moose::CoordinateSystemType & coord_sys,
     174             :            const unsigned int rz_radial_coord)
     175             : {
     176             :   mooseAssert((coord_sys == Moose::COORD_XYZ) || (coord_sys == Moose::COORD_RZ),
     177             :               "This function only supports calculations of divergence in Cartesian and "
     178             :               "axisymmetric coordinate systems");
     179    35788507 :   auto div = gradient.tr();
     180    35788507 :   if (coord_sys == Moose::COORD_RZ)
     181             :     // u_r / r
     182     6557166 :     div += value(rz_radial_coord) / point(rz_radial_coord);
     183    35788507 :   return div;
     184             : }
     185             : 
     186             : /**
     187             :  * Compute wall heat transfer coefficient
     188             :  * @param Nu Nusselt number
     189             :  * @param k Thermal conductivity
     190             :  * @param D_h Hydraulic diameter
     191             :  *
     192             :  * @return the wall heat transfer coefficient
     193             :  */
     194             : template <typename T1, typename T2, typename T3>
     195             : auto
     196           0 : wallHeatTransferCoefficient(const T1 & Nu, const T2 & k, const T3 & D_h)
     197             : {
     198        4950 :   return Nu * k / D_h;
     199             : }
     200             : 
     201             : // Prevent implicit instantiation in other translation units where these classes are used
     202             : extern template Real
     203             : findUStar<Real>(const Real & mu, const Real & rho, const Real & u, const Real dist);
     204             : extern template ADReal
     205             : findUStar<ADReal>(const ADReal & mu, const ADReal & rho, const ADReal & u, const Real dist);
     206             : 
     207             : extern template Real findyPlus<Real>(const Real & mu, const Real & rho, const Real & u, Real dist);
     208             : extern template ADReal
     209             : findyPlus<ADReal>(const ADReal & mu, const ADReal & rho, const ADReal & u, Real dist);
     210             : 
     211             : extern template Real computeSpeed<Real>(const libMesh::VectorValue<Real> & velocity);
     212             : extern template ADReal computeSpeed<ADReal>(const libMesh::VectorValue<ADReal> & velocity);
     213             : 
     214             : extern template Real computeShearStrainRateNormSquared<Real>(const Moose::Functor<Real> & u,
     215             :                                                              const Moose::Functor<Real> * v,
     216             :                                                              const Moose::Functor<Real> * w,
     217             :                                                              const Moose::ElemArg & elem_arg,
     218             :                                                              const Moose::StateArg & state);
     219             : extern template ADReal computeShearStrainRateNormSquared<ADReal>(const Moose::Functor<ADReal> & u,
     220             :                                                                  const Moose::Functor<ADReal> * v,
     221             :                                                                  const Moose::Functor<ADReal> * w,
     222             :                                                                  const Moose::ElemArg & elem_arg,
     223             :                                                                  const Moose::StateArg & state);
     224             : }

Generated by: LCOV version 1.14