12#include "libmesh/vector_value.h"
18delta(
unsigned int i,
unsigned int j)
29 return a > 0 ? 1 : (
a < 0 ? -1 : 0);
33getIndex(
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);
67 using std::log, std::sqrt, std::pow, std::max, std::abs;
70 constexpr int MAX_ITERS{50};
71 constexpr Real REL_TOLERANCE{1e-6};
74 mooseAssert(
mu > 0,
"Need a strictly positive viscosity");
75 mooseAssert(
rho > 0,
"Need a strictly positive density");
76 mooseAssert(u > 0,
"Need a strictly positive velocity");
77 mooseAssert(dist > 0,
"Need a strictly positive wall distance");
87 T u_star = max(1e-20, (-b_c + sqrt(
pow(b_c, 2) + 4.0 * a_c * c_c)) / (2.0 * a_c));
90 for (
int i = 0; i < MAX_ITERS; ++i)
95 T new_u_star = max(1e-20, u_star - residual / deriv);
101 if (rel_err < REL_TOLERANCE)
105 mooseException(
"Could not find the wall friction velocity (mu: ",
115template Real
findUStar<Real>(
const Real &
mu,
const Real &
rho,
const Real & u,
const Real dist);
123 using std::max, std::log, std::abs;
127 constexpr int MAX_ITERS{10};
128 constexpr Real REL_TOLERANCE{1e-2};
131 mooseAssert(
mu > 0,
"Need a strictly positive viscosity");
132 mooseAssert(u > 0,
"Need a strictly positive velocity");
133 mooseAssert(
rho > 0,
"Need a strictly positive density");
134 mooseAssert(dist > 0,
"Need a strictly positive wall distance");
136 Real yPlusLast = 0.0;
137 T yPlus = dist * u *
rho /
mu;
140 unsigned int iters = 0;
149 ++iters < MAX_ITERS);
162 using std::abs, std::exp, std::log, std::max, std::pow;
164 constexpr int MAX_ITERS{35};
165 constexpr Real REL_TOLERANCE{1e-3};
166 constexpr Real DERIV_TOLERANCE{1e-12};
168 mooseAssert(Pr > 0,
"Need a strictly positive Prandtl number");
169 mooseAssert(Pr_t > 0,
"Need a strictly positive turbulent Prandtl number");
171 const auto Pr_ratio = Pr / Pr_t;
173 const auto jayatilleke_P =
174 9.24 * (
pow(Pr_ratio, 0.75) - 1.0) * (1.0 + 0.28 * exp(-0.007 * Pr_ratio));
176 auto f = [&](
const T y)
189 auto y_plus_last = y_plus;
192 const auto f_min =
f(y_plus_min);
196 unsigned int iters = 0;
199 y_plus_last = y_plus;
201 const auto f_val =
f(y_plus);
202 const auto df_val = df(y_plus);
205 if (abs(df_val) < DERIV_TOLERANCE)
206 mooseException(
"Derivative vanished while finding the thermal matching non-dimensional wall "
213 auto y_new = y_plus - f_val / df_val;
216 if (y_new <= y_plus_min)
217 y_new = 0.5 * (y_plus + y_plus_min);
220 }
while (abs((y_plus - y_plus_last) / y_plus_last) > REL_TOLERANCE && ++iters < MAX_ITERS);
222 if (iters >= MAX_ITERS && abs(
f(y_plus)) > REL_TOLERANCE * Pr_t)
223 mooseException(
"Could not find the thermal matching non-dimensional wall distance (Pr: ",
255 const unsigned int rz_radial_coord)
257 const auto & grad_u = u.
gradient(elem_arg, state);
258 const T Sij_xx = 2.0 * grad_u(0);
265 const T grad_xx = grad_u(0);
275 T trace = Sij_xx / 3.0;
279 const auto & grad_v = (*v).gradient(elem_arg, state);
280 Sij_xy = grad_u(1) + grad_v(0);
281 Sij_yy = 2.0 * grad_v(1);
287 trace += Sij_yy / 3.0;
291 const auto & grad_w = (*w).gradient(elem_arg, state);
293 Sij_xz = grad_u(2) + grad_w(0);
294 Sij_yz = grad_v(2) + grad_w(1);
295 Sij_zz = 2.0 * grad_w(2);
303 trace += Sij_zz / 3.0;
309 mooseAssert(elem_arg.
elem,
"ElemArg must reference an element for cylindrical calculations.");
311 mooseAssert(
radius > 0.0,
"Axisymmetric radial coordinate should be positive.");
314 switch (rz_radial_coord)
323 mooseError(
"Unsupported axisymmetric radial coordinate index: ", rz_radial_coord);
326 mooseAssert(radial_functor,
327 "The functor corresponding to the axisymmetric radial velocity must be provided.");
328 const T radial_velocity = (*radial_functor)(elem_arg, state);
329 Sij_zz = 2.0 * radial_velocity /
radius;
330 grad_zz = radial_velocity /
radius;
331 trace += Sij_zz / 3.0;
336 return (Sij_xx - trace) * grad_xx + Sij_xy * grad_xy + Sij_xz * grad_xz + Sij_xy * grad_yx +
337 (Sij_yy - trace) * grad_yy + Sij_yz * grad_yz + Sij_xz * grad_zx + Sij_yz * grad_zy +
338 (Sij_zz - trace) * grad_zz;
346 const unsigned int rz_radial_coord);
354 const unsigned int rz_radial_coord);
361 const std::set<SubdomainID> & block_ids,
362 std::unordered_set<const Elem *> & wall_bounded)
365 wall_bounded.clear();
370 auto gather_functor = [&subproblem, &wall_bounded](
const processor_id_type libmesh_dbg_var(pid),
371 const std::vector<dof_id_type> & elem_ids,
372 std::vector<unsigned char> & data_to_fill)
374 mooseAssert(pid != subproblem.
processor_id(),
"We shouldn't be gathering from ourselves.");
375 data_to_fill.resize(elem_ids.size());
379 for (
const auto i : index_range(elem_ids))
381 const auto elem =
mesh.elem_ptr(elem_ids[i]);
382 data_to_fill[i] = wall_bounded.count(elem) != 0;
386 auto action_functor = [&subproblem, &wall_bounded](
const processor_id_type libmesh_dbg_var(pid),
387 const std::vector<dof_id_type> & elem_ids,
388 const std::vector<unsigned char> & filled_data)
391 "The request filler shouldn't have been ourselves");
392 mooseAssert(elem_ids.size() == filled_data.size(),
"I think these should be the same size");
396 for (
const auto i : index_range(elem_ids))
398 const auto elem =
mesh.elem_ptr(elem_ids[i]);
400 wall_bounded.insert(elem);
405 std::unordered_map<processor_id_type, std::vector<dof_id_type>> elem_ids_requested;
407 for (
const auto & elem : fe_problem.
mesh().
getMesh().active_local_element_ptr_range())
408 if (block_ids.find(elem->subdomain_id()) != block_ids.end())
409 for (
const auto i_side : elem->side_index_range())
413 std::set<BoundaryID> combined_side_bds;
415 combined_side_bds.insert(side_bnds.begin(), side_bnds.end());
416 if (
const auto neighbor = elem->neighbor_ptr(i_side))
418 const auto neighbor_side = neighbor->which_neighbor_am_i(elem);
419 const auto & neighbor_bnds = subproblem.
mesh().
getBoundaryIDs(neighbor, neighbor_side);
420 combined_side_bds.insert(neighbor_bnds.begin(), neighbor_bnds.end());
424 if (neighbor->processor_id() != subproblem.
processor_id() &&
425 block_ids.find(neighbor->subdomain_id()) != block_ids.end())
426 elem_ids_requested[neighbor->processor_id()].push_back(neighbor->id());
429 for (
const auto wall_id : wall_boundary_ids)
430 if (combined_side_bds.count(wall_id))
432 wall_bounded.insert(elem);
437 unsigned char * bool_ex =
nullptr;
439 subproblem.
comm(), elem_ids_requested, gather_functor, action_functor, bool_ex);
447 const std::set<SubdomainID> & block_ids,
448 std::map<
const Elem *, std::vector<Real>> & dist_map)
453 for (
const auto & elem : fe_problem.
mesh().
getMesh().active_local_element_ptr_range())
454 if (block_ids.find(elem->subdomain_id()) != block_ids.end())
455 for (
const auto i_side : elem->side_index_range())
459 std::set<BoundaryID> combined_side_bds;
461 combined_side_bds.insert(side_bnds.begin(), side_bnds.end());
462 if (
const auto neighbor = elem->neighbor_ptr(i_side))
464 const auto neighbor_side = neighbor->which_neighbor_am_i(elem);
465 const std::vector<BoundaryID> & neighbor_bnds =
467 combined_side_bds.insert(neighbor_bnds.begin(), neighbor_bnds.end());
470 for (
const auto wall_id : wall_boundary_ids)
471 if (combined_side_bds.count(wall_id))
476 const auto & neighbor = elem->neighbor_ptr(i_side);
478 const auto & elem_for_fi = elem_has_fi ? elem : neighbor;
479 const auto side = elem_has_fi ? i_side : neighbor->which_neighbor_am_i(elem);
484 dist_map[elem].push_back(dist);
494 const std::set<SubdomainID> & block_ids,
495 std::map<
const Elem *, std::vector<const FaceInfo *>> & face_info_map)
497 face_info_map.clear();
500 for (
const auto & elem : fe_problem.
mesh().
getMesh().active_local_element_ptr_range())
501 if (block_ids.find(elem->subdomain_id()) != block_ids.end())
502 for (
const auto i_side : elem->side_index_range())
506 std::set<BoundaryID> combined_side_bds;
508 combined_side_bds.insert(side_bnds.begin(), side_bnds.end());
509 if (elem->neighbor_ptr(i_side) && !elem->neighbor_ptr(i_side)->is_remote())
511 const auto neighbor = elem->neighbor_ptr(i_side);
512 const auto neighbor_side = neighbor->which_neighbor_am_i(elem);
513 const std::vector<BoundaryID> & neighbor_bnds =
515 combined_side_bds.insert(neighbor_bnds.begin(), neighbor_bnds.end());
518 for (
const auto wall_id : wall_boundary_ids)
519 if (combined_side_bds.count(wall_id))
524 const auto & neighbor = elem->neighbor_ptr(i_side);
526 const auto & elem_for_fi = elem_has_fi ? elem : neighbor;
527 const auto side = elem_has_fi ? i_side : neighbor->which_neighbor_am_i(elem);
530 face_info_map[elem].push_back(fi);
DualNumber< Real, DNDerivativeType, true > ADReal
Real f(Real x)
Test function for Brents method.
const std::vector< double > y
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
void mooseError(Args &&... args)
virtual MooseMesh & mesh() override
const Point & normal() const
const Point & neighborCentroid() const
const Point & elemCentroid() const
const Point & faceCentroid() const
const std::vector< const FaceInfo * > & faceInfo() const
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
GradientType gradient(const ElemArg &elem, const StateArg &state) const
virtual MooseMesh & mesh()=0
Point vertex_average() const
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
bool elemHasFaceInfo(const Elem &elem, const Elem *const neighbor)
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.
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...
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...
int computeSign(const Real &a)
Sign function, returns $+1$ if $a$ is positive and $-1$ if $a$ is negative.
template ADReal findyPlus< ADReal >(const ADReal &mu, const ADReal &rho, const ADReal &u, Real dist)
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, const Moose::CoordinateSystemType coord_sys=Moose::COORD_XYZ, const unsigned int rz_radial_coord=0)
Utility function to compute the shear strain rate.
template Real computeSpeed< Real >(const libMesh::VectorValue< Real > &velocity)
static constexpr Real von_karman_constant
static const std::string cp
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\equiv \frac{\rho Vd}{\mu}$, with respect to an ar...
template ADReal computeSpeed< ADReal >(const libMesh::VectorValue< ADReal > &velocity)
static const std::string mu
static const std::string v
static const std::string k
T findUStar(const T &mu, const T &rho, const T &u, Real dist)
Finds the friction velocity using standard velocity wall functions formulation.
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 Moose::CoordinateSystemType coord_sys, const unsigned int rz_radial_coord)
static constexpr Real E_turb_constant
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\equiv\frac{\mu C_p}{k}$, with respect to an arbitr...
template Real findYplusThermal< Real >(const Real &Pr, const Real &Pr_t)
T findYplusThermal(const T &Pr, const T &Pr_t)
Finds the thermal non-dimensional wall distance at which the laminar and logarithmic temperature wall...
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...
static constexpr Real min_y_plus
template ADReal findUStar< ADReal >(const ADReal &mu, const ADReal &rho, const ADReal &u, const Real dist)
T computeSpeed(const libMesh::VectorValue< T > &velocity)
Compute the speed (velocity norm) given the supplied velocity.
template Real findyPlus< Real >(const Real &mu, const Real &rho, const Real &u, Real dist)
int delta(unsigned int i, unsigned int j)
Delta function, which returns zero if $i\ne j$ and unity if $i=j$.
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, const Moose::CoordinateSystemType coord_sys, const unsigned int rz_radial_coord)
template Real findUStar< Real >(const Real &mu, const Real &rho, const Real &u, const Real dist)
static const std::string velocity
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-...
void pull_parallel_vector_data(const Communicator &comm, const MapToVectors &queries, GatherFunctor &gather_data, const ActionFunctor &act_on_data, const datum *example)
const libMesh::Elem * elem