Skip to content

Commit f7239d1

Browse files
committed
More apply clang-tidy-19
Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>
1 parent cebfb0c commit f7239d1

20 files changed

+163
-194
lines changed

power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/serialization/deserializer.hpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,11 @@ class Deserializer {
673673
while (n_components-- != 0) {
674674
component_key_ = parse_string();
675675
Idx const component_size = parse_map_array<visit_array_t, stay_offset>().size;
676-
count_per_scenario.push_back({.component = component_key_, .size = component_size, .offset = offset_});
677-
// skip all the real content
678-
parse_skip();
676+
size_t const scenario_offset = offset_;
677+
// skip all the real content but check if it has map
678+
bool const has_map = parse_skip_check_map();
679+
count_per_scenario.push_back(
680+
{.component = component_key_, .size = component_size, .offset = scenario_offset, .has_map = has_map});
679681
}
680682
component_key_ = {};
681683
return count_per_scenario;
@@ -724,8 +726,8 @@ class Deserializer {
724726
elements_per_scenario * batch_size; // multiply
725727
handler.add_component_info(component_key_, elements_per_scenario, total_elements);
726728
// check if all scenarios only contain array data
727-
bool const only_values_in_data = std::none_of(component_byte_meta.cbegin(), component_byte_meta.cend(),
728-
[](auto const& x) { return x.has_map; });
729+
bool const only_values_in_data =
730+
std::ranges::none_of(component_byte_meta, [](auto const& x) { return x.has_map; });
729731
msg_data_offsets_.push_back(std::move(component_byte_meta));
730732
// enable attribute indications if possible
731733
if (only_values_in_data) {

power_grid_model_c/power_grid_model/include/power_grid_model/common/common.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct Idx2D {
3131
};
3232

3333
struct Idx2DHash {
34-
std::size_t operator()(const Idx2D& idx) const {
34+
std::size_t operator()(Idx2D const& idx) const {
3535
size_t const h1 = std::hash<Idx>{}(idx.group);
3636
size_t const h2 = std::hash<Idx>{}(idx.pos);
3737
return h1 ^ (h2 << 1);

power_grid_model_c/power_grid_model/include/power_grid_model/common/exception.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class InvalidArguments : public PowerGridError {
5353
class MissingCaseForEnumError : public InvalidArguments {
5454
public:
5555
template <typename T>
56-
MissingCaseForEnumError(std::string const& method, const T& value)
56+
MissingCaseForEnumError(std::string const& method, T const& value)
5757
: InvalidArguments{method, std::string{typeid(T).name()} + " #" + detail::to_string(static_cast<IntS>(value))} {
5858
}
5959
};
@@ -291,7 +291,7 @@ class UnreachableHit : public PowerGridError {
291291
class TapSearchStrategyIncompatibleError : public InvalidArguments {
292292
public:
293293
template <typename T1, typename T2>
294-
TapSearchStrategyIncompatibleError(std::string const& method, const T1& value1, const T2& value2)
294+
TapSearchStrategyIncompatibleError(std::string const& method, T1 const& value1, T2 const& value2)
295295
: InvalidArguments{
296296
method, std::string{typeid(T1).name()} + " #" + detail::to_string(static_cast<IntS>(value1)) + " and " +
297297
std::string{typeid(T2).name()} + " #" + detail::to_string(static_cast<IntS>(value2))} {}

power_grid_model_c/power_grid_model/include/power_grid_model/common/three_phase_tensor.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ template <column_vector DerivedA> inline auto mean_val(Eigen::ArrayBase<DerivedA
238238
inline DoubleComplex mean_val(DoubleComplex const& z) { return z; }
239239
inline double mean_val(double z) { return z; }
240240

241-
template <symmetry_tag sym, class T> inline auto process_mean_val(const T& m) {
241+
template <symmetry_tag sym, class T> inline auto process_mean_val(T const& m) {
242242
if constexpr (is_symmetric_v<sym>) {
243243
return mean_val(m);
244244
} else {
@@ -348,9 +348,7 @@ inline auto all_zero(RealValue<asymmetric_t> const& value) { return (value == Re
348348
//
349349
// The function assumes that the current value is normalized and new value should be normalized with scalar
350350
template <symmetry_tag sym, class Proxy>
351-
inline void
352-
update_real_value(RealValue<sym> const& new_value, Proxy&& current_value,
353-
double scalar) { // NOLINT(cppcoreguidelines-missing-std-forward) // perfect forward into void
351+
inline void update_real_value(RealValue<sym> const& new_value, Proxy&& current_value, double scalar) {
354352
if constexpr (is_symmetric_v<sym>) {
355353
if (!is_nan(new_value)) {
356354
std::forward<Proxy>(current_value) = scalar * new_value;

power_grid_model_c/power_grid_model/include/power_grid_model/common/timer.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class Timer {
2929
Timer(CalculationInfo& info, int code, std::string name)
3030
: info_(&info), code_(code), name_(std::move(name)), start_(Clock::now()) {}
3131

32-
Timer(const Timer&) = delete;
32+
Timer(Timer const&) = delete;
3333
Timer(Timer&&) = default;
34-
Timer& operator=(const Timer&) = delete;
34+
Timer& operator=(Timer const&) = delete;
3535

3636
Timer& operator=(Timer&& timer) noexcept {
3737
// Stop the current timer

power_grid_model_c/power_grid_model/include/power_grid_model/component/base.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class Base {
3636
Base& operator=(Base&&) = default;
3737

3838
protected:
39-
Base(const Base&) = default;
40-
Base& operator=(const Base&) = default;
39+
Base(Base const&) = default;
40+
Base& operator=(Base const&) = default;
4141

4242
private:
4343
ID id_;

power_grid_model_c/power_grid_model/include/power_grid_model/component/load_gen.hpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ class LoadGen final : public std::conditional_t<is_generator_v<appliance_type_>,
173173
case const_i:
174174
return params() * cabs(u);
175175
default:
176-
auto const& load_gen_name =
177-
this->name; // NOLINT(readability-static-accessed-through-instance) // for derived class type
178-
throw MissingCaseForEnumError(std::string{load_gen_name} + " power scaling factor", this->type());
176+
throw MissingCaseForEnumError(std::string{name} + " power scaling factor", this->type());
179177
}
180178
}
181179
};

power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
369369
state_, update_data, 0, components_to_update, update_independence, false);
370370
}
371371

372-
void update_state(const UpdateChange& changes) {
372+
void update_state(UpdateChange const& changes) {
373373
// if topology changed, everything is not up to date
374374
// if only param changed, set param to not up to date
375375
is_topology_up_to_date_ = is_topology_up_to_date_ && !changes.topo;
@@ -523,9 +523,9 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
523523
*meta_data_,
524524
},
525525
ignore_output);
526-
} catch (const SparseMatrixError&) { // NOLINT(bugprone-empty-catch) // NOSONAR
526+
} catch (SparseMatrixError const&) { // NOLINT(bugprone-empty-catch) // NOSONAR
527527
// missing entries are provided in the update data
528-
} catch (const NotObservableError&) { // NOLINT(bugprone-empty-catch) // NOSONAR
528+
} catch (NotObservableError const&) { // NOLINT(bugprone-empty-catch) // NOSONAR
529529
// missing entries are provided in the update data
530530
}
531531

power_grid_model_c/power_grid_model/include/power_grid_model/math_solver/iterative_linear_se_solver.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ template <symmetry_tag sym_type> class IterativeLinearSESolver {
215215
auto const& power = std::invoke(branch_power_[measured_side], measured_value, obj);
216216
block.g() +=
217217
dot(hermitian_transpose(param.branch_param[obj].value[measured_side * 2 + b0]),
218-
diagonal_inverse(power.p_variance + power.q_variance),
218+
diagonal_inverse(static_cast<IndependentComplexRandVar<sym>>(power).variance),
219219
param.branch_param[obj].value[measured_side * 2 + b1]);
220220
}
221221
}
@@ -310,7 +310,8 @@ template <symmetry_tag sym_type> class IterativeLinearSESolver {
310310
// eta += Y{side, b}^H * (variance^-1) * i_branch_{f, t}
311311
rhs_block.eta() +=
312312
dot(hermitian_transpose(param.branch_param[obj].value[measured_side * 2 + b]),
313-
diagonal_inverse(m.p_variance + m.q_variance), conj(m.value / u[measured_bus]));
313+
diagonal_inverse(static_cast<IndependentComplexRandVar<sym>>(m).variance),
314+
conj(m.value() / u[measured_bus]));
314315
}
315316
}
316317
}

power_grid_model_c/power_grid_model/include/power_grid_model/math_solver/measured_values.hpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -473,14 +473,17 @@ template <symmetry_tag sym> class MeasuredValues {
473473
}
474474

475475
if (is_normal(accumulated_inverse_p_variance) && is_normal(accumulated_inverse_q_variance)) {
476-
return PowerSensorCalcParam<sym>{accumulated_p_value / accumulated_inverse_p_variance +
477-
1.0i * accumulated_q_value / accumulated_inverse_q_variance,
478-
RealValue<sym>{1.0} / accumulated_inverse_p_variance,
479-
RealValue<sym>{1.0} / accumulated_inverse_q_variance};
476+
return PowerSensorCalcParam<sym>{
477+
.real_component = {.value = accumulated_p_value / accumulated_inverse_p_variance,
478+
.variance = RealValue<sym>{1.0} / accumulated_inverse_p_variance},
479+
.imag_component = {.value = accumulated_q_value / accumulated_inverse_q_variance,
480+
.variance = RealValue<sym>{1.0} / accumulated_inverse_q_variance}};
480481
}
481-
return PowerSensorCalcParam<sym>{accumulated_p_value + 1.0i * accumulated_q_value,
482-
RealValue<sym>{std::numeric_limits<double>::infinity()},
483-
RealValue<sym>{std::numeric_limits<double>::infinity()}};
482+
return PowerSensorCalcParam<sym>{
483+
.real_component = {.value = accumulated_p_value,
484+
.variance = RealValue<sym>{std::numeric_limits<double>::infinity()}},
485+
.imag_component = {.value = accumulated_q_value,
486+
.variance = RealValue<sym>{std::numeric_limits<double>::infinity()}}};
484487
}
485488

486489
template <sensor_calc_param_type CalcParam, bool only_magnitude = false>
@@ -588,9 +591,9 @@ template <symmetry_tag sym> class MeasuredValues {
588591
FlowVector& source_flow) const {
589592
// residual normalized by variance
590593
// mu = (sum[S_i] - S_cal) / sum[variance]
591-
auto const delta = bus_appliance_injection.value - s;
592-
ComplexValue<sym> const mu =
593-
real(delta) / bus_appliance_injection.p_variance + 1.0i * imag(delta) / bus_appliance_injection.q_variance;
594+
auto const delta = ComplexValue<sym>{bus_appliance_injection.value() - s};
595+
ComplexValue<sym> const mu = real(delta) / bus_appliance_injection.real_component.variance +
596+
1.0i * imag(delta) / bus_appliance_injection.imag_component.variance;
594597

595598
// S_i = S_i_mea - var_i * mu
596599
auto const calculate_injection = [&mu](auto const& power) {

power_grid_model_c/power_grid_model/include/power_grid_model/math_solver/newton_raphson_se_solver.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ template <symmetry_tag sym_type> class NewtonRaphsonSESolver {
436436
/// @param order Order enum to determine if (chi, psi) = (row, col) or (col, row)
437437
/// @param measured_power
438438
void process_branch_measurement(NRSEGainBlock<sym>& block, NRSEGainBlock<sym>& diag_block, NRSERhs<sym>& rhs_block,
439-
const auto& y_xi_xi, const auto& y_xi_mu, const auto& u_state, Order const order,
440-
const auto& measured_power) {
439+
auto const& y_xi_xi, auto const& y_xi_mu, auto const& u_state, Order const order,
440+
auto const& measured_power) {
441441
auto const hm_u_chi_u_chi_y_xi_xi = hm_complex_form(y_xi_xi, u_state.u_chi_u_chi_conj(order));
442442
auto const nl_u_chi_u_chi_y_xi_xi = dot(hm_u_chi_u_chi_y_xi_xi, u_state.abs_u_chi_inv(order));
443443

@@ -461,8 +461,8 @@ template <symmetry_tag sym_type> class NewtonRaphsonSESolver {
461461
}
462462

463463
void multiply_add_branch_blocks(NRSEGainBlock<sym>& block, NRSEGainBlock<sym>& diag_block, NRSERhs<sym>& rhs_block,
464-
auto& left_block, const auto& right_block, const auto& measured_power,
465-
const auto& f_x_complex) {
464+
auto& left_block, auto const& right_block, auto const& measured_power,
465+
auto const& f_x_complex) {
466466
auto const& block_F_T_k_w = transpose_multiply_weight(left_block, measured_power);
467467

468468
multiply_add_jacobian_blocks_lhs(diag_block, block_F_T_k_w, left_block);

power_grid_model_c/power_grid_model/include/power_grid_model/math_solver/observability.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace power_grid_model::math_solver {
1414
namespace detail {
1515

1616
template <symmetry_tag sym>
17-
std::tuple<Idx, Idx> count_voltage_sensors(const Idx n_bus, const MeasuredValues<sym>& measured_values) {
17+
std::tuple<Idx, Idx> count_voltage_sensors(Idx const n_bus, MeasuredValues<sym> const& measured_values) {
1818
Idx n_voltage_sensor{};
1919
Idx n_voltage_phasor_sensor{};
2020
for (Idx bus = 0; bus != n_bus; ++bus) {

power_grid_model_c/power_grid_model/include/power_grid_model/optimizer/tap_position_optimizer.hpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ using RankedTransformerGroups = std::vector<std::vector<Idx2D>>;
4242

4343
constexpr auto infty = std::numeric_limits<Idx>::max();
4444
constexpr Idx2D unregulated_idx = {.group = -1, .pos = -1};
45-
4645
struct TrafoGraphVertex {
4746
bool is_source{};
4847
};
@@ -55,11 +54,11 @@ struct TrafoGraphEdge {
5554
constexpr TrafoGraphEdge(Idx2D regulated_idx_, EdgeWeight weight_)
5655
: regulated_idx{regulated_idx_}, weight{weight_} {}
5756

58-
bool operator==(const TrafoGraphEdge& other) const {
57+
bool operator==(TrafoGraphEdge const& other) const {
5958
return regulated_idx == other.regulated_idx && weight == other.weight;
6059
} // thanks boost
6160

62-
auto constexpr operator<=>(const TrafoGraphEdge& other) const {
61+
auto constexpr operator<=>(TrafoGraphEdge const& other) const {
6362
if (auto cmp = weight <=> other.weight; cmp != 0) { // NOLINT(modernize-use-nullptr)
6463
return cmp;
6564
}
@@ -334,7 +333,7 @@ inline auto get_edge_weights(TransformerGraph const& graph) -> TrafoGraphEdgePro
334333
"away from the source than the tap side.\n");
335334
}
336335
if (!is_unreachable(edge_res)) {
337-
result.push_back({.regulated_idx = graph[e].regulated_idx, .weight = edge_res});
336+
result.emplace_back(graph[e].regulated_idx, edge_tgt_rank);
338337
}
339338
}
340339

@@ -345,7 +344,7 @@ inline auto rank_transformers(TrafoGraphEdgeProperties const& w_trafo_list) -> R
345344
auto sorted_trafos = w_trafo_list;
346345

347346
std::ranges::sort(sorted_trafos,
348-
[](const TrafoGraphEdge& a, const TrafoGraphEdge& b) { return a.weight < b.weight; });
347+
[](TrafoGraphEdge const& a, TrafoGraphEdge const& b) { return a.weight < b.weight; });
349348

350349
RankedTransformerGroups groups;
351350
auto previous_weight = std::numeric_limits<EdgeWeight>::lowest();

power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/dataset.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class DatasetInfo {
2929
DatasetInfo(RawDatasetInfo const* info) noexcept : info_{info} {}
3030
DatasetInfo(DatasetInfo&&) = default;
3131
DatasetInfo& operator=(DatasetInfo&&) = default;
32-
DatasetInfo(const DatasetInfo&) = delete; // No copy constructor
33-
DatasetInfo& operator=(const DatasetInfo&) = delete; // No copy assignment
32+
DatasetInfo(DatasetInfo const&) = delete; // No copy constructor
33+
DatasetInfo& operator=(DatasetInfo const&) = delete; // No copy assignment
3434
~DatasetInfo() = default;
3535

3636
std::string name() const { return std::string{handle_.call_with(PGM_dataset_info_name, info_)}; }
@@ -88,8 +88,8 @@ class DatasetWritable {
8888
: dataset_{dataset}, info_{handle_.call_with(PGM_dataset_writable_get_info, dataset_)} {}
8989
DatasetWritable(DatasetWritable&&) = default;
9090
DatasetWritable& operator=(DatasetWritable&&) = default;
91-
DatasetWritable(const DatasetWritable&) = delete; // No copy constructor
92-
DatasetWritable& operator=(const DatasetWritable&) = delete; // No copy assignment
91+
DatasetWritable(DatasetWritable const&) = delete; // No copy constructor
92+
DatasetWritable& operator=(DatasetWritable const&) = delete; // No copy assignment
9393
~DatasetWritable() = default;
9494

9595
RawWritableDataset const* get() const { return dataset_; }

tests/cpp_unit_tests/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# SPDX-License-Identifier: MPL-2.0
44

55
set(PROJECT_SOURCES
6-
"test_all_components.cpp"
76
"test_entry_point.cpp"
7+
"test_all_components.cpp"
88
"test_common.cpp"
99
"test_exceptions.cpp"
1010
"test_component_list.cpp"

tests/cpp_unit_tests/test_current_sensor.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ TEST_CASE("Test current sensor") {
7878
CHECK(sym_sensor_output.i_angle_residual == doctest::Approx(0.0));
7979

8080
// Check symmetric sensor output for asymmetric parameters
81-
CHECK(asym_sensor_param.i_real_variance[0] == doctest::Approx(i_variance_pu));
82-
CHECK(asym_sensor_param.i_imag_variance[1] ==
81+
CHECK(asym_sensor_param.measurement.real_component.variance[0] == doctest::Approx(i_variance_pu));
82+
CHECK(asym_sensor_param.measurement.imag_component.variance[1] ==
8383
doctest::Approx(i_variance_pu * sin(deg_240) * sin(deg_240) +
8484
i_angle_variance_pu * i_pu * i_pu * cos(deg_240) * cos(deg_240)));
85-
CHECK(real(asym_sensor_param.value[0]) == doctest::Approx(i_pu));
86-
CHECK(imag(asym_sensor_param.value[1]) == doctest::Approx(i_pu * sin(deg_240)));
85+
CHECK(real(asym_sensor_param.measurement.value()[0]) == doctest::Approx(i_pu));
86+
CHECK(imag(asym_sensor_param.measurement.value()[1]) == doctest::Approx(i_pu * sin(deg_240)));
8787

8888
CHECK(sym_sensor_output_asym_param.id == 0);
8989
CHECK(sym_sensor_output_asym_param.energized == 1);

0 commit comments

Comments
 (0)