diff --git a/.clang-tidy b/.clang-tidy index f988f5d9449..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, @@ -12,16 +14,48 @@ Checks: '-*, -cppcoreguidelines-no-malloc, -cppcoreguidelines-owning-memory, misc-const-correctness, + 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, + mpi-*, performance-faster-string-find, performance-for-range-copy, performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-inefficient-string-concatenation, 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 ' +CheckOptions: +- key: modernize-pass-by-value.ValuesOnly + value: 'true' + HeaderFilterRegex: 'Source[a-z_A-Z0-9\/]+\.H$' 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/.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) 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. 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/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/BTD_Plotfile_Header_Impl.cpp b/Source/Diagnostics/BTD_Plotfile_Header_Impl.cpp index 9a19e671e46..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 @@ -21,7 +22,7 @@ using namespace amrex::literals; BTDPlotfileHeaderImpl::BTDPlotfileHeaderImpl (std::string const & Headerfile_path) - : m_Header_path(Headerfile_path) + : m_Header_path{Headerfile_path} { } @@ -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; @@ -177,7 +178,7 @@ BTDPlotfileHeaderImpl::WriteHeader () BTDMultiFabHeaderImpl::BTDMultiFabHeaderImpl (std::string const & Headerfile_path) - : m_Header_path(Headerfile_path) + : m_Header_path{Headerfile_path} { } @@ -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) { @@ -353,7 +354,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/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..be168f3ca2e 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]; @@ -1169,11 +1159,15 @@ 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 == 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(); @@ -1194,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, @@ -1210,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) { @@ -1244,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. diff --git a/Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp b/Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp index 9e33a1fc230..4d551a271dc 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(); } @@ -50,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; @@ -161,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 15fa5f9afe7..2275ee83fec 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(); } @@ -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 b557a9b09e0..3192ba815c3 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 de7a5a5cba7..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; @@ -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 34562b9835d..13b4faecad1 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) { @@ -390,7 +390,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(), rtmap); + pc->getMass(), time, rtmap); parser_filter.m_units = InputUnits::SI; GeometryFilter const geometry_filter(part_diag.m_do_geom_filter, part_diag.m_diag_domain); @@ -579,8 +579,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) { @@ -588,7 +588,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/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/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 abc4b1a9908..5a3bb5a9e4b 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; // figure out which particle attribute is upstream 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/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/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 714e475918c..519093a678c 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()"); @@ -577,7 +578,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(), rtmap); + pc->getMass(), time, rtmap); parser_filter.m_units = InputUnits::SI; GeometryFilter const geometry_filter(particle_diags[i].m_do_geom_filter, particle_diags[i].m_diag_domain); @@ -1206,9 +1207,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 @@ -1250,8 +1250,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 8cfbaaa5bb6..f3d249c92e0 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/ElectrostaticSolver.H b/Source/FieldSolver/ElectrostaticSolver.H index 31601ca4212..2503156174f 100644 --- a/Source/FieldSolver/ElectrostaticSolver.H +++ b/Source/FieldSolver/ElectrostaticSolver.H @@ -8,11 +8,14 @@ #define ELECTROSTATICSOLVER_H_ #include +#include #include #include #include #include +#include + namespace ElectrostaticSolver { struct PhiCalculatorEB { @@ -41,7 +44,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 (); @@ -101,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/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= 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/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.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 1ed86864710..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 ce8b1b10885..603049a79cf 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -86,6 +86,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 { @@ -310,7 +334,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"; } @@ -391,6 +415,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 @@ -1210,30 +1240,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 @@ -1241,52 +1271,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/Parallelization/WarpXRegrid.cpp b/Source/Parallelization/WarpXRegrid.cpp index d60ebfbb05a..b09f4ad8344 100644 --- a/Source/Parallelization/WarpXRegrid.cpp +++ b/Source/Parallelization/WarpXRegrid.cpp @@ -235,7 +235,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, @@ -244,7 +244,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/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/Filter/FilterFunctors.H b/Source/Particles/Filter/FilterFunctors.H index 075a2d420d4..cd30c5d57ab 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 @@ -92,16 +91,19 @@ struct ParserFilter * \param a_is_active whether the test is active * \param a_filter_parser parser taking t, x, y, z, ux, uy, uz, upstream, track 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<9> const& a_filter_parser, - amrex::Real a_mass, std::map& a_rt_param_map) - : m_is_active(a_is_active), m_function_partparser(a_filter_parser), m_mass(a_mass) - { - m_ius = a_rt_param_map["upstream"] - PIdx::nattribs; - m_itr = a_rt_param_map["track"] - PIdx::nattribs; - m_t = WarpX::GetInstance().gett_new(0); - m_units = InputUnits::WarpX; - } + const amrex::Real a_mass, const amrex::Real time, + std::map& a_rt_param_map): + m_is_active{a_is_active}, + m_function_partparser{a_filter_parser}, + m_mass{a_mass}, + m_t{time}, + m_units{InputUnits::WarpX}{ + m_ius = a_rt_param_map["upstream"] - PIdx::nattribs; + m_itr = a_rt_param_map["track"] - PIdx::nattribs; + } /** * \brief return 1 if the particle is selected by the parser @@ -170,12 +172,12 @@ private: int m_ius; int m_itr; public: - /** Parser function with 9 input variables, t,x,y,z,ux,uy,uz,upstream,track */ + /** Parser function with 7 input variables, t,x,y,z,ux,uy,uz */ amrex::ParserExecutor<9> 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; }; 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/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 f3c93269cae..99dbe776829 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(); @@ -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) { const int* const AMREX_RESTRICT ion_lev = (do_field_ionization)? pti.GetiAttribs(particle_icomps["ionizationLevel"]).dataPtr():nullptr; @@ -2899,13 +2901,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/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.H b/Source/Particles/WarpXParticleContainer.H index 6e0d3f4f927..6169ae540b5 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -207,6 +207,10 @@ public: const bool apply_boundary_and_scale_volume = false, const bool interpolate_across_levels = true, const int icomp = 0); + void DepositCharge (std::unique_ptr& rho, const int lev, + const bool local = false, const bool reset = false, + const bool apply_boundary_and_scale_volume = false, + const int icomp = 0); std::unique_ptr GetChargeDensity(int lev, bool local = false); diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index f0f745f76fc..7c98e286f0b 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -976,58 +976,9 @@ WarpXParticleContainer::DepositCharge (amrex::VectorsetVal(0., icomp*nc, nc, rho[lev]->nGrowVect()); - - // Loop over particle tiles and deposit charge on each level -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) - { - const int thread_num = omp_get_thread_num(); -#else - const int thread_num = 0; -#endif - for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti) - { - const long np = pti.numParticles(); - auto const & wp = pti.GetAttribs(PIdx::w); - - int* AMREX_RESTRICT ion_lev = nullptr; - if (do_field_ionization) - { - ion_lev = pti.GetiAttribs(particle_icomps["ionizationLevel"]).dataPtr(); - } - - DepositCharge(pti, wp, ion_lev, rho[lev].get(), icomp, 0, np, thread_num, lev, lev); - } -#ifdef AMREX_USE_OMP - } -#endif - -#ifdef WARPX_DIM_RZ - if (apply_boundary_and_scale_volume) - { - WarpX::GetInstance().ApplyInverseVolumeScalingToChargeDensity(rho[lev].get(), lev); - } -#endif - - // Exchange guard cells - if (local == false) { - // Possible performance optimization: - // pass less than `rho[lev]->nGrowVect()` in the fifth input variable `dst_ng` - ablastr::utils::communication::SumBoundary( - *rho[lev], 0, rho[lev]->nComp(), rho[lev]->nGrowVect(), rho[lev]->nGrowVect(), - WarpX::do_single_precision_comms, m_gdb->Geom(lev).periodicity()); - } - -#ifndef WARPX_DIM_RZ - if (apply_boundary_and_scale_volume) - { - // Reflect density over PEC boundaries, if needed. - WarpX::GetInstance().ApplyRhofieldBoundary(lev, rho[lev].get(), PatchType::fine); - } -#endif + DepositCharge ( + rho[lev], lev, local, reset, apply_boundary_and_scale_volume, icomp + ); } // Now that the charge has been deposited at each level, @@ -1053,72 +1004,90 @@ WarpXParticleContainer::DepositCharge (amrex::Vector -WarpXParticleContainer::GetChargeDensity (int lev, bool local) +void +WarpXParticleContainer::DepositCharge (std::unique_ptr& rho, + const int lev, const bool local, const bool reset, + const bool apply_boundary_and_scale_volume, + const int icomp) { - const auto& gm = m_gdb->Geom(lev); - const auto& ba = m_gdb->ParticleBoxArray(lev); - const auto& dm = m_gdb->DistributionMap(lev); - BoxArray nba = ba; - -#ifdef WARPX_DIM_RZ - const bool is_PSATD_RZ = - (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD); -#else - const bool is_PSATD_RZ = false; -#endif - if( !is_PSATD_RZ ) - nba.surroundingNodes(); - - // Number of guard cells for local deposition of rho - const WarpX& warpx = WarpX::GetInstance(); - const int ng_rho = warpx.get_ng_depos_rho().max(); - - auto rho = std::make_unique(nba,dm,WarpX::ncomps,ng_rho); - rho->setVal(0.0); + // Reset the rho array if reset is True + int const nc = WarpX::ncomps; + if (reset) rho->setVal(0., icomp*nc, nc, rho->nGrowVect()); + // Loop over particle tiles and deposit charge on each level #ifdef AMREX_USE_OMP #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) { -#endif -#ifdef AMREX_USE_OMP - const int thread_num = omp_get_thread_num(); + const int thread_num = omp_get_thread_num(); #else - const int thread_num = 0; + const int thread_num = 0; #endif + for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti) + { + const long np = pti.numParticles(); + auto const & wp = pti.GetAttribs(PIdx::w); - for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti) + int* AMREX_RESTRICT ion_lev = nullptr; + if (do_field_ionization) { - const long np = pti.numParticles(); - auto& wp = pti.GetAttribs(PIdx::w); - - const int* const AMREX_RESTRICT ion_lev = (do_field_ionization)? - pti.GetiAttribs(particle_icomps["ionizationLevel"]).dataPtr():nullptr; - - DepositCharge(pti, wp, ion_lev, rho.get(), 0, 0, np, - thread_num, lev, lev); + ion_lev = pti.GetiAttribs(particle_icomps["ionizationLevel"]).dataPtr(); } + + DepositCharge(pti, wp, ion_lev, rho.get(), icomp, 0, np, thread_num, lev, lev); + } #ifdef AMREX_USE_OMP } #endif #ifdef WARPX_DIM_RZ - WarpX::GetInstance().ApplyInverseVolumeScalingToChargeDensity(rho.get(), lev); + if (apply_boundary_and_scale_volume) + { + WarpX::GetInstance().ApplyInverseVolumeScalingToChargeDensity(rho.get(), lev); + } #endif - if (local == false) { + // Exchange guard cells + if ( !local ) { // Possible performance optimization: // pass less than `rho->nGrowVect()` in the fifth input variable `dst_ng` ablastr::utils::communication::SumBoundary( *rho, 0, rho->nComp(), rho->nGrowVect(), rho->nGrowVect(), - WarpX::do_single_precision_comms, gm.periodicity()); + WarpX::do_single_precision_comms, + m_gdb->Geom(lev).periodicity() + ); } #ifndef WARPX_DIM_RZ - // Reflect density over PEC boundaries, if needed. - WarpX::GetInstance().ApplyRhofieldBoundary(lev, rho.get(), PatchType::fine); + if (apply_boundary_and_scale_volume) + { + // Reflect density over PEC boundaries, if needed. + WarpX::GetInstance().ApplyRhofieldBoundary(lev, rho.get(), PatchType::fine); + } #endif +} + +std::unique_ptr +WarpXParticleContainer::GetChargeDensity (int lev, bool local) +{ + const auto& ba = m_gdb->ParticleBoxArray(lev); + const auto& dm = m_gdb->DistributionMap(lev); + BoxArray nba = ba; + +#ifdef WARPX_DIM_RZ + const bool is_PSATD_RZ = + (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD); +#else + const bool is_PSATD_RZ = false; +#endif + if( !is_PSATD_RZ ) + nba.surroundingNodes(); + + // Number of guard cells for local deposition of rho + const WarpX& warpx = WarpX::GetInstance(); + const int ng_rho = warpx.get_ng_depos_rho().max(); + auto rho = std::make_unique(nba, dm, WarpX::ncomps,ng_rho); + DepositCharge(rho, lev, local, true, true, 0); return rho; } @@ -1146,7 +1115,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 +1191,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 +1228,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/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/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/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/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/WarpX.H b/Source/WarpX.H index 2e19029da09..3cc04db6b0d 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 @@ -109,8 +115,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; @@ -1127,6 +1131,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; @@ -1249,12 +1267,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 */ diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index e863c80350c..a5ec2e73b81 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -234,11 +234,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; } @@ -246,14 +260,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(); @@ -306,12 +326,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); @@ -1132,7 +1146,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 +1385,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 +1410,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 +1429,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 +1450,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 +1469,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 +1523,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 +1597,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 +2360,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 +2374,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; 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]; } } } 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'); +} 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(); diff --git a/Tools/ReconnectionInputAndTools/inputs_reconnection_s30_attr.2d b/Tools/ReconnectionInputAndTools/inputs_reconnection_s30_attr.2d index ac5cc622824..e408f150363 100644 --- a/Tools/ReconnectionInputAndTools/inputs_reconnection_s30_attr.2d +++ b/Tools/ReconnectionInputAndTools/inputs_reconnection_s30_attr.2d @@ -155,7 +155,7 @@ EnergyHI.bin_min = 1 EnergyHI.bin_max = 2 Bsq.type = FieldReduction -Bsq.reduced_function(x,y,z,Ex,Ey,Ez,Bx,By,Bz) = Bx*Bx + By*By + Bz*Bz +Bsq.reduced_function(x,y,z,Ex,Ey,Ez,Bx,By,Bz,jx,jy,jz) = Bx*Bx + By*By + Bz*Bz Bsq.reduction_type = Integral Bsq.intervals = 20 diff --git a/Tools/ReconnectionInputAndTools/inputs_reconnection_s30_test.2d b/Tools/ReconnectionInputAndTools/inputs_reconnection_s30_test.2d index d7f3f196185..1d0c9ca723f 100644 --- a/Tools/ReconnectionInputAndTools/inputs_reconnection_s30_test.2d +++ b/Tools/ReconnectionInputAndTools/inputs_reconnection_s30_test.2d @@ -169,7 +169,7 @@ EnergyHI.bin_min = 1 EnergyHI.bin_max = 2 Bsq.type = FieldReduction -Bsq.reduced_function(x,y,z,Ex,Ey,Ez,Bx,By,Bz) = Bx*Bx + By*By + Bz*Bz +Bsq.reduced_function(x,y,z,Ex,Ey,Ez,Bx,By,Bz,jx,jy,jz) = Bx*Bx + By*By + Bz*Bz Bsq.reduction_type = Integral Bsq.intervals = 20 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