HowTo Use OpenFOAM with Eclipse

From OpenFOAMWiki
Revision as of 20:11, 22 November 2010 by Boroli (Talk | contribs)

Using Eclipse CDT for developing OpenFOAM

Please note: This offering is not approved or endorsed by OpenCFD® Limited, the producer of OpenFOAM® software and owner of the OpenFOAM® and OpenCFD® trademarks.

1 Thanks to ..

Patrik Eder for his help with setting up Eclipse and Holger Marschall for proofreading.

2 Versions

Operating system: openSuse 10.2

OpenFOAM version: OpenFOAM-1.6.x

Eclipse version: eclipse 3.5.1 (eclipse Galileo)

3 Eclipse Capabilities

"Eclipse is an open source community whose projects are focused on building an extensible development platform, runtimes and application frameworks for building, deploying and managing software across the entire software lifecycle. Many people know us, and hopefully love us, as a Java IDE but Eclipse is much more than a Java IDE." -

Eclipse is a powerful integrated development environment IDE originally developed for Java programming. But with the C/C++ Development Toolkit (CDT) extension Eclipse becomes a very common IDE for C++ programming.

If you want to work on a project in OpenFOAM, it is even not necessary to import the whole OpenFOAM-folder. Only import the project you are working on and the rest of the code will be linked for developing and debugging.

4 Aim of the tutorial

In this tutorial we will import a standard OpenFOAM solver and set up Eclipse for OpenFOAM. After a short introduction in Eclipse's developing features for applications and libraries, debugging in the Eclipse environment using the GNU Debugger GDB will be presented. Everything will be carried out with simpleFoam on the test case pitzDaily while having a look at the turbulence models as libraries.

5 Download and set up Eclipse

To start developing OpenFOAM with Eclipse just download the current version for C/C++ from This version already contains the C++ extension CDT (C/C++ Development Tools). Unpack the downloaded file and start Eclipse by clicking on the executable or start Eclipse from the terminal after setting the path variable.

For more information on CDT and CDT installation refer to Further information.

While launching create your own workspace or use the default workspace (for further information refer to Limit the number of sources). Change developing environment to C++ in the menu bar under Window -> Show View -> C/C++ Projects. Create a new C++ project in the menu bar under Files -> New -> C++ Project. A C++ project can be a test case, an application or a library of OpenFOAM. Deactivate Use default location, then select the folder you want to import. Set a name for your project. Click Finish.

Import simpleFoam

Now, set the OpenFOAM compiler properties for Eclipse. Right-click on your new project in the project explorer on the left side, select properties. Set the compiler command under C/C++-Build. Deactivate the default build command and type in OpenFOAM's wmake. Deactivate Generate Makefiles automatically. Set the build directory – maybe you have to remove the /Release or /Debug. Click OK. Make sure, that Project -> Automatically build in the menu bar is deactivated.

Set build command

6 Developing and compiling

Open your project folder in the project explorer and double-click a file, so the editor will open the file in the middle of your screen. You can now edit your file comfortably with the Eclipse text editor. Code highlighting for C++ is default setting.

User interface

The Eclipse editor offers some advantageous tool as the indexer that searches your workspace or project for variables and objects. Another tool is the automatic completion for functions. Call a class and set a „dot“ for a function after it, and you will be offered a list of available functions including parameters. This allows fast programming and avoids searching and jumping between windows. Errors and warnings are marked on the left side of the editor window. Additionally you can set bookmarks or tasks. But please keep in mind that the indexer works only for the imported parts of OpenFOAM.

On the right hand side you can select the outline tab, which presents you the outline of current functions, namespaces and files. (Hint: If the outline tab is missing select: Window -> Show View -> outline – this is valid for all views)

If you want to compile a certain part of your imported project, you must create a make target for Eclipse. Therefore select the make targets tab on the right side of the window. Select the folder where your Make folder is in, and create a new make target with the new make target button.

For compiling an application create a make target named wmake and leave the make target box plain. Build command is the default wmake -- corresponding to the console command wmake.

If you want to execute wclean, create a make target named wclean and leave the make target box plain again. Change the build command to wclean.

Execute your make target by double-clicking on it and watch the output in the console window.

