FAST S-Func MEXing process

Provide feedback, request enhancements, and get help with wind-turbine computer-aided engineering tools.

Moderators: Bonnie.Jonkman, Jason.Jonkman

Stefano.Cottafavi
Posts: 46
Joined: Wed Jul 09, 2008 2:26 pm
Organization: Ampyx Power
Location: NL
Location: The Hague, NL
Contact:

FAST S-Func MEXing process

Postby Stefano.Cottafavi » Wed Jul 16, 2008 9:54 am

Hi,
presentation first, my name is Stefano I'm from Modena,Italy. I would like to thank Marhall B. for his quick reply and account activation.

I'm trying to rebuild FAST S-Func for use within Simulink but I'm not able to figure out what is the mex-fortran gateway function layout...

Step-by-step: I'm able to succesfully compile FAST source code and get a standard .exe (using eclipseIDE+photran+g95 free compiler); I can mex the fortran sample within gnumex without error, but what I want is to mex FAST that is more complex/structured project...

First of all, I know I need to code the gateway function but I wouldn't "guess" which variables I should pass and which not, if some source is already available out there. Does such function exist for download in some NWTC software package?

Thank you in advance for any help/suggestion you can give

@Jason Jonkman: I can send the sys sources if you are interested in.

cheers
stefano

Jason.Jonkman
Posts: 4223
Joined: Thu Nov 03, 2005 4:38 pm
Location: Boulder, CO
Contact:

RE: FAST S-Func MEXing process

Postby Jason.Jonkman » Thu Jul 17, 2008 1:26 pm

Dear Stefano,

I answered your e-mail to the same question, but I'll respond to this post so that other users can view the answer also.

We haven't yet released the source code for compiling the MATLAB/Simulink version of FAST because we are not currently happy with how it has to be modified with each different release of MATLAB/Simulink. But since you asked for it, I've provided a link below to the source code and other files you should need to compile it yourself.

In FAST v6.01 (the version that is currently downloadable from our website as of July, 2008), I used an old version of MATLAB--v7.0.4.365 (R14) Service Pack 2--to compile the FAST_SFunc.dll. The extension of the FAST_SFunc was changed from .dll to .mexw32 in R2006a and later versions of MATLAB.

Here is a link to the archive of the yet-to-be-released (as of July 2008) FAST v6.02c-jmj with AeroDyn v12.58: http://wind.nrel.gov/designcodes/simulators/fast/FAST_v602c-jmj.exe. In this version, I compiled the corresponding FAST_SFunc.mexw32 with MATLAB v7.2.0.232 (R2006a), which also works with MATLAB R2006b. However, the model will not run in MATLAB R2007a or R2008a without additional changes. To get it to run on R2007a or R2008a, I had to update the FAST_SFunc source code again. (As it turns out, the FAST_SFunc source code was using an obsolete intrinsic function that had to be replaced in MATLAB R2007a.)

The updated source code for compiling the FAST S-Function in MATLAB R2007a (or R2008a) can be downloaded from http://wind.nrel.gov/public/jjonkman/FAST/Files_2007a.zip. You can use the files in this archive to compile the FAST S-Function yourself. The archive also contains the updated MATLAB R2007a (or R2008a) version of the FAST_SFunc.mexw32 for FAST v6.02c-jmj with AeroDyn v12.58. The m-file "Make_FAST_SFunc.m" is the MATLAB script used to actually compile the mexw32 in R2007a (or R2008a). Additional changes may be required to get it to compile with other releases of MATLAB. Examine (and modify) this file as necessary. There are instructions at the top of this file.

We do plan on improving how we distribute the FAST_SFunc source code in our next release of FAST (available after July, 2008). In the mean time, I apologize for the confusion.

Best regards,
Jason Jonkman, Ph.D.
Senior Engineer | National Wind Technology Center (NWTC)

National Renewable Energy Laboratory (NREL)
15013 Denver West Parkway | Golden, CO 80401
+1 (303) 384 – 7026 | Fax: +1 (303) 384 – 6901
nwtc.nrel.gov

Stefano.Cottafavi
Posts: 46
Joined: Wed Jul 09, 2008 2:26 pm
Organization: Ampyx Power
Location: NL
Location: The Hague, NL
Contact:

Postby Stefano.Cottafavi » Sun Sep 28, 2008 11:00 am

