From f30dd34e7abd1d953a1967b17952e75e23ed7361 Mon Sep 17 00:00:00 2001 From: petersalemink95 Date: Wed, 8 Jan 2025 08:49:47 +0100 Subject: [PATCH] single base_current_ Signed-off-by: petersalemink95 --- .../component/current_sensor.hpp | 31 +++++++++---------- tests/cpp_unit_tests/test_current_sensor.cpp | 4 +-- 2 files changed, 16 insertions(+), 19 deletions(-) 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 95fd3ca59..b03bfffb0 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 @@ -74,8 +74,9 @@ template class CurrentSensor : public Ge explicit CurrentSensor(CurrentSensorInput const& current_sensor_input, double u_rated) : GenericCurrentSensor{current_sensor_input}, i_angle_measured_{current_sensor_input.i_angle_measured}, - i_angle_sigma_{current_sensor_input.i_angle_sigma} { - set_current(current_sensor_input, u_rated); + i_angle_sigma_{current_sensor_input.i_angle_sigma}, + base_current_{base_power_3p * inv_sqrt3 / u_rated} { + set_current(current_sensor_input); switch (current_sensor_input.measured_terminal_type) { case MeasuredTerminalType::branch_from: @@ -89,12 +90,11 @@ template class CurrentSensor : public Ge } }; - UpdateChange update(CurrentSensorUpdate const& update_data, double const& u_rated) { - double const base_current = base_power_3p * inv_sqrt3 / u_rated; - double const scalar = 1.0 / base_current; + UpdateChange update(CurrentSensorUpdate const& update_data) { + double const scalar = 1.0 / base_current_; if (!is_nan(update_data.i_sigma)) { - i_sigma_ = update_data.i_sigma / base_current; + i_sigma_ = update_data.i_sigma / base_current_; } if (!is_nan(update_data.i_angle_sigma)) { i_angle_sigma_ = update_data.i_angle_sigma; @@ -104,15 +104,13 @@ template class CurrentSensor : public Ge return {false, false}; } - CurrentSensorUpdate inverse(CurrentSensorUpdate update_data, - double const& u_rated) const { + CurrentSensorUpdate + inverse(CurrentSensorUpdate update_data) const { assert(update_data.id == this->id() || is_nan(update_data.id)); - double const base_current = base_power_3p * inv_sqrt3 / u_rated; - - set_if_not_nan(update_data.i_sigma, i_sigma_ * base_current); + set_if_not_nan(update_data.i_sigma, i_sigma_ * base_current_); set_if_not_nan(update_data.i_angle_sigma, i_angle_sigma_); - set_if_not_nan(update_data.i_measured, i_measured_ * base_current); + set_if_not_nan(update_data.i_measured, i_measured_ * base_current_); set_if_not_nan(update_data.i_angle_measured, i_angle_measured_); return update_data; @@ -123,12 +121,11 @@ template class CurrentSensor : public Ge RealValue i_angle_measured_{}; double i_sigma_{}; double i_angle_sigma_{}; + double base_current_{}; - void set_current(CurrentSensorInput const& input, double const& u_rated) { - double const base_current = base_power_3p * inv_sqrt3 / u_rated; - double const scalar = 1.0 / base_current; - i_sigma_ = input.i_sigma / base_current; - i_measured_ = input.i_measured * scalar; + void set_current(CurrentSensorInput const& input) { + i_sigma_ = input.i_sigma / base_current_; + i_measured_ = input.i_measured / base_current_; } // TODO when filling the functions below take in mind that i_angle_sigma is optional diff --git a/tests/cpp_unit_tests/test_current_sensor.cpp b/tests/cpp_unit_tests/test_current_sensor.cpp index 2403331d1..8b4ebd639 100644 --- a/tests/cpp_unit_tests/test_current_sensor.cpp +++ b/tests/cpp_unit_tests/test_current_sensor.cpp @@ -148,7 +148,7 @@ TEST_CASE("Test current sensor") { expected.i_angle_measured = i_angle_measured; } - auto const inv = current_sensor.inverse(cs_update, u_rated); + auto const inv = current_sensor.inverse(cs_update); CHECK(inv.id == expected.id); check_nan_preserving_equality(inv.i_sigma, expected.i_sigma); @@ -223,7 +223,7 @@ TEST_CASE("Test current sensor") { i_sigma, i_angle_sigma, i_measured, i_angle_measured}, u_rated}; - auto const inv = current_sensor.inverse(cs_update, u_rated); + auto const inv = current_sensor.inverse(cs_update); CHECK(inv.id == expected.id); check_nan_preserving_equality(inv.i_sigma, expected.i_sigma);