aboutsummaryrefslogtreecommitdiff
path: root/Source/Utils/WarpXUtil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Utils/WarpXUtil.cpp')
-rw-r--r--Source/Utils/WarpXUtil.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/Source/Utils/WarpXUtil.cpp b/Source/Utils/WarpXUtil.cpp
index 4a884330a..4ec7ebb51 100644
--- a/Source/Utils/WarpXUtil.cpp
+++ b/Source/Utils/WarpXUtil.cpp
@@ -3,6 +3,7 @@
#include <WarpXUtil.H>
#include <WarpXConst.H>
#include <AMReX_ParmParse.H>
+#include <WarpX.H>
using namespace amrex;
@@ -95,3 +96,44 @@ void ConvertLabParamsToBoost()
pp_wpx.addarr("fine_tag_hi", fine_tag_hi);
}
}
+
+/* \brief Function that sets the value of MultiFab MF to zero for z between
+ * zmin and zmax.
+ */
+void NullifyMF(amrex::MultiFab& mf, int lev, amrex::Real zmin, amrex::Real zmax){
+ BL_PROFILE("WarpX::NullifyMF()");
+#ifdef _OPENMP
+#pragma omp parallel if (Gpu::notInLaunchRegion())
+#endif
+ for(amrex::MFIter mfi(mf, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi){
+ const amrex::Box& bx = mfi.tilebox();
+ // Get box lower and upper physical z bound, and dz
+ const amrex::Real zmin_box = WarpX::LowerCorner(bx, lev)[2];
+ const amrex::Real zmax_box = WarpX::UpperCorner(bx, lev)[2];
+ amrex::Real dz = WarpX::CellSize(lev)[2];
+ // Get box lower index in the z direction
+#if (AMREX_SPACEDIM==3)
+ const int lo_ind = bx.loVect()[2];
+#else
+ const int lo_ind = bx.loVect()[1];
+#endif
+ // Check if box intersect with [zmin, zmax]
+ if ( (zmin>zmin_box && zmin<=zmax_box) ||
+ (zmax>zmin_box && zmax<=zmax_box) ){
+ Array4<Real> arr = mf[mfi].array();
+ // Set field to 0 between zmin and zmax
+ ParallelFor(bx,
+ [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept{
+#if (AMREX_SPACEDIM==3)
+ const Real z_gridpoint = zmin_box+(k-lo_ind)*dz;
+#else
+ const Real z_gridpoint = zmin_box+(j-lo_ind)*dz;
+#endif
+ if ( (z_gridpoint >= zmin) && (z_gridpoint < zmax) ) {
+ arr(i,j,k) = 0.;
+ };
+ }
+ );
+ }
+ }
+}