Skip to content

Commit 38a1421

Browse files
authored
Merge pull request #1111 from PowerGridModel/feature/clang-tidy
Clean-up main model: fix windows clang-tidy
2 parents 964f50b + ad3c3eb commit 38a1421

File tree

9 files changed

+40
-34
lines changed

9 files changed

+40
-34
lines changed

power_grid_model_c/power_grid_model/include/power_grid_model/job_interface.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ template <typename Adapter> class JobInterface {
8484
static_cast<Adapter*>(this)->thread_safe_add_calculation_info_impl(info);
8585
}
8686

87-
protected:
88-
// Protected & defaulted special members — CRTP: only the derived can create/copy/move this base
87+
private:
88+
friend Adapter;
8989
JobInterface() = default;
9090
JobInterface(const JobInterface& /*other*/) = default;
9191
JobInterface& operator=(const JobInterface& /*other*/) = default;

power_grid_model_c/power_grid_model/include/power_grid_model/main_core/output.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include "../all_components.hpp"
1111

12+
#include <concepts>
13+
1214
namespace power_grid_model::main_core {
1315

1416
namespace detail {
@@ -103,7 +105,7 @@ template <typename Component, typename IndexType, class ComponentContainer, std:
103105
constexpr void produce_output(MainModelState<ComponentContainer> const& state, ComponentOutput&& output,
104106
ResFunc&& func) {
105107
std::ranges::transform(get_component_citer<Component>(state), comp_base_sequence<Component>(state),
106-
std::ranges::begin(output), std::forward<ResFunc>(func));
108+
std::ranges::begin(std::forward<ComponentOutput>(output)), std::forward<ResFunc>(func));
107109
}
108110

109111
} // namespace detail

