This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

C++ expression interpolate to MixedFunctionSpace to use errornorm

0 votes

Hi,

I get the error message,
Error: Unable to interpolate function into function space.
*** Reason: Rank of function (0) does not match rank of function space (1).
*** Where: This error was encountered inside FunctionSpace.cpp.

when I try this

V = FunctionSpace(mesh, 'Lagrange', 2)

V1 = VectorFunctionSpace(mesh, 'Lagrange', 2)

u_e = interpolate(u_c, V1)#Wspace.sub(0))

u_e_proj = project(u_e, Wspace.sub(0))

bcs.apply(u_e.vector())

u_error = errornorm(u_c, U)#, degree_rise = 4)

U is the result of the stokes solver, and u_c is the result a C++ expression for the analytical velocity u.
The problem is I try to project the u_c to the same space as U, which is Wspace, which is a mixed function space(on Taylor hood elements), to do the errornorm. It doesn't work unfortunately. None of the other things I have tried either, like first interpolating to a FunctionSpace then projecting to a VectorFunctionSpace.

Best,
SS_

asked Mar 12, 2016 by SS_ FEniCS Novice (120 points)

Try collapsing the space as

Wspace.sub(0).collapse()

because usually subspaces aren't regular spaces. Collapsing generates a regular one.

...