0% found this document useful (0 votes)
47 views

Introduction in Freefem++ Advanced

This document discusses numerical modeling of transport problems using freefem++ software, with examples in biology, computational fluid dynamics, traffic flow, and energy transfer. It covers transport equations, numerical analysis of finite difference schemes, an introduction to freefem++, and the method of characteristics.

Uploaded by

Eriselda Goga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Introduction in Freefem++ Advanced

This document discusses numerical modeling of transport problems using freefem++ software, with examples in biology, computational fluid dynamics, traffic flow, and energy transfer. It covers transport equations, numerical analysis of finite difference schemes, an introduction to freefem++, and the method of characteristics.

Uploaded by

Eriselda Goga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 163

Numerical modeling of transport problems using

freefem++ software – with examples in biology, CFD,


traffic flow and energy transfer
Florian de Vuyst

To cite this version:


Florian de Vuyst. Numerical modeling of transport problems using freefem++ software – with exam-
ples in biology, CFD, traffic flow and energy transfer. Master. Modélisation numérique des problèmes
de transport sur freefem++, ENS CACHAN, 2013, pp.162. �cel-00842234�

HAL Id: cel-00842234


https://cel.archives-ouvertes.fr/cel-00842234
Submitted on 10 Jul 2013

HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est


archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents
entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non,
lished or not. The documents may come from émanant des établissements d’enseignement et de
teaching and research institutions in France or recherche français ou étrangers, des laboratoires
abroad, or from public or private research centers. publics ou privés.
1

Numerical modeling of transport problems


using freefem++ software

with examples in biology, CFD, traffic flow and energy transfer

IsoValue
72.9873
90.3807
101.976
113.572
125.167
136.763
148.359
159.954
171.55
183.145
194.741
206.336
217.932
229.528
241.123
252.719
264.314
275.91
287.506
299.101
310.697
322.292
333.888
345.483
357.079
368.675
380.27
391.866
403.461
415.057
426.653
438.248
449.844
461.439
473.035
484.63
496.226
507.822
519.417
531.013
542.608
554.204
565.799
577.395
588.991
600.586
612.182
623.777
635.373
664.362

Florian De Vuyst

Department of Mathematics – ENS CACHAN


2
Contents

1 Transport equations 7
1.1 Pure transport equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.1.1 Non homogeneous case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.1.2 Stationary case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2 Conservative case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3 Connections between transport and conservation equations. . . . . . . . . . . . . . . 11

2 Numerical analysis of Eulerian difference schemes 13


2.1 Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2 Finite difference schemes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3 Numerical stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3.1 ℓ∞ stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3.2 ℓ1 stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.3.3 ℓ2 stability, von Neumann stability . . . . . . . . . . . . . . . . . . . . . . . 17
2.4 Consistency properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.4.1 Lax-Wendroff scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.4.2 Von-Neumann stability of the Lax-Wendroff scheme . . . . . . . . . . . . . 20
2.5 Lax-Friedrichs scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.5.1 Von Neumann stability analysis of the Lax-Friedrichs scheme . . . . . . . . 21
2.6 Hybrid interpolated fluxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.6.1 Stability analysis of the hybrid interpolated scheme . . . . . . . . . . . . . . 22
2.7 Equivalent equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.8 Numerical experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.8.1 Scilab source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.8.2 Numerical results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

3 Introduction to freefem++ 29
3.1 Stationary elliptic problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.1.1 Finite element method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.1.2 Practical implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.2 Heat problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.2.1 Implementation in freefem++ . . . . . . . . . . . . . . . . . . . . . . . 34
3.3 A problem of thermal engineering . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

3
4 CONTENTS

4 The Method of characteristics 41


4.1 Mathematical setting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.1.1 freefem++ source code of the pure transport problem . . . . . . . . . . . 42
4.1.2 Numerical Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

5 Stokes equations and Navier-Stokes equations 47


5.1 Setting of the equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
5.2 Analysis of the stationary Stokes problem . . . . . . . . . . . . . . . . . . . . . . . 48
5.3 Numerical method for the Navier-Stokes equations . . . . . . . . . . . . . . . . . . 51
5.4 Numerical experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.4.1 freefem++ source code . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.4.2 Numerical results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

6 Fractional step methods 57


6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
6.2 Continuous analysis, case of a linear system . . . . . . . . . . . . . . . . . . . . . . 58
6.3 Strang second-order symmetric splitting . . . . . . . . . . . . . . . . . . . . . . . . 59
6.4 Discrete time advance schemes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
6.4.1 First order scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
6.4.2 Second order schemes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
6.5 Chorin-Temam fractional step method for the Navier-Stokes equations . . . . . . . . 62
6.5.1 Boundary conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

7 Case study. Population dynamics and migration flux analysis 65


7.1 Lokta-Volterra equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
7.1.1 Analysis of some qualitative properties of the solutions . . . . . . . . . . . . 67
7.2 A fractional step approach to solve the Lokta-Volterra equations. . . . . . . . . . . . 68
7.3 Introducing spatial effects, population diffusion phenomenon . . . . . . . . . . . . . 70
7.4 Adding seasonal migration into the model . . . . . . . . . . . . . . . . . . . . . . . 73

8 Model of biological spatial pigment pattern formation 77


8.1 Cell chemotaxis model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
8.1.1 Dimensionless equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
8.2 Zero-dimensional model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
8.3 Linear stability analysis of the complete model . . . . . . . . . . . . . . . . . . . . 79
8.3.1 Continuous variation of a single parameter . . . . . . . . . . . . . . . . . . 81
8.4 Numerical discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
8.4.1 Fractional step method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
8.4.2 Full discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
8.4.3 freefem++ source code of the numerical scheme and numerical results . . 83

9 Vehicle traffic flow modeling 87


9.1 Setting of the problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
9.2 Some mathematical aspects of nonlinear transport equations . . . . . . . . . . . . . 88
9.2.1 Smooth autosimilar solutions . . . . . . . . . . . . . . . . . . . . . . . . . . 89
9.2.2 Shock wave discontinuous solution . . . . . . . . . . . . . . . . . . . . . . 90
9.3 Transport equation of a vehicle fraction . . . . . . . . . . . . . . . . . . . . . . . . 92
CONTENTS 5

9.4 System of conservation laws . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92


9.5 Finite difference methods for nonlinear transport equations . . . . . . . . . . . . . . 93
9.5.1 Nonlinear extension of the Lax-Wendroff scheme . . . . . . . . . . . . . . . 94
9.6 Nonlinear Lax-Friedrichs scheme, hybrid scheme . . . . . . . . . . . . . . . . . . . 94
9.7 Numerical scheme for the transport equation of a vehicle fraction . . . . . . . . . . . 95
9.8 Numerical experiment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
9.8.1 Scilab source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
9.8.2 One-dimensional numerical results . . . . . . . . . . . . . . . . . . . . . . . 99
9.9 Pseudo two-dimensional model for lane connection modeling . . . . . . . . . . . . . 99
9.9.1 freefem++ source code for the viscous two-dimensional model . . . . . . 100
9.9.2 Numerical results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

10 Biological cell migration and proliferation 105


10.1 Biological and mathematical requirements . . . . . . . . . . . . . . . . . . . . . . . 105
10.2 Guidelines for PDE modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
10.3 Numerical results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
10.3.1 freefem++ source code . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
10.3.2 Numerical results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

11 Gas Dynamics 113


11.1 Perfect gas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
11.2 Discretization in time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
11.3 Full discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
11.4 Numerical experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
11.4.1 freefem++ source code of the supersonic flow problem around an ellipse . 116
11.4.2 Numerical results at infinite Mach number equal to 1.5 . . . . . . . . . . . . 117
11.4.3 Numerical results at infinite Mach number equal to 4 . . . . . . . . . . . . . 117

12 Fluid Mechanics and heat transfer 123


12.1 Model assumptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
12.1.1 Dimensionless equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
12.1.2 Boundary conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
12.2 Mathematical problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
12.3 Numerical discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
12.3.1 Time discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
12.3.2 Variational formulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
12.4 Numerical experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
12.4.1 freefem++ source code of the heat transfer problem . . . . . . . . . . . . 127
12.4.2 Numerical results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

13 Stochastic diffusion processes, Fokker-Planck equations 133


13.1 Ordinary and Stochastic differential equations . . . . . . . . . . . . . . . . . . . . . 133
13.2 Fokker-Planck equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
13.3 Computational approaches based on Stochastic Differential Equations . . . . . . . . 135
13.3.1 Monte-Carlo methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
13.4 Numerical solution of the Fokker-Planck equations . . . . . . . . . . . . . . . . . . 135
6 CONTENTS

13.4.1 Boundary conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136


13.5 Numerical example : metabolite reactions . . . . . . . . . . . . . . . . . . . . . . . 137
13.5.1 Scilab source code of the Monte Carlo approach . . . . . . . . . . . . . . 138
13.5.2 Numerical results of the Monte-Carlo method . . . . . . . . . . . . . . . . . 139
13.5.3 freefem++ source of the Fokker-Planck solver . . . . . . . . . . . . . . . 139
13.5.4 Numerical results with the Fokker-Planck model . . . . . . . . . . . . . . . 141

14 Multiphase flows 145


14.1 Setting of the equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
14.1.1 Transmission conditions, jump conditions . . . . . . . . . . . . . . . . . . . 146
14.1.2 Final model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
14.2 Semi-discretization in time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
14.3 Front tracking by a level function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
14.4 Application. Liquid sloshing in a box. . . . . . . . . . . . . . . . . . . . . . . . . . 150
14.4.1 freefem++ source code of the sloshing problem . . . . . . . . . . . . . . 150
14.4.2 Numerical results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
14.5 Application. Injection moulding problem . . . . . . . . . . . . . . . . . . . . . . . 151
14.5.1 freefem++ source code of the injection moulding problem . . . . . . . . . 151
14.5.2 Numerical results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Chapter 1

Transport equations

1.1 Pure transport equations


Let x(t; t0 , x0 ) denotes the position of a material point with initial position x0 at time t0 . If there is no
ambiguity, we will denote it in the simpler way x(t). If the particle x(t) moves at velocity u(x(t), t),
then the kinematic equation writes
dx
= u(x(t), t). (1.1)
dt
Now suppose that x(t) carries a quantity q which does not evolve during time:

q(x(t), t) = C. (1.2)

Of course we have
d
[q(x(t), t)] = 0.
dt
Using partial derivatives, we get
∂q ∂q dx
+ = 0.
∂t ∂x dt
Combining with (1.1), a standard transport equation is obtained

∂q
+ ∇x q · u = 0. (1.3)
∂t
The notation ∇x means that the gradient applies in the x-direction. Without ambiguity, we will only
denote it ∇ as usually.
In the literature, it is usual to find what is referred to as Lagrangian derivatives or particle derivative

D ∂
= + u · ∇x (1.4)
Dt ∂t
which is the time derivative of a quantity following particle trajectories. Of course, the transport
equation (1.3) is equivalent to
Dq
= 0. (1.5)
Dt

7
8 CHAPTER 1. TRANSPORT EQUATIONS

1.1.1 Non homogeneous case


In the non homogeneous case, we have an additional nonzero right-hand side in equation (1.5) that
expresses the gain or loss of the quantity q. Imagine for example a reacting chemical species that
would be convected by a working fluid. Then the equation becomes

Dq
= s(q, x, t) (1.6)
Dt
or equivalently
∂q
+ u · ∇x q = s(q, x, t). (1.7)
∂t
The notation s for the right hand side is often used to refer to as a source term.

1.1.2 Stationary case


Let us now consider the stationary case of the non-homogeneous transport equation. That means that
the field q does not depend on time directly. In particular, u = u(x) and s = s(q, x). Stationary flows
or steady states are of practical interest because they often occur as the limit case (large time) of an
unsteady process. Thus we have to solve the equation

u · ∇x q = s(q, x). (1.8)

Equation (1.8) alone does not define a mathematically well-posed problem. We need to add some
boundary conditions of conditions at infinity. Let now consider a bounded domain Ω of Rd as shown
in figure 3.1. We will denote ∂Ω the boundary of Ω, n(x) the exterior normal vector to the boundary
∂Ω at position x and ∂Ω+ (resp. ∂Ω− ) the set

∂Ω± = {x ∈ ∂Ω / ± u(x) · n(x) > 0.} . (1.9)

The boundary ∂Ω− in the context of (1.9) is referred to as the inflow boundary because of the negative

Figure 1.1: Steady transport problem in a bounded domain Ω.


1.2. CONSERVATIVE CASE 9

sign of u · n. Then we must give some information on the inflow boundary, for example Dirichlet
boundary conditions
q = q − on ∂Ω− (1.10)
for a given function q − defined on ∂Ω− . From the Lagrangian description of equation (1.8), it is
possible to analytically solve problem (1.8)-(1.10). Let (x(α; x0 ))α≥0 be the parameterized trajectory
of a point at position x for parameter α with initial position x0 ∈ ∂Ω− . That means that x(α; x0 )) is
solution of the differential problem

 dx
= u(x), α > 0,
dα (1.11)
 x(s(α = 0)) = x ∈ ∂Ω− .
0

The solution of (1.11) is in integral form


Z α
x(α) = x0 + u(x(α′ )) dα′ . (1.12)
0

The Lagrangian form of equation (1.8) then reads

dq
= s(q(α), x(α)). (1.13)

From the initial value q(α = 0) = q − , we get the analytical q solution in integral form too
Z α

q(α) = q + s(q(α′ ), x(α′ )) dα′ . (1.14)
0

1.2 Conservative case


Let us consider a time-dependent bounded smooth domain Ωt = Ω(t) which is convected itself by a
velocity field u (imagine for example a bubble rising up into the water). The Reynolds theorem (see
the Continuum Mechanics literature, [6] for example) states that, for a convected quantity q = q(x, t)
into Ωt , we have Z  
d ∂q
Z
q(x, t) dx = + ∇x · (u q) dx. (1.15)
dt Ωt Ωt ∂t
The Reynolds theorem formula can be rigorously derived using differential calculus and the Jacobian
of the transformation that maps the space-time variables (x, t) into the couple (x(t), t) where x(t) is
moving according to the velocity field u, i.e. ẋ(t) = u(x(t), t).
Let us focus on some corollaries of the Reynolds Theorem. First, consider q = 1. Denoting |Ωt |
the measure of the domain Ωt , expression (1.15) states that

d|Ωt |
Z
= (∇ · u) dx. (1.16)
dt Ωt

It is observed that if the velocity field is divergence-free, then any moving domain Ωt preserves its
volume. The flow generated by u is said to be incompressible. Otherwise Ωt increases or decreases
according to the sign of ∇ · u.
10 CHAPTER 1. TRANSPORT EQUATIONS

As a verification of the Reynolds Theorem, let us multiply equation (1.15) by |Ωt |−1 . We succes-
sively have
Z  
1 ∂q 1 d
Z
+ ∇x · (u q) dx = q(x, t) dx
|Ωt | Ωt ∂t |Ωt | dt Ωt
  Z  
d 1 d 1
Z
= q(x, t) dx − q(x, t) dx
dt |Ωt | Ωt Ωt dt |Ωt |
  Z
d 1 1 d|Ωt |
Z
= q(x, t) dx + q(x, t) dx .
dt |Ωt | Ωt Ωt |Ωt |2 dt

From equation (1.16), we get


Z       
1 ∂q d 1 1 1
Z Z Z
+ ∇x · (u q) dx = q(x, t) dx + q(x, t) dx (∇ · u) dx .
|Ωt | Ωt ∂t dt |Ωt | Ωt |Ωt | Ωt |Ωt | Ωt

Considering an infinitesimal volume, for |Ωt | → 0, we get

∂q dq
+ ∇x · (u q) = + q ∇x · u (1.17)
∂t dt
and then retrieve the particle derivative of q:
dq ∂q
= + u · ∇x q.
dt ∂t
The Reynolds Theorem is also at the origin of the conservation laws that governs many Physics in
the nature. Indeed, suppose that the production rate of q is s:
d
Z Z
q(x, t) dx = s(x, t) dx. (1.18)
dt Ωt Ωt

Again, dividing (1.18) by |Ωt |, applying the Reynolds Theorem formula (1.15) and considering an
infinitesimal volume Ωt leads to the following balance equation in conservation form
∂q
+ ∇ · (qu) = s(x, t). (1.19)
∂t
Conservation forms of equations are always sought if it is possible because they provide stability and
conversation properties on the solutions of the equations. For example, integrating equation (1.19)
over any fixed bounded domain ω and applying Green’s formula to the divergence term gives the
balance equation
d
Z Z Z
q(x, t) dx − qu · nω dσ = s(x, t) dx. (1.20)
dt ω ∂ω ω
By denoting for any quantity z Z
zω = z(x, t) dx,
ω
we get the balance law
dqω
Z
= sω + qu · nω dσ. (1.21)
dt ∂ω
1.3. CONNECTIONS BETWEEN TRANSPORT AND CONSERVATION EQUATIONS. 11

The evolution of qω is governed by the production rate sω but also by the flux of q through the boundary
surface ∂ω . The flux Φ = qu · n defines a ’mass flux’ of quantity q at velocity u · n in the normal
direction. That’s the reason of why it is called a conservation form. For an adjacent neighboring
volume ω ′ , both volumes ω and ω ′ exchange some ’mass’ q through a surface flux
Z Z
qu · nω dσ = − qu · nω′ dσ.
∂ω∩∂ω ′ ∂ω∩∂ω ′

and in opposite sense.

1.3 Connections between transport and conservation equations.


Transport and conservation equations in their homogeneous form respectively are

∂t q + u · ∇q = 0 (1.22)

and
∂t q + ∇ · (qu) = 0. (1.23)
For q smooth enough, we can of course rewrite equation (1.23) as

∂t q + u · ∇q + q∇ · u = 0.

If ∇ · u = 0, then both transport equation and convection equation are equivalent. Remember that
a divergence-free velocity field induces an incompressible flow. Consequently, there is no effect of
compressibility or dilatation and q is actually a conserved quantity.
The well-known continuity equation in Gas Dynamics expresses the conservation of the mass of
the gas from its density ρ [kg.m−3 ] (which is an intensive variable):

∂ρ
+ ∇ · (ρu) = 0. (1.24)
∂t
It is interesting to notice that if c is a convected quantity in the gas (for example the concentration of
a non-reacting chemical pollutant),
∂c
+ u · ∇c = 0 (1.25)
∂t
it is always possible to write a conservation equation, at least for smooth solutions of the equations.
By multiplying by ρ equation (1.25) and by c equation (1.24), summing up we get the conservation
law
∂(ρc)
+ ∇ · (ρcu) = 0. (1.26)
∂t
Quantity c is not conserved (only convected) but quantity ρc is conserved (but not convected in the
strict sense, except for incompressible flows).
12 CHAPTER 1. TRANSPORT EQUATIONS
Chapter 2

Numerical analysis of Eulerian difference


schemes

In this chapter, we shall consider computational methods to solve the transport equation

∂t q + u · ∇q = s. (2.1)

There are many methods like finite difference (FD) schemes but also finite volume (FV) scheme, finite
elements methods (FEM), method of characteristics, particle methods, etc. This chapter is aimed at
introducing important concepts of numerical analysis like numerical stability, consistency and order
of accuracy.

2.1 Framework
As a starting point, we first consider homogeneous one-dimensional transport equations. Suppose
also that the transport velocity is constant, let say a > 0. We here consider the infinite spatial domain
Ω = R. The linear transport equation is

∂t q + a∂x q = 0, , x ∈ R, t > 0. (2.2)

The initial data q 0 is supposed to belong to all the Lp -spaces, p ≥ 1 and p = ∞. Of course, the
solution q of (2.2) is analytically known, namely

q(x, t) = q 0 (x − at) ∀t > 0. (2.3)

In particular we have

||q(., t)||Lp = ||q 0 ||Lp , ∀t > 0, p ≥ 1, p = ∞. (2.4)

The solution for the continuous problem is stable in Lp -norm meaning that it does not blow up in time,
and even stays constant in time. This is a good framework to study the numerical stability of discrete
time advance schemes.

13
14 CHAPTER 2. NUMERICAL ANALYSIS OF EULERIAN DIFFERENCE SCHEMES

2.2 Finite difference schemes


We shall discretize the PDE problem (2.2),(2.3). Let us consider a uniform mesh step h > 0 and the
discretization points
xj = jh, j ∈ Z. (2.5)
We also consider a time discretization, not necessary uniform. By defining the initial discrete instant
t0 = 0, we build a sequences (tn )n∈N from a time step sequences (∆tn > 0)n∈N such that

tn+1 = tn + ∆tn . (2.6)

At each discretization point, we consider qjn which is a discretization of the continuous solution q at
spatial point xj and instant tn , i.e.
qjn ≈ q(xj , tn ). (2.7)
As starting point, one can define the values (qj0 )j∈Z from the continuous initial data q 0 by exactly
taking
qj0 = q 0 (xj ), j ∈ Z. (2.8)
The time advance finite difference scheme consists in computing new values (qjn+1 )j∈Z from already
known values (qjn )j∈Z at the previous instant tn using a discrete version of (2.2).
They are many ways to discretize (2.2) in both space and time. A semi-discretization in time can
be
q(x, tn+1 ) − q(x, tn )
+ a∂x q(x, tn ) = 0 (2.9)
∆tn
using the backward Euler scheme formula, which defines a time-explicit scheme, or

q(x, tn+1 ) − q(x, tn )


+ a∂x q(x, tn+1 ) = 0 (2.10)
∆tn
using the forward Euler scheme formula, which defines a time-implicit one and requires a linear
inversion process to get all the qjn+1 . Of course, one could also use time discrete schemes more
accurate than the first order Euler formula. Let us focus on the time discrete scheme (2.9). To get
a really computational scheme, we also discretize (2.9) in space. There are again many ways to
approximate ∂x q at point (xj , tn ). For example, the centered difference scheme
n
qj+1 n
− qj−1
(∂x q)(xj , tn ) ≈ (2.11)
2h
defines the centered scheme. The upwind discretization rule
qjn − qj−1
n
(∂x q)(xj , tn ) ≈ (2.12)
h
defines the so-called explicit Euler upwind scheme whereas the downwind rule
n
qj+1 − qjn
n
(∂x q)(xj , t ) ≈ (2.13)
h
defines the explicit Euler downwind scheme. As a matter of fact, some of numerical presented above
are numerically stable whereas some of them are not.
2.3. NUMERICAL STABILITY 15

2.3 Numerical stability


For numerical stability purposes it is convenient to consider the ℓp norms of the sequences (qjn )j∈Z
defined by
 1/p
X
||q n ||p =  |qjn |p  , p ∈ N, (2.14)
j∈Z

||q n ||∞ = sup |qjn |. (2.15)


j∈Z

Let us first consider the explicit upwind scheme with Euler time discretization (a > 0):

qjn+1 − qjn n
qjn − qj−1
+a = 0. (2.16)
∆tn h

2.3.1 ℓ∞ stability
Generally, ℓ∞ analysis is used to get some information on the extrema of the sequences.

Is is easy to show that (2.16) is ℓ∞ -stable under a condition of the time step ∆tn . This scheme can be
rewritten in incremental form
∆tn ∆tn n
 
n+1
qj = 1−a qjn + a q . (2.17)
h h j−1

It is observed that qjn+1 is nothing else but a linear convex combination of qjn and qj−1
n provided that
n
∆t is such that
∆tn
a ≤ 1. (2.18)
h
The condition (2.18) is referred to as the Courant-Friedrichs-Lewy condition or simply CFL condition.
It is usual to introduce the so-called local Courant number
∆tn
νn = a . (2.19)
h
Because convex combinations are stable in ℓ∞ norm, the CFL condition (2.18) defines a sufficient
condition of ℓ∞ stability. Actually it is also a necessary condition. Consider the particular initial
sequences qj0 = 1(j≤0) (j) with ν n = ν > 1 for all n ∈ N. Then it is easy to check that q11 = ν,
q22 = ν 2 , . . ., qkk = ν k ∀k ≥ 1 so that for any M > 0 there is always a rank n0 such that for all n ≥ 0,
we have ||q n ||∞ > M.
Remark that the limit stability case v n = 1 (Courant number exactly equal to one) leads to the
numerical scheme
qjn+1 = qj−1
n
, (2.20)
which is compatible with the structure of the exact continuous solution

q(x, tn+1 ) = q(x − a∆tn , tn ) = q(x − h, tn ). (2.21)

To summarize, let us enunciate the following theorem


16 CHAPTER 2. NUMERICAL ANALYSIS OF EULERIAN DIFFERENCE SCHEMES

Theorem 1. The explicit upwind scheme (2.16) is conditionally ℓ∞ -stable

||q n+1 ||∞ ≤ ||q n ||∞ ∀n ∈ N. (2.22)

with the stability CFL condition (2.18) on the time step. For a Courant number ν = 1, the scheme
exactly propagates the discretized initial condition.

2.3.2 ℓ1 stability
The ℓ1 -norms are practical to study the appearance of alternative oscillating discrete patterns in dis-
crete solutions.
Let start again from the Euler upwind scheme using the Courant number :

qjn+1 = (1 − ν n )qjn + ν n qj−1


n
. (2.23)

Consider first a Courant number ν n less than 1. Taking the absolute value of the expression and
applying the triangular inequality gives

|qjn+1 | ≤ (1 − ν n )|qjn | + ν n |qj−1


n
|. (2.24)

Suppose that ||q n ||1 ≤ +∞. Summing up (2.24) over the j then gives
X X X
|qjn+1 | ≤ (1 − ν n ) |qjn | + ν n n
|qj−1 |.
j∈Z j∈Z j∈Z

and thus
||q n+1 ||1 ≤ ||q n ||1 . (2.25)
The ℓ1 -norm is decreasing during time iterations so the numerical method is ℓ1 -stable for Courant
numbers less than one. On the other hand it is easy to build a counterexample thats shows that the
condition ν n = ν > 1 makes the numerical scheme unstable. Consider for example a discrete initial
condition (qj0 ) ∈ ℓ1 (Z) such that
0
qj0 .qj+1 < 0 ∀j ∈ Z. (2.26)
(it is an alternate discrete function). Then for ν > 1, it is easy to check that the alternate property is
preserved during the iterations
n
qjn .qj+1 < 0 ∀j ∈ Z, n ∈ N (2.27)
with also
qjn .qjn+1 < 0 ∀j ∈ Z, n ∈ N. (2.28)
From the scheme (1.24), one can notice that

qjn+1 = sgn(qj−1
n
)|1 − ν||qjn | + νqj−1
n

so that
|qjn+1 | > ν|qj−1
n
| ∀j ∈ Z
or again
||q n ||1 > ν n ||q 0 ||1 ∀n ∈ N (2.29)
making the numerical scheme unstable. We thus get the same stability results as in the previous ℓ∞
case.
2.3. NUMERICAL STABILITY 17

2.3.3 ℓ2 stability, von Neumann stability


The von Neumann ℓ2 -stability gives information of the evolution of the energy of the solution and on
the frequency spectrum. For that we use the Fourier transform
1
Z
F (f )(ξ) = √ f (x)e−ixξ dx (2.30)
2π R
for f ∈ L1 (R) ∩ L2 (R). it is known that the Fourier transform is an isometry: F (f ) ∈ L2 (R) and
||f ||L2 = ||F (f )||L2 . (2.31)
We will also make use of the common properties of the Fourier transforms like
F (Th f )(ξ) = eihξ F (f )(ξ) (2.32)
where Th f (x) = f (x − h).
To simplify the stability analysis in the sense of von Neumann, it is more convenient to deal with
a semi-implicit version of the explicit Euler upwind scheme:
q n+1 (x) − q n (x) q n (x) − q n (x − h)
+ a = 0, ∀x ∈ R. (2.33)
∆tn h
The Fourier transform is a linear transform. Applying it on equation (2.33) and using (2.32) gives the
expression
 
F (q n+1 )(ξ) − F (q n )(ξ) + ν n F (q n )(ξ) − eihξ F (q n )(ξ) = 0, ∀ξ ∈ R. (2.34)

or again h i
F (F )(q n+1 )(ξ) = 1 − ν n (1 − eihξ ) F (q n )(ξ). (2.35)
We have to check for which values of ν n the modulus of the amplification factor a(hξ) = 1 − ν n (1 −
eihξ ) is less than one, for any frequency ξ. One finds
|a(hξ)|2 = [1 − ν n (1 − eihξ )][1 − ν n (1 − e−ihξ )]

= 1 − 2ν n (1 − cos(hξ)) + (ν n )2 |1 − eihξ |2

= 1 − 4ν n sin2 (hξ/2) + 4(ν n )2 sin2 (hξ/2) ≤ 1.


That gives the condition
4 sin2 (hξ/2)ν n (ν n − 1) ≤ 0 ∀ξ ∈ R
equivalent again to
ν n ≤ 1. (2.36)
Under condition (2.36) and due to the isometry property of the Fourier transform, we have
||q n+1 ||L2 = ||F (q n+1 )L2 || ≤ ||F (q n )||L2 = ||q n ||L2 . (2.37)
As exercise, we let the reader show that the explicit downwind Euler scheme as well as the centered
scheme with Euler time discrete formula are unconditionally unstable in the sense of von Neumann.
We summarize by the following theorem:
Theorem 2. The explicit upwind scheme is conditionally stable in the sense of von Neumann under
Courant numbers less than one. The explicit downwind scheme as well as the centered schemes are
unconditionally unstable.
18 CHAPTER 2. NUMERICAL ANALYSIS OF EULERIAN DIFFERENCE SCHEMES

2.4 Consistency properties


Another important feature of a discretization scheme is the consistency property and the order of
accuracy. Let us analyze the order of accuracy the the explicit upwind scheme. For the sake of
simplicity, we will restrict our analysis again to the one-dimensional case. Let us once again recall the
expression of the explicit upwind scheme:

qjn+1 − qjn qjn − qj−1


n
+a = 0. (2.38)
∆tn h
The error of consistency consists in measuring the residual computed from the exact solution of the
continuous problem

q(xj , tn+1 ) − q(xj , tn ) q(xj , tn ) − q(xj−1 , tn )


Rjn (h, ∆tn ) = + a . (2.39)
∆tn h
If it is possible to write Taylor expansions of the exact solution near points (xj , tn ) (this is possible
with enough regularity), there exists θn ∈ (tn , tn+1 ) such that
1
q(xj , tn+1 ) = q(xj , tn ) + ∆tn ∂t q(xj , tn ) + (∆tn )2 ∂tt
2
(xj , θn )
2
and yj ∈ (xj−1 , xj ) such that
1
q(xj−1 , tn ) = q(xj , tn ) − h ∂t q(xj , tn ) + h2 ∂xx
2
q(yn , tn )
2
Then we get the residual
1 1
Rjn (h, ∆tn ) = ∆tn ∂tt
2
(xj , θn ) − ah∂xx
2
q(yn , tn ). (2.40)
2 2
2 q and ∂ 2 are bounded functions, then equation (2.40) shows that
If both ∂tt xx

Rjn (h, ∆tn ) = O(∆tn ) + O(h) ∀j ∈ Z, n ∈ N. (2.41)

The explicit upwind scheme is said to be first order accurate (in both space and time). It is possible to
build counterexamples to show that this cannot be better than (2.41).
There are some numerical schemes that provide a smaller rate or error of consistency or equiva-
lently a higher order of accuracy. Let us give the definition
Definition 1 (order of accuracy). A numerical scheme is said to be p-th order accurate in space and
q-th order accurate in time if its residual is in the form

Rjn (h, ∆tn ) = O(hp ) + O((∆tn )q ) ∀j ∈ Z, n ∈ N. (2.42)

2.4.1 Lax-Wendroff scheme


It is of course of interest to define a methodology of construction of higher order accurate scheme.
We shall construct now a second-order accurate scheme in both space and time. The solutions of the
transport are supposed to be smooth enough to write high-order derivatives. Derivating

∂t q + a∂x q = 0,
2.4. CONSISTENCY PROPERTIES 19

with respect to t allows us to write:


2
∂tt q = a2 ∂xx
2
q.
By writing a Taylor expansion in time up to the third order, we have
1
q(xj , tn+1 ) = q(xj , tn ) + ∆tn ∂t q(xj , tn ) + (∆tn )2 a2 ∂xx
2
(xj , tn ) + O(∆t3 ).
2
So it appears interesting to define a discrete time derivative in the form
q(xj , tn+1 ) − q(xj , tn ) 1 2 n −q(xj+1 , tn ) + 2q(xj , tn ) − q(xj−1 , tn )
∂t q(xj , tn ) ≈ − a ∆t . (2.43)
∆tn 2 h2
whose error of consistency is
O((∆tn )2 ) + O(h ∆tn )
or again
O((∆tn )2 ) + O(h2 )
(indeed ab ≤ 12 (a2 + b2 )). For the spatial derivative, we simply use the centered finite difference
which is known to be second-order accurate:
q(xj+1 , tn ) − q(xj−1 , tn )
(∂x q)(xj , tn ) ≈ (2.44)
2h
with consistency error
O(h2 ).
The two discretization schemes (2.43) and (2.44) lead to the so-called Lax-Wendroff scheme (exer-
cise):
Definition 2. The Lax-Wendroff scheme for the transport equation (1.2) is the following second order
accurate scheme:
qjn+1 − qjn ΦLW LW
j+1/2 − Φj−1/2
+ =0 (2.45)
∆tn h
where the so-called Lax-Wendroff flux is
aqjn + aqj+1
n
1
ΦLW
j+1/2 = − ν n a(qj+1
n
− qjn ). (2.46)
2 2
still with Courant number
a∆tn
νn = . (2.47)
h
The script (2.46),(2.47) is interesting because it show that the numerical scheme has the conserva-
tion form (2.46). The numerical flux (2.47) is made of a centered flux and an artificial spatial viscosity
term. The numerical flux if second-order consistent with
1
Φ = aq − ν n ah∂x q
2
Remark 1. Remark that the upwind explicit scheme can also be written in conservation form
qjn+1 − qjn Φup up
j+1/2 − Φj−1/2
+ =0 (2.48)
∆tn h
with upwind numerical flux
aqjn + aqj+1
n
1
Φup
j+1/2 =
n
− |a|(qj+1 − qjn ) (2.49)
2 2
(exercise).
20 CHAPTER 2. NUMERICAL ANALYSIS OF EULERIAN DIFFERENCE SCHEMES

2.4.2 Von-Neumann stability of the Lax-Wendroff scheme


We shall study the ℓ2 -stability of the Lax-Wendroff scheme. For that, as mentioned above we consider
a continuous-in-space version of that numerical scheme:
∆tn
q n+1 (x) − q n (x) + ΦLW (x, x + h) − ΦLW (x − h, x) = 0

(2.50)
h
with
aq n (x) + aq n (x + h) 1 n n
ΦLW (x, x + h) = − aν (q (x + h) − q n (x)).
2 2
By taking the Fourier transform of this expression, we get

1 + e−ihξ
 
1
q̂ n+1 (ξ) − q̂ n (ξ) + ν n − ν n (e−ihξ − 1) q̂ n (ξ)
2 2
ihξ
 
n 1+e 1 n
− ν − ν (1 − e ) q̂ n (ξ) = 0
ihξ
2 2
that simplifies into

q̂ n+1 (ξ) = [1 − ν n {ν n (1 − cos(hξ)) − i sin(hξ)}] q̂ n (ξ), ∀ξ ∈ R. (2.51)

The amplification factor is

a(hξ) = 1 − ν n {ν n (1 − cos(hξ)) − i sin(hξ)}.

To find the stability condition, the inequality

|a(hξ)|2 ≤ 1.

has to be solved. Using the identity sin2 (hξ) = 1−cos2 (hξ), it is found that the condition is equivalent
to
(1 − cos2 (hξ))2 (ν n )2 ((ν n )2 − 1) ≤ 0, ∀ξ ∈ R.
That shows that the Lax-Wendroff scheme is ℓ2 -stable for Courant numbers less than one.

2.5 Lax-Friedrichs scheme


The Lax-Friedrichs scheme is another stable candidate based on the following approximation scheme:
n
qj+1 n
− qj−1
∂x q(xj , tn ) ≈ (second order accurate),
2h
n +q n
qj−1
qjn+1 − 2
j+1

∂t q(xj , tn ) ≈ (first order accurate).


∆tn
It is easy to check that the residual of the discrete time derivative can be written
q(xj−1 ,tn )+q(xj+1 ,tn )
q(xj , tn+1 ) − 2 ∆tn 2 2
1 h2 ∂xx 2
q(ξj− , tn ) + ∂xx q(ξj+ , tn )
− ∂t q(xj , tn ) = ∂tt q(xj , θn ) +
∆tn 2 2 ∆tn 2
(2.52)
2.5. LAX-FRIEDRICHS SCHEME 21

