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


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,

// 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);

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.

Let me know if this is not clear to you.

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