/
line.py
278 lines (233 loc) 路 10.2 KB
/
line.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
import logging
from andes.core.model import Model, ModelData # NOQA
from andes.core.param import IdxParam, DataParam, NumParam # NOQA
from andes.core.var import Algeb, State, ExtAlgeb # NOQA
from andes.core.service import ConstService # NOQA
logger = logging.getLogger(__name__)
class LineData(ModelData):
"""
Data for Line.
"""
def __init__(self):
super().__init__()
self.bus1 = IdxParam(model='Bus', info="idx of from bus")
self.bus2 = IdxParam(model='Bus', info="idx of to bus")
self.Sn = NumParam(default=100.0,
info="Power rating",
non_zero=True,
tex_name=r'S_n',
unit='MW',
)
self.fn = NumParam(default=60.0,
info="rated frequency",
tex_name='f',
unit='Hz',
)
self.Vn1 = NumParam(default=110.0,
info="AC voltage rating",
non_zero=True,
tex_name=r'V_{n1}',
unit='kV',
)
self.Vn2 = NumParam(default=110.0,
info="rated voltage of bus2",
non_zero=True,
tex_name=r'V_{n2}',
unit='kV',
)
self.r = NumParam(default=1e-8,
info="line resistance",
tex_name='r',
z=True,
unit='p.u.',
)
self.x = NumParam(default=1e-8,
info="line reactance",
tex_name='x',
z=True,
unit='p.u.',
)
self.b = NumParam(default=0.0,
info="shared shunt susceptance",
y=True,
unit='p.u.',
)
self.g = NumParam(default=0.0,
info="shared shunt conductance",
y=True,
unit='p.u.',
)
self.b1 = NumParam(default=0.0,
info="from-side susceptance",
y=True,
tex_name='b_1',
unit='p.u.',
)
self.g1 = NumParam(default=0.0,
info="from-side conductance",
y=True,
tex_name='g_1',
unit='p.u.',
)
self.b2 = NumParam(default=0.0,
info="to-side susceptance",
y=True,
tex_name='b_2',
unit='p.u.',
)
self.g2 = NumParam(default=0.0,
info="to-side conductance",
y=True,
tex_name='g_2',
unit='p.u.',
)
self.trans = NumParam(default=0,
info="transformer branch flag",
unit='bool',
)
self.tap = NumParam(default=1.0,
info="transformer branch tap ratio",
tex_name='t_{ap}',
non_negative=True,
unit='float',
)
self.phi = NumParam(default=0.0,
info="transformer branch phase shift in rad",
tex_name=r'\phi',
unit='radian',
)
self.owner = IdxParam(model='Owner', info="owner code")
self.xcoord = DataParam(info="x coordinates")
self.ycoord = DataParam(info="y coordinates")
class Line(LineData, Model):
"""
AC transmission line model.
To reduce the number of variables, line injections are summed at bus equations
and are not stored. Current injections are not computed.
"""
def __init__(self, system=None, config=None):
LineData.__init__(self)
Model.__init__(self, system, config)
self.group = 'ACLine'
self.flags.pflow = True
self.flags.tds = True
self.a1 = ExtAlgeb(model='Bus', src='a', indexer=self.bus1, tex_name='a_1',
info='phase angle of the from bus',
ename='Pij',
tex_ename='P_{ij}',
)
self.a2 = ExtAlgeb(model='Bus', src='a', indexer=self.bus2, tex_name='a_2',
info='phase angle of the to bus',
ename='Pji',
tex_ename='P_{ji}',
)
self.v1 = ExtAlgeb(model='Bus', src='v', indexer=self.bus1, tex_name='v_1',
info='voltage magnitude of the from bus',
ename='Qij',
tex_ename='Q_{ij}',
)
self.v2 = ExtAlgeb(model='Bus', src='v', indexer=self.bus2, tex_name='v_2',
info='voltage magnitude of the to bus',
ename='Qji',
tex_ename='Q_{ji}',
)
self.gh = ConstService(tex_name='g_h')
self.bh = ConstService(tex_name='b_h')
self.gk = ConstService(tex_name='g_k')
self.bk = ConstService(tex_name='b_k')
self.yh = ConstService(tex_name='y_h', vtype=complex)
self.yk = ConstService(tex_name='y_k', vtype=complex)
self.yhk = ConstService(tex_name='y_{hk}', vtype=complex)
self.ghk = ConstService(tex_name='g_{hk}')
self.bhk = ConstService(tex_name='b_{hk}')
self.itap = ConstService(tex_name='1/t_{ap}')
self.itap2 = ConstService(tex_name='1/t_{ap}^2')
self.gh.v_str = 'g1 + 0.5 * g'
self.bh.v_str = 'b1 + 0.5 * b'
self.gk.v_str = 'g2 + 0.5 * g'
self.bk.v_str = 'b2 + 0.5 * b'
self.yh.v_str = 'u * (gh + 1j * bh)'
self.yk.v_str = 'u * (gk + 1j * bk)'
self.yhk.v_str = 'u/((r+1e-8) + 1j*(x+1e-8))'
self.ghk.v_str = 're(yhk)'
self.bhk.v_str = 'im(yhk)'
self.itap.v_str = '1/tap'
self.itap2.v_str = '1/tap/tap'
self.a1.e_str = 'u * (v1 ** 2 * (gh + ghk) * itap2 - \
v1 * v2 * (ghk * cos(a1 - a2 - phi) + \
bhk * sin(a1 - a2 - phi)) * itap)'
self.v1.e_str = 'u * (-v1 ** 2 * (bh + bhk) * itap2 - \
v1 * v2 * (ghk * sin(a1 - a2 - phi) - \
bhk * cos(a1 - a2 - phi)) * itap)'
self.a2.e_str = 'u * (v2 ** 2 * (gh + ghk) - \
v1 * v2 * (ghk * cos(a1 - a2 - phi) - \
bhk * sin(a1 - a2 - phi)) * itap)'
self.v2.e_str = 'u * (-v2 ** 2 * (bh + bhk) + \
v1 * v2 * (ghk * sin(a1 - a2 - phi) + \
bhk * cos(a1 - a2 - phi)) * itap)'
class JumperData(ModelData):
"""
Data for jumper that merges two buses into one.
"""
def __init__(self):
ModelData.__init__(self)
self.bus1 = IdxParam(model='Bus', info="idx of from bus")
self.bus2 = IdxParam(model='Bus', info="idx of to bus")
class JumperModel(Model):
"""
Jumper model implementation.
"""
def __init__(self, system, config):
Model.__init__(self, system, config)
self.flags.pflow = True
self.flags.tds = True
self.group = 'ACShort'
self.a1 = ExtAlgeb(model='Bus', src='a', indexer=self.bus1, tex_name='a_1',
info='phase angle of the from bus',
ename='Pij',
tex_ename='P_{ij}',
)
self.a2 = ExtAlgeb(model='Bus', src='a', indexer=self.bus2, tex_name='a_2',
info='phase angle of the to bus',
ename='Pji',
tex_ename='P_{ji}',
)
self.v1 = ExtAlgeb(model='Bus', src='v', indexer=self.bus1, tex_name='v_1',
info='voltage magnitude of the from bus',
ename='Qij',
tex_ename='Q_{ij}',
)
self.v2 = ExtAlgeb(model='Bus', src='v', indexer=self.bus2, tex_name='v_2',
info='voltage magnitude of the to bus',
ename='Qji',
tex_ename='Q_{ji}',
)
self.p = Algeb(info='active power (1 to 2)',
e_str='u * (a1 - a2)',
tex_name='P',
diag_eps=True,
)
self.q = Algeb(info='active power (1 to 2)',
e_str='u * (v1 - v2)',
tex_name='Q',
diag_eps=True,
)
self.a1.e_str = 'p'
self.a2.e_str = '-p'
self.v1.e_str = 'q'
self.v2.e_str = '-q'
class Jumper(JumperData, JumperModel):
"""
Jumper is a device to short two buses (merging two buses into one).
Jumper can connect two buses satisfying one of the following conditions:
- neither bus is voltage-controlled
- either bus is voltage-controlled
- both buses are voltage-controlled, and the voltages are the same.
If the buses are controlled in different voltages, power flow will
not solve (as the power flow through the jumper will be infinite).
In the solutions, the ``p`` and ``q`` are flowing out of bus1
and flowing into bus2.
"""
def __init__(self, system, config):
JumperData.__init__(self)
JumperModel.__init__(self, system, config)