FF Basic Tutorial
FF Basic Tutorial
Yannick Deleuze
Laboratoire Jacques-Louis Lions, Sorbonne Universités, UPMC Univ Paris 06, France
Scientific Computing and Cardiovascular Lab, Department of ESOE, National Taiwan University
Center of Advanced Study in Theoretical Sciences, National Taiwan University
CASTS-LJLL Workshop
Under the supervision
on Applied Mathematics of
and Mathematical Sciences
Marc Thiriet May
and 28, 2013 Tony W.H. Sheu
Outline
Introduction
Numerical examples
Outline
Introduction
FreeFem++
Numerical examples
FreeFem++
Goal
Present a basic introduction to FreeFem++ for beginners with FreeFem++.
Outline
Introduction
FreeFem++
Numerical examples
FreeFem++
http://www.freefem.org/ff++
F. Hecht, O. Pironneau
A. Le Hyaric, K. Ohtsuka
FreeFem++ scripts can be written in any text editor and saved to a ”.edp” file.
Lauching an ’.edp’ file depends on your operating system.
1 x , y , z // C a r t e s i a n c o o r d i n a t e s
2 N . x , N . y , N . z // Normal v e c t o r components
3 i n t k = 1 0 ; // i n t e g e r
4 r e a l a = 2 . 5 ; // r e a l
5 b o o l b=(a <3.) ; / b o o l e a n
6 r e a l [ i n t ] a r r a y ( k ) ; // a r r a y o f k e l e m e n t s
7 a r r a y [ ] [ 5 ] ; // 6 t h v a l u e o f t h e a r r a y
8 mesh Th ; // 2d mesh
9 mesh3 Th3 // 3d mesh
10 f e s p a c e Vh ( Th , P1 ) ; // f i n i t e e l e m e n t s p a c e
11 Vh u=x ; // f i n i t e e l e m e n t f u n c t i o n
12 Vh3<complex> uc = x+ 1 . i ∗y ; // c o m p l e x f i n i t e e l e m e n t f u n c t i o n
13 f e s p a c e Xh ( Th , [ P2 , P2 , P1 ] ) ;
14 Xh [ u1 , u2 , p ] ; // a v e c t o r i a l f i n i t e e l e m e n t f u n c t i o n o r a r r a y
15 u [ ] ; // t h e a r r a y a s s o c i a t e d t o FE f u n c t i o n u
16 u ( 1 . , 0 . 1 , 3 . ) ; // v a l u e o f u a t p o i n t ( 1 . , 0 . 1 , 3 . )
17 u [ ] . max ; // max o f t h e a r r a y u
18 u [ ] . min ; // max o f t h e a r r a y u
19 u [ ] . sum ; //sum o f a l l e l e m e n t s o f u
20 u [ ] . l 1 ; // l 1 norm o f u
21 u [ ] . l 2 ; // l 2 norm o f u
22 u [ ] . l i n f t y ; // l i n f i n i t y norm o f u
23 macro d i v ( u , v ) ( dx ( u )+dy ( v ) ) // EOM
24 macro Grad ( u ) [ dx ( u ) , dy ( u ) ] // EOM
25 f u n c f=x+y ; // f u n c t i o n
26 f u n c r e a l f ( i n t i , r e a l a ) { . . . . . ; r e t u r n i+a ; }
27 v a r f a ( [ u1 , u2 , p ] , [ v1 , v2 , q ] )= i n t 2 d ( . . . ) + on ( . . )
28 m a t r i x A = a ( Vh , Vh , s o l v e r=UMFPACK) ; // r i g i d m a t r i c o f t h e p r o b l e m
29 r e a l [ i n t ] b=a ( 0 , V3h ) ; // r i g h t hand s i d e
30 u [ ] =Aˆ−1∗b ; // s o l v i n g u = Aˆ−1∗b
Outline
Introduction
Numerical examples
Outline
Introduction
Numerical examples
Laplace equation
−∇2 u = f , in Ω
u|∂Ω = g.
Outline
Introduction
Numerical examples
Integration by parts
2. Integration by parts
Z Z Z
∂v ∂u
u dx = − v dx + u v dΓ
Ω ∂xi Ω ∂xi ∂Ω
Due to the Dirichlet boundary conditions we choose v such that v|∂Ω = 0. Let
Vϕ = {w ∈ H 1 (Ω)|w|∂Ω = ϕ}, then the problem becomes
R R
a(u, v ) = Ω
∇u.∇v is the bilinear form and l(v ) = Ω
fv is the linear form.
Finite element method
Freefem++ uses the most common finite elements for the discretisation of the
continuous problem.
Consider the continuous piecewise polynomial of degree one (P1 ) finite element
dizcretization on the triangulation Th of Ωh .
The discrete problem becomes
Introduction
Numerical examples
Meshing
It order to solve the problem on a computer, we need to decretize it. The first
step of the discretisation is to triangulate the physical domain Ω into the
computational domain Th. We can use the keyword square to triangulate the
domain and generate the mesh. We need to provide a number N of vertex
placed on the borders.
square
1 i n t nn =10;
2 mesh Th = s q u a r e ( nn , nn ) ;
3 p l o t ( Th , w a i t =1 , p s=” m e s h s q u a r e . e p s ” ) ;
rectangle
1 r e a l x0 =0 , x1 =10; r e a l l x=x1−x0 ;
2 r e a l y0 =0 , y1 =5; r e a l l y=y1−y0 ;
3 mesh Th1=s q u a r e ( nn , 2 ∗ nn , [ x0+(x1−x0 ) ∗x , y0+(y1−y0 ) ∗ y ] ) ;
4 p l o t ( Th1 , w a i t =1 , p s=” m e s h r e c t a n g l e . e p s ” ) ;
Note that we use the keyword plot to plot the mesh and the keyword wait to
stop the program at each plot.
Meshing : borders
Figure : Square mesh generated with Figure : Rectangle mesh generated with
square square
Meshing : borders
1 i n t c i r c l e =0;
2 b o r d e r c ( t =0 ,2∗ p i ) { x=1+3∗ c o s ( t ) ; y=−1+3∗ s i n ( t ) ; l a b e l= c i r c l e ; }
3 mesh Th3=b u i l d m e s h ( c ( 1 0 0 ) ) ;
4 p l o t ( Th3 , w a i t =1 , p s=” c i r c l e . e p s ” , cmm=” C i r c l e mesh ” ) ;
Circle mesh
Ranunculoid mesh
Meshing : save & load
1 s a v e m e s h ( Th2 , ” m e s h f i l e . msh” ) ;
Introduction
Numerical examples
Finite Element Spaces
fespace defines the the discrete FE space for the unknowns and test functions;
n o
Vh(Th, P1) = w (x, y )|w (x, y ) = ΣM k=1 wk Φk (x, y ), wk ∈ R
04, 571587 (1994). (The residual-free bubbles technique interprets the stabilization parameter as the mean value of the solution of a
where dx(u) = ∂u
∂x
∂u
, dy(u) = ∂y . The keyword on defines the Dirichlet boundary
condition on the borders 1, 2, 3 and 4.
1 f u n c f =1; // r i g h t hand s i d e f u n c t i o n
2 f u n c g =0; // boundary c o n d i t i o n f u n c t i o n
3
4 // definion of the problem
5 problem l a p l a c e (u , v ) =
6 i n t 2 d ( Th ) ( dx ( u ) ∗ dx ( v ) + dy ( u ) ∗ dy ( v ) ) // b i l i n e a r form
7 − i n t 2 d ( Th ) ( f ∗ v ) // l i n e a r form
8 + on ( 1 , 2 , 3 , 4 , u=g ) ; // b o u n d a r y c o n d i t i o n form
Solve the problem
FreeFem++ automatically builds the associate matrix and the second member
vector.
1 laplace ;
FreeFem++ solves elliptic equation. The user should specify it’s own
algorithms to solve parabolic and hyperbolic problems.
The user can specify the solver to solve the linear problem associated.
FreeFem++ provides a large variety of linear direct and iterative solvers (LU,
Cholesky, Crout, CG, GMRES, multi-frontal method UMFPACK, MUMPS
(MUltifrontal Massively Parallel sparse direct Solver), SuperLU, ...).
Visualization
Use the keyword plot to plot the solution with useful options :
I ps= string to save the plot in a eps file;
I cmm = string to add comment
I if value= 1 plot the value of isolines
I if fill=1 color fill between isolines
I if wait=1 stop the program at this plot
1 p l o t ( u , p s=” L a p l a c e . e p s ” , v a l u e =1 , w a i t =1 , f i l l =1 , cmm=” S o l u t i o n u o f
t h e L a p l a c e e q u a t i o n i n \Omega” ) ;
Outline
Introduction
Numerical examples
Heat equation
Convection
Stationary Stokes problem
Convection-Diffusion Equation
Outline
Introduction
Numerical examples
Heat equation
Time discretization
Spatial discretization
Practical implementation
Convection
Stationary Stokes problem
Convection-Diffusion Equation
Heat problem
First, let us consider a time discretization of the heat equation (35) . Time is
discretize with finite difference schemes such as
θ - scheme [Raviart-Thomas 1998]
We discretize time (0, T ) in M − 1 intervals ∆t = T
M−1
and M points (tm )M−1
m=0
such that U(tm , x) = U m (x).
∂U U n+1 − U n
≈ = θF (U n+1 ) + (1 − θ)F (U n )
∂t ∆t
I Euler explicit (θ = 0)
I Euler implicit (θ = 1)
I Crank-Nicolson (θ = 12 )
Time discretization
Let us choose the Euler implicit quadrature. The heat problem in its
semi-discrete form becomes
u n+1 − u n
− ∇ · (κ∇u n+1 ) = 0
∆t
Exercise : Implement the Crank-Nicolson scheme or any higher order scheme of
your choice.
Spatial discretization
a(u, v ) = l(v )
with
1 n+1
κ∇u n+1 ∇v the bilinear form,
R R
I a(u, v ) = Ω ∆t
u v+ Ω
R R 1 n
I and l(v ) = − ∂ΓN
κ UN v − Ω ∆t u v the linear form.
Heat equation on the unit square
square mesh
1 i n t CD=10; // c o u l d be a n y t h i n g
2 r e a l x0 =0 , x1 =1;
3 r e a l y0 =0 , y1 =1;
4 i n t nn =30;
5 mesh Ths=s q u a r e ( nn , nn , [ x0+(x1−x0 ) ∗x , y0+(y1−y0 ) ∗ y ] ) ;
6 i n t [ i n t ] l a b e l s =[1 ,CD, 2 , CD, 3 , CD, 4 , CD ] ; // c h a n g e t h e l a b e l s from
1 , 2 , 3 , 4 t o CD
7 Ths=c h a n g e ( Ths , l a b e l= l a b e l s ) ;
8 p l o t ( Ths , w a i t =1 , p s=” s q u a r e . e p s ” , cmm=” s q u a r e mesh ” ) ;
Defining the problem
Parameters
1 i n t i ; // t i m e l o o p i t e r a t o r
2 i n t M=10; // t i m e i t e r a t i o n s
3 r e a l d t = 0 . 0 0 0 0 1 ; // t i m e s t e p
Initial condition
1 u = s i n ( p i ∗x ) ∗ s i n ( p i ∗y ) ;
Variational problem
1 r e a l kappa= 1 ;
2 macro F ( u , v ) kappa ∗( dx ( u ) ∗ dx ( v )+dy ( u ) ∗ dy ( v ) ) //eom
3 p r o b l e m h e a t ( u , v , i n i t =i )
4 = i n t 2 d ( Ths ) ( u∗ v / d t )
5 + i n t 2 d ( Ths ) ( F ( u , v ) )
6 − i n t 2 d ( Ths ) ( u0∗ v / d t )
7 + on (CD, u=0)
8 ;
Solving the system
Time loop
1 f o r ( i =0; i <M; i ++) {
2 u0=u ; // u p d a t e from p r e v i o u s s t e p t i m e
3 h e a t ; // s o l v e t h e l i n e a r s y s t e m
4 p l o t ( u , w a i t =0 , f i l l =1 , v a l u e =1 ,cmm=” s o l u t i o n a t t i m e ”
+i ∗ dt , v i s o=v i s o ) ; // p l o t t h e s o l u t i o n a t e a c h
step time
5 }
Visualize the solution
!_N
!_D
Figure : Ω
Introduction
Numerical examples
Heat equation
Convection
Characteristic-Galerkin method
Operators
Solvers
Input-Output
Practical implementation
Stationary Stokes problem
Convection-Diffusion Equation
Convection
Characteristic-Galerkin method
The convection equation can be discretised as [See FreeFem++
documentation]
u n+1 (x) − u n (X n )
= f n (x).
∆t
1 p r o b l e m c o n v e c t ( u , w)
2 = i n t 2 d ( Th ) ( 1/ d t ∗u∗w)
3 − i n t 2 d ( Th ) ( 1 / d t ∗ c o n v e c t ( [ a1 , a2 ] , − dt , up ) ∗w)
4 − i n t 2 d ( Th ) ( f ∗w) ;
Operators
The user can provide the solver to solve the linear problem associated.
FreeFem++ provides a large variety of linear direct and iterative solvers (LU,
Cholesky, Crout, CG, GMRES, UMFPACK, MUMPS, SuperLU, ...).
A useful option is init. If init 6= 0, than the decomposition of the stiff matrix
associated to the problem is reused.
Exercise :
I Change the solver used.
I Use the init parameter to save computational time.
Input-Output in FreeFem++
The user can import/export data from FreeFem++ such as meshes files,
postscript images, text files. Other format are handle with FreeFem++ to
interact with third parties softwares.
Terminal
The syntax write/read in the terminal is similar to C++ with the keywords cin,
cout, <<, >>, endl.
1 i n t nn ;
2 c o u t << ” number o f n o d e s on t h e b o r d e r s nn= ” << e n d l ; // w r i t i n g i n
the terminal
3 c i n >> nn ; // r e a d v a l u e from t h e t e r m i n a l
4 mesh Tht=s q u a r e ( nn , nn ) ;
Files
To write/read a file, first the user need to declare a variable with ofstream
(output) or ifstream (input). Then, the syntax for input and output in a file
remains the same.
1 i f s t r e a m f i n ( ” d a t a . t x t ” ) ; // d e c l a r e an i n p u t from f i l e
2 r e a l ff , fg ;
3 f i n >> f f ; // r e a d s t h e 1 s r t v a l u e from t h e f i l e
4 f i n >> f g ; // r e a d s t h e 2 nd v a l u e from t h e f i l e
5 f u n c f= f f ;
6 f u n c g=f g ;
Input-Output in FreeFem++
Mesh
To import/export mesh the function read mesh and save mesh are available.
Refer to the documentation for full list of format one can import in
FreeFem++.
1 s a v e m e s h ( Tht , ” m e s h f i l e . msh” ) ; // e x p o r t mesh
2 mesh Th = r e a d m e s h ( ” m e s h f i l e . msh” ) ; // i m p o r t mesh
1 Vh u 4 p l o t ;
2 { ifstream fu (” s o l u t i o n . txt ”) ;
3 f u >> u 4 p l o t [ ] ; } // i m p o r t a FE s o l u t i o n
4 p l o t ( u 4 p l o t , p s=” L a p l a c e . e p s ” ) ; // e x p o r t image
9 8 8
0 0 4
0.5 0 1
1 0 2
0 0.5 4
0.5 0.5 0
N b V e r t i c e s NbElements NbBorderElem
1 0.5 2
// c o o r d i n a t e s o f v e r t i c e s
0 1 4
x1 y1 l a b e l // 1 s r t v e r t i c e
0.5 1 3
x2 y2 l a b e l // 2 nd v e r t i c e
1 1 3
...
1 2 5 0
// e l e m e n t w i t h 3 v e r t i c e s 1 , 2 , 3
1 5 4 0
v1 v2 v3 r e g i o n
2 3 6 0
v1 v2 v4 r e g i o n
2 6 5 0
v3 v4 v5 r e g i o n
4 5 8 0
...
4 8 7 0
// b o u n d a r y e l e m e n t i s a s e g m e n t
5 6 9 0
of 2 v e r t i c e s
5 9 8 0
v1 v2 l a b e l
1 2 1
v2 v3 l a b e l
2 3 1
...
3 6 2
6 9 2
8 7 3
9 8 3
4 1 4
7 4 4
FE solution file
9
6 . 2 5 e−62 6 . 2 5 e−32 6 . 2 5 e−62 6 . 2 5 e−32
0.0625
6 . 2 5 e−32 6 . 2 5 e−62 6 . 2 5 e−32 6 . 2 5 e−62
NbVertices
u (1) u (2) u (3)
u (4) u (5) . . .
... u( NbVertices )
Pure convection
Pure convection
u(10)
Introduction
Numerical examples
Heat equation
Convection
Stationary Stokes problem
Governing equations
Variational formulation
Practical implementation
Convection-Diffusion Equation
Stationary Stokes equations
where u = (u1 , u2 ) is the velocity vector and p the pressure. ∇2 , here, stands
for the vector Laplacian. In Cartesian coordinantes, ∇2 u = (∇2 u1 , ∇2 u2 ).
Variational problem
1 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 // F i n i t e E l e m e n t S p a c e s
3 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
4 f e s p a c e Xh ( Th , P2 ) ;
5 f e s p a c e Mh( Th , P1 ) ;
6 Xh u2 , v2 ;
7 Xh u1 , v1 ;
8 Mh p , q ;
9
10 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
11 // S t o k e s
12 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
13 f u n c g=4∗y∗(1−y ) ;
14
15 s o l v e S t o k e s ( [ u1 , u2 , p ] , [ v1 , v2 , q ] , s o l v e r=UMFPACK) =
16 // I m p l e m e n t t h e s t o k e s p r o b l e m
17 + on ( 1 , u1=g , u2 =0)
18 + on ( 2 , 4 , u1 =0 , u2=0)
19 + on ( 3 , p=0) ;
Implementation of the Stokes problem
1 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 // F i n i t e E l e m e n t S p a c e s
3 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
4 f e s p a c e Xh ( Th , P2 ) ;
5 f e s p a c e Mh( Th , P1 ) ;
6 Xh u2 , v2 ;
7 Xh u1 , v1 ;
8 Mh p , q ;
9
10
11 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
12 // S t o k e s
13 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
14 f u n c g=4∗y∗(1−y ) ; // ∗( c o s ( 0 . 1 ∗ i ) +2) ; // p u l s a t i v e f l o w
15
16 s o l v e S t o k e s ( [ u1 , u2 , p ] , [ v1 , v2 , q ] , s o l v e r=C r o u t ) =
17 i n t 2 d ( Th ) ( ( dx ( u1 ) ∗ dx ( v1 ) + dy ( u1 ) ∗ dy ( v1 )
18 + dx ( u2 ) ∗ dx ( v2 ) + dy ( u2 ) ∗ dy ( v2 ) )
19 + p∗q ∗ ( 0 . 0 0 0 0 0 1 )
20 + p∗ dx ( v1 )+ p∗ dy ( v2 )
21 + dx ( u1 ) ∗q+ dy ( u2 ) ∗q
22 )
23 + on ( 1 , u1=g , u2 =0)
24 + on ( 2 , 4 , u1 =0 , u2=0)
25 + on ( 3 , p=0) ;
26
27 p l o t ( c o e f = 0 . 2 ,cmm=” [ u1 , u2 ] and p ” , p , [ u1 , u2 ] , w a i t =1) ;
Outline
Introduction
Numerical examples
Heat equation
Convection
Stationary Stokes problem
Convection-Diffusion Equation
Governing equation
Variational formulation
Practical implementation
Convection-Diffusion Equation
The convection-diffusion equation describes the physical phenomena where
particles or other physical quantities are transferred inside a physical system
due to two processes: diffusion and convection.
∂φ
+ ∇.(uφ) − ∇.(ν∇φ) = 0,
∂t
φ|t=0 = φ0 ,
φ = φD on ΓD
∇φ.~n = u.~nφ on ΓN .
where u = (u1 , u2 ) is the velocity vector of a fluid vector, such that ∇.u = 0 in
Ω and ν is the diffusion coefficient.
In most common situation, the diffusion coefficient is constant and the velocity
field describes an incompressible flow i.e. ∇.u = 0. Then the problem simplifies
to
∂φ
+ u.∇φ − ν∇2 φ = 0,
∂t
φ|t=0 = φ0 ,
φ = φD on ΓD
∇φ.~n = u.~nφ on ΓN .
Diffusion-convection of a pollutant in a lake
∂φ
+ u.∇φ − ν∇2 φ
IsoValue
-0.489928
= 0, -0.444094
-0.39826
-0.352426
-0.306592
∂t -0.260758
-0.214923
-0.169089
-0.123255
-0.0774214
-0.0315874
φ0 ,
0.0142466
φ|t=0 = 0.0600806
0.105915
0.151749
0.197583
0.243417
0.289251
0.335085
0.380919
We model the the evolution of the density of particles in a Stokes flow. The the
evolution of the density of pollutant φ is described by the following problem :
find the numerical solution φh ∈ Vh such that ∀vh ∈ Vh
Z
∂φh
vh − u.∇vh φh + ν∇φh .∇vh = 0, (1)
Ω ∂t
where u = (u1 , u2 ) is the velocity of the fluid and ν is the diffusivity of the
particles.
Diffusion-convection of particles in a Stokes flow
1 // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
2 // D e f i n i n g t h e t i m e p r o b l e m
3 // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
4 r e a l nu = 0 . 0 1 ; // d i f u s i v i t y
5 r e a l d t = 0 . 0 1 ; // t i m e s t e p
6 i n t M=300; // t i m e i t e r a t i o n s
7 i n t i t e =0; // t i m e i t e r a t i o n
8
9 // b i l i n e a r form
10 macro a t ( p h i h , vh ) ( 1 . / d t ∗ p h i h ∗ vh + nu ∗ ( dx ( p h i h ) ∗ dx ( vh ) + dy ( p h i h
) ∗ dy ( vh ) ) + ( u1 ∗ dx ( p h i h ) + u2 ∗ dy ( p h i h ) ) ∗ vh ) //eom
11 // l i n e a r form
12 macro l ( vh ) ( 1 . / d t ∗ p h i p ∗ vh ) //eom
13
14 p r o b l e m CD ( p h i , w , i n i t = i t e ) =
15 i n t 2 d ( Th ) ( a t ( p h i , w) )
16 −i n t 2 d ( Th ) ( l (w) ) ;
1 // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
2 // S o l v i n g t h e p r o b l e m
3 // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
4 // i n i t i a l c o n d i t i o n : p o l l u t i o n
5 f u n c i n i t p h i = 2∗ e xp ( −500∗(( x −0.5) ˆ2+(y −0.5) ˆ 2 ) ) ;
6 p h i= i n i t p h i ;
7 p l o t ( p h i , f i l l =1 , v a l u e =1 , w a i t =1 , cmm=” p h i ( 0 ) ” ) ;
8
9 f o r ( i t e =0; i t e <M; i t e ++){
10 p h i p=p h i ;
11 CD ;
12 p l o t ( p h i , w a i t =0 , f i l l =1 , cmm=” p h i ( ”+ i t e ∗ d t+” ) ” ) ;
1 macro g r a d ( u ) [ dx ( u ) , dy ( u ) ] //eom
2
3 p r o b l e m CDconvect ( p h i , w) =
4 i n t 2 d ( Th ) ( 1/ d t ∗ p h i ∗w + nu∗ g r a d ( p h i ) ’ ∗ g r a d (w) )
5 − i n t 2 d ( Th ) ( 1 / d t ∗ c o n v e c t ( [ u1 , u2 ] , − dt , p h i p ) ∗w)
6 ;
Exercise : different meshes