diff options
author | 2019-06-18 14:03:14 -0700 | |
---|---|---|
committer | 2019-06-18 14:03:14 -0700 | |
commit | 2628876d44bbd67c17ecb8a8db61a36aea36fad0 (patch) | |
tree | 668dcf8ed4208f310021f6023c9c055a9cc3f81d /Source/Utils/WarpXUtil.cpp | |
parent | 828b516cd72d0e8cd0dd0225a2fde12aeee8dbff (diff) | |
parent | 89df8eb11ed61bd6d6f58a2e096b1eb3a132538a (diff) | |
download | WarpX-2628876d44bbd67c17ecb8a8db61a36aea36fad0.tar.gz WarpX-2628876d44bbd67c17ecb8a8db61a36aea36fad0.tar.zst WarpX-2628876d44bbd67c17ecb8a8db61a36aea36fad0.zip |
Merge branch 'dev' into update_perftest
Diffstat (limited to 'Source/Utils/WarpXUtil.cpp')
-rw-r--r-- | Source/Utils/WarpXUtil.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Source/Utils/WarpXUtil.cpp b/Source/Utils/WarpXUtil.cpp index 4a884330a..a5ea6d75a 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,43 @@ 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 ( (zmax>zmin_box && zmin<=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.; + }; + } + ); + } + } +} |