// NBPROC 3 // Computation of the eigen value and eigen vector of the // Dirichlet problem on square $]0,\pi[^2$ // Functionnal interface // ---------------------------------------- // we use the inverse shift mode // the shift is given with sigma real // ------------------------------------- // find $\lamda$ such that: // $$ \int_{\omega} \nabla u_ \nabla v = \lamba \int_{\omega} u \nabla v $$ load "MUMPS_mpi" verbosity=7; mesh Th=square(20,20,[pi*y,pi*x]); Th=change(Th,fregion= (mpisize*nuTriangle)/Th.nt); plot(Th,wait=1,fill=1); fespace Vh(Th,P2); Vh u1,u2; int n=Vh.ndof; real sigma = 00; // value of the shift varf a(u1,u2)= int2d(Th,mpirank)( dx(u1)*dx(u2) + dy(u1)*dy(u2) - sigma* u1*u2 ) + on(1,2,3,4,u1=0) ; // Boundary condition varf b([u1],[u2]) = int2d(Th,mpirank)( u1*u2 ) ; // no Boundary condition int[int] info(40); info=-1; info(0)=1; matrix A= a(Vh,Vh,solver=sparsesolver,master=-1,info=info); matrix B= b(Vh,Vh,solver=CG,eps=1e-20); func real[int] FA(real[int] & u) { // resolution distribuer mais pas le second membre if(mpirank==0) {int cas=1; broadcast(processor(0),cas);} else u=0; // second menbre non distribute real[int] Au=A^-1*u;return Au; } func real[int] FB(real[int] & u) { if(mpirank==0) { int cas=2; broadcast(processor(0),cas);} broadcast(processor(0),u); real[int] Alu=B*u,Au(Alu.n); mpiReduce(Alu,Au,processor(0),mpiSUM); return Au; } func int Farpack(int i) { real[int] u(n); while(1) { int cas ; broadcast(processor(0),cas); cout << mpirank << " " << cas << endl; if(cas==1) FA(u); else if(cas==2) FB(u); else break; } return 0; } // important remark: // the boundary condition is make with exact penalisation: // we put 1e30=tgv on the diagonal term of the lock degre of freedom. // So take dirichlet boundary condition just on $a$ variationnal form // and not on $b$ variationnanl form. // because we solve // $$ w=A^-1*B*v $$ int nev=20; // number of computed eigen valeu close to sigma real[int] ev(nev); // to store nev eigein value Vh[int] eV(nev); // to store nev eigen vector if(mpirank==0) { int k=EigenValue(n,FA,FB,sym=true,sigma=sigma,value=ev,vector=eV,tol=1e-10,maxit=0,ncv=0); int cas=0; broadcast(processor(0),cas); // tol= the tolerace // maxit= the maximal iteration see arpack doc. // ncv see arpack doc. // the return value is number of converged eigen value. k=min(k,nev); // some time the number of converged eigen value // can be greater than nev; int nerr=0; real[int] eev(36); eev=1e100; for(int i=1,k=0;i<7;++i) for(int j=1;j<7;++j) eev[k++]=i*i+j*j; eev.sort; cout << eev << endl; for (int i=0;i 1e-6) nerr++; if(abs(ev[i]-eev[i]) > 1e-1) nerr++; cout << " ---- " << i<< " " << ev[i] << " == " << eev[i] << " err= " << err << " --- "<