From f96dde8721bc1e5d71084d864fa674c1eac9bf47 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Wed, 17 Jul 2019 13:31:18 -0700 Subject: replace FieldGather by FieldGatherFortran to keep old version --- Source/Particles/PhysicalParticleContainer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index d47a7b220..24a8904e9 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1055,9 +1055,9 @@ PhysicalParticleContainer::EvolveES (const Vector& dx = WarpX::CellSize(lev); -- cgit v1.2.3 From 8430b823965088a3f67efdbb7c99f71c2cda7d31 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Wed, 17 Jul 2019 13:40:29 -0700 Subject: field gather function in PPC --- Source/Particles/PhysicalParticleContainer.H | 20 +++ Source/Particles/PhysicalParticleContainer.cpp | 193 +++++++++++++++++-------- 2 files changed, 156 insertions(+), 57 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index 25d79c8fd..ec9d7f98b 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -39,6 +39,26 @@ public: const amrex::MultiFab& By, const amrex::MultiFab& Bz) final; + void FieldGather(WarpXParIter& pti, + RealVector& Exp, + RealVector& Eyp, + RealVector& Ezp, + RealVector& Bxp, + RealVector& Byp, + RealVector& Bzp, + amrex::FArrayBox const * exfab, + amrex::FArrayBox const * eyfab, + amrex::FArrayBox const * ezfab, + amrex::FArrayBox const * bxfab, + amrex::FArrayBox const * byfab, + amrex::FArrayBox const * bzfab, + const int ngE, const int e_is_nodal, + const long offset, + const long np_to_gather, + int thread_num, + int lev, + int depos_lev); + virtual void Evolve (int lev, const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 24a8904e9..e46fa0560 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -6,7 +6,7 @@ #include #include #include - +#include using namespace amrex; @@ -1395,38 +1395,16 @@ PhysicalParticleContainer::Evolve (int lev, if (! do_not_push) { + const long np_gather = (cEx) ? nfine_gather : np; + + int e_is_nodal = Ex.is_nodal() and Ey.is_nodal() and Ez.is_nodal(); + // // Field Gather of Aux Data (i.e., the full solution) // - const int ll4symtry = false; - long lvect_fieldgathe = 64; - - const std::array& xyzmin_grid = WarpX::LowerCorner(box, lev); - const int* ixyzmin_grid = box.loVect(); - - const long np_gather = (cEx) ? nfine_gather : np; - - BL_PROFILE_VAR_START(blp_pxr_fg); - - warpx_geteb_energy_conserving( - &np_gather, - m_xp[thread_num].dataPtr(), - m_yp[thread_num].dataPtr(), - m_zp[thread_num].dataPtr(), - Exp.dataPtr(),Eyp.dataPtr(),Ezp.dataPtr(), - Bxp.dataPtr(),Byp.dataPtr(),Bzp.dataPtr(), - ixyzmin_grid, - &xyzmin_grid[0], &xyzmin_grid[1], &xyzmin_grid[2], - &dx[0], &dx[1], &dx[2], - &WarpX::nox, &WarpX::noy, &WarpX::noz, - BL_TO_FORTRAN_ANYD(*exfab), - BL_TO_FORTRAN_ANYD(*eyfab), - BL_TO_FORTRAN_ANYD(*ezfab), - BL_TO_FORTRAN_ANYD(*bxfab), - BL_TO_FORTRAN_ANYD(*byfab), - BL_TO_FORTRAN_ANYD(*bzfab), - &ll4symtry, &WarpX::l_lower_order_in_v, &WarpX::do_nodal, - &lvect_fieldgathe, &WarpX::field_gathering_algo); + FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, + exfab, eyfab, ezfab, bxfab, byfab, bzfab, + Ex.nGrow(), e_is_nodal, 0, np_gather, thread_num, lev, lev); if (np_gather < np) { @@ -1435,13 +1413,14 @@ PhysicalParticleContainer::Evolve (int lev, const std::array& cxyzmin_grid = WarpX::LowerCorner(cbox, lev-1); const int* cixyzmin_grid = cbox.loVect(); - const FArrayBox* cexfab = &(*cEx)[pti]; - const FArrayBox* ceyfab = &(*cEy)[pti]; - const FArrayBox* cezfab = &(*cEz)[pti]; - const FArrayBox* cbxfab = &(*cBx)[pti]; - const FArrayBox* cbyfab = &(*cBy)[pti]; - const FArrayBox* cbzfab = &(*cBz)[pti]; - + // Data on the grid + FArrayBox const* cexfab = &(*cEx)[pti]; + FArrayBox const* ceyfab = &(*cEy)[pti]; + FArrayBox const* cezfab = &(*cEz)[pti]; + FArrayBox const* cbxfab = &(*cBx)[pti]; + FArrayBox const* cbyfab = &(*cBy)[pti]; + FArrayBox const* cbzfab = &(*cBz)[pti]; + if (WarpX::use_fdtd_nci_corr) { #if (AMREX_SPACEDIM == 2) @@ -1494,26 +1473,13 @@ PhysicalParticleContainer::Evolve (int lev, #endif } - long ncrse = np - nfine_gather; - warpx_geteb_energy_conserving( - &ncrse, - m_xp[thread_num].dataPtr()+nfine_gather, - m_yp[thread_num].dataPtr()+nfine_gather, - m_zp[thread_num].dataPtr()+nfine_gather, - Exp.dataPtr()+nfine_gather, Eyp.dataPtr()+nfine_gather, Ezp.dataPtr()+nfine_gather, - Bxp.dataPtr()+nfine_gather, Byp.dataPtr()+nfine_gather, Bzp.dataPtr()+nfine_gather, - cixyzmin_grid, - &cxyzmin_grid[0], &cxyzmin_grid[1], &cxyzmin_grid[2], - &cdx[0], &cdx[1], &cdx[2], - &WarpX::nox, &WarpX::noy, &WarpX::noz, - BL_TO_FORTRAN_ANYD(*cexfab), - BL_TO_FORTRAN_ANYD(*ceyfab), - BL_TO_FORTRAN_ANYD(*cezfab), - BL_TO_FORTRAN_ANYD(*cbxfab), - BL_TO_FORTRAN_ANYD(*cbyfab), - BL_TO_FORTRAN_ANYD(*cbzfab), - &ll4symtry, &WarpX::l_lower_order_in_v, &WarpX::do_nodal, - &lvect_fieldgathe, &WarpX::field_gathering_algo); + e_is_nodal = cEx->is_nodal() and cEy->is_nodal() and cEz->is_nodal(); + FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, + cexfab, ceyfab, cezfab, + cbxfab, cbyfab, cbzfab, + cEx->nGrow(), e_is_nodal, + nfine_gather, np-nfine_gather, + thread_num, lev, lev-1); } BL_PROFILE_VAR_STOP(blp_pxr_fg); @@ -2112,3 +2078,116 @@ PhysicalParticleContainer::ContinuousInjection(const RealBox& injection_box) const int lev=0; AddPlasma(lev, injection_box); } + +void +PhysicalParticleContainer::FieldGather(WarpXParIter& pti, + RealVector& Exp, + RealVector& Eyp, + RealVector& Ezp, + RealVector& Bxp, + RealVector& Byp, + RealVector& Bzp, + FArrayBox const * exfab, + FArrayBox const * eyfab, + FArrayBox const * ezfab, + FArrayBox const * bxfab, + FArrayBox const * byfab, + FArrayBox const * bzfab, + const int ngE, const int e_is_nodal, + const long offset, + const long np_to_gather, + int thread_num, + int lev, + int gather_lev) +{ + AMREX_ALWAYS_ASSERT_WITH_MESSAGE((gather_lev==(lev-1)) || + (gather_lev==(lev )), + "Gather buffers only work for lev-1"); + + // If no particles, do not do anything + if (np_to_gather == 0) return; + + const std::array& dx = WarpX::CellSize(std::max(gather_lev,0)); + const Real stagger_shift = e_is_nodal ? 0.0 : 0.5; + + // Get box =from which field is gathered. + Box box; + if (lev == gather_lev) { + box = pti.tilebox(); + } else { + const IntVect& ref_ratio = WarpX::RefRatio(gather_lev); + box = amrex::coarsen(pti.tilebox(),ref_ratio); + } + + box.grow(ngE); + + const Array4& ex_arr = exfab->array(); + const Array4& ey_arr = eyfab->array(); + const Array4& ez_arr = ezfab->array(); + const Array4& bx_arr = bxfab->array(); + const Array4& by_arr = byfab->array(); + const Array4& bz_arr = bzfab->array(); + + const Real * const AMREX_RESTRICT xp = m_xp[thread_num].dataPtr() + offset; + const Real * const AMREX_RESTRICT zp = m_zp[thread_num].dataPtr() + offset; + const Real * const AMREX_RESTRICT yp = m_yp[thread_num].dataPtr() + offset; + + // Lower corner of tile box physical domain + const std::array& xyzmin = WarpX::LowerCorner(box, gather_lev); + + const Dim3 lo = lbound(box); + + if (WarpX::l_lower_order_in_v){ + if (WarpX::nox == 1){ + doGatherShapeN<1,1>(xp, yp, zp, + Exp.dataPtr() + offset, Eyp.dataPtr() + offset, + Ezp.dataPtr() + offset, Bxp.dataPtr() + offset, + Byp.dataPtr() + offset, Bzp.dataPtr() + offset, + ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, + np_to_gather, dx, + xyzmin, lo, stagger_shift); + } else if (WarpX::nox == 2){ + doGatherShapeN<2,1>(xp, yp, zp, + Exp.dataPtr() + offset, Eyp.dataPtr() + offset, + Ezp.dataPtr() + offset, Bxp.dataPtr() + offset, + Byp.dataPtr() + offset, Bzp.dataPtr() + offset, + ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, + np_to_gather, dx, + xyzmin, lo, stagger_shift); + } else if (WarpX::nox == 3){ + doGatherShapeN<3,1>(xp, yp, zp, + Exp.dataPtr() + offset, Eyp.dataPtr() + offset, + Ezp.dataPtr() + offset, Bxp.dataPtr() + offset, + Byp.dataPtr() + offset, Bzp.dataPtr() + offset, + ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, + np_to_gather, dx, + xyzmin, lo, stagger_shift); + } + } else { + if (WarpX::nox == 1){ + doGatherShapeN<1,0>(xp, yp, zp, + Exp.dataPtr() + offset, Eyp.dataPtr() + offset, + Ezp.dataPtr() + offset, Bxp.dataPtr() + offset, + Byp.dataPtr() + offset, Bzp.dataPtr() + offset, + ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, + np_to_gather, dx, + xyzmin, lo, stagger_shift); + } else if (WarpX::nox == 2){ + doGatherShapeN<2,0>(xp, yp, zp, + Exp.dataPtr() + offset, Eyp.dataPtr() + offset, + Ezp.dataPtr() + offset, Bxp.dataPtr() + offset, + Byp.dataPtr() + offset, Bzp.dataPtr() + offset, + ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, + np_to_gather, dx, + xyzmin, lo, stagger_shift); + } else if (WarpX::nox == 3){ + doGatherShapeN<3,0>(xp, yp, zp, + Exp.dataPtr() + offset, Eyp.dataPtr() + offset, + Ezp.dataPtr() + offset, Bxp.dataPtr() + offset, + Byp.dataPtr() + offset, Bzp.dataPtr() + offset, + ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, + np_to_gather, dx, + xyzmin, lo, stagger_shift); + } + } +} -- cgit v1.2.3 From d0f799ada37b37245b884f064989f0f498b8dc7c Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Wed, 17 Jul 2019 14:05:40 -0700 Subject: docstring for FieldGether function --- Source/Particles/PhysicalParticleContainer.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index e46fa0560..0e1204dc4 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1473,6 +1473,7 @@ PhysicalParticleContainer::Evolve (int lev, #endif } + // Field gather for particles in gather buffers e_is_nodal = cEx->is_nodal() and cEy->is_nodal() and cEz->is_nodal(); FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, cexfab, ceyfab, cezfab, @@ -2079,6 +2080,19 @@ PhysicalParticleContainer::ContinuousInjection(const RealBox& injection_box) AddPlasma(lev, injection_box); } +/* \brief Gather fields from FArrayBox exfab, eyfab, ezfab, bxfab, byfab, + * bzfab into arrays of fields on particles Exp, Eyp, Ezp, Bxp, Byp, Bzp. + * \param Exp-Bzp: fields on particles. + * \param exfab-bzfab: FAB of electric and magnetic fields for particles in pti + * \param ngE: number of guard cells for E + * \param e_is_nodal: 0 if E is staggered, 1 if E is nodal + * \param offset: index of first particle for which fields are gathered + * \param np_to_gather: number of particles onto which fields are gathered + * \param thread_num: if using OpenMP, thread number + * \param lev: level on which particles are located + * \param gather_lev: level from which particles gather fields (lev-1) for + particles in buffers. + */ void PhysicalParticleContainer::FieldGather(WarpXParIter& pti, RealVector& Exp, -- cgit v1.2.3 From a9bf7c5d24596d88e4c96e9ae5d2b5efce694b51 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Wed, 17 Jul 2019 14:30:08 -0700 Subject: use old version when running rz --- Source/Particles/PhysicalParticleContainer.cpp | 51 ++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 0e1204dc4..3f9e8da67 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1402,9 +1402,36 @@ PhysicalParticleContainer::Evolve (int lev, // // Field Gather of Aux Data (i.e., the full solution) // + BL_PROFILE_VAR_START(blp_pxr_fg); +#ifdef WARPX_RZ + const int ll4symtry = false; + long lvect_fieldgathe = 64; + const std::array& xyzmin_grid = WarpX::LowerCorner(box, lev); + const int* ixyzmin_grid = box.loVect(); + warpx_geteb_energy_conserving( + &np_gather, + m_xp[thread_num].dataPtr(), + m_yp[thread_num].dataPtr(), + m_zp[thread_num].dataPtr(), + Exp.dataPtr(),Eyp.dataPtr(),Ezp.dataPtr(), + Bxp.dataPtr(),Byp.dataPtr(),Bzp.dataPtr(), + ixyzmin_grid, + &xyzmin_grid[0], &xyzmin_grid[1], &xyzmin_grid[2], + &dx[0], &dx[1], &dx[2], + &WarpX::nox, &WarpX::noy, &WarpX::noz, + BL_TO_FORTRAN_ANYD(*exfab), + BL_TO_FORTRAN_ANYD(*eyfab), + BL_TO_FORTRAN_ANYD(*ezfab), + BL_TO_FORTRAN_ANYD(*bxfab), + BL_TO_FORTRAN_ANYD(*byfab), + BL_TO_FORTRAN_ANYD(*bzfab), + &ll4symtry, &WarpX::l_lower_order_in_v, &WarpX::do_nodal, + &lvect_fieldgathe, &WarpX::field_gathering_algo); +#else FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, exfab, eyfab, ezfab, bxfab, byfab, bzfab, Ex.nGrow(), e_is_nodal, 0, np_gather, thread_num, lev, lev); +#endif if (np_gather < np) { @@ -1474,6 +1501,29 @@ PhysicalParticleContainer::Evolve (int lev, } // Field gather for particles in gather buffers +#ifdef WARPX_RZ + + long ncrse = np - nfine_gather; + warpx_geteb_energy_conserving( + &ncrse, + m_xp[thread_num].dataPtr()+nfine_gather, + m_yp[thread_num].dataPtr()+nfine_gather, + m_zp[thread_num].dataPtr()+nfine_gather, + Exp.dataPtr()+nfine_gather, Eyp.dataPtr()+nfine_gather, Ezp.dataPtr()+nfine_gather, + Bxp.dataPtr()+nfine_gather, Byp.dataPtr()+nfine_gather, Bzp.dataPtr()+nfine_gather, + cixyzmin_grid, + &cxyzmin_grid[0], &cxyzmin_grid[1], &cxyzmin_grid[2], + &cdx[0], &cdx[1], &cdx[2], + &WarpX::nox, &WarpX::noy, &WarpX::noz, + BL_TO_FORTRAN_ANYD(*cexfab), + BL_TO_FORTRAN_ANYD(*ceyfab), + BL_TO_FORTRAN_ANYD(*cezfab), + BL_TO_FORTRAN_ANYD(*cbxfab), + BL_TO_FORTRAN_ANYD(*cbyfab), + BL_TO_FORTRAN_ANYD(*cbzfab), + &ll4symtry, &WarpX::l_lower_order_in_v, &WarpX::do_nodal, + &lvect_fieldgathe, &WarpX::field_gathering_algo);# +else e_is_nodal = cEx->is_nodal() and cEy->is_nodal() and cEz->is_nodal(); FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, cexfab, ceyfab, cezfab, @@ -1481,6 +1531,7 @@ PhysicalParticleContainer::Evolve (int lev, cEx->nGrow(), e_is_nodal, nfine_gather, np-nfine_gather, thread_num, lev, lev-1); +#endif } BL_PROFILE_VAR_STOP(blp_pxr_fg); -- cgit v1.2.3 From e44075f29c45398a09a72848d8592b0a80fee06d Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Wed, 17 Jul 2019 14:36:45 -0700 Subject: minor fix. Now RZ should test passes --- Source/Particles/PhysicalParticleContainer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 3f9e8da67..357a187fd 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1522,8 +1522,8 @@ PhysicalParticleContainer::Evolve (int lev, BL_TO_FORTRAN_ANYD(*cbyfab), BL_TO_FORTRAN_ANYD(*cbzfab), &ll4symtry, &WarpX::l_lower_order_in_v, &WarpX::do_nodal, - &lvect_fieldgathe, &WarpX::field_gathering_algo);# -else + &lvect_fieldgathe, &WarpX::field_gathering_algo); +#else e_is_nodal = cEx->is_nodal() and cEy->is_nodal() and cEz->is_nodal(); FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, cexfab, ceyfab, cezfab, -- cgit v1.2.3 From 571aa14bb468a7f51fc664ef8f50f29c5397b97a Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Wed, 24 Jul 2019 14:37:29 -0700 Subject: add some more comments --- Source/Particles/PhysicalParticleContainer.cpp | 57 ++++++++++++++------------ 1 file changed, 31 insertions(+), 26 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 357a187fd..ec54305bb 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -2171,11 +2171,13 @@ PhysicalParticleContainer::FieldGather(WarpXParIter& pti, // If no particles, do not do anything if (np_to_gather == 0) return; - + // Get cell size on gather_lev const std::array& dx = WarpX::CellSize(std::max(gather_lev,0)); + // Set staggering shift depending on e_is_nodal const Real stagger_shift = e_is_nodal ? 0.0 : 0.5; - // Get box =from which field is gathered. + // Get box from which field is gathered. + // If not gathering from the finest level, the box is coarsened. Box box; if (lev == gather_lev) { box = pti.tilebox(); @@ -2184,6 +2186,7 @@ PhysicalParticleContainer::FieldGather(WarpXParIter& pti, box = amrex::coarsen(pti.tilebox(),ref_ratio); } + // Add guard cells to the box. box.grow(ngE); const Array4& ex_arr = exfab->array(); @@ -2202,55 +2205,57 @@ PhysicalParticleContainer::FieldGather(WarpXParIter& pti, const Dim3 lo = lbound(box); + // Depending on l_lower_in_v and WarpX::nox, call + // different versions of template function doGatherShapeN if (WarpX::l_lower_order_in_v){ if (WarpX::nox == 1){ - doGatherShapeN<1,1>(xp, yp, zp, - Exp.dataPtr() + offset, Eyp.dataPtr() + offset, + doGatherShapeN<1,1>(xp, yp, zp, + Exp.dataPtr() + offset, Eyp.dataPtr() + offset, Ezp.dataPtr() + offset, Bxp.dataPtr() + offset, - Byp.dataPtr() + offset, Bzp.dataPtr() + offset, - ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, + Byp.dataPtr() + offset, Bzp.dataPtr() + offset, + ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, np_to_gather, dx, xyzmin, lo, stagger_shift); } else if (WarpX::nox == 2){ - doGatherShapeN<2,1>(xp, yp, zp, - Exp.dataPtr() + offset, Eyp.dataPtr() + offset, + doGatherShapeN<2,1>(xp, yp, zp, + Exp.dataPtr() + offset, Eyp.dataPtr() + offset, Ezp.dataPtr() + offset, Bxp.dataPtr() + offset, - Byp.dataPtr() + offset, Bzp.dataPtr() + offset, - ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, + Byp.dataPtr() + offset, Bzp.dataPtr() + offset, + ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, np_to_gather, dx, xyzmin, lo, stagger_shift); } else if (WarpX::nox == 3){ - doGatherShapeN<3,1>(xp, yp, zp, - Exp.dataPtr() + offset, Eyp.dataPtr() + offset, + doGatherShapeN<3,1>(xp, yp, zp, + Exp.dataPtr() + offset, Eyp.dataPtr() + offset, Ezp.dataPtr() + offset, Bxp.dataPtr() + offset, - Byp.dataPtr() + offset, Bzp.dataPtr() + offset, - ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, + Byp.dataPtr() + offset, Bzp.dataPtr() + offset, + ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, np_to_gather, dx, xyzmin, lo, stagger_shift); } } else { if (WarpX::nox == 1){ - doGatherShapeN<1,0>(xp, yp, zp, - Exp.dataPtr() + offset, Eyp.dataPtr() + offset, + doGatherShapeN<1,0>(xp, yp, zp, + Exp.dataPtr() + offset, Eyp.dataPtr() + offset, Ezp.dataPtr() + offset, Bxp.dataPtr() + offset, - Byp.dataPtr() + offset, Bzp.dataPtr() + offset, - ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, + Byp.dataPtr() + offset, Bzp.dataPtr() + offset, + ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, np_to_gather, dx, xyzmin, lo, stagger_shift); } else if (WarpX::nox == 2){ - doGatherShapeN<2,0>(xp, yp, zp, - Exp.dataPtr() + offset, Eyp.dataPtr() + offset, + doGatherShapeN<2,0>(xp, yp, zp, + Exp.dataPtr() + offset, Eyp.dataPtr() + offset, Ezp.dataPtr() + offset, Bxp.dataPtr() + offset, - Byp.dataPtr() + offset, Bzp.dataPtr() + offset, - ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, + Byp.dataPtr() + offset, Bzp.dataPtr() + offset, + ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, np_to_gather, dx, xyzmin, lo, stagger_shift); } else if (WarpX::nox == 3){ - doGatherShapeN<3,0>(xp, yp, zp, - Exp.dataPtr() + offset, Eyp.dataPtr() + offset, + doGatherShapeN<3,0>(xp, yp, zp, + Exp.dataPtr() + offset, Eyp.dataPtr() + offset, Ezp.dataPtr() + offset, Bxp.dataPtr() + offset, - Byp.dataPtr() + offset, Bzp.dataPtr() + offset, - ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, + Byp.dataPtr() + offset, Bzp.dataPtr() + offset, + ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, np_to_gather, dx, xyzmin, lo, stagger_shift); } -- cgit v1.2.3 From c51759f954fc58b15efeeb492e56d1f58ce6b892 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Wed, 24 Jul 2019 14:40:27 -0700 Subject: use Weiqun convention for function definition --- Source/Particles/MultiParticleContainer.cpp | 2 +- Source/Particles/PhysicalParticleContainer.H | 56 +++++++++++++------------- Source/Particles/PhysicalParticleContainer.cpp | 38 ++++++++--------- 3 files changed, 48 insertions(+), 48 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index ab4400dad..f9d29e254 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -331,7 +331,7 @@ MultiParticleContainer::RedistributeLocal (const int num_ghost) } Vector -MultiParticleContainer::NumberOfParticlesInGrid(int lev) const +MultiParticleContainer::NumberOfParticlesInGrid (int lev) const { const bool only_valid=true, only_local=true; Vector r = allcontainers[0]->NumberOfParticlesInGrid(lev,only_valid,only_local); diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index ec9d7f98b..eebc9b55d 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -27,37 +27,37 @@ public: const amrex::Vector > > >& masks) override; virtual void EvolveES (const amrex::Vector, 3> >& E, - amrex::Vector >& rho, + amrex::Vector >& rho, amrex::Real t, amrex::Real dt) override; #endif // WARPX_DO_ELECTROSTATIC - virtual void FieldGatherFortran(int lev, - const amrex::MultiFab& Ex, - const amrex::MultiFab& Ey, - const amrex::MultiFab& Ez, - const amrex::MultiFab& Bx, - const amrex::MultiFab& By, - const amrex::MultiFab& Bz) final; - - void FieldGather(WarpXParIter& pti, - RealVector& Exp, - RealVector& Eyp, - RealVector& Ezp, - RealVector& Bxp, - RealVector& Byp, - RealVector& Bzp, - amrex::FArrayBox const * exfab, - amrex::FArrayBox const * eyfab, - amrex::FArrayBox const * ezfab, - amrex::FArrayBox const * bxfab, - amrex::FArrayBox const * byfab, - amrex::FArrayBox const * bzfab, - const int ngE, const int e_is_nodal, - const long offset, - const long np_to_gather, - int thread_num, - int lev, - int depos_lev); + virtual void FieldGatherFortran (int lev, + const amrex::MultiFab& Ex, + const amrex::MultiFab& Ey, + const amrex::MultiFab& Ez, + const amrex::MultiFab& Bx, + const amrex::MultiFab& By, + const amrex::MultiFab& Bz) final; + + void FieldGather (WarpXParIter& pti, + RealVector& Exp, + RealVector& Eyp, + RealVector& Ezp, + RealVector& Bxp, + RealVector& Byp, + RealVector& Bzp, + amrex::FArrayBox const * exfab, + amrex::FArrayBox const * eyfab, + amrex::FArrayBox const * ezfab, + amrex::FArrayBox const * bxfab, + amrex::FArrayBox const * byfab, + amrex::FArrayBox const * bzfab, + const int ngE, const int e_is_nodal, + const long offset, + const long np_to_gather, + int thread_num, + int lev, + int depos_lev); virtual void Evolve (int lev, const amrex::MultiFab& Ex, diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index ec54305bb..b98797b56 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -2145,25 +2145,25 @@ PhysicalParticleContainer::ContinuousInjection(const RealBox& injection_box) particles in buffers. */ void -PhysicalParticleContainer::FieldGather(WarpXParIter& pti, - RealVector& Exp, - RealVector& Eyp, - RealVector& Ezp, - RealVector& Bxp, - RealVector& Byp, - RealVector& Bzp, - FArrayBox const * exfab, - FArrayBox const * eyfab, - FArrayBox const * ezfab, - FArrayBox const * bxfab, - FArrayBox const * byfab, - FArrayBox const * bzfab, - const int ngE, const int e_is_nodal, - const long offset, - const long np_to_gather, - int thread_num, - int lev, - int gather_lev) +PhysicalParticleContainer::FieldGather (WarpXParIter& pti, + RealVector& Exp, + RealVector& Eyp, + RealVector& Ezp, + RealVector& Bxp, + RealVector& Byp, + RealVector& Bzp, + FArrayBox const * exfab, + FArrayBox const * eyfab, + FArrayBox const * ezfab, + FArrayBox const * bxfab, + FArrayBox const * byfab, + FArrayBox const * bzfab, + const int ngE, const int e_is_nodal, + const long offset, + const long np_to_gather, + int thread_num, + int lev, + int gather_lev) { AMREX_ALWAYS_ASSERT_WITH_MESSAGE((gather_lev==(lev-1)) || (gather_lev==(lev )), -- cgit v1.2.3 From 1b67c15a76868332487c203562ab3e824d2f2e65 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Fri, 26 Jul 2019 14:05:14 -0700 Subject: get rid of Fortran field gather except for RZ --- Source/Evolve/WarpXEvolveEM.cpp | 16 ++++++++-------- Source/Particles/MultiParticleContainer.H | 7 ++++--- Source/Particles/MultiParticleContainer.cpp | 9 +++++---- Source/Particles/PhysicalParticleContainer.H | 14 +++++++------- Source/Particles/PhysicalParticleContainer.cpp | 24 +++++++++++++++++------- Source/Particles/WarpXParticleContainer.H | 7 ++++--- 6 files changed, 45 insertions(+), 32 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index f1f7c698c..32a4747db 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -189,9 +189,9 @@ WarpX::EvolveEM (int numsteps) UpdateAuxilaryData(); for (int lev = 0; lev <= finest_level; ++lev) { - mypc->FieldGatherFortran(lev, - *Efield_aux[lev][0],*Efield_aux[lev][1],*Efield_aux[lev][2], - *Bfield_aux[lev][0],*Bfield_aux[lev][1],*Bfield_aux[lev][2]); + mypc->FieldGather(lev, + *Efield_aux[lev][0],*Efield_aux[lev][1],*Efield_aux[lev][2], + *Bfield_aux[lev][0],*Bfield_aux[lev][1],*Bfield_aux[lev][2]); } last_plot_file_step = step+1; @@ -241,11 +241,11 @@ WarpX::EvolveEM (int numsteps) UpdateAuxilaryData(); for (int lev = 0; lev <= finest_level; ++lev) { - mypc->FieldGatherFortran(lev, - *Efield_aux[lev][0],*Efield_aux[lev][1], - *Efield_aux[lev][2], - *Bfield_aux[lev][0],*Bfield_aux[lev][1], - *Bfield_aux[lev][2]); + mypc->FieldGather(lev, + *Efield_aux[lev][0],*Efield_aux[lev][1], + *Efield_aux[lev][2], + *Bfield_aux[lev][0],*Bfield_aux[lev][1], + *Bfield_aux[lev][2]); } if (write_plot_file) diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 76e3c44bc..7c9ede411 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -84,9 +84,10 @@ public: /// Performs the field gather operation using the input fields E and B, for all the species /// in the MultiParticleContainer. This is the electromagnetic version of the field gather. /// - void FieldGatherFortran (int lev, - const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, const amrex::MultiFab& Ez, - const amrex::MultiFab& Bx, const amrex::MultiFab& By, const amrex::MultiFab& Bz); + void FieldGather (int lev, + const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, + const amrex::MultiFab& Ez, const amrex::MultiFab& Bx, + const amrex::MultiFab& By, const amrex::MultiFab& Bz); /// /// This evolves all the particles by one PIC time step, including current deposition, the diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index f9d29e254..beb9de207 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -239,12 +239,13 @@ MultiParticleContainer::sumParticleCharge (bool local) #endif // WARPX_DO_ELECTROSTATIC void -MultiParticleContainer::FieldGatherFortran (int lev, - const MultiFab& Ex, const MultiFab& Ey, const MultiFab& Ez, - const MultiFab& Bx, const MultiFab& By, const MultiFab& Bz) +MultiParticleContainer::FieldGather (int lev, + const MultiFab& Ex, const MultiFab& Ey, + const MultiFab& Ez, const MultiFab& Bx, + const MultiFab& By, const MultiFab& Bz) { for (auto& pc : allcontainers) { - pc->FieldGatherFortran(lev, Ex, Ey, Ez, Bx, By, Bz); + pc->FieldGather(lev, Ex, Ey, Ez, Bx, By, Bz); } } diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index eebc9b55d..33572c87d 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -31,13 +31,13 @@ public: amrex::Real t, amrex::Real dt) override; #endif // WARPX_DO_ELECTROSTATIC - virtual void FieldGatherFortran (int lev, - const amrex::MultiFab& Ex, - const amrex::MultiFab& Ey, - const amrex::MultiFab& Ez, - const amrex::MultiFab& Bx, - const amrex::MultiFab& By, - const amrex::MultiFab& Bz) final; + virtual void FieldGather (int lev, + const amrex::MultiFab& Ex, + const amrex::MultiFab& Ey, + const amrex::MultiFab& Ez, + const amrex::MultiFab& Bx, + const amrex::MultiFab& By, + const amrex::MultiFab& Bz) final; void FieldGather (WarpXParIter& pti, RealVector& Exp, diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index b98797b56..91ad03e9b 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1055,9 +1055,9 @@ PhysicalParticleContainer::EvolveES (const Vector& dx = WarpX::CellSize(lev); @@ -1066,11 +1066,14 @@ PhysicalParticleContainer::FieldGatherFortran (int lev, MultiFab* cost = WarpX::getCosts(lev); #ifdef _OPENMP -#pragma omp parallel +#pragma omp parallel #endif { - Cuda::ManagedDeviceVector xp, yp, zp; - +#ifdef _OPENMP + int thread_num = omp_get_thread_num(); +#else + int thread_num = 0; +#endif for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti) { Real wt = amrex::second(); @@ -1106,7 +1109,7 @@ PhysicalParticleContainer::FieldGatherFortran (int lev, // // copy data from particle container to temp arrays // - pti.GetPosition(xp, yp, zp); + pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); const std::array& xyzmin = WarpX::LowerCorner(box, lev); const int* ixyzmin = box.loVect(); @@ -1116,6 +1119,7 @@ PhysicalParticleContainer::FieldGatherFortran (int lev, // const int ll4symtry = false; long lvect_fieldgathe = 64; +#ifdef WARPX_RZ warpx_geteb_energy_conserving( &np, xp.dataPtr(), @@ -1135,6 +1139,12 @@ PhysicalParticleContainer::FieldGatherFortran (int lev, BL_TO_FORTRAN_ANYD(bzfab), &ll4symtry, &WarpX::l_lower_order_in_v, &WarpX::do_nodal, &lvect_fieldgathe, &WarpX::field_gathering_algo); +#else + int e_is_nodal = Ex.is_nodal() and Ey.is_nodal() and Ez.is_nodal(); + FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, + &exfab, &eyfab, &ezfab, &bxfab, &byfab, &bzfab, + Ex.nGrow(), e_is_nodal, 0, np, thread_num, lev, lev); +#endif if (cost) { const Box& tbx = pti.tilebox(); diff --git a/Source/Particles/WarpXParticleContainer.H b/Source/Particles/WarpXParticleContainer.H index 1b2a06171..7cf53260a 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -103,9 +103,10 @@ public: virtual void FieldGatherES (const amrex::Vector, 3> >& E, const amrex::Vector > > >& masks) {} - virtual void FieldGatherFortran (int lev, - const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, const amrex::MultiFab& Ez, - const amrex::MultiFab& Bx, const amrex::MultiFab& By, const amrex::MultiFab& Bz) {} + virtual void FieldGather (int lev, + const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, + const amrex::MultiFab& Ez, const amrex::MultiFab& Bx, + const amrex::MultiFab& By, const amrex::MultiFab& Bz) {} #ifdef WARPX_DO_ELECTROSTATIC virtual void EvolveES (const amrex::Vector, 3> >& E, -- cgit v1.2.3 From 6f351e2a6162bf57d0201978ff03ef740293e3af Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Fri, 26 Jul 2019 14:14:14 -0700 Subject: fix RZ. Now both 2D and RZ give same result as before --- Source/Particles/PhysicalParticleContainer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 91ad03e9b..6d47373f9 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1122,9 +1122,9 @@ PhysicalParticleContainer::FieldGather (int lev, #ifdef WARPX_RZ warpx_geteb_energy_conserving( &np, - xp.dataPtr(), - yp.dataPtr(), - zp.dataPtr(), + m_xp[thread_num].dataPtr(), + m_yp[thread_num].dataPtr(), + m_zp[thread_num].dataPtr(), Exp.dataPtr(),Eyp.dataPtr(),Ezp.dataPtr(), Bxp.dataPtr(),Byp.dataPtr(),Bzp.dataPtr(), ixyzmin, -- cgit v1.2.3 From 254e048de10275870a92d2862c77d237679a3d11 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Wed, 31 Jul 2019 15:27:38 -0700 Subject: cleaning suggested in Remi's review --- Source/Particles/Gather/FieldGather.H | 20 ++++++++++---------- Source/Particles/PhysicalParticleContainer.cpp | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/Gather/FieldGather.H b/Source/Particles/Gather/FieldGather.H index a1d3baed7..be96dd393 100644 --- a/Source/Particles/Gather/FieldGather.H +++ b/Source/Particles/Gather/FieldGather.H @@ -52,33 +52,33 @@ void doGatherShapeN(const amrex::Real * const xp, [=] AMREX_GPU_DEVICE (long ip) { // --- Compute shape factors // x direction - // Get particle position after 1/2 push back in position - const amrex::Real xmid = (xp[ip]-xmin)*dxi; + // Get particle position + const amrex::Real x = (xp[ip]-xmin)*dxi; // Compute shape factors for node-centered quantities amrex::Real AMREX_RESTRICT sx [depos_order + 1]; // j: leftmost grid point (node-centered) that particle touches - const int j = compute_shape_factor(sx, xmid); + const int j = compute_shape_factor(sx, x); // Compute shape factors for cell-centered quantities amrex::Real AMREX_RESTRICT sx0[depos_order + 1 - lower_in_v]; // j0: leftmost grid point (cell-centered) that particle touches const int j0 = compute_shape_factor( - sx0, xmid-stagger_shift); + sx0, x-stagger_shift); #if (AMREX_SPACEDIM == 3) // y direction - const amrex::Real ymid= (yp[ip]-ymin)*dyi; + const amrex::Real y = (yp[ip]-ymin)*dyi; amrex::Real AMREX_RESTRICT sy [depos_order + 1]; - const int k = compute_shape_factor(sy, ymid); + const int k = compute_shape_factor(sy, y); amrex::Real AMREX_RESTRICT sy0[depos_order + 1 - lower_in_v]; const int k0 = compute_shape_factor( - sy0, ymid-stagger_shift); + sy0, y-stagger_shift); #endif // z direction - const amrex::Real zmid= (zp[ip]-zmin)*dzi; + const amrex::Real z = (zp[ip]-zmin)*dzi; amrex::Real AMREX_RESTRICT sz [depos_order + 1]; - const int l = compute_shape_factor(sz, zmid); + const int l = compute_shape_factor(sz, z); amrex::Real AMREX_RESTRICT sz0[depos_order + 1 - lower_in_v]; const int l0 = compute_shape_factor( - sz0, zmid-stagger_shift); + sz0, z-stagger_shift); // Set fields on particle to zero Exp[ip] = 0; diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 0fe5831a8..d1f399f9a 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1124,9 +1124,9 @@ PhysicalParticleContainer::FieldGather (int lev, // // Field Gather // - const int ll4symtry = false; - long lvect_fieldgathe = 64; #ifdef WARPX_RZ + const int ll4symtry = false; + long lvect_fieldgathe = 64; warpx_geteb_energy_conserving( &np, m_xp[thread_num].dataPtr(), @@ -1421,7 +1421,7 @@ PhysicalParticleContainer::Evolve (int lev, // BL_PROFILE_VAR_START(blp_pxr_fg); #ifdef WARPX_RZ - const int ll4symtry = false; + const int ll4symtry = false; long lvect_fieldgathe = 64; const std::array& xyzmin_grid = WarpX::LowerCorner(box, lev); const int* ixyzmin_grid = box.loVect(); -- cgit v1.2.3