# How to assemble restriction matrix to extract the DoFs on the boundary

**URL:** <https://community.freefem.org/t/how-to-assemble-restriction-matrix-to-extract-the-dofs-on-the-boundary/460>\
**Category:** General Discussion\
**Created:** [June 9, 2020, 9:59pm UTC](https://community.freefem.org/t/how-to-assemble-restriction-matrix-to-extract-the-dofs-on-the-boundary/460 "2020-06-09T21:59:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Psywah](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/psywah/32/65_2.png) [@Psywah](https://community.freefem.org/u/Psywah)\
**Post date:** [June 9, 2020, 9:59pm UTC](https://community.freefem.org/t/how-to-assemble-restriction-matrix-to-extract-the-dofs-on-the-boundary/460/1 "2020-06-09T21:59:31Z")

</div>

Hi,

I want to assemble a restriction matrix to extract the DoFs on part of the boundary.

I know the interpolate function can assemble such matrix by providing two FE function spaces. Can we define a P1 function space on one side of the unit square? then interpolate it to the P1 function space on the unit square?  
see attached code.

Best regards,  
Shihua

// Mesh  
mesh Th = square(4, 4);  
plot(Th, wait=true);

// Fespace  
fespace Vh(Th, P1);

// Fespace on one edge of unit square  
meshL Eh=segment(4); //  
fespace EVh(Eh , P1);

// interpolate matrix from  
matrix Rt;  
Rt = interpolate(Vh,EVh,inside=true);

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [June 10, 2020, 5:27am UTC](https://community.freefem.org/t/how-to-assemble-restriction-matrix-to-extract-the-dofs-on-the-boundary/460/2 "2020-06-10T05:27:20Z")

</div>

Are your two meshes conforming? If so, I’d strongly advise against your technique. Much more efficient to extract the border from the original square, instead of building a new `meshL`. See an example [here](https://github.com/FreeFem/FreeFem-sources/blob/develop/examples/hpddm/helmholtz-coupled-2d-PETSc-complex.edp#L85-L101).

Let me know if this is not clear to you.

---

<div class="post-metadata">

**Author:** ![Psywah](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/psywah/32/65_2.png) [@Psywah](https://community.freefem.org/u/Psywah)\
**Post date:** [June 10, 2020, 10:18am UTC](https://community.freefem.org/t/how-to-assemble-restriction-matrix-to-extract-the-dofs-on-the-boundary/460/3 "2020-06-10T10:18:18Z")

</div>

Dear Pierre , Thank you very much. It works now.
