% restriction et prolongement sur Gamma
close all
clear all

meshfile=fc_oogmsh.gmsh.buildmesh2d('condenser11',10);
Th=fc_simesh.siMesh(meshfile); % maillage global

Th.plotmeshinfo()

u=@(x,y) cos(pi*x).*sin(pi/3*y)+1;

%%% 1-simplex in dim==2
i=Th.find(1,20); % get index of the 1-simplices elementary mesh with label=20
Eh=Th.sTh{i};
Ug=Th.eval(u); % Ug: dimension Th.nq
Ul=Eh.eval(u); % Ul: dimension Eh.nq

% prolongement par 0 dans Th (maillage global)
P=zeros(Th.nq,1);
P(Eh.toGlobal)=Ul;  

figure()
Th.plot(P)
shading interp
view(3);axis off;hold on
colorbar
Th.plotmesh('z',P,'edgecolor','k','facecolor','None','merge',true)

% prolongement par 1 dans Th (maillage global)
P2=ones(Th.nq,1);
P2(Eh.toGlobal)=Ul;  

figure()
Th.plot(P2)
shading interp
view(3);axis off;hold on
colorbar
Th.plotmesh('z',P2,'edgecolor','k','facecolor','None','merge',true)

% restriction dans Eh (i.e. Gamma(20) )
W=Ug(Eh.toGlobal);  % W: dimension Eh.nq
assert(all(W==Ul))  % W == Ul

figure()
Eh.plot(W,'linewidth',2)
shading interp
view(3);axis off;hold on
colorbar
Th.plotmesh('z',P2,'edgecolor','lightgray','facecolor','None','merge',true)

