Copyrights ©

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


It comes from daily engineering practice - the need to make OpenFOAM calculations more interactive and automated at the same time. As it appears, the referenced OpenFOAM C++ API is not the best point to start from.

Surely, it is hard to define a really interactive application on top of C++ code. Such code needs to be compiled and run before user could see the results of modifications have been made. How about the interactivity like MatLab, where user can actually play with its functionality step by step, immediately see the results and analyze them?

Also, in case of C++ defined solvers, to be able to run an optimization scheme or benchmark calculations, user need to invent its own "scripting wheel". This "scripting 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. Not every user has enough experience and time to to develop such functionality.

pythonFlu is targeted to provide strong and scalable basis to fulfill all the mentioned requirements; to be able to make user interaction with OpenFOAM functionality really handy and automated.


pythonFlu provides Python wrapping for OpenFOAM C++ API. It enriches the existing OpenFOAM best features, such as expressiveness and robustness, with such unique Python advantages as interactivity and automation. pythonFlu delivers unique engineering environment, where everything can be accessed and run in 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
  • Encourages solver developers to improve the original performance by avoiding unnecessary data duplication
  • Supports scalable application development though usage of an advanced memory management technology (see, managedFlu, for more details)
  • Allows to define pure Python classes derived from corresponding OpenFOAM C++ ones (definition of custom fvPathFields and "physical models", for example)
  • Makes it possible to distribute pythonFlu based solver code in a light-weight, portable, ready to use Python format
  • Supports different OpenFOAM versions and forks


To be able to use pythonFlu it is necessary to have OpenFOAM and Python packages installed. The easiest way to install pythonFlu is from binaries (available for Ubuntu Linux through Launchpad). In case of installation from sources it additionally requires SWIG (tested with 1.3.36 - 1.3.40 and 2.0.3 - 2.0.6), GCC compiler and about 2Gb RAM.


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

  • This language traditionally preferred for scientific and engineering programming
  • Python 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 semi-automatic wrapping of large scale C++ projects
  • In the simplest cases does not require C++ codding at all (unlike BoostPython)


pythonFlu comes with a set of Python solvers that imitate the corresponding OpenFOAM ones. See, for example, how pythonFlu simulates the referenced icoFoam C++ solver (*). By providing these Python solvers pythonFlu demonstrates its capability to define the same OpenFOAM related functionality but completely through the Python. These examples are the best entry point to start with.

The more advanced pythonFlu example is an integration of OpenFOAM and SALOME functionality (*). SALOME does not know about OpenFOAM neither OpenFOAM knows about SALOME. As both of them can be reached through corresponding Python API, it is possible to glue them up to define a complete engineering workflow starting from geometric CAD model definition and meshing up to sophisticated post processing. Python provides a common ground to bind such different applications in a seamless way.


At the current time there is one more library that can help OpenFOAM users to introduce some kind of interactivity and automation in their engineering 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 some external channels (the corresponding input files and console outputs), while pythonFlu defines the solver itself, therefore can directly access to all its data user 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 can handle pythonFlu defined solvers in the same way as referenced OpenFOAM ones.


pythonFlu is heading towards the complete covering of the referenced OpenFOAM C++ API. Such unique pythonFlu capabilities as interactivity and automation will be evolved through other specific projects. pythonFlu will stay as a basis for the pythonFlu eco-system is going to be developed.