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 : const Moose::CoordinateSystemType coord_sys = Moose::COORD_XYZ,
135 : const unsigned int rz_radial_coord = 0);
136 :
137 : /**
138 : * Map marking wall bounded elements
139 : * The map passed in \p wall_bounded_map gets cleared and re-populated
140 : */
141 : void getWallBoundedElements(const std::vector<BoundaryName> & wall_boundary_name,
142 : const FEProblemBase & fe_problem,
143 : const SubProblem & subproblem,
144 : const std::set<SubdomainID> & block_ids,
145 : std::unordered_set<const Elem *> & wall_bounded);
146 :
147 : /**
148 : * Map storing wall ditance for near-wall marked elements
149 : * The map passed in \p dist_map gets cleared and re-populated
150 : */
151 : void getWallDistance(const std::vector<BoundaryName> & wall_boundary_name,
152 : const FEProblemBase & fe_problem,
153 : const SubProblem & subproblem,
154 : const std::set<SubdomainID> & block_ids,
155 : std::map<const Elem *, std::vector<Real>> & dist_map);
156 :
157 : /**
158 : * Map storing face arguments to wall bounded faces
159 : * The map passed in \p face_info_map gets cleared and re-populated
160 : */
161 : void getElementFaceArgs(const std::vector<BoundaryName> & wall_boundary_name,
162 : const FEProblemBase & fe_problem,
163 : const SubProblem & subproblem,
164 : const std::set<SubdomainID> & block_ids,
165 : std::map<const Elem *, std::vector<const FaceInfo *>> & face_info_map);
166 :
167 : /**
168 : * Compute the divergence of a vector given its matrix of derivatives
169 : */
170 : template <typename T, typename VectorType, typename PointType>
171 : T
172 26953946 : divergence(const TensorValue<T> & gradient,
173 : const VectorType & value,
174 : const PointType & point,
175 : const Moose::CoordinateSystemType & coord_sys,
176 : const unsigned int rz_radial_coord)
177 : {
178 : mooseAssert((coord_sys == Moose::COORD_XYZ) || (coord_sys == Moose::COORD_RZ),
179 : "This function only supports calculations of divergence in Cartesian and "
180 : "axisymmetric coordinate systems");
181 26953946 : auto div = gradient.tr();
182 26953946 : if (coord_sys == Moose::COORD_RZ)
183 : // u_r / r
184 4943604 : div += value(rz_radial_coord) / point(rz_radial_coord);
185 26953946 : return div;
186 : }
187 :
188 : /**
189 : * Compute wall heat transfer coefficient
190 : * @param Nu Nusselt number
191 : * @param k Thermal conductivity
192 : * @param D_h Hydraulic diameter
193 : *
194 : * @return the wall heat transfer coefficient
195 : */
196 : template <typename T1, typename T2, typename T3>
197 : auto
198 0 : wallHeatTransferCoefficient(const T1 & Nu, const T2 & k, const T3 & D_h)
199 : {
200 3300 : return Nu * k / D_h;
201 : }
202 :
203 : // Prevent implicit instantiation in other translation units where these classes are used
204 : extern template Real
205 : findUStar<Real>(const Real & mu, const Real & rho, const Real & u, const Real dist);
206 : extern template ADReal
207 : findUStar<ADReal>(const ADReal & mu, const ADReal & rho, const ADReal & u, const Real dist);
208 :
209 : extern template Real findyPlus<Real>(const Real & mu, const Real & rho, const Real & u, Real dist);
210 : extern template ADReal
211 : findyPlus<ADReal>(const ADReal & mu, const ADReal & rho, const ADReal & u, Real dist);
212 :
213 : extern template Real computeSpeed<Real>(const libMesh::VectorValue<Real> & velocity);
214 : extern template ADReal computeSpeed<ADReal>(const libMesh::VectorValue<ADReal> & velocity);
215 :
216 : extern template Real
217 : computeShearStrainRateNormSquared<Real>(const Moose::Functor<Real> & u,
218 : const Moose::Functor<Real> * v,
219 : const Moose::Functor<Real> * w,
220 : const Moose::ElemArg & elem_arg,
221 : const Moose::StateArg & state,
222 : const Moose::CoordinateSystemType coord_sys,
223 : const unsigned int rz_radial_coord);
224 : extern template ADReal
225 : computeShearStrainRateNormSquared<ADReal>(const Moose::Functor<ADReal> & u,
226 : const Moose::Functor<ADReal> * v,
227 : const Moose::Functor<ADReal> * w,
228 : const Moose::ElemArg & elem_arg,
229 : const Moose::StateArg & state,
230 : const Moose::CoordinateSystemType coord_sys,
231 : const unsigned int rz_radial_coord);
232 : }
|