wmake wclean

Now, create your own turbulence model as described in the OpenFOAM Wiki tutorial "How to use your own turbulence model" of the Special Interest Group (SIG) Turbomachinery. Import the library as C++ project as mentioned above. For compiling the new turbulence model using wmake libso in OpenFOAM, name your make target libso – the build command stays wmake. In analogous way create a wclean libso make target.

User interface - "wmake libso" target

7 Running applications and debugging

For testing a solver begin with importing the test case folder as a C++ project as mentioned before – you should run your preprocessing tools as blockMesh in the terminal on beforehand. Then set up the run configurations in the menu bar under Run -> Run Configurations. Choose your test case as project and your solver as application. Here, the test case pitzDaily is chosen as project and the solver simpleFoam is chosen as application. To start your simulation just click on the run button and follow the console output.

Run configurations

It is also possible to debug applications under Eclipse with the GNU Debugger gdb. Therefore you may need to compile your OpenFOAM version in the debug mode of the compiler. Change the compiler settings in OpenFOAM/OpenFOAM-1.6.x/etc/bashrc to debug with WM_COMPILE_OPTION:=Debug and compile OpenFOAM using ./Allwmake. This will take a few minutes.

Open the configurations for debugging under Debug -> Debug Configurations. Choose the same settings for project and application as for the run configurations. Finally make sure, that you are using the GDB (DSF) Create Process Launcher. If necessary, change it by clicking on hyperlink Select other.

Debug configurations

Start debugging by clicking on Debug. Now, the debug perspective should open – if not, activate it in the menu bar under Window -> Open Perspective -> Debug. The program should stop at the first breakpoint that is default set to the begin of main{}. Now you can set breakpoints by clicking on the bar left in the editor window. Restart debugging by clicking on the green play button. Watch the console output on the bottom, the variable values and breakpoints on the right hand side. Unfortunately, Eclipse isn’t able to display the values of vectors or even vector fields.

You can walk through the code line by line while Eclipse emphasizes the line of the file it is currently reading. Use step into and step over buttons as well as breakpoint to navigate through the code.

Debug perspective

8 Annotations and hints

8.1 Eclipse and python

Installing pydev, the python extension, enables Eclipse to define python projects and even use python with pyFOAM / OpenFOAM.

Therefore download the current pydev .zip-file (version 1.5.4 is recommended) from the sourceforge Unzip the file in the dropins folder and restart Eclipse. (for Eclipse 3.4 or 3.5)

For first steps follow the Getting Started Guide on

Alternative installation via Install new software:

- Select Help -> Install new software

- Click on Add Button

- Set pydev as name

- Enter as location

- Select ok and wait till site was contacted

- pydev is now available as installation option, select it, click on next and acknowledge everything

- Download and install will be executed

- pydev is available after restarting Eclipse

After installation a new project type pydev may be selected. Please make sure that upon creation Eclipse lists your pyFOAM project as pydev project. Otherwise the wrong indexer may be used. If so right click your project in the projects tab, select the entry pydev and set as pydev project. This will link the project with the python backbone.

8.2 Working in parallel with the terminal

You can still work on your project in the console, but if you then switch to Eclipse again, don't forget to refresh your workspace (F5). This may take a few seconds.

8.3 Increase Java heap space for Eclipse

If you get out-of-memory errors from Eclipse you may have to increase Java heap space for Eclipse in the eclipse.ini file, which manages start options for Eclipse. This error may occur if your OpenFOAM project is to big in size. For further information have a look at:

For example increase the heap space to 1024 MB and minimum size of 256 MB, PermGenSize is 1024 MB.


Use top command for watching heap space usage in linux console.

8.4 Limit the number of sources

It is advisable to keep the number of projects per workspace small. If you include a large number of projects with many sources the start up and usage will slow down due to the indexer thread. You can work with multiple workspaces, Eclipse will ask you at start up which you want to use, its also possible to spread a project over multiple workspaces by importing (don't copy!) it in several workspaces.

8.5 Further information

Eclipse homepage:

Eclipse CDT Wiki:

Eclipse tutorial:

All of this information in Presentation form: eclipseTutorial.pdf

-- by A. Mahrla, 5 May 2010