diff --git a/.clang-tidy b/.clang-tidy index c39b96d30..c52496b4f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -3,6 +3,7 @@ Checks: '-*, -bugprone-easily-swappable-parameters, -bugprone-implicit-widening-of-multiplication-result, -bugprone-misplaced-widening-cast, + -bugprone-unchecked-optional-access, cert-* -cert-err58-cpp, cppcoreguidelines-avoid-goto, @@ -50,6 +51,8 @@ Checks: '-*, performance-move-constructor-init, performance-no-automatic-move, performance-no-int-to-ptr, + performance-unnecessary-copy-initialization, + performance-unnecessary-value-param, readability-avoid-const-params-in-decls, readability-const-return-type, readability-container-contains, diff --git a/src/initialization/InitAmrCore.cpp b/src/initialization/InitAmrCore.cpp index 5a1f0be8b..18412dd2a 100644 --- a/src/initialization/InitAmrCore.cpp +++ b/src/initialization/InitAmrCore.cpp @@ -73,7 +73,7 @@ namespace details default_init_AMReX(); } - amrex::ParmParse pp_amr("amr"); + amrex::ParmParse const pp_amr("amr"); amrex::Vector n_cell(AMREX_SPACEDIM); bool const has_ncell = pp_amr.queryarr("n_cell", n_cell); @@ -86,18 +86,18 @@ namespace details AmrCoreData amrex_amrcore_gridding () { - amrex::ParmParse pp_amr("amr"); + amrex::ParmParse const pp_amr("amr"); // Domain index space - we use temporary values here, then fix later - amrex::Vector n_cell = {AMREX_D_DECL(256,256,256)}; - amrex::Box domain(amrex::IntVect(0), amrex::IntVect(n_cell)); + amrex::Vector const n_cell = {AMREX_D_DECL(256,256,256)}; + amrex::Box const domain(amrex::IntVect(0), amrex::IntVect(n_cell)); // Domain physical size // we might resize this dynamically auto rb = details::init_physical_domain(); // Periodicity (none) - amrex::Array is_periodic{AMREX_D_DECL(0,0,0)}; + amrex::Array const is_periodic{AMREX_D_DECL(0,0,0)}; // Mesh-refinement int max_level = 0; @@ -116,11 +116,11 @@ namespace details const int nprocs = amrex::ParallelDescriptor::NProcs(); const amrex::IntVect high_end = amr_info.blocking_factor[0] * amrex::IntVect(AMREX_D_DECL(nprocs,1,1)) - amrex::IntVect(1); - amrex::Box domain(amrex::IntVect(0), high_end); + amrex::Box const domain(amrex::IntVect(0), high_end); // adding amr.n_cell for consistency amrex::ParmParse pp_amr("amr"); auto const n_cell_iv = domain.size(); - amrex::Vector n_cell_v(n_cell_iv.begin(), n_cell_iv.end()); + amrex::Vector const n_cell_v(n_cell_iv.begin(), n_cell_iv.end()); pp_amr.addarr("n_cell", n_cell_v); // Domain physical size @@ -128,9 +128,9 @@ namespace details auto rb = details::init_physical_domain(); // Periodicity (none) - amrex::Array is_periodic{AMREX_D_DECL(0,0,0)}; + amrex::Array const is_periodic{AMREX_D_DECL(0,0,0)}; - amrex::Geometry geom(domain, rb, amrex::CoordSys::cartesian, is_periodic); + amrex::Geometry const geom(domain, rb, amrex::CoordSys::cartesian, is_periodic); return {geom, amr_info}; } } // namespace impactx::initialization diff --git a/src/initialization/InitElement.cpp b/src/initialization/InitElement.cpp index 4f3a4a000..78630acba 100644 --- a/src/initialization/InitElement.cpp +++ b/src/initialization/InitElement.cpp @@ -58,7 +58,7 @@ namespace detail * @param[in] nslice_default * @param[in] mapsteps_default */ - void read_element (std::string element_name, + void read_element (std::string const & element_name, std::list & m_lattice, int nslice_default, int mapsteps_default) @@ -94,7 +94,7 @@ namespace detail int nslice = nslice_default; pp_element.get("ds", ds); pp_element.get("rc", rc); - pp_element.get("k", k); + pp_element.get("k", k); pp_element.queryAdd("nslice", nslice); m_lattice.emplace_back( CFbend(ds, rc, k, nslice) ); } else if (element_type == "dipedge") { @@ -216,14 +216,14 @@ namespace detail m_lattice.emplace_back( ExactDrift(ds, nslice) ); } else if (element_type == "sbend_exact") { amrex::Real ds, phi; - amrex::Real B = 0.0; + amrex::Real B = 0.0; int nslice = nslice_default; pp_element.get("ds", ds); pp_element.get("phi", phi); pp_element.queryAdd("B", B); pp_element.queryAdd("nslice", nslice); m_lattice.emplace_back( ExactSbend(ds, phi, B, nslice) ); - } else if (element_type == "uniform_acc_chromatic") { + } else if (element_type == "uniform_acc_chromatic") { amrex::Real ds, ez, bz; int nslice = nslice_default; pp_element.get("ds", ds); @@ -252,7 +252,7 @@ namespace detail pp_element.queryAdd("encoding", openpmd_encoding); m_lattice.emplace_back(diagnostics::BeamMonitor(openpmd_name, openpmd_backend, openpmd_encoding)); } else if (element_type == "line") { - // Parse the lattice elements + // Parse the lattice elements for the sub-lattice in the line amrex::ParmParse pp_sub_lattice(element_name); std::vector sub_lattice_elements; pp_sub_lattice.queryarr("elements", sub_lattice_elements); diff --git a/src/initialization/InitMeshRefinement.cpp b/src/initialization/InitMeshRefinement.cpp index 6301fdd9d..d9eef334e 100644 --- a/src/initialization/InitMeshRefinement.cpp +++ b/src/initialization/InitMeshRefinement.cpp @@ -52,7 +52,7 @@ namespace impactx }; // charge (rho) mesh - amrex::BoxArray const cba = ba; + amrex::BoxArray const& cba = ba; // for MR levels (TODO): //cba.coarsen(refRatio(lev - 1)); diff --git a/src/initialization/Warnings.cpp b/src/initialization/Warnings.cpp index 0ec5c0e53..738d90021 100644 --- a/src/initialization/Warnings.cpp +++ b/src/initialization/Warnings.cpp @@ -58,7 +58,7 @@ bool ImpactX::early_param_check () BL_PROFILE("ImpactX::early_param_check"); amrex::Print() << "\n"; - amrex::ParmParse().QueryUnusedInputs(); + amrex::ParmParse::QueryUnusedInputs(); // Print the warning list right after the first step. amrex::Print() << ablastr::warn_manager::GetWMInstance() diff --git a/src/particles/ImpactXParticleContainer.H b/src/particles/ImpactXParticleContainer.H index e2b5261c8..6c0adf1d1 100644 --- a/src/particles/ImpactXParticleContainer.H +++ b/src/particles/ImpactXParticleContainer.H @@ -182,7 +182,7 @@ namespace impactx * @param refpart reference particle */ void - SetRefParticle (RefPart const refpart); + SetRefParticle (RefPart const & refpart); /** Get reference particle attributes * @@ -224,7 +224,7 @@ namespace impactx * * @param order the order of the particle shape */ - void SetParticleShape (int const order); + void SetParticleShape (int order); /** Compute the min and max of the particle position in each dimension * diff --git a/src/particles/ImpactXParticleContainer.cpp b/src/particles/ImpactXParticleContainer.cpp index b8d69d306..c587694d4 100644 --- a/src/particles/ImpactXParticleContainer.cpp +++ b/src/particles/ImpactXParticleContainer.cpp @@ -57,7 +57,7 @@ namespace impactx SetParticleSize(); } - void ImpactXParticleContainer::SetParticleShape (int const order) { + void ImpactXParticleContainer::SetParticleShape (int order) { if (m_particle_shape.has_value()) { throw std::logic_error( @@ -155,7 +155,7 @@ namespace impactx } void - ImpactXParticleContainer::SetRefParticle (RefPart const refpart) + ImpactXParticleContainer::SetRefParticle (RefPart const & refpart) { m_refpart = refpart; } diff --git a/src/particles/diagnostics/DiagnosticOutput.H b/src/particles/diagnostics/DiagnosticOutput.H index 7c3a593fe..7a0881092 100644 --- a/src/particles/diagnostics/DiagnosticOutput.H +++ b/src/particles/diagnostics/DiagnosticOutput.H @@ -40,10 +40,10 @@ namespace impactx::diagnostics * @param append open a new file with a fresh header (false) or append data to an existing file (true) */ void DiagnosticOutput (ImpactXParticleContainer const & pc, - OutputType const otype, + OutputType otype, std::string file_name, - int const step = 0, - bool const append = false); + int step = 0, + bool append = false); } // namespace impactx::diagnostics diff --git a/src/particles/diagnostics/DiagnosticOutput.cpp b/src/particles/diagnostics/DiagnosticOutput.cpp index 835955a89..703dbff48 100644 --- a/src/particles/diagnostics/DiagnosticOutput.cpp +++ b/src/particles/diagnostics/DiagnosticOutput.cpp @@ -19,21 +19,23 @@ #include // for ParticleReal #include // for PrintToFile +#include + namespace impactx::diagnostics { void DiagnosticOutput (ImpactXParticleContainer const & pc, OutputType const otype, std::string file_name, - int const step, - bool const append) + int step, + bool append) { BL_PROFILE("impactx::diagnostics::DiagnosticOutput"); using namespace amrex::literals; // for _rt and _prt // keep file open as we add more and more lines - amrex::AllPrintToFile file_handler(file_name); + amrex::AllPrintToFile file_handler(std::move(file_name)); // write file header per MPI RANK if (!append) { diff --git a/src/particles/diagnostics/NonlinearLensInvariants.H b/src/particles/diagnostics/NonlinearLensInvariants.H index 8f1104d42..8713b4c73 100644 --- a/src/particles/diagnostics/NonlinearLensInvariants.H +++ b/src/particles/diagnostics/NonlinearLensInvariants.H @@ -80,16 +80,16 @@ namespace impactx::diagnostics using Complex = amrex::GpuComplex; // convert transverse phase space coordinates to normalized units - amrex::ParticleReal xn = x/(m_cn*sqrt(m_beta)); - amrex::ParticleReal yn = y/(m_cn*sqrt(m_beta)); - amrex::ParticleReal pxn = px*sqrt(m_beta)/m_cn + m_alpha*x; - amrex::ParticleReal pyn = py*sqrt(m_beta)/m_cn + m_alpha*y; + amrex::ParticleReal const xn = x/(m_cn*sqrt(m_beta)); + amrex::ParticleReal const yn = y/(m_cn*sqrt(m_beta)); + amrex::ParticleReal const pxn = px*sqrt(m_beta)/m_cn + m_alpha*x; + amrex::ParticleReal const pyn = py*sqrt(m_beta)/m_cn + m_alpha*y; // assign complex position zeta = x + iy - Complex zeta(xn, yn); - Complex zetaconj(xn, -yn); - Complex re1(1.0_prt, 0.0_prt); - Complex im1(0.0_prt, 1.0_prt); + Complex const zeta(xn, yn); + Complex const zetaconj(xn, -yn); + Complex const re1(1.0_prt, 0.0_prt); + Complex const im1(0.0_prt, 1.0_prt); // compute croot = sqrt(1-zeta**2) Complex croot = amrex::pow(zeta, 2); @@ -113,7 +113,7 @@ namespace impactx::diagnostics amrex::ParticleReal Iinv = Ipotential.m_real; // compute invariants H and I - amrex::ParticleReal Jz = xn*pyn - yn*pxn; + amrex::ParticleReal const Jz = xn*pyn - yn*pxn; Hinv = (pow(xn,2) + pow(yn,2) + pow(pxn,2) + pow(pyn,2))/2 + m_tn*Hinv; Iinv = pow(Jz,2) + pow(pxn,2) + pow(xn,2) + m_tn*Iinv; diff --git a/src/particles/distribution/All.H b/src/particles/distribution/All.H index 81ee15d7c..e3a833708 100644 --- a/src/particles/distribution/All.H +++ b/src/particles/distribution/All.H @@ -22,9 +22,7 @@ #include -namespace impactx -{ -namespace distribution +namespace impactx::distribution { using KnownDistributions = std::variant< None, /* must be first, so KnownDistributions creates a default constructor */ @@ -37,7 +35,6 @@ namespace distribution Waterbag >; -} // namespace distribution -} // namespace impactx +} // namespace impactx::distribution #endif // IMPACTX_DISTRIBUTION_ALL_H diff --git a/src/particles/distribution/Gaussian.H b/src/particles/distribution/Gaussian.H index c8b5f46ed..16adf7800 100644 --- a/src/particles/distribution/Gaussian.H +++ b/src/particles/distribution/Gaussian.H @@ -16,9 +16,7 @@ #include -namespace impactx -{ -namespace distribution +namespace impactx::distribution { struct Gaussian { @@ -112,7 +110,6 @@ namespace distribution amrex::ParticleReal m_muxpx,m_muypy,m_mutpt; //! correlation length-momentum }; -} // namespace distribution -} // namespace impactx +} // namespace impactx::distribution #endif // IMPACTX_DISTRIBUTION_GAUSSIAN diff --git a/src/particles/distribution/KVdist.H b/src/particles/distribution/KVdist.H index 4403825cc..42843e537 100644 --- a/src/particles/distribution/KVdist.H +++ b/src/particles/distribution/KVdist.H @@ -16,9 +16,7 @@ #include -namespace impactx -{ -namespace distribution +namespace impactx::distribution { struct KVdist { @@ -94,7 +92,7 @@ namespace distribution pt = ln1*cos(2_prt*pi*u2); // Scale to produce the identity covariance matrix: - amrex::ParticleReal c = sqrt(3.0_prt); + amrex::ParticleReal const c = sqrt(3.0_prt); x = 2_prt*x; y = 2_prt*y; t = c*t; @@ -125,7 +123,6 @@ namespace distribution amrex::ParticleReal m_muxpx,m_muypy,m_mutpt; //! correlation length-momentum }; -} // namespace distribution -} // namespace impactx +} // namespace impactx::distribution #endif // IMPACTX_DISTRIBUTION_KVDIST diff --git a/src/particles/distribution/Kurth4D.H b/src/particles/distribution/Kurth4D.H index 709b23791..c436d73b9 100644 --- a/src/particles/distribution/Kurth4D.H +++ b/src/particles/distribution/Kurth4D.H @@ -16,9 +16,7 @@ #include -namespace impactx -{ -namespace distribution +namespace impactx::distribution { struct Kurth4D { @@ -104,7 +102,7 @@ namespace distribution pt = ln1*cos(2_prt*pi*u2); // Scale to produce the identity covariance matrix: - amrex::ParticleReal c = sqrt(3.0_prt); + amrex::ParticleReal const c = sqrt(3.0_prt); x = 2_prt*x; y = 2_prt*y; t = c*t; @@ -135,7 +133,6 @@ namespace distribution amrex::ParticleReal m_muxpx,m_muypy,m_mutpt; //! correlation length-momentum }; -} // namespace distribution -} // namespace impactx +} // namespace impactx::distribution #endif // IMPACTX_DISTRIBUTION_KURTH4D diff --git a/src/particles/distribution/Kurth6D.H b/src/particles/distribution/Kurth6D.H index 675f5ea9c..d32216a00 100644 --- a/src/particles/distribution/Kurth6D.H +++ b/src/particles/distribution/Kurth6D.H @@ -16,9 +16,7 @@ #include -namespace impactx -{ -namespace distribution +namespace impactx::distribution { struct Kurth6D { @@ -110,7 +108,7 @@ namespace distribution pt = pr*costheta - p2*sintheta; // Scale to produce the identity covariance matrix: - amrex::ParticleReal c = sqrt(5.0_prt); + amrex::ParticleReal const c = sqrt(5.0_prt); x = c*x; y = c*y; t = c*t; @@ -141,7 +139,6 @@ namespace distribution amrex::ParticleReal m_muxpx,m_muypy,m_mutpt; //! correlation length-momentum }; -} // namespace distribution -} // namespace impactx +} // namespace impactx::distribution #endif // IMPACTX_DISTRIBUTION_KURTH6D diff --git a/src/particles/distribution/None.H b/src/particles/distribution/None.H index 001ea3034..8ed85b7ac 100644 --- a/src/particles/distribution/None.H +++ b/src/particles/distribution/None.H @@ -14,9 +14,7 @@ #include -namespace impactx -{ -namespace distribution +namespace impactx::distribution { struct None { @@ -52,7 +50,6 @@ namespace distribution } }; -} // namespace distribution -} // namespace impactx +} // namespace impactx::distribution #endif // IMPACTX_DISTRIBUTION_NONE diff --git a/src/particles/distribution/Semigaussian.H b/src/particles/distribution/Semigaussian.H index a5d8762e5..652bd03d1 100644 --- a/src/particles/distribution/Semigaussian.H +++ b/src/particles/distribution/Semigaussian.H @@ -16,9 +16,7 @@ #include -namespace impactx -{ -namespace distribution +namespace impactx::distribution { struct Semigaussian { @@ -83,7 +81,7 @@ namespace distribution t = 2_prt*(t-0.5_prt); // Scale to produce the identity covariance matrix: - amrex::ParticleReal c = sqrt(3.0_prt); + amrex::ParticleReal const c = sqrt(3.0_prt); x = 2_prt*x; y = 2_prt*y; t = c*t; @@ -124,7 +122,6 @@ namespace distribution amrex::ParticleReal m_muxpx,m_muypy,m_mutpt; //! correlation length-momentum }; -} // namespace distribution -} // namespace impactx +} // namespace impactx::distribution #endif // IMPACTX_DISTRIBUTION_SEMIGAUSSIAN diff --git a/src/particles/distribution/Triangle.H b/src/particles/distribution/Triangle.H index 492072665..0a761982a 100644 --- a/src/particles/distribution/Triangle.H +++ b/src/particles/distribution/Triangle.H @@ -18,9 +18,7 @@ #include -namespace impactx -{ -namespace distribution +namespace impactx::distribution { struct Triangle { @@ -139,7 +137,6 @@ namespace distribution amrex::ParticleReal m_muxpx, m_muypy, m_mutpt; //! correlation length-momentum }; -} // namespace distribution -} // namespace impactx +} // namespace impactx::distribution #endif // IMPACTX_DISTRIBUTION_TRIANGLE diff --git a/src/particles/distribution/Waterbag.H b/src/particles/distribution/Waterbag.H index c14d3dec4..30a7f1d10 100644 --- a/src/particles/distribution/Waterbag.H +++ b/src/particles/distribution/Waterbag.H @@ -16,9 +16,7 @@ #include -namespace impactx -{ -namespace distribution +namespace impactx::distribution { struct Waterbag { @@ -129,7 +127,6 @@ namespace distribution amrex::ParticleReal m_muxpx,m_muypy,m_mutpt; //! correlation length-momentum }; -} // namespace distribution -} // namespace impactx +} // namespace impactx::distribution #endif // IMPACTX_DISTRIBUTION_WATERBAG diff --git a/src/particles/elements/ChrDrift.H b/src/particles/elements/ChrDrift.H index 70dae024f..389b2d189 100644 --- a/src/particles/elements/ChrDrift.H +++ b/src/particles/elements/ChrDrift.H @@ -71,9 +71,9 @@ namespace impactx amrex::ParticleReal const t = p.pos(RealAoS::t); // initialize output values of momenta - amrex::ParticleReal pxout = px; - amrex::ParticleReal pyout = py; - amrex::ParticleReal ptout = pt; + amrex::ParticleReal const pxout = px; + amrex::ParticleReal const pyout = py; + amrex::ParticleReal const ptout = pt; // length of the current slice amrex::ParticleReal const slice_ds = m_ds / nslice(); diff --git a/src/particles/elements/ChrQuad.H b/src/particles/elements/ChrQuad.H index 8f381e8e8..81ad83b28 100644 --- a/src/particles/elements/ChrQuad.H +++ b/src/particles/elements/ChrQuad.H @@ -95,7 +95,7 @@ namespace impactx // compute particle momentum deviation delta + 1 amrex::ParticleReal delta1; delta1 = sqrt(1_prt - 2_prt*pt/bet + pow(pt,2)); - amrex::ParticleReal delta = delta1 - 1_prt; + amrex::ParticleReal const delta = delta1 - 1_prt; // compute phase advance per unit length in s (in rad/m) // chromatic dependence on delta is included @@ -104,7 +104,7 @@ namespace impactx // intialize output values of momenta amrex::ParticleReal pxout = px; amrex::ParticleReal pyout = py; - amrex::ParticleReal ptout = pt; + amrex::ParticleReal const ptout = pt; // paceholder variables amrex::ParticleReal q1 = x; @@ -142,15 +142,15 @@ namespace impactx // advance longitudinal position and momentum // the corresponding symplectic update to t - amrex::ParticleReal term = pt + delta/bet; - amrex::ParticleReal t0 = t - term*slice_ds/delta1; - - amrex::ParticleReal w = omega*delta1; - amrex::ParticleReal term1 = -(pow(p2,2)+pow(q2,2)*pow(w,2))*sinh(2_prt*slice_ds*omega); - amrex::ParticleReal term2 = -(pow(p1,2)-pow(q1,2)*pow(w,2))*sin(2_prt*slice_ds*omega); - amrex::ParticleReal term3 = -2_prt*q2*p2*w*cosh(2_prt*slice_ds*omega); - amrex::ParticleReal term4 = -2_prt*q1*p1*w*cos(2_prt*slice_ds*omega); - amrex::ParticleReal term5 = 2_prt*omega*(q1*p1*delta1 + q2*p2*delta1 + amrex::ParticleReal const term = pt + delta/bet; + amrex::ParticleReal const t0 = t - term*slice_ds/delta1; + + amrex::ParticleReal const w = omega*delta1; + amrex::ParticleReal const term1 = -(pow(p2,2)+pow(q2,2)*pow(w,2))*sinh(2_prt*slice_ds*omega); + amrex::ParticleReal const term2 = -(pow(p1,2)-pow(q1,2)*pow(w,2))*sin(2_prt*slice_ds*omega); + amrex::ParticleReal const term3 = -2_prt*q2*p2*w*cosh(2_prt*slice_ds*omega); + amrex::ParticleReal const term4 = -2_prt*q1*p1*w*cos(2_prt*slice_ds*omega); + amrex::ParticleReal const term5 = 2_prt*omega*(q1*p1*delta1 + q2*p2*delta1 -(pow(p1,2)+pow(p2,2))*slice_ds - (pow(q1,2)-pow(q2,2))*pow(w,2)*slice_ds); p.pos(RealAoS::t) = t0 + (-1_prt+bet*pt)/(8_prt*bet*pow(delta1,3)*omega) *(term1+term2+term3+term4+term5); diff --git a/src/particles/elements/Drift.H b/src/particles/elements/Drift.H index f14ba3fb9..fdfdd57cd 100644 --- a/src/particles/elements/Drift.H +++ b/src/particles/elements/Drift.H @@ -68,9 +68,9 @@ namespace impactx amrex::ParticleReal const t = p.pos(RealAoS::t); // initialize output values of momenta - amrex::ParticleReal pxout = px; - amrex::ParticleReal pyout = py; - amrex::ParticleReal ptout = pt; + amrex::ParticleReal const pxout = px; + amrex::ParticleReal const pyout = py; + amrex::ParticleReal const ptout = pt; // length of the current slice amrex::ParticleReal const slice_ds = m_ds / nslice(); diff --git a/src/particles/elements/ExactDrift.H b/src/particles/elements/ExactDrift.H index a74766b04..158d9b08f 100644 --- a/src/particles/elements/ExactDrift.H +++ b/src/particles/elements/ExactDrift.H @@ -69,9 +69,9 @@ namespace impactx amrex::ParticleReal const t = p.pos(RealAoS::t); // initialize output values of momenta - amrex::ParticleReal pxout = px; - amrex::ParticleReal pyout = py; - amrex::ParticleReal ptout = pt; + amrex::ParticleReal const pxout = px; + amrex::ParticleReal const pyout = py; + amrex::ParticleReal const ptout = pt; // length of the current slice amrex::ParticleReal const slice_ds = m_ds / nslice(); @@ -81,7 +81,7 @@ namespace impactx amrex::ParticleReal const betgam = refpart.beta_gamma(); // compute the radical in the denominator (= pz): - amrex::ParticleReal pzden = sqrt(pow(pt-1_prt/bet,2) - + amrex::ParticleReal const pzden = sqrt(pow(pt-1_prt/bet,2) - 1_prt/pow(betgam,2) - pow(px,2) - pow(py,2)); // advance position and momentum (exact drift) diff --git a/src/particles/elements/NonlinearLens.H b/src/particles/elements/NonlinearLens.H index 7175a0b47..51fb3861b 100644 --- a/src/particles/elements/NonlinearLens.H +++ b/src/particles/elements/NonlinearLens.H @@ -89,8 +89,8 @@ namespace impactx // assign complex position zeta = (x + iy)/cnll Complex zeta(x, y); zeta = zeta/m_cnll; - Complex re1(1.0_prt, 0.0_prt); - Complex im1(0.0_prt, 1.0_prt); + Complex const re1(1.0_prt, 0.0_prt); + Complex const im1(0.0_prt, 1.0_prt); // compute croot = sqrt(1-zeta**2) Complex croot = amrex::pow(zeta, 2); @@ -106,9 +106,9 @@ namespace impactx dF = dF + carcsin/amrex::pow(croot,3); // compute momentum kick - amrex::ParticleReal kick = -m_knll/m_cnll; - amrex::ParticleReal dpx = kick*dF.m_real; - amrex::ParticleReal dpy = -kick*dF.m_imag; + amrex::ParticleReal const kick = -m_knll/m_cnll; + amrex::ParticleReal const dpx = kick*dF.m_real; + amrex::ParticleReal const dpy = -kick*dF.m_imag; // advance position and momentum p.pos(RealAoS::x) = x; diff --git a/src/particles/elements/PRot.H b/src/particles/elements/PRot.H index 87a712e7e..f4bb49deb 100644 --- a/src/particles/elements/PRot.H +++ b/src/particles/elements/PRot.H @@ -84,10 +84,10 @@ namespace impactx amrex::ParticleReal ptout = pt; // store rotation angle and initial, final values of pz - amrex::ParticleReal theta = m_phi_out - m_phi_in; - amrex::ParticleReal pz = sqrt(1.0_prt - 2.0_prt*pt/beta + amrex::ParticleReal const theta = m_phi_out - m_phi_in; + amrex::ParticleReal const pz = sqrt(1.0_prt - 2.0_prt*pt/beta + pow(pt,2) - pow(py,2) - pow(px + sin(m_phi_in),2)); - amrex::ParticleReal pzf = pz*cos(theta) - (px + + amrex::ParticleReal const pzf = pz*cos(theta) - (px + sin(m_phi_in))*sin(theta); // advance position and momentum diff --git a/src/particles/elements/Quad.H b/src/particles/elements/Quad.H index 30fd2057b..c15c27bbf 100644 --- a/src/particles/elements/Quad.H +++ b/src/particles/elements/Quad.H @@ -85,7 +85,7 @@ namespace impactx // intialize output values of momenta amrex::ParticleReal pxout = px; amrex::ParticleReal pyout = py; - amrex::ParticleReal ptout = pt; + amrex::ParticleReal const ptout = pt; if(m_k > 0.0) { // advance position and momentum (focusing quad) diff --git a/src/particles/elements/RFCavity.H b/src/particles/elements/RFCavity.H index 32c92ac76..86ac3154a 100644 --- a/src/particles/elements/RFCavity.H +++ b/src/particles/elements/RFCavity.H @@ -136,7 +136,7 @@ namespace RFCavityData RFCavityData::next_id++; // validate sin and cos coefficients are the same length - m_ncoef = cos_coef.size(); + m_ncoef = int(cos_coef.size()); if (m_ncoef != int(sin_coef.size())) throw std::runtime_error("RFCavity: cos and sin coefficients must have same length!"); diff --git a/src/particles/elements/Sbend.H b/src/particles/elements/Sbend.H index ac7d49e3a..509a242c5 100644 --- a/src/particles/elements/Sbend.H +++ b/src/particles/elements/Sbend.H @@ -71,8 +71,8 @@ namespace impactx // initialize output values of momenta amrex::ParticleReal pxout = px; - amrex::ParticleReal pyout = py; - amrex::ParticleReal ptout = pt; + amrex::ParticleReal const pyout = py; + amrex::ParticleReal const ptout = pt; // length of the current slice amrex::ParticleReal const slice_ds = m_ds / nslice(); diff --git a/src/particles/elements/SoftQuad.H b/src/particles/elements/SoftQuad.H index 3fa7f0a84..481a72368 100644 --- a/src/particles/elements/SoftQuad.H +++ b/src/particles/elements/SoftQuad.H @@ -141,7 +141,7 @@ namespace SoftQuadrupoleData SoftQuadrupoleData::next_id++; // validate sin and cos coefficients are the same length - m_ncoef = cos_coef.size(); + m_ncoef = int(cos_coef.size()); if (m_ncoef != int(sin_coef.size())) throw std::runtime_error("SoftQuadrupole: cos and sin coefficients must have same length!"); diff --git a/src/particles/elements/SoftSol.H b/src/particles/elements/SoftSol.H index 46276022f..4e617efdd 100644 --- a/src/particles/elements/SoftSol.H +++ b/src/particles/elements/SoftSol.H @@ -146,7 +146,7 @@ namespace SoftSolenoidData SoftSolenoidData::next_id++; // validate sin and cos coefficients are the same length - m_ncoef = cos_coef.size(); + m_ncoef = int(cos_coef.size()); if (m_ncoef != int(sin_coef.size())) throw std::runtime_error("SoftSolenoid: cos and sin coefficients must have same length!"); diff --git a/src/particles/elements/diagnostics/openPMD.cpp b/src/particles/elements/diagnostics/openPMD.cpp index 4b61e5358..96e8d8146 100644 --- a/src/particles/elements/diagnostics/openPMD.cpp +++ b/src/particles/elements/diagnostics/openPMD.cpp @@ -109,7 +109,7 @@ namespace detail * @return pair of openPMD record and component name */ inline std::pair< std::string, std::string > - name2openPMD ( std::string const& fullName ) + name2openPMD ( const std::string& fullName ) { std::string record_name = fullName; std::string component_name = io::RecordComponent::SCALAR; @@ -126,10 +126,10 @@ namespace detail // TODO: move to ablastr io::RecordComponent get_component_record ( io::ParticleSpecies & species, - std::string const comp_name + std::string comp_name ) { // handle scalar and non-scalar records by name - const auto [record_name, component_name] = name2openPMD(comp_name); + const auto [record_name, component_name] = name2openPMD(std::move(comp_name)); return species[record_name][component_name]; } #endif @@ -240,8 +240,8 @@ namespace detail // helpers to parse strings to openPMD auto const scalar = openPMD::RecordComponent::SCALAR; - auto const getComponentRecord = [&beam](std::string const comp_name) { - return detail::get_component_record(beam, comp_name); + auto const getComponentRecord = [&beam](std::string comp_name) { + return detail::get_component_record(beam, std::move(comp_name)); }; // define data set and metadata @@ -377,8 +377,8 @@ namespace detail //if (numParticleOnTile == 0) continue; auto const scalar = openPMD::RecordComponent::SCALAR; - auto const getComponentRecord = [&beam](std::string const comp_name) { - return detail::get_component_record(beam, comp_name); + auto const getComponentRecord = [&beam](std::string comp_name) { + return detail::get_component_record(beam, std::move(comp_name)); }; // AoS: position and particle ID @@ -393,7 +393,7 @@ namespace detail for (auto i = 0; i < numParticleOnTile; i++) { curr.get()[i] = aos[i].pos(currDim); } - std::string const positionComponent = positionComponents[currDim]; + std::string const& positionComponent = positionComponents[currDim]; beam["position"][positionComponent].storeChunk(curr, {offset}, {numParticleOnTile64}); } diff --git a/src/particles/elements/mixin/beamoptic.H b/src/particles/elements/mixin/beamoptic.H index d272b2aee..e4908463a 100644 --- a/src/particles/elements/mixin/beamoptic.H +++ b/src/particles/elements/mixin/beamoptic.H @@ -58,7 +58,7 @@ namespace detail RefPart ref_part) : m_element(std::move(element)), m_aos_ptr(aos_ptr), m_part_px(part_px), m_part_py(part_py), m_part_pt(part_pt), - m_ref_part(std::move(ref_part)) + m_ref_part(ref_part) { } diff --git a/src/particles/spacecharge/GatherAndPush.H b/src/particles/spacecharge/GatherAndPush.H index a788270b5..2fa700d0b 100644 --- a/src/particles/spacecharge/GatherAndPush.H +++ b/src/particles/spacecharge/GatherAndPush.H @@ -38,7 +38,7 @@ namespace impactx::spacecharge ImpactXParticleContainer & pc, std::unordered_map > const & space_charge_field, const amrex::Vector& geom, - amrex::ParticleReal const slice_ds + amrex::ParticleReal slice_ds ); } // namespace impactx diff --git a/src/particles/transformation/CoordinateTransformation.H b/src/particles/transformation/CoordinateTransformation.H index e0321b152..c104bb9a3 100644 --- a/src/particles/transformation/CoordinateTransformation.H +++ b/src/particles/transformation/CoordinateTransformation.H @@ -13,9 +13,7 @@ #include "particles/ImpactXParticleContainer.H" -namespace impactx -{ -namespace transformation +namespace impactx::transformation { /** Direction of the \see CoordinateTransformation */ @@ -33,7 +31,6 @@ namespace transformation void CoordinateTransformation (ImpactXParticleContainer &pc, Direction const & direction); -} // namespace transformation -} // namespace impactx +} // namespace impactx::transformation #endif // IMPACTX_COORDINATE_TRANSFORMATION_H diff --git a/src/particles/transformation/CoordinateTransformation.cpp b/src/particles/transformation/CoordinateTransformation.cpp index c2b38b403..dbf143698 100644 --- a/src/particles/transformation/CoordinateTransformation.cpp +++ b/src/particles/transformation/CoordinateTransformation.cpp @@ -19,10 +19,11 @@ #include -namespace impactx::transformation { +namespace impactx::transformation +{ void CoordinateTransformation (ImpactXParticleContainer &pc, Direction const &direction) - { + { BL_PROFILE("impactx::transformation::CoordinateTransformation"); using namespace amrex::literals; // for _rt and _prt @@ -93,4 +94,4 @@ namespace impactx::transformation { } // end loop over all particle boxes } // env mesh-refinement level loop } -} // namespace impactx +} // namespace impactx::transformation diff --git a/src/particles/transformation/ToFixedS.H b/src/particles/transformation/ToFixedS.H index 859f08807..c69fa0576 100644 --- a/src/particles/transformation/ToFixedS.H +++ b/src/particles/transformation/ToFixedS.H @@ -19,9 +19,7 @@ #include -namespace impactx -{ -namespace transformation +namespace impactx::transformation { struct ToFixedS { @@ -97,7 +95,6 @@ namespace transformation amrex::ParticleReal m_pzd; ///< Design value of pz/mc = beta*gamma. }; -} // namespace transformation -} // namespace impactx +} // namespace impactx::transformation #endif // IMPACTX_TO_FIXED_S_H diff --git a/src/particles/transformation/ToFixedT.H b/src/particles/transformation/ToFixedT.H index 1515075b5..b6ce3fe5e 100644 --- a/src/particles/transformation/ToFixedT.H +++ b/src/particles/transformation/ToFixedT.H @@ -19,9 +19,7 @@ #include -namespace impactx -{ -namespace transformation +namespace impactx::transformation { struct ToFixedT { @@ -97,7 +95,6 @@ namespace transformation amrex::ParticleReal m_ptd; ///< Design value of pt/mc2 = -gamma. }; -} // namespace transformation -} // namespace impactx +} // namespace impactx::transformation #endif // IMPACTX_TO_FIXED_T_H diff --git a/src/python/ImpactX.cpp b/src/python/ImpactX.cpp index 79bdfc593..8d9fa61b8 100644 --- a/src/python/ImpactX.cpp +++ b/src/python/ImpactX.cpp @@ -40,7 +40,7 @@ namespace detail * @return the queried value (or throws if not found) */ template< typename T> - auto get_or_throw (std::string const prefix, std::string const name) + auto get_or_throw (std::string const & prefix, std::string const & name) { T value; bool const has_name = amrex::ParmParse(prefix).query(name.c_str(), value); @@ -58,7 +58,7 @@ void init_ImpactX (py::module& m) .def(py::init<>()) .def("load_inputs_file", - [](ImpactX const & /* ix */, std::string const filename) { + [](ImpactX const & /* ix */, std::string const & filename) { #if defined(AMREX_DEBUG) || defined(DEBUG) // note: only in debug, since this is costly for the file // system for highly parallel simulations with MPI @@ -276,7 +276,7 @@ void init_ImpactX (py::module& m) [](ImpactX & /* ix */){ return detail::get_or_throw("impactx", "abort_on_warning_threshold"); }, - [](ImpactX & ix, std::string const str_abort_on_warning_threshold) { + [](ImpactX & ix, std::string const & str_abort_on_warning_threshold) { amrex::ParmParse pp_impactx("impactx"); pp_impactx.add("abort_on_warning_threshold", str_abort_on_warning_threshold); // query input for warning logger variables and set up warning logger accordingly @@ -358,7 +358,7 @@ void init_ImpactX (py::module& m) ) .def( "space_charge_field", - [](ImpactX & ix, int const lev, std::string const comp) { + [](ImpactX & ix, int lev, std::string const & comp) { return &ix.m_space_charge_field.at(lev).at(comp); }, py::arg("lev"), py::arg("comp"), @@ -407,7 +407,7 @@ void init_ImpactX (py::module& m) // "ImpactX version") .def_property_readonly_static( "have_mpi", - [](py::object){ + [](py::object const &){ #ifdef AMREX_USE_MPI return true; #else @@ -416,7 +416,7 @@ void init_ImpactX (py::module& m) }) .def_property_readonly_static( "have_gpu", - [](py::object){ + [](py::object const &){ #ifdef AMREX_USE_GPU return true; #else @@ -425,7 +425,7 @@ void init_ImpactX (py::module& m) }) .def_property_readonly_static( "have_omp", - [](py::object){ + [](py::object const &){ #ifdef AMREX_USE_OMP return true; #else @@ -434,7 +434,7 @@ void init_ImpactX (py::module& m) }) .def_property_readonly_static( "gpu_backend", - [](py::object){ + [](py::object const &){ #ifdef AMREX_USE_CUDA return "CUDA"; #elif defined(AMREX_USE_HIP) diff --git a/src/python/elements.cpp b/src/python/elements.cpp index fd7a506be..c0eb8e74a 100644 --- a/src/python/elements.cpp +++ b/src/python/elements.cpp @@ -8,6 +8,7 @@ #include #include +#include #include namespace py = pybind11; @@ -26,25 +27,25 @@ void init_elements(py::module& m) kel .def(py::init<>()) .def(py::init()) - .def(py::init([](py::list l){ + .def(py::init([](py::list const & l){ auto v = new KnownElementsList; for (auto const & handle : l) v->push_back(handle.cast()); return v; })) - .def("append", [](KnownElementsList &v, KnownElements el) { v.emplace_back(el); }, + .def("append", [](KnownElementsList &v, KnownElements el) { v.emplace_back(std::move(el)); }, "Add a single element to the list.") .def("extend", - [](KnownElementsList &v, KnownElementsList l) { + [](KnownElementsList &v, KnownElementsList const & l) { for (auto const & el : l) v.push_back(el); return v; }, "Add a list of elements to the list.") .def("extend", - [](KnownElementsList &v, py::list l) { + [](KnownElementsList &v, py::list const & l) { for (auto const & handle : l) { auto el = handle.cast(); @@ -186,7 +187,7 @@ void init_elements(py::module& m) .def(py::init([]( amrex::ParticleReal xkick, amrex::ParticleReal ykick, - std::string units) + std::string const & units) { if (units != "dimensionless" && units != "T-m") throw std::runtime_error(R"(units must be "dimensionless" or "T-m")"); @@ -250,21 +251,21 @@ void init_elements(py::module& m) [](Programmable & p) { return p.m_push; }, [](Programmable & p, std::function new_hook - ) { p.m_push = new_hook; }, + ) { p.m_push = std::move(new_hook); }, "hook for push of whole container (pc, step)" ) .def_property("beam_particles", [](Programmable & p) { return p.m_beam_particles; }, [](Programmable & p, std::function new_hook - ) { p.m_beam_particles = new_hook; }, + ) { p.m_beam_particles = std::move(new_hook); }, "hook for beam particles (pti, RefPart)" ) .def_property("ref_particle", [](Programmable & p) { return p.m_ref_particle; }, [](Programmable & p, std::function new_hook - ) { p.m_ref_particle = new_hook; }, + ) { p.m_ref_particle = std::move(new_hook); }, "hook for reference particle (RefPart)" ) ;