Actual source code: example8.edp
 1 /*******************************************************
 2  *  This file is part of the FreeFEM tutorial made by  *
 3  *      Pierre Jolivet <pierre@joliv.et>               *
 4  *                                                     *
 5  *  See https://joliv.et/FreeFem-tutorial for more     *
 6  *                                                     *
 7  *   Description: trunc, new2old, and restrict         *
 8  *******************************************************/
  
10 border a(t=0, 2*pi) { x=cos(t); y=sin(t); label=1; }
11 mesh Th = buildmesh(a(80));
12 Th = change(Th, fregion = (x^2 + y^2 < 0.1) ? 1 : 0);
 
14 int[int] n2o;
15 mesh ThNew = trunc(Th, x < 0.0 || y < 0.0 || region == 1, new2old = n2o);
 
17 func Pk = P2; // consistent finite element space
18 fespace Vh(Th, Pk); // full mesh
19 fespace VhNew(ThNew, Pk); // submesh
 
21 Vh u = x^2 + y^2;
22 VhNew uNew = u;
23 plot(u, wait = 1, cmm = "u on the original mesh");
24 plot(uNew, wait = 1, cmm = "u on the filtered mesh through interpolation");
25 int[int] R = restrict(VhNew, Vh, n2o);
26 uNew = 0;
27 uNew[] = u[](R);
28 plot(uNew, wait = 1, cmm = "u on the filtered mesh through new2old + restrict");
 
30 uNew = cos(x)*sin(y);
31 u = uNew;
32 plot(uNew, wait = 1, cmm = "u on the filtered mesh");
33 plot(u, wait = 1, cmm = "u on the original mesh through interpolation");
34 u = 0;
35 u[](R) = uNew[];
36 plot(u, wait = 1, cmm = "u on the original mesh through new2old + restrict");