-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_carsons.py
318 lines (264 loc) · 8.88 KB
/
test_carsons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import pytest
from numpy.testing import assert_array_almost_equal
from numpy import array
from carsons.carsons import (
CarsonsEquations,
convert_geometric_model,
perform_kron_reduction,
)
# `carsons` implements the model entirely in SI metric units, however this
# conversion allows us to enter in impedance as ohm-per-mile in the test
# harness, which means we can lift matrices directly out of the ieee test
# network.
OHM_PER_MILE_TO_OHM_PER_METER = 1 / 1609.344
class ABCN_geometry_line():
""" IEEE 13 Configuration 601 Line Geometry """
@property
def resistance(self):
return {
'A': 0.000115575,
'B': 0.000115575,
'C': 0.000115575,
'N': 0.000367852,
}
@property
def geometric_mean_radius(self):
return {
'A': 0.00947938,
'B': 0.00947938,
'C': 0.00947938,
'N': 0.00248107,
}
@property
def wire_positions(self):
return {
'A': (0.762, 8.5344),
'B': (2.1336, 8.5344),
'C': (0, 8.5344),
'N': (1.2192, 7.3152),
}
@property
def phases(self):
return [
'A',
'B',
'C',
'N',
]
class CBN_geometry_line():
""" IEEE 13 Configuration 603 Line Geometry """
@property
def resistance(self):
return {
'B': 0.000695936,
'C': 0.000695936,
'N': 0.000695936,
}
@property
def geometric_mean_radius(self):
return {
'B': 0.00135941,
'C': 0.00135941,
'N': 0.00135941,
}
@property
def wire_positions(self):
return {
'B': (2.1336, 8.5344),
'C': (0, 8.5344),
'N': (1.2192, 7.3152),
}
@property
def phases(self):
return [
'B',
'C',
'N',
]
class CN_geometry_line():
""" IEEE 13 Configuration 605 Line Geometry"""
@property
def resistance(self):
return {
'C': 0.000695936,
'N': 0.000695936,
}
@property
def geometric_mean_radius(self):
return {
'C': 0.00135941,
'N': 0.00135941,
}
@property
def wire_positions(self):
return {
'C': (0, 8.8392),
'N': (0.1524, 7.3152),
}
@property
def phases(self):
return [
'C',
'N',
]
class ABCN_balanced_line():
@property
def resistance(self):
return {
'A': 0.000115575,
'B': 0.000115575,
'C': 0.000115575,
'N': 0.000115575,
}
@property
def geometric_mean_radius(self):
return {
'A': 0.00947938,
'B': 0.00947938,
'C': 0.00947938,
'N': 0.00947938,
}
@property
def wire_positions(self):
return {
'A': (0.762, 8.5344),
'B': (2.1336, 8.5344),
'C': (0, 8.5344),
'N': (1.2192, 7.3152),
}
@property
def phases(self):
return [
'A',
'B',
'C',
'N',
]
def ABCN_line_geometry_phase_impedance():
""" IEEE 13 Configuration 601 Impedance Solution """
return OHM_PER_MILE_TO_OHM_PER_METER * array([
[0.3465 + 1.0179j, 0.1560 + 0.5017j, 0.1580 + 0.4236j],
[0.1560 + 0.5017j, 0.3375 + 1.0478j, 0.1535 + 0.3849j],
[0.1580 + 0.4236j, 0.1535 + 0.3849j, 0.3414 + 1.0348j]])
def ABCN_line_z_primitive():
return array([
[1.74792626e-04+0.00085989j,
5.92176264e-05+0.00052913j,
5.92176264e-05+0.00048481j,
5.92176264e-05+0.00048873j],
[5.92176264e-05+0.00052913j,
1.74792626e-04+0.00085989j,
5.92176264e-05+0.0004515j,
5.92176264e-05+0.00046756j],
[5.92176264e-05+0.00048481j,
5.92176264e-05+0.0004515j,
1.74792626e-04+0.00085989j,
5.92176264e-05+0.00047687j],
[5.92176264e-05+0.00048873j,
5.92176264e-05+0.00046756j,
5.92176264e-05+0.00047687j,
4.27069626e-04+0.00096095j]])
def ABCN_balanced_z_primitive():
return array([
[1.74792626e-04+0.00085989j,
5.92176264e-05+0.00052913j,
5.92176264e-05+0.00048481j,
5.92176264e-05+0.00048873j],
[5.92176264e-05+0.00052913j,
1.74792626e-04+0.00085989j,
5.92176264e-05+0.0004515j,
5.92176264e-05+0.00046756j],
[5.92176264e-05+0.00048481j,
5.92176264e-05+0.0004515j,
1.74792626e-04+0.00085989j,
5.92176264e-05+0.00047687j],
[5.92176264e-05+0.00048873j,
5.92176264e-05+0.00046756j,
5.92176264e-05+0.00047687j,
1.74792626e-04+0.00085989j]
])
def CBN_line_geometry_phase_impedance():
""" IEEE 13 Configuration 603 Impedance Solution """
return OHM_PER_MILE_TO_OHM_PER_METER * array([
[0.0000 + 0.0000j, 0.0000 + 0.0000j, 0.0000 + 0.0000j],
[0.0000 + 0.0000j, 1.3294 + 1.3471j, 0.2066 + 0.4591j],
[0.0000 + 0.0000j, 0.2066 + 0.4591j, 1.3238 + 1.3569j]])
def CN_line_geometry_phase_impedance():
""" IEEE 13 Configuration 605 Impedance Solution """
return OHM_PER_MILE_TO_OHM_PER_METER * array([
[0.0000 + 0.0000j, 0.0000 + 0.0000j, 0.0000 + 0.0000j],
[0.0000 + 0.0000j, 0.0000 + 0.0000j, 0.0000 + 0.0000j],
[0.0000 + 0.0000j, 0.0000 + 0.0000j, 1.3292 + 1.3475j]])
def CN_line_z_primitive():
return array([
[0.0+0.j, 0.0+0.j, 0.0+0.j, 0.0+0.j],
[0.0+0.j, 0.0+0.j, 0.0+0.j, 0.0+0.j],
[0.0+0.j, 0.0+0.j, 7.5515e-04+1.006e-3j, 5.9217e-05+0.00047649j],
[0.0+0.j, 0.0+0.j, 5.921e-05+0.00047649j, 7.5515e-04+0.00100631j]])
def z_primitive_no_neutral():
return array([[1.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j],
[0.0 + 0.0j, 1.0 + 0.0j, 0.0 + 0.0j],
[0.0 + 0.0j, 0.0 + 0.0j, 1.0 + 0.0j]])
def z_primitive_one_neutral():
return array([[1.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j, 1.0 + 0.0j],
[0.0 + 0.0j, 1.0 + 0.0j, 0.0 + 0.0j, 1.0 + 0.0j],
[0.0 + 0.0j, 0.0 + 0.0j, 1.0 + 0.0j, 1.0 + 0.0j],
[1.0 + 0.0j, 1.0 + 0.0j, 1.0 + 0.0j, 1.0 + 0.0j]])
def expected_z_abc_one_neutral():
return array([
[0.0 + 0.0j, -1.0 + 0.0j, -1.0 + 0.0j],
[-1.0 + 0.0j, 0.0 + 0.0j, -1.0 + 0.0j],
[-1.0 + 0.0j, -1.0 + 0.0j, 0.0 + 0.0j]])
def z_primitive_three_neutrals():
return array([
[1 + 0j, 0 + 0j, 0 + 0j, 1 + 0j, 2 + 0j, 3 + 0j],
[0 + 0j, 1 + 0j, 0 + 0j, 1 + 0j, 2 + 0j, 3 + 0j],
[0 + 0j, 0 + 0j, 1 + 0j, 1 + 0j, 2 + 0j, 3 + 0j],
[1 + 0j, 1 + 0j, 1 + 0j, 1 + 0j, 0 + 0j, 0 + 0j],
[2 + 0j, 2 + 0j, 2 + 0j, 0 + 0j, 1 + 0j, 0 + 0j],
[3 + 0j, 3 + 0j, 3 + 0j, 0 + 0j, 0 + 0j, 1 + 0j]])
def expected_z_abc_three_neutrals():
return array([
[-13 + 0j, -14 + 0j, -14 + 0j],
[-14 + 0j, -13 + 0j, -14 + 0j],
[-14 + 0j, -14 + 0j, -13 + 0j]])
@pytest.mark.parametrize(
"line,expected_impedance",
[(ABCN_geometry_line(), ABCN_line_geometry_phase_impedance()),
(CBN_geometry_line(), CBN_line_geometry_phase_impedance()),
(CN_geometry_line(), CN_line_geometry_phase_impedance())])
def test_converts_geometry_to_phase_impedance(line, expected_impedance):
actual_impedance = convert_geometric_model(line)
assert_array_almost_equal(expected_impedance,
actual_impedance,
decimal=4)
@pytest.mark.parametrize(
"line,z_primitive_expected",
[(ABCN_geometry_line(), ABCN_line_z_primitive()),
(CN_geometry_line(), CN_line_z_primitive())])
def test_unbalanced_carsons_equations(line, z_primitive_expected):
model = CarsonsEquations(line)
z_primitive_computed = model.build_z_primitive()
assert_array_almost_equal(
z_primitive_expected,
z_primitive_computed,
decimal=4)
@pytest.mark.parametrize(
"line,z_primitive_expected",
[(ABCN_balanced_line(), ABCN_balanced_z_primitive())])
def test_balanced_carsons_equations(line, z_primitive_expected):
model = CarsonsEquations(line)
z_primitive_computed = model.build_z_primitive()
assert_array_almost_equal(
z_primitive_expected,
z_primitive_computed,
decimal=4
)
@pytest.mark.parametrize(
"z_primitive,expected_z_abc",
[(z_primitive_no_neutral(), z_primitive_no_neutral()),
(z_primitive_one_neutral(), expected_z_abc_one_neutral()),
(z_primitive_three_neutrals(), expected_z_abc_three_neutrals())])
def test_kron_reduction(z_primitive, expected_z_abc):
actual_z_abc = perform_kron_reduction(z_primitive)
assert (actual_z_abc == expected_z_abc).all()