Dear Jason,
I've been busy for a while but I came back working on FAST, and I've been able to use your files to successfully compile .exe and .mexw32 FAST :D

I've also uploaded a short how-to for the ones interested in Eclipse+Photran+G95 usage (actually only for S-Function), and can be found here

http://www.stefanocottafavi.com

I hope to find the time to put there also a sample FAST Fortran project and the simple .exe compiling procedure too.

Of course I'll be happy to help other as you helped me; feel free to send over comments suggestions or bugs you find.

cheers
stefano

Jason.Jonkman
Posts: 4223
Joined: Thu Nov 03, 2005 4:38 pm
Location: Boulder, CO
Contact:

RE: FAST S-Func MEXing process

Postby Jason.Jonkman » Mon Sep 29, 2008 9:32 am

Dear Stefano,

Thanks for developing that site and supplying the link. I'll be sure to forward users to your site when they ask me how to compile FAST with the G95 compiler.

Best regards,
Jason Jonkman, Ph.D.
Senior Engineer | National Wind Technology Center (NWTC)

National Renewable Energy Laboratory (NREL)
15013 Denver West Parkway | Golden, CO 80401
+1 (303) 384 – 7026 | Fax: +1 (303) 384 – 6901
nwtc.nrel.gov

Amit.Mohanty
Posts: 7
Joined: Sun Jan 03, 2010 2:00 am
Organization: Idaho National Laboratory
Location: Idaho Falls

Re: FAST S-Func MEXing process

Postby Amit.Mohanty » Sat Jan 09, 2010 3:25 pm

Dear All,
I was wondering if I can follow the same steps of a 64 bit Windows 7 +MATLAB 2009b? What are the additional changes I have to make?

Thanks
Amit

Jason.Jonkman
Posts: 4223
Joined: Thu Nov 03, 2005 4:38 pm
Location: Boulder, CO
Contact:

Re: FAST S-Func MEXing process

Postby Jason.Jonkman » Mon Jan 11, 2010 10:49 am

Dear Amit,

I'm not sure if Stefano still views this forum. You could, perhaps, post a comment on Stefano's website. But you may just need to try it yourself.

Best regards,
Jason Jonkman, Ph.D.
Senior Engineer | National Wind Technology Center (NWTC)

National Renewable Energy Laboratory (NREL)
15013 Denver West Parkway | Golden, CO 80401
+1 (303) 384 – 7026 | Fax: +1 (303) 384 – 6901
nwtc.nrel.gov

Stefano.Cottafavi
Posts: 46
Joined: Wed Jul 09, 2008 2:26 pm
Organization: Ampyx Power
Location: NL
Location: The Hague, NL
Contact:

Re: FAST S-Func MEXing process

Postby Stefano.Cottafavi » Fri Feb 26, 2010 3:18 am

Dear Amit, Jason
sorry for the late reply but I've been quite busy these days.
I think the makefile should work also on WIn7 x64 and newer MATLAB but the best is try and see what happens.

good luck and let me know

cheers
ste
Stefano Cottafavi
Project Engineer Mechatronics

Ampyx Power
The Hague, NL

Ursula.Smolka
Posts: 2
Joined: Fri Oct 03, 2008 3:49 pm
Location: University Stuttgart
Contact:

Re: FAST S-Func MEXing process

Postby Ursula.Smolka » Tue Feb 08, 2011 10:19 am

Dear Stefano,

I have been following your post on compiling FastSFunction for 32bit architectures. As you suggested the make file you wrote should run similarly for mexw64 compilation. So I took your instructions from your homepage and tried to compile.
Unfortunately I get an error message:

"
An internal error occured during: "Buidling Workspace". Could not find a file to match the module name: Blade
"

Up to now I just could not figure out what mistake I am making. Maybe just the order of compilation is wrong? So I'll post my new header. Hoping that someone might have already solved the problem.

Greetings
Ursula

# Folders
ROOT = ..
SRCF = ${ROOT}/src

# Configuration options
NAME = FAST_SFunc.mexw64
OUT = Objects

# Commands
FC = g95
DEBUG =
OPTIM = -O0
WARNING = -Wno-line-truncation
INCLUDE = -I"C:\Program Files\MATLAB\R2010b\extern\include"
LIBRARY = -L"C:\Program Files\MATLAB\R2010b\bin\win64" -lmex -lmat -lmx
MACRO = -DMATLAB_MEX_FILE
OPTIONS = -fmod=Modules -fcase-upper -fno-underscoring -r8
MACHINE =
OUTPUT = -o $(NAME)

