Skip to content

Commit

Permalink
Fix clang-tidy 19 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshingles committed Sep 4, 2024
1 parent 718f3ee commit 29ccf5a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Checks: >
-bugprone-easily-swappable-parameters,
-bugprone-exception-escape,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-multi-level-implicit-pointer-conversion,
-bugprone-narrowing-conversions,
-boost-use-ranges,
-llvmlibc-*,
Expand Down Expand Up @@ -39,6 +40,7 @@ Checks: >
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
-modernize-use-ranges,
-performance-enum-size,
-readability-identifier-length,
-readability-function-cognitive-complexity,
-readability-magic-numbers,
Expand Down
4 changes: 2 additions & 2 deletions input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,8 @@ void read_phixs_data() {

if (!tmpallphixs.empty()) {
assert_always((nbftables * globals::NPHIXSPOINTS) == std::ssize(tmpallphixs));
// nbftables is not large enough! This is a bug.
// copy the photoionisation tables into one contiguous block of memory

// copy the photoionisation tables into one contiguous block of memory
#ifdef MPI_ON
MPI_Win win_allphixsblock = MPI_WIN_NULL;

Expand Down
2 changes: 1 addition & 1 deletion packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct Packet {
int pellet_nucindex{-1}; // nuclide index of the decaying species
float trueemissionvelocity{-1};

inline auto operator==(const Packet &rhs) const -> bool {
auto operator==(const Packet &rhs) const -> bool {
return (number == rhs.number && type == rhs.type &&
(em_pos[0] == rhs.em_pos[0] && em_pos[1] == rhs.em_pos[1] && em_pos[2] == rhs.em_pos[2]) &&
nu_cmf == rhs.nu_cmf && where == rhs.where && prop_time == rhs.prop_time && tdecay == rhs.tdecay &&
Expand Down
4 changes: 2 additions & 2 deletions ratecoeff.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ constexpr auto simpson_integrator(auto &params, double a, double b, int sampleco
weight = 4.;
}

const double x = a + deltax * i;
const double x = a + (deltax * i);

integral += weight * func_integrand(x, &params) * deltax;
}
Expand All @@ -80,7 +80,7 @@ auto integrator(auto params, double a, double b, double epsabs, double epsrel, i
double *abserr) {
if constexpr (USE_SIMPSON_INTEGRATOR) {
// need an odd number for Simpson rule
const int samplecount = std::max(1, static_cast<int>((b / a) / globals::NPHIXSNUINCREMENT)) * 4 + 1;
const int samplecount = (std::max(1, static_cast<int>((b / a) / globals::NPHIXSNUINCREMENT)) * 4) + 1;

*result = simpson_integrator<func_integrand>(params, a, b, samplecount);
*abserr = 0.;
Expand Down
2 changes: 1 addition & 1 deletion rpkt.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void MPI_Bcast_binned_opacities(int modelgridindex, int root_node_id);
assert_testmodeonly(ion < get_nions(element) - 1);
const int groundcontindex = globals::elements[element].ions[ion].groundcontindex;
assert_always(groundcontindex >= 0);
return nonemptymgi * globals::nbfcontinua_ground + groundcontindex;
return (nonemptymgi * globals::nbfcontinua_ground) + groundcontindex;
}

inline auto keep_this_cont(int element, const int ion, const int level, const int modelgridindex,
Expand Down
6 changes: 3 additions & 3 deletions sn3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ inline void gsl_error_handler_printout(const char *reason, const char *file, int
const int phixstargetindex) -> int {
const int contindex = -1 - globals::elements[element].ions[ion].levels[level].cont_index + phixstargetindex;

const int bflutindex = tempindex * globals::nbfcontinua + contindex;
const int bflutindex = (tempindex * globals::nbfcontinua) + contindex;
assert_testmodeonly(bflutindex >= 0);
assert_testmodeonly(bflutindex <= TABLESIZE * globals::nbfcontinua);
return bflutindex;
Expand Down Expand Up @@ -321,8 +321,8 @@ constexpr auto get_range_chunk(const ptrdiff_t size, const ptrdiff_t nchunks,
assert_always(nchunk >= 0);
const auto minchunksize = size / nchunks; // integer division, minimum non-empty cells per process
const auto n_remainder = size % nchunks;
const auto nstart = (minchunksize + 1) * std::min(n_remainder, nchunk) +
minchunksize * std::max(static_cast<ptrdiff_t>(0), nchunk - n_remainder);
const auto nstart = ((minchunksize + 1) * std::min(n_remainder, nchunk)) +
(minchunksize * std::max(static_cast<ptrdiff_t>(0), nchunk - n_remainder));
const auto nsize = (nchunk < n_remainder) ? minchunksize + 1 : minchunksize;
assert_testmodeonly(nstart >= 0);
assert_testmodeonly(nsize >= 0);
Expand Down
23 changes: 12 additions & 11 deletions vectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// return the the magnitude of a vector
template <size_t VECDIM>
[[nodiscard]] constexpr auto vec_len(const std::array<double, VECDIM> &vec) -> double {
const double squaredlen = std::accumulate(vec.begin(), vec.end(), 0., [](auto a, auto b) { return a + b * b; });
const double squaredlen = std::accumulate(vec.begin(), vec.end(), 0., [](auto a, auto b) { return a + (b * b); });

return std::sqrt(squaredlen);
}
Expand Down Expand Up @@ -89,7 +89,7 @@ template <size_t S1, size_t S2>
const double ndotv_on_c = dot(dir_rf, vel_rf) / CLIGHT;
const double dopplerfactorsq = USE_RELATIVISTIC_DOPPLER_SHIFT
? std::pow(1. - ndotv_on_c, 2) / (1 - (dot(vel_rf, vel_rf) / CLIGHTSQUARED))
: (1. - 2 * ndotv_on_c);
: (1. - (2 * ndotv_on_c));

assert_testmodeonly(std::isfinite(dopplerfactorsq));
assert_testmodeonly(dopplerfactorsq > 0);
Expand Down Expand Up @@ -220,7 +220,8 @@ constexpr auto move_pkt_withtime(Packet &pkt, const double distance) -> double {

// ref1_sc is the ref1 axis in the scattering plane ref1 = n1 x ( n1 x n2 )
const double n1_dot_n2 = dot(n1, n2);
auto ref1_sc = std::array<double, 3>{n1[0] * n1_dot_n2 - n2[0], n1[1] * n1_dot_n2 - n2[1], n1[2] * n1_dot_n2 - n2[2]};
auto ref1_sc =
std::array<double, 3>{(n1[0] * n1_dot_n2) - n2[0], (n1[1] * n1_dot_n2) - n2[1], (n1[2] * n1_dot_n2) - n2[2]};
ref1_sc = vec_norm(ref1_sc);

const double cos_stokes_rot_1 = std::clamp(dot(ref1_sc, ref1), -1., 1.);
Expand Down Expand Up @@ -250,7 +251,7 @@ constexpr auto move_pkt_withtime(Packet &pkt, const double distance) -> double {
[[nodiscard]] constexpr auto meridian(const std::array<double, 3> &n)
-> std::tuple<std::array<double, 3>, std::array<double, 3>> {
// for ref_1 use (from triple product rule)
const double n_xylen = std::sqrt(n[0] * n[0] + n[1] * n[1]);
const double n_xylen = std::sqrt((n[0] * n[0]) + (n[1] * n[1]));
const auto ref1 =
std::array<double, 3>{-1. * n[0] * n[2] / n_xylen, -1. * n[1] * n[2] / n_xylen, (1 - (n[2] * n[2])) / n_xylen};

Expand Down Expand Up @@ -285,9 +286,9 @@ constexpr auto move_pkt_withtime(Packet &pkt, const double distance) -> double {
// const double v_cr_e[3] = {beta[1] * e_rf[2] - beta[2] * e_rf[1], beta[2] * e_rf[0] - beta[0] * e_rf[2],
// beta[0] * e_rf[1] - beta[1] * e_rf[0]};

const auto e_cmf = std::array<double, 3>{e_par[0] + gamma_rel * (e_perp[0] + v_cr_b[0]),
e_par[1] + gamma_rel * (e_perp[1] + v_cr_b[1]),
e_par[2] + gamma_rel * (e_perp[2] + v_cr_b[2])};
const auto e_cmf = std::array<double, 3>{e_par[0] + (gamma_rel * (e_perp[0] + v_cr_b[0])),
e_par[1] + (gamma_rel * (e_perp[1] + v_cr_b[1])),
e_par[2] + (gamma_rel * (e_perp[2] + v_cr_b[2]))};
return vec_norm(e_cmf);
}

Expand All @@ -301,7 +302,7 @@ constexpr auto frame_transform(const std::array<double, 3> &n_rf, double *Q, dou
const double U0 = *U;

// Compute polarisation (which is invariant)
const double p = sqrt(Q0 * Q0 + U0 * U0);
const double p = sqrt((Q0 * Q0) + (U0 * U0));

// We want to compute the angle between ref1 and the electric field
double rot_angle = 0;
Expand Down Expand Up @@ -334,9 +335,9 @@ constexpr auto frame_transform(const std::array<double, 3> &n_rf, double *Q, dou

// Define electric field by linear combination of ref1 and ref2 (using the angle just computed)

const auto elec_rf = std::array<double, 3>{cos(rot_angle) * ref1_rf[0] - sin(rot_angle) * ref2_rf[0],
cos(rot_angle) * ref1_rf[1] - sin(rot_angle) * ref2_rf[1],
cos(rot_angle) * ref1_rf[2] - sin(rot_angle) * ref2_rf[2]};
const auto elec_rf = std::array<double, 3>{(cos(rot_angle) * ref1_rf[0]) - (sin(rot_angle) * ref2_rf[0]),
(cos(rot_angle) * ref1_rf[1]) - (sin(rot_angle) * ref2_rf[1]),
(cos(rot_angle) * ref1_rf[2]) - (sin(rot_angle) * ref2_rf[2])};

// Aberration
const auto n_cmf = angle_ab(n_rf, v);
Expand Down

0 comments on commit 29ccf5a

Please sign in to comment.