I am running two FAST S-Functions in the same simulink file, representing wind turbines operating at two different wind speeds. The version of FAST is v8.16 and the two functions are named FAST_SFunc_1.mexw64 and FAST_SFunc_2.mexw64. However, the following error occurs during the compilation process:
Error reported by S-function ‘FAST_SFunc_2’ in ‘NREL_5MW_Full/Wind Turbine Type 4-2/FAST Nonlinear Wind Turbine/S-Function’:
FAST_InitializeAll:FAST_Init:FAST_ReadPrimaryFile:Error allocating memory for the p%LinTimes array; array was already allocated.
FAST_ReadPrimaryFile:Error allocating memory for the p%LinTimes array; array was already allocated.
According to the guidance from [url]http://forums.nrel.gov/t/running-multiple-models-in-simulink/1642/1], I guess the reason might be that both mexw64 files are using the same DLL file (FAST_Library_x64.dll) at the same time. If I have a copy of another DLL file named FAST_Library_x64_2.dll, how can I get the mexw64 file to call it. Should I recompile the FAST_Library_x64.lib file to include the FAST_Library_x64_2.dll before recompiling the mexw64 file?
I would be very appreciated if let me know how to correct it.
To support multiple OpenFAST models within the same Simulink model, you’ll have to have multiple copies of the FAST S-Function (FAST_SFunc.mex64) and multiple copies of the FAST Library (FAST_Library_x64.dll). The name of the FAST Library is set when you compile the FAST S-Function using create_FAST_SFunc.m, so, you’ll need to modify the name in this file when you compile the S-Function(s).
Thank you very much for your help! In fact, I have recompiled the FAST_SFunc.mex64 file as you suggested. However, this mex64 file still calls the original FAST_Library_x64.dll file instead of its copy with a different name. I guess the reason is that mex64 is compiled based on the FAST_Library_x64.lib file, which specifies the name of the DLL file that mex64 will call. If this is the case, how can I modify the FAST_Library_x64.lib file?
There are a few things that may have to change for you to use two copies of the FAST_SFunc.
- When you create FAST_Library_x64_2.dll, you cannot simply rename the original DLL. The associated .lib file needs to be changed (its contents need to know the new name of the DLL). You will have to re-build the DLL in Visual Studio with the new name for the resulting DLL. This will create the appropriate .lib file for you. Open the FAST_Library.sln file, open the FAST_Library project properties window, and modify the target name to end in "2" (the target name will be [b]$(ProjectName)$(PlatformName)_2[/b]) . Then build the solution; this should create the FAST_Library_x64_2.dll and FAST_Library_x64_2.lib files.
- You will probably also have to rename the S-Function so Simulink doesn’t get confused about which DLL you are calling. To do this, you will have to edit line 21 in FAST_SFunc.c. Change
#define S_FUNCTION_NAME FAST_SFunc
#define S_FUNCTION_NAME FAST_SFunc_2
- You will need to tell the mex file the name of the new library. You can do so by adding the ‘_2’ to the library name in the mex command. You will also need to tell Matlab to give this new mex function a different name by adding the ‘-output’ flag. I think this command should work to create the new mex file:
mex -v -L..\..\bin -lFAST_Library_x64_2 ...
-I..\..\Source -I..\..\Source\dependencies\OpenFOAM -outdir ..\..\bin COMPFLAGS='$COMPFLAGS /MT' ...
-output FAST_SFunc_2 FAST_SFunc.c
- After you have created FAST_SFunc_2.mexw64, you will have to modify your Simulink model to call ‘FAST_SFunc_2’ instead of
FAST_SFunc for one of the turbine instances.
Thank you so much for such a detailed guide, it does work!