error indicator and mesh adaption, in freefem++ - …hecht/ftp/fh-mamerm09.pdf · error indicator...

49
Error indicator and mesh adaption, in FreeFem++ F. Hecht Laboratoire Jacques-Louis Lions Universit´ e Pierre et Marie Curie Paris, France http://www.freefem.org mailto:[email protected] Marmern, Pau, juin 2009 1

Upload: dinhkhue

Post on 16-Sep-2018

228 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Error indicator and meshadaption, in FreeFem++

F. HechtLaboratoire Jacques-Louis Lions

Universite Pierre et Marie Curie

Paris, France

http://www.freefem.org mailto:[email protected]

Marmern, Pau, juin 2009 1

Page 2: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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

Page 3: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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

Page 4: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Introduction II

The principle of mesh adaptation of a exact solution u, and a computed

solution uT on a mesh T .

The two to do mesh adaptation

Pb1 Find the mesh T such ||u − uT ||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− uT ||X ≤ ε for a

given ε tolerance value.

This two problems, are optimization problem

Marmern, Pau, juin 2009 4

Page 5: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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

Page 6: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

2D anisotrope meshes adapted to 2 functions

f1 = (10 ∗ x3 + y3) + atan2(0.001, (sin(5 ∗ y)− 2 ∗ x))

f2 = (10 ∗ y3 + x3) + 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

Page 7: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Surface meshes

2.5. Validation et exemples 45

la manière suivante :DP = 1 ! min

i|"nP , ui#|,

où ui représente le vecteur unitaire porté par la droite PPi et nP est le vecteurnormal unitaire à la surface.

On pourra aussi considérer qu’un maillage de surface composé de triangles est op-timal 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

Fig. 2.10 – Représentation des 83 carreaux paramétrés définissant la surface d’unavion.

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éesprincipalement au niveau du nez de l’avion. On choisit une métrique de la forme

!

"1h2 0 00 1

h2 00 0 1

h2

#

$

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 di!érentes mértiques isotropes.

46 Chapitre 2. Génération et adaptation de maillage de surface issue d’une CAO

On remarque que l’hétérogénéité des edges conduit à des maillages (Fig. 2.12 enbas) dont certains éléments sont de mauvaise qualité. Par rapport aux spécificationsdésirées pour le maillage, les edges de très petites tailles sont pénalisantes. Ainsi,lorsque la taille voulue est grande par rapport à la taille de certains éléments donnéspar géométrie, on obtient des maillages qui respectent mal le champ de métrique. LaEn revanche dès que les edges sont de l’ordre de grandeur de la taille de maille désirée,on obtient des maillages dont quasiement l’intégralité des mailles ont la bonne taille.Ainsi dans le cas de l’avion, dès que h ! 3 plus de 95% des arêtes sont de la bonnetaille car on est moins pénalisé par la petite taille des edges.

nt ne1"2

< l <"

2(en %) Q < 3 (en %)

h = 1 1327 2650 61.61 84.42h = 0.5 3391 6778 89.55 95.21h = 0.3 8559 17114 96.55 98.66h = 0.1 73240 146476 99.56 99.96

Tab. 2.2 – Comparaison des maillages obtenus avec di!érentes tailles de maillesimposées sur la surface

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’inter-polation à l’aide de métrique dans l’espace des paramètres construite à l’aide des

With Salome II, software

Marmern, Pau, juin 2009 7

Page 8: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Surface meshes continuing2.6. Conclusion 49

Fig. 2.12 – Maillage uniforme sur la surface de taille h = 0.3 (en haut) et adapté àla courbure (en bas).

2.6. 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

Page 9: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

TET meshes

Courtesy of F. Alauzet

Marmern, Pau, juin 2009 9

Page 10: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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

Page 11: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Metric / unit Mesh

In Euclidean geometry the length |γ| of a curve γ of Rd 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 ` of Γ w.r.t M is :

` =∫ 1

0||γ′||M =

∫ 1

0

√γ′(t).M(γ(t))γ′(t)dt

The key-idea is to construct a mesh where thelengths of the edges are close to 1 accordingly toM.

Marmern, Pau, juin 2009 11

Page 12: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Remark on the Metric

Let S be a surface , parametrized by

