-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFC4_Combined_Driver.m
232 lines (202 loc) · 6.34 KB
/
FC4_Combined_Driver.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
% FC4 - SS_Model_Driver
close all; clear all; clc
%% Load in Simulation or Test Data
load('Test_Results.mat','test_results');
load('OpenFAST_Results.mat','sim_results');
% test_results = sim_results;
%% Prepare Time Vector
% Extract time vector
test_time = test_results.Time;
sim_time = sim_results.Time;
% Smooth time vector
if exist("test_time","var")
dt = mean(diff(test_time));
test_time = linspace(min(test_time),max(test_time),length(test_time))';
end
% Prepare to shift wind input
if exist("test_time","var")
dt = max(test_time)/length(test_time);
causality_shift_index = floor(29.95/dt);
else
dt = max(sim_time)/length(sim_time);
causality_shift_index = floor(29.95/dt);
end
%% Prepare Wave Input
% From Experiment
eta = test_results.Wave1Elev;
% eta = sim_results.Wave1Elev;
%% Prepare wind input
% Wind Case
wind_case = 3;
% Load in appropriate wind file
switch wind_case
case 0 % No wind
if exist("test_time","var")
wind = zeros(size(test_time));
else
wind = zeros(size(sim_time));
end
rotor_lock = true;
case 1 % W01 - Below Rated
wind = readmatrix('C:\Umaine Google Sync\Masters Working Folder\FOCAL_C2\Models\FOCAL_C4\Wind\W01_fullScale_20230505.wnd');
if exist("test_time","var")
wind = pchip(wind(:,1),wind(:,2),test_time);
else
wind = pchip(wind(:,1),wind(:,2),sim_time);
end
rotor_lock = false;
case 2 % W02 - Rated
wind = readmatrix('C:\Umaine Google Sync\Masters Working Folder\FOCAL_C2\Models\FOCAL_C4\Wind\W02_fullScale_R02_20230606.wnd','FileType','text');
if exist("test_time","var")
wind = pchip(wind(:,1),wind(:,2),test_time);
else
wind = pchip(wind(:,1),wind(:,2),sim_time);
end
rotor_lock = false;
case 3 % W03 - Above Rated
wind = readmatrix('C:\Umaine Google Sync\Masters Working Folder\FOCAL_C2\Models\FOCAL_C4\Wind\W03_fullScale_R02_20230613.wnd','FileType','text');
if exist("test_time","var")
wind = pchip(wind(:,1),wind(:,2),test_time);
else
wind = pchip(wind(:,1),wind(:,2),sim_time);
end
rotor_lock = false;
case 4 % Step Wind
wind = readmatrix("C:\Umaine Google Sync\Masters Working Folder\FOCAL_C2\Models\FOCAL_Base\Wind\Step_Wind_N10_U1_T750.wnd",'FileType','text');
if exist("test_time","var")
wind = pchip(wind(:,1),wind(:,2),test_time);
else
wind = pchip(wind(:,1),wind(:,2),sim_time);
end
rotor_lock = false;
end
% Time-shift wind to account for hydro causalization time
% wind = [zeros(causality_shift_index,1);
% wind(1:end-causality_shift_index)];
%% Prepare Control Input Values
% Blade pitch command (collective)
try
c_pitch = test_results.pitch1Position*(pi/180);
catch
c_pitch = sim_results.BldPitch1*(pi/180);
disp('Using OpenFAST blade pitch values.');
end
% Generator torque command
try
gen_torque = test_results.genTorqueSetpointActual;
catch
gen_torque = sim_results.GenTq*10^3;
disp('Using OpenFAST generator torque values.')
end
%% Form Input Vector
sim_inputs = [wind,gen_torque,c_pitch,eta];
%% Load in SS Model & Remove Azimuth State
% Define Path
platform_dir = 'C:\Umaine Google Sync\GitHub\FOWT_Optimal_Control\Models\FOCAL_C4\Linear_Files\3 - Combined Model';
% Load in raw files
load(sprintf('%s\\FOCAL_C4_A.mat',platform_dir),'A');
load(sprintf('%s\\FOCAL_C4_B.mat',platform_dir),'B');
load(sprintf('%s\\FOCAL_C4_C.mat',platform_dir),'C');
load(sprintf('%s\\FOCAL_C4_D.mat',platform_dir),'D');
load(sprintf('%s\\FOCAL_C4_y_OP.mat',platform_dir));
% Remove rotor azimuth state from state vector
A = A([1:8,10:end],[1:8,10:end]);
B = B([1:8,10:end],[1,8,9,94]);
C = C(:,[1:8,10:end]);
D = 0*D(:,[1,8,9,94]);
% Discretize Platform
platform_sys_c = ss(A,B,C,D);
platform_sys_d = c2d(platform_sys_c,dt,'zoh');
% [A_platform,B_platform,C_platform,D_platform] = ssdata(platform_sys_d);
% Reduce model size
R = reducespec(platform_sys_d,"modal");
% view(R)
rsys = getrom(R,Frequency=[0.05,1],Damping=[0,0.4]);
platform_sys_d = rsys;
% Clear out A,B,C,D matrices
clear A B C D platform_sys_c
%% Perform Simulation
if exist("test_time","var")
Y = lsim(platform_sys_d,sim_inputs,test_time);
ss_time = [test_time;0];
else
Y = lsim(platform_sys_d,sim_inputs,sim_time);
ss_time = sim_time;
end
Y = Y + y_OP';
%% Plot Results
% Plot parameters
tmax = 7500;
% Plot Platform Surge
figure
% subplot(4,1,2)
gca; hold on; box on;
title('Platform Surge')
xlim([0,tmax])
plot(ss_time(1:end-1)-29.95,Y(:,18),'DisplayName','State-Space')
plot(sim_time,sim_results.PtfmSurge,'DisplayName','OpenFAST')
try
plot(test_time,test_results.PtfmSurge,'DisplayName','Experiment')
end
legend
% Plot Platform Heave
figure
% subplot(4,1,1)
gca; hold on; box on;
xlim([0,tmax])
title('Platform Heave [m]')
plot(ss_time(1:end-1)-29.95,Y(:,20),'DisplayName','State-Space');
plot(sim_time,sim_results.PtfmHeave,'DisplayName','OpenFAST')
try
plot(test_time,test_results.PtfmHeave,'DisplayName','Experiment')
end
legend
% Plot Platform Pitch
figure
% subplot(4,1,1)
gca; hold on; box on;
xlim([0,tmax])
title('Platform Pitch [deg]')
plot(ss_time(1:end-1)-29.95,Y(:,22),'DisplayName','State-Space');
plot(sim_time,sim_results.PtfmPitch,'DisplayName','OpenFAST')
try
plot(test_time,test_results.PtfmPitch,'DisplayName','Experiment')
end
legend
% Plot rotor speed
figure
% subplot(4,1,3)
gca; hold on; box on;
xlim([0,tmax])
title('Rotor Speed [RPM]')
% xlim([0 500])
plot(ss_time(1:end-1)-29.95,Y(:,9),'DisplayName','State-Space');
plot(sim_time,sim_results.RotSpeed,'DisplayName','OpenFAST')
try
plot(test_time,(test_results.genSpeed*(30/pi)),'DisplayName','Experiment');
end
legend
% Plot tower bending
figure
gca; hold on; box on;
xlim([0,tmax]);
title('Tower Base Bending Moment')
plot(ss_time(1:end-1)-29.95,Y(:,13),'DisplayName','State-Space');
plot(test_time,test_results.towerBotMy*10^-3,'DisplayName','Experiment')
legend
% % Plot wave elevation
% figure
% % subplot(4,1,3)
% gca; hold on; box on;
% xlim([0,tmax])
% title('Wave Elevation [m]')
% plot(test_results.Time,test_results.Wave1Elev)
%
% % Plot Wind Speed
% figure
% % subplot(4,1,4)
% gca; hold on; box on;
% plot(test_results.Time,test_results.WindCal,'DisplayName','Experiment')
% title('Wind Speed [m/s]')
% xlabel('Time [s]')
% legend