Debian Codegraph @

idp/buildmeshS.idp

raw
1 func meshS buildmeshS(meshL & TL,int orientation,int minsurf)
2 {
3 int withp=0;
4 if(withp) plot(TL,wait=1);
5
6 // calcul du barycentre de TL;
7 real lg=int1d(TL)(1.);
8 R3 B(int1d(TL)(x)/lg, int1d(TL)(y)/lg, int1d(TL)(z)/lg);
9 if(verbosity>2) cout <<" Barycenter: " << B << endl;
10
11 R3 NL(int1d(TL,qforder=1)((Tl^(P-B)).x),int1d(TL)((Tl^(P-B)).y),int1d(TL)((Tl^(P-B)).z));
12
13 NL /= NL.l2;
14 if(verbosity) cout << " NL = "<< NL << endl;
15 R3 U0 = (B-TL(0).P);
16 R3 V = U0^NL; V /=V.l2;
17 R3 U = V^NL ;
18 if(verbosity>5) cout << " det = " << det(U,V,NL) << " == " << 1 << endl;
19 assert(abs(det(U,V,NL)-1)< 1e-6);
20 if(verbosity>2) cout << " New Frame : "<< U << " , " << V << " , " << NL << endl;
21 real bu = U'*B, bv=V'*B, bn = NL'*B;
22 meshL TLm = movemeshL(TL,transfo=[U'*P-bu,V'*P-bv,NL'*P-bn]);
23 meshL TL0 = movemeshL(TL,transfo=[U'*P-bu,V'*P-bv,0]);
24 fespace VLm(TLm,P1); VLm zLm = z;
25 fespace VL0(TL0,P1); VL0 zL0; zL0[]= zLm[];
26 mesh Th = buildmesh(TL0,fixeborder=1);
27 real[int] bb(4);
28 boundingbox(Th,bb);
29 if(verbosity>5) cout << " bb = "<< bb << endl;
30 real lTh = max(bb[1]-bb[0],bb[3]-bb[2]); // lg characteristic of Th
31 if(withp) plot(Th,TLm,wait=1);
32 fespace V2(Th,P1);
33 V2 g=zL0;
34 real ginf =g[].linfty;
35 if(verbosity>5) cout << " ginf "<< ginf << " " << lTh << endl;
36 real errf = 0.1*g[].linfty/lTh;// err fixe point
37 real errN = 1e-6*g[].linfty/lTh;// err newton..
38 V2 u=0,v,up;
39 macro grad(u) [dx(u),dy(u)]//
40 int[int] labs=labels(Th);
41 int nbiter = 100;
42 if( minsurf == 0 || ginf < 1e-3*lTh) nbiter = 1;
43 for(int i=0; i< nbiter; ++i)
44 {
45 up[]=u[];
46 solve Pb(u,v) = int2d(Th)( (dx(u)*dx(v) + dy(u)*dy(v) )
47 / sqrt( 1+ (dx(up)*dx(up) + dy(up)*dy(up) )) )
48 +on(labs,u=g);
49 real area = int2d(Th)( sqrt(1+ (dx(u)*dx(u) + dy(u)*dy(u) )));
50 up[] -= u[];
51 real err= up[].linfty ;
52 if(verbosity) cout << i << " fixed point, surface = "<< area<< " err infty = " << err << "/" << errf << endl;
53 if(withp) plot(u, dim=3,fill=3, cmm=i+" area="+area+" err= "+err);
54 if(err<errf) break;
55 }
56 // iteration de newton
57
58 macro DJ(u,v) int2d(Th) ( grad(u)'*grad(v)/ sqrt(1+ grad(u)'*grad(u)) ) //
59 macro D2J(u,v,w) int2d(Th) ( grad(w)'*grad(v)/ sqrt(1+ grad(u)'*grad(u))
60 - (grad(u)'*grad(w))*(grad(u)'*grad(v)) / (1+ grad(u)'*grad(u))^1.5 ) //
61
62 for(int i=0; i< nbiter-1; ++i)
63 { up[]=u[];
64 solve PbNewton(u,v) = D2J(up,u,v) - D2J(up,up,v) + DJ(up,v)
65 +on(labs,u=g);
66 real area = int2d(Th)( sqrt(1+ (dx(u)*dx(u) + dy(u)*dy(u) )));
67 up[] -= u[];
68 real err= up[].linfty ;
69 if(verbosity) cout << i << " Newton surface = "<< area<< " err infty = " << err << "/" << errN << endl;
70 if(withp) plot(u, dim=3,fill=3, cmm=i+" area="+area+" err= "+err);
71 if(err<errN) break;
72 }
73 // MOVE = B+U*x+V*y+NL*z
74 meshS Ths=movemesh23(Th,transfo=[
75 B.x+U.x*x+V.x*y+NL.x*u,
76 B.y+U.y*x+V.y*y+NL.y*u,
77 B.z+U.z*x+V.z*y+NL.z*u],
78 orientation=orientation);
79 if(withp) plot(Ths,TL,wait=1);
80 return Ths;
81 }
82
83
84 func meshS buildmeshSminsurf(meshL & TL,int orientation)
85 {return buildmeshS(TL,orientation,1);}
86 func meshS buildmeshSLap(meshL & TL,int orientation)
87 {return buildmeshS(TL,orientation,0);}
88
89