Skip to content

Commit

Permalink
fix calculation for ration ne 1.0
Browse files Browse the repository at this point in the history
PPSE/17
  • Loading branch information
sudo-ac committed Sep 23, 2024
1 parent 8c152d5 commit ff1e1e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,20 @@ class GenericBranch final : public Branch {
BranchCalcParam<asymmetric_t> asym_calc_param() const override {
// the following code section adapts the calculation from the transformer.cpp for a YNyn equivalent

// calculate the zero sequence parameters (YNyn equivalent)
DoubleComplex const z0_series = 1.0 / y1_series_ + 3.0 * (z_grounding_to_ + z_grounding_from_ / ratio_ / ratio_);
DoubleComplex const y0_series = 1.0 / z0_series;

// calculate the zero sequence parameters
BranchCalcParam<symmetric_t> param0 = calc_param_y_sym(y0_series, y1_shunt_, ratio_ * std::exp(1.0i * shift_));

// positive sequence (param1)
auto const param1 = calc_param_y_sym(y1_series_, y1_shunt_, ratio_ * std::exp(1.0i * shift_));

// negative sequence (param2)
auto const param2 = calc_param_y_sym(y1_series_, y1_shunt_, ratio_ * std::exp(1.0i * (-shift_)));
// calculate the zero sequence parameters
// zero sequence, default zero
BranchCalcParam<symmetric_t> param0{};


// calculate the zero sequence parameters (YNyn equivalent)
DoubleComplex const z0_series = 1.0 / y1_series_ + 3.0 * (z_grounding_to_ + z_grounding_from_ / ratio_ / ratio_);
DoubleComplex const y0_series = 1.0 / z0_series;
param0 = calc_param_y_sym(y0_series, y1_shunt_, ratio_ * std::exp(1.0i * shift_));

// calculate the symmetrical matrices
ComplexTensor<asymmetric_t> const sym_matrix = get_sym_matrix();
Expand Down
20 changes: 11 additions & 9 deletions tests/cpp_unit_tests/test_genericbranch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <power_grid_model/component/genericbranch.hpp>

#include <doctest/doctest.h>
#include <iostream>

namespace power_grid_model {

Expand Down Expand Up @@ -100,15 +101,17 @@ TEST_CASE("Test YNyn12") {
.x_grounding_from = 2.0,
.r_grounding_to = 1.0,
.x_grounding_to = 4.0,
.ratio = 1.0,
.ratio = 1.05,
.shift = 0.0,
.sn = 30e6};

double const u1_rated{u1};
double const u2_rated{u2};

GenericBranch YNyn12{input, u1_rated, u2_rated};
double const k = input.ratio;
double const k = input.ratio; // magnitude of komplex transformer ratio
DoubleComplex const tap_ratio = k * std::exp(1.0i * (input.shift)); // komplex transformer ratio

double const base_y_from = base_i_from / (u1_rated / sqrt3);
double const base_y_to = base_i_to / (u2_rated / sqrt3);
DoubleComplex const z_grounding_from = (input.r_grounding_from + 1i * input.x_grounding_from) * base_y_from;
Expand All @@ -118,6 +121,7 @@ TEST_CASE("Test YNyn12") {
DoubleComplex const z_1_series = (z_real + 1i * z_imag) * base_y_to;
DoubleComplex const z_2_series = z_1_series;
DoubleComplex const z_0_series = z_1_series + 3.0 * (z_grounding_to + z_grounding_from / k / k);

ComplexTensor<asymmetric_t> z_diagonal;
z_diagonal << z_0_series, 0.0, 0.0, 0.0, z_1_series, 0.0, 0.0, 0.0, z_2_series;

Expand All @@ -129,11 +133,11 @@ TEST_CASE("Test YNyn12") {
y_shunt_diagonal << y_1_shunt, 0.0, 0.0, 0.0, y_1_shunt, 0.0, 0.0, 0.0, y_1_shunt;
ComplexTensor<asymmetric_t> const y_shunt = dot(A, y_shunt_diagonal, A_inv);

ComplexTensor<asymmetric_t> const y_ff = inv(z_series) + 0.5 * y_shunt;
ComplexTensor<asymmetric_t> const y_ft = -inv(z_series);
ComplexTensor<asymmetric_t> const y_tf = -inv(z_series);
ComplexTensor<asymmetric_t> const y_tt = inv(z_series) + 0.5 * y_shunt;

ComplexTensor<asymmetric_t> const y_tt = inv(z_series) + 0.5 * y_shunt;
ComplexTensor<asymmetric_t> const y_ff = (1.0 / k / k) * y_tt;
ComplexTensor<asymmetric_t> const y_ft = (-1.0 / conj(tap_ratio))*inv(z_series);
ComplexTensor<asymmetric_t> const y_tf = (-1.0 / tap_ratio)*inv(z_series);
BranchCalcParam<asymmetric_t> const param = YNyn12.calc_param<asymmetric_t>();

CHECK((cabs(param.value[0] - y_ff) < numerical_tolerance).all());
Expand All @@ -142,8 +146,6 @@ TEST_CASE("Test YNyn12") {
CHECK((cabs(param.value[3] - y_tt) < numerical_tolerance).all());
SUBCASE("Test genericbranch phase shift") { CHECK(YNyn12.phase_shift() == doctest::Approx(0.0)); }
SUBCASE("Test genericbranch loading") { CHECK(YNyn12.loading(60.0e6, 0.0) == doctest::Approx(2.0)); }


}


Expand Down

0 comments on commit ff1e1e0

Please sign in to comment.