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