VertexCFD  0.0-dev
VertexCFD_Closure_ElectricCurrentDensity_impl.hpp
1 #ifndef VERTEXCFD_CLOSURE_ELECTRICCURRENTDENSITY_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_ELECTRICCURRENTDENSITY_IMPL_HPP
3 
4 #include "utils/VertexCFD_Utils_VectorField.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, int NumSpaceDim>
16 ElectricCurrentDensity<EvalType, Traits, NumSpaceDim>::ElectricCurrentDensity(
17  const panzer::IntegrationRule& ir)
18  : _grad_electric_potential("GRAD_electric_potential", ir.dl_vector)
19  , _sigma("electrical_conductivity", ir.dl_scalar)
20 {
21  // Evaluated fields
22  Utils::addEvaluatedVectorField(*this,
23  ir.dl_scalar,
24  _electric_current_density,
25  "electric_current_density_");
26 
27  // Dependent fields
28  this->addDependentField(_grad_electric_potential);
29  this->addDependentField(_sigma);
30  Utils::addDependentVectorField(*this, ir.dl_scalar, _velocity, "velocity_");
31  Utils::addDependentVectorField(
32  *this, ir.dl_scalar, _ext_magn_field, "external_magnetic_field_");
33 
34  this->setName("Electric Potential Electric Current Density "
35  + std::to_string(num_space_dim) + "D");
36 }
37 
38 //---------------------------------------------------------------------------//
39 template<class EvalType, class Traits, int NumSpaceDim>
40 void ElectricCurrentDensity<EvalType, Traits, NumSpaceDim>::evaluateFields(
41  typename Traits::EvalData workset)
42 {
43  auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
44  workset.num_cells);
45  Kokkos::parallel_for(this->getName(), policy, *this);
46 }
47 
48 //---------------------------------------------------------------------------//
49 template<class EvalType, class Traits, int NumSpaceDim>
50 KOKKOS_INLINE_FUNCTION void
51 ElectricCurrentDensity<EvalType, Traits, NumSpaceDim>::operator()(
52  const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
53 {
54  const int cell = team.league_rank();
55  const int num_point = _electric_current_density[0].extent(1);
56 
57  Kokkos::parallel_for(
58  Kokkos::TeamThreadRange(team, 0, num_point), [&](const int point) {
59  // Electric current density: 2-D case
60  // x-component
61  _electric_current_density[0](cell, point)
62  = -_sigma(cell, point)
63  * _grad_electric_potential(cell, point, 0);
64  _electric_current_density[0](cell, point)
65  += _sigma(cell, point) * _velocity[1](cell, point)
66  * _ext_magn_field[2](cell, point);
67  // y-component
68  _electric_current_density[1](cell, point)
69  = -_sigma(cell, point)
70  * _grad_electric_potential(cell, point, 1);
71  _electric_current_density[1](cell, point)
72  += -_sigma(cell, point) * _velocity[0](cell, point)
73  * _ext_magn_field[2](cell, point);
74 
75  // Electric current density: 3-D case
76  if (num_space_dim == 3)
77  {
78  // x-component
79  _electric_current_density[0](cell, point)
80  -= _sigma(cell, point) * _velocity[2](cell, point)
81  * _ext_magn_field[1](cell, point);
82  // y-component
83  _electric_current_density[1](cell, point)
84  += _sigma(cell, point) * _velocity[2](cell, point)
85  * _ext_magn_field[0](cell, point);
86  // z-component
87  _electric_current_density[2](cell, point)
88  = -_sigma(cell, point)
89  * _grad_electric_potential(cell, point, 2);
90  _electric_current_density[2](cell, point)
91  += _sigma(cell, point)
92  * (_velocity[0](cell, point)
93  * _ext_magn_field[1](cell, point)
94  - _velocity[1](cell, point)
95  * _ext_magn_field[0](cell, point));
96  }
97  });
98 }
99 
100 //---------------------------------------------------------------------------//
101 
102 } // end namespace ClosureModel
103 } // end namespace VertexCFD
104 
105 #endif // end
106  // VERTEXCFD_CLOSURE_ELECTRICCURRENTDENSITY_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23