-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_OLloadSchedule.m
85 lines (76 loc) · 2.83 KB
/
model_OLloadSchedule.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
% model_OLloadSchedule.m function m-file
% AUTHORS:
% Jeremy Simmons (email: [email protected])
% University of Minnesota
% Department of Mechanical Engineering
%
% CREATION DATE:
% 6/15/2022
%
% PURPOSE:
% This function implements three functions for the model predictive load
% scheduling algorithm based on the input "outputConfig".
% outputConfig:
% 1 - perform a simulation over the prediction horizon for the model
% predictive loadsensing algorithm and output the average power captured
% 2 - perform a simulation for a state update through the control update
% step
% 3 - evaluate constraints on the load schedule
% 4 - Simulate duing ramp period to obtain settled ICs
% The inputs include all variables to define a simulation and include a
% specified load schedule.
%
% FUNCTION M-FILES
%
% UPDATES
% 6/15/2022 - created.
%
% 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/>.
%
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = model_OLloadSchedule(t,y,Tbar,tp,par,outputConfig)
switch outputConfig
case {1 3}
% run simulation
switch outputConfig
case 1; tspan = [t,t+tp];
case 3; tspan = [t,t+par.dt_ctrl];
end
Tpto = @(tprime) Tpto_ramp(tprime-t,Tbar,par.dt_ctrl);
out = sim_OLloadSchedule(tspan,y,Tpto,par);
switch outputConfig
case 1; varargout = {mean(out.power.P_WEC)};
case 3; varargout = {out.y};
end
case 2
% constraints c <= 0, ceq = 0
% limit on rate of change in torque demand
N = length(Tbar) - 1;
c = zeros(N,1);
for n = 1:N
c(n) = abs(Tbar(n+1)-Tbar(n)) ...
- par.dTdt_max*par.dt_ctrl;
end
ceq = [];
varargout = {c,ceq};
case 4
% run simulation for initial condition following ramp period
tspan = par.tstart+[-par.Tramp,0]-par.TrampMPLS;
Tpto = @(tprime) Tpto_ramp(tprime-tspan(1),Tbar,par.dt_ctrl);
out = sim_OLloadSchedule(tspan,y,Tpto,par);
varargout = {out.y};
end
end