Extend ufl/dolfin integration with mirroring of function space and mesh classes

Issue #307 resolved
Martin Sandve Alnæs created an issue

New types will need to be introduced in ufl for this, and dolfin types will need adjustment as well. A natural progression seems to be:

  1. DONE: Make a new ufl.FunctionSpace class
  2. DONE: Make a ufl.Mesh class (formerly ufl.Domain) (For now dolfin.Mesh has a ufl.Mesh instead of being one).
  3. DONE: Revert ufl.FiniteElement to use a Cell and not a Domain. (For now dolfin.FunctionSpace has a ufl.FunctionSpace instead of being one).
  4. DONE: Make ufl.Mesh have a coordinate element without circular references
  5. DONE: Add a 'degree' property to dolfin.MeshGeometry (currently always 1) and use this to create a ufl.Mesh with a Lagrange coordinate element

This involved a lot of refactoring and renaming and is infrastructure for a range of features. One such feature is non-affine domains fully integrated in all of dolfin. Another feature is a nice interface for the multimesh support that Anders is working on. The final goal includes being able to express mixed function spaces over multiple meshviews of different topological dimension, with the possible extension to multiple meshes. Something like this, but the design will be iterative:

cell = triangle
coordinate_element = VectorElement("Lagrange", cell, 2)
element = FiniteElement("Lagrange", cell, 2)

mesh = Mesh(coordinate_element)
meshview1 = MeshView(mesh, codim=1)
meshview2 = MeshView(mesh, codim=0)

V = FunctionSpace(mesh, element)
V1 = FunctionSpace(meshview1, element)
V2 = FunctionSpace(meshview2, element)

W = MixedFunctionSpace(V, V1, V2)

u = TrialFunction(W)
v = TestFunction(W)
a = inner(u,v)*dx

Having a nice interface to these features is not just sugar coating, it's necessary to be able to fully combine these features with automatic differentiation and automated optimization.

Work on MeshView and MixedFunctionSpace was previously mentioned here, but those warrant their own issues. Further work on extending dolfin Mesh degree > 1 should also be its own issue.

Comments (13)

  1. Martin Sandve Alnæs reporter

    Here's a use case that shows why these design changes are necessary:

    from dolfin import *
    parameters["form_compiler"]["representation"] = "uflacs"
    
    mesh = UnitSquareMesh(3,3)
    Vx = VectorFunctionSpace(mesh, "Lagrange", 2)
    x = Function(Vx)
    D = Domain(x)
    V = VectorFunctionSpace(D, "Lagrange", 2)
    f = Function(V)
    
    vx = TestFunction(Vx) # Fail
    v = TestFunction(V) # Ok
    
    #print Vx.ufl_element().domains() # affine
    print V.ufl_element().domains() # non-affine
    print f.domains() # non-affine
    print f.element().domains() # non-affine
    print
    print f.function_space().ufl_element().domains() # affine BUG
    
    M = inner(grad(f), grad(f))*dx(D)
    L = derivative(M, f, v)
    assemble(L)
    

    Reason:

    class FunctionSpaceFromCpp(FunctionSpaceBase):
        "FunctionSpace represents a finite element function space."
        def __new__(cls, cppV, element=None):
            if not isinstance(cppV, (cpp.FunctionSpace)):
                cpp.dolfin_error("functionspace.py",
                                 "create function space",
                                 "Illegal argument, not a cpp.FunctionSpace: " + str(cppV))
    
            # Lets be agressive in abusing dynamic typing shall we...
            cppV._dolfin_element = cppV.element()
            cppV._ufl_element = eval(cppV.element().signature(), ufl.__dict__).reconstruct(domain=cppV.mesh())
            cppV.__class__ = FunctionSpaceBase
            return cppV
    

    I'll get back to explaining in more detail.

  2. Martin Sandve Alnæs reporter

    This is work in progress now, however it's difficult and possibly not necessary to use as much inheritance as suggested above.

  3. Martin Sandve Alnæs reporter

    With the branches in next now much of the fundamentals here are done. However don't get your hopes up when reading this: the issue was too big so I narrowed it down quite a bit. Also the non-affine mesh functionality will be inaccessible now until we fix dolfin.

  4. Martin Sandve Alnæs reporter

    Most of the issues mentioned here are done. If anything important is left, it will show up when considering other issues.

  5. Log in to comment