Finite Volume Method For One Dimensional
Finite Volume Method For One Dimensional
Guillaume Riflet
MARETEC IST
1
1 The advection-diffusion equation 2
where V is a control volume held fixed in time relative the laboratory refer-
ence frame and vVt |V is the relative velocity of the moving control volume
Vt relative to the laboratory reference frame or to V , which is the same.
The flow velocity relative the laboratory reference frame v is then given
by
v = vr + vVt |V ,
and minding that ∂V = ∂Vt and V = Vt at one time instant, equation 4
1 The advection-diffusion equation 3
rewrites
∫ I
d P dV
V
=− P (v · n) dS
dt
I ∂V
− −K (∇P · n) dS
∂V ∫
being V the gaussian volume, ∂V its boundary, E the vector field, and E · n
its flux through the boundary. n is defined as the external normal unit
vector to the boundary. Hence, by applying equation(6) to equation(2), the
finite volume formulation of equation (7) is obtained:
∫ ∫
d V P dV
=− ∇ · (v P ) dV
dt
∫ V
− ∇ · (− K ∇P ) dV
V
∫
+ (Sc − Sk) dV. (7)
V
A few comments: first, the control volume is held fixed in time. Second,
the time derivative applied to a function varying in time only in its explicit
component (such as P (x, t)), may be annotated as a partial derivative,
∂
∂t , without loss of generality. Third, the total derivative and the partial
derivative are related by the Leibniz chain rule,
d P (x(t), t) ∂P (x(t0 ), t)
dt = ∂t
t0 t0
d x(t) ∂P (x(t0 ), t0 )
+
dt t0 ∂x
d y(t) ∂P (x(t0 ), t0 )
+
dt t0 ∂y
d z(t) ∂P (x(t0 ), t0 )
+ .
dt
t0 ∂z
If dx
dt = 0, then the partial derivative equals the total derivative, which is
the case of P within the fixed volume V .
By noting that
∇ · (v P ) = v · ∇P + P ∇ · v,
equation 8 returns
∂P
+ v · ∇P + P ∇ · v + ∇ · (− K ∇P ) − Sc + Sk = 0.
∂t
By noting that the material derivative is defined by
D ∂
≡ + v · ∇,
Dt ∂t
equation 8 finally yields
DP
+ P ∇ · v + ∇ · (− K ∇P ) − Sc + Sk = 0.
Dt
In incompressible fluids we have ∇ · v = 0, hence in such case
DP
+ ∇ · (− K ∇P ) − Sc + Sk = 0. (9)
Dt
Thus, to sum up, equation (5) is the integral equation of advection and
diffusion (with source and sink terms) in flux form, equation (7) is the
1 The advection-diffusion equation 5
v · n1 = u v · n2 = −u
∇P · n1 = ∂P
∂x ∇P · n2 = − ∂P
∂x .
1 The advection-diffusion equation 6
∫
P dV
Thus we get, if we define P ≡ V
V ,
∫ ( )
∂ VP dV ∂ PV
=
∂t ∂t
∂P
= V,
∂t
∫
P dS
furthermore, if we define P̃i ≡ Ai
Ai , we obtain
∫ 6 ∫
∑
P (v · n) dS = P (v · ni) dS
A i=1 Ai
∫ ∫
= u P dS − u P dS
A1 A2
= u P˜1 A1 − u P˜2 A2 ,
∫ ∂P
dS
finally, if we approximate Ai ∂x
Ai ≈ ∂P
∂x , we have
∫ 6 ∫
∑
−K (∇P · n) dS = −K (∇P · ni) dS
A i=1 Ai
∫ ∫
∂P ∂P
= −K dS + K dS
A1 ∂x A2 ∂x
∂P ∂P
= −K A1 + K A2 .
∂x (A1 ) ∂x (A2 )
∂P ∂P ∂P
V = −u P˜1 A1 + u P˜2 A2 + K A1 − K A2 + Sc’ − Sk’
∂t ∂x (A1 ) ∂x (A2 )
∂P A1 ˜ A2 ˜ A1 ∂P A2 ∂P Sc’ Sk’
= −u P1 +u P2 +K −K + − . (11)
∂t V V V ∂x (A1 ) V ∂x (A2 ) V V
Now the whole of the game is to find numerical schemes that evaluate the
time and space derivatives, in equation (11), of the volume averaged P , ∂P
∂t
∂P
and ∂x properties; as well as to evaluate the surface averaged property P̃ .
1 The advection-diffusion equation 7
∂P P (t + ∆t) − P (t)
(t) ≈ (12)
∂t ∆t
• Time backward or implicit method
∂P P (t) − P (t − ∆t)
(t) ≈ (13)
∂t ∆t
• Midpoint method
∂P P (t + ∆t) − P (t − ∆t)
(t) ≈ . (14)
∂t 2 ∆t
As a note, it can be shown ( [3], [4] ) that the forward and backward method
have first-order precision and that the midpoint method has second-order
precision, on an uniform grid.
A1 ∂P A2 ∂P
−K +K
V ∂x (i+1/2) V ∂x (i−1/2)
( )
K Pi+1 − Pi Pi − Pi−1
=− −
∆x ∆x ∆x
K
=− (Pi+1 − 2 Pi + Pi−1 ) , (15)
∆x2
• Advection typically uses the upwind method (backward method if u <
0, and forward method if u ≥ 0),
2 Some notes on numerical methods 8
{
Pi , if u≥0
Pi+1/2 =
{ Pi+1 , if u<0
, (16)
Pi−1 , if u≥0
Pi−1/2 =
Pi , if u<0
A1 A2
u P −u P
V i+1/2 V i−1/2
= 0 Pi+1 + u
∆x Pi + − ∆x u
Pi−1 , if u ≥ 0
= u
Pi+1 + − ∆xu
Pi + 0 Pi−1 , if u < 0
∆x
u
u
u
− u
+ u
= − ∆x ∆x
Pi+1 +
Pi − ∆x ∆x
Pi−1 , (17)
2 ∆x 2
• or the central i method (i.e. midpoint method),
Pi+1 +Pi
Pi+1/2 = 2
Pi +Pi−1 , (18)
Pi−1/2 = 2
A1 A2 u u
u Pi+1/2 − u Pi−1/2 = Pi+1 + 0 Pi − Pi−1 . (19)
V V 2 ∆x 2 ∆x
′ ′′ (dt)2 ( )
f (t + dt) = f (t) + f (t) dt + f (t) + o (dt)3 . (22)
2
A first derivative approximation may be obtained from equation 22,
′ f (t + dt) − f (t)
f (t) = + o (dt) . (23)
dt
The first derivative approximation in equation (23) yields first order error.
This numerical method is often referred to as the explicit method or the
forward in time method. Note that
o((dt)3 )
= o((dt)2 ),
dt
o(dt) = o(−dt) = −o(dt),
are general properties of truncature error operator.
′ (−dt)2
′′
( )
f (t − dt) = f (t) + f (t) (−dt) + f (t) + o (−dt)3 . (24)
2
2 Some notes on numerical methods 10
2.2.1 positivity
Indeed, if the coefficients affected to P were negative, that would violate the
principle of positive mass, or positivity, and the numerical solution would
return negative oscillations of the property concentration. Thus, to ensure
that positivity is not violated, it is required that:
Ai ≥ 0,
∀i Bi ≥ 0, (31)
Ci ≥ 0.
Some numerical schemes can only ensure this condition for a limited range
of parameters. A numerical scheme robustness is measured by the range of
values that the parameters may take that ensure the stability condition in
equation 32.
What Pi+1 gains from Pi (Ai+1 ) and what Pi−1 gains from Pi
(Ci−1 ) is equal to what Pi looses (Bi ).
Fig. 3: Advected boat by a uniform current along time (from top to bot-
tom). The dotted boat represents a realistic advection. The all-
black boat represents advection by an upwind time-forward scheme
in a unidimensional grid. The all-black boat falls in pieces, after each
time iteration, as a consequence of numerical diffusion. Thus, finite-
difference solvers aren’t adequate to model pure advection. However,
they work adequately to model advection and diffusion.
2 Some notes on numerical methods 14
f (t + ∆t) − f (t)
f ′ (t) ≈
∆t
⇔ f (t + ∆t) ≈ f (t) + ∆t f ′ (t).
f (t + ∆t) − f (t)
f ′ (t + ∆t) ≈
∆t
′
⇔ f (t + ∆t) ∆t − f (t + ∆t) ≈ f (t) .
f (t + 2 ∆t) − f (t)
f ′ (t + ∆t) ≈
2 ∆t
⇔ f (t + 2 ∆t) ≈ 2 ∆t f ′ (t + ∆t) + f (t) ,
thus, in order to compute f (m ∆t) for any m, f ((m − 2) ∆t) and f ((m − 1) ∆t)
are both required. Another issue with the midpoint method is that consec-
utive time steps may come decoupled if the two initial conditions are un-
similar. To re-enable coupling, use of filters such as Robert-Asselin filters
may be required [5], at the expense of some precision in the solution,
3 The problem
duct contains a grid at each end that filters the tracer while letting pass the
fluid. Boundary condition i is called open boundary condition and boundary
condition ii is equivalent to a fully closed boundary condition. The partic-
ularity of the open boundary condition is that we must impose a tracer
concentration of PbL (t) on the left end of the duct, and a tracer concentra-
tion of PbR (t) on the right end, be it Dirichelet or Neumann conditions. On
the other hand, the main interest of the closed boundary condition is to test
if the numerical methods conserve the tracer’s total mass inside the domain
as expected.
scheme. {
Cr if u ≥ 0
CrL = ,
0 if u < 0
{
0 if u ≥ 0
CrR = .
−Cr if u < 0
Let us define the concentration of the tracer imposed at the boundaries by:
{
fL if Dirichelet
PbL = ,
P1 if Neumann
{
fR if Dirichelet
PbR = .
PN if Neumann
The stability and positivity criteria introduced below are the simultaneous
combination of inequations 31, 32 and 33 applied to this case.
stability criteria:
0 ≤ ∥Cr∥ + 2 Dif ≤ 1.
closed boundary condition:
0 ≤ ∥Cr∥ ≤ 2 Dif ≤ 1.
unconditionally stable:
positivity criteria:
0 ≤ ∥Cr∥ ≤ 2 Dif ≤ +∞.
closed boundary condition:
(Cr/2 − Dif ) P2 (t + ∆t)
+ (1 + Cr/2 − Cr/2 + 2 Dif ) P1 (t + ∆t)
= P1 (t) − (−Cr/2 − Dif) PbL (t),
The previous section limited to describe numerical methods suitable for ad-
vective and diffusive processes only. However, generic tracers may also have
source/sink and/or growth/decay terms. Besides involving more terms in
the equation, the stability conditions of the numerical scheme also change.
This section proposes to describe mathematically a mass conservative eco-
logical system composed by three variables of state describing a predador-
prey-nutrients system, that are transported in a 1D-channel. The stability
conditions of the numerical implementation are also considered.
where Pzoo , Pphy and Pnut are, respectively, the concentrations of zooplank-
ton, phytoplankton and nutrients. kh is the assimilation rate of phytoplank-
ton by zooplankton, kg is the grazing rate of phytoplankton and kmz is the
mortality rate of zookplankton. eh is the zooplankton’s efficiency rate of
assimilation of phytoplankton (phytoplankton grazes with 100 percent of
efficiency). All the remains of dead zooplankton and dead phytoplankton
are wholly decomposed into nutrients by bacteria. Growth terms come with
a plus sign, and depletion terms come with a minus sign. The system of
equations 35 is globally conservative, as the sum of the initial masses of the
three properties is preserved over time.
By substituting the ecological model in equations 35 in the source and
sink terms of equation 8, the full ecological model system of differential
equations writes
∂Pzoo
∂t = −∇ · (v Pzoo ) + ∇ · (Kzoo ∇Pzoo ) + λzoo Pzoo ,
∂Pphy
= −∇ · (v Pphy ) + ∇ · (Kphy ∇Pphy ) + λphy Pphy , (36)
∂t
∂Pnut
∂t = −∇ · (v Pnut ) + ∇ · (Knut ∇Pnut ) − λnut Pnut + Scnut ,
where
λzoo ≡ eh kh Pphy − kmz ,
λ ≡ kg Pnut − kh Pzoo ,
phy
(37)
λ ≡ kg Pphy ,
nut
Sc ≡ ((1 − eh ) kh Pphy + kmz ) Pzoo .
nut
In particular, λzoo and λphy are growth or decay coefficients of the zooplank-
ton and phytoplankton, respectively. Their sign can change over time. λnut
is always positive and is a decay coefficient in the nutrients equation. Fi-
nally, Scnut is a source term in the nutrients equation. Growth and source
5 Adding sources and sinks to build an ecological model 25
terms tend to stabilize the numerical solution of equations 36, using the ex-
plicit method, whereas decay terms may reduce the stability interval when
using the explicit method.
To meet the positivity (eq. 31) and stability (eq. 32) criteria, the following
constraints must be followed for equations 38,
0 ≤ Ai ≤ 1,
∀i 0 ≤ Bi − ∆t λi ≤ 1, (39)
0 ≤ Ci ≤ 1.
If ∃i, Sci < Ski then the model may undershoot. (40)
References