Capytaine : a Python-based linear potential flow solver

Assuming an incompressible, inviscid and irrotational flow, the fluid motion can be modeled by a scalar field φ, called velocity potential and such that u = ∇φ. The conservation of the mass of the fluid can be written as a Laplace problem ∇φ = 0 . Assuming small motions of the floating body and small wave heights, the boundary condition at the free surface can be linearized. The resulting problem is fully linear and can be solved in the frequency domain.


Context
One of the first phases of the design of any ship or floating structure is its simulation with a linear potential flow model.This model gives a description of the interaction between the ocean waves and the floating body (Newman, 1977).
Assuming an incompressible, inviscid and irrotational flow, the fluid motion can be modeled by a scalar field ϕ, called velocity potential and such that u = ∇ϕ.The conservation of the mass of the fluid can be written as a Laplace problem ∇ 2 ϕ = 0 .Assuming small motions of the floating body and small wave heights, the boundary condition at the free surface can be linearized.The resulting problem is fully linear and can be solved in the frequency domain.
The problem can be formulated as a boundary integral problem and solved by the Boundary Element Method (BEM).In contrast with other BEM problems, the linear potential flow solvers use an expression of the Green's function which accounts for the boundary conditions at the free surface and the sea bottom.Thus, only the wet surface of the floating body needs to be discretized.The Green's function can be computed in several ways (Xie et al., 2018), which are implemented in several software, most of them commercial and closed-source.
However, the capabilities of the code are limited in comparison with its commercial counterparts.Developing new features is difficult since the core of the implementation dating back from the 1970's is poorly readable and the documentation is scarce.The goal of the present work is the modernization of this code in order to have an open-source linear potential flow solver that is easier to maintain and develop.

The capytaine Python package
The present work is a complete modernization of the Nemoh code, including a refactoring of the core routines and a Python user interface.
The core routines have been kept in Fortran, although a more modern coding style has been used.Dead code has been removed, no global variables are used anymore, more meaningful names have been used for functions and variables and a lot of comments have been added.This new version is meant to be used within the scientific Python ecosystem.The integration of the Fortran core with Python has been done with F2PY (Peterson, 2009).The naive linear solver included in Nemoh has been replaced by a call to the state-of-the-art solvers from the Numpy and Scipy libraries (Jones, Oliphant, Peterson, & others, 2001;T. Oliphant, 2006).The Intel MKL library can thus be used to solve the linear system in parallel with OpenMP.The rest of the code is the independent computation of the coefficients of a matrix and has been straightforwardly parallelized with OpenMP, making most of the code parallel.
The code has also been integrated with other Python libraries.Reading, writing and transforming meshes is done by the integration of the meshmagick (Rongère, 2017) library.The default output format is a xarray.Dataset (Hoyer & Hamman, 2017) that can be saved in the standard NetCDF format.VTK (Schroeder, Martin, & Lorensen, 2006) is used for the 3D visualization of the meshes and the results.Testing of the code is done with the pytest (Krekel et al., 2004) library.
Efforts have been made to follow best practices for the development of scientific software.For instance, the default output object includes the inputs and the settings of the solver in order to ease the reproducibility of the results.However, the present version is a step back with respect to Nemoh regarding the durability of the code.Indeed, the original code is a single Fortran project with no dependency.Thus it requires far less maintenance than the present code which is built on top of several layers of fast evolving languages and software.
This more modular version of the code allows the experimentation of new techniques to improve its performance.Hierarchical matrices have been implemented in the code and their combination with the use of local symmetries of the mesh is being tested (Ancellin & Dias, 2018, 2019).It might have been more efficient to try to merge the code into an existing BEM solver instead of redeveloping advanced BEM techniques.The present work is nonetheless a step towards a fully modular code, in which the current Green's function evaluation routines could be used in another BEM solver (e.g.(Alouges & Aussal, 2018)), and conversely other methods for the computation of the Green's function (Xie et al., 2018) could be plugged in to the present user interface.