Skip to content

Commit 7ee98ff

Browse files
authored
fix issues found by clang-tidy with the rule modernize-use-nodiscard (#1313)
1 parent 3905e43 commit 7ee98ff

7 files changed

Lines changed: 42 additions & 22 deletions

File tree

src/diagnostics/Diagnostic.H

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ public:
9292
* \param[in] output_time physical time of current step
9393
* \param[in] max_time physical time of last step
9494
*/
95-
bool hasAnyFieldOutput (int output_step, int max_step,
95+
[[nodiscard]] bool
96+
hasAnyFieldOutput (int output_step, int max_step,
9697
amrex::Real output_time, amrex::Real max_time) const
9798
{
9899
for (const auto& fd : m_field_data) {
@@ -108,7 +109,8 @@ public:
108109
* \param[in] output_time physical time of current step
109110
* \param[in] max_time physical time of last step
110111
*/
111-
bool hasBeamOutput (int output_step, int max_step,
112+
[[nodiscard]] bool
113+
hasBeamOutput (int output_step, int max_step,
112114
amrex::Real output_time, amrex::Real max_time) const
113115
{
114116
return m_output_beam_names.size() > 0 &&
@@ -123,7 +125,8 @@ public:
123125
* \param[in] output_time physical time of current step
124126
* \param[in] max_time physical time of last step
125127
*/
126-
bool hasAnyOutput (int output_step, int max_step,
128+
[[nodiscard]] bool
129+
hasAnyOutput (int output_step, int max_step,
127130
amrex::Real output_time, amrex::Real max_time) const
128131
{
129132
return hasAnyFieldOutput(output_step, max_step, output_time, max_time) ||
@@ -132,15 +135,18 @@ public:
132135

133136
/** \brief determines if rho is requested as a diagnostic
134137
*/
135-
bool needsRho () const;
138+
[[nodiscard]] bool
139+
needsRho () const;
136140

137141
/** \brief determines if rho for every individual plasma is requested as a diagnostic
138142
*/
139-
bool needsRhoIndividual () const;
143+
[[nodiscard]] bool
144+
needsRhoIndividual () const;
140145

141146
/** \brief determines if the temperature parameters for every individual plasma are requested as a diagnostic
142147
*/
143-
bool needsTempIndividual () const;
148+
[[nodiscard]] bool
149+
needsTempIndividual () const;
144150

145151
/** \brief calculate box which possibly was trimmed in case of slice IO
146152
*

src/fields/Fields.H

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ public:
104104
/** get function for the 2D slices (const version)
105105
* \param[in] lev MR level
106106
*/
107-
const amrex::MultiFab& getSlices (int lev) const {return m_slices[lev]; }
107+
[[nodiscard]] const amrex::MultiFab&
108+
getSlices (int lev) const {return m_slices[lev]; }
108109
/** get amrex::MultiFab of a field in a slice
109110
* \param[in] lev MR level
110111
* \param[in] islice slice index

src/particles/beam/MultiBeam.H

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,16 @@ public:
8282
/** \brief Return 1 species
8383
* \param[in] i index of the beam
8484
*/
85-
const BeamParticleContainer& getBeam (int i) const {return m_all_beams[i];}
85+
[[nodiscard]] const BeamParticleContainer&
86+
getBeam (int i) const {return m_all_beams[i];}
8687

8788
/** returns the number of beams */
88-
int get_nbeams () const {return m_nbeams;}
89+
[[nodiscard]] int
90+
get_nbeams () const {return m_nbeams;}
8991

9092
/** returns the name of a beam */
91-
std::string get_name (int i) const {return m_all_beams[i].get_name();}
93+
[[nodiscard]] std::string
94+
get_name (int i) const {return m_all_beams[i].get_name();}
9295

9396
/** \brief Store the finest level of every beam particle on which_slice in the cpu() attribute.
9497
* \param[in] current_N_level number of MR levels active on the current slice
@@ -108,7 +111,8 @@ public:
108111
/** \brief returns if the SALAME algorithm should be used on this slice
109112
* \param[in] step time step of simulation
110113
*/
111-
bool isSalameNow (const int step);
114+
[[nodiscard]] bool
115+
isSalameNow (const int step);
112116

113117
/** \brief returns if any beam uses the SALAME algorithm
114118
*/

src/particles/plasma/MultiPlasma.H

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,16 @@ public:
116116
const MultiLaser& laser);
117117

118118
/** \brief whether any plasma species uses a neutralizing background, e.g. no ion motion */
119-
bool AnySpeciesNeutralizeBackground () const;
119+
[[nodiscard]] bool
120+
AnySpeciesNeutralizeBackground () const;
120121

121122
/** returns a Vector of names of the plasmas */
122-
const amrex::Vector<std::string>& GetNames() const {return m_names;}
123+
[[nodiscard]] const amrex::Vector<std::string>&
124+
GetNames() const {return m_names;}
123125

124126
/** returns number of plasma species */
125-
int GetNPlasmas() const {return m_nplasmas;}
127+
[[nodiscard]] int
128+
GetNPlasmas() const {return m_nplasmas;}
126129

127130
/** Reorder particles to speed-up current deposition
128131
* \param[in] islice zeta slice index

src/particles/profiles/GetInitialDensity.H

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct PlasmaDensityAccessor {
7878
amrex::RealVect m_dx_inv;
7979
amrex::Real m_unitSI = 1;
8080

81-
AMREX_GPU_HOST_DEVICE
81+
[[nodiscard]] AMREX_GPU_HOST_DEVICE
8282
amrex::Real array (int i, int j, int k) const {
8383
const int ii = std::min(m_bigend[0], std::max(0, i));
8484
const int jj = std::min(m_bigend[1], std::max(0, j));
@@ -93,7 +93,7 @@ struct PlasmaDensityAccessor {
9393
}
9494
}
9595

96-
AMREX_GPU_HOST_DEVICE
96+
[[nodiscard]] AMREX_GPU_HOST_DEVICE
9797
amrex::Real operator() (amrex::Real x, amrex::Real y, amrex::Real z) const {
9898
if (m_profile_type == 0) {
9999
return m_density_func(x, y, z);

src/particles/sorting/BoxSort.H

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,20 @@ public:
2626
const amrex::Geometry& a_geom);
2727

2828
//! \brief returns the pointer to the permutation array
29-
index_type* boxCountsPtr () noexcept { return m_box_counts_cpu.dataPtr(); }
29+
[[nodiscard]] index_type*
30+
boxCountsPtr () noexcept { return m_box_counts_cpu.dataPtr(); }
3031

3132
//! \brief returns the pointer to the offsets array
32-
index_type* boxOffsetsPtr () noexcept { return m_box_offsets_cpu.dataPtr(); }
33+
[[nodiscard]] index_type*
34+
boxOffsetsPtr () noexcept { return m_box_offsets_cpu.dataPtr(); }
3335

3436
//! \brief returns the pointer to the permutation array
35-
const index_type* boxCountsPtr () const noexcept { return m_box_counts_cpu.dataPtr(); }
37+
[[nodiscard]] const index_type*
38+
boxCountsPtr () const noexcept { return m_box_counts_cpu.dataPtr(); }
3639

3740
//! \brief returns the pointer to the offsets array
38-
const index_type* boxOffsetsPtr () const noexcept { return m_box_offsets_cpu.dataPtr(); }
41+
[[nodiscard]] const index_type*
42+
boxOffsetsPtr () const noexcept { return m_box_offsets_cpu.dataPtr(); }
3943

4044

4145
/** Number of particles in each box, stored on the cpu */

src/utils/MultiBuffer.H

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,13 @@ private:
136136

137137
// calculate distance of a and b in the periodic range [0,m_nslices) with
138138
// a barrier at current_slice
139-
int periodic_distance (int current_slice, int a, int b) const;
139+
[[nodiscard]] int
140+
periodic_distance (int current_slice, int a, int b) const;
140141

141142
// calculate min of a and b in the periodic range [0,m_nslices) with
142143
// a barrier at current_slice
143-
int periodic_min (int current_slice, int a, int b) const;
144+
[[nodiscard]] int
145+
periodic_min (int current_slice, int a, int b) const;
144146

145147
// send some dummy messages so MPI can pre-register the memory
146148
void pre_register_memory ();

0 commit comments

Comments
 (0)