Skip to content

Commit

Permalink
Include MATLAB processing scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhar-abbas committed Sep 27, 2019
1 parent 02a9f93 commit 0aff18e
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 0 deletions.
94 changes: 94 additions & 0 deletions Matlab_Toolbox/Pl_FastPlots.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
function Pl_FastPlots(varargin)
% This function plots outputs from openfast simulations. There is an
% attempt to organize the created plots into some sort of
% categories.
%
% Inputs: varargin - Some number of structures, should be created from
% Post_LoadFastOut.m, or output from a simulink run.
% Each structure will be plotted on top of the previous
% one.
%
% Nikhar Abbas - February 2019




%% Cases to plot
% Switches to turn on/off some categories of plots. Cases are defined in
% the next section
plsw.MI = 0; % MI, Main Inputs
plsw.DTO = 0; % DTO, Drivetrain Outputs
plsw.B1 = 1; % B1, Baseline1
plsw.PD = 1; % PD, Primary Dynamics
plsw.RO = 1; % RO, Rotor Performance Outputs
plsw.Fl1 = 0; % Fl1, Basic Floating Parameters
plsw.AF = 0; % All Floating Parameters
plsw.Twr = 0; % Twr, Turbine params with Twr Motions
plsw.Rand = 0; % Some random metrics I care about now
cases = fieldnames(plsw);

%% Plot Cases
% Everything defined here should have a switch above
pc.MI = {'Wind1VelX', 'BldPitch1', 'GenTq'};
pc.DTO = {'GenPwr', 'RotSpeed', 'GenSpeed'};
pc.B1 = {'Wind1VelX', 'BldPitch1', 'GenTq', 'RotSpeed', 'GenPwr'};
pc.PD = {'BldPitch1', 'GenTq', 'GenSpeed'};
pc.RO = {'RtTSR','RtAeroCp'};
pc.Fl1 = {'PtfmPitch', 'BldPitch1'};
pc.AF = {'PtfmPitch', 'PtfmRoll', 'PtfmSurge', 'PtfmYaw', 'PtfmHeave', 'PtfmSway'};
pc.Twr = {'GenTq','BldPitch1','RotSpeed', 'TwrBsFxt'};
pc.Rand = {'RtAeroCt', 'TwrBsFxt', 'GenPwr'};

%% load outdata to be plotted
for args = 1:length(varargin)
outdata(args) = varargin(args); % load data
end


% Plot!
for dind = 1:length(outdata)
fo = outdata{dind};

time = fo.Time;

fignum = 100;
for cind = 1:length(cases)
if plsw.(cases{cind})
pcats = pc.(cases{cind}); % Categories to plot
subsize = length(pcats);

for plind = 1:length(pcats)
fig = figure(fignum); hold on % Create figure
subplot(subsize,1,plind)
try
% plot data
pdata = fo.(pcats{plind}); % data to plot
pl = plot(time,pdata);
ylabel(pcats{plind})

if strcmp(pcats{plind},'BldPitch1')
ylim([-5, 45]);
elseif strcmp(pcats{plind},'RtAeroCp')
ylim([0 0.6]);
end

grid on
pl.LineWidth = 1.5;

if plind == subsize
xlabel('Time')
end
catch
disp([pcats{plind} ' was not available in the OutList'])
end

end
fignum = fignum+1;
end
end
end




end
55 changes: 55 additions & 0 deletions Matlab_Toolbox/Post_LoadFastOut.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
function fastout = Post_LoadFastOut(FAST_OutFile)
% Load Model Output from a *.out file
% Loads OpenFast model output into a MATLAB structure to be post processed
%
%
% Inputs: FAST_OutFile - *.out file from an openfast run
% Outputs: fastout - data structure containing output data
%
% Nikhar Abbas

fid = fopen(FAST_OutFile, 'r');
if fid == -1, error('Error loading file'), end

% Define Headers
n_rec = 0; % record keeper to keep while loop running until the header line has been found
ind = 0;
while n_rec == 0
ind = ind+1;
tline = fgetl(fid);
w_str = strtrim(tline);
w_str = strsplit(w_str);
if strcmpi(w_str{1},'time')
n_rec = 1;
headers = w_str; % define headers

tline = fgetl(fid);
check = strtrim(tline);
if check(1) == '(' % find units line
units = strtrim(tline);
units = strsplit(units); % define units
ind = ind+1; % index headerlines
end
end
end

frewind(fid)

dstr = cell(1,length(headers)); %load data
dstr(:) = {'%f '};

dat = textscan(fid, strjoin(dstr), 'headerlines',ind);

%Put data in structure
fastout.headers = headers;
fastout.units = units;
for i = 1:length(headers)
try
fastout.(headers{i}) = dat{i};
catch
warning(['Outlist Parameter ' headers{i} ' was not loaded from the fast.out file.'])
end
end

fclose(fid);
end
57 changes: 57 additions & 0 deletions Matlab_Toolbox/Post_TestCases.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
% Post_TestCases.m
% Script to load and plot data from test cases in the WTC_Toolbox

%% Define and load test cases

% Define test case names (lan
testcases = { '5MW_Step_Legacy';...
'5MW_Step_Baseline';...
'5MW_BR_Legacy';...
'5MW_BR_Baseline';...
'5MW_NR_Legacy';...
'5MW_NR_Baseline';...
'5MW_AR_Legacy';...
'5MW_AR_Baseline';...
'5MW_OC4_ARsteady_Legacy';...
'5MW_OC4_ARsteady_Baseline';...
};


% Load OpenFAST output data
for i = 1:length(testcases)
% Define filepaths
fastdir = ['../Test_Cases/',testcases{i}];
infilename = dir([fastdir filesep '*.fst']);
outfilename = [infilename.name(1:end-3) 'out'];
outfile = [fastdir filesep,outfilename];

% Load to data structure
if strcmp(testcases{i}(1:3),'5MW')
fo.(testcases{i}(5:end)) = Post_LoadFastOut(outfile);
else
fo.(testcases{i}) = Post_LoadFastOut(outfile);
end
end


%% Plot Data
% Will want to (un)comment desired cases to plot

% Below Rated
% Pl_FastPlots(fo.Step_Legacy, fo.Step_Baseline)

% Below Rated
% Pl_FastPlots(fo.BR_Legacy, fo.BR_Baseline)

% Near Rated
% Pl_FastPlots(fo.NR_Legacy, fo.NR_Baseline)

% % Above Rated
% Pl_FastPlots(fo.AR_Legacy, fo.AR_Baseline)

% % Floating, Above Rated steady
Pl_FastPlots(fo.OC4_ARsteady_Legacy, fo.OC4_ARsteady_Baseline)




0 comments on commit 0aff18e

Please sign in to comment.