# Interpolation operator "="

**URL:** <https://community.freefem.org/t/interpolation-operator/2476>\
**Category:** General Discussion\
**Created:** [May 20, 2023, 3:33pm UTC](https://community.freefem.org/t/interpolation-operator/2476 "2023-05-20T15:33:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kallol](https://avatars.discourse-cdn.com/v4/letter/k/59ef9b/32.png) [@kallol](https://community.freefem.org/u/kallol)\
**Post date:** [May 20, 2023, 3:33pm UTC](https://community.freefem.org/t/interpolation-operator/2476/1 "2023-05-20T15:33:05Z")

</div>

Dear all,  
I want to interpolate a function u from one finite element space Vh to another finite element space Wh. Both spaces are based on P2 dicontinuous finite elements. I have used the operator “=” for interpolation. The “=” operator use linear interpolation. Will there be any problem for using this linear interpolation as I am using P2 elements? Or how can I use second order interpolation?  
Thanks in advance.

---

<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:** [May 20, 2023, 5:35pm UTC](https://community.freefem.org/t/interpolation-operator/2476/2 "2023-05-20T17:35:29Z")

</div>

Search the docs for “interpolate” as there is a function by this name that takes  
two fespaces and returns a matrix that transforms one set of points into the other.  
You could probably do this for a small mesh and verify it is what you expect.  
Apparently IIRC you can also write u[i]=w(x,y) where u and w are defined in two different  
fespaces. If you want to try these let us know how they work compared to expectations.

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [May 20, 2023, 6:22pm UTC](https://community.freefem.org/t/interpolation-operator/2476/3 "2023-05-20T18:22:19Z")

</div>

Of course, some error will be introduced by using linear interpolation with higher order elements, but this is much more efficient than a higher order interpolation method. Further, even if you used a higher-order method, the (continuous) interpolation would still be imperfect due to the discontinuous nature of your FE space. Depending on the smoothness of your functions and the resolution of your mesh, I expect that the interpolation error from moving the locations of the discontinuities would be more important than the error from linear vs quadratic interpolation.

So, while I can’t definitively say whether there will be any problem with linear interpolation in your specific case, I can say that second order interpolation would not eliminate your problem. I think your best case is to use linear interpolation, as currently implemented in FreeFEM. If you need higher resolution, you can always use `splitmesh` to refine the mesh before the interpolation step.

---

<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:** [May 21, 2023, 7:33am UTC](https://community.freefem.org/t/interpolation-operator/2476/4 "2023-05-21T07:33:13Z")

</div>

Dear all,

remark, the interpolation operator is link to the element finites,  
but for discontinuous finite element you have to be careful if the mesh is no same  
because you can have common interpolation points on different element, so the only coordinate of point are not suffisante.

---

<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:** [May 21, 2023, 1:29pm UTC](https://community.freefem.org/t/interpolation-operator/2476/5 "2023-05-21T13:29:23Z")

</div>

you can play with this for example.  
Its easy to get some oscillation with the P2 elements for example and the P1  
are linear interpolators. I’ve never used the disocontinuous elements but  
have seen the non-monotonic step during mesh adaptation.

```auto
load "msh3"
load "medit"
int nx=10;
int nx2=22;
int[int] lbe=[100,200]; // begin and end point labels 
meshL Th1=Sline(nx, [1.0*x],label=lbe);
meshL Th2=Sline(nx2, [.5+ .25*(x-.5)],label=lbe);
fespace Vh1(Th1,P1);
fespace Vh2(Th2,P2);
Vh1 u1x=x;
Vh1 u1=(x>.5)?1:0;
Vh2 u2x=x;
Vh2 u2;
matrix A=interpolate(Vh2,Vh1);
u2[]=A*u1[];
cout<<u1x[]<<endl;
cout<<u1[]<<endl;
cout<<" u2 "<<endl;
cout<<u2x[]<<endl;
cout<<u2[]<<endl;

```