for θn ∈ (tn , tn+1 ), ξj− ∈ (xj−1,xj ) and ξj+ ∈ (xj , xj+1 ). Expression (2.52) shows that the approxi-
mation stays first order accurate provided that h and ∆tn are of the same order, or more exactly
h
≤ C, (2.53)
∆tn
where C is a constant which is independent from h and ∆tn . Remark that this could not be the case
for possibly restrictive stability conditions like for example
∆tn
≤ C ′.
h2
In the next subsection, we will do the von Neumann stability analysis of the Lax-Friedrichs scheme.
So the Lax-Friedrichs scheme is written as
n +q n
qj−1
qjn+1 − 2
j+1 n
qj+1 n
− qj−1
+a = 0. (2.54)
∆tn 2h
It is easy to check that is can written in conservation form
∆tn  F L 
qjn+1 = qjn − Φj+1/2 − ΦLFj−1/2 (2.55)
h
where the Lax-Friedrichs numerical flux is
aqjn + aqj+1
n
1
ΦLF
j+1/2 = − n a(qj+1 n
− qjn ). (2.56)
2 2ν
We again recognize a centered flux plus an artificial viscosity term.

2.5.1 Von Neumann stability analysis of the Lax-Friedrichs scheme


We consider a continuous-in-space version of the Lax-Friedrichs scheme:
∆tn
q n+1 (x) − q n (x) + ΦLF (x, x + h) − ΦLF (x − h, x) = 0

(2.57)
h
with
aq n (x) + aq n (x + h) 1
ΦLF (x, x + h) = − n a(q n (x + h) − q n (x)).
2 2ν
By taking the Fourier transform of this expression, we get
1 + e−ihξ
 
1
q̂ n+1 (ξ) − q̂ n (ξ) + ν n − n (e−ihξ − 1) q̂ n (ξ)
2 2ν
ihξ
 
n 1+e 1
− ν − n (1 − e ) q̂ n (ξ) = 0
ihξ
2 2ν
that simplifies into
q̂ n+1 (ξ) = [cos(hξ) − iν n sin(hξ)}] q̂ n (ξ), ∀ξ ∈ R. (2.58)
The amplification factor is
a(hξ) = cos(hξ)) − iν n sin(hξ)}.
The stability condition inequality |a(hξ)|2 ≤ 1 writes
cos2 (hξ) + (ν n )2 sin2 (hξ) ≤ 1, (2.59)
clearly showing that the Lax-Friedrichs is stable in the von Neumann sense for Courant numbers less
than one.
22 CHAPTER 2. NUMERICAL ANALYSIS OF EULERIAN DIFFERENCE SCHEMES

2.6 Hybrid interpolated fluxes


So far, we have seen three different stable schemes, namely the upwind (UP) scheme, the Lax-
Wendroff (LW) scheme and the Lax-Friedrichs (LF) scheme. All three can be written in conservation
form
∆tn  n 
qjn+1 = qjn − Φj+1/2 − Φnj−1/2 , (2.60)
h
with different numerical flux Φnj+1/2 for each of them. Let us recall the three numerical fluxes written
for any a (can be positive or negative):
1
ΦU P c n n
j+1/2 = Φj+1/2 − |a|(qj+1 − qj ), (2.61)
2
1 n
ΦLW c n n
j+1/2 = Φj+1/2 − ν |a|(qj+1 − qj ), (2.62)
2
1
ΦLF c
j+1/2 = Φj+1/2 −
n
|a|(qj+1 − qjn ), (2.63)
2ν n
where
aqjn + aqj+1
n
Φcj+1/2 =
2
is the second order centered flux. It is interesting so see that all three share the same structure and can
even be written under the generic form
1
Φnj+1/2 (θ) = Φcj+1/2 − (ν n )θ |a|(qj+1
n
− qjn ) (2.64)
2
using a parameter θ ∈ [−1, 1]. The UP scheme corresponds to θ = 0 whereas θ = 1 gives the LW
scheme and θ = −1 gives the LF scheme. To implement the three numerical scheme, we only need
to implement the numerical method with the free parameter θ ∈ [−1, 1] and use it as a configuration
parameter. For parameters θ different from −1, 0, 1, the numerical method (2.60),(2.64) defines a
natural interpolation of the three common schemes.

2.6.1 Stability analysis of the hybrid interpolated scheme


For the hybrid interpolated scheme, the amplification relation then becomes
h  i
q̂ n+1 (ξ) = 1 − ν n (ν n )θ (1 − cos(hξ)) − i sin(hξ) q̂ n (ξ). (2.65)

The stability condition


|a(hξ)|2 ≤ 1 ∀ξ ∈ R
reads (denoting ω = hξ and ν n = ν for simplicity)

ν 2 sin2 ω + ν 2(1+θ) (1 − cos ω)2 − 2ν 1+θ (1 − cos ω) ≤ 0.

By denoting y = cos ω, this can be simplified into

ν 2 (1 + y) + ν 2(1+θ) (1 − y) − 2ν 1+θ ≤ 0 ∀y ∈ [−1, 1) (2.66)

(the case y = 1 is automatically satisfied). The analysis can be finalized by a simple study of function
(as exercise).
2.7. EQUIVALENT EQUATION 23

2.7 Equivalent equation


It is of interest to exhibit what kind of equation a first order scheme solves at second order accuracy.
This is exactly the definition of the equivalent equation. Let us write the equivalent equation for the
hybrid interpolated scheme. Using Taylor expansion, it is an easy matter of fact to show that

qjn+1 − qjn ∆tn 2


≈ ∂t q(xj , tn ) + ∂ q(qj , tn ) + O((∆tn )2 )
∆tn 2 tt
and
Φnj+1/2 − Φnj−1/2 h
≈ a∂x q(xj , tn ) − (ν n )θ |a|∂xx
2
q(xj , tn ) + O(h2 ).
h 2
Consequently, truncating up to second order terms gives the equivalent equation
h n θ 2 ∆tn 2
∂t q + a∂x q = (ν ) |a|∂xx q− ∂ q. (2.67)
2 2 tt
2 q = a2 ∂ 2 q, one can also write the convection-diffusion-like equation
From ∂tt xx

∆tn 2
 
h n θ 2
∂t q + a∂x q − (ν ) |a| − a ∂xx q = 0. (2.68)
2 2
In order to have a positive diffusion (necessary for stability at the continuous level), this requires
h n θ ∆tn 2
(ν ) |a| ≥ a
2 2
which can also be written
(ν n )1−θ ≤ 1. (2.69)
and defines a necessary condition of stability. Notice that the second order term vanishes for θ = 1,
showing once again that the Lax-Wendroff scheme is second order accurate (in both space and time).

2.8 Numerical experiments


2.8.1 Scilab source code

1 // Advect. sce ( Scilab )


2 // Numerical schemes for the pure advection equation
3 // Interpolation parameter theta in [−1,1];
4 // Courant number nu<=1;
5 theta = -1;
6 N = 1000;
7 h = 1 / N;
8 x = h/2 : h: 1-h/2;
9 key = 3;
10 // Initial condition
11 if (key==1) then
12 // Step solution
13 u = 0 + ((1/4-abs(x-1/2))>0);
14 //
24 CHAPTER 2. NUMERICAL ANALYSIS OF EULERIAN DIFFERENCE SCHEMES

15 elseif (key==2) then


16 // Pyramid−shaped function
17 u = max(0, 1-4*abs(x-1/2));
18 //
19 else
20 // Sine function
21 u = sin(2*%pi*x);
22 end;
23 plot(x, u, ’.-’); xgrid();
24 nu = 0.5;
25 a = 1;
26 time = 0;
27 lambda = nu / abs(a);
28 dt = h * lambda;
29 //
30 for it=1:2e3
31 time = time + dt;
32 Phi = 0.5*a*([u, u(1)] + [u(N), u]) ...
33 - 0.5*nu^theta*abs(a)*([u, u(1)] - [u(N), u]);
34 u = u - lambda * (Phi(2:N+1) - Phi(1:N));
35 //
36 // Comparison with exact solution
37 //
38 xmodulo = modulo(a*time,1);
39 if (key==1) then
40 // Step solution
41 uex = 0 + ((1/4-abs(x-xmodulo-1/2))>0) ...
42 + ((1/4-abs(x-xmodulo+1/2))>0);
43 elseif (key==2)
44 // Pyramid function
45 uex = max(0, 1-4*abs(x-xmodulo-1/2)) ...
46 + max(0, 1-4*abs(x-xmodulo+1/2));
47 else
48 // Sine function
49 uex = sin(2*%pi*(x-xmodulo)) ;
50 end;
51 if ~modulo(it, 50) then
52 drawlater();
53 clf();
54 subplot(1,2,1), plot(x, u, ’.-’, x, uex, ’-’); xgrid();
55 xtitle(’Discrete solution (uh)’);
56 subplot(1,2,2), plot(x, u-uex, ’.-’); xgrid();
57 xtitle(’Error (uh-u_ex)’);
58 drawnow();
59 end;
60 end;

2.8.2 Numerical results


2.8. NUMERICAL EXPERIMENTS 25

Discrete solution (uh) Error (uh−u_ex)

1.4 0.8

1.2 0.6

1.0
0.4

0.8
0.2

0.6
0.0
0.4

−0.2
0.2

−0.4
0.0

−0.2 −0.6

−0.4 −0.8
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Discrete solution (uh) Error (uh−u_ex)

1.2 0.5

0.4
1.0
0.3

0.8 0.2

0.1
0.6

0.0

0.4
−0.1

0.2 −0.2

−0.3
0.0
−0.4

−0.2 −0.5
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Discrete solution (uh) Error (uh−u_ex)

1.0 0.5

0.9 0.4

0.8 0.3

0.7 0.2

0.6 0.1

0.5 0.0

0.4 −0.1

0.3 −0.2

0.2 −0.3

0.1 −0.4

0.0 −0.5
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Discrete solution (uh) Error (uh−u_ex)

1.0 0.5

0.9 0.4

0.8 0.3

0.7 0.2

0.6 0.1

0.5 0.0

0.4 −0.1

0.3 −0.2

0.2 −0.3

0.1 −0.4

0.0 −0.5
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Discrete solution (uh) Error (uh−u_ex)

1.0 0.5

0.9 0.4

0.8 0.3

0.7 0.2

0.6 0.1

0.5 0.0

0.4 −0.1

0.3 −0.2

0.2 −0.3

0.1 −0.4

0.0 −0.5
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Figure 2.1: Numerical solution with the step function as initial condition. Respective discrete solutions
and errors for θ = 1, 21 , 0, − 12 , −1 (ν n = 12 is used here, final time is T = 1).
26 CHAPTER 2. NUMERICAL ANALYSIS OF EULERIAN DIFFERENCE SCHEMES

Discrete solution (uh) Error (uh−u_ex)

1.0 0.015

0.8 0.010

0.6 0.005

0.4 0.000

0.2 −0.005

0.0 −0.010

−0.2 −0.015
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Discrete solution (uh) Error (uh−u_ex)

1.0 0.03

0.02
0.8

0.01

0.6
0.00

0.4 −0.01

−0.02
0.2

−0.03

0.0
−0.04

−0.2 −0.05
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Discrete solution (uh) Error (uh−u_ex)

1.0 0.04

0.9

0.02
0.8

0.7
0.00

0.6

0.5 −0.02

0.4

−0.04
0.3

0.2
−0.06

0.1

0.0 −0.08
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Discrete solution (uh) Error (uh−u_ex)

1.0 0.05

0.9

0.8

0.7
0.00

0.6

0.5

0.4

−0.05
0.3

0.2

0.1

0.0 −0.10
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Discrete solution (uh) Error (uh−u_ex)

1.0 0.10

0.9

0.8 0.05

0.7

0.6 0.00

0.5

0.4 −0.05

0.3

0.2 −0.10

0.1

0.0 −0.15
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Figure 2.2: Numerical solution with the pyramid-shaped function as initial condition. Respective
discrete solutions and errors for θ = 1, 12 , 0, − 21 , −1 (ν n = 12 is used here, final time is T = 1).
2.8. NUMERICAL EXPERIMENTS 27

Discrete solution (uh) Error (uh−u_ex)

1.0 4e−005

0.8
3e−005

0.6
2e−005
0.4

1e−005
0.2

0.0 0e+000

−0.2
−1e−005

−0.4
−2e−005
−0.6

−3e−005
−0.8

−1.0 −4e−005
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Discrete solution (uh) Error (uh−u_ex)

1.0 0.005

0.8 0.004

0.6 0.003

0.4 0.002

0.2 0.001

0.0 0.000

−0.2 −0.001

−0.4 −0.002

−0.6 −0.003

−0.8 −0.004

−1.0 −0.005
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Discrete solution (uh) Error (uh−u_ex)

1.0 0.010

0.8 0.008

0.6 0.006

0.4 0.004

0.2 0.002

0.0 0.000

−0.2 −0.002

−0.4 −0.004

−0.6 −0.006

−0.8 −0.008

−1.0 −0.010
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Discrete solution (uh) Error (uh−u_ex)

1.0 0.020

0.8
0.015

0.6
0.010
0.4

0.005
0.2

0.0 0.000

−0.2
−0.005

−0.4
−0.010
−0.6

−0.015
−0.8

−1.0 −0.020
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Discrete solution (uh) Error (uh−u_ex)

1.0 0.03

0.8

0.02
0.6

0.4
0.01

0.2

0.0 0.00

−0.2

−0.01
−0.4

−0.6
−0.02

−0.8

−1.0 −0.03
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Figure 2.3: Numerical solution with the sine function as initial condition. Respective discrete solutions
and errors for θ = 1, 21 , 0, − 12 , −1 (ν n = 12 is used here, final time is T = 1).
28 CHAPTER 2. NUMERICAL ANALYSIS OF EULERIAN DIFFERENCE SCHEMES
Chapter 3

Introduction to freefem++

freefem++ is a language and an integrated development environment with visualization facilities


for the Finite Element Method (FEM). It is dedicated to the simulation of two-dimensional or three-
dimensional, steady or unsteady, linear or nonlinear Partial Differential problems defined from their
variational formulation. freefem++ is written in C++ and the freefem++ language is a C++
idiom. The software can be downloaded at
http://www.freefem.org/ff++/.
The software is well-documented. The user will find the freefem++ manual and various examples
at
http://www.freefem.org/ff++/ftp/freefem++doc.pdf

3.1 Stationary elliptic problem


freefem++ is able to solve Laplace problems and general elliptic problems in only a few lines.
The problem has to be set from its discrete variational formulation. As example, consider the elliptic
problem with Robin boundary conditions (δ, ε > 0)

−∆u + δu = 1 in Ω, (3.1)
∂u
+ εu = 0 on ∂Ω. (3.2)
∂n
To write the variational formulation of the problem, first multiply (3.1) by a smooth test function v
and then integrate it over the bounded domain Ω. Applying Green’s formula gives
∂u
Z Z Z Z
∇u · ∇v dx − v dσ + δ uv dx = v dx (3.3)
Ω ∂Ω ∂n Ω Ω

Now, due to the boundary condition (3.2), it can be rewritten


Z Z Z Z
∇u · ∇v dx + δ uv dx + ε uv dσ = v dx (3.4)
Ω Ω ∂Ω Ω

or again written in the abstract form


a(u, v) = ℓ(v) (3.5)

29
30 CHAPTER 3. INTRODUCTION TO FREEFEM++

where Z Z Z
a(u, v) = ∇u · ∇v dx + δ uv dx + ε uv dσ (3.6)
Ω Ω ∂Ω

and Z
ℓ(v) = v dx. (3.7)

Of course, we would like to find a unique solution of (3.6),(3.7) if it is possible. The Lax-Milgram
Theorem (see for example [1]) guides us to find the proper space in which the solution u and the test
functions v must live for a well-posed problem. Let us recall the theorem:

Theorem 3 (Lax-Milgram). Let H be a Hilbert space with scalar product (., .) and associated norm
||.||. Let ℓ(.) be a linear form, continuous on H and a(., .) a bilinear form which is

• continuous on H × H: ∃c > 0 /

|a(u, v)| ≤ C ||u||.||v|| ∀u, v ∈ H2 , (3.8)

• coercive (or H − elliptic): ∃a > 0 /

a(u, v) ≥ α ||u||2 . (3.9)

Then there exist a unique u in H such that

a(u, v) = ℓ(v) ∀v ∈ H. (3.10)

In our example, the bilinear form a in (3.6) involves gradients of u and v. Thus we need to find a
Hilbert space for which gradients exist in some sense. The Sobolev space H 1 (Ω)

H 1 (Ω) = {v ∈ L2 (Ω), ∂i v ∈ L2 (Ω), i = 1, . . . , d} (3.11)

is proved to be a Hilbert space for the scalar product


Z Z
(u, v)H 1 = uv dx + ∂i u∂i v dx (3.12)
Ω Ω

= (u, v)L2 + (∇u, ∇v)L2 . (3.13)

The H 1 -scalar defines the associated H 1 -norm


q
||u||H 1 = ||u||2L2 + ||∇u||2L2 . (3.14)

Let us verify that all the assumptions of the Lax-Milgram Theorem are satisfied when H = H 1 (Ω). It
is clear that the form a is bilinear. It is also continuous thanks to the Cauchy-Schwarz inequality:

|a(u, v)| ≤ ||∇u||L2 .||∇v||L2 + (δ + ε) (||u||L2 .||v||L2 )

≤ (1 + δ + ε) ||u||H 1 .||v||H 1 .
3.1. STATIONARY ELLIPTIC PROBLEM 31

It is clearly H 1 -elliptic:
Z Z Z
2 2
a(u, u) = |∇u| dx + δ u dx + u2 dσ
Ω Ω ∂Ω

≥ min(1, δ) (||∇u||2L2 + ||u||2L2 )

= min(1, δ) ||u||2H 1 .

Finally, the form ℓ is clearly linear and continuous in H 1 thanks to Cauchy-Schwarz inequality:
Z
|ℓ(v)| ≤ 1.|v| dx ≤ |Ω|||v||L2 ≤ |Ω|||v||H 1 .

From the Lax-Milgram theorem , we have proved that the problem: find u ∈ H 1 (Ω) such that
Z Z Z Z
∇u · ∇v dx + δ uv dx + ε uv dσ = v dx ∀v ∈ H 1 (Ω) (3.15)
Ω Ω ∂Ω Ω

has a unique solution in H 1 (Ω). Actually, it defines what we call a weak solution of the initial PDE
problem (3.1),(3.2).

3.1.1 Finite element method


The freefem++ computational approach is based on (some convenient) discretization of the contin-
uous problem (3.15). For that, one can use a conformal discrete Finite Element space V h , meaning that
V h it embedded into the continuous space H 1 (Ω). freefem++ includes most of the common finite
elements (P1, P2, P1-bubble, etc.). Let us for example consider a continuous piecewise polynomial of
degree one P 1 Finite Element discretization on a triangulation T h of Ωh :
n o
V h = v h ∈ H 1 (Ωh ), v h ∈ C 0 (Ωh ), v|K
h
∈ P 1 (K) ∀K ∈ Th . (3.16)

It is easy to check that


V h ⊂ H 1 (Ωh ).

The discrete Finite Element problem then becomes: find uh ∈ V h such that
Z Z Z Z
h h h h h h
∇u · ∇v dx + δ u v dx + ε u v dσ = v h dx ∀v h ∈ V h . (3.17)
Ωh Ωh ∂Ωh Ωh

Because the continuous bilinear form in (3.17) has still the ellipticity property in H = V h provided
with the H 1 -scalar product, the Lax-Milgram theorem can be applied. This shows that the discrete
problem (3.17) has a unique solution uh ∈ V h . Practically, the FE method requires the building of a
large sparse matrix and the solution of a large sparse linear system. freefem++ includes a large set
of both direct and iterative solvers (LU, Choleski, UMFPACK, conjugate gradient, bicgstab, GMRES,
etc...). See the user manual about more details on these solvers and the way to call them.
32 CHAPTER 3. INTRODUCTION TO FREEFEM++

3.1.2 Practical implementation


freefem++ language is a high-level interpreted language dedicated to FEM. There are primitives for
geometry CAD definition, triangulation and mesh, finite element space definition, variable definition,
variational problem definition, linear system solution and visualization facilities.

The following program written in freefem++ language implements the standard Lagrangian P 1
FE and the variational formulation (3.17) on the unit disk. Important freefem++ commands are
border for border geometry definition, mesh for mesh generation, fespace for the definition of
the Finite element space, problem for defining a variational problem and solver for its solution,
and finally plot for visualization.

1 // Laplace.edp
2 // Laplace problem with robin boundary conditions
3 real epsilon = 1e-2;
4 border domega(t=0,2*pi){x=cos(t); y=sin(t);}
5 mesh Th = buildmesh (domega(100));
6 plot(Th, wait=1, ps="ThLaplace.eps");
7 fespace Vh(Th,P1);
8 Vh uh, vh;
9 func f=1;
10 real cpu=clock();
11 solve Poisson(uh, vh, solver=LU) = // defines the PDE
12 int2d(Th)(dx(uh)*dx(vh) + dy(uh)*dy(vh)) // bilinear part
13 + int1d(Th, domega)(epsilon*uh*vh)
14 - int2d(Th)( f*vh); // right hand side
15 cout << " CPU time = " << clock()-cpu << endl;
16 plot(uh, nbiso=50, fill=0, value=1, wait=1, ps="res.eps");
17 // Done !

3.2 Heat problem


freefem++ is able to solve time-dependent problems. As example, let us consider the following
heat problem. The boundary ∂Ω is partitioned into two boundaries Γ1 and Γ2 :
∂u
− ∇ · (κ∇u) = 0 in (0, T ) × Ω,
∂t
u(., t = 0) = θ in Ω,
∂u
= −1 on (0, T ) × Γ1 ,
∂n
u=θ on [0, T ) × Γ2 .

As first step, consider a time-discretization of the equation, let say by the backward implicit Euler
quadrature. The PDE in its semi-discrete form reads

un+1 − un
− ∇ · (κ∇un+1 ) = 0. (3.18)
∆tn
3.2. HEAT PROBLEM 33

IsoValue
49.9775
49.9825
49.9875
49.9925
49.9975
50.0026
50.0076
50.0126
50.0176
50.0226
50.0276
50.0326
50.0376
50.0426
50.0476
50.0526
50.0576
50.0626
50.0676
50.0726
50.0776
50.0826
50.0876
50.0926
50.0977
50.1027
50.1077
50.1127
50.1177
50.1227
50.1277
50.1327
50.1377
50.1427
50.1477
50.1527
50.1577
50.1627
50.1677
50.1727
50.1777
50.1827
50.1877
50.1928
50.1978
50.2028
50.2078
50.2128
50.2178
50.2228

Figure 3.1: The problem (3.16) solved with freefem++ on the unit disk. Automatic meshing and
plot of the isocontours of the solution.

For spatial discretization, we shall use the Finite Element method. Multiplying (3.18) by a smooth test
function v, integrating over Ω and applying Green’s formula leads to

1 ∂un+1 1
Z Z Z Z
n+1 n+1
u v dx + κ∇u · ∇v dx − κ v dσ = un v dx. (3.19)
∆tn Ω Ω ∂Ω ∂n ∆tn Ω

The finite element space to consider for u here is the H 1 Sobolev space made of functions with trace
equal to θ on Γ2 . Defining for any g ∈ H 1/2 (Γ2 )

Vg = v ∈ H 1 (Ω), v = g on Γ2 ,

(3.20)

one considers a test function v ∈ V0 and the variational formulation


1 1
Z Z Z Z
n+1 n+1
u v dx + κ∇u · ∇v dx + κv dσ = un v dx. (3.21)
∆tn Ω Ω Γ1 ∆tn Ω

It is once again possible to apply the Lax-Milgram Theorem and show that the problem to find un+1 ∈
Vθ such that (3.21) holds for all v ∈ V0 has a unique solution.
The fully discretized problem is based on a discretization of the Sobolev spaces
n o
V h = v h ∈ H 1 (Ωh ), v h ∈ C 0 (Ωh ), v|K
h
∈ P 1 (K) ∀K ∈ Th , (3.22)
n o
Vgh = v h ∈ V h , v h = g h on Γh2 for g h ∈ H 1/2 (Γh2 ), (3.23)

and the variational formulation set into a finite dimensional linear space: find uh ∈ Vθh such that

1 1
Z Z Z Z
h,n+1 h h,n+1 h
u v dx + κ∇u · ∇v dx + κv dσ = uh,n v h dx ∀v h ∈ V0h .
∆tn Ω Ω Γ1 ∆tn Ω
(3.24)
34 CHAPTER 3. INTRODUCTION TO FREEFEM++

3.2.1 Implementation in freefem++

1 // Heat.edp ( freefem++)
2 // Linear Heat problem with inhomogeneous Dirichlet boundary
3 // conditions and Neuman nonzero flux boundary conditions .
4 //
5 real theta = 20; // initial and boundary temperature
6 real kappa = 0.1; // thermal conductivity
7 real dt = 0.5; // time step size
8 //
9 border Gamma1(t=0,2*pi){x=cos(t); y=sin(t);}
10 border Gamma2(t=0, 1){x=-0.5+t; y=0.3;}
11 mesh Th = buildmesh (Gamma1(100)+Gamma2(60));
12 plot(Th, wait=1, ps="Th.eps");
13 //
14 fespace Vh(Th,P1);
15 Vh uh, uold, vh;
16 // Initialization
17 uh = theta; uold = uh;
18 problem heatstep(uh, vh, solver=LU) = // defines the problem
19 int2d(Th)(uh*vh/dt)
20 - int2d(Th)(uold*vh/dt)
21 + int2d(Th)(kappa*dx(uh)*dx(vh) + kappa*dy(uh)*dy(vh))
22 + int1d(Th, Gamma1)(kappa*vh)
23 + on(Gamma2, uh=theta); // Dirichlet BC
24 // Performs 6 time steps
25 for (int it=0;it<6;it++) {
26 // Update temperature field at previous time step
27 uold = uh;
28 // Then perform a time step
29 heatstep;
30 plot(uh, nbiso=50, fill=1, value=1, wait=1, ps="res"+it+".eps");
31
32 }
33 // Done !

3.3 A problem of thermal engineering


Let us here consider a more realistic problem of thermal engineering design. From two different mate-
rials - one is cheap, the other is expensive - we would like to build a composite material that provides
good thermal resistance properties. If V is a volume occupied by a wall made of that composite ma-
terial, Vc is the volume occupied by the cheap material and Ve = V − Vc the volume occupied by the
expensive one, the ratio
Ve Ve
µ= = (3.25)
V Vc + Ve
is fixed for economical purposes. We consider the geometry presented in figure 3.3. A rectangular
room Ωr has a size Lx × Ly . At the center of the left wall, we have a radiator that locally keeps the
temperature at Tr . We will denote that part of the wall Γr . The remainder of the left wall plus the upper
and lower walls will be denoted Γa . We will suppose zero thermal flux boundary conditions on Γa .
The domain Ωw of the wall of the right part of the room is modeled. It will be made of the composite
3.3. A PROBLEM OF THERMAL ENGINEERING 35

IsoValue IsoValue IsoValue


19.7397 19.5912 19.4689
19.7475 19.6035 19.4848
19.7527 19.6117 19.4954
19.7579 19.6198 19.5061
19.7631 19.628 19.5167
19.7683 19.6362 19.5273
19.7735 19.6444 19.5379
19.7787 19.6525 19.5486
19.7839 19.6607 19.5592
19.7891 19.6689 19.5698
19.7943 19.6771 19.5804
19.7995 19.6852 19.591
19.8047 19.6934 19.6017
19.81 19.7016 19.6123
19.8152 19.7098 19.6229
19.8204 19.7179 19.6335
19.8256 19.7261 19.6442
19.8308 19.7343 19.6548
19.836 19.7425 19.6654
19.8412 19.7506 19.676
19.8464 19.7588 19.6866
19.8516 19.767 19.6973
19.8568 19.7752 19.7079
19.862 19.7833 19.7185
19.8672 19.7915 19.7291
19.8724 19.7997 19.7398
19.8776 19.8079 19.7504
19.8828 19.816 19.761
19.8881 19.8242 19.7716
19.8933 19.8324 19.7822
19.8985 19.8406 19.7929
19.9037 19.8487 19.8035
19.9089 19.8569 19.8141
19.9141 19.8651 19.8247
19.9193 19.8733 19.8354
19.9245 19.8815 19.846
19.9297 19.8896 19.8566
19.9349 19.8978 19.8672
19.9401 19.906 19.8778
19.9453 19.9142 19.8885
19.9505 19.9223 19.8991
19.9557 19.9305 19.9097
19.9609 19.9387 19.9203
19.9662 19.9469 19.931
19.9714 19.955 19.9416
19.9766 19.9632 19.9522
19.9818 19.9714 19.9628
19.987 19.9796 19.9734
19.9922 19.9877 19.9841
20.0052 20.0082 20.0106

IsoValue IsoValue IsoValue


19.3594 19.2584 19.164
19.3786 19.2806 19.1891
19.3914 19.2954 19.2058
19.4042 19.3103 19.2225
19.417 19.3251 19.2393
19.4299 19.3399 19.256
19.4427 19.3548 19.2727
19.4555 19.3696 19.2894
19.4683 19.3844 19.3061
19.4811 19.3993 19.3229
19.4939 19.4141 19.3396
19.5067 19.4289 19.3563
19.5195 19.4438 19.373
19.5324 19.4586 19.3897
19.5452 19.4734 19.4065
19.558 19.4883 19.4232
19.5708 19.5031 19.4399
19.5836 19.5179 19.4566
19.5964 19.5328 19.4733
19.6092 19.5476 19.4901
19.622 19.5624 19.5068
19.6349 19.5773 19.5235
19.6477 19.5921 19.5402
19.6605 19.6069 19.5569
19.6733 19.6218 19.5737
19.6861 19.6366 19.5904
19.6989 19.6514 19.6071
19.7117 19.6663 19.6238
19.7245 19.6811 19.6405
19.7374 19.6959 19.6572
19.7502 19.7108 19.674
19.763 19.7256 19.6907
19.7758 19.7404 19.7074
19.7886 19.7553 19.7241
19.8014 19.7701 19.7408
19.8142 19.7849 19.7576
19.827 19.7998 19.7743
19.8398 19.8146 19.791
19.8527 19.8294 19.8077
19.8655 19.8443 19.8244
19.8783 19.8591 19.8412
19.8911 19.8739 19.8579
19.9039 19.8888 19.8746
19.9167 19.9036 19.8913
19.9295 19.9184 19.908
19.9423 19.9333 19.9248
19.9552 19.9481 19.9415
19.968 19.9629 19.9582
19.9808 19.9778 19.9749
20.0128 20.0148 20.0167

Figure 3.2: The problem (3.24) solved with freefem++ . The mesh and the fields at the six first
discrete time steps are plotted.

material. The width of the wall is named ℓx , so that V = ℓx Ly . The right part of the composite
wall denoted by Γext is in contact with the exterior. The will denote Text the exterior temperature and
will impose the Dirichlet boundary condition T = Text on Γext . Finally, we will respectively denote
by κa , κc and κe the thermal conductivity coefficients of the ambient air, the cheap material and the
expensive material. From the computation, we will extract performance indicators like:
36 CHAPTER 3. INTRODUCTION TO FREEFEM++

1. the mean room temperature


1
Z
J1 = T̄ = T dx; (3.26)
|Ωa | Ωa

2. the minimal temperature in the room

J2 = min T (x); (3.27)


x∈Ωa

3. the standard deviation of temperature:


s
1
Z
2
J3 = T (x) − T̄ dx. (3.28)
Ωa Ωa

Figure 3.3: A problem of thermal engineering design. The room domain Ωa , the wall domain Ωw
made of the expensive material domain Ωe and the cheap material domain Ωc .

Of course they are many ways to define the composite material: it can be organized by layers with one
or several layers of expensive material. It can be designed as inclusion of spherical expensive material
particulates, organized deterministically or randomly, etc. A complex engineering design would to be
optimize the placement of the expensive material marked by the domain Ωe , for example

min J3 (Ωe ) (3.29)


Ωe

subject to
|Ωe |
= µ. (3.30)
|Ωw |

This problem belongs to the general mathematical problem of shape optimization.

Let us denote Ω the whole interior domain of figure 3.3. The stationary thermal problem to consider
3.3. A PROBLEM OF THERMAL ENGINEERING 37

is

−∇ · (κ(.)∇T ) = 0 in Ω, (3.31)
∂T
=0 on Γa = ∂Ω\(Γr ∪ Γext ), (3.32)
∂n
T = Tr on Γr , (3.33)

T = Text on Γext (3.34)

where κ(.) is the piecewise constant thermal conductivity defined from κa , κc and κe :

κ(x) = κa 1x∈Ωa (x) + κc 1x∈Ωc (x) + κe 1x∈Ωe (x). (3.35)

1 // ThermalDesign.edp
2 // Thermal design engineeering problem
3 // Wall composite material made of two homogeneous materials,
4 // on is cheap, the other one is expensive .
5 real Lx = 4, Ly=5, lr=1, lx=0.3;
6 real Tr=20, Text = -5;
7 real hy = 0.1;
8 real hx = 0.1;
9 real mu = 0.2;
10 real kappaa = 10;
11 real kappac = 1;
12 real kappae = 0.008;
13 //
14 real V = lx*Ly;
15 real Ve = mu * V;
16 real xem = Lx + hx;
17 real deltaxe = Ve / (Ly-2*hy);
18 //
19 border c1(t=0,Lx){x=t; y=0;}
20 border c1w(t=Lx,Lx+lx){x=t; y=0;}
21 border cext(t=0,Ly){x=Lx+lx; y=t;}
22 border c3w(t=Lx+lx,Lx){x=t; y=Ly;}
23 border c3(t=Lx,0){x=t; y=Ly;}
24 border c4(t=Ly,Ly/2+lr/2){x=0; y=t;}
25 border cr(t=Ly/2+lr/2,Ly/2-lr/2){x=0; y=t;}
26 border c5(t=Ly/2-lr/2,0){x=0; y=t;}
27 border c0(t=0,Ly){x=Lx; y=t;}
28 //
29 border ce1(t=xem, xem+deltaxe){x=t; y=hy;}
30 border ce2(t=hy,Ly-hy){x=xem+deltaxe; y=t;}
31 border ce3(t=xem+deltaxe, xem){x=t; y=Ly-hy;}
32 border ce4(t=Ly-hy,hy){x=xem; y=t;}
33 //
34 mesh Th = buildmesh(c1(30)+c1w(10)+cext(100)
35 +c3w(10)+c3(30)+c4(15)+cr(15)+c5(15)+c0(100)
36 +ce1(15)+ce2(500)+ce3(15)+ce4(500));
37 plot(Th, ps="mesh.eps", wait=1);
38
38 CHAPTER 3. INTRODUCTION TO FREEFEM++

39 mesh Th2=buildmesh( c1(30)+c0(100)+c3(30)+c4(15)


40 +cr(15)+c5(15) );
41 //
42 fespace Vh(Th, P1);
43 Vh kappa, th, vh;
44 real region1 = Th(Lx/2,Ly/2).region;
45 real region2 = Th(xem+deltaxe/2, Ly/2).region;
46 kappa = kappac + (kappaa-kappac)*(region==region1)
47 +(kappae-kappac)*(region==region2);
48 plot(kappa, nbiso=60, fill=1, value=1);
49 //
50 problem thermal(th, vh) =
51 int2d(Th)(kappa*dx(th)*dx(vh)+kappa*dy(th)*dy(vh))
52 +on(cext, th=Text)
53 +on(cr, th=Tr);
54 //
55 thermal;
56 real[int] colorhsv=[ // color hsv model
57 4./6., 1 , 0.5, // dark blue
58 4./6., 1 , 1, // blue
59 5./6., 1 , 1, // magenta
60 1, 1. , 1, // red
61 1, 0.5 , 1 // light red
62 ];
63 real[int] viso(26);
64 for (int i=0; i<viso.n; i++)
65 viso[i] = -5+i;
66 plot(th,viso=viso(0:viso.n-1), value=1, fill=1,
67 ps="tfield.eps");
68 // Performance indicators
69 fespace Vh2(Th2, P1);
70 Vh2 th2 = th;
71 real J1, J2, J3;
72 // Mean value
73 J1 = int2d(Th2)(th2)/Th2.area;
74 J2 = th2[].min;
75 J3 = sqrt(int2d(Th2)((th2-J1)^2)/Th2.area);
76 // Min value
77 // Standard Deviation
78 cout << "Mean temperature = " << J1 << endl;
79 cout << "Min temperature = " << J2 << endl;
80 cout << "Standard deviation = " << J3 << endl;
81 cout << "Done." << endl;
3.3. A PROBLEM OF THERMAL ENGINEERING 39

Mean temperature = 16.9214


Min temperature = 13.5943
Standard deviation = 0.98602
Done.
times: compile 0.187s, execution 1.282s, mpirank:0

