VertexCFD  0.0-dev
VertexCFD_Closure_IncompressibleRealizableKEpsilonEddyViscosity_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_INCOMPRESSIBLEREALIZABLEKEPSILONEDDYVISCOSITY_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_INCOMPRESSIBLEREALIZABLEKEPSILONEDDYVISCOSITY_IMPL_HPP
3 
4 #include "utils/VertexCFD_Utils_SmoothMath.hpp"
5 #include "utils/VertexCFD_Utils_VectorField.hpp"
6 
7 #include <Panzer_HierarchicParallelism.hpp>
8 
9 namespace VertexCFD
10 {
11 namespace ClosureModel
12 {
13 //---------------------------------------------------------------------------//
14 template<class EvalType, class Traits, int NumSpaceDim>
15 IncompressibleRealizableKEpsilonEddyViscosity<EvalType, Traits, NumSpaceDim>::
16  IncompressibleRealizableKEpsilonEddyViscosity(
17  const panzer::IntegrationRule& ir)
18  : _turb_kinetic_energy("turb_kinetic_energy", ir.dl_scalar)
19  , _turb_dissipation_rate("turb_dissipation_rate", ir.dl_scalar)
20  , _A_0(4.0)
21  , _nu_t("turbulent_eddy_viscosity", ir.dl_scalar)
22 {
23  // Add dependent fields
24  this->addDependentField(_turb_kinetic_energy);
25  this->addDependentField(_turb_dissipation_rate);
26 
27  Utils::addDependentVectorField(
28  *this, ir.dl_vector, _grad_velocity, "GRAD_velocity_");
29 
30  // Add evaluated fields
31  this->addEvaluatedField(_nu_t);
32 
33  // Closure model name
34  this->setName(
35  "Realizable K-Epsilon Incompressible Turbulent Eddy Viscosity "
36  + std::to_string(num_space_dim) + "D");
37 }
38 
39 //---------------------------------------------------------------------------//
40 template<class EvalType, class Traits, int NumSpaceDim>
41 void IncompressibleRealizableKEpsilonEddyViscosity<EvalType, Traits, NumSpaceDim>::
42  evaluateFields(typename Traits::EvalData workset)
43 {
44  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
45  workset.num_cells);
46  Kokkos::parallel_for(this->getName(), policy, *this);
47 }
48 
49 //---------------------------------------------------------------------------//
50 template<class EvalType, class Traits, int NumSpaceDim>
51 KOKKOS_INLINE_FUNCTION void
52 IncompressibleRealizableKEpsilonEddyViscosity<EvalType, Traits, NumSpaceDim>::
53 operator()(const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
54 {
55  using std::acos;
56  using std::cos;
57  using std::pow;
58  using std::sqrt;
59 
60  const int cell = team.league_rank();
61  const int num_point = _nu_t.extent(1);
62  const auto tol = 1.0e-10;
63  const double sqrt_six = sqrt(6.0);
64 
65  Kokkos::parallel_for(
66  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
67  // Calculate mag square of symmetric and skew symmetric velocity
68  // gradient components.
69  // COMMENT: The Omega2 term must be modified if these equations
70  // are to be solved in a rotating reference frame.
71  scalar_type S2 = 0.0;
72  scalar_type Omega2 = 0.0;
73  scalar_type W = 0.0;
74 
75  for (int i = 0; i < num_space_dim; ++i)
76  {
77  for (int j = 0; j < num_space_dim; ++j)
78  {
79  S2 += pow(0.5
80  * (_grad_velocity[i](cell, point, j)
81  + _grad_velocity[j](cell, point, i)),
82  2.0);
83  Omega2 += pow(0.5
84  * (_grad_velocity[i](cell, point, j)
85  - _grad_velocity[j](cell, point, i)),
86  2.0);
87  for (int k = 0; k < num_space_dim; ++k)
88  {
89  W += 1.0 / 8.0
90  * (_grad_velocity[i](cell, point, j)
91  + _grad_velocity[j](cell, point, i))
92  * (_grad_velocity[j](cell, point, k)
93  + _grad_velocity[k](cell, point, j))
94  * (_grad_velocity[k](cell, point, i)
95  + _grad_velocity[i](cell, point, k));
96  }
97  }
98  }
99 
100  S2 = SmoothMath::max(S2, tol, 0.0);
101  Omega2 = SmoothMath::max(Omega2, tol, 0.0);
102  W /= pow(S2, 1.5);
103 
104  // Calculate parameters for viscosity
105  const scalar_type Us = sqrt(S2 + Omega2);
106  const scalar_type phi
107  = 1.0 / 3.0
108  * acos(SmoothMath::max(
109  SmoothMath::min(sqrt_six * W, 1.0, 0.0), -1.0, 0.0));
110  const scalar_type As = sqrt_six * cos(phi);
111  const scalar_type C_nu
112  = 1.0
113  / (_A_0
114  + (As * Us * _turb_kinetic_energy(cell, point)
115  / SmoothMath::max(
116  _turb_dissipation_rate(cell, point), tol, 0.0)));
117 
118  // Eddy viscosity calculation
119  _nu_t(cell, point)
120  = C_nu * pow(_turb_kinetic_energy(cell, point), 2.0)
121  / SmoothMath::max(
122  _turb_dissipation_rate(cell, point), tol, 0.0);
123  });
124 }
125 
126 //---------------------------------------------------------------------------//
127 
128 } // end namespace ClosureModel
129 } // end namespace VertexCFD
130 
131 #endif // end
132  // VERTEXCFD_CLOSURE_INCOMPRESSIBLEREALIZABLEKEPSILONEDDYVISCOSITY_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23