diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/component/current_sensor.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/component/current_sensor.hpp index 5dd682879..8b6598b9f 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/component/current_sensor.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/component/current_sensor.hpp @@ -39,7 +39,7 @@ class GenericCurrentSensor : public Sensor { SensorShortCircuitOutput get_null_sc_output() const { return {.id = id(), .energized = 0}; } // getter for calculation param - template PowerSensorCalcParam calc_param() const { + template CurrentSensorCalcParam calc_param() const { if constexpr (is_symmetric_v) { return sym_calc_param(); } else { diff --git a/tests/cpp_unit_tests/test_current_sensor.cpp b/tests/cpp_unit_tests/test_current_sensor.cpp index ee8eb94d5..6c3fcac5c 100644 --- a/tests/cpp_unit_tests/test_current_sensor.cpp +++ b/tests/cpp_unit_tests/test_current_sensor.cpp @@ -7,6 +7,64 @@ #include namespace power_grid_model { -TEST_CASE("Test current sensor") {} +TEST_CASE("Test current sensor") { + SUBCASE("Symmetric Current Sensor - generator, branch_from, branch_to, source") { + for (auto const terminal_type : {MeasuredTerminalType::generator, MeasuredTerminalType::branch_from, + MeasuredTerminalType::branch_to, MeasuredTerminalType::source}) { + CAPTURE(terminal_type); + + CurrentSensorInput sym_current_sensor_input{}; + sym_current_sensor_input.id = 0; + sym_current_sensor_input.measured_object = 1; + sym_current_sensor_input.measured_terminal_type = terminal_type; + sym_current_sensor_input.angle_measurement_type = AngleMeasurementType::local; + sym_current_sensor_input.i_sigma = 1.0; + sym_current_sensor_input.i_measured = 1.0 * 1e3; + sym_current_sensor_input.i_angle_measured = 0.0; + sym_current_sensor_input.i_angle_sigma = nan; + + double const u_rated = 10.0e3; + double const base_current = base_power_3p / u_rated / sqrt3; + + ComplexValue const i_sym = (1.0 * 1e3 + 1i * 0.0) / base_current; + ComplexValue const i_asym = i_sym * RealValue{1.0}; + + CurrentSensor sym_current_sensor{sym_current_sensor_input, u_rated}; + + CurrentSensorCalcParam sym_sensor_param = sym_current_sensor.calc_param(); + CurrentSensorCalcParam asym_sensor_param = sym_current_sensor.calc_param(); + + CurrentSensorOutput sym_sensor_output = sym_current_sensor.get_output(i_sym); + CurrentSensorOutput sym_sensor_output_asym_param = + sym_current_sensor.get_output(i_asym); + + // Check symmetric sensor output for symmetric parameters + CHECK(sym_sensor_param.i_variance == doctest::Approx(0.0)); + CHECK(sym_sensor_param.i_angle_variance == doctest::Approx(0.0)); + CHECK(real(sym_sensor_param.value) == doctest::Approx(0.0)); + CHECK(imag(sym_sensor_param.value) == doctest::Approx(0.0)); + + CHECK(sym_sensor_output.id == 0); + CHECK(sym_sensor_output.energized == 0); + CHECK(sym_sensor_output.i_residual == doctest::Approx(0.0)); + CHECK(sym_sensor_output.i_angle_residual == doctest::Approx(0.0)); + + // Check symmetric sensor output for asymmetric parameters + CHECK(asym_sensor_param.i_variance[0] == doctest::Approx(0.0)); + CHECK(asym_sensor_param.i_angle_variance[1] == doctest::Approx(0.0)); + CHECK(real(asym_sensor_param.value[0]) == doctest::Approx(0.0)); + CHECK(imag(asym_sensor_param.value[1]) == doctest::Approx(0.0)); + + CHECK(sym_sensor_output_asym_param.id == 0); + CHECK(sym_sensor_output_asym_param.energized == 0); + CHECK(sym_sensor_output_asym_param.i_residual[0] == doctest::Approx(0.0)); + CHECK(sym_sensor_output_asym_param.i_angle_residual[1] == doctest::Approx(0.0)); + + CHECK(sym_current_sensor.get_terminal_type() == terminal_type); + + CHECK(sym_current_sensor.get_angle_measurement_type() == AngleMeasurementType::local); + } + } +} } // namespace power_grid_model