# Compiler flags (CFLAGS), Linker flags (LFLAGS)
CFLAGS = -c ${DEBUG} ${OPTIM} ${WARNING} ${INCLUDE} ${OPTIONS}
LFLAGS = -shared ${MACRO} ${LIBRARY} ${MACHINE} ${OUTPUT}

# Targets: S-Function
fasts: ModG95.o SysG95.o DoublePrecGnu.o \
NWTC_IO.o NWTC_Num.o NWTC_Aero.o NWTC_Library.o \
SharedInflowDefs.o HHWind.o FFWind.o FDWind.o CTWind.o UserWind.o InflowWindMod.o \
SharedTypes.o AeroMods.o GenSubs.o AeroSubs.o AeroDyn.o \
FAST_Mods.o NoiseMods.o fftpack.o FFTMod.o \
AeroCalc.o HydroCalc.o FastIO.o FAST.o FAST_Lin.o \
PitchControl_ACH.o SetVersion.o UserSubs.o UserVSCont_KP.o \
FastSimulink.o FastGateway.o makefile

${FC} ${LFLAGS} ${OUTPUT} \
$(OUT)/ModG95.o $(OUT)/SysG95.o $(OUT)/DoublePrecGnu.o \
$(OUT)/NWTC_IO.o $(OUT)/NWTC_Num.o $(OUT)/NWTC_Aero.o $(OUT)/NWTC_Library.o\
$(OUT)/SharedInflowDefs.o $(OUT)/HHWind.o $(OUT)/FFWind.o $(OUT)/FDWind.o $(OUT)/CTWind.o $(OUT)/UserWind.o $(OUT)/InflowWindMod.o\
$(OUT)/SharedTypes.o $(OUT)/AeroMods.o $(OUT)/GenSubs.o $(OUT)/AeroSubs.o $(OUT)/AeroDyn.o\
$(OUT)/FAST_Mods.o $(OUT)/NoiseMods.o $(OUT)/fftpack.o $(OUT)/FFTMod.o \
$(OUT)/AeroCalc.o $(OUT)/HydroCalc.o $(OUT)/FastIO.o $(OUT)/FAST.o $(OUT)/FAST_Lin.o \
$(OUT)/PitchControl_ACH.o $(OUT)/SetVersion.o $(OUT)/UserSubs.o $(OUT)/UserVSCont_KP.o \
$(OUT)/FastSimulink.o $(OUT)/FastGateway.o

Bonnie.Jonkman
Posts: 557
Joined: Thu Nov 10, 2005 10:51 am
Organization: Envision Energy USA
Location: Colorado
Location: Boulder, CO
Contact:

Re: FAST S-Func MEXing process

Postby Bonnie.Jonkman » Tue Feb 15, 2011 4:37 pm

Hi, Ursula.

I think you're probably correct that the order of compilation is wrong. To compile the S_Function, you should be able to use the order of the files listed in the make_FAST_SFunc.m file, possibly replacing the SysMatlab.f90 file with one modified for Matlab on your compiler (you'll likely have to remove the lines that say "USE IFPORT"). In the code you've shared, it looks like there are a couple of extra object files listed and some that are out of order.
Bonnie Jonkman

Envision Energy USA, 2016-
National Renewable Energy Laboratory, 2003-2016

Mario.Schirru
Posts: 6
Joined: Thu Oct 18, 2012 7:31 am
Organization: self
Location: Germany

Re: FAST S-Func MEXing process

Postby Mario.Schirru » Thu Jun 06, 2013 3:01 am

Hi all,

I have been trying hard to mex the S-function on Matlab R2013a with intel composer XE 2011 using the "intelf12msvs2010shellopts.bat" and the "make_FAST_SFunc.m" files provided. Of course I changed the paths in the "make_FAST_SFunc" file, but, after creating all the .mod files, I get the error message:

'link' is not recognized as an internal or external command,
operable program or batch file.

I have been trying to change some paths, got different error messages, but was not able to mex the S-Function.

Does anybody have a solution?

Thanks in advance,
Mario

Mario.Schirru
Posts: 6
Joined: Thu Oct 18, 2012 7:31 am
Organization: self
Location: Germany

Re: FAST S-Func MEXing process

Postby Mario.Schirru » Thu Jun 06, 2013 7:00 am

