dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #05394
Python interface working
The DOLFIN Python interface now supports definition and assembly of
variational forms. (Without needing to define separate form files,
compiling with FFC etc.)
The Poisson demo is now available both in C++ and Python. Here's the
Python demo:
http://www.fenics.org/hg/dolfin?f=5b8e685eabe7;file=src/demo/pde/poisson/python/demo.py
Some further details:
1. Everything from FFC is now available by default in (Py)DOLFIN,
including FiniteElement, TestFunction, TrialFunction, grad, div etc.
2. Forms can be assembled into matrices or vectors by just calling the
assemble() function:
mesh = UnitSquare(10, 10)
A = assemble(dot(grad(v), grad(u))*dx, mesh)
3. The class LinearPDE is now also available in Python and can be used
to solve linear variational problems:
pde = LinearPDE(a, L, mesh, bc)
u = pde.solve()
plot(u)
4. A Function in PyDOLFIN is both a ffc.Function and a dolfin::Function.
So it can be used for coefficients in variational forms (like v*f*dx)
but one can also plot the function, save it to file, use it as
coefficient in another form etc. And it's not necessary to keep track of
the order in which functions are defined (like when working with a form
file in FFC and a C++ code). Functions are extracted automatically from
the form in the right order.
5. When defining a Function by overloading eval() in Python, one must do
values[0] = <expression> (not return <expression>) even if the Function
is scalar. We might be able to solve this at some point, but it's a
little tricky (SWIG related).
6. When defining a SubDomain by overloading inside() in Python, one must
make sure to return a Python bool (not numpy.bool). This is a little
annoying (that numpy has its own bool). This might also be possible to
fix at some point.
7. What happens when a form is assembled is that DOLFIN calls ffc.jit()
to generate code, compile the code and suck it back in as a Python
module. This is handled by Instant. The first time a form is compiled,
it may take some time before the code has been compiled and generated,
but the next time, Instant checks the md5sum of the generated code to
see that it doesn't need to regenerate and recompile.
Try it out and see if it works. I'm also interested in comments on the
interface. I'm pretty happy with the way it turned out. The only thing I
don't like is that defining a simple function like sin(x) for a
right-hand side takes a few lines of code to define (since you have to
subclass Function).
/Anders