Pratique de l’optimisation numérique et du calcul scientifique ......ut + fb, Y, 4 u, u,, uy) =...
Transcript of Pratique de l’optimisation numérique et du calcul scientifique ......ut + fb, Y, 4 u, u,, uy) =...
Pratique de l’optimisation numérique et du calcul scientifique
4AE04
1
Plan
1. Introduction
2. Problème modèle : Les équations de Burgers
1. Les équations
2. Les solutions exactes
3. Méthodes de Résolutions
3. Adaptation de maillage automatique
1. Les équations
2. La résolutions
3. Exemples
4. Projet sous matlab
2
Pourquoi des méthodes numériques
3
Pourquoi des méthodes numériques
4
Pourquoi des méthodes numériques
5
Pourquoi des méthodes numériques
6
Problèmatiques liés aux méthodes numériques
7
Maillage
Complexité...
8
(Jouhaud & Sagaut, J. Fluid Engng, 2008)
Maillage et calcul numérique
Principe : Raffiner le maillage dans les zones de forts gradients
Objectif : minimiser les coûts de calculMéthodes :
1. Raffinement à priori
2. Raffinement dynamique en cours de simulation
9
Problème modèle :Les équations de Burgers
Modèle 2D
10
An Adaptive Mesh-Moving and Local Refinement Method l 49
flows, boundary and shear layers in viscous flows, and reaction zones in combus-
tion processes. The numerical solution of these problems is usually difficult
because the nature, location, and duration of the structures are often not known
in advance. Thus, conventional numerical approaches that calculate solutions on
a prescribed (typically uniform) mesh often fail to adequately resolve the fine-
scale phenomena, have excessive computational costs, or produce incorrect
results. Adaptive procedures that evolve with the solution offer a robust, reliable,
and efficient alternative. Such techniques have been the subject of a great deal
of recent attention (cf. Babuska et al. [8,9] and Thompson [29]) and are generally
capable of introducing finer meshes in regions where greater resolution is needed
[l, 2, 3, 6, 14, 15, 22, 261, moving meshes in order to follow isolated dynamic
phenomena [l, 2, 5, 20, 22, 26, 281, or changing the order of methods in specific
regions of the problem domain [17, 211. The utility of such adaptive techniques
is greatly enhanced when they are capable of providing an estimate of the accuracy
of the computed solution. Local error estimates are often used as refinement
indicators and to produce solutions that satisfy either local or global accuracy
specifications [ 1,2,3,6,14,15,26]. Successful error estimates have been obtained
using h-refinement [6,14,15], where the difference between solutions on different
meshes is used to estimate the error, and p-refinement [l, 2, 3, 15, 211 where the
difference between methods of different orders are used to estimate the error.
We discuss an adaptive procedure that combines mesh movement and local
refinement for m-dimensional vector systems of partial differential equations having the form
ut + fb, Y, 4 u, u,, uy) = P’b, Y, 4 u)u,lx + P2k Y, t, uhl,, (Ha)
for t > 0, (x, y) E 0,
with initial conditions
u(x, Y, 0) = UO(& YL for (x, y) E D U dQ, (l.lb)
and appropriate well-posed boundary conditions on the boundary d R of a rectan-
gular region Q.
We suppose that a numerical method is available for calculating approximate
solutions and error indicators of (1.1) at each node of a moving mesh of
quadrilateral cells. Most numerical methods are applicable, and the error indi-
cator can either be an estimate of the local discretization error or another function
(e.g., an estimate of the solution gradient or curvature) that is large where
additional resolution is needed and small where less resolution is desired. Our
adaptive algorithm consists of three parts: (i) movement of a coarse base mesh,
(ii) local refinement of the base mesh in regions where resolution is inadequate,
and (iii) creation and regeneration of the base mesh when it becomes overly
distorted. Mesh motion can substantially reduce errors of hyperbolic problems
for a very modest computational cost. Mesh motion alone, however, cannot
produce a solution that will satisfy a prescribed error tolerance in all situations.
For this reason, we have combined mesh motion with local mesh refinement and recursively solve local problems in regions where error tolerances are not satisfied.
The local solution scheme successively reduces the domain size, and thus further
ACM Transactions on Mathematical Software, Vol. 16, No. 1, March 1990.
An Adaptive Mesh-Moving and Local Refinement Method l 49
flows, boundary and shear layers in viscous flows, and reaction zones in combus-
tion processes. The numerical solution of these problems is usually difficult
because the nature, location, and duration of the structures are often not known
in advance. Thus, conventional numerical approaches that calculate solutions on
a prescribed (typically uniform) mesh often fail to adequately resolve the fine-
scale phenomena, have excessive computational costs, or produce incorrect
results. Adaptive procedures that evolve with the solution offer a robust, reliable,
and efficient alternative. Such techniques have been the subject of a great deal
of recent attention (cf. Babuska et al. [8,9] and Thompson [29]) and are generally
capable of introducing finer meshes in regions where greater resolution is needed
[l, 2, 3, 6, 14, 15, 22, 261, moving meshes in order to follow isolated dynamic
phenomena [l, 2, 5, 20, 22, 26, 281, or changing the order of methods in specific
regions of the problem domain [17, 211. The utility of such adaptive techniques
is greatly enhanced when they are capable of providing an estimate of the accuracy
of the computed solution. Local error estimates are often used as refinement
indicators and to produce solutions that satisfy either local or global accuracy
specifications [ 1,2,3,6,14,15,26]. Successful error estimates have been obtained
using h-refinement [6,14,15], where the difference between solutions on different
meshes is used to estimate the error, and p-refinement [l, 2, 3, 15, 211 where the
difference between methods of different orders are used to estimate the error.
We discuss an adaptive procedure that combines mesh movement and local
refinement for m-dimensional vector systems of partial differential equations having the form
ut + fb, Y, 4 u, u,, uy) = P’b, Y, 4 u)u,lx + P2k Y, t, uhl,, (Ha)
for t > 0, (x, y) E 0,
with initial conditions
u(x, Y, 0) = UO(& YL for (x, y) E D U dQ, (l.lb)
and appropriate well-posed boundary conditions on the boundary d R of a rectan-
gular region Q.
We suppose that a numerical method is available for calculating approximate
solutions and error indicators of (1.1) at each node of a moving mesh of
quadrilateral cells. Most numerical methods are applicable, and the error indi-
cator can either be an estimate of the local discretization error or another function
(e.g., an estimate of the solution gradient or curvature) that is large where
additional resolution is needed and small where less resolution is desired. Our
adaptive algorithm consists of three parts: (i) movement of a coarse base mesh,
(ii) local refinement of the base mesh in regions where resolution is inadequate,
and (iii) creation and regeneration of the base mesh when it becomes overly
distorted. Mesh motion can substantially reduce errors of hyperbolic problems
for a very modest computational cost. Mesh motion alone, however, cannot
produce a solution that will satisfy a prescribed error tolerance in all situations.
For this reason, we have combined mesh motion with local mesh refinement and recursively solve local problems in regions where error tolerances are not satisfied.
The local solution scheme successively reduces the domain size, and thus further
ACM Transactions on Mathematical Software, Vol. 16, No. 1, March 1990.
Conditions initiales :
Modèle 1D
Stationnaire
Instationnaire
11
Solution exacte
Burgers stationnaire avec conditions de Robin
Solution :
12
avec
Solution
Comparaison Analytique / Numerique :
13
Burgers 1D instationnaire
Problème de déplacement de front
Solution
14
Stratégie de Raffinement
Topologie des mailles élémentaires
Méthode : Eléments finis, Volume finis, Spectral
Forme des mailles :
1D
2D : quadrilatère, triangle, ...
3D : Tétraèdre, Héxaèdres
Raffinement
à priori : statique au cours de la simulation
adaptatif
Critère de raffinement : Erreur, gradient, ...
15
Maillage
Complexité...
16
(Jouhaud & Sagaut, J. Fluid Engng, 2008)
Probème physique et maillage
Densité baryonique
17
Stratégie de raffinement dynamique
Structure arborescente : Hiérarchie Quad Trees
18
1D 2D
Ondes de choc
Méthode : AMR
19
Exemple : Jet
20
Exemple : Rayleigh - Taylor
Méthode AMR : fort gradient de concentration.
21
Exemple : MHD 2D
Nappes de courant : gradients intenses.
22
Exemple : dynamo solaire
composante radiale de la vitesse dans le soleil (3D)
23
Méthodes Numériques etéquations de Burgers
Shémas : u,t + a u,x = 0
Conditions initialesfor i=1:nx
x(i) = (i-1)*dx ; u(i) = sin(x(i)*2*pi) ; end
24
Notations :
w est la solution exacte
si u est le vecteur des valeurs u(i) alors up est le vecteur des u(i+1) um est le vecteur des u(i-1)
Schémas classiques
Lax-Friedrichs
25
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% marche en temps : Lax-Friedrichs avec cfl=0.9%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% w est la solution exacte% si u est le vecteur des valeurs u(i) alors % up est le vecteur des u(i+1) % um est le vecteur des u(i-1)% for n=1:nt%up = wshift2('1D',u,+1) ;um = wshift2('1D',u,-1) ;v = (up+um)/2 - (0.5*dt/dx)*a*(up-um) ;u = v ; % affichage de la solution approchee et exacteif mod(n,5) == 0 w = soltr(w,nx,dx,dt,a,n) ; plot(x,u,'o',x,w) ; axis([0 lg -1.1 1.1]) ; title('Lax-Friedrichs, cfl=0.9') pause(0) ;end%end
Lax Friedrichs
Evolution temporelle : CFL = 0.9
26
Schémas classiques
Lax Friedrichs
27
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% nouveau schema: Lax-Friedrichs avec cfl=1.1 (explose)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%dt = 1.1*cfl ;nt = 400 ;%% for n=1:nt%up = wshift2('1D',u,+1) ;um = wshift2('1D',u,-1) ;v = (up+um)/2 - (0.5*dt/dx)*a*(up-um) ;u = v ; if mod(n,5) == 0w = soltr(w,nx,dx,dt,a,n) ;plot(x,u,'o',x,w) ;axis([0 lg -1.1 1.1]) ;title('Lax-Friedrichs, cfl=1.1')pause(0) ;end%end
Lax Friedrichs
Evolution temporelle : CFL = 1.1
28
Lax Friedrichs
CFL = 0.1 (très dissipatif )
29
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% nouveau schema: Lax-Friedrichs avec cfl=0.1 (tres dissipatif)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%dt = 0.1*cfl ;nt = 1000 ;
Lax Friedrichs
Evolution temporelle : CFL = 0.1
30
Schémas classiques
Centré explicite
31
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% nouveau schema: centre explicite avec cfl=0.5 (explose)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%dt = 0.5*cfl ;nt = 400 ;
for n=1:nt%up = wshift2('1D',u,+1) ;um = wshift2('1D',u,-1) ;v = u - (0.5*dt/dx)*a*(up-um) ;u = v ; if mod(n,5) == 0w = soltr(w,nx,dx,dt,a,n) ;plot(x,u,'o',x,w) ;axis([0 lg -1.1 1.1]) ;title('centre explicite, cfl=0.5')pause(0) ;end%end
Centré Explicite
CFL = 0.5
32
Schémas classiques
Centré explicité : CFL =0.1
33
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% nouveau schema: centre explicite avec cfl=0.1 (n'explose pas)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%dt = 0.1*cfl ;nt = 1000 ;
Centré explicite
CFL = 0.1
34
Centré implicite
Centré impliciteCFL=0.9
35
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% nouveau schema: centre implicite avec cfl=0.9%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%dt = 0.9*cfl ;nt = 400 ;%%% initialisation%x=zeros(1,nx) ;u=zeros(1,nx) ;v=zeros(1,nx) ;w=zeros(1,nx) ;for i=1:nx x(i) = (i-1)*dx ; u(i) = sin(x(i)*2*pi) ;endw = u ;mat=zeros(nx,nx) ;for i=2:nx-1 mat(i,i) = 1. ; mat(i,i+1) = (0.5*dt/dx)*a ; mat(i,i-1) = -(0.5*dt/dx)*a ;endmat(1,1) = 1. ;mat(1,2) = (0.5*dt/dx)*a ;mat(1,nx) = -(0.5*dt/dx)*a ;mat(nx,nx-1)= -(0.5*dt/dx)*a ;mat(nx,1) = (0.5*dt/dx)*a ;mat(nx,nx) = 1. ;smat = sparse(mat) ; plot(x,u) ;axis([0 lg -1.1 1.1]) ;title('centre implicite, cfl=0.9')
for n=1:nt%u0=u';v=smat\u0 ;u = v' ; if mod(n,5) == 0w = soltr(w,nx,dx,dt,a,n) ;plot(x,u,'o',x,w) ;axis([0 lg -1.1 1.1]) ;title('centre implicite, cfl=0.9')pause(0) ;end%F = getframe(fig); aviobj = addframe(aviobj,F);end
Centré implicite
CFL = 0.9
36
Centré implicité
CFL = 2
37
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% nouveau schema: centre implicite avec cfl=2.0%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%dt = 2.0*cfl ;nt = 400 ;
Centré implicité
CFL = 2
38
Lax Wendroff
Lax-Wendroff
39
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% nouveau schema: Lax-Wendroff avec cfl=0.9%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%dt = 0.9*cfl ;nt = 800 ;%% for n=1:nt%up = wshift2('1D',u,+1) ;um = wshift2('1D',u,-1) ;v = u - (0.5*dt/dx)*a*(up-um) + ... (0.5*dt*dt/(dx*dx))*( a*a*(up-u) ... - a*a*(u-um) ) ;u = v ; if mod(n,5) == 0w = soltr(w,nx,dx,dt,a,n) ;plot(x,u,'o',x,w) ;axis([0 lg -1.1 1.1]) ;title('Lax-Wendroff, cfl=0.9')pause(0) ;end%end
Lax Wendroff
CFL = 0.9
40
Solution discontinue
Condition initiale créneau
41
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% donnee initiale = creneau% nouveau schema: Lax-Friedrichs avec cfl=0.9%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%dt = 0.9*cfl ;nt = 400 ;%% initialisation%x=zeros(1,nx) ;u=zeros(1,nx) ;v=zeros(1,nx) ;w=zeros(1,nx) ;up=zeros(1,nx) ;um=zeros(1,nx) ;for i=1:nx x(i) = (i-1)*dx ; if x(i) < lg/2 u(i) = -1. ; else u(i) = 1. ; endendw = u ; plot(x,u) ;axis([0 lg -1.1 1.1]) ;title('Lax-Friedrichs, cfl=0.9') pause ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% marche en temps : Lax-Friedrichs%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for n=1:nt%up = wshift2('1D',u,+1) ;um = wshift2('1D',u,-1) ;v = (up+um)/2 - (0.5*dt/dx)*a*(up-um) ;u = v ; if mod(n,5) == 0 for i=1:nx xi = (i-1)*dx-a*n*dt ; xint = floor(xi/lg) ; xi = xi - xint*lg ; if xi < lg/2 w(i) = -1. ; else w(i) = 1. ; end endplot(x,u,'o',x,w) ;axis([0 lg -1.1 1.1]) ;title('Lax-Friedrichs, cfl=0.9')pause(0) ;end%end pause ;
Lax Friedrichs
Créneau
42
Lax Wendroff
CréneauCFL = 0.9
43
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% donnee initiale = creneau% nouveau schema: Lax-Wendroff avec cfl=0.9%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%dt = 0.9*cfl ;nt = 400 ;%
for n=1:nt%up = wshift2('1D',u,+1) ;um = wshift2('1D',u,-1) ;v = u - (0.5*dt/dx)*a*(up-um) + ... (0.5*dt*dt/(dx*dx))*( a*a*(up-u) ... - a*a*(u-um) ) ;u = v ; if mod(n,5) == 0 for i=1:nx xi = (i-1)*dx-a*n*dt ; xint = floor(xi/lg) ; xi = xi - xint*lg ; if xi < lg/2 w(i) = -1. ; else w(i) = 1. ; end endplot(x,u,'o',x,w) ;axis([0 lg -1.4 1.4]) ;title('Lax-Wendroff, cfl=0.9')pause(0) ;end%end
Lax Wendroff
Créneau
44
Adaptation automatique
Méthode du maillage mobile
Points de grille mobiles
Dérivée temporelle de u sur cette grille
Fonction de monitoring
45
Advection de front d’onde
Adaptation du maillage
46
Exemples d’applications
transport linéaire en 2-d
transport linéaire non diffusif
trafic routier
équations d'Euler 2-d
Euler avec friction et Darcy
schémas VFRoe et VFRoe-ncv
chocs non classiques
schéma exact de Godunov
approximation d'ordre élevé
schéma équilibre
dynamique des gaz sans pression
couplage de deux systèmes
MHD -> modèle de Thomas
47
Projet Numerique : 3x4h
48
UPMC M1 EE
UE : 4AE04
Pratique de l’optimisation numerique et du calcul
scientifique
Resolution d’EDP
et maillage adaptatif
1. Maillage Adaptatif
(a) Lire le code matlab et faire le lien avec l’article de Huang et al..
(b) Donner la signification du parametre ⌧ et etudier son influence sur la simulation.
(c) Donner la signification du parametre � et etudier son influence sur la simulation.
(d) Donner la signification du parametre p et etudier son influence sur la simulation.
(e) Tracer les evolutions temporelles des quantites H(t) et E(t) de l’article de Huanget al.. Comparer les resultats obtenus pour la simulation avec le meme jeu deparametres (fig. 6 p287). Commenter vos resultats.
(f) Comparer la methodes a maillage adaptatif avec les methodes a maillage fixe clas-sique : Euler, Lax-Wendro↵, Lax-Friedrichs en regime stationnaire et instation-naire.
(g) Que peut-on conclure sur l’interet des methodes a maillage adaptatif.
1
Projet Numerique : 3x4h
49
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−0.4
−0.3
−0.2
−0.1
0
0.1
0.2
0.3
0.4
x
solu
tion
u
Burgers equation. Mass matrix M(t,y). MMPDE6
t = 0t = 0.2t = 0.6t = 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
0.2
0.4
0.6
0.8
1
xt
Burgers equation. Grid trajectories
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−0.4
−0.3
−0.2
−0.1
0
0.1
0.2
0.3
0.4Lax−Wendroff
2
50