From bdef308e6c5b4aeed8190b6ecdb25b00a51ca5f9 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Wed, 6 Nov 2019 16:22:41 -0800 Subject: Implement space-charge initialization (non-relativistic, single-level) --- Source/Particles/WarpXParticleContainer.cpp | 82 ++++++++++++----------------- 1 file changed, 34 insertions(+), 48 deletions(-) (limited to 'Source/Particles/WarpXParticleContainer.cpp') diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index 7fb57500d..29a7d95c7 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -501,68 +501,56 @@ WarpXParticleContainer::DepositCharge (WarpXParIter& pti, RealVector& wp, } void -WarpXParticleContainer::DepositCharge (Vector >& rho, bool local) +WarpXParticleContainer::DepositCharge (Vector >& rho, + bool local, bool reset) { int num_levels = rho.size(); int finest_level = num_levels - 1; - // each level deposits it's own particles + // each level deposits its own particles const int ng = rho[0]->nGrow(); for (int lev = 0; lev < num_levels; ++lev) { - rho[lev]->setVal(0.0, ng); - - const auto& gm = m_gdb->Geom(lev); - const auto& ba = m_gdb->ParticleBoxArray(lev); - - const Real* dx = gm.CellSize(); - const Real* plo = gm.ProbLo(); - BoxArray nba = ba; - nba.surroundingNodes(); - - for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti) { - const Box& box = nba[pti]; + if (reset) rho[lev]->setVal(0.0, ng); +#ifdef _OPENMP +#pragma omp parallel + { +#endif +#ifdef _OPENMP + int thread_num = omp_get_thread_num(); +#else + int thread_num = 0; +#endif + for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti) + { + const long np = pti.numParticles(); auto& wp = pti.GetAttribs(PIdx::w); - const auto& particles = pti.GetArrayOfStructs(); - int nstride = particles.dataShape().first; - const long np = pti.numParticles(); - FArrayBox& rhofab = (*rho[lev])[pti]; + pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); + + int* AMREX_RESTRICT ion_lev; + if (do_field_ionization){ + ion_lev = pti.GetiAttribs(particle_icomps["ionization_level"]).dataPtr(); + } else { + ion_lev = nullptr; + } - WRPX_DEPOSIT_CIC(particles.dataPtr(), nstride, np, - wp.dataPtr(), &this->charge, - rhofab.dataPtr(), box.loVect(), box.hiVect(), - plo, dx, &ng); + DepositCharge(pti, wp, ion_lev, rho[lev].get(), 0, 0, np, thread_num, lev, lev); } +#ifdef _OPENMP + } +#endif - if (!local) rho[lev]->SumBoundary(gm.periodicity()); - } +#ifdef WARPX_DIM_RZ + WarpX::GetInstance().ApplyInverseVolumeScalingToChargeDensity(rho[lev].get(), lev); +#endif - // now we average down fine to crse - std::unique_ptr crse; - for (int lev = finest_level - 1; lev >= 0; --lev) { - const BoxArray& fine_BA = rho[lev+1]->boxArray(); - const DistributionMapping& fine_dm = rho[lev+1]->DistributionMap(); - BoxArray coarsened_fine_BA = fine_BA; - coarsened_fine_BA.coarsen(m_gdb->refRatio(lev)); - - MultiFab coarsened_fine_data(coarsened_fine_BA, fine_dm, rho[lev+1]->nComp(), 0); - coarsened_fine_data.setVal(0.0); - - IntVect ratio(AMREX_D_DECL(2, 2, 2)); // FIXME - - for (MFIter mfi(coarsened_fine_data); mfi.isValid(); ++mfi) { - const Box& bx = mfi.validbox(); - const Box& crse_box = coarsened_fine_data[mfi].box(); - const Box& fine_box = (*rho[lev+1])[mfi].box(); - WRPX_SUM_FINE_TO_CRSE_NODAL(bx.loVect(), bx.hiVect(), ratio.getVect(), - coarsened_fine_data[mfi].dataPtr(), crse_box.loVect(), crse_box.hiVect(), - (*rho[lev+1])[mfi].dataPtr(), fine_box.loVect(), fine_box.hiVect()); + if (!local) { + const auto& gm = m_gdb->Geom(lev); + rho[lev]->SumBoundary(gm.periodicity()); } - - rho[lev]->copy(coarsened_fine_data, m_gdb->Geom(lev).periodicity(), FabArrayBase::ADD); } } @@ -841,5 +829,3 @@ WarpXParticleContainer::particlePostLocate(ParticleType& p, if (pld.m_lev == lev-1){ } } - - -- cgit v1.2.3 From 0bf5b667a13e2e4a8cf58516ead3665a224209b9 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Fri, 8 Nov 2019 08:54:48 -0800 Subject: Minor fixes --- Source/Particles/WarpXParticleContainer.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'Source/Particles/WarpXParticleContainer.cpp') diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index 29a7d95c7..9abeaf131 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -504,21 +504,16 @@ void WarpXParticleContainer::DepositCharge (Vector >& rho, bool local, bool reset) { + // Loop over the refinement levels + for (int lev = 0; lev < max_level; ++lev) { - int num_levels = rho.size(); - int finest_level = num_levels - 1; - - // each level deposits its own particles - const int ng = rho[0]->nGrow(); - for (int lev = 0; lev < num_levels; ++lev) { - - if (reset) rho[lev]->setVal(0.0, ng); + // Reset the `rho` array if `reset` is True + if (reset) rho[lev]->setVal(0.0, rho[lev]->nGrow()); + // Loop over particle tiles and deposit charge #ifdef _OPENMP -#pragma omp parallel + #pragma omp parallel { -#endif -#ifdef _OPENMP int thread_num = omp_get_thread_num(); #else int thread_num = 0; -- cgit v1.2.3 From 074741f7d5fb64f43c1ca692669e407c264c0b88 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Fri, 8 Nov 2019 12:18:48 -0800 Subject: Use mesh refinement averaging --- Source/Particles/WarpXParticleContainer.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'Source/Particles/WarpXParticleContainer.cpp') diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index 9abeaf131..6f195fa87 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -510,7 +510,7 @@ WarpXParticleContainer::DepositCharge (Vector >& rho, // Reset the `rho` array if `reset` is True if (reset) rho[lev]->setVal(0.0, rho[lev]->nGrow()); - // Loop over particle tiles and deposit charge + // Loop over particle tiles and deposit charge on each level #ifdef _OPENMP #pragma omp parallel { @@ -542,10 +542,23 @@ WarpXParticleContainer::DepositCharge (Vector >& rho, WarpX::GetInstance().ApplyInverseVolumeScalingToChargeDensity(rho[lev].get(), lev); #endif - if (!local) { - const auto& gm = m_gdb->Geom(lev); - rho[lev]->SumBoundary(gm.periodicity()); - } + // Exchange guard cells + if (!local) rho[lev]->SumBoundary( m_gdb->Geom(lev).periodicity() ); + } + + // Now that the charge has been deposited at each level, + // we average down from fine to crse + for (int lev = finest_level - 1; lev >= 0; --lev) { + const DistributionMapping& fine_dm = rho[lev+1]->DistributionMap(); + BoxArray coarsened_fine_BA = rho[lev+1]->boxArray(); + coarsened_fine_BA.coarsen(m_gdb->refRatio(lev)); + MultiFab coarsened_fine_data(coarsened_fine_BA, fine_dm, rho[lev+1]->nComp(), 0); + coarsened_fine_data.setVal(0.0); + + int const refinement_ratio = 2; + + interpolateDensityFineToCoarse( rho[lev+1], coarsened_fine_data, refinement_ratio ); + rho[lev].ParallelAdd( coarsened_fine_data, m_gdb->Geom(lev).periodicity() ); } } -- cgit v1.2.3 From aea192d6ff5aabfedf09c9f139e831fb5d7bbdd6 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Mon, 11 Nov 2019 20:43:52 -0800 Subject: Update DepositCharge --- Source/Parallelization/Make.package | 1 + Source/Parallelization/WarpXComm.cpp | 14 +++++++------- Source/Particles/WarpXParticleContainer.cpp | 9 +++++---- Source/WarpX.H | 23 ----------------------- 4 files changed, 13 insertions(+), 34 deletions(-) (limited to 'Source/Particles/WarpXParticleContainer.cpp') diff --git a/Source/Parallelization/Make.package b/Source/Parallelization/Make.package index c74583522..7c3c38627 100644 --- a/Source/Parallelization/Make.package +++ b/Source/Parallelization/Make.package @@ -2,6 +2,7 @@ CEXE_sources += WarpXComm.cpp CEXE_sources += WarpXRegrid.cpp CEXE_headers += WarpXSumGuardCells.H CEXE_headers += WarpXComm_K.H +CEXE_headers += WarpXComm.H INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Parallelization VPATH_LOCATIONS += $(WARPX_HOME)/Source/Parallelization diff --git a/Source/Parallelization/WarpXComm.cpp b/Source/Parallelization/WarpXComm.cpp index 52df3dc25..851b78748 100644 --- a/Source/Parallelization/WarpXComm.cpp +++ b/Source/Parallelization/WarpXComm.cpp @@ -1,14 +1,14 @@ +#include "WarpXComm.H" #include #include #include #include -#include -#include +#include +#include #include #include - using namespace amrex; void @@ -503,9 +503,9 @@ WarpX::SyncCurrent () } void -WarpX::interpolateCurrentFineToCoarse ( std::array< amrex::MultiFab const *, 3 > const & fine, - std::array< amrex::MultiFab *, 3 > const & coarse, - int const refinement_ratio) +interpolateCurrentFineToCoarse ( std::array< amrex::MultiFab const *, 3 > const & fine, + std::array< amrex::MultiFab *, 3 > const & coarse, + int const refinement_ratio) { BL_PROFILE("interpolateCurrentFineToCoarse()"); BL_ASSERT(refinement_ratio == 2); @@ -563,7 +563,7 @@ WarpX::SyncRho () } void -WarpX::interpolateDensityFineToCoarse (const MultiFab& fine, MultiFab& coarse, int const refinement_ratio) +interpolateDensityFineToCoarse (const MultiFab& fine, MultiFab& coarse, int const refinement_ratio) { BL_PROFILE("interpolateDensityFineToCoarse()"); BL_ASSERT(refinement_ratio == 2); diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index 6f195fa87..4be339707 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -7,7 +7,7 @@ #include #include #include - +#include // Import low-level single-particle kernels #include #include @@ -505,7 +505,8 @@ WarpXParticleContainer::DepositCharge (Vector >& rho, bool local, bool reset) { // Loop over the refinement levels - for (int lev = 0; lev < max_level; ++lev) { + int const finest_level = rho.size() - 1; + for (int lev = 0; lev < finest_level; ++lev) { // Reset the `rho` array if `reset` is True if (reset) rho[lev]->setVal(0.0, rho[lev]->nGrow()); @@ -557,8 +558,8 @@ WarpXParticleContainer::DepositCharge (Vector >& rho, int const refinement_ratio = 2; - interpolateDensityFineToCoarse( rho[lev+1], coarsened_fine_data, refinement_ratio ); - rho[lev].ParallelAdd( coarsened_fine_data, m_gdb->Geom(lev).periodicity() ); + interpolateDensityFineToCoarse( *rho[lev+1], coarsened_fine_data, refinement_ratio ); + rho[lev]->ParallelAdd( coarsened_fine_data, m_gdb->Geom(lev).periodicity() ); } } diff --git a/Source/WarpX.H b/Source/WarpX.H index 4275df3c5..d17787c57 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -419,29 +419,6 @@ private: std::array, 3> getInterpolatedB(int lev) const; - /** \brief Fills the values of the current on the coarse patch by - * averaging the values of the current of the fine patch (on the same level). - * Also fills the guards of the coarse patch. - * - * \param[in] fine fine patches to interpolate from - * \param[out] coarse coarse patches to interpolate to - * \param[in] refinement_ratio integer ratio between the two - */ - void interpolateCurrentFineToCoarse (std::array< amrex::MultiFab const *, 3 > const & fine, - std::array< amrex::MultiFab *, 3 > const & coarse, - int const refinement_ratio); - - /** \brief Fills the values of the charge density on the coarse patch by - * averaging the values of the charge density of the fine patch (on the same level). - * - * \param[in] fine fine patches to interpolate from - * \param[out] coarse coarse patches to interpolate to - * \param[in] refinement_ratio integer ratio between the two - */ - void interpolateDensityFineToCoarse (const amrex::MultiFab& fine, - amrex::MultiFab& coarse, - int const refinement_ratio); - void ExchangeWithPmlB (int lev); void ExchangeWithPmlE (int lev); void ExchangeWithPmlF (int lev); -- cgit v1.2.3 From f4925a8a2c9ac1b88178dca21ac78d067cb35c37 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Wed, 13 Nov 2019 14:48:50 -0800 Subject: Fix error in DepositCharge --- Source/Particles/WarpXParticleContainer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Particles/WarpXParticleContainer.cpp') diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index 01a2e5ccb..24b7e51a3 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -506,7 +506,7 @@ WarpXParticleContainer::DepositCharge (Vector >& rho, { // Loop over the refinement levels int const finest_level = rho.size() - 1; - for (int lev = 0; lev < finest_level; ++lev) { + for (int lev = 0; lev <= finest_level; ++lev) { // Reset the `rho` array if `reset` is True if (reset) rho[lev]->setVal(0.0, rho[lev]->nGrow()); -- cgit v1.2.3 From 3983a4153a21164fe2a955a22c1824687e1148a8 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Sat, 16 Nov 2019 06:57:40 -0800 Subject: Minor fixes --- Source/Initialization/InitSpaceChargeField.cpp | 9 +++++---- Source/Particles/WarpXParticleContainer.H | 3 ++- Source/Particles/WarpXParticleContainer.cpp | 7 +++++-- 3 files changed, 12 insertions(+), 7 deletions(-) (limited to 'Source/Particles/WarpXParticleContainer.cpp') diff --git a/Source/Initialization/InitSpaceChargeField.cpp b/Source/Initialization/InitSpaceChargeField.cpp index 67cc46ccb..73ee0478e 100644 --- a/Source/Initialization/InitSpaceChargeField.cpp +++ b/Source/Initialization/InitSpaceChargeField.cpp @@ -29,9 +29,10 @@ WarpX::InitSpaceChargeField (WarpXParticleContainer& pc) } // Deposit particle charge density (source of Poisson solver) - bool local = false; - bool reset = true; - pc.DepositCharge(rho, local, reset); + bool const local = false; + bool const reset = true; + bool const do_rz_volume_scaling = true; + pc.DepositCharge(rho, local, reset, do_rz_volume_scaling); // Compute the potential phi, by solving the Poisson equation computePhi( rho, phi ); @@ -114,7 +115,7 @@ WarpX::computeE(amrex::Vector, 3> >& const Box& tby = mfi.tilebox(Ey_nodal_flag); const Box& tbz = mfi.tilebox(Ez_nodal_flag); - const auto& phi_arr = phi[0]->array(mfi); + const auto& phi_arr = phi[lev]->array(mfi); const auto& Ex_arr = (*E[lev][0])[mfi].array(); const auto& Ey_arr = (*E[lev][1])[mfi].array(); const auto& Ez_arr = (*E[lev][2])[mfi].array(); diff --git a/Source/Particles/WarpXParticleContainer.H b/Source/Particles/WarpXParticleContainer.H index 7da25b452..89dbae7b5 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -185,7 +185,8 @@ public: const amrex::MultiFab& Bz) = 0; void DepositCharge(amrex::Vector >& rho, - bool local = false, bool reset = true); + bool local = false, bool reset = false, + bool do_rz_volume_scaling = false ); std::unique_ptr GetChargeDensity(int lev, bool local = false); virtual void DepositCharge(WarpXParIter& pti, diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index 24b7e51a3..09f51ef49 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -502,7 +502,8 @@ WarpXParticleContainer::DepositCharge (WarpXParIter& pti, RealVector& wp, void WarpXParticleContainer::DepositCharge (Vector >& rho, - bool local, bool reset) + bool local, bool reset, + bool do_rz_volume_scaling) { // Loop over the refinement levels int const finest_level = rho.size() - 1; @@ -540,7 +541,9 @@ WarpXParticleContainer::DepositCharge (Vector >& rho, #endif #ifdef WARPX_DIM_RZ - if (reset) WarpX::GetInstance().ApplyInverseVolumeScalingToChargeDensity(rho[lev].get(), lev); + if (do_rz_volume_scaling) { + WarpX::GetInstance().ApplyInverseVolumeScalingToChargeDensity(rho[lev].get(), lev); + } #endif // Exchange guard cells -- cgit v1.2.3 From 93b3c21262035097d7204521e0afd76b0e15db44 Mon Sep 17 00:00:00 2001 From: Yinjian Zhao Date: Wed, 20 Nov 2019 14:26:54 -0800 Subject: Add do_not_deposit_current. --- Source/Particles/WarpXParticleContainer.H | 1 + Source/Particles/WarpXParticleContainer.cpp | 5 +++++ 2 files changed, 6 insertions(+) (limited to 'Source/Particles/WarpXParticleContainer.cpp') diff --git a/Source/Particles/WarpXParticleContainer.H b/Source/Particles/WarpXParticleContainer.H index 7b0d2d1d0..d3da279fe 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -301,6 +301,7 @@ protected: bool m_gather_from_main_grid = false; static int do_not_push; + static int do_not_deposit_current; // Whether to allow particles outside of the simulation domain to be // initialized when they enter the domain. diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index 65a82f233..5a777b79a 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -17,6 +17,7 @@ using namespace amrex; int WarpXParticleContainer::do_not_push = 0; +int WarpXParticleContainer::do_not_deposit_current = 0; WarpXParIter::WarpXParIter (ContainerType& pc, int level) : ParIter(pc, level, MFItInfo().SetDynamic(WarpX::do_dynamic_scheduling)) @@ -120,6 +121,7 @@ WarpXParticleContainer::ReadParameters () #endif pp.query("do_tiling", do_tiling); pp.query("do_not_push", do_not_push); + pp.query("do_not_deposit_current", do_not_deposit_current); initialized = true; } @@ -309,6 +311,9 @@ WarpXParticleContainer::DepositCurrent(WarpXParIter& pti, // If no particles, do not do anything if (np_to_depose == 0) return; + // If user decides not to deposit current + if (do_not_deposit_current) return; + const long ngJ = jx->nGrow(); const std::array& dx = WarpX::CellSize(std::max(depos_lev,0)); int j_is_nodal = jx->is_nodal() and jy->is_nodal() and jz->is_nodal(); -- cgit v1.2.3 From b5c79cdcfdbc64413ac9f195c97bda3acf6db2c1 Mon Sep 17 00:00:00 2001 From: Yinjian Zhao Date: Wed, 20 Nov 2019 14:53:44 -0800 Subject: Also do not deposit charge. --- Source/Particles/WarpXParticleContainer.H | 2 +- Source/Particles/WarpXParticleContainer.cpp | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'Source/Particles/WarpXParticleContainer.cpp') diff --git a/Source/Particles/WarpXParticleContainer.H b/Source/Particles/WarpXParticleContainer.H index 1fedc1d3e..41a11b442 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -301,7 +301,7 @@ protected: bool m_gather_from_main_grid = false; static int do_not_push; - static int do_not_deposit_current; + static int do_not_deposit; // Whether to allow particles outside of the simulation domain to be // initialized when they enter the domain. diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index 06000a32f..c256df6aa 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -18,7 +18,7 @@ using namespace amrex; int WarpXParticleContainer::do_not_push = 0; -int WarpXParticleContainer::do_not_deposit_current = 0; +int WarpXParticleContainer::do_not_deposit = 0; WarpXParIter::WarpXParIter (ContainerType& pc, int level) : ParIter(pc, level, MFItInfo().SetDynamic(WarpX::do_dynamic_scheduling)) @@ -122,7 +122,7 @@ WarpXParticleContainer::ReadParameters () #endif pp.query("do_tiling", do_tiling); pp.query("do_not_push", do_not_push); - pp.query("do_not_deposit_current", do_not_deposit_current); + pp.query("do_not_deposit", do_not_deposit); initialized = true; } @@ -273,8 +273,8 @@ WarpXParticleContainer::DepositCurrent(WarpXParIter& pti, // If no particles, do not do anything if (np_to_depose == 0) return; - // If user decides not to deposit current - if (do_not_deposit_current) return; + // If user decides not to deposit + if (do_not_deposit) return; const long ngJ = jx->nGrow(); const std::array& dx = WarpX::CellSize(std::max(depos_lev,0)); @@ -433,6 +433,9 @@ WarpXParticleContainer::DepositCharge (WarpXParIter& pti, RealVector& wp, // If no particles, do not do anything if (np_to_depose == 0) return; + // If user decides not to deposit + if (do_not_deposit) return; + const long ngRho = rho->nGrow(); const std::array& dx = WarpX::CellSize(std::max(depos_lev,0)); const Real q = this->charge; -- cgit v1.2.3 From 1fd18a4ad2da297a69e3eadec5f76e459d9b638a Mon Sep 17 00:00:00 2001 From: levinem <14362448+levinem@users.noreply.github.com> Date: Thu, 21 Nov 2019 20:39:14 -0500 Subject: Made similar for loop condition updates in other files. Changed an int const declaration to a const int declaration. --- Source/Diagnostics/ParticleIO.cpp | 5 +++-- Source/Parallelization/WarpXRegrid.cpp | 5 +++-- Source/Particles/WarpXParticleContainer.cpp | 22 ++++++++++++++-------- 3 files changed, 20 insertions(+), 12 deletions(-) (limited to 'Source/Particles/WarpXParticleContainer.cpp') diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 4fca8c8cb..bd820d0ba 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -171,8 +171,9 @@ PhysicalParticleContainer::ConvertUnits(ConvertDirection convert_direction) factor = 1./mass; } - const auto& finestLevel = finestLevel(); - for (int lev=0; lev<=finestLevel; ++lev){ + const int nLevels = finestLevel(); + + for (int lev=0; lev<=nLevels; ++lev){ #ifdef _OPENMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif diff --git a/Source/Parallelization/WarpXRegrid.cpp b/Source/Parallelization/WarpXRegrid.cpp index 2ae167283..c36634365 100644 --- a/Source/Parallelization/WarpXRegrid.cpp +++ b/Source/Parallelization/WarpXRegrid.cpp @@ -1,4 +1,3 @@ - #include #include @@ -12,7 +11,9 @@ WarpX::LoadBalance () AMREX_ALWAYS_ASSERT(costs[0] != nullptr); - for (int lev = 0; lev <= finestLevel(); ++lev) + const int nLevels = finestLevel(); + + for (int lev = 0; lev <= nLevels; ++lev) { const Real nboxes = costs[lev]->size(); const Real nprocs = ParallelDescriptor::NProcs(); diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index c256df6aa..571de6c4e 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -1,4 +1,3 @@ - #include #include @@ -514,7 +513,7 @@ WarpXParticleContainer::DepositCharge (Vector >& rho, bool do_rz_volume_scaling) { // Loop over the refinement levels - int const finest_level = rho.size() - 1; + const int finest_level = rho.size() - 1; for (int lev = 0; lev <= finest_level; ++lev) { // Reset the `rho` array if `reset` is True @@ -567,7 +566,7 @@ WarpXParticleContainer::DepositCharge (Vector >& rho, MultiFab coarsened_fine_data(coarsened_fine_BA, fine_dm, rho[lev+1]->nComp(), 0); coarsened_fine_data.setVal(0.0); - int const refinement_ratio = 2; + const int refinement_ratio = 2; interpolateDensityFineToCoarse( *rho[lev+1], coarsened_fine_data, refinement_ratio ); rho[lev]->ParallelAdd( coarsened_fine_data, m_gdb->Geom(lev).periodicity() ); @@ -632,7 +631,8 @@ Real WarpXParticleContainer::sumParticleCharge(bool local) { amrex::Real total_charge = 0.0; - for (int lev = 0; lev < finestLevel(); ++lev) + const int nlevels = finestLevel(); + for (int lev = 0; lev < nlevels; ++lev) { #ifdef _OPENMP @@ -662,7 +662,9 @@ std::array WarpXParticleContainer::meanParticleVelocity(bool local) { amrex::Real inv_clight_sq = 1.0/PhysConst::c/PhysConst::c; - for (int lev = 0; lev <= finestLevel(); ++lev) { + const int nLevels = finestLevel(); + + for (int lev = 0; lev <= nLevels; ++lev) { #ifdef _OPENMP #pragma omp parallel reduction(+:vx_total, vy_total, vz_total, np_total) @@ -706,7 +708,9 @@ Real WarpXParticleContainer::maxParticleVelocity(bool local) { amrex::ParticleReal max_v = 0.0; - for (int lev = 0; lev <= finestLevel(); ++lev) + const int nLevels = finestLevel(); + + for (int lev = 0; lev <= nLevels; ++lev) { #ifdef _OPENMP @@ -732,7 +736,7 @@ WarpXParticleContainer::PushXES (Real dt) { BL_PROFILE("WPC::PushXES()"); - int num_levels = finestLevel() + 1; + const int num_levels = finestLevel() + 1; for (int lev = 0; lev < num_levels; ++lev) { const auto& gm = m_gdb->Geom(lev); @@ -761,7 +765,9 @@ WarpXParticleContainer::PushXES (Real dt) void WarpXParticleContainer::PushX (Real dt) { - for (int lev = 0; lev <= finestLevel(); ++lev) { + const int nLevels = finestLevel(); + + for (int lev = 0; lev <= nLevels; ++lev) { PushX(lev, dt); } } -- cgit v1.2.3 From 1f64e254435723a952ff3296075ca9a52694dce5 Mon Sep 17 00:00:00 2001 From: levinem <14362448+levinem@users.noreply.github.com> Date: Thu, 21 Nov 2019 20:49:47 -0500 Subject: Added a line break between the const int declaration and the for loop. Updated the nLevels variable name to CamelCase. --- Source/Particles/WarpXParticleContainer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Source/Particles/WarpXParticleContainer.cpp') diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index 571de6c4e..a7e5b82da 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -631,8 +631,9 @@ Real WarpXParticleContainer::sumParticleCharge(bool local) { amrex::Real total_charge = 0.0; - const int nlevels = finestLevel(); - for (int lev = 0; lev < nlevels; ++lev) + const int nLevels = finestLevel(); + + for (int lev = 0; lev < nLevels; ++lev) { #ifdef _OPENMP -- cgit v1.2.3 From 25a614fe9e3bdbae8008b408976e65232286b1c5 Mon Sep 17 00:00:00 2001 From: Yinjian Zhao Date: Mon, 25 Nov 2019 11:16:01 -0700 Subject: Change do_not_depoist to be species related. --- Docs/source/running_cpp/parameters.rst | 8 ++++---- Source/Particles/PhysicalParticleContainer.cpp | 1 + Source/Particles/WarpXParticleContainer.cpp | 1 - 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'Source/Particles/WarpXParticleContainer.cpp') diff --git a/Docs/source/running_cpp/parameters.rst b/Docs/source/running_cpp/parameters.rst index 59c4be5fd..a16e0bfec 100644 --- a/Docs/source/running_cpp/parameters.rst +++ b/Docs/source/running_cpp/parameters.rst @@ -363,15 +363,15 @@ Particle initialization Split particles of the species when crossing the boundary from a lower resolution domain to a higher resolution domain. -* ``.do_not_deposit`` (`0` or `1` optional; default `0`) - If `1` is given, both charge deposition and current deposition will - not be done, so the fields due to particles remain zero. - * ``.split_type`` (`int`) optional (default `0`) Splitting technique. When `0`, particles are split along the simulation axes (4 particles in 2D, 6 particles in 3D). When `1`, particles are split along the diagonals (4 particles in 2D, 8 particles in 3D). +* ``.do_not_deposit`` (`0` or `1` optional; default `0`) + If `1` is given, both charge deposition and current deposition will + not be done, thus that species does not contribute to the fields. + * ``.plot_species`` (`0` or `1` optional; default `1`) Whether to plot particle quantities for this species. diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 4f6d032e9..55290cf1f 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -39,6 +39,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp // Initialize splitting pp.query("do_splitting", do_splitting); pp.query("split_type", split_type); + pp.query("do_not_deposit", do_not_deposit); pp.query("do_continuous_injection", do_continuous_injection); pp.query("initialize_self_fields", initialize_self_fields); diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index c256df6aa..7b5bf16d1 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -122,7 +122,6 @@ WarpXParticleContainer::ReadParameters () #endif pp.query("do_tiling", do_tiling); pp.query("do_not_push", do_not_push); - pp.query("do_not_deposit", do_not_deposit); initialized = true; } -- cgit v1.2.3 From 3ad7f72470374320a8681543f1a1efab457dd717 Mon Sep 17 00:00:00 2001 From: levinem <14362448+levinem@users.noreply.github.com> Date: Tue, 26 Nov 2019 18:37:21 -0500 Subject: Removed the blank lines between the nLevels declarations and the for loops. Moved the prefix operator change back to its original postfix unary position. Changed the int const changes back to their original const int declarations. --- Source/Diagnostics/ParticleIO.cpp | 3 +-- Source/Parallelization/WarpXRegrid.cpp | 1 - Source/Particles/WarpXParticleContainer.cpp | 8 ++------ 3 files changed, 3 insertions(+), 9 deletions(-) (limited to 'Source/Particles/WarpXParticleContainer.cpp') diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index bd820d0ba..c08d58d36 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -172,8 +172,7 @@ PhysicalParticleContainer::ConvertUnits(ConvertDirection convert_direction) } const int nLevels = finestLevel(); - - for (int lev=0; lev<=nLevels; ++lev){ + for (int lev=0; lev<=nLevels; lev++){ #ifdef _OPENMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif diff --git a/Source/Parallelization/WarpXRegrid.cpp b/Source/Parallelization/WarpXRegrid.cpp index c36634365..29ccc8f4d 100644 --- a/Source/Parallelization/WarpXRegrid.cpp +++ b/Source/Parallelization/WarpXRegrid.cpp @@ -12,7 +12,6 @@ WarpX::LoadBalance () AMREX_ALWAYS_ASSERT(costs[0] != nullptr); const int nLevels = finestLevel(); - for (int lev = 0; lev <= nLevels; ++lev) { const Real nboxes = costs[lev]->size(); diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index a7e5b82da..009f90f24 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -513,7 +513,7 @@ WarpXParticleContainer::DepositCharge (Vector >& rho, bool do_rz_volume_scaling) { // Loop over the refinement levels - const int finest_level = rho.size() - 1; + int const finest_level = rho.size() - 1; for (int lev = 0; lev <= finest_level; ++lev) { // Reset the `rho` array if `reset` is True @@ -566,7 +566,7 @@ WarpXParticleContainer::DepositCharge (Vector >& rho, MultiFab coarsened_fine_data(coarsened_fine_BA, fine_dm, rho[lev+1]->nComp(), 0); coarsened_fine_data.setVal(0.0); - const int refinement_ratio = 2; + int const refinement_ratio = 2; interpolateDensityFineToCoarse( *rho[lev+1], coarsened_fine_data, refinement_ratio ); rho[lev]->ParallelAdd( coarsened_fine_data, m_gdb->Geom(lev).periodicity() ); @@ -632,7 +632,6 @@ Real WarpXParticleContainer::sumParticleCharge(bool local) { amrex::Real total_charge = 0.0; const int nLevels = finestLevel(); - for (int lev = 0; lev < nLevels; ++lev) { @@ -664,7 +663,6 @@ std::array WarpXParticleContainer::meanParticleVelocity(bool local) { amrex::Real inv_clight_sq = 1.0/PhysConst::c/PhysConst::c; const int nLevels = finestLevel(); - for (int lev = 0; lev <= nLevels; ++lev) { #ifdef _OPENMP @@ -710,7 +708,6 @@ Real WarpXParticleContainer::maxParticleVelocity(bool local) { amrex::ParticleReal max_v = 0.0; const int nLevels = finestLevel(); - for (int lev = 0; lev <= nLevels; ++lev) { @@ -767,7 +764,6 @@ void WarpXParticleContainer::PushX (Real dt) { const int nLevels = finestLevel(); - for (int lev = 0; lev <= nLevels; ++lev) { PushX(lev, dt); } -- cgit v1.2.3