VertexCFD  0.0-dev
VertexCFD_Closure_ConductionErrorNorms_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_CONDUCTIONERRORNORMS_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_CONDUCTIONERRORNORMS_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>
23  const panzer::IntegrationRule& ir)
24  : _L1_error_continuity("L1_Error_continuity", ir.dl_scalar)
25  , _L1_error_energy("L1_Error_energy", ir.dl_scalar)
26  , _L2_error_continuity("L2_Error_continuity", ir.dl_scalar)
27  , _L2_error_energy("L2_Error_energy", ir.dl_scalar)
28  , _volume("volume", ir.dl_scalar)
29  , _exact_temperature("Exact_temperature", ir.dl_scalar)
30  , _temperature("temperature", ir.dl_scalar)
31 {
32  // exact solution
33  this->addDependentField(_exact_temperature);
34 
35  // numerical solution
36  this->addDependentField(_temperature);
37 
38  // error between exact and numerical solution
39  this->addEvaluatedField(_L1_error_continuity);
40  Utils::addEvaluatedVectorField(
41  *this, ir.dl_scalar, _L1_error_momentum, "L1_Error_momentum_");
42  this->addEvaluatedField(_L2_error_continuity);
43  Utils::addEvaluatedVectorField(
44  *this, ir.dl_scalar, _L2_error_momentum, "L2_Error_momentum_");
45 
46  this->addEvaluatedField(_L1_error_energy);
47  this->addEvaluatedField(_L2_error_energy);
48  this->addEvaluatedField(_volume);
49 
50  this->setName("Conduction Error Norms " + std::to_string(num_space_dim)
51  + "D");
52 }
53 
54 //---------------------------------------------------------------------------//
55 template<class EvalType, class Traits, int NumSpaceDim>
57  typename Traits::EvalData workset)
58 {
59  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
60  workset.num_cells);
61  Kokkos::parallel_for(this->getName(), policy, *this);
62 }
63 
64 //---------------------------------------------------------------------------//
65 template<class EvalType, class Traits, int NumSpaceDim>
66 KOKKOS_INLINE_FUNCTION void
68  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
69 {
70  const int cell = team.league_rank();
71  const int num_point = _temperature.extent(1);
72 
73  Kokkos::parallel_for(
74  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
75  using std::abs;
76  using std::pow;
77 
78  // L1/L2 error norms for temperature. All other variables are set
79  // to zero on the solid region.
80  _L1_error_energy(cell, point) = abs(
81  _temperature(cell, point) - _exact_temperature(cell, point));
82 
83  _L2_error_energy(cell, point) = pow(
84  _temperature(cell, point) - _exact_temperature(cell, point), 2);
85 
86  _L1_error_continuity(cell, point) = 0.0;
87 
88  _L2_error_continuity(cell, point) = 0.0;
89 
90  for (int i = 0; i < num_space_dim; ++i)
91  {
92  _L1_error_momentum[i](cell, point) = 0.0;
93  _L2_error_momentum[i](cell, point) = 0.0;
94  }
95 
96  _volume(cell, point) = 1.0;
97  });
98 }
99 
100 //---------------------------------------------------------------------------//
101 
102 } // end namespace ClosureModel
103 } // end namespace VertexCFD
104 
105 #endif // VERTEXCFD_CLOSURE_CONDUCTIONERRORNORMS_IMPL_HPP
VertexCFD::ClosureModel::ConductionErrorNorms::_L1_error_continuity
PHX::MDField< scalar_type, panzer::Cell, panzer::Point > _L1_error_continuity
L1 error of the continuity equation (scalar field).
Definition: VertexCFD_Closure_ConductionErrorNorms.hpp:73
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23
VertexCFD::ClosureModel::ConductionErrorNorms::_L1_error_momentum
Kokkos::Array< PHX::MDField< scalar_type, panzer::Cell, panzer::Point >, num_space_dim > _L1_error_momentum
L1 error of the momentum equations (vector field).
Definition: VertexCFD_Closure_ConductionErrorNorms.hpp:82
VertexCFD::ClosureModel::ConductionErrorNorms::_L2_error_continuity
PHX::MDField< scalar_type, panzer::Cell, panzer::Point > _L2_error_continuity
L2 error of the continuity equation (scalar field).
Definition: VertexCFD_Closure_ConductionErrorNorms.hpp:88
VertexCFD::ClosureModel::ConductionErrorNorms::ConductionErrorNorms
ConductionErrorNorms(const panzer::IntegrationRule &ir)
Constructor.
Definition: VertexCFD_Closure_ConductionErrorNorms_impl.hpp:22
VertexCFD::ClosureModel::ConductionErrorNorms::_L1_error_energy
PHX::MDField< scalar_type, panzer::Cell, panzer::Point > _L1_error_energy
L1 error of the energy equation (scalar field).
Definition: VertexCFD_Closure_ConductionErrorNorms.hpp:85
VertexCFD::ClosureModel::ConductionErrorNorms::scalar_type
typename EvalType::ScalarT scalar_type
Alias for the scalar type used by the evaluation type.
Definition: VertexCFD_Closure_ConductionErrorNorms.hpp:37
VertexCFD::ClosureModel::ConductionErrorNorms::_L2_error_energy
PHX::MDField< scalar_type, panzer::Cell, panzer::Point > _L2_error_energy
L2 error of the energy equation (scalar field).
Definition: VertexCFD_Closure_ConductionErrorNorms.hpp:96
VertexCFD::ClosureModel::ConductionErrorNorms::num_space_dim
static constexpr int num_space_dim
Number of spatial dimensions (compile‑time constant).
Definition: VertexCFD_Closure_ConductionErrorNorms.hpp:40
VertexCFD::ClosureModel::ConductionErrorNorms::operator()
KOKKOS_INLINE_FUNCTION void operator()(const Kokkos::TeamPolicy< PHX::exec_space >::member_type &team) const
Kokkos functor invoked for each team of threads.
Definition: VertexCFD_Closure_ConductionErrorNorms_impl.hpp:67
VertexCFD::ClosureModel::ConductionErrorNorms::_L2_error_momentum
Kokkos::Array< PHX::MDField< scalar_type, panzer::Cell, panzer::Point >, num_space_dim > _L2_error_momentum
L2 error of the momentum equations (vector field).
Definition: VertexCFD_Closure_ConductionErrorNorms.hpp:93
VertexCFD::ClosureModel::ConductionErrorNorms::_volume
PHX::MDField< scalar_type, panzer::Cell, panzer::Point > _volume
Cell volume at each integration point (used for weighting).
Definition: VertexCFD_Closure_ConductionErrorNorms.hpp:99
VertexCFD::ClosureModel::ConductionErrorNorms::evaluateFields
void evaluateFields(typename Traits::EvalData workset) override
Evaluate the error norm fields over the workset.
Definition: VertexCFD_Closure_ConductionErrorNorms_impl.hpp:56