Getfem-python interface
Introduction
As of version 1.7, getfem++ provides an interface to the Python scripting language. Python is a nice, cross-platform, and free language. With the addition of the numarray package, python provides a basic subset of Matlab functionalities (i.e. dense arrays). The VTK toolkit may provide visualization tools via its python interface (or via mayavi), and data files for openDX may be exported. The sparse matrix routines are provided by the getfem interface.Building the python interface
Use ./configure --enable-python=yes when the getfem-interface is built. It requires the python developpement files (python.h etc.) to be available, and also the numarray package to be installed (its installation is straightforward if it not provided by your linux distribution).The getfem module
The python interface is available via a python module getfem.py. In order to use the interface you have to load it with
import getfem;
m=getfem.Mesh('cartesian', range(0, 3), range(0,3))
or
from getfem import *;
m=Mesh('cartesian', range(0, 3), range(0,3))
If the getfem.py (and the internal getfem_.so) module is not installed in a standard location for python, you may have to set the PYTHONPATH environnement variable to its location.
A nice command-line python shell is ipython.
getfem-python Classes
The general organization of the python-interface is the following:- Each class from the matlab interface has a corresponding class in the python interface: the gfMesh class becomes the getfem.Mesh class in python, the gfSlice becomes the getfem.Slice etc.
- Each get and set method of the matlab interface has been
translated into a method of the corresponding class in the python
interface. For example
gf_mesh_get(m, 'outer faces'); gf_mesh_get(m, 'pts');becomesm.outer_faces(); m.pts();Some methods have been renamed when there was ambiguity, for examplegf_mesh_set(m, 'pts', P)isgetfem.Mesh.set_pts(P) -
The other getfem-matlab function function have a very simple
mapping to their python equivalent:
gf_compute(mf, U, 'foo',...) getfem.compute_foo(mf, U) or getfem.compute('foo',...) gf_asm('foobar',...) getfem.asm_foobar(...) or getfem.asm('foobar',...) gf_linsolve('gmres',...) getfem.linsolve_gmres(...) or getfem.linsolve('gmres',...)
memory management
A nice advantage over the Matlab interface is that you do not have to explicitely delete objects that are not used any more, this is done automagically. You can however inspect the content of the getfem workspace with the function getfem.memstats().
Documentation
The getfem.py module is largely documented. This documentation has been extracted into the getfem-python reference. The getfem-matlab user guide may also be used, as 95% of its content translates quite directly into python (with the exception of the plotting functions, which are specific to matlab).Examples
- tests/python/demo_tripod.py : this is the python equivalent of the matlab demo_tripod. There is also a demo_tripod_alt.py which does not use the model bricks.
- tests/python/demo_plate.py : an example of use of the linear plate model bricks.


