FAST MEXing with Eclipse, Photran and G95 Compiler PDF Print E-mail

FAST is a very useful software for the simulation of Wind Turbine Generator systems, developed at the National Renewable Energy Laboratory (NREL); the program core consists of a non-linear multi-body model written in FORTRAN that can be also implemented in MATLAB/Simulink® as a S-Function.

The FAST software package can be downloaded from NWTC Design Codes page and already contains a good set of example WTG; along with the command line Windows version of the program, a couple of Simulink model, based on a MEXed version of FAST (that is a .dll or mexw32/mexw64 depending on new/old releases), is also available.

FAST is "ready to go" but can happen that you want to change some parts of the code to satisfy certain requirements; the complete source code is available and the following steps can be used to build an executable file or a dynamic library.

 

INDEX


REQUIREMENTS

First of all the methods described here are intended for Windows users, but I didn't spent time to figure out compatibilities on other OS that however could exist.

Compiling FORTRAN code means that at least one FORTRAN compiler is set on your system; two free compilers, GFortran and G95 are available and I've choosen the second. These compilers need a UNIX-like C development environment, provided on Windows by Cygwin or MinGW. The latter will be used for this purpose.

Install first MinGW (MSYS is recomended too) and then G95. Instructions, how-to, installers and other resources are available from the respective web pages and are frequently updated (that's why not directly linked from here).

The Mathworks grants compatibility with most commercial FORTRAN compilers like Compaq/HP and Intel; there is no supporting documentation for the free G95 compiler(GNU) but has been succesfully tested too.

Last thing we need to speed up coding/debugging phase is a full featured FORTRAN IDE; Eclipse + Photran plugin will do the job. If it is your first time using Eclipse download Eclipse IDE for C/C++ Developers otherwise you can simply downloand/install the Photran plugin.

 

REFERENCES

I found some very helpful pages on the net and here they go as a reference for you too:


BUILD FAST

A. Standard MAKEFILE

How to compile Matlab-compatible (or Simulink-compatible) MEX files? Assuming you have downloaded FAST and AeroDyn packages from the NWTC repository, create a new FORTRAN project in Eclipse with whatever name you want (FAST602c for me)and import the source files (this creates a copy, not affecting your original). This is done by right-clicking within the Project Explorer and selecting Import->General->File System and browsing to the correct file/folder. A destination subfolder can be specified in Into folder textfield (for the purpose AeroDyn will be copied to FAST602c/AeroDyn, and FAST source to FAST602c/Source, FASTDynamics.f90 and FASTGateway.f90, used for the S-Function only, will be copied to FAST602c).

Then we need to prepare the output folder, by right-clicking on the Project Explorer then New->Folder and name it SFunc; create also two SFunc subfolders named Modules and Objects (just to keep the workspace clean)

Next, we create the makefile by right-clicking on the SFunc folder inside the Project Explorer then New->File and choosing makefile (no extension) as filename and finally copying the following lines, or simply downloading (from DOWNLOAD section) and importing the makefile into SFunc dir.

 

# FAST MEX - Stefano Cottafavi 07/2008 - Manual makefile
# for Eclipse + Photran + G95 FORTRAN compiler
 
# Folders
ROOT = ..
SRCF = ${ROOT}/Source
SRCA = ${ROOT}/AeroDyn
 
# Configuration options
NAME = FAST602c_SFunc.mexw32
OUT = Objects
 
# Commands
FC = g95
DEBUG =
OPTIM = -O0
WARNING = -Wno-line-truncation
INCLUDE = -I"D:\Program Files (x86)\MATLAB\R2007b\extern\include"
LIBRARY = -L"D:\Program Files (x86)\MATLAB\R2007b\bin\win32" -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 \
fftpack.o \
AeroModsS.o FFTMod.o NoiseMods.o FastMods.o \
AeroSubs.o GenSubsS.o NoiseSubs.o UserSubs.o \
GenUse.o SetVersion.o \
AeroCalc.o HydroCalc.o FastIO.o FAST2ADAMS.o FAST_Lin.o \
PitchControl.o SpeedControl.o UserWind.o \
Fast.o FastDynamics.o FastGateway.o makefile
 
${FC} ${LFLAGS} ${OUTPUT} \
$(OUT)/ModG95.o $(OUT)/SysG95.o \
$(OUT)/fftpack.o \
$(OUT)/AeroModsS.o $(OUT)/FFTMod.o $(OUT)/NoiseMods.o $(OUT)/FastMods.o \
$(OUT)/GenSubsS.o $(OUT)/AeroSubs.o $(OUT)/NoiseSubs.o $(OUT)/UserSubs.o \
$(OUT)/GenUse.o $(OUT)/SetVersion.o \
$(OUT)/HydroCalc.o $(OUT)/AeroCalc.o $(OUT)/FastIO.o $(OUT)/FAST2ADAMS.o $(OUT)/FAST_Lin.o \
$(OUT)/PitchControl.o $(OUT)/SpeedControl.o $(OUT)/UserWind.o \
$(OUT)/Fast.o $(OUT)/FastDynamics.o $(OUT)/FastGateway.o
 
#clean:
# rm -f *.mod *.o
 
# -- COMPILE
FastDynamics.o: ${ROOT}/FASTDynamics.f90 makefile
${FC} ${CFLAGS} ${ROOT}/FASTDynamics.f90 -o ${OUT}/$@
FastGateway.o: ${ROOT}/FastGateway.f90 makefile
${FC} ${CFLAGS} ${ROOT}/FastGateway.f90 -o ${OUT}/$@
 
fftpack.o: $(SRCF)/fftpack.f makefile
${FC} ${CFLAGS} $(OPT) $(SRCF)/fftpack.f -o $(OUT)/$@
FFTMod.o: $(SRCF)/FFTMod.f90 makefile
${FC} ${CFLAGS} $(OPT) $(SRCF)/FFTMod.f90 -o $(OUT)/$@
 
ModG95.o: $(SRCF)/ModG95.f90 makefile
${FC} ${CFLAGS} $(SRCF)/ModG95.f90 -o $(OUT)/$@
SysG95.o: $(SRCF)/SysG95.f90 makefile
${FC} ${CFLAGS} $(SRCF)/SysG95.f90 -o $(OUT)/$@
AeroMods.o: $(SRCA)/AeroMods.f90 makefile
${FC} ${CFLAGS} $(SRCA)/AeroMods.f90 -o $(OUT)/$@
AeroModsS.o: $(SRCA)/AeroMods_SFunc.f90 makefile
${FC} ${CFLAGS} $(SRCA)/AeroMods_SFunc.f90 -o $(OUT)/$@
NoiseMods.o: $(SRCF)/NoiseMods.f90 makefile
${FC} ${CFLAGS} $(SRCF)/NoiseMods.f90 -o $(OUT)/$@
FastMods.o: $(SRCF)/FAST_Mods.f90 makefile
${FC} ${CFLAGS} $(SRCF)/FAST_Mods.f90 -o $(OUT)/$@
GenSubs.o: $(SRCA)/GenSubs.f90 makefile
${FC} ${CFLAGS} $(SRCA)/GenSubs.f90 -o $(OUT)/$@
GenSubsS.o: $(SRCA)/GenSubs_SFunc.f90 makefile
${FC} ${CFLAGS} $(SRCA)/GenSubs_SFunc.f90 -o $(OUT)/$@
AeroSubs.o: $(SRCA)/AeroSubs.f90 makefile
${FC} ${CFLAGS} $(SRCA)/AeroSubs.f90 -o $(OUT)/$@
NoiseSubs.o: $(SRCF)/NoiseSubs.f90 makefile
${FC} ${CFLAGS} $(SRCF)/NoiseSubs.f90 -o $(OUT)/$@
UserSubs.o: $(SRCF)/UserSubs.f90 makefile
${FC} ${CFLAGS} $(SRCF)/UserSubs.f90 -o $(OUT)/$@
 
SetVersion.o: $(SRCF)/SetVersion.f90 makefile
${FC} ${CFLAGS} $(SRCF)/SetVersion.f90 -o $(OUT)/$@
GenUse.o: $(SRCF)/GenUse.f90 makefile
${FC} ${CFLAGS} $(SRCF)/GenUse.f90 -o $(OUT)/$@
 
FastIO.o: $(SRCF)/Fast_IO.f90 makefile
${FC} ${CFLAGS} $(SRCF)/Fast_IO.f90 -o $(OUT)/$@
AeroCalc.o: $(SRCF)/AeroCalc.f90 makefile
${FC} ${CFLAGS} $(SRCF)/AeroCalc.f90 -o $(OUT)/$@
HydroCalc.o: $(SRCF)/HydroCalc.f90 makefile
${FC} ${CFLAGS} $(SRCF)/HydroCalc.f90 -o $(OUT)/$@
FAST2ADAMS.o: $(SRCF)/FAST2ADAMS.f90 makefile
${FC} ${CFLAGS} $(SRCF)/FAST2ADAMS.f90 -o $(OUT)/$@
FAST_Lin.o: $(SRCF)/FAST_Lin.f90 makefile
${FC} ${CFLAGS} $(SRCF)/FAST_Lin.f90 -o $(OUT)/$@
 
UserWind.o: $(SRCA)/UserWind.f90 makefile
${FC} ${CFLAGS} $(SRCA)/UserWind.f90 -o $(OUT)/$@
PitchControl.o: $(SRCF)/PitchCntrl_ACH.f90 makefile
${FC} ${CFLAGS} $(SRCF)/PitchCntrl_ACH.f90 -o $(OUT)/$@
SpeedControl.o: $(SRCF)/UserVSCont_KP.f90 makefile
${FC} ${CFLAGS} $(SRCF)/UserVSCont_KP.f90 -o $(OUT)/$@
 
Fast.o: $(SRCF)/FAST.f90 makefile
${FC} ${CFLAGS} $(SRCF)/FAST.f90 -o $(OUT)/$@
FastProg.o: $(SRCF)/FAST_Prog.f90 makefile
${FC} ${CFLAGS} $(SRCF)/FAST_Prog.f90 -o $(OUT)/$@
 

 

IMPORTANT: the makefile contains two variables, INLCUDE and LIBRARY: those are additional path to let compiler and linker know where your additional headers (.h) and lib files are stored (in this case we MUST add MATLAB header and lib files).

Change those variables to

INCLUDE = -I"yourdrive:\yourmatlab\extern\include"
LIBRARY = -L"yourdrive:\yourmatlab\bin\win32" -lmex -lmat -lmx

 

IMPORTANT: the proposed makefile has no optimization; to force hard optimization or customize the process a bit more follow G95 Manual instructions.

 

Finally, Photran has a view called Make targets in which you can link all targets from a makefile; once you have your makefile inside the SFunc folder just right-click on it then go to Make targets->Create and fill in with a name of your choice (FAST SFunc for me) and fasts for the target.

Double clicking on the target hopefully should build FAST602c_SFunc.mexw32 and put it inside SFunc folder.


fast_fortran

 

B. Autotools MAKEFILE

TODO

 

C. Managed MAKEFILE

This option creates a makefile starting from project dependent settings (toolchain, compiler, linker, etc...). At the time of writing, this is unusable feature for projects with multiple source files (so with FAST too) due to an error on compile/link dependencies order.

 

DOWNLOAD

MAKEFILE

FAST G95 Helpers (SysG95.f90, ModG95.f90)

 

Comments

avatar Scott Larwood
0
 
 
Hi Steffano, thank you for posting this information. I'm just trying to get a FAST executable compiled with G95. I got your make file for this from Jason's folder, but I don't understand what to do with it in Photran. I'll try to use your information here, but is there any other specific information I need?

Thanks,
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
Good Day. What other dungeon is so dark as one's own heart! What jailer so inexorable as one's self!
I am from Romania and also now'm speaking English, give true I wrote the following sentence: "Wellbutrin, only, i am speaking ever also better on this mentor."

Thank you so much for your future answers ;). Discontinuing wellbutrin.
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Scott Larwood
0
 
 
Hi Steffano,

With some effort I have my version of FAST compiled with G95 through Eclipse. My new problem is getting turbulent wind files read. Would you please let me know if you have problems reading full-field wind files.

Thanks,
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Scott Larwood
0
 
 
Found that I can read the binary wind files in G95 with ACCESS='STREAM' in the open command
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
Name *
URL
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Last Updated on Tuesday, 31 March 2009 12:32