-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFOCAL_C2_3_Any_Sim_Plotter.m
203 lines (166 loc) · 6.19 KB
/
FOCAL_C2_3_Any_Sim_Plotter.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
%% Plot SS Results Against Full Simulation Results
close all; clear all; clc;
% Define time offset if .ssexctn files used
tc = struct();
tc.OpenFAST = 0;
tc.Simulink = 29.975;
tc.Experiment = 0;
tc.Observer = 29.975;
%% --------------- User Inputs ---------------- %%
% Comparison flag (1: OpenFAST | 2: Simulink | 3: Experimental | 4: Simulink Observer)
type = [1,3,4];
plot_mark = {'none','none','none'};
xrange = [4625,4700];
% xrange = [240 450];
% Descriptions
desc = {'OpenFAST';
'StateSpace';
'Experiment';
'Kalman'};
color = {"#0072BD";
"#D95319";
[0.3,0.3,0.3];
"#7E2F8E"};
style = {'-';
'-';
'--';
'-'};
width = [1,1,1,1.25];
% vars = {'Wave1Elev'};
units = {'deg','kN','m'};
vars = {'PtfmPitch','TwrBsMyt','PtfmHeave'};
% vars = {'TwrBsMyt'};
% vars = {'PtfmSurge','PtfmSway','PtfmHeave','PtfmRoll','PtfmPitch','PtfmYaw'}; %,'TTDspFA','TTDspSS','GenSpeed'}
% % vars = {'PtfmHeave','Wave1Elev'}
% % vars = {'TwrBsFxt','TwrBsFyt','TwrBsFzt','TwrBsMxt','TwrBsMyt','TwrBsMzt'}
% units = {'deg','N','m'}
for i = 1:length(type)
t = type(i);
switch t
case 1 % OpenFAST Non-Linear Simulation Results
load('OpenFAST_Results.mat');
sim_results.Time = sim_results.Time-tc.OpenFAST;
sim_results = renameStructField(sim_results,'T_1_','FAIRTEN1');
sim_results = renameStructField(sim_results,'T_2_','FAIRTEN2');
sim_results = renameStructField(sim_results,'T_3_','FAIRTEN3');
full_results{i} = sim_results;
clear sim_results;
case 2 % Simulink State Space Simulation
load('Simulink_Results.mat');
slx_results.Time = slx_results.Time-tc.Simulink;
slx_results = renameStructField(slx_results,'T1','FAIRTEN1');
slx_results = renameStructField(slx_results,'T2','FAIRTEN2');
slx_results = renameStructField(slx_results,'T3','FAIRTEN3');
full_results{i} = slx_results;
clear slx_results;
case 3 % Experimental Results
load('Test_Results.mat')
test_results.Time = test_results.Time - tc.Experiment;
test_results = renameStructField(test_results,'T_1_','FAIRTEN1');
test_results = renameStructField(test_results,'HSShftV','GenSpeed');
test_results = renameStructField(test_results,'T_2_','FAIRTEN2');
test_results = renameStructField(test_results,'T_3_','FAIRTEN3');
test_results = renameStructField(test_results,'TwrBsAx','PtfmTAxt');
test_results = renameStructField(test_results,'TwrBsAz','PtfmTAzt');
% test_results.GenSpeed = test_results.GenSpeed*9.4
% test_results.TwrBsMxt = test_results.TwrBsMxt*10^-3;
test_results.TwrBsMyt = test_results.TwrBsMyt*10^-3;
% test_results.TwrBsMzt = test_results.TwrBsMzt*10^-3;
% test_results.TwrBsFxt = test_results.TwrBsFxt*10^-3;
% test_results.TwrBsFyt = test_results.TwrBsFyt*10^-3;
% test_results.TwrBsFzt = test_results.TwrBsFzt*10^-3;
full_results{i} = test_results;
clear test_results
% case 4 % Simulink with Observer
% load('SimulinkObserver_Results.mat');
% slx_obs_results.Time = slx_obs_results.Time - tc.Observer
%
% slx_obs_results = renameStructField(slx_obs_results,'T1','FAIRTEN1');
% slx_obs_results = renameStructField(slx_obs_results,'T2','FAIRTEN2');
% slx_obs_results = renameStructField(slx_obs_results,'T3','FAIRTEN3');
% % slx_obs_results.TwrBsMyt = lowpass(slx_obs_results.TwrBsMyt,0.16,24);
% full_results{i} = slx_obs_results;
% clear slx_obs_results
case 4
load('Kalman_Results.mat','kalman_results');
kalman_results.Time = kalman_results.Time-tc.Observer;
full_results{i} = kalman_results;
clear kalman_results;
end
end
% % Scale the experimental results
% exp_res = full_results{2};
% t = exp_res.Time;
% tmax_old = max(t);
% tmax_new = tmax_old*1;
% dt = max(t)/length(t);
% tnew = linspace(0,tmax_new,length(t))';
% exp_res.Time = tnew;
% full_results{2} = exp_res;
% Variable to plot
for i = 1:length(type)
plotvar.(desc{type(i)}).Time = full_results{i}.Time;
for j = 1:length(vars)
try
vals = full_results{i}.(vars{j});
vals = rMean(vals);
% vals = vals - mean(vals(1:10));
plotvar.(desc{type(i)}).(vars{j}) = vals;
catch
fprintf('Could not store %s: Result not present in %s results! \n',vars{j},desc{type(i)});
end
end
end
%% -------------- Do Plotting --------------- %%
for i = 1:length(vars)
figure('Name',sprintf('Model Comparison | %s',vars{i}))
ax = gca; box on; hold on;
xlim(xrange)
xlabel('Time [s]');
try
title(sprintf('%s [%s]',vars{i},units{i}));
end
for j = 1:length(type)
try
plot(plotvar.(desc{type(j)}).Time,plotvar.(desc{type(j)}).(vars{i}),...
'DisplayName',desc{type(j)},'Color',color{type(j)},'LineStyle',style{type(j)},...
'LineWidth',width(type(j)));
catch
fprintf('Could not plot %s: Result not present in %s results! \n',vars{i},desc{type(j)});
end
end
legend('Location','northwest')
end
% figure('Name','SS to Simulation Comparison')
% num_plot = 3;
% for k = 1:num_plot
% subplot(num_plot,1,k)
% ax = gca; box on; hold on;
% xlabel('Time [s]')
% xlim(xrange);
% title(varnames{k})
%
% switch k
% case 1
% for i = 1:length(type)
% plot(time{i},var1{i},'DisplayName',desc{i});
% end
%
% case 2
% for i = 1:length(type)
% plot(time{i},var2{i},'DisplayName',desc{i});
% end
%
% case 3
% for i = 1:length(type)
% plot(time{i},var3{i},'DisplayName',desc{i});
% end
%
% case 4
% for i = 1:length(type)
% plot(time{i},var4{i},'DisplayName',desc{i});
% end
% end
%
% legend
% end