VertexCFD  0.0-dev
VertexCFD_Closure_RADReaction_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_RADREACTION_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_RADREACTION_IMPL_HPP
3 
4 #include "utils/VertexCFD_Utils_ScalarFieldView.hpp"
5 
6 #include <Panzer_HierarchicParallelism.hpp>
7 
8 #include <string>
9 
10 namespace VertexCFD
11 {
12 namespace ClosureModel
13 {
14 //---------------------------------------------------------------------------//
15 template<class EvalType, class Traits>
16 RADReaction<EvalType, Traits>::RADReaction(
17  const panzer::IntegrationRule& ir,
18  const SpeciesProperties::ConstantSpeciesProperties& species_prop,
19  const std::string& neutron_flux_name)
20  : _num_species(species_prop.numSpecies())
21  , _neutron_flux(neutron_flux_name, ir.dl_scalar)
22  , _bateman_matrix(Kokkos::ViewAllocateWithoutInitializing("bateman_"
23  "matrix"),
24  _num_species,
25  _num_species)
26  , _mic_cross_section(Kokkos::ViewAllocateWithoutInitializing("microscopic_"
27  "cross_"
28  "section"),
29  _num_species,
30  _num_species)
31  , _build_bateman(species_prop.buildBateman())
32  , _build_transmutation(species_prop.buildTransmutationSource())
33 {
34  // Copy bateman matrix from host to device
35  if (_build_bateman)
36  {
37  auto bateman_matrix_host
38  = Kokkos::create_mirror_view(Kokkos::HostSpace{}, _bateman_matrix);
39  bateman_matrix_host = species_prop.batemanMatrix();
40  Kokkos::deep_copy(_bateman_matrix, bateman_matrix_host);
41  }
42 
43  // Copy microscopic cross-section matrix from host to device
44  if (_build_transmutation)
45  {
46  auto mic_cross_sec_host = Kokkos::create_mirror_view(
47  Kokkos::HostSpace{}, _mic_cross_section);
48  mic_cross_sec_host = species_prop.microscopicCrossSection();
49  Kokkos::deep_copy(_mic_cross_section, mic_cross_sec_host);
50  }
51 
52  // Evaluated fields
53  Utils::addEvaluatedScalarFieldView(*this,
54  ir.dl_scalar,
55  _num_species,
56  _reaction_term,
57  "REACTION_TERM_reaction_advection_"
58  "diffusion_equation_");
59 
60  // Dependent fields
61  Utils::addDependentScalarFieldView(
62  *this, ir.dl_scalar, _num_species, _species, "species_");
63 
64  if (_build_transmutation)
65  this->addDependentField(_neutron_flux);
66 
67  this->setName("RAD Equation Reaction Term");
68 }
69 
70 //---------------------------------------------------------------------------//
71 template<class EvalType, class Traits>
72 void RADReaction<EvalType, Traits>::evaluateFields(
73  typename Traits::EvalData workset)
74 {
75  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
76  workset.num_cells);
77  Kokkos::parallel_for(this->getName(), policy, *this);
78 }
79 
80 //---------------------------------------------------------------------------//
81 template<class EvalType, class Traits>
82 KOKKOS_INLINE_FUNCTION void RADReaction<EvalType, Traits>::operator()(
83  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
84 {
85  const int cell = team.league_rank();
86  const int num_point = _reaction_term[0].extent(1);
87 
88  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, 0, num_point),
89  [&](const int point) {
90  for (int num = 0; num < _num_species; ++num)
91  {
92  _reaction_term[num](cell, point) = 0.0;
93  for (int spe = 0; spe < _num_species; ++spe)
94  {
95  if (_build_bateman)
96  _reaction_term[num](cell, point)
97  += _species[spe](cell, point)
98  * _bateman_matrix(num, spe);
99 
100  if (_build_transmutation)
101  _reaction_term[num](cell, point)
102  += _species[spe](cell, point)
103  * _neutron_flux(cell, point)
104  * _mic_cross_section(num, spe);
105  }
106  }
107  });
108 }
109 
110 //---------------------------------------------------------------------------//
111 
112 } // end namespace ClosureModel
113 } // end namespace VertexCFD
114 
115 #endif // end VERTEXCFD_CLOSURE_RADREACTION_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23