F (u) ∈ R3 with(u) ∈ R2, and let Γ(t) = F (γ(t)), t ∈ [0,1]

be a curve on the surface. The length of the curve Γ is

|Γ| =∫ 1

0

√Γ′(t).Γ′(t)dt

|Γ| =∫ 1

0

√(∂F γ′(t)).∂F γ′(t)dt =

∫ 1

0

√γ′(t).t∂F ∂F γ′(t)dt

and on a parametric surface the metric is

M = t∂F∂F

Marmern, Pau, juin 2009 12

Page 13: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Unit ball / the Metric versus mesh size

if M is constant (independent of x) ` = 1 imply the study of the set of

point EM = x ∈ Rd/x.Mx = 1.

So a good edge PQ is such that PQ ∈ EM.

v1

v2P

Q

Let us call,vi the d unit eigenvectors and λi the d eigenvalues of matrix M.

The mesh size hi in direction vi is given by 1/√λi so λi = 1

h2i

Marmern, Pau, juin 2009 13

Page 14: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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

Page 15: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

A Classical Schema of mesh adaption

i=0 ;

Let T ih an initial mesh

loop

compute ui the solution on mesh T ih

evaluate the level of error ε

si ε < ε0 break

compute the new local mesh size hi+1

construct a mesh according to prescribe the mesh size.

Remark, how transform a local a posteriori local error indicator on mesh

size. Theoriticaly we want to estimate : ∂ηK∂hi

But we use hi+1 = ChiηKηK

where ηK is the mean value of ηK, and C is a

user parameter.

Marmern, Pau, juin 2009 15

Page 16: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Optimality Problem Pb2,

Find a small mesh T in number of node such that ||u− uT ||X ≤ ε for a

given ε tolerance value.

If you use the previous Schema of a interpolation problem in L∞ norme for

P1 continuous Lagrange finite element with a metric. (i.e : uT = IT (u),

where IT 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

Page 17: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Optimality Problem Pb2 II

An error estimate in R2

With the P1 finite element the error interpolation is :

||u− IT u||T∞ ≤1

6sup

x,y,z∈T| t ~xyH(z) ~xy | ≤

1

6sup

x,y,z∈Tt ~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 = 16ε0

|H| and where ε0 is the expected error.

Marmern, Pau, juin 2009 17

Page 18: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Metric computation with Hessien for P1 Lagrange finiteelement

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|∂iju|

where ε0 is the global level of error, the user parameter.

But, u is unknown here, we just known uT the discret solution We use a

reconstruction algorithm get not to bad approximation of ∇∇uT .

Remark : the mathematical problem is here.

Marmern, Pau, juin 2009 18

Page 19: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Optimal meshes in H1 semi-norm

The problem is find the mesh minimizing ||∇(u− Iu)||L2 with a fixed

number of points

ul = x2 − y2 ur = x3y + y3 + tanh(10(sin(5y)− 2x))

3.5. Résultats numériques 71

Dans un cadre anisotrope, où une métrique anisotrope est prescrite en tout pointdu domaine, nous pouvons définir une mesure de qualité en considérant maintenantle produit scalaire dans la métrique.

Soit M cette métrique, alors la mesure d’un angle dans la métrique est donnéepar la formule suivante

!M = arcos

!!BC, BA"

#BC#M#BA#M

"(3.16)

Nous remplaçons alors ! par l’expression 3.16 et nous obtenons une mesure de qualitédans un cadre anisotrope

QPM

#$

%

2!M" , si 0 $ !M < "

22% 2!M

" , si "2 $ !M < "

0 " $ !M

(3.17)

Fig. 3.10 – Maillages mixtes triangles/quadrangles.

3.5 Résultats numériques

Pour chaque exemple nous présentons le maillage initial et le maillage final ainsique les erreurs associées. Pour étudier numériquement la convergence de l’erreurd’interpolation, nous traçons également l’erreur en fonctions du nombre d’éléments.

Pour illustrer l’approche , nous présentons ici des résultats numériques pour dif-férents exemples : trois exemples de fonctions analytiques et un exemple de résolu-tion numérique d’un problème aux dérivées partielles. Le but va ici être d’utiliserle schéma d’adaptation défini précédemment afin de générer des maillages optimauxvis-à-vis de la semi-norme H1. Le maillage résultant sera considéré comme optimaldans la mesure où il s’agit de la triangulation qui minimise l’erreur d’interpolationparmi toutes les triangulations possibles.

De plus, nous comparerons les résultats avec ceux donnés par des méthodes clas-siques d’adaptation de maillage telles que décrites dans le premier chapitre. A cettefin, on considérera des maillages initiaux construits à partir d’une carte de tailles ba-sées sur une majoration de l’erreur d’interpolation en norme L! et qui fait intervenirla matrice hessienne de la surface pris en valeur absolue.

Remark : We start the process, with a Hessian adapted mesh. And in this

case, the gain is just of 2− 5%.

Marmern, Pau, juin 2009 19

Page 20: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Same idea, apply on surface

78 Chapitre 3. Génération de maillages optimaux en seminorme H1

0

0.2

0.4

0.6

0.8

1

1.2

500 1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6000

J(T

h)

nbt

f4(x,y):initial meshf4(x,y):resulting mesh

Fig. 3.17 – Représentation shading de la surface d’un objet définie par une BRepavant (à gauche) et après (à droite) optimisation de sa rugosité.

3.6 Conclusion

Nous avons proposé une méthodes simple d’optimisation de maillage basé surl’étude de la semi-norme H1 de l’erreur d’interpolation. Nous avons ensuite analysénumériquement cette méthode à travers des exemples de surfaces analytiques (sur-faces cartésiennes ou issue d’un système de CAO) et un exemple d’équations auxdérivées partielles.

Les principaux enseignements que l’on peut en tirer sont :

– D’un point de vue adaptation par éléments finis, une méthode de maillage ba-sée sur une optimisation de Delaunay anisotrope et une carte de taille baséesur la matrice hessienne de la solution permet de générer de bons maillagesvis-à-vis de la norme H1.

Marmern, Pau, juin 2009 20

Page 21: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Residual error indicator

For the Laplace problem

−∆u = f in Ω,∂u

∂n= 0 on ∂Ω

the classical error ηK element indicator [C. Bernardi, R. Verfurth] is :

ηK =

√∫Kh2K|(f + ∆uh)|2 +

∫∂K

he|[∂uh∂n

]|2

where on triangle K, hK is size of the longest edge, he is the size of the

current edge, n the normal.

Theorem : This indicator is optimal with Lagrange Finite element

c0

√∑K

η2K ≤ ||u− uh||H1

≤ c1√∑K

η2K

where c0 and c1 are two constant independent of h , if Th is a regular

family of triangulation.

Marmern, Pau, juin 2009 21

Page 22: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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

Page 23: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Hierarchical error indicator

The idea is very simple, take a Hierarchy Lagrange finite element space [R.

Bank, ..]

Xph = v ∈ H1(Ω)/∀K ∈ Th v|K ∈ Pp(K)

by construction we have : Xph ⊂ X

p+1h

Denote Yp+1h a finite element space such that Xp+1

h = Xph ⊕ Y

p+1h (with

degrees of freedom of Xp+1h not in X

ph).

First, find u ∈ Xph/R such that :

∀vh ∈ Xph/R,

∫Ω∇uh.∇vhdx =

∫Ωfvhdx

Second, find eh ∈ Y p+1 such that

∀vh ∈ Yp+1h ,

∫Ω∇eh.∇vhdx =

∫Ωfvh −∇uh.∇vhdx

Marmern, Pau, juin 2009 23

Page 24: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Hierarchical error indicator, suite

A lot of technique can be use to simplify the previous problem to compute

eh, here the matrix is big, the condition number of this matrix is generally

good.

remark, it possible to compute a good approximation of eh where we solve

just local problem.

eh give a good approximation of the real error at the place of the new

degree of freedom.

See work of I. Babuska, R. Bank, O. Zienkiewicz, J. Zhu ....

Marmern, Pau, juin 2009 24

Page 25: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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

Page 26: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Computation of a approximation of the mesh size hi :

The mesh size hi around a point i is given the average of all the length of

edge around vertex i.

Let us introduce two linears form :

ls(v) =∑

K∈Th

∑e∈K

∫ev; lc(v) =

∑K∈Th

∑e∈K

∫e

v

|e|

where e is a edge of K and |e| the length of edge e.

remark : ls(wi) given the sum of the length of edge around vertex i and

lc(wi) given the count of edge around i.

So :

hi =ls(wi)

lc(wi)

where wi the finite element basis function associated to vertex i.

Marmern, Pau, juin 2009 26

Page 27: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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

Page 28: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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

Page 29: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

A not to bad solution

10−10u−∆u = f in Ω,∂u

∂n= 0 on ∂Ω

we take a L-shape domain :Ω =]0,1[2\[12,1[ and f = x− y.

Nb of Triangles = 153834, Nb of Vertices 77574

Marmern, Pau, juin 2009 29

Page 30: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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

Page 31: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Intial mesh, Iteration 0, nt=54 nv=39

Marmern, Pau, juin 2009 31

Page 32: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Residual Error indicator

1e-05

0.0001

0.001

0.01

0.1

1

100 1000 10000 100000

LinftyH1err

Err RErr H1/(x)

Marmern, Pau, juin 2009 32

Page 33: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Mesh Residual Error indicator, Iteration 5, nt=9076 nv=4687

Marmern, Pau, juin 2009 33

Page 34: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Hierarchical Error indicator

1e-05

0.0001

0.001

0.01

0.1

1

100 1000 10000 100000

LinftyH1err

Err RErr H1/(x)

Marmern, Pau, juin 2009 34

Page 35: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Mesh Hierarchical Error indicator, Iteration 5, nt=4256nv=2244

Marmern, Pau, juin 2009 35

Page 36: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Metric aniso

1e-05

0.0001

0.001

0.01

0.1

1

100 1000 10000 100000

LinftyH1err

Err RErr H1/(x)

Marmern, Pau, juin 2009 36

Page 37: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Mesh Metric aniso Error indicator, Iteration 3, nt= 2240nv=1197

Marmern, Pau, juin 2009 37

Page 38: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Metric iso, Iteration 3, nt=3325 nv=1755

1e-05

0.0001

0.001

0.01

0.1

1

100 1000 10000 100000

LinftyH1err

Err RErr H1/(x)

Marmern, Pau, juin 2009 38

Page 39: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Mesh Metric iso Error indicator, Iteration 3

Marmern, Pau, juin 2009 39

Page 40: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Comparaision in semi norm H1

0.001

0.01

0.1

100 1000 10000 100000

M aniso H1M iso H1

R iso H1 (1.8)R iso H1 (1.25)

Marmern, Pau, juin 2009 40

Page 41: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

Comparaision in norm L∞

1e-05

0.0001

0.001

0.01

100 1000 10000 100000

M aniso LinftyM iso Linfty

R iso Linfty (1.8)R iso Linfty (1.25)

1/x

Marmern, Pau, juin 2009 41

Page 42: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

First, a bad adaptation scheme for an transient problem

Let Th initial mesh

loop in time i

i=0 ;

adaptation loop ia

compute uji the solution on mesh T j

h ievaluate 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

Page 43: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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

Page 44: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

A better adaptation scheme for transient problem

The mesh be implicit now and we just adding a fixe point schema :

big loop in time I

save uIj to wI

j = 0 and let T jh to the current mesh.

loop fixe point on j

M = M(wI) and do ujI = wI with interpolation

small loop in time i

compute ujI+i the solution on mesh T j

h i

M =M∩M(ujI+i)

evaluate the level of error ε

if ε < ε0 break

construct a new mesh T j+1h i

according to the Metric M

Marmern, Pau, juin 2009 44

Page 45: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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 Mv and Mu , find

a metrix Muv call intersection with the biggest ellipse such that :

B(Muv) ⊂ B(Mu) ∩ B(Mv)

Marmern, Pau, juin 2009 45

Page 46: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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(wI)

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(ujI+i)

adaptmesh(th,v,err=tol,metric=[m11[],m22[],m12[]],nomeshgeneration=

true) ;

Marmern, Pau, juin 2009 46

Page 47: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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

Page 48: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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

Page 49: Error indicator and mesh adaption, in FreeFem++ - …hecht/ftp/FH-Mamerm09.pdf · Error indicator and mesh adaption, in FreeFem++ F. Hecht ... Mx= 1g. So a good edge PQis ... tion

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