-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQit.m
203 lines (160 loc) · 5.63 KB
/
Qit.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
function [V,swingbus] = Qit(V,Ybus,Sbus,pv,pq,bus,Bpp,Vm,Va)
%Pit Performs 1P for a generator disturbance
% Input: complex voltage V vector, Ybus, Sbus, pv, pq, bus, Bpp,Vm,Va
% Outputs:complex voltage V vector, the swing bus
%--------------------------------------------------------------------------
% Set-Up Bpp Matrix Minus Swing Bus Minus PV Buses
%--------------------------------------------------------------------------
% Determines the Swing Bus
D = size(bus);
swingbus = -1;
for i=1:D(1)
if bus(i,2) == 3;
swingbus = bus(i,1);
else
end;
end;
% This section removes only the swing bus
bpprimematrixnoswing = zeros(8,8);
for i=1:9
for j = 1:9
if (i ~= swingbus & j ~= swingbus)
if (i < swingbus & j < swingbus)
bpprimematrixnoswing(i,j) = Bpp(i,j);
else
if (i > swingbus & j < swingbus)
bpprimematrixnoswing(i-1,j) = Bpp(i,j);
else
if (i < swingbus & j > swingbus)
bpprimematrixnoswing(i,j-1) = Bpp(i,j);
else
if (i > swingbus & j > swingbus)
bpprimematrixnoswing(i-1,j-1) = Bpp(i,j);
else
end;
end;
end;
end;
end;
end;
end;
% bpprimematrixnoswing holds the matrix with the swing bus removed
% This section removes the pv buses
D = size(pv); % Determines how many pv buses there are to remove..
pv2 = pv; % used for the loop down below
for k=1:D(1) % loops through the number of pv buses to eliminate them from the bpp matrix no swing
% this is needed to keep the generator pv index algined with the
% current bpprimematrixnoswing matrix index
for t=1:D(1)
if pv2(t) >= 2
pv2(t) = pv2(t)-1;
else
pv2(t) = 1;
end;
end;
D2 = size(bpprimematrixnoswing); % Determines the current dimensions of the bpp matrix minus swing and minus loop pv bus
bpprimematrixnoswing2 = zeros(D2(1)-1,D(2)-1); % creates a temporary matrix to store the new Bpp matrix minus loop pv minus swing
for i=1:D2(1) % for 1 to the size of the bpp matrix with the swing removed and current loop pv bus removed.
for j = 1:D2(1)
if (i ~= pv2(k) & j ~= pv2(k)) % pv(k) is the pv bus being removed from the Bpp matrix without the swing.
if (i < pv2(k) & j < pv2(k))
bpprimematrixnoswing2(i,j) = bpprimematrixnoswing(i,j);
else
if (i > pv2(k) & j < pv2(k))
bpprimematrixnoswing2(i-1,j) = bpprimematrixnoswing(i,j);
else
if (i < pv2(k) & j > pv2(k))
bpprimematrixnoswing2(i,j-1) = bpprimematrixnoswing(i,j);
else
if (i > pv2(k) & j > pv2(k))
bpprimematrixnoswing2(i-1,j-1) = bpprimematrixnoswing(i,j);
else
end;
end;
end;
end;
end;
end;
end;
bpprimematrixnoswing = bpprimematrixnoswing2; % assigns the reduced bpp matrix
end;
% Reduce the Va matrix for the swing bus
Vmtemp = zeros(8,1);
for i=1:9
if i < swingbus
Vmtemp(i,1) = Vm(i,1) ;
else
if i > swingbus
Vmtemp(i-1,1) = Vm(i,1);
else
end;
end;
end;
Vmtemp2 = Vmtemp;
% Reduces the Va matrix minus the swing for the pv buses
D = size(pv);
pv2 = pv;
for k=1:D(1) % loops for each bus
D2 = size(Vmtemp2);
Vmtemp3 = zeros(D2(1)-1,1);
% this is needed to keep the generator pv index algined with the
% current Va matrix index
for t=1:D(1)
if pv2(t) >= 2
pv2(t) = pv2(t)-1;
else
pv2(t) = 1;
end;
end;
for i=1:D2(1)
if i < pv2(k)
Vmtemp3(i,1) = Vmtemp2(i,1) ;
else
if i > pv2(k)
Vmtemp3(i-1,1) = Vmtemp2(i,1);
else
end;
end;
end;
Vmtemp2 = Vmtemp3;
end;
Vmtemp = Vmtemp2;
%-------------------------------------------------------------------------
% Compute the Reative Power MisMatch
%-------------------------------------------------------------------------
mis = V .* conj(Ybus * V) - Sbus;
delQ=-imag(mis(pq));
%-------------------------------------------------------------------------
% Computes the delVmag
%-------------------------------------------------------------------------
delVmag = bpprimematrixnoswing\(delQ./Vmtemp);
%-------------------------------------------------------------------------
% Augment the delVmag matrix for the swing bus and pv buses
%-------------------------------------------------------------------------
delVmag2 = zeros(9,1);
D = size(pv);
increment = 1;
for i=1:9
if i == swingbus
else
flag = 0; % determines if it is a pav bus to reconstruct
for k=1:D(1)
if pv(k) == i
flag = 1;
else
end
end
if flag == 1;
else
delVmag2(i) = delVmag(increment);
increment = increment + 1;
end
end
end;
delVmag = delVmag2;
%-------------------------------------------------------------------------
% Update Complex Voltage Values
%-------------------------------------------------------------------------
Vm = Vm + delVmag;
V = Vm .* exp(sqrt(-1) * Va); % This is the complex voltage
return;