1 #ifndef VERTEXCFD_CLOSURE_EXTERNALMAGNETICFIELD_IMPL_HPP
2 #define VERTEXCFD_CLOSURE_EXTERNALMAGNETICFIELD_IMPL_HPP
4 #include "utils/VertexCFD_Utils_VectorField.hpp"
6 #include <Panzer_HierarchicParallelism.hpp>
7 #include <Panzer_Workset_Utilities.hpp>
8 #include <Teuchos_StandardParameterEntryValidators.hpp>
14 namespace ClosureModel
17 template<
class EvalType,
class Traits>
18 ExternalMagneticField<EvalType, Traits>::ExternalMagneticField(
19 const panzer::IntegrationRule& ir,
20 const Teuchos::ParameterList& user_params)
21 : _ir_degree(ir.cubature_degree)
22 , _ext_magn_type(ExtMagnType::constant)
25 if (user_params.isType<std::string>(
"External Magnetic Field Type"))
27 const auto type_validator = Teuchos::rcp(
28 new Teuchos::StringToIntegralParameterEntryValidator<ExtMagnType>(
29 Teuchos::tuple<std::string>(
"constant",
"toroidal"),
31 _ext_magn_type = type_validator->getIntegralValue(
32 user_params.get<std::string>(
"External Magnetic Field Type"));
36 if (_ext_magn_type == ExtMagnType::constant)
38 const auto ext_magn_vct = user_params.get<Teuchos::Array<double>>(
39 "External Magnetic Field Value");
41 const auto zero_array = Teuchos::Array<double>(field_size, 0.0);
42 const auto d_ext_magn_vct_dt
43 = user_params.isType<Teuchos::Array<double>>(
44 "External Magnetic Field Time Rate of "
46 ? user_params.get<Teuchos::Array<double>>(
47 "External Magnetic Field Time Rate "
51 for (
int dim = 0; dim < field_size; ++dim)
53 _ext_magn_vct[dim] = ext_magn_vct[dim];
54 _d_ext_magn_vct_dt[dim] = d_ext_magn_vct_dt[dim];
57 else if (_ext_magn_type == ExtMagnType::toroidal)
60 = user_params.get<
double>(
"Toroidal Field Magnitude");
64 Utils::addEvaluatedVectorField(
65 *
this, ir.dl_scalar, _ext_magn_field,
"external_magnetic_field_");
67 this->setName(
"External Magnetic Field");
71 template<
class EvalType,
class Traits>
72 void ExternalMagneticField<EvalType, Traits>::postRegistrationSetup(
73 typename Traits::SetupData sd, PHX::FieldManager<Traits>&)
75 _ir_index = panzer::getIntegrationRuleIndex(_ir_degree, (*sd.worksets_)[0]);
79 template<
class EvalType,
class Traits>
80 void ExternalMagneticField<EvalType, Traits>::evaluateFields(
81 typename Traits::EvalData workset)
85 _ip_coords = workset.int_rules[_ir_index]->ip_coordinates;
86 auto policy = panzer::HP::inst().teamPolicy<scalar_type, PHX::Device>(
88 Kokkos::parallel_for(this->getName(), policy, *
this);
92 template<
class EvalType,
class Traits>
93 KOKKOS_INLINE_FUNCTION
void ExternalMagneticField<EvalType, Traits>::operator()(
94 const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team)
const
96 const int cell = team.league_rank();
97 const int num_point = _ext_magn_field[0].extent(1);
100 Kokkos::parallel_for(
101 Kokkos::TeamThreadRange(team, 0, num_point), [&](
const int point) {
102 if (_ext_magn_type == ExtMagnType::constant)
104 for (
int dim = 0; dim < field_size; ++dim)
106 _ext_magn_field[dim](cell, point)
107 = _ext_magn_vct[dim] + _d_ext_magn_vct_dt[dim] * _time;
110 else if (_ext_magn_type == ExtMagnType::toroidal)
112 _ext_magn_field[0](cell, point)
113 = -_ip_coords(cell, point, 1) * _toroidal_field_magn
114 / (_ip_coords(cell, point, 0) * _ip_coords(cell, point, 0)
115 + _ip_coords(cell, point, 1)
116 * _ip_coords(cell, point, 1));
118 _ext_magn_field[1](cell, point)
119 = _ip_coords(cell, point, 0) * _toroidal_field_magn
120 / (_ip_coords(cell, point, 0) * _ip_coords(cell, point, 0)
121 + _ip_coords(cell, point, 1)
122 * _ip_coords(cell, point, 1));
124 _ext_magn_field[2](cell, point) = 0.0;
134 #endif // end VERTEXCFD_CLOSURE_EXTERNALMAGNETICFIELD_IMPL_HPP