VertexCFD  0.0-dev
VertexCFD_Closure_IncompressibleKEpsilonSource_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_INCOMPRESSIBLEKEPSILONSOURCE_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_INCOMPRESSIBLEKEPSILONSOURCE_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 #include <math.h>
10 
11 namespace VertexCFD
12 {
13 namespace ClosureModel
14 {
15 //---------------------------------------------------------------------------//
16 template<class EvalType, class Traits, int NumSpaceDim>
17 IncompressibleKEpsilonSource<EvalType, Traits, NumSpaceDim>::
18  IncompressibleKEpsilonSource(const panzer::IntegrationRule& ir)
19  : _nu_t("turbulent_eddy_viscosity", ir.dl_scalar)
20  , _turb_kinetic_energy("turb_kinetic_energy", ir.dl_scalar)
21  , _turb_dissipation_rate("turb_dissipation_rate", ir.dl_scalar)
22  , _C_1(1.44)
23  , _C_2(1.92)
24  , _k_source("SOURCE_turb_kinetic_energy_equation", ir.dl_scalar)
25  , _k_prod("PRODUCTION_turb_kinetic_energy_equation", ir.dl_scalar)
26  , _k_dest("DESTRUCTION_turb_kinetic_energy_equation", ir.dl_scalar)
27  , _e_source("SOURCE_turb_dissipation_rate_equation", ir.dl_scalar)
28  , _e_prod("PRODUCTION_turb_dissipation_rate_equation", ir.dl_scalar)
29  , _e_dest("DESTRUCTION_turb_dissipation_rate_equation", ir.dl_scalar)
30 {
31  // Add dependent fields
32  this->addDependentField(_nu_t);
33  this->addDependentField(_turb_kinetic_energy);
34  this->addDependentField(_turb_dissipation_rate);
35 
36  Utils::addDependentVectorField(
37  *this, ir.dl_vector, _grad_velocity, "GRAD_velocity_");
38 
39  // Add evaluated fields
40  this->addEvaluatedField(_k_source);
41  this->addEvaluatedField(_k_prod);
42  this->addEvaluatedField(_k_dest);
43  this->addEvaluatedField(_e_source);
44  this->addEvaluatedField(_e_prod);
45  this->addEvaluatedField(_e_dest);
46 
47  // Closure model name
48  this->setName("K-Epsilon Incompressible Source "
49  + std::to_string(num_space_dim) + "D");
50 }
51 
52 //---------------------------------------------------------------------------//
53 template<class EvalType, class Traits, int NumSpaceDim>
54 void IncompressibleKEpsilonSource<EvalType, Traits, NumSpaceDim>::evaluateFields(
55  typename Traits::EvalData workset)
56 {
57  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
58  workset.num_cells);
59  Kokkos::parallel_for(this->getName(), policy, *this);
60 }
61 
62 //---------------------------------------------------------------------------//
63 template<class EvalType, class Traits, int NumSpaceDim>
64 KOKKOS_INLINE_FUNCTION void
65 IncompressibleKEpsilonSource<EvalType, Traits, NumSpaceDim>::operator()(
66  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
67 {
68  const int cell = team.league_rank();
69  const int num_point = _nu_t.extent(1);
70  const double max_tol = 1.0e-10;
71  using std::pow;
72 
73  Kokkos::parallel_for(
74  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
75  // Production term
76  _k_prod(cell, point) = 0.0;
77 
78  for (int i = 0; i < num_space_dim; ++i)
79  {
80  for (int j = 0; j < num_space_dim; ++j)
81  {
82  _k_prod(cell, point)
83  += pow(0.5
84  * (_grad_velocity[i](cell, point, j)
85  + _grad_velocity[j](cell, point, i)),
86  2.0);
87  }
88  }
89 
90  // Turbulent kinetic energy terms
91  _k_prod(cell, point) *= (2.0 * _nu_t(cell, point));
92  if (_turb_kinetic_energy(cell, point) > 0.0)
93  {
94  _k_dest(cell, point) = -SmoothMath::max(
95  _turb_dissipation_rate(cell, point), 0.0, 0.0);
96  }
97  else
98  {
99  _k_dest(cell, point) = 0.0;
100  }
101  _k_source(cell, point) = _k_prod(cell, point)
102  + _k_dest(cell, point);
103 
104  // Turbulent dissipation rate terms
105  _e_prod(cell, point)
106  = _C_1
107  * SmoothMath::max(
108  _turb_dissipation_rate(cell, point), 0.0, 0.0)
109  / SmoothMath::max(
110  _turb_kinetic_energy(cell, point), max_tol, 0.0)
111  * _k_prod(cell, point);
112  _e_dest(cell, point)
113  = -_C_2
114  * pow(SmoothMath::max(
115  _turb_dissipation_rate(cell, point), 0.0, 0.0),
116  2.0)
117  / SmoothMath::max(
118  _turb_kinetic_energy(cell, point), max_tol, 0.0);
119  _e_source(cell, point) = _e_prod(cell, point)
120  + _e_dest(cell, point);
121  });
122 }
123 
124 //---------------------------------------------------------------------------//
125 
126 } // end namespace ClosureModel
127 } // end namespace VertexCFD
128 
129 #endif // end
130  // VERTEXCFD_CLOSURE_INCOMPRESSIBLEKEPSILONSOURCE_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23