# Convolution operator?

**URL:** <https://community.freefem.org/t/convolution-operator/2586>\
**Category:** General Discussion\
**Created:** [July 6, 2023, 3:28pm UTC](https://community.freefem.org/t/convolution-operator/2586 "2023-07-06T15:28:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sruget](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@sruget](https://community.freefem.org/u/sruget)\
**Post date:** [July 6, 2023, 3:28pm UTC](https://community.freefem.org/t/convolution-operator/2586/1 "2023-07-06T15:28:40Z")

</div>

Hey everyone,

I want to operate a convolution on a function.  
After a short investigation in the documentation, it appears to me that this was not implemented. I am quite surprise about it. Maybe I am wrong and the convolution operator is named differently ? Have you ever face the need for a convolution operator, and, if yes, how did you manage to deal with that issue ?

Thanks a lot,

Simon

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [July 6, 2023, 4:59pm UTC](https://community.freefem.org/t/convolution-operator/2586/2 "2023-07-06T16:59:28Z")

</div>

U;m curious too although with an unpredictable mesh not sure it is  
as easy to define as a grid. You can access FFT via fftw and do it int  
the frequency domain I suppose. I was just curious about simple shifts  
but again with a nonuniform grid I guess that involves an interpolation  
etc.

---

<div class="post-metadata">

**Author:** ![julienG](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/julieng/32/222_2.png) [@julienG](https://community.freefem.org/u/julienG)\
**Post date:** [July 6, 2023, 9:55pm UTC](https://community.freefem.org/t/convolution-operator/2586/3 "2023-07-06T21:55:02Z")

</div>

Does this example for [Green function](https://www.um.es/freefem/ff++/pmwiki.php?n=Main.HowToComputeAGreenFunction) solves your problem? Convolution is of course costly

---

<div class="post-metadata">

**Author:** ![murea](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@murea](https://community.freefem.org/u/murea)\
**Post date:** [July 7, 2023, 4:18pm UTC](https://community.freefem.org/t/convolution-operator/2586/4 "2023-07-07T16:18:29Z")

</div>

Hi,

I am also interested.  
A tentative is below.  
etaeps is the mollifier.  
But it is very slow !

Cornel

### 

real epsmol=0.2;

func real eta(real x, real y){  
real tmp;

if ( x^2+y^2 \< (1-0.001)^2)  
tmp=exp( 1/(x^2+y^2-1) );  
else  
tmp=0;

return tmp;  
}

cout \<\< eta(0,0) \<\< endl;

real C;  
C=1/int2d(Th)(eta(x,y));  
cout \<\< C \<\< endl;

fespace VhP1(Th,P1);

VhP1 etah=eta(x,y);

//plot(etah, wait=1,value=1,fill=1, dim=3, cmm=“eta”);

func real etaeps(real x, real y){  
real tmp;

tmp=C\*eta(x/epsmol,y/epsmol) /(epsmol)^2;

return tmp;  
}

VhP1 dir1P1, dir1nonP1;

dir1nonP1=abs(x)\*abs(y);

for (int i=0;i\<Th.nv;i++){

cout \<\< “i=” \<\< i \<\< endl;

dir1P1[i]= int2d(Th)(etaeps(Th(i).x -x, Th(i).y -y)\*dir1nonP1(x,y) ) ;

};

plot(dir1P1, wait=1,value=1,fill=1, dim=3, cmm="dir1P1 mollifer ");

---

<div class="post-metadata">

**Author:** ![sruget](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@sruget](https://community.freefem.org/u/sruget)\
**Post date:** [July 9, 2023, 10:01am UTC](https://community.freefem.org/t/convolution-operator/2586/5 "2023-07-09T10:01:27Z")

</div>

Yes I guess you’re right : it should be more difficult to implement with a non uniform grid. It could explain why it has not been implemented in FF+ so far. Mine is uniform, so the responses given by julienG and murea (below) works as far as I’m concern !

---

<div class="post-metadata">

**Author:** ![sruget](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@sruget](https://community.freefem.org/u/sruget)\
**Post date:** [July 9, 2023, 10:02am UTC](https://community.freefem.org/t/convolution-operator/2586/6 "2023-07-09T10:02:51Z")

</div>

Yes it works, thanks ! Nevertheless (and as you mentionned it), it is very slow as soon as you work with fine meshes (which was expected obviously haha)

---

<div class="post-metadata">

**Author:** ![sruget](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@sruget](https://community.freefem.org/u/sruget)\
**Post date:** [July 9, 2023, 10:06am UTC](https://community.freefem.org/t/convolution-operator/2586/7 "2023-07-09T10:06:36Z")

</div>

Thanks, it works too ! It is more or less the same as what JulienG referred to !  
Yes sadly, I guess nothing more sophisticated (ie faster) has been implemented for now ☹
