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

Error on Interpolate and projection

+3 votes

Hi
I am trying to solve polygonal domain for Raviart-Thomas elements.

In that. i will use interpolate or projection over through vectorFunctionspace in the following codes like some error occur:

X = VectorFunctionSpace(mesh, "RT", 2)
Y = FunctionSpace(mesh, "CG", 1)
Z = FunctionSpace(mesh, "CG", 1)
W = MixedFunctionSpace([X,Y,Y,Y,Y,Y,Y])

then i use TestFunctions(W) ,TairlFunctions(W) after that i get error on Shape mismatch on projection should used like codes

pd0 = Expression(('-pi*(1+pi*pi)*cos(pi*x[1])*sin(pi*x[2])','-pi*(1+pi*pi)*sin(pi*x[1])*cos(pi*x[2])'))

x = Function(X)
pd = project(pd0, X)

then, If i use projection

x = Function(X)
m = interpolate(pd0 ,X)
pd1 = grad(m)
pd = project(pd1, X)

then following error occur are

File "poly.py", line 62, in
m = interpolate(pd0 ,X)
File "/usr/lib/python2.7/dist-packages/dolfin/fem/interpolation.py", line 64, in interpolate
Pv.interpolate(v)
RuntimeError:
*** -------------------------------------------------------------------------
*** Error: Unable to interpolate function into function space.
*** Reason: Rank of function (1) does not match rank of function space (2).
*** Where: This error was encountered inside FunctionSpace.cpp.
*** Process: 0
*** -------------------------------------------------------------------------

then i solve variational inequality

a0 = inner(p-pd,pt)*dx + inner(div(pt),p1)*dx

Can anybody clarify this to me?

Thank you

asked Jan 17, 2014 by Manickam FEniCS Novice (450 points)
edited Jan 17, 2014 by Manickam

1 Answer

+3 votes
 
Best answer

Updated answer after discussion: RT is a vector-element so you should use a regular FunctionSpace for the interpolation, and project into VectorFunctionSpace

X0 = FunctionSpace(mesh, "RT", 2)
X = VectorFunctionSpace(mesh, "RT", 2)
m = interpolate(Expression(('...', '...')), X0)
dp = project(grad(m), X)
answered Jan 17, 2014 by mikael-mortensen FEniCS Expert (29,340 points)
selected Jan 20, 2014 by Jan Blechta

But the problem appears when trying to interpolate pd0 on a VectorFunctionSpace, which should work fine.

I tested, and it seems that the problem is with the RT-elements (it works with CG elements). As far as I can see, this should be filed as a bug?

I see, RT is a vector element. Use FunctionSpace(mesh, 'RT', 2) and interpolation works, but not project. This should work though:

X0 = FunctionSpace(mesh, "RT", 2)
X = VectorFunctionSpace(mesh, "RT", 2)
u = interpolate(Expression(('1', '2')), X0)
project(grad(u), X)

Thanks mikael and oyvinev for discussing to give valuable suggestion to me..

Is it possible to do it with functions defined on A mixed space X0 * X?

The functions interpolate and Project are Not working well with
the subspaces like W.sub(0)...

...