← Back to team overview

dolfin team mailing list archive

Re: PyDOLFIN progress

 

On Fri, Jan 27, 2006 at 04:43:56PM +0100, Johan Jansson wrote:
> Hi again,
> 
> I've now added two functions:
> 
> import_form(formlist, formname):
>   """Generates and imports a module corresponding to the FFC form.
>   Returns the module."""
> 
> import_formfile(filename):
>   """Generates and imports a module corresponding to the FFC form file.
>   Returns the module."""
> 
> which allows us to do what we've discussed. I.e.:

Very good!

> from dolfin import *
> from ffc.compiler.compiler import *
> 
> element = FiniteElement("Lagrange", "tetrahedron", 1)
> 
> v = BasisFunction(element)
> u = BasisFunction(element)
> 
> a = dot(grad(u), grad(v))*dx
> 
> form1 = import_form(a, "Poisson")
> 
> a1 = form1.PoissonBilinearForm()
> mesh = UnitCube(1, 1, 1)
> A1 = Matrix()
> 
> FEM_assemble(a1, A1, mesh)
> 
> An even better improvement would be to hide import_form() inside an
> assemble function. It should be possible to write a function:
> 
> def assemble(form, matrix, mesh):
>   form1 = import_form(form, "Anonymous")
>   FEM_assemble(form1.AnonymousBilinearForm(), matrix, mesh)

I think that would be very good.

The assemble function will need to know the arity of the form so it
can pick the right version (Linear or Bilinear). Maybe something like
this:

def assemble(form, matrix, mesh):
    compiled_form = import_form(form, "Anonymous")
    if compiled_form.arity() == 0:
        FEM_assemble(compiled_form.AnonymousFunctional(), matrix, mesh)
    if compiled_form.arity() == 1:
        FEM_assemble(compiled_form.AnonymousLinearForm(), matrix, mesh)
    elif compiled_form.arity() == 2:
        FEM_assemble(compiled_form.AnonymousBiLinearForm(), matrix, mesh)
    else:
        suitable error message

The function arity() is not part of the Form interface but we could
add it:

    virtual unsigned int arity() const = 0;

Each subclass of Form must implement it (Functional, LinearForm,
BilinearForm).

Functional is not in place yet, but I think Johan Hoffman is working
on it. (??)

> Then an end-user doesn't have to be aware of this step at all. There
> needs to be some extra administration to take care of what type of
> form and coefficients though.

ok, you thought of that.

What about the Function class? There is a class named Function in FFC
that represents the restriction of a global Function to a cell, and
there's the global Function in DOLFIN. Sound like trouble if we mix
the two?

/Anders



Follow ups

References