VertexCFD  0.0-dev
VertexCFD_Closure_IncompressibleErrorNorms_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_INCOMPRESSIBLEERRORNORMS_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_INCOMPRESSIBLEERRORNORMS_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 IncompressibleErrorNorms<EvalType, Traits, NumSpaceDim>::IncompressibleErrorNorms(
23  const panzer::IntegrationRule& ir,
24  const Teuchos::ParameterList& fluid_params)
25  : _L1_error_continuity("L1_Error_continuity", ir.dl_scalar)
26  , _L1_error_energy("L1_Error_energy", ir.dl_scalar)
27  , _L2_error_continuity("L2_Error_continuity", ir.dl_scalar)
28  , _L2_error_energy("L2_Error_energy", ir.dl_scalar)
29  , _volume("volume", ir.dl_scalar)
30  , _exact_lagrange_pressure("Exact_lagrange_pressure", ir.dl_scalar)
31  , _exact_temperature("Exact_temperature", ir.dl_scalar)
32  , _lagrange_pressure("lagrange_pressure", ir.dl_scalar)
33  , _temperature("temperature", ir.dl_scalar)
34 {
35  // Temperature boolean
36  _use_temp = fluid_params.isType<bool>("Build Temperature Equation")
37  ? fluid_params.get<bool>("Build Temperature Equation")
38  : false;
39 
40  // exact solution
41  this->addDependentField(_exact_lagrange_pressure);
42  Utils::addDependentVectorField(
43  *this, ir.dl_scalar, _exact_velocity, "Exact_velocity_");
44  if (_use_temp)
45  this->addDependentField(_exact_temperature);
46 
47  // numerical solution
48  this->addDependentField(_lagrange_pressure);
49  Utils::addDependentVectorField(*this, ir.dl_scalar, _velocity, "velocity_");
50  if (_use_temp)
51  this->addDependentField(_temperature);
52 
53  // error between exact and numerical solution
54  this->addEvaluatedField(_L1_error_continuity);
55  Utils::addEvaluatedVectorField(
56  *this, ir.dl_scalar, _L1_error_momentum, "L1_Error_momentum_");
57  this->addEvaluatedField(_L2_error_continuity);
58  Utils::addEvaluatedVectorField(
59  *this, ir.dl_scalar, _L2_error_momentum, "L2_Error_momentum_");
60 
61  if (_use_temp)
62  {
63  this->addEvaluatedField(_L1_error_energy);
64  this->addEvaluatedField(_L2_error_energy);
65  }
66  this->addEvaluatedField(_volume);
67 
68  this->setName("Incompressible Error Norms " + std::to_string(num_space_dim)
69  + "D");
70 }
71 
72 //---------------------------------------------------------------------------//
73 template<class EvalType, class Traits, int NumSpaceDim>
74 void IncompressibleErrorNorms<EvalType, Traits, NumSpaceDim>::evaluateFields(
75  typename Traits::EvalData workset)
76 {
77  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
78  workset.num_cells);
79  Kokkos::parallel_for(this->getName(), policy, *this);
80 }
81 
82 //---------------------------------------------------------------------------//
83 template<class EvalType, class Traits, int NumSpaceDim>
84 KOKKOS_INLINE_FUNCTION void
85 IncompressibleErrorNorms<EvalType, Traits, NumSpaceDim>::operator()(
86  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
87 {
88  const int cell = team.league_rank();
89  const int num_point = _lagrange_pressure.extent(1);
90 
91  Kokkos::parallel_for(
92  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
93  using std::abs;
94  using std::pow;
95 
96  // L1/L2 error norms
97  _L1_error_continuity(cell, point)
98  = abs(_lagrange_pressure(cell, point)
99  - _exact_lagrange_pressure(cell, point));
100 
101  if (_use_temp)
102  {
103  _L1_error_energy(cell, point)
104  = abs(_temperature(cell, point)
105  - _exact_temperature(cell, point));
106  }
107 
108  _L2_error_continuity(cell, point)
109  = pow(_lagrange_pressure(cell, point)
110  - _exact_lagrange_pressure(cell, point),
111  2);
112 
113  if (_use_temp)
114  {
115  _L2_error_energy(cell, point) = pow(
116  _temperature(cell, point) - _exact_temperature(cell, point),
117  2);
118  }
119 
120  for (int i = 0; i < num_space_dim; ++i)
121  {
122  _L1_error_momentum[i](cell, point)
123  = abs(_velocity[i](cell, point)
124  - _exact_velocity[i](cell, point));
125  _L2_error_momentum[i](cell, point) = pow(
126  _velocity[i](cell, point) - _exact_velocity[i](cell, point),
127  2);
128  }
129 
130  _volume(cell, point) = 1.0;
131  });
132 }
133 
134 //---------------------------------------------------------------------------//
135 
136 } // end namespace ClosureModel
137 } // end namespace VertexCFD
138 
139 #endif // VERTEXCFD_CLOSURE_INCOMPRESSIBLEERRORNORMS_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23