Skip to content

Commit e944c7c

Browse files
Clang-tidy: enforce clang-tidy_readability_make_member_function_const check (#4510)
* enforce clang-tidy_readability_make_member_function_const check * fix bug * address additional issues found with clang-tidy * Fix more issues. --------- Co-authored-by: Weiqun Zhang <weiqunzhang@lbl.gov>
1 parent 0b147c7 commit e944c7c

27 files changed

+44
-43
lines changed

.clang-tidy

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ Checks: '
4141
-readability-implicit-bool-conversion,
4242
-readability-isolate-declaration,
4343
-readability-magic-numbers,
44-
-readability-make-member-function-const,
4544
-readability-named-parameter,
4645
-readability-uppercase-literal-suffix
4746
'

Source/AcceleratorLattice/AcceleratorLattice.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ AcceleratorLattice::InitElementFinder (int const lev, amrex::BoxArray const & ba
8888
}
8989

9090
void
91-
AcceleratorLattice::UpdateElementFinder (int const lev)
92-
{
91+
AcceleratorLattice::UpdateElementFinder (int const lev) // NOLINT(readability-make-member-function-const)
92+
{ // Techniquely clang-tidy is correct because
93+
// m_element_finder is unique_ptr, not const*.
9394
if (m_lattice_defined) {
9495
for (amrex::MFIter mfi(*m_element_finder); mfi.isValid(); ++mfi)
9596
{

Source/AcceleratorLattice/LatticeElementFinder.H

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ struct LatticeElementFinder
7272
* @param[in] a_offset particle index offset needed to access particle info
7373
* @param[in] accelerator_lattice a reference to the accelerator lattice at the refinement level
7474
*/
75-
LatticeElementFinderDevice GetFinderDeviceInstance (WarpXParIter const& a_pti, int a_offset,
76-
AcceleratorLattice const& accelerator_lattice);
75+
[[nodiscard]] LatticeElementFinderDevice GetFinderDeviceInstance (
76+
WarpXParIter const& a_pti, int a_offset, AcceleratorLattice const& accelerator_lattice) const;
7777

7878
/* The index lookup tables for each lattice element type */
7979
amrex::Gpu::DeviceVector<int> d_quad_indices;
@@ -89,7 +89,7 @@ struct LatticeElementFinder
8989
*/
9090
void setup_lattice_indices (amrex::Gpu::DeviceVector<amrex::ParticleReal> const & zs,
9191
amrex::Gpu::DeviceVector<amrex::ParticleReal> const & ze,
92-
amrex::Gpu::DeviceVector<int> & indices);
92+
amrex::Gpu::DeviceVector<int> & indices) const;
9393
};
9494

9595
/**

Source/AcceleratorLattice/LatticeElementFinder.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ LatticeElementFinder::UpdateIndices (int const lev, amrex::MFIter const& a_mfi,
7878

7979
LatticeElementFinderDevice
8080
LatticeElementFinder::GetFinderDeviceInstance (WarpXParIter const& a_pti, int const a_offset,
81-
AcceleratorLattice const& accelerator_lattice)
81+
AcceleratorLattice const& accelerator_lattice) const
8282
{
8383
LatticeElementFinderDevice result;
8484
result.InitLatticeElementFinderDevice(a_pti, a_offset, accelerator_lattice, *this);
@@ -124,7 +124,7 @@ LatticeElementFinderDevice::InitLatticeElementFinderDevice (WarpXParIter const&
124124
void
125125
LatticeElementFinder::setup_lattice_indices (amrex::Gpu::DeviceVector<amrex::ParticleReal> const & zs,
126126
amrex::Gpu::DeviceVector<amrex::ParticleReal> const & ze,
127-
amrex::Gpu::DeviceVector<int> & indices)
127+
amrex::Gpu::DeviceVector<int> & indices) const
128128
{
129129

130130
using namespace amrex::literals;

Source/BoundaryConditions/WarpXFieldBoundaries.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void WarpX::ApplyJfieldBoundary (const int lev, amrex::MultiFab* Jx,
119119
#ifdef WARPX_DIM_RZ
120120
// Applies the boundary conditions that are specific to the axis when in RZ.
121121
void
122-
WarpX::ApplyFieldBoundaryOnAxis (amrex::MultiFab* Er, amrex::MultiFab* Et, amrex::MultiFab* Ez, int lev)
122+
WarpX::ApplyFieldBoundaryOnAxis (amrex::MultiFab* Er, amrex::MultiFab* Et, amrex::MultiFab* Ez, int lev) const
123123
{
124124
const amrex::IntVect ngE = get_ng_fieldgather();
125125

Source/Diagnostics/BTD_Plotfile_Header_Impl.H

+5-5
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ class BTDMultiFabHeaderImpl
171171
void WriteMultiFabHeader ();
172172

173173
/** Returns size, m_ba_size, of the Box Array, m_ba.*/
174-
int ba_size () {return m_ba_size;}
174+
[[nodiscard]] int ba_size () const {return m_ba_size;}
175175
/** Returns box corresponding to the ith box in the BoxArray, m_ba.
176176
* \param[in] ibox index of the box in the BoxArray.
177177
*/
178-
amrex::Box ba_box (int ibox) {return m_ba[ibox]; }
178+
[[nodiscard]] amrex::Box ba_box (int ibox) const {return m_ba[ibox]; }
179179
/** Returns prefix of the ith-fab on disk, i.e., ith fab of the MultiFab data.
180180
* \param[in] ifab index of the ith fab in the MultiFab data.
181181
*/
@@ -316,17 +316,17 @@ public:
316316
/** Reads the particle header file at m_Header_path and stores its data*/
317317
void ReadHeader ();
318318
/** Writes the meta-data of particle box array in header file, with path, m_Header_path*/
319-
void WriteHeader ();
319+
void WriteHeader () const;
320320
/** Returns the size of the box array, m_ba_size */
321-
int ba_size () {return m_ba_size; }
321+
[[nodiscard]] int ba_size () const {return m_ba_size; }
322322
/** Increases Box array size, m_ba_size, by add_size
323323
* \param[in] add_size
324324
*/
325325
void IncreaseBoxArraySize ( const int add_size) { m_ba_size += add_size;}
326326
/** Returns box corresponding to the ith box in the BoxArray, m_ba.
327327
* \param[in] ibox index of the box in the BoxArray.
328328
*/
329-
amrex::Box ba_box (int ibox) {return m_ba[ibox]; }
329+
[[nodiscard]] amrex::Box ba_box (int ibox) const {return m_ba[ibox]; }
330330
/** Resize boxArray, m_ba, to size, m_ba_size. */
331331
void ResizeBoxArray () { m_ba.resize(m_ba_size); }
332332
/** Set Box indices of the ith-box in Box Array, m_ba, to the new Box, ba_box.

Source/Diagnostics/BTD_Plotfile_Header_Impl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ BTDParticleDataHeaderImpl::ReadHeader ()
516516
}
517517

518518
void
519-
BTDParticleDataHeaderImpl::WriteHeader ()
519+
BTDParticleDataHeaderImpl::WriteHeader () const
520520
{
521521
if (amrex::FileExists(m_Header_path)) {
522522
amrex::FileSystem::Remove(m_Header_path);

Source/Diagnostics/BTDiagnostics.H

+4-4
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ private:
275275
* \param[in] t_lab lab-frame time of the snapshot
276276
* \param[in] t_boost boosted-frame time at level, lev
277277
*/
278-
amrex::Real UpdateCurrentZBoostCoordinate(amrex::Real t_lab, amrex::Real t_boost)
278+
[[nodiscard]] amrex::Real UpdateCurrentZBoostCoordinate(amrex::Real t_lab, amrex::Real t_boost) const
279279
{
280280
const amrex::Real current_z_boost = (t_lab / m_gamma_boost - t_boost) * PhysConst::c / m_beta_boost;
281281
return current_z_boost;
@@ -284,7 +284,7 @@ private:
284284
* \param[in] t_lab lab-frame time of the snapshot
285285
* \param[in] t_boost boosted-frame time at level, lev
286286
*/
287-
amrex::Real UpdateCurrentZLabCoordinate(amrex::Real t_lab, amrex::Real t_boost)
287+
[[nodiscard]] amrex::Real UpdateCurrentZLabCoordinate(amrex::Real t_lab, amrex::Real t_boost) const
288288
{
289289
const amrex::Real current_z_lab = (t_lab - t_boost / m_gamma_boost ) * PhysConst::c / m_beta_boost;
290290
return current_z_lab;
@@ -294,13 +294,13 @@ private:
294294
* \param[in] ref_ratio refinement ratio in the z-direction at level, lev-1.
295295
* The ref-ratio in the z-direction for single-level diagnostics is 1.
296296
*/
297-
amrex::Real dz_lab (amrex::Real dt, amrex::Real ref_ratio);
297+
[[nodiscard]] amrex::Real dz_lab (amrex::Real dt, amrex::Real ref_ratio) const;
298298
/** Compute k-index corresponding to current lab-frame z co-ordinate (m_current_z_lab)
299299
* for the ith buffer i_buffer, and at level, lev.
300300
* \param[in] i_buffer snapshot index
301301
* \param[in] lev mesh-refinement level at which the lab-frame z-index is computed
302302
*/
303-
int k_index_zlab (int i_buffer, int lev);
303+
[[nodiscard]] int k_index_zlab (int i_buffer, int lev) const;
304304
/** whether field buffer is full
305305
* \param[in] i_buffer buffer id for which the buffer size is checked.
306306
* returns bool = true is buffer is full, that is,

Source/Diagnostics/BTDiagnostics.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -863,13 +863,14 @@ BTDiagnostics::PrepareFieldDataForOutput ()
863863

864864

865865
amrex::Real
866-
BTDiagnostics::dz_lab (amrex::Real dt, amrex::Real ref_ratio){
866+
BTDiagnostics::dz_lab (amrex::Real dt, amrex::Real ref_ratio) const
867+
{
867868
return PhysConst::c * dt * 1._rt/m_beta_boost * 1._rt/m_gamma_boost * 1._rt/ref_ratio;
868869
}
869870

870871

871872
int
872-
BTDiagnostics::k_index_zlab (int i_buffer, int lev)
873+
BTDiagnostics::k_index_zlab (int i_buffer, int lev) const
873874
{
874875
auto & warpx = WarpX::GetInstance();
875876
const amrex::Real prob_domain_zmin_lab = m_snapshot_domain_lab[i_buffer].lo( m_moving_window_dir );

Source/Diagnostics/Diagnostics.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public:
114114
/** Whether the last timestep is always dumped */
115115
[[nodiscard]] bool DoDumpLastTimestep () const {return m_dump_last_timestep;}
116116
/** Returns the number of snapshots used in BTD. For Full-Diagnostics, the value is 1*/
117-
int getnumbuffers() {return m_num_buffers;}
117+
[[nodiscard]] int getnumbuffers() const {return m_num_buffers;}
118118
/** Time in lab-frame associated with the ith snapshot
119119
* \param[in] i_buffer index of the buffer
120120
*/

Source/Diagnostics/MultiDiagnostics.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public:
3838
/** Start a new iteration, i.e., dump has not been done yet. */
3939
void NewIteration ();
4040
Diagnostics& GetDiag(int idiag) {return *alldiags[idiag]; }
41-
int GetTotalDiags() {return ndiags;}
41+
[[nodiscard]] int GetTotalDiags() const {return ndiags;}
4242
DiagTypes diagstypes(int idiag) {return diags_types[idiag];}
4343
private:
4444
/** Vector of pointers to all diagnostics */

Source/Diagnostics/ReducedDiags/ReducedDiags.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public:
9494
* This function queries deprecated input parameters and aborts
9595
* the run if one of them is specified.
9696
*/
97-
void BackwardCompatibility ();
97+
void BackwardCompatibility () const;
9898

9999
};
100100

Source/Diagnostics/ReducedDiags/ReducedDiags.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void ReducedDiags::LoadBalance ()
8686
// load balancing operations
8787
}
8888

89-
void ReducedDiags::BackwardCompatibility ()
89+
void ReducedDiags::BackwardCompatibility () const
9090
{
9191
const amrex::ParmParse pp_rd_name(m_rd_name);
9292
std::vector<std::string> backward_strings;

Source/Diagnostics/WarpXOpenPMD.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public:
4444
using ParticleIter = typename amrex::ParIter<0, 0, PIdx::nattribs, 0, amrex::PinnedArenaAllocator>;
4545

4646
WarpXParticleCounter (ParticleContainer* pc);
47-
unsigned long GetTotalNumParticles () {return m_Total;}
47+
[[nodiscard]] unsigned long GetTotalNumParticles () const {return m_Total;}
4848

4949
std::vector<unsigned long long> m_ParticleOffsetAtRank;
5050
std::vector<unsigned long long> m_ParticleSizeAtRank;

Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public:
126126
*/
127127
void FillElectronPressureMF (
128128
std::unique_ptr<amrex::MultiFab> const& Pe_field,
129-
amrex::MultiFab* const& rho_field );
129+
amrex::MultiFab* const& rho_field ) const;
130130

131131
// Declare variables to hold hybrid-PIC model parameters
132132
/** Number of substeps to take when evolving B */

Source/FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ void HybridPICModel::CalculateElectronPressure(const int lev, DtType a_dt_type)
508508

509509
void HybridPICModel::FillElectronPressureMF (
510510
std::unique_ptr<amrex::MultiFab> const& Pe_field,
511-
amrex::MultiFab* const& rho_field )
511+
amrex::MultiFab* const& rho_field ) const
512512
{
513513
const auto n0_ref = m_n0_ref;
514514
const auto elec_temp = m_elec_temp;

Source/Initialization/InjectorMomentum.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
using namespace amrex;
1111

12-
void InjectorMomentum::clear ()
12+
void InjectorMomentum::clear () // NOLINT(readability-make-member-function-const)
1313
{
1414
switch (type)
1515
{

Source/Particles/Collision/BackgroundMCC/BackgroundMCCCollision.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public:
3232
BackgroundMCCCollision ( BackgroundMCCCollision&& ) = delete;
3333
BackgroundMCCCollision& operator= ( BackgroundMCCCollision&& ) = delete;
3434

35-
amrex::ParticleReal get_nu_max (amrex::Vector<ScatteringProcess> const& mcc_processes);
35+
[[nodiscard]] amrex::ParticleReal get_nu_max (amrex::Vector<ScatteringProcess> const& mcc_processes) const;
3636

3737
/** Perform the collisions
3838
*

Source/Particles/Collision/BackgroundMCC/BackgroundMCCCollision.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ BackgroundMCCCollision::BackgroundMCCCollision (std::string const collision_name
162162
* ranges from 1e-4 to 5000 eV in 0.2 eV increments
163163
*/
164164
amrex::ParticleReal
165-
BackgroundMCCCollision::get_nu_max(amrex::Vector<ScatteringProcess> const& mcc_processes)
165+
BackgroundMCCCollision::get_nu_max(amrex::Vector<ScatteringProcess> const& mcc_processes) const
166166
{
167167
using namespace amrex::literals;
168168
amrex::ParticleReal nu, nu_max = 0.0;

Source/Particles/Collision/CollisionBase.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public:
2929

3030
virtual ~CollisionBase() = default;
3131

32-
int get_ndt() {return m_ndt;}
32+
[[nodiscard]] int get_ndt() const {return m_ndt;}
3333

3434
protected:
3535

Source/Particles/ParticleBoundaries.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct ParticleBoundaries
2727
void SetBoundsY (ParticleBoundaryType bc_lo, ParticleBoundaryType bc_hi);
2828
void SetBoundsZ (ParticleBoundaryType bc_lo, ParticleBoundaryType bc_hi);
2929

30-
bool CheckAll (ParticleBoundaryType bc);
30+
[[nodiscard]] bool CheckAll (ParticleBoundaryType bc) const;
3131

3232
void BuildReflectionModelParsers ();
3333

Source/Particles/ParticleBoundaries.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ParticleBoundaries::SetBoundsZ (ParticleBoundaryType bc_lo, ParticleBoundaryType
5454
}
5555

5656
bool
57-
ParticleBoundaries::CheckAll (ParticleBoundaryType bc)
57+
ParticleBoundaries::CheckAll (ParticleBoundaryType bc) const
5858
{
5959
return (data.xmin_bc == bc && data.xmax_bc == bc
6060
#ifdef WARPX_DIM_3D

Source/Particles/PhysicalParticleContainer.H

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public:
224224

225225
void MapParticletoBoostedFrame (amrex::ParticleReal& x, amrex::ParticleReal& y, amrex::ParticleReal& z,
226226
amrex::ParticleReal& ux, amrex::ParticleReal& uy, amrex::ParticleReal& uz,
227-
amrex::Real t_lab = 0.);
227+
amrex::Real t_lab = 0.) const;
228228

229229
void AddGaussianBeam (
230230
PlasmaInjector const& plasma_injector,
@@ -253,7 +253,7 @@ public:
253253
amrex::Gpu::HostVector<amrex::ParticleReal>& particle_uy,
254254
amrex::Gpu::HostVector<amrex::ParticleReal>& particle_uz,
255255
amrex::Gpu::HostVector<amrex::ParticleReal>& particle_w,
256-
amrex::Real t_lab= 0.);
256+
amrex::Real t_lab= 0.) const;
257257

258258
/**
259259
* \brief Default initialize runtime attributes in a tile. This routine does not initialize the

Source/Particles/PhysicalParticleContainer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ void PhysicalParticleContainer::InitData ()
471471
}
472472

473473
void PhysicalParticleContainer::MapParticletoBoostedFrame (
474-
ParticleReal& x, ParticleReal& y, ParticleReal& z, ParticleReal& ux, ParticleReal& uy, ParticleReal& uz, Real t_lab)
474+
ParticleReal& x, ParticleReal& y, ParticleReal& z, ParticleReal& ux, ParticleReal& uy, ParticleReal& uz, Real t_lab) const
475475
{
476476
// Map the particles from the lab frame to the boosted frame.
477477
// This boosts the particle to the lab frame and calculates
@@ -810,7 +810,7 @@ PhysicalParticleContainer::CheckAndAddParticle (
810810
Gpu::HostVector<ParticleReal>& particle_uy,
811811
Gpu::HostVector<ParticleReal>& particle_uz,
812812
Gpu::HostVector<ParticleReal>& particle_w,
813-
Real t_lab)
813+
Real t_lab) const
814814
{
815815
if (WarpX::gamma_boost > 1.) {
816816
MapParticletoBoostedFrame(x, y, z, ux, uy, uz, t_lab);

Source/WarpX.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ public:
727727

728728
#ifdef WARPX_DIM_RZ
729729
// Applies the boundary conditions that are specific to the axis when in RZ.
730-
void ApplyFieldBoundaryOnAxis (amrex::MultiFab* Er, amrex::MultiFab* Et, amrex::MultiFab* Ez, int lev);
730+
void ApplyFieldBoundaryOnAxis (amrex::MultiFab* Er, amrex::MultiFab* Et, amrex::MultiFab* Ez, int lev) const;
731731
#endif
732732

733733
/**

Source/ablastr/utils/timer/Timer.H

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace ablastr::utils::timer
4444
*
4545
* @return the duration
4646
*/
47-
double get_duration () noexcept;
47+
[[nodiscard]] double get_duration () const noexcept;
4848

4949

5050
/**
@@ -53,7 +53,7 @@ namespace ablastr::utils::timer
5353
*
5454
* @return the maximum duration across all the MPI ranks
5555
*/
56-
double get_global_duration ();
56+
[[nodiscard]] double get_global_duration () const;
5757

5858
private:
5959

Source/ablastr/utils/timer/Timer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ Timer::record_stop_time() noexcept
2424
}
2525

2626
double
27-
Timer::get_duration () noexcept
27+
Timer::get_duration () const noexcept
2828
{
2929
return m_stop_time - m_start_time;
3030
}
3131

3232
double
33-
Timer::get_global_duration ()
33+
Timer::get_global_duration () const
3434
{
3535
auto duration = this->get_duration();
3636
amrex::ParallelDescriptor::ReduceRealMax(

0 commit comments

Comments
 (0)