IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
FDTDSolverBase.hpp
Go to the documentation of this file.
1//
2// Class FDTDSolverBase
3// Base class for solvers for Maxwell's equations using the FDTD method
4//
5
6namespace ippl {
7
17 template <typename EMField, typename SourceField, fdtd_bc boundary_conditions>
24
31 template <typename EMField, typename SourceField, fdtd_bc boundary_conditions>
37
42 * conditions for the fields.
43 */
44 template <typename EMField, typename SourceField, fdtd_bc boundary_conditions>
45 void
47 typename SourceField::BConds_t vector_bcs;
48 auto bcsetter_single = [&vector_bcs]<size_t Idx>(const std::index_sequence<Idx>&) {
49 vector_bcs[Idx] = std::make_shared<ippl::PeriodicFace<SourceField>>(Idx);
50 return 0;
51 };
52 auto bcsetter = [bcsetter_single]<size_t... Idx>(const std::index_sequence<Idx...>&) {
53 int x = (bcsetter_single(std::index_sequence<Idx>{}) ^ ...);
54 (void)x;
55 };
56 bcsetter(std::make_index_sequence<Dim * 2>{});
57 A_n.setFieldBC(vector_bcs);
58 A_np1.setFieldBC(vector_bcs);
59 A_nm1.setFieldBC(vector_bcs);
60 }
61
68 template <typename EMField, typename SourceField, fdtd_bc boundary_conditions>
70 // Look into this, maybe cyclic swap is better
71 Kokkos::deep_copy(this->A_nm1.getView(), this->A_n.getView());
72 Kokkos::deep_copy(this->A_n.getView(), this->A_np1.getView());
73 }
74
77 *
78 * Applies the specified boundary conditions (periodic or absorbing) to the fields.
79 */
80 template <typename EMField, typename SourceField, fdtd_bc boundary_conditions>
82 if constexpr (boundary_conditions == periodic) {
83 A_n.getFieldBC().apply(A_n);
84 A_nm1.getFieldBC().apply(A_nm1);
85 A_np1.getFieldBC().apply(A_np1);
86 } else {
88 true_nr += (A_n.getNghost() * 2);
90 bcs.apply(A_n, A_nm1, A_np1, this->dt, true_nr, layout_mp->getLocalNDIndex());
91 }
92 }
93
100 template <typename EMField, typename SourceField, fdtd_bc boundary_conditions>
102 *(Maxwell<EMField, SourceField>::En_mp) = typename EMField::value_type(0);
103 *(Maxwell<EMField, SourceField>::Bn_mp) = typename EMField::value_type(0);
104 ippl::Vector<scalar, 3> inverse_2_spacing = ippl::Vector<scalar, 3>(0.5) / hr_m;
105 const scalar idt = scalar(1.0) / dt;
106 auto A_np1 = this->A_np1.getView(), A_n = this->A_n.getView(),
107 A_nm1 = this->A_nm1.getView();
108 auto source = Maxwell<EMField, SourceField>::JN_mp->getView();
109 auto Eview = Maxwell<EMField, SourceField>::En_mp->getView();
110 auto Bview = Maxwell<EMField, SourceField>::Bn_mp->getView();
111
112 // Calculate the electric and magnetic fields
113 // Curl and grad of ippl are not used here, because we have a 4-component vector and we need
114 // it for the last three components
115 Kokkos::parallel_for(
116 this->A_n.getFieldRangePolicy(), KOKKOS_LAMBDA(size_t i, size_t j, size_t k) {
118 dAdt[0] = (A_np1(i, j, k)[1] - A_n(i, j, k)[1]) * idt;
119 dAdt[1] = (A_np1(i, j, k)[2] - A_n(i, j, k)[2]) * idt;
120 dAdt[2] = (A_np1(i, j, k)[3] - A_n(i, j, k)[3]) * idt;
121
123 (A_n(i + 1, j, k) - A_n(i - 1, j, k)) * inverse_2_spacing[0];
125 (A_n(i, j + 1, k) - A_n(i, j - 1, k)) * inverse_2_spacing[1];
127 (A_n(i, j, k + 1) - A_n(i, j, k - 1)) * inverse_2_spacing[2];
128
129 ippl::Vector<scalar, 3> grad_phi{dAdx[0], dAdy[0], dAdz[0]};
131 dAdy[3] - dAdz[2],
132 dAdz[1] - dAdx[3],
133 dAdx[2] - dAdy[1],
134 };
135 Eview(i, j, k) = -dAdt - grad_phi;
136 Bview(i, j, k) = curlA;
137 });
138 Kokkos::fence();
139 }
140
141} // namespace ippl
Definition Archive.h:20
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.
void evaluate_EB()
Evaluates the electric and magnetic fields.
void applyBCs()
Applies the boundary conditions.
Vector< int, Dim > nr_m
void setPeriodicBoundaryConditions()
Sets periodic boundary conditions.
virtual void step()=0
Steps the solver forward in time. This is a pure virtual function.
void solve() override
Solves the FDTD equations.
void timeShift()
Shifts the saved fields in time.
typename EMField::value_type::value_type scalar
FDTDSolverBase(SourceField &source, EMField &E, EMField &B)
Constructor for the FDTDSolverBase class.
void setEMFields(EMField &E, EMField &B)
Definition Maxwell.h:52
EMField * En_mp
Definition Maxwell.h:80
EMField * Bn_mp
Definition Maxwell.h:81
virtual void setSources(SourceField &four_current)
Definition Maxwell.h:45
SourceField * JN_mp
Definition Maxwell.h:77