Hello everyone,
I have read different Forum posts but I could not find anything related.
Of course, I have been able to run the OpenFAST S-Function via Simulink model. There is not any problem doing so.
But what I am looking for is to run the S-Function control development capabilities through a Matlab script.
Is it possible to call the S-Function from a Matlab Script without using the Simulink model?
Or using something similar to what it is done in openfast_library.py for Python: openfast/glue-codes/python at main · OpenFAST/openfast · GitHub
Thank you so much in advance!
JL
Hi Javier,
You could try this script/repository: ROSCO/runFAST.m at main · NREL/ROSCO · GitHub
It will require updating some paths and maybe a few fixes along the way. We don’t test it as much as the other parts of the repository, but we keep it up there because it’s useful to some folks.
I hope this helps.
Best, Dan
Hello Daniel,
Thanks for your quick response!
I will have a look into it.
Best,
JL
Hello again,
I have checked carefully the script that Daniel provides here: ROSCO/runFAST.m at main · NREL/ROSCO · GitHub
And it is not what I am looking for. That script runs a complete simulation of a model with ROSCO controller.
Maybe I need to explain myself a little bit clearer.
The main idea is to develop a controller in a matlab script and call OpenFAST as simulation model each time step. In a simple way, I am providing the inputs of the controller to OpenFAST simulation model and I would like to take the states from it to feedback them to my controller.
So, is there any way to call OpenFAST each time step from a Matlab Script?
In Python this can be done after loading the dynamic library and all the functions within it:
Load OpenFAST library:
LoadLibrary(path + ‘/libopenfastlib.dylib’)
Update the states based on the new control inputs:
fast_update(iTurb, NumInputs, InputAry)
I tried this same structure in Matlab but does not work.
I would appreciate if someone have dealed with this before and could provide me some guide how to solve this.
Best,
JL
Hi JL,
I think this is essentially what happens within the Simulink S_Function. You can technically call FAST_SFunc
from a Matlab script, but I haven’t heard of many people doing it that way. I think you will need to figure out from the OpenFAST source code and/or the Simulink model what the exact inputs to the S_Function are and there are parameters loaded to the S_Function in Simulink. You’ll need to figure out how to reproduce that to get the OpenFAST inputs to the S_Function.
Best, Dan
>> FAST_SFunc(0,0,0,0)
ans =
0
0
0
0
0
0
0
3
0
0
0 ...
Dear @Javier.Lopez,
There are two examples of Simulink calling OpenFAST v3.3.0 in the repository here: openfast/glue-codes/simulink at v3.3.0 · OpenFAST/openfast · GitHub. Note that this interface does change between versions (typically with additional control channels).
You will need to compile OpenFAST specifically for coupling to Simulink (vs-build/OpenFAST-Simullink
for Windows + Visual Studio, or for CMake
builds, add the -DBUILD_OPENFAST_SIMULINK_API=On
option to the CMake command
and build the openfast
target).
There is a create_FAST_SFunc.m
provided as well for creating the mex function (you will need the appropriate compilers installed that MATLAB can find).
For further information, there are multiple issues posted with hints on getting the compilation and linking to Simulink working here: Issues · OpenFAST/openfast · GitHub
Regards,
Andy
Hello,
I’m trying to run the OpenFAST Simulink test case Run_Test01_SIG
for validating the S-Function, but I’m encountering errors in both MATLAB and Simulink. Here’s the full error report:
Errors in MATLAB:
Error while obtaining sizes from MEX S-function ‘FAST_SFunc’ in ‘Test01_SIG/FAST Nonlinear Wind Turbine/S-Function’.
Invalid MEX-file ‘C:\Program Files\openfast-3.5.4\openfast-3.5.4\glue-codes\simulink\examples\FAST_SFunc.mexw64’: Le module spécifié est introuvable.
The expression: u(strmatch(‘LSSGagVxa’,OutList)) in ‘Test01_SIG/Fcn’ has a syntax error.
Errors in Simulink:
S-Function Error:Error while obtaining sizes from MEX S-function ‘FAST_SFunc’ in ‘Test01_SIG/FAST Nonlinear Wind Turbine/S-Function’.
Invalid MEX-file:Invalid MEX-file ‘C:\Program Files\openfast-3.5.4\openfast-3.5.4\glue-codes\simulink\examples\FAST_SFunc.mexw64’: Le module spécifié est introuvable.
thank you
Dear @Kaouthar.Othmani,
The syntax error regarding LSSGagVxa
has been asked and answered on this forum before, e.g., see: problem in running Test03 to Test25. Does that solve the issue?
Best regards,
unfortunately no ,
those are the errors in matlab :
slight_smile: Run_Test01_SIG
Error using Run_Test01_SIG (line 36)
Error due to multiple causes.
Caused by:
Error using Run_Test01_SIG (line 36)
Error while obtaining sizes from MEX S-function ‘FAST_SFunc’ in ‘Test01_SIG/FAST Nonlinear Wind Turbine/S-Function’.
Error using Run_Test01_SIG (line 36)
Invalid MEX-file ‘C:\Program Files\openfast-3.5.4\openfast-3.5.4\glue-codes\simulink\examples\FAST_SFunc.mexw64’: Le module spécifié est introuvable.
Error using Run_Test01_SIG (line 36)
The expression: u(strmatch(‘LSSGagVxa’,OutList))
in ‘Test01_SIG/Fcn’
has a syntax error
That is the same error you posted earlier. As asked in the forum post I linked to, does ElastoDyn output LSSGagVxa
exist in your OutList
?
Dear @Kaouthar.Othmani,
OutList
is an array generated by the OpenFAST S-Function that should be accessible within MATLAB/Simluink. Is LSSGagVxa
in this array?
The OutList
array is set in the various OutList
sections of the OpenFAST input files for each module. LSSGagVxa
is an output that could be added within ElastoDyn.
Best regards,
Hello everyone,
I’m new to programming, MATLAB, and OpenFAST, and I’m trying to learn how to use them together for a project. Please forgive me if I’m slow in understanding or if my questions seem basic—I’m still at the beginning of this journey!
I’m encountering a few issues and would really appreciate step-by-step guidance:
About OutList I found an Excel file called OutListParameters
, and I noticed that the variable LSSGagVxa
isn’t listed there. When I try to check for OutList
in MATLAB using disp(OutList);
, I get the error:
Unrecognized function or variable ‘OutList’.
I also tried running the FAST_SFunc
file directly in MATLAB, but I got the following error:
Invalid MEX-file ‘C:\Program Files\openfast-3.5.4\openfast-3.5.4\glue-codes\simulink\examples\FAST_SFunc.mexw64’: Le module spécifié est introuvable.
Could someone kindly explain:
What exactly OutList
is and how I can verify its contents?
If LSSGagVxa
is not in the OutList
, what should I do to include it in OpenFAST?
How to resolve the FAST_SFunc
error? Is it a problem with my OpenFAST installation or a missing dependency?
Please keep in mind that I have a limited background in programming, so simpler, more detailed instructions would really help me.
Thank you so much for your patience and support!
Best regards,
Dear @Jason.Jonkman ,
I have outlined the key problems I encountered:
-
MEX File Error
-
Simulink S-Function Error
-
Output List Error
- While running the script, there is an issue with the
OutList
variable used to define certain parameters. Specifically, the script references a parameter named LSSGagVxa
, but this is missing from the output list. This mismatch may be causing additional errors in the script execution.
-
CMake Configuration Errors
- I attempted to rebuild the
FAST_SFunc.mexw64
file using CMake and MinGW, but encountered multiple issues:
-
MATLAB Compiler Setup Issues
- Running
mex -setup
in MATLAB initially indicated that no supported compilers were available. After installing MinGW, I retried but the integration with OpenFAST’s S-function remains unsuccessful.
Given the above issues, I would appreciate guidance to solve those problems.
Best regards,
Dear @Kaouthar.Othmani,
I’m not familiar enough with CMake to answer your compiling questions. But I’m doubtful that you should have to recompile the S-Function.
My guess is your first error is triggering the others. For example, if the S-Function is not loading, the OutList
variable will not be generated, which will trigger error (3).
Regarding (1), can you clarify–are you running Windows and is your version of MATLAB 64 bit? If so, can you clarify the steps you are using to download and execute the Run_Test01_SIG.m script?
Best regards,