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:

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