-
Notifications
You must be signed in to change notification settings - Fork 0
/
Recorder.m
183 lines (163 loc) · 9.07 KB
/
Recorder.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
classdef Recorder < handle
%Recorder: stores the state trajectories and plots them
%This class can store state trajectories, convert them to i.e. voltage
%or current trajectories and plot them according to the wishes.
properties
x_save
v_limit_reached
i_limit_reached
f_limit_reached
p_g_limit_reached
q_g_limit_reached
f_function_save
h_function_save
iteration = 0
transient_length = 100
start_disp = 1
m
n
node_legend
line_legend
end
methods
function obj = Recorder(mystate,f_function,h_function, iterations)
x = mystate.getx();
obj.m = length(mystate.i)/2;
obj.n = length(mystate.v);
obj.x_save = [x,zeros(length(x),iterations)];
obj.f_function_save = [f_function,zeros(1,iterations)];
obj.h_function_save = [h_function,zeros(1,iterations)];
assert(obj.transient_length >= 1);
assert(5*obj.n + 2*obj.m + 1 == length(x));
obj.v_limit_reached = false(length(x),iterations);
obj.i_limit_reached = false(length(x),iterations);
obj.f_limit_reached = false(length(x),iterations);
obj.p_g_limit_reached = false(length(x),iterations);
obj.q_g_limit_reached = false(length(x),iterations);
for i=1:obj.n
obj.node_legend{i} = ['Node ', num2str(i)];
end
for i=1:obj.m
obj.line_legend{i} = ['Line ', num2str(i)];
obj.line_legend{i+obj.m} = ['Line (opp. dir.)', num2str(i)];
end
end
function store(obj, mystate, f_function, h_function)
obj.f_function_save(:,obj.iteration) = f_function;
obj.h_function_save(:,obj.iteration) = h_function;
obj.x_save(:,obj.iteration) = mystate.getx();
obj.start_disp = min(obj.transient_length, obj.iteration);
end
function count(obj)
obj.iteration = obj.iteration + 1;
end
function store_limits(obj, mystate, mygrid)
obj.v_limit_reached(:,obj.iteration) = logical(Controller.v_limit_reached(mystate, mygrid));
obj.i_limit_reached(:,obj.iteration) = logical(Controller.i_limit_reached(mystate, mygrid));
obj.f_limit_reached(:,obj.iteration) = logical(Controller.f_limit_reached(mystate, mygrid));
obj.p_g_limit_reached(:,obj.iteration) = logical(Controller.S_limit_reached(mystate, mygrid));
obj.q_g_limit_reached(:,obj.iteration) = logical(Controller.S_limit_reached(mystate, mygrid));
end
function plotV(obj)
figure(1);
plot(gca, obj.x_save(1:obj.n,1:obj.iteration)');
ylabel(gca,'Voltage [p.u.]');
xlabel(gca,'Iterations');
end
function plotAll(obj)
f2 = figure(2);
clf
f2.Position = [0 0 1900 1000];
mp = 2;
np = 4;
m = obj.m;
n = obj.n;
v = subplot(mp,np,1);
i = subplot(mp,np,2);
f = subplot(mp,np,3);
p_g = subplot(mp,np,5);
q_g = subplot(mp,np,6);
p_ref = subplot(mp,np,7);
f_function = subplot(mp,np,4);
h_function = subplot(mp,np,8);
hold(v,'on')
plot(v,obj.x_save(1:obj.n,obj.start_disp:obj.iteration)');
for k=1:obj.n
x_values = 1:(obj.iteration - (obj.start_disp - 1)); %shift the index according to the
x_values = x_values(obj.v_limit_reached(k,obj.start_disp:obj.iteration)); %take out all the points where the limit was not reached
y_values = obj.x_save(k,obj.start_disp:obj.iteration); %trim the voltage values down to the desired length
y_values = y_values(obj.v_limit_reached(k,obj.start_disp:obj.iteration)); %take out all the points where the limit was not reached
plot(v,x_values,y_values,'xr','LineWidth',2);
end
ylabel(v,'v: Voltage amplitude [p.u.]');
xlabel(v,'Iterations');
legend(v,obj.node_legend);
hold(v,'off')
hold(i,'on')
plot(i, obj.x_save(5*n+1:5*n+2*m,obj.start_disp:obj.iteration)');
for k=(5*n+1):(5*n+2*m)
x_values = 1:(obj.iteration - (obj.start_disp - 1)); %shift the index according to the
x_values = x_values(obj.i_limit_reached(k,obj.start_disp:obj.iteration)); %take out all the points where the limit was not reached
y_values = obj.x_save(k,obj.start_disp:obj.iteration); %trim the voltage values down to the desired length
y_values = y_values(obj.i_limit_reached(k,obj.start_disp:obj.iteration)); %take out all the points where the limit was not reached
plot(i,x_values,y_values,'xr','LineWidth',2);
end
ylabel(i,'i: Current amplitude [p.u.]');
xlabel(i,'Iterations');
legend(i,obj.line_legend);
hold(i,'off')
hold(f,'on')
plot(f, obj.x_save(end,obj.start_disp:obj.iteration)');
for k=(5*n+2*m+1):(5*n+2*m+1)
x_values = 1:(obj.iteration - (obj.start_disp - 1)); %shift the index according to the
x_values = x_values(obj.f_limit_reached(k,obj.start_disp:obj.iteration)); %take out all the points where the limit was not reached
y_values = obj.x_save(k,obj.start_disp:obj.iteration); %trim the voltage values down to the desired length
y_values = y_values(obj.f_limit_reached(k,obj.start_disp:obj.iteration)); %take out all the points where the limit was not reached
plot(f,x_values,y_values,'xr','LineWidth',2);
end
ylabel(f,'f: Frequency deviation [Hz]');
xlabel(f,'Iterations');
hold(f,'off')
hold(p_g,'on')
plot(p_g, obj.x_save(2*n+1:3*n,obj.start_disp:obj.iteration)');
p_g.ColorOrderIndex = 1;
plot(p_g, obj.x_save(4*n+1:5*n,obj.start_disp:obj.iteration)','--');
for k=(2*n+1):(3*n)
x_values = 1:(obj.iteration - (obj.start_disp - 1)); %shift the index according to the
x_values = x_values(obj.p_g_limit_reached(k,obj.start_disp:obj.iteration)); %take out all the points where the limit was not reached
y_values = obj.x_save(k,obj.start_disp:obj.iteration); %trim the voltage values down to the desired length
y_values = y_values(obj.p_g_limit_reached(k,obj.start_disp:obj.iteration)); %take out all the points where the limit was not reached
plot(p_g,x_values,y_values,'xr','LineWidth',2);
end
ylabel(p_g,'p_g: Active Power generated [p.u]');
xlabel(p_g,'Iterations');
legend(p_g,obj.node_legend);
hold(p_g,'off')
hold(q_g,'on')
plot(q_g, obj.x_save(3*n+1:4*n,obj.start_disp:obj.iteration)');
for k=(3*n+1):(4*n)
x_values = 1:(obj.iteration - (obj.start_disp - 1)); %shift the index according to the
x_values = x_values(obj.q_g_limit_reached(k,obj.start_disp:obj.iteration)); %take out all the points where the limit was not reached
y_values = obj.x_save(k,obj.start_disp:obj.iteration); %trim the voltage values down to the desired length
y_values = y_values(obj.q_g_limit_reached(k,obj.start_disp:obj.iteration)); %take out all the points where the limit was not reached
plot(q_g,x_values,y_values,'xr','LineWidth',2);
end
ylabel(q_g,'q_g: Reactive Power generated [p.u]');
xlabel(q_g,'Iterations');
legend(q_g,obj.node_legend);
hold(q_g,'off')
plot(p_ref, obj.x_save(4*n+1:5*n,obj.start_disp:obj.iteration)');
ylabel(p_ref,'p_{ref}: Reference value for prim. frequency controller [p.u]');
xlabel(p_ref,'Iterations');
legend(p_ref,obj.node_legend);
plot(f_function, obj.f_function_save(:,obj.start_disp:obj.iteration)');
ylabel(f_function,'f(x): cost function value');
xlabel(f_function,'Iterations');
plot(h_function, obj.h_function_save(:,obj.start_disp:obj.iteration)');
ylabel(h_function,'h(x): staying in the physical valid space');
xlabel(h_function,'Iterations');
%figure(1)
%plot(sum(obj.x_save(3*n+1:4*n,obj.start_disp:obj.iteration)))
end
end
end