Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... ·...

34
Coarse grid Schwarz DDM parallel solver in FreeFem++ (y ε) F. Hecht Laboratoire Jacques-Louis Lions Université Pierre et Marie Curie Paris, France with J. Morice, G. Allaire, Cécile Dobrzynski, P. Gostaff, P. Ventura, F. Nataf ... http://www.freefem.org mailto:[email protected] With the support of ANR (French gov.) ANR-07-CIS7-002-01 http://www.freefem.org/ff2a3/ http://www-anr-ci.cea.fr/

Transcript of Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... ·...

Page 1: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Coarse grid SchwarzDDM parallel solver in

FreeFem++ (y ε)F. Hecht

Laboratoire Jacques-Louis LionsUniversité Pierre et Marie Curie

Paris, France

with J. Morice, G. Allaire, Cécile Dobrzynski, P. Gostaff, P.Ventura, F. Nataf ...

http://www.freefem.org mailto:[email protected] the support of ANR (French gov.) ANR-07-CIS7-002-01http://www.freefem.org/ff2a3/ http://www-anr-ci.cea.fr/

Page 2: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Outline

IntroductionHistoryThe main characteristicsThe Changes form 12/09 to 12/10

Academic Examples3d Poisson equation with mesh adaptationMove objet in meshesLinear elasticty equationSchwarz DDM methods with MPIPeriodic Surface Acoustic Waves Transducer Analysis

TrickHow to extract boundary from bitmapHow to extract DoF numbering in know order

DDM parallel solver in FreeFem++ (y ε) 2

Page 3: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Introduction FreeFem++ is a software to solve numerically

partial differential equations (PDE) in IR2) and in IR3) with finiteelements methods. We used a user language to set and control theproblem. The FreeFem++ language allows for a quick specificationof linear PDE’s, with the variational formulation of a linear steadystate problem and the user can write they own script to solve nolinear problem and time depend problem. You can solve coupledproblem or problem with moving domain or eigenvalue problem, domesh adaptation , compute error indicator, etc ...FreeFem++ is a freeware and this run on Mac, Unix and Windowarchitecture, in parallel with MPI.

DDM parallel solver in FreeFem++ (y ε) 3

Page 4: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

History

1987 MacFem/PCFem les ancêtres (O. Pironneau en Pascal)payant.

1992 FreeFem réécriture de C++ (P1,P0 un maillage) O.Pironneau, D. Bernardi, F. Hecht , C. Prudhomme(adaptation Maillage, bamg).

1996 FreeFem+ réécriture de C++ (P1,P0 plusieurs maillages)O. Pironneau, D. Bernardi, F. Hecht (algèbre de fonction).

1998 FreeFem++ réécriture avec autre noyau élément fini, etun autre langage utilisateur ; F. Hecht, O. Pironneau,K.Ohtsuka.

1999 FreeFem 3d (S. Del Pino) , Une première version defreefem en 3d avec des méthodes de domaine fictif.

2008 FreeFem++ v3 réécriture du noyau élément fini pourprendre en compte les cas multidimensionnels : 1d,2d,3d...

DDM parallel solver in FreeFem++ (y ε) 4

Page 5: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

For who, for what !

For what1. R&D2. Academic Research ,3. Teaching of FEM, PDE, Weak form and variational form4. Algorithmes prototyping5. Numerical experimentation6. Scientific computing and Parallel computing

For who : the researcher, engineer, professor, student...

The mailling list mailto:[email protected] with308 members with a flux of 5-20 messages per day.

DDM parallel solver in FreeFem++ (y ε) 5

Page 6: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

The main characteristics I/II (2D)(3D)

I Wide range of finite elements : linear (2d,3d) and quadraticLagrangian (2d,3d) elements, discontinuous P1 andRaviart-Thomas elements (2d,3d), 3d Edge element , vectorialelement , mini-element( 2d, 3d), ...

I Automatic interpolation of data from a mesh to an other one (with matrix construction if need), so a finite element functionis view as a function of (x, y, z) or as an array.

I Definition of the problem (complex or real value) with thevariational form with access to the vectors and the matrix.

I Discontinuous Galerkin formulation (only in 2d to day).I LU, Cholesky, Crout, CG, GMRES, UMFPack, SuperLU,

MUMPS, HIPS, HYPRE, SUPERLU_DIST, PASTIX. ...sparse linear solver ; eigenvalue and eigenvector computationwith ARPACK.

I Online graphics with OpenGL/GLUT, C++ like syntax.

