From ff77f1d63fb4dd8b9e1f3a0b8955da4741a2a11a Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Date: Fri, 12 Jul 2024 15:21:08 +0200 Subject: [PATCH] Formatting and naming Signed-off-by: Santiago Figueroa --- .../math_solver/common_solver_functions.hpp | 40 +++++++++---------- .../cpp_validation_tests/test_validation.cpp | 3 -- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/math_solver/common_solver_functions.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/math_solver/common_solver_functions.hpp index c34e28d3a..78206acbf 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/math_solver/common_solver_functions.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/math_solver/common_solver_functions.hpp @@ -62,52 +62,52 @@ template inline void calculate_source_result(IdxRange const& sources, Idx bus_number, YBus const& y_bus, PowerFlowInput const& input, SolverOutput& output, ComplexValue const& i_load_gen_bus) { - ComplexValue const i_source_total = - conj(output.bus_injection[bus_number] / output.u[bus_number]) - i_load_gen_bus; + ComplexValue const i_inj_t = conj(output.bus_injection[bus_number] / output.u[bus_number]) - i_load_gen_bus; std::vector sources_acc(sources.size()); std::ranges::transform(sources, sources_acc.begin(), [&](Idx const source) { return source; }); if (sources_acc.size() == 0) { ; // Do nothing } else if (sources_acc.size() == 1) { - output.source[sources_acc[0]].i = i_source_total; + output.source[sources_acc[0]].i = i_inj_t; output.source[sources_acc[0]].s = output.u[bus_number] * conj(output.source[sources_acc[0]].i); } else { std::vector> y_ref_acc(sources.size()); - std::vector> i_norton_acc(sources.size()); + std::vector> i_ref_acc(sources.size()); std::ranges::transform(sources, y_ref_acc.begin(), [&](Idx const source) -> ComplexTensor { ComplexTensor y_ref = y_bus.math_model_param().source_param[source]; return y_ref; }); - std::ranges::transform(sources, i_norton_acc.begin(), [&](Idx const source) -> ComplexValue { + std::ranges::transform(sources, i_ref_acc.begin(), [&](Idx const source) -> ComplexValue { ComplexValue const u_ref{input.source[source]}; ComplexTensor const y_ref = y_bus.math_model_param().source_param[source]; return dot(y_ref, u_ref); }); - ComplexTensor const y_ref_total = - std::accumulate(y_ref_acc.begin(), y_ref_acc.end(), ComplexTensor{}); - ComplexTensor z_ref_total{}; + ComplexTensor const y_ref_t = std::accumulate(y_ref_acc.begin(), y_ref_acc.end(), ComplexTensor{}); + ComplexTensor z_ref_t{}; if constexpr (is_symmetric_v) { - z_ref_total = 1.0 / y_ref_total; + z_ref_t = 1.0 / y_ref_t; } else { - DoubleComplex const s = y_ref_total(0); - DoubleComplex const m = y_ref_total(1); + DoubleComplex const s = y_ref_t(0); // Diagonal elements + DoubleComplex const m = y_ref_t(1); // Off diagonal elements + // z_ref_t is obtained from: y_ref_t -> y_012 -> z_012 -> z_ref_t + // s_z, m_z are diagonal and off-diagonal elements of z_ref_t DoubleComplex const s_z = (2.0 / (3.0 * (s - m))) + (1.0 / (3.0 * (s + (2.0 * m)))); DoubleComplex const m_z = (1.0 / (3.0 * (s + (2.0 * m)))) - (1.0 / (3.0 * (s - m))); - z_ref_total = ComplexTensor{s_z, m_z}; + z_ref_t = ComplexTensor{s_z, m_z}; } - ComplexValue const i_norton_total = - std::accumulate(i_norton_acc.begin(), i_norton_acc.end(), ComplexValue{}); + ComplexValue const i_ref_t = std::accumulate(i_ref_acc.begin(), i_ref_acc.end(), ComplexValue{}); for (size_t i = 0; i < sources.size(); ++i) { Idx const source = sources_acc[i]; - ComplexValue const aux1 = dot(z_ref_total, i_norton_total); + ComplexValue const u_ref_t = dot(z_ref_t, i_ref_t); ComplexValue const u_ref_i{input.source[i]}; - ComplexValue aux2 = (u_ref_i - aux1); + ComplexValue delta_u = (u_ref_i - u_ref_t); + // Arbitrary precision threshold (20.0) needs further discussion. constexpr auto precision = 20.0 * std::numeric_limits::epsilon(); - if (max_val(cabs(aux2)) < (precision * ((max_val(cabs(u_ref_i)) + max_val(cabs(aux1))) / 2.0))) { - aux2 = ComplexValue{0.0}; + if (max_val(cabs(delta_u)) < (precision * ((max_val(cabs(u_ref_i)) + max_val(cabs(u_ref_t))) / 2.0))) { + delta_u = ComplexValue{0.0}; } - ComplexValue const aux3 = dot(dot(y_ref_acc[i], z_ref_total), i_source_total); - output.source[source].i = dot(y_ref_acc[i], aux2) + aux3; + ComplexValue const i_inj_rhs = dot(dot(y_ref_acc[i], z_ref_t), i_inj_t); + output.source[source].i = dot(y_ref_acc[i], delta_u) + i_inj_rhs; output.source[source].s = output.u[bus_number] * conj(output.source[source].i); } } diff --git a/tests/cpp_validation_tests/test_validation.cpp b/tests/cpp_validation_tests/test_validation.cpp index b69047cc9..98afca0a0 100644 --- a/tests/cpp_validation_tests/test_validation.cpp +++ b/tests/cpp_validation_tests/test_validation.cpp @@ -629,9 +629,6 @@ TEST_CASE("Validation test single") { TEST_CASE("Validation test batch") { std::vector const& all_cases = get_all_batch_cases(); for (CaseParam const& param : all_cases) { - if (param.case_name != "power_flow/source-big-sk-asym-newton_raphson_batch") { - continue; - } SUBCASE(param.case_name.c_str()) { try { validate_batch_case(param);