VertexCFD  0.0-dev
VertexCFD_Closure_VariableSUPGFlux_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_VARIABLESUPGFLUX_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_VARIABLESUPGFLUX_IMPL_HPP
3 
4 #include "utils/VertexCFD_Utils_VectorField.hpp"
5 
6 #include <Panzer_HierarchicParallelism.hpp>
7 
8 namespace VertexCFD
9 {
10 namespace ClosureModel
11 {
12 //---------------------------------------------------------------------------//
13 template<class EvalType, class Traits, int NumSpaceDim>
14 VariableSUPGFlux<EvalType, Traits, NumSpaceDim>::VariableSUPGFlux(
15  const panzer::IntegrationRule& ir,
16  const Teuchos::ParameterList& closure_params)
17  : _variable_name(closure_params.get<std::string>("Field Name"))
18  , _equation_name(closure_params.get<std::string>("Equation Name"))
19  , _var_diff_flux("DIFFUSION_FLUX_" + _equation_name, ir.dl_vector)
20  , _tau_supg_var("tau_supg_" + _variable_name, ir.dl_scalar)
21  , _dxdt_var("DXDT_" + _variable_name, ir.dl_scalar)
22  , _var_source("SOURCE_" + _equation_name, ir.dl_scalar)
23  , _grad_var("GRAD_" + _variable_name, ir.dl_vector)
24 {
25  // Add contributed fields
26  this->addContributedField(_var_diff_flux);
27 
28  // Add dependent fields
29  Utils::addDependentVectorField(*this, ir.dl_scalar, _velocity, "velocity_");
30  this->addDependentField(_dxdt_var);
31  this->addDependentField(_grad_var);
32  this->addDependentField(_var_source);
33  this->addDependentField(_tau_supg_var);
34 
35  this->setName("Variable SUPG Flux " + std::to_string(num_space_dim) + "D");
36 }
37 
38 //---------------------------------------------------------------------------//
39 template<class EvalType, class Traits, int NumSpaceDim>
40 void VariableSUPGFlux<EvalType, Traits, NumSpaceDim>::evaluateFields(
41  typename Traits::EvalData workset)
42 {
43  // Allocate space for thread-local temporaries in parallel for
44  size_t bytes;
45  if constexpr (Sacado::IsADType<scalar_type>::value)
46  {
47  const int fad_size = Kokkos::dimension_scalar(_tau_supg_var.get_view());
48  bytes = scratch_view::shmem_size(
49  _tau_supg_var.extent(1), NUM_TMPS, fad_size);
50  }
51  else
52  {
53  bytes = scratch_view::shmem_size(_tau_supg_var.extent(1), NUM_TMPS);
54  }
55 
56  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
57  workset.num_cells);
58  policy.set_scratch_size(0, Kokkos::PerTeam(bytes));
59  Kokkos::parallel_for(this->getName(), policy, *this);
60 }
61 
62 //---------------------------------------------------------------------------//
63 template<class EvalType, class Traits, int NumSpaceDim>
64 KOKKOS_INLINE_FUNCTION void
65 VariableSUPGFlux<EvalType, Traits, NumSpaceDim>::operator()(
66  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
67 {
68  const int cell = team.league_rank();
69  const int num_point = _tau_supg_var.extent(1);
70 
71  // Initialize scratch memory
72  scratch_view tmp_field;
73  if constexpr (Sacado::IsADType<scalar_type>::value)
74  {
75  const int fad_size = Kokkos::dimension_scalar(_tau_supg_var.get_view());
76  tmp_field
77  = scratch_view(team.team_shmem(), num_point, NUM_TMPS, fad_size);
78  }
79  else
80  {
81  tmp_field = scratch_view(team.team_shmem(), num_point, NUM_TMPS);
82  }
83 
84  Kokkos::parallel_for(
85  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
86  auto&& var_res = tmp_field(point, VAR_RES);
87 
88  // Compute strong residual of scalar equation
89  // (non-conservative version)
90  var_res = _dxdt_var(cell, point);
91  var_res -= _var_source(cell, point);
92 
93  for (int i = 0; i < num_space_dim; ++i)
94  {
95  var_res += _velocity[i](cell, point)
96  * _grad_var(cell, point, i);
97  }
98 
99  // Loop over cartesian components, build strong residual, and add
100  // SUPG contribution to equation
101  for (int j = 0; j < num_space_dim; ++j)
102  {
103  _var_diff_flux(cell, point, j) += _tau_supg_var(cell, point)
104  * var_res
105  * _velocity[j](cell, point);
106  }
107  });
108 }
109 
110 //---------------------------------------------------------------------------//
111 
112 } // end namespace ClosureModel
113 } // end namespace VertexCFD
114 
115 #endif // end VERTEXCFD_CLOSURE_VARIABLESUPGFLUX_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23