Debian Codegraph @

idp/Heat3d.idp

raw
1 load "medit"
2 include "getARGV.idp"
3
4 func f= 1. ; // right hand side function
5 func g=0.; ; // boundary condition function
6 func u0= 0;
7 real dt=getARGV("-dt",0.01);
8 int nn=getARGV("-n",10);
9 int imax=getARGV("-niter",10);
10 int op=getARGV("-op",1);
11 int pplot=getARGV("-plot",0);
12
13 mesh Th2D=square(nn,nn);
14 int[int] refm=[1,1,2,1,3,1,4,1];
15 int[int] refu=[0,1];
16 mesh3 Th=buildlayers(Th2D,nn,zbound=[0.,1.],labelmid=refm,labelup=refu,labeldown=refu);
17
18
19 // to slip integral on each processor
20 // set a region number of a processor number
21 real ccc = mpisize/real(Th.nt) ;
22 if(op) Th=change(Th,fregion= min(mpisize-1,int(nuTriangle* ccc+1e-10)));
23 else Th=change(Th,fregion=0);
24 int reg= op ? mpirank : 0;
25 // end of trick
26 cout << " *** Th: vol " << Th.mesure << " " << int3d(Th,reg)(1.) << endl;
27 fespace Vh(Th,P2) ; // P1 FE space
28 Vh uh=u0 ; // unkown and test function.
29
30
31 real temps=clock();
32
33 real time1,time2,time6;
34 time1=clock();
35
36 // compute only on region number = processor number
37 varf vlaplace(uh,vh) = // definition de problem
38 int3d(Th,reg)( uh*vh+ dt*(dx(uh)*dx(vh) + dy(uh)*dy(vh)+ dz(uh)*dz(vh)) ) // bil. form
39 + int3d(Th,reg)( dt*vh*f) + on(1,uh=g) ;
40 varf vmasse(u,v) = int3d(Th,reg)(u*v);
41 varf von1(uh,vh) = on(1,uh=1) ;
42
43 matrix AA = vlaplace(Vh,Vh,tgv=ttgv) ;
44 time1=clock()-time1;
45 // reduce the matrice to get the full matrice
46 // warning the tgv number is now mpisize*tgv for B.C.
47 varf vffullpattern(u,v) = int2d(Th,qforder=1)(u*v);
48 matrix A=vffullpattern(Vh,Vh);
49 time6=clock();
50 if(op) mpiAllReduce(AA,A,mpiCommWorld,mpiSUM);
51 else A=AA;
52
53 time6 = clock()-time6;
54 time2=clock();
55 set(A,solver=sparsesolver,tgv=ttgv) ; // factorize
56 time2=clock()-time2;
57
58 real time3=clock();
59 matrix M = vmasse(Vh,Vh);
60 time3=clock()-time3;
61
62 real [int] b(A.n),bb(A.n) ;
63 real[int] bcl= vlaplace(0,Vh,tgv=ttgv) ; // The B.C vector
64 real[int] Gamma = von1(0,Vh,tgv=1); //
65
66 real time4=0,time5=0;
67
68 for(int i=0 ;i<imax;i++)
69 {
70
71 real time4tmp=clock();
72 bb = M*uh[];
73 bb += bcl ;
74
75 time4=time4+(clock()-time4tmp);
76 real time6tmp=clock();
77 if(op) mpiAllReduce(bb,b,mpiCommWorld,mpiSUM);
78 else b=bb;
79 time6=time6+(clock()-time6tmp);
80 real time5tmp=clock();
81 uh[] = A^-1*b ; // resolution
82 time5=time5+(clock()-time5tmp);
83 if(mpirank==0)
84 cout << " -- time " << (i+1)*dt << " ||uh|| " << uh[].linfty << " ||b|| " << b.linfty << endl;
85
86 }
87 //savesol("Heat-Time-"+imax+"-nn-"+nn+"-superludist.sol",Th,uh);
88 //savemesh(Th,"Heat-Time-"+imax+"-nn-"+nn+"-superludist.mesh");
89 cout << "Time resolution " << clock()-temps << endl;
90 if( mpirank==0 && pplot) medit("Heat",Th,uh);
91 cout << "======================================" << endl;
92 cout << " CPU TIME : " << endl;
93 cout << " matrix A " << time1 << endl;
94 cout << " factorization " << time2 << endl;
95 cout << " mass matrix " << time3 << endl;
96 cout << " RHS (Matrix vector Product with mass matrix) " << endl;
97 cout << " " << time4/imax << endl;
98 cout << " solving " << time5/imax << endl;
99 cout << " MpiReduce " << time6 << endl;
100 cout << " all " << clock()-temps << endl;
101 cout << "======================================" << endl;
102
103
104
105