Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
auto const [y_series, y_shunt, k] = transformer_params();
return calc_param_y_sym(y_series, y_shunt, k * std::exp(1.0i * (clock_ * deg_30)));
}
BranchCalcParam<asymmetric_t> asym_calc_param() const final {

Check failure on line 216 in power_grid_model_c/power_grid_model/include/power_grid_model/component/transformer.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 29 to the 25 allowed.

See more on https://sonarcloud.io/project/issues?id=PowerGridModel_power-grid-model&issues=AZqm09HrMkJTTJ2mAAjT&open=AZqm09HrMkJTTJ2mAAjT&pullRequest=1197
auto const [y_series, y_shunt, k] = transformer_params();
// positive sequence
auto const param1 = calc_param_y_sym(y_series, y_shunt, k * std::exp(1.0i * (clock_ * deg_30)));
Expand All @@ -232,17 +232,35 @@
DoubleComplex const y0_series = 1.0 / z0_series;
param0 = calc_param_y_sym(y0_series, y_shunt, k * std::exp(1.0i * phase_shift_0));
}
// YNd
if (winding_from_ == WindingType::wye_n && winding_to_ == WindingType::delta && from_status()) {
DoubleComplex const z0_series = 1.0 / y_series + 3.0 * z_grounding_from_ / k / k;
DoubleComplex const y0_series = 1.0 / z0_series;
param0.yff() = (y0_series + y_shunt) / k / k;
// YN*

Check warning on line 235 in power_grid_model_c/power_grid_model/include/power_grid_model/component/transformer.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the commented out code.

See more on https://sonarcloud.io/project/issues?id=PowerGridModel_power-grid-model&issues=AZqmbydBdIPvaMuHcmjp&open=AZqmbydBdIPvaMuHcmjp&pullRequest=1197
else if (winding_from_ == WindingType::wye_n && from_status()) {
// ground path always possible via magnetization branch
DoubleComplex y0 = y_shunt;
if (winding_to_ == WindingType::delta) {
// additional path via zk
y0 += y_series;
}
if (y0 != DoubleComplex{0.0, 0.0}) {
// avoid division by zero
DoubleComplex const z0 = 1.0 / y0 + 3.0 * z_grounding_from_ / k / k;
y0 = 1.0 / z0;
param0.yff() = y0 / k / k;
}
}
// Dyn
if (winding_from_ == WindingType::delta && winding_to_ == WindingType::wye_n && to_status()) {
DoubleComplex const z0_series = 1.0 / y_series + 3.0 * z_grounding_to_;
DoubleComplex const y0_series = 1.0 / z0_series;
param0.ytt() = (y0_series + y_shunt);
// *yn
else if (winding_to_ == WindingType::wye_n && to_status()) {
// ground path always possible via magnetization branch
DoubleComplex y0 = y_shunt;
if (winding_from_ == WindingType::delta) {
// additional path via zk
y0 += y_series;
}
if (y0 != DoubleComplex{0.0, 0.0}) {
// avoid division by zero
DoubleComplex const z0 = 1.0 / y0 + 3.0 * z_grounding_to_;
y0 = 1.0 / z0;
param0.ytt() = y0;
}
}
// ZN*
// Zero sequence impedance of zigzag winding is approximately 10% of positive sequence impedance
Expand Down
4 changes: 2 additions & 2 deletions tests/cpp_unit_tests/test_transformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ TEST_CASE("Test Transfomer - Test grounding - Dyn11") {
DoubleComplex const y_0_ff = low_admittance;
DoubleComplex const y_0_ft = 0.0;
DoubleComplex const y_0_tf = 0.0;
DoubleComplex const y_0_tt = (1.0 / (z_1_series + 3.0 * z_grounding_to)) + y_1_shunt;
DoubleComplex const y_0_tt = (1.0 / (1.0 / (1.0 / z_1_series + y_1_shunt) + 3.0 * z_grounding_to));

// Sequence admittances -> phase addmitance
ComplexTensor<asymmetric_t> y_ff_diagonal;
Expand Down Expand Up @@ -707,7 +707,7 @@ TEST_CASE("Test Transformer - Dyn11 - tap_max and tap_min flipped") {
DoubleComplex const y_0_ff = low_admittance;
DoubleComplex const y_0_ft = 0.0;
DoubleComplex const y_0_tf = 0.0;
DoubleComplex const y_0_tt = (1.0 / (z_1_series + 3.0 * z_grounding_to)) + y_1_shunt;
DoubleComplex const y_0_tt = (1.0 / (1.0 / (1.0 / z_1_series + y_1_shunt) + 3.0 * z_grounding_to));

// Sequence admittances -> phase addmitance
ComplexTensor<asymmetric_t> y_ff_diagonal;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "1.0",
"type": "asym_output",
"is_batch": false,
"attributes": {},
"data": {
"node": [
{"id": 1, "energized": 1, "u_pu": [1, 1, 1], "u": [5773.5026918962576, 5773.5026918962576, 5773.5026918962576], "u_angle": [-2.474640575439679e-44, -2.0943951023931953, 2.0943951023931953], "p": [824880.19181322691, 1072224.8788595221, 1102894.9293272516], "q": [218912.27669635782, 40693.031260342112, 344009.43645155017]},
{"id": 2, "energized": 1, "u_pu": [1.1450055302608289, 0.94457144911056157, 0.91924181371456271], "u": [6610.6925111969977, 5453.4858041281759, 5307.2450859846258], "u_angle": [-0.03356887190092963, -1.984902584683417, 1.9252028204298137], "p": [-949999.9999999979, -1000000.0000000031, -1049999.9999999963], "q": [1.6449686064130695e-08, -3.0224494451098491e-09, 3.984667595393038e-09]}
],
"transformer": [
{"id": 4, "energized": 1, "loading": 0.30817316848870924, "p_from": [824880.19181322691, 1072224.8788595221, 1102894.9293272516], "q_from": [218912.27669635782, 40693.031260342126, 344009.43645155017], "i_from": [147.81913770559706, 185.84849584851148, 200.10395179782012], "s_from": [853434.18945704808, 1072996.791066251, 1155300.7043637931], "p_to": [-949999.9999999979, -1000000.0000000031, -1049999.9999999963], "q_to": [1.644994521118116e-08, -2.9986559036607486e-09, 3.9875615770433002e-09], "i_to": [143.70657815212488, 183.36895628169123, 197.84275702149816], "s_to": [949999.9999999979, 1000000.0000000031, 1049999.9999999963]}
],
"asym_load": [
{"id": 6, "energized": 1, "p": [950000, 1000000, 1050000], "q": [0, 0, 0], "i": [143.70657815212516, 183.36895628169069, 197.84275702149884], "s": [950000, 1000000, 1050000], "pf": [1, 1, 1]}
],
"source": [
{"id": 7, "energized": 1, "p": [824880.19181322691, 1072224.8788595221, 1102894.9293272516], "q": [218912.27669635782, 40693.031260342126, 344009.43645155017], "i": [147.81913770559706, 185.84849584851148, 200.10395179782012], "s": [853434.18945704808, 1072996.791066251, 1155300.7043637931], "pf": [0.96654223840975118, 0.99928060157014831, 0.9546388443817313]}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>

SPDX-License-Identifier: MPL-2.0
21 changes: 21 additions & 0 deletions tests/data/power_flow/zero_sequence_yyn_transformer/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "1.0",
"type": "input",
"is_batch": false,
"attributes": {},
"data": {
"node": [
{"id": 1, "u_rated": 10000},
{"id": 2, "u_rated": 10000}
],
"transformer": [
{"id": 4, "from_node": 1, "to_node": 2, "from_status": 1, "to_status": 1, "u1": 10000, "u2": 10000, "sn": 10000000, "uk": 0.10000000000000001, "pk": 0, "i0": 0.050000000000000003, "p0": 0, "winding_from": 0, "winding_to": 1, "clock": 12, "tap_side": 0, "tap_pos": 0, "tap_min": 0, "tap_max": 0, "tap_nom": 0, "tap_size": 0}
],
"asym_load": [
{"id": 6, "node": 2, "status": 1, "type": 0, "p_specified": [950000, 1000000, 1050000], "q_specified": [0, 0, 0]}
],
"source": [
{"id": 7, "node": 1, "status": 1, "u_ref": 1, "sk": 1.0000000000000001e+50, "rx_ratio": 0, "z01_ratio": 1}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>

SPDX-License-Identifier: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"calculation_method": [
"newton_raphson"
],
"rtol": 1e-07,
"atol": 1e-07
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>

SPDX-License-Identifier: MPL-2.0
Loading