IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
StandardFDTDSolver.hpp
Go to the documentation of this file.
1
5
6namespace ippl {
7
18 template <typename EMField, typename SourceField, fdtd_bc boundary_conditions>
20 SourceField& source, EMField& E, EMField& B)
21 : FDTDSolverBase<EMField, SourceField, boundary_conditions>(source, E, B) {
22 initialize();
23 }
24
32 template <typename EMField, typename SourceField, fdtd_bc boundary_conditions>
34 const auto& ldom = this->layout_mp->getLocalNDIndex();
35 const int nghost = this->A_n.getNghost();
36 const auto aview = this->A_n.getView();
37 const auto anp1view = this->A_np1.getView();
38 const auto anm1view = this->A_nm1.getView();
39 const auto source_view = Maxwell<EMField, SourceField>::JN_mp->getView();
40
41 // Calculate the coefficients for the nondispersive update
42 const scalar a1 = scalar(2)
43 * (scalar(1) - Kokkos::pow(this->dt / this->hr_m[0], 2)
44 - Kokkos::pow(this->dt / this->hr_m[1], 2)
45 - Kokkos::pow(this->dt / this->hr_m[2], 2));
46 const scalar a2 = Kokkos::pow(this->dt / this->hr_m[0], 2);
47 const scalar a4 = Kokkos::pow(this->dt / this->hr_m[1], 2);
48 const scalar a6 = Kokkos::pow(this->dt / this->hr_m[2], 2);
49 const scalar a8 = Kokkos::pow(this->dt, 2);
50 Vector<uint32_t, Dim> true_nr = this->nr_m;
51 true_nr += (nghost * 2);
52 constexpr uint32_t one_if_absorbing_otherwise_0 =
53 boundary_conditions == absorbing
54 ? 1
55 : 0; // 1 if absorbing, 0 otherwise, indicates the start index of the field
56
57 // Update the field values
58 Kokkos::parallel_for(
59 "Source field update", ippl::getRangePolicy(aview, nghost),
60 KOKKOS_LAMBDA(const size_t i, const size_t j, const size_t k) {
61 // global indices
62 const uint32_t ig = i + ldom.first()[0];
63 const uint32_t jg = j + ldom.first()[1];
64 const uint32_t kg = k + ldom.first()[2];
65 // check if at a boundary of the field
66 uint32_t val =
67 uint32_t(ig == one_if_absorbing_otherwise_0)
68 + (uint32_t(jg == one_if_absorbing_otherwise_0) << 1)
69 + (uint32_t(kg == one_if_absorbing_otherwise_0) << 2)
70 + (uint32_t(ig == true_nr[0] - one_if_absorbing_otherwise_0 - 1) << 3)
71 + (uint32_t(jg == true_nr[1] - one_if_absorbing_otherwise_0 - 1) << 4)
72 + (uint32_t(kg == true_nr[2] - one_if_absorbing_otherwise_0 - 1) << 5);
73 // update the interior field values
74 if (val == 0) {
75 SourceVector_t interior = -anm1view(i, j, k) + a1 * aview(i, j, k)
76 + a2 * (aview(i + 1, j, k) + aview(i - 1, j, k))
77 + a4 * (aview(i, j + 1, k) + aview(i, j - 1, k))
78 + a6 * (aview(i, j, k + 1) + aview(i, j, k - 1))
79 + a8 * source_view(i, j, k);
80 anp1view(i, j, k) = interior;
81 }
82 });
83 Kokkos::fence();
84 this->A_np1.fillHalo();
85 this->applyBCs();
86 }
87
94 template <typename EMField, typename SourceField, fdtd_bc boundary_conditions>
96 // get layout and mesh
97 this->layout_mp = &(this->JN_mp->getLayout());
98 this->mesh_mp = &(this->JN_mp->get_mesh());
99
100 // get mesh spacing, timestep, domain, and mesh size
101 this->hr_m = this->mesh_mp->getMeshSpacing();
102 this->dt = this->hr_m[0] / 2;
103 for (unsigned int i = 0; i < Dim; ++i) {
104 this->dt = std::min(this->dt, this->hr_m[i] / 2);
105 }
106 this->domain_m = this->layout_mp->getDomain();
107 for (unsigned int i = 0; i < Dim; ++i)
108 this->nr_m[i] = this->domain_m[i].length();
109
110 // initialize fields
111 this->A_nm1.initialize(*(this->mesh_mp), *(this->layout_mp));
112 this->A_n.initialize(*(this->mesh_mp), *(this->layout_mp));
113 this->A_np1.initialize(*(this->mesh_mp), *(this->layout_mp));
114
115 // Initialize fields to zero
116 this->A_nm1 = 0.0;
117 this->A_n = 0.0;
118 this->A_np1 = 0.0;
119
120 // set the mesh domain
121 if constexpr (boundary_conditions == periodic) {
123 }
124 }
125} // namespace ippl
Definition Archive.h:20
RangePolicy< View::rank, typenameView::execution_space, PolicyArgs... >::policy_type getRangePolicy(const View &view, int shift=0)
FDTDSolverBase(SourceField &source, EMField &E, EMField &B)
SourceField * JN_mp
Definition Maxwell.h:77
typename SourceField::value_type SourceVector_t
typename EMField::value_type::value_type scalar
static constexpr unsigned Dim
virtual void step() override
Advances the simulation by one time step.
virtual void initialize() override
Initializes the solver.
StandardFDTDSolver(SourceField &source, EMField &E, EMField &B)
Constructs a StandardFDTDSolver.