ResSimCh6 PDF
ResSimCh6 PDF
6
CONTENTS
Having worked through this chapter the student should be able to:
• write down from memory simple finite difference expressions for derivatives,
(∂P/∂x), (∂P/∂t) and (∂2P/∂x2) explaining your spatial (space) and temporal (time)
n n +1 n +1 n +1
notation ( Pi , Pi , Pi +1 , Pi −1 etc. ); for (∂P/∂x), the student should know the
meaning of the forward difference, the backward difference and the central difference
and the order of the error associated with each, O(Δx) or O(Δx2).
• write a simple spreadsheet to solve the explicit numerical scheme for a simple
PDE for given boundary and initial conditions and be able to describe the effect of
time step size, Δt.
• show how the implicit finite difference scheme applied to a simple linear PDE
leads to a set of linear equations which are tridiagonal in 1D and pentadiagonal in
2D.
• describe a solution strategy for the non-linear single phase 2D pressure equation
where the fluid and rock compressibility (and density, ρ, and viscosity, μ) are functions
of the dependent variable, pressure, P(x,y,t).
• write down the discretised form of both the pressure and saturation equation for
two-phase flow given the governing equations (in simplified form in 1D), and be able
to explain why these lead to sets of non-linear algebraic equations.
• outline with an explanation and a simple flow chart the main idea behind the IMPES
solution strategy for the discretised two-phase flow equations.
• write down the expanded expressions for a set of linear equations which, in compact
form are written A.x = b, where the matrix A is an nxn matrix of (known) coefficients
(aij; i = rows, j = columns), b is a vector of n (known) values and x is the vector of n
unknowns which we are solving for.
• explain clearly the main differences between a direct and an iterative solution
method for the set of linear equations, A.x = b.
• write down the algorithm for a very simple iterative scheme for solving A.x = b,
and be able to describe the significance of the initial guess, x(0) , what is meant by
iteration (and iteration counter, ν), the idea of convergence of x(ν) as ν → ∞; and be
able to comment on the number of iterations required for convergence, Niter.
2
Numerical Methods in Reservoir Simulation
6
• explain how to apply (without derivation) the Newton-Raphson method for
solving a single non-linear algebraic equation, f ( x ) = 0 ; Newton-Raphson scheme
f ( x (ν ) )
=> x (ν +1) = x (ν ) − .
f ' ( x (ν ) )
• extend the application of the Newton-Raphson to sets of non-linear algebraic
equations such as those arising from the discretisation of the two-phase pressure and
S
saturation equations; F( X ) = 0, where X = and S and P are the (unknown)
P
vectors of saturation and pressure; (given the Newton-Raphson expression,
[ ]
X (ν +1) = X (ν ) − J ( X (ν ) ) .F( X (ν ) )).
−1
• understand, but not be able to reproduce the detailed derivation of, the more
mathematical explanation of numerical dispersion.
As noted in Chapter 5, the multi-phase flow equations for real systems are so complex
that it is not remotely possible to solve them analytically. In practice these equations
can only be solved numerically. The most commonly applied numerical methods
are based on finite difference approximations of the flow equations and this approach
will be followed in this chapter.
In the numerical solution of the multi-phase flow equations, we need to solve for
pressure and flow. An outline of how this is done is presented but we do not go into
great detail.
1. INTRODUCTION
At the very start of this course, we considered a very simple “simulation model” for a
growing colony of bacteria. The number of bacteria, N, grew with a rate proportional
to N itself i.e. (dN/dt) = α.N, where α is a constant. We saw that this simple equation
α.t
had a well-known analytical solution, N( t ) = N o .e , where No is the number of
bacteria at time, t =0. This exponential growth law provides the solution to our
model. However, we also introduced the idea of a numerical model where, even
although we could solve the problem analytically, we formulated it this way, in any
case. The numerical version of the model came up with the algorithm (or recipe)
N n +1 = (1 + α.∆t ).N n . In the exercise in Chapter 1, you should have compared the
results of the analytical and numerical models and found out that, they get closer as
In Chapter 5, we already met the equations for single-phase and two-phase flow of
compressible fluids through porous media. These turned out to be non-linear partial
differential equations (PDEs). Recall that a non-linear PDE is one where certain
coefficients in the equation depend on the answer we are trying to find e.g. Sw(x,t),
P(x,y,z,t) etc. For example, for single phase compressible flow, the equation for
pressure, P(x,t), in 1D is given by:
∂P ∂ k.ρ ∂P
c( P) =
∂t ∂x µ ∂x
(1)
In this equation, both the generalised compressibility term, c(P) (of both the rock and
the fluid), and the density, ρ(P), terms depend on the unknown pressure, P, which
we are trying to find. As noted previously, such non-linear PDEs are very difficult
to solve analytically and we must usually resort to numerical methods. The main
topic of this module is on how we solve the reservoir flow equations numerically.
This process involves the following steps:
(i) Firstly, we must take the PDE describing the flow process and “chop it up” into
grid blocks in space. This is known as spatial discretisation and, in this course,
we will exclusively use finite difference methods for this purpose.
(ii) When we apply finite differences, we usually end up with sets of non-linear
algebraic equations which are still quite difficult to solve. In some cases, we do
solve these non-linear equations. However, we usually linearise these equations
in order to obtain a set of linear equations.
(iii) We then solve the resulting sets of linear equations. Many numerical options
are available for solving sets of linear equations and these will be discussed below.
This is often done iteratively by repeatedly solving them until the numerical solution
converges.
This module will deal successively with each of the parts of the numerical solution
process, (i) - (iii) above.
4
Numerical Methods in Reservoir Simulation
6
dx ∂t ∂x
2
Approximation 1 -Forward Differences (fd): we may take the slope between Pi and
Pi+1 as being approximately dP at xi to obtain:
dx i
dP = Pi +1 − Pi
dx i fd ∆x (2)
Approximation 2 -Backward Differences (bd): we may take the slope between Pi-1
and Pi as being approximately
dP at x to obtain:
dx i
i
dP = Pi − Pi −1
dx i bd ∆x (3)
dP = 1 dP + dP = 1 Pi +1 − Pi + Pi − Pi −1
dx i cd 2 dx i fd dx i bd 2 ∆x ∆x
dP P −P
= i +1 i −1
dx i cd 2.∆x (4)
P(x)
Pi
Pi-1
∆x = constant
∆x ∆x
xi-1 xi xi-1 Figure 1
x
Notation for the application
Notation:
∆x = the x- grid spacing or distance between grid points of finite difference methods
(i - 1), i, (i + 1) = the x - label (subscript) for the grid point or block numbers
for approximating
Pi-1, Pi, Pi+1 = the corresponding function values at grid point i-1, i, i+1 etc.
derivatives.
dP
Each of the above approximations to is shown graphically in Figure 2.
dx i
You may wonder why we bother with three different numerical approximations to
dP
dx i and ask: which is “best”? There is not an unqualified answer to this question
just yet, but let us take a simple numerical example where we know the right answer
and examine each of the forward, backward and central difference approximations.
The values given in Figure 3 will illustrate how the methods perform. Firstly, simply
calculate the values given by each methods for the data in Figure 3:
The quantity in square brackets after each of the finite difference approximations
above is the error i.e. the difference between that method and the right answer which
is 2.7183. As expected from the figure for this case, the forward difference answer
is a little too high (by ≈ +0.14) and the backward difference answer is a little too
low (by ≈ -0.13). The central difference approximation is rather better than either
of the previous ones. In fact, we note that the fd and bd methods give an error of
order Δx, the grid spacing (where, as engineers, we are saying 0.14 ≈ 0.1 !). The
cd approximation, on the other hand, has an error of order Δx2 (where again we are
6
Numerical Methods in Reservoir Simulation
6
saying 0.005 (0.1x0.1 = 0.01). More formally, we say that the error in the fd and bd
approximations are "of order Δx" which we denote, O(Δx), and the cd approximation
has an error "of order Δx2" which we denote, O(Δx2).
∂2 P
2
Now consider the finite difference approximation of the second derivative, ∂x
∂P
Going back to Figure 1, the definition of second derivative at ∂x xi is the rate of
change of slope (dP/dx) at xi. Therefore, we can evaluate this derivative between xi-1
and xi (i.e. the bd approximation) and then do the same between xi and xi+1 (i.e. the
fd approximation) and simply take the rate of change of these two quantities with
respect to x, as follows:
dP − dP
∂ P
2 dx i fd dx i bd
2 ≈
∂x ∆x
Pi +1 − Pi − Pi − Pi −1
∆x i fd ∆x i bd
≈
∆x
∂2 P ( Pi +1 + Pi −1 − 2 Pi )
2 ≈
∂x ∆x 2 (6)
∂2 P
2
Calculating the numerical value of ∂x for the example in Figure 3 (where again
∂2 P
2 = 2.7183 since the example is the exponential function), gives:
∂x
Thus, we can see that the error in this case (err ≈ 0.0017 ≈ 0.12) is actually O(Δx2).
In the introductory section of Chapter 1, we already applied the idea of finite differences
(although we didn’t call it that at the time) to the simple ordinary differential equation
dN
(ODE); = α .N .
dt
Here, N (number of bacteria in the colony) as a function of time, N(t), is the unknown
we want to find. Denoting Nn and Nn+1 as the size of the colony at times t (labelled
n) and t+Δt (labelled n+1), we applied finite differences to obtain:
dt ∆t
N n +1 ≈ (1 + α .∆t ) N n (8)
This gave us our very simple algorithm to explicitly calculate Nn+1. We then took
this as the current value of N and applied the algorithm repeatedly.
dP Pi+1 - Pi-1
=
dx i cd 2.∆x
Pi+1
P(x)
dP Pi+1 - Pi
=
Pi dx i fd ∆x Figure 2
Pi-1 Graphical illustration of the
dP Pi - Pi-1 finite difference derivatives
=
dx i bd ∆x calculated by backward
∆x ∆x differences (bd), forward
xi-1 xi xi+1 differences (cd) and central
x ∆x = constant
differences.
Pi+1 3.0042
P(x)
Pi 2.7183
Pi-1 2.4596
Figure 3
A numerical example where
0.1 0.1
the function values and
0.9 1.0 1.1 derivative values are known
x
(P(x) = ex)
8
Numerical Methods in Reservoir Simulation
6
EXERCISE 1.
dy = 2. y 2 + 4
dt
where, at t = 0, y(t = 0) = 1. Take time steps of Δt = 0.001 (arbitrary time units) and
step the solution forward to t = 0.25. Use the notation yn+1 for the (unknown) y at
n+1 time level and yn for the (known) y value at the current, n, time level.
∂P k ∂2 P
=
∂t cφµ ∂x 2
(9)
k
where the constant cφµ is the hydraulic diffusivity, which we denoted previously
by Dh. As we noted in Chapter 5, this PDE is linear which has known analytical
solutions for various boundary conditions. However, we will again neglect these
and apply numerical methods as an example of how to use finite differences to solve
PDEs numerically. To make things even simpler, we will take Dh = 1, giving the
equation:
∂P ∂ P
2
= 2
∂t ∂x
(10)
This is the pressure equation for a 1D system where 0 ≤ x ≤ L, where L is the length
of the system. We can visualise this physically - much as we did in Chapter 5, Section
2.1 - using Figure 4. After the system is held constant at P = Po, the inlet pressure is
raised (at x = 0) instantly to P = Pin while the outlet pressure is held at Pout = Po.
t = t1 t = t2
P Figure 4
Physical picture of pressure
Po Pout = Po propagation in a 1D (com-
t=0 pressible) system described
0 x L
by. ∂P ∂ 2 P
= 2
∂t ∂x
These pressures, Pin and Pout, represent the constant pressure boundary conditions
(Mathematically these are sometimes called Dirichlet boundary conditions). In other
words, these are set, as if by experiment, and the system between 0 < x < L must “sort
itself out” or "respond" by simply obeying equation 10 above. We now approach
this problem using finite differences as follows:
• fix the boundary conditions which, in this case, are as follows (see Figure
4):
∂P P n +1 − Pi n
≈ i
∂t i ∆t (11)
and
∂2 P Pi ??+1 + Pi ??−1 − 2 Pi ??
2 ≈
∂x i ∆x 2 (12)
10
Numerical Methods in Reservoir Simulation
6
∂2 P Pi n+1 + Pi n−1 − 2 Pi n
2 ≈
∂x i ∆x 2 (13)
Equating the numerical finite difference approximations of each of the above derivatives
as required by the original PDE, equation 10 (i.e. equating the expressions in equations
11 and 13) gives:
Pi n +1 − Pi n Pi n+1 + Pi n−1 − 2 Pi n
≈
∆t ∆x (14)
which easily rearranges to obtain an explicit expression for, Pi n +1, the only
unknown in the above equation:
∆t
Pi n +1 = Pi n +
∆x 2
( Pi n+1 + Pi n−1 − 2 Pi n )
(15)
Equation 15 gives the algorithm for propagating the solution of the PDE forward in
time from the given set of initial conditions.
We now consider how to set the initial conditions. The initial conditions are the values
of all the P0i (i = 1, 2, 3 ... , NX) at t = 0. From Figure 4, these are clearly:
P10
P10
P1 = 1 for all time (boundary condition)
Pi 00
Pi 0 = 0 at time t = 0 for 2 < i < NX-1
Pi
0
PNX 0
= Po for all time (boundary condition)
PNX 0
PNX
Let us now apply the above algorithm to the solution of equation 10. For this
problem, suppose we take the following data:
0 ≤ x ≤ 1.0
Δx = 0.1 => implies 11 grid points, P1 , P2 , P3, .... , P11 (NX = 11).
Δt = 0.001
n +1
The problem is then to calculate the solution, P(x,t), - that is Pi for all i (at all
grid points) and all future times up to some final time (possibly when the equation
comes to a steady-state as will happen in this example). This can be done by filling
in the “solution chart” Table 1 - see Exercise 2 below.
Time
x= 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
t n (BC↓) (BC↓)
i= 1 2 3 4 5 6 7 8 9 10 11
0 0 P0
i
→ 1 0 0 0 0 0 0 0 0 0 0
(IC)
0.1 100 P100
i 1 0
EXERCISE 2.
∆t
2 ( i +1
Pi n +1 = Pi n + P n + Pi n−1 − 2 Pi n )
∆x
Hint: make up a spread sheet as above and set the first unknown block (shown grey
shaded in table above) with the above formula. Copy this and paste it into all of the
cells in the entire unknown area (surrounded by bold border above).
12
Numerical Methods in Reservoir Simulation
6
The assumption we made in equation 12 was that the spatial derivative was taken at
the n (known) time level. This allowed us to develop an explicit formula for Pi n +1
(for all i). This method is therefore known as an explicit finite difference method.
We can learn about some interesting and useful features of the explicit method
which is encapsulated in equation 15 by simply experimenting with the spreadsheet
CHAP6Ex2.xls. Three features of this method can be illustrated by “numerical
experiment” as follows:
(ii) the effect of refining the spatial grid size, Δx (or number of grid cells, NX);
EXERCISE 3.
• Sensitivity to Δx: the effects of grid refinement are that, as the grid blocks get
smaller (i.e. Δx → 0 or NX → ∞). The answer should get more accurate although,
to make this happen, you need to reduce the time step as well.
∂P ∂2 P
= 0, which implies => 2 = 0
∂t ∂x
But the “curve” with a zero second derivative (i.e. a first derivative which is constant)
is a straight line. Therefore, this result is physically reasonable and our numerical
model appears to be behaving correctly.
n n n
Time P i-1 Pi P i+1
∆x ∆x
Time level n
i-1 i i+1 Figure 5.
∆t Schematic of the explicit
finite difference algorithm
Time level n + 1
n+1 n+1 n+1 for solving the simple
P i-1 Pi P i+1
pressure equation (a PDE).
∂P P n +1 − Pi n
≈ i
∂t i ∆t (16)
∂2 P Pi n+1+1 + Pi n−1+1 − 2 Pi n +1
2 ≈
∂x i ∆x 2 (17)
As before, we now equate the numerical finite difference approximations of each of the
above derivatives (as required by the original PDE, equation 10) to obtain:
Pi n +1 − Pi n Pi n+1+1 + Pi n−1+1 − 2 Pi n +1
≈
∆t ∆x (18)
n +1
This equation shouldPibe compared with equation 14. In the previous case, this could
easily be rearranged intoPi +1 an explicit equation for Pi n +1 (equation 15). However,
n
equation 18 above cannot be rearranged to give a simple expression for the pressure
n +1 n +1
at the new time step P i −1 , Pi
(n+1), .and Pi n+1+1 there now appear to be three unknowns at
Indeed,
Pi n−1+1 , Ptoi n +be
time level (n+1), viz. Pi n−1+1 , Pi n +1 and Pi n+1+1 . This appears
1 n +1
a bitPiof
and +1 a paradox:
how do we find three unknowns from a single equation (equation 18 above)? The
answer is not really too difficult: Basically, we have an equation - like equation 18
- at every grid point. We will show below that this leads to a set of linear equations
where we have exactly the same number of unknowns as we have linear equations.
14
Numerical Methods in Reservoir Simulation
6
Therefore, if these equations are all linearly independent, then we can solve them
numerically. This is a bit more trouble than our earlier simple explicit finite difference
method. Because, we do not get an explicit expression for our unknowns - instead
we get an implicit set of equations - this method is known as an implicit finite
difference method.
To see where these linear equations come from, rearrange equation 18 above
to obtain:
∆x 2 n +1 ∆x 2 n
Pi n−1+1 − 2 + P
i
n + 1 + P n +1
= − P
∆t Pi
i +1
∆t i (19)
where all the unknowns ( Pi n−1+1 , Pi n +1 and Pi n+1+1 ) are on the LHS of the equation
and the term on the RHS is “known”, since it is at the old time level, n. We
can write this equation as follows:
∆x 2 ∆x 2 n
and where ai −1 = 1; ai = − 2 + ; a
i +1 = 1 and bi = − P
∆t ∆t i
are all constants. The ai do not change throughout the calculation but the quantity bi is
updated at each time step as the newly calculated Pn+1 is set to the Pn for the next time
step. We can see how this works for the 5 grid block system in Figure 6 below:
1 2 3 4 5
n n n n n
P1 P2 P3 P4 P5
Time level n ∆x
∆t
Time level n=1
Figure 6.
P n+1
1
P n+1
2
P n+1
3
P n+1
4
P n+1
5
Simple example of a 5 grid
block system showing how
Boundary Boundary
the implicit finite difference condition condition
scheme is applied (fixed) (fixed)
At each grid point, then (a) we know the value from the boundary condition (i =
1 and i = 5), (b) it uses a boundary condition (i=2 and i=4) or (c) it is specified
completely by equation 20 (only i = 3, in this case - but it would be most points
for a large number of grid points).
∆x 2 n
i=3 P2n +1 + a3 P3n +1 + P4n +1 = b3 = − P
∆t 3
∆x 2 n
P3n +1 + a4 P4n +1 + P5 = b4 = − P
∆t 4
i=4
∆x 2 n
=> P3n +1 + a4 P4n +1 = − P − P5
∆t 4
Therefore there are only three unknowns in the above set of linear equations
( P2n +as
( P2n +1 , P3n +1 and P4n +1 ) which can be summarised
1
,P n +1
and P4n +1 )
follows:
3
∆x 2 n
i = 2: a2 P2n +1 + P3n +1 = − P − P1
∆t 2
n +1 n +1 n +1 ∆x 2 n
i = 3: P2 + aP 3 3 + P 4 = − P
∆t 3
n +1 n +1 ∆x 2 n
i = 4: P 3 + aP 4 4 = − P − P5
∆t 4
(21)
Note that the set of linear equations above can be represented as a simple
matrix equation as follows:
∆x 2 n
− P2 − P1
P2n +1 ∆t
a2 1 0
∆x 2
n +1
a3 P3 = − P3
n
1 1
∆t
0 1 a4 n +1
P4
− ∆x P n −
2
P5
∆t 4
(22)
16
Numerical Methods in Reservoir Simulation
6
The structure of this matrix equation
P1 and Pis clearer when there are more equations
12
involved. For example, it is quite easy to show that, if we take 12 grid points instead
of the 5 above, we obtain 10 equations (using the two fixed boundary conditions,
P1 and P12 ) for the quantities, P2n +1 , P3n +1 , P4n +1 ....P11n +1, of the form:
− ( ∆x 2 ∆t ) P2n − P1
n +1 n +1 n +1 n +1 P2n +1
P2a2 , P
13 ,0P 4 0 ....P110 0 0 0 0 0 n +1 − ( ∆x 2 ∆t ) P3n
1 a3 1 0 0 0 0 0 0 0 P3
n +1 − ( ∆x 2 ∆t ) P4n
0 1 a4 0 0 0 0 0 0 0 P4
P n +1 − ( ∆x 2 ∆t ) P5n
0 0 1 a5 1 0 0 0 0 0 5
0 0 0 1 a6 1 0 0 0 0 P6n +1 − ( ∆x 2 ∆t ) P6n
n +1 =
0 0 0 0 1 a7 1 0 0 0 P7 − ( ∆x 2 ∆t ) P7n
0
0 0 0 0 1 a8 1 0 0 n +1
− ( ∆x 2
P8 ∆t ) P8n
0 0 0 0 0 0 1 a9 1 0 P n +1
9 − ( ∆x 2 ∆t ) P9n
0 0 0 0 0 0 0 1 a10 1 P10n +1
0 0 0 0 0 0 0 0 1 a11 n +1 − ( ∆x 2 ∆t ) P10n
P11
− ( ∆x 2 ∆t ) P11n − P12
(23)
− ( ∆x 2 ∆t ) P2n − P1
P2n +1 − ( ∆x 2 ∆t ) P3n
n +1
a2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
P3 − ( ∆x 2 ∆t ) P4n
1 a3 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 n +1
P4 − ( ∆x 2 ∆t ) P5n
0 1 a4 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 P n +1
0 1 a5 1 0 0 0 0 0 0 0 0 0 0 0 0 0
5 − ( ∆x 2 ∆t ) P6n
0 P6n +1
0 0 0 1 a6 1 0 0 0 0 0 0 0 0 0 0 0 0 n +1 − ( ∆x 2 ∆t ) P7n
P7
0 0 0 0 1 a7 1 0 0 0 0 0 0 0 0 0 0 0 − ( ∆x 2
n +1 ∆t ) P8n
0 0 0 0 0 1 a8 1 0 0 0 0 0 0 0 0 0 0 P8
P n +1 − ( ∆x 2 ∆t ) P9n
0 0 0 0 0 0 1 a9 1 0 0 0 0 0 0 0 0 0 9
P10n +1 − ( ∆x 2 ∆t ) P10n
0 0 0 0 0 0 0 1 a10 1 0 0 0 0 0 0 0 0
0
n +1 =
0 0 0 0 0 0 0 1 a11 1 0 0 0 0 0 0 0 P11 −( ∆x 2 ∆t ) P11n
n +1
0 0 0 0 0 0 0 0 0 1 a12 1 0 0 0 0 0 0 − ( ∆x 2
0
P12 ∆t ) P12n
0 0 0 0 0 0 0 0 0 1 a13 1 0 0 0 0 0 P n +1
− ( ∆x 2
0 0 0 0 0 0 0 0 0 0 0 1 a14 1 0 0 0 0
13 ∆t ) P13n
P n +1
− ( ∆x 2
0 0 0 0 0 0 0 0 0 0 0 0 1 a15 1 0 0 0 14 ∆t ) P14n
P15n +1
0 0 0 0 0 0 0 0 0 0 0 0 0 1 a16 1 0 0 − ( ∆x 2
n +1 ∆t ) P15n
P16
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 a17 1 0 − ( ∆x 2
0
n +1 ∆t ) P16n
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 a18 1 P17
− ( ∆x 2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 a19
P n +1 ∆t ) P17n
18
P19n +1 − ( ∆x 2 ∆t ) P18n
( ∆t ) P19 − P20
− ∆x 2 n
(24)
(i) It is tridiagonal - that is, it has a maximum of three non-zero elements in any
row and these are symmetric around the central diagonal;
(ii) It is very sparse - that is, most of the elements are zero. In an MxM matrix,
there are only 3M non-zero terms but M2 actual elements. If M = 100, then the
matrix is only (300/1002)x100% = 3% filled with non-zero terms.
18
Numerical Methods in Reservoir Simulation
6
THE THOMAS ALGORITHM
subroutine thomas
c Thomas algorithm for tridiagonal systems
+ (N ! matrix size
+ ,a ! diagonal
+ ,b ! super-diagonal
+ ,c ! sub-diagonal
+ ,s ! rhs
+ ,x ! solution
+ )
c----------------------------------------
c This program accompanies the book:
c C. Pozrikidis; Numerical Computation in Science and Engineering
c Oxford University Press, 1998
c------------------------------------------------
c Coefficient matrix:
c | a1 b1 0 0 ... 0 0 0 |
c | c2 a2 b2 0 ... 0 0 0 |
c | 0 c3 a3 b3 ... 0 0 0 |
c | .............................. |
c | 0 0 0 0 ... cn-1 an-1 bn-1 |
c | 0 0 0 0 ... 0 cn an |
c------------------------------------------
Implicit Double Precision (a-h,o-z)
Dimension a(200),b(200),c(200),s(200),x(200)
Dimension d(200),y(200)
Parameter (tol=0.000000001) this is a measure of how close to coverage we are
c prepare
Na = N-1
c reduction to upper bidiagonal
d(1) = b(1)/a(1)
y(1) = s(1)/a(1)
DO i=1,Na
i1 = i+1
Den = a(i1)-c(i1)*d(i)
d(i1) = b(i1)/Den
y(i1) =(s(i1)-c(i1)*y(i))/Den
End DO
c Back substitution
x(N) = y(N)
DO i=Na,1,-1
x(i)= y(i)-d(i)*x(i+1)
End DO
c Verification and alarm
Res = s(1)-a(1)*x(1)-b(1)*x(2)
If(abs(Res).gt.tol) write (6,*) “ thomas: alarm”
DO i=2,Na
Res = s(i)-c(i)*x(i-1)-a(i)*x(i)-b(i)*x(i+1)
If(abs(Res).gt.tol) write (6,*) “ thomas: alarm”
End DO
Figure 7. Res = s(N)-c(N)*x(N-1)-a(N)*x(N)
The Thomas algorithm for If(abs(Res).gt.tol) write (6,*) “ thomas: alarm”
the solution of tridiagonal c Done
matrix systems. 100 Format (1x,f15.10)
Return
End
Institute of Petroleum Engineering, Heriot-Watt University 19
Finally, we note that the implicit finite difference method can be viewed as shown
in Figure 8 below. The choice of the (n+1) time level for the spatial discretisation
leads to a set of linear equations which are somewhat more difficult to solve than the
simple algebraic equation that arises in the explicit method (equation 15). However,
there are exactly the same number of linear equations as there are unknowns and so
it is possible to solve these.
n n n
Time P i-1 Pi P i+1
∆x ∆x
Time level n
i-1 i i+1 Figure 8.
∆t
Schematic of the implicit
finite difference algorithm
Time level n + 1
n+1 n+1 n+1 for solving the simple pres-
P i-1 Pi P i+1
sure PDE
(iii) the issue of non-linearity for a compressible system e.g. c(P) is clearly a
function of P(x,t), which is the “unknown”.
cµφ ∂P ∂ ˜ ∂P ∂ ∂P
= kx + k̃ y
k ∂t ∂x ∂x ∂y ∂y (25)
k˜ x and k˜ y cφµ
k
cφµ k˜ x and k˜ y
(a
k simplified form of equation 39, Chapter 5) where the term k is a constant
which we will denote as β below, k is an average permeability of the entire
reservoir and k˜ x and k˜ y are the local permeabilities normalised by k ; i.e.
k non-linearities for
k˜ x = k x / k and k˜ y = ky / k. Note that we have avoided the
the moment (the quantities c(P), μ and ρ usually depend on pressure). However, the
k k˜ x = k x / k and k˜ y = ky / k.
20
k˜ x = k x / k and k˜ y = ky / k.
Numerical Methods in Reservoir Simulation
6
system may be anisotropic (kx ≠ ky) and heterogeneous (the permeability may vary
from grid block to grid block).
i, j + 1
(j + 1/2)
∆y
i - 1, j i, j i + 1, j
(j - 1/2)
Figure 9. i, j - 1
y (j)
Discretisation and notation
∆x
for the 2D pressure 1/ )
(i - 2 (i + 1/2)
equation. x (i)
∂P ∂ ∂P ∂ ∂P
β = k˜x + k˜y
∂t ∂x ∂x ∂y ∂y
(26)
we obtain:
˜ ∂P ∂P ˜ ∂P ∂P
− k˜ x k y − k˜ y
k x ∂x
n +1
P −P
n
i +1/ 2 ∂x i −1/ 2 ∂y j +1/ 2 ∂y j −1/ 2
β ≈ +
∆t ∆x ∆y
(27)
where the (i ± 1/2) and (j ± 1/2) subscripts refer to quantities at the boundaries as
shown in Figure 9. We can now expand these boundary flows as follows:
(˜ ) (˜ ) (˜ )
where the quantities k x i +1/ 2 , k x i −1/ 2 , k y j +1/ 2 and k y j −1/ 2 are some type of (˜ )
average permeabilities between the two neighbouring grid blocks - as discussed in
Chapter 4. Note also we have chosen the spatial discretisation terms at the new (n+1)
time level making the this an implicit finite difference scheme.
We can rearrange equation 28 above by taking all the unknown terms (at n+1) to the
LHS and the known terms (at time level n) to the RHS. This gives the following:
−
( )
k˜ x
i −1 / 2
P n +1
−
( )
k˜ x
i +1 / 2
P n +1
+
( )
k˜
x
i −1 / 2
+
( )
k˜ x
i +1 / 2
+
( )
k˜ y
j −1 / 2
+
( )
k˜ y
j +1 / 2
−
β n +1
Pi , j
i −1, j i +1, j
∆x 2 ∆x 2 ∆x
2
∆x 2 ∆y 2 ∆y 2 ∆t
−
( )
k˜ x
j −1 / 2
P n +1
−
( )
k˜ y
j +1 / 2
Pi ,nj++11 =
β n
Pi , j
i , j −1
∆y ∆y ∆t
2 2
(29)
Since the coefficients in equation 29 above are constants, then this defines a set of
linear equations similar to those found in 1D. However, here we have up to five
non-zero terms per grid block to deal with rather than the three we found for the
1D system. The matrix which arises in this 2D case is known as a pentadiagonal
matrix. This set of linear equations can be written as follows:
ai −1, j .Pi n−1+,1j + ai +1, j .Pi n+1+,1j + ai , j .Pi ,nj+1 + ai , j −1 .Pi ,nj+−11 + ai , j +1 .Pi ,nj++11 = bi , j
(30)
where the constant coefficients, ai −1, j , ai +1, j , ai , j , ai , j −1 and ai , j +1 , are given by the
coefficients in equation 29; bi, j is also a (know) constant.
22
Numerical Methods in Reservoir Simulation
6
j=5 m = 17 m = 18 m = 19 m = 20
j=4 m = 13 m = 14 m = 15 m = 16
j=3 m=9 m = 10 m = 11 m = 12
j=2 m=5 m=6 m=7 m=8
j=1 m=1 m=2 m=3 m=4
i=1 i=2 i=3 i=4
Notation:
NX = maximum number of grid blocks in x - direction, i = NX;
Figure 10. NY = maximum number of grid blocks in y - direction, j = NY
Numbering system for 2D m = grid block number in the natural ordering scheme shown
m = (j - 1).NX + i
grid conversion from (i,j) →
e.g. for i = 3, j = 4 and NX = 4, m = (4 - 1).4 + 3 = 15 (as above)
m counter.
where the ãm are the reordered coefficients where the subscript is calculated from
the m-formula in Figure 10. For example:
Note that, when we apply the above equation numbering scheme to the example in
Figure 10 (NX = 4, NY = 5 and therefore, 1 ≤ m ≤ 20), certain “neighbours” are
“missing” since a block is at the boundary (or in a corner where two neighbours are
missing). For example, for block (i = 3; j = 3), that is block m = 9, the “j-1 block” is
not there. Therefore, the coefficient Am-1 =0 in this case. This is best seen by writing
out the structure of the 20 x 20 A-matrix by referring to Figure 10; the A-matrix
structure is shown in Figure 11.
Note that the A-matrix structure in Figure 11 is sparse and has a maximum of five
non-zero coefficients in a given row - it is a pentadiagonal matrix.
All implicit methods for discretising the pressure equation lead to sets of linear
equations. These have the general matrix form:
A.x = b (34)
where A is a matrix like the examples shown above, x is the column vector of unknowns
(like the pressures) and b is a column vector of the RHSs. This is just like equation
31 but it is in shorthand form. We will discuss methods for solving these equations
later in this chapter. For the meantime, we will just assume that it can be solved. We
next consider when the PDEs describing a phenomenon are non-linear PDEs.
∂P ∂ kx ρ ∂P ∂ ky ρ ∂P
c( P) = +
∂t ∂x µ ∂x ∂y µ ∂y
(35)
where the non-linearities arise in this equation due to the dependence of the generalised
compressibility, c(P), the density, ρ(P) and the viscosity, μ(P), on pressure, P(x,t). It
is the pressure that is the main unknown in this equation and, hence, if these quantities
depend on it, then they introduce difficulties into the equations. In fact, we will see
shortly that the equations that arise are not linear equations - they are non-linear
algebraic equations.
24
Numerical Methods in Reservoir Simulation
6
Proceeding as before, we can discretise the above equation as follows:
kx ρ ∂P kx ρ ∂P ky ρ ∂P k ρ ∂P
− − y
P n +1 − P n µ ∂x i +1/ 2 µ ∂x i −1/ 2 µ ∂y j +1/ 2 µ ∂y j −1/ 2
c( P) = +
∆t ∆x ∆y
(36)
where we have not yet decided on the time level of the non-linearities (i.e. the time
level of the pressure, Pn or Pn+1, at which we evaluate c, ρ and μ). The most difficult
case would be if these were set at the “unknown” time level Pn+1 and this is what we
will do as follows:
k ρ n +1 ∂P k ρ n +1 ∂P
x − x
P n +1
− P n
µ ∂x µ ∂x i −1/ 2
c( P n +1 ) =
i +1 / 2
∆t ∆x
ky ρ n +1 ∂P ky ρ n +1 ∂P
−
µ ∂y j +1/ 2 µ ∂y j −1/ 2
+
∆y
(37)
∂P ∂P
Now expanding up the and terms gives:
∂x ∂y
n +1 n +1
kρ kρ Pi ,nj+1 − Pi ,nj+−11
+ y 2
µ.∆y j +1/ 2
(
Pi ,nj++11 − Pi ,nj+1 ) − y 2
µ.∆y j −1/ 2 ∆y
(39)
α in−+11, j .Pi n−1+,1j + α in++11, j .Pi n+1+,1j + α in, +j 1 .Pi,nj+1 + α in, +j −11 .Pi,nj+−11 + α in, +j +11 .Pi,nj++11 = βin, +j 1
(41)
where the elements of theA-matrix (now denoted α in−+11, j , α in, +j −11 , α in, +j 1 , α in++11, j and α in, +j +11 )
are not constants since they depend on the (unknown) value of Pn+1.
(i) We can actually use a numerical equation solver which is specifically designed
to solve more difficult non-linear problems. An example of this type of approach
is in using the Newton-Raphson method. We will return to this method later (once
we have seen how to solve linear equations).
(i) We can choose to apply a more pragmatic algorithms such as the following:
(a) Although our α-terms in equation 41 are strictly at time level (n+1), simply
take them at time level n, as a first guess. So we approximate equation 41 by the
following first guess:
α in−1, j .Pi n−1+,1j + α in+1, j .Pi n+1+,1j + α in, j .Pi,nj+1 + α in, j −1 .Pi,nj+−11 + α in, j +1 .Pi,nj++11 = βin, j
Pi ,nj+1 α in−1, j , α in+1, j , α in, j , α i(42)
n
, j −1 , α i , j +1 and β i , j
n n
n +1
Pi , at
where the quantities α in−1, j , α in+1, j , α in, j , α in, j −1 , α in, j +1 and βin, j are evaluated j the
[(
α iν, j = α i , j Pi,nj+1 )]
ν
(P )
n +1 ν
i, j
(43)
26
Numerical Methods in Reservoir Simulation
6
Pi ,nj+1
ν
(c) Use the latest iterated values of the α i , j to solve the (now linear) equations to
(P ) n +1 ν
( )
ν +1
go from i, j to Pi ,nj+1 .
∑ (P ) n +1 ν +1
( )
ν
Err = i, j − Pi ,nj+1
all i , j (44)
The algorithm outlined in (ii) above for solving the non-linear pressure equation
is represented in Figure 12.
( )
n ν
values of pressure = Pi , j
[(
α iν, j = α i , j Pin, j+1 )]
ν
where ν = current iteration number.
( )
ν +1
to obtain Pin, j+1 = Pin, j+1
Calculate
∑ (P ) n +1 ν +1
( )
ν
Err = i, j − Pi ,nj+1
all i , j
No - continue iterations
Err < Tol ?
Figure 12.
Algorithm for the numerical Yes (the method has converged)
solution of the non-linear
Stop
2D pressure equations:
From Chapter 5, we use the highly simplified form of the 1D pressure and saturation
equations, where we choose to solve for ⇒ P(x,t) and So (x,t) as shown in Chapter
5, equations 81 and 82. Note that we have taken zero capillary pressure (therefore
P = Po = Pw) and zero gravity which gives:
∂ ∂P
PRESSURE EQUATION λ T ( So ) = 0 (45)
∂x ∂x
∂S ∂ ∂P
SATURATION EQUATION φ o = λ o ( So ) (46)
∂t ∂x ∂x
The quantity λ T ( So ) is the total mobility and is the sum of the oil and water mobilities;
λ T ( So ) = λ o ( So ) + λ w ( So ) . The above two equations are clearly coupled together since
the oil saturation appears in the non-linear coefficient of the pressure equation. Likewise,
λ T ( So ) in
the pressure appears (So ) + λterm
= λthe
o flow w
(Soon) the RHS of the saturation equation.
We can now apply finite differences to each of these equations in the same
way as discussed above to obtain, for the pressure equation (see notation in
Figure 8):
∂P ∂P
λ T ( So ) ∂x − λ T ( So )
∂x i −1/ 2
i +1 / 2
=0
∆x (47)
Pi n+1+1 − Pi n +1 Pi n +1 − Pi n−1+1
λ ( S
T o )
∆x
− λ ( S
i +1/ 2 T o
)
∆x
i −1 / 2
=0
∆x (48)
28
Numerical Methods in Reservoir Simulation
(λ (S )) T o i +1 / 2
and λ T (So ) ( ) i −1 / 2
6
(λ (S )) ( )
n +1
T o and λSTo(So )
i +1 / 2 i −1 / 2
(λ ((λS (S)) ))
n +1
(λ ( S ))
( )
n +1 nT+1 o
( ) n +1 o i +1 / 2
λ
(λ (S )) ∆x ( P − P ) − ∆x ( P − P ) = 0
S
n +1 T o
T i +1 / 2 n +1 n +1 T o
i −1 / 2 n +1 n +1
i +21 / 2 i +1 i 2 i i −1
T o
i −1 / 2
(λ (S )) n +1
(λ (S ))
o
n +1 (49) T i −1 / 2
T o
i −1 / 2
The above equation can now be arranged into the usual order as follows:
(λ (S ))
T
n +1
o
i −1 / 2
P n +1
−
T (
λ ( Son +1 ) ) i −1 / 2
+
(λ (S )) T
n +1
o
i +1 / 2
P n +1 + T o
(
λ ( S n +1 ) ) i +1 / 2
Pi n+1+1 = 0
i −1
∆x 2
∆x 2 ∆x 2
i ∆x 2
(50)
n +1 n +1 n +1
P i −1 , Pi and P i +1
This is a non-linear set of algebraic equations for the unknown pressures,
Pi n−1+1 , Pi n +1 and Pi n+1+1 , but the coefficients depend on the - also unknown - saturations,
Son +1. Note that equation 50 represents one of a set of equations since there is one
at each grid point (and at the ends of the 1D system the values may be set by the
Son +1
boundary conditions).
We now consider the discretisation of the saturation equation 46. Finite differences
may be applied to this equation as follows:
∂P ∂P
λ o ( So ) ∂x
n +1
− λ o ( So )
∂x i −1/ 2
S −S n
i +1 / 2
φ =
oi oi
∆t ∆x (51)
Again, we can expand the derivative terms at the (i+1/2) and (i-1/2) boundaries (Figure
9) and we can take the mobility terms at the (n+1) time level to obtain:
Soin+1 − Soin λ o ( So )
n +1
( ) (
λ ( Son +1 ) )
φ
∆t
=
∆x 2
i +1 / 2
(P n +1
i +1 − Pi n +1
) − o ∆x 2 i −1 / 2
(P
i
n +1
−P n +1
i −1 )
(52)
The above non-linear algebraic set of equations can be written in various ways. Two
particularly useful ways to write the above equations are as follows:
∆t λ o ( So )
n +1
( ) (
λ ( Son +1 ) )
Sn +1
oi =S +
n
φ
oi
∆x 2
i +1 / 2
(P n +1
i +1 − Pi n +1
) − o ∆x 2 i −1 / 2
(P
i
n +1
−P n +1
i −1 )
(53)
or Form B:
∆t λ o ( So )
n +1
( ) (
λ ( Son +1 ) )
n +1
Sn +1
oi −S −
n
φ
oi
∆x 2
i +1 / 2
(P n +1
i +1 − Pi n +1
) − o ∆x 2 i −1 / 2
(i
P n +1
− Pi −1 ) = 0
(54)
The reason for writing the above two forms of the saturation equation is that each is
useful, depending on how we intend to approach the solution of the coupled pressure
(equation 45) and saturation (equation 46) equations.
As with the case of the solution of the non-linear single phase pressure equation for
a compressible system, we have two strategies which we can use to solve the two-
phase equations above, as follows:
(i) We can actually use a numerical equation solver which is specifically designed to
solve more difficult non-linear problems; e.g. the Newton-Raphson method. We will
return to this method later (once we have seen how to solve linear equations).
(i) We can again choose to apply a more pragmatic algorithm and this is the subject
of section 4.2 below.
Pressure:
(λ (S ))
T
n +1
o
i −1 / 2
P n +1
−
(
λ ( Son +1 )
T ) i −1 / 2
+
(λ (S ))
T
n +1
o
i +1 / 2
P n +1 + T o
(
λ ( S n +1 ) ) i +1 / 2
Pi n+1+1 = 0
i −1
∆x 2
∆x 2 ∆x 2
i ∆x 2
(50)
Saturation:
(
∆t λ o ( So )
n +1
) λ ( Son +1 ) ( )
n +1
Soin+1 + Soin −
φ ∆x 2
i +1 / 2
( i +1 i ) − o ∆x 2
P n +1
− P n +1 i −1 / 2
(i
P n +1
− Pi −1 )
(53)
30
Numerical Methods in Reservoir Simulation
6
Pressure equation 50 would be a set of linear equations if the coefficients were
known at the current time step (n), rather than being specified at the (n+1) - i.e. the
unknown - time level. However, we could solve equation 50 above as if it were
Pi n−1+1 , Pi n +1 and Pi n+1+1
a linear system of equations by time-lagging Pi n−1+1as
the coefficients n +1
, Pbefore and
P 1 n +nthe
n +(see
P +i1 1+1 and Pi n+1+1
i i −1 , iP
algorithm in Figure 13). This would give us a “first guess” (or first iteration) to find
Pi n−n1++11, Pi nn++11and Pi n+n1++11
the unknowns i.e. the quantities Pin−+11 , Pi and Pi +1 . The same problem exists
P
forPthen +1saturation
, P n +1 equation
and P n +1 53, if wei had the first guess at the Pi n +1 (by thePprocedure i
n +1
i −1 i i +1
just mentioned), then we could use Pi nthese
+1 latest values of pressure and still time lag
n +1
the coefficients (the oil mobility Sterms)Pni +1 and use the saturation equation 53 as if it
+1
werePi n an
o
+1 explicit expression. This would give us an updated Sonvalue of Son +1 which
could then be used back in the pressure Sonn++11 equation and the whole process could be
So n +1 νpreviously.
( ) ( )
iterated until convergence, as discussed
( () ) ( ) A flow chart of this procedure
ν ν
Pi −1 , Pi n +1 and Pi n+1+1 .n +1 ν n +1n +ν1 ν n +1n +ν1 ν
hasSalready been outlined in Chapter 5 (Figure 9) but is elaborated
o
n + 1
( ) (( ))
P i −1 ,herePi Pin
i −1
Figure
and, Pi Pi +1 and.
( P ) , ( P ) and ( P )
i −n1 +1 ν i n +1 ν i +n1 +1 ν
( P as) the
known i −1 , ( PIMPES
n +1 ν
) and
i ( P ) which stands for IMplicit(Sin Pressure,
n +1 ν
approximation,
n +1 ν
i +1
i i +1
) , (S(S Explicit
) )etc.
, ( S ) etc.
i
n +1 ν n +1n +ν1 ν
i +1i
n +1 ν
i +1
in Saturation. This can be iterated(until
S )it,converges
((SS )) etc.
n +1 ν n +1 ν
although there are limitations in
( S ) , i n +1 ν
etc. i +n1+1 ν
the size of time step, Δt, which can be taken. If Δt is too large, the IMPES method
i i +1
may(Sbecome
i ) , (Sunstable
n +1 ν
) etc.and give unphysical results like the example in Exercise 3
n +1 ν
i +1
above.
PRESSURE EQUN. Set the total mobilities ⇒ λ T (Soν )i +1/ 2 and λ T (Soν )i −1/ 2
obtain the linearised pressure equation:
(λ (S ))
T
ν
o
λ (Soν )
Pin−+11 −
T
i −1 / 2 i −1 / 2
+
( )
λ T (Soν ) (
i +1 / 2 n +1
Pi +
λ T (Soν ) )
i +1 / 2
Pin++11 = 0
( )
∆x 2
∆x 2
∆x 2
∆x 2
Solve this linear implicit pressure equation for pressure at iteration, ν, to
obtain:
SATURATION EQUN. Now update the saturation equation as if it were explicit by taking
ν ν
(i) the oil mobility terms at the latest iteration, ν ⇒ λ 0 (So )i λ 0 (So )i +1 , etc.
(ii) the latest values of the pressures just calculated implicity ⇒ ( Pin−+11 ) , ( Pin +1 ) and ( Pin++11 )
ν ν ν
(
∆t λ o (So ) i +1/ 2
ν
) (
λ (Soν ) )
Soin+1 = Soin +
φ ∆x 2
(
(Pin++11 ) − (Pin +1 )
ν ν
) − o
∆x 2
i −1 / 2
(
(Pin +1 ) − (Pin−+11 )
ν ν
)
ν = ν +1
NX NX
Err. = ∑ ( Pin +1 ) − ( Pin +1 ) + ∑ (Sin +1 ) − (Sin +1 )
ν ν −1 ν ν −1
i =1 i =1
Figure 13.
Note that the Err. term above would have some scaling factors weighing the IMPES Algorithm for the
pressure and saturation terms because of the units of pressure.
numerical solution of the
two-phase pressure and sat-
No - continue iteration Yes
uration equations (IMPES
Is Err. < Tol ? Stop
⇒ IMplicit in Pressure,
Explicit in Saturation)
32
Numerical Methods in Reservoir Simulation
6
5 THE NUMERICAL SOLUTION OF LINEAR EQUATIONS
where the aij and bi are known constants and the xi (i = 1, 2, ... , n) are the unknown
quantities which we are trying to find. The xi in our pressure equation, for example,
would be the unknown pressures at the next time step.
and the set of linear equations can be written in very compact form as follows:
A.x = b (58)
4. x1 + 2. x2 + 1. x3 = 13
1. x1 + 3. x2 + 3. x3 = 14
2. x1 + 1. x2 + 2. x3 = 11 (59)
How do we solve these? In the above case, you can do a simple trial and error
solution to find that x1 = 2, x2 = 1 and x3 = 3, although this would be virtually
impossible if there were hundreds of equations. Remember, there is one equation for
every grid block in a linearised pressure equation in reservoir simulation (although
there are lots of zeros in the A matrix). This implies that we need a clear
numerical algorithm that a computer can work through and solve the linear
equations. The overview of approaches to solving these equations is discussed
in the next section.
34
Numerical Methods in Reservoir Simulation
6
Basically, there are two main approaches for solving sets of linear equations involving
direct methods and iterative methods as follows:
(i) Direct Methods: this group of methods involves following a specific algorithm
and taking a fixed number of steps to get to the answer (i.e. the numerical values
of x1, x2 .. xn). Usually, this involves a set of forward elimination steps in order to
get the equations into a particularly suitable form for solution (see below), followed
by a back substitution set of steps which give us the answer. An example of such
a direct method is Gaussian Elimination.
(ii) Iterative Methods: in this type of method, we usually start off with a first guess
(or estimate) to the solution vector, say x(o) . Where we take this as iteration zero,
v = 0. We then have a procedure - an algorithm - for successively improving this
guess by iteration to obtain, x(1) → x(2) → x(3) .... → x(ν) etc. If it is successful, then
this iterative method should converge to the correct x as ν increases. The solution
should get closer and closer to the “correct” answer but, in many cases, we cannot
say exactly how quickly it will get there. Therefore, iterative methods do not
have a fixed number of steps in them as do direct methods. Examples of iterative
methods are the Jacobi iteration, the LSOR (Line Successive Over Relaxation)
method, etc.
The following two sections will discuss each of these approaches for solving
sets of linear equations in turn.
A.x = b (60)
Remember that any mathematical operation we perform on one of the linear equations
(e.g. multiplying through by x2) must be performed on both sides of the equation i.e.
The C-matrix above is in upper triangular form i.e. only the diagonals and above
are non-zero (cij ≠ 0, if j ≥ i) and all elements below the diagonal are zero (cij = 0,
if i > j), as shown above. Now consider why this particular form is of interest in
solving the original equations. The reason is that, if we have formed the augmented
matrix correctly (i.e. doing the same operations to the A and b coefficients), then the
following matrix equation is equivalent to the original matrix equation:
Therefore,
This matrix equation is very easy to solve, as can be seen by writing it out
in full as follows:
36
Numerical Methods in Reservoir Simulation
6
c11 . x1 + c12 . x2 + c13 . x3 + c14 . x4 + c15 . x5 ... + c1n . xn = e1
cn −1, n −1 . xn −1 + cn −1, n . xn = en −1
cnn . xn = en
(65)
We can easily solve this equation by back-substitution, starting from the equation n
which only has one term to find xn, this xn is then used in the (n-1) equation (which
has 2 terms) to find xn-1 etc. as follows:
e − c .x
cn −1, n −1 . xn −1 + cn −1, n . xn = en −1 => xn −1 = n −1 n −1, n n use xn −1 , xn in ..
cn −1, n −1
cn − 2, n − 2 . xn − 2 + cn − 2, n −1 . xn −1 + cn − 2, n . xn = en − 2
e - cn − 2, n −1 . xn −1 − cn − 2, n . xn
=> xn − 2 = n − 2 etc.
cn − 2, n − 2
(66)
Hence, by working back through these equations in upper triangular form, we can
calculate xn, xn-1, , xn-2.... back to x1.
Solve
4 x -the1following
x − 2 x simple
+ 1example
x + 1ofx an
= upper
5 triangular matrix:
1 2 3 4 5
4 x1 - 1x2 − 2 x3 + 1 x 4 + 1x 5 = 5
2 x 2 − 2 x3 + 1x4 + 2 x5 = 12
2 x2 − 2 x3 + 1x4 + 2 x5 = 12
3 x3 + 4 x4 + 1x5 = 30
3 x3 + 4 x4 + 1x5 = 30
2 x4 − 1x 5 = 3
2 x 4 − 1x 5 = 3
3 x5 = 15
3 x5 = 15
Answer
Answer:
Answer
x1 = ..........; x2 = ..........; x3 = ..........; x4 = ..........; x5 = ..........
x1 = ..........; x2 = ..........; x3 = ..........; x4 = ..........; x5 = ..........
Our simple scheme starts with the longhand version of a set of linear equations and,
for our purposes, we will just take a set of four linear equations as follows:
38
Numerical Methods in Reservoir Simulation
6
1
x1 =
a11
[
b1 − ( a12 x2 + a13 x3 + a14 x4 )]
1
x2 =
a22
[
b2 − ( a21 x1 + a23 x3 + a24 x4 ) ]
1
x3 =
a33
[
b3 − ( a31 x1 + a32 x2 + a34 x4 ) ]
1
x4 =
a44
[
b4 − ( a41 x1 + a42 x2 + a43 x3 ) ]
(68)
The resulting equations are precisely equivalent to the original set although, if
anything, they look a bit more complicated. Why would we deliberately complicate
the situation? In fact, the above reorganised equations forms the basis for an
iterative scheme, which we can use to solve the equations numerically. Firstly, we
need to introduce some notation as follows:
Notation:
(ν )
xi
xi(v) - the solution for xi at iteration ν; where ν is the iteration
counter.
Using the above notation in equations 68 above, gives the following simple iteration
scheme:
x2(ν +1) =
1
a22
[
b2 − ( a21 . x2(ν ) + a23 . x3(ν ) + a24 . x4(ν ) ) ]
x3(ν +1) =
1
a33
[
b3 − ( a31 . x1(ν ) + a32 . x2(ν ) + a34 . x4(ν ) ) ]
x4(ν +1) =
1
a44
[
b3 − ( a41 . x1(ν ) + a42 . x2(ν ) + a43 . x3(ν ) ) ] (69)
(ii) Update the solution to the next iteration ν+1 using equations 69
4
Err. = ∑ xik +1 − x ki
(iii) Estimate an Error term (Err.) by comparing the latest with the previous
i =1
iteration of the unknowns, e.g.:
4
Err. = ∑ xiν +1 − xiν
i =1
If yes - the scheme has converged; if no - go back to step (ii) and continue
the iterations.
Example: Solve the following set of equations using the iterative scheme above.
40
Numerical Methods in Reservoir Simulation
6
(0) (0) (0) (0)
Take the first guess: x1 = 2, x2 = 2, x3 = 2, x4 = 2
(
x1(ν +1) = (1 / 3.1) * 13.92 - (- 0.32 x2(ν ) + 0.5 x3(ν ) + 0.1x4(ν ) ) )
(
x2(ν +1) = (1 / 2.1) * 5.63 - (0.20 x ( ν + 1)
1 + 0.33 x3(ν ) + 0.21x4(ν ) ))
(
x3(ν +1) = (1 / 4.0) * 15.19 - (0.23x (ν +1)
1 - 0.32 x2(ν +1) + 0.30 x4(ν ) ))
(
x4(ν +1) = (1 / 5.2) * 16.76 - ( 0.42 x (ν +1)
1 + 0.22 x2(ν +1) + 0.5 x3(ν +1) ))
EXERCISE 5.
Iteration
counter x at iter. ν
ν x1 x2 x3 x4
First guess = 0 2.0 2.0 2.0 2.0
1
2
3
4
5
6
7
8
9
10
Iteration
counter x at iter. ν
ν x1 x2 x3 x4
In some First
cases, it may
guess = 0be possible
2.0 to develop
2.0 improved
2.0 iteration 2.0 schemes by using
the latest information 1that is available. For
4.309677 1.97619 example, in
3.6925the above iteration scheme,
2.784615
we could use the very latest value of x1
2 4.008926 (ν+1)
when we are calculating x2(ν+1) since we
1.411795 3.498943 2.436331
3 3.993119 1.505683
already have this quantity. Likewise, we can use both 3.497206
x1(ν+1) 2.503112
and x2(ν+1) when we
4 4.000937 1.500783 3.500617 2.500584
calculate x3 (ν+1)
etc as shown below:
5 3.999963 1.499755 3.499965 2.499832
6 3.999986 1.500026 3.499995 2.500017
7 4.000003 1.5 3.500002 2.500001
8 4 1.499999 3.5 2.5
Converged ⇒ 9 4 1.5 3.5 2.5
10 4 1.5 3.5 2.5
(
x2(ν +1) = (1 / 2.1) * 5.63 - (0.20 x ( ν + 1)
1 + 0.33 x3(ν ) + 0.21x4(ν ) ))
(
x3(ν +1) = (1 / 4.0) * 15.19 - (0.23x (ν +1)
1 - 0.32 x2(ν +1) + 0.30 x4(ν ) ))
(
x4(ν +1) = (1 / 5.2) * 16.76 - ( 0.42 x (ν +1)
1 + 0.22 x2(ν +1) + 0.5 x3(ν +1) ))
x1(ν +1) , x2(ν +1) , x3(ν +1) => underlined terms, imply they are at the latest time
available).
Iteration
counter x at iter. ν
ν x1 x2 x3 x4
First guess = 0 2 2 2 2
1 4.309677 1.756221 3.540191 2.460283
2 4.021247 1.495632 3.501408 2.498333
3 3.999376 1.500005 3.500161 2.500035
4 3.999973 1.499974 3.499997 2.500004
5 3.999998 1.5 3.5 2.5
Converged ⇒ 6 4 1.5 3.5 2.5
7 4 1.5 3.5 2.5
8 4 1.5 3.5 2.5
9 4 1.5 3.5 2.5
10 4 1.5 3.5 2.5
Clearly, comparing this table with the previous one using the simple point iterative
method, we see that this method does indeed converge quicker. Although this
is just one example, it is generally true that using the latest information in an
iterative scheme improves convergence.
Notes on iterative schemes: there are several point to note about iterative
schemes, which we have not really demonstrated or explained here. However,
you can confirm some of these points by using the supplied spreadsheets.
These points are:
(i) Iterative solution schemes for linear equations are often relatively simply to apply
- and to program on a computer (usually in FORTRAN). If you study the supplied
spreadsheets (CHAP6Ex5.xls), you can see that they are quite simple in structure
for this set of equations.
42
Numerical Methods in Reservoir Simulation
6
(ii) The convergence rate of an iterative scheme may depend on how good the initial
guess (x(0)) is. If you want to demonstrate this for yourself, run the spreadsheet
(CHAP6Ex5.xls) with a more remote initial guess. Here is the same example as
that presented above with a completely absurd initial guess:
Iteration
counter x at iter. ν
ν x1 x2 x3 x4
First guess = 0 900 -2000 456 23000
1 -1017.45 -2454.69 -1932.95 -28.7
2 63.79526 406.2002 -131.922 375.1144
3 55.59796 -20.1756 4.491703 -6.43019
4 1.890636 -2.67691 -0.53117 0.84584
5 4.326953 2.668945 3.538073 3.234699
6 4.090824 1.389409 3.519613 2.420476
7 3.987986 1.49622 3.491895 2.495457
8 4.001064 1.502872 3.500729 2.50191
9 4.000117 1.499593 3.500025 2.499722
10 3.999963 1.500013 3.499982 2.500005
11 4.000004 1.500006 3.500003 2.500004
12 4 1.499999 3.5 2.499999
Converged ⇒ 13 4 1.5 3.5 2.5
14 4 1.5 3.5 2.5
15 4 1.5 3.5 2.5
(iii) We cannot tell in advance how many iterations may be required in order to
converge a given iterative scheme. Clearly, from the results above, a good initial
guess helps. In reservoir simulation, when we solve the pressure equation, a good
enough guess of the new pressure is the values of the old pressures at the last
time step. If nothing radical has changed in the reservoir, then this may be
fine. However, if new wells have started up in the model or existing wells have
changed rate very significantly, then the “pressure at last time step” guess may
not be very good. However, with a very robust numerical method, convergence
should still be achieved.
(iv) It helps in an iterative method to use the latest information available. This was
demonstrated in the iterative schemes in spreadsheet CHAP6Ex5.xls.
EXERCISE 6.
Which is best method (i.e. that requiring the lowest amount of computational work),
BAND or LSOR, for the following problems?
44
Numerical Methods in Reservoir Simulation
6
We can summarise our comparison between direct and iterative methods for solving
the sets of linear equations that arise in reservoir simulation as follows:
(i) A direct method for solving a set of linear equations has an algorithm that
involves a fixed number of steps for a given size of problem. Given that the
equations are properly behaved (i.e. the problem has a stable solution), the direct
method is guaranteed to get to the solution in this fixed number of steps. No first
guess is required for a direct method.
(ii) An iterative method on the other hand, starts from a first guess at the solution (x(o))
and then applied a (usually simpler) algorithm to get better and better approximations
to the true solution of the linear equations. If successful, the method will converge
in a certain number of iterations, Niter, which we hope will be as small as possible.
However, we cannot usually tell what this number will be in advance. Also, in some
cases the iterative method may not converge for certain types of “difficult” problem.
We may need to have good first guess to make our iterative method fast. Also, it
often helps to use the latest computed information that is available (see example
above).
(iii) Usually the amount of “work” required for a direct method is smaller for
smaller problems but iterative methods usually win out for larger problems. For
an iterative method, the amount of work per iteration is usually relatively small
but the number of iterations (Niter) required to reach convergence may be large and
is usually unknown in advance.
The linear equations which arise in reservoir simulation may be solved by a direct
solution method or an iterative solution method. Fill in the table below:
Give a very
brief description
of each method
Main advantages 1. 1.
2. 2.
Main 1. 1.
disadvantages
2. 2.
46
Numerical Methods in Reservoir Simulation
6
In this section, we will introduce the general idea of solving sets of non-linear equations
numerically and indicate how this can be applied to the two-phase flow equations.
We will do this in a simplified manner that shows the basic principles without going
into too much detail. Firstly, compare the difference between solving the following
two sets of two equations, a set of 2 linear equations:
2 x1 + x2 = 10
3 x1 − x2 = 5 (72)
x1 + 2 x2 .e − x1 = 2
x2 .( x1 )2 − x1 .( x2 ) = −5
2
(73)
It is immediately obvious that the second set of non-linear equations is more difficult.
The first set of linear equations can be rearranged easily to show that x1 = 3 and x2 =
4. However, it is not as straightforward to do the same thing for the non-linear set
of equations. As a first attempt to solve these, we might try to develop an iterative
scheme by rearranging the equations as follows
(ν )
x1(ν +1) = 2 − 2 x2(ν ) .e − x1
(ν +1)
x2(ν ) .( x1(ν ) )2 +5
x =
x1(ν )
2
(74)
The actual solution in this case is, x1 =2.51068, x2 = 3.144089. Applying the above
iterative scheme with a first guess, x1(0) = x2(0) = 1.0, gives the results shown in Table
2 below (where we have removed some of the intermediate iterations).
Table 2: Non-linear scheme applied to solution of equations 73 using the point iterative
scheme of equation 74 (spreadsheet, CHAP6Ex5.xls - Sheet 3)
You can check the results in Table 2 or experiment with other first guesses using
Sheet 3 of spreadsheet CHAP6Ex5.xls. We note that the convergence rate in Table
2 is not very fast but, in this case, it does reach a solution. In general, it is usually
very difficult to establish for certain whether a given scheme will converge for non-
linear equations although there is a large body of mathematics associated with the
solution of such systems (which is beyond the scope of this course).
x 2 .e − x = 0.30 (75)
which has the solution x = 0.829069 (you can verify this by calculating x 2 .e − x
and making sure it is 0.30 - to an accuracy of ~ 4.6x10-8). This equation can be
represented as:
and the solution we require is the value of x for which the function f(x) is zero.
Expand f(x) as a Taylor series as follows:
δx 2 ' '
f ( x ) ≈ f ( xo ) + δx. f ' ( x0 ) + . f ( x0 ) + ...
2 (77)
where we have neglected all the second order and higher terms. Since we require
the solution for f(x) = 0, then we obtain:
48
Numerical Methods in Reservoir Simulation
6
which can be rearranged to the following algorithm to estimate our updated guess,
x(ν+1) as follows:
f ( x (ν ) )
x (ν +1) = x (ν ) −
f ' ( x (ν ) ) (80)
This equation is the basis of the Newton-Raphson algorithm for obtaining better and
better estimates of the solution of the equation, f(x) = 0. Note that we need both a first
guess, x(0), and also an expression for the derivative f ' (x(ν)) at iteration ν. In the simple
example in equation 76, we can obtain the derivative analytically as follows:
df ( x )
= f ' ( x ) = 2 x.e − x − x 2 .e − x
dx (81)
( x (ν ) )2 .e − x (ν ) − 0.30
x ( ν + 1)
=x (ν )
- (ν ) − x ( ν )
− ( x (ν ) ) .e − x
2 (ν )
2 x .e
(82)
The point iterative method of the previous section and the Newton-Raphson method
of equation 82 have both been applied to the solution of equation 75 (see Sheet 4
of spreadsheet CHAP6Ex5.xls for details). The results are shown in Table 3 for a
first guess of x(0) = 1.
Table 3: Comparison of the point iterative and Newton-Raphson methods for solving
non-linear equation 75; (see spreadsheet CHAP6Ex5.xls - Sheet 4 for details)
ν Point Newton-
Iteration Raphson
method method
x(ν) x(ν)
0 1 1
1 0.903042 0.815485
2 0.860307 0.825272
3 0.84212 0.82806
4 0.834497 0.828805
5 0.831322 0.829
6 0.830003 0.829051
7 0.829456 0.829064
8 0.82923 0.829068
9 0.829136 0.829069
10 0.829097 0.829069
11 0.82908 0.829069
12 0.829074 0.829069
13 0.829071 0.829069
14 0.82907 0.829069
15 0.829069 0.829069
16 0.829069 0.829069
F1 ( x1 , x2 ) = 0
F2 ( x1 , x2 ) = 0 (83)
where, in the case of equation 73 above, these functions would be given by:
F1 ( x1 , x2 ) = x1 + 2 x2 .e − x1 − 2
F2 ( x1 , x2 ) = x2 .( x1 )2 − x1 .( x2 ) + 5
2
(84)
The problem is then to find the values of x1 and x2 that make F1 = F2 = 0. In this
section, we present Newton’s method for the solution of sets of non-linear equations.
Basically, we will simply state the Newton-Raphson algorithm without proof (although
it will resemble the simple form of the Newton-Raphson method above) for sets of
non-linear equations. We will then illustrate what this means for the example of the
set of two non-linear equations above (equation 73).
Definitions:
As before,
(ν )
x (νx) and andx (νx+(ν1)+1=) the solution vectors at iteration levels ν and (ν+1)
F(Fx((ν)x) =) =0 0forforthe
the"true"
"true"solution
solutionofofthe
thesetsetofofnon
non - linearequations
- linear equations
x
50
F( x ) = 0 for the "true" solution of the set of non - linear equations
Numerical Methods in Reservoir Simulation
6
That is:
F1 ( x1ν , x2ν , x3ν ,....., x νN )
F2 ( x1ν , x2ν , x3ν ,....., x νN )
F3 ( x1ν , x2ν , x3ν ,....., x νN )
F( x ) =
(ν )
.....
.....
F ( x ν , x ν , x ν ,....., x ν )
N 1 2 3 N
(85)
[ J ( x )]
−1
(ν )
= the inverse of the Jacobian matrix. (Recall that the inverse of a
matrix A is denoted by A-1 and by definition, A-1 .A = I, where I is the identity matrix
- all diagonals 1 and all other elements zero - see below). The above matrix is also
an NxN matrix with the property:
[ J ( x )] .[ J ( x )] = I, the identity matrix
−1
(ν ) (ν )
1 0 0 0 0 ...... 0
10 0 1 0 0 0 0 0 0 ...... 0 0
......
0 1 0 0 0 ......
0 0 1 0 0 ...... 0 0
00 0 0 1 0 0 1 0 0 ...... 0 0
......
[ ] [
That is → J ( x (ν ) ) . J ( x (ν ) ) = I = ]
−1
0 0 0 1 0 (87)
0 0 0 0 1 ...... 0 0
......
[ ] [
J(x ) . J(x ) = I = ]
−1
(ν ) (ν )
0 .......
0 0 0 1 ...... 0
.......
.......
.......
0 0 0 0 0 ...... 1
0 0 0 0 0 ...... 1
Institute of Petroleum Engineering, Heriot-Watt University 51
Using all of the above definitions, the Newton-Raphson algorithm for a set of non-
linear equations, F( x ) = 0, is given by the following expression:
[ ]
x (ν+1) = x (ν) − J ( x (ν) ) .F( x (ν) )
−1
(88)
We first demonstrate how this is applied to a simple example (equations 73) before
going on to show how it is applied to the more complicated non-linear sets of
equations which arise in the fully implicit discretisation of the reservoir simulation
equations.
F1 ( x1 , x2 ) = x1 + 2 x2 .e − x1 − 2
F2 ( x1 , x2 ) = x2 .( x1 )2 − x1 .( x2 ) + 5
2
(89)
F1 ( x1 , x2 ) x1 + 2 x2 .e − x1 − 2
F( x ) = =
F2 ( x1 , x2 ) x2 .( x1 )2 − x1 .( x2 ) + 5
2
(90)
∂F1 ( x (ν ) ) ∂F1 ( x (ν ) )
∂x1 ∂x2
J(x ) =
(ν )
∂F2 ( x (ν ) ) ∂F2 ( x (ν ) )
∂x1 ∂x2
(91)
(
1 − 2 x (ν ) .e − x1(ν )
2 ) (2.e )
− x1( ν )
J ( x (ν ) ) =
(
2 1 (2 )
2 x (ν ) . x (ν ) − x (ν ) 2
) (( x ) − 2x
(ν ) 2
1
(ν )
1 . x2(ν ) )
(92)
52
Numerical Methods in Reservoir Simulation
6
( ) (2.e )
−1
1 − 2 x (ν ) .e − x1(ν ) − x1( ν ) x (ν ) + 2 x (ν ) .e − x1(ν ) − 2
2
1 2
x ( ν + 1) = x ( ν ) −
(
2 1
(2 )
2 x (ν ) . x (ν ) − x (ν ) 2
) (( x ) − 2x
(ν ) 2
1
(ν )
1 . x2(ν ) )
x2(ν ) .( x1(ν ) )2 − x1(ν ) .( x2(ν ) ) + 5
2
(93)
[ ( )]
−1
(ν )
which we could solve if we knew how to invert the Jacobian matrix to find J x
This is a detail which we don’t need to know for this course but it can be done.
Indeed, for a 2x2 matrix - such as in the above case - it is quite easy to work out the
inverse. The inverse of a simple 2 x 2 matrix A given by:
A = a b
c d
is well known to be
A-1 = 1 d − b
( ad − bc) − c a
This can easily be proven by multiplying out there matrices and showing that
A-1 .A = I. The factor (ad-bc) is known as the determinant of the matrix and it must be
non-zero for A-1 to exist. Rather than using equation above to write out the analytical
[ ]
form of the J ( x (ν ) ) matrix we first simply numerically evaluate the matrix J at a
[]
−1
given iteration and apply equation above no get J . This is done in the spreadsheet
Chap6Exxx.xls where results are shown.
[ J ( x )]
−1
(k )
= *** (94)
which allows us to apply the Newton-Raphson method directly to our simple example.
For details see Sheet 5 spreadsheet ***.xls. The results are shown in Table 6.xx.
(NOTES & SPEADSHEET STILL UNDER CONSTRUCTION)
(λ (S ))
T
n +1
o
i −1 / 2
Pn +1
−
(
λ (Son +1 )
T ) i −1 / 2
+
(λ (S ))
T
n +1
o
i +1 / 2
P n +1 + T o
(
λ (S n + 1 ) ) i +1 / 2
Pin++11 = 0
i −1
∆x 2
∆x 2 ∆x 2
i ∆x 2
(
∆t λ o ( So )
n +1
) λ ( Son +1 )( )
n +1
Soin+1 − Soin −
φ ∆x 2
i +1 / 2
( i +1 i ) − o ∆x 2
P n +1
− P n +1 i −1 / 2
(i
P n +1
− Pi −1 ) = 0
n +1
Given that the unknowns that we are trying to find are Pi , Sin +1 i = 1,2, NX. ,
then we can write the above equations in general form as:
FP, i ( S n +1 , P n +1 ) = 0
FS , i ( S n +1 , P n +1 ) = 0
(95)
FP, i ( S n +1 , P n +1 ) andn +F1S , i (nS+n1+1 , P n +1 ) n +1 n +1
where the two non-linear equations, FP, i ( S , P ) and FS , i ( S , P ) , arise from
the pressure (P) and saturation (S) equations, respectively, as given above. The
vectors of unknowns, S n +1 and P n +1, nare
+1 given nby
+1 :
S and P
n +1
S 1 P1n +1
n +1 n +1
S2 P2
n +1 n +1
S3 P3
... ...
... ...
S n +1 P n +1
S n +1 = i −1 and P n +1 = i −1
Sin +1 Pi n +1
n +1 n +1
Si +1 Pi +1
... ...
... ...
... ...
S n +1 P n +1
NX NX (96)
54
Numerical Methods in Reservoir Simulation
6
FP, i ( S n +1 , P n +1 ) and FS , i ( S n +1 , P n +1 )
We may also write one total unknows vector Xn+1 using a combination of the saturation
and pressure vectors as follows:
S1 n +1
n +1
P1
S n +1
2
P2 n +1
X n +1 =
S n +1
i
Pi n +1
S n +1
NX
n +1
PNX
The saturations and pressures are coupled together to their nearest neighbours through
the discretisation equations (50 and 54 above). The general form of the solution using
the Newton iteration is then to take a starting guess (iteration, ν=0) Xn+1(0) and then
apply the formulation as above to obtain:
[ ]
−1
X n +1 (ν +1) = X n +1(ν ) + J ( X )(ν ) . F ( X (ν ) )
In this course, we will not give any more detail on the solution of the non-linear
equations which arise in reservoir simulation.
In this section, we return to the issue of numerical dispersion - a term which we will
now use interchangeably with “numerical diffusion”. Indeed, “diffusion” is often
referred to as quite a specific physical effect which is described by certain well-known
equations which are, not surprisingly, known as diffusion equations. For example,
the simplified pressure equation derived in Chapter 5, equation 27, is an example of
a diffusion equation. This equation has the form:
∂P ∂2 P
= Dh 2
∂t ∂x (97)
where Dh is the hydraulic diffusivity (Dh = k/( cf .φ.μ)) and this is a standard form
of the classical diffusion equation. We now consider how the effects of a grid can
lead to “diffusion-like” terms when we try to solve the flow equations numerically.
∂2 P
In the above equations, it is specifically the 2 term that is the “dispersive” or
“diffusive” part. ∂x
∂S ∂f
φ w = − v w
∂t ∂x (98)
qw
56 fw ( Sw ) =
qw + qo
Numerical Methods in Reservoir Simulation
6
fw ( Sw )
qw
( fw ( Sw ) = ) which is a function only of water saturation, Sw. We can
qw + qo
differentiate fw ( Sw ) by the chain rule to obtain:
fw ( Sw ) ∂f ∂S
∂S ∂f
φ w = − v w = − v w w
∂ft S = ∂xqw ∂Sw ∂x
w( w) (99)
qw + qo
∂f
− v w
where the termfw ( Sw)∂Sw is a non-linear term giving the water velocity, v w (Sw ) ,
which is also a function of water saturation: that is:
∂f
v w (S w ) = − v w fw (Sw )
∂Sw (100)
To simplify the problem even further for our purposes here, we take a straight line
∂fw
fractional flow, fw (Sw ) , which means that ∂Sw is a constant and, hence, so is
the water velocity, Vw. Hence, the simple 1D transport equation for a convected
waterfront is:
∂fw
w ∂S ∂Sw
∂S
= −wv w
∂t ∂x (101)
where, as noted above, vw is now constant. This equation describes the physical
situation illustrated schematically in Figure 14.
t1 t2 Governing equation
1 ∂Sw ∂Sw
= - Vw
∂t ∂x
Figure 14
Sw Vw = constant
The advance of a sharp
Water Vw Oil
saturation front governed
0 x2 - x1
by the transport equation x1 x2 Vw =
x t2 - t1
with a constant velocity vw.
Starting from the transport equation 101 above, we can easily apply finite differences
using our familiar notation (Chapter 5) to obtain:
Sn +1 − Swi
n
Swi − Swi −1
φ wi = − vw + Error terms
∆t ∆x (102)
where we have used the backward difference (sometimes referred to as the upstream
∂Sw
difference) to discretise the spatial term, ∂x . Note that we have not yet specified
the time level of the spatial terms. If we take these at the n time level (known), then it
SPACE
∂S δx ∂ Sw
2 2
Sw (x, t ) = Sw (x 0 ) + δx. w + + higher order terms
(t fixed) ∂x 2 ∂x 2 (103)
∂S δt 2 ∂ 2S
TIME Sw ( x, t ) = Sw ( t 0 ) + δt. + 2 + higher order terms
w w
∂t 2 ∂t
(x fixed) (104)
We can rearrange each of the above equations 103 and 104 to obtain the finite
∂S ∂S
difference approximations for the ∂x
and
∂t terms with the leading error
terms as follows (now ignoring the higher order terms):
∂S S(x, t ) − S(x 0 ) δx ∂ 2S
SPACE ≈ − 2 (105)
∂x δx 2 ∂x
∂S S(x, t ) − S( t 0 ) δt ∂ S
2
TIME ≈ − 2 ∂t 2 (106)
∂t δt
To return to our usual notation, we make the identities:
S( x, t ) ⇔ Sin +1
S( x 0 ) ⇔ Si −1
S( t 0 ) ⇔ Sin
δx ⇔ ∆x
δt ⇔ ∆t (107)
∂S Si − Si −1 ∆x ∂ S
2
≈ −
∂x ∆x 2 ∂x 2
(108)
n +1
∂S Si − Si ∆t ∂ S
n 2
≈ −
∂t ∆t 2 ∂t 2
(109)
58
Numerical Methods in Reservoir Simulation
6
We now substitute the above finite difference approximations into the governing
equation 102 with their leading error terms as follows:
Sn +1 − Sin ∆t ∂ 2S Si − Si −1 v w .∆x ∂ 2S
φ i − ≈ − v w +
∆t 2 ∂t 2 ∆x 2 ∂x 2 (110)
Sn +1 − Sin Si − Si −1 v w .∆x ∂ 2S ∆t ∂ 2S
φ i ≈ − v w + +
∆t ∆x 2 ∂x 2 2 ∂t 2
Error term (111)
The error term in the finite difference scheme is now clear and is shown in equation
111. However, it still needs some simplifying since it is a strange mixed term with
∂ 2S ∂ 2S ∂ 2S
2 and 2
both ∂x ∂t terms in it. We now want to eliminate the ∂t 2 term
and this is done by using the original governing equation.
∂ 2S ∂Sw ∂S
To obtain
2 , first note from the original equation 101 that
= − vw w
∂t ∂t ∂x
∂Sw
and we can then differentiate with respect to t as follows:
∂t
∂ ∂Sw ∂ 2Sw ∂ ∂S
= 2 = − vw w
∂t ∂t ∂t ∂t ∂x (112)
∂ ∂Sw ∂ ∂S
− vw = − vw w
∂t ∂x ∂x ∂t (113)
∂S
We now return again to the governing equation (equation 101) and use it for w
in equation 113 to obtain: ∂t
∂ ∂Sw ∂ ∂Sw 2 ∂ Sw
2
− vw = − v −
w v = v w
∂x ∂t ∂x ∂x
w
∂x 2 (114)
and hence:
∂ 2 Sw 2 ∂ Sw
2
2 = v w
∂t ∂x 2 (115)
We now substitute this expression into the error term in equation 111 above to obtain
the following:
v .∆x v 2w ∆t ∂ 2S
= w +
2 2 ∂x 2 (116)
The finite difference equation with its error term in equation 111 now becomes:
In this equation, we now see that the form of the error term is exactly like a “diffusive”
term i.e. it multiplies a (∂2Sw/∂x2) term. Hence we identify the level of numerical
dispersion or diffusion, Dnum, arising from our simple finite difference scheme as:
v .∆x v 2w ∆t ∆x v w ∆t ∆x v w ∆t
D num = w + = v w . + D num = v w . +
2 2 2 2 (118) 2 2
∆x v w ∆t
If D num = v w . + , we can take such a small time step that v w ∆t << ∆x
For this case: 2 2
v w .∆x
∆x≈
D num
v w ∆t <<
2 (119)
(i) Firstly, we may apply an explicit finite difference method to obtain an accurate
solution of the following convection-dispersion equation.
∂Sw ∂Sw ∂ 2 Sw
= − v w + D. 2
∂t ∂x ∂x (120)
That is, where the numerical dispersion is much less than the physical dispersion due
to the explicit D term. If this solution is converged (i.e. does not change on refining
Δx and Δt) then we can plot this at a suitable time, t1, as shown in Figure 15.
Governing equation:
2
1 t = t1 Sw Sw Sw
= - Vw +D
t x x2
Sw Figure 15.
Vw = water velocity
Dispersed frontal displace-
0 ment with a known and con-
x
verged level of dispersion.
60
Numerical Methods in Reservoir Simulation
6
n +1
Swi − Swi
n
Swi
n
− Swi
n
−1
(ii) Now take only the explicit finite difference φapproximation
=−
tov wthe
convection
∆t ∆x
equation only, that is:
Sn +1 − Swi
n
Swi
n
− Swi
n
−1 v .∆t n
φ wi = − vw which gives ⇒ Swi
n +1
= Swi
n
− w (Swi − Swi
n
−1 )
∆t ∆x ∆x.φ
Solve this with a relatively coarser grid, Δx, but with a fine time step thus predicting
vwv.∆ x n
w .∆t
2x.φ.( Choose 1)
n +1
S = S n
Dwinum to be −
wi Swi − Swi
n
−this level of dispersion to deliberately match that in
∆
part (i) above i.e. choose Δx such that Dnum = D. Plot out a saturation profile like
that in Figure 15 at the same time t1 and compare these.
8 CLOSING REMARKS
This lists (without proof) some useful theorems from matrix algebra which underpin
much of the practical application work which we have described in this section.
A.x = b
The central problem which we are interested in is:
A.x = b
A.x = b where A is an NxN square matrix
(ii) det( A ) ≠ 0 ; the determinant of the matrix is non-zero. This is a number found
by “multiplying out” the matrixI.in A a=specific
A.I = Away.
(v) the columns of A are linearly independent. Where (iv) and (v) say that we
cannot get one
Aof
.x the
= 0rows or columns by making some combination of the existing
ones.
3. If the matrixAA=isGpositive
.G T definite then it can be decomposed in exactly one
way into a product: A = G.G T
such that matrix G is lower triangular and has positive entries on the main diagonal.
G decomposition.
This is known as Cholesky
62
Numerical Methods in Reservoir Simulation
6
SOLUTIONS TO EXERCISES
EXERCISE 1.
dy = 2. y 2 + 4
dt
where, at t = 0, y(t = 0) = 1. Take time steps of Δt = 0.001 (arbitrary time units) and
step the solution forward to t = 0.25. Use the notation yn+1 for the (unknown) y at
n+1 time level and yn for the (known) y value at the current, n, time level.
SOLUTION 1.
y n +1 − y n
= 2.( y ) + 4
n 2
n +1∆t n
y −y
= 2.( y ) + 4
n 2
∆t
which is rearranged to the explicit formula:
y n +1 = y n + ∆t (2.( y n )2 + 4)
ny+n1+1 − yn n
y = y + ∆=t (22.(.(yy )) ++ 44)
nn 22
n +du ∆t y n +1 − y n
y 1 − y n = 1 tan −n1 2 u
∫ u 2 + α 2 α = 2.( y ) + 4
n 2
= 2.( y ) +4
which can be set 1 easily α
∆t up quite on a spreadsheet. ∆ t
du −1n 2u
∫y 2 += αy 2 + ∆αt(tan
n +1 n =
2.( y ) + 4)
α might need the standard form of the following
To find the uanalytical answer, you
integral: y =2 y + ∆t2(2=.( y ) +tan
1n +1 dy n1 2
)
−1 y y n++1C= y n + ∆t (2.( y n )2 + 4)
2 ∫ ydu+ ( 2 1) 2 ∫
n
4 = dt = t
2 2
1 dy= tan −11 u −1 y
∫2 u∫2y+2 α+ 2( 2α)2 = 2 2α tan 2 = ∫ dt = t + Cdu 1 u
du 1 −1 u ∫ = tan −1
α∫ u=2 +2α 2 α = tan
α u +α
2 2
α α
Using this1standard form gives:
α = 2 2 dy 2 = 1 tan −1 y = dt = t + C
2 1∫ y + (−1 2 )y 2 2 2 ∫ 1 dy 1 y
1 tandy 1+C −1 y
= =
22 ∫ 2y 2 + ( 2 )22 2 2
t tan
= ∫ dt = t
2 +∫ Cy 2
+ ( 2 ) 2
=
2 2
tan −1
2
=
1 −1 y
2
α2 =2 tan 2 2 = t +C
where C isy(the [
α t=) = 2 2 tan 2 2 (t + C )
this becomes:
]
constant of integration and we identify α = 2 above. Therefore,
2 2
−1
[ = t +C ]
y2 2 (t + C )
y(1t ) =tan2 tan
2
1 y−1 1 1 y
C 1= tan −1tan = t+=C0.2176049 tan −1 = t +C
2 2 2Heriot-Watt
2 22 1Engineering,
Institute of Petroleum University
2 2 2 63
−1 1
C =
2 2
tan[
y(t ) = 2 tan 2 2 (t + C )
2
= 0 .]2176049
∫ u + α = α tan α
2 2
du 1 u
∫ u + α = α tan α
−1
2 2
du 1 u
∫1 u + αdy= α tan
−1
1 y
21 ∫ y +dy
α tan −1
= ∫ dt = t + C
2 2
=
2
( 2) 2
2 12 y2
−1
21 ∫ y +dy ∫
= tan = dt = t + C
2
( 2) 2
2 12 2
−1 y
α2 ∫= y 2+ ( 2 ) = 2 2 tan
2 2
2 ∫
= dt = t + C
α= 2
α 1= tan 2 −1 y = t +C
2 12 y2
tan −1 = t +C
2 12 2
−1 yto:
which easily rearranges
[
y2(t )2=tan2 tan = t +C
2 2 (t + C )
2 ]
[
y(t ) = 2 tan 2 2 (t + C ) ]
tan[2 12 (t += C0).2176049
y(t=) = 1 2 tan
C −1 ]
conditions since y(t = 0) = 1; it is easy to see that:
We now find C from the initial
2 12 12
C= tan −1 = 0.2176049
2 12 2
1
C= tan −1 = 0.2176049
2 2 2
This is implemented in the spreadsheet CHAP6Ex1.xls. Note that at t > 0.3, both
the analytical and numerical solutions go a bit strange (very large and they start to
disagree) since the tan function has a singularity y(t) → ∞.
EXERCISE 2.
∆t
Pi n +1 = Pi n +
∆x 2
( Pi n+1 + Pi n−1 − 2 Pi n )
Hint: make up a spread sheet as above and set the first unknown block (shown grey
shaded in table above) with the above formula. Copy this and paste it into all of the
cells in the entire unknown area (surrounded by red border above).
SOLUTION 2.
EXERCISE 3.
64
Numerical Methods in Reservoir Simulation
6
EXERCISE 4.
2 x − 22xx2 −+ 21xx3
2 3 4
++ 12xx4 = +122 x5 = 12
5
3 x5 = 153 x5 = 15
SOLUTION 4.
Answer Answer
x1 = ..........;
x1 = ..........; x2 = ..........;
x2 = ..........; x3 = ..........;
x3 = ..........; x4 = ..........;
x4 = ..........; x5 = ..........
x5 = ..........
EXERCISE 5.
Iteration
counter x at iter. ν
ν x1 x2 x3 x4
First guess = 0 2.0 2.0 2.0 2.0
1
2
3
4
5
6
7
8
9
10
SOLUTION 5. Iteration
counter x at iter. ν
ν x1 x2 x3 x4
Answer First
- Exercise
guess =5: 0see spreadsheet
2.0 CHAP6Ex5.xls
2.0 2.0 - Sheet2.0
1
1 4.309677 1.97619 3.6925 2.784615
POINT ITERATIVE SOLUTION
2 OF LINEAR
4.008926 1.411795EQUATIONS
3.498943 2.436331
3 3.993119 1.505683 3.497206 2.503112
4 4.000937 1.500783 3.500617 2.500584
5 3.999963 1.499755 3.499965 2.499832
6 3.999986 1.500026 3.499995 2.500017
7 4.000003 1.5 3.500002 2.500001
8 4 1.499999 3.5 2.5
Converged ⇒ 9 4 1.5 3.5 2.5
10 4 1.5 3.5 2.5
Iteration
counter x at iter. ν
ν x1 x2 x3 x4
First guess = 0 2.0 2.0 2.0 2.0
1 4.309677 1.97619 3.6925 2.784615
2 4.008926 1.411795 3.498943 2.436331
3 3.993119 1.505683 3.497206 2.503112
4 4.000937 1.500783 3.500617 2.500584
5 3.999963 1.499755 3.499965 2.499832
6 3.999986 1.500026 3.499995 2.500017
7 4.000003 1.5 3.500002 2.500001
8 4 1.499999 3.5 2.5
Converged ⇒ 9 4 1.5 3.5 2.5
10 4 1.5 3.5 2.5
EXERCISE 6.
Which is best method (i.e. that requiring the lowest amount of computational work),
BAND or LSOR, for the following problems?
SOLUTION 6.
66
Numerical Methods in Reservoir Simulation
6
EXERCISE 7.
The linear equations which arise in reservoir simulation may be solved by a direct
solution method or an iterative solution method. Fill in the table below:
Give a very
brief description
of each method
Main advantages 1. 1.
2. 2.
Main 1. 1.
disadvantages
2. 2.