Skip to content

Commit d63571f

Browse files
authored
Merge pull request #41 from bluejuniper/master
Calculate sequence impedances
2 parents 1b1fda6 + 693b066 commit d63571f

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
.pytest_cache/
2+
.mypy_cache/
23
*/__pycache__/
4+
5+
.coverage
6+
carsons.code-workspace

carsons/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from carsons.carsons import (convert_geometric_model, # noqa 401
22
calculate_impedance, # noqa 401
3+
calculate_sequence_impedance_matrix,
4+
calculate_sequence_impedances,
5+
CarsonsEquations,
36
ConcentricNeutralCarsonsEquations, # noqa 401
47
MultiConductorCarsonsEquations) # noqa 401
58

carsons/carsons.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,25 @@
22
from itertools import islice
33
from typing import Dict, Iterable, Iterator, Tuple
44

5-
from numpy import arctan, cos, log, sin, sqrt, zeros
6-
from numpy import ndarray
5+
from numpy import arctan, cos, log, sin, sqrt, zeros, exp
6+
from numpy import array, ndarray
77
from numpy import pi as π
88
from numpy.linalg import inv
99

10+
alpha = exp(2j*π/3)
11+
12+
A = array([
13+
[1, 1, 1],
14+
[1, alpha**2, alpha],
15+
[1, alpha, alpha**2],
16+
])
17+
18+
Ainv = (1/3)*array([
19+
[1, 1, 1],
20+
[1, alpha, alpha**2],
21+
[1, alpha**2, alpha],
22+
])
23+
1024

1125
def convert_geometric_model(geometric_model) -> ndarray:
1226
carsons_model = CarsonsEquations(geometric_model)
@@ -65,6 +79,15 @@ def perform_kron_reduction(z_primitive: ndarray, dimension=3) -> ndarray:
6579
return Z_abc
6680

6781

82+
def calculate_sequence_impedance_matrix(Z):
83+
return Ainv @ Z @ A
84+
85+
86+
def calculate_sequence_impedances(Z):
87+
Z012 = calculate_sequence_impedance_matrix(Z)
88+
return Z012[1, 1], Z012[0, 0]
89+
90+
6891
class CarsonsEquations():
6992

7093
ρ = 100 # resistivity, ohms/meter^3

tests/test_carsons.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from carsons.carsons import (
55
CarsonsEquations,
66
perform_kron_reduction,
7+
calculate_sequence_impedance_matrix,
8+
calculate_sequence_impedances,
79
)
810
from tests.test_overhead_line import (
911
ACBN_geometry_line,
@@ -136,6 +138,32 @@ def expected_z_abc_three_neutrals():
136138
[-14 + 0j, -14 + 0j, -13 + 0j]])
137139

138140

141+
def z_abc_kersting_4_1():
142+
"""Kron-reduced impedance matrix from Kersting 3rd Ed., ex. 4.1"""
143+
return array([
144+
[0.4576+1.078j, 0.1560+0.5017j, 0.1535+0.3849j],
145+
[0.1560+0.5017j, 0.4666+1.*1.0482j, 0.1580+0.4236j],
146+
[0.1535+0.3849j, 0.1580+0.4236j, 0.4615+1.0651j]])
147+
148+
149+
def z_012_kersting_4_1():
150+
"""Sequence impedance matrix from Kersting 3rd Ed., ex. 4.1"""
151+
return array([
152+
[0.7735+1.9373j, 0.0256+0.0115j, -0.0321+0.0159j],
153+
[-0.0321+0.0159j, 0.3061+0.6270j, -0.0723-0.0060j],
154+
[0.0256+0.0115j, 0.0723-0.0059j, 0.3061+0.6270j]])
155+
156+
157+
def z_1_kersting_4_1():
158+
"""Positive-sequence impedance from Kersting 3rd Ed., ex. 4.1"""
159+
return 0.3061 + 0.6270j
160+
161+
162+
def z_0_kersting_4_1():
163+
"""Zero-sequence impedance from Kersting 3rd Ed., ex. 4.1"""
164+
return 0.7735 + 1.9373j
165+
166+
139167
@pytest.mark.parametrize(
140168
"line,z_primitive_expected",
141169
[(ACBN_geometry_line(), ACBN_line_z_primitive()),
@@ -169,3 +197,22 @@ def test_balanced_carsons_equations(line, z_primitive_expected):
169197
def test_kron_reduction(z_primitive, expected_z_abc):
170198
actual_z_abc = perform_kron_reduction(z_primitive)
171199
assert (actual_z_abc == expected_z_abc).all()
200+
201+
202+
@pytest.mark.parametrize(
203+
"z_abc,z_012_expected",
204+
[(z_abc_kersting_4_1(), z_012_kersting_4_1())])
205+
def test_sequence_impedance_matrix(z_abc, z_012_expected):
206+
z_012_computed = calculate_sequence_impedance_matrix(z_abc)
207+
assert_array_almost_equal(z_012_expected, z_012_computed, decimal=0.001)
208+
209+
210+
@pytest.mark.parametrize(
211+
"z_abc,expected_z1,expected_z0",
212+
[(z_abc_kersting_4_1(), z_1_kersting_4_1(), z_0_kersting_4_1())])
213+
def test_sequence_impedance(z_abc, expected_z1, expected_z0):
214+
actual_z1, actual_z0 = calculate_sequence_impedances(z_abc)
215+
assert actual_z1.real == pytest.approx(expected_z1.real, 0.001)
216+
assert actual_z1.imag == pytest.approx(expected_z1.imag, 0.001)
217+
assert actual_z0.real == pytest.approx(expected_z0.real, 0.001)
218+
assert actual_z0.imag == pytest.approx(expected_z0.imag, 0.001)

0 commit comments

Comments
 (0)