← Back to team overview

dolfin team mailing list archive

PyDOLFIN

 

Hi!

I've made some progress with SWIG and the generated Python module
PyDOLFIN (a Python interface to DOLFIN). The module is generated
completely automatically, one thing that needs some manual work is
type-mapping between C++ and Python, for example std::string to Python
string, and the DOLFIN typedefs aren't recognized (dolfin::real and
dolfin::uint for example), so that needs to be mapped manually as well
(the mapping only needs to be done once of course).

If you have SWIG (package name "swig" in Debian) and Python, try
running the "test.sh" script in src/demo/scripting/pydolfin/.

One problem we need to solve is that SWIG doesn't support nested
classes. Perhaps we can come up with an alternative? I don't think
they're crucial for us.

Here's a sample (interactive) session:

$ python
Python 2.4.1 (#2, Apr  1 2005, 09:56:40) 
[GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydolfin
>>> mesh1 = pydolfin.Mesh("cow05b.xml.gz")
Reading mesh from file "cow05b.xml.gz".
Computing mesh connectivity:
  Found 306 nodes
  Found 844 cells
  Created 1367 edges
  Created 1906 faces
  Sorting mesh entities locally.
>>> mesh2 = pydolfin.Mesh("cow05c.xml.gz")
Reading mesh from file "cow05c.xml.gz".
Computing mesh connectivity:
  Found 306 nodes
  Found 844 cells
  Created 1367 edges
  Created 1906 faces
  Sorting mesh entities locally.
>>> mesh1.noNodes()
306
>>> mesh2.noNodes()
306
>>> mesh1.merge(mesh2)
Computing mesh connectivity:
  Found 612 nodes
  Found 1688 cells
  Created 2734 edges
  Created 3812 faces
  Sorting mesh entities locally.
>>> mesh1.noNodes()
612
>>> meshfile1 = pydolfin.File("mymesh.xml.gz")
>>> meshfile1 << mesh1
Saved mesh mesh (no description) to file mymesh.xml.gz in XML format.
>>> 

  Johan



Follow ups