odevauchelle / pyFreeFem

Python wrapper library for FreeFem++
GNU General Public License v3.0
19 stars 4 forks source link

pyFreeFem

pyFreeFem is a simple Python wrapper for the finite-element software FreeFem++. It helps importing and exporting meshes, finite-element matrices and vectors to and from FreeFem++. This library can only handle two-dimensional finite-element spaces.

Here is an example of its use:

Boltzmann Distribution of Sediment Transport, A. Abramian, O. Devauchelle, G. Seizilles, E. Lajeunesse, Physical Review Letters, 123, 014501, 2019 [arXiv]

Quick example

Run FreeFem++ from Python:

import pyFreeFem as pyff

script = pyff.edpScript( 'cout << "Hello world!" << endl;' )

print( script.run() )
>>> Hello world!

Create a mesh

FreeFem++ attributes labels to nodes, triangles and boundaries. pyFreeFem includes a mesh class inherited from matplotlib.tri.Triangulation which keeps track of these labels.

script = pyff.edpScript('''
border Circle( t = 0, 2*pi ){ x = cos(t); y = sin(t); }
mesh Th = buildmesh( Circle(10) );
''')

script += pyff.OutputScript( Th = 'mesh' )

Th = script.get_output()['Th']

Th.plot_triangles( labels = 'index' )
Th.plot_nodes( labels = 'index', color = 'tab:blue' )
Th.plot_boundaries( color = 'red' )
pp.legend( title = 'Boundary label' )
pp.show()

Circular mesh

Like for the parent matplotlib.tri.Triangulation class, the nodes coordinates are stored in Th.x and Th.y, whereas the connectivity is stored in Th.triangles.

Creating a mesh with FreeFem++ can be useful by itself, for instance to calculate travel times along known streamlines. Often, though, we want to use that mesh for finite elements computations.

Documentation

More examples can be found in the documentation.

Latest tested version.

To do