forked from saveriob/approx-pf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscenarios.m
372 lines (260 loc) · 8.36 KB
/
scenarios.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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
% This code generates a extra set of simulations of the model presented in
%
% S. Bolognani, S. Zampieri
% "On the existence and linear approximation of the power flow solution in power distribution networks"
% to appear on IEEE Transactions on Power Systems.
% doi: 10.1109/TPWRS.2015.2395452
% Preprint available at http://arxiv.org/abs/1403.5031
%
% This source code is distributed in the hope that it will be useful, but without any warranty.
% We do request that publications in which this testbed is adopted, explicitly acknowledge that fact by citing the above mentioned paper.
%
% MatLab OR GNU Octave, version 3.8.1 available at http://www.gnu.org/software/octave/
% MATPOWER 5.1 available at http://www.pserc.cornell.edu/matpower/
%
% tab width 4
clear all
close all
clc
more off
addpath('matpower5.1');
define_constants;
% Load case_ieee123, inspired by the IEEE 123 test feeder, with
% - symmetric lines
% - balanced loads modeled as PQ buses
% - balanced shunt capacitors
% - switched in their normal position
% - ideal voltage regulators
% The modified testbed is distributed as case_ieee123 in the casefiles
% directory, and needs to be copied in the matpower directory.
mpc = loadcase('case_ieee123');
% As described in the attached technical note, the following simulations will be performed:
% 1) nominal scenario
% 2) uniform overload
% 3) lumped overload
% 4) shunt capacitors
% 5) voltage regulation
% 6) tap changer
% 7) PV buses
% 8) high R/X ratio
% For all these cases, voltage magnitude and voltage phases will be plotted.
% Define useful constants
PCCindex = find(mpc.bus(:,BUS_TYPE)==3);
n = length(mpc.bus(:,BUS_TYPE));
PQnodes = setdiff(1:n,PCCindex);
% Build Laplacian L (neglecting shunt admittances)
nbr = size(mpc.branch,1);
nbu = size(mpc.bus,1);
L = zeros(nbu,nbu);
for br = 1:nbr
br_F_BUS = mpc.branch(br,F_BUS);
br_T_BUS = mpc.branch(br,T_BUS);
br_BR_R = mpc.branch(br,BR_R);
br_BR_X = mpc.branch(br,BR_X);
br_Y = 1 / (br_BR_R + 1j * br_BR_X);
L(br_F_BUS, br_T_BUS) = -br_Y;
L(br_T_BUS, br_F_BUS) = -br_Y;
L(br_F_BUS, br_F_BUS) = L(br_F_BUS, br_F_BUS) + br_Y;
L(br_T_BUS, br_T_BUS) = L(br_T_BUS, br_T_BUS) + br_Y;
end
% Build matrix X
X = inv(L(PQnodes,PQnodes));
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CASE 1
figno = 1;
disp('FIGURE 1: Nominal scenario');
results = runpf(mpc, mpoption('VERBOSE', 0, 'OUT_ALL',0));
full_s = makeSbus(mpc.baseMVA, mpc.bus, mpc.gen);
s = full_s(PQnodes);
UPCC = 1;
u_true = results.bus(PQnodes,VM) .* exp(1j * results.bus(PQnodes,VA)/180*pi);
u_appr = UPCC + X * conj(s);
u_true_nom = u_true;
u_appr_nom = u_appr;
figure(figno)
subplot(211)
plot(1:(n-1), abs(u_true), 'ko ', 1:(n-1), abs(u_appr), 'k. ');
title('Voltage magnitude')
xlim([1 n-1]);
subplot(212)
plot(1:(n-1), angle(u_true), 'ko ', 1:(n-1), angle(u_appr), 'k. ');
title('Voltage angle')
xlim([1 n-1]);
savedata;
errorfigures;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CASE 2
figno = 2;
disp('FIGURE 2: Uniform overload');
mpc = loadcase('case_ieee123');
r = 2;
mpc.bus(PQnodes,PD) = r * mpc.bus(PQnodes,PD);
mpc.bus(PQnodes,GS) = r * mpc.bus(PQnodes,GS);
mpc.bus(PQnodes,QD) = r * mpc.bus(PQnodes,QD);
mpc.bus(PQnodes,BS) = r * mpc.bus(PQnodes,BS);
results = runpf(mpc, mpoption('VERBOSE', 0, 'OUT_ALL',0));
full_s = makeSbus(mpc.baseMVA, mpc.bus, mpc.gen);
s = full_s(PQnodes);
UPCC = 1;
u_true = results.bus(PQnodes,VM) .* exp(1j * results.bus(PQnodes,VA)/180*pi);
u_appr = UPCC + X * conj(s);
plotdata;
savedata;
errorfigures;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CASE 3
figno = 3;
disp('FIGURE 3: Lumped overload %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
mpc = loadcase('case_ieee123');
r = 50;
mpc.bus(32,PD) = r * mpc.bus(32,PD);
mpc.bus(32,GS) = r * mpc.bus(32,GS);
mpc.bus(32,QD) = r * mpc.bus(32,QD);
mpc.bus(32,BS) = r * mpc.bus(32,BS);
results = runpf(mpc, mpoption('VERBOSE', 0, 'OUT_ALL',0));
full_s = makeSbus(mpc.baseMVA, mpc.bus, mpc.gen);
s = full_s(PQnodes);
UPCC = 1;
u_true = results.bus(PQnodes,VM) .* exp(1j * results.bus(PQnodes,VA)/180*pi);
u_appr = UPCC + X * conj(s);
plotdata;
savedata;
errorfigures;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CASE 4
figno = 4;
disp('FIGURE 4: Shunt capacitor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
mpc = loadcase('case_ieee123');
full_s = makeSbus(mpc.baseMVA, mpc.bus, mpc.gen);
s = full_s(PQnodes);
mpc.bus(26,BS) = 0.600;
mpc.bus(28,BS) = 0.050;
mpc.bus(29,BS) = 0.050;
mpc.bus(30,BS) = 0.050;
results = runpf(mpc, mpoption('VERBOSE', 0, 'OUT_ALL',0));
UPCC = 1;
u_true = results.bus(PQnodes,VM) .* exp(1j * results.bus(PQnodes,VA)/180*pi);
L4 = L;
L4(26,26) = L4(26,26) + 1j * 0.600;
L4(28,28) = L4(28,28) + 1j * 0.050;
L4(29,29) = L4(29,29) + 1j * 0.050;
L4(30,30) = L4(30,30) + 1j * 0.050;
X4 = inv(L4(PQnodes,PQnodes));
w = -X4 * L4(PQnodes,PCCindex);
u_appr = UPCC*w + X4 * inv(diag(conj(w))) * conj(s);
plotdata;
savedata;
errorfigures;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CASE 5
figno = 5;
disp('FIGURE 5: Voltage regulation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
mpc = loadcase('case_ieee123');
t = 120/124;
mpc.branch(17,TAP) = t;
results = runpf(mpc, mpoption('VERBOSE', 0, 'OUT_ALL',0));
full_s = makeSbus(mpc.baseMVA, mpc.bus, mpc.gen);
s = full_s(PQnodes);
UPCC = 1;
u_true = results.bus(PQnodes,VM) .* exp(1j * results.bus(PQnodes,VA)/180*pi);
% Build grid matrices for tap position t
reg_buses = [];
for bus = 1:n-1
if (abs(X(bus,17)-X(17,17))<1e-5)
reg_buses = [reg_buses bus];
end
end
L5 = zeros(nbu,nbu);
for br = 1:nbr
br_F_BUS = mpc.branch(br,F_BUS);
br_T_BUS = mpc.branch(br,T_BUS);
br_BR_R = mpc.branch(br,BR_R);
br_BR_X = mpc.branch(br,BR_X);
br_Y = 1 / (br_BR_R + 1j * br_BR_X);
if (ismember(br_F_BUS, reg_buses) || ismember(br_T_BUS, reg_buses))
tt = t^2;
else
tt = 1;
end
L5(br_F_BUS, br_T_BUS) = - tt * br_Y;
L5(br_T_BUS, br_F_BUS) = - tt * br_Y;
L5(br_F_BUS, br_F_BUS) = L5(br_F_BUS, br_F_BUS) + tt * br_Y;
L5(br_T_BUS, br_T_BUS) = L5(br_T_BUS, br_T_BUS) + tt * br_Y;
end
X5 = inv(L5(PQnodes,PQnodes));
d = ones(n-1,1);
d(reg_buses) = 1/t;
u_appr = diag(d) * (UPCC + X5 * conj(s));
plotdata;
savedata;
errorfigures;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CASE 6
figno = 6;
disp('FIGURE 6: Tap changer %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
mpc = loadcase('case_ieee123');
tp = 124/120;
mpc.gen(1,VG) = tp;
results = runpf(mpc, mpoption('VERBOSE', 0, 'OUT_ALL',0));
full_s = makeSbus(mpc.baseMVA, mpc.bus, mpc.gen);
s = full_s(PQnodes);
UPCC = tp;
u_true = results.bus(PQnodes,VM) .* exp(1j * results.bus(PQnodes,VA)/180*pi);
u_appr = UPCC + X/tp * conj(s);
plotdata;
savedata;
errorfigures;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CASE 7
figno = 7;
disp('FIGURE 7: PV buses %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
mpc = loadcase('case_ieee123');
PVbus = [15 51];
mpc.bus(PVbus,BUS_TYPE) = 2;
mpc.gen = [mpc.gen; ...
PVbus' ones(size(PVbus'))*[0 0 200 -200 1 1 1 200 -200 0 0 0 0 0 0 0 0 0 0 0 ]];
mpc.gencost = [mpc.gencost; ...
ones(size(PVbus'))*[ 2 0 0 3 0.01 40 0 ]];
results = runpf(mpc, mpoption('VERBOSE', 0, 'OUT_ALL',0));
full_s = makeSbus(mpc.baseMVA, mpc.bus, mpc.gen);
s = full_s(PQnodes);
UPCC = 1;
Q = -inv(imag(X(PVbus,PVbus)));
R = real(X(PVbus,PVbus)) * real(s(PVbus));
S = real(X(PVbus,setdiff(PQnodes,PVbus))) * real(s(setdiff(PQnodes,PVbus)));
T = imag(X(PVbus,setdiff(PQnodes,PVbus))) * imag(s(setdiff(PQnodes,PVbus)));
qPVbus = Q * (R + S + T);
s(PVbus) = s(PVbus) + 1j * qPVbus;
u_true = results.bus(PQnodes,VM) .* exp(1j * results.bus(PQnodes,VA)/180*pi);
u_appr = UPCC + X * conj(s);
plotdata;
savedata;
errorfigures;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CASE 8
figno = 8;
disp('FIGURE 8: High R/X ratio %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
mpc = loadcase('case_ieee123_ug');
L8 = zeros(nbu,nbu);
for br = 1:nbr
br_F_BUS = mpc.branch(br,F_BUS);
br_T_BUS = mpc.branch(br,T_BUS);
br_BR_R = mpc.branch(br,BR_R);
br_BR_X = mpc.branch(br,BR_X);
br_Y = 1 / (br_BR_R + 1j * br_BR_X);
L8(br_F_BUS, br_T_BUS) = -br_Y;
L8(br_T_BUS, br_F_BUS) = -br_Y;
L8(br_F_BUS, br_F_BUS) = L8(br_F_BUS, br_F_BUS) + br_Y;
L8(br_T_BUS, br_T_BUS) = L8(br_T_BUS, br_T_BUS) + br_Y;
end
% Build matrix X
X8 = inv(L8(PQnodes,PQnodes));
results = runpf(mpc, mpoption('VERBOSE', 0, 'OUT_ALL',0));
full_s = makeSbus(mpc.baseMVA, mpc.bus, mpc.gen);
s = full_s(PQnodes);
UPCC = 1;
u_true = results.bus(PQnodes,VM) .* exp(1j * results.bus(PQnodes,VA)/180*pi);
u_appr = UPCC + X8 * conj(s);
plotdata;
savedata;
errorfigures;