Run OpenFAST S-Function from Matlab Script

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