Figure 3.4: A snapshot of the standard output of the freefem++ program ThermalDesign.edp.

Figure 3.5: Mesh computed by ThermalDesign.edp for the thermal design problem. The com-
posite wall here is organized in layers. One can notice the strong variation of diameter of the triangles
due to the room/wall aspect ratio involving different spatial scales.

IsoValue
-5
-4
-3
-2
-1
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Figure 3.6: Temperature field computed by the freefem++ program ThermalDesign.edp. Each
band of color represents a temperature range of 1 degree.
40 CHAPTER 3. INTRODUCTION TO FREEFEM++
Chapter 4

The Method of characteristics

4.1 Mathematical setting


In dimension d = 1, 2, 3 and for a domain Ω ⊂ Rd , the inhomogeneous convection equation is written

∂t q + u · ∇q = f on Ω × (0, T ) (4.1)
where u(x, t) ∈ Rd . Recall that the equation (4.1) can be discretized as

Dq
=f
Dt
i.e.
dq dX
(X(t), t) = f (X(t), t), (t) = u(X(t), t)
dt dt
where D is the particle derivative (also called the total derivative operator). So a good time discretiza-
tion scheme is one step of backward convection by the so-called method of Characteristics:

q n+1 (x) − q n (X n (x))


= f n (x) (4.2)
∆tn

where X n (x) is an approximation of the solution at time tn (tn+1 = tn + ∆tn ) of the ordinary
differential equation
dX
(t) = un (X(t)), X(tn+1 ) = x
dt
where un (x) = u(x, tn ). Because, by Taylor’s expansion, we have

d
X ∂q ∂Xi n+1
q n (X(tn )) = q n (X(tn+1 )) − ∆tn (X(tn+1 )) (t ) + o(∆tn )
∂xi ∂t
i=1

q (x) − ∆t u (x) · ∇q n (x) + o(∆tn )


n n n
(4.3)

where Xi (t) are the i-th components of X(t), q n (x) = q(x, tn ) and x = X(tn+1 ). From (4.3), it
follows that
q n (X n (x)) = q n (x) − ∆tn un (x) · ∇q n (x) + o(∆tn ). (4.4)

41
42 CHAPTER 4. THE METHOD OF CHARACTERISTICS

Also if we apply Taylor’s expansion for t 7→ q n (x − un (x)t), 0 ≤ t ≤ ∆tn , then

q n (x − un (x)∆tn ) = q n (x) − ∆tn un (x) · ∇q n (x) + o(∆tn ).

Denoting the freefem++ function

convect(un , −∆tn , q n ) ≈ q n (x − un ∆tn )

we can get the approximation

q n (X n (x)) ≈ convect(un , −∆tn , q n )

by
X n ≈ x 7→ x − ∆tn un (x).

4.1.1 freefem++ source code of the pure transport problem

1 // Convection.edp (Freefem++)
2 real Lx = 6;
3 real Ly = 4;
4 real dt = 3;
5 real dtsnap=100, time=0, tsnap=dt;
6 int itmax=300;
7 //
8 real[int] A(2), B(2), C(2), D(2);
9 real[int] E(2), F(2), G(2), H(2);
10 real[int] I(2), J(2), K(2), L(2);
11 real[int] O(2), P(2), Q(2), R(2);
12 real[int] itplot(itmax), masse(itmax);
13 A = [0,0]; B=[Lx,0];
14 C= [Lx,Ly]; D=[0,Ly];
15 E=[Lx/2,Ly/4]; F=[Lx/2,3*Ly/4];
16 G=[Lx/6,Ly/4]; H=[5*Lx/6,Ly/4];
17 I=[Lx/6,3*Ly/4]; J=[5*Lx/6,3*Ly/4];
18 O=[0, Ly/2]; P=[Lx/3,Ly/2];
19 Q=[2*Lx/3, Ly/2]; R=[Lx,Ly/2];
20 border c1(t=0,1){x=(1-t)*A[0]+t*B[0]; y=(1-t)*A[1]+t*B[1];}
21 border c2(t=0,1){x=(1-t)*B[0]+t*C[0]; y=(1-t)*B[1]+t*C[1];}
22 border c3(t=0,1){x=(1-t)*C[0]+t*D[0]; y=(1-t)*C[1]+t*D[1];}
23 border c4(t=0,1){x=(1-t)*D[0]+t*A[0]; y=(1-t)*D[1]+t*A[1];}
24 border c5(t=0,1){x=(1-t)*E[0]+t*F[0]; y=(1-t)*E[1]+t*F[1];}
25 border c6(t=0,1){x=(1-t)*G[0]+t*H[0]; y=(1-t)*G[1]+t*H[1];}
26 border c7(t=0,1){x=(1-t)*I[0]+t*J[0]; y=(1-t)*I[1]+t*J[1];}
27 border c8(t=0,1){x=(1-t)*O[0]+t*P[0]; y=(1-t)*O[1]+t*P[1];}
28 border c9(t=0,1){x=(1-t)*Q[0]+t*R[0]; y=(1-t)*Q[1]+t*R[1];}
29 int nn=20;
30 mesh Th = buildmesh( c1(8*nn)+c2(6*nn)+c3(8*nn)+c4(6*nn)
31 +c5(4*nn)+c6(5*nn)+c7(5*nn)+c8(3*nn)+c9(3*nn) );
32 plot (Th, ps="mesh.eps");
33 //
34 func fy=x-Lx/2;
4.1. MATHEMATICAL SETTING 43

35 fespace Uh(Th, P1b);


36 fespace Vh(Th, P1);
37 Uh u1, u2, u1h, u2h;
38 Vh p, ph, q;
39 //
40 problem Stokes([u1, u2, p],[u1h, u2h,ph]) =
41 int2d(Th)(dx(u1)*dx(u1h)+dy(u1)*dy(u1h))
42 +int2d(Th)(dx(u2)*dx(u2h)+dy(u2)*dy(u2h))
43 +int2d(Th)(dx(p)*u1h+dy(p)*u2h)
44 +int2d(Th)(dx(u1)*ph+dy(u2)*ph)
45 -int2d(Th)(fy*u2h)
46 +on(c1,c2,c3,c4,c5,c6,c7,c8,c9, u1=0, u2=0);
47 //
48 Stokes; plot([u1, u2], ps="velocity.eps");
49 //
50 q = (sqrt((x-Lx/2)^2+(y-Ly/8)^2)<0.2);
51 real masse0 = int2d(Th)(q);
52 //
53 plot(q, nbiso=40, fill=1);
54 //
55 for (int it=0; it<itmax; it++){
56 itplot[it] = it;
57 q = convect([u1,u2], -dt, q);
58 masse[it] = int2d(Th)(q);
59 time += dt;
60 plot(q, nbiso=40, fill=1);
61 cout << "Masse0 = " << masse0 << "Masse(t) = "
62 << masse[it] << endl;
63 if (time >= tsnap) {
64 tsnap += dtsnap;
65 plot(q, nbiso=60, fill=1, ps="q_time="+time+".eps");
66 }
67 }
68 plot([itplot, masse], ps="histomasse.eps", value=1);
69 ofstream of("histomasse.txt");
70 for (int it=0; it<itmax; it++) {
71 of << itplot[it] << " " << masse[it] << endl;
72 }

4.1.2 Numerical Results


44 CHAPTER 4. THE METHOD OF CHARACTERISTICS

Figure 4.1: Independent stationary velocity field computed with the Stokes equations

Figure 4.2: Numerical solution of the pure convection problem. Numerical solution at time t = 3.

Figure 4.3: Numerical solution of the pure convection problem. Numerical solution at time t = 105.
4.1. MATHEMATICAL SETTING 45

Figure 4.4: Numerical solution of the pure convection problem. Numerical solution at time t = 204.

Figure 4.5: Numerical solution of the pure convection problem. Numerical solution at time t = 405.

Figure 4.6: Numerical solution of the pure convection problem. Numerical solution at time t = 603.
46 CHAPTER 4. THE METHOD OF CHARACTERISTICS

Figure 4.7: Numerical solution of the pure convection problem. Numerical solution at time t = 804.

0.13
"histomasse.txt" using 1:2

0.125

0.12

0.115

0.11

0.105

0.1

0.095

0.09

0.085
0 50 100 150 200 250 300

Figure 4.8: History of the total mass of the solution t 7→ ||q(., t)||L1 . One can observe an increasing
error of mass conservation.
Chapter 5

Stokes equations and Navier-Stokes


equations

5.1 Setting of the equations


Let us consider a Newtonian fluid with density ρ and velocity u. For an incompressible fluid (constant
density), the continuity equation of mass conservation

∂t ρ + ∇ · (ρu) = 0 (5.1)

simply writes
∇ · u = 0. (5.2)
Let p be the pressure of the fluid, µ the dynamic viscosity and ρ a volume external force. The balance
equation of momentum

∂t (ρu) + ∇ · (ρu ⊗ u) − ∇ · (µ∇u) + ∇p = ρf (5.3)

also simplifies as
∂t u + u · ∇u − ν∆u + ∇p = f . (5.4)
where ν = µ/ρ denotes the static viscosity. The two equations (5.2) and (5.3) form the well-known
Navier-Stokes equations. Those equations are nonlinear because of the inertial term u · ∇u. The
existence and uniqueness of solutions of these equations in the 3D case in still an open problem. It is
known that the structure of the solutions can be quite complex especially for small viscosities ν where
turbulence occurs.
Dimensionless Navier-Stokes equations make appear the Reynolds number

U 0 L0
Re = (5.5)
ν
where U0 and L0 are respectively velocity and length characteristic scales. The dimensionless Navier-
Stokes equations then write

1
∇ · u = 0, ∂t u + u · ∇u − ∆u + ∇p = f . (5.6)
Re

47
48 CHAPTER 5. STOKES EQUATIONS AND NAVIER-STOKES EQUATIONS

Small Reynolds numbers lead to a laminar flow dominated by “Stokes effects" whereas large Reynolds
numbers lead to a turbulent flow. For intermediate Reynolds, the flow is said to be in transition
regime with appearance of unsteady instabilities. When the flow is dominated by viscous effects
(small Reynolds numbers), the initial term u · ∇u is rather small compred to the viscous term. Thus,
the Navier-Stokes equations can be approximated by the Stokes equations

∇ · u = 0, (5.7)
1
∂t u − ∆u + ∇p = f . (5.8)
Re
When the flow is closed to a steady state, the unsteady Stokes equation can be approximated by so-
called stationary Stokes equations

∇ · u = 0, (5.9)
1
− ∆u + ∇p = f . (5.10)
Re

5.2 Analysis of the stationary Stokes problem


Let us consider a smooth spatial domain Ω ∈ R2 . For reasons that will appear later, we shall consider
an approximate model of the Stokes equations, namely the pseudo-compressible approximation where
a pressure term is added to the continuity equation:

−ν∆u + ∇p = f , (5.11)

∇ · u + ε p = 0. (5.12)

As an example, let us consider a boundary ∂Ω splitted up into three borders ∂Ω = Γ1 ∪ Γ2 ∪ Γ3 with


distinct boundary conditions. On Γ1 , we will consider Dirichlet boundary condition for the velocity:

u=g on Γ1 (5.13)

(for example a given velocity profile for inlet flow). On Γ2 , we will consider wall boundary no-slip
conditions:
u = 0 on Γ2 . (5.14)
On Γ3 , let us consider homogeneous Neumann conditions on velocity and a zero pressure condition
∂u
= 0, p = 0 on Γ3 . (5.15)
∂n
(usual for outlet boundary conditions for example) Let us now write the variational formulation of the
problem. The first equation (5.11) also writes component-by-component

−ν∆uj + ∂j p = fj , j = 1, 2.

By multiplying by a smooth test function vj and integrating over Ω, we get


Z Z Z
−ν ∆uj vj dx + ∂j p vj dx = fj vj dx.
Ω Ω Ω
5.2. ANALYSIS OF THE STATIONARY STOKES PROBLEM 49

Applying Green’s formula gives


∂uj
Z Z Z Z Z
−ν vj dγ + ν ∇uj · ∇vj dx + pnj vj dγ − p∂j vj dx = fj vj dx.
∂Ω ∂n Ω ∂Ω Ω Ω

This can be written in vector form


∂u
Z Z Z Z Z
−ν · v dγ + ν ∇u · ∇v dx + p v · n dγ − p ∇ · v dx = f · v dx (5.16)
∂Ω ∂n Ω ∂Ω Ω Ω

with v = (v1 , v2 ). We also multiply equation (5.12) by a smooth test function q and integrate over Ω:
Z Z
∇ · u q dx + ε p q dx = 0. (5.17)
Ω Ω

Now, we have to find the proper functional spaces for both the unknowns (u, p) and the test functions
(v, q) according to the boundary conditions (5.13)-(5.15). For any ϕ ∈ H 1/2 (Γ1 ), let us consider the
product space

Vϕ = (v, q) ∈ [H 1 (Ω)]2 × L2 (Ω), v = ϕ on Γ1 , v = 0 on Γ2 .



(5.18)

It is clear that V = V0 is a Hilbert space for the scalar product

((u, p), (v, q))V = (u, v)H 1 (Ω) + (p, q)L2 (Ω) (5.19)

and the associated norm


 1/2
||(u, p)||V = ||u||2H 1 (Ω) + ||p||2L2 (Ω) .

By choosing functions (u, p) ∈ Vg and (v, q) ∈ V , all the terms in (5.18),(5.19) have a sense. From
boundary conditions (5.13)-(5.15), the variational formulation (5.16) reduces to
Z Z Z
ν ∇u · ∇v dx − p ∇ · v dx = f · v dx. (5.20)
Ω Ω Ω

So the problem is to find a solution (u, p) ∈ Vg such that (5.20) and (5.17) hold for all (v, q) ∈ V .
This is also equivalent to find (u, p) ∈ Vg such that
Z Z Z Z Z
ν ∇u · ∇v dx − p ∇ · v dx + q ∇ · u dx + ε p q dx = f · v dx (5.21)
Ω Ω Ω Ω Ω

for all (v, q) ∈ V . Equation (5.21) is in the form

a ((u, p), (v, q)) = ℓ (v, q) (5.22)

with
Z Z Z Z
a ((u, p), (v, q)) = ν ∇u · ∇v dx − p ∇ · v dx + q ∇ · u dx + ε p q dx (5.23)
Ω Ω Ω Ω

and Z
ℓ (v, q) = f · v dx. (5.24)

50 CHAPTER 5. STOKES EQUATIONS AND NAVIER-STOKES EQUATIONS

We are going to verify that the assumptions on the Lax-Milgram theorem are satisfied. First, remember
that V his a Hilbert space with scalar product (5.19). Clearly, a is a bilinear form in V × V and ℓ
is a linear form in V . Let us show the continuity property with respect to the V -norm. First by the
Cauchy-Schwarz inqequality we have

|ℓ(v, q)| ≤ ||f ||[L2 (Ω)]2 ||v||[L2 (Ω)]2

≤ ||f ||[L2 (Ω)]2 ||v||[H 1 (Ω)]2

≤ ||f ||[L2 (Ω)]2 ||(v, q)||V .

Secondly, we have also

|a ((u, p), (v, q)) | ≤ ν||u||H 1 (Ω) ||v||H 1 (Ω) + ||p||L2 (Ω) ||∇ · v||L2 (Ω) + ||q||L2 (Ω) ||∇ · u||L2 (Ω)
+ε ||p||L2 (Ω) ||q||L2 (Ω)

≤ (ν + 2 + ε) ||(u, p)||V ||(v, q)||V

so that a is a bilinear form, continuous in V × V . The last property to verify is the V -ellipticity of the
bilinear form a. From (5.23) we have
Z Z
a ((u, p), (u, p)) = |∇u|2 dx + ε p2 dx
Ω Ω

= |u|2H 1 (Ω) + ε ||p||2L2 (Ω)

≥ min(1, ε)||(u, p)||V .

This last inequality shows the V -ellipticity property as soon as ε > 0. Thus, the Lax-Milgram theorem
states that the solution (u, p) of the problem (5.22) exists and is unique. For a Finite Element method
which is conformal in V , we also have this result of existence and uniqueness, showing that the discrete
problem
a((uh , ph ), (v h , q h )) = ℓ(v h , q h ) ∀(v h , q h ) ∈ V h ⊂ V (5.25)

is well-posed. Remark that the pseudo-compressibility assumption is important to get the V -ellipticity
property. Under the true incompressibility hypothesis (ε = 0), more theoretical developments and a
deeper analysis are required. The existence and uniqueness comes from a property of ellipticity called
the inf-sup condition or also referred to as LLB (Ladyzenskaya-Babuska-Brezzi) condition (see[1]).
From the discrete point of view, stable Finite Element method for the true incompressible Stokes
equations are method that satisfy a discrete version of the inf-sup condition (the so-called discrete inf-
sup condition). Discrete inf-sup conditions are proved for example for P1-bubble/P1 approximations
(P1-bubble in velocity and P1 in pressure) or P2/P1 approximation (P2 in velocity and P1 in pressure).
The P1/P1 approximation violates the discrete inf-sup condition. In that case, some parasite modes
appear in the discrete solution. This topic is beyond the scope of this course. The interested reader
can refer to the important literature on this topic (see[1, ?]).
5.3. NUMERICAL METHOD FOR THE NAVIER-STOKES EQUATIONS 51

5.3 Numerical method for the Navier-Stokes equations


Let us consider now the time-dependent Navier-Stokes equations with the pseudo compressibility
approximation:

∂t u + u · ∇u − ν∆u + ∇p = f , (5.26)

∇ · u + ε p = 0. (5.27)

The system of equations becomes nonlinear due to the convection term. The simplest way to approx-
imate these equations is to use the methods of characteristics for the convection term and standard
Finite Elements for the other term. A semi-discrete time discretization of (5.26),(5.27) gives

un+1 (x) − un ◦ X n (x)


− ν∆un+1 (x) + ∇pn+1 (x) = f (x), (5.28)
∆t
∇ · un+1 (x) + ε pn+1 (x) = 0. (5.29)

For a given field un , considering (un+1 , pn+1 ) as the unknowns, the system (5.28),(5.29) is seen as
the Stokes equations. Then we can apply the results obtained for the Stokes problem. Considering the
same boundary conditions as the previous section, the variational problem of (5.28),(5.29) is to find
(un+1 , pn+1 ) ∈ Vg such that

un+1 − un ◦ X n
Z Z Z Z
n+1 n+1
· v dx + ν ∇u · ∇v dx − p ∇ · v dx = f · v dx,
(5.30)
Ω ∆t Ω Ω Ω
Z Z
∇ · un+1 q dx + ε pn+1 q dx = 0. (5.31)
Ω Ω

for all (v, q) ∈ V . As exercise, we reader will show the continuity and ellipticity constants of the
underlying bilinear and linear forms.

5.4 Numerical experiments


5.4.1 freefem++ source code

1 //
2 real Re = 600.0;
3 real nu = 1.0/Re;
4 real Lx = 12;
5 real Ly = 5;
6 real dt = 0.5;
7 border c1(t=0,1){x=t*Lx; y=0;}
8 border c2(t=0,1){x=Lx; y=t*Ly;}
9 border c3(t=1,0){x=t*Lx; y=Ly;}
10 border c4(t=1,0){x=0; y=t*Ly;}
11 border c5(t=2*pi,0){x=4+0.2*cos(t); y=Ly/2+0.2*sin(t);}
12 border c6(t=0,1){x=5+Lx/2*t; y=Ly/2+0.4;}
13 border c7(t=0,1){x=5+Lx/2*t; y=Ly/2-0.4;}
14 //
52 CHAPTER 5. STOKES EQUATIONS AND NAVIER-STOKES EQUATIONS

15 mesh Th = buildmesh(c1(80)+c2(40)+c3(80)+c4(20)
16 +c5(60)+c6(100)+c7(100));
17 plot(Th);
18 //
19 fespace Uh(Th, P2);
20 fespace Vh(Th, P1);
21 Uh u, v, uh, vh, uold, vold;
22 Vh p, ph;
23 Vh uplot, vplot, vort;
24 //
25 // Velocity field is initialized by steady state solution
26 //
27 real eps = 1e-10;
28 problem steadystokes([u,v,p], [uh,vh,ph]) =
29 int2d(Th)( nu*dx(u)*dx(uh) + nu*dy(u)*dy(uh) )
30 +int2d(Th)(nu*dx(v)*dx(vh) + nu*dy(v)*dy(vh) )
31 -int2d(Th)(p*dx(uh))
32 -int2d(Th)(p*dy(vh))
33 -int1d(Th, c2)(nu*dx(u)*N.x*uh+nu*dy(u)*N.y*uh)
34 -int1d(Th, c2)(nu*dx(v)*N.x*vh+nu*dy(v)*N.y*vh)
35 +int2d(Th)(dx(u)*ph + dy(v)*ph)
36 +int2d(Th)(eps*p*ph)
37 +on(c1, c3, c5, u=0, v=0)
38 +on(c4, u=4.0 * y/Ly * (1-y/Ly), v=0);
39 //
40 steadystokes;
41 uplot = u;
42 vplot = v;
43 plot(Th, [uplot,vplot], nbiso=40, value=1);
44 uold = u;
45 vold = v;
46 //
47 // Now go for unsteady Navier−Stokes equations .
48 //
49 int it = 0;
50 problem navierstokes([u,v,p], [uh,vh,ph], init=it,
51 solver=sparsesolver) =
52 int2d(Th)(u*uh/dt)
53 -int2d(Th)(convect([uold,vold], -dt, uold)*uh/dt)
54 +int2d(Th)(v*vh/dt)
55 -int2d(Th)(convect([uold,vold], -dt, vold)*vh/dt)
56 +int2d(Th)( nu*dx(u)*dx(uh) + nu*dy(u)*dy(uh) )
57 +int2d(Th)(nu*dx(v)*dx(vh) + nu*dy(v)*dy(vh) )
58 -int2d(Th)(p*dx(uh))
59 -int2d(Th)(p*dy(vh))
60 -int1d(Th, c2)(nu*dx(u)*N.x*uh+nu*dy(u)*N.y*uh)
61 -int1d(Th, c2)(nu*dx(v)*N.x*vh+nu*dy(v)*N.y*vh)
62 +int2d(Th)(dx(u)*ph + dy(v)*ph)
63 +int2d(Th)(eps*p*ph)
64 +on(c1, c3, c5, u=0, v=0)
65 +on(c4, u=4.0 * y/Ly * (1-y/Ly), v=0);
66 //
5.4. NUMERICAL EXPERIMENTS 53

67 for (it=0; it<20; it++) {


68 for (int subit=0; subit<5; subit++) {
69 navierstokes;
70 // Th = adaptmesh(Th, [u,v]) ; u = u; v = v;
71 uold = u;
72 vold = v;
73 }
74 uplot = u;
75 vplot = v;
76 plot(Th, [uplot, vplot], nbiso=60, ps="u_ns_it="+it+".eps");
77 vort = dy(u)-dx(v);
78 plot(vort, nbiso=60, fill=0, ps="vort_ns_it="+it+".eps");
79 }

5.4.2 Numerical results


54 CHAPTER 5. STOKES EQUATIONS AND NAVIER-STOKES EQUATIONS

Figure 5.1: Vorticity contours during simulation.


5.4. NUMERICAL EXPERIMENTS 55

Figure 5.2: Vorticity contours during simulation. Von Karman instabilities develop.
56 CHAPTER 5. STOKES EQUATIONS AND NAVIER-STOKES EQUATIONS

Figure 5.3: Vorticity contours during simulation. Von Karman instabilities develop.
Chapter 6

Fractional step methods

Fractional step methods also known as operator splitting methods are time advance schemes where
partial differential equations are splitted up into different simpler (well-posed) partial differential
equations. The different PDE problems are solved sequentially. Those are interesting computational
approaches especially when the Physics is complex. When the whole Physics is a combination of
different effects (convection, diffusion, reaction, exchanges, etc.), fractional steps method solve each
physical effect independently and sequentially. Fractional step methods can also be seen as a way to
couple component codes where each code solves a particular Physics.

6.1 Introduction
Let us consider an ordinary differential system of equations
du
= f1 (u) + f2 (u) (6.1)
dt
where f1 and f2 both are continuously differentiable functions. With an initial data

u(0) = u0 ∈ Rp (6.2)

the problem has a unique maximal solution in a time interval I that includes 0. Let ∆t be a small time
step such that [0, ∆t] ⊂ I. Then a Taylor expansion gives
du 0
u(∆t) = u0 + ∆t (u ) + o(∆t)
dt
= u0 + ∆t f1 (u0 ) + f2 (u0 ) + o(∆t).

(6.3)

A fractional step method for (6.1),(6.2) can be the following one:


1. First solve the differential problem
du
= f1 (u), (6.4)
dt
u(0) = u0 (6.5)

over a time step. Let û0 = u(∆t).

57
58 CHAPTER 6. FRACTIONAL STEP METHODS

2. Then solve the differential problem


dû
= f2 (û), (6.6)
dt
û(0) = û0 (6.7)

over a time step ∆t.


Then it is easy to check that the solution û(∆t) is an approximation of order 1 in ∆t of the true
solution u(∆t) of (6.1),(6.2) at time ∆t. Indeed, from Taylor expansions we have
dû 0
û(∆t) = û0 + ∆t (û ) + o(∆t)
dt
= u0 + ∆t f2 (û0 ) + o(∆t)

= u0 + ∆t f1 (u0 ) + ∆t f2 (u0 + ∆t f1 (u0 ) + o(∆t)) + o(∆t)

= u0 + ∆t f1 (u0 ) + f2 (u0 ) + o(∆t).



(6.8)

Thus Taylor expansions (6.3) and (6.8) are identical and û(∆t) is a first order approximation in ∆t of
u(∆t).

As we will see, there are higher order fractional steps methods. We have also to check that the
splitting approach is stable in time.

6.2 Continuous analysis, case of a linear system


Consider now the linear problem
du
= Au + Bu, (6.9)
dt
u(0) = u0 (6.10)

for some square matrices A and B. The analytical solution of (6.9) and (6.10) is

u(t) = exp ((A + B)t) u0 , t ≥ 0. (6.11)

Proceeding in two steps by splitting up the problem into


du
= Au, (6.12)
dt
u(0) = u0 (6.13)

whose solution is u(t) = exp(At) u0 , and


dû
= B û, (6.14)
dt
û(0) = û0 = exp(At) u0 , (6.15)
6.3. STRANG SECOND-ORDER SYMMETRIC SPLITTING 59

the approximate solution is


û(t) = exp(Bt) exp(At) u0 (6.16)
which is in general different from (6.11). At a small instant t = ∆t, we have by from Taylor expan-
sions

u(∆t) = exp((A + B)∆t) u0


∆t2
 
2
= I + ∆t(A + B) + (A + B) u0 + o(∆t2 )
2
∆t2 2
 
= I + ∆t(A + B) + (A + AB + BA + B ) u0 + o(∆t2 )
2
(6.17)
2

on one side and

û(∆t) = exp(B∆t) exp(A∆t) u0


∆t2 2 ∆t2 2
  
= I + ∆tB + B I + ∆tA + A u0 + o(∆t2 )
2 2
∆t2 2
 
= I + ∆t(A + B) + (A + 2BA + B ) u0 + o(∆t2 )
2
(6.18)
2

on the other side. From (6.17) and (6.18), one can conclude that the fractional step method generally
leads to a first order approximate solution. In the particular case where matrices A and B commute,
i.e.
AB = BA, (6.19)
then the approximation is second order accurate.

6.3 Strang second-order symmetric splitting


We shall prove that the following symmetric three-step fractional step method provides second-order
accuracy. By denoting
PA∆t u0 (6.20)
the solution of
du
= A u, u(0) = u0 , (6.21)
dt
at time ∆t and
∆t 0
PB u (6.22)
the solution of
du
= B u, u(0) = u0 , (6.23)
dt
at time ∆t, the Strang second-order symmetric splitting consists in approximating the exact solu-
tion u(∆t) by
∆t/2 ∆t ∆t/2 0
û(∆t) = PA PB PA u . (6.24)
60 CHAPTER 6. FRACTIONAL STEP METHODS

Let us show that the approximation (6.24) is second order accurate in time. We have also

∆t ∆t
û(∆t) = exp(A ) exp(B∆t) exp(A ) u0 . (6.25)
2 2
By a Taylor expansion of order in ∆t in (6.24), we get

∆t2 2 ∆t2 2 ∆t2 2


   
∆t ∆t
û(∆t) = I+ A+ A I + ∆tB + B I+ A+ A u0 + o(∆t2 )
2 8 2 2 8
 
∆t 2
= I + ∆tA + ∆tB + (A + AB + BA + B ) u0 + o(∆t2 )
2
2

= exp((A + B)∆t) + o(∆t2 )

which proves the assertion.

6.4 Discrete time advance schemes


Let us now consider discrete times advances schemes combined with an operator splitting approach.

6.4.1 First order scheme


Consider again the nonlinear differential problem (6.1),(6.2). Let un be an approximation of order
1 of u(tn ), ∆t a time step and tn+1 = tn + ∆t the next discrete time. Using for example forward
Euler schemes for the integration of each step, we get the following scheme corresponding to the time
iteration n:

1. Compute first
ûn+1 = un + ∆t f1 (un ); (6.26)

2. Then compute
un+1 = ûn+1 + ∆t f2 (ûn+1 ). (6.27)

It is an easy matter of fact to show that the fractional step metho (6.26),(6.27) is first order accurate.
By using (6.26) into (6.27) we have

un+1 = un + ∆t f1 (un ) + ∆t f2 (un + ∆t f1 (un )) . (6.28)

The consistency error of expression (6.28) is

u(tn+1 ) − u(tn )
εn = − f1 (u(tn )) − f2 (u(tn ) + ∆t f1 (u(tn )))
∆t
∂f2
= f1 (u(tn )) + f2 (u(tn )) + o(1) − f1 (u(tn )) − f2 (u(tn )) − ∆t (u(tn ))f1 (u(tn )) + o(∆t)
∂u
= o(1).
6.4. DISCRETE TIME ADVANCE SCHEMES 61

6.4.2 Second order schemes


For many applications where dynamical effects or transient phases are important, first order schemes
are not sufficiently accurate to compute the dynamics. Therefore second order fractional step schemes
are needed. From the second order symmetric Strang splitting scheme, let us define a discrete time
advance scheme.

Each step of the operator splitting has to solved with a second order scheme too in order to get global
second order accuracy.

Recall first that the following two-step Runge-Kutta RK2 time-advance scheme (also known as the
Heun scheme) is second order accurate: for the solution of u̇ = f (u) between tn and tn+1 , it is
written
ûn+1 = un + ∆tf (un ), (6.29)
∆t
un+1 = un + f (un ) + f (ûn+1 ) .

(6.30)
2
The consistency error is
u(tn+1 ) − u(tn ) 1
 
n n ∂f n
ε = − f (u(t )) + ∆t f (u(t ))(u(t )) + f (u(t )) + o(∆t)
n n
∆t 2 ∂u
∆t d2 u
 
n n 1 n ∂f n
= f (u(t )) + (u(t )) − f (u(t )) + ∆t f (u(t ))(u(t )) + f (u(t )) + o(∆t)
n n
2 dt2 2 ∂u
= o(∆t)
because
d2 u d ∂f du ∂f
= f (u) = = (u(t))f (u(t)).
dt2 dt ∂u dt ∂u
∆t/2
Let us now define the discrete Strang fractional step scheme. For that, let us denote P1 the time
propagator operator over a time step ∆t
2 of the solution of the problem
du
= f1 (u(t)),
dt
u(0) = u0
i.e.
∆t/2 ∆t
P1 u0 = u( ) (6.31)
2
and P2∆t the time propagator operator over a time step ∆t of the solution of the problem
dv
= f2 (v(t)),
dt
v(0) = u0
i.e.
P2∆t u0 = v(∆t). (6.32)
Then the discrete Strang splitting scheme using the Heun scheme as second time advance scheme is
defined by the three following steps:
62 CHAPTER 6. FRACTIONAL STEP METHODS

∆t/2
1. Approximation of the state P1 un :

∆t
û1,n+1 = un + f1 (un ), (6.33)
2
∆t
u1,n+1 = un + f1 (un ) + f1 (û1,n+1 ) ;

(6.34)
4

2. Approximation of the state P2∆t u1,n+1 :

û2,n+1 = u1,n+1 + ∆tf2 (u1,n+1 ), (6.35)


∆t
u2,n+1 = u1,n+1 + f2 (u1,n+1 ) + f2 (û2,n+1 ) ;

(6.36)
2

∆t/2
3. Approximation of the state P1 u2,n+1 :

∆t
ûn+1 = u2,n+1 + f1 (u2,n+1 ), (6.37)
2
∆t
un+1 = u2,n+1 + f1 (u2,n+1 ) + f1 (ûn+1 ) .

(6.38)
4

As exercise, the proof of second order consistency is let to the reader.

6.5 Chorin-Temam fractional step method for the Navier-Stokes equa-


tions
In this section, we will consider true incompressible time-dependent Navier-Stokes equations.

With standard discretizations, both velocity u and pressure p variables are solved simultaneously. It
is said that the velocity and pressure are coupled in the solution. From the numerical point of view,
this leads of course to a large system to solve at each time step. In three dimensions for example,
considering P1 approximations and N degrees of freedom, the size of the system to solve is 4N .

Because the solution of 4 linear systems of size N has lower complexity than the solution of a linear
system of size 4N , techniques of variable decoupling have been investigated. The so-called Chorin-
Temam fractional step method is based on a splitting of the Navier-Stokes equation into two parts.
Each time step is made of two substeps:

1. Step 1. First solve the equation by “forgetting” the pressure term over a time interval ∆t:

u⋆ (x) − un ◦ X n (x)
− ν∆un+1 (x) = f (x). (6.39)
∆t

2. Step 2. Solve the remaining par of the system (pressure term) over a time interval ∆t:

un+1 − u⋆
+ ∇pn+1 = 0 (6.40)
∆t
6.5. CHORIN-TEMAM FRACTIONAL STEP METHOD FOR THE NAVIER-STOKES EQUATIONS63

in order to project the velocity un+1 on a divergence-free velocity field. We want ∇ · un+1 = 0.
By taking the divergence of the equation (6.40), one gets the Poisson pressure equation

∇ · u⋆
− ∆pn+1 = − . (6.41)
∆t
Once the Poisson equation is solve, the velocity field is updated according to the rule

un+1 = u⋆ − ∆t ∇pn+1 . (6.42)

A remarkable property of Chorin-Temam’s method is that the solution un+1 at time tn+1 is consistent
with the Navier-Stokes solution with order of accuracy O(∆t).

By using this fractional step approach, the velocity and pressure fields are indeed weakly coupled.
During step 1, only the velocity is changed. More over, because the Laplacian is a “diagonal” oper-
ator, each component of the velocity can be solved independently. Step 1 requires the solution of d
independent convection-diffusion problems. In step 2, a Poisson problem on the pressure alone has to
be solved.

6.5.1 Boundary conditions


We have also to take care of the boundary conditions in this fractional step approach. For step 1, one
can use the prescribed boundary conditions on the velocity, i.e.

∂u⋆
u⋆ = g on Γ1 , u⋆ = 0 on Γ2 , = 0 on Γ3 .
∂n
For the second step, it is a little more tricky because we have to add artificial boundary conditions on
for the unknown pressure to get a boundary value problem. Velocity boundary conditions are already
taken into account in the first step, so we would like that the velocity correction step does not affect
the boundary velocity too much. From (6.42), we have at any boundary

∂un+1 ∂u⋆ ∂pn+1


= − ∆t = 0.
∂t ∂n ∂n
So the natural boundary condition for the Poisson problem is

∂pn+1
= 0 on ∂Ω. (6.43)
∂n
Unfortunately, there is no control on the tangential derivative of the pressure on the boundary. The
Chorin-Temam fractional step method is known to have a lack of accuracy near boundaries. The sec-
ond difficulty is that the solution of a Poisson problem with purely homogeneous Neumann boundary
conditions is not unique and defined up to a constant. A perturbed “regularized” Poisson problem

∇ · u⋆
− ∆p + ε p = − (6.44)
∆t
should be considered numerically in order to get the ellipticity property.
64 CHAPTER 6. FRACTIONAL STEP METHODS
Chapter 7

Case study. Population dynamics and


migration flux analysis

Population dynamics are typically convection-reaction-diffusion equations which model the migration
process of two kinds of population with interaction between both populations. Such models are able to
explain the migration dynamics of predators and preys ecosystems or for instance the human migration
flux into a large city.

7.1 Lokta-Volterra equations


Suppose that two animal species are living in the same territory, a family of predators (in number u in
the sequel) and a family of preys (in number v). To write a model, some assumptions are done. It is
supposed that preys without predators are proliferating, predators without preys vanish, and that preys
are kept by predators at a fixed rate. In this section, it is also assumed that the spatial distribution of
the populations is homogeneous, so that there is no spatial effect.

