Copyrights ©

  • 2010 - Alexey Petrov
  • 2009 - 2010 Pebble Bed Modular Reactor (Pty) Limited (PBMR)
  • GNU General Public License, version 3

Developers: Alexey Petrov, Andrey Simurzin


It comes from daily engineering practice. I mean the need to make OpenFOAM calculation environment more interactive and more automated at the same time.

It is hard to interact with OpenFOAM solver because of C++ code definition - it needs to be compiled before you could see the results of modifications you have made. How about the interactivity like in MatLab, where you can actually play with its functionality step by step, immediately see the results and analyze them?

To automate interaction with solver, to run an optimization scheme or benchmark calculations you need to invent your own "scripting" wheel. This wheel will be responsible for passing the data to and fro binary solver, controlling and analyzing the solver output, running the solver execution and stopping it. Do you have enough experience and time spent to?


pythonFlu is the Python wrapping for OpenFOAM C++ API. It enriches the existing OpenFOAM best features, such as expressiveness and robustness, with such unique advantages as interactivity and automation. Using pythonFlu you possess all the power of OpenFOAM; you have the same performance and use the same math-like notation. Certainly, pythonFlu neither provides a commonplace GUI interface nor os going to define a solver for you, however, it gives you much more - a unique engineering environment, where everything can be accessed and run under the same Python terms.


  • Moderates the existing steep OpenFOAM learning curve by substituting the initial C++ interface with an easy to learn Python one
  • Keeps the same performance as the referenced OpenFOAM C++ solvers. Even more, pythonFlu encourages solver developers to improve the original performance by avoiding unnecessary data duplication
  • Enables definition of OpenFOAM pure Python classes derived from the corresponding C++ ones
    (Allows you to define custom fvPathFields and "physical models", for example)
  • Makes it possible to distribute your pythonFlu solver code in a light-weight, portable, ready to use Python format
  • Supports different OpenFOAM versions and forks. So, if you have some preferences on account of OpenFOAM distribution, there should be no problem


To be able to use pythonFlu you need to have OpenFOAM and Python installed in your environment. Installation can be done either from pre-compiled binaries (available for Ubuntu from Launchpad) or from sources. If you prefer to compile from sources you need to have SWIG (tested with 1.3.36 - 2.0.4 version), GCC as well as about 2Gb RAM installed on your machine.


Python was chosen as the target wrapping language because of the following advantages :

  • This language is mostly used in scientific and engineering programming
  • Its code is easy to read, understand and learn how to program
  • ''Python code is typically 5-10 times shorter than the equivalent C++ code''
  • ''A Python programmer can finish in two months what two C++ programmers can't complete in a year''
  • Comes with a vast collection of libraries (standard and third-party ones)
  • Is very close to C++ and supports all modern programming features, like
    • Object Oriented Programming (classes, inheritance, virtual functions e.t.c )
    • Operators customization (the user can write a custom definition for '+' or '-')
    • Exception-based error handling

SWIG was chosen as wrapping generator because of the following advantages :

  • Widely used, robust and proven solution for wrapping of large scale projects
  • In the simplest cases does not require C++ codding at all (unlike [www.boost.org/libs/python/doc BoostPython])


pythonFlu comes with examples that reproduce corresponding OpenFOAM C++ solvers. See how pythonFlu simulates the referenced icoFoam C++ solver (*). By providing these solvers, pythonFlu demonstrates its basic capability to define the same functionality purely in Python. These examples are the best entry point to start and lay your hands on pythonFlu.

The more advanced example of pythonFlu potential is the integration of OpenFOAM and SALOME functionalities (*). SALOME does not know about OpenFOAM neither OpenFOAM does know about SALOME. As both of them can be reached through Python, it is possible to glue them up to define a complete engineering calculation development cycle starting from geometric CAD model definition and meshing up to sophisticated post processing. Python gives you a common ground to bind such different applications in a seamless way.


At the current moment there is one more library that can help OpenFOAM users to introduce some interactivity and automation in their calculation practice, namely PyFoam (by Bernhard Gschaider). "This library was developed to control OpenFOAM-simulations with a decent scripting language to do parameter-variations and results analysis". The difference between pythonFlu and PyFoam is that PyFoam interacts with solvers through the corresponding input files and console outputs, while pythonFlu defines the solver itself, therefore can directly access to all data you need and control the solver execution from inside.

Actually, pythonFlu and PyFoam can be successfully used in a combination. If you prefer to manage OpenFOAM functionality from the outside - PyFoam will suite you best. If you need to have precise and direct control on every point of solver execution - pythonFlu is the only choice.

Note : PyFoam handles pythonFlu defined solvers in the same way as referenced OpenFOAM ones.


In the nearest future pythonFlu will completely cover existing OpenFOAM C++ API. At the same time, the greatest power of pythonFlu lays in its interactive and automation capabilities. All these capabilities are going to be highlighted and implemented into other specific projects. pythonFlu will stay as a basis for the pythonFlu eco-system we are going to develop.