DDM parallel solver in FreeFem++ (y ε) 6

Page 7: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

The main characteristics II/II (2D)(3D)

I Analytic description of boundaries, with specification by theuser of the intersection of boundaries in 2d.

I Automatic mesh generator, based on the Delaunay-Voronoïalgorithm. (2d,3d)

I load and save Mesh, solutionI Mesh adaptation based on metric, possibly anisotropic (only in

2d), with optional automatic computation of the metric fromthe Hessian of a solution. (2d,3d).

I Link with other soft : parview, gmsh , vtk, medit, gnuplotI Dynamic linking to add plugin.I Full MPI iterfaceI Wide range of of examples : Navier-Stokes 3d, elasticity 3d,

fluid structure, eigenvalue problem, Schwarz’ domaindecomposition algorithm, residual error indicator ...

DDM parallel solver in FreeFem++ (y ε) 7

Page 8: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

How to use

on Unix build a "yours.edp" file with your favorite editor :emacs, vi, nedit, etc. EnterFreeFem++ yours.edp orFreeFem++ must be in a directory of your PATH shellvariable.

on Window, MacOs X build a "yours.edp" file with your favoritetext editor (raw text, not word text) : emacs, winedit,wordpad, bbedit, ... and click on the icon of theapplication FreeFem++ and load you file via de openfile dialog box or drag and drop the icon of your builtfile on the application FreeFem++ icon.

DDM parallel solver in FreeFem++ (y ε) 8

Page 9: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

The Changes form 12/09 to 12/10

I add some interface with lapack (inverse of fullmatrix, eigenvalue of full matrix)

I change the version of tetgen to 1.4.3 download (4time faster)

I add 3d beam examples e*3d/beam.edpI add dynamic load interface with newuoa fortran

optimizer without derivative see ffnewuoa.edpexample ins examples++-load

I correct problem of free of mesh in case of gluingmeshes Th = Tha + Thb;

I add 3d example and interpolation matrix (e ∗ 3d/mat_interpole.edp)

I writing schwarz-nm-3d.edp examplesI add array of 3d meshI add seekp, tellp method on ostream type seekg,

teeg method on istream typeI correct ’ operator do alway in complex case the

conj and trans (Hermissian stuff)

I plot of complex field and 3d vector .. ( ? ? ?)

I uniformize named parameter in change,movemesh, in load "msh" , glumesh, ...

I change mesh2 tool to make a renumbering ofvertex for periodic 3d mesh.Th = change(Th, renumv = old2new) ;

I correct SubStringI add automatic compilation of download software,

(lots of parallel solver)

I Simplify the compilation of dynamics plugin withff-c++ -auto

I correct mistake in mpiI do asynchronous Isend/Irecv of matrix , meshes.

I 3d mesh adaptation exempleI correct interface of mshmet (compute 3d metric),

freeyams surface adaptation, mmg3d (3d meshmovement)

I add quoting in macro argument

I add script to simple the launch of mpi caseI add MPI version on WindowsI Compile a version for Windows 64 arch ?

DDM parallel solver in FreeFem++ (y ε) 9

Page 10: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

L’equation de Poisson

Dans domaine Ω de R3 de bord ∂Ω partitionné en Γ1 et Γe, leproblème est de trouver u la solution de

−∆u = 1 dans Ω, u = 0 sur Γ1,∂u

∂~n= 0 sur Γe (1)

Notons Vg = v ∈ H1(Ω)/v|Γ1= g l’espace de fonction 1 fois

dérivable ad-hoc.La formulation variationnelle est : trouver u ∈ V0(Ω) , telle que∫

Ω∇u.∇v −

∫Ω

1v+

∫Γ

∂u

∂nv = 0, ∀v ∈ V0(Ω) (2)

La méthode des éléments finis associée ne revient qu’à remplacerVg par un espace de dimension fini choisi.

DDM parallel solver in FreeFem++ (y ε) 10

Page 11: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Poisson equation with 3d mesh adaptation

load "msh3" load "tetgen" load "mshmet" load "medit"int nn = 6;int[int] l1111=[1,1,1,1],l01=[0,1],l11=[1,1]; // label numberingmesh3 Th3=buildlayers(square(nn,nn,region=0,label=l1111),

nn, zbound=[0,1], labelmid=l11,labelup = l01,labeldown = l01);Th3=trunc(Th3,(x<0.5)|(y < 0.5)|(z < 0.5) ,label=1); // remove ]0.5, 1[3

