Vector Space Function

Asked by Sebastian Rau

Hello,

i have a problem concerning a function of a Vector Function Space:
So there is a two dimensional mesh, and i use the function spaces and the function f as

V = FunctionSpace(mesh,"CG",1)
Q = FunctionSpace(mesh,"CG",1)
W = MixedFunctionSpace(V, Q)
f = Function(W)

Then, after some steps, i want to calculate

inner(grad(f[0]), f[1])*dx,

but that gives me a shape mismatch error, so i guess f[1] only denotes the first component of the function in Space Q !? How can i call the part of f being in Q, such that the dimensions fit?

Your help is very much appreciated, thanks!

Regards
Sebastian

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Martin Sandve Alnæs
Solved:
Last query:
Last reply:
Revision history for this message
Praveen C (cpraveen) said :
#1

But Q is a scalar function space. So f[1] is a scalar and the inner product does not make sense. Also you should probably do

W = MixedFunctionSpace([V, Q])

Revision history for this message
Best Martin Sandve Alnæs (martinal) said :
#2

You probably mean VectorFunctionSpace?

To answer your question:
fv, fq = split(f)

For debugging, here's a tip:
print f.shape(), fv.shape(), fq.shape()

Revision history for this message
Sebastian Rau (rau) said :
#3

Sorry, yes i meant Q = VectorFunctionSpace.

And thanks Martin, that solves my question. Now i am facing another one (how to calculate the tensor product, so that means that if i have two vectors a and b i want to have the matrix (A)_ij = a_i*b_j , the dot product gives me a scalar for this case, but i will post that in a new thread).

Regards
Sebastian

Revision history for this message
Sebastian Rau (rau) said :
#4

Thanks Martin Sandve Alnæs, that solved my question.

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#5

Index notation:
i,j = indices(2)
Aij = a[i]*b[j]

Tensor notation:
A = outer(a,b)

Or make a matrix from the index notation case:
B = as_tensor(Aij, (i,j))

Tip: Try this and print A.shape(), A.free_indices() for A, B, Aij.

Martin

On 30 May 2012 09:55, Sebastian Rau
<email address hidden> wrote:
> Question #198313 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/198313
>
>    Status: Answered => Solved
>
> Sebastian Rau confirmed that the question is solved:
> Sorry, yes i meant Q = VectorFunctionSpace.
>
> And thanks Martin, that solves my question. Now i am facing another one
> (how to calculate the tensor product, so that means that if i have two
> vectors a and b i want to have the matrix (A)_ij = a_i*b_j , the dot
> product gives me a scalar for this case, but i will post that in a new
> thread).
>
> Regards
> Sebastian
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Sebastian Rau (rau) said :
#6

Thanks a lot! i found the solution with outer( ...) in the meanwhile, too.