Debian Codegraph @

3rdparty/dissection/src/freefem++-interface/examples++-load/cavityNewtow.Dissection.edp

raw
1 /*
2 Incompressible Navier Stokes
3 with Taylor-Hood Finite element
4 No linearity : Newton methode
5 continuation on Reynols Number
6 Mesh adaptation
7 */
8 //load "UMFPACK64"
9 //defaulttoUMFPACK64();
10 load "Dissection"
11 defaulttoDissection();
12 verbosity=5;
13 real reymax = 6400; // ok < 125000
14 mesh Th=square(60,60);
15 fespace Xh(Th,P2);
16 fespace Mh(Th,P1);
17 fespace XXMh(Th,[P2,P2,P1]);
18 XXMh [u1,u2,p];
19 XXMh [v1,v2,q];
20
21 macro div(u1,u2) (dx(u1)+dy(u2))//
22 macro grad(u1,u2) [dx(u1),dy(u2)]//
23 macro ugrad(u1,u2,v) (u1*dx(v)+u2*dy(v)) //
24 macro Ugrad(u1,u2,v1,v2) [ugrad(u1,u2,v1),ugrad(u1,u2,v2)]//
25 solve Stokes ([u1,u2,p],[v1,v2,q],solver=sparsesolver,strategy=102,tolpivot=1.0e-2) =
26 int2d(Th)( ( dx(u1)*dx(v1) + dy(u1)*dy(v1)
27 + dx(u2)*dx(v2) + dy(u2)*dy(v2) )
28 - p*div(v1,v2)-q*div(u1,u2)
29 // - p*q*(0.000001)
30 )
31 + on(3,u1=4*x*(1-x),u2=0)
32 + on(1,2,4,u1=0,u2=0);
33
34 Xh uu1=u1,uu2=u2;
35 //plot(coef=0.2,cmm=" [u1,u2] et p ",p,[uu1,uu2]);
36
37 Xh psi,phi;
38
39 solve streamlines(psi,phi,solver=sparsesolver,strategy=101,tolpivot=1.0e-16) =
40 int2d(Th)( dx(psi)*dx(phi) + dy(psi)*dy(phi))
41 + int2d(Th)( -phi*(dy(u1)-dx(u2)))
42 + on(1,2,3,4,psi=0);
43 // default tolpivot=1.0e-16 without kernel detection
44 // strategy=101 <=> symmetric = 100 + diagonal scaling = 1
45 int i=0;
46 real nu=1./100.;
47 real dt=0.1;
48 real alpha=1/dt;
49
50 /* NL
51 varf vNS ([u1,u2,p],[v1,v2,q],solver=Crout,init=i) =
52 int2d(Th)(
53 alpha*( u1*v1 + u2*v2)
54 + nu * ( dx(u1)*dx(v1) + dy(u1)*dy(v1)
55 + dx(u2)*dx(v2) + dy(u2)*dy(v2) )
56 + p*q*(0.000001)
57 + p*dx(v1)+ p*dy(v2)
58 + dx(u1)*q+ dy(u2)*q
59 + Ugrad(u1,u2,u1,u2)'*[v1,v2]
60 )
61 + on(3,u1=1,u2=0)
62 + on(1,2,4,u1=0,u2=0)
63 */
64
65 XXMh [up1,up2,pp];
66 varf vDNS ([u1,u2,p],[v1,v2,q]) =
67 int2d(Th)(
68 + nu * ( dx(u1)*dx(v1) + dy(u1)*dy(v1)
69 + dx(u2)*dx(v2) + dy(u2)*dy(v2) )
70 // - p*q*(0.000001)
71 + p*dx(v1)+ p*dy(v2)
72 - dx(u1)*q- dy(u2)*q
73 + Ugrad(u1,u2,up1,up2)'*[v1,v2]
74 + Ugrad(up1,up2,u1,u2)'*[v1,v2]
75 )
76 + on(1,2,3,4,u1=1,u2=1) // u1 = 0, u2 = 0
77 ;
78
79 varf vNS ([u1,u2,p],[v1,v2,q]) =
80 int2d(Th)(
81
82 + nu * ( dx(up1)*dx(v1) + dy(up1)*dy(v1)
83 + dx(up2)*dx(v2) + dy(up2)*dy(v2) )
84 // - pp*q*(0.000001)
85 + pp*dx(v1)+ pp*dy(v2)
86 - dx(up1)*q- dy(up2)*q
87 + Ugrad(up1,up2,up1,up2)'*[v1,v2]//'
88 )
89 + on(1,2,3,4,u1=0,u2=0) //homogeneous Dirichlet bc. for linear not affine
90 ;
91
92 for(real re=100;re<=reymax;re *=2)
93 {
94
95 real lerr=0.04;
96
97 if(re>8000) lerr=0.01;
98 if(re>10000) lerr=0.005;
99 for(int step=0;step<2;step++)
100 {
101 Th=adaptmesh(Th,[u1,u2],p,err=lerr,nbvx=100000);
102 //plot(Th,wait=0,ps="mesh."+re+".eps");
103 [u1,u2,p]=[u1,u2,p];
104 [up1,up2,pp]=[up1,up2,pp];
105
106 for (i=0;i<=20;i++)
107 {
108 nu =1./re;
109 up1[]=u1[];
110 real walltime0=time();
111 real clocktime0=clock();
112 matrix Ans=vDNS(XXMh,XXMh,tgv=1e+30);
113 real walltime1=time();
114 real clocktime1=clock();
115 real[int] b = vNS(0,XXMh,tgv=1e+30);
116 real walltime2=time();
117 real clocktime2=clock();
118 real[int,int] kernn(1,1);
119 real[int,int] kernt(1,1);
120 int kerndim;
121 set(Ans,solver=sparsesolver,strategy=2, tolpivot=1.0e-2);
122 // default scaling startegy = KKT_SCALE
123 dissectionkernel(Ans,kerneldim=kerndim,kerneln=kernn,kernelt=kernt);
124 cout << "kern dim = " << kerndim << endl;
125 real[int] kern(XXMh.ndof);
126 kern = kernn(:,0);
127 real[int] bBC = vDNS(0, XXMh, tgv=1.0); //Ans.diag;
128 real[int] vv(XXMh.ndof);
129 vv = Ans * kern;
130 vv = bBC ? 0.0 : vv;
131 cout << "orthogonality of kernel vector of A " << vv.max << endl;
132 kern = kernt(:,0);
133 vv = Ans' * kern;
134 vv = bBC ? 0.0 : vv;
135 cout << "orthogonality of kernel vector of A^T " << vv.max << endl;
136 XXMh [w1, w2, r];
137 w1[] = kern;
138 plot([w1, w2], cmm="kernel vector",value=true,wait=1);
139 plot(r, cmm="kernel pressure",value=true,wait=1);
140
141 real walltime3=time();
142 real clocktime3=clock();
143 real[int] w = Ans^-1*b;
144 real walltime4=time();
145 real clocktime4=clock();
146 u1[] -= w;
147 cout << " iter = "<< i << " " << w.l2 << " rey = " << re << endl;
148 /*
149 cout << " time "
150 << walltime1 - walltime0 << " / "
151 << clocktime1 - clocktime0 << " : "
152 << walltime2 - walltime1 << " / "
153 << clocktime2 - clocktime1 << " : "
154 << walltime3 - walltime2 << " / "
155 << clocktime3 - clocktime2 << " : "
156 << walltime4 - walltime3 << " / "
157 << clocktime4 - clocktime3 << endl;
158 */
159 if(w.l2<1e-6) break;
160 uu1=u1;uu2=u2;
161 } ;
162 }
163 uu1=u1;uu2=u2;
164 // streamlines;
165 plot(Th,wait=0);
166 plot(coef=0.2,cmm="rey="+re+" [u1,u2]",[uu1,uu2],wait=0,nbiso=20,ps="cavity-"+re+".eps");
167 }