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

MixedFunction error with vector and scalar

0 votes

Hello Friends
I have to solve mixed function space with vector and scalar simultaneously in FEniCS. But still i getting error on shape mismatch.
Here i wrote programme code

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

Test and Trial Functions

(p, y, u, p1, p2, p3, z) = TrialFunctions(W)
(pt, yt, ut, p1t, p2t, p3t, zt) = TestFunctions(W)

After i have some boundary conditions, then

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])'))
k = interpolate(pd0, X0)
pd = project(grad(k), X)
a0 = inner(p-pd,pt)*dx + inner(div(pt),p1)*dx + inner(pt,p2)*dx - inner(div(pt),p3)*dx

Error occur on second term only, while taking scalar and vector as mixed space, then

Traceback (most recent call last):
File "optimal.py", line 49, in
a0 = inner(p-pd,pt)dx + inner(div(pt),p1)dx + inner(pt,p2)dx - inner(div(pt),p3)dx
File "/usr/lib/python2.7/dist-packages/ufl/operators.py", line 127, in inner
return Inner(a, b)
File "/usr/lib/python2.7/dist-packages/ufl/tensoralgebra.py", line 184, in new
ufl_assert(ash == bsh, "Shape mismatch.")
File "/usr/lib/python2.7/dist-packages/ufl/assertions.py", line 37, in ufl_assert
if not condition: error(message)
File "/usr/lib/python2.7/dist-packages/ufl/log.py", line 154, in error
raise self._exception_type(self._format_raw(
message))
ufl.log.UFLException: Shape mismatch

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

2 Answers

+3 votes
 
Best answer

Replace this line:

X = VectorFunctionSpace(mesh, "RT", 2)

by

 X = FunctionSpace(mesh, "RT", 2)

The Raviart-Thomas (RT) element family is a vector element by construction. So, in your code you create a vector of vector elements (a tensor element), which I do not think is what you intend to do.

answered Jan 23, 2014 by Marie E. Rognes FEniCS User (5,380 points)
selected Jan 23, 2014 by Jan Blechta
+2 votes

First, a tip on how to go ahead debugging this: Split the large form

inner(p-pd,pt)*dx + inner(div(pt),p1)*dx + inner(pt,p2)*dx - inner(div(pt),p3)*dx

into its components:

a00 = inner(p-pd,pt)*dx
a01 = inner(div(pt),p1)*dx
a02 = inner(pt,p2)*dx
a03 = inner(div(pt),p3)*dx

Then you will find that there is a shape mismatch in a01 (also in a03). Take a look at

print div(pt).shape()
print p1.shape()

This reveals that div(pt) is a vector, and p1 is scalar. This is what you would expect. Since Raviart Tomas is a vector element, the VectorFunctionSpace with RT is a tensor space, and the divergence of a tensor is a tensor 1 order smaller (in this case, a vector).

answered Jan 23, 2014 by Øyvind Evju FEniCS Expert (17,700 points)

I agree that, In my case, if we take pt as a vector, then div(pt) becomes a scalar after that inner product with scalar p1 it doesn't work in FEniCS. So how to define that term. Equation like this AMS Paper

Hi, I only skimmed through the paper but I did not see there any tensor function space, only vector and scalar function spaces. That is, only X0 and Y from your code were used. Can you check that?

...