forked from saveriob/approx-pf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaper.m
445 lines (295 loc) · 10.8 KB
/
paper.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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
% This code generates the simulations included 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');
% 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); % FROM bus
br_T_BUS = mpc.branch(br,T_BUS); % TO bus
br_BR_R = mpc.branch(br,BR_R); % RESISTANCE
br_BR_X = mpc.branch(br,BR_X); % INDUCTANCE
br_Y = 1 / (br_BR_R + 1j * br_BR_X); % ADMITTANCE
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));
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figno = 1;
disp('FIGURE 1: Voltage magnitude');
results = runpf(mpc, mpoption('VERBOSE', 0, 'OUT_ALL',0));
full_s = makeSbus(mpc.baseMVA, mpc.bus, mpc.gen);
s = full_s(PQnodes);
u_true = results.bus(PQnodes,VM) .* exp(1j * results.bus(PQnodes,VA)/180*pi);
u_appr = 1 + X * conj(s);
figure(figno)
plot(1:(n-1), abs(u_true), 'ko ', 1:(n-1), abs(u_appr), 'k. ');
title('Voltage magnitude')
xlim([1 n-1]);
% check conditions of Theorem 1 for the existence of a practical solution
rho_2_star = max(arrayfun(@(idx) norm(X(idx,:),2), 1:size(X,1)));
fprintf(1,'X 2-star: %f\n', rho_2_star);
fprintf(1,'s 2-norm: %f\n', norm(s,2));
fprintf(1,'4 * ||X|| * ||s|| = %f <? 1\n\n', 4 * rho_2_star * norm(s,2));
% check if condition is verified with algebraic connectivity of L
eigL = sort(abs(eig(L)));
sigma2 = eigL(2);
fprintf(1,'sigma_2: %f\n', sigma2);
fprintf(1,'s 2-norm: %f\n', norm(s,2));
fprintf(1,'4 * ||s|| / sigma_2 = %f <? 1\n\n', 4 * norm(s,2) / sigma2);
% check if condition is verified with p=1, q=Inf norms
rho_Inf_star = max(max(abs(X)));
fprintf(1,'X Inf-star: %f\n', rho_Inf_star);
fprintf(1,'s 1-norm: %f\n', norm(s,1));
fprintf(1,'4 * ||X|| * ||s|| = %f <? 1\n\n', 4 * rho_Inf_star * norm(s,1));
% plot error bands for different p-norms
ps = [1 2];
nps = length(ps);
margins = zeros(n-1,nps);
hold on
for p = 1:nps
normq = arrayfun(@(idx) norm(X(idx,:),holder(ps(p))), 1:size(X,1));
margins(:,p) = 4 * normq * max(normq) * norm(s,ps(p))^2;
plot(1:(n-1), abs(u_appr)-margins(:,p), p, 1:(n-1), abs(u_appr)+margins(:,p), p);
text(n, abs(u_appr(end))-margins(end,p), num2str(ps(p)));
end
ylim([0.5 1.1])
% Save voltage magnitude data
fname = 'data_paper_voltagem.data';
myfile=fopen(fname,'w');
fprintf(myfile,'bus appr real min1 max1 min2 max2');
fclose(myfile);
data_voltagem = [(1:n-1)' ...
abs(u_appr) ...
results.bus(PQnodes,VM) ...
abs(u_appr)-margins(:,1) ...
abs(u_appr)+margins(:,1) ...
abs(u_appr)-margins(:,2) ...
abs(u_appr)+margins(:,2)];
save('-append', '-ascii', fname, 'data_voltagem');
errorfigures;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DC power flow comparison
figno = 2;
disp('FIGURE 2: Voltage angles');
figure(figno)
% plot
% - true angles
% - approximate model
% - linear angles
% - DC power flow
plot( 1:(n-1), angle(u_true)/pi*180, 'ko ', ...
1:(n-1), angle(u_appr)/pi*180, 'k. ', ...
1:(n-1), imag(X * conj(s))/pi*180, 'kx ', ...
1:(n-1), (imag(X) * real(s)) /pi*180, 'k+ ');
title('Voltage angle')
xlim([1 n-1]);
% Save voltage angle data
fname = 'data_paper_voltagea.data';
myfile=fopen(fname,'w');
fprintf(myfile,'bus appr real linear dc');
fclose(myfile);
data_voltagem = [(1:n-1)' ...
angle(u_appr)/pi*180 ...
angle(u_true)/pi*180 ...
imag(X * conj(s))/pi*180 ...
(imag(X) * real(s)) /pi*180];
save('-append', '-ascii', fname, 'data_voltagem');
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figno = 3;
disp('FIGURE 3: Voltage magnitude (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);
u_true = results.bus(PQnodes,VM) .* exp(1j * results.bus(PQnodes,VA)/180*pi);
u_appr = 1 + X * conj(s);
figure(figno)
plot(1:(n-1), abs(u_true), 'ko ', 1:(n-1), abs(u_appr), 'k. ');
title('Voltage magnitude')
xlim([1 n-1]);
% check conditions of Theorem 1 for the existence of a practical solution
rho_2_star = max(arrayfun(@(idx) norm(X(idx,:),2), 1:size(X,1)));
fprintf(1,'X 2-star: %f\n', rho_2_star);
fprintf(1,'s 2-norm: %f\n', norm(s,2));
fprintf(1,'4 * ||X|| * ||s|| = %f <? 1\n\n', 4 * rho_2_star * norm(s,2));
% check if condition is verified with algebraic connectivity of L
eigL = sort(abs(eig(L)));
sigma2 = eigL(2);
fprintf(1,'sigma_2: %f\n', sigma2);
fprintf(1,'s 2-norm: %f\n', norm(s,2));
fprintf(1,'4 * ||s|| / sigma_2 = %f <? 1\n\n', 4 * norm(s,2) / sigma2);
% check if condition is verified with p=1, q=Inf norms
rho_Inf_star = max(max(abs(X)));
fprintf(1,'X Inf-star: %f\n', rho_Inf_star);
fprintf(1,'s 1-norm: %f\n', norm(s,1));
fprintf(1,'4 * ||X|| * ||s|| = %f <? 1\n\n', 4 * rho_Inf_star * norm(s,1));
% plot error bands for different p-norms
ps = [1 2];
nps = length(ps);
margins = zeros(n-1,nps);
hold on
for p = 1:nps
normq = arrayfun(@(idx) norm(X(idx,:),holder(ps(p))), 1:size(X,1));
margins(:,p) = 4 * normq * max(normq) * norm(s,ps(p))^2;
plot(1:(n-1), abs(u_appr)-margins(:,p), p, 1:(n-1), abs(u_appr)+margins(:,p), p);
text(n, abs(u_appr(end))-margins(end,p), num2str(ps(p)));
end
ylim([0.5 1.1])
% Save voltage magnitude data
fname = 'data_paper_voltagem_overload.data';
myfile=fopen(fname,'w');
fprintf(myfile,'bus appr real min1 max1 min2 max2');
fclose(myfile);
data_voltagem = [(1:n-1)' ...
abs(u_appr) ...
results.bus(PQnodes,VM) ...
abs(u_appr)-margins(:,1) ...
abs(u_appr)+margins(:,1) ...
abs(u_appr)-margins(:,2) ...
abs(u_appr)+margins(:,2)];
save('-append', '-ascii', fname, 'data_voltagem');
errorfigures;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figno = 4;
disp('FIGURE 4: Voltage magnitude (spot 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);
u_true = results.bus(PQnodes,VM) .* exp(1j * results.bus(PQnodes,VA)/180*pi);
u_appr = 1 + X * conj(s);
figure(figno)
plot(1:(n-1), abs(u_true), 'ko ', 1:(n-1), abs(u_appr), 'k. ');
title('Voltage magnitude')
xlim([1 n-1]);
% check conditions of Theorem 1 for the existence of a practical solution
rho_2_star = max(arrayfun(@(idx) norm(X(idx,:),2), 1:size(X,1)));
fprintf(1,'X 2-star: %f\n', rho_2_star);
fprintf(1,'s 2-norm: %f\n', norm(s,2));
fprintf(1,'4 * ||X|| * ||s|| = %f <? 1\n\n', 4 * rho_2_star * norm(s,2));
% check if condition is verified with algebraic connectivity of L
eigL = sort(abs(eig(L)));
sigma2 = eigL(2);
fprintf(1,'sigma_2: %f\n', sigma2);
fprintf(1,'s 2-norm: %f\n', norm(s,2));
fprintf(1,'4 * ||s|| / sigma_2 = %f <? 1\n\n', 4 * norm(s,2) / sigma2);
% check if condition is verified with p=1, q=Inf norms
rho_Inf_star = max(max(abs(X)));
fprintf(1,'X Inf-star: %f\n', rho_Inf_star);
fprintf(1,'s 1-norm: %f\n', norm(s,1));
fprintf(1,'4 * ||X|| * ||s|| = %f <? 1\n\n', 4 * rho_Inf_star * norm(s,1));
% plot error bands for different p-norms
ps = [1 2];
nps = length(ps);
margins = zeros(n-1,nps);
hold on
for p = 1:nps
normq = arrayfun(@(idx) norm(X(idx,:),holder(ps(p))), 1:size(X,1));
margins(:,p) = 4 * normq * max(normq) * norm(s,ps(p))^2;
plot(1:(n-1), abs(u_appr)-margins(:,p), p, 1:(n-1), abs(u_appr)+margins(:,p), p);
text(n, abs(u_appr(end))-margins(end,p), num2str(ps(p)));
end
ylim([0.5 1.1])
% Save voltage magnitude data
fname = 'data_paper_voltagem_spotoverload.data';
myfile=fopen(fname,'w');
fprintf(myfile,'bus appr real min1 max1 min2 max2');
fclose(myfile);
data_voltagem = [(1:n-1)' ...
abs(u_appr) ...
results.bus(PQnodes,VM) ...
abs(u_appr)-margins(:,1) ...
abs(u_appr)+margins(:,1) ...
abs(u_appr)-margins(:,2) ...
abs(u_appr)+margins(:,2)];
save('-append', '-ascii', fname, 'data_voltagem');
errorfigures;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figno = 5;
disp('FIGURE 5: Voltage magnitude (PV bus)');
mpc = loadcase('case_ieee123');
PVbus = [15 51];
mpc.bus(PVbus,BUS_TYPE) = 2;
mpc.gen = [mpc.gen; ...
[ PVbus(1) 0 0 200 -200 1 1 1 200 -200 0 0 0 0 0 0 0 0 0 0 0 ] ; ...
[ PVbus(2) 0 0 200 -200 1 1 1 200 -200 0 0 0 0 0 0 0 0 0 0 0 ]];
mpc.gencost = [mpc.gencost; ...
[ 2 0 0 3 0.01 40 0 ]; ...
[ 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);
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 = 1 + X * conj(s);
figure(figno)
plot(1:(n-1), abs(u_true), 'ko ', 1:(n-1), abs(u_appr), 'k. ');
title('Voltage magnitude')
xlim([1 n-1]);
ylim([0.9 1.05])
% Save voltage magnitude data
fname = 'data_paper_voltagem_pvbus.data';
myfile=fopen(fname,'w');
fprintf(myfile,'bus appr real');
fclose(myfile);
data_voltagem = [(1:n-1)' ...
abs(u_appr) ...
results.bus(PQnodes,VM)];
save('-append', '-ascii', fname, 'data_voltagem');
errorfigures;