Skip to content

Commit ca34d02

Browse files
committed
address some comments
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
1 parent 24d0a70 commit ca34d02

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

power_grid_model_c/power_grid_model/include/power_grid_model/component/current_sensor.hpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,29 +154,29 @@ template <symmetry_tag current_sensor_symmetry_> class CurrentSensor : public Ge
154154
CurrentSensorOutput<sym_calc> output{};
155155
output.id = id();
156156
output.energized = 1; // current sensor is always energized
157-
auto i_output = i;
158157
auto const i_calc_param = calc_param<sym_calc>();
159158
auto const angle_measurement_type = i_calc_param.angle_measurement_type;
160159
auto const i_measured_complex = i_calc_param.measurement.value();
161-
if (angle_measurement_type == AngleMeasurementType::local_angle) {
162-
// I_l = conj(I_g) * exp(i * u_angle)
163-
// Tranform back the output angle to the local angle frame of reference
164-
auto const u_angle = arg(u);
165-
i_output = conj(i_output) * (cos(u_angle) + 1i * sin(u_angle));
166-
}
160+
ComplexValue<sym_calc> i_output = [&i, &u, &angle_measurement_type] {
161+
switch (angle_measurement_type) {
162+
case AngleMeasurementType::global_angle: {
163+
return i;
164+
}
165+
case AngleMeasurementType::local_angle: {
166+
// I_l = conj(I_g) * exp(i * u_angle)
167+
// Tranform back the output angle to the local angle frame of reference
168+
auto const u_angle = arg(u);
169+
return ComplexValue<sym_calc>{conj(i) * (cos(u_angle) + 1i * sin(u_angle))};
170+
}
171+
default: {
172+
throw MissingCaseForEnumError{"generic output angle measurement type", angle_measurement_type};
173+
}
174+
}
175+
}();
167176
output.i_residual = (cabs(i_measured_complex) - cabs(i_output)) * base_current_;
168177
// arg(e^i * u_angle) = u_angle in (-pi, pi]
169178
auto const unbounded_i_angle_residual = arg(i_measured_complex) - arg(i_output);
170-
if constexpr (is_symmetric_v<sym_calc>) {
171-
output.i_angle_residual =
172-
arg(ComplexValue<sym_calc>{cos(unbounded_i_angle_residual), sin(unbounded_i_angle_residual)});
173-
} else {
174-
output.i_angle_residual = arg(ComplexValue<sym_calc>{
175-
cos(unbounded_i_angle_residual(0)) + 1i * sin(unbounded_i_angle_residual(0)),
176-
cos(unbounded_i_angle_residual(1)) + 1i * sin(unbounded_i_angle_residual(1)),
177-
cos(unbounded_i_angle_residual(2)) + 1i * sin(unbounded_i_angle_residual(2)),
178-
});
179-
}
179+
output.i_angle_residual = arg(ComplexValue<sym_calc>{exp(1.0i * unbounded_i_angle_residual)});
180180
return output;
181181
}
182182
};

tests/cpp_unit_tests/test_current_sensor.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,13 @@ TEST_CASE("Test current sensor") {
5656
double const i_angle_sigma_pi = 0.2;
5757
double const i_angle_variance_pu = i_angle_sigma_pi * i_angle_sigma_pi;
5858

59-
auto const i_sym =
60-
ComplexValue<symmetric_t>{(1e3 * cos(i_angle) + 1i * 1e3 * sin(i_angle)) / base_current};
61-
auto const i_asym = ComplexValue<asymmetric_t>{
62-
(1e3 * cos(i_angle) + 1i * 1e3 * sin(i_angle)) / base_current,
63-
(1e3 * cos(i_angle + deg_240) + 1i * 1e3 * sin(i_angle + deg_240)) / base_current,
64-
(1e3 * cos(i_angle + deg_120) + 1i * 1e3 * sin(i_angle + deg_120)) / base_current};
65-
auto const i_asym_local =
66-
ComplexValue<asymmetric_t>{(1e3 * cos(i_angle) + 1i * 1e3 * sin(i_angle)) / base_current,
67-
(1e3 * cos(i_angle) + 1i * 1e3 * sin(i_angle)) / base_current,
68-
(1e3 * cos(i_angle) + 1i * 1e3 * sin(i_angle)) / base_current};
59+
auto const i_sym = ComplexValue<symmetric_t>{(1e3 * exp(1.0i * i_angle)) / base_current};
60+
auto const i_asym = ComplexValue<asymmetric_t>{(1e3 * exp(1.0i * i_angle)) / base_current,
61+
(1e3 * exp(1.0i * (i_angle + deg_240))) / base_current,
62+
(1e3 * exp(1.0i * (i_angle + deg_120))) / base_current};
63+
auto const i_asym_local = ComplexValue<asymmetric_t>{(1e3 * exp(1.0i * i_angle)) / base_current,
64+
(1e3 * exp(1.0i * i_angle)) / base_current,
65+
(1e3 * exp(1.0i * i_angle)) / base_current};
6966

7067
CurrentSensor<symmetric_t> const sym_current_sensor{sym_current_sensor_input, u_rated};
7168

@@ -111,7 +108,7 @@ TEST_CASE("Test current sensor") {
111108

112109
CHECK(sym_sensor_output_asym_param.id == 0);
113110
CHECK(sym_sensor_output_asym_param.energized == 1);
114-
for (auto phase = 0; phase < 3; ++phase) {
111+
for (auto phase : IdxRange{3}) {
115112
CAPTURE(phase);
116113
CHECK(sym_sensor_output_asym_param.i_residual[phase] == doctest::Approx(0.0));
117114
CHECK(sym_sensor_output_asym_param.i_angle_residual[phase] == doctest::Approx(0.0));

0 commit comments

Comments
 (0)