Pierre Augier, Ashwin Vishnu Mohanan,
Arman Khoubani, Pooria Danaeifar
Journées thématiques de la Société Française de Thermique, 3-4 July 2023



Me: CNRS researcher
lab experiments fluidlab |
image processing fluidimage |
simulations fluidsim |
performance transonic |
Fluidsim: user centric CFD framework
internal solvers mostly based on pseudo-spectral methods
fluidsim-core: library to build solvers from any methods and codes
For Arman Khoubani’s PhD thesis… 2 new Python packages:
Snek5000 (general framework)
Snek5000-cbox (solver convection in a box)
Collaboration with Ashwin Vishnu Mohanan (Stockholm university)
A new Python package
Improve user experience for all aspects of numerical studies using Nek5000
Good quality software:
tested (coverage > 95%), documented, modular, user centric
A new workflow for Nek5000
Success for our study on instabilities in vertical convection!
Tens of simulations with complex relations
Advanced postprocessing with Python
0 Nek5000 user…
many OpenFOAM users…
So let’s build a Fluidsim framework for OpenFOAM! (Master 2 internship, Pooria Danaeifar)

A (very) new Python package
Improve user experience for all aspects of numerical studies using OpenFOAM
Good quality software:
tested (coverage > 95%), documented, modular, user centric
A new workflow for OpenFOAM

2 CFD open-source community driven frameworks
Great tools
Avoid manual copy and edition of OpenFOAM/Nek5000 input files
Split the workflow in 2 steps
Described sets of potential simulations
Create the directory/files for 1 particular simulation and launch it
Integrated object oriented API (sim object)
Share and reuse more than just the core CFD codes
The set (and the associated parameters) are described in a small Python package called a “Fluidsim solver”
Warning for Openfoam users
“Fluidsim solver” and “OpenFOAM solvers” are very different things!
1 script with arguments to launch different simulations
Automation of case generation, simulation launching and postprocessing (parametric studies, optimization, …)
Programmatic generation of complex and parametrized input files (for example blockMeshDict) and initial conditions
Programmatic control of simulations at runtime (example here)
Simple visualisations (figures and movies) with 1 line of Python
Install
Launch a simulation with an existing solver
Reload a sim object for runtime control / post-processing / plots
Create a new Fluidsimfoam solver from a case
Require Python >=3.9
Clone NEK5000 code and pip install snek5000-cbox
Install OpenFOAM and pip install fluidsimfoam
Run a script (or notebook) with
Content of the script:
from fluidsimfoam_dam import Simul
params = Simul.create_default_params()
params.output.sub_directory = "tuto_fluidsimfoam/dam"
params.control_dict.end_time = 4.0
params.parallel.method = "simple"
params.parallel.nsubdoms = 2
params.parallel.nsubdoms_xyz = [2, 1, 1]
params.constant.transport.water.nu = 0.5e-6
params.block_mesh_dict.height_dam = 0.5
params.block_mesh_dict.width_dam = 0.2
params.block_mesh_dict.nx = 80
params.block_mesh_dict.ny = 80
# creation of the simulation directory
sim = Simul(params)
# run the simulation (i.e. all necessary OpenFOAM commands)
sim.make.exec("run")
# or for programmatic control of the simulation
# sim.make.exec_async("run")sim objectApplications: runtime control / post-processing / plots
In a terminal:
which gives:
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.14.0 -- An enhanced Interactive Python. Type '?' for help.
Loading simulation
path_run: /home/users/me/Sim_data/tests_fluidsimfoam/dambreak/dambreak_run_2023-06-08_14-56-26
INFO sim: <class 'fluidsimfoam_dambreak.Simul'>
sim.output.log: <class 'fluidsimfoam.output.log.Log'>
sim.output.fields: <class 'fluidsimfoam.output.fields.Fields'>
input_files:
- in 0: U alpha_water p_rgh
- in constant: g transportProperties turbulenceProperties
- in system: blockMeshDict controlDict decomposeParDict fvSchemes fvSolution sampling setFieldsDict
sim.output: <class 'fluidsimfoam_dambreak.output.OutputDambreak'>
sim.oper: <class 'fluidsimfoam.operators.Operators'>
sim.init_fields: <class 'fluidsimfoam.init_fields.InitFields'>
sim.make: <class 'fluidsimfoam.make.MakeInvoke'>
`sim`, `params`, `np`, `plt` and `pd` variables are available
In [1]:
sim objectThen, in IPython shell:
sim.params
sim.stop_time_loop()
sim.output.log.plot_clock_times()
sim.output.log.time_last
# Change a parameter affecting just one file:
sim.params.control_dict.end_time = 2
sim.input_files.control_dict.generate_file()
# Get the cells coordinates
x, y, z = sim.oper.get_cells_coords()
# Read output fields:
field = sim.output.fields.read_field("U", time_approx="last")
vx, vy, vz = field.get_components()
# Plots
sim.output.plot_coutour("alpha.water", time=0.4)
sim.output.plot_profile()fluidsimfoam-dam solver was created?fluidsimfoam-initiate-solver dambreak \
-c $FOAM_TUTORIALS/multiphase/interFoam/laminar/damBreak/damBreakOpenFOAM users, try it for one of your case!
Errors? Create an issue here: https://foss.heptapod.net/fluiddyn/fluidsimfoam/-/issues
fluiddyn, fluidimage, fluidlab, fluidsim…
and two promissing kids!
Become community projects?
We need to build a community of users (creating issues and feature requests), contributors and core developers.
If you are interested, do not hesitate to (i) star the projects and (ii) open issues!