From cafd5549a21a6e49f3de4015d6634e69dec2c8da Mon Sep 17 00:00:00 2001 From: NeilZaim <49716072+NeilZaim@users.noreply.github.com> Date: Mon, 28 Sep 2020 23:00:57 +0200 Subject: Add option to only resample cells with high enough number of macroparticles (#1385) * Add option to only resample cells with high enough number of macroparticles * Apply suggestions from code review Co-authored-by: Axel Huebl --- Source/Particles/Resampling/LevelingThinning.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'Source/Particles/Resampling/LevelingThinning.cpp') diff --git a/Source/Particles/Resampling/LevelingThinning.cpp b/Source/Particles/Resampling/LevelingThinning.cpp index 1504a0f6b..ec1205fa8 100644 --- a/Source/Particles/Resampling/LevelingThinning.cpp +++ b/Source/Particles/Resampling/LevelingThinning.cpp @@ -22,6 +22,10 @@ LevelingThinning::LevelingThinning (const std::string species_name) amrex::Warning("WARNING: target ratio for leveling thinning is smaller or equal to one." " It is possible that no particle will be removed during resampling"); } + + pp.query("resampling_algorithm_min_ppc", m_min_ppc); + AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_min_ppc >= 1, + "Resampling min_ppc should be greater than or equal to 1"); } void LevelingThinning::operator() (WarpXParIter& pti, const int lev, @@ -47,6 +51,7 @@ void LevelingThinning::operator() (WarpXParIter& pti, const int lev, const auto cell_offsets = bins.offsetsPtr(); const amrex::Real target_ratio = m_target_ratio; + const int min_ppc = m_min_ppc; // Loop over cells amrex::ParallelForRNG( n_cells, @@ -58,8 +63,9 @@ void LevelingThinning::operator() (WarpXParIter& pti, const int lev, const auto cell_stop = static_cast(cell_offsets[i_cell+1]); const int cell_numparts = cell_stop - cell_start; - // do nothing for cells without particles - if (cell_numparts == 0) + // do nothing for cells with less particles than min_ppc + // (this intentionally includes skipping empty cells, too) + if (cell_numparts < min_ppc) return; amrex::Real average_weight = 0._rt; -- cgit v1.2.3