Laboratory experiments in the Coriolis platform with Python

       

Pierre Augier, A. Vishnu (KTH), C. Bonamy, A. Campagne, J. Sommeria, S. Viboud, C. Bonamy, N. Mordant (ERC Watu)...


Journée Python Sciences and Data in Grenoble, 8/03/2018
http://www.legi.grenoble-inp.fr/people/Pierre.Augier/python-science-data-grenoble-launching-day.html


$\newcommand{\kk}{\boldsymbol{k}} \newcommand{\eek}{\boldsymbol{e}_\boldsymbol{k}} \newcommand{\eeh}{\boldsymbol{e}_\boldsymbol{h}} \newcommand{\eez}{\boldsymbol{e}_\boldsymbol{z}} \newcommand{\cc}{\boldsymbol{c}} \newcommand{\uu}{\boldsymbol{u}} \newcommand{\vv}{\boldsymbol{v}} \newcommand{\bnabla}{\boldsymbol{\nabla}} \newcommand{\Dt}{\mbox{D}_t} \newcommand{\p}{\partial} \newcommand{\R}{\mathcal{R}} \newcommand{\eps}{\varepsilon} \newcommand{\mean}[1]{\langle #1 \rangle} \newcommand{\epsK}{\varepsilon_{\!\scriptscriptstyle K}} \newcommand{\epsA}{\varepsilon_{\!\scriptscriptstyle A}} \newcommand{\epsP}{\varepsilon_{\!\scriptscriptstyle P}} \newcommand{\epsm}{\varepsilon_{\!\scriptscriptstyle m}} \newcommand{\CKA}{C_{K\rightarrow A}} \newcommand{\D}{\mbox{D}}$

Laboratoire des Ecoulements Géophysiques et Industriels

Geophysical fluid dynamics: atmosphere, oceans, lacs, rivers, ...

  • Fluids: Navier-Stokes equations

    $\p_t \vv + \vv\cdot\bnabla\vv = - \bnabla p + \nu \bnabla^2 \vv,$

    plus rotation, density stratification, etc.

  • (anisotropic) turbulence

  • Tools and methods:

    • theory
    • simulations
    • experiments

FluidDyn project

A project to foster open-science and open-source in fluid mechanics

   

A thesis:

  • open-source never so strong,
  • new tools and methods allowing collective work,
  • possibility of collaborations on good quality research codes (not simple for scientists).

Some FluidDyn Python packages (1)

fluiddyn

Pure-python code that can be reused in scripts or in specialized FluidDyn packages. Miscellaneous command-line utilities.

fluidfft

C++ and Python classes useful to perform Fast Fourier Transform (FFT) in sequential and in parallel.

fluidsim

Computational Fluid Dynamics (CFD) Python framework (mainly pseudo-spectral methods).

Some FluidDyn Python packages (2)

fluidlab

For laboratory experiments. Communication with various hardware devices such as motors, sensors, pumps.

fluidimage

Scalable image processing: calibrate cameras, preprocessing images, Particle Image Velocimetry (PIV) and processing of velocity fields.

fluidcoriolis

Experiments in the Coriolis platform and Open Data.

fluidfoam

Loading, plotting and processing of OpenFoam data.

FluidDyn project

Examples for

  • Good coding practice: readable and understandable Python code (PEP 8).
  • Source control management (Mercurial) and forge (Bitbucket) simple for the new comers.
  • Packaging and installation procedures.
  • Licenses: depending on the packages, CeCILL-B or CeCILL licenses.
  • Documentation sites produced with the standard and up-to-date tools:
    Sphinx, Readthedocs, Anaconda and Jupyter.
  • Unittest and continuous integration with Bitbucket Pipeline and Travis.

Conditions for collaborative development!

Numerical simulations, pseudo-spectral methods

  • periodic: based on Fast Fourier Transforms
  • fast and very accurate


Standard method: Fortran codes

  • highly efficient (HPC)
  • monolythic, highly specialized (nearly one code per research group...)
  • not so user friendly


FluidDyn Python packages: fluidfft and fluidsim

  • versatile
  • user and developer friendly
  • efficient (HPC)

fluidfft

Fast Fourier Transform (FFT) in sequential and in parallel, with CPU and GPU.

  • Hierarchy of C++ classes to use different FFT libraries.

  • Cython wrappers of the C++ classes. Cython .pyx and .pdx files produced from template files using the template library mako.

  • Python operators classes (2d and 3d) to write code independently of the library used for the computation of the FFT.

  • Pythran to speedup critical code. Performance $\simeq$ Fortran.

  • Commandline utilities (fluidfft-bench and fluidfft-bench-analysis).

  • Unittest !

fluidsim

Python framework to run sequential and parallel (MPI) Computational Fluid Dynamics (CFD) simulations and on-the-fly processing for a variety of problems (Navier-Stokes, Shallow Water, Föppl von Kármán equations, ...).

  • highly modular, object-oriented structure (solver, state, time stepping, output, ...),

  • specialized in pseudo-spectral methods (based on fluidfft),

  • very user friendly,

  • very efficient (much faster than Dedalus, faster than SpectralDNS).

Laboratory experiments with Python, the example of the Coriolis platform

The Coriolis platform
(13 m diameter)
Used by international researchers through European projects (Euhit, Hydralab).

The MILESTONE experiment

Stratified and rotating turbulence in the Coriolis platform

 2 sets of experiments

  • Summer 2016 (a collaboration between KTH, Stockholm, Sweden and LEGI).

  • Summer 2017: focused on mixing without rotation

Top view (MILESTONE 2016)

A new carriage for the Coriolis plateform

  • 3 m $\times$ 1 m
  • runs on tracks (13 m long)
  • good control in position ($\Delta x<$ 5 mm) and in speed ($U< 25$ cm/s)

Measurements: PIV and probes (density, temperature)

scanning PIV
probes on traverses

Using computers for laboratory experiments

  • Many drivers, libraries and software only for Windows
  • Labview and Matlab

Using Python and open-source solutions

  • A community of hackers!

  • Python packages for

    • communication protocols: pyserial, pyvisa, modbus, ...
    • library wrappers: pydaqnx for NI boards, ...
    • GUI: matplotlib, PyQt, Qtgraph, ...
    • microservices: rpyc, xmlrcp, ...
  • async, await and asyncio for asynchronous input/output (see asyncio in autolib's car)

  • Arduino, Micropython for microcontrollers, Raspberry Pi

  • Python friendly companies (Labjack for acquisition boards, ...)

  • Python packages for experiments (control instruments, ...): fluidlab, lantz, place

See also this presentation on Factory Automation with Python...

Example of the carriage in the Coriolis platform

Equipment

  • Motor and its servo drive Lexium LXM32 (Schneider Electric)
  • Position sensor: quadrature signal via an acquisition board LabJack U3-HV

Software solutions (in fluidlab and fluidcoriolis)

  • For the LXM32:
    • communication modbus TCP (pymodbus)
    • I/O-Scanning (regular ping pong between LXM32 and the computer)
  • 3 servers with rpyc (motor, position sensor and carriage)
  • control of the carriage via Ipython
  • GUI (using a carriage client) with PyQt (made with qtdesigner)

Example of the 3D-2C PIV in the Coriolis platform

PIV: Particle Image Velocimetry

Equipment

  • Labjack T7 acquisition board
  • Oscillating mirror
  • Powerfull laser
  • Cameras

Software solutions

  • Simple functions to control the mirror and trigger the cameras via the T7 board (in fluidlab).

  • PIV processing with fluidimage

fluidimage: scientific processing of images

Many images (~ 20 To of raw data): embarrassingly parallel problem

  • Open-source
  • Clusters and PC, with CPU and/or GPU
  • Asynchronous computations

    • topologies of tasks
    • IO and CPU bounded tasks are splitted
  • Efficient algorithms and tools for fast computation with Python (Pythran, Theano, Pycuda, ...)

  • Images preprocessing

  • 2D PIV, scanning PIV, stereo PIV, BOS

  • Utilities to display and analyze the PIV fields

    • Plots of PIV fields (similar to PivMat)
    • Calcul of spectra, anisotropic structure functions, characteristic turbulent length scales


Remark: highly inspired by PivMat (F. Moisy) and UVmat (J. Sommeria), that we continue to use, in particular for calibration

Calcul of scanning PIV on the LEGI cluster

Example of scripts to launch a PIV computation:


from fluidimage.topologies.piv import TopologyPIV

params = TopologyPIV.create_default_params()

params.series.path = '../../image_samples/Karman/Images'
params.series.ind_start = 1
params.piv0.shape_crop_im0 = 32
params.multipass.number = 2
params.multipass.use_tps = True
# params.saving.how has to be equal to 'complete' for idempotent jobs
# (on clusters)
params.saving.how = 'complete'
params.saving.postfix = 'piv_complete'

topology = TopologyPIV(params, logging_level='info')
topology.compute()

Calcul of scanning PIV on the LEGI cluster

Remark: launching computations on cluster is highly simplified by using fluiddyn:


from fluiddyn.clusters.legi import Calcul7 as Cluster

cluster = Cluster()

cluster.submit_script(
    'piv_complete.py', name_run='fluidimage',
    nb_cores_per_node=8,
    walltime='3:00:00',
    omp_num_threads=1,
    idempotent=True, delay_signal_walltime=300)


On another cluster, for example Froggy (Ciment, GRICAD), change the first line as:

from fluiddyn.clusters.ciment import Froggy

Analysis, production of scientific figures, Open-Data

  • For one experiments, a lot of different files for different types of data (txt and hdf5 files)
  • Classes for experiments and types of data (for example probe data or PIV field).
In [4]:
from fluidcoriolis.milestone17 import Experiment as Experiment17
iexp = 21
exp = Experiment17(iexp)
exp.name
Out[4]:
'Exp21_2017-07-11_D0.5_N0.55_U0.12'
In [5]:
print(f'N = {exp.N} rad/s and Uc = {exp.Uc} m/s')
N = 0.55 rad/s and Uc = 0.12 m/s
In [6]:
print(f'Rc = {exp.Rc:.0f} and Fh = {exp.Fhc:.2f}')
Rc = 11425 and Fh = 0.44
In [7]:
print(f'{exp.nb_periods} periods of {exp.period} s')
3 periods of 125.0 s
In [8]:
print(f'{exp.nb_levels} levels for the scanning PIV')
5 levels for the scanning PIV

Studying and plotting PIV data

In [9]:
from fluidcoriolis.milestone import Experiment
exp = Experiment(73)
In [10]:
cam = 'PCO_top'  # MILESTONE16
pack = exp.get_piv_pack(camera=cam)
In [11]:
piv_fields = pack.get_piv_array_toverT(i_toverT=80)
/home/pierre/16MILESTONE/Data_light/PCO_top/Exp73_2016-07-13_N0.8_L6.0_V0.16_piv3d/v_exp73_t080.h5
In [12]:
piv_fields = piv_fields.gaussian_filter(0.5).truncate(2)
In [13]:
piv = pack.get_piv2d(ind_time=10, level=1)
piv = piv.gaussian_filter(0.5).truncate(2)
piv.display()
_ = plt.xlim([-1.7, 0.5])
_ = plt.ylim([-1.3, 1.3])

Conclusions

  • We can do several things with Python

  • Even studying fluid dynamics

   


8 March: International Women Day... And for PySciDataGre ?