VertexCFD  0.0-dev
VertexCFD_Closure_IncompressibleEnstrophy_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_INCOMPRESSIBLEENSTROPHY_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_INCOMPRESSIBLEENSTROPHY_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 <cmath>
10 
11 namespace VertexCFD
12 {
13 namespace ClosureModel
14 {
15 //---------------------------------------------------------------------------//
16 template<class EvalType, class Traits, int NumSpaceDim>
17 IncompressibleEnstrophy<EvalType, Traits, NumSpaceDim>::IncompressibleEnstrophy(
18  const panzer::IntegrationRule& ir)
19  : _vorticity("vorticity", ir.dl_vector)
20  , _enstrophy("enstrophy", ir.dl_scalar)
21  , _divergence("divergence", ir.dl_scalar)
22  , _mag_divergence("divergence_magnitude", ir.dl_scalar)
23  , _nu("kinematic_viscosity", ir.dl_scalar)
24 {
25  // Add evaluated fields
26  this->addEvaluatedField(_vorticity);
27  this->addEvaluatedField(_enstrophy);
28  this->addEvaluatedField(_divergence);
29  this->addEvaluatedField(_mag_divergence);
30 
31  // Add dependent field
32  this->addDependentField(_nu);
33  Utils::addDependentVectorField(
34  *this, ir.dl_vector, _grad_velocity, "GRAD_velocity_");
35 
36  this->setName("Incompressible Enstrophy " + std::to_string(num_space_dim)
37  + "D");
38 }
39 
40 //---------------------------------------------------------------------------//
41 template<class EvalType, class Traits, int NumSpaceDim>
42 void IncompressibleEnstrophy<EvalType, Traits, NumSpaceDim>::evaluateFields(
43  typename Traits::EvalData workset)
44 {
45  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
46  workset.num_cells);
47  Kokkos::parallel_for(this->getName(), policy, *this);
48 }
49 
50 //---------------------------------------------------------------------------//
51 template<class EvalType, class Traits, int NumSpaceDim>
52 KOKKOS_INLINE_FUNCTION void
53 IncompressibleEnstrophy<EvalType, Traits, NumSpaceDim>::operator()(
54  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
55 {
56  const int cell = team.league_rank();
57  const int num_point = _enstrophy.extent(1);
58  using Kokkos::pow;
59 
60  Kokkos::parallel_for(
61  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
62  // Calculate vorticity vector
63  if (num_space_dim < 3)
64  {
65  _vorticity(cell, point, 0)
66  = _grad_velocity[1](cell, point, 0)
67  - _grad_velocity[0](cell, point, 1);
68  _vorticity(cell, point, 1) = 0.0;
69  }
70  else
71  {
72  _vorticity(cell, point, 0)
73  = _grad_velocity[2](cell, point, 1)
74  - _grad_velocity[1](cell, point, 2);
75  _vorticity(cell, point, 1)
76  = _grad_velocity[0](cell, point, 2)
77  - _grad_velocity[2](cell, point, 0);
78  _vorticity(cell, point, 2)
79  = _grad_velocity[1](cell, point, 0)
80  - _grad_velocity[0](cell, point, 1);
81  }
82 
83  // Calculate enstrophy and divergence
84  _enstrophy(cell, point) = 0.0;
85  _divergence(cell, point) = 0.0;
86 
87  for (int dim = 0; dim < num_space_dim; ++dim)
88  {
89  _enstrophy(cell, point)
90  += pow(_vorticity(cell, point, dim), 2.0);
91  _divergence(cell, point)
92  += _grad_velocity[dim](cell, point, dim);
93  }
94 
95  _enstrophy(cell, point) *= _nu(cell, point);
96  _mag_divergence(cell, point)
97  = SmoothMath::abs(_divergence(cell, point), 0.0);
98  });
99 }
100 
101 //---------------------------------------------------------------------------//
102 
103 } // end namespace ClosureModel
104 } // end namespace VertexCFD
105 
106 #endif // end VERTEXCFD_CLOSURE_INCOMPRESSIBLEENSTROPHY_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23