VertexCFD  0.0-dev
VertexCFD_Closure_IncompressibleLSVOFErrorNorms_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_INCOMPRESSIBLELSVOFERRORNORMS_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_INCOMPRESSIBLELSVOFERRORNORMS_IMPL_HPP
3 
4 #include "utils/VertexCFD_Utils_VectorField.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 #include <cmath>
14 #include <string>
15 
16 namespace VertexCFD
17 {
18 namespace ClosureModel
19 {
20 //---------------------------------------------------------------------------//
21 template<class EvalType, class Traits, int NumSpaceDim>
22 IncompressibleLSVOFErrorNorms<EvalType, Traits, NumSpaceDim>::
23  IncompressibleLSVOFErrorNorms(const panzer::IntegrationRule& ir,
24  const Teuchos::ParameterList& closure_params)
25  : _L1_error_continuity("L1_Error_continuity", ir.dl_scalar)
26  , _L2_error_continuity("L2_Error_continuity", ir.dl_scalar)
27  , _volume("volume", ir.dl_scalar)
28  , _dof_name(closure_params.get<std::string>("DOF Name"))
29  , _exact_pressure("Exact_lagrange_pressure", ir.dl_scalar)
30  , _exact_dof("Exact_" + _dof_name, ir.dl_scalar)
31  , _pressure("lagrange_pressure", ir.dl_scalar)
32  , _dof(_dof_name, ir.dl_scalar)
33  , _L1_error_dof("L1_Error_" + _dof_name, ir.dl_scalar)
34  , _L2_error_dof("L2_Error_" + _dof_name, ir.dl_scalar)
35 {
36  // Check if NS equations are solved
37  _solve_ns = closure_params.isType<bool>("Compute NS Error Norms")
38  ? closure_params.get<bool>("Compute NS Error Norms")
39  : false;
40 
41  // Add NS terms
42  if (_solve_ns)
43  {
44  // Dependent fields
45  this->addDependentField(_exact_pressure);
46  this->addDependentField(_pressure);
47 
48  Utils::addDependentVectorField(
49  *this, ir.dl_scalar, _exact_velocity, "Exact_velocity_");
50  Utils::addDependentVectorField(
51  *this, ir.dl_scalar, _velocity, "velocity_");
52 
53  // Evaluated fields
54  this->addEvaluatedField(_L1_error_continuity);
55  this->addEvaluatedField(_L2_error_continuity);
56 
57  Utils::addEvaluatedVectorField(
58  *this, ir.dl_scalar, _L1_error_momentum, "L1_Error_momentum_");
59  Utils::addEvaluatedVectorField(
60  *this, ir.dl_scalar, _L2_error_momentum, "L2_Error_momentum_");
61  }
62 
63  // LSVOF terms
64  this->addDependentField(_dof);
65  this->addDependentField(_exact_dof);
66  this->addEvaluatedField(_L1_error_dof);
67  this->addEvaluatedField(_L2_error_dof);
68 
69  this->addEvaluatedField(_volume);
70 
71  this->setName("Incompressible LSVOF Error Norms "
72  + std::to_string(num_space_dim) + "D");
73 }
74 
75 //---------------------------------------------------------------------------//
76 template<class EvalType, class Traits, int NumSpaceDim>
77 void IncompressibleLSVOFErrorNorms<EvalType, Traits, NumSpaceDim>::evaluateFields(
78  typename Traits::EvalData workset)
79 {
80  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
81  workset.num_cells);
82  Kokkos::parallel_for(this->getName(), policy, *this);
83 }
84 
85 //---------------------------------------------------------------------------//
86 template<class EvalType, class Traits, int NumSpaceDim>
87 KOKKOS_INLINE_FUNCTION void
88 IncompressibleLSVOFErrorNorms<EvalType, Traits, NumSpaceDim>::operator()(
89  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
90 {
91  const int cell = team.league_rank();
92  const int num_point = _volume.extent(1);
93 
94  Kokkos::parallel_for(
95  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
96  using Kokkos::abs;
97  using Kokkos::pow;
98 
99  // L1/L2 error norms for NS equations
100  if (_solve_ns)
101  {
102  _L1_error_continuity(cell, point) = abs(
103  _pressure(cell, point) - _exact_pressure(cell, point));
104 
105  _L2_error_continuity(cell, point) = pow(
106  _pressure(cell, point) - _exact_pressure(cell, point), 2.0);
107 
108  for (int i = 0; i < num_space_dim; ++i)
109  {
110  _L1_error_momentum[i](cell, point)
111  = abs(_velocity[i](cell, point)
112  - _exact_velocity[i](cell, point));
113  _L2_error_momentum[i](cell, point)
114  = pow(_velocity[i](cell, point)
115  - _exact_velocity[i](cell, point),
116  2.0);
117  }
118  }
119 
120  // L1/L2 error norms for LSVOF terms
121  _L1_error_dof(cell, point)
122  = abs(_dof(cell, point) - _exact_dof(cell, point));
123  _L2_error_dof(cell, point)
124  = pow(_dof(cell, point) - _exact_dof(cell, point), 2.0);
125 
126  _volume(cell, point) = 1.0;
127  });
128 }
129 
130 //---------------------------------------------------------------------------//
131 
132 } // end namespace ClosureModel
133 } // end namespace VertexCFD
134 
135 #endif // VERTEXCFD_CLOSURE_INCOMPRESSIBLELSVOFERRORNORMS_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23