Actually I have to immediately update my previous post: I was able to correctly mex the 32bit S-Function by modifying the "intelf12msvs2010opts.dat" file according to the suggestions of Bonnie:

% (3) Change COMPFLAGS in this new .bat file:
% add these flags if they aren't there already:
% /assume:byterecl /traceback /real_size:64 /Qzero /Qsave
% remove these flags if they exist:
% /fpp /fixed
% (4) Check variables OPTIMFLAGS and DEBUGFLAGS in the .bat file:
% remove /MD if it is there

but when I try to do the same thing for a 64bit S-Function, although I get an error free process, the Simulink Simulation crashes as soon as I try to run it. Did anybody succeed in mexing successfully a 64bit S-Function? How did it work?

Thank you,
Mario

Bonnie.Jonkman
Posts: 557
Joined: Thu Nov 10, 2005 10:51 am
Organization: Envision Energy USA
Location: Colorado
Location: Boulder, CO
Contact:

Re: FAST S-Func MEXing process

Postby Bonnie.Jonkman » Thu Jun 06, 2013 11:03 am

Hi, Mario.

We are aware of an issue with the FAST_SFunc not working on 64-bit Matlab. As you said, it compiles without error, but then crashes Matlab. Unfortunately, we have not had time to debug the issue. Our immediate solution is to use 32-bit Matlab.

If you do find a solution, please let us know.
Bonnie Jonkman

Envision Energy USA, 2016-
National Renewable Energy Laboratory, 2003-2016

Kaveh.Jalili
Posts: 4
Joined: Thu Jun 27, 2013 8:42 pm
Organization: University of Texas at Dallas
Location: Texas

Re: FAST S-Func MEXing process

Postby Kaveh.Jalili » Wed Jul 10, 2013 9:02 pm

Hello,
I need to make the S_Function (mex in the matlab). But I do not know which versions of FAST , AeroDyn, Inflow, ... should be used.
all the versions are changing very fast and making me confused.

would you please tel me where can I find required files for making the S_Function and which versions?


Best Regards,
Kaveh

Borchersen.Anders
Posts: 2
Joined: Mon May 20, 2013 4:40 am
Organization: Aalborg University
Location: Denmark

Re: FAST S-Func MEXing process

Postby Borchersen.Anders » Thu Jul 11, 2013 7:05 am

Mario.Schirru wrote:Actually I have to immediately update my previous post: I was able to correctly mex the 32bit S-Function by modifying the "intelf12msvs2010opts.dat" file according to the suggestions of Bonnie:

% (3) Change COMPFLAGS in this new .bat file:
% add these flags if they aren't there already:
% /assume:byterecl /traceback /real_size:64 /Qzero /Qsave
% remove these flags if they exist:
% /fpp /fixed
% (4) Check variables OPTIMFLAGS and DEBUGFLAGS in the .bat file:
% remove /MD if it is there

but when I try to do the same thing for a 64bit S-Function, although I get an error free process, the Simulink Simulation crashes as soon as I try to run it. Did anybody succeed in mexing successfully a 64bit S-Function? How did it work?

Thank you,
Mario


Hi Mario and others,

I have the 64bit S-function working without any problems in Linux.
To make it work you need to change some numbers in the FASTGateway.f90 since some of it is fixed at 4 where they need to be 8 for it to work in 64 bit.
You can see all the patches and a guide for getting it up and running in Ubuntu here:http://kom.aau.dk/~anb/fast/fastinstall.html

Br
Anders

Bonnie.Jonkman
Posts: 557
Joined: Thu Nov 10, 2005 10:51 am
Organization: Envision Energy USA
Location: Colorado
Location: Boulder, CO
Contact:

Re: FAST S-Func MEXing process

Postby Bonnie.Jonkman » Fri Jul 12, 2013 2:47 pm

Kaveh,

If you are starting out with a new project, you should use the latest version of FAST on the web site. Currently, that is v7.02.00d-bjj. The web site also tells you which versions of the other codes you will need to compile with. If the current version of a supporting FAST module is only slightly different than the one you need, the newer version will probably work, too. If you're still having trouble, let us know which versions you are trying to use.
Bonnie Jonkman

Envision Energy USA, 2016-
National Renewable Energy Laboratory, 2003-2016


Return to “Computer-Aided Engineering Software Tools”

Who is online

Users browsing this forum: No registered users and 1 guest