fespace Vh(Th3,P1); Vh u,v; // FE. space definitionmacro Grad(u) [dx(u),dy(u),dz(u)] // EOMproblem Poisson(u,v,solver=CG) =

int3d(Th3)( Grad(u)’*Grad(v) ) -int3d(Th3)( 1*v ) + on(1,u=0);

real errm=1e-2; // level of errorfor(int ii=0; ii<5; ii++)

Poisson; Vh h;h[]=mshmet(Th3,u,normalization=1,aniso=0,nbregul=1,hmin=1e-3,

hmax=0.3,err=errm);errm*= 0.8; // change the level of errorTh3=tetgreconstruction(Th3,switch="raAQ",sizeofvolume=h*h*h/6.);medit("U-adap-iso-"+ii,Th3,u,wait=1);

Run:Laplace-Adapt-3d.edp

DDM parallel solver in FreeFem++ (y ε) 11

Page 12: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Move structure in meshes

load "msh3" load "tetgen" load "medit" load "mmg3d"include "MeshSurface.idp" real hs = 0.8;int[int] N=[4/hs,8/hs,11.5/hs]; real [int,int] B=[[-2,2],[-2,6],[-10,1.5]];int [int,int] L=[[311,311],[311,311],[311,311]];mesh3 ThH = SurfaceHex(N,B,L,1); mesh3 ThSg =Sphere(1,hs,300,-1); // "gluing" surface meshesmesh3 ThSd =Sphere(1,hs,310,-1);ThSd=movemesh3(ThSd,transfo=[x,4+y,z]); mesh3 ThHS=ThH+ThSg+ThSd;real voltet=(hs^3)/6.; real[int] domaine = [0,0,-4,1,voltet];real [int] holes=[0,0,0,0,4,0];mesh3 Th = tetg(ThHS,switch="pqaAAYYQ",regionlist=domaine,holelist=holes);medit("Box-With-two-Ball",Th);

// End build mesh

int[int] opt=[9,0,64,0,0,3]; // options of mmg3d see freeem++ docreal[int] vit=[0,0,-0.3]; //

fespace Vh(Th,P1); macro Grad(u) [dx(u),dy(u),dz(u)] //Vh uh,vh; // to compute the displacemnt fieldproblem Lap(uh,vh,solver=CG) = int3d(Th)(Grad(uh)’*Grad(vh))

+ on(310,300,uh=vit[2] ) + on(311,uh=0.);

for(int it=0; it<29; it++)Lap; plot(Th,uh);Th=mmg3d(Th,options=opt,displacement=[0.,0.,uh],memory=1000);

Run:fallingspheres.edp

DDM parallel solver in FreeFem++ (y ε) 12

Page 13: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Linear Lame equation, weak form

Let a domain Ω ⊂ Rd with a partition of ∂Ω in Γd,Γn.Find the displacement u field such that :

−∇.σ(u) = f in Ω, u = 0 on Γd, σ(u).n = 0 on Γn (3)

Where ε(u) = 12(∇u + t∇u) and σ(u) = Aε(u) with A the

linear positif operator on symmetric d× d matrix corresponding tothe material propriety. Denote Vg = v ∈ H1(Ω)d/v|Γd = g .The Basic displacement variational formulation is : find u ∈ V0(Ω), such that∫

Ωε(v) : Aε(u) =

∫Ωv.f+

∫Γ((Aε(u)).n).v, ∀v ∈ V0(Ω) (4)

DDM parallel solver in FreeFem++ (y ε) 13

Page 14: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Linear elasticty equation, in FreeFem++ The

finite element method is just : replace Vg with a finite elementspace, and the FreeFem++ code :load "medit" include "cube.idp"int[int] Nxyz=[20,5,5];real [int,int] Bxyz=[[0.,5.],[0.,1.],[0.,1.]];int [int,int] Lxyz=[[1,2],[2,2],[2,2]];mesh3 Th=Cube(Nxyz,Bxyz,Lxyz);

// Alu ...real rhoAlu = 2600, alu11= 1.11e11 , alu12 = 0.61e11 ;real alu44= (alu11-alu12)*0.5;func Aalu = [ [alu11, alu12,alu12, 0. ,0. ,0. ],

[alu12, alu11,alu12, 0. ,0. ,0. ],[alu12, alu12,alu11, 0. ,0. ,0. ],[0. , 0. , 0. , alu44,0. ,0. ],[0. , 0. , 0. , 0. ,alu44,0. ],[0. , 0. , 0. , 0. ,0. ,alu44]

];real gravity = -9.81;

