short introduction to freefem
TRANSCRIPT
-
8/10/2019 Short Introduction to Freefem
1/29
A short introduction to FreeFem++
M. Ersoy
Basque Center for Applied Mathematics
12 November 2010
-
8/10/2019 Short Introduction to Freefem
2/29
Outline of the talkOutline of the talk
1 Introduction
2 HOW TOsolve steady pdes : e.g. Laplace equationsolve unsteady pdes : e.g. Heat equation
M. Ersoy (BCAM) Freefem++ 12 November 2010 2 / 22
-
8/10/2019 Short Introduction to Freefem
3/29
OutlineOutline
1 Introduction
2 HOW TOsolve steady pdes : e.g. Laplace equationsolve unsteady pdes : e.g. Heat equation
M. Ersoy (BCAM) Freefem++ 12 November 2010 3 / 22
-
8/10/2019 Short Introduction to Freefem
4/29
-
8/10/2019 Short Introduction to Freefem
5/29
A software for solving PDEs
FreeFem++ for 2D-3D 1 PDEsFinite element method
Freesoftware : available at http://www.freefem.org/ff++/ 2 , it runs on Linux Windows
Mac
1. in progress2. Useful documentation available at http://www.freefem.org/ff++/ftp/freefem++doc.
pdfM. Ersoy (BCAM) Freefem++ 12 November 2010 4 / 22
http://www.freefem.org/ff++/http://www.freefem.org/ff++/ftp/freefem++doc.pdfhttp://www.freefem.org/ff++/ftp/freefem++doc.pdfhttp://www.freefem.org/ff++/ftp/freefem++doc.pdfhttp://www.freefem.org/ff++/ftp/freefem++doc.pdfhttp://www.freefem.org/ff++/ftp/HISTORYhttp://www.freefem.org/ff++/ -
8/10/2019 Short Introduction to Freefem
6/29
A software for solving PDEs
FreeFem++for 2D-3D1
PDEsFinite element method
Free software : available at http://www.freefem.org/ff++/ 2 , it runs on Linux Windows
Mac++extension of FreeFem and FreeFem+ (see Historichttp://www.freefem.org/ff++/ftp/HISTORY)
1. in progress2. Useful documentation available at http://www.freefem.org/ff++/ftp/freefem++doc.
pdfM. Ersoy (BCAM) Freefem++ 12 November 2010 4 / 22
http://www.freefem.org/ff++/http://www.freefem.org/ff++/ftp/HISTORYhttp://www.freefem.org/ff++/ftp/freefem++doc.pdfhttp://www.freefem.org/ff++/ftp/freefem++doc.pdfhttp://www.freefem.org/ff++/ftp/freefem++doc.pdfhttp://www.freefem.org/ff++/ftp/freefem++doc.pdfhttp://www.freefem.org/ff++/ftp/HISTORYhttp://www.freefem.org/ff++/ -
8/10/2019 Short Introduction to Freefem
7/29
A software for solving PDEs
FreeFem++ for 2D-3D1
PDEsFinite element method
Free software : available at http://www.freefem.org/ff++/ 2 , it runs on Linux Windows
Mac++ extension of FreeFem and FreeFem+ (see Historichttp://www.freefem.org/ff++/ftp/HISTORY)
FreeFem++ team : Olivier Pironneau, Frederic Hecht, Antoine Le Hyaric,Jacques Morice
1. in progress2. Useful documentation available at http://www.freefem.org/ff++/ftp/freefem++doc.
pdfM. Ersoy (BCAM) Freefem++ 12 November 2010 4 / 22
http://www.freefem.org/ff++/http://www.freefem.org/ff++/ftp/HISTORYhttp://www.freefem.org/ff++/ftp/freefem++doc.pdfhttp://www.freefem.org/ff++/ftp/freefem++doc.pdfhttp://www.freefem.org/ff++/ftp/freefem++doc.pdfhttp://www.freefem.org/ff++/ftp/freefem++doc.pdfhttp://www.freefem.org/ff++/ftp/HISTORYhttp://www.freefem.org/ff++/ -
8/10/2019 Short Introduction to Freefem
8/29
OutlineOutline
1 Introduction
2 HOW TOsolve steady pdes : e.g. Laplace equationsolve unsteady pdes : e.g. Heat equation
M. Ersoy (BCAM) Freefem++ 12 November 2010 5 / 22
-
8/10/2019 Short Introduction to Freefem
9/29
OutlineOutline
1 Introduction
2 HOW TOsolve steady pdes : e.g. Laplace equationsolve unsteady pdes : e.g. Heat equation
M. Ersoy (BCAM) Freefem++ 12 November 2010 6 / 22
-
8/10/2019 Short Introduction to Freefem
10/29
The problem
Given fL2(), find H10 () such that :
= f in (x1, x2) = 0 on 1
n:= n= 0 on 2
M. Ersoy (BCAM) Freefem++ 12 November 2010 7 / 22
-
8/10/2019 Short Introduction to Freefem
11/29
Variational formulation (VF)
Let w be a test function, the VF of the Laplace equation is :
w dx=
f w d x
or equivalentlyA(, w) =l(w)
where the bilinear form is
A(, w) =
w dx
and the linear one :l(w) =
f w d x
M. Ersoy (BCAM) Freefem++ 12 November 2010 8 / 22
-
8/10/2019 Short Introduction to Freefem
12/29
Variational problem
Problem is now to find vH10 () such that, for every wH10 () :
A(, w) =l(w)
where the bilinear form is
A(, w) =
w dx
and the linear one :
l(w) = f w d xWe set V =H1() in the next
M. Ersoy (BCAM) Freefem++ 12 November 2010 9 / 22
-
8/10/2019 Short Introduction to Freefem
13/29
FEM : Galerkin method
Let Vh V with dimVh=nh,
Vh =
u(x, y); u(x, y) =
nhk=1
ukk(x, y), uk R
where k Ps is a polynom of degree s.Now, the problem is to find hVh such that :
wVh, A(h, w) =l(w)
So, we have to solve :
i {1, . . . , nh}, A(j , i) =l(i)
M. Ersoy (BCAM) Freefem++ 12 November 2010 10 / 22
-
8/10/2019 Short Introduction to Freefem
14/29
Spaces VhSpaces Vh =Vh(h, P) will depend on the mesh :
h=
n
k=1
Tk
andthe approximation PP0 piecewise constant approximationP1 C
0 piecewise linear approximation
...M. Ersoy (BCAM) Freefem++ 12 November 2010 11 / 22
-
8/10/2019 Short Introduction to Freefem
15/29
With FreeFem++
To numerically solve the Laplace equation, we have to :
1 mesh the domain (define the border + mesh)
2 write the VF3 show the result
its easy !
M. Ersoy (BCAM) Freefem++ 12 November 2010 12 / 22
-
8/10/2019 Short Introduction to Freefem
16/29
Step 1 : mesh of the domain
if = 1+ 2+. . .thenFreeFem++ define border commands : borderGamma1(t = t0,tf){x = gam11(t), y = gam12(t)} ; borderGamma2(t = t0,tf){x = gam21(t), y = gam22(t)} ; ...
where the set {x = gam11(t), y = gam12(t)} is a parametrisation of theborder Gamma1 with t [t0, tf]
M. Ersoy (BCAM) Freefem++ 12 November 2010 13 / 22
http://edp/maillage.edp -
8/10/2019 Short Introduction to Freefem
17/29
Step 1 : mesh of the domain
if = 1+ 2+. . .thenFreeFem++ define border commands : borderGamma1(t = t0,tf){x = gam11(t), y = gam12(t)} ; borderGamma2(t = t0,tf){x = gam21(t), y = gam22(t)} ; ...
where the set {x = gam11(t), y = gam12(t)} is a parametrisation of theborder Gamma1 with t [t0, tf]
FreeFem++ mesh commands :
meshMeshName =buildmesh(Gamma1(m1)+Gamma1(m2)+. . . ) ;
where mi are positive (or negative) numbers to indicate the number of pointshould on j . example
M. Ersoy (BCAM) Freefem++ 12 November 2010 13 / 22
http://edp/maillage.edphttp://edp/maillage.edp -
8/10/2019 Short Introduction to Freefem
18/29
S 2 VF
-
8/10/2019 Short Introduction to Freefem
19/29
Step 2 : write the VFPremliminar
To write the VF, we need to
define finite element space , we will use :
fespaceNameFEspace(MeshName,P) ;
where P = P0 or P1 or P2, . . . . Example :fespaceVh(Omegah,P2) ;
use interpolated function, for instance,
Vh f = x+y ;
N.B. x and y are reserved key words
M. Ersoy (BCAM) Freefem++ 12 November 2010 14 / 22
S 2 VF
-
8/10/2019 Short Introduction to Freefem
20/29
Step 2 : write the VFVF
VF is simply what we write on paper, for instance, for the Laplace equation, weshould have :
Vh phi, w, f ;
problemLaplace(phi,w)int2d(Omegah)(dx(phi)*dx(w) + dy(phi)*dy(w))- int2d(Omegah)(f*w)
+ boundary conditions;
where w, phi belong to FE space Vh.
M. Ersoy (BCAM) Freefem++ 12 November 2010 15 / 22
S 2 VF
-
8/10/2019 Short Introduction to Freefem
21/29
Step 2 : write the VFVF
VF is simply what we write on paper, for instance, for the Laplace equation, weshould have :
Vh phi, w, f ;
problemLaplace(phi,w)int2d(Omegah)(dx(phi)*dx(w) + dy(phi)*dy(w))- int2d(Omegah)(f*w)
+ boundary conditions;
where w, phi belong to FE space Vh.Next, to solve it, just write :
Laplace ;
M. Ersoy (BCAM) Freefem++ 12 November 2010 15 / 22
S 2 VF
-
8/10/2019 Short Introduction to Freefem
22/29
Step 2 : write the VFVF
VF is simply what we write on paper, for instance, for the Laplace equation, weshould have :
Vh phi, w, f ;
problemLaplace(phi,w)int2d(Omegah)(dx(phi)*dx(w) + dy(phi)*dy(w))- int2d(Omegah)(f*w)
+ boundary conditions;
where w, phi belong to FE space Vh.
or equivalently write directly :
solveLaplace(phi,w)int2d(Omegah)(dx(phi)*dx(w) + dy(phi)*dy(w))-int2d(Omegah)(f*w)+ boundary conditions
;M. Ersoy (BCAM) Freefem++ 12 November 2010 15 / 22
Step 2 write the VF
-
8/10/2019 Short Introduction to Freefem
23/29
Step 2 : write the VFBoundary conditions 3
Dirichlet condition u= g : +on(BorderName, u=g)
Neumann condition nu= g : -int1d(Th)( g*w). . .
3. see the manual p. 142M. Ersoy (BCAM) Freefem++ 12 November 2010 16 / 22
Step 3 : show the result
-
8/10/2019 Short Introduction to Freefem
24/29
Step 3 : show the result
to plot
plot(phi) ;
or
plot([dx(phi),dy(phi)]) ;
Laplace equation
M. Ersoy (BCAM) Freefem++ 12 November 2010 17 / 22
Outline
http://edp/Laplace.edphttp://edp/Laplace.edp -
8/10/2019 Short Introduction to Freefem
25/29
Outline
1 Introduction
2 HOW TOsolve steady pdes : e.g. Laplace equationsolve unsteady pdes : e.g. Heat equation
M. Ersoy (BCAM) Freefem++ 12 November 2010 18 / 22
The problem
-
8/10/2019 Short Introduction to Freefem
26/29
The problem
Given fL2(), find H1() such that :
t= f in (x1, x2) =z(x1, x2) on 1n:= n= 0 on 2
may be rewritten, after an implicit Euler finite difference approximation in time asfollows :
n+1 n
t n+1 =fn
M. Ersoy (BCAM) Freefem++ 12 November 2010 19 / 22
Variational formulation
-
8/10/2019 Short Introduction to Freefem
27/29
Variational formulation
The Variational formulation for the semi discrete equation is : let w be a testfunction, we write :
n+1 nt
w+n+1 w dx=
fnw dx
M. Ersoy (BCAM) Freefem++ 12 November 2010 20 / 22
The FreeFem formulation
-
8/10/2019 Short Introduction to Freefem
28/29
The FreeFem formulation
Following the steady state case, the problem is then :
solveLaplace(phi,w)int2d(Omegah)(phi*w/dt+dx(phi)*dx(w) + dy(phi)*dy(w))
-int2d(Omegah)(phiold*w/dtf*w)+ boundary conditions;
where we have to solve iteratively this discrete equation. example
M. Ersoy (BCAM) Freefem++ 12 November 2010 21 / 22
http://edp/evo1.edphttp://edp/evo1.edp -
8/10/2019 Short Introduction to Freefem
29/29
Enjoy
yourself
M. Ersoy (BCAM) Freefem++ 12 November 2010 22 / 22