With these assumptions, the dynamical system is clearly


du
= a uv − b u, (7.1)
dt
dv
= −c uv + d v, (7.2)
dt
where the positive constant a corresponds to the growth rate of predators by prey capture and the
positive constant b is the natural death rate. Also, constants c and d respectively represent the loss rate
of preys by capture and their natural proliferation rate.

By a time scale change, it is possible to write the system (7.1),(7.2) by the normalized one
du
= α u(v − 1), (7.3)
dt
dv
= v(1 − u), (7.4)
dt
for a constant α ≥ 0. To (7.3),(7.4), an initial condition is added
u(0) = u0 , v(0) = v 0 . (7.5)

65
66CHAPTER 7. CASE STUDY. POPULATION DYNAMICS AND MIGRATION FLUX ANALYSIS

The following Scilab code below is able to plot different trajectory solutions for different initial
conditions. The figure 7.1 shows a graphical result of the Scilab code. One can observe that
solutions are periodical in time. They create a closed trajectory solution in the state space (u, v),
u, v ≥ 0.
1 // odelokta . sce ( Scilab file ) − florian de vuyst
2 //
3 // This file is a modification of the initial file
4 // "ode_lotka .dem.sce", part of the Scilab project .
5 //
6 // Sharks and sardins : Lotka−Volterra ODE
7 //
8
9
10 text = ["Lotka-Volterra:"; ..
11 "du/dt = u(v-1)/2"; ..
12 "dv/dt = v(1-u)"; ..
13 ""; ..
14 "A trajectory is plotted by clicking on the"; ..
15 " LEFT button of the mouse."; ..
16 " The trajectory is updated as you move the mouse."; ..
17 " To fix the trajectory, click again on the LEFT button."; ..
18 "You can start over by clicking on the LEFT button again"; ..
19 " or stop everything by clicking on the RIGHT button." ];
20
21 x_message(text);
22 my_handle = scf(100001);
23 clf(my_handle,"reset");
24 demo_viewCode("odelokta.sce");
25
26 function yprim=f(t,y)
27 yprim=[alpha*y(1)*(y(2)-1) y(2)*(1-y(1))]
28 endfunction
29
30 alpha = 0.5;
31 xmin = 0; xmax = 4.0; ymin = 0; ymax = 6.0;
32 fx = xmin:0.5:xmax; fy = ymin:0.5:ymax;
33 fchamp(f,1,fx,fy);
34 xlabel(’u (normalized nb. of predators)’,’fontsize’,3)
35 ylabel(’v (normalized nb. of preys)’,’fontsize’,3)
36 a=gca();a.margins(3)=0.2;
37 title([_("Lokta-Volterra vector field")
38 "du/dt = u(v-1)/2";
39 "dv/dt = v(1-u)"],’fontsize’,3)
40
41 t0 = 0; tmax = 20;
42 t = t0:0.05:tmax;
43 oldx0 = 10*xmax; oldy0 = 10*ymax;
44 dx = 0.1; dy = 0.1;
45 rtol = 0.0001; atol = rtol;
46
47 while (%t)
7.1. LOKTA-VOLTERRA EQUATIONS 67

48 [b,x0,y0]=xclick();
49 if or(b==[2 5 -1000]) then break end;
50 if or(b==[0 3]) & xmin<x0 & x0<xmax & ymin<y0 & y0<ymax then
51 sol=ode([x0;y0],t0,t,rtol,atol,f);
52 xpoly(sol(1,:)’,sol(2,:)’);
53 p=gce();p.thickness=2;p.foreground=5;
54 rep=[x0,y0,-1];
55 while rep(3)==-1 then
56 rep=xgetmouse();
57 x0=rep(1); y0=rep(2);
58 if (xmin<x0 & x0<xmax & ymin<y0 & y0<ymax) & (abs(x0-oldx0)>=dx | abs
(y0-oldy0)>=dy) then
59 sol=ode([x0;y0],t0,t,rtol,atol,f);
60 p.data=[sol(1,:)’ sol(2,:)’];
61 oldx0=x0; oldy0=y0;
62 end
63 end
64 end
65 end

Lokta-Volterra vector field


du/dt = u(v-1)/2
dv/dt = v(1-u)

7
v (normalized nb. of preys)

0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5
u (normalized nb. of predators)

Figure 7.1: The vector field and some trajectories (with different initial conditions) for the Lokta-
Volterra system (7.3),(7.4) with α 21 in the state space (u, v). One can numerically observe a periodical
behaviour of the solutions.

7.1.1 Analysis of some qualitative properties of the solutions


It can be remarked that any solution of the system (7.3),(7.4) such that u 6= 1 and v 6= 0 at any time,
verifies the equation
du u(v − 1)
=α (7.6)
dv v(1 − u)
which can be easily integrated as

αv + u − log(v α u) = αv 0 + u0 − log((v 0 )α u0 ).
68CHAPTER 7. CASE STUDY. POPULATION DYNAMICS AND MIGRATION FLUX ANALYSIS

From the study of the function f (u, v) = αv + u − log(v α u) in R+


⋆ , one can prove the periodical
feature of the differential system.

Let us now consider the equilibrium states of the system (7.3),(7.4). The constants states solutions of
u̇ = v̇ = 0 are (u, v) = (0, 0) and (u, v) = (1, 1). Linearizing the system (7.3),(7.4) in the vicinity of
(0, 0) gives
du
= −αu,
dt
dv
= v.
dt
In particular v(t) = v 0 et and thus (0, 0) is an unstable equilibrium. Let us now consider the second
equilibrium (u, v) = (1, 1). By considering the change of variable u = 1+w, v = 1+z, the linearized
system in variables (w, z) in the vicinity of (0, 0) gives
dw
= αz,
dt
dz
= −w
dt
in the form
d
(w, z)T = A (w, z)T (7.7)
dt
with  
0 α
A= (7.8)
−1 0
with solution (w, z)T (t) = exp(At)(w0 , z 0 )T , t ≥ 0. The stability of the equilibrium depends of
the eigenstructure of A. By denoting λ1 and λ2 the two eigenvalues of A in C, we clearly have

tr(A) = 0 = λ1 + λ2 and det(A) = λ1 λ2 = α > 0. This shows that λ1 = λ̄2 = i α. Both
eigenvalues are pure imaginary complexes. This shows that the equilibrium (1, 1) is a center in the
theory of dynamical systems. In particular, solutions are periodical, oscillating toward the center with

a period √ α
.

7.2 A fractional step approach to solve the Lokta-Volterra equations.


The Strang splitting presented in the previous chapter can be used here as a "numerical solver" of
the nonlinear Lokta-Volterra equations. Let ∆t be a small time step. A second-order fractional step
approach can be we following:
∆t
1. First solve the following problem over a time step 2 :
du
= αu(v − 1), (7.9)
dt
dv
= 0, (7.10)
dt
u(0) = u0 , (7.11)

v(0) = v 0 . (7.12)
7.2. A FRACTIONAL STEP APPROACH TO SOLVE THE LOKTA-VOLTERRA EQUATIONS.69

The analytical solution of (7.9)-(7.12) at time ∆t/2 is