DDM parallel solver in FreeFem++ (y ε) 14

Page 15: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Linear elasticty equation, in FreeFem++

The problem code :

fespace Vh(Th,[P1,P1,P1]);Vh [u1,u2,u3], [v1,v2,v3];macro Strain(u1,u2,u3) [ dx(u1), dy(u2),dz(u3), (dz(u2)

+dy(u3)), (dz(u1)+dx(u3)), (dy(u1)+dx(u2)) ] // EOMsolve Lame([u1,u2,u3],[v1,v2,v3])=

int3d(Th)( Strain(v1,v2,v3)’*(Aalu*Strain(u1,u2,u3)) )- int3d(Th) ( rhoAlu*gravity*v3)+ on(1,u1=0,u2=0,u3=0) ;

real coef= 0.1/u1[].linfty; int[int] ref2=[1,0,2,0];mesh3 Thm=movemesh3(Th,

transfo=[x+u1*coef,y+u2*coef,z+u3*coef],label=ref2);

plot(Th,Thm, wait=1,cmm="coef amplification = "+coef );medit("Th-Thm",Th,Thm);

DDM parallel solver in FreeFem++ (y ε) 15

Page 16: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Lame equation / figure

Run:beam-3d.edp Run:beam-EV-3d.edp Run:beam-3d-Adapt.edp

DDM parallel solver in FreeFem++ (y ε) 16

Page 17: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Poisson equation with Schwarz method

The sketch of the method is :

I Construction of the local partition of the unityI Construction of the overlapping,I the Schwarz alternating method,I asynchronous Send/Receive (Hard)I an GMRES version for Schwarz alternating method,I Parallel visualisation for debugging

The explanation of the two scriptexamples++-mpi/DDM-Schwarz-Lap-[23]dd.edp, a schwarzparallel with a complexity in constant with the number of processnp :

DDM parallel solver in FreeFem++ (y ε) 17

Page 18: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Poisson equation with Schwarz method

To solve the following Poisson problem on domain Ω with boundary Γ in L2(Ω) :

−∆u = f, in Ω, and u = g on Γ,

where f and g are two given functions of L2(Ω) and of H12 (Γ),

Let introduce (πi)i=1,..,Np a regular partition of the unity of Ω, q-e-d :

πi ∈ C0(Ω) : πi ≥ 0 andNp∑i=1

πi = 1.

Denote Ωi the sub domain which is the support of πi function and also denote Γi theboundary of Ωi.The parallel Schwarz method is (Algorithm Number 0) Let ` = 0 the iterator and ainitial guest u0 respecting the boundary condition (i.e. u0

|Γ = g).

∀i = 1.., Np : −∆u`i = f, in Ωi, and u`i = u` on Γi \ Γ, u`i = g on Γi ∩ Γ(5)

u`+1 =

Np∑i=1

πiu`i (6)

DDM parallel solver in FreeFem++ (y ε) 18

Page 19: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

After discretization with the Lagrange finite element method, with a compatible mesh Thi of Ωi, i. e.,the exist a global mesh Th such that Thi is include in Th.Let us denote :

I Vhi the finite element space corresponding to domain Ωi,

I Nhi is the set of the degree of freedom σki ,

I NΓihi

is the set of the degree of freedom of Vhi on the boundary Γi of Ωi,

I σki (vh) is the value the degree of freedom k,

I V0hi = vh ∈ Vhi : ∀k ∈ NΓihi, σk

i (vh) = 0,

I the conditional expression a ? b : c is defined like in C of C++ language by

a?b : c ≡

if a is true then return belse return c .

Remark we never use finite element space associated to the full domain Ω because it to expensive.

We have to defined to operator to build the previous algorithm :We denote u`

h|i the restriction of u`h on Vhi, so the discrete problem on Ωi of problem (5) is find

u`hi∈ Vhi such that :

∀vhi ∈ V0i :

∫Ωi

∇vhi.∇u`hi

=

∫Ωi

fvhi, ∀k ∈ NΓihi

: σki (u

`hi

) = (k ∈ Γ) ? gki : σ

