dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #01052
Re: PyDOLFIN
On Thu, Sep 29, 2005 at 05:58:30PM +0200, Johan Jansson wrote:
> 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 that's the only manual work involved, I'm very impressed.
> 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.
You mean don't use nested classes in DOLFIN?
Can we still have private nested classes that are not exposed in the
interface?
> 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.
> >>>
Excellent!
It would look even better with "from dolfin import *". Then one
could do mesh1 = Mesh("cow05b.xml.gz") etc.
/Anders
Follow ups
References
-
PyDOLFIN
From: Johan Jansson, 2005-09-29