0 −1) ∆t
v ⋆,1 = v 0 , u⋆,1 = u0 eα(v 2 . (7.13)

2. Second, solve the following problem over a time step ∆t:


du
= 0, (7.14)
dt
dv
= v(1 − u) (7.15)
dt
u(0) = u⋆,1 , (7.16)

v(0) = v ⋆,1 . (7.17)

The analytical solution of (7.14)-(7.17) at time ∆t is


⋆,1 )∆t
u⋆,2 = u⋆,1 , v ⋆,2 = v ⋆,1 e(1−u . (7.18)

∆t
3. Finaly solve the following problem over a time step 2 :

du
= αu(v − 1), (7.19)
dt
dv
= 0, (7.20)
dt
u(0) = u⋆,2 , (7.21)

v(0) = v ⋆,2 . (7.22)

The analytical solution of (7.19)-(7.21) at time ∆t/2 is


⋆,2 −1) ∆t
v ⋆,3 = v ⋆,2 , u⋆,3 = u⋆,2 eα(v 2 . (7.23)

To summarize, a second order approximation (u(∆t), v(∆t)) for the Lokta-Volterra equations at
time ∆t is
0 −1) ∆t
u⋆ = u0 eα(v 2 , (7.24)
⋆ )∆t
v(∆t) = v0 e(1−u , (7.25)
∆t
u(∆t) = u⋆ eα(v(∆t)−1) 2 . (7.26)

The following Scilab program implements the integration scheme (7.24)-(7.26) and solves the
Lokta-Volterra problem with (u0 , v 0 ) = (2, 4). Figure 7.2 is the graphical output the of Scilab
program loktastrang.sce.
1 // Loktastrang . sce ( Scilab )
2 // Solution of the Lokta−Volterra equations
3 // using a second order Strang splitting as
4 // integration scheme
70CHAPTER 7. CASE STUDY. POPULATION DYNAMICS AND MIGRATION FLUX ANALYSIS

5 //
6 clear;
7 alpha = 0.5;
8 u(1,1) = 2;
9 v(1,1) = 4;
10 t(1,1) = 0;
11 dt = 0.1;
12 //
13 for n=1:400
14 ustar = u(n,1) *exp(alpha*(v(n,1)-1)*dt/2);
15 v(n+1,1) = v(n,1) * exp((1-ustar)*dt);
16 u(n+1,1) = ustar*exp(alpha*(v(n+1,1)-1)*dt/2);
17 t(n+1,1) = t(n,1) + dt;
18 end; // for n
19 //
20 clf();
21 subplot(1,2,1), plot(u, v, ’.-’);xlabel("u");ylabel("v");xgrid();
22 subplot(1,2,2), plot(t, u, ’x-’, t, v, ’+-’);
23 xlabel("Time t"); ylabel("u(t) and v(t)"); xgrid();

5.0 5.0

4.5 4.5

4.0 4.0

3.5 3.5
u(t) and v(t)

3.0 3.0
v

2.5 2.5

2.0 2.0

1.5 1.5

1.0 1.0

0.5 0.5

0.0 0.0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 0 5 10 15 20 25 30 35 40 45
u Time t

Figure 7.2: Numerical solution of the Lokta-Volterra solver (7.24)-(7.26) plotted in the spate space
first and secondly as a time series (for both u and v).

7.3 Introducing spatial effects, population diffusion phenomenon


Suppose now that the spatial distribution of predators and preys is no more homogeneous. The indi-
vidual random walk of both predators and preys introduces at the macroscopic scale a spatial diffusion
operator. Assuming that the diffusion is isotropic in any direction, the dynamic system then becomes
the PDE reaction-diffusion system
∂u
− ν∆u = α u(v − 1), (7.27)
∂t
∂v
− µ∆v = v(1 − u) (7.28)
∂t
from some diffusion coefficients ν, µ > 0. The following Freefem++ program LoktaVolterra.edp
implements the Strang fractional step method with successive solutions of reactions and diffusion
7.3. INTRODUCING SPATIAL EFFECTS, POPULATION DIFFUSION PHENOMENON 71

problems, a spatial P2 Finite Element approximation is used. In this numerical example, ν = 10−3 ,
µ = 10−4 and the following initial data is used:

u0 (x) = 0.1, v 0 (x) = 2 1(0<x,y< 1 ) (x).


2

Zero-flux homogeneous Neumann boundary conditions are used.


1 // LoktaVolterra .edp (Freefem++)
2 // Solve the Rreaction−Diffusion equation
3 // of the Lokta−Volterra Prey−predator model
4 // by the Strang splitting fractional step method.
5 // The differential reaction system is itself solved
6 // by a Strang splitting . Square spatial domain
7 //
8 mesh Th = square(40, 40);
9 fespace Vh(Th, P2);
10 fespace Wh(Th, P1);
11 real alpha = 0.5;
12 real t = 0.0;
13 real dt = 0.2;
14 real nu = 0.001;
15 real mu = 0.0001;
16 real theta = 0.49;
17 int it=0;
18 //
19 Vh u, uh, uold;
20 Vh v, vh, vold;
21 Wh dxu, dyu, dxv, dyv;
22 //
23 problem heatu (u, uh, init=it) =
24 int2d(Th)(u*uh/dt)
25 -int2d(Th)(uold*uh/dt)
26 +int2d(Th)(nu*(1-theta)*dx(u)*dx(uh)
27 +nu*(1-theta)*dy(u)*dy(uh))
28 +int2d(Th)(nu*(theta)*dx(uold)*dx(uh)
29 +nu*(theta)*dy(uold)*dy(uh));
30 //
31 problem heatv (v, vh, init=it) =
32 int2d(Th)(v*vh/dt)
33 -int2d(Th)(vold*vh/dt)
34 +int2d(Th)(mu*(1-theta)*dx(v)*dx(vh)
35 +mu*(1-theta)*dy(v)*dy(vh))
36 +int2d(Th)(mu*(theta)*dx(vold)*dx(vh)
37 +mu*(theta)*dy(vold)*dy(vh));
38 //
39 // Initializing
40 u = 1 + 0.5*cos(3*pi*x)*sin(3*pi*y); uold = u;
41 v = 1 + 0.5*sin(3*pi*x)*cos(3*pi*x); vold = v;
42 //
43 // Big loop in time
44 for (it=0; it<200; it++) {
45 for (int subit=0; subit<1; subit++){
72CHAPTER 7. CASE STUDY. POPULATION DYNAMICS AND MIGRATION FLUX ANALYSIS

46 t = t + dt;
47 // Fractional step method
48 // Step a. Solve the reaction system on ( dt /2)
49 u = u * exp(alpha*(v-1)*dt*0.25);
50 v = v * exp((1-u)*dt*0.5);
51 u = u * exp(alpha*(v-1)*dt*0.25);
52 uold = u; vold = v;
53 //
54 // Step b. Solve the diffusion system on ( dt )
55 heatu; uold = u;
56 heatv; vold = v;
57 //
58 // Step c . Solve the reaction system on ( dt /2)
59 u = u * exp(alpha*(v-1)*dt*0.25);
60 v = v * exp((1-u)*dt*0.5);
61 u = u * exp(alpha*(v-1)*dt*0.25);
62 uold = u; vold = v;
63 }
64 plot(u, nbiso=40, value=1, fill=0);//, ps="crd_u_it="+it+".eps");
65 plot(v, nbiso=40, value=1, fill=0);//, ps="crd_v_it="+it+".eps");
66 //
67 } // for it

IsoValue IsoValue
0.0692282 0.0783405
0.134109 0.240732
0.198989 0.403123
0.26387 0.565514
0.32875 0.727905
0.393631 0.890296
0.458511 1.05269
0.523392 1.21508
0.588272 1.37747
0.653152 1.53986
0.718033 1.70225
0.782913 1.86464
0.847794 2.02703
0.912674 2.18942
0.977555 2.35182
1.04244 2.51421
1.10732 2.6766
1.1722 2.83899
1.23708 3.00138
1.30196 3.16377
1.36684 3.32616
1.43172 3.48855
1.4966 3.65094
1.56148 3.81334
1.62636 3.97573
1.69124 4.13812
1.75612 4.30051
1.821 4.4629
1.88588 4.62529
1.95076 4.78768
2.01564 4.95007
2.08052 5.11246
2.1454 5.27485
2.21028 5.43725
2.27516 5.59964
2.34004 5.76203
2.40493 5.92442
2.46981 6.08681
2.53469 6.2492
2.59957 6.41159

IsoValue IsoValue
0.0422417 0.0183727
0.0996581 0.0551184
0.157075 0.091864
0.214491 0.12861
0.271907 0.165355
0.329324 0.202101
0.38674 0.238846
0.444156 0.275592
0.501573 0.312338
0.558989 0.349083
0.616406 0.385829
0.673822 0.422575
0.731238 0.45932
0.788655 0.496066
0.846071 0.532811
0.903488 0.569557
0.960904 0.606303
1.01832 0.643048
1.07574 0.679794
1.13315 0.716539
1.19057 0.753285
1.24799 0.790031
1.3054 0.826776
1.36282 0.863522
1.42024 0.900268
1.47765 0.937013
1.53507 0.973759
1.59248 1.0105
1.6499 1.04725
1.70732 1.084
1.76473 1.12074
1.82215 1.15749
1.87957 1.19423
1.93698 1.23098
1.9944 1.26772
2.05182 1.30447
2.10923 1.34121
2.16665 1.37796
2.22406 1.41471
2.28148 1.45145

Figure 7.3: Lokta-Volterra numerical solutions at some instants. Iso-contours of u (left) and v (right).
7.4. ADDING SEASONAL MIGRATION INTO THE MODEL 73

IsoValue IsoValue
0.0115869 0.0369259
0.0310976 0.110778
0.0506083 0.18463
0.070119 0.258481
0.0896297 0.332333
0.10914 0.406185
0.128651 0.480037
0.148162 0.553889
0.167672 0.627741
0.187183 0.701592
0.206694 0.775444
0.226205 0.849296
0.245715 0.923148
0.265226 0.997
0.284737 1.07085
0.304247 1.1447
0.323758 1.21856
0.343269 1.29241
0.362779 1.36626
0.38229 1.44011
0.401801 1.51396
0.421311 1.58781
0.440822 1.66167
0.460333 1.73552
0.479844 1.80937
0.499354 1.88322
0.518865 1.95707
0.538376 2.03093
0.557886 2.10478
0.577397 2.17863
0.596908 2.25248
0.616418 2.32633
0.635929 2.40018
0.65544 2.47404
0.67495 2.54789
0.694461 2.62174
0.713972 2.69559
0.733483 2.76944
0.752993 2.8433
0.772504 2.91715

IsoValue IsoValue
0.0233599 0.0236973
0.0695841 0.0710919
0.115808 0.118487
0.162032 0.165881
0.208256 0.213276
0.254481 0.26067
0.300705 0.308065
0.346929 0.35546
0.393153 0.402854
0.439377 0.450249
0.485601 0.497643
0.531825 0.545038
0.578049 0.592433
0.624273 0.639827
0.670498 0.687222
0.716722 0.734617
0.762946 0.782011
0.80917 0.829406
0.855394 0.8768
0.901618 0.924195
0.947842 0.97159
0.994066 1.01898
1.04029 1.06638
1.08651 1.11377
1.13274 1.16117
1.17896 1.20856
1.22519 1.25596
1.27141 1.30335
1.31764 1.35075
1.36386 1.39814
1.41008 1.44554
1.45631 1.49293
1.50253 1.54033
1.54876 1.58772
1.59498 1.63511
1.6412 1.68251
1.68743 1.7299
1.73365 1.7773
1.77988 1.82469
1.8261 1.87209

IsoValue IsoValue
0.0374151 0.0285637
0.112178 0.085691
0.186941 0.142818
0.261704 0.199946
0.336467 0.257073
0.41123 0.3142
0.485992 0.371328
0.560755 0.428455
0.635518 0.485583
0.710281 0.54271
0.785044 0.599837
0.859807 0.656965
0.93457 0.714092
1.00933 0.771219
1.0841 0.828347
1.15886 0.885474
1.23362 0.942601
1.30838 0.999729
1.38315 1.05686
1.45791 1.11398
1.53267 1.17111
1.60744 1.22824
1.6822 1.28537
1.75696 1.34249
1.83172 1.39962
1.90649 1.45675
1.98125 1.51388
2.05601 1.571
2.13078 1.62813
2.20554 1.68526
2.2803 1.74238
2.35506 1.79951
2.42983 1.85664
2.50459 1.91377
2.57935 1.97089
2.65412 2.02802
2.72888 2.08515
2.80364 2.14228
2.8784 2.1994
2.95317 2.25653

Figure 7.4: Lokta-Volterra numerical solutions at some instants. Iso-contours of u (left) and v (right).

7.4 Adding seasonal migration into the model

Preys usually migrate in order to find better places for food. In a seasonal migration, animals are
moving from north to south and vice-versa. This can be coarsely modeled by an independent time-
dependent vertical and periodic vector field

a(x, t) = (0, σ sin(ωt)) .

Then the equations of evolution of predator and prey density are

∂u
− ν∆u = α u(v − 1), (7.29)
∂t
∂v
+ a · ∇v − µ∆v = v(1 − u) (7.30)
∂t
74CHAPTER 7. CASE STUDY. POPULATION DYNAMICS AND MIGRATION FLUX ANALYSIS

In this case, the equation splitting can be on one side a transport-diffusion equation

∂u
− ν∆u = 0,
∂t
Dt v − µ∆v = 0,

with
Dt = ∂t + a · ∇,
and on the other side a (nonlinear) reaction equation

du
= αu(v − 1),
dt
dv
= v(1 − u).
dt
The implementation is also the same as in a previous case. Here a Lagrangian derivative Dt v has to
be discretized in a stable way, for example using the method of characteristics. In Freefem++ the
convect function can be used for example. Numerical results are performed with the parameters
ν = 5 10−4 , µ = 2 10−4 , ∆t = 0.08, σ = 0.4, ω = π and α = 0.5. The initial condition considered
in this simulation is
u0 (x) = 0.1, v 0 (x) = 1((x− 1 )2 +(y− 1 )2 ≤ 1 ) (x).
2 2 32

Periodic boundary conditions are used for the top and bottom borders while zero-flux boundary con-
ditions are used for both left and right borders.

From figures 7.5 to 7.6, isocontours of predator and prey densities at successive instants. One can ob-
serve the complex dynamics of the migration for both two populations, with moving regions of both
high and low density. Predators tend to "follow" preys during their seasonal migration.
7.4. ADDING SEASONAL MIGRATION INTO THE MODEL 75

IsoValue IsoValue
0.101949 0.108786
0.265466 0.327254
0.428984 0.545722
0.592502 0.764191
0.75602 0.982659
0.919538 1.20113
1.08306 1.4196
1.24657 1.63806
1.41009 1.85653
1.57361 2.075
1.73713 2.29347
1.90065 2.51194
2.06416 2.7304
2.22768 2.94887
2.3912 3.16734
2.55472 3.38581
2.71823 3.60428
2.88175 3.82275
3.04527 4.04121
3.20879 4.25968
3.37231 4.47815
3.53582 4.69662
3.69934 4.91509
3.86286 5.13355
4.02638 5.35202
4.1899 5.57049
4.35341 5.78896
4.51693 6.00743
4.68045 6.2259
4.84397 6.44436
5.00748 6.66283
5.171 6.8813
5.33452 7.09977
5.49804 7.31824
5.66156 7.53671
5.82507 7.75517
5.98859 7.97364
6.15211 8.19211
6.31563 8.41058
6.47915 8.62905

IsoValue IsoValue
0.0425492 0.0485705
0.119495 0.145835
0.196441 0.2431
0.273387 0.340365
0.350333 0.43763
0.427279 0.534895
0.504225 0.632159
0.581171 0.729424
0.658117 0.826689
0.735063 0.923954
0.812009 1.02122
0.888955 1.11848
0.965901 1.21575
1.04285 1.31301
1.11979 1.41028
1.19674 1.50754
1.27368 1.60481
1.35063 1.70207
1.42758 1.79934
1.50452 1.8966
1.58147 1.99387
1.65841 2.09113
1.73536 2.1884
1.81231 2.28566
1.88925 2.38293
1.9662 2.48019
2.04314 2.57746
2.12009 2.67472
2.19704 2.77199
2.27398 2.86925
2.35093 2.96651
2.42787 3.06378
2.50482 3.16104
2.58177 3.25831
2.65871 3.35557
2.73566 3.45284
2.8126 3.5501
2.88955 3.64737
2.9665 3.74463
3.04344 3.8419

IsoValue IsoValue
0.0310887 0.0561102
0.0916202 0.168338
0.152152 0.280567
0.212683 0.392795
0.273215 0.505023
0.333746 0.617251
0.394278 0.729479
0.454809 0.841707
0.515341 0.953935
0.575872 1.06616
0.636404 1.17839
0.696935 1.29062
0.757467 1.40285
0.817998 1.51508
0.87853 1.6273
0.939061 1.73953
0.999593 1.85176
1.06012 1.96399
1.12066 2.07622
1.18119 2.18845
1.24172 2.30067
1.30225 2.4129
1.36278 2.52513
1.42331 2.63736
1.48384 2.74959
1.54438 2.86181
1.60491 2.97404
1.66544 3.08627
1.72597 3.1985
1.7865 3.31073
1.84703 3.42295
1.90757 3.53518
1.9681 3.64741
2.02863 3.75964
2.08916 3.87187
2.14969 3.9841
2.21022 4.09632
2.27075 4.20855
2.33129 4.32078
2.39182 4.43301

IsoValue IsoValue
0.0927657 0.159169
0.277964 0.477394
0.463162 0.79562
0.648361 1.11385
0.833559 1.43207
1.01876 1.7503
1.20396 2.06852
1.38915 2.38675
1.57435 2.70497
1.75955 3.0232
1.94475 3.34142
2.12995 3.65965
2.31515 3.97787
2.50035 4.2961
2.68554 4.61432
2.87074 4.93255
3.05594 5.25078
3.24114 5.569
3.42634 5.88723
3.61154 6.20545
3.79673 6.52368
3.98193 6.8419
4.16713 7.16013
4.35233 7.47835
4.53753 7.79658
4.72273 8.1148
4.90792 8.43303
5.09312 8.75125
5.27832 9.06948
5.46352 9.38771
5.64872 9.70593
5.83392 10.0242
6.01911 10.3424
6.20431 10.6606
6.38951 10.9788
6.57471 11.2971
6.75991 11.6153
6.94511 11.9335
7.13031 12.2517
7.3155 12.57

Figure 7.5: Convection-Reaction-Diffusion prey-predator Lokta-Volterra numerical solutions at suc-


cessive instants. Iso-contours of predator density u (left) and prey density v (right).
76CHAPTER 7. CASE STUDY. POPULATION DYNAMICS AND MIGRATION FLUX ANALYSIS

IsoValue IsoValue
0.0595854 0.113418
0.178673 0.332782
0.29776 0.552146
0.416848 0.771511
0.535935 0.990875
0.655022 1.21024
0.77411 1.4296
0.893197 1.64897
1.01228 1.86833
1.13137 2.0877
1.25046 2.30706
1.36955 2.52642
1.48863 2.74579
1.60772 2.96515
1.72681 3.18452
1.8459 3.40388
1.96498 3.62325
2.08407 3.84261
2.20316 4.06197
2.32225 4.28134
2.44133 4.5007
2.56042 4.72007
2.67951 4.93943
2.7986 5.15879
2.91768 5.37816
3.03677 5.59752
3.15586 5.81689
3.27494 6.03625
3.39403 6.25562
3.51312 6.47498
3.63221 6.69434
3.75129 6.91371
3.87038 7.13307
3.98947 7.35244
4.10856 7.5718
4.22764 7.79117
4.34673 8.01053
4.46582 8.22989
4.58491 8.44926
4.70399 8.66862

IsoValue IsoValue
0.121182 0.102171
0.205362 0.29402
0.289543 0.485869
0.373724 0.677719
0.457905 0.869568
0.542086 1.06142
0.626267 1.25327
0.710448 1.44512
0.794629 1.63696
0.87881 1.82881
0.962991 2.02066
1.04717 2.21251
1.13135 2.40436
1.21553 2.59621
1.29971 2.78806
1.3839 2.97991
1.46808 3.17176
1.55226 3.36361
1.63644 3.55546
1.72062 3.74731
1.8048 3.93916
1.88898 4.131
1.97316 4.32285
2.05734 4.5147
2.14152 4.70655
2.2257 4.8984
2.30989 5.09025
2.39407 5.2821
2.47825 5.47395
2.56243 5.6658
2.64661 5.85765
2.73079 6.0495
2.81497 6.24135
2.89915 6.4332
2.98333 6.62504
3.06751 6.81689
3.15169 7.00874
3.23588 7.20059
3.32006 7.39244
3.40424 7.58429

IsoValue IsoValue
0.0733245 0.0810052
0.116889 0.181845
0.160453 0.282684
0.204017 0.383523
0.247582 0.484363
0.291146 0.585202
0.33471 0.686041
0.378275 0.786881
0.421839 0.88772
0.465403 0.98856
0.508968 1.0894
0.552532 1.19024
0.596096 1.29108
0.639661 1.39192
0.683225 1.49276
0.726789 1.5936
0.770354 1.69444
0.813918 1.79527
0.857482 1.89611
0.901047 1.99695
0.944611 2.09779
0.988175 2.19863
1.03174 2.29947
1.0753 2.40031
1.11887 2.50115
1.16243 2.60199
1.206 2.70283
1.24956 2.80367
1.29313 2.90451
1.33669 3.00535
1.38025 3.10619
1.42382 3.20703
1.46738 3.30787
1.51095 3.4087
1.55451 3.50954
1.59808 3.61038
1.64164 3.71122
1.6852 3.81206
1.72877 3.9129
1.77233 4.01374

IsoValue IsoValue
0.15004 0.182873
0.297992 0.424096
0.445945 0.665318
0.593897 0.90654
0.74185 1.14776
0.889802 1.38898
1.03775 1.63021
1.18571 1.87143
1.33366 2.11265
1.48161 2.35387
1.62956 2.5951
1.77752 2.83632
1.92547 3.07754
2.07342 3.31876
2.22137 3.55998
2.36933 3.80121
2.51728 4.04243
2.66523 4.28365
2.81318 4.52487
2.96114 4.7661
3.10909 5.00732
3.25704 5.24854
3.40499 5.48976
3.55294 5.73098
3.7009 5.97221
3.84885 6.21343
3.9968 6.45465
4.14475 6.69587
4.29271 6.9371
4.44066 7.17832
4.58861 7.41954
4.73656 7.66076
4.88452 7.90198
5.03247 8.14321
5.18042 8.38443
5.32837 8.62565
5.47633 8.86687
5.62428 9.1081
5.77223 9.34932
5.92018 9.59054

Figure 7.6: Convection-Reaction-Diffusion prey-predator Lokta-Volterra numerical solutions at suc-


cessive instants. Iso-contours of predator density u (left) and prey density v (right).
Chapter 8

Model of biological spatial pigment


pattern formation

During the development of an embryo, there is a rapid growth, not only in cell numbers, but also in
specialization and complex organization among cells. Cells in the vertebrate embryo divide, migrate,
differentiate and for the various organs of the body. Many of the structures have a regular pattern such
as the vertebrae in the spine, the pattern of feather, etc.

Pigment patterns are generated by chromatophore cells which lie in the dermal or epidermal layers
of the skin. There are several types of chromatophores each containing different pigments; the most
common are melanin-bearing cells and melanophores which contain black, brown or yellow pigments.
During development, pigment cell precursors - chromatoblasts - originate in the neural crest. These
cells spread over the skin at a roughly uniform density. Whether or not the skin develops a pigmented
patch depends on whether pigment cells produce pigment or remain quiescent. chromatophore inter-
actions may result in pigmented cells and unpigmented cells gathering in different regions to produce
stripes or spots.

The principle mathematical models for pigmentation to date have been mainly reaction-diffusion mod-
els, pioneered in the 1980s. These models hypothesize the existence of chemicals (morphogens) which
react and diffuse and, under appropriate conditions, generate spatially heterogeneous patterns. This
chemical landscape is viewed as a pre-pattern to which cells then respond in some genetically prede-
termined way and differentiate accordingly.

Oster and Murray (1989, []) proposed a simple cell-chemotaxis model for pattern formation which
takes account of cell motility and chemotaxis, the chemical process by which cells migrate up a chem-
ical gradient. Some of the developments of this chapter are pioneered by Maini et al. [] who have
established that a cell-chemotaxis model can produce a wide variety of observed patterns.

8.1 Cell chemotaxis model


The model mechanism involves the cell density, ρ(x, t) and chemo-attractant concentration c(x, t),
where x and t are the spatial coordinate and time respectively, and consists of equations which describe
their motion and net production. The general form of the cell equation is the conservative balance

77
78 CHAPTER 8. MODEL OF BIOLOGICAL SPATIAL PIGMENT PATTERN FORMATION

equation
∂ρ
+ ∇ · Jρ = R(ρ) (8.1)
∂t
where Jρ is the flux of cells and R(ρ) is the local net cell production. From biological considerations,
it is assumed that there is two contributions to the flux term, namely a random Fickian diffusion
process with diffusive flux
J d = −Dρ ∇ρ (8.2)
where Dρ is the diffusion coefficient, and chemotaxis with chemotactic flux

J c = αρ∇c (8.3)

where α is the chemotaxis coefficient. Remark that J c is a nonlinear term. We take the cell production
term to be adequately described by logistic growth of the form R(ρ) = rρ(ρ∞ − ρ) where rρ∞ is
the linear mitotic growth rate with r and ρ∞ both nonnegative constants. The logistic growth rate is
the simplest way to describe the characteristic sigmoidal growth exhibited by several cell types. As
summary, the equation for cell density is
∂ρ
+ α∇ · (ρ∇c) − Dρ ∆ρ = rρ(ρ∞ − ρ). (8.4)
∂t
It is a nonlinear convection-reaction-diffusion equation. We assume that the cell secretes its own
chemoattractant according to a growth rate in the form

β+ρ
It is also supposed to diffuse with diffusion coefficient Dc and to linearly degrade (apoptosis) at a rate
γc. The equation for chemotactic concentration c is then
∂c Sρ
− Dc ∆c = − γc (8.5)
∂t β+ρ
with positive constants S, β and γ. Equation (8.4) and (8.5) form a coupled system of nonlinear partial
differential equations.

8.1.1 Dimensionless equations


To reduce the number of parameters, it is usual to write the model in non-dimensional terms. For any
quantity q, let us denote by q0 a dimensional constant and the non-dimensional quantity q̄ defined as
q
q̄ = .
q0
By denoting ∇¯ and ∆¯ respectively the gradient and the Laplace operator with respect to the non-
dimensional space variable x̄, the non-dimensional equations write
ρ0 ∂ ρ̄ αρ0 c0 ¯
+ ¯ − Dρ ∆ρ̄
α∇ · (ρ̄∇c̄) ¯ = r(ρ0 )2 ρ̄( ρ∞ − ρ̄)
t0 ∂ t̄ (x0 ) 2 (x0 ) 2 ρ0
and
c0 ∂c̄ c0 ¯ = Sρ0 ρ̄
− Dc ∆c̄ − γc0 c̄.
t0 ∂ t̄ (x0 ) 2 β 1 + ρβ0 ρ̄
8.2. ZERO-DIMENSIONAL MODEL 79

Introducing a scaling factor s, the following choice


s
Dc s s S
x0 = , t0 = , ρ0 = β, c0 = ,
γ γ γ

gives the non-dimensional equations become (omiting the bar symbols for the sake of simplicity)
∂ρ
+ α∇ · (ρ∇c) − D∆ρ = srρ(ρ∞ − ρ), (8.6)
∂t
 
∂c ρ
− ∆c = s −c . (8.7)
∂t 1+ρ
For simplicity, the spatial domain Ω is supposed to be a rectangle of respective lengths Lx and Ly .
Moreover we consider zero flux boundary conditions, meaning that no cell or chemoattractant migrates
through the boundary:
∇ρ · n = ∇c · n = 0, x ∈ ∂Ω. (8.8)

8.2 Zero-dimensional model


Forgetting the spatial terms, the so-called 0-dimensional model is

= srρ(ρ∞ − ρ), (8.9)
dt
 
dc ρ
=s −c . (8.10)
dt 1+ρ
ρ∞
There are two equilibrium states (ρ, c) = (0, 0) and (ρ, c) = (ρ∞ , 1+ρ ∞
). To know wether those
equilibrium states are stable or unstable, one linearizes the dynamical system in the vicinity of the
equilibrium. For (ρ, c) small enough, the system is equivalent to
!  !
ρ ρ

d srρ∞ 0
= .
dt c s −s c
There are two real eigenvalues for the linearized system, one of them is positive so that the equilibrium
ρ∞
state is unstable. For the second equilibrium (ρ, c) = (ρ∞ , 1+ρ ∞
), using the new variables ρ′ =
ρ
ρ − ρ∞ , c′ = c − 1+ρ∞∞ , for (ρ′ , c′ ) small enough, the system is equivalent to the linearized one

ρ′ ρ′
! ! !
d −srρ∞ 0
= s .
dt c′ (1+ρ∞ )2
−s c′
According to the sign of the two eigenvalues, the second equilibrium state is stable.

8.3 Linear stability analysis of the complete model


Now we carry out the analysis of the system (8.6),(8.7). It is easy to check that the constant steady-
states of (8.6),(8.7) are the equilibrium states of the dynamical system (8.9),(8.10). The steady-
state (0, 0) is always unstable by inspection so we only consider the non-zero steady state (ρ, c) =
80 CHAPTER 8. MODEL OF BIOLOGICAL SPATIAL PIGMENT PATTERN FORMATION

ρ∞
(ρ∞ , 1+ρ ∞
) here.
ρ∞
We set ρ = ρ∞ + u and c = 1+ρ∞ + v where |u|, |v| are small, substitute into (8.6)-(8.8) and only
retain linear terms. This gives the PDE problem of linear partial differential equations which governs
the behaviour near the steady state:

∂t u − D∆u + αρ∞ ∆v = −rsρ∞ u in Ω, (8.11)


 
u
∂t v − ∆v = s −v in Ω, (8.12)
(1 + ρ∞ )2
n · ∇u = n · ∇v = 0 on ∂Ω. (8.13)

We look for planar wave solutions of (8.11)-(8.13) i.e. solutions in the form
! !
u u0
= exp(ik · x + λt) (8.14)
v v0

where λ = λ(k) determines the temporal growth rate of the disturbance with wave vector k. Let us
denote k = |k|. Putting (8.14) into (8.11),(8.12) gives

λu + Dk 2 u + αρ∞ k 2 v = −rρ∞ su,


 
u
λv + k 2 v = s − v .
(1 + ρ∞ )2
These inequalities have to be satisfied for x and any t. Then we have the compatibility linear system

Dk 2 − rρ∞ s αρ∞ k 2 v
! ! !
u0 u0
s
= −λ
(1+ρ∞ )2
k2 + s v0 v0

This is an eigenvalue problem. Non-trivial solutions for u0 and v0 exist only if λ, the dispersion
relation satisfies the characteristic polynomial
   
2 2 4 sρ∞ α 2 2
λ + [(D + 1)k + rρ∞ + s] λ + Dk + rρ∞ s + Ds − k + rρ∞ s = 0. (8.15)
(1 + ρ∞ )2
Moreover, the wave with wavenumber |k| must satisfy the boundary conditions (8.13). Denoting
k = (kx , ky ), we get the compatibility conditions
mπ ℓπ
kx = , ky = , m, ℓ ∈ N.
Lx Ly

The linear spatial eigenmodes then are cos mπx/Lx cos ℓπy/Ly . In (8.15), λ = λ(k 2 ) clearly depends
on k 2 . If λ(k 2 ) < 0, then a disturbance of wavevector k will decay in time. If λ(k 2 ) > 0 for some
k 2 then the disturbance with wavenumbers will grow and the system will evolve to a nonuniform
spatially structured solution. On the rectangular domain [0, Lx ] × [0, Ly ], the values of k 2 which
produce a pattern are those where λ(k 2 ) > 0 with
 2
ℓ2

2 2 m
k =k·k =π + 2 . (8.16)
L2x Ly
8.4. NUMERICAL DISCRETIZATION 81

The critical value occur when λ(k 2 ) = 0, that is when k satisfies


 
4 sρ∞ α
Dk + rρ∞ s + Ds − k 2 + rρ∞ s2 = 0. (8.17)
(1 + ρ∞ )2

In order to find at least one unstable mode, we require equation (8.17) to have only one double root
solution for k 2 , so we further impose the condition for equal roots, namely
 2
sρ∞ α
rρ∞ s + Ds − − 4Drρ∞ s2 = 0. (8.18)
(1 + ρ∞ )2

Hence the modulus of the critical wave vector is given by



2s Drρ∞  rρ 1/2

kc2 = =s . (8.19)
2D D

By choosing D, s, r and N appropriately, we can find a k 2 from (8.16) which satisfies equation (8.19),
and then solve equation (8.18) for α (one can take the larger root for α so that kc2 is positive). This
determines the point in (ρ∞ , D, r, s, α) parameter space where the mode (8.19) is isolated.

8.3.1 Continuous variation of a single parameter


From equations (8.17)-(8.19), it is clear that by making appropriately vary any of the five parameters
r, ρ∞ , s, D or α, the uniform steady state can evolve to a non-uniform steady-state. The chemotaxis
parameter α is a key parameter so one can fix the others and make vary α to locate bifurcations in α
and follow the corresponding solutions.

8.4 Numerical discretization


The problem is hard to solve because of strongly nonlinear terms and important convective effects.
Recall the equation of cell density

∂t ρ + ∇ · (αρ∇c) − D∆ρ = srρ(ρ∞ − ρ). (8.20)

First, let us emphasize the convection term. By denoting

u = α∇c, (8.21)

the cell density equation can be rewritten

Dt ρ + αρ∆c − D∆ρ = srρ(ρ∞ − ρ) (8.22)

where Dt denotes the particle derivative

Dt = ∂t + u · ∇. (8.23)
82 CHAPTER 8. MODEL OF BIOLOGICAL SPATIAL PIGMENT PATTERN FORMATION

8.4.1 Fractional step method


The term αρδc is not easy to treat because of its nonconservative form and nonlinear nature. Thus
it is appropriate to consider here a fractional step method. A fractional step method allows us to
successively deal with each term of an operator in an ODE or a PDE. Consequently, a time step is a
multi-step process made of several steps that “solve” each part of the equation treated separately. For
equation (8.20), it is convenient first to solve

Dt ρ − D∆ρ = srρ(ρ∞ − ρ) (8.24)

which only depends on c by means of Dt , then solve the system

∂r ρ + αρ∆c = 0, (8.25)
 
ρ
∂t c − ∆c = s −c . (8.26)
1+ρ
Remark that equation (8.25) can be rewritten in conservation form

∂t σ + α∆c = 0 (8.27)

with σ = log(ρ). A semi-discretization in time gives the following scheme:


1. Solve the semi-implicit linear scheme in ρ⋆ :
ρ⋆ − ρn ◦ X n
− D∆ρ⋆ = srρn (ρ∞ − ρ⋆ ) (8.28)
∆tn
with boundary conditions
∂ρ⋆
= 0. (8.29)
∂n
The function ρ⋆ will serve as “initial data” of cell density for the next step:

2. Solve the following linear problem (σ ⋆ = log(ρ⋆ )):

σ n+1 − σ ⋆
+ α∆cn+1 = 0 in Ω, (8.30)
∆tn
∂σ n+1
=0 on ∂Ω, (8.31)
∂n
cn+1 − cn ρ⋆
 
− ∆cn+1 = s − cn+1 in Ω, (8.32)
∆tn 1 + ρ⋆
∂cn+1
=0 on ∂Ω, (8.33)
∂n
then compute
ρn+1 = exp(σ n+1 ) (8.34)
to end the time iteration tn → tn+1 .
Of course, the global time advance scheme is not fully implicit and thus may not be unconditionally
stable.
8.4. NUMERICAL DISCRETIZATION 83

8.4.2 Full discretization


The full discretization of the problem will correspond to Finite Element space discretization of the
semi-discretized scheme (8.28)-(8.33).

1. The variational formulation of (8.28),(8.29) leads to


ρ⋆ − ρn ◦ X n h
Z Z Z
⋆ h
n
v dx + D∇ρ · ∇v dx = sr ρn (ρ∞ − ρ⋆ ) v h dx ∀v h ∈ V h .
Ω h ∆t Ω h Ω h
(8.35)
Once ρ⋆ ∈ V h is computed by (8.35) then compute
h
σ ⋆ = P W (log(ρ⋆ )) (8.36)

as the projection on the σ-Finite Element space of the field log(ρ⋆ ).

2. The variational formulation of (8.30)-(8.33) leads to

σ n+1 − σ ⋆ h
Z Z
n
σ dx − α∇cn+1 · ∇σ h dx
Ω h ∆t Ω h

n+1 n Z  ⋆ 
c −c h ρ
Z Z
n+1 h n+1
+ n
c dx + ∇c · ∇c dx − s ⋆
−c ch dx = 0
Ω h ∆t Ω h Ω h 1 + ρ

∀σ h ∈ W h , ch ∈ X h . (8.37)

To finish, let compute


h
ρn+1 = P V (exp(σ n+1 )) (8.38)
as the projection on V h of the field exp(σ n+1 ).

To completely define the numerical method, we have to choose some convenient Finite Element
spaces. The classical P 1 is convenient for both ρ and σ. However, for c the P 2 Finite Element
space is preferable because we need to compute the convective vector field

u = α∇c

from c. If c is piecewise P 2 in a triangle, then ∇c will be piecewise P 1 .

8.4.3 freefem++ source code of the numerical scheme and numerical results

1 // Chemotaxis.edp ( freefem++)
2 // Chemotaxis model for biological pattern generation
3 //
4 // Parameter definition
5 real r = 38.05;
6 real alpha = 285;
7 real rhoinf =1;
8 real D = 0.25;
9 real s = 1;
10 real Lx = 3.5;
11 real Ly = 4;
84 CHAPTER 8. MODEL OF BIOLOGICAL SPATIAL PIGMENT PATTERN FORMATION

12 real dt = 0.05;
13 //
14 mesh Th=square(40, 40, [Lx*x, Ly*y]);
15 plot(Th, wait=0);
16 fespace Vh(Th, P1);
17 Vh rho, rhoold, rhotest, u1, u2, output;
18 Vh sigma, sigmaold, sigmatest;
19 fespace Wh(Th, P2);
20 Wh c, cold, ctest;
21 // Starting from the ( unstable ) constant state
22 rho = rhoinf;
23 rhoold=rho;
24 c = rhoinf/(1+rhoinf);
25 cold=c;
26 u1 = alpha * dx(c);
27 u2 = alpha * dy(c);
28 // Then go to the PDE problem
29 problem step1(rho, rhotest) =
30 int2d(Th)(rho*rhotest /dt)
31 -int2d(Th)( convect([u1,u2], -dt, rhoold)*rhotest /dt)
32 +int2d(Th)(D*dx(rho)*dx(rhotest)+D*dy(rho)*dy(rhotest))
33 -int2d(Th)(r*s*rhoold*rhoinf*rhotest)
34 +int2d(Th)(r*s*rhoold*rho*rhotest);
35
36 problem step2([sigma, c], [sigmatest, ctest]) =
37 int2d(Th)( sigma*sigmatest /dt)
38 -int2d(Th)( sigmaold*sigmatest /dt)
39 -int2d(Th)(alpha*dx(c)*dx(sigmatest)+alpha*dy(c)*dy(sigmatest))
40 +int2d(Th)(c*ctest /dt)
41 - int2d(Th)(cold*ctest /dt)
42 +int2d(Th)(dx(c)*dx(ctest) + dy(c)*dy(ctest))
43 -int2d(Th)(s*rho/(1+rho)*ctest)
44 +int2d(Th)(s*c*ctest);
45
46 for (int it=0; it<200; it++) {
47 cout << "it = " << it << endl;
48 // Step 1
49 step1;
50 rhoold = rho;
51 sigmaold = log(rhoold);
52 //
53 step2;
54 u1 = alpha * dx(c);
55 u2 = alpha * dy(c);
56 rho = exp(sigma);
57 rhoold = rho;
58 cold = c;
59 //
60 // plot (c , nbiso=60, value=1, wait=0);
61 plot( rho , nbiso=40, grey=1, fill=1, value=1, wait=0);
62 }
63 cout << "cmin = " << c[].min << " cmax = " << c[].max << endl;
8.4. NUMERICAL DISCRETIZATION 85

64 cout << "rhomin = " << rho[].min << " rhomax = " << rho[].max << endl;
65 //
66 plot( rho, nbiso=60, grey=1, fill=1, value=0, wait=0, ps="rho.eps");
67 plot(c , nbiso=60, grey=1, fill=1, value=0, wait=0, ps="c.eps");

Figure 8.1: Isocontours of cell density (left) and chemoattractant concentration (right) in grey colors.
The parameter alpha used here is α = 285. Stable steady state starting from the constant unstable
steady state.

Figure 8.2: Isocontours of cell density (left) and chemoattractant concentration (right) in grey colors.
The parameter alpha used here is α = 305. Stable steady state starting from the constant unstable
steady state.
86 CHAPTER 8. MODEL OF BIOLOGICAL SPATIAL PIGMENT PATTERN FORMATION
Chapter 9

Vehicle traffic flow modeling

9.1 Setting of the problem


Although vehicle traffic flow is intrinsically a discrete dynamical process, it is possible to model it
continuously at a certain level of description. If we are looking at a highway quite war from it, the
flow can seen as a continuous flow with respect to macroscopic quantities like density ρ and flow rate
q. Let us denote S = [x− , x+ ] a bounded road section. Then the evolution of the quantity of vehicle
on that section is governed by the gain-loss equation
dS
= q(x− , t) − q(x+ , t). (9.1)
dt
By introducing a vehicle density ρ = ρ(x, t) and assuming a continuously varying flow rate, then (9.58)
can write
d ∂q
Z Z
ρ(x, t) dx + = 0. (9.2)
dt S S ∂s
This balance equation holds for any road section S. Then for an infinitesimal road section S with
|S| → 0, one gets almost everywhere the conservation equation

∂t ρ + ∂x q = 0. (9.3)

The class of partial differential equation (9.3) was introduced in the 1930s by Whitham. Today, the
so-called Whitham first-order models are still used in transportation engineering, especially for traffic
forecast and travel time estimation.

A closure is required for equation (9.3), in order to link density and flow rate. First, due to the
dimension of q, it is natural to consider a flow rate as a vehicle mean velocity times the vehicle
density:
q = ρu. (9.4)
Now the closure is then transfered onto the speed u. For a free highway with only few vehicles, it is
natural to consider that the vehicle speed is the free speed uf fixed by speed limitation. On the other
hand, a car is “stopped” in a fully jammed lane of maximum critical density ρc , so its velocity can be
considered as zero. For intermediate velocities, one can consider as first approximation a linear law
 
ρ
u = u(ρ) = uf 1 − . (9.5)
ρc

87
88 CHAPTER 9. VEHICLE TRAFFIC FLOW MODELING

The equation (9.5) is referred to as the fundamental diagram in the traffic theory. It appears that the
fundamental law (9.5) is a rather good approximation of the reality. Statistics performed on real traffic
measurements show that real data plotted in the density-velocity or density-occupancy state space
can be linearly regressed as in (9.5). Remark that the function ρ 7→ q(ρ) = ρu(ρ) is parabolic (see
figure 9.8) with maximum flow rate
1
q M = ρc u f (9.6)
4
at density ρ = ρc /2. We fall into a nonlinear partial differential equation in the form

Figure 9.1: Fundamental diagram of traffic

∂t ρ + ∂x (ρ u(ρ)) = 0 (9.7)

with u(ρ) given by (9.5).

9.2 Some mathematical aspects of nonlinear transport equations


Although (9.5) has a rather simple script, its mathematical analysis is not so easy and requires atten-
tion. In particular, we are going to see that solutions of equations (9.7) can develop discontinuities
(also name shocks) during time, even if the initial data is smooth. When discontinuities exists, equa-
tion (9.7) is read in a weak sense, i.e. in the sense of distributions.
For smooth solutions, equation (9.7) can be written in nonconservative form. Denoting a(ρ) =
q ′ (ρ), it is equivalent to the nonlinear transport equation

∂t ρ + a(ρ)∂x ρ = 0 (9.8)

where the characteristic velocity a(ρ) depends itself on ρ. In the case of (9.5), we have
 
ρ
a(ρ) = uf 1 − 2
ρc
which is different from the vehicle velocity. It is important to understand the difference between
the vehicle velocity and the characteristic velocity. If we have a Lagrangian description of the flow,
meaning there are (vehicle) particles flowing with differential equation for the vehicle position
dx
= u(ρ(x(t), t)).
dt
9.2. SOME MATHEMATICAL ASPECTS OF NONLINEAR TRANSPORT EQUATIONS 89

Now consider the characteristic velocity a(ρ) = q ′ (ρ). Suppose a density solution in the form

ρ(x, t) = ρ0 + ερ1 (x, t) (9.9)

for a constant ρ0 and a small parameter 0 < ε ≪ 1, meaning that the density is almost constant up to
a perturbation ερ1 (x, t). Introducing expression (9.9) into (9.8) gives
 
da
∂t (ρ0 + ερ1 ) + a(ρ0 ) + ε (ρ0 )ρ1 ∂x (ρ0 + ερ1 ) = 0.

Then, homogeneous terms of degree 1 in ε give the linearized equation

∂t ρ1 + a(ρ0 )∂x ρ1 = 0. (9.10)

Equation (9.10) shows that the fluctuations of the solutions are propagating at characteristic veloc-
ity a(ρ0 ) but not u(ρ0 ). The characteristic velocity is the speed of propagation of the information
whereas the vehicle velocity is the material velocity.

9.2.1 Smooth autosimilar solutions


In this section, we are looking for continuous solutions of the variable ξ = x/t, i.e.
x
ρ(x, t) = φ( ). (9.11)
t
Putting (9.11) into (9.8) gives the differential equation
x ′ x x 1 x
− 2
φ ( ) + a(φ( )) φ′ ( ) = 0
t t t t t
or again
x
(a(φ(ξ) − ξ)) φ′ (ξ) = 0, ξ= . (9.12)
t
To (9.12), we will add the “initial condition”

ρ = ρL at point ξ = ξL (9.13)

(L means “left” for reasons that will appear later). There are different kinds of solutions for (9.12),(9.13).
Either φ′ (ξ) = 0 and thus Φ(ξ) is locally constant. Or Φ′ (ξ) 6= 0 and we have the solution

ξ = a(φ(ξ)). (9.14)

In the case of (9.5), we have  


ρ
a(ρ) = uf 1−2 (9.15)
ρc
and thus from (9.14)  
ρc ξ
φ(ξ) = 1− . (9.16)
2 uf
This gives the compatibility condition between ρL and ξL :
 
ρc ξL
ρL = 1− .
2 uf
90 CHAPTER 9. VEHICLE TRAFFIC FLOW MODELING

For example, the function in figure 9.9 in the (x, t) half plane plotted with characteristics is solution
of the equation (9.12). The ξ-varying part of the solution is delimited by two constant states ρL and
ρR . Such a solution is called a rarefaction wave or a rarefaction fan. Because of
Z ξR
φ(ξR ) − φ(ξL ) = φ′ (ξ) dξ,
ξL

we have the compatibility condition


ρc
ρR − ρL = − (ξR − ξL ). (9.17)
2uf
For ξR > ξL , we have ρR < ρL . The flow indeed tends to rarefy with accelerating vehicles within the
fan.

Figure 9.2: A rarefaction fan, autosimilar solution of the traffic equation.

9.2.2 Shock wave discontinuous solution


We are now looking for solutions in the form

ρ(x, t) = φ(x − σt). (9.18)

The quantity σ is a wave propagation velocity. Putting the expression (9.18) into (9.7) gives
d
− σφ′ (ξ) + [q(φ(ξ))] = 0, ξ = x − σt. (9.19)

In order to consider discontinuous functions φ, we write a weak formulation of (9.19). Let ξ 7→ v(ξ)
a compactly supported smooth function. Then, using an integration by parts, we can write for any
ξ ∈ R,
Z ξ Z ξ
′ d
0 = −σ v(s)φ (s) ds + v(s) [q(φ(s))] ds
−∞ −∞ dξ
Z ξ Z ξ
ξ ′ ξ
= −[σv(s)φ(s)]∞ + σ v (s)φ(s) ds + [v(s)q(φ(s))]−∞ − v ′ (s)q(φ(s)) ds
−∞ −∞
Z ξ Z ξ
= v(ξ) (−σφ(ξ) + q(φ(ξ))) + σ v ′ (s)φ(s) ds − v ′ (s)q(φ(s)) ds. (9.20)
−∞ −∞
9.2. SOME MATHEMATICAL ASPECTS OF NONLINEAR TRANSPORT EQUATIONS 91

Now consider a discontinuous weak solution in the form

Φ(ξ) = ρL + (ρR − ρL ) H(ξ) (9.21)

where ρL and ρR and two constant states and H(x) = 1(x≥0) (x) denotes the Heaviside function. Let
v be a compactly supported function whose support includes the origin. From the weak formulation
we get
Z 0 Z 0
− − ′
v ′ (s)q(φ(s)) ds = 0.

v(0) −σφ(0 ) + q(φ(0 )) + σ v (s)φ(s) ds − (9.22)
−∞ −∞

In a similar way, integrating from ξ = 0 to +∞ gives


Z ∞ Z ∞
+ + ′
v ′ (s)q(φ(s)) ds = 0.

− v(0) −σφ(0 ) + q(φ(0 )) + σ v (s)φ(s) ds − (9.23)
0 0

Because we have also


Z Z

−σ v (s)φ(s) ds + v ′ (s)q(φ(s)) ds = 0, (9.24)
R R

summing up (9.22), (9.23) and (9.24) gives the relations

v(0) −σ(φ(0+ ) − φ(0− )) + q(φ(0+ )) − q(φ(0− )) = 0 ∀v ∈ D(R).




One obtains the well-known Rankine-Hugoniot jump compatibility conditions

σ(ρR − ρL ) = q(ρR ) − q(ρL ) (9.25)

often written
σ |[ρ]| = |[q(ρ)]|. (9.26)

Remark that due to the parabolic form of q, one can have q(ρL ) = q(ρR ) for ρL 6= ρR . In that case,

Figure 9.3: A discontinuous shock wave solution. Through the discontinuity, we must satisfy the
Rankine-Hugoniot jump compatibility conditions.

the Rankine-Hugoniot relations give σ = 0. In other words, stationary shock waves do exist.
92 CHAPTER 9. VEHICLE TRAFFIC FLOW MODELING

9.3 Transport equation of a vehicle fraction


There are different kinds of vehicles on a road: car, trucks, motobikes. It can be interesting to track
a particular category to known the behavior among all the vehicles. Sometimes, vehicles are forming
some platoons and one can be interested in knowing and following the concentration of the platoons.
If c denotes the concentration of vehicle of interest, the quantity (ρc) refers to the partial density of
vehicles of interest. If there is no distinction of velocity between all the kinds of vehicles, we have of
course the conservation law
∂t (ρc) + ∂x (ρc u(ρ)) = 0. (9.27)
For solutions of class C 1 , equation (9.27) can be expanded as

ρ {∂t c + u(ρ)∂c } + c {∂t ρ + ∂x (ρu(ρ))} = 0.

Thus we get the transport equation on the concentration c:

∂t c + u(ρ) ∂x c = 0. (9.28)

9.4 System of conservation laws


The continuity equation (9.8) combined with the conservation law (9.27) form a system of conserva-
tion laws
∂t U + ∂x F (U ) = 0 (9.29)
with vector state U = (ρ, ρc) and vector flux F (U ) = (ρ u(ρ), ρc u(ρ)). For smooth solution, it can
be written in nonconservation form

∂t U + A(U )∂x U = 0 (9.30)

where A(U ) = DU F (U ) is the Jacobian matrix of the flux. It is easy to check that
∂ρcu(ρ) ∂(ρcu(ρ))
= ρc u′ (ρ), = u(ρ).
∂ρ ∂(ρc)
Thus A(U ) is equal to !
a(ρ) 0
A(U ) = (9.31)
ρc u′ (ρ) u(ρ)
where a(ρ) = q ′ (ρ) = u(ρ) + ρu′ (ρ). If u′ (ρ) = 0, then A(U ) is in diagonal form and u(ρ) is an
eigenvalue of multiplicity 2. Otherwise if u′ (ρ) 6= 0, then A(U ) has two distinct eigenvalues a(ρ) and
u(ρ) so that A(U ) is diagonalizable in R. A system in the form (9.29) such that the Jacobian matrix
is diagonalizable in R is called a hyperbolic system of conservation laws. The eigenvalues of the
Jacobian matrix define the characteristic velocities of the system. Here, we have λ1 (U ) = a(ρ) and
λ2 (U ) = u(ρ). The first eigenvector is equal to r1 (U ) = (1, c) and the second one is r2 (U ) = (0, 1).

Denoting by R(U ) the eigenvector matrix, i.e. R(U ) = col(r1 (U ), r2 (U )) and

Λ(U ) = diag(λ1 (U ), λ2 (U )),

we have
A(U ) = R(U )Λ(U )R−1 (U ). (9.32)
9.5. FINITE DIFFERENCE METHODS FOR NONLINEAR TRANSPORT EQUATIONS 93

9.5 Finite difference methods for nonlinear transport equations


Here, we need to design both robust and stable numerical methods, able to converge to (possibly) dis-
continuous weak solutions. In Chapter 2, we have introduced the upwind scheme for linear transport
equations. A good candidate here would be extend the upwind conservative schemes to the case of
nonlinear transport equations.
For that, we are going to locally linearize the traffic equation at each computational cell inter-
face. Let consider a uniform spatial discretization with nodes xj = jh, j ∈ Z and cells Ij =
(xj−1/2 , xj+1/2 ), xj+1/2 = (j + 1/2)h. If on the interval (xj , xj+1 ), between instants tn and tn+1
the traffic equation is linearized into
∂t ρ + anj+1/2 ∂x ρ = 0, x ∈ (xj , xj+1 ), t ∈ (tn , tn+1 ), (9.33)
for some mean propagation velocity, then the upwind scheme naturally writes
∆tn  n 
ρn+1
j = ρ n
j − (a j−1/2 ) + n
(ρj − ρ n
j−1 ) + (a n
j+1/2 ) − n
(ρ j+1 − ρn
j ) (9.34)
h
with the notation x+ = max(x, 0) and x− = min(x, 0). Unfortunately, the nonlinear upwind
scheme (9.34) is not in conservation form, making its irrelevant in most cases for discontinuous solu-
tions with incapability to correctly predict the shock propagation velocity at the discrete level. There
is only a particular choice where the upwind scheme (9.34) can be written in conservation form. The
following theorem enlightens the right choice of averages:
Theorem 4. If the average anj+1/2 is chosen such that
n n n

 a(ρj ) if ρj = ρj+1 ,

anj+1/2 = q(ρnj+1 ) − q(ρnj ) (9.35)
 otherwise.
ρnj+1 − ρnj

then the upwind scheme (9.34) has the conservative form


∆tn  n 
ρn+1
j = ρ n
j − Φ j+1/2 − Φ n
j−1/2 (9.36)
h
with consistent numerical flux
q(ρnj ) + q(ρnj+1 ) 1 n
Φnj+1/2 = − |aj+1/2 | (ρnj+1 − ρnj ). (9.37)
2 2
The average in (9.35) is called a Roe average and the numerical scheme (9.37) is called the Roe
scheme. The Roe scheme has ℓ1 , ℓ2 and ℓ∞ stability properties under the Courant-Friedrichs-Lewy
condition (CFL condition)
∆tn
sup |an | ≤ 1. (9.38)
h j∈Z j+1/2
The proof is let to the reader as exercise. Remark that the Roe average formula can be put in mirror
with the Rankine-Hugoniot jump conditions. Indeed from (9.35) we have
anj+1/2 (ρnj+1 − ρnj ) = q(ρnj+1 ) − q(ρnj ).
All happens as if the linearized problem were adapt its local propagation velocity to a shock wave
velocity and as if all the waves were replaced by shock waves in the linearized problem.
94 CHAPTER 9. VEHICLE TRAFFIC FLOW MODELING

9.5.1 Nonlinear extension of the Lax-Wendroff scheme


As in the linear case, it appears that the Roe scheme is only first order accurate. It is natural to look for
a second order accurate conservative scheme. To reach second order accuracy in time, we start from
the Taylor expansion
(∆tn )2 2
ρ(xj , tn+1 ) = ρ(xj , tn ) + ∆tn ∂t ρ(xj , tn ) + ∂tt ρ(xj , tn ) + O((∆tn )3 ), (9.39)
2
Time partial derivatives are then replaced by spatial derivatives:
2 2
q(ρ) = −∂x (a(ρ)∂t ρ) = ∂x a2 (ρ)∂x ρ

∂t ρ = −∂x q(ρ), ∂tt ρ = −∂xt

Thus,
ρ(xj , tn+1 ) − ρ(xj , tn ) ∆tn
∂x a2 (ρ)∂x ρ (xj , tn ) = ∂t ρ(xj , tn ) + O((∆tn )2 ).

n
− (9.40)
∆t 2
The following spatial discretization for the second term still preserves the second order accuracy
n 2 n n n 2 n n
ρn+1
j − ρnj ∆tn (aj+1/2 ) (ρj+1 − ρj ) − (aj−1/2 ) (ρj − ρj−1 )
− ≈ ∂t ρ(xj , tn ) (9.41)
∆tn 2 h2
where anj+1/2 is a second order accurate approximation of a(xj+1/2 , tn ). For spatial derivatives, a
centered formula is simply used:
q(ρnj+1 ) − q(ρnj−1 )
(∂x q(ρ))(xj , tn ) ≈ . (9.42)
2h
The use of the formulae (9.41),(9.42) gives the nonlinear Lax-Wendroff scheme. It can be written in
conservation form (exercise)
 
ρn+1
j = ρn
j − λ n
Φ n
j+1/2 − Φ n
j−1/2 (9.43)

with the Lax-Wendroff numerical flux


q(ρnj ) + q(ρnj+1 ) 1 n n
Φnj+1/2 = − λ (aj+1/2 )2 (ρnj+1 − ρnj ) (9.44)
2 2
with λn = ∆tn /h.

9.6 Nonlinear Lax-Friedrichs scheme, hybrid scheme


With similar arguments, it can be shown that the nonlinear extension of the Lax-Friedrichs scheme is
a conservative scheme with numerical flux
q(ρnj ) + q(ρnj+1 ) 1
Φnj+1/2 = − n (ρnj+1 − ρnj ). (9.45)
2 2λ
The Roe scheme, the Lax-Wendroff scheme and the Lax-Friedrichs scheme have a common structure.
All three can be written
q(ρnj ) + q(ρnj+1 ) 1  n n θ
Φnj+1/2 = − λ |aj+1/2 | |anj+1/2 |(ρnj+1 − ρnj ) (9.46)
2 2
9.7. NUMERICAL SCHEME FOR THE TRANSPORT EQUATION OF A VEHICLE FRACTION95

with θ = −1 for the Lax-Friedrichs scheme, θ = 0 for the upwind Roe scheme and θ = 1 for the
Lax-Wendroff scheme. For any θ ∈ [−1, 1], expression (9.46) defines a hybrid interpolated numerical
flux.

Of course, there are many other ways to interpolate these three schemes. For example, one could have
used
q(ρnj ) + q(ρnj+1 ) 1  +

Φnj+1/2 = − n (λn |anj+1/2 |)1+θ − θ− (1 − λn |anj+1/2 |)) (ρnj+1 − ρnj ) (9.47)
2 2λ

with notations θ+ = max(θ, 0) and θ− = min(θ, 0). Actually, the numerical flux (9.47) is preferred
to (9.46) because it is Lipschitz continuous. On the other hand the numerical flux (9.46) has an infinite
derivative when a → 0 for θ ∈ (−1, 0], what can lead to numerical instabilities for low moving
characteristics. Another deeper reason to prefer expression (9.47) is that the numerical method has a
discrete entropy property for θ ∈ [−1, 0) which is not the case for (9.46). This topic is beyond the
goal of this course and is not much more detailed.

1 1

0.9 0.9

0.8 0.8

0.7 0.7
y = |a|1+θ −θ−(1−|a|)

0.6 0.6
y = |a|θ

0.5 0.5
+

0.4 0.4

0.3 0.3

0.2 0.2

0.1 0.1

0 0
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
a a

Figure 9.4: Comparison of the interpolation functions in expressions (9.46) and (9.47).

9.7 Numerical scheme for the transport equation of a vehicle fraction


Formerly, we have talk about the transport equation of the fraction of a given class of vehicles:

∂t c + u(ρ)∂x c = 0. (9.48)

Actually, it is preferable to work on a conservative form of (9.48) which is equivalent to (9.48) for
smooth solutions, as already seen:

∂t (ρc) + ∂x (ρcu(ρ)) = 0. (9.49)


96 CHAPTER 9. VEHICLE TRAFFIC FLOW MODELING

In particular, one can write Rankine-Hugoniot jump conditions on (9.49) whereas it is impossible on
the nonconservative equation (9.48).

The quantity (ρc) is the partial density of vehicles of the class. Because equation (9.49) is in con-
servation form (the number of vehicle of the class of interest is conserved), it is natural to look for
conservative schemes for numerical discretization to keep the conservation property at the discrete
level. The numerical scheme has to respect some expected properties like the fact that the fraction
variable c is a quantity evolving within the interval [0, 1]. We have to build a numerical scheme which
has a discrete local monotonicity property or a discrete maximum principle property. These properties
are sufficient conditions in order to ensure the discrete sequences (cnj )j∈Z to stay into [0, 1] if the initial
sequences (c0j )j∈Z has values into [0, 1].

From the previous numerical time-advance scheme for ρ:


 
ρn+1
j = ρ n
j − λ n
Φ n
j+1/2 − Φ n
j−1/2 (9.50)

with Φnj+1/2 given for example by (9.47), we look for a conservative discretization of equation (9.49)
in the form  
(ρc)n+1
j = (ρc)nj − λn Ψnj+1/2 − Ψnj−1/2 . (9.51)

Once (ρcj )n+1 is computed, one can compute cn+1


j as

(ρc)n+1
j
cn+1
j = . (9.52)
ρn+1
j

The difficulty is to find a convenient numerical flux which guarantees c so stay in [0, 1] at the discrete
level. The numerical flux Ψnj+1/2 must be consistent with the physical flux Ψ = ρcu(ρ). For stability
purpose, we decide to upwind the numerical flux Ψnj+1/2 according to the sign of the total mass flux
Φnj+1/2 . This means
( n n
cj Φj+1/2 if Φnj+1/2 ≥ 0,
n
Ψj+1/2 = (9.53)
cnj+1 Φnj+1/2 if Φnj−1/2 < 0.

Remark that expression (9.53) can be written in condensed form

Ψnj+1/2 = cnj max(0, Φnj+1/2 ) + cnj+1 min(0, Φnj+1/2 ) (9.54)

or again
cnj + cnj+1 n 1
Ψnj+1/2 = Φj+1/2 − |Φnj+1/2 |(cnj+1 − cnj ). (9.55)
2 2
Because Φnj+1/2 is consistent with the physical flux q(ρ) = ρ u(ρ), it is clear that Ψnj+1/2 is consistent
with the flux Ψ = ρcu(ρ).

Let us show that the leading scheme has the expected properties under some conditions. Develop-
9.8. NUMERICAL EXPERIMENT 97

ing (9.51) with (9.55) gives


cnj + cj+1 1 n

cn+1
j ρn+1
j = ρ n n
c
j j − λ n
Φ n
j+1/2 − |Φj+1/2 |(cnj+1 − cnj )
2 2
cnj−1 + cnj

1
−Φnj−1/2 + |Φnj−1/2 |(cnj − cnj−1 )
2 2
n o
= cnj ρnj − λn (Φnj+1/2 − Φnj−1/2 )

λn
− (|Φnj+1/2 | − Φnj+1/2 + |Φnj−1/2 | + Φnj−1/2 ) cnj
2
λn
+ (|Φnj+1/2 | − Φnj+1/2 ) cnj+1
2
λn n
+ |Φ | + Φnj−1/2 ) cnj−1
2 j−1/2
λn
= ρn+1
j cnj − (|Φnj+1/2 | − Φnj+1/2 + |Φnj−1/2 | + Φnj−1/2 ) cnj
2
λn
+ (|Φnj+1/2 | − Φnj+1/2 ) cnj+1
2
λn n
+ |Φ | + Φnj−1/2 ) cnj−1 .
2 j−1/2
Thus we see that the numerical scheme can be written in incremental form

cn+1
j = (1 − αjn − βjn )cnj + αjn cnj−1 + βjn cnj+1 (9.56)

where αjn et βjn can be easily extracted from the previous development. In order to get the dis-
crete maximum principle property, we need to ensure that the coefficients αjn and βjn belong to [0, 1].
Assuming that the numerical time-advance scheme for ρ has the positivity property (meaning that
ρnj > 0 ∀j, n), we directly have αjn , βjn ≥ 0. The other bound is satisfied according to the new
CFL-like condition
|Φnj+1/2 | 1
λn sup n+1 ≤ . (9.57)
j∈Z ρj 2
A drawback of the CFL condition (9.57) is that the expression is not completely explicit (λn is needed
to compute both ρn+1
j and Φnj+1/2 ). In practice, it is observed that a standard CFL condition less than
1/2 gives the expected numerical properties.

Let us emphasize that the construction above is important numerically speaking. Without taking care
of the discrete maximum principle property, some commonly used numerical schemes can create
overshoots or undershoots with violation of the admissible interval [0, 1].

9.8 Numerical experiment


9.8.1 Scilab source code
98 CHAPTER 9. VEHICLE TRAFFIC FLOW MODELING

1 // Traffic . sce ( Scilab )


