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

How to calculate u.T*M*u

0 votes

Hello,
i am a absolute novice..
i want to calculate $u_d^T \ M_v \ u_d$ respectively $(u_d , M_v u_d)$, where $M_v$ the velocity mass matrix and u some velocity vectors are

Mv = assemble(inner(u,v)*dx)

So unfortunately

    Mv_u = Mv*udiff
udMud = inner(udiff,Mv_u)

doesn't work for me. I had some attempts with as_vector but that doesn't work..
My aim is to get a scalar to calculate the square root.
I did not find any fitting solution yet so I hope some can help me. I'm sorry if this topic already exists

asked Jan 25, 2016 by Farbdrucker FEniCS Novice (160 points)

1 Answer

+1 vote

There are a couple of things to notice here.
First, it is not clear if 'udiff' is of type Function or
Vector. The vector containing the Function 'udiffs's dofs can be obtained
by the udiff.vector().

Notice also that several packages have functions 'inner'.
I assume in the above code that you use the ufl function inner.
If so you need udiff to be a function and you would need to assemble.
Hence, something like:

d = inner(udiff, udiff)*dx
d = sqrt(d)

If udiff is of type Vector, you may use (for instance)
the numpy function inner:

d = inner(Mv_u.array(), udiff.array())

answered Jan 25, 2016 by Kent-Andre Mardal FEniCS Expert (14,380 points)
...