Introduction in Freefem++ Advanced
Introduction in Freefem++ Advanced
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
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
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
Transport equations
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
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.
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
The boundary ∂Ω− in the context of (1.9) is referred to as the inflow boundary because of the negative
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
dq
= s(q(α), x(α)). (1.13)
dα
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
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
∂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σ.
∂ω∩∂ω ′ ∂ω∩∂ω ′
∂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
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
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
In particular we have
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
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
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
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 :
Consider first a Courant number ν n less than 1. Taking the absolute value of the expression and
applying the triangular inequality gives
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
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
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
∂t q + a∂x q = 0,
2.4. CONSISTENCY PROPERTIES 19
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
|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.
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.
(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
∆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).
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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++
−∆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 Ω Ω
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 /
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 (Ω)
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:
≤ (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||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).
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++
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 !
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)
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++
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 !
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++
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
subject to
|Ωe |
= µ. (3.30)
|Ωw |
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)
where κ(.) is the piecewise constant thermal conductivity defined from κa , κc and κe :
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++
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
∂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:
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
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
by
X n ≈ x 7→ x − ∆tn un (x).
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
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
∂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
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
−ν∆u + ∇p = f , (5.11)
∇ · u + ε p = 0. (5.12)
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.
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
((u, p), (v, q))V = (u, v)H 1 (Ω) + (p, q)L2 (Ω) (5.19)
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)
Ω Ω Ω Ω Ω
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
|a ((u, p), (v, q)) | ≤ ν||u||H 1 (Ω) ||v||H 1 (Ω) + ||p||L2 (Ω) ||∇ · v||L2 (Ω) + ||q||L2 (Ω) ||∇ · u||L2 (Ω)
+ε ||p||L2 (Ω) ||q||L2 (Ω)
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
Ω Ω
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
∂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
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.
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
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 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)
57
58 CHAPTER 6. FRACTIONAL STEP METHODS
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.
for some square matrices A and B. The analytical solution of (6.9) and (6.10) is
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.
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
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
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
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
∆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
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
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.
∂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
∂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
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.
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
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.
αv + u − log(v α u) = αv 0 + u0 − log((v 0 )α u0 ).
68CHAPTER 7. CASE STUDY. POPULATION DYNAMICS AND MIGRATION FLUX ANALYSIS
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
2π
a period √ α
.
v(0) = v 0 . (7.12)
7.2. A FRACTIONAL STEP APPROACH TO SOLVE THE LOKTA-VOLTERRA EQUATIONS.69
∆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)
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).
problems, a spatial P2 Finite Element approximation is used. In this numerical example, ν = 10−3 ,
µ = 10−4 and the following initial data is used:
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).
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
∂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
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
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.
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
Sρ
β+ρ
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.
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)
ρ′ ρ′
! ! !
d −srρ∞ 0
= s .
dt c′ (1+ρ∞ )2
−s c′
According to the sign of the two eigenvalues, the second equilibrium state is stable.
ρ∞
(ρ∞ , 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:
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
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
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
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.
u = α∇c, (8.21)
Dt = ∂t + u · ∇. (8.23)
82 CHAPTER 8. MODEL OF BIOLOGICAL SPATIAL PIGMENT PATTERN FORMATION
∂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)
σ 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
σ 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 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
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
∂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
∂t ρ + ∂x (ρ u(ρ)) = 0 (9.7)
∂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
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.
dρ
Then, homogeneous terms of degree 1 in ε give the linearized equation
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.
ρ = ρ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)
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
The quantity σ is a wave propagation velocity. Putting the expression (9.18) into (9.7) gives
d
− σφ′ (ξ) + [q(φ(ξ))] = 0, ξ = x − σt. (9.19)
dξ
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
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)
−∞ −∞
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
∂t c + u(ρ) ∂x c = 0. (9.28)
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).
we have
A(U ) = R(U )Λ(U )R−1 (U ). (9.32)
9.5. FINITE DIFFERENCE METHODS FOR NONLINEAR TRANSPORT EQUATIONS 93
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 θ = −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).
∂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:
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].
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)
(ρ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.
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
λ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].
Figure 9.5: Numerical solution using a CFL number equal to 0.5 and θ = −0.1, after one time
iterations.
Figure 9.6: Numerical solution using a CFL number equal to 0.5 and θ = −0.1, after 20 time itera-
tions.
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.
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");
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
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.
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
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)].
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";
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
(p is the pressure of the fluid) and the equation of the conservation of the energy
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
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.
γ = 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
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.
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 Ω
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.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 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.
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.
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
∇ · 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
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
u = uin in Ω. (12.18)
126 CHAPTER 12. FLUID MECHANICS AND HEAT TRANSFER
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:
∇ · 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.
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
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
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
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
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 [].
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
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
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.
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 ]
∂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.
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.
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.
D ∂
= + v(x) · ∇x , (13.14)
Dt ∂t
136 CHAPTER 13. STOCHASTIC DIFFUSION PROCESSES, FOKKER-PLANCK EQUATIONS
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
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
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
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.
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
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.
1 // Fokker.edp (Freefem++)
2 // Fokker−Planck equations,
3 // Simple stochastic metabolite reaction model
4 //
140 CHAPTER 13. STOCHASTIC DIFFUSION PROCESSES, FOKKER-PLANCK EQUATIONS
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.
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");
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.
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.
∂t ρ + ∇ · (ρu) = 0, (14.3)
145
146 CHAPTER 14. MULTIPHASE FLOWS
∂t U + ∇ · F = S, (14.5)
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
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
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 Σ 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
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.
Dt ρ = 0 (14.16)
using the Lagrangian derivative. This is also true for the dynamic viscosity
Dt µ = 0. (14.17)
∇ · 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
ρ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.
Suppose the function Ψ known. Then both density and viscosity are computed as
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
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.
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.
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.
Figure 14.7: Simulation of liquid sloshing in a closed tank. Discrete free boundary and velocity field.
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";
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
158
INDEX 159
particle derivative, 7, 41
planar wave, 80
Poiseuille flow, 125
Prandtl number, 124
probability density function, 134
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).
[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).
[15] P. Kotelenez, Stochastic ordinary and stochastic partial differential equations: transition from
microscopic to macroscopic equations, Springer-Verlag New-York Inc. (2008).
161
162 BIBLIOGRAPHY
[19] J.P. Chancelier, D. Delebecque, C. Gomez, M. Goursat, Introduction à Scilab, Springer Editions
(2007).