2 // Whitham first order model of traffic flow
3 // Periodic boundary conditions
4 //
5 function q = qrho(rho)
6 // Traffic parameters
7 ufree = 110;
8 rhoc = 400;
9 q = ufree * rho .* (1-rho/rhoc);
10 endfunction;
11 //
12 ufree = 110;
13 rhoc = 400;
14 N = 200;
15 cfl = 0.5;
16 theta = -0.1; // Hybridation parameter
17 h = 1 / N;
18 x = h/2 : h: 1-h/2;
19 rho = zeros(1,N);
20 phi = zeros(1,N+1);
21 aroe = zeros(1,N+1);
22 //
23 // Initial data
24 rho = 0.4*rhoc * (1 + 0.4*sin(6*%pi*x));
25 clf(); plot(x, rho, ’.-’);
26 //
27 for it=1:100
28 q = qrho(rho);
29 drho = [rho,rho(1)] - [rho(N),rho];
30 dq = [q,q(1)] - [q(N),q];
31 K = find(abs(drho)>=1e-5);
32 L = find(abs(drho)<1e-5);
33 aroe(K) = dq(K) ./ drho(K);
34 aroe(L) = ufree*(1-2*rho(L)/rhoc);
35 rl = cfl / max(abs(aroe));
36 phi = 0.5*([q,q(1)]+[q(N),q]) ...
37 - 0.5*((rl*abs(aroe)+1e-5).^theta) .* abs(aroe) .* drho;
38 rho = rho - rl * ( phi(2:N+1) - phi(1:N) );
39 drawlater();
40 clf();
41 u = ufree * (1-rho/rhoc);
42 subplot(3,1,1), plot(x, rho, ’.-’);
43 xgrid(); xtitle("Vehicle density [Nb/km]");
44 subplot(3,1,2), plot(x, u , ’.-’);
45 xgrid(); xtitle("Vehicle speed [km/h]");
46 subplot(3,1,3), plot(x, rho .* u , ’.-’);
47 xgrid(); xtitle("Vehicle flow rate [Nb/h]");
48 drawnow();
49 end;
9.9. PSEUDO TWO-DIMENSIONAL MODEL FOR LANE CONNECTION MODELING 99

Vehicle density [Nb/km]


240
220
200
180
160
140
120
100
80
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Vehicle speed [km/h]
85
80
75
70
65
60
55
50
45
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Vehicle flow rate [Nb/h]
11000
10500
10000
9500
9000
8500
8000
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Figure 9.5: Numerical solution using a CFL number equal to 0.5 and θ = −0.1, after one time
iterations.

Vehicle density [Nb/km]


240
220
200
180
160
140
120
100
80
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Vehicle speed [km/h]
85
80
75
70
65
60
55
50
45
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Vehicle flow rate [Nb/h]
11000
10500
10000
9500
9000
8500
8000
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Figure 9.6: Numerical solution using a CFL number equal to 0.5 and θ = −0.1, after 20 time itera-
tions.

9.8.2 One-dimensional numerical results

9.9 Pseudo two-dimensional model for lane connection modeling


The heuristic multidimensional extension of the traffic flow equation with a diffusion term writes

∂t ρ + ∇ · (ρ u(ρ)n) − ν∆ρ = 0. (9.58)


100 CHAPTER 9. VEHICLE TRAFFIC FLOW MODELING

Vehicle density [Nb/km]


210
200
190
180
170
160
150
140
130
120
110
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Vehicle speed [km/h]
80
75
70
65
60
55
50
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Vehicle flow rate [Nb/h]
11000
10800
10600
10400
10200
10000
9800
9600
9400
9200
9000
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Figure 9.7: Numerical solution using a CFL number equal to 0.5 and θ = −0.1, after 100 time
iterations. Several shock waves appear. The numerical scheme is able to capture the discontinuities.

9.9.1 freefem++ source code for the viscous two-dimensional model

1 // Traffic .edp (Freefem++)rho


2 // Peudo one−dimension vehicle trafic flow with road branching
3 // Model \ partial_t \rho+\nabla(rho V(rho) n)−\nu\Delta\rho=0.
4 // V(rho) = q(rho) /rho with q(rho) = rho ∗ Vfree∗(1−rho/rhoc)
5 //
6 real [int] A(2), B(2), C(2), D(2), E(2);
7 real [int] F(2), G(2), H(2), I(2), J(2);
8 real [int] K(2), L(2), M(2), Ng(2);
9 A = [0,0]; B = [9, 1.5]; C = [12, 1.5]; D = [21,0];
10 E = [6, 2]; F = [15, 2]; G = [0, 4]; H = [9, 2.5];
11 I = [12, 2.5]; J = [21, 4]; K = [0, 1]; L = [0, 3];
12 M = [21, 1]; Ng = [21, 3];
13 border c1(t=0,1){x=(1-t)*A[0]+t*B[0]; y=(1-t)*A[1]+t*B[1];}
14 border c2(t=0,1){x=(1-t)*B[0]+t*C[0]; y=(1-t)*B[1]+t*C[1];}
15 border c3(t=0,1){x=(1-t)*C[0]+t*D[0]; y=(1-t)*C[1]+t*D[1];}
16 border c4(t=0,1){x=(1-t)*G[0]+t*L[0]; y=(1-t)*G[1]+t*L[1];}
17 border c5(t=0,1){x=(1-t)*L[0]+t*E[0]; y=(1-t)*L[1]+t*E[1];}
18 border c6(t=0,1){x=(1-t)*E[0]+t*K[0]; y=(1-t)*E[1]+t*K[1];}
19 border c7(t=0,1){x=(1-t)*K[0]+t*A[0]; y=(1-t)*K[1]+t*A[1];}
20 border c8(t=0,1){x=(1-t)*D[0]+t*M[0]; y=(1-t)*D[1]+t*M[1];}
21 border c9(t=0,1){x=(1-t)*M[0]+t*F[0]; y=(1-t)*M[1]+t*F[1];}
22 border c10(t=0,1){x=(1-t)*F[0]+t*Ng[0]; y=(1-t)*F[1]+t*Ng[1];}
23 border c11(t=0,1){x=(1-t)*Ng[0]+t*J[0]; y=(1-t)*Ng[1]+t*J[1];}
24 border c12(t=0,1){x=(1-t)*J[0]+t*I[0]; y=(1-t)*J[1]+t*I[1];}
25 border c13(t=0,1){x=(1-t)*I[0]+t*H[0]; y=(1-t)*I[1]+t*H[1];}
26 border c14(t=0,1){x=(1-t)*H[0]+t*G[0]; y=(1-t)*H[1]+t*G[1];}
27 //
9.9. PSEUDO TWO-DIMENSIONAL MODEL FOR LANE CONNECTION MODELING 101

28 mesh Th = buildmesh(c1(60)+c2(30)+c3(60)
29 +c4(6)+c5(50)+c6(50)+c7(6)
30 +c8(6)+c9(50)+c10(50)+c11(6)
31 +c12(60)+c13(30)+c14(60) );
32 plot(Th, ps = "mesh.eps");
33 //
34 fespace Vh(Th, P1);
35 Vh rho, rhoold, sigma, sigmaold, rhoh, sigmah, p, ph;
36 Vh n1, n2, u1, u2, u1visu, u2visu, vrho;
37 fespace Wh(Th, P2);
38 Wh phi, phih;
39 //
40 real rho0 = 25; // [nb cars / km]
41 real rhoc = 300; // critical density
42 real vfree = 110; // [km / h]
43 real nu = 10; // viscosity
44 real dt = 0.004; // time step
45 real t = 0; // current time
46 // Initial field
47 rho = rho0;
48 rhoold = rho0;
49
50 // Step 0. Define a velocity unit vector by solving an
51 // independent Laplace problem, then get the unit
52 // vector of the gradient of the solution
53 //
54 problem Laplace(phi, phih) =
55 int2d(Th)( dx(phi)*dx(phih) + dy(phi)*dy(phih))
56 +int1d(Th, c4)(phih) + int1d(Th, c7)(phih)
57 +on(c8, c11, phi=0);
58 Laplace;
59 n1 = dx(phi)/sqrt(dx(phi)^2+dy(phi)^2);
60 n2 = dy(phi)/sqrt(dx(phi)^2+dy(phi)^2);
61 vrho = vfree * (1-rho / rhoc);
62 //
63 u1 = vrho*n1;
64 u2 = vrho*n2;
65 //
66 problem step1(rho, rhoh) =
67 int2d(Th)( rho*rhoh/dt )
68 -int2d(Th)( convect([u1,u2], -dt, rhoold)*rhoh/dt )
69 +int2d(Th)( nu*dx(rho)*dx(rhoh) + nu*dy(rho)*dy(rhoh) )
70 +int2d(Th)(rho*dx(u1)*rhoh+rho*dy(u2)*rhoh)
71 +on(c4, rho=rho0)
72 +on(c7, rho=rhoc);
73
74 for (int it=0 ; it<200 ; it++) {
75 t += dt;
76 step1;
77 rhoold = rho;
78 vrho = vfree * (1 - rho / rhoc);
79 u1 = vrho * n1;
102 CHAPTER 9. VEHICLE TRAFFIC FLOW MODELING

80 u2 = vrho * n2;
81 plot(rho, nbiso=50, fill=1, value=1, wait=0);
82 }
83 cout << "Final time = " << t << endl;
84 plot(rho, nbiso=40, fill=1, value=1, ps="rho.eps");
85 u1visu = u1/vfree;
86 u2visu = u2/vfree;
87 plot([u1visu, u2visu], value=1, ps="speed.eps");

9.9.2 Numerical results

Figure 9.8: Computational mesh


9.9. PSEUDO TWO-DIMENSIONAL MODEL FOR LANE CONNECTION MODELING 103

IsoValue
17.9487
28.5256
35.5769
42.6282
49.6795
56.7308
63.7821
70.8333
77.8846
84.9359
91.9872
99.0385
106.09
113.141
120.192
127.244
134.295
141.346
148.397
155.449
162.5
169.551
176.603
183.654
190.705
197.756
204.808
211.859
218.91
225.962
233.013
240.064
247.115
254.167
261.218
268.269
275.321
282.372
289.423
307.051

Vec Value
0
0.0482482
0.0964963
0.144744
0.192993
0.241241
0.289489
0.337737
0.385985
0.434233
0.482482
0.53073
0.578978
0.627226
0.675474
0.723722
0.77197
0.820219
0.868467
0.916715

Figure 9.9: Density contour levels and velocity field at a given instant. One can observe a backward
propagating traveling wave at the top left lane, revealing the downstream bottleneck.
104 CHAPTER 9. VEHICLE TRAFFIC FLOW MODELING
Chapter 10

Biological cell migration and


proliferation

Modeling of biological cell migration and proliferation is of importance for the understanding of
diseases like cancer (tumour growth, metastases migration, tissue invasion, etc.). When the cell density
is large enough, the continuous medium assumption is a good approximation and partial differential
equations can be written.

10.1 Biological and mathematical requirements


Biological expectations and some expected mathematical properties lead to the following require-
ments. In what follows, we are going to derive the “simplest” mathematical model able to fulfill these
requirements.

1. Without proliferation and apoptosis (cell death), the number of cell has to be conserved. So
migration phenomenon should be modeled by a conservation law.

2. Travelling waves and sharp cell fronts are observed in biological experiments. Thus this be-
haviour must be reproduced by the model.

3. Sometimes cell fronts reach a steady state. That means that the cell fronts slow down and stop in
finite time, revealing a cell region with a boundary (think about animal skin marks and patterns
for example). This behaviour also has to be reproduced by the model.

4. Known biochemical factors like chemoattractant and chemorepellent agents are able to attract
or repel biological cells.

5. Cell motility is the ability for a cell to freely move, generally with a brownian motion. From the
macroscopic point of view, this is a diffusive phenomenon. If the diffusion is isotropic, then the
diffusion operator is the Laplace operator.

6. There are biological regulation factors that limit the cell density up to a certain threshold.

105
106 CHAPTER 10. BIOLOGICAL CELL MIGRATION AND PROLIFERATION

10.2 Guidelines for PDE modeling


As already seen in a previous chapter, the Keller-Segel model already takes into account cell motility
(diffusion), proliferation (source terms) and propagation due to the presence of a chemoattractant c.
Moreover, the Keller-Segel system is in conservation form.

But he Keller-Segel cannot reproduce traveling waves or sharp cell moving fronts. So a modification
of these equations or the adding of a new modeling term is necessary.

In traffic flow modeling we have seen that a nonlinear flux term in the equation can create unsteady or
steady discontinuities (shock waves). So the idea is the replace the Keller-Segel convection term
∇ · (αρ∇c)
by
∇ · (q(ρ)∇c) (10.1)
for a nonlinear concave function q : [0, +∞) → R. Thus, we are looking for a mathematical model
in the form
∂t ρ − ν∆ρ + ∇ · (q(ρ)∇c) = rρ(ρ∞ − ρ), (10.2)
ρ
∂t c − ∆c = s( − c) (10.3)
ρ∞
where ν > 0 is the diffusion rate, r > 0 is a proliferation rate and ρ∞ > 0 is the threshold cell density.
The quantity c is the concentration of chemoattractant (or chemorepellent according to the sign of
q(ρ)). The parameter s > 0 is a reaction rate for c. The convective flux for the cells is
J = q(ρ)∇c. (10.4)
Next step, we need a closure for q(ρ). The first constraint is q(0) = 0 (no flux is there is no cell). In
∇c
the direction n = ||∇c|| , there is a flux
j = J · n = q(ρ) ||∇c||.
The flux can be designed in order to attract cells located in low density regions toward denser regions
(clustering) and to repel cells located in dense regions in order to colonize free regions (migration).
One can consider for example a strictly concave function q(ρ) such that q(0) = 0 and q(ρc ) = 0 for
some ρc ∈ (0, ρ∞ ]. One can consider for example a polynomial of degree 2 crossing the two points:
 
ρ
q(ρ) = α ρ 1 − (10.5)
ρc
with some constant α > 0. Practically, the constants α, ρc and ρ∞ should be chosen according
to some biological considerations and by identification from measurements. Figure 10.1 shows a
candidate function q(ρ). The characteristic velocity for the convective term is
v = q ′ (ρ) ∇c. (10.6)
In the case of (10.5), one gets  
ρ
v =α 1−2 ∇c. (10.7)
ρc
There is two ways to get a null characteristic velocity leading in that case to a locally stationary wave.
Either ∇c = 0 or q ′ (ρ) = 0.
10.3. NUMERICAL RESULTS 107

Figure 10.1: Function ρ 7→ q(rho). For ρ ∈ [0, ρc ], the flux is positive and the chemical species acts
as a chemoattractant [region(a)]. For ρ ∈ [ρc , ρ∞ ], the flux is negative and the chemical species with
acts as a chemorepellent [region (b)].

10.3 Numerical results


10.3.1 freefem++ source code

1 //
2 // MigrationNN.edp (Freefem++)
3 // Migration/ Proliferation model − florian de vuyst
4 //
5 real Lx = 3;
6 real Ly = 2;
7 real dt = 0.05;
8 real uf = 1;
9 real rhoc = 100;
10 mesh Th = square(60, 40, [x*Lx,y*Ly]);
11 fespace Uh(Th, P2, periodic=[[3,x],[1,x]]);
12 fespace Vh(Th, P1, periodic=[[3,x],[1,x]]);
13 Uh rho, lrho, rhoold, rhoh, c, ch, cold;
14 Vh u1, u2, u, n1, n2, v1, v2, rhop1, cp1;
15 rho = rhoc*exp( -40*(x-Lx/4)^2 - 40*(y-Ly/2)^2 )
16 + rhoc*exp( -40*(x-3*Lx/4)^2 - 40*(y-Ly/2)^2 )
17 + rhoc*exp( -40*(x-0.55*Lx)^2 - 40*(y-Ly/2)^2 );
18 Th = adaptmesh(Th, rho, periodic=[[3,x],[1,x]]);
19 plot(Th);
20 rho = rho;
21 c = rho/rhoc;
22 rhoold = rho;
23 cold = c;
24 // plot (rho, nbiso=50, wait=1);
25 //
26 problem migr([rho, c], [rhoh, ch]) =
27 int2d(Th)(rho*rhoh/dt)
28 -int2d(Th)(convect([v1,v2], -dt,rhoold)*rhoh/dt)
29 +int2d(Th)(dx(v1)*rho*rhoh+dy(v2)*rho*rhoh)
30 +int2d(Th)(0.01*dx(rho)*dx(rhoh)+0.01*dy(rho)*dy(rhoh))
31 -int2d(Th)(0.01*rho*(rhoc-rhoold)*rhoh)
108 CHAPTER 10. BIOLOGICAL CELL MIGRATION AND PROLIFERATION

32 +int2d(Th)(c*ch/dt)
33 -int2d(Th)(cold*ch/dt)
34 +int2d(Th)(dx(c)*dx(ch)+dy(c)*dy(ch))
35 -int2d(Th)(10*(rho/rhoc-c)*ch);
36 //
37 for (int it=0; it<20; it++) {
38 for (int substep=0; substep<2; substep++){
39 u1 = -dx(cold);
40 u2 = -dy(cold);
41 v1 = 0.5 * u1 * rhoold/rhoc;
42 v2 = 0.5 * u2 * rhoold/rhoc;
43 migr;
44 Th = adaptmesh(Th, rho, periodic=[[3,x],[1,x]]);
45 rho=rho;
46 c=c;
47 rhoold = rho;
48 cold = c;
49 }
50 // Visu
51 rhop1 = rho; cp1 = c;
52 plot(Th, rhop1, nbiso=50, fill=0, value=1,
53 ps="migr_it="+it+".eps");
54 }
55 cout << "Done.\n";

10.3.2 Numerical results


10.3. NUMERICAL RESULTS 109

IsoValue
1.01785
3.05508
5.09232
7.12955
9.16678
11.204
13.2412
15.2785
17.3157
19.353
21.3902
23.4274
25.4647
27.5019
29.5391
31.5764
33.6136
35.6508
37.6881
39.7253
41.7625
43.7998
45.837
47.8742
49.9115
51.9487
53.9859
56.0232
58.0604
60.0976
62.1349
64.1721
66.2093
68.2466
70.2838
72.321
74.3583
76.3955
78.4327
80.47
82.5072
84.5444
86.5817
88.6189
90.6561
92.6934
94.7306
96.7678
98.8051
100.842

IsoValue
0.584089
1.75379
2.92349
4.09319
5.26289
6.43259
7.60229
8.77199
9.94169
11.1114
12.2811
13.4508
14.6205
15.7902
16.9599
18.1296
19.2993
20.469
21.6387
22.8084
23.9781
25.1478
26.3175
27.4872
28.6569
29.8266
30.9963
32.166
33.3357
34.5054
35.6751
36.8448
38.0145
39.1842
40.3539
41.5236
42.6933
43.863
45.0327
46.2024
47.3721
48.5418
49.7115
50.8812
52.0509
53.2206
54.3903
55.56
56.7297
57.8994

IsoValue
0.506198
1.51998
2.53376
3.54754
4.56132
5.5751
6.58888
7.60266
8.61644
9.63022
10.644
11.6578
12.6716
13.6853
14.6991
15.7129
16.7267
17.7405
18.7542
19.768
20.7818
21.7956
22.8094
23.8231
24.8369
25.8507
26.8645
27.8783
28.892
29.9058
30.9196
31.9334
32.9472
33.961
34.9747
35.9885
37.0023
38.0161
39.0299
40.0436
41.0574
42.0712
43.085
44.0988
45.1125
46.1263
47.1401
48.1539
49.1677
50.1814

Figure 10.2: Cell density contour levels at different instants. Initially there are three cell sites. During
migration and proliferation, the sites are growing and merging. One can see the sharp cell front moving
in the medium.
110 CHAPTER 10. BIOLOGICAL CELL MIGRATION AND PROLIFERATION

IsoValue
0.4902
1.47219
2.45417
3.43616
4.41815
5.40013
6.38212
7.36411
8.34609
9.32808
10.3101
11.2921
12.274
13.256
14.238
15.22
16.202
17.184
18.166
19.1479
20.1299
21.1119
22.0939
23.0759
24.0579
25.0399
26.0219
27.0038
27.9858
28.9678
29.9498
30.9318
31.9138
32.8958
33.8777
34.8597
35.8417
36.8237
37.8057
38.7877
39.7697
40.7517
41.7336
42.7156
43.6976
44.6796
45.6616
46.6436
47.6256
48.6075

IsoValue
0.488583
1.46804
2.4475
3.42696
4.40642
5.38588
6.36534
7.3448
8.32426
9.30372
10.2832
11.2626
12.2421
13.2216
14.201
15.1805
16.1599
17.1394
18.1189
19.0983
20.0778
21.0572
22.0367
23.0161
23.9956
24.9751
25.9545
26.934
27.9134
28.8929
29.8724
30.8518
31.8313
32.8107
33.7902
34.7697
35.7491
36.7286
37.708
38.6875
39.667
40.6464
41.6259
42.6053
43.5848
44.5643
45.5437
46.5232
47.5026
48.4821

IsoValue
0.493843
1.48235
2.47086
3.45937
4.44788
5.43639
6.4249
7.41341
8.40192
9.39043
10.3789
11.3674
12.356
13.3445
14.333
15.3215
16.31
17.2985
18.287
19.2755
20.264
21.2525
22.241
23.2296
24.2181
25.2066
26.1951
27.1836
28.1721
29.1606
30.1491
31.1376
32.1261
33.1146
34.1032
35.0917
36.0802
37.0687
38.0572
39.0457
40.0342
41.0227
42.0112
42.9997
43.9883
44.9768
45.9653
46.9538
47.9423
48.9308

Figure 10.3: Cell density contour levels at different instants. Initially there are three cell sites. During
migration and proliferation, the sites are growing and merging. One can see the sharp cell front moving
in the medium.
10.3. NUMERICAL RESULTS 111

IsoValue
0.501963
1.50563
2.50929
3.51296
4.51662
5.52029
6.52395
7.52762
8.53128
9.53495
10.5386
11.5423
12.5459
13.5496
14.5533
15.5569
16.5606
17.5643
18.5679
19.5716
20.5753
21.5789
22.5826
23.5863
24.5899
25.5936
26.5972
27.6009
28.6046
29.6082
30.6119
31.6156
32.6192
33.6229
34.6266
35.6302
36.6339
37.6376
38.6412
39.6449
40.6486
41.6522
42.6559
43.6596
44.6632
45.6669
46.6705
47.6742
48.6779
49.6815

IsoValue
0.512442
1.53643
2.56042
3.58441
4.6084
5.63239
6.65638
7.68037
8.70436
9.72835
10.7523
11.7763
12.8003
13.8243
14.8483
15.8723
16.8963
17.9203
18.9442
19.9682
20.9922
22.0162
23.0402
24.0642
25.0882
26.1122
27.1362
28.1602
29.1841
30.2081
31.2321
32.2561
33.2801
34.3041
35.3281
36.3521
37.3761
38.4
39.424
40.448
41.472
42.496
43.52
44.544
45.568
46.592
47.616
48.6399
49.6639
50.6879

IsoValue
0.539463
1.61496
2.69046
3.76595
4.84145
5.91695
6.99245
8.06794
9.14344
10.2189
11.2944
12.3699
13.4454
14.5209
15.5964
16.6719
17.7474
18.8229
19.8984
20.9739
22.0494
23.1249
24.2004
25.2759
26.3514
27.4269
28.5024
29.5779
30.6534
31.7289
32.8044
33.8799
34.9554
36.0309
37.1064
38.1819
39.2574
40.3329
41.4084
42.4839
43.5594
44.6349
45.7104
46.7859
47.8613
48.9368
50.0123
51.0878
52.1633
53.2388

Figure 10.4: Cell density contour levels at different instants. Initially there are three cell sites. During
migration and proliferation, the sites are growing and merging. One can see the sharp cell front moving
in the medium.
112 CHAPTER 10. BIOLOGICAL CELL MIGRATION AND PROLIFERATION
Chapter 11

Gas Dynamics

When a fluid is considered incompressible and inviscid and is not subjected to the effect of external
forces, the governing equations are the so-called compressible Euler equations. They are made of the
continuity equation that expresses the conservation of the mass

∂t ρ + ∇ · (ρu) = 0, (11.1)

(ρ is the fluid density, u is the velocity), the equation of conservation of the momentum

∂t (ρu) + ∇ · (ρu ⊗ u) + ∇p = 0 (11.2)

(p is the pressure of the fluid) and the equation of the conservation of the energy

∂t (ρE) + ∇ · ((ρE + p)u) = 0 (11.3)

where E is the specific total energy made of the kinetic energy u2 /2 (u = ||u||) and the internal
energy e:
u2
E= +e (11.4)
2
The Euler system (11.1)-(11.3) is a rather complex system. It is known that solutions can develop
discontinuity (shock waves) even if the initial data is of arbitrary regularity. This possible loss of regu-
larity has strong implications on theoretical numerical analysis and the proper way to discretize those
equations. Best numerical methods for the Euler equations are conservative upwind Finite Volume
methods.
Despite we here adopt the method of Characteristics + FE strategy. For numerical experiments, we
will focus on a supersonic flow around an elliptic body. We will see that the numerical solutions are
not so bad and anyway give a rather good information on the features of the supersonic flow (separated
shock, compression shock, etc.). So the freefem++ environment is a good candidate a have a first
sight on those king of solutions before going further in more sophisticated conservative numerical
methods. In order to implement a FE-like program for the Euler equations, we need to prepare the
equations in a suited form. For the continuity equation, remember that using the total derivative, for
sufficiently smooth solutions one can write

Dt ρ + ρ∇ · u = 0 (11.5)

or equivalently
D t aρ + ∇ · u = 0 (11.6)

113
114 CHAPTER 11. GAS DYNAMICS

using the new variable aρ = log(ρ). Equation (11.6) is interesting because it is linear with respect to
the variables aρ and u. Now, let us consider the momentum equation. Using the standard Einstein’s
mute indexes, it can be rewritten

∂t (ρui ) + (ρui uj ),j + p,i = 0, i = 1, . . . , d.

From the continuity equation, ∂t ρ = −(ρuj ),j , it is easy to obtain

1
∂t ui + uj ui,j + p,i = 0
ρ
or in vector form
1
∂t u + u · ∇u + ∇p = 0 (11.7)
ρ
or again
1
Dt u + ∇p = 0. (11.8)
ρ
By the same approach, one can obtain the equation on E
1
Dt E + ∇ · (pu) = 0. (11.9)
ρ
One can also successively obtain from (11.4) and (11.8)
1 1
0 = Dt e + Dt (u2 ) + ∇ · (pu)
2 ρ
1
= Dt e + u · Dt u + ∇ · (pu)
ρ
1 1
= Dt e − u · ∇p + ∇ · (pu)
ρ ρ
p
= Dt e + ∇ · u (11.10)
ρ
which gives an equation on for the internal energy.

11.1 Perfect gas


The perfect gas closure is usually
1 p
e= (11.11)
γ−1 ρ
where γ is the ratio of the (constant here) specific heats cp and cv . The ratio γ is equal to

γ = 1.4 (11.12)

for a diatomic gas. Let us write an equation for the pressure. From equations (11.5) and (11.10), one
has
Dt (ρe) + (ρe + p) ∇ · u = 0, (11.13)
11.2. DISCRETIZATION IN TIME 115

then
Dt p + γp ∇ · u = 0. (11.14)

from (11.11). It appears again interesting to introduced the new variable ap = log(p) to get the linear
equation
Dt ap + γ ∇ · u = 0. (11.15)

So far we have written the original system (11.1)-(11.3) in the equivalent form (for smooth solutions)

Dt aρ + ∇ · u = 0, (11.16)
1
Dt u + ∇p = 0, (11.17)
ρ
Dt ap + γ ∇ · u = 0. (11.18)

A nonlinear term remains in the equation, namely ρ1 ∇p. For practical reasons appearing in the numer-
ical approach, we will rather the following equivalent script of equation (11.17):

1
Dt u + ∇ap = 0 (11.19)
T

where T = p/ρ is a temperature.

11.2 Discretization in time


Let ∆t be a time step. The total derivatives are discretized according to the method of characteristics:

an+1
ρ − anρ ◦ X n
+ ∇ · un+1 = 0, (11.20)
∆t
1 un+1 − un ◦ X n
+ ∇an+1
ρ = 0, (11.21)
Tn ∆t
an+1
p − anp ◦ X n
+ γ ∇ · un+1 = 0. (11.22)
∆t
Some comments are necessary: first remark that for stability purposes, the numerical scheme is made
implicit. The divergence and gradient terms are systematically taken as implicit. In this way, the three
equations are fully coupled. One can notice that the term 1/T is taken explicit in order to keep a linear
system. The time discretization is said to be semi-implicit. In this way, the problem (11.20)-(11.22)
of unknowns (an+1
ρ , un+1 , an+1
p ) becomes linear.

11.3 Full discretization


To complete the discretization, we use the Finite Element formalism for spatial discretization. Due to
the fact that we have a system of PDEs, we need a test function for each equation (four in two space
dimensions).
116 CHAPTER 11. GAS DYNAMICS

Let us denote v the test function for the aρ-equation, v1 and v2 the test functions for each compo-
nent of the velocity and w the test function for the ap -equation. The variational formulation reads
Z n+1
aρ − anρ ◦ X n
Z
v dx + ∇ · un+1 v dx
Ω ∆t Ω
Z
1 u n+1 −u ◦Xn n Z
+ n
· (v1 , v2 ) dx + ∇an+1
ρ · (v1 , v2 ) dx
Ω T ∆t Ω
Z n+1
ap − anp ◦ X n
Z
+ w dx + γ ∇ · un+1 w dx = 0 ∀v, v1 , v2 , w ∈ V h . (11.23)
Ω ∆t Ω

11.4 Numerical experiments


11.4.1 freefem++ source code of the supersonic flow problem around an ellipse

1 // Program schockellipse .edp ( freefem++)


2 // Supersonic perfect gas flow around an ellipse
3 // Be careful : nonconservative formulation of the
4 // compressible Euler equations .
5 // A conservative Finite Volume method should be used
6 // Author : florian .de−vuyst@ecp.fr
7 //
8 real gamma = 1.4;
9 real pinf = 1e2;
10 real rhoinf = 0.3;
11 real cinf = sqrt(gamma*pinf/rhoinf); // speed of sound
12 real uinf = 1.5 * cinf; // infinite flow Mach number is 2
13 real radius = 10; // Radius of the infinite flow boundary
14 real alpha = 0.3; // Attack angle (radian)
15 real x0 = -4; // x−translation of the body
16 real ra = 2, rb = 0.3; // Features of the body ellipse
17 real dt = 0.01; // Time step
18 //
19 // External infinite boundary is a circle
20 border binf(t=0,2*pi){x=radius*cos(t); y=radius*sin(t);}
21 // Body is an ellipse
22 border wall(t=0,2*pi){x=x0+cos(alpha)*ra*cos(t)+sin(alpha)*rb*sin(t);
23 y=-sin(alpha)*ra*cos(t)+cos(alpha)*rb*sin(t);}
24 mesh Th = buildmesh(binf(100)+wall(-80));
25 plot(Th, wait=0, ps="Th.eps");
26 //
27 fespace Vh(Th, P1); // FE space
28 Vh rho, p, arho, ap, T, u1, u2; // unknowns
29 Vh rhoold, pold, Told, arhoold, apold, u1old, u2old;
30 // fields at former instant
31 Vh v, v1, v2, w; // test functions
32 //
33 // Field initialization
34 rho = rhoinf; p = pinf;
35 u1 = uinf; u2 = 0;
11.4. NUMERICAL EXPERIMENTS 117

36 arho = log(rho); ap = log(p);


37 T = p/rho; // temperature−like
38 plot(T, nbiso=50, fill=1, value=1, wait=0);
39 // Go for the partial differential problem
40 problem euler([arho, u1, u2, ap], [v, v1, v2, w]) =
41 int2d(Th)(arho*v/dt)
42 -int2d(Th)(convect([u1old,u2old], -dt, arhoold)*v/dt)
43 +int1d(Th, binf)((uinf*N.x)*v)
44 -int2d(Th)(u1*dx(v)+u2*dy(v))
45 +int2d(Th)(u1*v1/Told/dt)
46 -int2d(Th)(convect([u1old,u2old], -dt, u1old)*v1/Told/dt)
47 +int2d(Th)(u2*v2/Told/dt)
48 -int2d(Th)(convect([u1old,u2old], -dt, u2old)*v2/Told/dt)
49 +int2d(Th)(dx(ap)*v1+dy(ap)*v2)
50 +int2d(Th)(ap*w/dt)
51 -int2d(Th)(convect([u1old,u2old], -dt, apold)*w/dt)
52 +int1d(Th, binf)(gamma*(uinf*N.x)*w)
53 -int2d(Th)(gamma*u1*dx(w)+gamma*u2*dy(w));
54

55 for (int it=0; it<80; it++) {


56 u1old = u1; u2old = u2;
57 arhoold = arho;
58 apold = ap;
59 Told = T;
60 euler;
61 if (it>70){
62 Th = adaptmesh(Th,ap);
63 u1=u1; u2=u2; arho=arho; ap=ap;
64 }
65 rho = exp(arho);
66 p = exp(ap);
67 T = p/rho;
68 plot(rho, nbiso=50, fill=0, value=1);
69 if (it<20) {
70 plot(rho, nbiso=50, fill=1, value=1, ps="rho_mach1.5_it"+it+".eps");
71 }
72 }
73 plot(T, nbiso=50, fill=1, value=1, ps="T.eps");
74 plot(T, nbiso=50, fill=0, value=1, ps="Tiso.eps");
75 plot(p, nbiso=50, fill=1, value=1, ps="p.eps");
76 plot(rho, nbiso=50, fill=1, value=1, ps="rho.eps");
77 plot([u1,u2], ps="velocity.eps");
78 plot(Th, ps="finalmesh.eps");

11.4.2 Numerical results at infinite Mach number equal to 1.5


11.4.3 Numerical results at infinite Mach number equal to 4
118 CHAPTER 11. GAS DYNAMICS

IsoValue IsoValue IsoValue


0.133132 0.136519 0.13627
0.148082 0.150791 0.150715
0.158048 0.160306 0.160346
0.168015 0.169821 0.169976
0.177981 0.179336 0.179606
0.187948 0.18885 0.189236
0.197914 0.198365 0.198866
0.20788 0.20788 0.208496
0.217847 0.217395 0.218126
0.227813 0.22691 0.227756
0.23778 0.236424 0.237386
0.247746 0.245939 0.247016
0.257713 0.255454 0.256646
0.267679 0.264969 0.266276
0.277646 0.274484 0.275907
0.287612 0.283998 0.285537
0.297579 0.293513 0.295167
0.307545 0.303028 0.304797
0.317512 0.312543 0.314427
0.327478 0.322058 0.324057
0.337445 0.331572 0.333687
0.347411 0.341087 0.343317
0.357378 0.350602 0.352947
0.367344 0.360117 0.362577
0.37731 0.369632 0.372207
0.387277 0.379146 0.381838
0.397243 0.388661 0.391468
0.40721 0.398176 0.401098
0.417176 0.407691 0.410728
0.427143 0.417206 0.420358
0.437109 0.42672 0.429988
0.447076 0.436235 0.439618
0.457042 0.44575 0.449248
0.467009 0.455265 0.458878
0.476975 0.46478 0.468508
0.486942 0.474294 0.478138
0.496908 0.483809 0.487768
0.506875 0.493324 0.497399
0.516841 0.502839 0.507029
0.526808 0.512354 0.516659
0.536774 0.521868 0.526289
0.54674 0.531383 0.535919
0.556707 0.540898 0.545549
0.566673 0.550413 0.555179
0.57664 0.559928 0.564809
0.586606 0.569442 0.574439
0.596573 0.578957 0.584069
0.606539 0.588472 0.593699
0.616506 0.597987 0.60333
0.641422 0.621774 0.627405

IsoValue IsoValue IsoValue


0.134192 0.13285 0.132106
0.14863 0.147377 0.146725
0.158256 0.157062 0.156472
0.167882 0.166747 0.166219
0.177508 0.176431 0.175965
0.187134 0.186116 0.185712
0.196759 0.195801 0.195458
0.206385 0.205486 0.205205
0.216011 0.21517 0.214952
0.225637 0.224855 0.224698
0.235263 0.23454 0.234445
0.244888 0.244225 0.244191
0.254514 0.25391 0.253938
0.26414 0.263594 0.263685
0.273766 0.273279 0.273431
0.283392 0.282964 0.283178
0.293017 0.292649 0.292924
0.302643 0.302333 0.302671
0.312269 0.312018 0.312418
0.321895 0.321703 0.322164
0.331521 0.331388 0.331911
0.341146 0.341073 0.341657
0.350772 0.350757 0.351404
0.360398 0.360442 0.361151
0.370024 0.370127 0.370897
0.37965 0.379812 0.380644
0.389275 0.389496 0.39039
0.398901 0.399181 0.400137
0.408527 0.408866 0.409883
0.418153 0.418551 0.41963
0.427779 0.428236 0.429377
0.437404 0.43792 0.439123
0.44703 0.447605 0.44887
0.456656 0.45729 0.458616
0.466282 0.466975 0.468363
0.475908 0.476659 0.47811
0.485533 0.486344 0.487856
0.495159 0.496029 0.497603
0.504785 0.505714 0.507349
0.514411 0.515399 0.517096
0.524036 0.525083 0.526843
0.533662 0.534768 0.536589
0.543288 0.544453 0.546336
0.552914 0.554138 0.556082
0.56254 0.563822 0.565829
0.572165 0.573507 0.575576
0.581791 0.583192 0.585322
0.591417 0.592877 0.595069
0.601043 0.602562 0.604815
0.625107 0.626774 0.629182

