OpenFAST / matlab-toolbox

Collection of Matlab tools developed for use with OpenFAST
Apache License 2.0
50 stars 67 forks source link

How use "runFAST.m" #42

Closed lqw075 closed 9 months ago

lqw075 commented 1 year ago

Hello everyone,

I don't quite understand how to use the matlab runFAST.m function. I would like to know how to modify which parameters to make it work properly.

This is the source code:

function status = runFAST(FASTfilenames, FASTexe, varargin) % Run a set of FAST simulations using FAST exe. % % TODO , parallelization... % % INPUTS % - FASTfilenames: list of fullpath (relative or absolute) to fst flies % - FASTexe: fullpath (relative or absolute) to an openfast executable % % OPTIONAL INPUTS: % - varargin is a set of ('key', value) pairs. % Look at opts below for the different options, and default values. % % OUPUTS: % - status: array of status for each simulation

% --- Optional arguments OptsFields={'flag',}; opts=struct(); % Default values opts.flag = '' ; % Extra flag passed as command line argument % Values input by users % NOTE: inputParser not available in Octave if mod(length(varargin),2)~=0; error('Varargin should have an even number of values, for key/values pairs'); end for iVar = 1:2:length(varargin) i = find( strcmp( OptsFields, varargin{iVar}) == 1); if ~isempty(i) opts.(OptsFields{i}) = varargin{iVar + 1}; else warning('Optional key %s not supported by function %s',varargin{iVar},mfilename) end end % --- Inputs sanity if ispc() FASTexe = strrep(FASTexe,'/','\'); end

status=zeros(1,length(FASTfilenames));

% --- Creating a list of commands commands=cell(1,length(FASTfilenames)); for isim = 1:length(FASTfilenames) FASTfile = FASTfilenames{isim}; if ispc() FASTfile = strrep(FASTfile,'/','\'); end sCmd= [FASTexe ' ' opts.flag ' ' FASTfile]; commands{isim}=sCmd; end

% --- Running status = runCommands(commands);

Thank you for your answers.

ebranlard commented 1 year ago

Hi, Make sure you can run OpenFAST from a regular terminal before trying this function. This matlab function is simply attempting to launch a set of system calls. You can see an example here: https://github.com/OpenFAST/matlab-toolbox/blob/main/Utilities/examples/runFAST_example.m. It is possible that this function does not work well on all platforms.

lqw075 commented 1 year ago

Hi, Make sure you can run OpenFAST from a regular terminal before trying this function. This matlab function is simply attempting to launch a set of system calls. You can see an example here: https://github.com/OpenFAST/matlab-toolbox/blob/main/Utilities/examples/runFAST_example.m. It is possible that this function does not work well on all platforms.

Thank you very much!This issue has been resolved. But when I run 'runFAST.m', I get this error:
"The expression: u(strmatch('Azimuth',OutList)) in 'ROSCO/Cyclic Pitch controller/extract Azimuth' has a syntax error The expression: u(strmatch('BldPitch1',OutList)) in 'ROSCO/Extract Signals/Extract BldPitch1' has a syntax error"

Here is the source code for 'runFAST.m': %% runFAST.m % This script will run a single FAST simulation with the ROSCO Simulink % controller. A more in depth version can be found at https://github.com/dzalkind/matlab-toolbox/tree/master/Simulations

clear;

[this_dir,~,~] = fileparts(mfilename('fullpath'));

% Compile FAST for use with simulink & mex using openfast docs fast.FAST_SFuncDir = '/Users/dzalkind/Tools/openfast-sim/glue-codes/simulink/src'; %%%% NEED FOR SIMULINK fast.FAST_InputFile = '5MW_Land_Simulink.fst'; % FAST input file (ext=.fst) fast.FAST_directory = '/Users/dzalkind/Tools/ROSCO/Test_Cases/5MW_Land_Simulink'; % Path to fst directory files

% Simulink Parameters % Model simu.SimModel = fullfile(this_dir,'Simulink','ROSCO');

% Script for loading parameters simu.ParamScript = fullfile(this_dir,'Utilities','load_ROSCO_params');

%% Simulink Setup

[ControlScriptPath,ControScript] = fileparts(simu.ParamScript); addpath(ControlScriptPath); addpath(fast.FAST_SFuncDir); addpath('Utilities') %% Read FAST Files & Load ROSCO Params from DISCON.IN

[Param,Cx] = ReadWrite_FAST(fast);

% Simulation Parameters simu.TMax = Param.FP.Val{contains(Param.FP.Label,'TMax')}; simu.dt = Param.FP.Val{contains(Param.FP.Label,'DT')}; [R,F] = feval(ControScript,Param,simu);

%% Premake OutList for Simulink

OutList = {'Time'}; OutList = [OutList; Param.IWP.OutList; Param.EDP.OutList; Param.ADP.OutList; Param.SvDP.OutList; ];

for iOut = 2:length(OutList) OutList{iOut} = OutList{iOut}(2:end-1); %strip "s end

%% Exectute FAST

% Using Simulink/S_Func FAST_InputFileName = [fast.FAST_directory,filesep,fast.FAST_InputFile]; TMax = simu.TMax;

SimulinkModel = simu.SimModel;

Out = sim(SimulinkModel, 'StopTime', num2str(simu.TMax)); sigsOut = get(Out,'sigsOut'); %internal control signals

%% Get OutData

SFuncOutStr = '.SFunc';

% Try text first, then binary [OutData,OutList] = ReadFASTtext([fast.FAST_directory,filesep,fast.FAST_InputFile(1:end-4),SFuncOutStr,'.out']); if isempty(OutData) [OutData,OutList] = ReadFASTbinary([fast.FAST_directory,filesep,fast.FAST_InputFile(1:end-4),SFuncOutStr,'.outb']); end

% Dump data to structure for i = 1:length(OutList) simout.(OutList{i}) = OutData(:,i); end

%% Plot Pl_FastPlots(simout)

I want to know how to solve it.Thank you for your answers!

jjonkman commented 1 year ago

Dear @lqw075,

Are output parameters Azimuth and BlPitch1 included in your OutList? If not, you could add them to the OutListin the ElastoDyn input file.

Best regards,

lqw075 commented 1 year ago

Dear @lqw075,

Are output parameters Azimuth and BlPitch1 included in your OutList? If not, you could add them to the OutListin the ElastoDyn input file.

Best regards,

Thanks for your reply! Yes, I checked. They're in the OutList.After modifying the other errors as you see fit, the program runs successfully.But a lot of warnings pop up. I wonder how much impact they have.These warnings can be broadly divided into three categories: Firstly: "'input port 1' of 'ROSCO/BldPitch Controller/Mux' is not connected"

Secondly: "If the inport ROSCO/Cyclic Pitch controller/1P Cyclic Pitch Controller1/PI - Q/Mq of subsystem 'ROSCO/Cyclic Pitch controller/1P Cyclic Pitch Controller1/PI - Q' involves direct feedback, then an algebraic loop exists, which Simulink cannot remove. To avoid this warning, consider clearing the 'Minimize algebraic loop occurrences' parameter of the subsystem or set the Algebraic loop diagnostic to 'none' in the Diagnostics tab of the Configuration Parameters dialog. "

Thirdly: "FAST_Solution:CalcOutputs_And_SolveForInputs:SolveOption2:RotCalcOutput:BEMT_CalcOutput(node 3, blade 1):UA_CalcOutput:UA_BlendSteady:Temporarily turning off UA due to high angle of attack or low relative velocity. This warning will not be repeated though the condition may persist. "

Best regards!

jjonkman commented 1 year ago

Dear @lqw075,

I can't comment on the ROSCO warnings as I'm not familiar with this Simulink model.

Regarding the unsteady airfoil aerodynamics (UA) warning, UA will be disabled if the instantaneous local angle of attack exceeds the value of UACutout specified in the airfoil data table.

Best regards,

lqw075 commented 1 year ago

Dear @lqw075,

Are output parameters Azimuth and BlPitch1 included in your OutList? If not, you could add them to the OutListin the ElastoDyn input file.

Best regards,

Thanks for your reply! I have a new problem when I run program “IEA-15-240-RWT-UMaineSemi.fst” in MATLAB.The controller version is "https://github.com/NREL/ROSCO/releases/tag/v2.5.0".This is the source code: %% runFAST.m % This script will run a single FAST simulation with the ROSCO Simulink % controller. A more in depth version can be found at https://github.com/dzalkind/matlab-toolbox/tree/master/Simulations

clear;

[this_dir,~,~] = fileparts(mfilename('fullpath'));

% Compile FAST for use with simulink & mex using openfast docs fast.FAST_SFuncDir ='E:\OPENFAST\IEA-15-240-RWT-1.1.2\ROSCO-2.5.0\ROSCO-2.5.0\Test_Cases\IEA-15-240-RWT-UMaineSemi\f_s'; % '/Users/dzalkind/Tools/openfast-sim/glue-codes/simulink/src'; %%%% NEED FOR SIMULINK fast.FAST_InputFile = 'IEA-15-240-RWT-UMaineSemi.fst'; %'5MW_Land_Simulink.fst'; % FAST input file (ext=.fst) fast.FAST_directory = 'E:\OPENFAST\IEA-15-240-RWT-1.1.2\ROSCO-2.5.0\ROSCO-2.5.0\Test_Cases\IEA-15-240-RWT-UMaineSemi';%'/Users/dzalkind/Tools/ROSCO/Test_Cases/5MW_Land_Simulink'; % Path to fst directory files

% Simulink Parameters % Model %simu.SimModel = fullfile(this_dir,'Simulink','ROSCO'); simu.SimModel = 'E:\OPENFAST\IEA-15-240-RWT-1.1.2\ROSCO-2.5.0\ROSCO-2.5.0\Matlab_Toolbox\Simulink\ROSCO';

% Script for loading parameters %simu.ParamScript = fullfile(this_dir,'Utilities','load_ROSCO_params'); simu.ParamScript = 'E:\OPENFAST\IEA-15-240-RWT-1.1.2\ROSCO-2.5.0\ROSCO-2.5.0\Matlab_Toolbox\Utilities\load_ROSCO_params';

%% Simulink Setup

[ControlScriptPath,ControScript] = fileparts(simu.ParamScript); addpath(ControlScriptPath); addpath(fast.FAST_SFuncDir); addpath('Utilities') %% Read FAST Files & Load ROSCO Params from DISCON.IN

[Param,Cx] = ReadWrite_FAST(fast);

% Simulation Parameters simu.TMax = Param.FP.Val{contains(Param.FP.Label,'TMax')}; simu.dt = Param.FP.Val{contains(Param.FP.Label,'DT')}; [R,F] = feval(ControScript,Param,simu);

%% Premake OutList for Simulink

OutList = {'Time'}; OutList = [OutList; Param.IWP.OutList; Param.EDP.OutList; Param.ADP.OutList; Param.SvDP.OutList; ];

for iOut = 2:length(OutList) OutList{iOut} = OutList{iOut}(2:end-1); %strip "s end

%% Exectute FAST

% Using Simulink/S_Func FAST_InputFileName = [fast.FAST_directory,filesep,fast.FAST_InputFile]; TMax = simu.TMax;

SimulinkModel = simu.SimModel;

Out = sim(SimulinkModel, 'StopTime', num2str(simu.TMax)); sigsOut = get(Out,'sigsOut'); %internal control signals

%% Get OutData

SFuncOutStr = '.SFunc';

% Try text first, then binary [OutData,OutList] = ReadFASTtext([fast.FAST_directory,filesep,fast.FAST_InputFile(1:end-4),SFuncOutStr,'.out']); if isempty(OutData) [OutData,OutList] = ReadFASTbinary([fast.FAST_directory,filesep,fast.FAST_InputFile(1:end-4),SFuncOutStr,'.outb']); end

% Dump data to structure for i = 1:length(OutList) simout.(OutList{i}) = OutData(:,i); end

%% Plot Pl_FastPlots(simout)

Here are the errors: The expression: u(strmatch('Azimuth',OutList)) in 'ROSCO/Cyclic Pitch controller/extract Azimuth' has a syntax error The expression: u(strmatch('BldPitch1',OutList)) in 'ROSCO/Extract Signals/Extract BldPitch1' has a syntax error But I checked. They were in the OutListin of ElastoDyn input file.I would like to know how to solve this problem. Best regards,

lqw075 commented 1 year ago

Dear @lqw075,

Are output parameters Azimuth and BlPitch1 included in your OutList? If not, you could add them to the OutListin the ElastoDyn input file.

Best regards,

Thanks for your reply! I have a new problem when I run program “IEA-15-240-RWT-UMaineSemi.fst” in MATLAB.The controller version is "https://github.com/NREL/ROSCO/releases/tag/v2.5.0".**This is the source code:** %% runFAST.m % This script will run a single FAST simulation with the ROSCO Simulink % controller. A more in depth version can be found at https://github.com/dzalkind/matlab-toolbox/tree/master/Simulations

clear;

[this_dir,~,~] = fileparts(mfilename('fullpath'));

% Compile FAST for use with simulink & mex using openfast docs fast.FAST_SFuncDir ='E:\OPENFAST\IEA-15-240-RWT-1.1.2\ROSCO-2.5.0\ROSCO-2.5.0\Test_Cases\IEA-15-240-RWT-UMaineSemi\f_s'; % '/Users/dzalkind/Tools/openfast-sim/glue-codes/simulink/src'; %%%% NEED FOR SIMULINK fast.FAST_InputFile = 'IEA-15-240-RWT-UMaineSemi.fst'; %'5MW_Land_Simulink.fst'; % FAST input file (ext=.fst) fast.FAST_directory = 'E:\OPENFAST\IEA-15-240-RWT-1.1.2\ROSCO-2.5.0\ROSCO-2.5.0\Test_Cases\IEA-15-240-RWT-UMaineSemi';%'/Users/dzalkind/Tools/ROSCO/Test_Cases/5MW_Land_Simulink'; % Path to fst directory files

% Simulink Parameters % Model %simu.SimModel = fullfile(this_dir,'Simulink','ROSCO'); simu.SimModel = 'E:\OPENFAST\IEA-15-240-RWT-1.1.2\ROSCO-2.5.0\ROSCO-2.5.0\Matlab_Toolbox\Simulink\ROSCO';

% Script for loading parameters %simu.ParamScript = fullfile(this_dir,'Utilities','load_ROSCO_params'); simu.ParamScript = 'E:\OPENFAST\IEA-15-240-RWT-1.1.2\ROSCO-2.5.0\ROSCO-2.5.0\Matlab_Toolbox\Utilities\load_ROSCO_params';

%% Simulink Setup

[ControlScriptPath,ControScript] = fileparts(simu.ParamScript); addpath(ControlScriptPath); addpath(fast.FAST_SFuncDir); addpath('Utilities') %% Read FAST Files & Load ROSCO Params from DISCON.IN

[Param,Cx] = ReadWrite_FAST(fast);

% Simulation Parameters simu.TMax = Param.FP.Val{contains(Param.FP.Label,'TMax')}; simu.dt = Param.FP.Val{contains(Param.FP.Label,'DT')}; [R,F] = feval(ControScript,Param,simu);

%% Premake OutList for Simulink

OutList = {'Time'}; OutList = [OutList; Param.IWP.OutList; Param.EDP.OutList; Param.ADP.OutList; Param.SvDP.OutList; ];

for iOut = 2:length(OutList) OutList{iOut} = OutList{iOut}(2:end-1); %strip "s end

%% Exectute FAST

% Using Simulink/S_Func FAST_InputFileName = [fast.FAST_directory,filesep,fast.FAST_InputFile]; TMax = simu.TMax;

SimulinkModel = simu.SimModel;

Out = sim(SimulinkModel, 'StopTime', num2str(simu.TMax)); sigsOut = get(Out,'sigsOut'); %internal control signals

%% Get OutData

SFuncOutStr = '.SFunc';

% Try text first, then binary [OutData,OutList] = ReadFASTtext([fast.FAST_directory,filesep,fast.FAST_InputFile(1:end-4),SFuncOutStr,'.out']); if isempty(OutData) [OutData,OutList] = ReadFASTbinary([fast.FAST_directory,filesep,fast.FAST_InputFile(1:end-4),SFuncOutStr,'.outb']); end

% Dump data to structure for i = 1:length(OutList) simout.(OutList{i}) = OutData(:,i); end

%% Plot Pl_FastPlots(simout)

Here are the errors: The expression: u(strmatch('Azimuth',OutList)) in 'ROSCO/Cyclic Pitch controller/extract Azimuth' has a syntax error The expression: u(strmatch('BldPitch1',OutList)) in 'ROSCO/Extract Signals/Extract BldPitch1' has a syntax error But I checked. They were in the OutListin of ElastoDyn input file.I would like to know how to solve this problem. Best regards,

dzalkind commented 1 year ago

Hi,

A similar question has been discussed here: https://github.com/NREL/ROSCO/issues/231

I suspect the issue lies in the around %% Premake OutList for Simulink. You could check that list in Matlab before Simulink is called.. Unfortunately, it's difficult for us to support this Matlab implementation and the old versions of the ROSCO controller.

Best, Dan

lqw075 commented 1 year ago

Hi,

A similar question has been discussed here: NREL/ROSCO#231

I suspect the issue lies in the around %% Premake OutList for Simulink. You could check that list in Matlab before Simulink is called.. Unfortunately, it's difficult for us to support this Matlab implementation and the old versions of the ROSCO controller.

Best, Dan

Thanks for your reply! The problem has been solved. change this

_%% Premake OutList for Simulink

OutList = {'Time'}; OutList = [OutList; Param.IWP.OutList; Param.EDP.OutList; Param.ADP.OutList; Param.SvDP.OutList; ];

for iOut = 2:length(OutList) OutList{iOut} = OutList{iOut}(2:end-1); %strip "s end_ to this

_%% Premake OutList for Simulink

OutList= {'Time'}; OutList2 = {'Time'}; OutList2 = [OutList2; Param.IWP.OutList; Param.EDP.OutList; Param.ADP.OutList; Param.SvDP.OutList; ];

for iOut = 2:length(OutList2) OutList = [OutList;OutList2{iOut}(1:end)]; %strip "s end

for iOut2 = 1:length(OutList) OutList{iOut2}=strrep(OutList{iOut2},'"',''); end_