errornorm(...) fails with vector fields

Issue #180 resolved
Nico Schlömer created an issue

If the dimensionality of a vector field is greater than that of the hosting mesh, errornorm(...) will needlessly bail out with

Error:   Unable to interpolate function into function space.
*** Reason:  Dimension 0 of function (3) does not match dimension 0 of function space (2).

MWE:

from dolfin import *

# Two-dimensional mesh
mesh = UnitSquareMesh(20, 20, 'crossed')

V = FunctionSpace(mesh, 'CG', 1)

# Three-dimensional vector field
W = MixedFunctionSpace([V, V, V])

f0 = Expression(('sin(x[1])', 'cos(x[0])', 'tan(x[0]*x[1])'))
f1 = Expression(('tan(x[1])', 'sin(x[0])', 'cos(x[0]*x[1])'))

u0 = project(f0, W)
u1 = project(f1, W)

# Error:   Unable to interpolate function into function space.
# *** Reason:  Dimension 0 of function (3) does not match dimension 0 of function space (2).
errornorm(u0, u1)

Comments (6)

  1. Martin Sandve Alnæs

    Allow arbitrary shaped functions in errornorm with TensorFunctionSpace.

    Fixes issue 180.

    Also did some cleanup and future proofing by avoiding passing mesh= to assemble.

    → <<cset ac5aa5a51166>>

  2. Log in to comment