IsoValue IsoValue IsoValue


0.132171 0.130712 0.128756
0.146813 0.145536 0.143704
0.156575 0.155419 0.153669
0.166337 0.165301 0.163634
0.176099 0.175183 0.1736
0.18586 0.185066 0.183565
0.195622 0.194948 0.19353
0.205384 0.204831 0.203496
0.215146 0.214713 0.213461
0.224907 0.224596 0.223426
0.234669 0.234478 0.233392
0.244431 0.244361 0.243357
0.254193 0.254243 0.253322
0.263955 0.264126 0.263288
0.273716 0.274008 0.273253
0.283478 0.283891 0.283218
0.29324 0.293773 0.293184
0.303002 0.303656 0.303149
0.312763 0.313538 0.313114
0.322525 0.323421 0.32308
0.332287 0.333303 0.333045
0.342049 0.343186 0.34301
0.351811 0.353068 0.352976
0.361572 0.362951 0.362941
0.371334 0.372833 0.372906
0.381096 0.382716 0.382871
0.390858 0.392598 0.392837
0.400619 0.40248 0.402802
0.410381 0.412363 0.412767
0.420143 0.422245 0.422733
0.429905 0.432128 0.432698
0.439667 0.44201 0.442663
0.449428 0.451893 0.452629
0.45919 0.461775 0.462594
0.468952 0.471658 0.472559
0.478714 0.48154 0.482525
0.488475 0.491423 0.49249
0.498237 0.501305 0.502455
0.507999 0.511188 0.512421
0.517761 0.52107 0.522386
0.527523 0.530953 0.532351
0.537284 0.540835 0.542317
0.547046 0.550718 0.552282
0.556808 0.5606 0.562247
0.56657 0.570483 0.572213
0.576331 0.580365 0.582178
0.586093 0.590248 0.592143
0.595855 0.60013 0.602108
0.605617 0.610013 0.612074
0.630021 0.634719 0.636987

IsoValue IsoValue IsoValue


0.124064 0.120151 0.116213
0.139231 0.135487 0.131737
0.149343 0.145711 0.142086
0.159454 0.155935 0.152435
0.169566 0.16616 0.162783
0.179677 0.176384 0.173132
0.189788 0.186608 0.183481
0.1999 0.196833 0.19383
0.210011 0.207057 0.204179
0.220123 0.217281 0.214528
0.230234 0.227505 0.224877
0.240346 0.23773 0.235226
0.250457 0.247954 0.245575
0.260568 0.258178 0.255924
0.27068 0.268402 0.266273
0.280791 0.278627 0.276622
0.290903 0.288851 0.286971
0.301014 0.299075 0.297319
0.311125 0.309299 0.307668
0.321237 0.319524 0.318017
0.331348 0.329748 0.328366
0.34146 0.339972 0.338715
0.351571 0.350196 0.349064
0.361682 0.360421 0.359413
0.371794 0.370645 0.369762
0.381905 0.380869 0.380111
0.392017 0.391093 0.39046
0.402128 0.401318 0.400809
0.41224 0.411542 0.411158
0.422351 0.421766 0.421507
0.432462 0.43199 0.431856
0.442574 0.442215 0.442204
0.452685 0.452439 0.452553
0.462797 0.462663 0.462902
0.472908 0.472887 0.473251
0.483019 0.483112 0.4836
0.493131 0.493336 0.493949
0.503242 0.50356 0.504298
0.513354 0.513784 0.514647
0.523465 0.524009 0.524996
0.533576 0.534233 0.535345
0.543688 0.544457 0.545694
0.553799 0.554681 0.556043
0.563911 0.564906 0.566392
0.574022 0.57513 0.57674
0.584134 0.585354 0.587089
0.594245 0.595578 0.597438
0.604356 0.605803 0.607787
0.614468 0.616027 0.618136
0.639746 0.641588 0.644008

IsoValue IsoValue IsoValue


0.116316 0.112577 0.108025
0.131899 0.12834 0.123994
0.142287 0.138849 0.13464
0.152676 0.149358 0.145286
0.163064 0.159867 0.155932
0.173453 0.170375 0.166578
0.183841 0.180884 0.177224
0.194229 0.191393 0.18787
0.204618 0.201902 0.198516
0.215006 0.212411 0.209162
0.225395 0.22292 0.219808
0.235783 0.233429 0.230454
0.246172 0.243938 0.2411
0.25656 0.254446 0.251745
0.266949 0.264955 0.262391
0.277337 0.275464 0.273037
0.287726 0.285973 0.283683
0.298114 0.296482 0.294329
0.308502 0.306991 0.304975
0.318891 0.3175 0.315621
0.329279 0.328008 0.326267
0.339668 0.338517 0.336913
0.350056 0.349026 0.347559
0.360445 0.359535 0.358205
0.370833 0.370044 0.368851
0.381222 0.380553 0.379497
0.39161 0.391062 0.390143
0.401999 0.401571 0.400789
0.412387 0.412079 0.411435
0.422775 0.422588 0.422081
0.433164 0.433097 0.432727
0.443552 0.443606 0.443373
0.453941 0.454115 0.454019
0.464329 0.464624 0.464665
0.474718 0.475133 0.475311
0.485106 0.485642 0.485957
0.495495 0.49615 0.496603
0.505883 0.506659 0.507248
0.516272 0.517168 0.517894
0.52666 0.527677 0.52854
0.537048 0.538186 0.539186
0.547437 0.548695 0.549832
0.557825 0.559204 0.560478
0.568214 0.569713 0.571124
0.578602 0.580221 0.58177
0.588991 0.59073 0.592416
0.599379 0.601239 0.603062
0.609768 0.611748 0.613708
0.620156 0.622257 0.624354
0.646127 0.648529 0.650969

IsoValue IsoValue IsoValue


0.104931 0.100457 0.0986249
0.121058 0.116779 0.115063
0.131809 0.127661 0.126022
0.14256 0.138542 0.13698
0.153312 0.149424 0.147939
0.164063 0.160305 0.158898
0.174815 0.171186 0.169857
0.185566 0.182068 0.180815
0.196317 0.192949 0.191774
0.207069 0.20383 0.202733
0.21782 0.214712 0.213692
0.228571 0.225593 0.22465
0.239323 0.236475 0.235609
0.250074 0.247356 0.246568
0.260826 0.258237 0.257526
0.271577 0.269119 0.268485
0.282328 0.28 0.279444
0.29308 0.290882 0.290403
0.303831 0.301763 0.301361
0.314582 0.312644 0.31232
0.325334 0.323526 0.323279
0.336085 0.334407 0.334237
0.346837 0.345289 0.345196
0.357588 0.35617 0.356155
0.368339 0.367051 0.367114
0.379091 0.377933 0.378072
0.389842 0.388814 0.389031
0.400593 0.399696 0.39999
0.411345 0.410577 0.410949
0.422096 0.421458 0.421907
0.432848 0.43234 0.432866
0.443599 0.443221 0.443825
0.45435 0.454102 0.454783
0.465102 0.464984 0.465742
0.475853 0.475865 0.476701
0.486605 0.486747 0.48766
0.497356 0.497628 0.498618
0.508107 0.508509 0.509577
0.518859 0.519391 0.520536
0.52961 0.530272 0.531494
0.540361 0.541154 0.542453
0.551113 0.552035 0.553412
0.561864 0.562916 0.564371
0.572616 0.573798 0.575329
0.583367 0.584679 0.586288
0.594118 0.595561 0.597247
0.60487 0.606442 0.608205
0.615621 0.617323 0.619164
0.626372 0.628205 0.630123
0.653251 0.655408 0.65752

Figure 11.1: Transient phase of the flow from the initial uniform flow. Isocontours of density for the
18 first time iterations.
11.4. NUMERICAL EXPERIMENTS 119

IsoValue IsoValue
0.107896 21.7117
0.124807 30.3306
0.13608 36.0765
0.147354 41.8224
0.158628 47.5683
0.169902 53.3142
0.181175 59.0601
0.192449 64.806
0.203723 70.552
0.214996 76.2979
0.22627 82.0438
0.237544 87.7897
0.248818 93.5356
0.260091 99.2815
0.271365 105.027
0.282639 110.773
0.293912 116.519
0.305186 122.265
0.31646 128.011
0.327733 133.757
0.339007 139.503
0.350281 145.249
0.361555 150.995
0.372828 156.741
0.384102 162.487
0.395376 168.232
0.406649 173.978
0.417923 179.724
0.429197 185.47
0.440471 191.216
0.451744 196.962
0.463018 202.708
0.474292 208.454
0.485565 214.2
0.496839 219.946
0.508113 225.692
0.519387 231.437
0.53066 237.183
0.541934 242.929
0.553208 248.675
0.564481 254.421
0.575755 260.167
0.587029 265.913
0.598303 271.659
0.609576 277.405
0.62085 283.151
0.632124 288.897
0.643397 294.642
0.654671 300.388
0.682855 314.753

Figure 11.2: Isocontours of density and pressure for the steady state solution.

IsoValue IsoValue
225.72 232.705
232.752 237.299
237.44 241.893
242.128 246.487
246.816 251.082
251.503 255.676
256.191 260.27
260.879 264.864
265.567 269.458
270.255 274.053
274.943 278.647
279.631 283.241
284.319 287.835
289.007 292.43
293.695 297.024
298.383 301.618
303.071 306.212
307.759 310.806
312.447 315.401
317.135 319.995
321.823 324.589
326.511 329.183
331.199 333.778
335.887 338.372
340.575 342.966
345.263 347.56
349.951 352.154
354.639 356.749
359.327 361.343
364.015 365.937
368.703 370.531
373.391 375.126
378.079 379.72
382.767 384.314
387.455 388.908
392.143 393.502
396.831 398.097
401.519 402.691
406.207 407.285
410.895 411.879
415.583 416.473
420.271 421.068
424.959 425.662
429.647 430.256
434.335 434.85
439.023 439.445
443.711 444.039
448.399 448.633
453.087 453.227
464.807 457.821

Figure 11.3: Isocontours of the temperature for the steady state solution.
120 CHAPTER 11. GAS DYNAMICS

Figure 11.4: Velocity field for the steady state.

Figure 11.5: Triangular initial and final mesh at the end of computation. The freefem++ command
adaptmesh was used for mesh refinement.
11.4. NUMERICAL EXPERIMENTS 121

IsoValue IsoValue
-0.0229276 -20.6079
0.0260594 11.5385
0.0587174 32.9694
0.0913755 54.4003
0.124033 75.8311
0.156692 97.262
0.18935 118.693
0.222008 140.124
0.254666 161.555
0.287324 182.986
0.319982 204.416
0.35264 225.847
0.385298 247.278
0.417956 268.709
0.450614 290.14
0.483272 311.571
0.51593 333.002
0.548588 354.433
0.581246 375.864
0.613904 397.295
0.646562 418.725
0.67922 440.156
0.711878 461.587
0.744536 483.018
0.777194 504.449
0.809852 525.88
0.84251 547.311
0.875168 568.742
0.907826 590.173
0.940484 611.603
0.973142 633.034
1.0058 654.465
1.03846 675.896
1.07112 697.327
1.10377 718.758
1.13643 740.189
1.16909 761.62
1.20175 783.051
1.23441 804.481
1.26706 825.912
1.29972 847.343
1.33238 868.774
1.36504 890.205
1.3977 911.636
1.43035 933.067
1.46301 954.498
1.49567 975.929
1.52833 997.359
1.56099 1018.79
1.64263 1072.37

Figure 11.6: Isocontours of density and pressure for the steady state solution with infinite Mach num-
ber equal to 4.

IsoValue IsoValue
72.9873 90.2647
90.3807 101.628
101.976 112.992
113.572 124.356
125.167 135.719
136.763 147.083
148.359 158.447
159.954 169.81
171.55 181.174
183.145 192.538
194.741 203.901
206.336 215.265
217.932 226.629
229.528 237.992
241.123 249.356
252.719 260.72
264.314 272.083
275.91 283.447
287.506 294.811
299.101 306.174
310.697 317.538
322.292 328.902
333.888 340.265
345.483 351.629
357.079 362.993
368.675 374.356
380.27 385.72
391.866 397.084
403.461 408.447
415.057 419.811
426.653 431.175
438.248 442.538
449.844 453.902
461.439 465.266
473.035 476.629
484.63 487.993
496.226 499.357
507.822 510.72
519.417 522.084
531.013 533.448
542.608 544.811
554.204 556.175
565.799 567.539
577.395 578.903
588.991 590.266
600.586 601.63
612.182 612.994
623.777 624.357
635.373 635.721
664.362 647.085

Figure 11.7: Isocontours of the temperature for the steady state solution with infinite Mach number
equal to 4.
122 CHAPTER 11. GAS DYNAMICS

Figure 11.8: Velocity field for the steady state with infinite Mach number equal to 4.
Chapter 12

Fluid Mechanics and heat transfer

Fluid Mechanics and Heat Transfer are of fundamental interest for the engineering of energy conver-
sion systems. Main of the energy conversion system use a working fluid that transports the heat. This
is the case the nuclear power system for refrigerators, cooling devices, air conditioning, etc.

As an example, we will consider here a compressible fluid that flows in a heating pipe. We will
suppose the fluid as weakly compressible with a density that depends on the temperature ρ = ρ(θ)
with
∂ρ
<0 (12.1)
∂θ
meaning that the fluid is lighter when is it heated. Then we will take into account the gravity. Due
to Archimedes’ buoyancy principle, the lighter heated fluid will tend to go upward with appearance
of Rayleigh-Taylor instabilities at the bottom thermal layer. That’s we want to investigate by the
numerical simulation.

12.1 Model assumptions


Because the fluid is assumed to be weakly compressible, we keep the zero-divergence assumption on
the velocity field, i.e.
∇ · u = 0. (12.2)
The fluid is supposed to be Newtonian, the momentum equation then gives the standard Navier-Stokes
equations with gravity as external volume force:
1
∂t u + u · ∇u − ν∆u + ∇p = g (12.3)
ρ(θ)
where ν is the kinematic viscosity of the fluid. The fluid is supposed to be thermally conductive with
constant coefficient κ. The balance equation of energy can be written as an equation of evolution of
the temperature. It can be reasonably approximated as a convection-diffusion equation
ρ cp ∂t θ + ρcp u · ∇θ − ∇ · (κ∇θ) = 0 (12.4)
where cp is the specific heat at constant pressure. For low compressible fluids, the density in (12.5) is
approximated by a constant ρ0 .
ρ0 cp ∂t θ + ρ0 cp u · ∇θ − ∇ · (κ∇θ) = 0 (12.5)

123
124 CHAPTER 12. FLUID MECHANICS AND HEAT TRANSFER

On the other hand, we keep the dependency of ρ on θ in (12.3) even if density variations are small in
order to evidence the buoyant force due to lighter heated fluid. So we need a closure for θ 7→ ρ(θ).
We will use the linearized law on the specific volume τ = 1/ρ:

τ = τ0 + β(θ − θ0 ) (12.6)

for some constants τ0 , θ0 and β > 0. Using (12.6), for β > 0, the inequality (1.1) is satisfied.

12.1.1 Dimensionless equations


It is always interesting to derive dimensionless equations for parameter analysis and systematic study
of all kind of solutions. From the engineering point of view, dimensionless numbers are of main
importance for system design. We will consider the symbol ⋆ for dimensionless variables and 0 index
for dimensioning constants. Considering,

t⋆ x⋆ u⋆ ν⋆ ρ⋆ g⋆ κ⋆
t= , x= , u= , ν= , ρ= , g= , κ= ,
T0 L0 U0 ν0 ρ0 g0 κ0
from (12.2),(12.3) and (12.4) we respectively get
U0 ⋆ ⋆
∇ · u = 0,
L0
U0 U0 ν 0 U0 1 p0 ⋆ ⋆
∂t⋆ u⋆ + 2 u⋆ · ∇⋆ u⋆ − 2 ∆⋆ u⋆ + ∇ p = g0 g ⋆ ,
T0 L0 L0 ρ 0 ρ⋆ L 0
θ0 U 0 θ0 ⋆ κ0 θ 0
ρ0 cp ∂t⋆ θ⋆ + ρ0 cp u · ∇⋆ θ⋆ − 2 ∇⋆ · (κ⋆ ∇⋆ θ⋆ ) = 0.
T0 L0 L0

If both time and pressure scales are chosen such that


L0
T0 = , p0 = ρ0 U02 , (12.7)
U0
then we get the following equations (forgetting the ⋆ symbol for brevity’s sake)

∇ · u = 0,
ν0 U0 1 L0 g 0
∂t u + u · ∇u − ∆u + ∇p = g,
L0 ρ U02
κ0
∂t θ + u · ∇θ − ∇ · (κ∇θ) = 0.
ρ0 U0 cp L0

There are three dimensionless numbers. The Reynolds number


L0
Re = (12.8)
ν0 U0
involves the spatial scale, the fluid velocity and the kinematic viscosity. The Prandtl number
ρ0 ν 0 c p
Pr = (12.9)
κ0
12.2. MATHEMATICAL PROBLEM 125

shows the importance of thermal conductivity with respect to the other effects. Finally the ratio

L0 g 0
(12.10)
U0
gives the importance of the source term scale with respect to the spatial scale and the velocity scale.
In what follows, we will consider g0 = U02 /L0 so that the dimensionless equations are written

∇ · u = 0, (12.11)
1 1
∂t u + u · ∇u − ∆u + ∇p = g, (12.12)
Re ρ(θ)
1 1
∂t θ + u · ∇θ − ∇ · (κ∇θ) = 0 (12.13)
Re P r
or in Lagrangian form

∇ · u = 0, (12.14)
Du 1 1
− ∆u + ∇p = g, (12.15)
Dt Re ρ(θ)
Dθ 1 1
− ∇ · (κ∇θ) = 0 (12.16)
Dt Re P r

12.1.2 Boundary conditions


We are interested in a fluid flowing into a duct with a heating wall. We consider a two dimensional
geometry as plotted in figure 12.1. The computational domain is a rectangle Ω of respective lengths
Lx and Ly . Left and right borders correspond to the inlet and the outlet. The four edges Γin , ΓT , ΓB
and Γout respectively represent the inflow border, the top wall boundary, the bottom wall boundary
and the outflow boundary. At the inlet, a constant temperature θin is imposed. We also consider a
steady state Poiseuille flow with parabolic velocity profile uin . Let us recall that the Poiseuille flow is
the stationary laminar flow between two infinite plates for which one can derive an analytical solution
of the Navier-Stokes equations with parabolic velocity profile.
At the outlet Γout , homogeneous Neumann boundary conditions are imposed for both velocity and
temperature. At the top wall boundary ΓT , a no slip boundary condition with zero velocity is imposed
for the fluid. A zero heat flux is also consider (adiabatic wall). At the bottom boundary ΓB , a no slip
boundary condition is imposed for velocity and a constant nonzero heat flux provides the heat to the
fluid:
∂θ
κ = Φ on ΓB . (12.17)
∂n

12.2 Mathematical problem


For initial conditions, the fluid is supposed to flow according to the laminar Poiseuille steady flow. For
compatibility between initial condition and inflow we consider the initial condition in velocity

u = uin in Ω. (12.18)
126 CHAPTER 12. FLUID MECHANICS AND HEAT TRANSFER

Figure 12.1: Schematic of the spatial domain Ω with boundary conditions

The initial temperature field will be assumed constant, equal to the inflow temperature:

θ = θin in Ω. (12.19)

We summarize here the whole mathematical time-dependent initial boundary value problem:

∇·u=0 in Ω × (0, T ), (12.20)


1 1
Dt u − ∆u + ∇p = g in Ω × (0, T ), (12.21)
Re ρ(θ)
1 1
Dt θ − ∇ · (κ∇θ) = 0 in Ω × (0, T ), (12.22)
Re P r
u(., t = 0) = uin in Ω, (12.23)

θ(., t = 0) = θin in Ω, (12.24)

u=0 on (ΓT ∪ ΓB ) × (0, T ), (12.25)

u = uin on Γin × [0, T ) (12.26)

θ = θin on Γin × [0, T ) (12.27)


∂u
=0 on Γout × [0, T ), (12.28)
∂n
∂θ
=0 on (ΓT ∪ Γout ) × [0, T ), (12.29)
∂n
∂θ
κ =Φ on ΓB × [0, T ). (12.30)
∂n
12.3. NUMERICAL DISCRETIZATION 127

12.3 Numerical discretization


12.3.1 Time discretization
First the partial differential equations are semi-discretized in time. As discussed in previous chap-
ters, total derivatives are discretized thanks to the method of characteristics. The nonlinear term is
discretized using a semi-implicit formula whereas the other linear terms are discretized implicitely:

∇ · un+1 = 0 in Ω, (12.31)
un+1 (x) − un ◦ X n (x) 1 1
− ∆un+1 + ∇pn+1 = g in Ω, (12.32)
∆t Re ρ(θn )
θn+1 (x) − θn ◦ X n (x) 1 1
∇ · κ∇θn+1 = 0

− in Ω, (12.33)
∆t Re P r
for n ∈ N and
u0 (x) = uin (x), θ0 (x) = θin , x ∈ Ω. (12.34)
With such a time discretization, it appears in (12.32) and (12.33) that there is separation of the un-
known variables un+1 (x) and θn+1 (x). Consequently, between two time steps tn and tn+1 , the
Navier-Stokes problem and the thermal problem can be solved separately.

12.3.2 Variational formulation


We are looking for a variational formulation of the problem with equations (12.31)-(12.34) and bound-
ary conditions (12.25) to (12.30). For the equation on temperature, there is no particular difficulty.
Considering the functional space

Vg = v ∈ H 1 (Ω), v = g on Γin ,

(12.35)

the problem is to find a temperature θn+1 ∈ Vθin such that, for all v ∈ V0 ,
Z n+1
θ (x) − θn ◦ X n (x) 1 1 1 1
Z Z
n+1 ,
v dx + κ∇θ · ∇v dx − Φv dx = 0. (12.36)
Ω ∆t Re P r Ω Re P r ΓB

12.4 Numerical experiments


12.4.1 freefem++ source code of the heat transfer problem

1 // ThermalConvection.edp (Freefem++)
2 // Forced + Natural heat convection in a pipe
3 // Navier−Stokes equations + convection− diffusion on themperature
4 //
5 real lx = 0.25;
6 real Lx = 3;
7 real Ly = 1;
8 real gravity = 9.81;
9 real thetain = 20;
10 real pout = 1;
11 real Cst = 1;
128 CHAPTER 12. FLUID MECHANICS AND HEAT TRANSFER

12 real uin0 = 0.2;


13 func uin = uin0 * 4*(y/Ly)*(1-y/Ly);
14 real HeatFlux = 100;
15 real dt = 0.1;
16 real nu = 0.001;
17 real kappa=0.001;
18 real t = 0, dtsnap = 0.5, ttosnap = 2;
19 //
20 border c1(t=0, lx){x=t; y=0;}
21 border c2(t=lx, Lx-lx){x=t;y=0;}
22 border c3(t=Lx-lx,Lx){x=t;y=0;}
23 border c4(t=0,Ly){x=Lx;y=t;}
24 border c5(t=Lx,0){x=t; y=Ly;}
25 border c6(t=Ly,0){x=0;y=t;}
26 //
27 mesh Th = buildmesh(c1(10)+c2(200)+c3(10)+c4(30)
28 +c5(100)+c6(30));
29 plot(Th, wait=0, ps="Mesh.eps");
30 //
31 fespace Uh(Th, P1b);
32 Uh u, v, uold, vold, uh, vh; // Velocity fields
33 fespace Xh(Th, P1);
34 Xh p, ph, theta, thetaold, thetah; // Temperate and pressure fields
35 Xh tau; // = 1/rho ( specific volume);
36 //
37 // Field initialization
38 u = uin;
39 v = 0;
40 theta = thetain;
41 uold = u; vold = v; thetaold = theta;
42 // Heat problem
43 problem HeatStep(theta, thetah) =
44 int2d(Th) (theta*thetah/dt)
45 -int2d(Th)(convect([u,v], -dt, thetaold)*thetah/dt)
46 +int2d(Th)(kappa*dx(theta)*dx(thetah)
47 +kappa*dy(theta)*dy(thetah))
48 -int1d(Th, c2)(kappa*HeatFlux*thetah)
49 +on(c6, theta=thetain);
50 //
51 problem NavierStokesStep([u, v, p], [uh, vh, ph]) =
52 int2d(Th)(u*uh/dt)
53 - int2d(Th)(convect([uold, vold], -dt, uold)*uh/dt )
54 + int2d(Th)(nu*dx(u)*dx(uh)+nu*dy(u)*dy(uh))
55 + int2d(Th) (tau * dx(p)*uh)
56 + int2d(Th)(v*vh/dt)
57 - int2d(Th)(convect([uold, vold], -dt, vold)*vh/dt )
58 + int2d(Th)(nu*dx(v)*dx(vh)+nu*dy(v)*dy(vh))
59 + int2d(Th)(tau * dy(p)*vh)
60 + int2d(Th)(gravity*vh)
61 + int2d(Th)( dx(u)*ph + dy(v)*ph )
62 + on(c6, u=uin, v=0)
63 + on(c1, c2, c3, c5, u=0, v=0);
12.4. NUMERICAL EXPERIMENTS 129

64 // Time steps
65 for (int it=0; it<150; it++) {
66 t = t + dt;
67 HeatStep;
68 thetaold = theta;
69 tau = Cst * theta;
70 NavierStokesStep;
71 uold = u; vold = v;
72 // plot ([u, v]) ;
73 // Th = adaptmesh(Th);
74 // u = u; v = v; uold = uold; vold = vold;
75 // theta = theta ; thetaold = thetaold ;
76 plot([u,v], theta, nbiso = 80, value=0);
77 if (t>=ttosnap) {
78 ttosnap = ttosnap + dtsnap;
79 plot([u,v], theta, nbiso = 80, value=0,
80 ps="field_t="+t+".eps");
81 }
82 }
130 CHAPTER 12. FLUID MECHANICS AND HEAT TRANSFER

12.4.2 Numerical results

Figure 12.2: Snapshots of the velocity field (arrows) and temperature field (isocontours) at successive
instants t = 2 s, t = 4s, t = 5.1s and t = 5.6s.
12.4. NUMERICAL EXPERIMENTS 131

Figure 12.3: Snapshots of the velocity field (arrows) and temperature field (isocontours) at successive
instants t = 6.1 s, t = 6.6s, t = 7.1s and t = 7.6s.
132 CHAPTER 12. FLUID MECHANICS AND HEAT TRANSFER

Figure 12.4: Snapshots of the velocity field (arrows) and temperature field (iso-contours) at successive
instants t = 8.1 s, t = 8.6s, t = 9.1s and t = 9.6s.
Chapter 13

Stochastic diffusion processes,


Fokker-Planck equations

This chapter is a short introduction to the stochastic problems. Some physical systems intrinsically
include stochastic effects due to the inherent noise. Moreover, for real applications it is usual to have
inexact knowledge of initial conditions or boundary conditions. Thus, an initial state can be seen as a
random variable. Each integral path can evolve in a different way because of random fluctuations in
the system. In the theory of stochastic differential system and Markov diffusion processes, it is shown
that the probability density function of the stochastic process is solution of a partial differential equa-
tion, namely the Fokker-Planck equation which is a (possibly high-dimensional) convection-diffusion
equation. The scope of this chapter is only limited to the computational aspects of the numerical
solution of either stochastic differential equations or Fokker-Planck equations. The reader who is in-
terested in the theoretical derivation of the Fokker-Planck equation can refer to the important literature
on this subject like [], [] or [].

13.1 Ordinary and Stochastic differential equations


A deterministic dynamical system is written

dx
= u(x), (13.1)
dt

where x(t) ∈ Rd and u : Rd → Rd is a vector field (here supposed not depend on time itself). For
well-posedness, we add to (13.1) an initial condition

x(t = 0) = x0 ∈ Rd (13.2)

and suppose that u is Lipschitz-continuous: there exists a Lipschitz constant L > 0 such that

||u(x) − u(x′ )|| ≤ ||x − x′ || ∀x, x′ ∈ Rd . (13.3)

In the case of a “non completely” known dynamical system, we have to model the uncertainty in some
sense. For example the initial state x0 if replaced by a random variable X. This random variable is
completely defined by its density probability function (or PDF) p(X). Of course this needs a closure

133
134 CHAPTER 13. STOCHASTIC DIFFUSION PROCESSES, FOKKER-PLANCK EQUATIONS

subject to some constraints. For example one can expect that


Z
E(X) = x p(x) dx = x0 (13.4)
Rd

where the expectation value x0 is known and the covariance matrix C with elements
Cij (X) = E [(xi − E(xi ))(xj − E(xj ))] (13.5)
is also known.
Now, when the system is subject to some random fluctuations during time, the way to rigorously
write the governing equation is a stochastic differential equation in the form
dX(t) = u(X(t)) dt + σ(X(t)) dB(t) (13.6)
where (X(t), t ≥ 0) now denotes a stochastic diffusion process with drift u, B in (13.5) maps Rd
to Md×p and B(t) denotes p-dimensional brownian motion. The matrix-valued function σ is also
supposed to be Lipschitz continuous. Below we will denote p(x, t) the probability density function at
state x and time t.

13.2 Fokker-Planck equations


The theory (see for example []) states that p is solution of a partial differential equation:
Theorem 5 (Fokker-Planck equations). Let us denote by p0 (x) the probability density function of the
random variable X. If the probability density function p(x, t) of the stochastic process (X(t), t ≥ 0)
has sufficient regularity, then it is solution of the Fokker-Planck problem
d d
∂p X ∂ 1 X ∂2
+ (uj (x)p) − (aij (x) p) = 0 ∀x ∈ Rn , t ≥ 0, (13.7)
∂t ∂xj 2 ∂xi ∂xj
j=1 i,j=1

p(x, t = 0) = p0 (x) almost surely in x, (13.8)


where
p
X
aij (x) = σik (x)σjk (x). (13.9)
k=1

What is remarkable here is that the “space” variable x is in with a dimension d that can be of
course big. Fokker-Planck equations naturally are high-dimensional PDEs. This feature makes their
numerical solution especially hard once d is greater than four.
Let us show that the Fokker-Planck equation is actually a standard convection-diffusion equation.
First denote A(x) = σ(x)σ(x)T ∈ Md×d . We have (using Einstein’s index summation)
∂i (∂j (aij (x) p)) = ∂i [aij,j (x) p + aij (x) p,j ]

= ∇x · (A(x) ∇p) + ∂i (aij,j (x) p) .


Therefore, denoting by v(x) the vector field defined by
d
1 X ∂aij
vi (x) = ui (x) − (x), (13.10)
2 ∂xj
j=1
13.3. COMPUTATIONAL APPROACHES BASED ON STOCHASTIC DIFFERENTIAL EQUATIONS135

the Fokker-Planck equation is written

∂p 1
+ ∇x · (v(x) p) − ∇x · (A(x)∇p) = 0, (13.11)
∂t 2
this is a linear high-dimensional convection-diffusion equation with symmetric positive variable coef-
ficient diffusion tensor A(x).
In the next sections, we are going to see how to solve these problem numerically.

13.3 Computational approaches based on Stochastic Differential Equa-


tions
For high-dimensional problems, it more convenient to integrate the SDE. The stochastic extension of
the Euler integration scheme is named the Euler-Maruyama approximation ([]): from a time instant
tn , a random variable X n at time tn , ∆t a time step, one computes the stochastic discrete process
(X n , n ∈ N)

X n+1 = X n + ∆t u(X n ) + ∆t σ(X n ) (B n+1 − B n ), n ∈ N, (13.12)

with initial random variable


X 0 = X. (13.13)

In (13.12), the random variables B n are p-dimensional independent variables with components B1n , B2n ,
. . . , Bpn which are N (0, 1) independent normally distributed random variables.

13.3.1 Monte-Carlo methods


The expressions (13.12),(13.13) are still theoretical. In order to have practical computations, some
realizations of these random variables are needed. Particle Monte-Carlo methods [] consist of the di-
rect numerical simulation of a certain number M of sample paths (also referred to as particles) using
M realizations of the initial random variable X and M discrete realization of the stochastic process
(X n , n ∈ N), also involving M realizations of the p-dimensional Gaussian variables B n , n ∈ N.

Monte-Carlo methods clearly are independent of the dimension of the problem what makes particu-
larly attractive for high-dimensional problems. Unfortunately, it is known that these methods suffer
from a lack of accuracy and anyway require a large number of realizations to get statistically accurate
results.

13.4 Numerical solution of the Fokker-Planck equations


For d = 1, 2 or 3, the Fokker-Planck equation (13.11) can be discretized using standard Finite element
or Finite Volume methods. This kind of discretization leads to much more accurate methods than
Monte-Carlo. Introducing the total derivative

D ∂
= + v(x) · ∇x , (13.14)
Dt ∂t
136 CHAPTER 13. STOCHASTIC DIFFUSION PROCESSES, FOKKER-PLANCK EQUATIONS

equation (13.11) can be written


Dp 1
+ p (∇ · v) − ∇ · (A(x)∇p) = 0. (13.15)
Dt 2
A semi-discretization of this equation gives, as already discussed in previous chapters

pn+1 (x) − pn ◦ X n (x) 1


+ pn+1 (x)(∇ · v)(x) − ∇ · (A(x)∇pn+1 (x)) = 0 ∀x ∈ Rd . (13.16)
∆tn 2
For spatial discretization, we need to restrict the state space Rd to a bounded domain. What is generally
chosen is a truncation rectangular domain with boundaries far enough such that the probability density
is close to zero on the artificial boundary, for all time t ≥ 0.

13.4.1 Boundary conditions


Equation (13.11) is clearly a conservation equation because of the form
∂p
+ ∇x · J = 0 (13.17)
∂t
with a probability flux J composed of a convective flux

J c (x) = v(x) p (13.18)

and a diffusive flux


1
J d (x) = − A(x)∇p. (13.19)
2
This conservation principle is necessary to guarantee the “mass” is conserved, i.e.
d
Z
p(x, t) dx = 0. (13.20)
dt Rd
Now, if the computational domain is restricted to bounded domain Ω, we need to satisfy the same
equation (13.19). By integrating equation (13.17) over Ω and applying Green’s formula, we get
d
Z Z
p(x, t) dx + J · n dγ = 0, (13.21)
dt Rd ∂Ω

where n is the standard exterior unit vector to Ω. So a natural boundary condition is zero flux condition
J · n = 0 to ensure mass conservation, i.e.
1
(v · n) p − (A(.)∇p) · n = 0 on ∂Ω (13.22)
2
which is a generalized Robin boundary condition. To summarize, now we have to solve by Finite
Elements the spatial problem

pn+1 − pn ◦ X n 1
+ pn+1 (∇ · v) − ∇ · (A∇pn+1 ) = 0 in Ω, (13.23)
∆tn 2
1
(v · n) pn+1 − A∇pn+1 · n = 0 on ∂Ω.

(13.24)
2
13.5. NUMERICAL EXAMPLE : METABOLITE REACTIONS 137

Therefore, a variational problem in the H 1 (Ω) Sobolev space is formulated as follows: find pn+1 ∈
H 1 (Ω) such that, for all q ∈ H 1 (Ω),

pn+1 − pn ◦ X n
Z Z Z
n+1
q dx + (∇ · v) p q dx − (v · n) pn+1 q dγ
Ω ∆tn Ω ∂Ω

1
Z
+ A∇pn+1 · ∇q dx = 0. (13.25)
2 Ω

Using conformal finite elements with a finite element discrete space V h ⊂ H 1 (Ω), the discrete prob-
lem to solve is to find ph,n+1 ∈ V h such that

ph,n+1 − ph,n ◦ X n h
Z Z Z
h,n+1 h
q dx + (∇ · v) p q dx − (v · n) ph,n+1 q h dγ
Ωh ∆tn Ωh ∂Ωh

1
Z
+ A∇ph,n+1 · ∇q h dx = 0 ∀q h ∈ V h . (13.26)
2 Ωh

13.5 Numerical example : metabolite reactions


Consider the following five reactions for the molecular species X and Y modeling the creation of two
metabolites controled by two enzymes, a reaction and their destruction:

k
X kY
∅ −→ X ∅ −→ Y
k2 xy
X + Y −→ ∅
µx µy
X −→ ∅ −→ ∅.

Without stochastic effects, according to the reaction rates, the deterministic system if differential equa-
tions that governs the molecular system is

dx
= kX − µx − k2 xy, (13.27)
dt
dy
= kY − µy − k2 xy (13.28)
dt

