Adapt does not return a valid FunctionSpace

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

Adapt does not return a valid FunctionSpace, reproduce with this code:

from dolfin import *

mesh = UnitSquareMesh(3,3)
Vx = VectorFunctionSpace(mesh, "CG", 1)
x = interpolate(Expression(("x[0]", "x[1]")), Vx)

mesh2 = adapt(mesh)
Vx2 = adapt(Vx, mesh2)
x2 = adapt(x, mesh2)

print type(Vx) # <class 'dolfin.functions.functionspace.VectorFunctionSpace'>
print type(Vx2) # <class 'dolfin.cpp.function.FunctionSpace'>
print Vx.ufl_element() # Ok
#print Vx2.ufl_element() # Fails, AttributeError: 'FunctionSpace' object has no attribute 'ufl_element'

xinterp = interpolate(x, Vx2) # Fails:
"""
*** Error:   Unable to compute interpolation.
*** Reason:  Illegal function space for interpolation, not a FunctionSpace (f_5).
*** Where:   This error was encountered inside interpolation.py.
"""

Comments (7)

  1. Stefan Jakobsson

    The type of the function space changes depending on how it is accessed

    print x2.function_space().id()==Vx2.id() # True
    print type(x2.function_space()) 
    # <class 'dolfin.functions.functionspace.FunctionSpaceBase'>
    print type(x2.function_space().ufl_element()) 
    # <class 'ufl.finiteelement.mixedelement.VectorElement'>
    

    As Mikael Mortensen points out, x2 is a function but x2.parent().child() is again a Coefficient. Moreover, print Vx2.parent().child().ufl_element() gives the expected answer although print Vx2.ufl_element() fails. I think something strange happens in the swig interface.

  2. Log in to comment