diff --git a/Source/BoundaryConditions/PML_RZ.cpp b/Source/BoundaryConditions/PML_RZ.cpp index cc05c126a55..0fc24bf8817 100644 --- a/Source/BoundaryConditions/PML_RZ.cpp +++ b/Source/BoundaryConditions/PML_RZ.cpp @@ -138,7 +138,7 @@ PML_RZ::FillBoundaryE (ablastr::fields::MultiFabRegister& fields, PatchType patc if (patch_type == PatchType::fine && pml_Er->nGrowVect().max() > 0) { amrex::Periodicity const& period = m_geom->periodicity(); - amrex::Vector mf = {pml_Er, pml_Et}; + const amrex::Vector mf = {pml_Er, pml_Et}; ablastr::utils::communication::FillBoundary(mf, WarpX::do_single_precision_comms, period, nodal_sync); } } @@ -152,7 +152,7 @@ PML_RZ::FillBoundaryB (ablastr::fields::MultiFabRegister& fields, PatchType patc amrex::MultiFab * pml_Bt = fields.get("pml_B_fp", Direction{1}, 0); amrex::Periodicity const& period = m_geom->periodicity(); - amrex::Vector mf = {pml_Br, pml_Bt}; + const amrex::Vector mf = {pml_Br, pml_Bt}; ablastr::utils::communication::FillBoundary(mf, WarpX::do_single_precision_comms, period, nodal_sync); } } diff --git a/Source/Evolve/WarpXEvolve.cpp b/Source/Evolve/WarpXEvolve.cpp index a4df5ea73bd..bd01aeaf359 100644 --- a/Source/Evolve/WarpXEvolve.cpp +++ b/Source/Evolve/WarpXEvolve.cpp @@ -663,8 +663,8 @@ WarpX::OneStep_multiJ (const amrex::Real cur_time) // (after checking that pointer to rho_fp on MR level 0 is not null) if (m_fields.has("rho_fp", 0) && rho_in_time == RhoInTime::Linear) { - ablastr::fields::MultiLevelScalarField rho_fp = m_fields.get_mr_levels("rho_fp", finest_level); - ablastr::fields::MultiLevelScalarField rho_cp = m_fields.get_mr_levels("rho_fp", finest_level); + const ablastr::fields::MultiLevelScalarField rho_fp = m_fields.get_mr_levels("rho_fp", finest_level); + const ablastr::fields::MultiLevelScalarField rho_cp = m_fields.get_mr_levels("rho_fp", finest_level); // Deposit rho at relative time -dt // (dt[0] denotes the time step on mesh refinement level 0) @@ -732,8 +732,8 @@ WarpX::OneStep_multiJ (const amrex::Real cur_time) // (after checking that pointer to rho_fp on MR level 0 is not null) if (m_fields.has("rho_fp", 0)) { - ablastr::fields::MultiLevelScalarField rho_fp = m_fields.get_mr_levels("rho_fp", finest_level); - ablastr::fields::MultiLevelScalarField rho_cp = m_fields.get_mr_levels("rho_cp", finest_level); + const ablastr::fields::MultiLevelScalarField rho_fp = m_fields.get_mr_levels("rho_fp", finest_level); + const ablastr::fields::MultiLevelScalarField rho_cp = m_fields.get_mr_levels("rho_cp", finest_level); // Move rho from new to old if rho is linear in time if (rho_in_time == RhoInTime::Linear) { PSATDMoveRhoNewToRhoOld(); } diff --git a/Source/FieldSolver/ElectrostaticSolvers/LabFrameExplicitES.cpp b/Source/FieldSolver/ElectrostaticSolvers/LabFrameExplicitES.cpp index de9f20a54aa..a2d45bcdb8d 100644 --- a/Source/FieldSolver/ElectrostaticSolvers/LabFrameExplicitES.cpp +++ b/Source/FieldSolver/ElectrostaticSolvers/LabFrameExplicitES.cpp @@ -29,10 +29,10 @@ void LabFrameExplicitES::ComputeSpaceChargeField ( using ablastr::fields::MultiLevelScalarField; using ablastr::fields::MultiLevelVectorField; - MultiLevelScalarField rho_fp = fields.get_mr_levels("rho_fp", max_level); - MultiLevelScalarField rho_cp = fields.get_mr_levels("rho_cp", max_level); + const MultiLevelScalarField rho_fp = fields.get_mr_levels("rho_fp", max_level); + const MultiLevelScalarField rho_cp = fields.get_mr_levels("rho_cp", max_level); MultiLevelScalarField phi_fp = fields.get_mr_levels("phi_fp", max_level); - MultiLevelVectorField Efield_fp = fields.get_mr_levels_alldirs("Efield_fp", max_level); + const MultiLevelVectorField Efield_fp = fields.get_mr_levels_alldirs("Efield_fp", max_level); mpc.DepositCharge(rho_fp, 0.0_rt); if (mfl) { @@ -41,7 +41,7 @@ void LabFrameExplicitES::ComputeSpaceChargeField ( } // Apply filter, perform MPI exchange, interpolate across levels - Vector > rho_buf(num_levels); + const Vector > rho_buf(num_levels); auto & warpx = WarpX::GetInstance(); warpx.SyncRho( rho_fp, rho_cp, amrex::GetVecOfPtrs(rho_buf) ); diff --git a/Source/FieldSolver/FiniteDifferenceSolver/EvolveB.cpp b/Source/FieldSolver/FiniteDifferenceSolver/EvolveB.cpp index 2fcc18a33d0..a5b85f7fbd7 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/EvolveB.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/EvolveB.cpp @@ -56,9 +56,9 @@ void FiniteDifferenceSolver::EvolveB ( [[maybe_unused]] amrex::Real const dt ) { using ablastr::fields::Direction; - ablastr::fields::VectorField Bfield = patch_type == PatchType::fine ? + const ablastr::fields::VectorField Bfield = patch_type == PatchType::fine ? fields.get_alldirs("Bfield_fp", lev) : fields.get_alldirs("Bfield_cp", lev); - ablastr::fields::VectorField Efield = patch_type == PatchType::fine ? + const ablastr::fields::VectorField Efield = patch_type == PatchType::fine ? fields.get_alldirs("Efield_fp", lev) : fields.get_alldirs("Efield_cp", lev); // Select algorithm (The choice of algorithm is a runtime option, diff --git a/Source/FieldSolver/FiniteDifferenceSolver/EvolveBPML.cpp b/Source/FieldSolver/FiniteDifferenceSolver/EvolveBPML.cpp index 9a83b4bc072..5d46d18ff4e 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/EvolveBPML.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/EvolveBPML.cpp @@ -56,9 +56,9 @@ void FiniteDifferenceSolver::EvolveBPML ( WARPX_ABORT_WITH_MESSAGE( "PML are not implemented in cylindrical geometry."); #else - ablastr::fields::VectorField Bfield = (patch_type == PatchType::fine) ? + const ablastr::fields::VectorField Bfield = (patch_type == PatchType::fine) ? fields.get_alldirs("pml_B_fp", level) : fields.get_alldirs("pml_B_cp", level); - ablastr::fields::VectorField Efield = (patch_type == PatchType::fine) ? + const ablastr::fields::VectorField Efield = (patch_type == PatchType::fine) ? fields.get_alldirs("pml_E_fp", level) : fields.get_alldirs("pml_E_cp", level); if (m_grid_type == ablastr::utils::enums::GridType::Collocated) { diff --git a/Source/FieldSolver/FiniteDifferenceSolver/EvolveE.cpp b/Source/FieldSolver/FiniteDifferenceSolver/EvolveE.cpp index ac18b2f7fae..7e9f62c589b 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/EvolveE.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/EvolveE.cpp @@ -58,9 +58,9 @@ void FiniteDifferenceSolver::EvolveE ( ) { using ablastr::fields::Direction; - ablastr::fields::VectorField Bfield = patch_type == PatchType::fine ? + const ablastr::fields::VectorField Bfield = patch_type == PatchType::fine ? fields.get_alldirs("Bfield_fp", lev) : fields.get_alldirs("Bfield_cp", lev); - ablastr::fields::VectorField Jfield = patch_type == PatchType::fine ? + const ablastr::fields::VectorField Jfield = patch_type == PatchType::fine ? fields.get_alldirs("current_fp", lev) : fields.get_alldirs("current_cp", lev); amrex::MultiFab* Ffield = nullptr; @@ -71,23 +71,19 @@ void FiniteDifferenceSolver::EvolveE ( ablastr::fields::VectorField edge_lengths; if (fields.has("edge_lengths", Direction{0}, lev)) { - edge_lengths = patch_type == PatchType::fine ? - fields.get_alldirs("edge_lengths", lev) : fields.get_alldirs("edge_lengths", lev); + edge_lengths = fields.get_alldirs("edge_lengths", lev); } ablastr::fields::VectorField face_areas; if (fields.has("face_areas", Direction{0}, lev)) { - face_areas = patch_type == PatchType::fine ? - fields.get_alldirs("face_areas", lev) : fields.get_alldirs("face_areas", lev); + face_areas = fields.get_alldirs("face_areas", lev); } ablastr::fields::VectorField area_mod; - if (fields.has("face_areas", Direction{0}, lev)) { - area_mod = patch_type == PatchType::fine ? - fields.get_alldirs("area_mod", lev) : fields.get_alldirs("area_mod", lev); + if (fields.has("area_mod", Direction{0}, lev)) { + area_mod = fields.get_alldirs("area_mod", lev); } ablastr::fields::VectorField ECTRhofield; if (fields.has("ECTRhofield", Direction{0}, lev)) { - ECTRhofield = patch_type == PatchType::fine ? - fields.get_alldirs("ECTRhofield", lev) : fields.get_alldirs("ECTRhofield", lev); + ECTRhofield = fields.get_alldirs("ECTRhofield", lev); } // Select algorithm (The choice of algorithm is a runtime option, @@ -221,7 +217,7 @@ void FiniteDifferenceSolver::EvolveECartesian ( if (Ffield) { // Extract field data for this grid/tile - Array4 F = Ffield->array(mfi); + const Array4 F = Ffield->array(mfi); // Loop over the cells and update the fields amrex::ParallelFor(tex, tey, tez, diff --git a/Source/FieldSolver/FiniteDifferenceSolver/EvolveEPML.cpp b/Source/FieldSolver/FiniteDifferenceSolver/EvolveEPML.cpp index 4da403156b0..d678bed3b01 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/EvolveEPML.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/EvolveEPML.cpp @@ -59,11 +59,11 @@ void FiniteDifferenceSolver::EvolveEPML ( "PML are not implemented in cylindrical geometry."); #else using ablastr::fields::Direction; - ablastr::fields::VectorField Efield = (patch_type == PatchType::fine) ? + const ablastr::fields::VectorField Efield = (patch_type == PatchType::fine) ? fields.get_alldirs("pml_E_fp", level) : fields.get_alldirs("pml_E_cp", level); - ablastr::fields::VectorField Bfield = (patch_type == PatchType::fine) ? + const ablastr::fields::VectorField Bfield = (patch_type == PatchType::fine) ? fields.get_alldirs("pml_B_fp", level) : fields.get_alldirs("pml_B_cp", level); - ablastr::fields::VectorField Jfield = (patch_type == PatchType::fine) ? + const ablastr::fields::VectorField Jfield = (patch_type == PatchType::fine) ? fields.get_alldirs("pml_j_fp", level) : fields.get_alldirs("pml_j_cp", level); ablastr::fields::VectorField edge_lengths; if (fields.has("pml_edge_lengths", Direction{0}, level)) { diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.H b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.H index 49d187431ce..03f51f7ba62 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.H @@ -226,7 +226,7 @@ class FiniteDifferenceSolver void EvolveFCylindrical ( amrex::MultiFab* Ffield, ablastr::fields::VectorField const & Efield, - amrex::MultiFab* const rhofield, + amrex::MultiFab* rhofield, int rhocomp, amrex::Real dt ); @@ -322,7 +322,7 @@ class FiniteDifferenceSolver template< typename T_Algo > void EvolveBPMLCartesian ( std::array< amrex::MultiFab*, 3 > Bfield, - ablastr::fields::VectorField const Efield, + ablastr::fields::VectorField Efield, amrex::Real dt, bool dive_cleaning); diff --git a/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.cpp b/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.cpp index b05b9ae1562..ac5bf34a1ff 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.cpp @@ -468,8 +468,8 @@ void HybridPICModel::HybridPICSolveE ( auto& warpx = WarpX::GetInstance(); ablastr::fields::VectorField current_fp_ampere = warpx.m_fields.get_alldirs("hybrid_current_fp_ampere", lev); - ablastr::fields::VectorField current_fp_external = warpx.m_fields.get_alldirs("hybrid_current_fp_external", lev); - ablastr::fields::ScalarField electron_pressure_fp = warpx.m_fields.get("hybrid_electron_pressure_fp", lev); + const ablastr::fields::VectorField current_fp_external = warpx.m_fields.get_alldirs("hybrid_current_fp_external", lev); + const ablastr::fields::ScalarField electron_pressure_fp = warpx.m_fields.get("hybrid_electron_pressure_fp", lev); // Solve E field in regular cells warpx.get_pointer_fdtd_solver_fp(lev)->HybridPICSolveE( diff --git a/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.H b/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.H index 74e45ba631c..b109229328e 100644 --- a/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.H +++ b/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.H @@ -68,8 +68,8 @@ public: [[nodiscard]] inline bool IsDefined () const { return m_is_defined; } void Define ( WarpX* a_WarpX, - std::string a_vector_type_name, - std::string a_scalar_type_name = "none" ); + const std::string& a_vector_type_name, + const std::string& a_scalar_type_name = "none" ); inline void Define ( const WarpXSolverVec& a_solver_vec ) diff --git a/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.cpp b/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.cpp index da359f35248..10673704759 100644 --- a/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.cpp +++ b/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.cpp @@ -21,8 +21,8 @@ WarpXSolverVec::~WarpXSolverVec () } void WarpXSolverVec::Define ( WarpX* a_WarpX, - std::string a_vector_type_name, - std::string a_scalar_type_name ) + const std::string& a_vector_type_name, + const std::string& a_scalar_type_name ) { WARPX_ALWAYS_ASSERT_WITH_MESSAGE( !IsDefined(), @@ -41,7 +41,7 @@ void WarpXSolverVec::Define ( WarpX* a_WarpX, m_array_type = FieldType::Efield_fp; } else if (m_vector_type_name=="Bfield_fp") { - m_array_type = FieldType::Efield_fp; + m_array_type = FieldType::Bfield_fp; } else if (m_vector_type_name=="vector_potential_fp_nodal") { m_array_type = FieldType::vector_potential_fp; diff --git a/Source/FieldSolver/WarpXPushFieldsEM.cpp b/Source/FieldSolver/WarpXPushFieldsEM.cpp index ede04b39632..43a964c1806 100644 --- a/Source/FieldSolver/WarpXPushFieldsEM.cpp +++ b/Source/FieldSolver/WarpXPushFieldsEM.cpp @@ -669,11 +669,11 @@ WarpX::PushPSATD () const int rho_old = spectral_solver_fp[0]->m_spectral_index.rho_old; const int rho_new = spectral_solver_fp[0]->m_spectral_index.rho_new; - ablastr::fields::MultiLevelScalarField rho_fp = m_fields.get_mr_levels("rho_fp", finest_level); - ablastr::fields::MultiLevelScalarField rho_cp = m_fields.get_mr_levels("rho_fp", finest_level); - ablastr::fields::MultiLevelVectorField current_fp = m_fields.get_mr_levels_alldirs("current_fp", finest_level); - ablastr::fields::MultiLevelVectorField current_cp = m_fields.get_mr_levels_alldirs("current_cp", finest_level); - ablastr::fields::MultiLevelVectorField current_buf = m_fields.get_mr_levels_alldirs("current_buf", finest_level); + const ablastr::fields::MultiLevelScalarField rho_fp = m_fields.get_mr_levels("rho_fp", finest_level); + const ablastr::fields::MultiLevelScalarField rho_cp = m_fields.get_mr_levels("rho_fp", finest_level); + const ablastr::fields::MultiLevelVectorField current_fp = m_fields.get_mr_levels_alldirs("current_fp", finest_level); + const ablastr::fields::MultiLevelVectorField current_cp = m_fields.get_mr_levels_alldirs("current_cp", finest_level); + const ablastr::fields::MultiLevelVectorField current_buf = m_fields.get_mr_levels_alldirs("current_buf", finest_level); if (fft_periodic_single_box) { diff --git a/Source/WarpX.H b/Source/WarpX.H index 40ad6f031c3..338a88b28b1 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -485,7 +485,7 @@ public: * Set the dotMask container */ void SetDotMask( std::unique_ptr& field_dotMask, - std::string field_name, int lev, int dir ) const; + const std::string& field_name, int lev, int dir ) const; [[nodiscard]] bool DoPML () const {return do_pml;} [[nodiscard]] bool DoFluidSpecies () const {return do_fluid_species;} diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 4efa58b8fee..d89404f17bf 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -2530,9 +2530,9 @@ WarpX::AllocLevelMFs (int lev, const BoxArray& ba, const DistributionMapping& dm } if (mypc->m_B_ext_particle_s == "read_from_file") { // These fields will be added to the fields that the particles see, and need to match the index type - auto Bfield_aux_levl_0 = m_fields.get("Bfield_aux", Direction{0}, lev); - auto Bfield_aux_levl_1 = m_fields.get("Bfield_aux", Direction{1}, lev); - auto Bfield_aux_levl_2 = m_fields.get("Bfield_aux", Direction{2}, lev); + auto* Bfield_aux_levl_0 = m_fields.get("Bfield_aux", Direction{0}, lev); + auto* Bfield_aux_levl_1 = m_fields.get("Bfield_aux", Direction{1}, lev); + auto* Bfield_aux_levl_2 = m_fields.get("Bfield_aux", Direction{2}, lev); // Same as Bfield_fp for reading external field data m_fields.alloc_init( "B_external_particle_field", Direction{0}, lev, amrex::convert(ba, Bfield_aux_levl_0->ixType()), @@ -2553,9 +2553,9 @@ WarpX::AllocLevelMFs (int lev, const BoxArray& ba, const DistributionMapping& dm } if (mypc->m_E_ext_particle_s == "read_from_file") { // These fields will be added to the fields that the particles see, and need to match the index type - auto Efield_aux_levl_0 = m_fields.get("Efield_aux", Direction{0}, lev); - auto Efield_aux_levl_1 = m_fields.get("Efield_aux", Direction{1}, lev); - auto Efield_aux_levl_2 = m_fields.get("Efield_aux", Direction{2}, lev); + auto* Efield_aux_levl_0 = m_fields.get("Efield_aux", Direction{0}, lev); + auto* Efield_aux_levl_1 = m_fields.get("Efield_aux", Direction{1}, lev); + auto* Efield_aux_levl_2 = m_fields.get("Efield_aux", Direction{2}, lev); // Same as Efield_fp for reading external field data m_fields.alloc_init( "E_external_particle_field", Direction{0}, lev, amrex::convert(ba, Efield_aux_levl_0->ixType()), @@ -2966,14 +2966,14 @@ WarpX::ComputeDivE(amrex::MultiFab& divE, const int lev) { if ( WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD ) { #ifdef WARPX_USE_FFT - ablastr::fields::VectorField Efield_aux_lev = m_fields.get_alldirs("Efield_aux", lev); + const ablastr::fields::VectorField Efield_aux_lev = m_fields.get_alldirs("Efield_aux", lev); spectral_solver_fp[lev]->ComputeSpectralDivE(lev, Efield_aux_lev, divE); #else WARPX_ABORT_WITH_MESSAGE( "ComputeDivE: PSATD requested but not compiled"); #endif } else { - ablastr::fields::VectorField Efield_aux_lev = m_fields.get_alldirs("Efield_aux", lev); + const ablastr::fields::VectorField Efield_aux_lev = m_fields.get_alldirs("Efield_aux", lev); m_fdtd_solver_fp[lev]->ComputeDivE(Efield_aux_lev, divE); } } @@ -3410,7 +3410,7 @@ WarpX::getFieldDotMaskPointer ( FieldType field_type, int lev, int dir ) const } void WarpX::SetDotMask( std::unique_ptr& field_dotMask, - std::string field_name, int lev, int dir ) const + const std::string& field_name, int lev, int dir ) const { // Define the dot mask for this field_type needed to properly compute dotProduct() // for field values that have shared locations on different MPI ranks diff --git a/Source/ablastr/fields/MultiFabRegister.cpp b/Source/ablastr/fields/MultiFabRegister.cpp index 25b0505e197..4e91180c7eb 100644 --- a/Source/ablastr/fields/MultiFabRegister.cpp +++ b/Source/ablastr/fields/MultiFabRegister.cpp @@ -569,10 +569,12 @@ namespace ablastr::fields // C++20: Replace with std::erase_if for (auto first = m_mf_register.begin(), last = m_mf_register.end(); first != last;) { - if (first->second.m_level == level) + if (first->second.m_level == level){ first = m_mf_register.erase(first); - else + } + else{ ++first; + } } } @@ -627,7 +629,7 @@ namespace ablastr::fields const amrex::Vector, 3 > >& old_vector_on_levels ) { - int const finest_level = old_vector_on_levels.size() - 1u; + auto const finest_level = static_cast(old_vector_on_levels.size() - 1u); MultiLevelVectorField field_on_level; field_on_level.reserve(finest_level+1); @@ -653,7 +655,7 @@ namespace ablastr::fields const amrex::Vector >& old_scalar_on_levels ) { - int const finest_level = old_scalar_on_levels.size() - 1u; + auto const finest_level = static_cast(old_scalar_on_levels.size() - 1u); MultiLevelScalarField field_on_level; field_on_level.reserve(finest_level+1);