VertexCFD  0.0-dev
VertexCFD_Closure_RADErrorNorms_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_RADERRORNORMS_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_RADERRORNORMS_IMPL_HPP
3 
4 #include "utils/VertexCFD_Utils_ScalarFieldView.hpp"
5 
6 #include <Panzer_GlobalIndexer.hpp>
7 #include <Panzer_HierarchicParallelism.hpp>
8 #include <Panzer_PureBasis.hpp>
9 #include <Panzer_Workset_Utilities.hpp>
10 
11 #include <Teuchos_Array.hpp>
12 
13 namespace VertexCFD
14 {
15 namespace ClosureModel
16 {
17 //---------------------------------------------------------------------------//
18 template<class EvalType, class Traits>
19 RADErrorNorms<EvalType, Traits>::RADErrorNorms(
20  const panzer::IntegrationRule& ir,
21  const SpeciesProperties::ConstantSpeciesProperties& species_prop)
22  : _num_species(species_prop.numSpecies())
23  , _volume("volume", ir.dl_scalar)
24 {
25  // Dependent variables
26  Utils::addDependentScalarFieldView(
27  *this, ir.dl_scalar, _num_species, _exact_species, "Exact_species_");
28  Utils::addDependentScalarFieldView(
29  *this, ir.dl_scalar, _num_species, _species, "species_");
30 
31  // Evaluated variables
32  Utils::addEvaluatedScalarFieldView(*this,
33  ir.dl_scalar,
34  _num_species,
35  _L1_error_species,
36  "L1_Error_reaction_advection_diffusion_"
37  "equation_");
38  Utils::addEvaluatedScalarFieldView(*this,
39  ir.dl_scalar,
40  _num_species,
41  _L2_error_species,
42  "L2_Error_reaction_advection_diffusion_"
43  "equation_");
44  this->addEvaluatedField(_volume);
45 
46  this->setName("RAD Error Norms");
47 }
48 
49 //---------------------------------------------------------------------------//
50 template<class EvalType, class Traits>
51 void RADErrorNorms<EvalType, Traits>::evaluateFields(
52  typename Traits::EvalData workset)
53 {
54  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
55  workset.num_cells);
56  Kokkos::parallel_for(this->getName(), policy, *this);
57 }
58 
59 //---------------------------------------------------------------------------//
60 template<class EvalType, class Traits>
61 KOKKOS_INLINE_FUNCTION void RADErrorNorms<EvalType, Traits>::operator()(
62  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
63 {
64  const int cell = team.league_rank();
65  const int num_point = _species[0].extent(1);
66 
67  Kokkos::parallel_for(
68  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
69  using Kokkos::abs;
70  using Kokkos::pow;
71  for (int num = 0; num < _num_species; ++num)
72  {
73  _L1_error_species[num](cell, point)
74  = abs(_species[num](cell, point)
75  - _exact_species[num](cell, point));
76 
77  _L2_error_species[num](cell, point)
78  = pow(_species[num](cell, point)
79  - _exact_species[num](cell, point),
80  2);
81  }
82  _volume(cell, point) = 1.0;
83  });
84 }
85 
86 //---------------------------------------------------------------------------//
87 
88 } // end namespace ClosureModel
89 } // end namespace VertexCFD
90 
91 #endif // VERTEXCFD_CLOSURE_RADERRORNORMS_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23