1 #ifndef WARPX_PEC_KERNELS_H_ 2 #define WARPX_PEC_KERNELS_H_ 7 #include <AMReX_Array.H> 8 #include <AMReX_Array4.H> 9 #include <AMReX_Config.H> 10 #include <AMReX_Extension.H> 11 #include <AMReX_GpuQualifiers.H> 12 #include <AMReX_IntVect.H> 13 #include <AMReX_REAL.H> 15 #include <AMReX_BaseFwd.H> 21 using namespace amrex;
31 AMREX_GPU_DEVICE AMREX_FORCE_INLINE
93 AMREX_GPU_DEVICE AMREX_FORCE_INLINE
95 const amrex::IntVect &dom_hi,
96 const amrex::IntVect &ijk_vec,
const int n,
97 amrex::Array4<amrex::Real>
const& Efield,
98 const amrex::IntVect& is_nodal,
99 amrex::GpuArray<int, 3>
const& fbndry_lo,
100 amrex::GpuArray<int, 3>
const& fbndry_hi )
106 amrex::IntVect ijk_mirror = ijk_vec;
107 bool OnPECBoundary =
false;
108 bool GuardCell =
false;
109 amrex::Real sign = 1._rt;
111 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
114 for (
int iside = 0; iside < 2; ++iside) {
115 const bool isPECBoundary = ( (iside == 0)
118 #if (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) 122 const bool is_tangent_to_PEC = ( (icomp == AMREX_SPACEDIM*idim)
125 const bool is_tangent_to_PEC = ( ( icomp == idim) ?
false :
true );
127 if (isPECBoundary ==
true) {
129 const int ig = ( (iside == 0)
130 ? (dom_lo[idim] - ijk_vec[idim])
131 : (ijk_vec[idim] - (dom_hi[idim] + is_nodal[idim]) ) );
133 if (is_tangent_to_PEC ==
true and is_nodal[idim] == 1) {
134 OnPECBoundary =
true;
138 ijk_mirror[idim] = ( ( iside == 0)
139 ? (dom_lo[idim] + ig)
140 : (dom_hi[idim] + is_nodal[idim] - ig));
143 if (is_tangent_to_PEC ==
true) sign *= -1._rt;
148 if (OnPECBoundary ==
true) {
150 Efield(ijk_vec,n) = 0._rt;
151 }
else if (GuardCell ==
true) {
152 Efield(ijk_vec,n) = sign * Efield(ijk_mirror,n);
209 AMREX_GPU_DEVICE AMREX_FORCE_INLINE
211 const amrex::IntVect & dom_hi,
212 const amrex::IntVect & ijk_vec,
const int n,
213 amrex::Array4<amrex::Real>
const& Bfield,
214 const amrex::IntVect & is_nodal,
215 amrex::GpuArray<int, 3>
const& fbndry_lo,
216 amrex::GpuArray<int, 3>
const& fbndry_hi )
218 amrex::IntVect ijk_mirror = ijk_vec;
219 bool OnPECBoundary =
false;
220 bool GuardCell =
false;
221 amrex::Real sign = 1._rt;
223 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
225 for (
int iside = 0; iside < 2; ++iside) {
226 const int isPECBoundary = ( (iside == 0 )
229 if (isPECBoundary ==
true) {
230 #if (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) 234 const bool is_normal_to_PEC = ( (icomp == AMREX_SPACEDIM*idim)
237 const bool is_normal_to_PEC = ( ( icomp == idim) ?
true :
false );
240 const int ig = ( (iside == 0)
241 ? (dom_lo[idim] - ijk_vec[idim])
242 : (ijk_vec[idim] - (dom_hi[idim] + is_nodal[idim]) ) );
245 if (is_normal_to_PEC ==
true and is_nodal[idim]==1) {
246 OnPECBoundary =
true;
248 }
else if ( ig > 0) {
251 ijk_mirror[idim] = ( (iside == 0)
252 ? (dom_lo[idim] + ig)
253 : (dom_hi[idim] + is_nodal[idim] - ig));
256 if (is_normal_to_PEC ==
true) sign *= -1._rt;
262 if (OnPECBoundary ==
true) {
264 Bfield(ijk_vec,n) = 0._rt;
265 }
else if (GuardCell ==
true) {
268 Bfield(ijk_vec,n) = sign * Bfield(ijk_mirror,n);
283 void ApplyPECtoEfield ( std::array<std::unique_ptr<amrex::MultiFab>, 3>& Efield,
294 void ApplyPECtoBfield ( std::array<std::unique_ptr<amrex::MultiFab>, 3>& Bfield,
298 #endif // WarpX_PEC_KERNELS_H_ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void SetBfieldOnPEC(const int icomp, const amrex::IntVect &dom_lo, const amrex::IntVect &dom_hi, const amrex::IntVect &ijk_vec, const int n, amrex::Array4< amrex::Real > const &Bfield, const amrex::IntVect &is_nodal, amrex::GpuArray< int, 3 > const &fbndry_lo, amrex::GpuArray< int, 3 > const &fbndry_hi)
Sets the magnetic field value normal to the PEC boundary to zero. The tangential (and normal) field v...
Definition: WarpX_PEC.H:210
bool isAnyBoundaryPEC()
Definition: WarpX_PEC.cpp:18
void ApplyPECtoBfield(std::array< std::unique_ptr< amrex::MultiFab >, 3 > &Bfield, const int lev, PatchType patch_type)
Sets the normal component of the magnetic field at the PEC boundary to zero. The guard cell values ar...
Definition: WarpX_PEC.cpp:108
perfect electric conductor (PEC) with E_tangential=0
Definition: WarpXAlgorithmSelection.H:103
int n
Definition: run_libensemble_on_warpx.py:68
Definition: WarpX_PEC.H:20
void ApplyPECtoEfield(std::array< std::unique_ptr< amrex::MultiFab >, 3 > &Efield, const int lev, PatchType patch_type)
Sets the tangential electric field at the PEC boundary to zero. The guard cell values are set equal a...
Definition: WarpX_PEC.cpp:27
PatchType
Definition: WarpX.H:71
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void SetEfieldOnPEC(const int icomp, const amrex::IntVect &dom_lo, const amrex::IntVect &dom_hi, const amrex::IntVect &ijk_vec, const int n, amrex::Array4< amrex::Real > const &Efield, const amrex::IntVect &is_nodal, amrex::GpuArray< int, 3 > const &fbndry_lo, amrex::GpuArray< int, 3 > const &fbndry_hi)
Sets the electric field value tangential to the PEC boundary to zero. The tangential Efield component...
Definition: WarpX_PEC.H:94
AMREX_GPU_DEVICE AMREX_FORCE_INLINE bool is_boundary_PEC(amrex::GpuArray< int, 3 > const &fboundary, int dir)
Determines if the field boundary condition stored in fboundary is PEC in direction, dir, is PEC.
Definition: WarpX_PEC.H:32
Definition: BreitWheelerEngineWrapper.H:35