Skip to content

Commit f9e0afc

Browse files
committed
enable c++ warnings;treat warnings as errors;fix warnings;
1 parent 7957b2c commit f9e0afc

58 files changed

Lines changed: 338 additions & 275 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cpp/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ add_library(epidemiology
3737
epidemiology/migration/migration.cpp
3838
epidemiology/utils/graph.h
3939
epidemiology/utils/graph.cpp
40+
epidemiology/utils/eigen.h
4041
epidemiology/utils/eigen_util.h
4142
epidemiology/secir/populations.h
4243
epidemiology/secir/populations.cpp
@@ -80,6 +81,9 @@ target_include_directories(epidemiology PUBLIC
8081

8182
target_compile_features(epidemiology PUBLIC cxx_std_14)
8283
target_link_libraries(epidemiology PUBLIC spdlog::spdlog Eigen3::Eigen)
84+
target_compile_options(epidemiology PRIVATE
85+
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>: -Wall -Wextra -Werror -Wshadow --pedantic-errors -Wno-deprecated-copy>
86+
$<$<CXX_COMPILER_ID:MSVC>: /W4 /WX>)
8387

8488
if (EPI_BUILD_EPI_IO)
8589

@@ -104,6 +108,9 @@ if (EPI_BUILD_EPI_IO)
104108
target_include_directories(epidemiology_io PRIVATE ${HDF5_INCLUDE_DIRS})
105109

106110
target_compile_definitions(epidemiology_io PUBLIC "-DHAVE_EPI_IO")
111+
target_compile_options(epidemiology_io PRIVATE
112+
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>: -Wall -Wextra -Werror -Wshadow --pedantic-errors -Wno-deprecated-copy>
113+
$<$<CXX_COMPILER_ID:MSVC>: /W4 /WX>)
107114

108115
endif(EPI_BUILD_EPI_IO)
109116

cpp/epidemiology/abm/location.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ namespace
3030
InfectionState random_transition(InfectionState old_state, double dt,
3131
const std::pair<InfectionState, double> (&transitions)[NumTransitions])
3232
{
33-
auto sum = std::accumulate(std::begin(transitions), std::end(transitions), 0.0, [](auto&& sum, auto&& t) {
34-
return t.second + sum;
33+
auto sum = std::accumulate(std::begin(transitions), std::end(transitions), 0.0, [](auto&& a, auto&& t) {
34+
return a + t.second;
3535
});
3636

3737
if (sum <= 0) {
@@ -78,7 +78,7 @@ InfectionState Location::interact(const Person& person, double dt, const GlobalI
7878
}
7979
}
8080

81-
void Location::begin_step(double dt, const GlobalInfectionParameters& global_params)
81+
void Location::begin_step(double /*dt*/, const GlobalInfectionParameters& global_params)
8282
{
8383
//cache for next step so it stays constant during the step while subpopulations change
8484
//otherwise we would have to cache all state changes during a step which uses more memory

cpp/epidemiology/abm/location.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "epidemiology/abm/state.h"
66
#include "epidemiology/abm/location_type.h"
77

8-
#include <Eigen/Core>
8+
#include "epidemiology/utils/eigen.h"
99
#include <array>
1010
#include <random>
1111

@@ -25,6 +25,14 @@ class Location
2525
*/
2626
Location(LocationType type);
2727

28+
/**
29+
* get the type of this location.
30+
*/
31+
LocationType get_type() const
32+
{
33+
return m_type;
34+
}
35+
2836
/**
2937
* a person interacts with the population at this location, may change infection state.
3038
* @param person the person that interacts with the population

cpp/epidemiology/abm/person.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class Person
5757
}
5858

5959
private:
60+
std::reference_wrapper<Location> m_location;
6061
InfectionState m_state;
6162
double m_time_until_carrier;
62-
std::reference_wrapper<Location> m_location;
6363
//age, times, ...
6464
};
6565

cpp/epidemiology/abm/random_number_generator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class DiscreteDistributionInPlace
230230
}
231231
}
232232
assert(false && "this should never happen.");
233-
return -1;
233+
return result_type(-1);
234234
}
235235

236236
private:

cpp/epidemiology/abm/simulation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace epi
55

66
AbmSimulation::AbmSimulation(double t, World&& world)
77
: m_world(std::move(world))
8+
, m_result(Eigen::Index(InfectionState::Count))
89
, m_t(t)
910
, m_dt(1.0)
10-
, m_result(Eigen::Index(InfectionState::Count))
1111
{
1212
store_result_at(t);
1313
}

cpp/epidemiology/abm/simulation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class AbmSimulation
4141
private:
4242
void store_result_at(double t);
4343

44-
double m_t;
45-
double m_dt;
4644
World m_world;
4745
TimeSeries<double> m_result;
46+
double m_t;
47+
double m_dt;
4848
};
4949

5050
} // namespace epi

cpp/epidemiology/math/euler.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@ bool EulerIntegratorCore::step(const DerivFunction& f, Eigen::Ref<const Eigen::V
1414
return true;
1515
}
1616

17-
ImplicitEulerIntegratorCore::ImplicitEulerIntegratorCore(double dt_min, double dt_max, SecirParams const& params)
18-
: m_abs_tol(1e-10)
19-
, m_rel_tol(1e-5)
20-
, m_dt_min(dt_min)
21-
, m_dt_max(dt_max)
22-
, m_params{params}
17+
ImplicitEulerIntegratorCore::ImplicitEulerIntegratorCore(SecirParams const& params)
18+
: m_params{params}
2319
{
2420
}
2521

26-
bool ImplicitEulerIntegratorCore::step(const DerivFunction& f, Eigen::Ref<const Eigen::VectorXd> yt, double& t,
22+
bool ImplicitEulerIntegratorCore::step(const DerivFunction& /*f*/, Eigen::Ref<const Eigen::VectorXd> yt, double& t,
2723
double& dt, Eigen::Ref<Eigen::VectorXd> ytp1) const
2824
{
2925
// 0: S, 1: E, 2: C, 3: I, 4: H, 5: U, 6: R, 7: D

cpp/epidemiology/math/euler.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ class ImplicitEulerIntegratorCore : public IntegratorCore
3636
public:
3737
/**
3838
* @brief Setting up the implicit Euler integrator
39-
* @param dt_min Mininum time step
40-
* @param dt_max Maximum time step
4139
* @param params Paramters of the SECIR/SECIHURD model
4240
*/
43-
ImplicitEulerIntegratorCore(double dt_min, double dt_max, SecirParams const& params);
41+
ImplicitEulerIntegratorCore(SecirParams const& params);
4442

4543
/**
4644
* @brief Fixed step width of the time implicit Euler time integration scheme
@@ -58,21 +56,7 @@ class ImplicitEulerIntegratorCore : public IntegratorCore
5856
return m_params;
5957
}
6058

61-
/// @param tol the required absolute tolerance for the comparison with the Fehlberg approximation (actually not really required but used in SecirSimulation constructor)
62-
void set_abs_tolerance(double tol)
63-
{
64-
m_abs_tol = tol;
65-
}
66-
67-
/// @param tol the required relative tolerance for the comparison with the Fehlberg approximation (actually not really required but used in SecirSimulation constructor)
68-
void set_rel_tolerance(double tol)
69-
{
70-
m_rel_tol = tol;
71-
}
72-
7359
private:
74-
double m_abs_tol, m_rel_tol;
75-
double m_dt_min, m_dt_max;
7660
const SecirParams& m_params;
7761
};
7862

cpp/epidemiology/math/integrator.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <epidemiology/utils/time_series.h>
55

6-
#include <Eigen/Core>
6+
#include "epidemiology/utils/eigen.h"
77
#include <memory>
88
#include <vector>
99
#include <functional>
@@ -76,10 +76,10 @@ class OdeIntegrator
7676
}
7777

7878
private:
79-
std::shared_ptr<IntegratorCore> m_core;
80-
double m_dt;
81-
TimeSeries<double> m_result;
8279
DerivFunction m_f;
80+
TimeSeries<double> m_result;
81+
double m_dt;
82+
std::shared_ptr<IntegratorCore> m_core;
8383
};
8484

8585
} // namespace epi

0 commit comments

Comments
 (0)