ki (u

`h|i)

where gki is the value of g associated to the degree of freedom k ∈ NΓihi

.

DDM parallel solver in FreeFem++ (y ε) 19

Page 20: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

In FreeFem++, it can be written has with U is the vector corresponding to u`h|i and the vector U1 is the

vector corresponding to u`hi

is the solution of :

real[int] U1(Ui.n) , b= onG .* U;b = onG ? b : Bi ; U1 = Ai^-1*b;

where onG[i] = (i ∈ Γi \ Γ)?1 : 0, and Bi the right of side of the problem, are defined by

fespace Whi(Thi,P2); // def of the Finite element space.varf vPb(U,V)= int3d(Thi)(grad(U)’*grad(V)) + int3d(Thi)(F*V) +on(1,U=g) + on(10,U=G);varf vPbon(U,V)=on(10,U=1)+on(1,U=0);matrix Ai = vPb(Whi,Whi,solver=sparsesolver);real[int] onG10 = vPbon(0,Whi);real[int] Bi=vPb(0,Whi);

where the freefem++ label of Γ is 1 and the label of Γi \ Γ is 10.

To build the transfer/update part corresponding to (6) equation on process i, let us call njpart thenumber the neighborhood of domain of Ωi (i.e : πj is none 0 of Ωi), we store in an array jpart of sizenjpart all this neighborhood. Let us introduce two array of matrix, Smj[j] to defined the vector to sendfrom i to j a neighborhood process, and the matrix rMj[j] to after to reduce owith neighborhood jdomain.So the tranfert and update part compute vi = πiui +

∑j∈Ji

πjuj and can be write the freefem++function Update :

func bool Update(real[int] &ui, real[int] &vi) int n= jpart.n;for(int j=0;j<njpart;++j) Usend[j][]=sMj[j]*ui;mpiRequest[int] rq(n*2);for (int j=0;j<n;++j) Irecv(processor(jpart[j],comm,rq[j ]), Ri[j][]);for (int j=0;j<n;++j) Isend(processor(jpart[j],comm,rq[j+n]), Si[j][]);for (int j=0;j<n*2;++j) int k= mpiWaitAny(rq);vi = Pii*ui;// set to πiui // apply the unity local partition .for(int j=0;j<njpart;++j) vi += rMj[j]*Vrecv[j][]; // add πjuj

return true;

DDM parallel solver in FreeFem++ (y ε) 20

Page 21: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

where the buffer are defined by :

InitU(njpart,Whij,Thij,aThij,Usend) // defined the send bufferInitU(njpart,Whij,Thij,aThij,Vrecv) // defined the revc buffer

with the following macro definition :

macro InitU(n,Vh,Th,aTh,U) Vh[int] U(n); for(int j=0;j<n;++j) Th=aTh[j]; U[j]=0; // EOM

Secondly (Algorithm Number 1) you can easily accelerate the fixe point algorithm by using a parallelGMRES algorithm after the introduction the following affine Ai operator sub domain Ωi.

func real[int] DJ0(real[int]& U) real[int] V(U.n) , b= onG10 .* U;b = onG10 ? b : Bi ; // take value of internal BC def throught onG10 arrayV = Ai^-1*b;Update(V,U);V -= U; return V;

Where the parallel MPIGMRES or MPICG algorithm is just a simple way to solve in parallel the followingAixi = bi, i = 1, .., Np by just changing the dot product by reduce the local dot product of all processwith the following MPI code :

template<class R> R ReduceSum1(R s,MPI_Comm * comm) R r=0;

MPI_Allreduce( &s, &r, 1 ,MPI_TYPE<R>::TYPE(), MPI_SUM, *comm );return r;

This is done in MPIGC dynamics library tool.

DDM parallel solver in FreeFem++ (y ε) 21

Page 22: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Thirdly (Algorithm Number 2) You can do the original problem with GMRES algorithm andpreconditioned by Schwarz method like :func real[int] DJ(real[int]& U) real[int] V(U.n);V = Ai*U;V = onG10 ? 0.: V;return V;

func real[int] PDJ(real[int]& U) /* C1*/ real[int] V(U.n), b= onG10 ? 0. : U;

V = Ai^-1*b;Update(V,U);return U;

Fourdly (Algorithm Number 3) Use a coarse grid preconditionerfunc bool CoarseSolve(

real[int]& V,real[int]& U,mpiComm& comm)

if(AC.n==0 && mpiRank(comm)==0)AC = vPbC(VhC,VhC,solver=sparsesolver);

real[int] Uc(Rci.n),Bc(Uc.n);Uc=Rci*U;mpiReduce(Uc,Bc,processor(0,comm),mpiSUM);if(mpiRank(comm)==0)

Uc = AC^-1*Bc;broadcast(processor(0,comm),Uc);

V = Pci*Uc;

func real[int] PDJC(real[int]& U) // the new precondition matrix C

real[int] V(U.n);CoarseSolve(V,U,comm);V = -V; // -C2*UoU += Ai*V; // U = (I-A C2) Uoreal[int] b= onG10 ? 0. : U;U = Ai^-1*b; // ( C1( I -A C2) UoV = U -V; /**/Update(V,U);return U;

Where vPbC is the Coarse varf, and where the matrix Rci, Pci are defined withmatrix Pci= interpolate(Whi,VhC,U2Vc=U2V); // with U2V=[0]; to the component to preservematrix Rci = Pci’*Pii;And the new left precondition matrix C build classical form C1, C2, Remark ;0 ' (Id − C1A)(Id − C2A) so Id ' −C1AC2A + C1A + C2A and we getC = C1 + C2 − C1AC2 = C1(Id − AC2) + C2.

We have all ingredient to solve in parallel if we have et the partitions of the unity. To build this partition

we do : the initial step on process 1 to build a coarse mesh, Th∗ of the full domain, and build the

partition π function constant equal to i on each sub domain Oi, i = 1, .., Np, of the grid with the

Metis graph partitioner and on each process i in 1.., Np doDDM parallel solver in FreeFem++ (y ε) 22

Page 23: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

1. Broadcast from process 1, the mesh Th∗ (call Thii in freefem++ script), and π function,

2. remark that the characteristic function 1IOiof domain Oi, is defined by (π = i)?1 : 0,

3. let us call Π2P (resp. Π2

V ) the L2 on P∗h the space P0 on Th∗ (resp. V ∗h the space P1 oneTh∗). build in parallel the πi and Ωi, such that Oi ⊂ Ωi where Oi = supp((Π2

V Π2C)m1IOi

),

and m is a the overlaps size on the coarse mesh We choose a function π∗i = (Π21Π2

0)m1IOiso

the partition of the unity is simply defined by πi = π∗i(∑Np

j=1 π∗j

)−1

The set Ji of neighborhood of the domain Ωi, Vhi, jpart and njpart can be defined with :

Vhi pii=π∗i ; Vhi[int] pij(npij); // local partition of 1 = pii +∑

j pij[j]int[int] jpart(npart); int njpart=0; Vhi sumphi = π∗i ;for (int i=0;i<npart;++i)

if(i != ipart ) if(int3d(Thi)( π∗j )>0) pij[njpart]=π∗j ;

sumphi[] += pij[njpart][]; jpart[njpart++]=i;pii[]=pii[] ./ sumphi[];

for (int j=0;j<njpart;++j) pij[j][] = pij[j][] ./ sumphi[];jpart.resize(njpart);

4. We call Th∗ij the sub mesh part of Thi where πj are none zero. and tank to the function trunc,

for(int jp=0;jp<njpart;++jp) aThij[jp] = trunc(Thi,pij[jp]>1e-10,label=10);

5. At this step we have all on the coarse mesh , so we can build the final fine mesh by splitting allmeshes : Thi, Thij[j],Thij[j] with freefem++ trunc mesh function.

6. The construction of the send/recv matrices sMj and rMj : can done with this code :mesh3 Thij=Thi; fespace Whij(Thij,Pk); // variable fespace meshes..matrix Pii; Whi wpii=pii; Pii = wpii[]; // Diagonal matrix corresponding ×πimatrix[int] sMj(njpart), rMj(njpart); // M send/rend case..for(int jp=0;jp<njpart;++jp)

int j=jpart[jp]; Thij = aThij[jp]; // change mesh to change Whij,Whijmatrix I = interpolate(Whij,Whi,U2Vc=[0]); // Whij <- WhisMj[jp] = I*Pii; rMj[jp] = interpolate(Whij,Whi,t=1,U2Vc=[0]); // Whij ->

WhiDDM parallel solver in FreeFem++ (y ε) 23

Page 24: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

This is to complex, To build a not to bad application, I have add code tout changevariable from parameter value with the following code , So all the definition a DDMidp file include here.include "DDM-Schwarz-macro.idp"include "AddLayer2d.idp"include "DDM-funcs-v2.idp"

include "getARGV.idp"verbosity=getARGV("-vv",0);...bool gmres=getARGV("-gmres",1);bool dplot=getARGV("-dp",0);int vdebug=getARGV("-d",0);And small include to make graphic in parallel of distribute solution of vector u onmesh Th with the following interface :

include "MPIplot.idp"func bool plotMPIall(mesh3 &Th,real[int] & u,string cm) PLOTMPIALL(mesh3,Pk, Th, u,cmm=cm,nbsio=3); // MPI plotreturn 1;

DDM parallel solver in FreeFem++ (y ε) 24

Page 25: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

The DDM function ... (in version 3.12)

// to build the partitionBuildPartitioning(mesh,Thg,Thi,aThij,pii,jpart

,comm,vdebug)

// build the transfer matricesBuildTransferMat(ipart,mesh,Pk,1,[0],

Thi,Whi,Whij,Thij,aThij,Usend,Vrecv,jpart,vdebug)

// def. of data and functions of the 4 algorithms.DMMDeffuncAndGlobals(Lap2,comm,jpart,Whi,

Vhc,1,Ai,vPbC,onG10,Pii,Usend,Vrecv,[0])

// solve the linear system Ai u = Bi in parallelLap2DDMSolver(Bi,u,v,gmres,eps,vdebug)

DDM parallel solver in FreeFem++ (y ε) 25

Page 26: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

The DDM function BuildPartitioning.

BuildPartitioning(sizeoverlaps,mesh,Thg,Thi,aThij,RAS,pii,jpart,comm,vdebug)

sizeoverlaps input size of sizeoverlaps (integer >0)mesh type of mesh : mesh or mesh3 of 2d or 3d case.Thg variable of global mesh (in)Thi the variable of mesh the current partition

i = mpiRank(comm), (variable declare inside)RAS boolean of set RAS pii or not.pii = πi (variable declare inside )

jpart the array (int[int] jpart(mpiSize) of list ofinsertect Thj with Thi (variable declare inside)

comm the mpi communication of this solver , for examplempiCommWorld

vdebug parameter for debugging 0 or 1 (for // graphics )

Remark, To day the label of internal boundary is 10.DDM parallel solver in FreeFem++ (y ε) 26

Page 27: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

The DDM macro BuildTransferMat.

BuildTransferMat(ipart,mesh,Pk,N,[0,1,2],Thi,Whi,Whij,Thij,aThij,Usend,Vrecv,jpart,vdebug)

Pk func to def the finite element [P2,P2,P1] for exampleN dimension of Image FE space if( Pk=[P2,P2,P1] )

then N=3.[0,1,2] The list (size N) of component used the Update

process ( put -1 to remove the pressure component(for Stokes problem)).

Whi the name the the finite element space on ThiWhij the FE array of array of FE function def of aThij meshaThij the array of all intersect mesh Thj with Thi.

Usend,Vsend name of buffed to tranfere data for Thj to Thj

DDM parallel solver in FreeFem++ (y ε) 27

Page 28: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

The DDM macro DMMDeffuncAndGlobals.

To defined all data and functions of the 4 algorithmsDMMDeffuncAndGlobals(Lap2,comm,jpart,Whi,

Vhc,N,Ai,vPbC,onG10,Pii,Usend,Vrecv,[0,1,2])

Lap2 de Prefixe given of all function and variable build.Ai the matrix of the probleme on the partition

vPbC the name the varf for the corse problem.onG10 on array the value tgv on internal boundary only and

0 otherwhere also on Γ the original bondary, you canuse the kind of code the defined this array ;

varf vPbon10([u],[v]) =on(10,u=1)+on(1,2,u=0);real[int] onG10 = vPbon10(0,Whi);

because the last on() win.

DDM parallel solver in FreeFem++ (y ε) 28

Page 29: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

The DDM macro DDMSolver.

Call the solver the linear system Aiu = BiLap2DDMSolver(Bi,u,v,gmres,eps,vdebug)choose of algorithm :gmres is

0 The true fixe point Schwarz algorithm (slow for teaching)1 GMRES on difference of tow iteration of previous algorithm.2 Classical GMRES preconditioned with Schwarz technics3 Classical GMRES preconditioned with Schwarz technics and

Coarse Grid solver (the best one)4 Bogus algorthim in test.

Where u before update and v is after update function, and eps isreal variable to set the level of error and return the final residual.

DDM parallel solver in FreeFem++ (y ε) 29

Page 30: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

A Parallel Numerical experiment on laptop

We consider first example in an academic situation to solve PoissonProblem on the cube Ω =]0, 1[3

−∆u = 1, in Ω; u = 0, on ∂Ω. (7)

Or on Linear Elasticity with Lame equatio, Stokes ProblemWith a cartesian meshes Thn of Ω with 6n3 tetrahedron, the coarsemesh is Th∗m, and m is a divisor of n.We do the validation of the algorithm on a Laptop Intel Core 2 Duowith 2 core at 2, 13 Ghz with 4Go of RAM DDR3 at 1067 Mhz,

Run:DDM-Schwarz-Lap-2dd.edp, Run:DDM-Schwarz-Lap-3d.edpRun:DDM-Schwarz-Stokes-2d.edp Run:DDM-Schwarz-Lame-2d.edpRun:DDM-Schwarz-Lame-3d.edp

DDM parallel solver in FreeFem++ (y ε) 30

Page 31: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Periodic Surface Acoustic Waves TransducerAnalysis using FreeFEM++

A true industrial numerical problem (2d) :1. 3 EDP : Dielectric, Elasticity, Piezoelectric , Linear, harmonic

approximation2. α-periodic B.C. (New simple idea)3. semi-infinite Dielectric domain (classical Fourier/Floquet

transforme)4. semi-infinite Piezoelectric domain (Hard)

In 9 month, we build with P. Ventura (100%, me 10%) a numericalsimulator form scratch (8 months for the validation), The only thing toadd to freefem++ is a interface with lapack to compute eigenvector offull 8× 8 matrix.

Le dernier message (hier) : Les calculs des paramètres physiquesdes transducteurs dans la bande d’arrêt et les évaluations decapacité statiques sont très satisfaisants par rapport aux résultatsexpérimentaux ! DDM parallel solver in FreeFem++ (y ε) 31

Page 32: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Trick to extract boundary from bitmap

load "ppm2rnm" load "isolineP1"string leman="lg.pgm";real AreaLac = 580.03; // Km2

int nbsmooth = 200; real hsize= 1;// build the curve file xy.txt ...

real[int,int] ff1(leman); // read image, in n×m arrayint nx = ff1.n, ny=ff1.m;mesh Th=square(nx-1,ny-1,[(nx-1)*(x),(ny-1)*(1-y)]);mesh Tf=Th;fespace Vh(Th,P1);Vh f1;f1[]=ff1; // change array in finite element function.real[int] v=isolineP1(Th,"xy.txt",f1,iso=0.25);Run:Leman-mesh.edp

DDM parallel solver in FreeFem++ (y ε) 32

Page 33: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Trick to extract DoF numbering in knoworder

For FE with 2 component (u1,u2) in good order on border 1 // x axis,such that on square ]0, 1[2.Remark : for(u1, u2) the interpolate of (x− 10, x− 10 + 1e− 10) wehave u2 < 0., u2 < 0. and u1 < u2 ; so after after sorting the array ofDoF value, we have u1, u2 at node 1 ,u1, u2 node 2, .... with nodenumbering increasing with x.

mesh Th=square(10,10);fespace Vh(Th,[P2,P2]); // example of finite elementint[int] ib(0:Vh.ndof-1); // array ib[i]=i of size the number of DoFvarf vbord([u1,u2],[v1,v2]) = on(1,u1=x-10,u2=x-10+1e-10);real[int] xb=vbord(0,Vh,tgv=1); // get the interpolation on border 1sort(xb,ib); // sort where xb[i] is the key, and ib[i] value.// Now in ib we have the numbering

xb = xb ? 1 : 0; // if 0 => not on label 1.int ndofon1 = xb.sum +0.5; // to count the number of non zero.ib.resize(ndofon1); // resize of the arraycout « ib « endl;

Run:BEM.edpDDM parallel solver in FreeFem++ (y ε) 33

Page 34: Coarse grid Schwarz DDM parallel solver in FreeFem++ (y+/uploads/Main/FF-Seville... · 2012-04-11 · IntroductionFreeFem++ isasoftwaretosolvenumerically partialdifferentialequations(PDE)inIR2)andinIR3)withfinite

Conclusion/Future

Freefem++ v3 isI very good tool to solve non standard PDE in 2D/3DI to try new domain decomposition domain algorithm

The the future we try to do :I Build more graphic with VTK, paraview , ... (in progress)I Add Finite volume facility for hyperbolic PDE (just begin C.F.

FreeVol Projet)I 3d anisotrope mesh adaptationI automate the parallel tool

Thank for you attention.

DDM parallel solver in FreeFem++ (y ε) 34