From c81a98d86431a987ccc204f62e278899fc57ef5e Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Fri, 28 Feb 2025 16:31:33 +0100 Subject: [PATCH 1/2] sort particles_for_deposition and sort_idx_type no longer static --- Source/Evolve/WarpXEvolve.cpp | 3 ++- Source/Particles/MultiParticleContainer.H | 5 ++++- Source/Particles/MultiParticleContainer.cpp | 9 ++++++--- Source/WarpX.H | 17 ++++++++++++----- Source/WarpX.cpp | 8 -------- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Source/Evolve/WarpXEvolve.cpp b/Source/Evolve/WarpXEvolve.cpp index 5593642a944..d2ea232d8ff 100644 --- a/Source/Evolve/WarpXEvolve.cpp +++ b/Source/Evolve/WarpXEvolve.cpp @@ -584,7 +584,8 @@ void WarpX::HandleParticlesAtBoundaries (int step, amrex::Real cur_time, int num if (verbose) { amrex::Print() << Utils::TextMsg::Info("re-sorting particles"); } - mypc->SortParticlesByBin(sort_bin_size); + mypc->SortParticlesByBin( + sort_bin_size, sort_particles_for_deposition, sort_idx_type); } } diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 0e33b6bac3c..d7e13ed2912 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -211,7 +211,10 @@ public: void WriteHeader (std::ostream& os) const; - void SortParticlesByBin (amrex::IntVect bin_size); + void SortParticlesByBin ( + const amrex::IntVect& bin_size, + bool sort_particles_for_deposition, + const amrex::IntVect& sort_idx_type); void Redistribute (); diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 6c08dc6aa8d..897d427c8ed 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -611,11 +611,14 @@ MultiParticleContainer::GetChargeDensity (int lev, bool local) } void -MultiParticleContainer::SortParticlesByBin (amrex::IntVect bin_size) +MultiParticleContainer::SortParticlesByBin ( + const amrex::IntVect& bin_size, + const bool sort_particles_for_deposition, + const amrex::IntVect& sort_idx_type) { for (auto& pc : allcontainers) { - if (WarpX::sort_particles_for_deposition) { - pc->SortParticlesForDeposition(WarpX::sort_idx_type); + if (sort_particles_for_deposition) { + pc->SortParticlesForDeposition(sort_idx_type); } else { pc->SortParticlesByBin(bin_size); } diff --git a/Source/WarpX.H b/Source/WarpX.H index 4f6024d426d..9200bff2a02 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -352,11 +352,6 @@ public: static utils::parser::IntervalsParser sort_intervals; static amrex::IntVect sort_bin_size; - //! If true, particles will be sorted in the order x -> y -> z -> ppc for faster deposition - static bool sort_particles_for_deposition; - //! Specifies the type of grid used for the above sorting, i.e. cell-centered, nodal, or mixed - static amrex::IntVect sort_idx_type; - static bool do_multi_J; static int do_multi_J_n_depositions; @@ -1489,6 +1484,18 @@ private: int noy_fft = 16; int noz_fft = 16; + + + //! If true, particles will be sorted in the order x -> y -> z -> ppc for faster deposition +#if defined(AMREX_USE_CUDA) + bool sort_particles_for_deposition = true; +#else + bool sort_particles_for_deposition = false; +#endif + + //! Specifies the type of grid used for the above sorting, i.e. cell-centered, nodal, or mixed + amrex::IntVect sort_idx_type = amrex::IntVect(AMREX_D_DECL(0,0,0)); + //! Solve Poisson equation when loading an external magnetic field to clean divergence //! This is useful to remove errors that could lead to non-zero B field divergence bool m_do_divb_cleaning_external = false; diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index c9e90850ee1..f4f06c4a265 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -164,14 +164,6 @@ bool WarpX::refine_plasma = false; utils::parser::IntervalsParser WarpX::sort_intervals; amrex::IntVect WarpX::sort_bin_size(AMREX_D_DECL(1,1,1)); -#if defined(AMREX_USE_CUDA) -bool WarpX::sort_particles_for_deposition = true; -#else -bool WarpX::sort_particles_for_deposition = false; -#endif - -amrex::IntVect WarpX::sort_idx_type(AMREX_D_DECL(0,0,0)); - bool WarpX::do_dynamic_scheduling = true; bool WarpX::do_multi_J = false; From 91dfc963e99491c8958aa6291f61808d72e24088 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 11 Mar 2025 14:20:27 +0100 Subject: [PATCH 2/2] use m_ prefix for private member variables --- Source/Evolve/WarpXEvolve.cpp | 2 +- Source/WarpX.H | 6 +++--- Source/WarpX.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Evolve/WarpXEvolve.cpp b/Source/Evolve/WarpXEvolve.cpp index d2ea232d8ff..4a6a745ccf0 100644 --- a/Source/Evolve/WarpXEvolve.cpp +++ b/Source/Evolve/WarpXEvolve.cpp @@ -585,7 +585,7 @@ void WarpX::HandleParticlesAtBoundaries (int step, amrex::Real cur_time, int num amrex::Print() << Utils::TextMsg::Info("re-sorting particles"); } mypc->SortParticlesByBin( - sort_bin_size, sort_particles_for_deposition, sort_idx_type); + sort_bin_size, m_sort_particles_for_deposition, m_sort_idx_type); } } diff --git a/Source/WarpX.H b/Source/WarpX.H index 9200bff2a02..d93460581d5 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -1488,13 +1488,13 @@ private: //! If true, particles will be sorted in the order x -> y -> z -> ppc for faster deposition #if defined(AMREX_USE_CUDA) - bool sort_particles_for_deposition = true; + bool m_sort_particles_for_deposition = true; #else - bool sort_particles_for_deposition = false; + bool m_sort_particles_for_deposition = false; #endif //! Specifies the type of grid used for the above sorting, i.e. cell-centered, nodal, or mixed - amrex::IntVect sort_idx_type = amrex::IntVect(AMREX_D_DECL(0,0,0)); + amrex::IntVect m_sort_idx_type = amrex::IntVect(AMREX_D_DECL(0,0,0)); //! Solve Poisson equation when loading an external magnetic field to clean divergence //! This is useful to remove errors that could lead to non-zero B field divergence diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index f4f06c4a265..d555c140469 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -1377,7 +1377,7 @@ WarpX::ReadParameters () } } - pp_warpx.query("sort_particles_for_deposition",sort_particles_for_deposition); + pp_warpx.query("sort_particles_for_deposition",m_sort_particles_for_deposition); Vector vect_sort_idx_type(AMREX_SPACEDIM,0); const bool sort_idx_type_is_specified = utils::parser::queryArrWithParser( @@ -1385,7 +1385,7 @@ WarpX::ReadParameters () vect_sort_idx_type, 0, AMREX_SPACEDIM); if (sort_idx_type_is_specified){ for (int i=0; i