-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_loadSchedule.m
168 lines (142 loc) · 5.18 KB
/
test_loadSchedule.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
% test_loadSchedule.m script m-file
% AUTHORS:
% Jeremy Simmons (email: simmo536@umn.edu)
% University of Minnesota
% Department of Mechanical Engineering
%
% CREATION DATE:
% 06/14/2022
%
% PURPOSE/DESCRIPTION:
% This script was used in developing and testing the a model predicitve
% load scheduling algorithm.
%
% FILE DEPENDENCY:
% sim_coulombPTO_V02x00.m
% parameters_coulombPTO_V01x00.m
%
% UPDATES:
% 06/14/2022 - (V01x00) - Created from studyPTO_V02x03 found in the 2021Q2
% pipeline modeling project folder.
%
% Copyright (C) 2022 Jeremy W. Simmons II
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <https://www.gnu.org/licenses/>.
%
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear
clc
path_models = ['.' filesep 'Modeling'];
addpath([path_models filesep 'Sea States'])
addpath([path_models filesep 'Solvers'])
addpath([path_models filesep 'WEC model'])
addpath([path_models filesep 'WEC model' filesep 'WECdata'])
addpath([path_models filesep 'Open-loop load schedule PTO'])
%% %%%%%%%%%%%% SIMULATION PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Simulation Parameters
par.Tramp = 250; % [s] excitation force ramp period
par.tstart = 0; %[s] start time of simulation
par.tend = 100; %[s] end time of simulation
par.odeSolverRelTol = 1e-9; % Rel. error tolerance parameter for ODE solver
par.odeSolverAbsTol = 1e-9; % Abs. error tolerance parameter for ODE solver
par.MaxStep = 1e-2;
par.wave.rngSeedPhase = 3; % set the seed for the random number generator
% set the number of frequency components used to calculate the wave
% elevation and excitation force using harmonic superposition
par.WEC.nw = 100;
%% %%%%%%%%%%%% COLLECT DATA %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Tp = [7.31 9.86 11.52 12.71 15.23 16.50];
% Hs = [2.34 2.64 5.36 2.05 5.84 3.25];
load('SSdata_HumboltBay_1D.mat')
nSS = length(Tp);
nVar1 = 1;
Tcoulomb = 1e6;%1e6*logspace(log10(0.1),log10(20),nVar1);% [Nm] PTO reaction torque
saveSimData = 1;
for iSS = 7%:nSS
par.wave.Hs = Hs(iSS);
par.wave.Tp = Tp(iSS);
% load parameters
par = parameters_OLloadSchedule(par,...
'nemohResults_vantHoff2009_20180802.mat','vantHoffTFCoeff.mat');
for iVar1 = 1:nVar1
param = par;
%% test model_OLloadSchedule.m
if 0
% define start and end times
tstart = param.tstart;
tend = param.tend;
tspan = [tstart; tend];
% Define intial conditions pre-ramp
y0 = [ 0, ...
0, ...
zeros(1,param.WEC.ny_rad)];
param.dt_ctrl = 2;
param.T_max = Tcoulomb(iVar1);
param.dTdt_max = param.T_max/5;
Tbar = Tcoulomb(iVar1)*ones(10,1);
tc = param.dt_ctrl*length(Tbar); % control horizon
tp = tend - tstart; % prediction horizon
tic
PPmean = model_OLloadSchedule(tstart,y0,Tbar,[tc tp],param,1);
toc
tic
[c, ceq] = model_OLloadSchedule(tstart,y0,Tbar,[tc tp],param,2);
toc
tic
yend = model_OLloadSchedule(tstart,y0,Tbar,[tc tp],param,3);
toc
end
%% test sim_OLloadSchedule with constant
if 0
% define anonymous function for open-loop load control
Tpto = @(t) Tcoulomb(iVar1);
% run simulation
tic
out = sim_OLloadSchedule(tspan,y0,Tpto,param);
toc
% Post-process
PPmean(iSS,iVar1) = mean(out.power.P_WEC);%mean(out.theta_dot.*out.T_pto);
if saveSimData
simOut(iSS,iVar1) = out;
end
end
%% test modelPredictiveLoadScheduling.m
if 1
% Load control parameters
lbFrac = 0.25;
param.T_max = Tcoulomb(iVar1);
param.dTdt_max = 1e6;
param.T_min = param.T_max*lbFrac; % [Nm] min PTO reaction torque
% Model predictive control parameters
param.dt_ctrl = 2; % interval between control updates
param.MPLS.tc = 10; % control horizon
param.MPLS.tp = param.MPLS.tc + 1.5*param.dt_ctrl; % prediction horizon
% Define intial conditions pre-ramp
y0 = [ 0, ...
0, ...
zeros(1,param.WEC.ny_rad)];
% Update initial conditions post-ramp
Tpto = 0.5*(param.T_max+param.T_min);
temp = model_OLloadSchedule([],y0,Tpto,[],param,4);
y0 = temp(end,:); clearvars temp
% Run MPLS
ticMPLS = tic;
[tMPLS,Tpto] = modelPredictiveLoadScheduling(y0,param);
toc(ticMPLS)
figure; plot(tMPLS,Tpto)
end
end
end
% save('data_coulombPTO_dampingStudy_20220601.mat')
return