Skip to content

Commit 45e11ab

Browse files
authored
Merge pull request #415 from boutproject/more-warning-fixes
More warning fixes
2 parents 0e601f7 + 07ff74e commit 45e11ab

File tree

9 files changed

+32
-25
lines changed

9 files changed

+32
-25
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ add_library(hermes_warnings INTERFACE)
203203
hermes_set_project_warnings(hermes_warnings ${HERMES_ERROR_ON_WARNINGS} "" "" "" "")
204204

205205
if (HERMES_ENABLE_WARNINGS)
206+
target_link_libraries(hermes-3-lib PRIVATE hermes_warnings)
206207
target_link_libraries(hermes-3 PRIVATE hermes_warnings)
207208
endif()
208209

include/adas_neon.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ constexpr std::initializer_list<char> neon_species_name<0>{'n', 'e'};
3737
/// ADAS effective ionisation (ADF11)
3838
///
3939
/// @tparam level The ionisation level of the ion on the left of the reaction
40-
template <int level>
40+
template <std::size_t level>
4141
struct ADASNeonIonisation : public OpenADAS {
4242
ADASNeonIonisation(std::string, Options& alloptions, Solver*)
4343
: OpenADAS(alloptions["units"], "scd96_ne.json", "plt96_ne.json", level,
@@ -57,7 +57,7 @@ struct ADASNeonIonisation : public OpenADAS {
5757
/// ADAS effective recombination coefficients (ADF11)
5858
///
5959
/// @tparam level The ionisation level of the ion on the right of the reaction
60-
template <int level>
60+
template <std::size_t level>
6161
struct ADASNeonRecombination : public OpenADAS {
6262
/// @param alloptions The top-level options. Only uses the ["units"] subsection.
6363
ADASNeonRecombination(std::string, Options& alloptions, Solver*)
@@ -75,7 +75,7 @@ struct ADASNeonRecombination : public OpenADAS {
7575

7676
/// @tparam level The ionisation level of the ion on the right of the reaction
7777
/// @tparam Hisotope The hydrogen isotope ('h', 'd' or 't')
78-
template <int level, char Hisotope>
78+
template <std::size_t level, char Hisotope>
7979
struct ADASNeonCX : public OpenADASChargeExchange {
8080
/// @param alloptions The top-level options. Only uses the ["units"] subsection.
8181
ADASNeonCX(std::string, Options& alloptions, Solver*)

include/adas_reaction.hxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "component.hxx"
66
#include "reaction.hxx"
7+
8+
#include <cstddef>
79
#include <vector>
810

911
/// Represent a 2D rate coefficient table (T,n)
@@ -13,7 +15,7 @@ struct OpenADASRateCoefficient {
1315
/// @param filename The file to read. Path relative to run working directory
1416
/// @param level The first index in the log coefficient array
1517
/// (ionisation level)
16-
OpenADASRateCoefficient(const std::string& filename, int level);
18+
OpenADASRateCoefficient(const std::string& filename, std::size_t level);
1719

1820
std::vector<std::vector<BoutReal>> log_coeff;
1921
std::vector<BoutReal> log_temperature;
@@ -53,7 +55,7 @@ struct OpenADAS : public ReactionBase {
5355
/// - The rate and radiation file names have "json_database/" prepended
5456
///
5557
OpenADAS(const Options& units, const std::string& rate_file,
56-
const std::string& radiation_file, int level, BoutReal electron_heating)
58+
const std::string& radiation_file, std::size_t level, BoutReal electron_heating)
5759
: rate_coef(std::string("json_database/") + rate_file, level),
5860
radiation_coef(std::string("json_database/") + radiation_file, level),
5961
electron_heating(electron_heating) {
@@ -79,7 +81,7 @@ private:
7981
};
8082

8183
struct OpenADASChargeExchange : public ReactionBase {
82-
OpenADASChargeExchange(const Options& units, const std::string& rate_file, int level)
84+
OpenADASChargeExchange(const Options& units, const std::string& rate_file, std::size_t level)
8385
: rate_coef(std::string("json_database/") + rate_file, level) {
8486
// Get the units
8587
Tnorm = get<BoutReal>(units["eV"]);

src/adas_reaction.cxx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
#include "../external/json.hxx"
2020

2121
#include <algorithm>
22+
#include <cstddef>
2223
#include <fstream>
2324
#include <iterator>
2425

25-
OpenADASRateCoefficient::OpenADASRateCoefficient(const std::string& filename, int level) {
26+
OpenADASRateCoefficient::OpenADASRateCoefficient(const std::string& filename, std::size_t level) {
2627
AUTO_TRACE();
2728

2829
// Read the rate file
@@ -54,7 +55,7 @@ OpenADASRateCoefficient::OpenADASRateCoefficient(const std::string& filename, in
5455

5556
namespace {
5657

57-
int get_high_index(const std::vector<BoutReal>& vec, BoutReal value) {
58+
auto get_high_index(const std::vector<BoutReal>& vec, BoutReal value) {
5859
ASSERT2(vec.size() > 1); // Need at least two elements
5960

6061
// Iterator pointing to the first element greater than or equal to log10T
@@ -64,10 +65,10 @@ int get_high_index(const std::vector<BoutReal>& vec, BoutReal value) {
6465
} else if (high_it == vec.begin()) {
6566
++high_it; // Shift to the second element
6667
}
67-
int high_index = std::distance(vec.begin(), high_it);
68+
const auto high_index = std::distance(vec.begin(), high_it);
6869

69-
ASSERT2((high_index > 0) and (high_index < static_cast<int>(vec.size())));
70-
return high_index;
70+
ASSERT2((high_index > 0) and (static_cast<std::size_t>(high_index) < vec.size()));
71+
return static_cast<std::size_t>(high_index);
7172
}
7273

7374
} // namespace
@@ -80,8 +81,8 @@ BoutReal OpenADASRateCoefficient::evaluate(BoutReal T, BoutReal n) {
8081
BoutReal log10n = log10(std::clamp(n, nmin, nmax));
8182

8283
// Get the upper index. Between 1 and size-1 inclusive
83-
int high_T_index = get_high_index(log_temperature, log10T);
84-
int high_n_index = get_high_index(log_density, log10n);
84+
const auto high_T_index = get_high_index(log_temperature, log10T);
85+
const auto high_n_index = get_high_index(log_density, log10n);
8586

8687
// Construct the simple interpolation grid
8788
// Find weightings based on linear distance
@@ -91,12 +92,13 @@ BoutReal OpenADASRateCoefficient::evaluate(BoutReal T, BoutReal n) {
9192
// | / \ | |
9293
// w00 ------ w10
9394

94-
int low_T_index = high_T_index - 1;
95+
// This is ok because high_T_index is >= 1
96+
const auto low_T_index = high_T_index - 1;
9597

9698
BoutReal x = (log10T - log_temperature[low_T_index])
9799
/ (log_temperature[high_T_index] - log_temperature[low_T_index]);
98100

99-
int low_n_index = high_n_index - 1;
101+
const auto low_n_index = high_n_index - 1;
100102

101103
BoutReal y = (log10n - log_density[low_n_index])
102104
/ (log_density[high_n_index] - log_density[low_n_index]);

src/component.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ std::unique_ptr<Component> Component::create(const std::string &type,
66
Options &alloptions,
77
Solver *solver) {
88

9-
return std::unique_ptr<Component>(
10-
ComponentFactory::getInstance().create(type, name, alloptions, solver));
9+
return ComponentFactory::getInstance().create(type, name, alloptions, solver);
1110
}
1211

1312
constexpr decltype(ComponentFactory::type_name) ComponentFactory::type_name;

src/detachment_controller.cxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "../include/detachment_controller.hxx"
22

3+
#include <bout/bout_types.hxx>
34
#include <bout/mesh.hxx>
45
using bout::globals::mesh;
56
#include <algorithm> // Include for std::max
@@ -8,7 +9,7 @@ using bout::globals::mesh;
89
#include <numeric>
910

1011
BoutReal calculateGradient(const std::vector<BoutReal>& x, const std::vector<BoutReal>& y) {
11-
size_t N = x.size();
12+
const auto N = x.size();
1213
BoutReal sum_x = std::accumulate(x.begin(), x.end(), 0.0);
1314
BoutReal sum_y = std::accumulate(y.begin(), y.end(), 0.0);
1415
BoutReal sum_xy = 0.0;
@@ -19,8 +20,9 @@ BoutReal calculateGradient(const std::vector<BoutReal>& x, const std::vector<Bou
1920
sum_x_squared += x[i] * x[i];
2021
}
2122

22-
BoutReal numerator = N * sum_xy - sum_x * sum_y;
23-
BoutReal denominator = N * sum_x_squared - sum_x * sum_x;
23+
const auto N_real = static_cast<BoutReal>(N);
24+
const BoutReal numerator = (N_real * sum_xy) - (sum_x * sum_y);
25+
const BoutReal denominator = (N_real * sum_x_squared) - (sum_x * sum_x);
2426

2527
if (denominator == 0) {
2628
return 0.0; // Handle division by zero or return an error code

src/ionisation.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ BoutReal ionisation_rate(BoutReal T) {
1414
const auto log_T = log(T);
1515
double lograte = 0.0;
1616
for (std::size_t i = 0; i < ioncoeffs.size(); i++) {
17-
lograte = lograte + ioncoeffs[i] * pow(log_T, i);
17+
lograte = lograte + (ioncoeffs[i] * pow(log_T, static_cast<BoutReal>(i)));
1818
}
1919

2020
return exp(lograte) * 1.0E-6;

src/neutral_mixed.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ NeutralMixed::NeutralMixed(const std::string& name, Options& alloptions, Solver*
104104
.withDefault<std::string>("multispecies");
105105

106106
if (precondition) {
107-
inv = std::unique_ptr<Laplacian>(Laplacian::create(&options["precon_laplace"]));
107+
inv = Laplacian::create(&options["precon_laplace"]);
108108

109109
inv->setInnerBoundaryFlags(INVERT_DC_GRAD | INVERT_AC_GRAD);
110110
inv->setOuterBoundaryFlags(INVERT_DC_GRAD | INVERT_AC_GRAD);

tests/unit/test_adas_reactions.hxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "../../include/adas_carbon.hxx"
77
#include "../../include/adas_lithium.hxx"
88
#include "../../include/adas_neon.hxx"
9+
#include <cstddef>
910

1011
/**
1112
* @brief Base fixture for tests of OpenADAS subclasses.
@@ -192,7 +193,7 @@ public:
192193
};
193194

194195
// Li CX
195-
template <int level, char Hisotope>
196+
template <std::size_t level, char Hisotope>
196197
class ADASLiCXReactionTest : public ADASCXReactionTest<ADASLithiumCX<level, Hisotope>> {
197198
public:
198199
ADASLiCXReactionTest(std::string lbl, std::string reaction_str)
@@ -217,7 +218,7 @@ public:
217218
};
218219

219220
// Ne CX
220-
template <int level, char Hisotope>
221+
template <std::size_t level, char Hisotope>
221222
class ADASNeCXReactionTest : public ADASCXReactionTest<ADASNeonCX<level, Hisotope>> {
222223
public:
223224
ADASNeCXReactionTest(std::string lbl, std::string reaction_str)
@@ -240,4 +241,4 @@ class ADASNep9TCXTest : public ADASNeCXReactionTest<8, 't'> {
240241
public:
241242
ADASNep9TCXTest() : ADASNeCXReactionTest<8, 't'>("Nep9TCX", "ne+9 + t -> ne+8 + t+") {}
242243
};
243-
#endif
244+
#endif

0 commit comments

Comments
 (0)