Calculating an overlap integral

Hello,

I am looking to find the correct method to calculate an integral over a 2D mesh defined as
\int_\Omega u_1(x,y)e^{iqx} u_2(x,y) dx dy
where q is a constant, u_1, u_2 are functions over the mesh.

Here is attempt 1 (for q = 1):

f = Expression('cos(x[0])', degree = 1)
integral_real = assemble(u1*f*u2*dx)
g = Expression('sin(x[0])', degree = 1)
integral_imag = assemble(u1*g*u2*dx)
print(integral_real + 1j*integral_imag)

Is this the right way to calculate such an integral?

Here you assume that u1 and u2 are real numbers, and the multiplication makes sense. However, if u1 and u2 are supposed to be complex you Need a further decomposition of u1 and u2 into its real and imaginary part.

As a side note, in dolfinx, there is support for complex numbers. You can test it in docker by using the image dolfinx/complex. The source code of dolfinx can be found here.

1 Like