VertexCFD  0.0-dev
VertexCFD_Closure_ElementLength_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_ELEMENTLENGTH_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_ELEMENTLENGTH_IMPL_HPP
3 
4 #include <Panzer_HierarchicParallelism.hpp>
5 
6 #include <cmath>
7 
8 namespace VertexCFD
9 {
10 namespace ClosureModel
11 {
12 //---------------------------------------------------------------------------//
13 template<class EvalType, class Traits>
14 ElementLength<EvalType, Traits>::ElementLength(const panzer::IntegrationRule& ir,
15  const std::string& prefix)
16  : _element_length(prefix + "element_length", ir.dl_vector)
17 {
18  this->addEvaluatedField(_element_length);
19  this->setName("Element Length");
20 }
21 
22 //---------------------------------------------------------------------------//
23 template<class EvalType, class Traits>
24 void ElementLength<EvalType, Traits>::evaluateFields(
25  typename Traits::EvalData workset)
26 {
27  // TODO don't assume a 0 basis index.
28  _grad_basis = this->wda(workset).bases[0]->grad_basis;
29  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
30  workset.num_cells);
31  Kokkos::parallel_for(this->getName(), policy, *this);
32 }
33 
34 //---------------------------------------------------------------------------//
35 template<class EvalType, class Traits>
36 KOKKOS_INLINE_FUNCTION void ElementLength<EvalType, Traits>::operator()(
37  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
38 {
39  const int cell = team.league_rank();
40  const int num_point = _element_length.extent(1);
41  const int num_space_dim = _element_length.extent(2);
42  const int num_basis = _grad_basis.extent(1);
43 
44  Kokkos::parallel_for(
45  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
46  using std::pow;
47 
48  for (int dim = 0; dim < num_space_dim; ++dim)
49  {
50  double grad_basis_squared = 0.0;
51  for (int basis = 0; basis < num_basis; ++basis)
52  {
53  grad_basis_squared
54  += pow(_grad_basis(cell, basis, point, dim), 2);
55  }
56  _element_length(cell, point, dim)
57  = pow(grad_basis_squared, -0.5);
58  }
59  });
60 }
61 
62 //---------------------------------------------------------------------------//
63 
64 } // end namespace ClosureModel
65 } // end namespace VertexCFD
66 
67 #endif // end VERTEXCFD_CLOSURE_ELEMENTLENGTH_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23