diff --git a/.clang-tidy b/.clang-tidy index 87e0bdc5dc..226e687d4e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -11,9 +11,40 @@ Checks: ' bugprone-*, -bugprone-easily-swappable-parameters, -bugprone-implicit-widening-of-multiplication-result, - -bugprone-misplaced-widening-cast, - -bugprone-narrowing-conversions, - cppcoreguidelines-avoid-goto + clang-analyzer-*, + -clang-analyzer-optin.mpi.MPI-Checker, + clang-diagnostic-*, + cppcoreguidelines-*, + -cppcoreguidelines-avoid-c-arrays, + -cppcoreguidelines-avoid-do-while, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-avoid-non-const-global-variables, + -cppcoreguidelines-init-variables, + -cppcoreguidelines-interfaces-global-init, + -cppcoreguidelines-macro-usage, + -cppcoreguidelines-no-malloc, + -cppcoreguidelines-non-private-member-variables-in-classes, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-pro-*, + google-build-explicit-make-pair, + google-build-namespaces, + google-global-names-in-headers, + misc-*, + -misc-const-correctness, + -misc-include-cleaner, + -misc-non-private-member-variables-in-classes, + -misc-no-recursion, + modernize-*, + -modernize-avoid-c-arrays, + -modernize-macro-to-enum, + -modernize-return-braced-init-list, + -modernize-use-auto, + -modernize-use-trailing-return-type, + performance-*, + -performance-enum-size, + -performance-inefficient-string-concatenation, + portability-*, + mpi-* ' HeaderFilterRegex: 'src[a-z_A-Z0-9\/]+\.H$' diff --git a/.github/workflows/clangtidy.yml b/.github/workflows/clangtidy.yml index bcee08174c..7f4ce98001 100644 --- a/.github/workflows/clangtidy.yml +++ b/.github/workflows/clangtidy.yml @@ -22,4 +22,8 @@ jobs: - name: Build & Install run: | ./tools/runClangTidy.sh + - name: Output clang-tidy log + if: always() + run: | + cat ./build_clang_tidy/clang-tidy.log diff --git a/src/Hipace.H b/src/Hipace.H index 4a38fb33ff..535a340618 100644 --- a/src/Hipace.H +++ b/src/Hipace.H @@ -35,7 +35,7 @@ namespace hpmg { class MultiGrid; } namespace FieldBoundary { - enum type { + enum type : int { Dirichlet, Periodic, Open @@ -43,7 +43,7 @@ namespace FieldBoundary { } namespace ParticleBoundary { - enum type { + enum type : int { Reflecting, Periodic, Absorbing @@ -60,6 +60,11 @@ struct Hipace_early_init /** Destructor for FFT cleanup */ ~Hipace_early_init (); + Hipace_early_init (const Hipace_early_init& rhs) = delete; + Hipace_early_init (Hipace_early_init&& rhs) = delete; + Hipace_early_init& operator= (const Hipace_early_init& rhs) = delete; + Hipace_early_init& operator= (Hipace_early_init&& rhs) = delete; + /** Struct containing physical constants (which values depends on the unit system, determined * at runtime): SI or normalized units. */ PhysConst m_phys_const; diff --git a/src/Hipace.cpp b/src/Hipace.cpp index 8e037b0ada..3a91bb027b 100644 --- a/src/Hipace.cpp +++ b/src/Hipace.cpp @@ -258,7 +258,7 @@ Hipace::ReadParameters () queryWithParser(pph, "collisions", m_collision_names); /** Initialize the collision objects */ - m_ncollisions = m_collision_names.size(); + m_ncollisions = static_cast(m_collision_names.size()); for (int i = 0; i < m_ncollisions; ++i) { m_all_collisions.emplace_back(CoulombCollision()); m_all_collisions.back().ReadParameters(m_multi_plasma.m_names, m_multi_beam.m_names, m_collision_names[i]); @@ -393,8 +393,8 @@ Hipace::MakeGeometry () }; std::array patch_len_lev { - n_cells_lev[0] * m_3D_geom[0].CellSize(0) / ref_ratio[0], - n_cells_lev[1] * m_3D_geom[0].CellSize(1) / ref_ratio[1], + amrex::Real(n_cells_lev[0]) * m_3D_geom[0].CellSize(0) / ref_ratio[0], + amrex::Real(n_cells_lev[1]) * m_3D_geom[0].CellSize(1) / ref_ratio[1], }; std::array old_patch_len { @@ -432,8 +432,8 @@ Hipace::MakeGeometry () int(amrex::Math::round((patch_hi_lev[2] - pos_offset_z) * m_3D_geom[0].InvCellSize(2))) ); - patch_lo_lev[2] = (zeta_lo-0.5_rt)*m_3D_geom[0].CellSize(2) + pos_offset_z; - patch_hi_lev[2] = (zeta_hi+0.5_rt)*m_3D_geom[0].CellSize(2) + pos_offset_z; + patch_lo_lev[2] = (amrex::Real(zeta_lo)-0.5_rt)*m_3D_geom[0].CellSize(2) + pos_offset_z; + patch_hi_lev[2] = (amrex::Real(zeta_hi)+0.5_rt)*m_3D_geom[0].CellSize(2) + pos_offset_z; const amrex::Box domain_3D_lev{amrex::IntVect(0,0,zeta_lo), amrex::IntVect(n_cells_lev[0]-1, n_cells_lev[1]-1, zeta_hi)}; @@ -549,11 +549,13 @@ Hipace::Evolve () } if (m_verbose >= 1) { - std::cout << utils::format_time{amrex::second() - start_time} - << " Rank " << rank - << " started step " << step - << " at time = " << m_physical_time - << " with dt = " << m_dt << std::endl; + amrex::OutStream() + << utils::format_time{amrex::second() - start_time} + << " Rank " << rank + << " started step " << step + << " at time = " << m_physical_time + << " with dt = " << m_dt << '\n'; + amrex::OutStream().flush(); } if (step+1 <= m_max_step) { @@ -612,8 +614,8 @@ Hipace::Evolve () if (!m_explicit) { // averaging predictor corrector loop diagnostics - m_predcorr_avg_iterations /= bx.length(Direction::z); - m_predcorr_avg_B_error /= bx.length(Direction::z); + m_predcorr_avg_iterations /= amrex::Real(bx.length(Direction::z)); + m_predcorr_avg_B_error /= amrex::Real(bx.length(Direction::z)); if (m_verbose >= 2) { amrex::AllPrint() << "Rank " << rank << ": avg. number of iterations " << m_predcorr_avg_iterations @@ -639,37 +641,39 @@ Hipace::Evolve () if (HeadRank()) { const double total_time_s = (amrex::second() - start_time); - amrex::IOFormatSaver iofmtsaver(std::cout); - std::cout << std::setprecision(4); + amrex::IOFormatSaver iofmtsaver(amrex::OutStream()); + amrex::OutStream() << std::setprecision(4); - std::cout << '\n' << "Finished Evolve after " << total_time_s << " seconds using " - << m_numprocs << (m_numprocs > 1 ? " ranks" : " rank" ) << std::endl; + amrex::OutStream() << '\n' << "Finished Evolve after " << total_time_s << + " seconds using " << m_numprocs << (m_numprocs > 1 ? " ranks" : " rank" ) << '\n'; if (m_num_plasma_particles_pushed + m_num_beam_particles_pushed > 0.) { - std::cout << "Total time per particle push: " + amrex::OutStream() << "Total time per particle push: " << 1e9 * total_time_s / (m_num_plasma_particles_pushed + m_num_beam_particles_pushed) << " nanoseconds"; if (m_num_plasma_particles_pushed > 0. && m_num_beam_particles_pushed > 0.) { - std::cout << " (" + amrex::OutStream() << " (" << 1e9 * total_time_s / m_num_plasma_particles_pushed << " plasma, " << 1e9 * total_time_s / m_num_beam_particles_pushed << " beam)"; } - std::cout << std::endl; + amrex::OutStream() << '\n'; } if (m_num_field_cells_updated + m_num_laser_cells_updated > 0.) { - std::cout << "Total time per cell update: " + amrex::OutStream() << "Total time per cell update: " << 1e9 * total_time_s / (m_num_field_cells_updated + m_num_laser_cells_updated) << " nanoseconds"; if (m_num_field_cells_updated > 0. && m_num_laser_cells_updated > 0.) { - std::cout << " (" + amrex::OutStream() << " (" << 1e9 * total_time_s / m_num_field_cells_updated << " field, " << 1e9 * total_time_s / m_num_laser_cells_updated << " laser)"; } - std::cout << std::endl; + amrex::OutStream() << '\n'; } + + amrex::OutStream().flush(); } } } @@ -1253,13 +1257,13 @@ Hipace::AddGridExternalFields (const int lev, const int islice) amrex::ParallelFor(to2D(bx), [=] AMREX_GPU_DEVICE (int i, int j) noexcept { - const amrex::Real x = i * dx + poff_x; - const amrex::Real y = j * dy + poff_y; - const amrex::Real xlo = (i-1) * dx + poff_x; - const amrex::Real ylo = (j-1) * dy + poff_y; - const amrex::Real xhi = (i+1) * dx + poff_x; - const amrex::Real yhi = (j+1) * dy + poff_y; - const amrex::Real z = islice * dz + poff_z; + const amrex::Real x = amrex::Real(i) * dx + poff_x; + const amrex::Real y = amrex::Real(j) * dy + poff_y; + const amrex::Real xlo = amrex::Real(i-1) * dx + poff_x; + const amrex::Real ylo = amrex::Real(j-1) * dy + poff_y; + const amrex::Real xhi = amrex::Real(i+1) * dx + poff_x; + const amrex::Real yhi = amrex::Real(j+1) * dy + poff_y; + const amrex::Real z = amrex::Real(islice) * dz + poff_z; const amrex::Real Bxp = external_fields[0](x, y, z, time); const amrex::Real Byp = external_fields[1](x, y, z, time); diff --git a/src/diagnostics/Diagnostic.H b/src/diagnostics/Diagnostic.H index 02095f3a05..f68c038676 100644 --- a/src/diagnostics/Diagnostic.H +++ b/src/diagnostics/Diagnostic.H @@ -25,7 +25,7 @@ class MultiPlasma; struct DiagnosticData { std::string m_diag_name; /**< name used for input parameters and in the output */ - enum struct diag_type { + enum struct diag_type : int { field, laser, histogram diff --git a/src/diagnostics/Diagnostic.cpp b/src/diagnostics/Diagnostic.cpp index 7f4813c72a..b62446906f 100644 --- a/src/diagnostics/Diagnostic.cpp +++ b/src/diagnostics/Diagnostic.cpp @@ -80,7 +80,7 @@ Diagnostic::needsRhoIndividual () const { queryWithParserAlt(pp, "field_data", comps, ppd); for (auto& c : comps) { // we don't know the names of all the plasmas here so just look for "rho_..." - if (c.find("rho_") == 0) { + if (c.starts_with("rho_")) { return true; } } @@ -97,9 +97,9 @@ Diagnostic::needsTempIndividual () const { queryWithParserAlt(pp, "field_data", comps, ppd); for (auto& c : comps) { // we don't know the names of all the plasmas here so just look for "ux_..." - if (c.find("w_") == 0 || - c.find("ux_") == 0 || c.find("uy_") == 0 || c.find("uz_") == 0 || - c.find("ux^2_") == 0 || c.find("uy^2_") == 0 || c.find("uz^2_") == 0) { + if (c.starts_with("w_") || + c.starts_with("ux_") || c.starts_with("uy_") || c.starts_with("uz_") || + c.starts_with("ux^2_") || c.starts_with("uy^2_") || c.starts_with("uz^2_")) { return true; } } @@ -175,7 +175,7 @@ Diagnostic::Initialize (int nlev, bool use_laser) { std::string base_geom_name = "level_0"; - if (diag_name_to_default_geometry.count(fd.m_diag_name) > 0) { + if (diag_name_to_default_geometry.contains(fd.m_diag_name)) { base_geom_name = diag_name_to_default_geometry.at(fd.m_diag_name); } @@ -183,7 +183,7 @@ Diagnostic::Initialize (int nlev, bool use_laser) { queryWithParserAlt(pp, "base_geometry", base_geom_name, ppd); DeprecatedInput(fd.m_diag_name, "level", "base_geometry"); - if (geometry_name_to_diag_type.count(base_geom_name) > 0) { + if (geometry_name_to_diag_type.contains(base_geom_name)) { fd.m_base_diag_type = geometry_name_to_diag_type.at(base_geom_name); } else { amrex::Abort("Unknown diagnostics base_geometry: '" + base_geom_name + "'!\n" + @@ -341,13 +341,13 @@ Diagnostic::Initialize (int nlev, bool use_laser) { is_global_comp_used[comp_name] = true; // remove all components comps_set.clear(); - } else if (geometry_name_to_output_comps[base_geom_name].count(comp_name) > 0) { + } else if (geometry_name_to_output_comps[base_geom_name].contains(comp_name)) { is_global_comp_used[comp_name] = true; // insert requested component comps_set.insert(comp_name); - } else if (comp_name.find("remove_") == 0 && - geometry_name_to_output_comps[base_geom_name].count( - comp_name.substr(std::string("remove_").size(), comp_name.size())) > 0) { + } else if (comp_name.starts_with("remove_") && + geometry_name_to_output_comps[base_geom_name].contains( + comp_name.substr(std::string("remove_").size(), comp_name.size()))) { is_global_comp_used[comp_name] = true; // remove requested component comps_set.erase(comp_name.substr(std::string("remove_").size(), comp_name.size())); @@ -365,7 +365,7 @@ Diagnostic::Initialize (int nlev, bool use_laser) { } fd.m_comps_output.assign(comps_set.begin(), comps_set.end()); - fd.m_nfields = fd.m_comps_output.size(); + fd.m_nfields = static_cast(fd.m_comps_output.size()); // copy the indexes of m_comps_output to the GPU fd.m_comps_output_idx.resize(fd.m_nfields); @@ -408,7 +408,7 @@ Diagnostic::Initialize (int nlev, bool use_laser) { if(m_output_beam_names.empty()) { m_output_beam_names = all_beam_names; } else { - for(std::string beam_name : m_output_beam_names) { + for(const std::string& beam_name : m_output_beam_names) { if(beam_name == "all" || beam_name == "All") { m_output_beam_names = all_beam_names; break; @@ -498,10 +498,10 @@ Diagnostic::ResizeFDiagFAB (amrex::Vector& field_geom, amrex::RealBox diag_domain = geom.ProbDomain(); for(int dir=0; dir<=2; ++dir) { // make diag_domain correspond to box - diag_domain.setLo(dir, geom.ProbLo(dir) - + (domain.smallEnd(dir) - geom.Domain().smallEnd(dir)) * geom.CellSize(dir)); - diag_domain.setHi(dir, geom.ProbHi(dir) - + (domain.bigEnd(dir) - geom.Domain().bigEnd(dir)) * geom.CellSize(dir)); + diag_domain.setLo(dir, geom.ProbLo(dir) + amrex::Real(domain.smallEnd(dir) + - geom.Domain().smallEnd(dir)) * geom.CellSize(dir)); + diag_domain.setHi(dir, geom.ProbHi(dir) + amrex::Real(domain.bigEnd(dir) + - geom.Domain().bigEnd(dir)) * geom.CellSize(dir)); } // trim the 3D box to slice box for slice IO diff --git a/src/diagnostics/OpenPMDWriter.H b/src/diagnostics/OpenPMDWriter.H index 88dab1964f..37c61e5999 100644 --- a/src/diagnostics/OpenPMDWriter.H +++ b/src/diagnostics/OpenPMDWriter.H @@ -62,7 +62,7 @@ private: */ void WriteBeamParticleData (MultiBeam& beams, openPMD::Iteration& iteration, const amrex::Geometry& geom, - const amrex::Vector< std::string > beamnames); + const amrex::Vector& beamnames); /** \brief writing openPMD field data * @@ -110,6 +110,11 @@ public: ~OpenPMDWriter (); + OpenPMDWriter (const OpenPMDWriter& rhs) = delete; + OpenPMDWriter (OpenPMDWriter&& rhs) = delete; + OpenPMDWriter& operator= (const OpenPMDWriter& rhs) = delete; + OpenPMDWriter& operator= (OpenPMDWriter&& rhs) = delete; + /** Read parameters from the input file */ void ReadParameters (); @@ -122,7 +127,7 @@ public: * \param[in] beams multi beam container which is written to openPMD file * \param[in] beamnames list of the names of the beam to be written to file */ - void InitBeamData (MultiBeam& beams, const amrex::Vector< std::string > beamnames); + void InitBeamData (MultiBeam& beams, const amrex::Vector& beamnames); /** \brief writing openPMD beam data * @@ -134,7 +139,7 @@ public: */ void WriteBeamDiagnostics ( MultiBeam& a_multi_beam, const amrex::Real physical_time, const int output_step, - const amrex::Vector< std::string > beamnames, + const amrex::Vector& beamnames, amrex::Vector const& geom3D); /** \brief writing openPMD field data @@ -153,7 +158,7 @@ public: * \param[in] beams multi beam container which is written to openPMD file * \param[in] beamnames list of the names of the beam to be written to file */ - void CopyBeams (MultiBeam& beams, const amrex::Vector< std::string > beamnames); + void CopyBeams (MultiBeam& beams, const amrex::Vector& beamnames); /** \brief Resets and flushes the openPMD series of all levels */ diff --git a/src/diagnostics/OpenPMDWriter.cpp b/src/diagnostics/OpenPMDWriter.cpp index 6fb15c7821..fd2e2cc585 100644 --- a/src/diagnostics/OpenPMDWriter.cpp +++ b/src/diagnostics/OpenPMDWriter.cpp @@ -23,7 +23,7 @@ namespace utils { { std::string record_name = fullName; std::string component_name = openPMD::RecordComponent::SCALAR; - std::size_t startComp = fullName.find_last_of("_"); + std::size_t startComp = fullName.find_last_of('_'); if( startComp != std::string::npos ) { // non-scalar record_name = fullName.substr(0, startComp); @@ -113,9 +113,9 @@ OpenPMDWriter::ReadParameters () queryWithParser(ppd, "openpmd_viewer_u_workaround", m_openpmd_viewer_workaround); } -OpenPMDWriter::OpenPMDWriter () {} +OpenPMDWriter::OpenPMDWriter () = default; -OpenPMDWriter::~OpenPMDWriter() {} +OpenPMDWriter::~OpenPMDWriter() = default; void OpenPMDWriter::InitDiagnostics () @@ -133,7 +133,7 @@ OpenPMDWriter::InitDiagnostics () void OpenPMDWriter::WriteBeamDiagnostics ( MultiBeam& a_multi_beam, const amrex::Real physical_time, const int output_step, - const amrex::Vector< std::string > beamnames, + const amrex::Vector& beamnames, amrex::Vector const& geom3D) { openPMD::Iteration iteration = m_outputSeries->iterations[output_step]; @@ -245,7 +245,7 @@ OpenPMDWriter::WriteFieldData ( } void -OpenPMDWriter::InitBeamData (MultiBeam& beams, const amrex::Vector< std::string > beamnames) +OpenPMDWriter::InitBeamData (MultiBeam& beams, const amrex::Vector& beamnames) { HIPACE_PROFILE("OpenPMDWriter::InitBeamData()"); @@ -269,8 +269,8 @@ OpenPMDWriter::InitBeamData (MultiBeam& beams, const amrex::Vector< std::string m_uint64_beam_data[ibeam].resize(m_int_names.size()); - for (std::size_t idx=0; idx beamnames) + const amrex::Vector& beamnames) { HIPACE_PROFILE("OpenPMDWriter::WriteBeamParticleData()"); @@ -355,7 +355,7 @@ OpenPMDWriter::WriteBeamParticleData (MultiBeam& beams, openPMD::Iteration& iter } void -OpenPMDWriter::CopyBeams (MultiBeam& beams, const amrex::Vector< std::string > beamnames) +OpenPMDWriter::CopyBeams (MultiBeam& beams, const amrex::Vector& beamnames) { HIPACE_PROFILE("OpenPMDWriter::CopyBeams()"); @@ -408,8 +408,8 @@ OpenPMDWriter::CopyBeams (MultiBeam& beams, const amrex::Vector< std::string > b ); } amrex::Gpu::copyAsync(amrex::Gpu::deviceToHost, - soa.GetRealData(idx).begin(), - soa.GetRealData(idx).begin() + np, + soa.GetRealData(int(idx)).begin(), + soa.GetRealData(int(idx)).begin() + np, m_real_beam_data[ibeam][idx].data() + m_offset[ibeam]); } } @@ -496,7 +496,7 @@ OpenPMDWriter::SetupRealProperties (openPMD::ParticleSpecies& currSpecies, auto particlesLineup = openPMD::Dataset(openPMD::determineDatatype(),{np}); /* we have 7 or 10 SoA real attributes: x, y, z, weight, ux, uy, uz, (sx, sy, sz) */ - int const NumSoARealAttributes = real_comp_names.size(); + int const NumSoARealAttributes = static_cast(real_comp_names.size()); std::set< std::string > addedRecords; // add meta-data per record only once for (int i = 0; i < NumSoARealAttributes; ++i) diff --git a/src/fields/Fields.H b/src/fields/Fields.H index 34645e3741..d38aa250a1 100644 --- a/src/fields/Fields.H +++ b/src/fields/Fields.H @@ -26,7 +26,7 @@ class MultiLaser; /** \brief describes which slice with respect to the currently calculated is used */ struct WhichSlice { - enum slice { Next=0, This, Previous, RhomJzIons, Salame, PCIter, PCPrevIter, N }; + enum slice : int { Next=0, This, Previous, RhomJzIons, Salame, PCIter, PCPrevIter, N }; }; struct assert_map : std::map { @@ -55,7 +55,7 @@ inline int N_Comps {0}; /** \brief Direction of each dimension. Can be used for clean handling 2D vs. 3D in the future */ struct Direction{ - enum dir{x=0, y, z}; + enum dir : int {x=0, y, z}; }; /** \brief Function to help converting field indexes to positions and backwards. Usage: @@ -71,7 +71,7 @@ GetPosOffset (const int dir, const amrex::Geometry& geom, const amrex::Box& box) using namespace amrex::literals; // match boxes at center point return 0.5_rt * (geom.ProbLo(dir) + geom.ProbHi(dir) - - geom.CellSize(dir) * (box.smallEnd(dir) + box.bigEnd(dir))); + - geom.CellSize(dir) * static_cast(box.smallEnd(dir) + box.bigEnd(dir))); } /** \brief Main class handling all field data structures and operations @@ -112,7 +112,7 @@ public: * \param[in] islice slice index * \param[in] comp component name of field (see Comps) */ - amrex::MultiFab getField (const int lev, const int islice, const std::string comp) { + amrex::MultiFab getField (const int lev, const int islice, const std::string& comp) { return amrex::MultiFab(getSlices(lev), amrex::make_alias, Comps[islice][comp], 1); } /** get amrex::MultiFab of the poisson staging area @@ -166,8 +166,8 @@ public: * \param[in] factor multiply the boundary value by this factor */ void SetBoundaryCondition (amrex::Vector const& geom, const int lev, - const int which_slice, std::string component, - amrex::MultiFab&& staging_area, + const int which_slice, const std::string& component, + amrex::MultiFab staging_area, amrex::Real offset, amrex::Real factor); /** \brief Interpolate values from coarse grid (lev-1) to the boundary of the fine grid (lev). @@ -235,7 +235,7 @@ public: * \param[in] do_sum if the fields are currents and needs to be summed * \param[in] comp_idx vector of component indexes such as Comps[WhichSlice::This]["Ez"] */ - void EnforcePeriodic (const bool do_sum, std::vector&& comp_idx); + void EnforcePeriodic (const bool do_sum, std::vector comp_idx); /** \brief Sets the initial guess of the B field from the two previous slices * * This modifies component Bx or By of slice 1 in m_fields.m_slices diff --git a/src/fields/Fields.cpp b/src/fields/Fields.cpp index 0291767137..ea05ab164e 100644 --- a/src/fields/Fields.cpp +++ b/src/fields/Fields.cpp @@ -152,10 +152,10 @@ Fields::AllocData ( "jx", "jy", "jz_beam", "Bx", "By", "Sy", "Sx", "Sy_back", "Sx_back"); } - isl = WhichSlice::PCIter; + // isl = WhichSlice::PCIter; // empty - isl = WhichSlice::PCPrevIter; + // isl = WhichSlice::PCPrevIter; // empty } else { @@ -222,7 +222,7 @@ Fields::AllocData ( Comps[isl].multi_emplace(N_Comps, "rhomjz"); } - isl = WhichSlice::Salame; + // isl = WhichSlice::Salame; // empty, not compatible isl = WhichSlice::PCIter; @@ -255,40 +255,26 @@ Fields::AllocData ( // The constructor takes the BoxArray and the DistributionMap of a slice, // so the FFTPlans are built on a slice. if (poisson_solver_str == "FFTDirichletDirectEven"){ - m_poisson_solver.push_back(std::unique_ptr( - new FFTPoissonSolverDirichletDirect(getSlices(lev).boxArray(), - getSlices(lev).DistributionMap(), - geom, true))); + m_poisson_solver.push_back(std::make_unique( + getSlices(lev).boxArray(), getSlices(lev).DistributionMap(), geom, true)); } else if (poisson_solver_str == "FFTDirichletDirectOdd"){ - m_poisson_solver.push_back(std::unique_ptr( - new FFTPoissonSolverDirichletDirect(getSlices(lev).boxArray(), - getSlices(lev).DistributionMap(), - geom, false))); + m_poisson_solver.push_back(std::make_unique( + getSlices(lev).boxArray(), getSlices(lev).DistributionMap(), geom, false)); } else if (poisson_solver_str == "FFTDirichletExpanded"){ - m_poisson_solver.push_back(std::unique_ptr( - new FFTPoissonSolverDirichletExpanded(getSlices(lev).boxArray(), - getSlices(lev).DistributionMap(), - geom)) ); + m_poisson_solver.push_back(std::make_unique( + getSlices(lev).boxArray(), getSlices(lev).DistributionMap(), geom)); } else if (poisson_solver_str == "FFTDirichletFast"){ - m_poisson_solver.push_back(std::unique_ptr( - new FFTPoissonSolverDirichletFast(getSlices(lev).boxArray(), - getSlices(lev).DistributionMap(), - geom)) ); + m_poisson_solver.push_back(std::make_unique( + getSlices(lev).boxArray(), getSlices(lev).DistributionMap(), geom)); } else if (poisson_solver_str == "FFTDirichletQuick"){ - m_poisson_solver.push_back(std::unique_ptr( - new FFTPoissonSolverDirichletQuick(getSlices(lev).boxArray(), - getSlices(lev).DistributionMap(), - geom)) ); + m_poisson_solver.push_back(std::make_unique( + getSlices(lev).boxArray(), getSlices(lev).DistributionMap(), geom)); } else if (poisson_solver_str == "FFTPeriodic") { - m_poisson_solver.push_back(std::unique_ptr( - new FFTPoissonSolverPeriodic(getSlices(lev).boxArray(), - getSlices(lev).DistributionMap(), - geom)) ); + m_poisson_solver.push_back(std::make_unique( + getSlices(lev).boxArray(), getSlices(lev).DistributionMap(), geom)); } else if (poisson_solver_str == "MGDirichlet") { - m_poisson_solver.push_back(std::unique_ptr( - new MGPoissonSolverDirichlet(getSlices(lev).boxArray(), - getSlices(lev).DistributionMap(), - geom)) ); + m_poisson_solver.push_back(std::make_unique( + getSlices(lev).boxArray(), getSlices(lev).DistributionMap(), geom)); } else { amrex::Abort("Unknown poisson solver '" + poisson_solver_str + "', must be 'FFTDirichletDirectEven', 'FFTDirichletDirectOdd', 'FFTDirichletExpanded', " @@ -341,7 +327,8 @@ template struct derivative { // use brace initialization as constructor amrex::MultiFab f_view; // field to calculate its derivative - const amrex::Geometry& geom; // geometry of field + // geometry of field + const amrex::Geometry& geom; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) // use .array(mfi) like with amrex::MultiFab derivative_inner array (amrex::MFIter& mfi) const { @@ -355,7 +342,8 @@ struct derivative { // use brace initialization as constructor amrex::MultiFab f_view1; // field on previous slice to calculate its derivative amrex::MultiFab f_view2; // field on next slice to calculate its derivative - const amrex::Geometry& geom; // geometry of field + // geometry of field + const amrex::Geometry& geom; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) // use .array(mfi) like with amrex::MultiFab derivative_inner array (amrex::MFIter& mfi) const { @@ -430,7 +418,8 @@ struct guarded_field_xy_inner { /** \brief if indices are outside of the fields box zero is returned */ struct guarded_field_xy { // use brace initialization as constructor - amrex::MultiFab& mfab; // field to be guarded (zero extended) + // field to be guarded (zero extended) + amrex::MultiFab& mfab; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) // use .array(mfi) like with amrex::MultiFab guarded_field_xy_inner array (amrex::MFIter& mfi) const { @@ -511,8 +500,10 @@ Fields::Copy (const int current_N_level, const int i_slice, DiagnosticData& fd, // Calculate to which diag_fab slices this slice could contribute const int i_slice_min = i_slice - depos_order_offset; const int i_slice_max = i_slice + depos_order_offset; - const amrex::Real pos_slice_min = i_slice_min * field_geom[0].CellSize(2) + poff_calc_z; - const amrex::Real pos_slice_max = i_slice_max * field_geom[0].CellSize(2) + poff_calc_z; + const amrex::Real pos_slice_min = amrex::Real(i_slice_min) * field_geom[0].CellSize(2) + + poff_calc_z; + const amrex::Real pos_slice_max = amrex::Real(i_slice_max) * field_geom[0].CellSize(2) + + poff_calc_z; int k_min = static_cast(amrex::Math::round((pos_slice_min - poff_diag_z) * fd.m_geom_io.InvCellSize(2))); const int k_max = static_cast(amrex::Math::round((pos_slice_max - poff_diag_z) @@ -523,7 +514,7 @@ Fields::Copy (const int current_N_level, const int i_slice, DiagnosticData& fd, // Put contributions from i_slice to different diag_fab slices in GPU vector m_rel_z_vec.resize(k_max+1-k_min); for (int k=k_min; k<=k_max; ++k) { - const amrex::Real pos = k * fd.m_geom_io.CellSize(2) + poff_diag_z; + const amrex::Real pos = amrex::Real(k) * fd.m_geom_io.CellSize(2) + poff_diag_z; const amrex::Real mid_i_slice = (pos - poff_calc_z)*field_geom[0].InvCellSize(2); m_rel_z_vec[k-k_min] = 0; for (int i=0; i<=depos_order_z; ++i) { @@ -549,7 +540,7 @@ Fields::Copy (const int current_N_level, const int i_slice, DiagnosticData& fd, diag_box.setBig(2, amrex::min(diag_box.bigEnd(2), k_stop)); } else { m_rel_z_vec.resize(1); - const amrex::Real pos_z = i_slice * field_geom[0].CellSize(2) + poff_calc_z; + const amrex::Real pos_z = amrex::Real(i_slice) * field_geom[0].CellSize(2) + poff_calc_z; if (fd.m_geom_io.ProbLo(2) <= pos_z && pos_z <= fd.m_geom_io.ProbHi(2)) { m_rel_z_vec[0] = field_geom[0].CellSize(2); k_min = 0; @@ -588,8 +579,8 @@ Fields::Copy (const int current_N_level, const int i_slice, DiagnosticData& fd, amrex::ParallelFor(diag_box, fd.m_nfields, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - const amrex::Real x = i * dx + poff_diag_x; - const amrex::Real y = j * dy + poff_diag_y; + const amrex::Real x = amrex::Real(i) * dx + poff_diag_x; + const amrex::Real y = amrex::Real(j) * dy + poff_diag_y; const int m = n[diag_comps]; if (m == -1) { // Ex diag_array(i,j,k,n) += rel_z_data[k-k_min] * ( @@ -608,8 +599,8 @@ Fields::Copy (const int current_N_level, const int i_slice, DiagnosticData& fd, amrex::ParallelFor(diag_box, fd.m_nfields, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - const amrex::Real x = i * dx + poff_diag_x; - const amrex::Real y = j * dy + poff_diag_y; + const amrex::Real x = amrex::Real(i) * dx + poff_diag_x; + const amrex::Real y = amrex::Real(j) * dy + poff_diag_y; const int m = n[diag_comps]; if (m == -1) { // real=|a^2|, imag=0 diag_array_laser(i,j,k,n) += amrex::GpuComplex{ @@ -791,8 +782,10 @@ SetDirichletBoundaries (Array2 RHS, const amrex::Box& solver_size, const int i_idx = box_lo0 + i_hi_edge*(box_len0-1) + i_is_changing_i*i; const int j_idx = box_lo1 + j_hi_edge*(box_len1-1) + i_not_changing_i*(i-box_len0); - const amrex::Real i_idx_offset = i_idx + (- i_lo_edge + i_hi_edge) * offset; - const amrex::Real j_idx_offset = j_idx + (- j_lo_edge + j_hi_edge) * offset; + const amrex::Real i_idx_offset = amrex::Real(i_idx) + + amrex::Real(- i_lo_edge + i_hi_edge) * offset; + const amrex::Real j_idx_offset = amrex::Real(j_idx) + + amrex::Real(- j_lo_edge + j_hi_edge) * offset; const amrex::Real x = i_idx_offset * dx + offset0; const amrex::Real y = j_idx_offset * dy + offset1; @@ -807,8 +800,8 @@ SetDirichletBoundaries (Array2 RHS, const amrex::Box& solver_size, void Fields::SetBoundaryCondition (amrex::Vector const& geom, const int lev, - const int which_slice, std::string component, - amrex::MultiFab&& staging_area, + const int which_slice, const std::string& component, + amrex::MultiFab staging_area, amrex::Real offset, amrex::Real factor) { const amrex::Box staging_box = geom[lev].Domain(); @@ -848,8 +841,8 @@ Fields::SetBoundaryCondition (amrex::Vector const& geom, const staging_area, [=] AMREX_GPU_DEVICE (int /*box_num*/, int i, int j, int) noexcept { - const amrex::Real x = (i * dx + poff_x) * scale; - const amrex::Real y = (j * dy + poff_y) * scale; + const amrex::Real x = (amrex::Real(i) * dx + poff_x) * scale; + const amrex::Real y = (amrex::Real(j) * dy + poff_y) * scale; if (x*x + y*y > cutoff_sq) { return amrex::IdentityTuple(MultipoleTuple{}, MultipoleReduceOpList{}); } @@ -927,8 +920,8 @@ Fields::LevelUpBoundary (amrex::Vector const& geom, const int l // set interpolated values near edge of fine field between outer_edge and inner_edge // to compensate for incomplete charge/current deposition in those cells if(inarrow_i_hi || jnarrow_j_hi) { - amrex::Real x = i * dx + offset0; - amrex::Real y = j * dy + offset1; + amrex::Real x = amrex::Real(i) * dx + offset0; + amrex::Real y = amrex::Real(j) * dy + offset1; arr_field_fine(i,j) = arr_field_coarse_interp(x,y); } }); @@ -961,8 +954,8 @@ Fields::LevelUp (amrex::Vector const& geom, const int lev, [=] AMREX_GPU_DEVICE (int i, int j) noexcept { // interpolate the full field - const amrex::Real x = i * dx + offset0; - const amrex::Real y = j * dy + offset1; + const amrex::Real x = amrex::Real(i) * dx + offset0; + const amrex::Real y = amrex::Real(j) * dy + offset1; arr_field_fine(i,j) = arr_field_coarse_interp(x,y); }); } @@ -1232,20 +1225,22 @@ Fields::SymmetrizeFields (int field_comp, const int lev, const int symm_x, const amrex::ParallelFor(to2D(quarter_box), [=] AMREX_GPU_DEVICE (int i, int j) noexcept { - const amrex::Real avg = 0.25_rt*(arr(i, j) + arr(upper_x - i, j)*symm_x - + arr(i, upper_y - j)*symm_y + arr(upper_x - i, upper_y - j)*symm_x*symm_y); + const amrex::Real symm_xr = amrex::Real(symm_x); + const amrex::Real symm_yr = amrex::Real(symm_y); + const amrex::Real avg = 0.25_rt*(arr(i, j) + arr(upper_x - i, j)*symm_xr + + arr(i, upper_y - j)*symm_yr + arr(upper_x - i, upper_y - j)*symm_xr*symm_yr); // Note: this may write to the same cell multiple times in the center. arr(i, j) = avg; - arr(upper_x - i, j) = avg*symm_x; - arr(i, upper_y - j) = avg*symm_y; - arr(upper_x - i, upper_y - j) = avg*symm_x*symm_y; + arr(upper_x - i, j) = avg*symm_xr; + arr(i, upper_y - j) = avg*symm_yr; + arr(upper_x - i, upper_y - j) = avg*symm_xr*symm_yr; }); } } void -Fields::EnforcePeriodic (const bool do_sum, std::vector&& comp_idx) +Fields::EnforcePeriodic (const bool do_sum, std::vector comp_idx) { amrex::MultiFab& mfab = getSlices(0); @@ -1285,8 +1280,8 @@ Fields::InitialBfieldGuess (const amrex::Real relative_Bfield_error, */ HIPACE_PROFILE("Fields::InitialBfieldGuess()"); - const amrex::Real mix_factor_init_guess = std::exp(-0.5_rt * std::pow(relative_Bfield_error / - ( 2.5_rt * predcorr_B_error_tolerance ), 2)); + const amrex::Real mix_factor_init_guess = std::exp(-0.5_rt * + amrex::Math::powi<2>(relative_Bfield_error / (2.5_rt * predcorr_B_error_tolerance))); amrex::MultiFab& slicemf = getSlices(lev); @@ -1438,7 +1433,7 @@ Fields::InSituComputeDiags (int step, int islice, const amrex::Geometry& geom3D, const int Bx = Comps[WhichSlice::This]["Bx"]; const int By = Comps[WhichSlice::This]["By"]; const int Bz = Comps[WhichSlice::This]["Bz"]; - AMREX_ALWAYS_ASSERT_WITH_MESSAGE(Comps[WhichSlice::This].count("jz_beam") > 0, + AMREX_ALWAYS_ASSERT_WITH_MESSAGE(Comps[WhichSlice::This].contains("jz_beam"), "Must use explicit solver for field insitu diagnostic"); const int jz_beam = Comps[WhichSlice::This]["jz_beam"]; diff --git a/src/fields/fft_poisson_solver/FFTPoissonSolver.H b/src/fields/fft_poisson_solver/FFTPoissonSolver.H index 842d08ff17..56a57a3b51 100644 --- a/src/fields/fft_poisson_solver/FFTPoissonSolver.H +++ b/src/fields/fft_poisson_solver/FFTPoissonSolver.H @@ -33,6 +33,11 @@ public: /** Abstract class needs a virtual destructor */ virtual ~FFTPoissonSolver () = default; + FFTPoissonSolver (const FFTPoissonSolver& rhs) = delete; + FFTPoissonSolver (FFTPoissonSolver&& rhs) = delete; + FFTPoissonSolver& operator= (const FFTPoissonSolver& rhs) = delete; + FFTPoissonSolver& operator= (FFTPoissonSolver&& rhs) = delete; + /** * Solve Poisson equation. The source term must be stored in the staging area m_stagingArea prior to this call. * diff --git a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletDirect.H b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletDirect.H index e1ea95dc7b..0546841e56 100644 --- a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletDirect.H +++ b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletDirect.H @@ -33,7 +33,12 @@ public: bool is_even); /** virtual destructor */ - virtual ~FFTPoissonSolverDirichletDirect () override final {} + ~FFTPoissonSolverDirichletDirect () final = default; + + FFTPoissonSolverDirichletDirect (const FFTPoissonSolverDirichletDirect& rhs) = delete; + FFTPoissonSolverDirichletDirect (FFTPoissonSolverDirichletDirect&& rhs) = delete; + FFTPoissonSolverDirichletDirect& operator= (const FFTPoissonSolverDirichletDirect& rhs) = delete; + FFTPoissonSolverDirichletDirect& operator= (FFTPoissonSolverDirichletDirect&& rhs) = delete; /** * \brief Define real space and spectral space boxes and multifabs, Dirichlet @@ -55,11 +60,11 @@ public: * * \param[in] lhs_mf Destination array, where the result is stored. */ - virtual void SolvePoissonEquation (amrex::MultiFab& lhs_mf) override final; + void SolvePoissonEquation (amrex::MultiFab& lhs_mf) final; /** Position and relative factor used to apply inhomogeneous Dirichlet boundary conditions */ - virtual amrex::Real BoundaryOffset() override final { return m_is_even ? 0.5 : 1.; } - virtual amrex::Real BoundaryFactor() override final { return m_is_even ? 2. : 1.; } + amrex::Real BoundaryOffset() final { return m_is_even ? 0.5 : 1.; } + amrex::Real BoundaryFactor() final { return m_is_even ? 2. : 1.; } private: /** Spectral fields, contains (real) field in Fourier space */ diff --git a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletDirect.cpp b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletDirect.cpp index 4d8d5759fb..a351226da0 100644 --- a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletDirect.cpp +++ b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletDirect.cpp @@ -61,12 +61,12 @@ FFTPoissonSolverDirichletDirect::define (amrex::BoxArray const& a_realspace_ba, const auto dx = gm.CellSizeArray(); const amrex::Real dxsquared = dx[0]*dx[0]; const amrex::Real dysquared = dx[1]*dx[1]; - const amrex::Real sine_x_factor = MathConst::pi / ( 2. * logical_nx); - const amrex::Real sine_y_factor = MathConst::pi / ( 2. * logical_ny); + const amrex::Real sine_x_factor = MathConst::pi / amrex::Real( 2. * logical_nx); + const amrex::Real sine_y_factor = MathConst::pi / amrex::Real( 2. * logical_ny); // Normalization of FFTW's 'DST-I' discrete sine transform (FFTW_RODFT00) // This normalization is used regardless of the sine transform library - const amrex::Real norm_fac = 0.5 / ( 2 * (logical_nx * logical_ny)); + const amrex::Real norm_fac = 0.5_rt / amrex::Real( 2 * (logical_nx * logical_ny)); // Calculate the array of m_eigenvalue_matrix for (amrex::MFIter mfi(m_eigenvalue_matrix, DfltMfi); mfi.isValid(); ++mfi ){ @@ -76,12 +76,15 @@ FFTPoissonSolverDirichletDirect::define (amrex::BoxArray const& a_realspace_ba, to2D(fft_box), [=] AMREX_GPU_DEVICE (int i, int j) noexcept { /* fast poisson solver diagonal x coeffs */ - amrex::Real sinex_sq = std::sin(( i - lo[0] + 1 ) * sine_x_factor) * std::sin(( i - lo[0] + 1 ) * sine_x_factor); + const amrex::Real sinex_sq = amrex::Math::powi<2>( + std::sin(amrex::Real( i - lo[0] + 1 ) * sine_x_factor)); /* fast poisson solver diagonal y coeffs */ - amrex::Real siney_sq = std::sin(( j - lo[1] + 1 ) * sine_y_factor) * std::sin(( j - lo[1] + 1 ) * sine_y_factor); + const amrex::Real siney_sq = amrex::Math::powi<2>( + std::sin(amrex::Real( j - lo[1] + 1 ) * sine_y_factor)); if ((sinex_sq!=0) && (siney_sq!=0)) { - eigenvalue_matrix(i,j) = norm_fac / ( -4.0 * ( sinex_sq / dxsquared + siney_sq / dysquared )); + eigenvalue_matrix(i,j) = norm_fac / ( -4.0_rt * + ( sinex_sq / dxsquared + siney_sq / dysquared )); } else { // Avoid division by 0 eigenvalue_matrix(i,j) = 0._rt; diff --git a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletExpanded.H b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletExpanded.H index e216037e72..c299650e09 100644 --- a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletExpanded.H +++ b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletExpanded.H @@ -32,7 +32,12 @@ public: amrex::Geometry const& gm); /** virtual destructor */ - virtual ~FFTPoissonSolverDirichletExpanded () override final {} + ~FFTPoissonSolverDirichletExpanded () final = default; + + FFTPoissonSolverDirichletExpanded (const FFTPoissonSolverDirichletExpanded& rhs) = delete; + FFTPoissonSolverDirichletExpanded (FFTPoissonSolverDirichletExpanded&& rhs) = delete; + FFTPoissonSolverDirichletExpanded& operator= (const FFTPoissonSolverDirichletExpanded& rhs) = delete; + FFTPoissonSolverDirichletExpanded& operator= (FFTPoissonSolverDirichletExpanded&& rhs) = delete; /** * \brief Define real space and spectral space boxes and multifabs, Dirichlet @@ -52,11 +57,11 @@ public: * * \param[in] lhs_mf Destination array, where the result is stored. */ - virtual void SolvePoissonEquation (amrex::MultiFab& lhs_mf) override final; + void SolvePoissonEquation (amrex::MultiFab& lhs_mf) final; /** Position and relative factor used to apply inhomogeneous Dirichlet boundary conditions */ - virtual amrex::Real BoundaryOffset() override final { return 1.; } - virtual amrex::Real BoundaryFactor() override final { return 1.; } + amrex::Real BoundaryOffset() final { return 1.; } + amrex::Real BoundaryFactor() final { return 1.; } private: /** Multifab eigenvalues, to solve Poisson equation with Dirichlet BC. */ diff --git a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletExpanded.cpp b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletExpanded.cpp index 72f5497d77..b36c886f36 100644 --- a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletExpanded.cpp +++ b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletExpanded.cpp @@ -156,12 +156,12 @@ FFTPoissonSolverDirichletExpanded::define (amrex::BoxArray const& a_realspace_ba const auto dx = gm.CellSizeArray(); const amrex::Real dxsquared = dx[0]*dx[0]; const amrex::Real dysquared = dx[1]*dx[1]; - const amrex::Real sine_x_factor = MathConst::pi / ( 2. * ( nx + 1 )); - const amrex::Real sine_y_factor = MathConst::pi / ( 2. * ( ny + 1 )); + const amrex::Real sine_x_factor = MathConst::pi / amrex::Real( 2 * ( nx + 1 )); + const amrex::Real sine_y_factor = MathConst::pi / amrex::Real( 2 * ( ny + 1 )); // Normalization of FFTW's 'DST-I' discrete sine transform (FFTW_RODFT00) // This normalization is used regardless of the sine transform library - const amrex::Real norm_fac = 0.5 / ( 2 * (( nx + 1 ) * ( ny + 1 ))); + const amrex::Real norm_fac = 0.5_rt / amrex::Real( 2 * (( nx + 1 ) * ( ny + 1 ))); // Calculate the array of m_eigenvalue_matrix for (amrex::MFIter mfi(m_eigenvalue_matrix, DfltMfi); mfi.isValid(); ++mfi ){ @@ -171,12 +171,15 @@ FFTPoissonSolverDirichletExpanded::define (amrex::BoxArray const& a_realspace_ba to2D(fft_box), [=] AMREX_GPU_DEVICE (int i, int j) noexcept { /* fast poisson solver diagonal x coeffs */ - amrex::Real sinex_sq = std::sin(( i - lo[0] + 1 ) * sine_x_factor) * std::sin(( i - lo[0] + 1 ) * sine_x_factor); + const amrex::Real sinex_sq = amrex::Math::powi<2>( + std::sin(amrex::Real( i - lo[0] + 1 ) * sine_x_factor)); /* fast poisson solver diagonal y coeffs */ - amrex::Real siney_sq = std::sin(( j - lo[1] + 1 ) * sine_y_factor) * std::sin(( j - lo[1] + 1 ) * sine_y_factor); + const amrex::Real siney_sq = amrex::Math::powi<2>( + std::sin(amrex::Real( j - lo[1] + 1 ) * sine_y_factor)); if ((sinex_sq!=0) && (siney_sq!=0)) { - eigenvalue_matrix(i,j) = norm_fac / ( -4.0 * ( sinex_sq / dxsquared + siney_sq / dysquared )); + eigenvalue_matrix(i,j) = norm_fac / ( -4.0_rt * + ( sinex_sq / dxsquared + siney_sq / dysquared )); } else { // Avoid division by 0 eigenvalue_matrix(i,j) = 0._rt; diff --git a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletFast.H b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletFast.H index becb102c4a..fbb4d23197 100644 --- a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletFast.H +++ b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletFast.H @@ -32,7 +32,12 @@ public: amrex::Geometry const& gm); /** virtual destructor */ - virtual ~FFTPoissonSolverDirichletFast () override final {} + ~FFTPoissonSolverDirichletFast () final = default; + + FFTPoissonSolverDirichletFast (const FFTPoissonSolverDirichletFast& rhs) = delete; + FFTPoissonSolverDirichletFast (FFTPoissonSolverDirichletFast&& rhs) = delete; + FFTPoissonSolverDirichletFast& operator= (const FFTPoissonSolverDirichletFast& rhs) = delete; + FFTPoissonSolverDirichletFast& operator= (FFTPoissonSolverDirichletFast&& rhs) = delete; /** * \brief Define real space and spectral space boxes and multifabs, Dirichlet @@ -52,11 +57,11 @@ public: * * \param[in] lhs_mf Destination array, where the result is stored. */ - virtual void SolvePoissonEquation (amrex::MultiFab& lhs_mf) override final; + void SolvePoissonEquation (amrex::MultiFab& lhs_mf) final; /** Position and relative factor used to apply inhomogeneous Dirichlet boundary conditions */ - virtual amrex::Real BoundaryOffset() override final { return 1.; } - virtual amrex::Real BoundaryFactor() override final { return 1.; } + amrex::Real BoundaryOffset() final { return 1.; } + amrex::Real BoundaryFactor() final { return 1.; } private: /** FArrayBox eigenvalues, to solve Poisson equation with Dirichlet BC. */ diff --git a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletFast.cpp b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletFast.cpp index 75c7bffb21..cec31c9e57 100644 --- a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletFast.cpp +++ b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletFast.cpp @@ -32,7 +32,7 @@ FFTPoissonSolverDirichletFast::FFTPoissonSolverDirichletFast ( * \param[in] n_data number of (contiguous) rows in position matrix */ template AMREX_GPU_DEVICE AMREX_FORCE_INLINE -amrex::GpuComplex to_complex (T&& in, int i, int j, int n_half, int n_data) { +amrex::GpuComplex to_complex (const T& in, int i, int j, int n_half, int n_data) { amrex::Real real = 0; amrex::Real imag = 0; if (i == 0) { @@ -62,7 +62,7 @@ amrex::GpuComplex to_complex (T&& in, int i, int j, int n_half, int * \param[in] sine_factor prefactor for ToSine equal to 1/(2*sin((idx+1)*pi/(n_data+1))) */ template AMREX_GPU_DEVICE AMREX_FORCE_INLINE -amrex::Real to_sine (T&& in, int i, int j, int n_data, const amrex::Real* sine_factor) { +amrex::Real to_sine (const T& in, int i, int j, int n_data, const amrex::Real* sine_factor) { const amrex::Real in_a = in(i+1, j); const amrex::Real in_b = in(n_data-i, j); // possible optimization: @@ -221,12 +221,12 @@ FFTPoissonSolverDirichletFast::define (amrex::BoxArray const& a_realspace_ba, const auto dx = gm.CellSizeArray(); const amrex::Real dxsquared = dx[0]*dx[0]; const amrex::Real dysquared = dx[1]*dx[1]; - const amrex::Real sine_x_factor = MathConst::pi / ( 2. * ( nx + 1 )); - const amrex::Real sine_y_factor = MathConst::pi / ( 2. * ( ny + 1 )); + const amrex::Real sine_x_factor = MathConst::pi / amrex::Real( 2 * ( nx + 1 )); + const amrex::Real sine_y_factor = MathConst::pi / amrex::Real( 2 * ( ny + 1 )); // Normalization of FFTW's 'DST-I' discrete sine transform (FFTW_RODFT00) // This normalization is used regardless of the sine transform library - const amrex::Real norm_fac = 0.5 / ( 2 * (( nx + 1 ) * ( ny + 1 ))); + const amrex::Real norm_fac = 0.5_rt / amrex::Real( 2 * (( nx + 1 ) * ( ny + 1 ))); // Calculate the array of m_eigenvalue_matrix m_eigenvalue_matrix.resize({{0,0,0}, {ny-1,nx-1,0}}); @@ -235,12 +235,15 @@ FFTPoissonSolverDirichletFast::define (amrex::BoxArray const& a_realspace_ba, [=] AMREX_GPU_DEVICE (int j, int i) noexcept { /* fast poisson solver diagonal x coeffs */ - amrex::Real sinex_sq = std::sin(( i + 1 ) * sine_x_factor) * std::sin(( i + 1 ) * sine_x_factor); + const amrex::Real sinex_sq = amrex::Math::powi<2>( + std::sin(amrex::Real(i + 1)*sine_x_factor)); /* fast poisson solver diagonal y coeffs */ - amrex::Real siney_sq = std::sin(( j + 1 ) * sine_y_factor) * std::sin(( j + 1 ) * sine_y_factor); + const amrex::Real siney_sq = amrex::Math::powi<2>( + std::sin(amrex::Real(j + 1)*sine_y_factor)); if ((sinex_sq!=0) && (siney_sq!=0)) { - eigenvalue_matrix(j,i) = norm_fac / ( -4.0_rt * ( sinex_sq / dxsquared + siney_sq / dysquared )); + eigenvalue_matrix(j,i) = norm_fac / ( -4.0_rt * + ( sinex_sq / dxsquared + siney_sq / dysquared )); } else { // Avoid division by 0 eigenvalue_matrix(j,i) = 0._rt; @@ -270,14 +273,16 @@ FFTPoissonSolverDirichletFast::define (amrex::BoxArray const& a_realspace_ba, amrex::Real* const sine_x_ptr = m_sine_x_factor.dataPtr(); amrex::ParallelFor(nx, [=] AMREX_GPU_DEVICE (int i) { - sine_x_ptr[i] = 1._rt / (2._rt * amrex::Math::sinpi((i + 1._rt) / (nx + 1._rt))); + sine_x_ptr[i] = 1._rt / (2._rt * amrex::Math::sinpi(amrex::Real(i + 1) / + amrex::Real(nx + 1))); }); m_sine_y_factor.resize(ny); amrex::Real* const sine_y_ptr = m_sine_y_factor.dataPtr(); amrex::ParallelFor(ny, [=] AMREX_GPU_DEVICE (int i) { - sine_y_ptr[i] = 1._rt / (2._rt * amrex::Math::sinpi((i + 1._rt) / (ny + 1._rt))); + sine_y_ptr[i] = 1._rt / (2._rt * amrex::Math::sinpi(amrex::Real(i + 1) / + amrex::Real(ny + 1))); }); } diff --git a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletQuick.H b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletQuick.H index b06f194524..0e4348ae6d 100644 --- a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletQuick.H +++ b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletQuick.H @@ -32,7 +32,12 @@ public: amrex::Geometry const& gm); /** virtual destructor */ - virtual ~FFTPoissonSolverDirichletQuick () override final {} + ~FFTPoissonSolverDirichletQuick () final = default; + + FFTPoissonSolverDirichletQuick (const FFTPoissonSolverDirichletQuick& rhs) = delete; + FFTPoissonSolverDirichletQuick (FFTPoissonSolverDirichletQuick&& rhs) = delete; + FFTPoissonSolverDirichletQuick& operator= (const FFTPoissonSolverDirichletQuick& rhs) = delete; + FFTPoissonSolverDirichletQuick& operator= (FFTPoissonSolverDirichletQuick&& rhs) = delete; /** * \param[in] realspace_ba BoxArray on which the FFT is executed. @@ -48,11 +53,11 @@ public: * * \param[in] lhs_mf Destination array, where the result is stored. */ - virtual void SolvePoissonEquation (amrex::MultiFab& lhs_mf) override final; + void SolvePoissonEquation (amrex::MultiFab& lhs_mf) final; /** Position and relative factor used to apply inhomogeneous Dirichlet boundary conditions */ - virtual amrex::Real BoundaryOffset() override final { return 0.5; } - virtual amrex::Real BoundaryFactor() override final { return 2.; } + amrex::Real BoundaryOffset() final { return 0.5; } + amrex::Real BoundaryFactor() final { return 2.; } private: /** Real array for the FFTs */ diff --git a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletQuick.cpp b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletQuick.cpp index 8b2ee2e621..b58793197c 100644 --- a/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletQuick.cpp +++ b/src/fields/fft_poisson_solver/FFTPoissonSolverDirichletQuick.cpp @@ -26,12 +26,13 @@ FFTPoissonSolverDirichletQuick::FFTPoissonSolverDirichletQuick ( namespace { template AMREX_GPU_DEVICE AMREX_FORCE_INLINE -amrex::Real dst2_in (T&& in, int i, int j, int n) { +amrex::Real dst2_in (const T& in, int i, int j, int n) { return 2*i < n ? in(2*i, j) : -in(2*(n-i)-1, j); } template AMREX_GPU_DEVICE AMREX_FORCE_INLINE -amrex::Real dst2_out (T&& in, int i, int j, int n, const amrex::GpuComplex* omega) { +amrex::Real dst2_out ( + const T& in, int i, int j, int n, const amrex::GpuComplex* omega) { if (2*i+1 < n) { return - (in(i+1, j) * omega[i+1]).imag(); } else { @@ -41,7 +42,7 @@ amrex::Real dst2_out (T&& in, int i, int j, int n, const amrex::GpuComplex AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::GpuComplex dst3_in ( - T&& in, int i, int j, int n, const amrex::GpuComplex* omega) { + const T& in, int i, int j, int n, const amrex::GpuComplex* omega) { if (i == 0) { return {in(n-1, j), 0}; @@ -53,7 +54,7 @@ amrex::GpuComplex dst3_in ( } template AMREX_GPU_DEVICE AMREX_FORCE_INLINE -amrex::Real dst3_out (T&& in, int i, int j, int n) { +amrex::Real dst3_out (const T& in, int i, int j, int n) { return i%2 == 0 ? in(i/2, j) : -in(n-1-i/2, j); } @@ -300,21 +301,21 @@ FFTPoissonSolverDirichletQuick::define (amrex::BoxArray const& a_realspace_ba, amrex::Real * const eig_x_ptr = m_eig_x.dataPtr(); amrex::Real * const eig_y_ptr = m_eig_y.dataPtr(); - const amrex::Real sine_x_factor = 1._rt / ( 2._rt * nx); - const amrex::Real sine_y_factor = 1._rt / ( 2._rt * ny); - const amrex::Real norm_fac = -4._rt * nx * ny; + const amrex::Real sine_x_factor = 1._rt / ( 2._rt * amrex::Real(nx)); + const amrex::Real sine_y_factor = 1._rt / ( 2._rt * amrex::Real(ny)); + const amrex::Real norm_fac = -4._rt * amrex::Real(nx * ny); const amrex::Real invdxsq = gm.InvCellSize(0)*gm.InvCellSize(0)*norm_fac; const amrex::Real invdysq = gm.InvCellSize(1)*gm.InvCellSize(1)*norm_fac; amrex::ParallelFor(nx, [=] AMREX_GPU_DEVICE (int i) noexcept { - const amrex::Real x_fac = amrex::Math::sinpi(sine_x_factor * (i+1)); + const amrex::Real x_fac = amrex::Math::sinpi(sine_x_factor * amrex::Real(i+1)); eig_x_ptr[i] = x_fac*x_fac*invdxsq; }); amrex::ParallelFor(ny, [=] AMREX_GPU_DEVICE (int i) noexcept { - const amrex::Real y_fac = amrex::Math::sinpi(sine_y_factor * (i+1)); + const amrex::Real y_fac = amrex::Math::sinpi(sine_y_factor * amrex::Real(i+1)); eig_y_ptr[i] = y_fac*y_fac*invdysq; }); @@ -345,7 +346,7 @@ FFTPoissonSolverDirichletQuick::define (amrex::BoxArray const& a_realspace_ba, amrex::GpuComplex* const omega_x_ptr = m_omega_x.dataPtr(); amrex::ParallelFor(nx/2+1, [=] AMREX_GPU_DEVICE (int i) { - auto [imag, real] = amrex::Math::sincospi(-i/amrex::Real(2._rt*nx)); + auto [imag, real] = amrex::Math::sincospi(-amrex::Real(i)/(2._rt * amrex::Real(nx))); omega_x_ptr[i] = {real, imag}; }); @@ -353,7 +354,7 @@ FFTPoissonSolverDirichletQuick::define (amrex::BoxArray const& a_realspace_ba, amrex::GpuComplex* const omega_y_ptr = m_omega_y.dataPtr(); amrex::ParallelFor(ny/2+1, [=] AMREX_GPU_DEVICE (int i) { - auto [imag, real] = amrex::Math::sincospi(-i/amrex::Real(2._rt*ny)); + auto [imag, real] = amrex::Math::sincospi(-amrex::Real(i)/(2._rt * amrex::Real(ny))); omega_y_ptr[i] = {real, imag}; }); } diff --git a/src/fields/fft_poisson_solver/FFTPoissonSolverPeriodic.H b/src/fields/fft_poisson_solver/FFTPoissonSolverPeriodic.H index e18098764f..5ad72ad021 100644 --- a/src/fields/fft_poisson_solver/FFTPoissonSolverPeriodic.H +++ b/src/fields/fft_poisson_solver/FFTPoissonSolverPeriodic.H @@ -36,7 +36,12 @@ public: amrex::Geometry const& gm); /** virtual destructor */ - virtual ~FFTPoissonSolverPeriodic () override final {} + ~FFTPoissonSolverPeriodic () final = default; + + FFTPoissonSolverPeriodic (const FFTPoissonSolverPeriodic& rhs) = delete; + FFTPoissonSolverPeriodic (FFTPoissonSolverPeriodic&& rhs) = delete; + FFTPoissonSolverPeriodic& operator= (const FFTPoissonSolverPeriodic& rhs) = delete; + FFTPoissonSolverPeriodic& operator= (FFTPoissonSolverPeriodic&& rhs) = delete; /** * \brief Define real space and spectral space boxes and multifabs, multiplier @@ -56,13 +61,13 @@ public: * * \param[in] lhs_mf Destination array, where the result is stored. */ - virtual void SolvePoissonEquation (amrex::MultiFab& lhs_mf) override final; + void SolvePoissonEquation (amrex::MultiFab& lhs_mf) final; /** Position and relative factor used to apply inhomogeneous Dirichlet boundary conditions * Note: inhomogeneous Dirichlet boundary conditions do not work with this solver */ - virtual amrex::Real BoundaryOffset() override final { return 1.; } - virtual amrex::Real BoundaryFactor() override final { return 1.; } + amrex::Real BoundaryOffset() final { return 1.; } + amrex::Real BoundaryFactor() final { return 1.; } private: /** Spectral fields, contains (complex) field in Fourier space */ diff --git a/src/fields/fft_poisson_solver/FFTPoissonSolverPeriodic.cpp b/src/fields/fft_poisson_solver/FFTPoissonSolverPeriodic.cpp index bed24ffa3a..03fdd24ef6 100644 --- a/src/fields/fft_poisson_solver/FFTPoissonSolverPeriodic.cpp +++ b/src/fields/fft_poisson_solver/FFTPoissonSolverPeriodic.cpp @@ -80,9 +80,9 @@ FFTPoissonSolverPeriodic::define ( amrex::BoxArray const& realspace_ba, amrex::ParallelFor(to2D(bx), [=] AMREX_GPU_DEVICE (int i, int j) noexcept { // kx is always positive (first axis of the real-to-complex FFT) - amrex::Real kx = dkx*i; + amrex::Real kx = dkx * amrex::Real(i); // The first half of ky is positive ; the other is negative - amrex::Real ky = (j tmp_real_arr = m_stagingArea.array(mfi); Array2 lhs_arr = lhs_mf.array(mfi); const amrex::Box fft_box = m_stagingArea[mfi].box(); - const amrex::Real inv_N = 1./fft_box.numPts(); + const amrex::Real inv_N = amrex::Real(1)/amrex::Real(fft_box.numPts()); amrex::ParallelFor( to2D(mfi.growntilebox()), [=] AMREX_GPU_DEVICE(int i, int j) noexcept { // Copy and normalize field diff --git a/src/fields/fft_poisson_solver/MGPoissonSolverDirichlet.H b/src/fields/fft_poisson_solver/MGPoissonSolverDirichlet.H index fc1bfd4de6..d2ea630a74 100644 --- a/src/fields/fft_poisson_solver/MGPoissonSolverDirichlet.H +++ b/src/fields/fft_poisson_solver/MGPoissonSolverDirichlet.H @@ -31,18 +31,23 @@ public: amrex::Geometry const& gm); /** virtual destructor */ - virtual ~MGPoissonSolverDirichlet () override final {} + ~MGPoissonSolverDirichlet () final = default; + + MGPoissonSolverDirichlet (const MGPoissonSolverDirichlet& rhs) = delete; + MGPoissonSolverDirichlet (MGPoissonSolverDirichlet&& rhs) = delete; + MGPoissonSolverDirichlet& operator= (const MGPoissonSolverDirichlet& rhs) = delete; + MGPoissonSolverDirichlet& operator= (MGPoissonSolverDirichlet&& rhs) = delete; /** * Solve Poisson equation. The source term must be stored in the staging area m_stagingArea prior to this call. * * \param[in] lhs_mf Destination array, where the result is stored. */ - virtual void SolvePoissonEquation (amrex::MultiFab& lhs_mf) override final; + void SolvePoissonEquation (amrex::MultiFab& lhs_mf) final; /** Position and relative factor used to apply inhomogeneous Dirichlet boundary conditions */ - virtual amrex::Real BoundaryOffset() override final { return m_mg->m_boundary_condition_offset; } - virtual amrex::Real BoundaryFactor() override final { return m_mg->m_boundary_condition_factor; } + amrex::Real BoundaryOffset() final { return m_mg->m_boundary_condition_offset; } + amrex::Real BoundaryFactor() final { return m_mg->m_boundary_condition_factor; } private: amrex::Real m_MG_tolerance_rel = 1.e-4; diff --git a/src/fields/fft_poisson_solver/fft/AnyFFT.H b/src/fields/fft_poisson_solver/fft/AnyFFT.H index 3438f01c76..f8caa34e5c 100644 --- a/src/fields/fft_poisson_solver/fft/AnyFFT.H +++ b/src/fields/fft_poisson_solver/fft/AnyFFT.H @@ -19,7 +19,7 @@ struct VendorPlan; -enum struct FFTType { +enum struct FFTType : int { C2C_2D_fwd, C2C_2D_bkw, C2R_2D, @@ -59,6 +59,12 @@ struct AnyFFT { /** \brief Destructor to destroy the FFT plan */ ~AnyFFT (); + AnyFFT () = default; + AnyFFT (const AnyFFT& rhs) = delete; + AnyFFT (AnyFFT&& rhs) = delete; + AnyFFT& operator= (const AnyFFT& rhs) = delete; + AnyFFT& operator= (AnyFFT&& rhs) = delete; + /** \brief Setup function that has to be called before any FFT plan is initialized. */ static void setup (); diff --git a/src/laser/Laser.cpp b/src/laser/Laser.cpp index 98e8f6d7eb..ea4ceb472e 100644 --- a/src/laser/Laser.cpp +++ b/src/laser/Laser.cpp @@ -19,10 +19,7 @@ #include #endif -Laser::Laser (std::string name) -{ - m_name = name; -} +Laser::Laser (std::string name) : m_name{std::move(name)} {} void Laser::ReadParameters (const amrex::Geometry& laser_geom_3D) @@ -153,8 +150,8 @@ Laser::GetEnvelopeFromFile (amrex::Geometry laser_geom_3D) { } if (mesh.containsAttribute("angularFrequency")) { - m_init_lambda0 = 2.*MathConst::pi*PhysConstSI::c - / mesh.getAttribute("angularFrequency").get(); + m_init_lambda0 = amrex::Real(2.*MathConst::pi*PhysConstSI::c + / mesh.getAttribute("angularFrequency").get()); } AMREX_ALWAYS_ASSERT_WITH_MESSAGE( @@ -198,7 +195,7 @@ Laser::GetEnvelopeFromFile (amrex::Geometry laser_geom_3D) { amrex::Abort("Incorrect axis labels in laser file, must be either tyx, zyx or tr"); } - const int ndim = m_file_geometry.size(); + const int ndim = static_cast(m_file_geometry.size()); for (int i=0; i>; diff --git a/src/laser/MultiLaser.cpp b/src/laser/MultiLaser.cpp index ce35194e59..811d52ec37 100644 --- a/src/laser/MultiLaser.cpp +++ b/src/laser/MultiLaser.cpp @@ -78,6 +78,7 @@ MultiLaser::ReadParameters () void MultiLaser::MakeLaserGeometry (const amrex::Geometry& field_geom_3D) { + using namespace amrex::literals; if (!m_use_laser) return; amrex::ParmParse pp("lasers"); @@ -109,8 +110,8 @@ MultiLaser::MakeLaserGeometry (const amrex::Geometry& field_geom_3D) int(amrex::Math::round((patch_hi_laser[2] - pos_offset_z) * field_geom_3D.InvCellSize(2))) ); - patch_lo_laser[2] = (zeta_lo-0.5)*field_geom_3D.CellSize(2) + pos_offset_z; - patch_hi_laser[2] = (zeta_hi+0.5)*field_geom_3D.CellSize(2) + pos_offset_z; + patch_lo_laser[2] = (amrex::Real(zeta_lo) - 0.5_rt) * field_geom_3D.CellSize(2) + pos_offset_z; + patch_hi_laser[2] = (amrex::Real(zeta_hi) + 0.5_rt) * field_geom_3D.CellSize(2) + pos_offset_z; // make the boxes const amrex::Box domain_3D_laser{amrex::IntVect(0, 0, zeta_lo), @@ -122,7 +123,7 @@ MultiLaser::MakeLaserGeometry (const amrex::Geometry& field_geom_3D) // make the geometry, slice box and ba and dm m_laser_geom_3D.define(domain_3D_laser, real_box, amrex::CoordSys::cartesian, {0, 0, 0}); - m_nlasers = m_names.size(); + m_nlasers = static_cast(m_names.size()); for (int i = 0; i < m_nlasers; ++i) { m_all_lasers.emplace_back(Laser(m_names[i])); @@ -297,8 +298,8 @@ MultiLaser::UpdateLaserAabs (const int islice, const int current_N_level, Fields [=] AMREX_GPU_DEVICE(int i, int j, int, auto interp_order) noexcept { using namespace WhichLaserSlice; - const amrex::Real x = i * dx_field + poff_field_x; - const amrex::Real y = j * dy_field + poff_field_y; + const amrex::Real x = amrex::Real(i) * dx_field + poff_field_x; + const amrex::Real y = amrex::Real(j) * dy_field + poff_field_y; const amrex::Real xmid = (x - poff_laser_x) * dx_laser_inv; const amrex::Real ymid = (y - poff_laser_y) * dy_laser_inv; @@ -352,7 +353,7 @@ MultiLaser::SetInitialChi (const MultiPlasma& multi_plasma) const amrex::Real c_t = pc.c * Hipace::m_physical_time; amrex::Real chi_factor = plasma.GetCharge() * plasma.GetCharge() * pc.mu0 / plasma.GetMass(); if (plasma.m_can_ionize) { - chi_factor *= plasma.m_init_ion_lev * plasma.m_init_ion_lev; + chi_factor *= amrex::Real(plasma.m_init_ion_lev * plasma.m_init_ion_lev); } auto density_func = plasma.m_density_func; @@ -365,8 +366,8 @@ MultiLaser::SetInitialChi (const MultiPlasma& multi_plasma) amrex::ParallelFor(to2D(mfi.growntilebox()), [=] AMREX_GPU_DEVICE(int i, int j) noexcept { - const amrex::Real x = i * dx_laser + poff_laser_x; - const amrex::Real y = j * dy_laser + poff_laser_y; + const amrex::Real x = amrex::Real(i) * dx_laser + poff_laser_x; + const amrex::Real y = amrex::Real(j) * dy_laser + poff_laser_y; laser_arr_chi(i, j) += density_func(x, y, c_t) * chi_factor; }); @@ -403,10 +404,10 @@ MultiLaser::InterpolateChi (const Fields& fields, amrex::Geometry const& geom_fi // chi near the boundaries is incorrect due to >0 deposition order. field_box.grow(-2*Fields::m_slices_nguards); - const amrex::Real pos_x_lo = field_box.smallEnd(0) * dx_field + poff_field_x; - const amrex::Real pos_x_hi = field_box.bigEnd(0) * dx_field + poff_field_x; - const amrex::Real pos_y_lo = field_box.smallEnd(1) * dy_field + poff_field_y; - const amrex::Real pos_y_hi = field_box.bigEnd(1) * dy_field + poff_field_y; + const amrex::Real pos_x_lo = amrex::Real(field_box.smallEnd(0)) * dx_field + poff_field_x; + const amrex::Real pos_x_hi = amrex::Real(field_box.bigEnd(0)) * dx_field + poff_field_x; + const amrex::Real pos_y_lo = amrex::Real(field_box.smallEnd(1)) * dy_field + poff_field_y; + const amrex::Real pos_y_hi = amrex::Real(field_box.bigEnd(1)) * dy_field + poff_field_y; // the indexes of the laser box where the fields box ends const int x_lo = amrex::Math::ceil((pos_x_lo - poff_laser_x) * dx_laser_inv); @@ -419,8 +420,8 @@ MultiLaser::InterpolateChi (const Fields& fields, amrex::Geometry const& geom_fi {m_interp_order}, mfi.growntilebox(), [=] AMREX_GPU_DEVICE(int i, int j, int, auto interp_order) noexcept { - const amrex::Real x = i * dx_laser + poff_laser_x; - const amrex::Real y = j * dy_laser + poff_laser_y; + const amrex::Real x = amrex::Real(i) * dx_laser + poff_laser_x; + const amrex::Real y = amrex::Real(j) * dy_laser + poff_laser_y; const amrex::Real xmid = (x - poff_field_x) * dx_field_inv; const amrex::Real ymid = (y - poff_field_y) * dy_field_inv; @@ -485,7 +486,7 @@ MultiLaser::AdvanceSliceMG (amrex::Real dt, bool non_centered_push) const PhysConst phc = get_phys_const(); const amrex::Real c = phc.c; - const amrex::Real k0 = 2.*MathConst::pi/m_lambda0; + const amrex::Real k0 = 2._rt * MathConst::pi/m_lambda0; const bool do_avg_rhs = m_MG_average_rhs; amrex::Real acoeff_real_scalar = 0._rt; @@ -665,7 +666,7 @@ MultiLaser::AdvanceSliceFFT (const amrex::Real dt, bool non_centered_push) const PhysConst phc = get_phys_const(); const amrex::Real c = phc.c; - const amrex::Real k0 = 2.*MathConst::pi/m_lambda0; + const amrex::Real k0 = 2._rt * MathConst::pi/m_lambda0; for ( amrex::MFIter mfi(m_slices, DfltMfi); mfi.isValid(); ++mfi ){ const amrex::Box& bx = mfi.tilebox(); @@ -803,8 +804,8 @@ MultiLaser::AdvanceSliceFFT (const amrex::Real dt, bool non_centered_push) m_forward_fft.Execute(); // Multiply by appropriate factors in Fourier space - amrex::Real dkx = 2.*MathConst::pi/m_laser_geom_3D.ProbLength(0); - amrex::Real dky = 2.*MathConst::pi/m_laser_geom_3D.ProbLength(1); + amrex::Real dkx = 2._rt * MathConst::pi/m_laser_geom_3D.ProbLength(0); + amrex::Real dky = 2._rt * MathConst::pi/m_laser_geom_3D.ProbLength(1); // acoeff_imag is supposed to be a nx*ny array. // For the sake of simplicity, we evaluate it on-axis only. const Complex acoeff = @@ -814,10 +815,10 @@ MultiLaser::AdvanceSliceFFT (const amrex::Real dt, bool non_centered_push) to2D(bx), [=] AMREX_GPU_DEVICE(int i, int j) noexcept { // divide rhs_fourier by -(k^2+a) - amrex::Real kx = (i 0. ? - 1._rt/(kx*kx + ky*ky + acoeff) : 0.; + amrex::Real kx = (i 0._rt ? + 1._rt/(kx*kx + ky*ky + acoeff) : 0._rt; rhs_fourier_arr(i,j) *= -inv_k2a; }); @@ -827,7 +828,7 @@ MultiLaser::AdvanceSliceFFT (const amrex::Real dt, bool non_centered_push) // Normalize and store solution in np1j00[0]. Guard cells are filled with 0s. amrex::Box grown_bx = bx; grown_bx.grow(m_slices_nguards); - const amrex::Real inv_numPts = 1./bx.numPts(); + const amrex::Real inv_numPts = 1._rt / amrex::Real(bx.numPts()); amrex::ParallelFor( to2D(grown_bx), [=] AMREX_GPU_DEVICE(int i, int j) noexcept { @@ -910,9 +911,9 @@ MultiLaser::InitLaserSlice (const int islice, const int comp) amrex::ParallelFor(to2D(bx), [=] AMREX_GPU_DEVICE (int i, int j) { - const amrex::Real x = i * dx_arr[0] + poff_x; - const amrex::Real y = j * dx_arr[1] + poff_y; - const amrex::Real z = islice * dx_arr[2] + poff_z; + const amrex::Real x = amrex::Real(i) * dx_arr[0] + poff_x; + const amrex::Real y = amrex::Real(j) * dx_arr[1] + poff_y; + const amrex::Real z = amrex::Real(islice) * dx_arr[2] + poff_z; const amrex::Real xmid = (x - laser_pos_offset[0]) * laser_dx_inv[0]; const amrex::Real ymid = (y - laser_pos_offset[1]) * laser_dx_inv[1]; @@ -942,9 +943,9 @@ MultiLaser::InitLaserSlice (const int islice, const int comp) amrex::ParallelFor(to2D(bx), [=] AMREX_GPU_DEVICE (int i, int j) { - const amrex::Real x = i * dx_arr[0] + poff_x; - const amrex::Real y = j * dx_arr[1] + poff_y; - const amrex::Real z = islice * dx_arr[2] + poff_z; + const amrex::Real x = amrex::Real(i) * dx_arr[0] + poff_x; + const amrex::Real y = amrex::Real(j) * dx_arr[1] + poff_y; + const amrex::Real z = amrex::Real(islice) * dx_arr[2] + poff_z; const amrex::Real r = std::sqrt(x*x + y*y); const amrex::Real theta = std::atan2(y, x); @@ -964,9 +965,9 @@ MultiLaser::InitLaserSlice (const int islice, const int comp) shape_factor(rmid, ir); val += (shape_r * shape_z) * laser_arr(ii, jj, 0); for (int im=1; im<=laser_bigend[2]/2; im++) { - val += (shape_r * shape_z) * std::cos(im*theta) * + val += (shape_r * shape_z) * std::cos(amrex::Real(im)*theta) * laser_arr(ii, jj, 2*im-1); - val += (shape_r * shape_z) * std::sin(im*theta) * + val += (shape_r * shape_z) * std::sin(amrex::Real(im)*theta) * laser_arr(ii, jj, 2*im); }}} @@ -982,9 +983,9 @@ MultiLaser::InitLaserSlice (const int islice, const int comp) amrex::ParallelFor(to2D(bx), [=] AMREX_GPU_DEVICE (int i, int j) { - const amrex::Real x = i * dx_arr[0] + poff_x; - const amrex::Real y = j * dx_arr[1] + poff_y; - const amrex::Real z = islice * dx_arr[2] + poff_z; + const amrex::Real x = amrex::Real(i) * dx_arr[0] + poff_x; + const amrex::Real y = amrex::Real(j) * dx_arr[1] + poff_y; + const amrex::Real z = amrex::Real(islice) * dx_arr[2] + poff_z; if (ilaser == 0) { arr(i, j, comp) = 0._rt; arr(i, j, comp + 1) = 0._rt; @@ -1011,9 +1012,9 @@ MultiLaser::InitLaserSlice (const int islice, const int comp) amrex::ParallelFor(to2D(bx), [=] AMREX_GPU_DEVICE (int i, int j) { - const amrex::Real x = i * dx_arr[0] + poff_x - x0; - const amrex::Real y = j * dx_arr[1] + poff_y - y0; - const amrex::Real z = islice * dx_arr[2] + poff_z - z0; + const amrex::Real x = amrex::Real(i) * dx_arr[0] + poff_x - x0; + const amrex::Real y = amrex::Real(j) * dx_arr[1] + poff_y - y0; + const amrex::Real z = amrex::Real(islice) * dx_arr[2] + poff_z - z0; // Coordinate rotation in yz plane for a laser propagating at an angle. const amrex::Real yp = std::cos(propagation_angle_yz) * y - std::sin( propagation_angle_yz ) * z; @@ -1072,7 +1073,7 @@ MultiLaser::InSituComputeDiags (int step, int islice, amrex::Real time, bool is_ const amrex::Real dx = m_laser_geom_3D.CellSize(0); const amrex::Real dy = m_laser_geom_3D.CellSize(1); const amrex::Real dz = m_laser_geom_3D.CellSize(2); - const amrex::Real dz2i = 1./(2. * dz); + const amrex::Real dz2i = 1._rt/(2._rt * dz); const amrex::Real dxdydz = dx * dy * dz; const int xmid_lo = m_laser_geom_3D.Domain().smallEnd(0) + (m_laser_geom_3D.Domain().length(0) - 1) / 2; @@ -1101,8 +1102,8 @@ MultiLaser::InSituComputeDiags (int step, int islice, amrex::Real time, bool is_ - abssq(arr(i,j, n00jp2_r), arr(i,j, n00jp2_i)) + abssq(arr(i,j, n00jp1_r), arr(i,j, n00jp1_i)) ) * dz2i; - const amrex::Real x = i * dx + poff_x; - const amrex::Real y = j * dy + poff_y; + const amrex::Real x = amrex::Real(i) * dx + poff_x; + const amrex::Real y = amrex::Real(j) * dy + poff_y; const bool is_on_axis = (i==xmid_lo || i==xmid_hi) && (j==ymid_lo || j==ymid_hi); const Complex aaxis{is_on_axis ? areal : 0._rt, is_on_axis ? aimag : 0._rt}; diff --git a/src/mg_solver/HpMultiGrid.H b/src/mg_solver/HpMultiGrid.H index a387c0cf8e..10fb2b6df8 100644 --- a/src/mg_solver/HpMultiGrid.H +++ b/src/mg_solver/HpMultiGrid.H @@ -50,6 +50,11 @@ public: /** \brief Dtor */ ~MultiGrid (); + MultiGrid (const MultiGrid& rhs) = delete; + MultiGrid (MultiGrid&& rhs) = delete; + MultiGrid& operator= (const MultiGrid& rhs) = delete; + MultiGrid& operator= (MultiGrid&& rhs) = delete; + /** \brief Solve the Type I equation given the initial guess, right hand side, * and the coefficient. * @@ -288,7 +293,7 @@ using amrex::ParallelFor; // amrex::ParallelFor does not do OpenMP. Thus we have hpmg::ParallelFor. template -void ParallelFor (T n, F&& f) noexcept +void ParallelFor (T n, const F& f) noexcept { if (n < 1000) { for (T i = 0; i < n; ++i) { @@ -303,7 +308,7 @@ void ParallelFor (T n, F&& f) noexcept } template -void ParallelFor (amrex::BoxND<2> const& box, F&& f) noexcept +void ParallelFor (amrex::BoxND<2> const& box, const F& f) noexcept { if (box.numPts() < 1000) { const auto lo = amrex::lbound(box); @@ -329,7 +334,7 @@ void ParallelFor (amrex::BoxND<2> const& box, F&& f) noexcept } template -void ParallelFor (amrex::BoxND<2> const& box, int ncomp, F&& f) noexcept +void ParallelFor (amrex::BoxND<2> const& box, int ncomp, const F& f) noexcept { if (box.numPts()*ncomp < 1000) { const auto lo = amrex::lbound(box); diff --git a/src/mg_solver/HpMultiGrid.cpp b/src/mg_solver/HpMultiGrid.cpp index 1eae41b288..d0f1b35fac 100644 --- a/src/mg_solver/HpMultiGrid.cpp +++ b/src/mg_solver/HpMultiGrid.cpp @@ -1464,7 +1464,7 @@ MultiGrid::vcycle () m_rhs.const_array().dataPtr() }; - if (m_cuda_graph_vcycle.count(key) == 0) { + if (!m_cuda_graph_vcycle.contains(key)) { cudaStreamBeginCapture(amrex::Gpu::gpuStream(), cudaStreamCaptureModeGlobal); #endif diff --git a/src/particles/beam/BeamParticleContainer.H b/src/particles/beam/BeamParticleContainer.H index 62b9575ed9..1008911479 100644 --- a/src/particles/beam/BeamParticleContainer.H +++ b/src/particles/beam/BeamParticleContainer.H @@ -23,14 +23,14 @@ class AdaptiveTimeStep; /** \brief Map names and indices for beam particles attributes (SoA data) */ struct BeamIdx { - enum { + enum : int { x=0, y, z, // position w, // weight ux, uy, uz, // momentum real_nattribs_in_buffer, real_nattribs=real_nattribs_in_buffer }; - enum { + enum : int { // no extra components stored in MultiBuffer, besides 64bit idcpu int_nattribs_in_buffer, // nsubcycles: by how many subcycles was this particle pushed already @@ -67,12 +67,12 @@ using BeamTileInit = amrex::ParticleTile< >; /** \brief Container for particles of 1 beam species. */ -class BeamParticleContainer +class BeamParticleContainer // NOLINT(clang-analyzer-optin.performance.Padding) { public: /** Constructor */ explicit BeamParticleContainer (std::string name) : - m_name(name) + m_name(std::move(name)) {} /** Read parameters in the input file */ @@ -101,26 +101,26 @@ public: /** Checks the input file first to determine its Datatype * \return physical time at which the simulation will start */ - amrex::Real InitBeamFromFileHelper (const std::string input_file, + amrex::Real InitBeamFromFileHelper (const std::string& input_file, const bool coordinates_specified, - const amrex::Array file_coordinates_xyz, + const amrex::Array& file_coordinates_xyz, const amrex::Geometry& geom, amrex::Real n_0, const int num_iteration, - const std::string species_name, + const std::string& species_name, const bool species_specified); /** Initialize a beam from an external input file using openPMD and HDF5 * \return physical time at which the simulation will start */ template - amrex::Real InitBeamFromFile (const std::string input_file, + amrex::Real InitBeamFromFile (const std::string& input_file, const bool coordinates_specified, - const amrex::Array file_coordinates_xyz, + const amrex::Array& file_coordinates_xyz, const amrex::Geometry& geom, amrex::Real n_0, const int num_iteration, - const std::string species_name, + const std::string& species_name, const bool species_specified); #endif @@ -294,7 +294,7 @@ private: amrex::Long m_num_particles; /**< Number of particles for fixed-weight Gaussian beam */ amrex::Real m_total_charge; /**< Total beam charge for fixed-weight Gaussian beam */ amrex::Real m_density; /**< Peak density for fixed-weight Gaussian beam */ - bool m_do_symmetrize {0}; /**< Option to symmetrize the beam */ + bool m_do_symmetrize = false; /**< Option to symmetrize the beam */ /** Array for the z position of all beam particles */ amrex::PODVector> m_z_array {}; diff --git a/src/particles/beam/BeamParticleContainer.cpp b/src/particles/beam/BeamParticleContainer.cpp index 7f74fba361..4a15d350d6 100644 --- a/src/particles/beam/BeamParticleContainer.cpp +++ b/src/particles/beam/BeamParticleContainer.cpp @@ -185,7 +185,7 @@ BeamParticleContainer::InitData (const amrex::Geometry& geom) m_total_charge = m_density*m_charge; for (int idim=0; idim(m_init_sorter.m_box_counts_cpu[slice]); resize(which_slice, num_particles, 0); auto ptd_init = getBeamInitSlice().getParticleTileData(); auto ptd = getBeamSlice(which_slice).getParticleTileData(); - const int slice_offset = m_init_sorter.m_box_offsets_cpu[slice]; + const int slice_offset = static_cast(m_init_sorter.m_box_offsets_cpu[slice]); const auto permutations = m_init_sorter.m_box_permutations.dataPtr(); const bool do_spin_tracking = m_do_spin_tracking; amrex::ParallelFor(num_particles, [=] AMREX_GPU_DEVICE (const int ip) { - const int idx_src = permutations[slice_offset + ip]; + const auto idx_src = permutations[slice_offset + ip]; ptd.rdata(BeamIdx::x)[ip] = ptd_init.rdata(BeamIdx::x)[idx_src]; ptd.rdata(BeamIdx::y)[ip] = ptd_init.rdata(BeamIdx::y)[idx_src]; ptd.rdata(BeamIdx::z)[ip] = ptd_init.rdata(BeamIdx::z)[idx_src]; @@ -399,7 +399,7 @@ BeamParticleContainer::initializeSlice (int slice, int which_slice) { ptd.m_runtime_rdata[1][ip] = ptd_init.m_runtime_rdata[1][idx_src]; ptd.m_runtime_rdata[2][ip] = ptd_init.m_runtime_rdata[2][idx_src]; } - ptd.idcpu(ip) = ptd_init.idcpu(idx_src); + ptd.idcpu(ip) = ptd_init.idcpu(static_cast(idx_src)); ptd.idata(BeamIdx::nsubcycles)[ip] = 0; ptd.idata(BeamIdx::mr_level)[ip] = 0; } @@ -422,7 +422,7 @@ BeamParticleContainer::initializeSlice (int slice, int which_slice) { // remove invalid particles so they don't show up in the beam diagnostic of the first time step amrex::removeInvalidParticles(getBeamSlice(which_slice)); - resize(which_slice, getBeamSlice(which_slice).size(), 0); + resize(which_slice, static_cast(getBeamSlice(which_slice).size()), 0); } void diff --git a/src/particles/beam/BeamParticleContainerInit.cpp b/src/particles/beam/BeamParticleContainerInit.cpp index 2b41163f18..40d7cadd4b 100644 --- a/src/particles/beam/BeamParticleContainerInit.cpp +++ b/src/particles/beam/BeamParticleContainerInit.cpp @@ -44,7 +44,7 @@ namespace const amrex::Real& x, const amrex::Real& y, const amrex::Real& z, const amrex::Real& ux, const amrex::Real& uy, const amrex::Real& uz, const amrex::Real& sx, const amrex::Real& sy, const amrex::Real& sz, - const amrex::Real& weight, const amrex::Long pid, const amrex::Long ip, + const amrex::Real& weight, const uint64_t pid, const int ip, const EnforceBC& enforceBC, bool do_spin) noexcept { amrex::Real xp = x; @@ -66,7 +66,7 @@ namespace } ptd.rdata(BeamIdx::w )[ip] = std::abs(weight); - ptd.idcpu(ip) = pid + ip; + ptd.idcpu(ip) = static_cast(pid) + ip; ptd.id(ip).make_valid(); } @@ -89,8 +89,8 @@ namespace void AddOneBeamParticleSlice ( const BeamTile::ParticleTileDataType& ptd, const amrex::Real x, const amrex::Real y, const amrex::Real z, const amrex::Real ux, const amrex::Real uy, - const amrex::Real uz, const amrex::Real weight, const amrex::Long pid, - const amrex::Long ip, const EnforceBC& enforceBC, + const amrex::Real uz, const amrex::Real weight, const uint64_t pid, + const int ip, const EnforceBC& enforceBC, const bool is_valid=true) noexcept { amrex::Real xp = x; @@ -110,7 +110,7 @@ namespace ptd.idata(BeamIdx::nsubcycles)[ip] = 0; ptd.idata(BeamIdx::mr_level)[ip] = 0; - ptd.idcpu(ip) = pid + ip; + ptd.idcpu(ip) = static_cast(pid) + ip; if (is_valid) { ptd.id(ip).make_valid(); // ensure id is valid } else { @@ -160,9 +160,9 @@ InitBeamFixedPPC3D () ParticleUtil::get_position_unit_cell(r, ppc, i_part); - amrex::Real x = plo[0] + (i + r[0])*dx[0]; - amrex::Real y = plo[1] + (j + r[1])*dx[1]; - amrex::Real z = plo[2] + (k + r[2])*dx[2]; + amrex::Real x = plo[0] + (amrex::Real(i) + r[0])*dx[0]; + amrex::Real y = plo[1] + (amrex::Real(j) + r[1])*dx[1]; + amrex::Real z = plo[2] + (amrex::Real(k) + r[2])*dx[2]; if (rand_ppc[0] + rand_ppc[1] + rand_ppc[2] == false ) { // If particles are evenly spaced, discard particles @@ -174,9 +174,9 @@ InitBeamFixedPPC3D () } else { // If particles are randomly spaced, discard particles // if the cell is outside the domain - amrex::Real xc = plo[0]+i*dx[0]; - amrex::Real yc = plo[1]+j*dx[1]; - amrex::Real zc = plo[2]+k*dx[2]; + amrex::Real xc = plo[0] + amrex::Real(i) * dx[0]; + amrex::Real yc = plo[1] + amrex::Real(j) * dx[1]; + amrex::Real zc = plo[2] + amrex::Real(k) * dx[2]; if (zc >= z_max || zc < z_min || ((xc-x_mean)*(xc-x_mean)+(yc-y_mean)*(yc-y_mean)) > radius_sq) { continue; @@ -214,7 +214,7 @@ InitBeamFixedPPCSlice (const int islice, const int which_beam_slice) const int num_ppc = ppc[0] * ppc[1] * ppc[2]; const amrex::Real scale_fac = Hipace::m_normalized_units ? - 1./num_ppc : dx[0]*dx[1]*dx[2]/num_ppc; + amrex::Real(1)/amrex::Real(num_ppc) : dx[0]*dx[1]*dx[2]/amrex::Real(num_ppc); const amrex::Real x_mean = m_position_mean[0]; const amrex::Real y_mean = m_position_mean[1]; @@ -249,9 +249,9 @@ InitBeamFixedPPCSlice (const int islice, const int which_beam_slice) ParticleUtil::get_position_unit_cell(r, ppc, i_part, engine, rand_ppc); - amrex::Real x = plo[0] + (i + r[0])*dx[0]; - amrex::Real y = plo[1] + (j + r[1])*dx[1]; - amrex::Real z = plo[2] + (islice + r[2])*dx[2]; + amrex::Real x = plo[0] + (amrex::Real(i) + r[0]) * dx[0]; + amrex::Real y = plo[1] + (amrex::Real(j) + r[1]) * dx[1]; + amrex::Real z = plo[2] + (amrex::Real(islice) + r[2]) * dx[2]; if (rand_ppc[0] + rand_ppc[1] + rand_ppc[2] == false ) { // If particles are evenly spaced, discard particles @@ -263,9 +263,9 @@ InitBeamFixedPPCSlice (const int islice, const int which_beam_slice) } else { // If particles are randomly spaced, discard particles // if the cell is outside the domain - amrex::Real xc = plo[0]+i*dx[0]; - amrex::Real yc = plo[1]+j*dx[1]; - amrex::Real zc = plo[2]+islice*dx[2]; + amrex::Real xc = plo[0] + amrex::Real(i) * dx[0]; + amrex::Real yc = plo[1] + amrex::Real(j) * dx[1]; + amrex::Real zc = plo[2] + amrex::Real(islice) * dx[2]; if (zc >= z_max || zc < z_min || ((xc-x_mean)*(xc-x_mean)+(yc-y_mean)*(yc-y_mean)) > radius_sq) { continue; @@ -306,9 +306,9 @@ InitBeamFixedPPCSlice (const int islice, const int which_beam_slice) ParticleUtil::get_position_unit_cell(r, ppc, i_part, engine, rand_ppc); - amrex::Real x = plo[0] + (i + r[0])*dx[0]; - amrex::Real y = plo[1] + (j + r[1])*dx[1]; - amrex::Real z = plo[2] + (islice + r[2])*dx[2]; + amrex::Real x = plo[0] + (amrex::Real(i) + r[0]) * dx[0]; + amrex::Real y = plo[1] + (amrex::Real(j) + r[1]) * dx[1]; + amrex::Real z = plo[2] + (amrex::Real(islice) + r[2]) * dx[2]; if (rand_ppc[0] + rand_ppc[1] + rand_ppc[2] == false) { // If particles are evenly spaced, discard particles @@ -320,9 +320,9 @@ InitBeamFixedPPCSlice (const int islice, const int which_beam_slice) } else { // If particles are randomly spaced, discard particles // if the cell is outside the domain - amrex::Real xc = plo[0]+i*dx[0]; - amrex::Real yc = plo[1]+j*dx[1]; - amrex::Real zc = plo[2]+islice*dx[2]; + amrex::Real xc = plo[0] + amrex::Real(i) * dx[0]; + amrex::Real yc = plo[1] + amrex::Real(j) * dx[1]; + amrex::Real zc = plo[2] + amrex::Real(islice) * dx[2]; if (zc >= z_max || zc < z_min || ((xc-x_mean)*(xc-x_mean)+(yc-y_mean)*(yc-y_mean)) > radius_sq) { continue; @@ -388,7 +388,7 @@ InitBeamFixedWeightSlice (int slice, int which_slice) if (!Hipace::HeadRank() || m_num_particles == 0) { return; } - const int num_to_add = m_init_sorter.m_box_counts_cpu[slice]; + const int num_to_add = static_cast(m_init_sorter.m_box_counts_cpu[slice]); if (m_do_symmetrize) { resize(which_slice, 4*num_to_add, 0); } else { @@ -402,7 +402,7 @@ InitBeamFixedWeightSlice (int slice, int which_slice) // Access particles' SoA const auto ptd = particle_tile.getParticleTileData(); - const amrex::Long slice_offset = m_init_sorter.m_box_offsets_cpu[slice]; + const auto slice_offset = m_init_sorter.m_box_offsets_cpu[slice]; const auto permutations = m_init_sorter.m_box_permutations.dataPtr(); amrex::Real * const pos_z = m_z_array.dataPtr(); @@ -421,13 +421,13 @@ InitBeamFixedWeightSlice (int slice, int which_slice) std::numeric_limits::max() : m_radius * m_radius; auto pos_mean_x = m_pos_mean_x_func; auto pos_mean_y = m_pos_mean_y_func; - const amrex::Real weight = m_total_charge / (m_num_particles * m_charge); + const amrex::Real weight = m_total_charge / (amrex::Real(m_num_particles) * m_charge); const GetInitialMomentum get_momentum = m_get_momentum; const auto enforceBC = EnforceBC(); amrex::ParallelForRNG( num_to_add, - [=] AMREX_GPU_DEVICE (amrex::Long i, const amrex::RandomEngine& engine) noexcept + [=] AMREX_GPU_DEVICE (int i, const amrex::RandomEngine& engine) noexcept { const amrex::Real z_central = pos_z[permutations[slice_offset + i]]; amrex::Real x = amrex::RandomNormal(0, pos_std[0], engine); @@ -491,7 +491,7 @@ InitBeamFixedWeightPDF3D () m_num_particles_slice.resize(domain.length(2) * m_pdf_ref_ratio); const amrex::Real zoffset = geom.ProbLo(2); - const amrex::Real zscale = geom.CellSize(2) / m_pdf_ref_ratio; + const amrex::Real zscale = geom.CellSize(2) / amrex::Real(m_pdf_ref_ratio); amrex::Real integral = 0._rt; amrex::Real max_density = 0._rt; @@ -499,9 +499,9 @@ InitBeamFixedWeightPDF3D () amrex::Real avg_uz_sq = 0._rt; for (int slice=domain.length(2)*m_pdf_ref_ratio-1; slice>=0; --slice) { - const amrex::Real zmin = zoffset + slice*zscale; - const amrex::Real zmax = zoffset + (slice+1)*zscale; - const amrex::Real zmid = 0.5_rt*(zmin + zmax); + const amrex::Real zmin = zoffset + amrex::Real(slice) * zscale; + const amrex::Real zmax = zoffset + amrex::Real(slice+1) * zscale; + const amrex::Real zmid = 0.5_rt * (zmin + zmax); const amrex::Real pdf_zmin = m_pdf_func(zmin); const amrex::Real pdf_zmax = m_pdf_func(zmax); @@ -551,14 +551,14 @@ InitBeamFixedWeightPDF3D () const amrex::Long num_to_add_now = num_to_add - num_added; for (int slice=domain.length(2)*m_pdf_ref_ratio-1; slice >=0; --slice) { - const amrex::Real zmin = zoffset + slice*zscale; - const amrex::Real zmax = zoffset + (slice+1)*zscale; + const amrex::Real zmin = zoffset + amrex::Real(slice) * zscale; + const amrex::Real zmax = zoffset + amrex::Real(slice+1) * zscale; const amrex::Real pdf_zmin = m_pdf_func(zmin); const amrex::Real pdf_zmax = m_pdf_func(zmax); const amrex::Real local_weight = 0.5_rt*(pdf_zmin+pdf_zmax); - const amrex::Real mean_particles = num_to_add_now*local_weight/integral; + const amrex::Real mean_particles = amrex::Real(num_to_add_now)*local_weight/integral; if (mean_particles >= 0) { // use a Poisson distribution to mimic how many independent particles would be @@ -587,9 +587,9 @@ InitBeamFixedWeightPDFSlice (int slice, int which_slice) if (!Hipace::HeadRank() || m_num_particles == 0) { return; } - unsigned int num_to_add_full = 0; + int num_to_add_full = 0; for (int r=m_pdf_ref_ratio-1; r>=0; --r) { - num_to_add_full += m_num_particles_slice[slice*m_pdf_ref_ratio+r]; + num_to_add_full += static_cast(m_num_particles_slice[slice*m_pdf_ref_ratio+r]); } if (m_do_symmetrize) { resize(which_slice, 4*num_to_add_full, 0); @@ -600,9 +600,9 @@ InitBeamFixedWeightPDFSlice (int slice, int which_slice) const uint64_t pid = m_id64; m_id64 += m_do_symmetrize ? 4*num_to_add_full : num_to_add_full; - unsigned int loc_index = 0; + int loc_index = 0; for (int r=m_pdf_ref_ratio-1; r>=0; --r) { - const unsigned int num_to_add = m_num_particles_slice[slice*m_pdf_ref_ratio+r]; + const int num_to_add = static_cast(m_num_particles_slice[slice*m_pdf_ref_ratio+r]); if (num_to_add == 0) continue; auto& particle_tile = getBeamSlice(which_slice); @@ -614,13 +614,13 @@ InitBeamFixedWeightPDFSlice (int slice, int which_slice) const amrex::Real z_foc = m_z_foc; const amrex::Real radius_sq = m_radius == std::numeric_limits::max() ? std::numeric_limits::max() : m_radius * m_radius; - const amrex::Real weight = m_total_weight / m_num_particles; + const amrex::Real weight = m_total_weight / amrex::Real(m_num_particles); const auto pos_func = m_pdf_pos_func; const auto u_func = m_pdf_u_func; const amrex::Geometry& geom = Hipace::GetInstance().m_3D_geom[0]; - const amrex::Real dz = geom.CellSize(2) / m_pdf_ref_ratio; - const amrex::Real zmin = geom.ProbLo(2) + (slice*m_pdf_ref_ratio+r)*dz; - const amrex::Real zmax = geom.ProbLo(2) + (slice*m_pdf_ref_ratio+r+1)*dz; + const amrex::Real dz = geom.CellSize(2) / amrex::Real(m_pdf_ref_ratio); + const amrex::Real zmin = geom.ProbLo(2) + amrex::Real(slice*m_pdf_ref_ratio+r)*dz; + const amrex::Real zmax = geom.ProbLo(2) + amrex::Real(slice*m_pdf_ref_ratio+r+1)*dz; const amrex::Real lo_weight = m_pdf_func(zmin); const amrex::Real hi_weight = m_pdf_func(zmax); AMREX_ALWAYS_ASSERT(lo_weight + hi_weight > 0._rt); @@ -634,7 +634,7 @@ InitBeamFixedWeightPDFSlice (int slice, int which_slice) amrex::ParallelForRNG( num_to_add, - [=] AMREX_GPU_DEVICE (unsigned int i, const amrex::RandomEngine& engine) noexcept + [=] AMREX_GPU_DEVICE (int i, const amrex::RandomEngine& engine) noexcept { // if m_pdf_ref_ratio is greater than one, a single slice of beam particles // needs to be initialized by multiple kernels so we need to keep track of the @@ -750,14 +750,14 @@ InitBeamFromList3D () const uint64_t pid = m_id64; m_id64 += m_num_particles_list; - amrex::ParallelFor(amrex::Long(m_num_particles_list), - [=] AMREX_GPU_DEVICE (const amrex::Long i) { + amrex::ParallelFor(static_cast(m_num_particles_list), + [=] AMREX_GPU_DEVICE (int i) { AddOneBeamParticle(ptd, p_x[i], p_y[i], p_z[i], p_ux[i], p_uy[i], p_uz[i], - do_spin_tracking ? p_sx[i] : 0., - do_spin_tracking ? p_sy[i] : 0., - do_spin_tracking ? p_sz[i] : 0., + do_spin_tracking ? p_sx[i] : amrex::Real(0), + do_spin_tracking ? p_sy[i] : amrex::Real(0), + do_spin_tracking ? p_sz[i] : amrex::Real(0), p_w[i], pid, i, enforceBC, do_spin_tracking); }); @@ -768,13 +768,13 @@ InitBeamFromList3D () #ifdef HIPACE_USE_OPENPMD amrex::Real BeamParticleContainer:: -InitBeamFromFileHelper (const std::string input_file, +InitBeamFromFileHelper (const std::string& input_file, const bool coordinates_specified, - const amrex::Array file_coordinates_xyz, + const amrex::Array& file_coordinates_xyz, const amrex::Geometry& geom, amrex::Real n_0, const int num_iteration, - const std::string species_name, + const std::string& species_name, const bool species_specified) { HIPACE_PROFILE("BeamParticleContainer::InitParticles()"); @@ -837,13 +837,13 @@ InitBeamFromFileHelper (const std::string input_file, template amrex::Real BeamParticleContainer:: -InitBeamFromFile (const std::string input_file, +InitBeamFromFile (const std::string& input_file, const bool coordinates_specified, - const amrex::Array file_coordinates_xyz, + const amrex::Array& file_coordinates_xyz, const amrex::Geometry& geom, amrex::Real n_0, const int num_iteration, - const std::string species_name, + const std::string& species_name, const bool species_specified) { HIPACE_PROFILE("BeamParticleContainer::InitParticles()"); @@ -1031,25 +1031,25 @@ InitBeamFromFile (const std::string input_file, amrex::Abort("Coud not find z coordinate in file. Use file_coordinates_xyz x1 x2 x3\n"); } - for(std::string name_r_c : {name_rx, name_ry, name_rz}) { + for(const std::string& name_r_c : {name_rx, name_ry, name_rz}) { if(!series.iterations[num_iteration].particles[name_particle][name_r].contains(name_r_c)) { - amrex::Abort("Beam input file does not contain " + name_r_c + " coordinate in " + - name_r + " (position)\n"); + amrex::Abort("Beam input file does not contain " + name_r_c + " coordinate in " + + name_r + " (position)\n"); } } - for(std::string name_u_c : {name_ux, name_uy, name_uz}) { + for(const std::string& name_u_c : {name_ux, name_uy, name_uz}) { if(!series.iterations[num_iteration].particles[name_particle][name_u].contains(name_u_c)) { - amrex::Abort("Beam input file does not contain " + name_u_c + " coordinate in " + - name_u + " (momentum)\n"); + amrex::Abort("Beam input file does not contain " + name_u_c + " coordinate in " + + name_u + " (momentum)\n"); } } if (m_do_spin_tracking) { - for(std::string name_s_c : {name_sx, name_sy, name_sz}) { + for(const std::string& name_s_c : {name_sx, name_sy, name_sz}) { if(!series.iterations[num_iteration].particles[name_particle][name_s].contains(name_s_c)) { - amrex::Abort("Beam input file does not contain " + name_s_c + " coordinate in " + - name_s + " (spin). An attempt to read these was done because " + - "do_spin_tracking is on for at least one beam.\n"); + amrex::Abort("Beam input file does not contain " + name_s_c + " coordinate in " + + name_s + " (spin). An attempt to read these was done because " + + "do_spin_tracking is on for at least one beam.\n"); } } } @@ -1072,7 +1072,7 @@ InitBeamFromFile (const std::string input_file, const auto num_to_add = electrons[name_r][name_rx].getExtent()[0]; - if(num_to_add >= 2147483647) { + if (num_to_add >= 2147483647) { amrex::Abort("Beam from file can't have more than 2'147'483'646 Particles\n"); } @@ -1122,7 +1122,7 @@ InitBeamFromFile (const std::string input_file, if(Hipace::m_normalized_units) { if(n_0 == 0) { if(electrons.containsAttribute("HiPACE++_Plasma_Density")) { - n_0 = electrons.getAttribute("HiPACE++_Plasma_Density").get(); + n_0 = amrex::Real(electrons.getAttribute("HiPACE++_Plasma_Density").get()); } else { amrex::Abort("Please specify the plasma density of the external beam " @@ -1202,7 +1202,7 @@ InitBeamFromFile (const std::string input_file, do_spin_tracking ? static_cast(s_y_ptr[i]) : 0., do_spin_tracking ? static_cast(s_z_ptr[i]) : 0., static_cast(w_w_ptr[i] * unit_ww), - pid, i, enforceBC, do_spin_tracking); + pid, static_cast(i), enforceBC, do_spin_tracking); }); amrex::Gpu::streamSynchronize(); diff --git a/src/particles/beam/MultiBeam.cpp b/src/particles/beam/MultiBeam.cpp index ed1b3f0345..860a839628 100644 --- a/src/particles/beam/MultiBeam.cpp +++ b/src/particles/beam/MultiBeam.cpp @@ -22,7 +22,7 @@ MultiBeam::ReadParameters () DeprecatedInput("beams", "insitu_freq", "insitu_period"); DeprecatedInput("beams", "all_from_file", "injection_type = from_file\nand beams.input_file = \n"); - m_nbeams = m_names.size(); + m_nbeams = static_cast(m_names.size()); for (int i = 0; i < m_nbeams; ++i) { m_all_beams.emplace_back(BeamParticleContainer(m_names[i])); m_all_beams.back().ReadParameters(); diff --git a/src/particles/collisions/CoulombCollision.H b/src/particles/collisions/CoulombCollision.H index 4d201e3a88..f54ec19d01 100644 --- a/src/particles/collisions/CoulombCollision.H +++ b/src/particles/collisions/CoulombCollision.H @@ -25,7 +25,7 @@ public: void ReadParameters ( const std::vector& plasma_species_names, const std::vector& beam_species_names, - std::string const collision_name); + std::string const& collision_name); /** * \brief Perform Coulomb collisions of plasma species over longitudinal push by 1 cell. diff --git a/src/particles/collisions/CoulombCollision.cpp b/src/particles/collisions/CoulombCollision.cpp index b688f39285..432af3624f 100644 --- a/src/particles/collisions/CoulombCollision.cpp +++ b/src/particles/collisions/CoulombCollision.cpp @@ -9,7 +9,7 @@ void CoulombCollision::ReadParameters( const std::vector& plasma_species_names, const std::vector& beam_species_names, - std::string const collision_name) + std::string const& collision_name) { using namespace amrex::literals; @@ -26,9 +26,9 @@ CoulombCollision::ReadParameters( // default Coulomb log is -1, if < 0 (e.g. not specified), will be computed automatically pp.query("CoulombLog", m_CoulombLog); - for (int i=0; i<(int) beam_species_names.size(); i++) { - if (beam_species_names[i] == collision_species[0]) m_nbeams += 1; - if (beam_species_names[i] == collision_species[1]) m_nbeams += 1; + for (auto& beamname : beam_species_names) { + if (beamname == collision_species[0]) m_nbeams += 1; + if (beamname == collision_species[1]) m_nbeams += 1; AMREX_ALWAYS_ASSERT_WITH_MESSAGE( m_nbeams <= 1, ".species must contain at maximum one beam species name!"); @@ -81,7 +81,7 @@ CoulombCollision::doPlasmaPlasmaCoulombCollision ( { // Logically particles per-cell, and return indices of particles in each cell PlasmaBins bins1 = findParticlesInEachTile(bx, 1, species1, geom); - int const n_cells = bins1.numBins(); + int const n_cells = static_cast(bins1.numBins()); // Counter to check there is only 1 box int count = 0; @@ -103,9 +103,10 @@ CoulombCollision::doPlasmaPlasmaCoulombCollision ( // volume is used to calculate density, but weights already represent density in normalized units const amrex::Real inv_dV = geom.InvCellSize(0)*geom.InvCellSize(1)*geom.InvCellSize(2); // static_cast to avoid precision problems in FP32 - const amrex::Real wp = std::sqrt(static_cast(background_density_SI) * - PhysConstSI::q_e*PhysConstSI::q_e / - (PhysConstSI::ep0*PhysConstSI::m_e)); + const amrex::Real wp = amrex::Real( + std::sqrt(static_cast(background_density_SI) * + PhysConstSI::q_e*PhysConstSI::q_e / + (PhysConstSI::ep0*PhysConstSI::m_e))); const amrex::Real dt = normalized_units ? geom.CellSize(2)/wp : geom.CellSize(2)/PhysConstSI::c; @@ -147,7 +148,7 @@ CoulombCollision::doPlasmaPlasmaCoulombCollision ( PlasmaBins bins1 = findParticlesInEachTile(bx, 1, species1, geom); PlasmaBins bins2 = findParticlesInEachTile(bx, 1, species2, geom); - int const n_cells = bins1.numBins(); + int const n_cells = static_cast(bins1.numBins()); // Counter to check there is only 1 box int count = 0; @@ -183,9 +184,10 @@ CoulombCollision::doPlasmaPlasmaCoulombCollision ( // volume is used to calculate density, but weights already represent density in normalized units const amrex::Real inv_dV = geom.InvCellSize(0)*geom.InvCellSize(1)*geom.InvCellSize(2); // static_cast to avoid precision problems in FP32 - const amrex::Real wp = std::sqrt(static_cast(background_density_SI) * - PhysConstSI::q_e*PhysConstSI::q_e / - (PhysConstSI::ep0*PhysConstSI::m_e)); + const amrex::Real wp = amrex::Real( + std::sqrt(static_cast(background_density_SI) * + PhysConstSI::q_e*PhysConstSI::q_e / + (PhysConstSI::ep0*PhysConstSI::m_e))); const amrex::Real dt = normalized_units ? geom.CellSize(2)/wp : geom.CellSize(2)/PhysConstSI::c; // Extract particles in the tile that `mfi` points to @@ -258,7 +260,7 @@ CoulombCollision::doBeamPlasmaCoulombCollision ( BeamBins bins1 = findBeamParticlesInEachTile(bx, 1, species1, geom); PlasmaBins bins2 = findParticlesInEachTile(bx, 1, species2, geom); - int const n_cells = bins2.numBins(); + int const n_cells = static_cast(bins2.numBins()); // Counter to check there is only 1 box int count = 0; @@ -293,9 +295,10 @@ CoulombCollision::doBeamPlasmaCoulombCollision ( // volume is used to calculate density, but weights already represent density in normalized units const amrex::Real inv_dV = geom.InvCellSize(0)*geom.InvCellSize(1)*geom.InvCellSize(2); // static_cast to avoid precision problems in FP32 - const amrex::Real wp = std::sqrt(static_cast(background_density_SI) * - PhysConstSI::q_e*PhysConstSI::q_e / - (PhysConstSI::ep0*PhysConstSI::m_e)); + const amrex::Real wp = amrex::Real( + std::sqrt(static_cast(background_density_SI) * + PhysConstSI::q_e*PhysConstSI::q_e / + (PhysConstSI::ep0*PhysConstSI::m_e))); const amrex::Real dt = normalized_units ? Hipace::GetInstance().m_dt/wp : Hipace::GetInstance().m_dt; diff --git a/src/particles/deposition/DepositionUtil.H b/src/particles/deposition/DepositionUtil.H index 4aac1861f4..2210f73374 100644 --- a/src/particles/deposition/DepositionUtil.H +++ b/src/particles/deposition/DepositionUtil.H @@ -43,7 +43,7 @@ template field, amrex::Box box, const PTD& ptd, amrex::GpuArray idx_cache, amrex::GpuArray idx_depos) { diff --git a/src/particles/deposition/TemperatureDeposition.cpp b/src/particles/deposition/TemperatureDeposition.cpp index 603c21f82e..c053752279 100644 --- a/src/particles/deposition/TemperatureDeposition.cpp +++ b/src/particles/deposition/TemperatureDeposition.cpp @@ -136,8 +136,8 @@ DepositTemperature (PlasmaParticleContainer& plasma, if (use_laser) { amrex::Real laser_norm_ion = laser_norm; if (can_ionize) { - laser_norm_ion *= - ptd.idata(PlasmaIdx::ion_lev)[ip] * ptd.idata(PlasmaIdx::ion_lev)[ip]; + const amrex::Real ilev = amrex::Real(ptd.idata(PlasmaIdx::ion_lev)[ip]); + laser_norm_ion *= ilev * ilev; } doLaserGatherShapeN<2>(xp, yp, Aabssqp, arr, cache_idx[0], dx_inv, dy_inv, x_pos_offset, y_pos_offset); diff --git a/src/particles/particles_utils/ParticleUtil.H b/src/particles/particles_utils/ParticleUtil.H index 9cfce2aac1..1acbf56162 100644 --- a/src/particles/particles_utils/ParticleUtil.H +++ b/src/particles/particles_utils/ParticleUtil.H @@ -41,9 +41,9 @@ namespace ParticleUtil int iy_part = (i_part % (ny * nz)) % ny; int iz_part = (i_part % (ny * nz)) / ny; - r[0] = rand[0] ? amrex::Random(engine) : (0.5_rt + ix_part)/nx; - r[1] = rand[1] ? amrex::Random(engine) : (0.5_rt + iy_part)/ny; - r[2] = rand[2] ? amrex::Random(engine) : (0.5_rt + iz_part)/nz; + r[0] = rand[0] ? amrex::Random(engine) : (0.5_rt + amrex::Real(ix_part))/amrex::Real(nx); + r[1] = rand[1] ? amrex::Random(engine) : (0.5_rt + amrex::Real(iy_part))/amrex::Real(ny); + r[2] = rand[2] ? amrex::Random(engine) : (0.5_rt + amrex::Real(iz_part))/amrex::Real(nz); } AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE @@ -57,9 +57,9 @@ namespace ParticleUtil int iy_part = (i_part % (ny * nz)) % ny; int iz_part = (i_part % (ny * nz)) / ny; - r[0] = (0.5_rt + ix_part)/nx; - r[1] = (0.5_rt + iy_part)/ny; - r[2] = (0.5_rt + iz_part)/nz; + r[0] = (0.5_rt + amrex::Real(ix_part))/amrex::Real(nx); + r[1] = (0.5_rt + amrex::Real(iy_part))/amrex::Real(ny); + r[2] = (0.5_rt + amrex::Real(iz_part))/amrex::Real(nz); } template @@ -78,8 +78,8 @@ namespace ParticleUtil do_init = true; int ix_part = i_part % nx; int iy_part = i_part / nx; - r[0] = (0.5_rt + ix_part)/nx; - r[1] = (0.5_rt + iy_part)/ny; + r[0] = (0.5_rt + static_cast(ix_part))/amrex::Real(nx); + r[1] = (0.5_rt + static_cast(iy_part))/amrex::Real(ny); } else { do_init = false; } @@ -102,13 +102,15 @@ namespace ParticleUtil amrex::Real s = amrex::Real(i_fine_transition_cells - lev * (n_fine_transition_cells + 1)) - / (n_fine_transition_cells + 1); + / amrex::Real(n_fine_transition_cells + 1); s = 1.5_rt*s - 0.5_rt*s*s*s; - r[0] = ((0.5_rt + ix_part_coarse) / nx_coarse) * (1._rt - s) + - ((0.5_rt + ix_part_fine) / nx_fine) * s; - r[1] = ((0.5_rt + iy_part_coarse) / ny_coarse) * (1._rt - s) + - ((0.5_rt + iy_part_fine) / ny_fine) * s; + r[0] = ((1._rt - s) * + (0.5_rt + amrex::Real(ix_part_coarse)) / amrex::Real(nx_coarse)) + + s * ((0.5_rt + amrex::Real(ix_part_fine)) / amrex::Real(nx_fine)); + r[1] = ((1._rt - s) * + (0.5_rt + amrex::Real(iy_part_coarse)) / amrex::Real(ny_coarse)) + + s * ((0.5_rt + amrex::Real(iy_part_fine)) / amrex::Real(ny_fine)); } else { do_init = false; } diff --git a/src/particles/plasma/MultiPlasma.H b/src/particles/plasma/MultiPlasma.H index 74ebb3ffa6..e2fddfbb7b 100644 --- a/src/particles/plasma/MultiPlasma.H +++ b/src/particles/plasma/MultiPlasma.H @@ -27,9 +27,10 @@ public: * \param[in] slice_gm slice geometry * \param[in] gm Geometry of the simulation, to get the cell size */ - void InitData (amrex::Vector slice_ba, - amrex::Vector slice_dm, - amrex::Vector slice_gm, amrex::Vector gm); + void InitData (const amrex::Vector& slice_ba, + const amrex::Vector& slice_dm, + const amrex::Vector& slice_gm, + const amrex::Vector& gm); /** \brief Loop over plasma species and initialize values used for ionization. * @@ -162,6 +163,7 @@ public: void InSituWriteToFile (int step, amrex::Real time, const amrex::Geometry& geom, bool is_last_step); + [[nodiscard]] PlasmaParticleContainer& GetPlasma (const std::string& name) { for (int i = 0; i < m_nplasmas; ++i) { if (m_names[i] == name) { @@ -172,6 +174,7 @@ public: return m_all_plasmas[0]; } + [[nodiscard]] const PlasmaParticleContainer& GetPlasma (const std::string& name) const { for (int i = 0; i < m_nplasmas; ++i) { if (m_names[i] == name) { diff --git a/src/particles/plasma/MultiPlasma.cpp b/src/particles/plasma/MultiPlasma.cpp index f685f10ed1..9c4886039c 100644 --- a/src/particles/plasma/MultiPlasma.cpp +++ b/src/particles/plasma/MultiPlasma.cpp @@ -29,7 +29,7 @@ MultiPlasma::ReadParameters () "hipace.background_density_SI", "", true); if (m_names[0] == "no_plasma") return; - m_nplasmas = m_names.size(); + m_nplasmas = static_cast(m_names.size()); for (int i = 0; i < m_nplasmas; ++i) { AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_names[i]!="beam", "Cannot have plasma with name 'beam'"); m_all_plasmas.emplace_back(PlasmaParticleContainer(m_names[i])); @@ -39,9 +39,10 @@ MultiPlasma::ReadParameters () } void -MultiPlasma::InitData (amrex::Vector slice_ba, - amrex::Vector slice_dm, - amrex::Vector slice_gm, amrex::Vector gm) +MultiPlasma::InitData (const amrex::Vector& slice_ba, + const amrex::Vector& slice_dm, + const amrex::Vector& slice_gm, + const amrex::Vector& gm) { for (auto& plasma : m_all_plasmas) { // make it think there is only level 0 diff --git a/src/particles/plasma/PlasmaParticleContainer.H b/src/particles/plasma/PlasmaParticleContainer.H index cfd61aef13..e30869fb6a 100644 --- a/src/particles/plasma/PlasmaParticleContainer.H +++ b/src/particles/plasma/PlasmaParticleContainer.H @@ -94,7 +94,7 @@ amrex::Real plasma_psi (amrex::Real ux, amrex::Real uy, amrex::Real uz, amrex::R /** \brief Map names and indices for plasma particles attributes (SoA data) */ struct PlasmaIdx { - enum { + enum : int { x=0, y, // position w, // weight, this will be returned by pos(2) ux, uy, // momentum @@ -113,7 +113,7 @@ struct PlasmaIdx #endif real_nattribs }; - enum { + enum : int { ion_lev, // ionization level int_nattribs }; @@ -129,7 +129,7 @@ public: explicit PlasmaParticleContainer (std::string name) : amrex::ParticleContainerPureSoA(), - m_name(name) + m_name(std::move(name)) {} /** Read parameters from the input file */ diff --git a/src/particles/plasma/PlasmaParticleContainer.cpp b/src/particles/plasma/PlasmaParticleContainer.cpp index 23f085edb3..79ce2d6977 100644 --- a/src/particles/plasma/PlasmaParticleContainer.cpp +++ b/src/particles/plasma/PlasmaParticleContainer.cpp @@ -59,7 +59,7 @@ PlasmaParticleContainer::ReadParameters () #endif queryWithParser(pp, "mass_Da", mass_Da); if(mass_Da != 0) { - m_mass = phys_const.m_p * mass_Da / 1.007276466621; + m_mass = phys_const.m_p * mass_Da / amrex::Real(1.007276466621); } queryWithParser(pp, "mass", m_mass); AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_mass != 0, "The plasma particle mass must be specified"); @@ -88,7 +88,7 @@ PlasmaParticleContainer::ReadParameters () } if(ion_lev_specified && !m_can_ionize) { - m_charge *= m_init_ion_lev; + m_charge *= amrex::Real(m_init_ion_lev); } queryWithParser(pp, "ionization_product", m_product_name); @@ -236,7 +236,7 @@ PlasmaParticleContainer::InitData (const amrex::Vector& geom3d) ")^2 < 1, " + amrex::ToString(lev) + ", " + - fine_patch_str + + std::move(fine_patch_str) + ")"; fine_patch_specified = true; @@ -405,9 +405,10 @@ IonizationModule (const int lev, auto& ptile_ion = plevel_ion.at(index); // Calculation of E0 in SI units for denormalization - const amrex::Real wp = std::sqrt(static_cast(background_density_SI) * - PhysConstSI::q_e*PhysConstSI::q_e / - (PhysConstSI::ep0 * PhysConstSI::m_e) ); + const amrex::Real wp = amrex::Real( + std::sqrt(static_cast(background_density_SI) * + PhysConstSI::q_e*PhysConstSI::q_e / + (PhysConstSI::ep0*PhysConstSI::m_e))); const amrex::Real E0 = Hipace::m_normalized_units ? wp * PhysConstSI::m_e * PhysConstSI::c / PhysConstSI::q_e : 1; @@ -424,7 +425,7 @@ IonizationModule (const int lev, amrex::Real* AMREX_RESTRICT adk_power = m_adk_power.data(); const int max_ion_lev = m_max_ion_lev; - long num_ions = ptile_ion.numParticles(); + int num_ions = ptile_ion.numParticles(); // This kernel supports multiple deposition orders (0, 1, 2, 3) at compile time @@ -441,7 +442,7 @@ IonizationModule (const int lev, amrex::ParallelForRNG(num_ions, cto_func); // enables the use of amrex::Random within the loop }, - [=] AMREX_GPU_DEVICE (long ip, const amrex::RandomEngine& engine, + [=] AMREX_GPU_DEVICE (int ip, const amrex::RandomEngine& engine, auto depos_order_xy) { if (!ptd_ion.id(ip).is_valid() || ptd_ion.cpu(ip) != lev) return; @@ -513,11 +514,12 @@ IonizationModule (const int lev, // This kernel adds the new ionized electrons to the Plasma Particle Container amrex::ParallelFor(num_ions, - [=] AMREX_GPU_DEVICE (long ip) { + [=] AMREX_GPU_DEVICE (int ip) { if(p_ion_mask[ip] != 0) { - const long pid = amrex::Gpu::Atomic::Add( p_ip_elec, 1u ); // ensures thread-safe access when incrementing `p_ip_elec` - const long pidx = pid + old_size; + // ensures thread-safe access when incrementing `p_ip_elec` + const int pid = static_cast(amrex::Gpu::Atomic::Add( p_ip_elec, 1u )); + const int pidx = pid + old_size; // Copy ion data to new electron // Set the ionized electron ID to 2 (valid/invalid) for the ionized electrons @@ -594,13 +596,14 @@ LaserIonization (const int islice, auto& ptile_ion = plevel_ion.at(index); // Calcuation of E0 in SI units for denormalization - const amrex::Real wp = std::sqrt(static_cast(background_density_SI) * - PhysConstSI::q_e*PhysConstSI::q_e / - (PhysConstSI::ep0 * PhysConstSI::m_e) ); + const amrex::Real wp = amrex::Real( + std::sqrt(static_cast(background_density_SI) * + PhysConstSI::q_e*PhysConstSI::q_e / + (PhysConstSI::ep0*PhysConstSI::m_e))); const amrex::Real E0 = Hipace::m_normalized_units ? wp * PhysConstSI::m_e * PhysConstSI::c / PhysConstSI::q_e : 1; const amrex::Real lambda0 = laser.GetLambda0(); - const amrex::Real omega0 = 2.0 * MathConst::pi * phys_const.c / lambda0; + const amrex::Real omega0 = 2._rt * MathConst::pi * phys_const.c / lambda0; const bool linear_polarization = laser.LinearPolarization(); auto ptd_ion = ptile_ion.getParticleTileData(); @@ -618,7 +621,7 @@ LaserIonization (const int islice, amrex::Real* AMREX_RESTRICT laser_dp_prefactor = m_laser_dp_prefactor.data(); const int max_ion_lev = m_max_ion_lev; - long num_ions = ptile_ion.numParticles(); + int num_ions = ptile_ion.numParticles(); // This kernel supports multiple deposition orders (0, 1, 2, 3) at compile time // and calculates ionization probability. If ionization occurs, it increments @@ -634,7 +637,7 @@ LaserIonization (const int islice, amrex::ParallelForRNG(num_ions, cto_func); // enables the use of `amrex::Random` within the loop }, - [=] AMREX_GPU_DEVICE (long ip, const amrex::RandomEngine& engine, + [=] AMREX_GPU_DEVICE (int ip, const amrex::RandomEngine& engine, auto depos_order_xy) { // Avoid temp slice @@ -724,7 +727,7 @@ LaserIonization (const int islice, [&] (auto cto_func) { amrex::ParallelForRNG(num_ions, cto_func); }, - [=] AMREX_GPU_DEVICE (long ip, const amrex::RandomEngine& engine, + [=] AMREX_GPU_DEVICE (int ip, const amrex::RandomEngine& engine, auto depos_order_xy) { if(p_ion_mask[ip] != 0) { @@ -777,8 +780,9 @@ LaserIonization (const int islice, uz = amrex::abs(A*A); } - const long pid = amrex::Gpu::Atomic::Add( p_ip_elec, 1u ); // ensures thread-safe access when incrementing `p_ip_elec` - const long pidx = pid + old_size; + // ensures thread-safe access when incrementing `p_ip_elec` + const int pid = static_cast(amrex::Gpu::Atomic::Add( p_ip_elec, 1u )); + const int pidx = pid + old_size; const amrex::Real psi = plasma_psi(ux, uy, uz, amrex::abs(A*A)); // Copy ion data to new electron // Set the ionized electron ID to 2 (valid/invalid) for the ionized electrons @@ -866,8 +870,8 @@ PlasmaParticleContainer::InSituComputeDiags (int islice) if (use_laser) { amrex::Real laser_norm_ion = laser_norm; if (can_ionize) { - laser_norm_ion *= - ptd.idata(PlasmaIdx::ion_lev)[ip] * ptd.idata(PlasmaIdx::ion_lev)[ip]; + const amrex::Real ilev = amrex::Real(ptd.idata(PlasmaIdx::ion_lev)[ip]); + laser_norm_ion *= ilev * ilev; } doLaserGatherShapeN<2>(x, y, Aabssqp, arr, aabs_comp, dx_inv, dy_inv, x_pos_offset, y_pos_offset); diff --git a/src/particles/plasma/PlasmaParticleContainerInit.cpp b/src/particles/plasma/PlasmaParticleContainerInit.cpp index 02b6e2ca1d..5af0184c84 100644 --- a/src/particles/plasma/PlasmaParticleContainerInit.cpp +++ b/src/particles/plasma/PlasmaParticleContainerInit.cpp @@ -52,8 +52,10 @@ InitParticles (const amrex::RealVect& a_u_std, amrex::Array scale_fac_lev {}; for (int lev = 0; lev < n_lev; ++lev) { const int num_ppc = ppc_lev[lev][0] * ppc_lev[lev][1]; - scale_fac_lev[lev] = num_ppc <= 0 ? 0. : - (Hipace::m_normalized_units ? 1./num_ppc : dx[0]*dx[1]*dx[2]/num_ppc); + scale_fac_lev[lev] = num_ppc <= 0 ? amrex::Real(0) : + (Hipace::m_normalized_units ? + amrex::Real(1)/amrex::Real(num_ppc) : + dx[0]*dx[1]*dx[2]/amrex::Real(num_ppc)); } amrex::IntVect box_nodal{amrex::IndexType::CELL,amrex::IndexType::CELL,amrex::IndexType::CELL}; @@ -105,8 +107,8 @@ InitParticles (const amrex::RealVect& a_u_std, amrex::ParallelFor(to2D(tile_box), [=] AMREX_GPU_DEVICE (int i, int j) noexcept { - const amrex::Real x = plo[0] + (i + 0.5_rt + x_offset)*dx[0]; - const amrex::Real y = plo[1] + (j + 0.5_rt + y_offset)*dx[1]; + const amrex::Real x = plo[0] + (amrex::Real(i) + 0.5_rt + x_offset)*dx[0]; + const amrex::Real y = plo[1] + (amrex::Real(j) + 0.5_rt + y_offset)*dx[1]; const int fine_val = static_cast(std::round(fine_patch_func(x, y))); arr_fine(i, j, comp_a) = std::min(max_lev+0, std::max(0, fine_val)) * (fine_transition_cells + 1); @@ -147,8 +149,8 @@ InitParticles (const amrex::RealVect& a_u_std, if (!do_init) return {false, 0, 0, 0}; - const amrex::Real x = plo[0] + (i + r[0] + x_offset)*dx[0]; - const amrex::Real y = plo[1] + (j + r[1] + y_offset)*dx[1]; + const amrex::Real x = plo[0] + (amrex::Real(i) + r[0] + x_offset)*dx[0]; + const amrex::Real y = plo[1] + (amrex::Real(j) + r[1] + y_offset)*dx[1]; const amrex::Real rsq = x*x + y*y; const amrex::Real density = density_func(x, y, c_t); @@ -274,8 +276,8 @@ InitParticles (const amrex::RealVect& a_u_std, } pidx += current_size; - ptd.id(pidx) = 1; // plasma id is only used to distinguish between valid/invalid - ptd.cpu(pidx) = 0; // level 0 + ptd.id(static_cast(pidx)) = 1; // plasma id is only used to distinguish between valid/invalid + ptd.cpu(static_cast(pidx)) = 0; // level 0 ptd.rdata(PlasmaIdx::x)[pidx] = x; ptd.rdata(PlasmaIdx::y)[pidx] = y; @@ -345,8 +347,8 @@ InitParticles (const amrex::RealVect& a_u_std, for (int imirror=0; imirror<3; ++imirror) { const amrex::Long midx = (imirror+1)*total_non_mirrored_particles + pidx; - ptd.id(midx) = 1; // plasma id is only used to distinguish between valid/invalid - ptd.cpu(midx) = 0; // level 0 + ptd.id(static_cast(midx)) = 1; // plasma id is only used to distinguish between valid/invalid + ptd.cpu(static_cast(midx)) = 0; // level 0 ptd.rdata(PlasmaIdx::x)[midx] = x_arr[imirror]; ptd.rdata(PlasmaIdx::y)[midx] = y_arr[imirror]; @@ -394,7 +396,7 @@ InitIonizationModule (const amrex::Geometry& geom, const amrex::Real background_ amrex::ParmParse pp(m_name); std::string physical_element; getWithParser(pp, "element", physical_element); - AMREX_ALWAYS_ASSERT_WITH_MESSAGE(ion_map_ids.count(physical_element) != 0, + AMREX_ALWAYS_ASSERT_WITH_MESSAGE(ion_map_ids.contains(physical_element), "There are no ionization energies available for this element. " "Please update src/utils/IonizationEnergiesTable.H using write_atomic_data_cpp.py"); AMREX_ALWAYS_ASSERT_WITH_MESSAGE((std::abs(m_product_pc->m_charge / m_charge +1) < 1e-3), @@ -422,9 +424,10 @@ InitIonizationModule (const amrex::Geometry& geom, const amrex::Real background_ const amrex::Real l_eff = std::sqrt(UH/h_ionization_energies[0]) - 1._rt; // Plasma frequency in SI units to denormalize ionization - const amrex::Real wp = std::sqrt(static_cast(background_density_SI) * - PhysConstSI::q_e*PhysConstSI::q_e / - (PhysConstSI::ep0 * PhysConstSI::m_e) ); + const amrex::Real wp = amrex::Real( + std::sqrt(static_cast(background_density_SI) * + PhysConstSI::q_e*PhysConstSI::q_e / + (PhysConstSI::ep0*PhysConstSI::m_e))); const amrex::Real dt = normalized_units ? geom.CellSize(2)/wp : geom.CellSize(2)/phys_const.c; m_adk_power.resize(ion_atomic_number); @@ -435,16 +438,18 @@ InitIonizationModule (const amrex::Geometry& geom, const amrex::Real background_ for (int i=0; i(rmid, ir); result += sz * sr * array(i, j, 0); for (int im=1; im<=m_bigend[2]/2; im++) { - result += sz * sr * array(i, j, 2*im-1) * std::cos(im*theta); - result += sz * sr * array(i, j, 2*im) * std::sin(im*theta); + result += sz * sr * array(i, j, 2*im-1) * std::cos(amrex::Real(im)*theta); + result += sz * sr * array(i, j, 2*im) * std::sin(amrex::Real(im)*theta); }}} return m_unitSI * result; } diff --git a/src/particles/profiles/GetInitialDensity.cpp b/src/particles/profiles/GetInitialDensity.cpp index 2f40f89741..13c8a61cd1 100644 --- a/src/particles/profiles/GetInitialDensity.cpp +++ b/src/particles/profiles/GetInitialDensity.cpp @@ -108,9 +108,9 @@ PlasmaDensityAccessor::define_from_file (const std::string& path, std::shared_pt if (mesh.geometry() == openPMD::Mesh::Geometry::cartesian) { m_profile_type = 1; - idx_perm[0] = axis_labels_map.count("x") > 0 ? axis_labels_map["x"] : -1; - idx_perm[1] = axis_labels_map.count("y") > 0 ? axis_labels_map["y"] : -1; - idx_perm[2] = axis_labels_map.count("z") > 0 ? axis_labels_map["z"] : -1; + idx_perm[0] = axis_labels_map.contains("x") ? axis_labels_map["x"] : -1; + idx_perm[1] = axis_labels_map.contains("y") ? axis_labels_map["y"] : -1; + idx_perm[2] = axis_labels_map.contains("z") ? axis_labels_map["z"] : -1; axis_labels_map.erase("x"); axis_labels_map.erase("y"); @@ -127,8 +127,8 @@ PlasmaDensityAccessor::define_from_file (const std::string& path, std::shared_pt strides.erase(strides.begin()); } - idx_perm[0] = axis_labels_map.count("r") > 0 ? axis_labels_map["r"] : -1; - idx_perm[1] = axis_labels_map.count("z") > 0 ? axis_labels_map["z"] : -1; + idx_perm[0] = axis_labels_map.contains("r") ? axis_labels_map["r"] : -1; + idx_perm[1] = axis_labels_map.contains("z") ? axis_labels_map["z"] : -1; idx_perm[2] = -1; axis_labels_map.erase("r"); @@ -144,7 +144,7 @@ PlasmaDensityAccessor::define_from_file (const std::string& path, std::shared_pt for (int i=0; i<3; ++i) { m_strides[i] = idx_perm[i] != -1 ? strides[idx_perm[i]] : 0; - m_bigend[i] = idx_perm[i] != -1 ? extent[idx_perm[i]] - 1 : 0; + m_bigend[i] = idx_perm[i] != -1 ? static_cast(extent[idx_perm[i]]) - 1 : 0; m_pos_offset[i] = idx_perm[i] != -1 ? static_cast( offset[idx_perm[i]] + spacing[idx_perm[i]] * position[idx_perm[i]]) : 0; m_dx_inv[i] = idx_perm[i] != -1 ? static_cast(1. / spacing[idx_perm[i]]) : 0; @@ -152,7 +152,7 @@ PlasmaDensityAccessor::define_from_file (const std::string& path, std::shared_pt if (use_mode) { m_strides[2] = mode_stride; - m_bigend[2] = mode_bigend; + m_bigend[2] = static_cast(mode_bigend); } m_unitSI = static_cast(comp.unitSI()); diff --git a/src/particles/profiles/GetInitialMomentum.H b/src/particles/profiles/GetInitialMomentum.H index a472de67e6..18824fd31f 100644 --- a/src/particles/profiles/GetInitialMomentum.H +++ b/src/particles/profiles/GetInitialMomentum.H @@ -14,7 +14,7 @@ #include /** \brief Beam profile type, currently only Gaussian */ -enum struct BeamMomentumType { Gaussian }; +enum struct BeamMomentumType : int { Gaussian }; /** \brief Functor gets the initial momentum for beam particles */ diff --git a/src/particles/pusher/BeamParticleAdvance.cpp b/src/particles/pusher/BeamParticleAdvance.cpp index f1a81ad8d7..709136d5a2 100644 --- a/src/particles/pusher/BeamParticleAdvance.cpp +++ b/src/particles/pusher/BeamParticleAdvance.cpp @@ -30,7 +30,7 @@ AdvanceBeamParticlesSlice ( const int n_subcycles = beam.m_n_subcycles; const bool radiation_reaction = beam.m_do_radiation_reaction; const amrex::Real time = Hipace::GetInstance().m_physical_time; - const amrex::Real dt = Hipace::GetInstance().m_dt / n_subcycles; + const amrex::Real dt = Hipace::GetInstance().m_dt / amrex::Real(n_subcycles); const bool spin_tracking = beam.m_do_spin_tracking; const amrex::Real spin_anom = beam.m_spin_anom; @@ -91,7 +91,8 @@ AdvanceBeamParticlesSlice ( const amrex::Real clight = phys_const.c; const amrex::Real inv_clight = 1.0_rt/phys_const.c; const amrex::Real charge_mass_ratio = beam.m_charge / beam.m_mass; - const amrex::Real min_z = gm[0].ProbLo(2) + (slice-gm[0].Domain().smallEnd(2))*gm[0].CellSize(2); + const amrex::Real min_z = gm[0].ProbLo(2) + + amrex::Real(slice-gm[0].Domain().smallEnd(2))*gm[0].CellSize(2); bool use_external_fields = beam.m_use_external_fields; auto external_fields = beam.m_external_fields; @@ -102,8 +103,8 @@ AdvanceBeamParticlesSlice ( AMREX_ALWAYS_ASSERT_WITH_MESSAGE(Hipace::m_background_density_SI != 0, "For radiation reactions with normalized units, a background plasma density != 0 must " "be specified via 'hipace.background_density_SI'"); - rr_factor *= std::sqrt(static_cast(Hipace::m_background_density_SI) - / (PhysConstSI::ep0 * PhysConstSI::m_e)) * PhysConstSI::q_e; + rr_factor *= amrex::Real(std::sqrt(static_cast(Hipace::m_background_density_SI) + / (PhysConstSI::ep0 * PhysConstSI::m_e)) * PhysConstSI::q_e); } // don't include slipped particles in count as they were already pushed diff --git a/src/particles/pusher/GetAndSetPosition.H b/src/particles/pusher/GetAndSetPosition.H index b4fbf20695..30d0217d7e 100644 --- a/src/particles/pusher/GetAndSetPosition.H +++ b/src/particles/pusher/GetAndSetPosition.H @@ -35,8 +35,8 @@ struct EnforceBC /** Constructor. */ EnforceBC () noexcept + : m_particle_boundary{Hipace::m_boundary_particles} { - m_particle_boundary = Hipace::m_boundary_particles; m_plo[0] = Hipace::m_boundary_particle_lo[0]; m_plo[1] = Hipace::m_boundary_particle_lo[1]; m_phi[0] = Hipace::m_boundary_particle_hi[0]; diff --git a/src/particles/pusher/PlasmaParticleAdvance.cpp b/src/particles/pusher/PlasmaParticleAdvance.cpp index 76f9786b91..8ac345e01c 100644 --- a/src/particles/pusher/PlasmaParticleAdvance.cpp +++ b/src/particles/pusher/PlasmaParticleAdvance.cpp @@ -66,7 +66,7 @@ AdvancePlasmaParticles (PlasmaParticleContainer& plasma, const Fields & fields, const int n_subcycles = plasma.m_n_subcycles; const auto enforceBC = EnforceBC(); - const amrex::Real dz = gm[0].CellSize(2) / n_subcycles; + const amrex::Real dz = gm[0].CellSize(2) / amrex::Real(n_subcycles); if (!temp_slice && lev == 0) { // only count particles on non-temp slices and only once for all MR levels @@ -100,9 +100,9 @@ AdvancePlasmaParticles (PlasmaParticleContainer& plasma, const Fields & fields, amrex::Real q_mass_clight_ratio = charge_mass_clight_ratio; amrex::Real laser_norm_ion = laser_norm; if (can_ionize) { - q_mass_clight_ratio *= ptd.idata(PlasmaIdx::ion_lev)[ip]; - laser_norm_ion *= - ptd.idata(PlasmaIdx::ion_lev)[ip] * ptd.idata(PlasmaIdx::ion_lev)[ip]; + const amrex::Real ilev = amrex::Real(ptd.idata(PlasmaIdx::ion_lev)[ip]); + q_mass_clight_ratio *= ilev; + laser_norm_ion *= ilev * ilev; } for (int i = 0; i < n_subcycles; i++) { diff --git a/src/particles/sorting/SliceSort.cpp b/src/particles/sorting/SliceSort.cpp index d003cfa059..bb1eb7bff7 100644 --- a/src/particles/sorting/SliceSort.cpp +++ b/src/particles/sorting/SliceSort.cpp @@ -22,7 +22,8 @@ shiftSlippedParticles (BeamParticleContainer& beam, const int slice, amrex::Geom const int num_particles = beam.getNumParticlesIncludingSlipped(WhichBeamSlice::This); const auto ptdr = beam.getBeamSlice(WhichBeamSlice::This).getParticleTileData(); // min_z is the lower end of WhichBeamSlice::This - const amrex::Real min_z = geom.ProbLo(2) + (slice-geom.Domain().smallEnd(2))*geom.CellSize(2); + const amrex::Real min_z = geom.ProbLo(2) + + amrex::Real(slice - geom.Domain().smallEnd(2))*geom.CellSize(2); amrex::ReduceOps reduce_op; amrex::ReduceData reduce_data(reduce_op); diff --git a/src/particles/sorting/TileSort.cpp b/src/particles/sorting/TileSort.cpp index 118624c24e..a106ea2b83 100644 --- a/src/particles/sorting/TileSort.cpp +++ b/src/particles/sorting/TileSort.cpp @@ -31,8 +31,8 @@ findParticlesInEachTile ( // Extract box properties const auto lo = lbound(cbx); const auto dxi = amrex::GpuArray({ - geom.InvCellSizeArray()[0]/bin_size, - geom.InvCellSizeArray()[1]/bin_size, + geom.InvCellSizeArray()[0] / amrex::Real(bin_size), + geom.InvCellSizeArray()[1] / amrex::Real(bin_size), 1.}); const auto plo = geom.ProbLoArray(); @@ -70,8 +70,8 @@ findBeamParticlesInEachTile ( // Extract box properties const auto lo = lbound(cbx); const auto dxi = amrex::GpuArray({ - geom.InvCellSizeArray()[0]/bin_size, - geom.InvCellSizeArray()[1]/bin_size, + geom.InvCellSizeArray()[0] / amrex::Real(bin_size), + geom.InvCellSizeArray()[1] / amrex::Real(bin_size), 1.}); const auto plo = geom.ProbLoArray(); diff --git a/src/salame/Salame.cpp b/src/salame/Salame.cpp index 05bb6f323d..136c8d56ed 100644 --- a/src/salame/Salame.cpp +++ b/src/salame/Salame.cpp @@ -25,7 +25,7 @@ SalameModule (Hipace* hipace, const int n_iter, const bool do_advance, int& last WhichSlice::This, {"Ez"}); } overloaded = false; - hipace->m_salame_zeta_initial = islice * hipace->m_3D_geom[0].CellSize(2) + + hipace->m_salame_zeta_initial = amrex::Real(islice) * hipace->m_3D_geom[0].CellSize(2) + GetPosOffset(2, hipace->m_3D_geom[0], hipace->m_3D_geom[0].Domain()); } last_islice = islice; @@ -311,7 +311,7 @@ SalameOnlyAdvancePlasma (Hipace* hipace, const int lev) bx_comp, by_comp, dx_inv, dy_inv, x_pos_offset, y_pos_offset); const amrex::Real q_m_c_ratio = can_ionize ? - ptd.idata(PlasmaIdx::ion_lev)[ip] * charge_mass_c_ratio + amrex::Real(ptd.idata(PlasmaIdx::ion_lev)[ip]) * charge_mass_c_ratio : charge_mass_c_ratio; #ifdef HIPACE_USE_AB5_PUSH @@ -382,7 +382,7 @@ SalameGetW (Hipace* hipace, const int current_N_level, const int islice) sum_Ez_only_salame /= sum_jz; // - 1 because this is for the Ez field of the next slice - const amrex::Real zeta = (islice-1) * hipace->m_3D_geom[0].CellSize(2) + + const amrex::Real zeta = amrex::Real(islice-1) * hipace->m_3D_geom[0].CellSize(2) + GetPosOffset(2, hipace->m_3D_geom[0], hipace->m_3D_geom[0].Domain()); // update target with user function sum_Ez_target = hipace->m_salame_target_func( @@ -408,7 +408,7 @@ SalameMultiplyBeamWeight (const amrex::Real W, Hipace* hipace) amrex::ParallelFor( beam.getNumParticles(WhichBeamSlice::This), - [=] AMREX_GPU_DEVICE (long ip) { + [=] AMREX_GPU_DEVICE (int ip) { // Skip invalid particles and ghost particles not in the last slice auto id = amrex::ParticleIDWrapper(idcpup[ip]); if (!id.is_valid()) return; diff --git a/src/utils/AdaptiveTimeStep.cpp b/src/utils/AdaptiveTimeStep.cpp index 480cd001dd..917236707f 100644 --- a/src/utils/AdaptiveTimeStep.cpp +++ b/src/utils/AdaptiveTimeStep.cpp @@ -198,7 +198,7 @@ AdaptiveTimeStep::CalculateFromMinUz ( std::sqrt(std::abs(m_timestep_data[ibeam][WhichDouble::SumWeightsTimesUzSquared] /m_timestep_data[ibeam][WhichDouble::SumWeights] - mean_uz*mean_uz)); - const amrex::Real sigma_uz_dev = mean_uz - 4.*sigma_uz; + const amrex::Real sigma_uz_dev = mean_uz - 4._rt * sigma_uz; const amrex::Real max_supported_uz = 1.e30; amrex::Real chosen_min_uz = std::min(std::max(sigma_uz_dev, m_timestep_data[ibeam][WhichDouble::MinUz]), @@ -240,8 +240,8 @@ AdaptiveTimeStep::CalculateFromMinUz ( // Just make sure min_uz is >0, to avoid nans below. min_uz = std::max(min_uz, 0.001_rt*m_threshold_uz); amrex::Real omega_b = std::sqrt(plasma_charge_density / - (2. * std::abs(min_uz * mass_charge_ratio) * ep0)); - new_dt = 2. * MathConst::pi / omega_b / m_nt_per_betatron; + (2._rt * std::abs(min_uz * mass_charge_ratio) * ep0)); + new_dt = 2._rt * MathConst::pi / omega_b / m_nt_per_betatron; new_time += new_dt; if (min_uz > m_threshold_uz) { new_dts[ibeam] = new_dt; @@ -298,7 +298,7 @@ AdaptiveTimeStep::GatherMinAccSlice (MultiBeam& beams, const amrex::Geometry& ge const auto idcpup = soa.GetIdCPUData().data(); reduce_op.eval(beam.getNumParticles(WhichBeamSlice::This), reduce_data, - [=] AMREX_GPU_DEVICE (long ip) noexcept -> ReduceTuple + [=] AMREX_GPU_DEVICE (int ip) noexcept -> ReduceTuple { if (amrex::ConstParticleIDWrapper(idcpup[ip]) < 0) return { 0._rt }; const amrex::Real xp = pos_x[ip]; @@ -326,11 +326,11 @@ AdaptiveTimeStep::CalculateFromDensity (amrex::Real t, amrex::Real& dt, MultiPla if (!m_do_adaptive_time_step) return; for (int ibeam = 0; ibeam < m_nbeams; ibeam++) { - m_timestep_data[ibeam][WhichDouble::MinUz] = 1e30; - m_timestep_data[ibeam][WhichDouble::MinAcc] = 0.; - m_timestep_data[ibeam][WhichDouble::SumWeights] = 0.; - m_timestep_data[ibeam][WhichDouble::SumWeightsTimesUz] = 0.; - m_timestep_data[ibeam][WhichDouble::SumWeightsTimesUzSquared] = 0.; + m_timestep_data[ibeam][WhichDouble::MinUz] = 1e30_rt; + m_timestep_data[ibeam][WhichDouble::MinAcc] = 0._rt; + m_timestep_data[ibeam][WhichDouble::SumWeights] = 0._rt; + m_timestep_data[ibeam][WhichDouble::SumWeightsTimesUz] = 0._rt; + m_timestep_data[ibeam][WhichDouble::SumWeightsTimesUzSquared] = 0._rt; } if (!m_adaptive_control_phase_advance) return; @@ -339,28 +339,29 @@ AdaptiveTimeStep::CalculateFromDensity (amrex::Real t, amrex::Real& dt, MultiPla const PhysConst pc = get_phys_const(); - amrex::Real dt_sub = dt / m_adaptive_phase_substeps; - amrex::Real phase_advance = 0.; - amrex::Real phase_advance0 = 0.; + amrex::Real dt_sub = dt / amrex::Real(m_adaptive_phase_substeps); + amrex::Real phase_advance = 0._rt; + amrex::Real phase_advance0 = 0._rt; // Get plasma density at beginning of step const amrex::Real plasma_charge_density0 = plasmas.maxChargeDensity(pc.c * t); - const amrex::Real omgb0 = std::sqrt(plasma_charge_density0 / (2. * m_min_uz_mq * pc.ep0)); + const amrex::Real omgb0 = std::sqrt(plasma_charge_density0 / (2._rt * m_min_uz_mq * pc.ep0)); // Numerically integrate the phase advance from t to t+dt. The time step is reduced such that // the expected phase advance equals that of a uniform plasma up to a tolerance level. for (int i = 0; i < m_adaptive_phase_substeps; i++) { - const amrex::Real plasma_charge_density = plasmas.maxChargeDensity(pc.c * (t+i*dt_sub)); - const amrex::Real omgb = std::sqrt(plasma_charge_density / (2. * m_min_uz_mq * pc.ep0)); + const amrex::Real plasma_charge_density = + plasmas.maxChargeDensity(pc.c * (t + amrex::Real(i) * dt_sub)); + const amrex::Real omgb = std::sqrt(plasma_charge_density / (2._rt * m_min_uz_mq * pc.ep0)); phase_advance += omgb * dt_sub; phase_advance0 += omgb0 * dt_sub; if(std::abs(phase_advance - phase_advance0) > - 2.*MathConst::pi*m_adaptive_phase_tolerance/m_nt_per_betatron) + 2._rt*MathConst::pi*m_adaptive_phase_tolerance/m_nt_per_betatron) { if (i==0) amrex::AllPrint()<<"WARNING: adaptive time step exits at first substep."<< " Consider increasing hipace.adaptive_phase_substeps!\n"; - dt = i*dt_sub; + dt = amrex::Real(i) * dt_sub; return; } } diff --git a/src/utils/Constants.H b/src/utils/Constants.H index 9f50c03b3b..6fe16ed598 100644 --- a/src/utils/Constants.H +++ b/src/utils/Constants.H @@ -29,7 +29,7 @@ namespace PhysConstSI /** \brief Namespace containing math constants */ namespace MathConst { - static constexpr amrex::Real pi = 3.14159265358979323846; + static constexpr amrex::Real pi = 3.14159265358979323846; // NOLINT(modernize-use-std-numbers) } /** \brief Struct containing physical constants, our main strategy to handle both SI and diff --git a/src/utils/GPUUtil.H b/src/utils/GPUUtil.H index 43c2d7ef11..ff209d9cb0 100644 --- a/src/utils/GPUUtil.H +++ b/src/utils/GPUUtil.H @@ -80,18 +80,13 @@ struct Array2 { #endif }; -template inline -Array2 to_array2 (amrex::Array4&& in) { - return Array2{in}; -} - template inline Array2 to_array2 (const amrex::Array4& in) { return Array2{in}; } template inline -T to_array2 (T&& in) { +T to_array2 (const T& in) { return in; } @@ -183,21 +178,6 @@ struct Array3 { #endif }; -template inline -Array3 to_array3 (amrex::Array4&& in) { - return Array3{in}; -} - -template inline -Array3 to_array3 (const amrex::Array4& in) { - return Array3{in}; -} - -template inline -T to_array3 (T&& in) { - return in; -} - inline amrex::MFItInfo DfltMfi; // Default MFIter inline amrex::MFItInfo DfltMfiTlng; // Default MFIter with Tiling diff --git a/src/utils/GridCurrent.cpp b/src/utils/GridCurrent.cpp index 1ed78ed1c0..e93757a488 100644 --- a/src/utils/GridCurrent.cpp +++ b/src/utils/GridCurrent.cpp @@ -44,7 +44,7 @@ GridCurrent::DepositCurrentSlice (Fields& fields, const amrex::Geometry& geom, i // Extract the longitudinal beam current amrex::MultiFab& S = fields.getSlices(lev); - const amrex::Real z = plo[2] + islice*dx_arr[2]; + const amrex::Real z = plo[2] + amrex::Real(islice) * dx_arr[2]; const amrex::Real delta_z = (z - pos_mean[2]) / pos_std[2]; const amrex::Real long_pos_factor = std::exp( -0.5_rt*(delta_z*delta_z) ); const amrex::Real loc_peak_current_density = m_peak_current_density; @@ -57,8 +57,8 @@ GridCurrent::DepositCurrentSlice (Fields& fields, const amrex::Geometry& geom, i amrex::ParallelFor( to2D(bx), [=] AMREX_GPU_DEVICE(int i, int j) { - const amrex::Real x = plo[0] + (i+0.5_rt)*dx_arr[0]; - const amrex::Real y = plo[1] + (j+0.5_rt)*dx_arr[1]; + const amrex::Real x = plo[0] + (amrex::Real(i) + 0.5_rt) * dx_arr[0]; + const amrex::Real y = plo[1] + (amrex::Real(j) + 0.5_rt) * dx_arr[1]; const amrex::Real delta_x = (x - pos_mean[0]) / pos_std[0]; const amrex::Real delta_y = (y - pos_mean[1]) / pos_std[1]; diff --git a/src/utils/GridIonization.cpp b/src/utils/GridIonization.cpp index a542f9c998..37e91e5b93 100644 --- a/src/utils/GridIonization.cpp +++ b/src/utils/GridIonization.cpp @@ -31,16 +31,16 @@ GridIonization::GetFieldComponents (const MultiPlasma& multi_plasma) return ret; } - ret.push_back("grid_ionization_w_elec"); - ret.push_back("grid_ionization_ux^2_elec"); - ret.push_back("grid_ionization_uy^2_elec"); - ret.push_back("grid_ionization_uz_elec"); - ret.push_back("grid_ionization_uz^2_elec"); + ret.emplace_back("grid_ionization_w_elec"); + ret.emplace_back("grid_ionization_ux^2_elec"); + ret.emplace_back("grid_ionization_uy^2_elec"); + ret.emplace_back("grid_ionization_uz_elec"); + ret.emplace_back("grid_ionization_uz^2_elec"); for (auto& plasma_name : m_names) { const auto& plasma = multi_plasma.GetPlasma(plasma_name); for (int ionlev=0; ionlev <= plasma.m_max_ion_lev; ++ionlev) { - ret.push_back("grid_ionization_w_" + plasma_name + "_" + std::to_string(ionlev)); + ret.emplace_back("grid_ionization_w_" + plasma_name + "_" + std::to_string(ionlev)); } } @@ -101,8 +101,8 @@ GridIonization::InitData (Fields& fields, const MultiPlasma& multi_plasma, amrex::ParallelFor(to2D(bx), [=] AMREX_GPU_DEVICE (int i, int j) { - const amrex::Real x = i * dx + poff_x; - const amrex::Real y = j * dy + poff_y; + const amrex::Real x = amrex::Real(i) * dx + poff_x; + const amrex::Real y = amrex::Real(j) * dy + poff_y; const amrex::Real rsq = x * x + y * y; @@ -168,13 +168,14 @@ GridIonization::IonizeGrid (Fields& fields, const MultiPlasma& multi_plasma, const amrex::Real poff_y = GetPosOffset(1, geom, geom.Domain()); // Calcuation of E0 in SI units for denormalization - const amrex::Real wp = std::sqrt(static_cast(Hipace::m_background_density_SI) * - PhysConstSI::q_e*PhysConstSI::q_e / - (PhysConstSI::ep0 * PhysConstSI::m_e) ); + const amrex::Real wp = amrex::Real( + std::sqrt(static_cast(Hipace::m_background_density_SI) * + PhysConstSI::q_e * PhysConstSI::q_e / + (PhysConstSI::ep0 * PhysConstSI::m_e))); const amrex::Real E0 = Hipace::m_normalized_units ? wp * PhysConstSI::m_e * PhysConstSI::c / PhysConstSI::q_e : 1; const amrex::Real lambda0 = laser.GetLambda0(); - const amrex::Real omega0 = 2.0 * MathConst::pi * phys_const.c / lambda0; + const amrex::Real omega0 = 2._rt * MathConst::pi * phys_const.c / lambda0; const bool linear_polarization = laser.LinearPolarization(); const amrex::Real* adk_prefactor = plasma.m_adk_prefactor.data(); @@ -206,8 +207,8 @@ GridIonization::IonizeGrid (Fields& fields, const MultiPlasma& multi_plasma, amrex::ParallelFor(to2D(bx), [=] AMREX_GPU_DEVICE (int i, int j) { - const amrex::Real x = i * dx + poff_x; - const amrex::Real y = j * dy + poff_y; + const amrex::Real x = amrex::Real(i) * dx + poff_x; + const amrex::Real y = amrex::Real(j) * dy + poff_y; Complex A = 0; Complex A_dx = 0; @@ -247,7 +248,7 @@ GridIonization::IonizeGrid (Fields& fields, const MultiPlasma& multi_plasma, const amrex::Real old_weight = arr(i, j, ion_weight_comp + ion_lev); const amrex::Real transferred_weight = old_weight * p; const amrex::Real new_weight = old_weight - transferred_weight; - chi += new_weight * chi_factor_ion * ion_lev * ion_lev; + chi += new_weight * chi_factor_ion * amrex::Real(ion_lev * ion_lev); arr(i, j, ion_weight_comp + ion_lev) = new_weight; arr(i, j, ion_weight_comp + ion_lev + 1) += transferred_weight; @@ -303,7 +304,7 @@ GridIonization::IonizeGrid (Fields& fields, const MultiPlasma& multi_plasma, // last ion level chi += arr(i, j, ion_weight_comp + max_ion_lev) * - chi_factor_ion * max_ion_lev * max_ion_lev; + chi_factor_ion * amrex::Real(max_ion_lev * max_ion_lev); arr(i, j, comps[0]) += chi; } diff --git a/src/utils/HipaceProfilerWrapper.H b/src/utils/HipaceProfilerWrapper.H index 01c39a4f2b..4796b0defc 100644 --- a/src/utils/HipaceProfilerWrapper.H +++ b/src/utils/HipaceProfilerWrapper.H @@ -31,7 +31,7 @@ void doStreamSynchronize () // Note that objects are destructed in the reverse order of declaration template -struct synchronizeOnDestruct { +struct synchronizeOnDestruct { // NOLINT(cppcoreguidelines-special-member-functions) AMREX_FORCE_INLINE ~synchronizeOnDestruct () { doStreamSynchronize(); diff --git a/src/utils/InsituUtil.H b/src/utils/InsituUtil.H index a8c57150f4..016491c2e6 100644 --- a/src/utils/InsituUtil.H +++ b/src/utils/InsituUtil.H @@ -29,7 +29,7 @@ struct DataNode { // constructor for nodes containing a simple datatype template - DataNode (const std::string& name, const T* data, std::size_t size = 1) : m_name{name} { + DataNode (std::string name, const T* data, std::size_t size = 1) : m_name{std::move(name)} { std::string type_letter = ""; if (std::is_integral_v && std::is_signed_v) type_letter = "i"; // int else if (std::is_integral_v && std::is_unsigned_v) type_letter = "u"; // unsiged int @@ -45,8 +45,9 @@ struct DataNode { } // constructor for nodes containing a structured datatype - DataNode (const std::string& name, const amrex::Vector& structured_format) - : m_name{name}, m_data_location{nullptr}, m_structured_format{structured_format} {} + DataNode (std::string name, amrex::Vector structured_format) + : m_name{std::move(name)}, m_data_location{nullptr}, + m_structured_format{std::move(structured_format)} {} }; // write JSON header describing the datatype @@ -81,7 +82,7 @@ inline void write_header (const amrex::Vector& nodes, std::ofstream& o inline void write_data (const amrex::Vector& nodes, std::ofstream& ofs) { for (auto& dn : nodes) { if (dn.m_data_location) { - ofs.write(dn.m_data_location, dn.m_data_size); + ofs.write(dn.m_data_location, static_cast(dn.m_data_size)); } else { // recursive call for nested structured datatypes write_data(dn.m_structured_format, ofs); diff --git a/src/utils/MultiBuffer.H b/src/utils/MultiBuffer.H index 53063f5c22..4ba9cf2fc1 100644 --- a/src/utils/MultiBuffer.H +++ b/src/utils/MultiBuffer.H @@ -13,7 +13,7 @@ #include "laser/MultiLaser.H" // declare MPI datatypes if compiled without MPI -using namespace amrex::mpidatatypes; +using namespace amrex::mpidatatypes; // NOLINT(google-global-names-in-headers) class MultiBuffer { @@ -39,10 +39,16 @@ public: // destructor to clean up all open MPI requests ~MultiBuffer(); + MultiBuffer () = default; + MultiBuffer (const MultiBuffer& rhs) = delete; + MultiBuffer (MultiBuffer&& rhs) = delete; + MultiBuffer& operator= (const MultiBuffer& rhs) = delete; + MultiBuffer& operator= (MultiBuffer&& rhs) = delete; + private: // to keep track of per-slice buffer location - enum struct memory_location { + enum struct memory_location : int { nowhere, pinned, device diff --git a/src/utils/MultiBuffer.cpp b/src/utils/MultiBuffer.cpp index eaae5addcf..e379c4ac9e 100644 --- a/src/utils/MultiBuffer.cpp +++ b/src/utils/MultiBuffer.cpp @@ -134,8 +134,8 @@ void MultiBuffer::initialize (int nslices, MultiBeam& beams, MultiLaser& laser) } if (laser.UseLaser()) { - size_estimate += laser.GetLaserGeom().Domain().numPts() - * m_laser_ncomp * sizeof(amrex::Real); + size_estimate += double(laser.GetLaserGeom().Domain().numPts() + * m_laser_ncomp * sizeof(amrex::Real)); } size_estimate /= 1024*1024*1024; @@ -239,7 +239,7 @@ MultiBuffer::~MultiBuffer () { if (m_datanodes[slice].m_metadata_progress == comm_progress::ready_to_send) { MPI_Isend( get_metadata_location(slice), - get_metadata_size(), + static_cast(get_metadata_size()), amrex::ParallelDescriptor::Mpi_typemap::type(), m_rank_send_to, m_tag_metadata_start + slice, @@ -254,7 +254,7 @@ MultiBuffer::~MultiBuffer () { } else { MPI_Isend( m_datanodes[slice].m_buffer, - m_datanodes[slice].m_buffer_size, + static_cast(m_datanodes[slice].m_buffer_size), amrex::ParallelDescriptor::Mpi_typemap::type(), m_rank_send_to, m_tag_buffer_start + slice, @@ -336,7 +336,7 @@ void MultiBuffer::make_progress (int slice, bool is_blocking_recv, if (allow_metadata_send) { MPI_Isend( get_metadata_location(slice), - get_metadata_size(), + static_cast(get_metadata_size()), amrex::ParallelDescriptor::Mpi_typemap::type(), m_rank_send_to, m_tag_metadata_start + slice, @@ -358,7 +358,7 @@ void MultiBuffer::make_progress (int slice, bool is_blocking_recv, } else if (allow_data_send) { MPI_Isend( m_datanodes[slice].m_buffer, - m_datanodes[slice].m_buffer_size, + static_cast(m_datanodes[slice].m_buffer_size), amrex::ParallelDescriptor::Mpi_typemap::type(), m_rank_send_to, m_tag_buffer_start + slice, @@ -391,7 +391,7 @@ void MultiBuffer::make_progress (int slice, bool is_blocking_recv, if (allow_metadata_recv) { MPI_Irecv( get_metadata_location(slice), - get_metadata_size(), + static_cast(get_metadata_size()), amrex::ParallelDescriptor::Mpi_typemap::type(), m_rank_receive_from, m_tag_metadata_start + slice, @@ -453,7 +453,7 @@ void MultiBuffer::make_progress (int slice, bool is_blocking_recv, allocate_buffer(slice); MPI_Irecv( m_datanodes[slice].m_buffer, - m_datanodes[slice].m_buffer_size, + static_cast(m_datanodes[slice].m_buffer_size), amrex::ParallelDescriptor::Mpi_typemap::type(), m_rank_receive_from, m_tag_buffer_start + slice, @@ -697,8 +697,8 @@ MultiBuffer::BufferOffset MultiBuffer::get_buffer_offset (int slice, MultiBeam& for (int b = 0; b < m_nbeams; ++b) { auto& beam = beams.getBeam(b); // Roundup the number of particles to a value that ensures proper alignment between types - const int num_particles_round_up = (get_metadata_location(slice)[b + 1] - + buffer_size_roundup - 1) / buffer_size_roundup * buffer_size_roundup; + const int num_particles_round_up = static_cast((get_metadata_location(slice)[b + 1] + + buffer_size_roundup - 1) / buffer_size_roundup * buffer_size_roundup); // add offset for idcpu, if used if (beam.communicateIdCpuComponent()) { @@ -855,7 +855,7 @@ void MultiBuffer::unpack_data (int slice, MultiBeam& beams, MultiLaser& laser, i for (int b = 0; b < m_nbeams; ++b) { auto& beam = beams.getBeam(b); - const int num_particles = get_metadata_location(slice)[b + 1]; + const int num_particles = static_cast(get_metadata_location(slice)[b + 1]); beam.resize(beam_slice, num_particles, 0); auto& soa = beam.getBeamSlice(beam_slice).GetStructOfArrays(); diff --git a/src/utils/OMPUtil.H b/src/utils/OMPUtil.H index 5de18e36d1..bd0311ef6a 100644 --- a/src/utils/OMPUtil.H +++ b/src/utils/OMPUtil.H @@ -26,7 +26,7 @@ using amrex::ParallelFor; // 1D ParallelFor template -void ParallelFor (T n, F&& f) noexcept +void ParallelFor (T n, const F& f) noexcept { #pragma omp parallel for simd for (T i = 0; i < n; ++i) { diff --git a/src/utils/Parser.H b/src/utils/Parser.H index 3340484487..9059d59881 100755 --- a/src/utils/Parser.H +++ b/src/utils/Parser.H @@ -182,8 +182,8 @@ namespace Parser // use my_constants directly (with recursive string parsing) if available // also check in local and global namespaces, same as the amrex parser AMREX_ALWAYS_ASSERT_WITH_MESSAGE( - recursive_symbols.count(parse_string) == 0, - "Expression '" + str + "' contains recursive symbol '" + parse_string + "'!\n" + !recursive_symbols.contains(parse_string), + "Expression '" + str + "' contains recursive symbol '" + parse_string + "'!\n" ); std::string replacer; if (amrex::ParmParse{}.contains(parse_string.c_str())) { @@ -303,7 +303,7 @@ namespace Parser amrex::ToString(n) + " should be " + amrex::ToString(AMREX_SPACEDIM) + "\n" ); for (auto i=0ul ; i != n ; ++i) { - fillWithParser(pp, str_arr[i], val_arr[i]); + fillWithParser(pp, str_arr[i], val_arr[int(i)]); } } @@ -317,7 +317,7 @@ namespace Parser amrex::ToString(n) + " should be " + amrex::ToString(AMREX_SPACEDIM) + "\n" ); for (auto i=0ul ; i != n ; ++i) { - fillWithParser(pp, str_arr[i], val_arr[i]); + fillWithParser(pp, str_arr[i], val_arr[int(i)]); } } diff --git a/src/utils/Parser.cpp b/src/utils/Parser.cpp index c012fddd64..9b4a39d31d 100644 --- a/src/utils/Parser.cpp +++ b/src/utils/Parser.cpp @@ -28,7 +28,7 @@ namespace Parser { "\"=\" or \"=[,,]\"." " Got: \"" + s + "\""; - auto pos = s.find_first_of("="); + auto pos = s.find_first_of('='); AMREX_ALWAYS_ASSERT_WITH_MESSAGE(pos != std::string::npos, abort_str); @@ -73,25 +73,25 @@ namespace Parser { if (local_variables_names.size() == 0) { auto exe = makeFunctionWithParser<0>(inputs[0], func_parser, {}, pp); - std::cout << "\nParser Debug Print \"" << inputs[0] << "\" = " - << exe() << "\n" << std::endl; + amrex::OutStream() << "\nParser Debug Print \"" << inputs[0] << "\" = " + << exe() << "\n\n"; } else if (local_variables_names.size() == 1) { auto exe = makeFunctionWithParser<1>(inputs[0], func_parser, local_variables_names, pp); - std::cout << "\nParser Debug Print \"" << inputs[0] << "\" = ["; + amrex::OutStream() << "\nParser Debug Print \"" << inputs[0] << "\" = ["; auto [lo, hi, n] = local_variables_bounds[0]; const double dx = (hi-lo)/(n-1); for (int i=0; i 0) { - std::cout << ", "; + amrex::OutStream() << ", "; } - std::cout << val; + amrex::OutStream() << val; } - std::cout << "]\n" << std::endl; + amrex::OutStream() << "]\n\n"; } else if (local_variables_names.size() == 2) { auto exe = makeFunctionWithParser<2>(inputs[0], func_parser, local_variables_names, pp); - std::cout << "\nParser Debug Print \"" << inputs[0] << "\" = ["; + amrex::OutStream() << "\nParser Debug Print \"" << inputs[0] << "\" = ["; auto [lox, hix, nx] = local_variables_bounds[0]; auto [loy, hiy, ny] = local_variables_bounds[1]; const double dx = (hix-lox)/(nx-1); @@ -99,23 +99,23 @@ namespace Parser { for (int j=0; j 0) { - std::cout << ",\n"; + amrex::OutStream() << ",\n"; } - std::cout << "["; + amrex::OutStream() << "["; for (int i=0; i 0) { - std::cout << ", "; + amrex::OutStream() << ", "; } - std::cout << val; + amrex::OutStream() << val; } - std::cout << "]"; + amrex::OutStream() << "]"; } - std::cout << "]\n" << std::endl; + amrex::OutStream() << "]\n\n"; } else if (local_variables_names.size() == 3) { auto exe = makeFunctionWithParser<3>(inputs[0], func_parser, local_variables_names, pp); - std::cout << "\nParser Debug Print \"" << inputs[0] << "\" = ["; + amrex::OutStream() << "\nParser Debug Print \"" << inputs[0] << "\" = ["; auto [lox, hix, nx] = local_variables_bounds[0]; auto [loy, hiy, ny] = local_variables_bounds[1]; auto [loz, hiz, nz] = local_variables_bounds[2]; @@ -125,31 +125,31 @@ namespace Parser { for (int k=0; k 0) { - std::cout << ",\n\n"; + amrex::OutStream() << ",\n\n"; } - std::cout << "["; + amrex::OutStream() << "["; for (int j=0; j 0) { - std::cout << ",\n"; + amrex::OutStream() << ",\n"; } - std::cout << "["; + amrex::OutStream() << "["; for (int i=0; i 0) { - std::cout << ", "; + amrex::OutStream() << ", "; } - std::cout << val; + amrex::OutStream() << val; } - std::cout << "]"; + amrex::OutStream() << "]"; } - std::cout << "]"; + amrex::OutStream() << "]"; } - std::cout << "]\n" << std::endl; + amrex::OutStream() << "]\n\n"; } else if (local_variables_names.size() == 4) { auto exe = makeFunctionWithParser<4>(inputs[0], func_parser, local_variables_names, pp); - std::cout << "\nParser Debug Print \"" << inputs[0] << "\" = ["; + amrex::OutStream() << "\nParser Debug Print \"" << inputs[0] << "\" = ["; auto [lox, hix, nx] = local_variables_bounds[0]; auto [loy, hiy, ny] = local_variables_bounds[1]; auto [loz, hiz, nz] = local_variables_bounds[2]; @@ -161,39 +161,40 @@ namespace Parser { for (int l=0; l 0) { - std::cout << ",\n\n\n"; + amrex::OutStream() << ",\n\n\n"; } - std::cout << "["; + amrex::OutStream() << "["; for (int k=0; k 0) { - std::cout << ",\n\n"; + amrex::OutStream() << ",\n\n"; } - std::cout << "["; + amrex::OutStream() << "["; for (int j=0; j 0) { - std::cout << ",\n"; + amrex::OutStream() << ",\n"; } - std::cout << "["; + amrex::OutStream() << "["; for (int i=0; i 0) { - std::cout << ", "; + amrex::OutStream() << ", "; } - std::cout << val; + amrex::OutStream() << val; } - std::cout << "]"; + amrex::OutStream() << "]"; } - std::cout << "]"; + amrex::OutStream() << "]"; } - std::cout << "]"; + amrex::OutStream() << "]"; } - std::cout << "]\n" << std::endl; + amrex::OutStream() << "]\n\n"; } else { amrex::Abort("DebugPrint(): Only supports up to 4 variables"); } + amrex::OutStream().flush(); } }