Skip to content

Commit 3fc94d2

Browse files
committed
bounded i angle residual
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
1 parent 9add8e1 commit 3fc94d2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,18 @@ template <symmetry_tag current_sensor_symmetry_> class CurrentSensor : public Ge
165165
i_output = conj(i_output) * (cos(u_angle) + 1i * sin(u_angle));
166166
}
167167
output.i_residual = (cabs(i_measured_complex) - cabs(i_output)) * base_current_;
168-
output.i_angle_residual = arg(i_measured_complex) - arg(i_output);
168+
// arg(e^i * u_angle) = u_angle in (-pi, pi]
169+
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 = arg(ComplexValue<sym_calc>{cos(unbounded_i_angle_residual), sin(unbounded_i_angle_residual)});
172+
} else {
173+
output.i_angle_residual = arg(
174+
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+
}
169180
return output;
170181
}
171182
};

0 commit comments

Comments
 (0)