Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy: unnecessary copy perf #428

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions src/initialization/InitAmrCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace details
default_init_AMReX();
}

amrex::ParmParse pp_amr("amr");
amrex::ParmParse const pp_amr("amr");

amrex::Vector<int> n_cell(AMREX_SPACEDIM);
bool const has_ncell = pp_amr.queryarr("n_cell", n_cell);
Expand All @@ -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<int> n_cell = {AMREX_D_DECL(256,256,256)};
amrex::Box domain(amrex::IntVect(0), amrex::IntVect(n_cell));
amrex::Vector<int> 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<int, AMREX_SPACEDIM> is_periodic{AMREX_D_DECL(0,0,0)};
amrex::Array<int, AMREX_SPACEDIM> const is_periodic{AMREX_D_DECL(0,0,0)};

// Mesh-refinement
int max_level = 0;
Expand All @@ -116,21 +116,21 @@ 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<int> n_cell_v(n_cell_iv.begin(), n_cell_iv.end());
amrex::Vector<int> const n_cell_v(n_cell_iv.begin(), n_cell_iv.end());
pp_amr.addarr("n_cell", n_cell_v);

// Domain physical size
// we might resize this dynamically
auto rb = details::init_physical_domain();

// Periodicity (none)
amrex::Array<int, AMREX_SPACEDIM> is_periodic{AMREX_D_DECL(0,0,0)};
amrex::Array<int, AMREX_SPACEDIM> 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
10 changes: 5 additions & 5 deletions src/initialization/InitElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
* @param[in] nslice_default
* @param[in] mapsteps_default
*/
void read_element (std::string element_name,
void read_element (std::string const & element_name,

Check warning

Code scanning / CodeQL

Poorly documented large function Warning

Poorly documented function: fewer than 2% comments for a function of 373 lines.
std::list<KnownElements> & m_lattice,
int nslice_default,
int mapsteps_default)
Expand Down Expand Up @@ -94,7 +94,7 @@
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") {
Expand Down Expand Up @@ -216,14 +216,14 @@
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);
Expand Down Expand Up @@ -252,7 +252,7 @@
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<std::string> sub_lattice_elements;
pp_sub_lattice.queryarr("elements", sub_lattice_elements);
Expand Down
2 changes: 1 addition & 1 deletion src/initialization/InitMeshRefinement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion src/initialization/Warnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/particles/ImpactXParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ namespace impactx
* @param refpart reference particle
*/
void
SetRefParticle (RefPart const refpart);
SetRefParticle (RefPart const & refpart);

/** Get reference particle attributes
*
Expand Down Expand Up @@ -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
*
Expand Down
4 changes: 2 additions & 2 deletions src/particles/ImpactXParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -155,7 +155,7 @@ namespace impactx
}

void
ImpactXParticleContainer::SetRefParticle (RefPart const refpart)
ImpactXParticleContainer::SetRefParticle (RefPart const & refpart)
{
m_refpart = refpart;
}
Expand Down
6 changes: 3 additions & 3 deletions src/particles/diagnostics/DiagnosticOutput.H
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions src/particles/diagnostics/DiagnosticOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@
#include <AMReX_REAL.H> // for ParticleReal
#include <AMReX_Print.H> // for PrintToFile

#include <utility>


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) {
Expand Down
18 changes: 9 additions & 9 deletions src/particles/diagnostics/NonlinearLensInvariants.H
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ namespace impactx::diagnostics
using Complex = amrex::GpuComplex<amrex::ParticleReal>;

// 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);
Expand All @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions src/particles/distribution/All.H
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
#include <variant>


namespace impactx
{
namespace distribution
namespace impactx::distribution
{
using KnownDistributions = std::variant<
None, /* must be first, so KnownDistributions creates a default constructor */
Expand All @@ -37,7 +35,6 @@ namespace distribution
Waterbag
>;

} // namespace distribution
} // namespace impactx
} // namespace impactx::distribution

#endif // IMPACTX_DISTRIBUTION_ALL_H
7 changes: 2 additions & 5 deletions src/particles/distribution/Gaussian.H
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#include <cmath>


namespace impactx
{
namespace distribution
namespace impactx::distribution
{
struct Gaussian
{
Expand Down Expand Up @@ -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
9 changes: 3 additions & 6 deletions src/particles/distribution/KVdist.H
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#include <cmath>


namespace impactx
{
namespace distribution
namespace impactx::distribution
{
struct KVdist
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
9 changes: 3 additions & 6 deletions src/particles/distribution/Kurth4D.H
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#include <cmath>


namespace impactx
{
namespace distribution
namespace impactx::distribution
{
struct Kurth4D
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
9 changes: 3 additions & 6 deletions src/particles/distribution/Kurth6D.H
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#include <cmath>


namespace impactx
{
namespace distribution
namespace impactx::distribution
{
struct Kurth6D
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
7 changes: 2 additions & 5 deletions src/particles/distribution/None.H
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
#include <AMReX_REAL.H>


namespace impactx
{
namespace distribution
namespace impactx::distribution
{
struct None
{
Expand Down Expand Up @@ -52,7 +50,6 @@ namespace distribution
}
};

} // namespace distribution
} // namespace impactx
} // namespace impactx::distribution

#endif // IMPACTX_DISTRIBUTION_NONE
Loading
Loading