From fedfe9ea83226a99eac3872fc0fe0521d9602f52 Mon Sep 17 00:00:00 2001 From: andrew-platt Date: Wed, 29 Jan 2025 22:29:07 -0700 Subject: [PATCH 1/5] Bugfix: missing include path in create_FAST_SFunc.m --- glue-codes/simulink/src/create_FAST_SFunc.m | 1 + 1 file changed, 1 insertion(+) diff --git a/glue-codes/simulink/src/create_FAST_SFunc.m b/glue-codes/simulink/src/create_FAST_SFunc.m index 207128b1ed..fe11bf70c8 100644 --- a/glue-codes/simulink/src/create_FAST_SFunc.m +++ b/glue-codes/simulink/src/create_FAST_SFunc.m @@ -72,6 +72,7 @@ ['-I' includeDir], ... '-I../../../modules/supercontroller/src', ... % needed for visual studio builds to find "SuperController_Types.h" '-I../../../modules/externalinflow/src', ... % needed for visual studio builds to find "ExternalInflow_Types.h" + '-I../../../modules/extloads/src', ... % needed for visual studio builds to find "ExtLoadsDX_Types.h" '-outdir', outDir, ... ['COMPFLAGS=$COMPFLAGS -MT -DS_FUNCTION_NAME=' mexname], ... '-output', mexname, ... From 66b91a94835f44e80fd48d204efbe4512fd584b1 Mon Sep 17 00:00:00 2001 From: andrew-platt Date: Thu, 30 Jan 2025 09:04:29 -0700 Subject: [PATCH 2/5] Change location of FAST_SFunc installed by cmake --- glue-codes/simulink/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glue-codes/simulink/CMakeLists.txt b/glue-codes/simulink/CMakeLists.txt index c927e8c0e2..72ff41d8c8 100644 --- a/glue-codes/simulink/CMakeLists.txt +++ b/glue-codes/simulink/CMakeLists.txt @@ -84,6 +84,6 @@ endif() install(TARGETS FAST_SFunc EXPORT "${CMAKE_PROJECT_NAME}Libraries" RUNTIME DESTINATION bin - LIBRARY DESTINATION lib + LIBRARY DESTINATION bin ARCHIVE DESTINATION lib ) From 1a9948cecdcd067909868e1e41fad9be3f39665f Mon Sep 17 00:00:00 2001 From: andrew-platt Date: Thu, 30 Jan 2025 10:08:57 -0700 Subject: [PATCH 3/5] Simulink: disable create_FAST_SFunc.m Mac/Linux/CMake builds --- glue-codes/simulink/src/create_FAST_SFunc.m | 67 +++++++-------------- 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/glue-codes/simulink/src/create_FAST_SFunc.m b/glue-codes/simulink/src/create_FAST_SFunc.m index fe11bf70c8..82b926e1db 100644 --- a/glue-codes/simulink/src/create_FAST_SFunc.m +++ b/glue-codes/simulink/src/create_FAST_SFunc.m @@ -1,24 +1,30 @@ %% INSTRUCTIONS -% This script is used to manually build a Simulink mex file which uses the openfastlib shared library (.dll, .so, .dylib). -% If you are building OpenFAST with CMake on linux or macOS or windows, you can automatically generate the mex file -% by specifying -DBUILD_OPENFAST_SIMULINK_API=ON when running cmake, you do not need to use this script. +% This script is used to manually build a Simulink mex file on Windows with Visual Studio. It uses the openfastlib shared +% library (.dll). % -% Before running this script, you must have compiled OpenFAST for Simulink to create a DLL (i.e., a shared library like .so, .dylib, .lib, etc.). -% - If cmake was used, make sure the install directory is specified properly in the `installDir` variable below, -% and if using Windows, set `built_with_visualStudio` to false. +% If you are using Windows and building with CMake, do not use this script. Instead use cmake to build the FAST_SFunc.mexXXXX directly. +% +% If you are not using Windows, do not use this script. Instead use cmake to build the FAST_SFunc.mexXXXX directly. +% +% Alternative building with CMAKE: +% specify -DBUILD_OPENFAST_SIMULINK_API=ON when running cmake +% - "make FAST_SFunc" will place the resulting mex file at /glue-codes/simulink/FAST_SFunc.mexXXXX +% - "make install" will place the resulting mex file at install/bin/FAST_SFunc.mexXXXX +% +% +% Before running this script, you must have compiled OpenFAST for Simulink to create a DLL (i.e., a shared library .lib). % - If the Visual Studio Solution file contained in the vs-build directory was used to create the DLL on Windows, % make sure `built_with_visualStudio` is set to true. % - The name of the library that was generated must match the `libname` variable below % and should be located in the directory specified by `libDir`. % - The `includeDir` variable must specify the directory that contains the following header files: -% "FAST_Library.h", "OpenFOAM_Types.h", and "SuperController_Types.h" -% - The `outDir` variable indicates where the resulting mex file will reside. +% "FAST_Library.h", "OpenFOAM_Types.h", "SuperController_Types.h", and "ExtLoadsDX_Types.h" % % Run `mex -setup` in Matlab to configure a C compiler if you have not already done so. mexname = 'FAST_SFunc'; % base name of the resulting mex file -built_with_visualStudio = false; %if the libraries were built with cmake, set to false +built_with_visualStudio = true; %if the libraries were built with cmake, set to false if (ispc && built_with_visualStudio) @@ -42,28 +48,19 @@ else %% defaults for cmake builds: - if ( ismac ) % Apple MacOS - installDir = '../../../install'; - outDir = fullfile(installDir, 'lib'); - elseif ( ispc ) % Windows PC - installDir = '../../../install'; - outDir = fullfile(installDir, 'lib'); - % If there are shared libraries does it work for outDir to be the local directory? - else - installDir = '../../../install'; - outDir = '.'; - end + fprintf( '\n----------------------------\n' ); + fprintf( 'Do not use this script with Mac/Linux. Follow the CMake instructions at the top of the script instead.' ); + fprintf( '\n----------------------------\n' ); - libDir = fullfile(installDir, 'lib'); - includeDir = fullfile(installDir, 'include'); - libName = 'openfastlib_mex'; end -%% BUILD COMMAND -fprintf( '\n----------------------------\n' ); -fprintf( 'Creating %s\n\n', [outDir filesep mexname '.' mexext] ); + if ispc () % Windows PC + %% BUILD COMMAND + fprintf( '\n----------------------------\n' ); + fprintf( 'Creating %s\n\n', [outDir filesep mexname '.' mexext] ); + mex('-largeArrayDims', ... ... % '-v', ... %add this line for "verbose" output (for debugging) @@ -78,22 +75,4 @@ '-output', mexname, ... 'FAST_SFunc.c'); -else % mac/unix - - mex('-largeArrayDims', ... - ... '-v', ... %add this line for "verbose" output (for debugging) - ['-L', libDir], ... - ['-l', libName], ... - '-lgfortran', ... - '-lquadmath', ... - '-llapack', ... - '-lblas', ... - '-ldl', ... - ['-I', includeDir], ... - '-outdir', outDir, ... - ['CFLAGS=$CFLAGS -DS_FUNCTION_NAME=' mexname], ... - ... ['CXXFLAGS=$CXXFLAGS -DS_FUNCTION_NAME=' mexname], ... - '-output', mexname, ... - 'FAST_SFunc.c'); - end From 175e475e3781a12db1450158549bc68256505285 Mon Sep 17 00:00:00 2001 From: andrew-platt Date: Thu, 30 Jan 2025 10:15:40 -0700 Subject: [PATCH 4/5] Docs: Update cmake options These were badly outdated --- docs/source/install/index.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/source/install/index.rst b/docs/source/install/index.rst index 6bd5b81ab6..2820da7c2e 100644 --- a/docs/source/install/index.rst +++ b/docs/source/install/index.rst @@ -460,19 +460,26 @@ The CMake options specific to OpenFAST and their default settings are: BUILD_DOCUMENTATION - Build documentation (Default: OFF) BUILD_FASTFARM - Enable FAST.Farm capabilities (Default: OFF) BUILD_OPENFAST_CPP_API - Enable building OpenFAST - C++ API (Default: OFF) + BUILD_OPENFAST_CPP_DRIVER - Enable building OpenFAST C++ driver using C++ CFD API (Default: OFF) + BUILD_OPENFAST_LIB_DRIVER - Enable building OpenFAST driver using C++ Library API (Default: OFF) BUILD_OPENFAST_SIMULINK_API - Enable building OpenFAST for use with Simulink (Default: OFF) BUILD_SHARED_LIBS - Enable building shared libraries (Default: OFF) BUILD_TESTING - Build the testing tree (Default: OFF) + BUILD_UNIT_TESTING - Enable unit testing (Default: ON) CMAKE_BUILD_TYPE - Choose the build type: Debug Release (Default: Release) CMAKE_Fortran_MODULE_DIRECTORY - Set the Fortran Modules directory CMAKE_INSTALL_PREFIX - Install path prefix, prepended onto install directories. - CODECOV - Enable infrastructure for measuring code coverage (Default: OFF) + CMAKE_MACOSX_RPATH - Use RPATH runtime linking (Default: ON) + CODECOVERAGE - Enable infrastructure for measuring code coverage (Default: OFF) DOUBLE_PRECISION - Treat REAL as double precision (Default: ON) FPE_TRAP_ENABLED - Enable Floating Point Exception (FPE) trap in compiler options (Default: OFF) GENERATE_TYPES - Use the openfast-registry to autogenerate types modules (Default: OFF) OPENMP - Enable OpenMP support (Default: OFF) - ORCA_DLL_LOAD - Enable OrcaFlex library load (Default: OFF) + ORCA_DLL_LOAD - Enable OrcaFlex library load (Default: ON) USE_DLL_INTERFACE - Enable runtime loading of dynamic libraries (Default: ON) + USE_LOCAL_STATIC_LAPACK - Enable downloading and building static LAPACK and BLAS libs (Default: OFF) + VARIABLE_TRACKING - Enables variable tracking for better runtime debugging output. May increase compile time. Valid only for GNU. (Defualt: ON) + Additional system-specific options may exist for a given system, but those should not impact the OpenFAST configuration. As mentioned above, the From 72bc70534f02428ccf2a72d62e0ae9c120e52a69 Mon Sep 17 00:00:00 2001 From: andrew-platt Date: Thu, 30 Jan 2025 10:56:32 -0700 Subject: [PATCH 5/5] Docs: add documentation on building Simulink MEX function --- docs/source/install/index.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/source/install/index.rst b/docs/source/install/index.rst index 2820da7c2e..643fa0fc38 100644 --- a/docs/source/install/index.rst +++ b/docs/source/install/index.rst @@ -761,6 +761,27 @@ through the Intel oneAPI distributions. .. _installation_appendix: +Simulink +~~~~~~~~ +To build the MEX function for coupling OpenFAST into Simulink, there are two +options depending on platform. + +Windows with Visual Studio +-------------------------- +For Windows, build with the `Release_Matlab` option from the Visual Studio +project in `vs-build/FAST/FAST.sln`. Then run +`glue-codes/simulink/src/create_FAST_SFunc.m` from MATLAB (instructions at the +top of this file). + +CMake +----- +For CMake builds on all platforms, enable the `-DBUILD_OPENFAST_SIMULINK_API=On` +option in CMake and build the `FAST_SFunc` target. This will place the +resulting `FAST_SFunc.mexXXXX` in +`/glue-codes/simulink/FAST_SFunc.mexXXXX` (and in the install +directory at `install/bin/FAST_SFunc.mexXXXX` if `make install` was called). + + Appendix ~~~~~~~~ The following are additional methods for installation which may not be fully