power_grid_model_c/power_grid_model/include/power_grid_model/main_core/topology.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ constexpr void register_topology_components(ComponentContainer const& components
180180

181181
template <std::same_as<Branch> Component, class ComponentContainer>
182182
requires common::component_container_c<ComponentContainer, Component>
183-
constexpr void register_connections_components(ComponentContainer components, ComponentConnections& comp_conn) {
183+
constexpr void register_connections_components(ComponentContainer const& components, ComponentConnections& comp_conn) {
184184
apply_registration<Component>(components, comp_conn.branch_connected, [](Branch const& branch) {
185185
return BranchConnected{static_cast<IntS>(branch.from_status()), static_cast<IntS>(branch.to_status())};
186186
});
@@ -189,7 +189,7 @@ constexpr void register_connections_components(ComponentContainer components, Co
189189
}
190190
template <std::same_as<Branch3> Component, class ComponentContainer>
191191
requires common::component_container_c<ComponentContainer, Component>
192-
constexpr void register_connections_components(ComponentContainer components, ComponentConnections& comp_conn) {
192+
constexpr void register_connections_components(ComponentContainer const& components, ComponentConnections& comp_conn) {
193193
apply_registration<Component>(components, comp_conn.branch3_connected, [](Branch3 const& branch3) {
194194
return Branch3Connected{static_cast<IntS>(branch3.status_1()), static_cast<IntS>(branch3.status_2()),
195195
static_cast<IntS>(branch3.status_3())};
@@ -200,7 +200,7 @@ constexpr void register_connections_components(ComponentContainer components, Co
200200

201201
template <std::same_as<Source> Component, class ComponentContainer>
202202
requires common::component_container_c<ComponentContainer, Component>
203-
constexpr void register_connections_components(ComponentContainer components, ComponentConnections& comp_conn) {
203+
constexpr void register_connections_components(ComponentContainer const& components, ComponentConnections& comp_conn) {
204204
apply_registration<Component>(components, comp_conn.source_connected,
205205
[](Source const& source) { return source.status(); });
206206
}

power_grid_model_c/power_grid_model/include/power_grid_model/main_core/y_bus.hpp

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

55
#pragma once
66

7+
#include "../common/common.hpp"
8+
79
namespace power_grid_model::main_core {
810

911
template <symmetry_tag sym, typename ComponentContainer, typename... ComponentType>
@@ -47,7 +49,7 @@ void prepare_y_bus(MainModelState<ComponentContainer> const& state_, Idx n_math_
4749

4850
template <symmetry_tag sym, typename ComponentContainer, typename... ComponentType>
4951
static std::vector<MathModelParamIncrement> get_math_param_increment(
50-
MainModelState<ComponentContainer> received_state, Idx n_math_solvers_,
52+
MainModelState<ComponentContainer>& received_state, Idx n_math_solvers_,
5153
std::array<std::vector<Idx2D>, main_core::utils::n_types<ComponentType...>> const& parameter_changed_components_) {
5254
using AddToIncrement =
5355
void (*)(std::vector<MathModelParamIncrement>&, MainModelState<ComponentContainer> const&, Idx2D const&);

power_grid_model_c/power_grid_model/include/power_grid_model/math_solver/y_bus.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ struct YBusStructure {
264264
// construct transpose entry
265265
lu_transpose_entry.resize(nnz_counter_lu);
266266
// default transpose_entry[i] = i
267-
std::iota(lu_transpose_entry.begin(), lu_transpose_entry.end(), 0);
267+
std::iota( // NOLINT(modernize-use-ranges) // not yet supported by some compilers
268+
lu_transpose_entry.begin(), lu_transpose_entry.end(), 0);
268269
// fill off-diagonal, loop all the branches
269270
for (auto const [entry_1, entry_2] : off_diag_map) {
270271
// for each branch entry tf and ft, they are transpose to each other

tests/benchmark_cpp/benchmark.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,26 @@ std::string make_key(LogEvent code) {
104104
}
105105

106106
auto get_benchmark_run_title(Option const& option, MainModelOptions const& model_options) {
107-
auto const mv_ring_type = option.has_mv_ring ? "meshed grid" : "radial grid";
107+
using namespace std::string_literals;
108+
auto const mv_ring_type = option.has_mv_ring ? "meshed grid"s : "radial grid"s;
108109
auto const sym_type =
109-
model_options.calculation_symmetry == CalculationSymmetry::symmetric ? "symmetric" : "asymmetric";
110+
model_options.calculation_symmetry == CalculationSymmetry::symmetric ? "symmetric"s : "asymmetric"s;
110111
auto const method = [calculation_method = model_options.calculation_method] {
111112
using enum CalculationMethod;
112113

113114
switch (calculation_method) {
114115
case newton_raphson:
115-
return "Newton-Raphson method";
116+
return "Newton-Raphson method"s;
116117
case linear:
117-
return "Linear method";
118+
return "Linear method"s;
118119
case linear_current:
119-
return "Linear current method";
120+
return "Linear current method"s;
120121
case iterative_current:
121-
return "Iterative current method";
122+
return "Iterative current method"s;
122123
case iterative_linear:
123-
return "Iterative linear method";
124+
return "Iterative linear method"s;
124125
case iec60909:
125-
return "IEC 60909 method";
126+
return "IEC 60909 method"s;
126127
default:
127128
throw MissingCaseForEnumError{"get_benchmark_run_title", calculation_method};
128129
}
@@ -171,15 +172,18 @@ struct PowerGridBenchmark {
171172
auto const run = [this, &model_options, &info](Idx batch_size_) {
172173
switch (model_options.calculation_type) {
173174
case short_circuit:
174-
return run_calculation<ShortCircuitOutputData>(model_options, batch_size_, info);
175+
run_calculation<ShortCircuitOutputData>(model_options, batch_size_, info);
176+
break;
175177
case power_flow:
176178
[[fallthrough]];
177179
case state_estimation: {
178180
switch (model_options.calculation_symmetry) {
179181
case CalculationSymmetry::symmetric:
180-
return run_calculation<OutputData<symmetric_t>>(model_options, batch_size_, info);
182+
run_calculation<OutputData<symmetric_t>>(model_options, batch_size_, info);
183+
break;
181184
case CalculationSymmetry::asymmetric:
182-
return run_calculation<OutputData<asymmetric_t>>(model_options, batch_size_, info);
185+
run_calculation<OutputData<asymmetric_t>>(model_options, batch_size_, info);
186+
break;
183187
default:
184188
throw MissingCaseForEnumError{"run_benchmark<calculation_symmetry>",
185189
model_options.calculation_symmetry};
@@ -231,11 +235,6 @@ struct PowerGridBenchmark {
231235
} // namespace
232236
} // namespace power_grid_model::benchmark
233237

234-
namespace {
235-
using power_grid_model::asymmetric_t;
236-
using power_grid_model::symmetric_t;
237-
} // namespace
238-
239238
int main(int /* argc */, char** /* argv */) {
240239
using enum power_grid_model::CalculationType;
241240
using enum power_grid_model::CalculationMethod;

tests/benchmark_cpp/fictional_grid_generator.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,8 @@ class FictionalGridGenerator {
646646
std::uniform_real_distribution<double> load_scaling_gen{0.0, 1.0};
647647
load_series.resize(input.size() * batch_size);
648648
auto const n_object = std::ssize(input);
649-
for (Idx batch : IdxRange{batch_size}) {
650-
for (Idx object : IdxRange{n_object}) {
649+
for (Idx const batch : IdxRange{batch_size}) {
650+
for (Idx const object : IdxRange{n_object}) {
651651
T const& input_obj = input[object];
652652
U& update_obj = load_series[batch * n_object + object];
653653
update_obj.id = input_obj.id;
@@ -698,10 +698,10 @@ class FictionalGridGenerator {
698698

699699
sensor_series.resize(input.size() * batch_size);
700700
auto const n_object = std::ssize(input);
701-
for (Idx object : IdxRange{n_object}) {
701+
for (Idx const object : IdxRange{n_object}) {
702702
T const& input_obj = input[object];
703703

704-
for (Idx batch : IdxRange{batch_size}) {
704+
for (Idx const batch : IdxRange{batch_size}) {
705705
U& update_obj = sensor_series[batch * n_object + object];
706706
update_obj.id = input_obj.id;
707707
if constexpr (is_symmetric_v<typename T::sym>) {

tests/cpp_unit_tests/test_dataset.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,10 @@ TEST_CASE_TEMPLATE("Test dataset (common)", DatasetType, ConstDataset, MutableDa
10711071
auto a_a1_buffer = std::vector<double>(a_elements_per_scenario * batch_size);
10721072
auto b_indptr = std::vector<Idx>{0, 0, 3};
10731073

1074-
std::iota(a_id_buffer.begin(), a_id_buffer.end(), ID{0});
1075-
std::iota(a_a1_buffer.begin(), a_a1_buffer.end(), 0.0);
1074+
std::iota( // NOLINT(modernize-use-ranges) // not yet supported by some compilers
1075+
a_id_buffer.begin(), a_id_buffer.end(), ID{0});
1076+
std::iota( // NOLINT(modernize-use-ranges) // not yet supported by some compilers
1077+
a_a1_buffer.begin(), a_a1_buffer.end(), 0.0);
10761078

10771079
add_homogeneous_buffer(dataset, A::name, a_elements_per_scenario, nullptr);
10781080
add_attribute_buffer(dataset, A::name, "id", static_cast<void*>(a_id_buffer.data()));

tests/cpp_unit_tests/test_exceptions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ TEST_CASE("Exceptions") {
3838
CHECK(std::string{InvalidArguments{"bar"}.what()} == "bar");
3939
CHECK(std::string{InvalidArguments{"foo", "bar"}.what()} == "foo is not implemented for bar!\n");
4040

41-
InvalidArguments::TypeValuePair const foo{"foo", "baz"};
42-
InvalidArguments::TypeValuePair const bar{"bar", "bla"};
41+
InvalidArguments::TypeValuePair const foo{.name = "foo", .value = "baz"};
42+
InvalidArguments::TypeValuePair const bar{.name = "bar", .value = "bla"};
4343
CHECK(std::string{InvalidArguments{"Test method", foo}.what()} ==
4444
"Test method is not implemented for the following combination of options!\n"
4545
" foo: baz\n");
@@ -298,8 +298,8 @@ TEST_CASE("Exceptions") {
298298
CHECK(std::string{ExperimentalFeature{"bar"}.what()} == "bar");
299299
CHECK(std::string{ExperimentalFeature{"foo", "bar"}.what()} == "foo is not implemented for bar!\n");
300300

301-
ExperimentalFeature::TypeValuePair const foo{"foo", "baz"};
302-
ExperimentalFeature::TypeValuePair const bar{"bar", "bla"};
301+
ExperimentalFeature::TypeValuePair const foo{.name = "foo", .value = "baz"};
302+
ExperimentalFeature::TypeValuePair const bar{.name = "bar", .value = "bla"};
303303
CHECK(std::string{ExperimentalFeature{"Test method", foo}.what()} ==
304304
"Test method is not implemented for the following combination of options!\n"
305305
" foo: baz\n");

0 commit comments

Comments
 (0)