Fluiddyn: A Python Open-Source Framework For Research and Teaching in Fluid Dynamics by Simulations, Experiments and Data Processing
Fluiddyn: A Python Open-Source Framework For Research and Teaching in Fluid Dynamics by Simulations, Experiments and Data Processing
Fluiddyn: A Python Open-Source Framework For Research and Teaching in Fluid Dynamics by Simulations, Experiments and Data Processing
SOFTWARE METAPAPER
FluidDyn is a project to foster open-science and open-source in the fluid dynamics community. It is thought
of as a research project to channel open-source dynamics, methods and tools to do science. We propose a
set of Python packages forming a framework to study fluid dynamics with different methods, in particular
laboratory experiments (package fluidlab), simulations (packages fluidfft, fluidsim and fluidfoam)
and data processing (package fluidimage). In the present article, we give an overview of the specialized
packages of the project and then focus on the base package called fluiddyn, which contains common
code used in the specialized packages. Packages fluidfft and fluidsim are described with greater detail
in two companion papers [4, 5]. With the project FluidDyn, we demonstrate that specialized scientific
code can be written with methods and good practices of the open-source community. The Mercurial
repositories are available in Bitbucket (https://bitbucket.org/fluiddyn/). All codes are documented using
Sphinx and Read the Docs, and tested with continuous integration run on Bitbucket Pipelines and Travis. To
improve the reuse potential, the codes are as modular as possible, leveraging the simple object-oriented
programming model of Python. All codes are also written to be highly efficient, using C++, Cython and
Pythran to speedup the performance of critical functions.
Keywords: Fluid dynamics research with Python; Numerical simulations; Laboratory experiments; Free and
open-source software; modular; object-oriented; collaborative; efficient; tested; documented
Funding statement: This project has indirectly benefited from funding from the foundation Simone et Cino
Del Duca de l’Institut de France, the European Research Council (ERC) under the European Union’s Horizon
2020 research and innovation program (grant agreement No 647018-WATU and Euhit consortium) and the
Swedish Research Council (Vetenskapsrådet): 2013-5191. We have also been able to use supercomputers
of CIMENT/GRICAD, CINES/GENCI (grant 2018-A0040107567) and the Swedish National Infrastructure
for Computing (SNIC).
The computer performance continues to increase rapid development cycle made the need to decentralize
exponentially, now also with the help of Graphical FluidDyn evident. Now, FluidDyn project hosts a number
Processing Units (GPU). This gave way to a big boom in of specialized packages, namely:
practical uses of data science and machine learning, which
drives a strong research on artificial intelligence. Such • fluiddyn3: The base package which contains
developments contribute to progresses in open-source pure-python code that can be reused in scripts or in
software. To summarize, there is a strong dynamics in specialized FluidDyn packages. It also contains codes
play around the use of computers (in particular with the for miscellaneous command-line utilities useful for a
web) and this creates very efficient tools and methods for typical fluid dynamics user.
collective work and software development. The code of this package is presented in further
These changes in our world also reflect in the way detail in its documentation (https://fluiddyn.readthe-
science is done. Software and programming in science docs.io/) and some prominent features are presented
occupy a much bigger place than before. The role of in the following subsection.
software in science has changed. In the past, coding • Transonic: a pure Python package to accelerate
was sometimes considered as an inferior activity by Python-Numpy code with Pythran and potentially
some scientists. The focus was on the theory and the other Python compilers.
mathematical demonstration, which had to be elegant as • fluidfft (see the companion paper [4]): a package
it gets included in the articles. In contrast, it was normal to which provides C++ and Python classes unifying vari-
write crude code and to just show the results. Nowadays, ous libraries to perform Fast Fourier Transform (FFT)
codes tend to be at the heart of research. in sequential and in parallel.
“Open-science” is a new trend taking advantage of these • fluidsim (see the companion paper [5]): Numerically
new facts. Pioneering attempts are being made to do better oriented framework to run sequential and parallel
science, improving reproducibility and collective efficiency, Computational Fluid Dynamics (CFD) simulations and
by using the open-source methods and tools for science on-the-fly post-processing for a variety of problems
and sharing and collaborating via the world wide web. (Navier-Stokes, Shallow Water, Föppl von Kármán
FluidDyn is a project to foster open-science and equations, to name a few). A study using fluidsim
open-source coding in Python in the field of fluid mechanics. has just been published in Physics of Fluids [3].
The project envisages to provide the technical framework • fluidlab: Package to handle laboratory experiments.
to allow collaborative development of tools useful for the Primarily used to communicate with various hard-
fluid mechanics community, and to do science with open ware devices such as motors and pumps, to handle
methods. We provide examples of solutions for: I/O between sensors, and to store data. Experiments
using fluidlab have been carried out in the DAMTP
• Good coding practice with readable and easy to fluid laboratory (Cambridge, UK. cf [2]), in ENS Lyon
comprehend Python code (PEP 8). laboratory (Lyon, France [6]) and at LEGI (Grenoble,
• Source control management (Mercurial) and forge France [1]).
(Bitbucket) simple for the newcomers. • fluidimage: Scalable image processing package
• Packaging and installation procedure. All packages which implements various algorithms to calibrate
are available from PyPI and can be install simply with cameras, to preprocess images, to do Particle
pip, the standard Python installation tool. Image Velocimetry (PIV) and to postprocess data.
• Licenses: depending on the packages, we choose fluidimage is used to process images taken during
to use the CeCILL-B or the CeCILL licenses. These experiments performed in the Coriolis platform at
licenses are compatible respectively with BSD and LEGI [1].
GPL licenses and adapted to both international and • fluidfoam: Small package to load OpenFoam data
French legal matters.2 and plot them.
• Documentation produced with standard and up-to-date • fluidcoriolis: Small package used to carry out
tools: Sphinx, Anaconda and Jupyter. Built and hosted experiments in the Coriolis platform (a large rotating
online at Read the Docs. Can also be generated offline. platform participating in the European consortiums
• Unittest and continuous integration with Bitbucket Euhit and Hydralab) and open the data obtained (see,
Pipelines and Travis. for example [1]). One of the motivations behind creat-
ing this package is to study how to use open-source to
We hope that such a clean framework will facilitate create and share open-data.
contributions from scientists in the field and that we can
build together a nice, user-friendly and efficient ecosystem A detailed presentation on the above packages can be
specialized in research and teaching in fluid dynamics. found in their respective documentations on the web
and for fluidfft and fluidsim in the two companion
Implementation and architecture papers [4, 5]. The code base was designed to follow
Organization of the code in packages Python 2.7 syntax during its genesis. Now, it has been
FluidDyn was originally intended to be a single package to made forward compatible with Python 3 through the
perform experiments and simulations. Since a typical user use of external package future. We now tend to abandon
may not be involved in both experiments and simulations Python 2.7 support for the next releases of the package.
and also, due to increasing complexity as a virtue of This article will now focus on the base package fluiddyn.
Augier et al: FluidDyn Art. 9, page 3 of 6
API of the Python library fluiddyn The classes of this module allows one to do it with a quite
All functions and classes defined in fluiddyn are pure simple and general API as shown in the tutorial on the
Python elements, meaning that no extensions are module.
implemented in fluiddyn. Thus the package fluiddyn
is extremely easy to install with just a pip install Module fluiddyn.util.mpi
command and no compilation. This simple module makes simultaneous sequential
The package fluiddyn is organized into five and MPI programming a breeze by providing number of
sub-packages: processes, nb_proc = 1 and rank = 0, when used
in sequential mode, otherwise providing the appropriate
• fluiddyn.io: This subpackage provides utilities for values provided by mpi4py package. Use of this module
input/output to different file formats. thwarts coding several if-else clauses. If the program was
• fluiddyn.util: Miscellaneous utilities. using MPI, also defines the variable comm as an alias for
• fluiddyn.calcul: Modules for numerical compu- the MPI.COMM_WORLD communicator.
tations.
• fluiddyn.clusters: Classes to launch jobs on Module fluiddyn.calcul.easyfft
HPC clusters. Thin wrapper for an unified API using classes around the
• fluiddyn.output: Utilities to produce scientific packages pyfftw and scipy.fftpack. It is very easy
outputs (figures and videos). to perform forward and inverse Fast Fourier Transforms
(FFT) in one-, two- and three-dimensions. The FFT can be
Sub-packages io, util and calcul are the largest multithreaded if the environment variable OMP_NUM_
in terms of lines of code and provides the Application THREADS is defined.
Programming Interfaces (API) to support fluidsim,
fluidlab and fluidimage. For the sake of brevity, we shall The fluiddyn command-line utilities
only describe here some of the most important modules. The package fluiddyn also provides few command-line
utilities to perform simple tasks useful for a scientist
Module fluiddyn.util.paramcontainer developing with Python and using the FluidDyn
Sub-package paramcontainer defines class packages.
ParamContainer which is a hierarchical container for
any type of parameters. As shown in this tutorial, various • fluidinfo
strengths of an object of this class include: Displays important information related to software
and hardware. It includes detailed information such
• Support containing and printing documentation on as currently installed FluidDyn packages, other third-
the parameters. party packages, C compiler, MPI and Numpy configu-
• Support printing to console as XML and saving as ration.
XML, HDF5 and NetCDF Files. • fluiddump
• Evaluate data types automatically while loading from Utility to print the hierarchy of HDF5 and NetCDF
saved files. files. It does not depend on the NetCDF4 library.
• Easy exploration in an interactive console. • fluidnbstripout
• Allows modification of default parameters through Very simple layer to stripout Jupyter notebooks of
simple Python script files. An error is raised if the user output, which is useful to keep the notebooks light-
attempts to use an invalid parameter. weight when included in a repository. This tool is
• Graphical User Interface (GUI) frontend with PyQt. based on nbstripout but, in contrast to nbstripout,
by default the notebooks with a file name ending as
Thus, it makes it a much more robust implementation ‘.nbconvert.ipynb’ are excluded.
for saving key parameters, compared to conventional • fluidcluster-help
methods which rely on text or CSV files. Tiny utility to print a short documentation on the
most useful commands to interact with the scheduler
Module fluiddyn.util.serieofarrays of a HPC cluster.
This module provides classes to iterate over files. It is a • fluidmat2py
common task in data processing to understand how to Utility to produce a strange code which is no longer
organize a sequence of files from filenames and formats. Matlab and not yet Python. This strange code is then
Typically, one has to form smaller sets of arrays contained much easier to translate into correct Python than the
in the files. For example, we may have a sequence such as: original Matlab code.
How to cite this article: Augier, P, Mohanan, A V and Bonamy, C 2019 FluidDyn: A Python Open-Source Framework for
Research and Teaching in Fluid Dynamics by Simulations, Experiments and Data Processing. Journal of Open Research
Software, 7: 9. DOI: https://doi.org/10.5334/jors.237
Copyright: © 2019 The Author(s). This is an open-access article distributed under the terms of the Creative Commons
Attribution 4.0 International License (CC-BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium,
provided the original author and source are credited. See http://creativecommons.org/licenses/by/4.0/.