IPPL API Reference
Independent Parallel Particle Layer C++ API
Loading...
Searching...
No Matches
FDTDSolverBase.hpp
1//
2// Class FDTDSolverBase
3// Base class for solvers for Maxwell's equations using the FDTD method
4//
5
6namespace ippl {
7
8 template <typename EMField, typename SourceField, fdtd_bc boundary_conditions>
15
22 template <typename EMField, typename SourceField, fdtd_bc boundary_conditions>
24 step();
25 timeShift();
26 evaluate_EB();
27 }
28
35 template <typename EMField, typename SourceField, fdtd_bc boundary_conditions>
36 void
38 typename SourceField::BConds_t vector_bcs;
39 auto bcsetter_single = [&vector_bcs]<size_t Idx>(const std::index_sequence<Idx>&) {
40 vector_bcs[Idx] = std::make_shared<ippl::PeriodicFace<SourceField>>(Idx);
41 return 0;
42 };
43 auto bcsetter = [bcsetter_single]<size_t... Idx>(const std::index_sequence<Idx...>&) {
44 int x = (bcsetter_single(std::index_sequence<Idx>{}) ^ ...);
45 (void)x;
46 };
47 bcsetter(std::make_index_sequence<Dim * 2>{});
48 A_n.setFieldBC(vector_bcs);
49 A_np1.setFieldBC(vector_bcs);
50 A_nm1.setFieldBC(vector_bcs);
51 }
59 template <typename EMField, typename SourceField, fdtd_bc boundary_conditions>
61 // Look into this, maybe cyclic swap is better
62 Kokkos::deep_copy(this->A_nm1.getView(), this->A_n.getView());
63 Kokkos::deep_copy(this->A_n.getView(), this->A_np1.getView());
64 }
65
71 template <typename EMField, typename SourceField, fdtd_bc boundary_conditions>
73 if constexpr (boundary_conditions == periodic) {
74 A_n.getFieldBC().apply(A_n);
75 A_nm1.getFieldBC().apply(A_nm1);
76 A_np1.getFieldBC().apply(A_np1);
77 } else {
78 Vector<uint32_t, Dim> true_nr = nr_m;
79 true_nr += (A_n.getNghost() * 2);
81 bcs.apply(A_n, A_nm1, A_np1, this->dt, true_nr, layout_mp->getLocalNDIndex());
82 }
83 }
84
91 template <typename EMField, typename SourceField, fdtd_bc boundary_conditions>
93 *(Maxwell<EMField, SourceField>::En_mp) = typename EMField::value_type(0);
94 *(Maxwell<EMField, SourceField>::Bn_mp) = typename EMField::value_type(0);
95 ippl::Vector<scalar, 3> inverse_2_spacing = ippl::Vector<scalar, 3>(0.5) / hr_m;
96 const scalar idt = scalar(1.0) / dt;
97 auto A_np1 = this->A_np1.getView(), A_n = this->A_n.getView(),
98 A_nm1 = this->A_nm1.getView();
99 auto source = Maxwell<EMField, SourceField>::JN_mp->getView();
100 auto Eview = Maxwell<EMField, SourceField>::En_mp->getView();
101 auto Bview = Maxwell<EMField, SourceField>::Bn_mp->getView();
102
103 // Calculate the electric and magnetic fields
104 // Curl and grad of ippl are not used here, because we have a 4-component vector and we need
105 // it for the last three components
106 Kokkos::parallel_for(
107 this->A_n.getFieldRangePolicy(), KOKKOS_LAMBDA(size_t i, size_t j, size_t k) {
109 dAdt[0] = (A_n(i, j, k)[1] - A_nm1(i, j, k)[1]) * idt;
110 dAdt[1] = (A_n(i, j, k)[2] - A_nm1(i, j, k)[2]) * idt;
111 dAdt[2] = (A_n(i, j, k)[3] - A_nm1(i, j, k)[3]) * idt;
112
114 (A_n(i + 1, j, k) - A_n(i - 1, j, k)) * inverse_2_spacing[0];
116 (A_n(i, j + 1, k) - A_n(i, j - 1, k)) * inverse_2_spacing[1];
118 (A_n(i, j, k + 1) - A_n(i, j, k - 1)) * inverse_2_spacing[2];
119
120 ippl::Vector<scalar, 3> grad_phi{dAdx[0], dAdy[0], dAdz[0]};
122 dAdy[3] - dAdz[2],
123 dAdz[1] - dAdx[3],
124 dAdx[2] - dAdy[1],
125 };
126 Eview(i, j, k) = -dAdt - grad_phi;
127 Bview(i, j, k) = curlA;
128 });
129 Kokkos::fence();
130 }
131
132} // namespace ippl
void evaluate_EB()
Evaluates the electric and magnetic fields.
Definition FDTDSolverBase.hpp:92
void applyBCs()
Applies the boundary conditions.
Definition FDTDSolverBase.hpp:72
void setPeriodicBoundaryConditions()
Sets periodic boundary conditions.
Definition FDTDSolverBase.hpp:37
void solve() override
Solves the FDTD equations.
Definition FDTDSolverBase.hpp:23
void timeShift()
Shifts the saved fields in time.
Definition FDTDSolverBase.hpp:60
FDTDSolverBase(SourceField &source, EMField &E, EMField &B)
Constructor for the FDTDSolverBase class.
Definition FDTDSolverBase.hpp:9
Definition Maxwell.h:20
void setEMFields(EMField &E, EMField &B)
Definition Maxwell.h:52
virtual void setSources(SourceField &four_current)
Definition Maxwell.h:45
Definition Vector.h:23
Definition Archive.h:20
Definition AbsorbingBC.h:407
void apply(field_type &FA_n, field_type &FA_nm1, field_type &FA_np1, dt_type dt, ippl::Vector< uint32_t, 3 > true_nr, ippl::NDIndex< 3 > lDom)
Applies second-order Mur ABC to the boundaries of the field.
Definition AbsorbingBC.h:418