with x, y > 0. It is easy to check that this system has a unique stable equilibrium state in (R+ )2 .
For a biomolecular system, it is often not reasonable to assume that the biomolecular system evolve
continuous as a continuous medium because molecules like enzymes or metabolites are in too low
number and molecular collision arise with some noise. Here, because there are five reactions, there
are five independent noises that represent the uncertainty of molecular collision for each reaction.
Statistics theory states that the standard deviation on reaction rates is proportional to the square root
of the mean reaction rates. Thus, the stochastic differential system is written
p p p
dX = (kX − µX − k2 XY ) dt + kX dB1 (t) + µX dB3 (t) + k2 XY dB5 (t),(13.29)
p p p
dY = (kY − µY − k2 XY ) dt + kY dB2 (t) + µY dB4 (t) + k2 XY dB5 (t).(13.30)
138 CHAPTER 13. STOCHASTIC DIFFUSION PROCESSES, FOKKER-PLANCK EQUATIONS

Notice that the system (13.29),(13.30) is in the form (13.6) with

σ(t) = N W 1/2 , (13.31)

where W = diag (kX , kY , µx, µy, k2 xy) and N is the stoichiometric coefiicient matrix
 
1 0 1 0 1
N= , (13.32)
0 1 0 1 1

That gives the following diffusion tensor A


 
kX + µx + k2 xy k2 xy
A(x) = . (13.33)
k2 xy kY + µy + k2 xy

For numerical experiments, we will use the following coefficients: kX = kY = 0.6, µ = k2 = 0.001.
The truncated state domain Ω = {0 ≤ x, y ≤ 200} will be used.

13.5.1 Scilab source code of the Monte Carlo approach

1 // Metobilte . sce ( Scilab )


2 // Simple stochastic metabolite reaction model
3 //
4 // Numerical solution using the Maruyama−Euler scheme.
5 // Monte−Carlo approach.
6 clear;
7 kx = 0.6; ky=kx;
8 mu = 0.001;
9 k2 = 0.001;
10 N = 5000;
11 Deltat = 0.05;
12 sqdt = sqrt(Deltat);
13 X = zeros(2,N);
14 //
15 // Initial cloud (N realisation of the
16 // initial random state )
17 X(1,:) = 140 + 5*rand(1,N, "normal");
18 X(2,:) = 160 + 5*rand(1,N, "normal");
19 clf(); plot(X(1,:), X(2,:), ’o’);
20 plot([0, 200], [0,200], ’.w’); xgrid();
21 xtitle("Initial Probability Density Function");
22 xlabel("X");ylabel("Y"); drawnow();
23 // stop ;
24 //
25 // Time loop
26 //
27 Bnold = sqdt*rand(5,N, "normal");
28 //
29 for it=1:2000
30 Bn = sqdt*rand(5,N, "normal");
31 // Euler
32 dX = (kx-mu*X(1,:)-k2*X(1,:).*X(2,:))*Deltat + ...
13.5. NUMERICAL EXAMPLE : METABOLITE REACTIONS 139

33 sqrt(kx).*(Bn(1,:)-Bnold(1,:)) ...
34 +sqrt(mu*X(1,:)) .*(Bn(3,:)-Bnold(3,:)) ...
35 +sqrt(k2*X(1,:).*X(2,:)) .*(Bn(5,:)-Bnold(5,:)) ;
36 //
37 dY = (ky-mu*X(2,:)-k2*X(1,:).*X(2,:))*Deltat + ...
38 sqrt(ky).*(Bn(2,:)-Bnold(2,:)) ...
39 +sqrt(mu*X(2,:)) .*(Bn(4,:)-Bnold(4,:)) ...
40 +sqrt(k2*X(1,:).*X(2,:)) .*(Bn(5,:)-Bnold(5,:)) ;
41 Bnold = Bn;
42 X = X + [dX; dY];
43 if ~modulo(it,100)
44 drawlater();
45 clf(); plot(X(1,:), X(2,:), ’o’);xgrid();
46 plot([0, 200], [0,200], ’.w’);
47 xtitle("Probability Density Function");
48 xlabel("X");ylabel("Y"); drawnow();
49 drawnow();
50 end;
51 end; // for it

13.5.2 Numerical results of the Monte-Carlo method

Initial Probability Density Function

200

180

160

140

120
Y

100

80

60

40

20

0
0 20 40 60 80 100 120 140 160 180 200
X

Figure 13.1: Monte-Carlo approach. N = 20000 realizations of the initial random variable are com-
puted.

13.5.3 freefem++ source of the Fokker-Planck solver

1 // Fokker.edp (Freefem++)
2 // Fokker−Planck equations,
3 // Simple stochastic metabolite reaction model
4 //
140 CHAPTER 13. STOCHASTIC DIFFUSION PROCESSES, FOKKER-PLANCK EQUATIONS

Probability Density Function

200

180

160

140

120
Y

100

80

60

40

20

0
0 20 40 60 80 100 120 140 160 180 200
X

Figure 13.2: Monte-Carlo approach. Monte-Carlo particles in the state space during the transient
transport phase.

Probability Density Function

200

180

160

140

120
Y

100

80

60

40

20

0
0 20 40 60 80 100 120 140 160 180 200
X

Figure 13.3: Monte-Carlo approach. Monte-Carlo particles in the state space at the statistically steady
state.

5 real kx = 0.6;
6 real ky = kx;
7 real mu = 0.001;
8 real k2 = 0.001;
9 real dt = 0.1;
13.5. NUMERICAL EXAMPLE : METABOLITE REACTIONS 141

10 //
11 real Lx = 200, Ly = 200;
12 mesh Th = square(60, 60, [x*Lx, y*Ly]);
13 fespace Vh(Th, P2); fespace Wh(Th,P1);
14 Vh p, qh, pold;
15 Wh v1h, v2h;
16 func a11 = kx + mu*x+k2 * x*y;
17 func a12 = k2*x*y;
18 func a21 = k2*x*y;
19 func a22 = ky+mu*y+k2 * x*y;
20 func v1 = (kx-mu*x-k2*x*y) - 0.5 * (mu+k2*y +k2*x);
21 func v2 = (ky-mu*y-k2*x*y) - 0.5 * (k2*y +mu+k2*x);
22 func dxv1 = - mu - k2*y - 0.5 * k2;
23 func dyv2 = - mu - k2*x -0.5 * k2;
24 //
25 v1h=v1; v2h=v2; plot([v1h, v2h], ps="Velocity.eps");
26 // Initializing the initial PDF
27 real sigma = 5, sigma2=sigma^2;
28 p = exp(-0.5*(x-140)^2/sigma2)*exp(-0.5*(y-160)^2/sigma2);
29 Th = adaptmesh(Th, p); p =p;
30 real massp = int2d(Th)(p); p = p / massp;
31 pold = p;
32 plot(p, nbiso=60, ps="initial.eps");
33 plot(p, Th, nbiso=60, ps="initialmesh.eps");
34 //
35 problem fokker(p, qh) =
36 int2d(Th)(p*qh/dt)
37 - int2d(Th)(convect([v1, v2], -dt, pold)*qh/dt)
38 +int2d(Th)(0.5*a11*dx(p)*dx(qh)+0.5*a22*dy(p)*dy(qh))
39 +int2d(Th)(0.5*a12*dy(p)*dx(qh)+0.5*a21*dx(p)*dy(qh))
40 - int1d(Th, 1,2,3,4)((v1*N.x+v2*N.y)*p*qh)
41 +int2d(Th)( (dxv1+dyv2)*p*qh );
42 //
43 int it;
44 for (it=0; it<200; it++) {
45 fokker; massp = int2d(Th)(p); p = p /massp; pold = p;
46 fokker; massp = int2d(Th)(p); p = p /massp; pold = p;
47 fokker; massp = int2d(Th)(p); p = p /massp; pold = p;
48 fokker; massp = int2d(Th)(p); p = p /massp; pold = p;
49 fokker; massp = int2d(Th)(p); p = p /massp; pold = p;
50 Th = adaptmesh(Th, p);
51 massp = int2d(Th)(p); p = p /massp; pold = p;
52 plot(p, Th, nbiso=60);
53 cout << "*** Mass = " << int2d(Th)(p) << endl;
54 }
55 plot(p, nbiso=40, ps="transient"+it+".eps");
56 plot(p, Th, nbiso=40, ps="transientmesh"+it+".eps");

13.5.4 Numerical results with the Fokker-Planck model


142 CHAPTER 13. STOCHASTIC DIFFUSION PROCESSES, FOKKER-PLANCK EQUATIONS

Figure 13.4: Velocity field in the state space.

Figure 13.5: Initial probability density function. The mesh was adapted according to the initial data.
13.5. NUMERICAL EXAMPLE : METABOLITE REACTIONS 143

Figure 13.6: Probability density function during the transient regime. Mesh adaptation is performed
during simulation.

Figure 13.7: Discrete probability density function at steady state.


144 CHAPTER 13. STOCHASTIC DIFFUSION PROCESSES, FOKKER-PLANCK EQUATIONS
Chapter 14

Multiphase flows

Multiphase flows are probably the flows of most interest in Fluid Engineering. Multiphase arise in
almost all fluid-based engineering process: petroleum pipe flows, plastics molding industry, pollutant
treatment, gas transportation in giant gas burner, power generators, engines, propulsion, etc.
As a matter of fact, theses kinds of flows are particularly hard to numerically model because of
some features: complex Physics but also free boundaries, phase change, big density ratios, etc.
Free boundary is an important feature. There are many ways to track free boundaries at the nu-
merical point of view : level set methods, volume of fluid methods, meshless particle methods, etc.
As an introduction, we will consider in this chapter a simple method which ...
As examples, we will consider two applications. The first one is a liquid sloshing in a closed box.
Of course, the simplicity of the front tracking method presented here is compensated by numer-
ous drawbacks and numerical artefacts: loss of material mass, diffuse boundary, inaccuracy on free
boundary position. To improve the front tracking, we should use advanced computational method like
high-order accuracy level sets method or conservative volume of fluid methods. But this is largely
beyond the scope and goal of this course of this course.

14.1 Setting of the equations


Let us consider two Newtonian viscous incompressible immiscible fluids k = 1, 2 with respective
(constant) density ρk , k = 1, 2 and constant dynamic viscosity µk , k = 1, 2. Let us consider a spatial
bounded domain Ω ⊂ Rd filled up by the two fluids. Although each fluid is incompressible with
constant density. The whole density function defined on the whole domain Ω can be seen as a function
of space and time
ρ(x, t) = ρ1 1(x∈Ωt1 ) (x) + ρ2 1(x∈Ωt2 ) (x) (14.1)
where Ωtk , k = 1, 2 is the volume occupied by the fluid k at time t in Ω. In the same way, we have for
the dynamic viscosity
µ(x, t) = µ1 1(x∈Ωt1 ) (x) + µ2 1(x∈Ωt2 ) (x). (14.2)
By also defining a velocity u and a pressure p on the whole domain Ω, under gravity g the flow is
governed by the Navier-Stokes equations

∂t ρ + ∇ · (ρu) = 0, (14.3)

∂t (ρu) + ∇ · (ρu ⊗ u) − ∇ · (µ∇u)) + ∇p = ρg. (14.4)

145
146 CHAPTER 14. MULTIPHASE FLOWS

The Navier-Stokes equations are in conservation form, i.e. in the form

∂t U + ∇ · F = S, (14.5)

with U = (ρ, u), F , F = (ρu, ρu ⊗ u − µ∇u + p I) and S = (0, ρg).

14.1.1 Transmission conditions, jump conditions


We have to understand if the equations intrinsically include the necessary transmission condition be-
tween the two fluids. The surface tension forces at fluid interface is neglected in this study.

Suppose that U is a piecewise C 1 function solution of (14.5). Let p = 1 + d and ϕ ∈ D(Ω). By


applying the Green formula, we have for any spatio-temporal domain D ∈ Ω × (0, T )
 
d
∂ϕ ∂ϕ
Z  X 
U· + Fj · − S · ϕ dx dt = 0. (14.6)
D ∂t ∂xj 
j=1

Now let Σ be the fluid interface between the two immiscible fluids, M be a point of Σ and D be a
small ball centered at M in the (x, t)-plane. We denote by D− and D+ the two open components of
D on each side of Σ (see figure 14.1. From (14.6), we also have

Figure 14.1: Jump transmission condition at fluid interface ((x, t)-plane).

d d
∂ϕ X ∂ϕ ∂ϕ X ∂ϕ
Z Z
{U · + Fj · − S · ϕ} dx dt + {U · + Fj · − S · ϕ} dx dt = 0. (14.7)
D− ∂t ∂xj D+ ∂t ∂xj
j=1 j=1

Suppose for instance that the normal vector n to the surface Σ points in D+ . Then, applying Green’s
formula in D+ and D− gives
d d
∂U X ∂F j
Z Z X
0 = − { + − S} · ϕ dx dt − {nt U + + nxj Fj+ } · ϕ ds
D + ∂t ∂xj
j=1 Σ∩D j=1

d d
∂U X ∂F j
Z Z X
− { + − S} · ϕ dx dt + {nt U − + nxj Fj− } · ϕ ds.
D− ∂t ∂xj Σ∩D
j=1 j=1
14.1. SETTING OF THE EQUATIONS 147

Since U is a classical solution of (14.5), we obtain


Z d 
X 
+
{−nt (U − U ) − −
Fj+ − Fj− · ϕ ds} = 0.
Σ∩D j=1

Since ϕ is arbitrary, we obtain the jump relation at the point M


d 
X 
− nt (U + − U − ) − Fj+ − Fj− = 0. (14.8)
j=1

The jump relation (14.8) is known the Rankine-Hugoniot condition, generalized here to any space
dimension. If we denote by
|[U ]| = U + − U −
the jump of U and similarly by
|[Fj |] = Fj+ − Fj−
the jump of Fj , j = 1, . . . , d, the jump condition may be written
d
X
nt |[U |] + nxj |[Fj |] = 0. (14.9)
j=1

If (nx1 , . . . , nxd ) 6= 0, let us set


n = (−σ, ν)
where σ ∈ R and ν = (ν1 , . . . , νd ) is a unit vector of Rd . Thené(14.9) can be equivalently written in
the form
X d
σ|[U |] = νj |[Fj ]|. (14.10)
j=1

If Σ is oriented and is the outward unit normal vector to σ, then ν and σ may be interpreted
n
|n|
respectively as the direction and the speed of propagation of the discontinuity Σ. Using the definition
of U and F , we get component by component

σ|[ρ]| = |[ρ u · ν]| (14.11)

and
∂u
σ|[ρu]| = |[ρu u · ν + pν − µ
]|. (14.12)
∂ν
Let us define Φ = ρ(u · ν − σ) the mass flux through the interface Σ. Because the two fluids are
supposed to be immiscible, there is no mass transfer between the two fluids. Thus Φ = 0 and we have

u+ · ν = u− · ν = σ.

and in particular
|[u · ν]| = 0. (14.13)
The transmission condition (14.13) is referred to as the kinematic jump condition. The second com-
patibility condition (14.12) can be rewritten
∂u
|[Φ u + pν − µ ]| = 0. (14.14)
∂ν
148 CHAPTER 14. MULTIPHASE FLOWS

But because Φ = 0 at the fluid interface, we have the second jump condition

∂u
|[−µ + pν]| = 0. (14.15)
∂ν
Equation (14.15) is referred to as the dynamic jump condition.

14.1.2 Final model


Because each of the two fluids are incompressible, one may look for a simpler system of equations.
Because ∇ · u = 0, the continuity equation is actually a transport equation which can be written

Dt ρ = 0 (14.16)

using the Lagrangian derivative. This is also true for the dynamic viscosity

Dt µ = 0. (14.17)

Still because ∇ · u = 0, the momentum equation can write

Dt (ρu) − ∇ · (µ∇u) + ∇p = ρg. (14.18)

Finally, because Dt ρ = 0, we have also

ρ Dt u − ∇ · (µ∇u) + ∇p = ρg. (14.19)

The system is closed with the zero-divergence velocity condition:

∇ · u = 0. (14.20)

One gets the standard Navier-Stokes equations (14.19),(14.20) coupled with the two transport equa-
tions (14.17),(14.18). It is a simple matter to show that equations (14.19) and (14.20) respect both
kinematic and dynamic jump conditions. For example, multiplying once again equation (14.20) by a
function ϕ ∈ D(Ω), integrating over the open D and applying Green’s formula, one gets
Z Z
u · ∇ϕ dx dt + u · ∇ϕ dx dt = 0.
D+ D−

Suppose for instance that the normal vector n the the surface Σ points in D+ . Then applying once
again Green’s formula in D+ and D− gives
Z Z Z Z
+
0=− ∇ · u ϕ dx dt − {u · ν}ϕ ds − ∇ · u ϕ dx dt + {−u− · ν}ϕ ds.
D+ Σ∩D D− Σ∩D

Since ∇ · u = 0 in D− and ∇ · u = 0 in D+ , we obtain


Z
|[u · ν]| ϕ ds = 0
Σ∩D

for any arbitray ϕ ∈ D(Ω) so that the kinematic condition is satisfied..


14.2. SEMI-DISCRETIZATION IN TIME 149

14.2 Semi-discretization in time


As already seen, the total derivatives are discretized according to be characteristic method. For nu-
merical stability purposes, the other terms are made implicit. From a time step ∆, the following
discrete-in-time equations are written

ρn+1 − ρn ◦ X n
= 0, (14.21)
∆t
µn+1 − µn ◦ X n
= 0, (14.22)
∆t
∇ · un+1 = 0, (14.23)
un+1 − un ◦ X n
ρn+1 − ∇ · (µn+1 ∇un+1 ) + ∇pn+1 = ρn+1 g, (14.24)
∆t

One can observe that, due to the features of the characteristic method, to the first equations can be
solved separately before the Navier-Stokes equations numerical solution. Once ρn+1 and µn+1 are
computed, one has to solve a standard Navier-Stokes problem, but with spatially varying density and
dynamic viscosity.

For a full discretization, one can use a standard Finite Element method suited for the Navier-Stokes
equations.

14.3 Front tracking by a level function


Actually, one of the drawbacks of the actual numerical scheme (14.21)-(14.24) is that the transport
equations Dt ρ = 0 and Dt µ = 0 are solved by an approximation scheme. Thus, inherent numerical
diffusion tends to create a discrete profile for density and viscosity near the fluid interface. Although
it is expected that the density of the continuous solution is either ρ1 or ρ2 according to the fluid
being present, the discrete density solved by the characteristic method can have unphysical values of
density, especially in the interval [min(ρ1 , ρ2 ), max(ρ1 , ρ2 )]. This is also true for the viscosity. A
way to proceed is to consider a levelset variable ψ such that ψ < 0 in Ωt1 , ψ > 0 in Ωt2 and the level
ψ = 0 exactly tracks the fluid interface σ. Because of the kinematic jump condition, a natural partial
differential equation for ψ is
Dt ψ = 0. (14.25)

Suppose the function Ψ known. Then both density and viscosity are computed as

ρ(x, t) = ρ1 1(ψ(x,t)<0) (x) + ρ2 1(ψ(x,t)>0) (x). (14.26)

µ(x, t) = µ1 1(ψ(x,t)<0) (x) + µ2 1(ψ(x,t)>0) (x). (14.27)

By construction this computational approach leads to sharp density and viscosity profiles. This ac-
curacy is sometimes paid by stability problems, especially for large density ratios between the two
fluids.
150 CHAPTER 14. MULTIPHASE FLOWS

14.4 Application. Liquid sloshing in a box.


14.4.1 freefem++ source code of the sloshing problem
1 // Twofluid .edp (Freefem++)
2 // Two−fluid flow ( incompressible fluids )
3 // Equations :
4 // div u = 0 in Omega
5 // D_t rho = 0 in Omega
6 // D_t(rho u) + div (mu grad u) + grad p = rho g.
7 //
8 real Lx = 2;
9 real Ly = 1;
10 real gravity = 9.81;
11 real rhom = 1.0, rhop = 10.0;
12 real num = 0.05, nup = 0.01;
13 real dt = 0.2;
14 real myratio=1.1;
15 mesh Th = square(120, 60, [x*Lx, y*Ly]);
16 mesh Thcoarse = square(40, 30, [x*Lx, y*Ly]);
17 fespace Uh(Th, P1b);
18 fespace Uhcoarse(Thcoarse, P1);
19 fespace Vh(Th, P1);
20 fespace Wh(Th, P2);
21 Uh u1, u2, u1old, u2old, u1h, u2h, pvisu;
22 Uhcoarse u1coarse, u2coarse;
23 Vh p, ph;
24 Wh phi, phih, phiold;
25 Wh rho, rhoold, mu;
26 //
27 // Initialisation
28 phi = 0.75*Ly/Lx*x -y; phiold=phi;
29 u1 = 0.0; u1old = u1;
30 u2 = 0.0; u2old = u2;
31 //
32 problem ConvectLevel(phi, phih) =
33 int2d(Th)(phi*phih/dt)
34 - int2d(Th)(convect([u1old,u2old], -dt, phiold)*phih/dt)
35 +int2d(Th)(0.001*dx(phi)*dx(phih)+0.001*dy(phi)*dy(phih));
36 //
37 problem NavierStokes([u1, u2, p], [u1h, u2h, ph]) =
38 int2d(Th)(rho*u1*u1h / dt)
39 - int2d(Th)(rho*convect([u1old,u2old], -dt, u1old)*u1h/dt)
40 +int2d(Th)(mu*dx(u1)*dx(u1h)+mu*dy(u1)*dy(u1h))
41 -int2d(Th)(p*dx(u1h))
42 + int2d(Th)(rho*u2*u2h/dt)
43 - int2d(Th)(rho*convect([u1old,u2old], -dt, u2old)*u2h/dt)
44 +int2d(Th)(mu*dx(u2)*dx(u2h)+mu*dy(u2)*dy(u2h))
45 -int2d(Th)(p*dy(u2h))
46 +int2d(Th)(rho*gravity*u2h)
47 +int2d(Th)((dx(u1)+dy(u2))*ph+0.000001*p*ph)
48 +on(1,2,3,4, u1=0, u2=0);
14.5. APPLICATION. INJECTION MOULDING PROBLEM 151

49 //
50 for (int it=0; it<30; it++) {
51 // First , convect density
52 for (int innerloop=0; innerloop<1;innerloop++){
53 rhoold = rho;
54 phiold = phi;
55 ConvectLevel;
56 rho = rhom*(phi<=0)+rhop*(phi>0);
57 mu = rhom*num*(phi<=0)+rhop*nup*(phi>0);
58 NavierStokes;
59 u1old = u1; u2old = u2;
60 }
61 u1coarse = u1;
62 u2coarse = u2;
63 // Th = adaptmesh(Th, rho, u1, u2); rho = rho; mu = mu; u1=u1; u2=u2;
64 // plot (rho, nbiso=60, fill =1, ps="rho_it="+it+".eps") ;
65 pvisu = p;
66 plot(rho, nbiso=40, fill=1, value=1,
67 ps="TwoFluidLevel_it"+it+".eps");
68 cout << "pmin, pmax = " << p[].min << " " << p[].max << endl;
69 }
70 cout << "\n\nTwofluid.edp: Done ! \n\n\n";
14.4.2 Numerical results

Figure 14.2: Simulation of liquid sloshing in a closed tank. Discrete free boundary and velocity field.

14.5 Application. Injection moulding problem


14.5.1 freefem++ source code of the injection moulding problem

1 // Moulding.edp (Freefem++)
2 //
3 real[int] PA(2); PA = [0, 0];
4 real[int] PB(2); PB = [9, 0];
5 real[int] PC(2); PC = [9, 9];
6 real[int] PD(2); PD = [8, 9];
7 real[int] PE(2); PE = [0, 9];
152 CHAPTER 14. MULTIPHASE FLOWS

Figure 14.3: Simulation of liquid sloshing in a closed tank. Discrete free boundary and velocity field.

Figure 14.4: Simulation of liquid sloshing in a closed tank. Discrete free boundary and velocity field.

8 real[int] PF(2); PF = [0, 6];


9 real[int] PG(2); PG = [0,4];
10 real[int] PH(2); PH = [1, 1];
11 real[int] PK(2); PK = [1,8];
12 real[int] PL(2); PL = [8,8];
13 real[int] PM(2); PM = [8,5];
14 real[int] PO(2); PO = [5,5];
15 real[int] PP(2); PP = [5,4];
16 real[int] PQ(2); PQ = [8,4];
17 real[int] PR(2); PR = [8,1];
18 border c1(t=0,1){x=(1-t)*PA[0]+t*PB[0]; y=(1-t)*PA[1]+t*PB[1];}
19 border c2(t=0,1){x=(1-t)*PB[0]+t*PC[0]; y=(1-t)*PB[1]+t*PC[1];}
20 border c3(t=0,1){x=(1-t)*PC[0]+t*PD[0]; y=(1-t)*PC[1]+t*PD[1];}
21 border c4(t=0,1){x=(1-t)*PD[0]+t*PE[0]; y=(1-t)*PD[1]+t*PE[1];}
22 border c5(t=0,1){x=(1-t)*PE[0]+t*PF[0]; y=(1-t)*PE[1]+t*PF[1];}
23 border c6(t=0,1){x=(1-t)*PF[0]+t*PG[0]; y=(1-t)*PF[1]+t*PG[1];}
14.5. APPLICATION. INJECTION MOULDING PROBLEM 153

Figure 14.5: Simulation of liquid sloshing in a closed tank. Discrete free boundary and velocity field.

Figure 14.6: Simulation of liquid sloshing in a closed tank. Discrete free boundary and velocity field.

24 border c7(t=0,1){x=(1-t)*PG[0]+t*PA[0]; y=(1-t)*PG[1]+t*PA[1];}


25 //
26 border c8(t=0,1){x=(1-t)*PH[0]+t*PK[0]; y=(1-t)*PH[1]+t*PK[1];}
27 border c9(t=0,1){x=(1-t)*PK[0]+t*PL[0]; y=(1-t)*PK[1]+t*PL[1];}
28 border c10(t=0,1){x=(1-t)*PL[0]+t*PM[0]; y=(1-t)*PL[1]+t*PM[1];}
29 border c11(t=0,1){x=(1-t)*PM[0]+t*PO[0]; y=(1-t)*PM[1]+t*PO[1];}
30 border c12(t=0,1){x=(1-t)*PO[0]+t*PP[0]; y=(1-t)*PO[1]+t*PP[1];}
31 border c13(t=0,1){x=(1-t)*PP[0]+t*PQ[0]; y=(1-t)*PP[1]+t*PQ[1];}
32 border c14(t=0,1){x=(1-t)*PQ[0]+t*PR[0]; y=(1-t)*PQ[1]+t*PR[1];}
154 CHAPTER 14. MULTIPHASE FLOWS

Figure 14.7: Simulation of liquid sloshing in a closed tank. Discrete free boundary and velocity field.

33 border c15(t=0,1){x=(1-t)*PR[0]+t*PH[0]; y=(1-t)*PR[1]+t*PH[1];}


34 //
35 int m=2;
36 mesh Th=buildmesh( c1(80*m)+c2(50*m)+c3(10*m)+c4(40*m)
37 +c5(30*m)+c6(10*m)+c7(30*m)
38 +c8(80*m)+c9(40*m)+c10(25*m)+c11(20*m)
39 +c12(5*m)+c13(20*m)+c14(25*m)+c15(30*m) );
40 plot(Th);
41 //
42 real gravity = 9.81;
43 real rhom = 1.0, rhop = 20.0;
44 real num = 0.1, nup = 10;
45 real dt = 1;
46 fespace Uh(Th, P1b);
47 fespace Vh(Th, P1);
48 fespace Wh(Th, P1b);
49 Uh u1, u2, u1old, u2old, u1h, u2h;
50 Vh p, ph;
51 Wh u1view, u2view;
52 Wh rho, rhoold, rho2, mu, muold;
53 //
54 // Initialisation
55 rho =rhom;
56 mu = rhom*num;
57 rho = rho + (rhop-rhom)*((x<0.2)*(y>PG[1])*(y<PF[1]));
58 mu = mu + (rhop*nup-rhom*num)*((x<0.2)*(y>PG[1])*(y<PF[1]));
59 u1 = 0.0; u1old = u1;
60 u2 = 0.0; u2old = u2;
61 //
62 plot(rho, nbiso = 60, fill=1);
14.5. APPLICATION. INJECTION MOULDING PROBLEM 155

63 int it = 0;
64 problem NavierStokes([u1, u2, p], [u1h, u2h, ph]) =
65 int2d(Th)(rho*u1*u1h/dt)
66 - int2d(Th)(rhoold*convect([u1old,u2old], -dt, u1old)*u1h/dt)
67 +int2d(Th)(mu*dx(u1)*dx(u1h)+mu*dy(u1)*dy(u1h))
68 +int2d(Th)(dx(p)*u1h)
69 + int2d(Th)(rho*u2*u2h/dt)
70 - int2d(Th)(rhoold*convect([u1old,u2old], -dt, u2old)*u2h/dt)
71 +int2d(Th)(mu*dx(u2)*dx(u2h)+mu*dy(u2)*dy(u2h))
72 +int2d(Th)(dy(p)*u2h)
73 +int2d(Th)(rho*gravity*u2h)
74 +int2d(Th)((dx(u1)+dy(u2))*ph+0.000001*p*ph)
75 +on(c6, u1=0.3, u2=0)
76 +on(c1,c2,c4,c5,c7,c8,c9,c10,c11,c12,c13,c14,c15, u1=0, u2=0);
77 //
78 real[int] viso(1); viso = [5, 10, 15];
79 for (it=0; it<40; it++) {
80 // First , convect density
81 for (int sit=0; sit<5; sit++) {
82 NavierStokes;
83 u1old = u1; u2old = u2;
84 rhoold = rho; muold = mu;
85 rho = convect([u1old,u2old], -dt, rho);
86 mu = convect([u1old,u2old], -dt, mu);
87 }
88 // Th = adaptmesh(Th, rho, u1, u2); rho = rho; mu = mu; u1=u1; u2=u2;
89 rho2 = rhop - rho;
90 plot(rho, fill=1, nbiso=3, viso=viso, value=1, ps="Moulding_rho_it"+it+"
.eps");
91 // plot (rho2, nbiso=60, fill =1, grey=1, bw=1, ps="Moulding_rho_it"+it+".eps");
92 }
93 //
94 cout << "\n\n\nDone.\n\n\n";

14.5.2 Numerical results


IsoValue
5
10
15

Figure 14.8: Simulation of injection molding. Material front just after the beginning of injection.
156 CHAPTER 14. MULTIPHASE FLOWS

IsoValue IsoValue
5 5
10 10
15 15

Figure 14.9: Simulation of injection molding. Material front profile during injection.

IsoValue IsoValue
5 5
10 10
15 15

Figure 14.10: Simulation of injection molding. Material front profile during injection.

IsoValue IsoValue
5 5
10 10
15 15

Figure 14.11: Simulation of injection molding. Material front profile during injection.
14.5. APPLICATION. INJECTION MOULDING PROBLEM 157

IsoValue IsoValue
5 5
10 10
15 15

Figure 14.12: Simulation of injection molding. Material front profile during injection.
Index

accuracy, 18, 94 eigenvalue problem, 80


adaptmesh (freefem++), 120 elliptic problem, 29
amplification factor, 20 energy equation, 113
artificial viscosity, 23 equilibrium, 79
autosimilar solution, 89 equivalent equation, 23
Euler scheme, 14
bifurcation, 81 Euler-Maruyama scheme, 135
bilinear form, 30
biomolecular system, 137 finite difference, 13, 14
boundary condition, 79 finite element, 31
boundary conditions, 9 finite volume, 13
buoyancy, 123 Fokker-Planck equation, 134
Fourier transform, 17
Cauchy-Schwarz inequality, 30 fractional step method, 82
CFL condition, 15, 93 freefem++, 29
chemotaxis, 77 freeway, 102
coercive form, 30 front tracking, 149
compressible flow, 113 functional, 36
conservation form, 10 fundamental diagram, 88
conservative equation, 9
gas dynamics, 11
conservative form, 87
Green’s formula, 10, 29, 136
conservative scheme, 93
consistency, 18 heat problem, 32
continuity equation, 113 heat transfer, 123
convect (freefem++), 42 Heun scheme, 61
convection problem, 44 Hilbert space, 30
convection-diffusion, 123 hybrid scheme, 22
convection-reaction-diffusion, 78
convective flux, 136 incompressible, 9, 11
cost function, 36 inf-sup condition, 50
Courant number, 16
jump condition, 147
jump conditions, 91
diffusion process, 134
diffusive flux, 78, 136 kinematic condition, 147
dimensionless equation, 78, 124 kinematic equation, 7
discontinuity, 88 kinematic viscosity, 123
dispersion relation, 80
dynamic jump condition, 148 Lagrangian, 9

158
INDEX 159

Lagrangian derivative, 7 stable equilibrium, 79


lagrangian derivative, 41 steady state, 79
Laplace problem, 29 stochastic, 133, 137
Lax-Friedrichs scheme, 20, 94 stochastic differential equation, 135
Lax-Milgram Theorem, 30, 33
Lax-Wendroff scheme, 18, 94 thermal conductivity, 37, 125
LBB condition, 50 thermal engineering, 34
linear stability, 79 total derivative, 41, 115
Lokta-Volterra equations, 65 trace function, 33
transport equation, 7, 11
Mach number, 117
metabolite reactions, 137 uncertainty, 137
method of characteristics, 41 unstable equilibrium, 79
momentum equation, 113 upwind scheme, 19
Monte-Carlo method, 135
variational formulation, 33, 116
Navier-Stokes equations, 123 vehicle traffic flow, 87
nonconservative form, 115 von Neumann stability, 17
numerical flux, 19, 21, 93
weak solution, 91
optimization, 36 working fluid, 123
order of accuracy, 18
ordinary differential equation, 133 zero flux boundary condition, 79, 136

particle derivative, 7, 41
planar wave, 80
Poiseuille flow, 125
Prandtl number, 124
probability density function, 134

Rankine-Hugoniot condition, 147


Rankine-Hugoniot relations, 91
rarefaction wave, 90
Rayleigh-Taylor instabilities, 123
Reynolds number, 124
Reynolds theorem, 10
RK2, 61
Robin boundary condition, 136
Roe scheme, 93

scilab, 23
semi-discrete form, 32
semi-discretization, 82
semi-implicit, 82
shape optimization, 36
shock wave, 90
Sobolev space, 30, 33, 137
stability, 15, 79
160 INDEX
Bibliography

[1] P.A. Raviart, J.M. Thomas, Introduction à l’Analyse numérique des équations aux dérivées par-
tielles, Dunod (2004).

[2] I. Danaila, F. Hecht, O. Pironneau, Simulation numérique en C++ - Cours et exercices corrigés,
Dunod (2003).

[3] E. F. Toro, Godunov Methods: theory and applications, Kluwer Academic (2001).

[4] E. Godlewski, P.A. Raviart, Numerical approximation of hyperbolic systems of conservation


laws, Springer-Verlag (1996).

[5] H. Yamaguchi, Engineering Fluid Mechanics, Kluwer Academic Publishers (2008)

[6] R. Temam and A. Miranville, Modélisation Mathématique et Mécanique des milieux continus,
Springer (2002).

[7] R. Haberman, Mathematical models: mechanical vibrations, population dynamics and traffic
flow, Society for Industrial and Applied Mathematics, Classics in Applied Mathematics (1998).

[8] B. Lucquin, O. Pironneau, Introduction to Scientific Computing, John Wiley and Sons (1998).

[9] N. G. van Kampen, Stochastic processes in Physics and Chemistry, North-Holland (1992).

[10] J. Istas, Mathematical modeling for the life sciences, Springer-Verlag Berlin (2005).

[11] B. S. Kerner, The Physics of Traffic: empirical freeway pattern features, engineering applications
and Theory, Springer-Verlag Berlin and Heidelberg (2004).

[12] L. Edelstein-Keshet, Mathamtical Models in Biology, Society for Industrial and Applied Mathe-
matics, Classics in Applied Mathematics (2008).

[13] J. N. Reddy, The Finite Element Method in heat transfer and Fluid Dynamics, CRC Press Inc.
(2000).

[14] B. Oksendal, Stochastic Differential Equations: an introduction with applications, Springer-


Verlag (2003).

[15] P. Kotelenez, Stochastic ordinary and stochastic partial differential equations: transition from
microscopic to macroscopic equations, Springer-Verlag New-York Inc. (2008).

[16] Stochastic Integration and differential equations, Springer-Verlag Berlin (2003).

161
162 BIBLIOGRAPHY

[17] Freefem++ Open Source Software, http://www.freefem.org/.

[18] Scilab Open Source Software, http://www.scilab.org/.

[19] J.P. Chancelier, D. Delebecque, C. Gomez, M. Goursat, Introduction à Scilab, Springer Editions
(2007).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy