-
Notifications
You must be signed in to change notification settings - Fork 148
/
dme_branch.m
305 lines (274 loc) · 12.4 KB
/
dme_branch.m
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
classdef dme_branch < mp.dm_element
% mp.dme_branch - Data model element for branch.
%
% Implements the data element model for branch elements, including
% transmission lines and transformers.
%
% Adds the following columns in the main data table, found in the
% :attr:`tab` property:
%
% =========== ========= ========================================
% Name Type Description
% =========== ========= ========================================
% ``bus_fr`` *integer* bus ID (``uid``) of "from" bus
% ``bus_to`` *integer* bus ID (``uid``) of "to" bus
% ``r`` *double* per unit series resistance
% ``x`` *double* per unit series reactance
% ``g_fr`` *double* per unit shunt conductance at "from" end
% ``b_fr`` *double* per unit shunt susceptance at "from" end
% ``g_to`` *double* per unit shunt conductance at "to" end
% ``b_to`` *double* per unit shunt susceptance at "to" end
% ``sm_ub_a`` *double* long term apparent power rating (MVA)
% ``sm_ub_b`` *double* short term apparent power rating (MVA)
% ``sm_ub_c`` *double* emergency apparent power rating (MVA)
% ``cm_ub_a`` *double* long term current magnitude rating (MVA
% equivalent at 1 p.u. voltage)
% ``cm_ub_b`` *double* short term current magnitude rating (MVA
% equivalent at 1 p.u. voltage)
% ``cm_ub_c`` *double* emergency current magnitude rating (MVA
% equivalent at 1 p.u. voltage)
% ``vad_lb`` *double* voltage angle difference lower bound
% ``vad_ub`` *double* voltage angle difference upper bound
% ``tm`` *double* transformer off-nominal turns ratio
% ``ta`` *double* transformer phase-shift angle (degrees)
% ``pl_fr`` *double* active power injection at "from" end
% ``ql_fr`` *double* reactive power injection at "from" end
% ``pl_to`` *double* active power injection at "to" end
% ``ql_to`` *double* reactive power injection at "to" end
% ``psh_fr`` *double* active power shunt losses at "from" end
% ``qsh_fr`` *double* reactive power shunt losses at "from" end
% ``psh_to`` *double* active power shunt losses at "to" end
% ``qsh_to`` *double* reactive power shunt losses at "to" end
% =========== ========= ========================================
% MATPOWER
% Copyright (c) 2020-2024, Power Systems Engineering Research Center (PSERC)
% by Ray Zimmerman, PSERC Cornell
%
% This file is part of MATPOWER.
% Covered by the 3-clause BSD License (see LICENSE file for details).
% See https://matpower.org for more info.
properties
fbus % bus index vector for "from" port (port 1) (all branches)
tbus % bus index vector for "to" port (port 2) (all branches)
r % series resistance (p.u.) for branches that are on
x % series reactance (p.u.) for branches that are on
g_fr % shunt conductance (p.u.) at "from" end for branches that are on
g_to % shunt conductance (p.u.) at "to" end for branches that are on
b_fr % shunt susceptance (p.u.) at "from" end for branches that are on
b_to % shunt susceptance (p.u.) at "to" end for branches that are on
tm % transformer off-nominal turns ratio for branches that are on
ta % xformer phase-shift angle (radians) for branches that are on
rate_a % long term flow limit (p.u.) for branches that are on
loss_tol = 1e-4; % loss values < this are displayed as ``-``
end %% properties
methods
function name = name(obj)
%
name = 'branch';
end
function label = label(obj)
%
label = 'Branch';
end
function label = labels(obj)
%
label = 'Branches';
end
function name = cxn_type(obj)
%
name = 'bus';
end
function name = cxn_idx_prop(obj)
%
name = {'fbus', 'tbus'};
end
function names = main_table_var_names(obj)
%
names = horzcat( main_table_var_names@mp.dm_element(obj), ...
{'bus_fr', 'bus_to', 'r', 'x', 'g_fr', 'b_fr', ...
'g_to', 'b_to', 'sm_ub_a', 'sm_ub_b', 'sm_ub_c', ...
'cm_ub_a', 'cm_ub_b', 'cm_ub_c', 'vad_lb', 'vad_ub', ...
'tm', 'ta', ... %% remove these when we separate out xformers
'pl_fr', 'ql_fr', 'pl_to', 'ql_to', ...
'psh_fr', 'qsh_fr', 'psh_to', 'qsh_to'} );
end
function vars = export_vars(obj)
%
vars = {'pl_fr', 'ql_fr', 'pl_to', 'ql_to', ...
'psh_fr', 'qsh_fr', 'psh_to', 'qsh_to'};
end
function s = export_vars_offline_val(obj)
%
s = export_vars_offline_val@mp.dm_element(obj); %% call parent
s.pl_fr = 0;
s.ql_fr = 0;
s.pl_to = 0;
s.ql_to = 0;
s.psh_fr = 0;
s.qsh_fr = 0;
s.psh_to = 0;
s.qsh_to = 0;
end
function obj = initialize(obj, dm)
%
initialize@mp.dm_element(obj, dm); %% call parent
%% get bus mapping info
b2i = dm.elements.bus.ID2i; %% bus num to idx mapping
%% set bus index vectors for port connectivity
obj.fbus = b2i(obj.tab.bus_fr);
obj.tbus = b2i(obj.tab.bus_to);
end
function obj = update_status(obj, dm)
%
%% get bus status info
bs = dm.elements.bus.tab.status; %% bus status
%% update status of branches connected to isolated/offline buses
obj.tab.status = obj.tab.status & bs(obj.fbus) & ...
bs(obj.tbus);
%% call parent to fill in on/off
update_status@mp.dm_element(obj, dm);
end
function obj = build_params(obj, dm)
%
obj.r = obj.tab.r(obj.on);
obj.x = obj.tab.x(obj.on);
obj.g_fr = obj.tab.g_fr(obj.on);
obj.b_fr = obj.tab.b_fr(obj.on);
obj.g_to = obj.tab.g_to(obj.on);
obj.b_to = obj.tab.b_to(obj.on);
obj.tm = obj.tab.tm(obj.on);
obj.ta = obj.tab.ta(obj.on) * pi/180;
obj.rate_a = obj.tab.sm_ub_a(obj.on) / dm.base_mva;
end
function obj = pp_data_cnt(obj, dm, rows, out_e, mpopt, fd, pp_args)
%
%% call parent
pp_data_cnt@mp.dm_element(obj, dm, rows, out_e, mpopt, fd, pp_args);
num_xf = length(find(obj.tab.tm));
num_xf_on = length(find(obj.tab.tm(obj.on)));
num_ln = obj.nr - num_xf;
num_ln_on = obj.n - num_xf_on;
ln = sprintf('%d', num_ln);
if num_ln == num_ln_on
ln_on = ln;
ln_off = '-';
else
ln_on = sprintf('%d', num_ln_on);;
ln_off = sprintf('%d', num_ln - num_ln_on);
end
xf = sprintf('%d', num_xf);
if num_xf == num_xf_on
xf_on = xf;
xf_off = '-';
else
xf_on = sprintf('%d', num_xf_on);;
xf_off = sprintf('%d', num_xf - num_xf_on);
end
%% print line, transformer counts
fprintf(fd, ' %-20s%7s %7s %7s\n', ' Lines', ln_on, ln_off, ln);
fprintf(fd, ' %-20s%7s %7s %7s\n', ' Transformers', xf_on, xf_off, xf);
end
function TorF = pp_have_section_sum(obj, mpopt, pp_args)
%
TorF = true;
end
function obj = pp_data_sum(obj, dm, rows, out_e, mpopt, fd, pp_args)
%
%% call parent
pp_data_sum@mp.dm_element(obj, dm, rows, out_e, mpopt, fd, pp_args);
%% print branch summary
p_loss = sum(obj.tab.pl_fr(obj.on)) + sum(obj.tab.pl_to(obj.on));
p_shunt = sum(obj.tab.psh_fr(obj.on)) + sum(obj.tab.psh_to(obj.on));
p_series = p_loss - p_shunt;
if abs(p_series) < obj.loss_tol
p_series_str = '- ';
else
p_series_str = sprintf('%12.2f', p_series);
end
fprintf(fd, ' %-29s %12s MW', 'Total branch series losses', ...
p_series_str);
if mpopt.model(1) ~= 'D' %% AC model
q_loss = sum(obj.tab.ql_fr(obj.on)) + sum(obj.tab.ql_to(obj.on));
q_shunt = sum(obj.tab.qsh_fr(obj.on)) + ...
sum(obj.tab.qsh_to(obj.on));
q_series = q_loss - q_shunt;
if abs(q_series) < obj.loss_tol
q_series_str = '- ';
else
q_series_str = sprintf('%12.2f', q_series);
end
fprintf(fd, ' %12s MVAr', q_series_str);
end
fprintf(fd, '\n');
if abs(p_shunt) < obj.loss_tol
p_shunt_str = '- ';
else
p_shunt_str = sprintf('%12.2f', p_shunt);
end
fprintf(fd, ' %-29s %12s MW', 'Total branch shunt losses', ...
p_shunt_str );
if mpopt.model(1) ~= 'D' %% AC model
if abs(q_shunt) < obj.loss_tol
q_shunt_str = '- ';
else
q_shunt_str = sprintf('%12.2f', q_shunt);
end
fprintf(fd, ' %12s MVAr', q_shunt_str );
end
fprintf(fd, '\n');
end
function h = pp_get_headers_det(obj, dm, out_e, mpopt, pp_args)
%
h = [ pp_get_headers_det@mp.dm_element(obj, dm, out_e, mpopt, pp_args) ...
{ ' Branch From To From Bus Injection To Bus Injection', ...
' ID Bus ID Bus ID Status P (MW) Q (MVAr) P (MW) Q (MVAr)', ...
'-------- -------- -------- ------ -------- -------- -------- --------' } ];
%% 1234567 123456789 123456789 -----1 1234567.90 123456.89 123456.89 123456.89
if mpopt.model(1) ~= 'D' %% AC model
h{end-2} = [h{end-2} ' Series Loss'];
h{end-1} = [h{end-1} ' P (MW) Q (MVAr)'];
h{end} = [h{end} ' -------- --------'];
%% 12345.789 123456.89
%% 12345.789 123456.89
end
end
function f = pp_get_footers_det(obj, dm, out_e, mpopt, pp_args)
%
if mpopt.model(1) == 'D' %% DC model (series losses)
f = {};
else %% AC model
p_loss = sum(obj.tab.pl_fr(obj.on)) + ...
sum(obj.tab.pl_to(obj.on));
p_shunt = sum(obj.tab.psh_fr(obj.on)) + ...
sum(obj.tab.psh_to(obj.on));
p_series = p_loss - p_shunt;
q_loss = sum(obj.tab.ql_fr(obj.on)) + ...
sum(obj.tab.ql_to(obj.on));
q_shunt = sum(obj.tab.qsh_fr(obj.on)) + ...
sum(obj.tab.qsh_to(obj.on));
q_series = q_loss - q_shunt;
f = {' -------- --------',
sprintf('%69s Total:%9.3f %9.2f', '', p_series, q_series)};
end
end
function TorF = pp_have_section_det(obj, mpopt, pp_args)
%
TorF = true;
end
function str = pp_data_row_det(obj, dm, k, out_e, mpopt, fd, pp_args)
%
str = sprintf('%7d %9d %9d %6d %10.2f %9.2f %9.2f %9.2f', ...
obj.tab.uid(k), obj.tab.bus_fr(k), obj.tab.bus_to(k), ...
obj.tab.status(k), ...
obj.tab.pl_fr(k), obj.tab.ql_fr(k), ...
obj.tab.pl_to(k), obj.tab.ql_to(k) );
if mpopt.model(1) ~= 'D' %% AC model
str = sprintf('%s %9.3f %9.2f', str, ...
obj.tab.pl_fr(k) + obj.tab.pl_to(k) ...
- obj.tab.psh_fr(k) - obj.tab.psh_to(k), ...
obj.tab.ql_fr(k) + obj.tab.ql_to(k) ...
- obj.tab.qsh_fr(k) - obj.tab.qsh_to(k) );
end
end
end %% methods
end %% classdef