Error indicator and mesh adaption, in FreeFem++ F. Hecht Laboratoire Jacques-Louis Lions Université Pierre et Marie Curie Paris, France http://www.freefem.org mailto:hecht@ann.jussieu.fr Marmern, Pau, juin 2009 1
PLAN Introduction state of the Art in mesh generation (triangle or tetrahedron) Some exemple Metric and unit meshes. Some optimal meshes Hessian mesh adaptation Residual error indicator Comparison : error indicator and Hessian Metric mesh adaptation for time-dependent problems a bad adaptation schema for unsteady case a correct adaptation schema for unsteady case Conclusion / Future Marmern, Pau, juin 2009 2
Introduction I The main goal of this talk is to present some numerical comparison beetween different techniques of mesh adaptations. The mesh generation needs a metric to define the mesh size constraint, and the goal of mesh adaptations is double : compute better solution at low cost. Now, the Hessian error indicator gives the metric in a natural way, but the other error indicators give just a level of local error, so the question is how to build a metric from this local error indicator. Marmern, Pau, juin 2009 3
Introduction II The principle of mesh adaptation of a exact solution u, and a computed solution u T on a mesh T. The two to do mesh adaptation Pb1 Find the mesh T such u u T X is minimal on the set mesh with a given number of node. Pb2 Find a small mesh T in number of node such that u u T X ε for a given ε tolerance value. This two problems, are optimization problem Marmern, Pau, juin 2009 4
State of the Art in TET/TRIA mesh generation Planar triangular mesh, all is done : classic, adapted, anisotrope, LGPL Surface mesh. done, on mono patch or patch dependent in progress on multi patch surface how to find the important line of the surface. 3D tet mesh classical mesh generation, ghs3d, tetgen (free),... (done) adapted isotrope (gamic, INRIA), done adapted anisotrope (first real case F. Alauzet, P. Frey) moving mesh (P. Frey) Marmern, Pau, juin 2009 5
2D anisotrope meshes adapted to 2 functions f 1 = (10 x 3 + y 3 ) + atan2(0.001, (sin(5 y) 2 x)) f 2 = (10 y 3 + x 3 ) + atan2(0.01, (sin(5 x) 2 y)). Enter? for help Enter? for help Enter? for help Done with freefem++ software or bamg Marmern, Pau, juin 2009 6
2.5. Validation et exemples 45 la manière suivante : D P = 1 min i n P, u i, où u i représente le vecteur unitaire porté par la droite P P i et n P est le vecteur normal unitaire à la surface. On pourra aussi considérer qu un maillage de surface composé de triangles est optimal s il s agit d un maillage unité par rapport à la carte de métriques géométriques (c est-à-dire celle qui est proportionnelle aux rayons de courbures principaux). 2.5.2 Résultats Surface meshes nt ne 2 < l < 2(en %) Q < 3 (en %) h = 1 1327 2650 61.61 84.42 h = 0.5 3391 6778 89.55 95.21 h = 0.3 8559 17114 96.55 98.66 h = 0.1 73240 146476 99.56 99.96 Tab. 2.2 Comparaison des maillages obtenus avec différentes tailles de mailles imposées sur la surface Fig. 2.10 Représentation des 83 carreaux paramétrés définissant la surface d un avion. With Salome II, software Exemple 1. Le premier exemple est le maillage surfacique uniforme d un avion. Cet avion se compose de 83 faces (Figure 2.10) et de 6 arêtes dégénérées situées principalement au niveau du nez de l avion. On choisit une métrique de la forme 1 0 0 h 2 1 0 0 h 2 1 0 0 h 2 afin de spécifier un champ de taille uniforme h sur la surface. La figure2.11 montre les maillages obtenus pour h = 0.5 et h = 0.3 et le tableau 2.2 donne les caractéristiques des maillages pour différentes mértiques isotropes. Fig. 2.11 Maillage uniforme sur la surface de taille h = 0.3 Exemple 2. Le deuxième exemple (Fig.2.12) consiste à contrôler l erreur d interpolation à l aide de métrique dans l espace des paramètres construite à l aide des Marmern, Pau, juin 2009 7
Surface meshes continuing Conclusion 49 Fig. 2.12 Maillage uniforme sur la surface de taille h = 0.3 (en haut) et adapté à la courbure (en bas). Marmern, Pau, juin 2009 8
TET meshes Courtesy of F. Alauzet Marmern, Pau, juin 2009 9
A main IDEA for mesh generation The difficulty is to find a tradeoff between the error estimate and the mesh generation, because this two work are strongly different. To do that, we propose way based on a metric M and unit mesh w.r.t M The metric is a way to control the mesh size. remark : The class of the mesh which can be created by the metric, is very large. Marmern, Pau, juin 2009 10
Metric / unit Mesh In Euclidean geometry the length γ of a curve γ of R d parametrized by γ(t) t=0..1 is γ = 1 0 γ = 1 0 γ (t).γ (t)dt We introduce the metric M(x) as a field of d d symmetric positive definite matrices, and the length l of Γ w.r.t M is : 1 1 l = 0 γ M = γ (t).m(γ(t))γ (t)dt 0 The key-idea is to construct a mesh where the lengths of the edges are close to 1 accordingly to M. Marmern, Pau, juin 2009 11
Remark on the Metric Let S be a surface, parametrized by F (u) R 3 with(u) R 2, and let Γ(t) = F (γ(t)), t [0, 1] be a curve on the surface. The length of the curve Γ is 1 Γ = Γ (t).γ (t)dt Γ = 1 0 ( F γ (t)). F γ (t)dt = and on a parametric surface the metric is 0 M = t F F 1 0 γ (t). t F F γ (t)dt Marmern, Pau, juin 2009 12
Unit ball / the Metric versus mesh size if M is constant (independent of x) l = 1 imply the study of the set of point E M = {x R d /x.mx = 1}. So a good edge P Q is such that P Q E M. Q v2 P v1 Let us call,v i the d unit eigenvectors and λ i the d eigenvalues of matrix M. The mesh size h i in direction v i is given by 1/ λ i so λ i = 1 h 2 i Marmern, Pau, juin 2009 13
Remark on metric : If the metric is independant of position, then geometry is euclidian. But the circle in metric become ellipse in classical space. Infact, the unit ball (ellipse) in a metric given the mesh size in all the direction, because the size of the edge of mesh is close to 1 the metric. If the metric is dependant of the position, then you can speak about Riemmanian geometry, and in this case the sides of triangle are geodesics, but the case of mesh generation, you want linear edge. Marmern, Pau, juin 2009 14
A Classical Schema of mesh adaption i=0 ; Let T i h loop an initial mesh compute u i the solution on mesh T i h evaluate the level of error ε si ε < ε 0 break compute the new local mesh size h i+1 construct a mesh according to prescribe the mesh size. Remark, how transform a local a posteriori local error indicator size. Theoriticaly we want to estimate : η K h i on mesh η But we use h i+1 = Ch K iηk user parameter. where η K is the mean value of η K, and C is a Marmern, Pau, juin 2009 15
Optimality Problem Pb2, Find a small mesh T in number of node such that u u T X ε for a given ε tolerance value. If you use the previous Schema of a interpolation problem in L norme for P 1 continuous Lagrange finite element with a metric. (i.e : u T = I T (u), where I T is the interpolation operator). M = 1 ε u = 1 ε H where H = u is the Hessian of u. Asymptotically (i.e ε is small enought), the unit mesh with respect to M is close to the optimal mesh. Work of A. Dervieux, F. Alauzet. Marmern, Pau, juin 2009 16
Optimality Problem Pb2 II An error estimate in R 2 With the P 1 finite element the error interpolation is : u I T u T 1 6 sup x,y,z T t xyh(z) xy 1 6 sup x,y,z T t xy H(z) xy where H have the same eigen-vectors and the eigen-value of H is the abs of the eigen-value of H, We take M = 1 6ε 0 H and where ε 0 is the expected error. Marmern, Pau, juin 2009 17
Metric computation with Hessien for P 1 Lagrange finite element The le Cea lemma say : the error is bound with the interpolation error. In a classical Adaption way, the metric tensor M is constructed in order to equilibrate the error of interpolation. As say the previous slide : the idea is M = C ε 0 ij u where ε 0 is the global level of error, the user parameter. But, u is unknown here, we just known u T the discret solution We use a reconstruction algorithm get not to bad approximation of u T. Remark : the mathematical problem is here. Marmern, Pau, juin 2009 18
dans un cadre anisotrope Optimal meshes in H 1 semi-norm 2θ Mπ, si 0 θ M < π 2 The problem is findq the P M mesh 2 minimizing 2θ M π, si π 2 (u θ M < Iu) π (3.17) L 2 with a fixed number of points 0 π θ M u l = x 2 y 2 u r = x 3 y + y 3 + tanh(10(sin(5y) 2x)) Remark : We start the process, with a Hessian adapted mesh. And in this case, the gain Fig. is just 3.10 of 2 Maillages 5%. mixtes triangles/quadrangles. Marmern, Pau, juin 2009 19
0.2 Same idea, apply on surface 0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6000 nbt Fig. 3.17 Représentation shading de la surface d un objet définie par une BRep avant (à gauche) Marmern, et Pau, après juin 2009 (à droite) optimisation de sa rugosité. 20
Residual error indicator For the Laplace problem u u = f in Ω, n = 0 on Ω the classical error η K element indicator [C. Bernardi, R. Verfürth] is : η K = K h2 K (f + u h) 2 + K h e [ u h n ] 2 where on triangle K, h K is size of the longest edge, h e is the size of the current edge, n the normal. Theorem : This indicator is optimal with Lagrange Finite element c 0 K η 2 K u u h H1 c 1 K η 2 K where c 0 and c 1 are two constant independent of h, if T h is a regular family of triangulation. Marmern, Pau, juin 2009 21
Error indicator in freefem++ fespace Nh(Th,P0) ; // a space of function constant by element Nh rho,etak ; varf indicator2(uu,chik) = intalledges(th)(chik*lenedge*square(jump(n.x*dx(u)+n.y*dy(u)))) +int1d(th)(chik*lenedge*square(n.x*dx(u)+n.y*dy(u))) +int2d(th)(chik*square(htriangle*(f-dxx(u)-dyy(u))) ) ;... rho=0 ; // to change the size of the associated array rho[] = indicator2(0,nh) ; etak= sqrt(rho) ; Marmern, Pau, juin 2009 22
Hierarchical error indicator The idea is very simple, take a Hierarchy Lagrange finite element space [R. Bank,..] X p h = {v H1 (Ω)/ K T h v K P p (K)} by construction we have : X p h Xp+1 h Denote Y p+1 h a finite element space such that X p+1 h = X p h Y p+1 h degrees of freedom of X p+1 h not in X p h ). (with First, find u X p h /R such that : Second, find e h Y p+1 such that v h X p h /R, Ω u h. v h dx = v h Y p+1 h, Ω e h. v h dx = Ω fv hdx Ω fv h u h. v h dx Marmern, Pau, juin 2009 23
Hierarchical error indicator, suite A lot of technique can be use to simplify the previous problem to compute e h, here the matrix is big, the condition number of this matrix is generally good. remark, it possible to compute a good approximation of e h where we solve just local problem. e h give a good approximation of the real error at the place of the new degree of freedom. See work of I. Babuška, R. Bank, O. Zienkiewicz, J. Zhu... Marmern, Pau, juin 2009 24
Code in FreeFem++ fespace Eh(Th,P2h) ; // the hierarchical FE space P2 without P1 Vh u,v ; Nh rho,etak ; Eh ue,ve ; real error=0.01 ; problem Probem1(u,v,solver=CG,eps=1.0e-6) = int2d(th,qforder=2)( u*v*1.0e-10+ dx(u)*dx(v) + dy(u)*dy(v)) + int2d(th,qforder=2)( (x-y)*v) ; problem ProbemE(ue,ve,solver=CG,eps=1.0e-6) = int2d(th)( ue*ve*1.0e-10+ dx(ue)*dx(ve) + dy(ue)*dy(ve)) + int2d(th)( (x-y)*ve -( u*ve*1.0e-10+ dx(u)*dx(ve) + dy(u)*dy(ve) )) ; Marmern, Pau, juin 2009 25
Computation of a approximation of the mesh size h i : The mesh size h i around a point i is given the average of all the length of edge around vertex i. Let us introduce two linears form : l s (v) = K T h e K e v; l c(v) = K T h e K where e is a edge of K and e the length of edge e. e v e remark : l s (w i ) given the sum of the length of edge around vertex i and l c (w i ) given the count of edge around i. So : h i = l s(w i ) l c (w i ) where w i the finite element basis function associated to vertex i. Marmern, Pau, juin 2009 26
How to code in FreeFEM++ fespace Vh(Th,P1) ; Vh nbeperv, meshsize ; varf vmeshsizen(u,v)=intalledges(th,qfnbpe=1)(v) ; varf vedgecount(u,v)=intalledges(th,qfnbpe=1)(v/lenedge) ; func bool MeshSizecomputation() { // computation of the mesh size // ----------------------------- nbeperv=0. ;nbeperv[]=vedgecount(0,vh) ; meshsize=0. ;meshsize[]=vmeshsizen(0,vh) ; meshsize[]=meshsize[]./nbeperv[] ; cout << " -- bound meshsize = " <<meshsize[].min << " " << meshsize[].max << endl ; return true ; // ----------------------------- } Marmern, Pau, juin 2009 27
The loop in FreeFem++ for (int i=0 ;i<100 ;i++) {... if(eps<eps0) break ; real etamean= int2d(th)(etak)/area ; MeshSizecomputation() ; // the computation of new mesh size meshsize = coef*meshsize * max(min(etamean/ etak,2.),0.333) ; Th=adaptmesh(Th,IsMetric=1,meshsize,splitpbedge=1,nbvx=100000) ; } Marmern, Pau, juin 2009 28
A not to bad solution 10 10 u u = f in Ω, u n = 0 on Ω we take a L-shape domain :Ω =]0, 1[ 2 \[ 2 1, 1[ and f = x y. Nb of Triangles = 153834, Nb of Vertices 77574 Marmern, Pau, juin 2009 29
4 tests with FreeFem++ All the test start with uniform mesh h = 1/5. We make 7 steps of adaptation Residual Error indicator (C = 1.8) Residual Hierarchical indicator (C = 1.25) isotrope Metric indicator ε i = 0.01 2 i anisotrope Metric indicator ε i = 0.01 2 i Marmern, Pau, juin 2009 30
Intial mesh, Iteration 0, nt=54 nv=39 Marmern, Pau, juin 2009 31
Residual Error indicator 1 0.1 Linfty H1 err Err R Err H 1/(x) 0.01 0.001 0.0001 1e-05 100 1000 10000 100000 Marmern, Pau, juin 2009 32
Mesh Residual Error indicator, Iteration 5, nt=9076 nv=4687 Marmern, Pau, juin 2009 33
Hierarchical Error indicator 1 0.1 Linfty H1 err Err R Err H 1/(x) 0.01 0.001 0.0001 1e-05 100 1000 10000 100000 Marmern, Pau, juin 2009 34
Mesh Hierarchical Error indicator, Iteration 5, nt=4256 nv=2244 Marmern, Pau, juin 2009 35
Metric aniso 1 0.1 Linfty H1 err Err R Err H 1/(x) 0.01 0.001 0.0001 1e-05 100 1000 10000 100000 Marmern, Pau, juin 2009 36
Mesh Metric aniso Error indicator, Iteration 3, nt= 2240 nv=1197 Marmern, Pau, juin 2009 37
Metric iso, Iteration 3, nt=3325 nv=1755 1 0.1 Linfty H1 err Err R Err H 1/(x) 0.01 0.001 0.0001 1e-05 100 1000 10000 100000 Marmern, Pau, juin 2009 38
Mesh Metric iso Error indicator, Iteration 3 Marmern, Pau, juin 2009 39
Comparaision in semi norm H 1 0.1 M aniso H1 M iso H1 R iso H1 (1.8) R iso H1 (1.25) 0.01 0.001 100 1000 10000 100000 Marmern, Pau, juin 2009 40
Comparaision in norm L 0.01 M aniso Linfty M iso Linfty R iso Linfty (1.8) R iso Linfty (1.25) 1/x 0.001 0.0001 1e-05 100 1000 10000 100000 Marmern, Pau, juin 2009 41
First, a bad adaptation scheme for an transient problem Let T h initial mesh loop in time i i=0 ; adaptation loop ia compute u j i the solution on mesh T j h i evaluate the level of error ε si ε < ε 0 break compute the new local mesh size construct a mesh according to prescribe the mesh size. interpolate de previous solution on new meshes Marmern, Pau, juin 2009 42
Example, iteration0,3,9,13,16,19 file:///users/hecht/work/articles/mit2/movies/pb.gif The problem is to much interpolation and we will be one step late Marmern, Pau, juin 2009 43
A better adaptation scheme for transient problem The mesh be implicit now and we just adding a fixe point schema : big loop in time save u I j to wi I j = 0 and let T j h to the current mesh. loop fixe point on j M = M(w I ) and do u j I = wi with interpolation small loop in time i compute u j I+i the solution on mesh T M = M M(u j I+i ) evaluate the level of error ε if ε < ε 0 break construct a new mesh T j+1 h i j h i according to the Metric M Marmern, Pau, juin 2009 44
Metrix intersection The unit ball B(M) in a metrix M plot the maximum mesh size on all the direction, is a ellipse. If you two unknows u and v, we just compute the metrix M v and M u, find a metrix M uv call intersection with the biggest ellipse such that : B(M uv ) B(M u ) B(M v ) Marmern, Pau, juin 2009 45
The FreeFem++ coding See convect-apt.edp exemple of full description fespace Vh(th,P1) ; Vh u1 = y, u2 = -x ; // rotation velocity Vh m11=0,m22=0,m12=0 ; // to store the metric field... // M = M(w I ) m11=0 ;m22=0 ;m12=0 ; // reset metrix (0 => infinite mesh size) adaptmesh(th,v,err=tol,metric=[m11[],m22[],m12[]],nomeshgeneration= true) ;... // M = M M(u j I+i ) adaptmesh(th,v,err=tol,metric=[m11[],m22[],m12[]],nomeshgeneration= true) ; Marmern, Pau, juin 2009 46
Two movies With level of error 0.05 file:///users/hecht/work/articles/mit2/movies/ok.gif With level of error 0.01 file:///users/hecht/work/articles/mit2/movies/ok2.gif Marmern, Pau, juin 2009 47
Some Idea to build mesh from image, The Chesapeake Bay How to solve to compute flow on : Do Chesapeake-mesh.edp Do Chesapeake-flow.edp Marmern, Pau, juin 2009 48
Conclusion The anisotrope metric adaption schema gives the best result but mathematically we have not real proof. And the metric gives a very good interface between mesh generation and PDE solver. Thank for your attention Marmern, Pau, juin 2009 49