-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreateLUTwFLORIDyn.m
More file actions
92 lines (67 loc) · 2.85 KB
/
Copy pathcreateLUTwFLORIDyn.m
File metadata and controls
92 lines (67 loc) · 2.85 KB
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
% Copyright (C) <2024>, M Becker
%
% List of the contributors to the development of FLORIDyn: see LICENSE file.
% Description and complete License: see LICENSE file.
% This program (FLORIDyn) is free software: you can redistribute it and/or modify
% it under the terms of the GNU Affero 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 Affero General Public License for more details.
% You should have received a copy of the GNU Affero General Public License
% along with this program (see COPYING file). If not, see <https://www.gnu.org/licenses/>.
% ======================================================================= %
% Updated: 16. Dez. 2024, M. Becker
% ======================================================================= %
%% Create a Steady state LUT with FLORIDyn
function lut = createLUTwFLORIDyn(Dirs, pathToSimulation)
% Load data from the simulation
% Reset the Matlab Path and load essential paths & the simulation path
addPaths;
% Get the settings for the wind field, visualization, controller and Sim.
[Wind, Vis, Sim, Con] = setup();
%Sim.EndTime = Overwrite_EndTime; % <- Reclict from NAWEA 2023 runs
% Add according functions to the search path
addFLORISPaths;
addFLORIDynPaths;
% Load linked data
turbProp = turbineArrayProperties();
paramFLORIS = parameterFLORIS();
paramFLORIDyn = parameterFLORIDyn();
% Preprocess loaded data
[T, Wind, Sim, Con, paramFLORIS, Vis] = ...
prepareSimulation(Wind,Con,paramFLORIDyn,paramFLORIS,turbProp,Sim,Vis);
clear turbProp
lut = zeros(length(Dirs),T.nT);
for iDir = 1:length(Dirs)
lb = Dirs(iDir) - 30;
ub = Dirs(iDir) + 30;
tic
f =@(x) cost_function_wrapper(x, Dirs(iDir), ...
T, Wind, Sim, Con, paramFLORIDyn, paramFLORIS, Vis);
% Optimize
options = optimoptions('particleswarm',...
'SwarmSize',100,...
'MaxIterations',40,...
'UseParallel',true,...
'Display','iter');
x = particleswarm(f,T.nT,...
ones(T.nT,1).*lb,...
ones(T.nT,1).*ub,options);
disp(['Total opt. time: ' num2str(toc) ' s.'])
disp(round(x,1))
lut(iDir,:) = round(x,1);
end
end
function J = cost_function_wrapper(yaw, dir, T, Wind, Sim, Con, ...
paramFLORIDyn, paramFLORIS, Vis)
Wind.Dir = [0, dir; 1000000, dir];
Con.YawData = [0, yaw(:)'; 1000000, yaw(:)'];
% ====== Init simulation
% Run initial conditions until no more change happens
T = initSimulation(T,Wind,Sim,Con,Vis,paramFLORIDyn,paramFLORIS);
[T,M,~,~] = FLORIDynCL(T,Wind,Sim,Con,Vis,paramFLORIDyn,paramFLORIS);
J = - sum(M.("Power generated [MW]")(end-T.nT+1:end));
end