12 #include "libmesh/vector_value.h" 18 delta(
unsigned int i,
unsigned int j)
29 return a > 0 ? 1 : (
a < 0 ? -1 : 0);
33 getIndex(
const Real & p,
const std::vector<Real> & bounds)
35 if (p < bounds.front() || p > bounds.back())
38 for (
unsigned int i = 1; i < bounds.size(); ++i)
42 return bounds.size() - 2;
47 const Real & Re,
const Real & rho,
const Real &
mu,
const Real & drho,
const Real & dmu)
49 return Re * (drho / std::max(rho, 1e-6) - dmu / std::max(
mu, 1e-8));
60 return (
k * (
mu * dcp +
cp * dmu) -
mu *
cp * dk) / std::max(
k *
k, 1e-8);
65 findUStar(
const T &
mu,
const T & rho,
const T & u,
const Real dist)
68 constexpr
int MAX_ITERS{50};
69 constexpr
Real REL_TOLERANCE{1e-6};
72 mooseAssert(
mu > 0,
"Need a strictly positive viscosity");
73 mooseAssert(rho > 0,
"Need a strictly positive density");
74 mooseAssert(u > 0,
"Need a strictly positive velocity");
75 mooseAssert(dist > 0,
"Need a strictly positive wall distance");
77 const T nu =
mu / rho;
85 T u_star = std::max(1e-20, (-b_c + std::sqrt(
std::pow(b_c, 2) + 4.0 * a_c * c_c)) / (2.0 * a_c));
88 for (
int i = 0; i < MAX_ITERS; ++i)
93 T new_u_star = std::max(1e-20, u_star - residual /
deriv);
99 if (rel_err < REL_TOLERANCE)
103 mooseException(
"Could not find the wall friction velocity (mu: ",
117 template <
typename T>
119 findyPlus(
const T &
mu,
const T & rho,
const T & u,
const Real dist)
123 constexpr
int MAX_ITERS{10};
124 constexpr
Real REL_TOLERANCE{1e-2};
127 mooseAssert(
mu > 0,
"Need a strictly positive viscosity");
128 mooseAssert(u > 0,
"Need a strictly positive velocity");
129 mooseAssert(rho > 0,
"Need a strictly positive density");
130 mooseAssert(dist > 0,
"Need a strictly positive wall distance");
132 Real yPlusLast = 0.0;
133 T yPlus = dist * u * rho /
mu;
136 unsigned int iters = 0;
145 ++iters < MAX_ITERS);
153 template <
typename T>
166 template <
typename T>
174 const auto & grad_u = u.
gradient(elem_arg, state);
175 const T Sij_xx = 2.0 * grad_u(0);
182 const T grad_xx = grad_u(0);
192 T trace = Sij_xx / 3.0;
196 const auto & grad_v = (*v).gradient(elem_arg, state);
197 Sij_xy = grad_u(1) + grad_v(0);
198 Sij_yy = 2.0 * grad_v(1);
204 trace += Sij_yy / 3.0;
208 const auto & grad_w = (*w).gradient(elem_arg, state);
210 Sij_xz = grad_u(2) + grad_w(0);
211 Sij_yz = grad_v(2) + grad_w(1);
212 Sij_zz = 2.0 * grad_w(2);
220 trace += Sij_zz / 3.0;
224 return (Sij_xx - trace) * grad_xx + Sij_xy * grad_xy + Sij_xz * grad_xz + Sij_xy * grad_yx +
225 (Sij_yy - trace) * grad_yy + Sij_yz * grad_yz + Sij_xz * grad_zx + Sij_yz * grad_zy +
226 (Sij_zz - trace) * grad_zz;
244 const std::set<SubdomainID> & block_ids,
245 std::unordered_set<const Elem *> & wall_bounded)
248 wall_bounded.clear();
251 for (
const auto & elem : fe_problem.
mesh().
getMesh().active_element_ptr_range())
253 if (block_ids.find(elem->subdomain_id()) != block_ids.end())
254 for (
const auto i_side : elem->side_index_range())
257 for (
const auto & wall_id : wall_boundary_ids)
259 for (
const auto side_id : side_bnds)
261 wall_bounded.insert(elem);
272 const std::set<SubdomainID> & block_ids,
273 std::map<
const Elem *, std::vector<Real>> & dist_map)
277 for (
const auto & elem : fe_problem.
mesh().
getMesh().active_element_ptr_range())
278 if (block_ids.find(elem->subdomain_id()) != block_ids.end())
279 for (
const auto i_side : elem->side_index_range())
282 for (
const auto &
name : wall_boundary_name)
285 for (
const auto side_id : side_bnds)
291 const auto & neighbor = elem->neighbor_ptr(i_side);
293 const auto & elem_for_fi = elem_has_fi ? elem : neighbor;
294 const auto side = elem_has_fi ? i_side : neighbor->which_neighbor_am_i(elem);
297 const auto & elem_centroid =
300 dist_map[elem].push_back(dist);
311 const std::set<SubdomainID> & block_ids,
312 std::map<
const Elem *, std::vector<const FaceInfo *>> & face_info_map)
314 face_info_map.clear();
316 for (
const auto & elem : fe_problem.
mesh().
getMesh().active_element_ptr_range())
317 if (block_ids.find(elem->subdomain_id()) != block_ids.end())
318 for (
const auto i_side : elem->side_index_range())
321 for (
const auto &
name : wall_boundary_name)
324 for (
const auto side_id : side_bnds)
330 const auto & neighbor = elem->neighbor_ptr(i_side);
332 const auto & elem_for_fi = elem_has_fi ? elem : neighbor;
333 const auto side = elem_has_fi ? i_side : neighbor->which_neighbor_am_i(elem);
336 face_info_map[elem].push_back(fi);
virtual MooseMesh & mesh()=0
int computeSign(const Real &a)
Sign function, returns $+1$ if $a$ is positive and $-1$ if $a$ is negative.
T computeShearStrainRateNormSquared(const Moose::Functor< T > &u, const Moose::Functor< T > *v, const Moose::Functor< T > *w, const Moose::ElemArg &elem_arg, const Moose::StateArg &state)
Utility function to compute the shear strain rate.
static constexpr Real von_karman_constant
bool elemHasFaceInfo(const Elem &elem, const Elem *const neighbor)
static constexpr Real min_y_plus
void mooseError(Args &&... args)
T computeSpeed(const libMesh::VectorValue< T > &velocity)
Compute the speed (velocity norm) given the supplied velocity.
Real prandtlPropertyDerivative(const Real &mu, const Real &cp, const Real &k, const Real &dmu, const Real &dcp, const Real &dk)
Computes the derivative of the Prandtl number, $Pr{ C_p}{k}$, with respect to an arbitrary variale $$...
bool isZero(const T &value, const Real tolerance=TOLERANCE *TOLERANCE *TOLERANCE)
template ADReal computeShearStrainRateNormSquared< ADReal >(const Moose::Functor< ADReal > &u, const Moose::Functor< ADReal > *v, const Moose::Functor< ADReal > *w, const Moose::ElemArg &elem_arg, const Moose::StateArg &state)
const boundary_id_type side_id
const Point & faceCentroid() const
int delta(unsigned int i, unsigned int j)
Delta function, which returns zero if $i j$ and unity if $i=j$.
template Real findUStar< Real >(const Real &mu, const Real &rho, const Real &u, const Real dist)
void getWallBoundedElements(const std::vector< BoundaryName > &wall_boundary_name, const FEProblemBase &fe_problem, const SubProblem &subproblem, const std::set< SubdomainID > &block_ids, std::unordered_set< const Elem *> &wall_bounded)
Map marking wall bounded elements The map passed in wall_bounded_map gets cleared and re-populated...
const Point & neighborCentroid() const
DualNumber< Real, DNDerivativeType, true > ADReal
template Real findyPlus< Real >(const Real &mu, const Real &rho, const Real &u, Real dist)
static const std::string cp
const std::vector< const FaceInfo *> & faceInfo() const
const Point & elemCentroid() const
Real deriv(unsigned n, unsigned alpha, unsigned beta, Real x)
static const std::string mu
template ADReal findUStar< ADReal >(const ADReal &mu, const ADReal &rho, const ADReal &u, const Real dist)
Real reynoldsPropertyDerivative(const Real &Re, const Real &rho, const Real &mu, const Real &drho, const Real &dmu)
Computes the derivative of the Reynolds number, $Re { Vd}{}$, with respect to an arbitrary variable $...
const Point & normal() const
unsigned int getIndex(const Real &p, const std::vector< Real > &bounds)
Determines the index $i$ in a sorted array such that the input point is within the $i$-th and $i+1$-t...
void getWallDistance(const std::vector< BoundaryName > &wall_boundary_name, const FEProblemBase &fe_problem, const SubProblem &subproblem, const std::set< SubdomainID > &block_ids, std::map< const Elem *, std::vector< Real >> &dist_map)
Map storing wall ditance for near-wall marked elements The map passed in dist_map gets cleared and re...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string v
template ADReal computeSpeed< ADReal >(const libMesh::VectorValue< ADReal > &velocity)
static constexpr Real E_turb_constant
GradientType gradient(const ElemArg &elem, const StateArg &state) const
template ADReal findyPlus< ADReal >(const ADReal &mu, const ADReal &rho, const ADReal &u, Real dist)
virtual MooseMesh & mesh() override
void getElementFaceArgs(const std::vector< BoundaryName > &wall_boundary_name, const FEProblemBase &fe_problem, const SubProblem &subproblem, const std::set< SubdomainID > &block_ids, std::map< const Elem *, std::vector< const FaceInfo *>> &face_info_map)
Map storing face arguments to wall bounded faces The map passed in face_info_map gets cleared and re-...
static const std::string velocity
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
T findyPlus(const T &mu, const T &rho, const T &u, Real dist)
Finds the non-dimensional wall distance normalized with the friction velocity Implements a fixed-poin...
template Real computeSpeed< Real >(const libMesh::VectorValue< Real > &velocity)
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
T findUStar(const T &mu, const T &rho, const T &u, Real dist)
Finds the friction velocity using standard velocity wall functions formulation.
MooseUnits pow(const MooseUnits &, int)
static const std::string k
template Real computeShearStrainRateNormSquared< Real >(const Moose::Functor< Real > &u, const Moose::Functor< Real > *v, const Moose::Functor< Real > *w, const Moose::ElemArg &elem_arg, const Moose::StateArg &state)
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const