https://mooseframework.inl.gov
Loading...
Searching...
No Matches
WCNSFVMixingLengthEnergyDiffusion.C
Go to the documentation of this file.
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
11#include "NS.h"
12#include "MathFVUtils.h"
13
15
18{
21 params.addClassDescription("Computes the turbulent diffusive flux that appears in "
22 "Reynolds-averaged fluid energy conservation equations.");
23 params.addRequiredParam<MooseFunctorName>("u", "The velocity in the x direction.");
24 params.addParam<MooseFunctorName>("v", "The velocity in the y direction.");
25 params.addParam<MooseFunctorName>("w", "The velocity in the z direction.");
26 params.addRequiredParam<MooseFunctorName>("mixing_length", "The turbulent mixing length.");
27 params.addRequiredParam<Real>(
28 "schmidt_number",
29 "The turbulent Schmidt number (or turbulent Prandtl number if the passive scalar is energy) "
30 "that relates the turbulent scalar diffusivity to the turbulent momentum diffusivity.");
31 params.addRequiredParam<MooseFunctorName>(NS::density, "Density");
32 params.addRequiredParam<MooseFunctorName>(NS::cp, "Specific heat capacity");
33
34 // We add the relationship manager here, this will select the right number of
35 // ghosting layers depending on the chosen interpolation method
37 "ElementSideNeighborLayers",
38 Moose::RelationshipManagerType::GEOMETRIC | Moose::RelationshipManagerType::ALGEBRAIC |
39 Moose::RelationshipManagerType::COUPLING,
40 [](const InputParameters & obj_params, InputParameters & rm_params)
41 { FVRelationshipManagerInterface::setRMParamsDiffusion(obj_params, rm_params, 3); });
42
43 params.set<unsigned short>("ghost_layers") = 2;
44 return params;
45}
46
48 : FVFluxKernel(params),
50 _dim(_subproblem.mesh().dimension()),
51 _u(getFunctor<ADReal>("u")),
52 _v(isParamValid("v") ? &getFunctor<ADReal>("v") : nullptr),
53 _w(isParamValid("w") ? &getFunctor<ADReal>("w") : nullptr),
54 _rho(getFunctor<ADReal>(NS::density)),
55 _cp(getFunctor<ADReal>(NS::cp)),
56 _mixing_len(getFunctor<ADReal>("mixing_length")),
57 _schmidt_number(getParam<Real>("schmidt_number"))
58{
59 if (_dim >= 2 && !_v)
61 "In two or more dimensions, the v velocity must be supplied using the 'v' parameter");
62 if (_dim >= 3 && !_w)
63 mooseError("In three dimensions, the w velocity must be supplied using the 'w' parameter");
64}
65
68{
69 using std::sqrt;
70
71 constexpr Real offset = 1e-15; // prevents explosion of sqrt(x) derivative to infinity
72
73 const auto face = makeCDFace(*_face_info);
74 const auto state = determineState();
75
76 const auto grad_u = _u.gradient(face, state);
77 ADReal symmetric_strain_tensor_norm = 2.0 * Utility::pow<2>(grad_u(0));
78 if (_dim >= 2)
79 {
80 const auto grad_v = _v->gradient(face, state);
81 symmetric_strain_tensor_norm +=
82 2.0 * Utility::pow<2>(grad_v(1)) + Utility::pow<2>(grad_v(0) + grad_u(1));
83 if (_dim >= 3)
84 {
85 const auto grad_w = _w->gradient(face, state);
86 symmetric_strain_tensor_norm += 2.0 * Utility::pow<2>(grad_w(2)) +
87 Utility::pow<2>(grad_u(2) + grad_w(0)) +
88 Utility::pow<2>(grad_v(2) + grad_w(1));
89 }
90 }
91
92 symmetric_strain_tensor_norm = sqrt(symmetric_strain_tensor_norm + offset);
93
94 // Interpolate the mixing length to the face
95 ADReal mixing_len = _mixing_len(face, state);
96
97 // Compute the eddy diffusivity for momentum
98 ADReal eddy_diff = symmetric_strain_tensor_norm * mixing_len * mixing_len;
99
100 // Use the turbulent Schmidt/Prandtl number to get the eddy diffusivity for
101 // the scalar variable
102 eddy_diff /= _schmidt_number;
103
104 const auto dTdn = gradUDotNormal(state, _correct_skewness);
105
106 ADReal rho_cp_face;
108 {
109 const auto ssf = singleSidedFaceArg();
110 rho_cp_face = _rho(ssf, state) * _cp(ssf, state);
111 }
112 else
113 {
114 // Interpolate the heat capacity
115 const auto face_elem = elemArg();
116 const auto face_neighbor = neighborArg();
117 interpolate(Moose::FV::InterpMethod::Average,
118 rho_cp_face,
119 _rho(face_elem, state) * _cp(face_elem, state),
120 _rho(face_neighbor, state) * _cp(face_neighbor, state),
121 *_face_info,
122 true);
123 }
124
125 return -1 * eddy_diff * rho_cp_face * dTdn;
126}
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("NavierStokesApp", WCNSFVMixingLengthEnergyDiffusion)
static InputParameters validParams()
Moose::ElemArg neighborArg(bool correct_skewness=false) const
Moose::ElemArg elemArg(bool correct_skewness=false) const
static InputParameters validParams()
bool onBoundary(const FaceInfo &fi) const
Moose::FaceArg singleSidedFaceArg(const FaceInfo *fi=nullptr, Moose::FV::LimiterType limiter_type=Moose::FV::LimiterType::CentralDifference, bool correct_skewness=false, const Moose::StateArg *state_limiter=nullptr) const
virtual ADReal gradUDotNormal(const Moose::StateArg &time, const bool correct_skewness) const
const FaceInfo * _face_info
static void setRMParamsDiffusion(const InputParameters &obj_params, InputParameters &rm_params, const unsigned short conditional_extended_layers)
Moose::FaceArg makeCDFace(const FaceInfo &fi, const bool correct_skewness=false) const
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addRelationshipManager(const std::string &name, Moose::RelationshipManagerType rm_type, Moose::RelationshipManagerInputParameterCallback input_parameter_callback=nullptr)
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
void mooseError(Args &&... args) const
Moose::StateArg determineState() const
Computes the turbulent diffusion of energy term in the weakly compressible formulation of the energy ...
const Moose::Functor< ADReal > & _u
x-velocity
const Moose::Functor< ADReal > & _rho
the fluid density
const Real & _schmidt_number
Turbulent Schmidt number (or turbulent Prandtl number)
WCNSFVMixingLengthEnergyDiffusion(const InputParameters &params)
const Moose::Functor< ADReal > & _mixing_len
Turbulent eddy mixing length.
const Moose::Functor< ADReal > & _cp
the specific heat capacity
const unsigned int _dim
the dimension of the simulation
const Moose::Functor< ADReal > *const _w
z-velocity
const Moose::Functor< ADReal > *const _v
y-velocity
MeshBase & mesh
static const std::string density
Definition NS.h:34
static const std::string cp
Definition NS.h:125