VertexCFD  0.0-dev
VertexCFD_Closure_FullInductionModelErrorNorms_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_FULLINDUCTIONMODELERRORNORMS_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_FULLINDUCTIONMODELERRORNORMS_IMPL_HPP
3 
4 #include <utils/VertexCFD_Utils_VectorField.hpp>
5 
6 #include "Panzer_GlobalIndexer.hpp"
7 #include "Panzer_PureBasis.hpp"
8 #include "Panzer_Workset_Utilities.hpp"
9 #include <Panzer_HierarchicParallelism.hpp>
10 
11 #include <Teuchos_Array.hpp>
12 
13 #include <cmath>
14 #include <string>
15 
16 namespace VertexCFD
17 {
18 namespace ClosureModel
19 {
20 //---------------------------------------------------------------------------//
21 template<class EvalType, class Traits, int NumSpaceDim>
22 FullInductionModelErrorNorms<EvalType, Traits, NumSpaceDim>::
23  FullInductionModelErrorNorms(const panzer::IntegrationRule& ir)
24  : _volume("volume", ir.dl_scalar)
25 {
26  // exact solution
27  Utils::addDependentVectorField(*this,
28  ir.dl_scalar,
29  _exact_induced_magnetic_field,
30  "Exact_induced_magnetic_field_");
31 
32  // numerical solution
33  Utils::addDependentVectorField(*this,
34  ir.dl_scalar,
35  _induced_magnetic_field,
36  "induced_magnetic_field_");
37 
38  // error between exact and numerical solution
39  Utils::addEvaluatedVectorField(
40  *this, ir.dl_scalar, _L1_error_induced, "L1_Error_induction_");
41  Utils::addEvaluatedVectorField(
42  *this, ir.dl_scalar, _L2_error_induced, "L2_Error_induction_");
43 
44  this->addEvaluatedField(_volume);
45 
46  this->setName("Full Induction Model Error Norms "
47  + std::to_string(num_space_dim) + "D");
48 }
49 
50 //---------------------------------------------------------------------------//
51 template<class EvalType, class Traits, int NumSpaceDim>
52 void FullInductionModelErrorNorms<EvalType, Traits, NumSpaceDim>::evaluateFields(
53  typename Traits::EvalData workset)
54 {
55  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
56  workset.num_cells);
57  Kokkos::parallel_for(this->getName(), policy, *this);
58 }
59 
60 //---------------------------------------------------------------------------//
61 template<class EvalType, class Traits, int NumSpaceDim>
62 KOKKOS_INLINE_FUNCTION void
63 FullInductionModelErrorNorms<EvalType, Traits, NumSpaceDim>::operator()(
64  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
65 {
66  const int cell = team.league_rank();
67  const int num_point = _induced_magnetic_field[0].extent(1);
68 
69  Kokkos::parallel_for(
70  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
71  using std::abs;
72  using std::pow;
73 
74  // L1/L2 error norms
75  for (int i = 0; i < num_space_dim; ++i)
76  {
77  _L1_error_induced[i](cell, point)
78  = abs(_induced_magnetic_field[i](cell, point)
79  - _exact_induced_magnetic_field[i](cell, point));
80  _L2_error_induced[i](cell, point)
81  = pow(_induced_magnetic_field[i](cell, point)
82  - _exact_induced_magnetic_field[i](cell, point),
83  2);
84  }
85 
86  _volume(cell, point) = 1.0;
87  });
88 }
89 
90 //---------------------------------------------------------------------------//
91 
92 } // end namespace ClosureModel
93 } // end namespace VertexCFD
94 
95 #endif // VERTEXCFD_CLOSURE_FULLINDUCTIONMODELERRORNORMS_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23