Opensource CFD with OpenFOAM & Scilab

OpenFOAM is a well known open-source Computational Fluid Dynamics (CFD) solution constantly evolving and able to compete with most famous industrial solutions on the market, like Fluent® or StarCCM+®. Besides having an extensive range of features to solve anything from complex fluid flows involving chemical reactions, turbulence and heat transfer, to acoustics, solid mechanics and electromagnetics, OpenFOAM offers a solid documentation from software installation to first steps with already set-up cases and tutorials.


Considering that the OpenCFD and the Scilab Teams are now part of ESI Group, we now have the potential of developing new solutions leveraging the assets of both software giving Scilab and OpenFOAM users the opportunity to bring their simulation to a whole new level. Here is a first quick tutorial for an elementary use of OpenFOAM together with Scilab.

Installing OpenFOAM

As said, the documentation is great. So see this link to download and compile OpenFOAM source code.

Quick introduction to the OpenFOAM process

OpenFOAM simulation setup is made through a set of text files called Dictionaries and located in a specific case directory.

As shown on above image, this case directory is divided into:

  • System directory: simulation parameters, schemes
  • Constant directory: mesh and flow properties definition
  • Time directories: needed field for specific time steps

Dictionaries are meant to be parameters for OpenFOAM utilities and solvers that are applications. For any application, the form of the command line entry can be found by simply entering the application name at the command line with the -help option. You just have to run it specifying (or not) your case directory.

Since those are regular text files, they can be completed created or modified through the Scilab command line interface with functions such as write.

See OpenFOAM User Guide and Tutorial Guide for more information.

OpenFOAM & Scilab make simulation rock together

Let’s see how to make basic interactions between Scilab and OpenFOAM. Our case for this example is a NACA 0012 airfoil simulated at different angles of attack.

  • Workspace

Considering that every OpenFOAM application (solvers & utilities) can be used on any directory using the parameter -case, you can work anywhere you want. In this example we will work in the airfoil case directory and will start by creating a new directory called Results, in which we will gather the pressure on the mesh for a defined set of angles of attack.

Now it’s scripting time:

  • OpenFOAM applications

With OpenFOAM source code compiled, you have access to all of the OpenFOAM applications just by calling them in the command line terminal. In order for it to work, you just have to “source” the OpenFOAM bashrc file. To do so, simply use the unix function for shell command execution in Scilab:


  • Simulation set-up from Scilab

This case is about studying a NACA 0012 airfoil behavior within a stream characterized by: Reynolds number = 3M, Mach number = 0.15 (V = 51.9m/s) and the set of angles of attack = -1, 0, 1, 2, 8, 15, 16, 17, 18, 19, 20 and 21 deg.

Now the idea is to change the velocity U in the 0 time directory and run the simulation for all cases using a for loop.

First, make sure to clean your time directories before you run a simulation using a classical Allclean file (you can find in every OpenFOAM tutorial) or making it your self using the unix command rm -rf. Once this is done, you can change your initial condition regarding the velocity using what you computed earlier:

Note that line 17, 19 & 21 of U file are just about adding blank space.

Now run your case using the OpenFOAM solver you need. If you are running your simulation parallel just use the decomposePar utility first and the reconstructPar utility for reconstruction.

Notaunix_w function is the same as the unix function but display shell outputs in Scilab shell.

Now just extract your pressure field at the last iteration (4000 here) and put it in the Resultsdirectory you created earlier. So shall your loop end.

  • Post-processing

It is now time for you to post-process your data leveraging OpenFOAM capabilities (postProcess utility) combined with Scilab specific features in signal processing, optimization, control system, etc …

Scilab plot of pressure field for angle of attack: 0, 8, 17 and 20 deg


This tutorial was just a quick introduction on how to make a combined use of OpenFOAM and Scilab to achieve powerful CFD simulation and analysis. Try this on your own and do not hesitate to share the ideas and issues you face with both communities. More tools and tutorials are coming on that same topic.