# FFT inside integral

**URL:** <https://community.freefem.org/t/fft-inside-integral/1424>\
**Category:** General Discussion\
**Created:** [January 10, 2022, 8:12pm UTC](https://community.freefem.org/t/fft-inside-integral/1424 "2022-01-10T20:12:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pepe](https://avatars.discourse-cdn.com/v4/letter/p/4da419/32.png) [@Pepe](https://community.freefem.org/u/Pepe)\
**Post date:** [January 10, 2022, 8:12pm UTC](https://community.freefem.org/t/fft-inside-integral/1424/1 "2022-01-10T20:12:52Z")

</div>

When we consider the unit square [0,1]^2. We can compute the FFT of a P1 function u by using dfft(u[], nx, -1).

I would like to know if it is somehow possible to use this trick inside an integral so to express something like

varf a(u,v) = int(Th)(eigenValues [].\* dfft(u[]) .\* ddft(v[])) ;

This would permit me to solve the following variational formula

 ![a(u,v)_=_int_s(x](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/cf251af0625ff31b3bec033fa004430e50a04793.jpeg)

where Ae is a diagonal operator for the Fourier Basis and so using fft allows us to construct the associated matrix quickly.

---

<div class="post-metadata">

**Author:** ![Pepe](https://avatars.discourse-cdn.com/v4/letter/p/4da419/32.png) [@Pepe](https://community.freefem.org/u/Pepe)\
**Post date:** [January 10, 2022, 8:27pm UTC](https://community.freefem.org/t/fft-inside-integral/1424/2 "2022-01-10T20:27:35Z")

</div>

I have thought about creating a function that goes from finite element space to finite element space. So for example, something like this

func Vh Ae ( Vh u, Vh v){  
u[] = eigenValueVector[] .\* dfft(u []);  
v[] = dfft(v[] );  
return (u\*v);  
}

But It doesn’t seem to work.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [January 10, 2022, 8:46pm UTC](https://community.freefem.org/t/fft-inside-integral/1424/3 "2022-01-10T20:46:00Z")

</div>

The problem is generally the matrix corresponding to the fourier mode is full in no fourier cas

so the matrix A associe to “a” is full, it is very bad to solve the problem, but you can solve a problem with bilinear form a , without construction the matrix A only the operator A\*u with CG or GMRES algorithm.

---

<div class="post-metadata">

**Author:** ![Pepe](https://avatars.discourse-cdn.com/v4/letter/p/4da419/32.png) [@Pepe](https://community.freefem.org/u/Pepe)\
**Post date:** [January 10, 2022, 8:54pm UTC](https://community.freefem.org/t/fft-inside-integral/1424/4 "2022-01-10T20:54:26Z")

</div>

Yes, I agree that the matrix is full. The problem is that Ae is really expensive to compute otherwise. In reality Ae is a Dirichlet-to-Neumann operator that has to be solved in 3D. This means that for each iteration of my scheme I would need to solve a 3D problem. Moreover, this way is less accurate.

That is why it is preferable to have a full 2D matrix but atleast I don’t lose that much acurracy and I don’t have to deal with huge meshes.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [January 11, 2022, 12:12pm UTC](https://community.freefem.org/t/fft-inside-integral/1424/5 "2022-01-11T12:12:00Z")

</div>

So if you have just to solve a problem with this matrix , so build the linear operator and use a  
a GMRES or CG to solve the linear problem,
