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

inner product of two dolfin::function

0 votes

Hi,

I have given two dolfin::function, say v and w. Mathematically, they lie both in the same Hilbert space V, but have different finite element discretizations: both P1 Elements, but different triangulations. How can I compute the L2-inner product of v and w? It should be possible, since it is only a linear combination of inner products of the FE basis functions.

I would be very happy about any help.
Thanks in advance,

frieder

asked Jul 5, 2016 by frieder FEniCS Novice (340 points)

1 Answer

0 votes

If I understand your question correctly, it should be sufficient to project w to the FunctionSpace that v is in, or vice versa. See the small example below.

from dolfin import *
mesh1 = UnitSquareMesh(20, 20)
mesh2 = UnitSquareMesh(20, 20)
V1 = FunctionSpace(mesh1, "Lagrange", 1)
V2 = FunctionSpace(mesh2, "Lagrange", 1)
v = Function(V1)
w = Function(V2)
w = project(w, V1) # note this line, or it won't run
inner_product = assemble(v * w * dx)
print inner_product
answered Jul 5, 2016 by maartent FEniCS User (3,910 points)
inner product of two dolfin::function with different meshes
...