From 0c77bd4dca5fdafa3e03768d3f0e3d61f626f0c1 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Fri, 28 Jul 2023 22:32:05 +0200 Subject: [PATCH 01/18] remove superfluous includes from LatticeElements (#4131) --- Source/AcceleratorLattice/LatticeElements/HardEdgedPlasmaLens.H | 1 - .../AcceleratorLattice/LatticeElements/HardEdgedPlasmaLens.cpp | 2 -- Source/AcceleratorLattice/LatticeElements/HardEdgedQuadrupole.H | 1 - .../AcceleratorLattice/LatticeElements/HardEdgedQuadrupole.cpp | 2 -- Source/AcceleratorLattice/LatticeElements/HardEdged_K.H | 1 - .../AcceleratorLattice/LatticeElements/LatticeElementBase.cpp | 2 -- 6 files changed, 9 deletions(-) diff --git a/Source/AcceleratorLattice/LatticeElements/HardEdgedPlasmaLens.H b/Source/AcceleratorLattice/LatticeElements/HardEdgedPlasmaLens.H index 9557219c021..43009c0c4ed 100644 --- a/Source/AcceleratorLattice/LatticeElements/HardEdgedPlasmaLens.H +++ b/Source/AcceleratorLattice/LatticeElements/HardEdgedPlasmaLens.H @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/Source/AcceleratorLattice/LatticeElements/HardEdgedPlasmaLens.cpp b/Source/AcceleratorLattice/LatticeElements/HardEdgedPlasmaLens.cpp index 6c87389f159..1c609d697e6 100644 --- a/Source/AcceleratorLattice/LatticeElements/HardEdgedPlasmaLens.cpp +++ b/Source/AcceleratorLattice/LatticeElements/HardEdgedPlasmaLens.cpp @@ -5,8 +5,6 @@ * License: BSD-3-Clause-LBNL */ #include "HardEdgedPlasmaLens.H" -#include "Utils/WarpXUtil.H" -#include "Utils/TextMsg.H" #include #include diff --git a/Source/AcceleratorLattice/LatticeElements/HardEdgedQuadrupole.H b/Source/AcceleratorLattice/LatticeElements/HardEdgedQuadrupole.H index ffbf0c8da98..82f1e860a40 100644 --- a/Source/AcceleratorLattice/LatticeElements/HardEdgedQuadrupole.H +++ b/Source/AcceleratorLattice/LatticeElements/HardEdgedQuadrupole.H @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/Source/AcceleratorLattice/LatticeElements/HardEdgedQuadrupole.cpp b/Source/AcceleratorLattice/LatticeElements/HardEdgedQuadrupole.cpp index 4cff9139521..cdb6502ecef 100644 --- a/Source/AcceleratorLattice/LatticeElements/HardEdgedQuadrupole.cpp +++ b/Source/AcceleratorLattice/LatticeElements/HardEdgedQuadrupole.cpp @@ -5,8 +5,6 @@ * License: BSD-3-Clause-LBNL */ #include "HardEdgedQuadrupole.H" -#include "Utils/WarpXUtil.H" -#include "Utils/TextMsg.H" #include #include diff --git a/Source/AcceleratorLattice/LatticeElements/HardEdged_K.H b/Source/AcceleratorLattice/LatticeElements/HardEdged_K.H index 14d368101f6..35e2dde7a8f 100644 --- a/Source/AcceleratorLattice/LatticeElements/HardEdged_K.H +++ b/Source/AcceleratorLattice/LatticeElements/HardEdged_K.H @@ -10,7 +10,6 @@ #include "Utils/WarpXConst.H" #include -#include /** * \brief Calculate the residence correction, the fraction of the time step the particle diff --git a/Source/AcceleratorLattice/LatticeElements/LatticeElementBase.cpp b/Source/AcceleratorLattice/LatticeElements/LatticeElementBase.cpp index 07f160f1730..6ef318057ff 100644 --- a/Source/AcceleratorLattice/LatticeElements/LatticeElementBase.cpp +++ b/Source/AcceleratorLattice/LatticeElements/LatticeElementBase.cpp @@ -5,8 +5,6 @@ * License: BSD-3-Clause-LBNL */ #include "LatticeElementBase.H" -#include "Utils/WarpXUtil.H" -#include "Utils/TextMsg.H" #include #include From 0de3dcde1231845f9ed190203fa67a0912218efb Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Mon, 31 Jul 2023 14:29:39 -0700 Subject: [PATCH 02/18] AMReX: Weekly Update (#4142) --- .github/workflows/cuda.yml | 2 +- Regression/WarpX-GPU-tests.ini | 2 +- Regression/WarpX-tests.ini | 2 +- cmake/dependencies/AMReX.cmake | 2 +- run_test.sh | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cuda.yml b/.github/workflows/cuda.yml index 0c03d760bf1..176b87ddd6a 100644 --- a/.github/workflows/cuda.yml +++ b/.github/workflows/cuda.yml @@ -110,7 +110,7 @@ jobs: which nvcc || echo "nvcc not in PATH!" git clone https://github.com/AMReX-Codes/amrex.git ../amrex - cd ../amrex && git checkout --detach b75dd9d5279263768c418ce19285f87de37209f9 && cd - + cd ../amrex && git checkout --detach cf8d9f8e233be2ac68aeb65a95e992adfb483939 && cd - make COMP=gcc QED=FALSE USE_MPI=TRUE USE_GPU=TRUE USE_OMP=FALSE USE_PSATD=TRUE USE_CCACHE=TRUE -j 2 build_nvhpc21-11-nvcc: diff --git a/Regression/WarpX-GPU-tests.ini b/Regression/WarpX-GPU-tests.ini index 2d8ff1df445..0123a6691c5 100644 --- a/Regression/WarpX-GPU-tests.ini +++ b/Regression/WarpX-GPU-tests.ini @@ -60,7 +60,7 @@ emailBody = Check https://ccse.lbl.gov/pub/GpuRegressionTesting/WarpX/ for more [AMReX] dir = /home/regtester/git/amrex/ -branch = b75dd9d5279263768c418ce19285f87de37209f9 +branch = cf8d9f8e233be2ac68aeb65a95e992adfb483939 [source] dir = /home/regtester/git/WarpX diff --git a/Regression/WarpX-tests.ini b/Regression/WarpX-tests.ini index 150cebd5ad6..ed1cbaf8ee2 100644 --- a/Regression/WarpX-tests.ini +++ b/Regression/WarpX-tests.ini @@ -59,7 +59,7 @@ emailBody = Check https://ccse.lbl.gov/pub/RegressionTesting/WarpX/ for more det [AMReX] dir = /home/regtester/AMReX_RegTesting/amrex/ -branch = b75dd9d5279263768c418ce19285f87de37209f9 +branch = cf8d9f8e233be2ac68aeb65a95e992adfb483939 [source] dir = /home/regtester/AMReX_RegTesting/warpx diff --git a/cmake/dependencies/AMReX.cmake b/cmake/dependencies/AMReX.cmake index 1055147ccac..e3151870447 100644 --- a/cmake/dependencies/AMReX.cmake +++ b/cmake/dependencies/AMReX.cmake @@ -243,7 +243,7 @@ set(WarpX_amrex_src "" set(WarpX_amrex_repo "https://github.com/AMReX-Codes/amrex.git" CACHE STRING "Repository URI to pull and build AMReX from if(WarpX_amrex_internal)") -set(WarpX_amrex_branch "b75dd9d5279263768c418ce19285f87de37209f9" +set(WarpX_amrex_branch "cf8d9f8e233be2ac68aeb65a95e992adfb483939" CACHE STRING "Repository branch for WarpX_amrex_repo if(WarpX_amrex_internal)") diff --git a/run_test.sh b/run_test.sh index f34f67cb436..7e6ba830ec9 100755 --- a/run_test.sh +++ b/run_test.sh @@ -71,7 +71,7 @@ python3 -m pip install --upgrade -r warpx/Regression/requirements.txt # Clone AMReX and warpx-data git clone https://github.com/AMReX-Codes/amrex.git -cd amrex && git checkout --detach b75dd9d5279263768c418ce19285f87de37209f9 && cd - +cd amrex && git checkout --detach cf8d9f8e233be2ac68aeb65a95e992adfb483939 && cd - # warpx-data contains various required data sets git clone --depth 1 https://github.com/ECP-WarpX/warpx-data.git # openPMD-example-datasets contains various required data sets From fc598a552025ce6e6f460ebf360e87545f60cd3d Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 31 Jul 2023 23:53:49 +0200 Subject: [PATCH 03/18] clang-tidy CI test: add misc-misleading-bidirectional check (#4140) --- .clang-tidy | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-tidy b/.clang-tidy index f988f5d9449..966a52648e2 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -12,6 +12,7 @@ Checks: '-*, -cppcoreguidelines-no-malloc, -cppcoreguidelines-owning-memory, misc-const-correctness, + misc-misleading-bidirectional, modernize-avoid-bind, modernize-concat-nested-namespaces, modernize-use-nullptr, From acf015f95243a063b74e095a9a9890d483fb842c Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 31 Jul 2023 23:58:08 +0200 Subject: [PATCH 04/18] remove WarpX::GetInstance() from PoissonBoundaryHandler::definePhiBCs (#4130) --- Source/FieldSolver/ElectrostaticSolver.H | 3 ++- Source/FieldSolver/ElectrostaticSolver.cpp | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Source/FieldSolver/ElectrostaticSolver.H b/Source/FieldSolver/ElectrostaticSolver.H index 31601ca4212..7de7a1bb57b 100644 --- a/Source/FieldSolver/ElectrostaticSolver.H +++ b/Source/FieldSolver/ElectrostaticSolver.H @@ -8,6 +8,7 @@ #define ELECTROSTATICSOLVER_H_ #include +#include #include #include #include @@ -41,7 +42,7 @@ namespace ElectrostaticSolver { bool has_non_periodic = false; bool phi_EB_only_t = true; - void definePhiBCs (); + void definePhiBCs (const amrex::Geometry& geom); void buildParsers (); void buildParsersEB (); diff --git a/Source/FieldSolver/ElectrostaticSolver.cpp b/Source/FieldSolver/ElectrostaticSolver.cpp index 6089cdbf2b7..3cb01efd31f 100644 --- a/Source/FieldSolver/ElectrostaticSolver.cpp +++ b/Source/FieldSolver/ElectrostaticSolver.cpp @@ -103,7 +103,8 @@ WarpX::AddBoundaryField () // Store the boundary conditions for the field solver if they haven't been // stored yet - if (!m_poisson_boundary_handler.bcs_set) m_poisson_boundary_handler.definePhiBCs(); + if (!m_poisson_boundary_handler.bcs_set) + m_poisson_boundary_handler.definePhiBCs(Geom(0)); // Allocate fields for charge and potential const int num_levels = max_level + 1; @@ -143,7 +144,8 @@ WarpX::AddSpaceChargeField (WarpXParticleContainer& pc) // Store the boundary conditions for the field solver if they haven't been // stored yet - if (!m_poisson_boundary_handler.bcs_set) m_poisson_boundary_handler.definePhiBCs(); + if (!m_poisson_boundary_handler.bcs_set) + m_poisson_boundary_handler.definePhiBCs(Geom(0)); #ifdef WARPX_DIM_RZ WARPX_ALWAYS_ASSERT_WITH_MESSAGE(n_rz_azimuthal_modes == 1, @@ -197,7 +199,8 @@ WarpX::AddSpaceChargeFieldLabFrame () // Store the boundary conditions for the field solver if they haven't been // stored yet - if (!m_poisson_boundary_handler.bcs_set) m_poisson_boundary_handler.definePhiBCs(); + if (!m_poisson_boundary_handler.bcs_set) + m_poisson_boundary_handler.definePhiBCs(Geom(0)); #ifdef WARPX_DIM_RZ WARPX_ALWAYS_ASSERT_WITH_MESSAGE(n_rz_azimuthal_modes == 1, @@ -838,11 +841,9 @@ WarpX::computePhiTriDiagonal (const amrex::VectorParallelCopy(phi1d_mf, 0, 0, 1); } -void ElectrostaticSolver::PoissonBoundaryHandler::definePhiBCs ( ) +void ElectrostaticSolver::PoissonBoundaryHandler::definePhiBCs (const amrex::Geometry& geom) { #ifdef WARPX_DIM_RZ - WarpX& warpx = WarpX::GetInstance(); - auto geom = warpx.Geom(0); if (geom.ProbLo(0) == 0){ lobc[0] = LinOpBCType::Neumann; dirichlet_flag[0] = false; @@ -866,6 +867,7 @@ void ElectrostaticSolver::PoissonBoundaryHandler::definePhiBCs ( ) const int dim_start = 1; #else const int dim_start = 0; + amrex::ignore_unused(geom); #endif for (int idim=dim_start; idim Date: Tue, 1 Aug 2023 00:08:20 +0200 Subject: [PATCH 05/18] Clang tidy CI test: add some modernize checks to clang-tidy CI test (#4133) * Clang Tidy: add several modernize checks * eliminate file included in commit by mistake * fix bug --- .clang-tidy | 18 ++++++++++++++++++ .../Diagnostics/BTD_Plotfile_Header_Impl.cpp | 6 +++--- .../BackTransformFunctor.cpp | 6 ++++-- .../BackTransformParticleFunctor.cpp | 2 +- Source/FieldSolver/ElectrostaticSolver.H | 4 +++- .../CartesianCKCAlgorithm.H | 2 +- .../CartesianNodalAlgorithm.H | 2 +- .../CartesianYeeAlgorithm.H | 2 +- .../CylindricalYeeAlgorithm.H | 2 +- .../PsatdAlgorithmComoving.cpp | 14 +++++++------- Source/Initialization/InjectorMomentum.H | 4 ++-- Source/Initialization/PlasmaInjector.cpp | 2 +- .../BinaryCollision/ParticleCreationFunc.H | 4 ++-- .../QEDInternals/BreitWheelerEngineWrapper.cpp | 7 +++---- .../QEDInternals/QuantumSyncEngineWrapper.cpp | 7 +++---- .../NamedComponentParticleContainer.H | 9 +++++---- Source/Particles/PhysicalParticleContainer.cpp | 4 ++-- Source/Utils/ParticleUtils.cpp | 6 +++--- Source/Utils/WarpXVersion.cpp | 4 ++-- Source/ablastr/utils/SignalHandling.cpp | 11 ++++++----- 20 files changed, 69 insertions(+), 47 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 966a52648e2..28fce3a2d92 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -15,6 +15,20 @@ Checks: '-*, misc-misleading-bidirectional, modernize-avoid-bind, modernize-concat-nested-namespaces, + modernize-deprecated-headers, + modernize-deprecated-ios-base-aliases, + modernize-loop-convert, + modernize-make-shared, + modernize-make-unique, + modernize-pass-by-value, + modernize-raw-string-literal, + modernize-redundant-void-arg, + modernize-replace-auto-ptr, + modernize-replace-disallow-copy-and-assign-macro, + modernize-replace-random-shuffle, + modernize-return-braced-init-list, + modernize-shrink-to-fit, + modernize-unary-static-assert, modernize-use-nullptr, performance-faster-string-find, performance-for-range-copy, @@ -25,4 +39,8 @@ Checks: '-*, readability-non-const-parameter ' +CheckOptions: +- key: modernize-pass-by-value.ValuesOnly + value: 'true' + HeaderFilterRegex: 'Source[a-z_A-Z0-9\/]+\.H$' diff --git a/Source/Diagnostics/BTD_Plotfile_Header_Impl.cpp b/Source/Diagnostics/BTD_Plotfile_Header_Impl.cpp index 9a19e671e46..d530cb091d8 100644 --- a/Source/Diagnostics/BTD_Plotfile_Header_Impl.cpp +++ b/Source/Diagnostics/BTD_Plotfile_Header_Impl.cpp @@ -21,7 +21,7 @@ using namespace amrex::literals; BTDPlotfileHeaderImpl::BTDPlotfileHeaderImpl (std::string const & Headerfile_path) - : m_Header_path(Headerfile_path) + : m_Header_path{Headerfile_path} { } @@ -177,7 +177,7 @@ BTDPlotfileHeaderImpl::WriteHeader () BTDMultiFabHeaderImpl::BTDMultiFabHeaderImpl (std::string const & Headerfile_path) - : m_Header_path(Headerfile_path) + : m_Header_path{Headerfile_path} { } @@ -353,7 +353,7 @@ BTDMultiFabHeaderImpl::CopyVec(amrex::Vector& dst, BTDSpeciesHeaderImpl::BTDSpeciesHeaderImpl (std::string const & Headerfile_path, std::string const& species_name) - : m_Header_path(Headerfile_path), m_species_name(species_name) + : m_Header_path{Headerfile_path}, m_species_name{species_name} { } diff --git a/Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp b/Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp index 9e33a1fc230..3e985f2919c 100644 --- a/Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp +++ b/Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp @@ -36,8 +36,10 @@ BackTransformFunctor::BackTransformFunctor (amrex::MultiFab const * mf_src, int amrex::Vector< std::string > varnames, amrex::Vector< std::string > varnames_fields, const amrex::IntVect crse_ratio - ) - : ComputeDiagFunctor(ncomp, crse_ratio), m_mf_src(mf_src), m_lev(lev), m_num_buffers(num_buffers), m_varnames(varnames), m_varnames_fields(varnames_fields) + ): + ComputeDiagFunctor(ncomp, crse_ratio), + m_mf_src{mf_src}, m_lev{lev}, m_num_buffers{num_buffers}, + m_varnames{std::move(varnames)}, m_varnames_fields{std::move(varnames_fields)} { InitData(); } diff --git a/Source/Diagnostics/ComputeDiagFunctors/BackTransformParticleFunctor.cpp b/Source/Diagnostics/ComputeDiagFunctors/BackTransformParticleFunctor.cpp index 15fa5f9afe7..0442dad7a00 100644 --- a/Source/Diagnostics/ComputeDiagFunctors/BackTransformParticleFunctor.cpp +++ b/Source/Diagnostics/ComputeDiagFunctors/BackTransformParticleFunctor.cpp @@ -71,7 +71,7 @@ BackTransformParticleFunctor::BackTransformParticleFunctor ( WarpXParticleContainer *pc_src, std::string species_name, int num_buffers) - : m_pc_src(pc_src), m_species_name(species_name), m_num_buffers(num_buffers) + : m_pc_src{pc_src}, m_species_name{std::move(species_name)}, m_num_buffers{num_buffers} { InitData(); } diff --git a/Source/FieldSolver/ElectrostaticSolver.H b/Source/FieldSolver/ElectrostaticSolver.H index 7de7a1bb57b..2503156174f 100644 --- a/Source/FieldSolver/ElectrostaticSolver.H +++ b/Source/FieldSolver/ElectrostaticSolver.H @@ -14,6 +14,8 @@ #include #include +#include + namespace ElectrostaticSolver { struct PhiCalculatorEB { @@ -102,7 +104,7 @@ namespace ElectrostaticSolver { public: EBCalcEfromPhiPerLevel(amrex::Vector > e_field) - : m_e_field(e_field) {} + : m_e_field(std::move(e_field)) {} void operator()(amrex::MLMG & mlmg, int const lev) { using namespace amrex::literals; diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianCKCAlgorithm.H b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianCKCAlgorithm.H index e3af70a0d6b..737146f24a3 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianCKCAlgorithm.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianCKCAlgorithm.H @@ -122,7 +122,7 @@ struct CartesianCKCAlgorithm { */ static amrex::IntVect GetMaxGuardCell () { // The ckc solver requires one guard cell in each dimension - return (amrex::IntVect(AMREX_D_DECL(1,1,1))); + return amrex::IntVect{AMREX_D_DECL(1,1,1)}; } /** diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianNodalAlgorithm.H b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianNodalAlgorithm.H index 01d83804bc4..b693ed8785f 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianNodalAlgorithm.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianNodalAlgorithm.H @@ -60,7 +60,7 @@ struct CartesianNodalAlgorithm { */ static amrex::IntVect GetMaxGuardCell () { // The nodal solver requires one guard cell in each dimension - return (amrex::IntVect(AMREX_D_DECL(1,1,1))); + return amrex::IntVect{AMREX_D_DECL(1,1,1)}; } /** diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianYeeAlgorithm.H b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianYeeAlgorithm.H index f2c8553d521..b762530e1a3 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianYeeAlgorithm.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianYeeAlgorithm.H @@ -60,7 +60,7 @@ struct CartesianYeeAlgorithm { */ static amrex::IntVect GetMaxGuardCell () { // The yee solver requires one guard cell in each dimension - return (amrex::IntVect(AMREX_D_DECL(1,1,1))); + return amrex::IntVect{AMREX_D_DECL(1,1,1)}; } /** diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H index ad8194a1376..b6c5c0a8ce8 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H @@ -65,7 +65,7 @@ struct CylindricalYeeAlgorithm { */ static amrex::IntVect GetMaxGuardCell () { // The cylindrical solver requires one guard cell in each dimension - return (amrex::IntVect(AMREX_D_DECL(1,1,1))); + return amrex::IntVect{AMREX_D_DECL(1,1,1)}; } /** Applies the differential operator `1/r * d(rF)/dr`, diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmComoving.cpp b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmComoving.cpp index 37bbc2ca3d7..075645233ec 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmComoving.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmComoving.cpp @@ -32,18 +32,18 @@ PsatdAlgorithmComoving::PsatdAlgorithmComoving (const SpectralKSpace& spectral_k const amrex::Real dt, const bool update_with_rho) // Members initialization - : SpectralBaseAlgorithm(spectral_kspace, dm, spectral_index, norder_x, norder_y, norder_z, grid_type), + : SpectralBaseAlgorithm{spectral_kspace, dm, spectral_index, norder_x, norder_y, norder_z, grid_type}, // Initialize the infinite-order k vectors (the argument n_order = -1 selects // the infinite order option, the argument grid_type=GridType::Staggered is then irrelevant) - kx_vec(spectral_kspace.getModifiedKComponent(dm, 0, -1, GridType::Staggered)), + kx_vec{spectral_kspace.getModifiedKComponent(dm, 0, -1, GridType::Staggered)}, #if defined(WARPX_DIM_3D) - ky_vec(spectral_kspace.getModifiedKComponent(dm, 1, -1, GridType::Staggered)), - kz_vec(spectral_kspace.getModifiedKComponent(dm, 2, -1, GridType::Staggered)), + ky_vec{spectral_kspace.getModifiedKComponent(dm, 1, -1, GridType::Staggered)}, + kz_vec{spectral_kspace.getModifiedKComponent(dm, 2, -1, GridType::Staggered)}, #else - kz_vec(spectral_kspace.getModifiedKComponent(dm, 1, -1, GridType::Staggered)), + kz_vec{spectral_kspace.getModifiedKComponent(dm, 1, -1, GridType::Staggered)}, #endif - m_v_comoving(v_comoving), - m_dt(dt) + m_v_comoving{v_comoving}, + m_dt{dt} { amrex::ignore_unused(update_with_rho); diff --git a/Source/Initialization/InjectorMomentum.H b/Source/Initialization/InjectorMomentum.H index aeeff83ca51..87b81381ce9 100644 --- a/Source/Initialization/InjectorMomentum.H +++ b/Source/Initialization/InjectorMomentum.H @@ -331,7 +331,7 @@ struct InjectorMomentumBoltzmann { using namespace amrex::literals; amrex::Real u[3]; - for (int idim = 0; idim < 3; ++idim) u[idim] = 0.0_rt; + for (auto& el : u) el = 0.0_rt; const amrex::Real beta = velocity(x,y,z); int const dir = velocity.direction(); const amrex::Real gamma = static_cast(1._rt/sqrt(1._rt-beta*beta)); @@ -432,7 +432,7 @@ struct InjectorMomentumJuttner { using namespace amrex::literals; amrex::Real u[3]; - for (int idim = 0; idim < 3; ++idim) u[idim] = 0.0_rt; + for (auto& el : u) el = 0.0_rt; amrex::Real const beta = velocity(x,y,z); int const dir = velocity.direction(); amrex::Real const gamma = static_cast(1._rt/sqrt(1._rt-beta*beta)); diff --git a/Source/Initialization/PlasmaInjector.cpp b/Source/Initialization/PlasmaInjector.cpp index 1ed86864710..4149ca4bcac 100644 --- a/Source/Initialization/PlasmaInjector.cpp +++ b/Source/Initialization/PlasmaInjector.cpp @@ -55,7 +55,7 @@ namespace { } PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) - : species_id(ispecies), species_name(name) + : species_id{ispecies}, species_name{name} { using namespace amrex::literals; diff --git a/Source/Particles/Collision/BinaryCollision/ParticleCreationFunc.H b/Source/Particles/Collision/BinaryCollision/ParticleCreationFunc.H index 085adcc8860..0868e31314a 100644 --- a/Source/Particles/Collision/BinaryCollision/ParticleCreationFunc.H +++ b/Source/Particles/Collision/BinaryCollision/ParticleCreationFunc.H @@ -113,7 +113,7 @@ public: const amrex::ParticleReal* AMREX_RESTRICT p_pair_reaction_weight ) const { - if (n_total_pairs == 0) return amrex::Vector(m_num_product_species, 0); + if (n_total_pairs == 0) return {m_num_product_species, 0}; // Compute offset array and allocate memory for the produced species amrex::Gpu::DeviceVector offsets(n_total_pairs); @@ -297,7 +297,7 @@ public: const amrex::ParticleReal* /*p_pair_reaction_weight*/ ) const { - return amrex::Vector(); + return {}; } }; diff --git a/Source/Particles/ElementaryProcess/QEDInternals/BreitWheelerEngineWrapper.cpp b/Source/Particles/ElementaryProcess/QEDInternals/BreitWheelerEngineWrapper.cpp index 249e35f6fc8..12f479d32ed 100644 --- a/Source/Particles/ElementaryProcess/QEDInternals/BreitWheelerEngineWrapper.cpp +++ b/Source/Particles/ElementaryProcess/QEDInternals/BreitWheelerEngineWrapper.cpp @@ -38,7 +38,7 @@ namespace pxr_sr = picsar::multi_physics::utils::serialization; BreitWheelerGetOpticalDepth BreitWheelerEngine::build_optical_depth_functor () const { - return BreitWheelerGetOpticalDepth(); + return {}; } BreitWheelerEvolveOpticalDepth @@ -46,8 +46,7 @@ BreitWheelerEngine::build_evolve_functor () const { AMREX_ALWAYS_ASSERT(m_lookup_tables_initialized); - return BreitWheelerEvolveOpticalDepth(m_dndt_table.get_view(), - m_bw_minimum_chi_phot); + return {m_dndt_table.get_view(), m_bw_minimum_chi_phot}; } BreitWheelerGeneratePairs @@ -55,7 +54,7 @@ BreitWheelerEngine::build_pair_functor () const { AMREX_ALWAYS_ASSERT(m_lookup_tables_initialized); - return BreitWheelerGeneratePairs(m_pair_prod_table.get_view()); + return {m_pair_prod_table.get_view()}; } bool BreitWheelerEngine::are_lookup_tables_initialized () const diff --git a/Source/Particles/ElementaryProcess/QEDInternals/QuantumSyncEngineWrapper.cpp b/Source/Particles/ElementaryProcess/QEDInternals/QuantumSyncEngineWrapper.cpp index 280c1cfd426..c9bede89167 100644 --- a/Source/Particles/ElementaryProcess/QEDInternals/QuantumSyncEngineWrapper.cpp +++ b/Source/Particles/ElementaryProcess/QEDInternals/QuantumSyncEngineWrapper.cpp @@ -38,22 +38,21 @@ namespace pxr_sr = picsar::multi_physics::utils::serialization; QuantumSynchrotronGetOpticalDepth QuantumSynchrotronEngine::build_optical_depth_functor () { - return QuantumSynchrotronGetOpticalDepth(); + return {}; } QuantumSynchrotronEvolveOpticalDepth QuantumSynchrotronEngine::build_evolve_functor () { AMREX_ALWAYS_ASSERT(m_lookup_tables_initialized); - return QuantumSynchrotronEvolveOpticalDepth(m_dndt_table.get_view(), - m_qs_minimum_chi_part); + return {m_dndt_table.get_view(), m_qs_minimum_chi_part}; } QuantumSynchrotronPhotonEmission QuantumSynchrotronEngine::build_phot_em_functor () { AMREX_ALWAYS_ASSERT(m_lookup_tables_initialized); - return QuantumSynchrotronPhotonEmission(m_phot_em_table.get_view()); + return {m_phot_em_table.get_view()}; } diff --git a/Source/Particles/NamedComponentParticleContainer.H b/Source/Particles/NamedComponentParticleContainer.H index 7b2ac6f63b6..5cf1c06b6b1 100644 --- a/Source/Particles/NamedComponentParticleContainer.H +++ b/Source/Particles/NamedComponentParticleContainer.H @@ -15,6 +15,7 @@ #include #include +#include /** Particle Attributes stored in amrex::ParticleContainer's struct of array */ @@ -89,10 +90,10 @@ public: std::map p_rcomps, std::map p_ricomps) : amrex::ParticleContainer<0,0,PIdx::nattribs,0,T_Allocator>(std::move(pc)), - particle_comps(p_comps), - particle_icomps(p_icomps), - particle_runtime_comps(p_rcomps), - particle_runtime_icomps(p_ricomps) {} + particle_comps(std::move(p_comps)), + particle_icomps(std::move(p_icomps)), + particle_runtime_comps(std::move(p_rcomps)), + particle_runtime_icomps(std::move(p_ricomps)) {} /** Copy constructor for NamedComponentParticleContainer */ NamedComponentParticleContainer ( const NamedComponentParticleContainer &) = delete; diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 60578d57f8f..0ed851e9fd5 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -2897,13 +2897,13 @@ PhysicalParticleContainer::getIonizationFunc (const WarpXParIter& pti, { WARPX_PROFILE("PhysicalParticleContainer::getIonizationFunc()"); - return IonizationFilterFunc(pti, lev, ngEB, Ex, Ey, Ez, Bx, By, Bz, + return {pti, lev, ngEB, Ex, Ey, Ez, Bx, By, Bz, ionization_energies.dataPtr(), adk_prefactor.dataPtr(), adk_exp_prefactor.dataPtr(), adk_power.dataPtr(), particle_icomps["ionizationLevel"], - ion_atomic_number); + ion_atomic_number}; } PlasmaInjector* PhysicalParticleContainer::GetPlasmaInjector () diff --git a/Source/Utils/ParticleUtils.cpp b/Source/Utils/ParticleUtils.cpp index 89dba1e1de0..60e04f12b86 100644 --- a/Source/Utils/ParticleUtils.cpp +++ b/Source/Utils/ParticleUtils.cpp @@ -53,12 +53,12 @@ namespace ParticleUtils { ParticleBins bins; bins.build(np, particle_ptr, cbx, // Pass lambda function that returns the cell index - [=] AMREX_GPU_DEVICE (const ParticleType& p) noexcept -> IntVect + [=] AMREX_GPU_DEVICE (const ParticleType& p) noexcept { - return IntVect(AMREX_D_DECL( + return IntVect{AMREX_D_DECL( static_cast((p.pos(0)-plo[0])*dxi[0] - lo.x), static_cast((p.pos(1)-plo[1])*dxi[1] - lo.y), - static_cast((p.pos(2)-plo[2])*dxi[2] - lo.z))); + static_cast((p.pos(2)-plo[2])*dxi[2] - lo.z))}; }); return bins; diff --git a/Source/Utils/WarpXVersion.cpp b/Source/Utils/WarpXVersion.cpp index 0e207614563..43978a4795a 100644 --- a/Source/Utils/WarpXVersion.cpp +++ b/Source/Utils/WarpXVersion.cpp @@ -18,7 +18,7 @@ WarpX::Version () version = std::string(WARPX_GIT_VERSION); #endif if( version.empty() ) - return std::string("Unknown"); + return {"Unknown"}; else return version; } @@ -31,7 +31,7 @@ WarpX::PicsarVersion () version = std::string(PICSAR_GIT_VERSION); #endif if( version.empty() ) - return std::string("Unknown"); + return {"Unknown"}; else return version; } diff --git a/Source/ablastr/utils/SignalHandling.cpp b/Source/ablastr/utils/SignalHandling.cpp index 0fdbd834e75..feaf69d002f 100644 --- a/Source/ablastr/utils/SignalHandling.cpp +++ b/Source/ablastr/utils/SignalHandling.cpp @@ -16,7 +16,7 @@ // For sigaction() et al. #if defined(__linux__) || defined(__APPLE__) -# include +# include #endif namespace ablastr::utils { @@ -121,8 +121,8 @@ SignalHandling::InitSignalHandling () signal_received_flags[signal_number] = false; bool signal_active = false; - for (int signal_request = 0; signal_request < SIGNAL_REQUESTS_SIZE; ++signal_request) { - signal_active |= signal_conf_requests[signal_request][signal_number]; + for (const auto& request : signal_conf_requests) { + signal_active |= request[signal_number]; } if (signal_active) { // at least one signal action is configured @@ -162,8 +162,9 @@ SignalHandling::CheckSignals () const bool signal_received = signal_received_flags[signal_number].exchange(false); if (signal_received) { - for (int signal_request = 0; signal_request < SIGNAL_REQUESTS_SIZE; ++signal_request) { - signal_actions_requested[signal_request] |= signal_conf_requests[signal_request][signal_number]; + int signal_request = 0; + for (const auto& request : signal_conf_requests) { + signal_actions_requested[signal_request++] |= request[signal_number]; } } } From 82b33d71743a60550884defdae3f05632859f081 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 1 Aug 2023 00:08:52 +0200 Subject: [PATCH 06/18] add a couple of performance checks to clang-tidy CI test (#4128) --- .clang-tidy | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.clang-tidy b/.clang-tidy index 28fce3a2d92..64dba091de0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -36,6 +36,8 @@ Checks: '-*, performance-inefficient-algorithm, performance-inefficient-string-concatenation, performance-inefficient-vector-operation, + performance-move-const-arg, + performance-move-constructor-init, readability-non-const-parameter ' From c25afd18c2d308ca4521c24fe3094f71a6b17e97 Mon Sep 17 00:00:00 2001 From: Grant Johnson <69021085+johnson452@users.noreply.github.com> Date: Mon, 31 Jul 2023 15:11:31 -0700 Subject: [PATCH 07/18] Update docs to mention updated signal handling for SIGILL (#4134) * Update docs to mention updated signal handling for SIGILL * Updated string --- Docs/source/usage/parameters.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Docs/source/usage/parameters.rst b/Docs/source/usage/parameters.rst index faf300092a2..0ad5d03e595 100644 --- a/Docs/source/usage/parameters.rst +++ b/Docs/source/usage/parameters.rst @@ -195,8 +195,7 @@ We follow the same naming, but remove the ``SIG`` prefix, e.g., the WarpX signal The ``TSTP`` (terminal stop) command is sent interactively from ``Ctrl+Z`` to temporarily send a process to sleep (until send in the background with commands such as ``bg`` or continued with ``fg``), overwriting it would thus disable that functionality. The signals ``KILL`` and ``STOP`` cannot be used. - The ``FPE`` signal should not be overwritten in WarpX, as it is `controlled by AMReX `__ for :ref:`debug workflows that catch invalid floating-point operations `. - + The ``FPE`` and ``ILL`` signals should not be overwritten in WarpX, as they are `controlled by AMReX `__ for :ref:`debug workflows that catch invalid floating-point operations `. .. tip:: For example, the following logic can be added to `Slurm batch scripts `__ (`signal name to number mapping here `__) to gracefully shut down 6 min prior to walltime. From 72fcddb19d7523308285cb0fdf15460076f34993 Mon Sep 17 00:00:00 2001 From: Grant Johnson <69021085+johnson452@users.noreply.github.com> Date: Mon, 31 Jul 2023 15:11:53 -0700 Subject: [PATCH 08/18] Update docs to mention updated signal handling for SIGILL (#4134) * Update docs to mention updated signal handling for SIGILL * Updated string From 0c570185ca98ad5024f90731176e24d52ad76b16 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 1 Aug 2023 00:12:50 +0200 Subject: [PATCH 09/18] add mpi checks to clang-tidy CI test (#4135) --- .clang-tidy | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-tidy b/.clang-tidy index 64dba091de0..8436124975f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -30,6 +30,7 @@ Checks: '-*, modernize-shrink-to-fit, modernize-unary-static-assert, modernize-use-nullptr, + mpi-*, performance-faster-string-find, performance-for-range-copy, performance-implicit-conversion-in-loop, From 9867ccb4d8e00d4b331c7446253f4d2031e58952 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 1 Aug 2023 00:17:16 +0200 Subject: [PATCH 10/18] move CheckGuardCells(amrex::MultiFab const& mf) function into anonymous namespace into warpx_init_data (#4141) --- Source/Initialization/WarpXInitData.cpp | 73 ++++++++++++++----------- Source/WarpX.H | 6 -- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index d5a8bfed052..3f37ef5416f 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -82,6 +82,30 @@ using namespace amrex; +namespace +{ + /** + * \brief Check that the number of guard cells is smaller than the number of valid cells, + * for a given MultiFab, and abort otherwise. + */ + void CheckGuardCells(amrex::MultiFab const& mf) + { + for (amrex::MFIter mfi(mf); mfi.isValid(); ++mfi) + { + const amrex::IntVect vc = mfi.validbox().enclosedCells().size(); + const amrex::IntVect gc = mf.nGrowVect(); + + std::stringstream ss_msg; + ss_msg << "MultiFab " << mf.tags()[1].c_str() << ":" << + " the number of guard cells " << gc << + " is larger than or equal to the number of valid cells " + << vc << ", please reduce the number of guard cells" << + " or increase the grid size by changing domain decomposition."; + WARPX_ALWAYS_ASSERT_WITH_MESSAGE(vc.allGT(gc), ss_msg.str()); + } + } +} + void WarpX::PostProcessBaseGrids (BoxArray& ba0) const { @@ -1177,30 +1201,30 @@ void WarpX::CheckGuardCells() { for (int dim = 0; dim < 3; ++dim) { - CheckGuardCells(*Efield_fp[lev][dim]); - CheckGuardCells(*Bfield_fp[lev][dim]); - CheckGuardCells(*current_fp[lev][dim]); + ::CheckGuardCells(*Efield_fp[lev][dim]); + ::CheckGuardCells(*Bfield_fp[lev][dim]); + ::CheckGuardCells(*current_fp[lev][dim]); if (WarpX::fft_do_time_averaging) { - CheckGuardCells(*Efield_avg_fp[lev][dim]); - CheckGuardCells(*Bfield_avg_fp[lev][dim]); + ::CheckGuardCells(*Efield_avg_fp[lev][dim]); + ::CheckGuardCells(*Bfield_avg_fp[lev][dim]); } } if (rho_fp[lev]) { - CheckGuardCells(*rho_fp[lev]); + ::CheckGuardCells(*rho_fp[lev]); } if (F_fp[lev]) { - CheckGuardCells(*F_fp[lev]); + ::CheckGuardCells(*F_fp[lev]); } if (G_fp[lev]) { - CheckGuardCells(*G_fp[lev]); + ::CheckGuardCells(*G_fp[lev]); } // MultiFabs on coarse patch @@ -1208,52 +1232,35 @@ void WarpX::CheckGuardCells() { for (int dim = 0; dim < 3; ++dim) { - CheckGuardCells(*Efield_cp[lev][dim]); - CheckGuardCells(*Bfield_cp[lev][dim]); - CheckGuardCells(*current_cp[lev][dim]); + ::CheckGuardCells(*Efield_cp[lev][dim]); + ::CheckGuardCells(*Bfield_cp[lev][dim]); + ::CheckGuardCells(*current_cp[lev][dim]); if (WarpX::fft_do_time_averaging) { - CheckGuardCells(*Efield_avg_cp[lev][dim]); - CheckGuardCells(*Bfield_avg_cp[lev][dim]); + ::CheckGuardCells(*Efield_avg_cp[lev][dim]); + ::CheckGuardCells(*Bfield_avg_cp[lev][dim]); } } if (rho_cp[lev]) { - CheckGuardCells(*rho_cp[lev]); + ::CheckGuardCells(*rho_cp[lev]); } if (F_cp[lev]) { - CheckGuardCells(*F_cp[lev]); + ::CheckGuardCells(*F_cp[lev]); } if (G_cp[lev]) { - CheckGuardCells(*G_cp[lev]); + ::CheckGuardCells(*G_cp[lev]); } } } } -void WarpX::CheckGuardCells(amrex::MultiFab const& mf) -{ - for (amrex::MFIter mfi(mf); mfi.isValid(); ++mfi) - { - const amrex::IntVect vc = mfi.validbox().enclosedCells().size(); - const amrex::IntVect gc = mf.nGrowVect(); - - std::stringstream ss_msg; - ss_msg << "MultiFab " << mf.tags()[1].c_str() << ":" << - " the number of guard cells " << gc << - " is larger than or equal to the number of valid cells " - << vc << ", please reduce the number of guard cells" << - " or increase the grid size by changing domain decomposition."; - WARPX_ALWAYS_ASSERT_WITH_MESSAGE(vc.allGT(gc), ss_msg.str()); - } -} - void WarpX::InitializeEBGridData (int lev) { #ifdef AMREX_USE_EB diff --git a/Source/WarpX.H b/Source/WarpX.H index 396c2bed98c..c595ef5958d 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -1240,12 +1240,6 @@ private: */ void CheckGuardCells(); - /** - * \brief Check that the number of guard cells is smaller than the number of valid cells, - * for a given MultiFab, and abort otherwise. - */ - void CheckGuardCells(amrex::MultiFab const& mf); - /** * \brief Checks for known numerical issues involving different WarpX modules */ From 31199f61b1526f61e64d9ff3122298c08d50b81f Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 1 Aug 2023 03:29:15 +0200 Subject: [PATCH 11/18] Remove WarpX::GetInstance call from ParserFilter functor (#4132) * remove WarpX::GetInstance from FilterFunctor * fix bug according to NeilZaim's suggestion * Time Doc Strings: Coarsest Level --- .../FlushFormats/FlushFormatOpenPMD.cpp | 2 +- .../FlushFormats/FlushFormatPlotfile.H | 2 ++ .../FlushFormats/FlushFormatPlotfile.cpp | 6 +++--- Source/Diagnostics/WarpXOpenPMD.H | 1 + Source/Diagnostics/WarpXOpenPMD.cpp | 5 +++-- Source/Particles/Filter/FilterFunctors.H | 18 +++++++++--------- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.cpp b/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.cpp index de7a5a5cba7..2c7e5350aa6 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.cpp @@ -158,7 +158,7 @@ FlushFormatOpenPMD::WriteToFile ( varnames, mf, geom, output_levels, output_iteration, time, isBTD, full_BTD_snapshot); // particles: all (reside only on locally finest level) - m_OpenPMDPlotWriter->WriteOpenPMDParticles(particle_diags, use_pinned_pc, isBTD, isLastBTDFlush, totalParticlesFlushedAlready); + m_OpenPMDPlotWriter->WriteOpenPMDParticles(particle_diags, time, use_pinned_pc, isBTD, isLastBTDFlush, totalParticlesFlushedAlready); // signal that no further updates will be written to this iteration m_OpenPMDPlotWriter->CloseStep(isBTD, isLastBTDFlush); diff --git a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.H b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.H index 744ef2e4b13..429bc4823e2 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.H +++ b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.H @@ -48,10 +48,12 @@ public: /** \brief Write particles data to file. * \param[in] filename name of output directory * \param[in] particle_diags Each element of this vector handles output of 1 species. + * \param[in] time the simulation time on the coarsest level * \param[in] isBTD whether this is a back-transformed diagnostic */ void WriteParticles(const std::string& filename, const amrex::Vector& particle_diags, + const amrex::Real time, bool isBTD = false) const; ~FlushFormatPlotfile() {} diff --git a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp index b543f19e912..0cf09ebf90b 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp @@ -99,7 +99,7 @@ FlushFormatPlotfile::WriteToFile ( WriteAllRawFields(plot_raw_fields, nlev, filename, plot_raw_fields_guards); - WriteParticles(filename, particle_diags, isBTD); + WriteParticles(filename, particle_diags, time, isBTD); WriteJobInfo(filename); @@ -339,7 +339,7 @@ FlushFormatPlotfile::WriteWarpXHeader( void FlushFormatPlotfile::WriteParticles(const std::string& dir, const amrex::Vector& particle_diags, - bool isBTD) const + const amrex::Real time, bool isBTD) const { for (auto& part_diag : particle_diags) { @@ -388,7 +388,7 @@ FlushFormatPlotfile::WriteParticles(const std::string& dir, ParserFilter parser_filter(part_diag.m_do_parser_filter, utils::parser::compileParser (part_diag.m_particle_filter_parser.get()), - pc->getMass()); + pc->getMass(), time); parser_filter.m_units = InputUnits::SI; GeometryFilter const geometry_filter(part_diag.m_do_geom_filter, part_diag.m_diag_domain); diff --git a/Source/Diagnostics/WarpXOpenPMD.H b/Source/Diagnostics/WarpXOpenPMD.H index aaa0acba88b..7cc5eda903c 100644 --- a/Source/Diagnostics/WarpXOpenPMD.H +++ b/Source/Diagnostics/WarpXOpenPMD.H @@ -136,6 +136,7 @@ public: void WriteOpenPMDParticles ( const amrex::Vector& particle_diags, + const amrex::Real time, const bool use_pinned_pc = false, const bool isBTD = false, const bool isLastBTDFlush = false, diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index 4b463415f06..b68cd7232b2 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -514,7 +514,8 @@ WarpXOpenPMDPlot::Init (openPMD::Access access, bool isBTD) void WarpXOpenPMDPlot::WriteOpenPMDParticles (const amrex::Vector& particle_diags, - const bool use_pinned_pc, const bool isBTD, const bool isLastBTDFlush, + const amrex::Real time, const bool use_pinned_pc, + const bool isBTD, const bool isLastBTDFlush, const amrex::Vector& totalParticlesFlushedAlready) { WARPX_PROFILE("WarpXOpenPMDPlot::WriteOpenPMDParticles()"); @@ -575,7 +576,7 @@ WarpXOpenPMDPlot::WriteOpenPMDParticles (const amrex::Vector& part ParserFilter parser_filter(particle_diags[i].m_do_parser_filter, utils::parser::compileParser (particle_diags[i].m_particle_filter_parser.get()), - pc->getMass()); + pc->getMass(), time); parser_filter.m_units = InputUnits::SI; GeometryFilter const geometry_filter(particle_diags[i].m_do_geom_filter, particle_diags[i].m_diag_domain); diff --git a/Source/Particles/Filter/FilterFunctors.H b/Source/Particles/Filter/FilterFunctors.H index c029087b997..e80b0be7d51 100644 --- a/Source/Particles/Filter/FilterFunctors.H +++ b/Source/Particles/Filter/FilterFunctors.H @@ -10,7 +10,6 @@ #include "Particles/Pusher/GetAndSetPosition.H" #include "Particles/WarpXParticleContainer.H" #include "Utils/WarpXConst.H" -#include "WarpX.H" #include #include @@ -91,14 +90,15 @@ struct ParserFilter * \param a_is_active whether the test is active * \param a_filter_parser parser taking t, x, y, z, ux, uy, and uz, and returning a boolean for selected particle * \param a_mass mass of the particle species + * \param time simulation time on the coarsest level */ ParserFilter(bool a_is_active, amrex::ParserExecutor<7> const& a_filter_parser, - amrex::Real a_mass) - : m_is_active(a_is_active), m_function_partparser(a_filter_parser), m_mass(a_mass) - { - m_t = WarpX::GetInstance().gett_new(0); - m_units = InputUnits::WarpX; - } + const amrex::Real a_mass, const amrex::Real time): + m_is_active{a_is_active}, + m_function_partparser{a_filter_parser}, + m_mass{a_mass}, + m_t{time}, + m_units{InputUnits::WarpX}{} /** * \brief return 1 if the particle is selected by the parser @@ -136,10 +136,10 @@ private: public: /** Parser function with 7 input variables, t,x,y,z,ux,uy,uz */ amrex::ParserExecutor<7> const m_function_partparser; - /** Store physical time. */ - amrex::ParticleReal m_t; /** Mass of particle species */ amrex::ParticleReal m_mass; + /** Store physical time on the coarsest level. */ + amrex::ParticleReal m_t; /** keep track of momentum units particles will come in with **/ InputUnits m_units; }; From 862df560823cedaf08b67cbee527ed9bedc79683 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 1 Aug 2023 04:07:07 +0200 Subject: [PATCH 12/18] Move GotoNextLine helper function into ablastr (#4139) * move GotoNextLine helper function into ablastr * fixed bug * Update Source/ablastr/utils/text/StreamUtils.H Co-authored-by: Axel Huebl --- .../Diagnostics/BTD_Plotfile_Header_Impl.cpp | 9 +++---- Source/Diagnostics/ParticleIO.cpp | 13 +++++----- Source/Diagnostics/WarpXIO.cpp | 22 +++++++---------- Source/WarpX.H | 2 -- Source/ablastr/utils/text/CMakeLists.txt | 1 + Source/ablastr/utils/text/Make.package | 1 + Source/ablastr/utils/text/StreamUtils.H | 24 +++++++++++++++++++ Source/ablastr/utils/text/StreamUtils.cpp | 17 +++++++++++++ 8 files changed, 63 insertions(+), 26 deletions(-) create mode 100644 Source/ablastr/utils/text/StreamUtils.H create mode 100644 Source/ablastr/utils/text/StreamUtils.cpp diff --git a/Source/Diagnostics/BTD_Plotfile_Header_Impl.cpp b/Source/Diagnostics/BTD_Plotfile_Header_Impl.cpp index d530cb091d8..9f4976c20cb 100644 --- a/Source/Diagnostics/BTD_Plotfile_Header_Impl.cpp +++ b/Source/Diagnostics/BTD_Plotfile_Header_Impl.cpp @@ -7,7 +7,8 @@ #include "BTD_Plotfile_Header_Impl.H" #include "Utils/TextMsg.H" -#include "WarpX.H" + +#include #include #include @@ -71,7 +72,7 @@ BTDPlotfileHeaderImpl::ReadHeaderData () for (int idim = 0; idim < m_spacedim; ++idim) { is >> m_prob_hi[idim]; } - WarpX::GotoNextLine(is); + ablastr::utils::text::goto_next_line(is); is >> m_prob_domain; @@ -232,7 +233,7 @@ BTDMultiFabHeaderImpl::ReadMultiFabHeader () for (int ifab = 0; ifab < m_ba.size(); ++ifab) { is >> m_FabOnDiskPrefix[ifab] >> m_fabname[ifab] >> m_fabhead[ifab]; } - WarpX::GotoNextLine(is); + ablastr::utils::text::goto_next_line(is); char ch; is >> in_hash >> ch >> in_hash; m_minval.resize(m_ba.size()); @@ -243,7 +244,7 @@ BTDMultiFabHeaderImpl::ReadMultiFabHeader () if( ch != ',' ) amrex::Error("Expected a ',' got something else"); } } - WarpX::GotoNextLine(is); + ablastr::utils::text::goto_next_line(is); is >> in_hash >> ch >> in_hash; m_maxval.resize(m_ba.size()); for (int ifab = 0; ifab < m_ba.size(); ++ifab) { diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 69df9957a65..c10e3468a71 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -17,7 +17,8 @@ #include "Utils/TextMsg.H" #include "Utils/WarpXConst.H" #include "Utils/WarpXProfilerWrapper.H" -#include "WarpX.H" + +#include #include #include @@ -48,7 +49,7 @@ LaserParticleContainer::ReadHeader (std::istream& is) m_updated_position.resize(3); for (int i = 0; i < 3; ++i) { is >> m_updated_position[i]; - WarpX::GotoNextLine(is); + ablastr::utils::text::goto_next_line(is); } } } @@ -72,7 +73,7 @@ RigidInjectedParticleContainer::ReadHeader (std::istream& is) // Read quantities that are specific to rigid-injected species int nlevs; is >> nlevs; - WarpX::GotoNextLine(is); + ablastr::utils::text::goto_next_line(is); AMREX_ASSERT(zinject_plane_levels.size() == 0); @@ -81,10 +82,10 @@ RigidInjectedParticleContainer::ReadHeader (std::istream& is) amrex::Real zinject_plane_tmp; is >> zinject_plane_tmp; zinject_plane_levels.push_back(zinject_plane_tmp); - WarpX::GotoNextLine(is); + ablastr::utils::text::goto_next_line(is); } is >> vzbeam_ave_boosted; - WarpX::GotoNextLine(is); + ablastr::utils::text::goto_next_line(is); } void @@ -107,7 +108,7 @@ void PhysicalParticleContainer::ReadHeader (std::istream& is) { is >> charge >> mass; - WarpX::GotoNextLine(is); + ablastr::utils::text::goto_next_line(is); } void diff --git a/Source/Diagnostics/WarpXIO.cpp b/Source/Diagnostics/WarpXIO.cpp index aeaf8530438..abc5c4f4548 100644 --- a/Source/Diagnostics/WarpXIO.cpp +++ b/Source/Diagnostics/WarpXIO.cpp @@ -19,6 +19,7 @@ #include "Diagnostics/MultiDiagnostics.H" #include +#include #ifdef AMREX_USE_SENSEI_INSITU # include @@ -50,13 +51,6 @@ namespace const std::string level_prefix {"Level_"}; } -void -WarpX::GotoNextLine (std::istream& is) -{ - constexpr std::streamsize bl_ignore_max { 100000 }; - is.ignore(bl_ignore_max, '\n'); -} - amrex::DistributionMapping WarpX::GetRestartDMap (const std::string& chkfile, const amrex::BoxArray& ba, int lev) const { std::string DMFileName = chkfile; @@ -116,7 +110,7 @@ WarpX::InitFromCheckpoint () int nlevs; is >> nlevs; - GotoNextLine(is); + ablastr::utils::text::goto_next_line(is); finest_level = nlevs-1; std::getline(is, line); @@ -171,10 +165,10 @@ WarpX::InitFromCheckpoint () amrex::Real moving_window_x_checkpoint; is >> moving_window_x_checkpoint; - GotoNextLine(is); + ablastr::utils::text::goto_next_line(is); is >> is_synchronized; - GotoNextLine(is); + ablastr::utils::text::goto_next_line(is); amrex::Vector prob_lo( AMREX_SPACEDIM ); std::getline(is, line); @@ -203,7 +197,7 @@ WarpX::InitFromCheckpoint () for (int lev = 0; lev < nlevs; ++lev) { BoxArray ba; ba.readFrom(is); - GotoNextLine(is); + ablastr::utils::text::goto_next_line(is); const DistributionMapping dm = GetRestartDMap(restart_chkfile, ba, lev); SetBoxArray(lev, ba); SetDistributionMap(lev, dm); @@ -215,19 +209,19 @@ WarpX::InitFromCheckpoint () for (int i=0; i> mypc->GetParticleContainer(i).m_current_injection_position; - GotoNextLine(is); + ablastr::utils::text::goto_next_line(is); } int do_moving_window_before_restart; is >> do_moving_window_before_restart; - GotoNextLine(is); + ablastr::utils::text::goto_next_line(is); if (do_moving_window_before_restart) { moving_window_x = moving_window_x_checkpoint; } is >> time_of_last_gal_shift; - GotoNextLine(is); + ablastr::utils::text::goto_next_line(is); auto & warpx = WarpX::GetInstance(); diff --git a/Source/WarpX.H b/Source/WarpX.H index c595ef5958d..f67a007d238 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -109,8 +109,6 @@ public: amrex::Real external_field=0.0, bool useparser = false, amrex::ParserExecutor<3> const& field_parser={}); - static void GotoNextLine (std::istream& is); - //! Author of an input file / simulation setup static std::string authors; diff --git a/Source/ablastr/utils/text/CMakeLists.txt b/Source/ablastr/utils/text/CMakeLists.txt index 03725694211..754ec285986 100644 --- a/Source/ablastr/utils/text/CMakeLists.txt +++ b/Source/ablastr/utils/text/CMakeLists.txt @@ -2,6 +2,7 @@ foreach(D IN LISTS WarpX_DIMS) warpx_set_suffix_dims(SD ${D}) target_sources(ablastr_${SD} PRIVATE + StreamUtils.cpp StringUtils.cpp ) endforeach() diff --git a/Source/ablastr/utils/text/Make.package b/Source/ablastr/utils/text/Make.package index 1cd8ee593b9..9a47977bd1f 100644 --- a/Source/ablastr/utils/text/Make.package +++ b/Source/ablastr/utils/text/Make.package @@ -1,3 +1,4 @@ +CEXE_sources += StreamUtils.cpp CEXE_sources += StringUtils.cpp VPATH_LOCATIONS += $(WARPX_HOME)/Source/ablastr/utils/text diff --git a/Source/ablastr/utils/text/StreamUtils.H b/Source/ablastr/utils/text/StreamUtils.H new file mode 100644 index 00000000000..b797c2fb63f --- /dev/null +++ b/Source/ablastr/utils/text/StreamUtils.H @@ -0,0 +1,24 @@ +/* Copyright 2023 + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ + +#ifndef ABLASTR_UTILS_TEXT_STREAMUTILS_H_ +#define ABLASTR_UTILS_TEXT_STREAMUTILS_H_ + +#include + +namespace ablastr::utils::text +{ + /** + * \brief This function drops the rest of the current line of + * the input stream "is" + * + * @param[in,out] is the input stream + */ + void goto_next_line (std::istream& is); +} + +#endif //ABLASTR_UTILS_TEXT_STREAMUTILS_H_ diff --git a/Source/ablastr/utils/text/StreamUtils.cpp b/Source/ablastr/utils/text/StreamUtils.cpp new file mode 100644 index 00000000000..965beb179ba --- /dev/null +++ b/Source/ablastr/utils/text/StreamUtils.cpp @@ -0,0 +1,17 @@ +/* Copyright 2023 + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ + +#include "StreamUtils.H" + +#include +#include + +void +ablastr::utils::text::goto_next_line (std::istream& is) +{ + is.ignore(std::numeric_limits::max(), '\n'); +} From 63dc76ff15c1c8660f30e1ff1cfcb9c2f04db814 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 1 Aug 2023 12:00:50 +0200 Subject: [PATCH 13/18] Refactoring: instantiate WarpX class via MakeWarpX function (#4104) * move functions from main to WarpX class and make WarpX constructible only using factory method * instantiate WarpX via MakeWarpX static member function * test adding MakeWarpX to warpx_init in python wrapper * revert to the use of a simple pointer for the WarpX instance * fix issue * use finalize in python wrapper * change finalize order * move finalize * fix bug --- Source/Initialization/PlasmaInjector.H | 2 +- Source/Initialization/PlasmaInjector.cpp | 6 ++-- Source/Initialization/WarpXInitData.cpp | 6 ++++ .../Particles/PhysicalParticleContainer.cpp | 2 +- Source/Python/WarpXWrappers.cpp | 2 +- Source/WarpX.H | 22 +++++++++++- Source/WarpX.cpp | 36 +++++++++++++------ Source/main.cpp | 14 ++------ 8 files changed, 61 insertions(+), 29 deletions(-) diff --git a/Source/Initialization/PlasmaInjector.H b/Source/Initialization/PlasmaInjector.H index 1c2fc453d73..d0c59f8d6a5 100644 --- a/Source/Initialization/PlasmaInjector.H +++ b/Source/Initialization/PlasmaInjector.H @@ -44,7 +44,7 @@ public: PlasmaInjector () = default; - PlasmaInjector (int ispecies, const std::string& name); + PlasmaInjector (int ispecies, const std::string& name, const amrex::Geometry& geom); ~PlasmaInjector (); diff --git a/Source/Initialization/PlasmaInjector.cpp b/Source/Initialization/PlasmaInjector.cpp index 4149ca4bcac..115fbfca132 100644 --- a/Source/Initialization/PlasmaInjector.cpp +++ b/Source/Initialization/PlasmaInjector.cpp @@ -54,8 +54,9 @@ namespace { } } -PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) - : species_id{ispecies}, species_name{name} +PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name, + const amrex::Geometry& geom): + species_id{ispecies}, species_name{name} { using namespace amrex::literals; @@ -83,7 +84,6 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) zmax = std::numeric_limits::max(); // NOTE: When periodic boundaries are used, default injection range is set to mother grid dimensions. - const amrex::Geometry& geom = WarpX::GetInstance().Geom(0); if( geom.isPeriodic(0) ) { # ifndef WARPX_DIM_1D_Z xmin = geom.ProbLo(0); diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 3f37ef5416f..ed6490c825c 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -411,6 +411,12 @@ WarpX::InitData () Print() << utils::logo::get_logo(); + // Diagnostics + multi_diags = std::make_unique(); + + /** create object for reduced diagnostics */ + reduced_diags = std::make_unique(); + // WarpX::computeMaxStepBoostAccelerator // needs to start from the initial zmin_domain_boost, // even if restarting from a checkpoint file diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 0ed851e9fd5..143847d4d42 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -236,7 +236,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp { BackwardCompatibility(); - plasma_injector = std::make_unique(species_id, species_name); + plasma_injector = std::make_unique(species_id, species_name, amr_core->Geom(0)); physical_species = plasma_injector->getPhysicalSpecies(); charge = plasma_injector->getCharge(); mass = plasma_injector->getMass(); diff --git a/Source/Python/WarpXWrappers.cpp b/Source/Python/WarpXWrappers.cpp index cbee65b6159..8d3be68be4d 100644 --- a/Source/Python/WarpXWrappers.cpp +++ b/Source/Python/WarpXWrappers.cpp @@ -173,7 +173,7 @@ namespace void warpx_finalize () { - WarpX::ResetInstance(); + WarpX::Finalize(); } void warpx_set_callback_py ( diff --git a/Source/WarpX.H b/Source/WarpX.H index f67a007d238..ae8f7dfcae1 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -83,9 +83,15 @@ public: friend class PML; static WarpX& GetInstance (); + static void ResetInstance (); - WarpX (); + /** + * \brief + * This method has to be called at the end of the simulation. It deletes the WarpX instance. + */ + static void Finalize(); + ~WarpX (); static std::string Version (); //!< Version of WarpX executable @@ -1116,6 +1122,20 @@ protected: private: + /** + * \brief + * WarpX constructor. This method should not be called directly, but rather through + * the static member function MakeWarpX(). MakeWarpX() is called by GetInstance () + * if an instance of the WarpX class does not currently exist. + */ + WarpX (); + + /** + * \brief + * This method creates a new instance of the WarpX class. + */ + static void MakeWarpX (); + // Singleton is used when the code is run from python static WarpX* m_instance; diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index a6e4f06a176..f5826fd9369 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -232,11 +232,25 @@ bool WarpX::do_device_synchronize = false; WarpX* WarpX::m_instance = nullptr; +void WarpX::MakeWarpX () +{ + ParseGeometryInput(); + + ConvertLabParamsToBoost(); + ReadBCParams(); + +#ifdef WARPX_DIM_RZ + CheckGriddingForRZSpectral(); +#endif + + m_instance = new WarpX(); +} + WarpX& WarpX::GetInstance () { if (!m_instance) { - m_instance = new WarpX(); + MakeWarpX(); } return *m_instance; } @@ -244,14 +258,20 @@ WarpX::GetInstance () void WarpX::ResetInstance () { - delete m_instance; - m_instance = nullptr; + if (m_instance){ + delete m_instance; + m_instance = nullptr; + } } -WarpX::WarpX () +void +WarpX::Finalize() { - m_instance = this; + WarpX::ResetInstance(); +} +WarpX::WarpX () +{ ReadParameters(); BackwardCompatibility(); @@ -304,12 +324,6 @@ WarpX::WarpX () // Particle Boundary Buffer (i.e., scraped particles on boundary) m_particle_boundary_buffer = std::make_unique(); - // Diagnostics - multi_diags = std::make_unique(); - - /** create object for reduced diagnostics */ - reduced_diags = std::make_unique(); - Efield_aux.resize(nlevs_max); Bfield_aux.resize(nlevs_max); diff --git a/Source/main.cpp b/Source/main.cpp index b889bb24a76..3051539d87e 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -11,7 +11,6 @@ #include "Initialization/WarpXAMReXInit.H" #include "Utils/WarpXProfilerWrapper.H" #include "Utils/WarpXrocfftUtil.H" -#include "Utils/WarpXUtil.H" #include #include @@ -27,22 +26,13 @@ int main(int argc, char* argv[]) utils::rocfft::setup(); - ParseGeometryInput(); - - ConvertLabParamsToBoost(); - ReadBCParams(); - -#ifdef WARPX_DIM_RZ - CheckGriddingForRZSpectral(); -#endif - { WARPX_PROFILE_VAR("main()", pmain); auto timer = ablastr::utils::timer::Timer{}; timer.record_start_time(); - WarpX warpx; + auto& warpx = WarpX::GetInstance(); warpx.InitData(); @@ -58,6 +48,8 @@ int main(int argc, char* argv[]) } WARPX_PROFILE_VAR_STOP(pmain); + + WarpX::Finalize(); } utils::rocfft::cleanup(); From 0aa12461bd956e9e9a08e0ac3b8e2c2263aa7661 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 1 Aug 2023 13:38:19 +0200 Subject: [PATCH 14/18] Clang tidy CI test: add several readability checks to clang tidy CI test (#4124) * add few readability checks to clang-tidy CI test * address all the issues found with clang-tidy * fix bug * fixed bug * fix residual issue * fix issue found with clang-tidy --- .clang-tidy | 10 +++ Source/BoundaryConditions/PML.cpp | 6 +- Source/BoundaryConditions/WarpX_PEC.H | 34 ++++--- Source/BoundaryConditions/WarpX_PEC.cpp | 7 +- Source/Diagnostics/BTDiagnostics.H | 4 +- Source/Diagnostics/BTDiagnostics.cpp | 88 ++++++++----------- .../BackTransformFunctor.cpp | 6 +- .../BackTransformParticleFunctor.cpp | 2 +- .../ComputeDiagFunctors/DivBFunctor.cpp | 4 +- .../ComputeDiagFunctors/DivEFunctor.cpp | 2 +- Source/Diagnostics/Diagnostics.cpp | 35 ++++---- .../FlushFormats/FlushFormatOpenPMD.cpp | 10 +-- .../FlushFormats/FlushFormatPlotfile.cpp | 6 +- Source/Diagnostics/FullDiagnostics.cpp | 15 ++-- Source/Diagnostics/MultiDiagnostics.cpp | 2 +- .../Diagnostics/ReducedDiags/FieldEnergy.cpp | 4 +- .../ReducedDiags/FieldMomentum.cpp | 5 +- .../Diagnostics/ReducedDiags/FieldProbe.cpp | 8 +- .../ReducedDiags/LoadBalanceCosts.cpp | 6 +- .../ReducedDiags/ParticleEnergy.cpp | 5 +- .../ReducedDiags/ParticleHistogram.cpp | 3 +- .../ReducedDiags/ParticleMomentum.cpp | 5 +- Source/Diagnostics/SliceDiagnostic.cpp | 14 +-- Source/Diagnostics/WarpXOpenPMD.cpp | 7 +- Source/Evolve/WarpXEvolve.cpp | 4 +- .../FiniteDifferenceSolver.cpp | 2 +- .../HybridPICModel/HybridPICModel.cpp | 18 ++-- .../PsatdAlgorithmFirstOrder.cpp | 8 +- .../SpectralAlgorithms/PsatdAlgorithmRZ.cpp | 4 +- .../SpectralSolver/SpectralFieldData.cpp | 26 +++--- .../SpectralSolver/SpectralFieldDataRZ.cpp | 4 +- Source/Initialization/WarpXInitData.cpp | 2 +- Source/Parallelization/WarpXRegrid.cpp | 4 +- .../BinaryCollision/BinaryCollision.H | 5 +- Source/Particles/LaserParticleContainer.cpp | 2 +- Source/Particles/MultiParticleContainer.H | 6 +- .../Particles/PhysicalParticleContainer.cpp | 6 +- Source/Particles/Resampling/Resampling.cpp | 2 +- Source/Particles/WarpXParticleContainer.cpp | 10 +-- Source/Utils/WarpXMovingWindow.cpp | 6 +- Source/WarpX.cpp | 28 +++--- 41 files changed, 199 insertions(+), 226 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 8436124975f..987c3c2a9f3 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -39,6 +39,16 @@ Checks: '-*, performance-inefficient-vector-operation, performance-move-const-arg, performance-move-constructor-init, + readability-non-const-parameter, + readability-simplify-boolean-expr, + readability-simplify-subscript-expr, + readability-static-accessed-through-instance, + readability-static-definition-in-anonymous-namespace, + readability-string-compare, + readability-suspicious-call-argument, + readability-uniqueptr-delete-release, + -readability-uppercase-literal-suffix, + readability-use-anyofallof, readability-non-const-parameter ' diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index cc66393813b..d34a2f73222 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -58,7 +58,7 @@ using namespace amrex; namespace { - static void FillLo (Sigma& sigma, Sigma& sigma_cumsum, + void FillLo (Sigma& sigma, Sigma& sigma_cumsum, Sigma& sigma_star, Sigma& sigma_star_cumsum, const int olo, const int ohi, const int glo, Real fac, const amrex::Real v_sigma) @@ -87,7 +87,7 @@ namespace }); } - static void FillHi (Sigma& sigma, Sigma& sigma_cumsum, + void FillHi (Sigma& sigma, Sigma& sigma_cumsum, Sigma& sigma_star, Sigma& sigma_star_cumsum, const int olo, const int ohi, const int ghi, Real fac, const amrex::Real v_sigma) @@ -115,7 +115,7 @@ namespace } #if (AMREX_SPACEDIM != 1) - static void FillZero (Sigma& sigma, Sigma& sigma_cumsum, + void FillZero (Sigma& sigma, Sigma& sigma_cumsum, Sigma& sigma_star, Sigma& sigma_star_cumsum, const int olo, const int ohi) { diff --git a/Source/BoundaryConditions/WarpX_PEC.H b/Source/BoundaryConditions/WarpX_PEC.H index c6d0559d1cd..2f68bc70c67 100644 --- a/Source/BoundaryConditions/WarpX_PEC.H +++ b/Source/BoundaryConditions/WarpX_PEC.H @@ -166,23 +166,22 @@ using namespace amrex; // For 2D : for icomp==1, (Ey in XZ, Etheta in RZ), // icomp=1 is tangential to both x and z boundaries // The logic below ensures that the flags are set right for 2D - const bool is_tangent_to_PEC = ( (icomp == AMREX_SPACEDIM*idim) - ? false : true ); + const bool is_tangent_to_PEC = (icomp != AMREX_SPACEDIM*idim); #elif (defined WARPX_DIM_1D_Z) // For 1D : icomp=0 and icomp=1 (Ex and Ey are tangential to the z boundary) // The logic below ensures that the flags are set right for 1D - const bool is_tangent_to_PEC = ( ( icomp == idim+2) ? false : true ); + const bool is_tangent_to_PEC = (icomp != idim+2); #else - const bool is_tangent_to_PEC = ( ( icomp == idim) ? false : true ); + const bool is_tangent_to_PEC = (icomp != idim); #endif - if (isPECBoundary == true) { + if (isPECBoundary) { // grid point ijk_vec is ig number of points pass the // domain boundary in direction, idim const int ig = get_cell_count_to_boundary( dom_lo, dom_hi, ijk_vec, is_nodal, idim, iside); if (ig == 0) { - if (is_tangent_to_PEC == true and is_nodal[idim] == 1) { + if (is_tangent_to_PEC && is_nodal[idim] == 1) { OnPECBoundary = true; } } else if (ig > 0) { @@ -192,15 +191,15 @@ using namespace amrex; : (dom_hi[idim] + 1 - ig)); GuardCell = true; // tangential components are inverted across PEC boundary - if (is_tangent_to_PEC == true) sign *= -1._rt; + if (is_tangent_to_PEC) sign *= -1._rt; } } // is PEC boundary } // loop over iside } // loop over dimensions - if (OnPECBoundary == true) { + if (OnPECBoundary) { // if ijk_vec is on a PEC boundary in any direction, set Etangential to 0. Efield(ijk_vec,n) = 0._rt; - } else if (GuardCell == true) { + } else if (GuardCell) { Efield(ijk_vec,n) = sign * Efield(ijk_mirror,n); } } @@ -288,19 +287,18 @@ using namespace amrex; const bool isPECBoundary = ( (iside == 0 ) ? is_boundary_PEC(fbndry_lo, idim) : is_boundary_PEC(fbndry_hi, idim) ); - if (isPECBoundary == true) { + if (isPECBoundary) { #if (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) // For 2D : for icomp==1, (By in XZ, Btheta in RZ), // icomp=1 is not normal to x or z boundary // The logic below ensures that the flags are set right for 2D - const bool is_normal_to_PEC = ( (icomp == AMREX_SPACEDIM*idim) - ? true : false ); + const bool is_normal_to_PEC = (icomp == (AMREX_SPACEDIM*idim)); #elif (defined WARPX_DIM_1D_Z) // For 1D : icomp=0 and icomp=1 (Bx and By are not normal to the z boundary) // The logic below ensures that the flags are set right for 1D - const bool is_normal_to_PEC = ( ( icomp == idim+2) ? true : false ); + const bool is_normal_to_PEC = (icomp == (idim+2)); #else - const bool is_normal_to_PEC = ( ( icomp == idim) ? true : false ); + const bool is_normal_to_PEC = (icomp == idim); #endif // grid point ijk_vec is ig number of points pass the @@ -310,7 +308,7 @@ using namespace amrex; if (ig == 0) { // Only normal component is set to 0 - if (is_normal_to_PEC == true and is_nodal[idim]==1) { + if (is_normal_to_PEC && is_nodal[idim]==1) { OnPECBoundary = true; } } else if ( ig > 0) { @@ -321,16 +319,16 @@ using namespace amrex; : (dom_hi[idim] + 1 - ig)); GuardCell = true; // Sign of the normal component in guard cell is inverted - if (is_normal_to_PEC == true) sign *= -1._rt; + if (is_normal_to_PEC) sign *= -1._rt; } } // if PEC Boundary } // loop over sides } // loop of dimensions - if (OnPECBoundary == true) { + if (OnPECBoundary) { // if ijk_vec is on a PEC boundary in any direction, set Bnormal to 0. Bfield(ijk_vec,n) = 0._rt; - } else if (GuardCell == true) { + } else if (GuardCell) { // Bnormal and Btangential is set opposite and equal to the value // in the mirror location, respectively. Bfield(ijk_vec,n) = sign * Bfield(ijk_mirror,n); diff --git a/Source/BoundaryConditions/WarpX_PEC.cpp b/Source/BoundaryConditions/WarpX_PEC.cpp index 6841fb9bc6b..b3986da0645 100644 --- a/Source/BoundaryConditions/WarpX_PEC.cpp +++ b/Source/BoundaryConditions/WarpX_PEC.cpp @@ -361,15 +361,14 @@ PEC::ApplyPECtoJfield(amrex::MultiFab* Jx, amrex::MultiFab* Jy, #if (defined WARPX_DIM_1D_Z) // For 1D : icomp=0 and icomp=1 (Ex and Ey are tangential to the z boundary) // The logic below ensures that the flags are set right for 1D - is_tangent_to_bndy[icomp][idim] = ( ( icomp == idim+2) ? false : true ); + is_tangent_to_bndy[icomp][idim] = (icomp != (idim+2)); #elif (defined WARPX_DIM_XZ) || (defined WARPX_DIM_RZ) // For 2D : for icomp==1, (Ey in XZ, Etheta in RZ), // icomp=1 is tangential to both x and z boundaries // The logic below ensures that the flags are set right for 2D - is_tangent_to_bndy[icomp][idim] = ( (icomp == AMREX_SPACEDIM*idim) - ? false : true ); + is_tangent_to_bndy[icomp][idim] = (icomp != AMREX_SPACEDIM*idim); #else - is_tangent_to_bndy[icomp][idim] = ( ( icomp == idim) ? false : true ); + is_tangent_to_bndy[icomp][idim] = (icomp != idim); #endif if (is_tangent_to_bndy[icomp][idim]){ diff --git a/Source/Diagnostics/BTDiagnostics.H b/Source/Diagnostics/BTDiagnostics.H index 348e44c297a..633902dd808 100644 --- a/Source/Diagnostics/BTDiagnostics.H +++ b/Source/Diagnostics/BTDiagnostics.H @@ -148,7 +148,7 @@ private: */ bool m_do_back_transformed_particles = true; - /** m_gamma_boost, is a copy of warpx.gamma_boost + /** m_gamma_boost, is a copy of WarpX::gamma_boost * That is, the Lorentz factor of the boosted frame in which the simulation is run. * The direction for Lorentz transformation is assumed to be along * ``warpx.boost_direction``, which is the same as the moving window direction. @@ -157,7 +157,7 @@ private: */ amrex::Real m_gamma_boost; amrex::Real m_beta_boost; - /** m_moving_window_dir is a copy of warpx.moving_window_dir + /** m_moving_window_dir is a copy of WarpX::moving_window_dir * Currently, back-transformed diagnostics only works if moving window is * in z-direction for both 2D and 3D simulations in the Cartesian frame of reference. */ diff --git a/Source/Diagnostics/BTDiagnostics.cpp b/Source/Diagnostics/BTDiagnostics.cpp index c368d245233..71834beadd0 100644 --- a/Source/Diagnostics/BTDiagnostics.cpp +++ b/Source/Diagnostics/BTDiagnostics.cpp @@ -64,7 +64,7 @@ void BTDiagnostics::DerivedInitData () auto & warpx = WarpX::GetInstance(); m_gamma_boost = WarpX::gamma_boost; m_beta_boost = std::sqrt( 1._rt - 1._rt/( m_gamma_boost * m_gamma_boost) ); - m_moving_window_dir = warpx.moving_window_dir; + m_moving_window_dir = WarpX::moving_window_dir; // Currently, for BTD, all the data is averaged+coarsened to coarsest level // and then sliced+back-transformed+filled_to_buffer. // The number of levels to be output is nlev_output. @@ -112,14 +112,12 @@ void BTDiagnostics::DerivedInitData () const amrex::ParmParse pp_diag_name(m_diag_name); int write_species = 1; pp_diag_name.query("write_species", write_species); - if (m_output_species_names.size() == 0 and write_species == 1) + if ((m_output_species_names.size() == 0) && (write_species == 1)) m_output_species_names = mpc.GetSpeciesNames(); - if (m_output_species_names.size() > 0 and write_species == 1) { - m_do_back_transformed_particles = true; - } else { - m_do_back_transformed_particles = false; - } + m_do_back_transformed_particles = + ((m_output_species_names.size() > 0) && (write_species == 1)); + // Turn on do_back_transformed_particles in the particle containers so that // the tmp_particle_data is allocated and the data of the corresponding species is // copied and stored in tmp_particle_data before particles are pushed. @@ -136,8 +134,8 @@ void BTDiagnostics::DerivedInitData () // check that simulation can fill all BTD snapshots const int lev = 0; const amrex::Real dt_boosted_frame = warpx.getdt(lev); - const int moving_dir = warpx.moving_window_dir; - const amrex::Real Lz_lab = warpx.Geom(lev).ProbLength(moving_dir) / warpx.gamma_boost / (1._rt+warpx.beta_boost); + const int moving_dir = WarpX::moving_window_dir; + const amrex::Real Lz_lab = warpx.Geom(lev).ProbLength(moving_dir) / WarpX::gamma_boost / (1._rt+WarpX::beta_boost); const int ref_ratio = 1; const amrex::Real dz_snapshot_grid = dz_lab(dt_boosted_frame, ref_ratio); // Need enough buffers so the snapshot length is longer than the lab frame length @@ -163,10 +161,10 @@ void BTDiagnostics::DerivedInitData () // if j = final snapshot starting step, then we want to solve // j dt_boosted_frame >= t_intersect_boost = i * dt_snapshot / gamma / (1+beta) // j >= i / gamma / (1+beta) * dt_snapshot / dt_boosted_frame - const int final_snapshot_starting_step = static_cast(std::ceil(final_snapshot_iteration / warpx.gamma_boost / (1._rt+warpx.beta_boost) * m_dt_snapshots_lab / dt_boosted_frame)); + const int final_snapshot_starting_step = static_cast(std::ceil(final_snapshot_iteration / WarpX::gamma_boost / (1._rt+WarpX::beta_boost) * m_dt_snapshots_lab / dt_boosted_frame)); const int final_snapshot_fill_iteration = final_snapshot_starting_step + num_buffers * m_buffer_size - 1; const amrex::Real final_snapshot_fill_time = final_snapshot_fill_iteration * dt_boosted_frame; - if (warpx.compute_max_step_from_btd) { + if (WarpX::compute_max_step_from_btd) { if (final_snapshot_fill_iteration > warpx.maxStep()) { warpx.updateMaxStep(final_snapshot_fill_iteration); amrex::Print()<<"max_step insufficient to fill all BTD snapshots. Automatically increased to: " @@ -206,20 +204,19 @@ void BTDiagnostics::ReadParameters () { BaseReadParameters(); - auto & warpx = WarpX::GetInstance(); - WARPX_ALWAYS_ASSERT_WITH_MESSAGE( warpx.gamma_boost > 1.0_rt, + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( WarpX::gamma_boost > 1.0_rt, "gamma_boost must be > 1 to use the back-transformed diagnostics"); - WARPX_ALWAYS_ASSERT_WITH_MESSAGE( warpx.boost_direction[2] == 1, + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( WarpX::boost_direction[2] == 1, "The back transformed diagnostics currently only works if the boost is in the z-direction"); - WARPX_ALWAYS_ASSERT_WITH_MESSAGE( warpx.do_moving_window, + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( WarpX::do_moving_window, "The moving window should be on if using the boosted frame diagnostic."); // The next two asserts could be relaxed with respect to check to current step - WARPX_ALWAYS_ASSERT_WITH_MESSAGE( warpx.end_moving_window_step < 0, + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( WarpX::end_moving_window_step < 0, "The moving window must not stop when using the boosted frame diagnostic."); - WARPX_ALWAYS_ASSERT_WITH_MESSAGE( warpx.start_moving_window_step == 0, + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( WarpX::start_moving_window_step == 0, "The moving window must start at step zero for the boosted frame diagnostic."); - WARPX_ALWAYS_ASSERT_WITH_MESSAGE( warpx.moving_window_dir == WARPX_ZINDEX, + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( WarpX::moving_window_dir == WARPX_ZINDEX, "The boosted frame diagnostic currently only works if the moving window is in the z direction."); WARPX_ALWAYS_ASSERT_WITH_MESSAGE( m_format == "plotfile" || m_format == "openpmd", @@ -236,7 +233,7 @@ BTDiagnostics::ReadParameters () pp_diag_name.query("do_back_transformed_fields", m_do_back_transformed_fields); pp_diag_name.query("do_back_transformed_particles", m_do_back_transformed_particles); AMREX_ALWAYS_ASSERT(m_do_back_transformed_fields or m_do_back_transformed_particles); - if (m_do_back_transformed_fields == false) m_varnames.clear(); + if (!m_do_back_transformed_fields) m_varnames.clear(); std::vector intervals_string_vec = {"0"}; @@ -340,10 +337,10 @@ BTDiagnostics::InitializeBufferData ( int i_buffer , int lev, bool restart) // When restarting boosted simulations, the code below needs to take // into account the fact that the position of the box at the beginning // of the simulation, is not the one that we had at t=0 (because of the moving window) - const amrex::Real boosted_moving_window_v = (warpx.moving_window_v - m_beta_boost*PhysConst::c) - / (1._rt - m_beta_boost * warpx.moving_window_v/PhysConst::c); + const amrex::Real boosted_moving_window_v = (WarpX::moving_window_v - m_beta_boost*PhysConst::c) + / (1._rt - m_beta_boost * WarpX::moving_window_v/PhysConst::c); // Lab-frame time for the i^th snapshot - if (restart == false) { + if (!restart) { const amrex::Real zmax_0 = warpx.Geom(lev).ProbHi(m_moving_window_dir); m_t_lab.at(i_buffer) = m_intervals.GetBTDIteration(i_buffer) * m_dt_snapshots_lab + m_gamma_boost*m_beta_boost*zmax_0/PhysConst::c; @@ -470,12 +467,12 @@ BTDiagnostics::InitializeBufferData ( int i_buffer , int lev, bool restart) // number of cells in z is modified since each buffer multifab always // contains a minimum m_buffer_size=256 cells const int num_z_cells_in_snapshot = m_max_buffer_multifabs[i_buffer] * m_buffer_size; - if (restart == false) { + if (!restart) { m_snapshot_domain_lab[i_buffer] = diag_dom; m_snapshot_domain_lab[i_buffer].setLo(m_moving_window_dir, - zmin_buffer_lab + warpx.moving_window_v * m_t_lab[i_buffer]); + zmin_buffer_lab + WarpX::moving_window_v * m_t_lab[i_buffer]); m_snapshot_domain_lab[i_buffer].setHi(m_moving_window_dir, - zmax_buffer_lab + warpx.moving_window_v * m_t_lab[i_buffer]); + zmax_buffer_lab + WarpX::moving_window_v * m_t_lab[i_buffer]); // To prevent round off errors, moving the snapshot domain by half a cell so that all the slices // lie close to the cell-centers in the lab-frame grid instead of on the edge of cell. const amrex::Real new_hi = m_snapshot_domain_lab[i_buffer].hi(m_moving_window_dir) @@ -499,7 +496,7 @@ BTDiagnostics::InitializeBufferData ( int i_buffer , int lev, bool restart) m_snapshot_box[i_buffer].setSmall( m_moving_window_dir, snapshot_kindex_hi - (num_z_cells_in_snapshot-1) ); // Setting hi k-index for the first buffer - if (restart == false) { + if (!restart) { m_buffer_k_index_hi[i_buffer] = m_snapshot_box[i_buffer].bigEnd(m_moving_window_dir); } } @@ -507,7 +504,7 @@ BTDiagnostics::InitializeBufferData ( int i_buffer , int lev, bool restart) void BTDiagnostics::DefineCellCenteredMultiFab(int lev) { - if (m_do_back_transformed_fields == false) return; + if (!m_do_back_transformed_fields) return; // Creating MultiFab to store cell-centered data in boosted-frame for the entire-domain // This MultiFab will store all the user-requested fields in the boosted-frame auto & warpx = WarpX::GetInstance(); @@ -529,7 +526,7 @@ void BTDiagnostics::InitializeFieldFunctors (int lev) { // Initialize fields functors only if do_back_transformed_fields is selected - if (m_do_back_transformed_fields == false) return; + if (!m_do_back_transformed_fields) return; #ifdef WARPX_DIM_RZ // For RZ, initialize field functors RZ for openpmd @@ -783,7 +780,7 @@ void BTDiagnostics::PrepareFieldDataForOutput () { // Initialize fields functors only if do_back_transformed_fields is selected - if (m_do_back_transformed_fields == false) return; + if (!m_do_back_transformed_fields) return; auto & warpx = WarpX::GetInstance(); // In this function, we will get cell-centered data for every level, lev, @@ -943,7 +940,7 @@ BTDiagnostics::DefineFieldBufferMultiFab (const int i_buffer, const int lev) } else if (lev > 0 ) { // Refine the geometry object defined at the previous level, lev-1 m_geom_output[i_buffer][lev] = amrex::refine( m_geom_output[i_buffer][lev-1], - warpx.RefRatio(lev-1) ); + WarpX::RefRatio(lev-1) ); } m_field_buffer_multifab_defined[i_buffer] = 1; } @@ -953,7 +950,6 @@ void BTDiagnostics::DefineSnapshotGeometry (const int i_buffer, const int lev) { if (m_snapshot_geometry_defined[i_buffer] == 1) return; - auto & warpx = WarpX::GetInstance(); if (lev == 0) { // Default non-periodic geometry for diags @@ -968,7 +964,7 @@ BTDiagnostics::DefineSnapshotGeometry (const int i_buffer, const int lev) } else if (lev > 0) { // Refine the geometry object defined at the previous level, lev-1 m_geom_snapshot[i_buffer][lev] = amrex::refine( m_geom_snapshot[i_buffer][lev-1], - warpx.RefRatio(lev-1) ); + WarpX::RefRatio(lev-1) ); } m_snapshot_geometry_defined[i_buffer] = 1; } @@ -980,28 +976,22 @@ BTDiagnostics::GetZSliceInDomainFlag (const int i_buffer, const int lev) const amrex::RealBox& boost_domain = warpx.Geom(lev).ProbDomain(); const amrex::Real buffer_zmin_lab = m_snapshot_domain_lab[i_buffer].lo( m_moving_window_dir ); const amrex::Real buffer_zmax_lab = m_snapshot_domain_lab[i_buffer].hi( m_moving_window_dir ); - if ( ( m_current_z_boost[i_buffer] <= boost_domain.lo(m_moving_window_dir) ) or - ( m_current_z_boost[i_buffer] >= boost_domain.hi(m_moving_window_dir) ) or - ( m_current_z_lab[i_buffer] <= buffer_zmin_lab ) or - ( m_current_z_lab[i_buffer] >= buffer_zmax_lab ) ) - { - // the slice is not in the boosted domain or lab-frame domain - return false; - } - return true; + const bool slice_not_in_domain = + ( m_current_z_boost[i_buffer] <= boost_domain.lo(m_moving_window_dir) ) || + ( m_current_z_boost[i_buffer] >= boost_domain.hi(m_moving_window_dir) ) || + ( m_current_z_lab[i_buffer] <= buffer_zmin_lab ) || + ( m_current_z_lab[i_buffer] >= buffer_zmax_lab ); + + return !slice_not_in_domain; } bool BTDiagnostics::GetKIndexInSnapshotBoxFlag (const int i_buffer, const int lev) { - if (k_index_zlab(i_buffer, lev) >= m_snapshot_box[i_buffer].smallEnd(m_moving_window_dir) and - k_index_zlab(i_buffer, lev) <= m_snapshot_box[i_buffer].bigEnd(m_moving_window_dir)) { - return true; - } - - return false; + return (k_index_zlab(i_buffer, lev) >= m_snapshot_box[i_buffer].smallEnd(m_moving_window_dir) && + k_index_zlab(i_buffer, lev) <= m_snapshot_box[i_buffer].bigEnd(m_moving_window_dir)); } void @@ -1014,7 +1004,7 @@ BTDiagnostics::Flush (int i_buffer) file_name = file_name+"/buffer"; } SetSnapshotFullStatus(i_buffer); - const bool isLastBTDFlush = ( m_snapshot_full[i_buffer] == 1 ) ? true : false; + const bool isLastBTDFlush = ( m_snapshot_full[i_buffer] == 1 ); bool const use_pinned_pc = true; bool const isBTD = true; double const labtime = m_t_lab[i_buffer]; @@ -1173,7 +1163,7 @@ void BTDiagnostics::MergeBuffersForPlotfile (int i_snapshot) std::rename(buffer_job_info_path.c_str(), snapshot_job_info_path.c_str()); } - if (m_do_back_transformed_fields == true) { + if (m_do_back_transformed_fields) { // Read the header file to get the fab on disk string BTDMultiFabHeaderImpl Buffer_FabHeader(recent_Buffer_FabHeaderFilename); Buffer_FabHeader.ReadMultiFabHeader(); diff --git a/Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp b/Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp index 3e985f2919c..4d551a271dc 100644 --- a/Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp +++ b/Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp @@ -52,8 +52,8 @@ BackTransformFunctor::operator ()(amrex::MultiFab& mf_dst, int /*dcomp*/, const if ( m_perform_backtransform[i_buffer] == 1) { auto& warpx = WarpX::GetInstance(); auto geom = warpx.Geom(m_lev); - const amrex::Real gamma_boost = warpx.gamma_boost; - const int moving_window_dir = warpx.moving_window_dir; + const amrex::Real gamma_boost = WarpX::gamma_boost; + const int moving_window_dir = WarpX::moving_window_dir; const amrex::Real beta_boost = std::sqrt( 1._rt - 1._rt/( gamma_boost * gamma_boost) ); const bool interpolate = true; std::unique_ptr< amrex::MultiFab > slice = nullptr; @@ -163,7 +163,7 @@ BackTransformFunctor::PrepareFunctorData (int i_buffer, m_current_z_boost[i_buffer] = current_z_boost; m_k_index_zlab[i_buffer] = k_index_zlab; m_perform_backtransform[i_buffer] = 0; - if (z_slice_in_domain == true and snapshot_full == 0) m_perform_backtransform[i_buffer] = 1; + if (z_slice_in_domain && (snapshot_full == 0)) m_perform_backtransform[i_buffer] = 1; m_max_box_size = max_box_size; } diff --git a/Source/Diagnostics/ComputeDiagFunctors/BackTransformParticleFunctor.cpp b/Source/Diagnostics/ComputeDiagFunctors/BackTransformParticleFunctor.cpp index 0442dad7a00..2275ee83fec 100644 --- a/Source/Diagnostics/ComputeDiagFunctors/BackTransformParticleFunctor.cpp +++ b/Source/Diagnostics/ComputeDiagFunctors/BackTransformParticleFunctor.cpp @@ -171,5 +171,5 @@ BackTransformParticleFunctor::PrepareFunctorData ( int i_buffer, bool z_slice_in m_current_z_boost.at(i_buffer) = current_z_boost; m_t_lab.at(i_buffer) = t_lab; m_perform_backtransform.at(i_buffer) = 0; - if (z_slice_in_domain == true and snapshot_full == 0) m_perform_backtransform.at(i_buffer) = 1; + if (z_slice_in_domain && (snapshot_full == 0)) m_perform_backtransform.at(i_buffer) = 1; } diff --git a/Source/Diagnostics/ComputeDiagFunctors/DivBFunctor.cpp b/Source/Diagnostics/ComputeDiagFunctors/DivBFunctor.cpp index 093b4960edf..b5782e76ae6 100644 --- a/Source/Diagnostics/ComputeDiagFunctors/DivBFunctor.cpp +++ b/Source/Diagnostics/ComputeDiagFunctors/DivBFunctor.cpp @@ -23,8 +23,8 @@ DivBFunctor::operator()(amrex::MultiFab& mf_dst, int dcomp, const int /*i_buffer constexpr int ng = 1; // A cell-centered divB multifab spanning the entire domain is generated // and divB is computed on the cell-center, with ng=1. - amrex::MultiFab divB( warpx.boxArray(m_lev), warpx.DistributionMap(m_lev), warpx.ncomps, ng ); - warpx.ComputeDivB(divB, 0, m_arr_mf_src, WarpX::CellSize(m_lev) ); + amrex::MultiFab divB( warpx.boxArray(m_lev), warpx.DistributionMap(m_lev), WarpX::ncomps, ng ); + WarpX::ComputeDivB(divB, 0, m_arr_mf_src, WarpX::CellSize(m_lev) ); // // Coarsen and Interpolate from divB to coarsened/reduced_domain mf_dst // ablastr::coarsen::sample::Coarsen( mf_dst, divB, dcomp, 0, nComp(), 0, m_crse_ratio); #ifdef WARPX_DIM_RZ diff --git a/Source/Diagnostics/ComputeDiagFunctors/DivEFunctor.cpp b/Source/Diagnostics/ComputeDiagFunctors/DivEFunctor.cpp index e0c5b755b02..62801cd431a 100644 --- a/Source/Diagnostics/ComputeDiagFunctors/DivEFunctor.cpp +++ b/Source/Diagnostics/ComputeDiagFunctors/DivEFunctor.cpp @@ -43,7 +43,7 @@ DivEFunctor::operator()(amrex::MultiFab& mf_dst, const int dcomp, const int /*i_ #endif const amrex::BoxArray& ba = amrex::convert(warpx.boxArray(m_lev), cell_type); - amrex::MultiFab divE(ba, warpx.DistributionMap(m_lev), warpx.ncomps, ng ); + amrex::MultiFab divE(ba, warpx.DistributionMap(m_lev), WarpX::ncomps, ng ); warpx.ComputeDivE(divE, m_lev); #ifdef WARPX_DIM_RZ diff --git a/Source/Diagnostics/Diagnostics.cpp b/Source/Diagnostics/Diagnostics.cpp index e33810e45ec..62c802483d2 100644 --- a/Source/Diagnostics/Diagnostics.cpp +++ b/Source/Diagnostics/Diagnostics.cpp @@ -212,7 +212,7 @@ Diagnostics::BaseReadParameters () } } // For a moving window simulation, the user-defined m_lo and m_hi must be converted. - if (warpx.do_moving_window) { + if (WarpX::do_moving_window) { #if defined(WARPX_DIM_3D) amrex::Vector dim_map {0, 1, 2}; #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) @@ -220,13 +220,13 @@ Diagnostics::BaseReadParameters () #else amrex::Vector dim_map {2}; #endif - if (warpx.boost_direction[ dim_map[warpx.moving_window_dir] ] == 1) { + if (WarpX::boost_direction[ dim_map[WarpX::moving_window_dir] ] == 1) { // Convert user-defined lo and hi for diagnostics to account for boosted-frame // simulations with moving window - const amrex::Real convert_factor = 1._rt/(warpx.gamma_boost * (1._rt - warpx.beta_boost) ); + const amrex::Real convert_factor = 1._rt/(WarpX::gamma_boost * (1._rt - WarpX::beta_boost) ); // Assuming that the window travels with speed c - m_lo[warpx.moving_window_dir] *= convert_factor; - m_hi[warpx.moving_window_dir] *= convert_factor; + m_lo[WarpX::moving_window_dir] *= convert_factor; + m_hi[WarpX::moving_window_dir] *= convert_factor; } } @@ -275,18 +275,17 @@ Diagnostics::BaseReadParameters () } } - bool checkpoint_compatibility = false; - if (m_format == "checkpoint"){ - if ( varnames_specified == false && - pfield_varnames_specified == false && - pfield_species_specified == false && - lo_specified == false && - hi_specified == false && - cr_specified == false && - species_specified == false ) checkpoint_compatibility = true; - } - return checkpoint_compatibility; + const bool checkpoint_compatibility = ( + m_format == "checkpoint" && + !varnames_specified && + !pfield_varnames_specified && + !pfield_species_specified && + !lo_specified && + !hi_specified && + !cr_specified && + !species_specified ); + return checkpoint_compatibility; } @@ -463,8 +462,8 @@ Diagnostics::InitBaseData () // For restart, move the m_lo and m_hi of the diag consistent with the // current moving_window location - if (warpx.do_moving_window) { - const int moving_dir = warpx.moving_window_dir; + if (WarpX::do_moving_window) { + const int moving_dir = WarpX::moving_window_dir; const int shift_num_base = static_cast((warpx.getmoving_window_x() - m_lo[moving_dir]) / warpx.Geom(0).CellSize(moving_dir) ); m_lo[moving_dir] += shift_num_base * warpx.Geom(0).CellSize(moving_dir); m_hi[moving_dir] += shift_num_base * warpx.Geom(0).CellSize(moving_dir); diff --git a/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.cpp b/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.cpp index 2c7e5350aa6..3832bf5e9c0 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatOpenPMD.cpp @@ -37,11 +37,11 @@ FlushFormatOpenPMD::FlushFormatOpenPMD (const std::string& diag_name) const bool encodingDefined = pp_diag_name.query("openpmd_encoding", openpmd_encoding); openPMD::IterationEncoding encoding = openPMD::IterationEncoding::groupBased; - if ( 0 == openpmd_encoding.compare("v") ) + if ( openpmd_encoding == "v" ) encoding = openPMD::IterationEncoding::variableBased; - else if ( 0 == openpmd_encoding.compare("g") ) + else if ( openpmd_encoding == "g" ) encoding = openPMD::IterationEncoding::groupBased; - else if ( 0 == openpmd_encoding.compare("f") ) + else if ( openpmd_encoding == "f" ) encoding = openPMD::IterationEncoding::fileBased; std::string diag_type_str; @@ -74,7 +74,7 @@ FlushFormatOpenPMD::FlushFormatOpenPMD (const std::string& diag_name) pp_diag_name.query("adios2_operator.type", operator_type); std::string const prefix = diag_name + ".adios2_operator.parameters"; const ParmParse pp; - auto entr = pp.getEntries(prefix); + auto entr = amrex::ParmParse::getEntries(prefix); std::map< std::string, std::string > operator_parameters; auto const prefix_len = prefix.size() + 1; @@ -90,7 +90,7 @@ FlushFormatOpenPMD::FlushFormatOpenPMD (const std::string& diag_name) pp_diag_name.query("adios2_engine.type", engine_type); std::string const engine_prefix = diag_name + ".adios2_engine.parameters"; const ParmParse ppe; - auto eng_entr = ppe.getEntries(engine_prefix); + auto eng_entr = amrex::ParmParse::getEntries(engine_prefix); std::map< std::string, std::string > engine_parameters; auto const prefixlen = engine_prefix.size() + 1; diff --git a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp index 0cf09ebf90b..744aad0193e 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp @@ -577,8 +577,8 @@ FlushFormatPlotfile::WriteAllRawFields( { // rho_fp will have either ncomps or 2*ncomps (2 being the old and new). When 2, return the new so // there is time synchronization. - const int nstart = warpx.getrho_fp(lev).nComp() - warpx.ncomps; - const MultiFab rho_new(warpx.getrho_fp(lev), amrex::make_alias, nstart, warpx.ncomps); + const int nstart = warpx.getrho_fp(lev).nComp() - WarpX::ncomps; + const MultiFab rho_new(warpx.getrho_fp(lev), amrex::make_alias, nstart, WarpX::ncomps); WriteRawMF(rho_new, dm, raw_pltname, default_level_prefix, "rho_fp", lev, plot_raw_fields_guards); } if (warpx.get_pointer_phi_fp(lev) != nullptr) { @@ -586,7 +586,7 @@ FlushFormatPlotfile::WriteAllRawFields( } // Averaged fields on fine patch - if (warpx.fft_do_time_averaging) + if (WarpX::fft_do_time_averaging) { WriteRawMF(warpx.getEfield_avg_fp(lev, 0) , dm, raw_pltname, default_level_prefix, "Ex_avg_fp", lev, plot_raw_fields_guards); diff --git a/Source/Diagnostics/FullDiagnostics.cpp b/Source/Diagnostics/FullDiagnostics.cpp index 742e84553c2..13dff5432cf 100644 --- a/Source/Diagnostics/FullDiagnostics.cpp +++ b/Source/Diagnostics/FullDiagnostics.cpp @@ -156,10 +156,7 @@ FullDiagnostics::DoComputeAndPack (int step, bool force_flush) { // Data must be computed and packed for full diagnostics // whenever the data needs to be flushed. - if (force_flush || m_intervals.contains(step+1) ){ - return true; - } - return false; + return (force_flush || m_intervals.contains(step+1)); } void @@ -489,7 +486,7 @@ FullDiagnostics::InitializeBufferData (int i_buffer, int lev, bool restart ) { } } - if (use_warpxba == false) { + if (!use_warpxba) { // Following are the steps to compute the lo and hi index corresponding to user-defined // m_lo and m_hi using the same resolution as the simulation at level, lev. amrex::IntVect lo(0); @@ -539,7 +536,7 @@ FullDiagnostics::InitializeBufferData (int i_buffer, int lev, bool restart ) { ba.coarsen(m_crse_ratio); // Generate a new distribution map if the physical m_lo and m_hi for the output // is different from the lo and hi physical co-ordinates of the simulation domain. - if (use_warpxba == false) dmap = amrex::DistributionMapping{ba}; + if (!use_warpxba) dmap = amrex::DistributionMapping{ba}; // Allocate output MultiFab for diagnostics. The data will be stored at cell-centers. const int ngrow = (m_format == "sensei" || m_format == "ascent") ? 1 : 0; int const ncomp = static_cast(m_varnames.size()); @@ -558,7 +555,7 @@ FullDiagnostics::InitializeBufferData (int i_buffer, int lev, bool restart ) { } else if (lev > 0) { // Take the geom object of previous level and refine it. m_geom_output[i_buffer][lev] = amrex::refine( m_geom_output[i_buffer][lev-1], - warpx.RefRatio(lev-1) ); + WarpX::RefRatio(lev-1) ); } } @@ -744,8 +741,8 @@ FullDiagnostics::MovingWindowAndGalileanDomainShift (int step) m_geom_output[0][lev].ProbDomain( amrex::RealBox(new_lo, new_hi) ); } // For Moving Window Shift - if (warpx.moving_window_active(step+1)) { - const int moving_dir = warpx.moving_window_dir; + if (WarpX::moving_window_active(step+1)) { + const int moving_dir = WarpX::moving_window_dir; const amrex::Real moving_window_x = warpx.getmoving_window_x(); // Get the updated lo and hi of the geom domain const amrex::Real* cur_lo = m_geom_output[0][0].ProbLo(); diff --git a/Source/Diagnostics/MultiDiagnostics.cpp b/Source/Diagnostics/MultiDiagnostics.cpp index d026314ffec..5a50dfb6565 100644 --- a/Source/Diagnostics/MultiDiagnostics.cpp +++ b/Source/Diagnostics/MultiDiagnostics.cpp @@ -81,7 +81,7 @@ MultiDiagnostics::FilterComputePackFlush (int step, bool force_flush, bool BackT { int i = 0; for (auto& diag : alldiags){ - if (BackTransform == true) { + if (BackTransform) { if (diags_types[i] == DiagTypes::BackTransformed) diag->FilterComputePackFlush (step, force_flush); } else { diff --git a/Source/Diagnostics/ReducedDiags/FieldEnergy.cpp b/Source/Diagnostics/ReducedDiags/FieldEnergy.cpp index 9db42f77ce6..a88690f863f 100644 --- a/Source/Diagnostics/ReducedDiags/FieldEnergy.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldEnergy.cpp @@ -180,7 +180,7 @@ FieldEnergy::ComputeNorm2RZ(const amrex::MultiFab& field, const int lev) amrex::Box tb = convert(tilebox, field.ixType().toIntVect()); // Lower corner of tile box physical domain - const std::array& xyzmin = warpx.LowerCorner(tilebox, lev, 0._rt); + const std::array& xyzmin = WarpX::LowerCorner(tilebox, lev, 0._rt); const Dim3 lo = lbound(tilebox); const Dim3 hi = ubound(tilebox); const Real rmin = xyzmin[0] + (tb.ixType().nodeCentered(0) ? 0._rt : 0.5_rt*dr); @@ -190,7 +190,7 @@ FieldEnergy::ComputeNorm2RZ(const amrex::MultiFab& field, const int lev) int const ncomp = field.nComp(); for (int idir=0 ; idir < AMREX_SPACEDIM ; idir++) { - if (warpx.field_boundary_hi[idir] == FieldBoundaryType::Periodic) { + if (WarpX::field_boundary_hi[idir] == FieldBoundaryType::Periodic) { // For periodic boundaries, do not include the data in the nodes // on the upper edge of the domain tb.enclosedCells(idir); diff --git a/Source/Diagnostics/ReducedDiags/FieldMomentum.cpp b/Source/Diagnostics/ReducedDiags/FieldMomentum.cpp index bde692a8eb4..b9698d5ffd2 100644 --- a/Source/Diagnostics/ReducedDiags/FieldMomentum.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldMomentum.cpp @@ -94,10 +94,7 @@ FieldMomentum::FieldMomentum (std::string rd_name) void FieldMomentum::ComputeDiags (int step) { // Check if the diags should be done - if (m_intervals.contains(step+1) == false) - { - return; - } + if (!m_intervals.contains(step+1)) return; // Get a reference to WarpX instance auto & warpx = WarpX::GetInstance(); diff --git a/Source/Diagnostics/ReducedDiags/FieldProbe.cpp b/Source/Diagnostics/ReducedDiags/FieldProbe.cpp index 4f32e83b0fc..7749d5ecc8d 100644 --- a/Source/Diagnostics/ReducedDiags/FieldProbe.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldProbe.cpp @@ -382,12 +382,12 @@ void FieldProbe::ComputeDiags (int step) amrex::Real move_dist = 0.0; bool const update_particles_moving_window = do_moving_window_FP && - step > warpx.start_moving_window_step && - step <= warpx.end_moving_window_step; + step > WarpX::start_moving_window_step && + step <= WarpX::end_moving_window_step; if (update_particles_moving_window) { const int step_diff = step - m_last_compute_step; - move_dist = dt*warpx.moving_window_v*step_diff; + move_dist = dt*WarpX::moving_window_v*step_diff; } // get MultiFab data at lev @@ -437,7 +437,7 @@ void FieldProbe::ComputeDiags (int step) auto const np = pti.numParticles(); if (update_particles_moving_window) { - const auto temp_warpx_moving_window = warpx.moving_window_dir; + const auto temp_warpx_moving_window = WarpX::moving_window_dir; amrex::ParallelFor( np, [=] AMREX_GPU_DEVICE (long ip) { amrex::ParticleReal xp, yp, zp; diff --git a/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp b/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp index 3c38c0ce42f..1ce88d043ff 100644 --- a/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp +++ b/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp @@ -87,7 +87,7 @@ void LoadBalanceCosts::ComputeDiags (int step) int nBoxes = 0; for (int lev = 0; lev < nLevels; ++lev) { - const auto cost = warpx.getCosts(lev); + const auto cost = WarpX::getCosts(lev); WARPX_ALWAYS_ASSERT_WITH_MESSAGE( cost, "ERROR: costs are not initialized on level " + std::to_string(lev) + " !"); nBoxes += cost->size(); @@ -110,10 +110,10 @@ void LoadBalanceCosts::ComputeDiags (int step) costs.resize(nLevels); for (int lev = 0; lev < nLevels; ++lev) { - costs[lev] = std::make_unique>(*warpx.getCosts(lev)); + costs[lev] = std::make_unique>(*WarpX::getCosts(lev)); } - if (warpx.load_balance_costs_update_algo == LoadBalanceCostsUpdateAlgo::Heuristic) + if (WarpX::load_balance_costs_update_algo == LoadBalanceCostsUpdateAlgo::Heuristic) { warpx.ComputeCostsHeuristic(costs); } diff --git a/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp b/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp index ebf280e8fa9..a132c135471 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp @@ -88,10 +88,7 @@ ParticleEnergy::ParticleEnergy (std::string rd_name) void ParticleEnergy::ComputeDiags (int step) { // Check if the diags should be done - if (m_intervals.contains(step+1) == false) - { - return; - } + if (!m_intervals.contains(step+1)) return; // Get MultiParticleContainer class object const auto & mypc = WarpX::GetInstance().GetPartContainer(); diff --git a/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp b/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp index 91f0b41f9b3..1b34c1c7aad 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp @@ -179,8 +179,7 @@ void ParticleHistogram::ComputeDiags (int step) auto const num_bins = m_bin_num; Real const bin_min = m_bin_min; Real const bin_size = m_bin_size; - const bool is_unity_particle_weight = - (m_norm == NormalizationType::unity_particle_weight) ? true : false; + const bool is_unity_particle_weight = (m_norm == NormalizationType::unity_particle_weight); bool const do_parser_filter = m_do_parser_filter; diff --git a/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp b/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp index 6dd2a0db321..5b370d29979 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp @@ -116,10 +116,7 @@ ParticleMomentum::ParticleMomentum (std::string rd_name) void ParticleMomentum::ComputeDiags (int step) { // Check if the diags should be done - if (m_intervals.contains(step+1) == false) - { - return; - } + if (!m_intervals.contains(step+1)) return; // Get MultiParticleContainer class object const auto & mypc = WarpX::GetInstance().GetPartContainer(); diff --git a/Source/Diagnostics/SliceDiagnostic.cpp b/Source/Diagnostics/SliceDiagnostic.cpp index 138ac1d778d..aede8b303b8 100644 --- a/Source/Diagnostics/SliceDiagnostic.cpp +++ b/Source/Diagnostics/SliceDiagnostic.cpp @@ -158,10 +158,10 @@ CreateSlice( const MultiFab& mf, const Vector &dom_geom, } - if (coarsen == false) { + if (!coarsen) { return smf; } - else if ( coarsen == true ) { + else { Vector crse_ba(1); crse_ba[0] = sba[0]; crse_ba[0].coarsen(slice_cr_ratio); @@ -226,13 +226,7 @@ CreateSlice( const MultiFab& mf, const Vector &dom_geom, } return cs_mf; - } - - WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - false, "Should not hit this return statement."); - - return smf; } @@ -363,7 +357,7 @@ CheckSliceInput( const RealBox real_box, RealBox &slice_cc_nd_box, bool modify_cr = true; - while ( modify_cr == true) { + while ( modify_cr ) { int lo_new = index_lo; int hi_new = index_hi; const int mod_lo = index_lo % slice_cr_ratio[idim]; @@ -400,7 +394,7 @@ CheckSliceInput( const RealBox real_box, RealBox &slice_cc_nd_box, modify_cr = true; } - if ( modify_cr == false ) { + if ( !modify_cr ) { index_lo = lo_new; index_hi = hi_new; } diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index b68cd7232b2..a3fc4864dd1 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -1205,9 +1205,8 @@ WarpXOpenPMDPlot::SetupMeshComp (openPMD::Mesh& mesh, // - Global offset std::vector const global_offset = getReversedVec(full_geom.ProbLo()); #if defined(WARPX_DIM_RZ) - auto & warpx = WarpX::GetInstance(); if (var_in_theta_mode) { - global_size.emplace(global_size.begin(), warpx.ncomps); + global_size.emplace(global_size.begin(), WarpX::ncomps); } #endif // - AxisLabels @@ -1249,8 +1248,8 @@ WarpXOpenPMDPlot::GetMeshCompNames (int meshLevel, std::vector< std::string > const field_components = detail::getFieldComponentLabels(var_in_theta_mode); for( std::string const& vector_field : vector_fields ) { for( std::string const& component : field_components ) { - if( vector_field.compare( varname_1st ) == 0 && - component.compare( varname_2nd ) == 0 ) + if( vector_field == varname_1st && + component == varname_2nd ) { field_name = varname_1st + varname.substr(2); // Strip component comp_name = varname_2nd; diff --git a/Source/Evolve/WarpXEvolve.cpp b/Source/Evolve/WarpXEvolve.cpp index a97c8712201..37023c8dde4 100644 --- a/Source/Evolve/WarpXEvolve.cpp +++ b/Source/Evolve/WarpXEvolve.cpp @@ -366,7 +366,7 @@ WarpX::Evolve (int numsteps) // inputs: unused parameters (e.g. typos) check after step 1 has finished if (!early_params_checked) { amrex::Print() << "\n"; // better: conditional \n based on return value - amrex::ParmParse().QueryUnusedInputs(); + amrex::ParmParse::QueryUnusedInputs(); //Print the warning list right after the first step. amrex::Print() << @@ -540,7 +540,7 @@ void WarpX::SyncCurrentAndRho () // Without periodic single box, synchronize J and rho here, // except with current correction or Vay deposition: // in these cases, synchronize later (in WarpX::PushPSATD) - if (current_correction == false && + if (!current_correction && current_deposition_algo != CurrentDepositionAlgo::Vay) { SyncCurrent(current_fp, current_cp, current_buf); diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.cpp b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.cpp index 851ff1a1a69..1bb557d009d 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.cpp @@ -43,7 +43,7 @@ FiniteDifferenceSolver::FiniteDifferenceSolver ( // Calculate coefficients of finite-difference stencil #ifdef WARPX_DIM_RZ m_dr = cell_size[0]; - m_nmodes = WarpX::GetInstance().n_rz_azimuthal_modes; + m_nmodes = WarpX::n_rz_azimuthal_modes; m_rmin = WarpX::GetInstance().Geom(0).ProbLo(0); if (fdtd_algo == ElectromagneticSolverAlgo::Yee || fdtd_algo == ElectromagneticSolverAlgo::HybridPIC ) { diff --git a/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.cpp b/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.cpp index 347a0ad6c1e..7213e599b67 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.cpp @@ -59,8 +59,6 @@ void HybridPICModel::AllocateLevelMFs (int lev, const BoxArray& ba, const Distri const IntVect& jz_nodal_flag, const IntVect& rho_nodal_flag) { - auto & warpx = WarpX::GetInstance(); - // The "electron_pressure_fp" multifab stores the electron pressure calculated // from the specified equation of state. // The "rho_fp_temp" multifab is used to store the ion charge density @@ -69,24 +67,24 @@ void HybridPICModel::AllocateLevelMFs (int lev, const BoxArray& ba, const Distri // interpolated or extrapolated to appropriate timesteps. // The "current_fp_ampere" multifab stores the total current calculated as // the curl of B. - warpx.AllocInitMultiFab(electron_pressure_fp[lev], amrex::convert(ba, rho_nodal_flag), + WarpX::AllocInitMultiFab(electron_pressure_fp[lev], amrex::convert(ba, rho_nodal_flag), dm, ncomps, ngRho, lev, "electron_pressure_fp", 0.0_rt); - warpx.AllocInitMultiFab(rho_fp_temp[lev], amrex::convert(ba, rho_nodal_flag), + WarpX::AllocInitMultiFab(rho_fp_temp[lev], amrex::convert(ba, rho_nodal_flag), dm, ncomps, ngRho, lev, "rho_fp_temp", 0.0_rt); - warpx.AllocInitMultiFab(current_fp_temp[lev][0], amrex::convert(ba, jx_nodal_flag), + WarpX::AllocInitMultiFab(current_fp_temp[lev][0], amrex::convert(ba, jx_nodal_flag), dm, ncomps, ngJ, lev, "current_fp_temp[x]", 0.0_rt); - warpx.AllocInitMultiFab(current_fp_temp[lev][1], amrex::convert(ba, jy_nodal_flag), + WarpX::AllocInitMultiFab(current_fp_temp[lev][1], amrex::convert(ba, jy_nodal_flag), dm, ncomps, ngJ, lev, "current_fp_temp[y]", 0.0_rt); - warpx.AllocInitMultiFab(current_fp_temp[lev][2], amrex::convert(ba, jz_nodal_flag), + WarpX::AllocInitMultiFab(current_fp_temp[lev][2], amrex::convert(ba, jz_nodal_flag), dm, ncomps, ngJ, lev, "current_fp_temp[z]", 0.0_rt); - warpx.AllocInitMultiFab(current_fp_ampere[lev][0], amrex::convert(ba, jx_nodal_flag), + WarpX::AllocInitMultiFab(current_fp_ampere[lev][0], amrex::convert(ba, jx_nodal_flag), dm, ncomps, ngJ, lev, "current_fp_ampere[x]", 0.0_rt); - warpx.AllocInitMultiFab(current_fp_ampere[lev][1], amrex::convert(ba, jy_nodal_flag), + WarpX::AllocInitMultiFab(current_fp_ampere[lev][1], amrex::convert(ba, jy_nodal_flag), dm, ncomps, ngJ, lev, "current_fp_ampere[y]", 0.0_rt); - warpx.AllocInitMultiFab(current_fp_ampere[lev][2], amrex::convert(ba, jz_nodal_flag), + WarpX::AllocInitMultiFab(current_fp_ampere[lev][2], amrex::convert(ba, jz_nodal_flag), dm, ncomps, ngJ, lev, "current_fp_ampere[z]", 0.0_rt); } diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmFirstOrder.cpp b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmFirstOrder.cpp index 946d938c7bf..e396efe12fb 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmFirstOrder.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmFirstOrder.cpp @@ -53,10 +53,10 @@ PsatdAlgorithmFirstOrder::pushSpectralFields (SpectralFieldData& f) const { const bool div_cleaning = m_div_cleaning; - const bool J_constant = (m_J_in_time == JInTime::Constant) ? true : false; - const bool J_linear = (m_J_in_time == JInTime::Linear ) ? true : false; - const bool rho_constant = (m_rho_in_time == RhoInTime::Constant) ? true : false; - const bool rho_linear = (m_rho_in_time == RhoInTime::Linear ) ? true : false; + const bool J_constant = (m_J_in_time == JInTime::Constant); + const bool J_linear = (m_J_in_time == JInTime::Linear); + const bool rho_constant = (m_rho_in_time == RhoInTime::Constant); + const bool rho_linear = (m_rho_in_time == RhoInTime::Linear); const amrex::Real dt = m_dt; const amrex::Real dt2 = dt*dt; diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmRZ.cpp b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmRZ.cpp index f6b3460e235..32825155fe8 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmRZ.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmRZ.cpp @@ -82,7 +82,7 @@ PsatdAlgorithmRZ::pushSpectralFields(SpectralFieldDataRZ & f) const bool update_with_rho = m_update_with_rho; const bool time_averaging = m_time_averaging; - const bool J_linear = (m_J_in_time == JInTime::Linear) ? true : false; + const bool J_linear = (m_J_in_time == JInTime::Linear); const bool dive_cleaning = m_dive_cleaning; const bool divb_cleaning = m_divb_cleaning; @@ -337,7 +337,7 @@ PsatdAlgorithmRZ::pushSpectralFields(SpectralFieldDataRZ & f) void PsatdAlgorithmRZ::InitializeSpectralCoefficients (SpectralFieldDataRZ const & f) { const bool time_averaging = m_time_averaging; - const bool J_linear = (m_J_in_time == JInTime::Linear) ? true : false; + const bool J_linear = (m_J_in_time == JInTime::Linear); // Fill them with the right values: // Loop over boxes and allocate the corresponding coefficients diff --git a/Source/FieldSolver/SpectralSolver/SpectralFieldData.cpp b/Source/FieldSolver/SpectralSolver/SpectralFieldData.cpp index ab4e3971055..0cd7a346352 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralFieldData.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralFieldData.cpp @@ -47,7 +47,7 @@ SpectralFieldIndex::SpectralFieldIndex (const bool update_with_rho, int c = 0; - if (pml == false) + if (!pml) { Ex = c++; Ey = c++; Ez = c++; Bx = c++; By = c++; Bz = c++; @@ -291,15 +291,15 @@ SpectralFieldData::ForwardTransform (const int lev, Complex spectral_field_value = tmp_arr(i,j,k); // Apply proper shift in each dimension #if (AMREX_SPACEDIM >= 2) - if (is_nodal_x==false) spectral_field_value *= xshift_arr[i]; + if (!is_nodal_x) spectral_field_value *= xshift_arr[i]; #endif #if defined(WARPX_DIM_3D) - if (is_nodal_y==false) spectral_field_value *= yshift_arr[j]; - if (is_nodal_z==false) spectral_field_value *= zshift_arr[k]; + if (!is_nodal_y) spectral_field_value *= yshift_arr[j]; + if (!is_nodal_z) spectral_field_value *= zshift_arr[k]; #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - if (is_nodal_z==false) spectral_field_value *= zshift_arr[j]; + if (!is_nodal_z) spectral_field_value *= zshift_arr[j]; #elif defined(WARPX_DIM_1D_Z) - if (is_nodal_z==false) spectral_field_value *= zshift_arr[i]; + if (!is_nodal_z) spectral_field_value *= zshift_arr[i]; #endif // Copy field into the right index fields_arr(i,j,k,field_index) = spectral_field_value; @@ -391,15 +391,15 @@ SpectralFieldData::BackwardTransform (const int lev, Complex spectral_field_value = field_arr(i,j,k,field_index); // Apply proper shift in each dimension #if (AMREX_SPACEDIM >= 2) - if (is_nodal_x==false) spectral_field_value *= xshift_arr[i]; + if (!is_nodal_x) spectral_field_value *= xshift_arr[i]; #endif #if defined(WARPX_DIM_3D) - if (is_nodal_y==false) spectral_field_value *= yshift_arr[j]; - if (is_nodal_z==false) spectral_field_value *= zshift_arr[k]; + if (!is_nodal_y) spectral_field_value *= yshift_arr[j]; + if (!is_nodal_z) spectral_field_value *= zshift_arr[k]; #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - if (is_nodal_z==false) spectral_field_value *= zshift_arr[j]; + if (!is_nodal_z) spectral_field_value *= zshift_arr[j]; #elif defined(WARPX_DIM_1D_Z) - if (is_nodal_z==false) spectral_field_value *= zshift_arr[i]; + if (!is_nodal_z) spectral_field_value *= zshift_arr[i]; #endif // Copy field into temporary array tmp_arr(i,j,k) = spectral_field_value; @@ -444,11 +444,11 @@ SpectralFieldData::BackwardTransform (const int lev, #endif // If necessary, do not fill the guard cells // (shrink box by passing negative number of cells) - if (m_periodic_single_box == false) + if (!m_periodic_single_box) { for (int dir = 0; dir < AMREX_SPACEDIM; dir++) { - if (static_cast(fill_guards[dir]) == false) mf_box.grow(dir, -mf_ng[dir]); + if ((fill_guards[dir]) == 0) mf_box.grow(dir, -mf_ng[dir]); } } diff --git a/Source/FieldSolver/SpectralSolver/SpectralFieldDataRZ.cpp b/Source/FieldSolver/SpectralSolver/SpectralFieldDataRZ.cpp index 10575b1898a..b5e9f4c90d2 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralFieldDataRZ.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralFieldDataRZ.cpp @@ -326,7 +326,7 @@ SpectralFieldDataRZ::FABZForwardTransform (amrex::MFIter const & mfi, amrex::Box [=] AMREX_GPU_DEVICE(int i, int j, int k, int mode) noexcept { Complex spectral_field_value = tmp_arr(i,j,k,mode); // Apply proper shift. - if (is_nodal_z==false) spectral_field_value *= zshift_arr[j]; + if (!is_nodal_z) spectral_field_value *= zshift_arr[j]; // Copy field into the correct index. int const ic = field_index + mode*n_fields; fields_arr(i,j,k,ic) = spectral_field_value*inv_nz; @@ -364,7 +364,7 @@ SpectralFieldDataRZ::FABZBackwardTransform (amrex::MFIter const & mfi, amrex::Bo int const ic = field_index + mode*n_fields; Complex spectral_field_value = fields_arr(i,j,k,ic); // Apply proper shift. - if (is_nodal_z==false) spectral_field_value *= zshift_arr[j]; + if (!is_nodal_z) spectral_field_value *= zshift_arr[j]; // Copy field into the right index. tmp_arr(i,j,k,mode) = spectral_field_value; }); diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index ed6490c825c..0e1bb4aa785 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -330,7 +330,7 @@ WarpX::PrintMainPICparameters () amrex::Print() << " | - current_centering_noz = " << WarpX::current_centering_noz << "\n"; } } - if (WarpX::use_hybrid_QED == true){ + if (WarpX::use_hybrid_QED){ amrex::Print() << " | - use_hybrid_QED = true \n"; } diff --git a/Source/Parallelization/WarpXRegrid.cpp b/Source/Parallelization/WarpXRegrid.cpp index 358316fc9d8..d890046dac6 100644 --- a/Source/Parallelization/WarpXRegrid.cpp +++ b/Source/Parallelization/WarpXRegrid.cpp @@ -233,7 +233,7 @@ WarpX::RemakeLevel (int lev, Real /*time*/, const BoxArray& ba, const Distributi auto dx = CellSize(lev); # ifdef WARPX_DIM_RZ - if ( fft_periodic_single_box == false ) { + if ( !fft_periodic_single_box ) { realspace_ba.grow(1, ngEB[1]); // add guard cells only in z } AllocLevelSpectralSolverRZ(spectral_solver_fp, @@ -242,7 +242,7 @@ WarpX::RemakeLevel (int lev, Real /*time*/, const BoxArray& ba, const Distributi dm, dx); # else - if ( fft_periodic_single_box == false ) { + if ( !fft_periodic_single_box ) { realspace_ba.grow(ngEB); // add guard cells } bool const pml_flag_false = false; diff --git a/Source/Particles/Collision/BinaryCollision/BinaryCollision.H b/Source/Particles/Collision/BinaryCollision/BinaryCollision.H index 2d6cba8b2dc..c521826814f 100644 --- a/Source/Particles/Collision/BinaryCollision/BinaryCollision.H +++ b/Source/Particles/Collision/BinaryCollision/BinaryCollision.H @@ -90,10 +90,7 @@ public: if(m_species_names.size() != 2) WARPX_ABORT_WITH_MESSAGE("Binary collision " + collision_name + " must have exactly two species."); - if (m_species_names[0] == m_species_names[1]) - m_isSameSpecies = true; - else - m_isSameSpecies = false; + m_isSameSpecies = (m_species_names[0] == m_species_names[1]); m_binary_collision_functor = CollisionFunctorType(collision_name, mypc, m_isSameSpecies); diff --git a/Source/Particles/LaserParticleContainer.cpp b/Source/Particles/LaserParticleContainer.cpp index 73e27b3c51b..6fb8aa97456 100644 --- a/Source/Particles/LaserParticleContainer.cpp +++ b/Source/Particles/LaserParticleContainer.cpp @@ -655,7 +655,7 @@ LaserParticleContainer::Evolve (int lev, WARPX_PROFILE_VAR_STOP(blp_pp); // Current Deposition - if (skip_deposition == false) + if (!skip_deposition) { // Deposit at t_{n+1/2} const amrex::Real relative_time = -0.5_rt * dt; diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 59815d150e3..3eb4cfba8d9 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -376,8 +376,8 @@ protected: MFItInfoCheckTiling(pc_src, pc_dsts...); - if (pc_src.do_tiling && amrex::Gpu::notInLaunchRegion()) { - info.EnableTiling(pc_src.tile_size); + if (WarpXParticleContainer::do_tiling && amrex::Gpu::notInLaunchRegion()) { + info.EnableTiling(WarpXParticleContainer::tile_size); } #ifdef AMREX_USE_OMP @@ -496,7 +496,7 @@ private: void MFItInfoCheckTiling(const WarpXParticleContainer& pc_src, First const& pc_dst, Args const&... others) const noexcept { - if (pc_src.do_tiling && amrex::Gpu::notInLaunchRegion()) { + if (WarpXParticleContainer::do_tiling && amrex::Gpu::notInLaunchRegion()) { WARPX_ALWAYS_ASSERT_WITH_MESSAGE(pc_dst.do_tiling, "For particle creation processes, either all or none of the " "particle species must use tiling."); diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 143847d4d42..56fdbc378d5 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -2059,10 +2059,12 @@ PhysicalParticleContainer::Evolve (int lev, // Gather and push for particles not in the buffer // WARPX_PROFILE_VAR_START(blp_fg); + const auto np_to_push = np_gather; + const auto gather_lev = lev; PushPX(pti, exfab, eyfab, ezfab, bxfab, byfab, bzfab, Ex.nGrowVect(), e_is_nodal, - 0, np_gather, lev, lev, dt, ScaleFields(false), a_dt_type); + 0, np_to_push, lev, gather_lev, dt, ScaleFields(false), a_dt_type); if (np_gather < np) { @@ -2103,7 +2105,7 @@ PhysicalParticleContainer::Evolve (int lev, WARPX_PROFILE_VAR_STOP(blp_fg); // Current Deposition - if (skip_deposition == false) + if (!skip_deposition) { // Deposit at t_{n+1/2} const amrex::Real relative_time = -0.5_rt * dt; diff --git a/Source/Particles/Resampling/Resampling.cpp b/Source/Particles/Resampling/Resampling.cpp index 40510a05c22..63ac448880b 100644 --- a/Source/Particles/Resampling/Resampling.cpp +++ b/Source/Particles/Resampling/Resampling.cpp @@ -18,7 +18,7 @@ Resampling::Resampling (const std::string species_name) std::string resampling_algorithm_string = "leveling_thinning"; // default resampling algorithm pp_species_name.query("resampling_algorithm", resampling_algorithm_string); - if (resampling_algorithm_string.compare("leveling_thinning") == 0) + if (resampling_algorithm_string == "leveling_thinning") { m_resampling_algorithm = std::make_unique(species_name); } diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index f0f745f76fc..ea9a6b3ecb3 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -1013,7 +1013,7 @@ WarpXParticleContainer::DepositCharge (amrex::VectornGrowVect()` in the fifth input variable `dst_ng` ablastr::utils::communication::SumBoundary( @@ -1106,7 +1106,7 @@ WarpXParticleContainer::GetChargeDensity (int lev, bool local) WarpX::GetInstance().ApplyInverseVolumeScalingToChargeDensity(rho.get(), lev); #endif - if (local == false) { + if (!local) { // Possible performance optimization: // pass less than `rho->nGrowVect()` in the fifth input variable `dst_ng` ablastr::utils::communication::SumBoundary( @@ -1146,7 +1146,7 @@ amrex::ParticleReal WarpXParticleContainer::sumParticleCharge(bool local) { total_charge = get<0>(reduce_data.value()); - if (local == false) ParallelDescriptor::ReduceRealSum(total_charge); + if (!local) ParallelDescriptor::ReduceRealSum(total_charge); total_charge *= this->charge; return total_charge; } @@ -1222,7 +1222,7 @@ std::array WarpXParticleContainer::meanParticleVelocity(bool lo } } - if (local == false) { + if (!local) { ParallelDescriptor::ReduceRealSum({vx_total,vy_total,vz_total}); ParallelDescriptor::ReduceLongSum(np_total); } @@ -1259,7 +1259,7 @@ amrex::ParticleReal WarpXParticleContainer::maxParticleVelocity(bool local) { } } - if (local == false) ParallelAllReduce::Max(max_v, ParallelDescriptor::Communicator()); + if (!local) ParallelAllReduce::Max(max_v, ParallelDescriptor::Communicator()); return max_v; } diff --git a/Source/Utils/WarpXMovingWindow.cpp b/Source/Utils/WarpXMovingWindow.cpp index e43740d87e2..f62453f63b9 100644 --- a/Source/Utils/WarpXMovingWindow.cpp +++ b/Source/Utils/WarpXMovingWindow.cpp @@ -135,7 +135,7 @@ WarpX::MoveWindow (const int step, bool move_j) if (step == end_moving_window_step) { amrex::Print() << Utils::TextMsg::Info("Stopping moving window"); } - if (moving_window_active(step) == false) return 0; + if (!moving_window_active(step)) return 0; // Update the continuous position of the moving window, // and of the plasma injection @@ -491,12 +491,12 @@ WarpX::shiftMF (amrex::MultiFab& mf, const amrex::Geometry& geom, const amrex::Box& outbox = mfi.fabbox() & adjBox; if (outbox.ok()) { - if (useparser == false) { + if (!useparser) { AMREX_PARALLEL_FOR_4D ( outbox, nc, i, j, k, n, { srcfab(i,j,k,n) = external_field; }) - } else if (useparser == true) { + } else { // index type of the src mf auto const& mf_IndexType = (tmpmf).ixType(); amrex::IntVect mf_type(AMREX_D_DECL(0,0,0)); diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index f5826fd9369..24e3ceb303f 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -1144,7 +1144,7 @@ WarpX::ReadParameters () // - field_gathering_algo set to "default" above // (default defined in Utils/WarpXAlgorithmSelection.cpp) // - reset default value here for hybrid grids - if (pp_algo.query("field_gathering", tmp_algo) == false) + if (!pp_algo.query("field_gathering", tmp_algo)) { if (grid_type == GridType::Hybrid) { @@ -1371,7 +1371,7 @@ WarpX::ReadParameters () J_in_time = GetAlgorithmInteger(pp_psatd, "J_in_time"); rho_in_time = GetAlgorithmInteger(pp_psatd, "rho_in_time"); - if (psatd_solution_type != PSATDSolutionType::FirstOrder || do_multi_J == false) + if (psatd_solution_type != PSATDSolutionType::FirstOrder || !do_multi_J) { WARPX_ALWAYS_ASSERT_WITH_MESSAGE( rho_in_time == RhoInTime::Linear, @@ -1396,7 +1396,7 @@ WarpX::ReadParameters () pp_psatd.query("current_correction", current_correction); - if (current_correction == false && + if (!current_correction && current_deposition_algo != CurrentDepositionAlgo::Esirkepov && current_deposition_algo != CurrentDepositionAlgo::Vay) { @@ -1415,18 +1415,18 @@ WarpX::ReadParameters () if (WarpX::current_deposition_algo == CurrentDepositionAlgo::Vay) { WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - fft_periodic_single_box == false, + !fft_periodic_single_box, "Option algo.current_deposition=vay must be used with psatd.periodic_single_box_fft=0."); } if (current_deposition_algo == CurrentDepositionAlgo::Vay) { WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - current_correction == false, + !current_correction, "Options algo.current_deposition=vay and psatd.current_correction=1 cannot be combined together."); } - // Auxiliary: boosted_frame = true if warpx.gamma_boost is set in the inputs + // Auxiliary: boosted_frame = true if WarpX::gamma_boost is set in the inputs const amrex::ParmParse pp_warpx("warpx"); const bool boosted_frame = pp_warpx.query("gamma_boost", gamma_boost); @@ -1436,10 +1436,10 @@ WarpX::ReadParameters () WARPX_ALWAYS_ASSERT_WITH_MESSAGE( !use_default_v_galilean || boosted_frame, - "psatd.use_default_v_galilean = 1 can be used only if warpx.gamma_boost is also set" + "psatd.use_default_v_galilean = 1 can be used only if WarpX::gamma_boost is also set" ); - if (use_default_v_galilean == true && boosted_frame == true) + if (use_default_v_galilean && boosted_frame) { m_v_galilean[2] = -std::sqrt(1._rt - 1._rt / (gamma_boost * gamma_boost)); } @@ -1455,10 +1455,10 @@ WarpX::ReadParameters () WARPX_ALWAYS_ASSERT_WITH_MESSAGE( !use_default_v_comoving || boosted_frame, - "psatd.use_default_v_comoving = 1 can be used only if warpx.gamma_boost is also set" + "psatd.use_default_v_comoving = 1 can be used only if WarpX::gamma_boost is also set" ); - if (use_default_v_comoving == true && boosted_frame == true) + if (use_default_v_comoving && boosted_frame) { m_v_comoving[2] = -std::sqrt(1._rt - 1._rt / (gamma_boost * gamma_boost)); } @@ -1509,7 +1509,7 @@ WarpX::ReadParameters () # else if (m_v_galilean[0] == 0. && m_v_galilean[1] == 0. && m_v_galilean[2] == 0. && m_v_comoving[0] == 0. && m_v_comoving[1] == 0. && m_v_comoving[2] == 0.) { - update_with_rho = (do_dive_cleaning) ? true : false; // standard PSATD + update_with_rho = do_dive_cleaning; // standard PSATD } else { update_with_rho = true; // Galilean PSATD or comoving PSATD @@ -1583,7 +1583,7 @@ WarpX::ReadParameters () // Without periodic single box, fill guard cells with backward FFTs, // with current correction or Vay deposition - if (fft_periodic_single_box == false) + if (!fft_periodic_single_box) { if (current_correction || current_deposition_algo == CurrentDepositionAlgo::Vay) @@ -2346,7 +2346,7 @@ WarpX::AllocLevelMFs (int lev, const BoxArray& ba, const DistributionMapping& dm realspace_ba.enclosedCells(); // Make it cell-centered // Define spectral solver # ifdef WARPX_DIM_RZ - if ( fft_periodic_single_box == false ) { + if ( !fft_periodic_single_box ) { realspace_ba.grow(1, ngEB[1]); // add guard cells only in z } if (field_boundary_hi[0] == FieldBoundaryType::PML && !do_pml_in_domain) { @@ -2360,7 +2360,7 @@ WarpX::AllocLevelMFs (int lev, const BoxArray& ba, const DistributionMapping& dm dm, dx); # else - if ( fft_periodic_single_box == false ) { + if ( !fft_periodic_single_box ) { realspace_ba.grow(ngEB); // add guard cells } bool const pml_flag_false = false; From b0b24a88c559d0359ef7d6a4493a5b565631954d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 1 Aug 2023 14:53:37 +0000 Subject: [PATCH 15/18] [pre-commit.ci] pre-commit autoupdate (#4145) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/hadialqattan/pycln: v2.1.6 → v2.2.0](https://github.com/hadialqattan/pycln/compare/v2.1.6...v2.2.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cb9abfdbbdf..b441fe3861c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -68,7 +68,7 @@ repos: # Autoremoves unused Python imports - repo: https://github.com/hadialqattan/pycln - rev: v2.1.6 + rev: v2.2.0 hooks: - id: pycln name: pycln (python) From be07243696a263fe3f7284d6031bf693bec662aa Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 2 Aug 2023 00:01:19 +0200 Subject: [PATCH 16/18] Clang tidy CI test: add almost all the cert-* checks (#4063) --- .clang-tidy | 2 ++ Source/Diagnostics/BTDiagnostics.cpp | 47 +++++++++++++++++++--------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 987c3c2a9f3..8bc92cefb4f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -3,6 +3,8 @@ Checks: '-*, -bugprone-easily-swappable-parameters, -bugprone-implicit-widening-of-multiplication-result, -bugprone-misplaced-widening-cast, + cert-* + -cert-err58-cpp, cppcoreguidelines-avoid-goto, cppcoreguidelines-interfaces-global-init, -cppcoreguidelines-avoid-non-const-global-variables, diff --git a/Source/Diagnostics/BTDiagnostics.cpp b/Source/Diagnostics/BTDiagnostics.cpp index 71834beadd0..be168f3ca2e 100644 --- a/Source/Diagnostics/BTDiagnostics.cpp +++ b/Source/Diagnostics/BTDiagnostics.cpp @@ -1159,8 +1159,12 @@ void BTDiagnostics::MergeBuffersForPlotfile (int i_snapshot) const std::string snapshot_WarpXHeader_path = snapshot_path + "/WarpXHeader"; const std::string buffer_job_info_path = recent_Buffer_filepath + "/warpx_job_info"; const std::string snapshot_job_info_path = snapshot_path + "/warpx_job_info"; - std::rename(buffer_WarpXHeader_path.c_str(), snapshot_WarpXHeader_path.c_str()); - std::rename(buffer_job_info_path.c_str(), snapshot_job_info_path.c_str()); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + std::rename(buffer_WarpXHeader_path.c_str(), snapshot_WarpXHeader_path.c_str()) == 0, + std::string("Renaming ").append(buffer_WarpXHeader_path).append(" to ").append(snapshot_WarpXHeader_path).append(" has failed")); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + std::rename(buffer_job_info_path.c_str(), snapshot_job_info_path.c_str()) == 0, + std::string("Renaming ").append(buffer_job_info_path).append(" to ").append(snapshot_job_info_path).append(" has failed")); } if (m_do_back_transformed_fields) { @@ -1184,15 +1188,19 @@ void BTDiagnostics::MergeBuffersForPlotfile (int i_snapshot) const std::string new_snapshotFabFilename = amrex::Concatenate("Cell_D_", m_buffer_flush_counter[i_snapshot], amrex_fabfile_digits); if (m_buffer_flush_counter[i_snapshot] == 0 || m_first_flush_after_restart[i_snapshot] == 1) { - std::rename(recent_Header_filename.c_str(), snapshot_Header_filename.c_str()); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + std::rename(recent_Header_filename.c_str(), snapshot_Header_filename.c_str()) == 0, + std::string("Renaming ").append(recent_Header_filename).append(" to ").append(snapshot_Header_filename).append(" has failed")); Buffer_FabHeader.SetFabName(0, Buffer_FabHeader.fodPrefix(0), new_snapshotFabFilename, Buffer_FabHeader.FabHead(0)); Buffer_FabHeader.WriteMultiFabHeader(); - std::rename(recent_Buffer_FabHeaderFilename.c_str(), - snapshot_FabHeaderFilename.c_str()); - std::rename(recent_Buffer_FabFilename.c_str(), - snapshot_FabFilename.c_str()); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + std::rename(recent_Buffer_FabHeaderFilename.c_str(), snapshot_FabHeaderFilename.c_str()) == 0, + std::string("Renaming ").append(recent_Buffer_FabHeaderFilename).append(" to ").append(snapshot_FabHeaderFilename).append(" has failed")); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + std::rename(recent_Buffer_FabFilename.c_str(), snapshot_FabFilename.c_str()) == 0, + std::string("Renaming ").append(recent_Buffer_FabFilename).append(" to ").append(snapshot_FabFilename).append(" has failed")); } else { // Interleave Header file InterleaveBufferAndSnapshotHeader(recent_Header_filename, @@ -1200,8 +1208,9 @@ void BTDiagnostics::MergeBuffersForPlotfile (int i_snapshot) InterleaveFabArrayHeader(recent_Buffer_FabHeaderFilename, snapshot_FabHeaderFilename, new_snapshotFabFilename); - std::rename(recent_Buffer_FabFilename.c_str(), - snapshot_FabFilename.c_str()); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + std::rename(recent_Buffer_FabFilename.c_str(), snapshot_FabFilename.c_str()) == 0, + std::string("Renaming ").append(recent_Buffer_FabFilename).append(" to ").append(snapshot_FabFilename).append(" has failed")); } } for (int i = 0; i < m_particles_buffer[i_snapshot].size(); ++i) { @@ -1234,22 +1243,32 @@ void BTDiagnostics::MergeBuffersForPlotfile (int i_snapshot) BufferSpeciesHeader.WriteHeader(); // copy Header file for the species - std::rename(recent_species_Header.c_str(), snapshot_species_Header.c_str()); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + std::rename(recent_species_Header.c_str(), snapshot_species_Header.c_str()) == 0, + std::string("Renaming ").append(recent_species_Header).append(" to ").append(snapshot_species_Header).append(" has failed")); if (BufferSpeciesHeader.m_total_particles == 0) continue; // if finite number of particles in the output, copy ParticleHdr and Data file - std::rename(recent_ParticleHdrFilename.c_str(), snapshot_ParticleHdrFilename.c_str()); - std::rename(recent_ParticleDataFilename.c_str(), snapshot_ParticleDataFilename.c_str()); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + std::rename(recent_ParticleHdrFilename.c_str(), snapshot_ParticleHdrFilename.c_str()) == 0, + std::string("Renaming ").append(recent_ParticleHdrFilename).append(" to ").append(snapshot_ParticleHdrFilename).append(" has failed")); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + std::rename(recent_ParticleDataFilename.c_str(), snapshot_ParticleDataFilename.c_str()) == 0, + std::string("Renaming ").append(recent_ParticleDataFilename).append(" to ").append(snapshot_ParticleDataFilename).append(" has failed")); } else { InterleaveSpeciesHeader(recent_species_Header,snapshot_species_Header, m_output_species_names[i], m_buffer_flush_counter[i_snapshot]); if (BufferSpeciesHeader.m_total_particles == 0) continue; if (m_totalParticles_flushed_already[i_snapshot][i]==0) { - std::rename(recent_ParticleHdrFilename.c_str(), snapshot_ParticleHdrFilename.c_str()); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + std::rename(recent_ParticleHdrFilename.c_str(), snapshot_ParticleHdrFilename.c_str()) == 0, + std::string("Renaming ").append(recent_ParticleHdrFilename).append(" to ").append(snapshot_ParticleHdrFilename).append(" has failed")); } else { InterleaveParticleDataHeader(recent_ParticleHdrFilename, snapshot_ParticleHdrFilename); } - std::rename(recent_ParticleDataFilename.c_str(), snapshot_ParticleDataFilename.c_str()); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + std::rename(recent_ParticleDataFilename.c_str(), snapshot_ParticleDataFilename.c_str()) == 0, + std::string("Renaming ").append(recent_ParticleDataFilename).append(" to ").append(snapshot_ParticleDataFilename).append(" has failed")); } } // Destroying the recently flushed buffer directory since it is already merged. From 1064077dd142362ee169844b511c9d3652a32f00 Mon Sep 17 00:00:00 2001 From: Arianna Formenti Date: Mon, 12 Jun 2023 16:27:53 -0700 Subject: [PATCH 17/18] added nodal electrostatic solver --- Source/FieldSolver/ElectrostaticSolver.cpp | 339 ++++++++++++++------- 1 file changed, 226 insertions(+), 113 deletions(-) diff --git a/Source/FieldSolver/ElectrostaticSolver.cpp b/Source/FieldSolver/ElectrostaticSolver.cpp index 3cb01efd31f..3e9bdfde371 100644 --- a/Source/FieldSolver/ElectrostaticSolver.cpp +++ b/Source/FieldSolver/ElectrostaticSolver.cpp @@ -476,21 +476,16 @@ WarpX::computeE (amrex::Vector, 3> > #else const Real inv_dz = 1._rt/dx[0]; #endif -#if (AMREX_SPACEDIM >= 2) - const Box& tbx = mfi.tilebox( E[lev][0]->ixType().toIntVect() ); -#endif -#if defined(WARPX_DIM_3D) - const Box& tby = mfi.tilebox( E[lev][1]->ixType().toIntVect() ); -#endif - const Box& tbz = mfi.tilebox( E[lev][2]->ixType().toIntVect() ); + const IntVect ex_type = E[lev][0]->ixType().toIntVect(); + const Box& tbx = mfi.tilebox( ex_type ); + const IntVect ey_type = E[lev][1]->ixType().toIntVect(); + const Box& tby = mfi.tilebox( ey_type ); + const IntVect ez_type = E[lev][2]->ixType().toIntVect(); + const Box& tbz = mfi.tilebox( ez_type ); const auto& phi_arr = phi[lev]->array(mfi); -#if (AMREX_SPACEDIM >= 2) const auto& Ex_arr = (*E[lev][0])[mfi].array(); -#endif -#if defined(WARPX_DIM_3D) const auto& Ey_arr = (*E[lev][1])[mfi].array(); -#endif const auto& Ez_arr = (*E[lev][2])[mfi].array(); const Real beta_x = beta[0]; @@ -499,58 +494,118 @@ WarpX::computeE (amrex::Vector, 3> > // Calculate the electric field // Use discretized derivative that matches the staggering of the grid. + // Nodal solver + if ((ex_type == IntVect::TheNodeVector()) && (ey_type == IntVect::TheNodeVector()) && (ez_type == IntVect::TheNodeVector())){ #if defined(WARPX_DIM_3D) - amrex::ParallelFor( tbx, tby, tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ex_arr(i,j,k) += - +(beta_x*beta_x-1)*inv_dx*( phi_arr(i+1,j,k)-phi_arr(i,j,k) ) - +beta_x*beta_y*0.25_rt*inv_dy*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k) - + phi_arr(i+1,j+1,k)-phi_arr(i+1,j-1,k)) - +beta_x*beta_z*0.25_rt*inv_dz*(phi_arr(i ,j,k+1)-phi_arr(i ,j,k-1) - + phi_arr(i+1,j,k+1)-phi_arr(i+1,j,k-1)); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ey_arr(i,j,k) += - +beta_y*beta_x*0.25_rt*inv_dx*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k) - + phi_arr(i+1,j+1,k)-phi_arr(i-1,j+1,k)) - +(beta_y*beta_y-1)*inv_dy*( phi_arr(i,j+1,k)-phi_arr(i,j,k) ) - +beta_y*beta_z*0.25_rt*inv_dz*(phi_arr(i,j ,k+1)-phi_arr(i,j ,k-1) - + phi_arr(i,j+1,k+1)-phi_arr(i,j+1,k-1)); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ez_arr(i,j,k) += - +beta_z*beta_x*0.25_rt*inv_dx*(phi_arr(i+1,j,k )-phi_arr(i-1,j,k ) - + phi_arr(i+1,j,k+1)-phi_arr(i-1,j,k+1)) - +beta_z*beta_y*0.25_rt*inv_dy*(phi_arr(i,j+1,k )-phi_arr(i,j-1,k ) - + phi_arr(i,j+1,k+1)-phi_arr(i,j-1,k+1)) - +(beta_z*beta_z-1)*inv_dz*( phi_arr(i,j,k+1)-phi_arr(i,j,k) ); - } - ); + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ex_arr(i,j,k) += + +(beta_x*beta_x-1)*0.5_rt*inv_dx*(phi_arr(i+1,j,k)-phi_arr(i-1,j,k)) + +beta_x*beta_y*0.5_rt*inv_dy*(phi_arr(i,j+1,k)-phi_arr(i,j-1,k)) + +beta_x*beta_z*0.5_rt*inv_dz*(phi_arr(i,j,k+1)-phi_arr(i,j,k-1)); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ey_arr(i,j,k) += + +beta_y*beta_x*0.5_rt*inv_dx*(phi_arr(i+1,j,k)-phi_arr(i-1,j,k)) + +(beta_y*beta_y-1)*0.5_rt*inv_dy*( phi_arr(i,j+1,k)-phi_arr(i,j-1,k) ) + +beta_y*beta_z*0.5_rt*inv_dz*(phi_arr(i,j,k+1)-phi_arr(i,j,k-1)); }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ez_arr(i,j,k) += + +beta_z*beta_x*0.5_rt*inv_dx*(phi_arr(i+1,j,k)-phi_arr(i-1,j,k)) + +beta_z*beta_y*0.5_rt*inv_dy*(phi_arr(i,j+1,k)-phi_arr(i,j-1,k)) + +(beta_z*beta_z-1)*0.5_rt*inv_dz*( phi_arr(i,j,k+1)-phi_arr(i,j,k-1) ); + } + ); #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - amrex::ParallelFor( tbx, tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ex_arr(i,j,k) += - +(beta_x*beta_x-1)*inv_dx*( phi_arr(i+1,j,k)-phi_arr(i,j,k) ) - +beta_x*beta_z*0.25_rt*inv_dz*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k) - + phi_arr(i+1,j+1,k)-phi_arr(i+1,j-1,k)); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ez_arr(i,j,k) += - +beta_z*beta_x*0.25_rt*inv_dx*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k) - + phi_arr(i+1,j+1,k)-phi_arr(i-1,j+1,k)) - +(beta_z*beta_z-1)*inv_dz*( phi_arr(i,j+1,k)-phi_arr(i,j,k) ); - } - ); - ignore_unused(beta_y); + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ex_arr(i,j,k) += + +(beta_x*beta_x-1)*0.5_rt*inv_dx*( phi_arr(i+1,j,k)-phi_arr(i-1,j,k) ) + +beta_x*beta_z*0.5_rt*inv_dz*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k)); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ey_arr(i,j,k) += + +beta_x*beta_y*0.5_rt*inv_dx*( phi_arr(i+1,j,k)-phi_arr(i-1,j,k) ) + +beta_y*beta_z*0.5_rt*inv_dz*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k)); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ez_arr(i,j,k) += + +beta_z*beta_x*0.5_rt*inv_dx*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k)) + +(beta_z*beta_z-1)*0.5_rt*inv_dz*( phi_arr(i,j+1,k)-phi_arr(i,j-1,k) ); + } + ); #else - amrex::ParallelFor( tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Ez_arr(i,j,k) += - +(beta_z*beta_z-1)*inv_dz*( phi_arr(i+1,j,k)-phi_arr(i,j,k) ); - } - ); - ignore_unused(beta_x,beta_y); + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ex_arr(i,j,k) += + +(beta_x*beta_z-1)*0.5_rt*inv_dz*( phi_arr(i+1,j,k)-phi_arr(i-1,j,k) ); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ey_arr(i,j,k) += + +beta_y*beta_z*0.5_rt*inv_dz*( phi_arr(i+1,j,k)-phi_arr(i-1,j,k)); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ez_arr(i,j,k) += + +(beta_z*beta_z-1)*0.5_rt*inv_dz*( phi_arr(i+1,j,k)-phi_arr(i-1,j,k) ); + } + ); +#endif + } + else{ + // Staggered solver +#if defined(WARPX_DIM_3D) + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ex_arr(i,j,k) += + +(beta_x*beta_x-1)*inv_dx*( phi_arr(i+1,j,k)-phi_arr(i,j,k) ) + +beta_x*beta_y*0.25_rt*inv_dy*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k) + + phi_arr(i+1,j+1,k)-phi_arr(i+1,j-1,k)) + +beta_x*beta_z*0.25_rt*inv_dz*(phi_arr(i ,j,k+1)-phi_arr(i ,j,k-1) + + phi_arr(i+1,j,k+1)-phi_arr(i+1,j,k-1)); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ey_arr(i,j,k) += + +beta_y*beta_x*0.25_rt*inv_dx*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k) + + phi_arr(i+1,j+1,k)-phi_arr(i-1,j+1,k)) + +(beta_y*beta_y-1)*inv_dy*( phi_arr(i,j+1,k)-phi_arr(i,j,k) ) + +beta_y*beta_z*0.25_rt*inv_dz*(phi_arr(i,j ,k+1)-phi_arr(i,j ,k-1) + + phi_arr(i,j+1,k+1)-phi_arr(i,j+1,k-1)); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ez_arr(i,j,k) += + +beta_z*beta_x*0.25_rt*inv_dx*(phi_arr(i+1,j,k )-phi_arr(i-1,j,k ) + + phi_arr(i+1,j,k+1)-phi_arr(i-1,j,k+1)) + +beta_z*beta_y*0.25_rt*inv_dy*(phi_arr(i,j+1,k )-phi_arr(i,j-1,k ) + + phi_arr(i,j+1,k+1)-phi_arr(i,j-1,k+1)) + +(beta_z*beta_z-1)*inv_dz*( phi_arr(i,j,k+1)-phi_arr(i,j,k) ); + } + ); +#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) + amrex::ParallelFor( tbx, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ex_arr(i,j,k) += + +(beta_x*beta_x-1)*inv_dx*( phi_arr(i+1,j,k)-phi_arr(i,j,k) ) + +beta_x*beta_z*0.25_rt*inv_dz*(phi_arr(i ,j+1,k)-phi_arr(i ,j-1,k) + + phi_arr(i+1,j+1,k)-phi_arr(i+1,j-1,k)); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ez_arr(i,j,k) += + +beta_z*beta_x*0.25_rt*inv_dx*(phi_arr(i+1,j ,k)-phi_arr(i-1,j ,k) + + phi_arr(i+1,j+1,k)-phi_arr(i-1,j+1,k)) + +(beta_z*beta_z-1)*inv_dz*( phi_arr(i,j+1,k)-phi_arr(i,j,k) ); + } + ); + ignore_unused(beta_y); +#else + amrex::ParallelFor( tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Ez_arr(i,j,k) += + +(beta_z*beta_z-1)*inv_dz*( phi_arr(i+1,j,k)-phi_arr(i,j,k) ); + } + ); + ignore_unused(beta_x,beta_y); #endif + } } } } @@ -597,9 +652,14 @@ WarpX::computeB (amrex::Vector, 3> > #else const Real inv_dz = 1._rt/dx[0]; #endif - const Box& tbx = mfi.tilebox( B[lev][0]->ixType().toIntVect() ); - const Box& tby = mfi.tilebox( B[lev][1]->ixType().toIntVect() ); - const Box& tbz = mfi.tilebox( B[lev][2]->ixType().toIntVect() ); + + const IntVect bx_type = B[lev][0]->ixType().toIntVect(); + const IntVect by_type = B[lev][1]->ixType().toIntVect(); + const IntVect bz_type = B[lev][2]->ixType().toIntVect(); + + const Box& tbx = mfi.tilebox( bx_type ); + const Box& tby = mfi.tilebox( by_type ); + const Box& tbz = mfi.tilebox( bz_type ); const auto& phi_arr = phi[lev]->array(mfi); const auto& Bx_arr = (*B[lev][0])[mfi].array(); @@ -614,61 +674,114 @@ WarpX::computeB (amrex::Vector, 3> > // Calculate the magnetic field // Use discretized derivative that matches the staggering of the grid. + // Nodal solver + if ((bx_type == IntVect::TheNodeVector()) && (by_type == IntVect::TheNodeVector()) && (bz_type == IntVect::TheNodeVector())){ #if defined(WARPX_DIM_3D) - amrex::ParallelFor( tbx, tby, tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Bx_arr(i,j,k) += inv_c * ( - -beta_y*inv_dz*0.5_rt*(phi_arr(i,j ,k+1)-phi_arr(i,j ,k) - + phi_arr(i,j+1,k+1)-phi_arr(i,j+1,k)) - +beta_z*inv_dy*0.5_rt*(phi_arr(i,j+1,k )-phi_arr(i,j,k ) - + phi_arr(i,j+1,k+1)-phi_arr(i,j,k+1))); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - By_arr(i,j,k) += inv_c * ( - -beta_z*inv_dx*0.5_rt*(phi_arr(i+1,j,k )-phi_arr(i,j,k ) - + phi_arr(i+1,j,k+1)-phi_arr(i,j,k+1)) - +beta_x*inv_dz*0.5_rt*(phi_arr(i ,j,k+1)-phi_arr(i ,j,k) - + phi_arr(i+1,j,k+1)-phi_arr(i+1,j,k))); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Bz_arr(i,j,k) += inv_c * ( - -beta_x*inv_dy*0.5_rt*(phi_arr(i ,j+1,k)-phi_arr(i ,j,k) - + phi_arr(i+1,j+1,k)-phi_arr(i+1,j,k)) - +beta_y*inv_dx*0.5_rt*(phi_arr(i+1,j ,k)-phi_arr(i,j ,k) - + phi_arr(i+1,j+1,k)-phi_arr(i,j+1,k))); - } - ); + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bx_arr(i,j,k) += inv_c * ( + -beta_y*inv_dz*0.5_rt*(phi_arr(i,j,k+1)-phi_arr(i,j,k-1)) + +beta_z*inv_dy*0.5_rt*(phi_arr(i,j+1,k)-phi_arr(i,j-1,k)) ); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + By_arr(i,j,k) += inv_c * ( + -beta_z*inv_dx*0.5_rt*(phi_arr(i+1,j,k)-phi_arr(i-1,j,k)) + +beta_x*inv_dz*0.5_rt*(phi_arr(i,j,k+1)-phi_arr(i,j,k-1)) ); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bz_arr(i,j,k) += inv_c * ( + -beta_x*inv_dy*0.5_rt*(phi_arr(i,j+1,k)-phi_arr(i,j-1,k)) + +beta_y*inv_dx*0.5_rt*(phi_arr(i+1,j,k)-phi_arr(i-1,j,k)) ); + } + ); #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - amrex::ParallelFor( tbx, tby, tbz, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Bx_arr(i,j,k) += inv_c * ( - -beta_y*inv_dz*( phi_arr(i,j+1,k)-phi_arr(i,j,k) )); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - By_arr(i,j,k) += inv_c * ( - -beta_z*inv_dx*0.5_rt*(phi_arr(i+1,j ,k)-phi_arr(i,j ,k) - + phi_arr(i+1,j+1,k)-phi_arr(i,j+1,k)) - +beta_x*inv_dz*0.5_rt*(phi_arr(i ,j+1,k)-phi_arr(i ,j,k) - + phi_arr(i+1,j+1,k)-phi_arr(i+1,j,k))); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Bz_arr(i,j,k) += inv_c * ( - +beta_y*inv_dx*( phi_arr(i+1,j,k)-phi_arr(i,j,k) )); - } - ); + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bx_arr(i,j,k) += inv_c * ( + -beta_y*inv_dz*0.5_rt*( phi_arr(i,j+1,k)-phi_arr(i,j-1,k)) ); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + By_arr(i,j,k) += inv_c * ( + -beta_z*inv_dx*0.5_rt*(phi_arr(i+1,j,k)-phi_arr(i-1,j,k)) + +beta_x*inv_dz*0.5_rt*(phi_arr(i,j+1,k)-phi_arr(i,j-1,k)) ); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bz_arr(i,j,k) += inv_c * ( + +beta_y*inv_dx*0.5_rt*( phi_arr(i+1,j,k)-phi_arr(i-1,j,k)) ); + } + ); #else - amrex::ParallelFor( tbx, tby, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - Bx_arr(i,j,k) += inv_c * ( - -beta_y*inv_dz*( phi_arr(i+1,j,k)-phi_arr(i,j,k) )); - }, - [=] AMREX_GPU_DEVICE (int i, int j, int k) { - By_arr(i,j,k) += inv_c * ( - +beta_x*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i,j,k))); - } - ); - ignore_unused(beta_z,tbz,Bz_arr); + amrex::ParallelFor( tbx, tby, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bx_arr(i,j,k) += inv_c * ( + -beta_y*inv_dz*( phi_arr(i+1,j,k)-phi_arr(i,j,k) )); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + By_arr(i,j,k) += inv_c * ( + +beta_x*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i,j,k))); + } + ); + ignore_unused(beta_z,tbz,Bz_arr); #endif + } + // Staggered solver + else{ +#if defined(WARPX_DIM_3D) + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bx_arr(i,j,k) += inv_c * ( + -beta_y*inv_dz*0.5_rt*(phi_arr(i,j ,k+1)-phi_arr(i,j ,k) + + phi_arr(i,j+1,k+1)-phi_arr(i,j+1,k)) + +beta_z*inv_dy*0.5_rt*(phi_arr(i,j+1,k )-phi_arr(i,j,k ) + + phi_arr(i,j+1,k+1)-phi_arr(i,j,k+1))); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + By_arr(i,j,k) += inv_c * ( + -beta_z*inv_dx*0.5_rt*(phi_arr(i+1,j,k )-phi_arr(i,j,k ) + + phi_arr(i+1,j,k+1)-phi_arr(i,j,k+1)) + +beta_x*inv_dz*0.5_rt*(phi_arr(i ,j,k+1)-phi_arr(i ,j,k) + + phi_arr(i+1,j,k+1)-phi_arr(i+1,j,k))); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bz_arr(i,j,k) += inv_c * ( + -beta_x*inv_dy*0.5_rt*(phi_arr(i ,j+1,k)-phi_arr(i ,j,k) + + phi_arr(i+1,j+1,k)-phi_arr(i+1,j,k)) + +beta_y*inv_dx*0.5_rt*(phi_arr(i+1,j ,k)-phi_arr(i,j ,k) + + phi_arr(i+1,j+1,k)-phi_arr(i,j+1,k))); + } + ); +#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) + amrex::ParallelFor( tbx, tby, tbz, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bx_arr(i,j,k) += inv_c * ( + -beta_y*inv_dz*( phi_arr(i,j+1,k)-phi_arr(i,j,k) )); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + By_arr(i,j,k) += inv_c * ( + -beta_z*inv_dx*0.5_rt*(phi_arr(i+1,j ,k)-phi_arr(i,j ,k) + + phi_arr(i+1,j+1,k)-phi_arr(i,j+1,k)) + +beta_x*inv_dz*0.5_rt*(phi_arr(i ,j+1,k)-phi_arr(i ,j,k) + + phi_arr(i+1,j+1,k)-phi_arr(i+1,j,k))); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bz_arr(i,j,k) += inv_c * ( + +beta_y*inv_dx*( phi_arr(i+1,j,k)-phi_arr(i,j,k) )); + } + ); +#else + amrex::ParallelFor( tbx, tby, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + Bx_arr(i,j,k) += inv_c * ( + -beta_y*inv_dz*( phi_arr(i+1,j,k)-phi_arr(i,j,k) )); + }, + [=] AMREX_GPU_DEVICE (int i, int j, int k) { + By_arr(i,j,k) += inv_c * ( + +beta_x*inv_dz*(phi_arr(i+1,j,k)-phi_arr(i,j,k))); + } + ); + ignore_unused(beta_z,tbz,Bz_arr); +#endif + } } } } From 82c9e0ce71556285622433fde089771de37d2ea0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Jun 2023 23:32:38 +0000 Subject: [PATCH 18/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/FieldSolver/ElectrostaticSolver.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/FieldSolver/ElectrostaticSolver.cpp b/Source/FieldSolver/ElectrostaticSolver.cpp index 3e9bdfde371..0e673ade573 100644 --- a/Source/FieldSolver/ElectrostaticSolver.cpp +++ b/Source/FieldSolver/ElectrostaticSolver.cpp @@ -547,12 +547,12 @@ WarpX::computeE (amrex::Vector, 3> > [=] AMREX_GPU_DEVICE (int i, int j, int k) { Ez_arr(i,j,k) += +(beta_z*beta_z-1)*0.5_rt*inv_dz*( phi_arr(i+1,j,k)-phi_arr(i-1,j,k) ); - } + } ); #endif } else{ - // Staggered solver + // Staggered solver #if defined(WARPX_DIM_3D) amrex::ParallelFor( tbx, tby, tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k) { @@ -674,7 +674,7 @@ WarpX::computeB (amrex::Vector, 3> > // Calculate the magnetic field // Use discretized derivative that matches the staggering of the grid. - // Nodal solver + // Nodal solver if ((bx_type == IntVect::TheNodeVector()) && (by_type == IntVect::TheNodeVector()) && (bz_type == IntVect::TheNodeVector())){ #if defined(WARPX_DIM_3D) amrex::ParallelFor( tbx, tby, tbz, @@ -686,7 +686,7 @@ WarpX::computeB (amrex::Vector, 3> > [=] AMREX_GPU_DEVICE (int i, int j, int k) { By_arr(i,j,k) += inv_c * ( -beta_z*inv_dx*0.5_rt*(phi_arr(i+1,j,k)-phi_arr(i-1,j,k)) - +beta_x*inv_dz*0.5_rt*(phi_arr(i,j,k+1)-phi_arr(i,j,k-1)) ); + +beta_x*inv_dz*0.5_rt*(phi_arr(i,j,k+1)-phi_arr(i,j,k-1)) ); }, [=] AMREX_GPU_DEVICE (int i, int j, int k) { Bz_arr(i,j,k) += inv_c * ( @@ -724,7 +724,7 @@ WarpX::computeB (amrex::Vector, 3> > ignore_unused(beta_z,tbz,Bz_arr); #endif } - // Staggered solver + // Staggered solver else{ #if defined(WARPX_DIM_3D) amrex::ParallelFor( tbx, tby, tbz,