You are on page 1of 145

Advanced Reservoir Simulation - 3 Phase, 3-D,

Implicit Beta Model

Leslie Thompson

Spring 2009
Contents

1 Finite Di¤erence Beta Model 4


1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Material Balance Equations - Beta Model . . . . . . . . . . . . . 5
1.2.1 Formulation in terms of mass concentrations . . . . . . . 9
1.3 Discrete Equations . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.3.1 Cartesian Coordinates . . . . . . . . . . . . . . . . . . . . 14
1.3.2 Cylindrical Coordinates . . . . . . . . . . . . . . . . . . . 20
1.4 PVT Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.5 Relative Permeabilities and Capillary Pressures . . . . . . . . . . 26
1.5.1 Two-Phase Relative Permeability . . . . . . . . . . . . . . 26
1.5.2 3-Phase Relative Permeability . . . . . . . . . . . . . . . . 29
1.6 Object Oriented Design . . . . . . . . . . . . . . . . . . . . . . . 30
1.6.1 Programming Speed versus Safety . . . . . . . . . . . . . 31
1.6.2 The Grid Class . . . . . . . . . . . . . . . . . . . . . . . . 36
1.6.3 The GridblockVariables Class . . . . . . . . . . . . . . . . 37
1.6.4 The Table Class . . . . . . . . . . . . . . . . . . . . . . . 39
1.6.5 The PVTProperties Class . . . . . . . . . . . . . . . . . . 41
1.6.6 Relative permeability and Capillary Pressure Classes . . . 43
1.6.7 Miscellaneous Class . . . . . . . . . . . . . . . . . . . . . 45

2 Implicit Solution using Newton’s Method 46


2.1 Evaluation of the Components of the Jacobian Matrix . . . . . . 52
2.1.1 Oil Equation . . . . . . . . . . . . . . . . . . . . . . . . . 52
2.1.2 Gas Equation . . . . . . . . . . . . . . . . . . . . . . . . . 62
2.1.3 Water Equation . . . . . . . . . . . . . . . . . . . . . . . . 72
2.2 Modeling of Wells . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
2.3 Computation of Well/Gridblock Mobility Terms . . . . . . . . . . 85
2.3.1 Fluid Injection . . . . . . . . . . . . . . . . . . . . . . . . 85
2.3.2 Application of Speci…ed Production Conditions . . . . . . 90
2.4 Boundary Conditions . . . . . . . . . . . . . . . . . . . . . . . . . 92
2.4.1 Sealed Boundary Block . . . . . . . . . . . . . . . . . . . 92
2.4.2 Speci…ed Rate or Pressure Boundary . . . . . . . . . . . . 92
2.5 Matrix Ordering and Structure . . . . . . . . . . . . . . . . . . . 95
2.5.1 Number of Non-zeros . . . . . . . . . . . . . . . . . . . . . 96

1
2.6 Saturation and Pressure Initialization . . . . . . . . . . . . . . . 98
2.6.1 Initialization from Average Data . . . . . . . . . . . . . . 98
2.6.2 Initialization from Gridblock Data . . . . . . . . . . . . . 98
2.6.3 Initialization from GOC and WOC Data . . . . . . . . . . 98
2.7 Simulator Objects . . . . . . . . . . . . . . . . . . . . . . . . . . 99
2.7.1 UMFSparseMatrix Class . . . . . . . . . . . . . . . . . . . 99
2.7.2 RelativePermCapPressData Structure . . . . . . . . . . . 100
2.7.3 FlowEquationBuilder Class . . . . . . . . . . . . . . . . . 100
2.7.4 Simulator Class . . . . . . . . . . . . . . . . . . . . . . . . 102
2.8 Overview of a Simulator Run . . . . . . . . . . . . . . . . . . . . 103

3 The Well Model 105


3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
3.2 Simplifying Assumptions . . . . . . . . . . . . . . . . . . . . . . . 106
3.3 Flow Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

3.3.1 Single Phase Flow . . . . . . . . . . . . . . . . . . . . . . 106


3.3.2 Multiphase Flow . . . . . . . . . . . . . . . . . . . . . . . 108
3.3.3 Speci…ed Heel Rate . . . . . . . . . . . . . . . . . . . . . . 109
3.3.4 Calculation of Pipe Pressure Drops . . . . . . . . . . . . . 111

4 Coupling of the Reservoir and Well Models 114


4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
4.2 Mapping Well Segments to Gridblocks . . . . . . . . . . . . . . . 115
4.3 Reservoir/Wellbore Interface . . . . . . . . . . . . . . . . . . . . 117

A PVT Correlations 122


A.1 Solution Gas-Oil Ratio . . . . . . . . . . . . . . . . . . . . . . . . 122
A.1.1 Standing[28] . . . . . . . . . . . . . . . . . . . . . . . . . . 122
A.1.2 Vazquez and Beggs[35] . . . . . . . . . . . . . . . . . . . . 122
A.1.3 Kartoatmodjo and Schmidt[21] . . . . . . . . . . . . . . . 123
A.2 Oil Formation Volume Factor . . . . . . . . . . . . . . . . . . . . 123
A.2.1 Standing[28] . . . . . . . . . . . . . . . . . . . . . . . . . . 124
A.2.2 Vazquez and Beggs[35] . . . . . . . . . . . . . . . . . . . . 124
A.2.3 Kartoatmodjo and Schmidt[21] . . . . . . . . . . . . . . . 124
A.3 Oil Viscosity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
A.3.1 Standing[28],[39] . . . . . . . . . . . . . . . . . . . . . . . 125
A.3.2 Kartoatmodjo and Schmidt[21] . . . . . . . . . . . . . . . 125
A.4 Gas Critical Properties . . . . . . . . . . . . . . . . . . . . . . . . 126
A.4.1 Sutton[32] . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
A.4.2 Standing[28] . . . . . . . . . . . . . . . . . . . . . . . . . . 126
A.4.3 Acid Gas Correction[40] . . . . . . . . . . . . . . . . . . . 127
A.5 Gas Compressibility (z) Factor . . . . . . . . . . . . . . . . . . . 127
A.5.1 Hall and Yarborough[19] . . . . . . . . . . . . . . . . . . . 128

2
A.5.2 Dranchuk and Abu Kassem[16] . . . . . . . . . . . . . . . 129
A.6 Gas Formation Volume Factor . . . . . . . . . . . . . . . . . . . . 130
A.7 Gas Viscosity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
A.7.1 Lee-Gonzalez[3] . . . . . . . . . . . . . . . . . . . . . . . . 130
A.7.2 Lucas[23] . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
A.8 Water Properties[41] . . . . . . . . . . . . . . . . . . . . . . . . . 131
A.8.1 Formation Volume Factor . . . . . . . . . . . . . . . . . . 131
A.8.2 Viscosity . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
A.8.3 Density . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132

B Solution of Systems of Nonlinear Equations Using Error Ori-


ented Descent 133
B.1 Restricted Step Newton Algorithm . . . . . . . . . . . . . . . . . 133
B.2 Quasi-Newton Algorithm[15], [38] . . . . . . . . . . . . . . . . . . 135

C C++ listing for the Miscellaneous Class 137


C.1 Miscellaneous.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
C.2 Miscellaneous.cpp . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

3
Chapter 1

Finite Di¤erence Beta


Model

1.1 Introduction
As used in this text, the term “Reservoir Simulation” refers to the modeling
of ‡uid ‡ow in petroleum reservoirs via a set of (partial di¤erential) equations
that (hopefully) capture the major physical features of the actual reservoir ‡ow.
The use of reservoir simulators allows us to approximately predict (at least
qualitatively) the behavior of the reservoir as it is produced under a variety
of di¤erent conditions without actually producing the real reservoir; in this
way, we can develop strategies to optimize production and/or recovery from a
reservoir before committing to an actual …eld implementation. Of course, the
quality of our predictions of reservoir behavior is completely dependent on our
knowledge of the geometry and rock and ‡uid properties of the reservoir that
we are modeling. In general, modern simulation studies do not seek a unique
answer to the predicted reservoir behavior; rather, they seek a range of possible
outcomes as determined by the degree of uncertainty in the input data. For
example, if simulation results from a set of equally probable reservoir system
descriptions (given the set of known data) indicate that drilling a new well at
a certain location will increase recovery, then it is assumed that a well at that
location in the real reservoir would most likely increase actual recovery.
Flow in the reservoir is assumed to be governed by a set of partial di¤er-
ential equations that describe conservation of mass, momentum and energy. In
this text, we will assume isothermal ‡ow in the reservoir (i.e., we will not con-
sider injection of ‡uids at temperatures signi…cantly di¤erent to the reservoir
temperature), so we will not consider conservation of energy. Further, we will
assume that the relationship between pressure drop and ‡ow rate is adequately
described by Darcy’s law, so our system of di¤erential equations will be re-
duced to a set of mass balance equations combined with Darcy’s law for phase
transport. In addition to the ‡ow equations, we will need to specify an initial

4
condition and appropriate boundary conditions. For very simple systems (i.e.,
‡ow of a slightly compressible, constant viscosity liquid), it may be possible to
solve the system of equations analytically; (in fact, the solutions used in the
analysis of pressure transient data for reservoir properties are developed this
way); however in general, the (approximate) solution of the system of equations
can only be obtained using numerical techniques. This text is focused on the
(implicit) numerical solution of the equations describing three-phase ‡ow of oil,
gas and water in a three dimensional reservoir. We discuss the formulation
for Cartesian coordinate systems in detail, and we outline the formulation for
cylindrical coordinate systems. We will assume that the PVT behavior of the
hydrocarbon ‡uid is well described by a “Beta” model, i.e., where there are
two distinct hydrocarbon species that can coexist and be transported in the
vapor or liquid phases. In the following we provide a detailed description of the
system under consideration and derive the set of equations that we will solve
numerically.

1.2 Material Balance Equations - Beta Model


We assume two hydrocarbon components, “oil” and “gas” distributed between
two hydrocarbon phases, “vapor” and “liquid”. In addition we assume the
presence of an aqueous phase which is immiscible with the hydrocarbon phases.
Darcy’s law for the velocity of phase “m” (m = o; w or g) in the x-direction is
given by
kx krm @pm
vm = C1 (1.1)
m Bm @x

where vm is the phase velocity, ft/day at standard conditions; kx is the absolute


permeability (md) in the x-direction, krm is the relative permeability to phase
“m”, m is the phase viscosity (cp), Bm is the phase formation volume factor,
(reservoir volume/standard volume), pm is the phase pressure, (psi), and the
units conversion constant C1 is
3
C1 = 1:127 10 (5:615) (1.2)

Similarly, the phase “m” velocity in the z-direction is given by

kz krm @pm g
vm = C1 + m (1.3)
m Bm @z 144gc

where m is the density of phase “m”, (lbm/ft3 ), g is the acceleration due to


gravity, (32.2 ft/sec2 ) and gc is a units conversion constant, (32.2 lbm-ft/lbf-
sec2 ).
By incorporating the Darcy’s law equations in the standard mass conserva-
tion equations for each species, we obtain the standard material balance equa-
tions for the “oil”, “gas”and “water”. In the Cartesian coordinate system these

5
equations are respectively[34]

@ kro @po rv krg @pg


C1 kx + +
@x o Bo @x g Bg @x
@ kro @po rv krg @pg
ky + +
@y B
o o @y g Bg @y
@ kro @po g rv krg @pg g
kz + L + + V =
@z o Bo @z 144gc B
g g @z 144gc
nw
X
@ So rv Sg e o;j (!
+ + Q x j) (1.4)
@t Bo Bg j=1

@ Rs kro @po krg @pg


C1 kx + +
@x o Bo @x g Bg @x
@ Rs kro @po krg @pg
ky + +
@y o Bo @y g Bg @y
@ Rs kro @po g krg @pg g
kz + L + + V =
@z o Bo @z 144gc g B g @z 144gc
n
X w
@ R s So Sg e g;j (!
+ + Q x j) (1.5)
@t Bo Bg j=1

@ krw @pw
C1 kx +
@x B
w w @x
@ krw @pw
ky +
@y B
w w @y
@ krw @pw g
kz + w =
@z w Bw @z 144gc
Xnw
@ Sw e w;j (!
+ Q x j) (1.6)
@t Bw j=1

Here the z coordinate is positive in the upward vertical direction, and

6
C1 = constant = 1:127 10 3 (5:615)
kx ; ky ; kz = Directional absolute permeabilities, md
kro ; krg ; krw = Relative permeabilities to oil (liquid), gas (vapor)
and water.
o; g ; w = Viscosities of oil (liquid), gas (vapor) and water, cp.
Bo ; B g ; B w = Formation volume factors for liquid, vapor and
water, bbl/STB or ft3 /scf.
pcgo = Capillary pressure of a gas/oil system (see Eq. 1.12)
pcow Capillary pressure of a oil/water system (see Eq. 1.11)
po ; p g ; p w = Pressures in the oil (liquid), gas (vapor) and water, psia
o; g ; w = Densities of oil (liquid), gas (vapor) and water, lbm/ft3 .
So ; S g ; S w = Saturations of oil (liquid), gas (vapor) and water.
rv = Volatility of oil in the vapor phase, STB oil/STB gas.
Rs = Solubility of gas in the liquid phase, STB gas/STB oil.
g = gravitational acceleration, 32.2 ft/sec2
gc = 32.2 lbm-ft/lbf-sec2
x; y; z = Positions in the coordinate axis directions, ft
e o;j ; Q
Q e g;j ; Qe w;j = Oil, gas and water volume removed per unit volume
per day from point ! x j ; scf/d/ft3
nw = Number of locations at which ‡uid is removed from
the reservoir.
(!
x j) = 1 at the point ! x j , 0 elsewhere.
With these de…nitions, the units on each side of the material balance equa-
tions are STB/bbl-day. Similarly, the equations for ‡ow in a cylindrical coordi-
nate system are written as
1 @ kro @po rv krg @pg
C1 rkr + +
r @r o B o @r g Bg @r
1 @ k kro @po rv krg @pg
+ +
r@ r B
o o @ g Bg @
@ kro @po g rv krg @pg g
kz + L + + V =
@z o Bo @z 144gc g Bg @z 144gc
@ So rv Sg
+ (1.7)
@t Bo Bg

1 @ Rs kro @po krg @pg


C1 rkr + +
r @r B
o o @r g Bg @r
1 @ k Rs kro @po krg @pg
+ +
r@ r B
o o @ g Bg @
@ Rs kro @po g krg @pg g
kz + L + + V =
@z o Bo @z 144gc g Bg @z 144gc
@ Rs So Sg
+ (1.8)
@t Bo Bg

7
1 @ krw @pw
C1 rkr +
r @r w B w @r
1 @ k krw @pw
+
r@ r w B w @
@ krw @pw g
kz + w =
@z w B w @z 144g c
@ Sw
(1.9)
@t Bw
(Note that Eqs. 1.7 - 1.9, we have not included source or sink functions; this
is because in this geometry, production and injection are usually included by
choosing appropriate boundary conditions.) In Eqs. 1.4 - 1.9, the phase pres-
sures, po , pg , pw and the phase saturations, So , Sg , and Sw are the dependent
variables. In addition to these material balance equations, the following “clo-
sure” relationships are also required.
The saturation constraint is given by
So + Sg + Sw = 1 (1.10)

Phase pressures are related via capillary pressure, so


pcow (Sw ) = po pw (1.11)
and
pcgo (Sg ) = pg po (1.12)
PVT properties must be de…ned as functions of pressure.
Phase relative permeabilities are de…ned as functions of phase saturation.
The system of equations described above are highly nonlinear and in general,
are very di¢ cult to solve; they incorporate interphase transfer of the hydrocar-
bon species as well as the possibility of counter-current ‡ow of phases (e.g.,
gas percolating to the top of the reservoir and water sinking to the bottom
of the reservoir). In traditional formulations, the solution variables are chosen
to be a phase pressure (e.g., oil) and two phase saturations in regions where
two hydrocarbon phases exist, and a phase pressure, a phase saturation and
saturation pressure in regions that are undersaturated. Solving for phase sat-
urations presents di¢ culties, since they may disappear or appear at bubble or
dew points, they are constrained to lie between zero and one, and they are much
smaller in magnitude than pressures. (The latter fact causes “scaling”problems
in the numerical procedures we use to solve the ‡ow equations.) In view of this,
we prefer to rewrite the material balance equations in terms of pressures and
component mass concentrations; using this approach, we always solve for the
same variables regardless of whether we are saturated or undersaturated, and
our equations more closely resemble the mass conservation equations associated
with multicomponent or compositional models. Thus, it is relatively easy to
generalize our formulation to “compositional” ‡uid models.

8
1.2.1 Formulation in terms of mass concentrations
Consider a 1 ft3 pore volume of the reservoir containing hydrocarbon liquid,
(oil), hydrocarbon vapor, (gas), and water. Since we are considering a unit
pore volume, the volumes of oil, gas and water must be So , Sg , and Sw ft3
respectively. Suppose in the unit pore volume we have nL lbm of hydrocarbon
liquid, nV lbm of hydrocarbon vapor and nW lbm of water. Further, suppose
that the hydrocarbon liquid phase is composed of no;L lbm of “oil” component
and ng;L lbm of “gas”component and the hydrocarbon vapor phase is composed
of no;V lbm of “oil”component and ng;V lbm of “gas”component. Also, assume
that the total mass of oil and gas components in the unit pore volume are no
and ng lbm respectively. Since the total mass of oil and gas components in the
unit volume must be the sums of masses of each component in each hydrocarbon
phase, we must have
no = no;L + no;V (1.13)
and
ng = ng;L + ng;V (1.14)
If the in situ densities of the hydrocarbon liquid and vapor phases are L
and V lbm/ft3 , then
nL
So = ; (1.15)
L
nV
Sg = ; (1.16)
V
and
nW
Sw = ; (1.17)
W
If the densities of the “oil” and “gas” components at standard conditions are
3
osc and gsc lbm/ft respectively, then from the basic de…nitions of our PVT
properties, we have
nL
L nL osc
Bo = = ; (1.18)
no;L no;L L
osc

nV
V
nV gsc
Bg = = ; (1.19)
ng;V ng;V V
gsc

nW
W w;sc
Bw = = ; (1.20)
nW W
w;sc

no;V
osc
no;V gsc
rv = = ; (1.21)
ng;V ng;V osc
gsc

9
and
ng;L
gsc ng;L osc
Rs = = : (1.22)
no;L no;L gsc
osc

Note that the product

ng;L no;V
R s rv = ; (1.23)
ng;V no;L

since the concentration of gas component in the liquid phase is by de…nition


smaller that the concentration of gas component in the vapor phase i..e., ng;L <
ng;V and similarly the oil concentration in the vapor phase is less than the oil
concentration in the liquid phase, i.e., no;V < no;L ; we must have

Rs rv < 1: (1.24)

Since
nL = no;L + ng;L ; (1.25)
and
nV = no;V + ng;V ; (1.26)
using Eqs. 1.18 - 1.22 it is easy to derive the following expressions for the in
situ phase densities:

o;sc + g;sc Rs
L = ; (1.27)
Bo

g;sc + o;sc rv
V = ; (1.28)
Bg
We write Eqs. 1.13, 1.14, 1.25, 1.26, 1.21 and 1.22 in matrix form as
2 32 3 2 3
1 0 1 1 0 0 no;L 0
6 0 1 0 0 1 1 7 6 7 6 7
6 7 6 no;V 7 6 0 7
6 1 1 0 0 0 0 7 6 nL 7 6 no 7
6 76 7=6 7 (1.29)
6 0 0 0 1 1 0 7 6 7 6 7
6 7 6 ng;L 7 6 ng 7
4 0 gsc 0 0 r
osc v 0 5 4 n g;V
5 4 0 5
R
gsc s 0 0 osc 0 0 n V 0

and solve using symbolic algebra software[2] to obtain the following expressions:

gsc no osc ng rv
no;L = (1.30)
(1 R s rv ) gsc

osc ng gsc no Rs rv
no;V = (1.31)
(1 R s rv ) gsc

10
gsc no osc ng rv osc + gsc Rs
nL = (1.32)
(1 R s rv ) gsc osc

gsc no osc ng rv Rs
ng;L = (1.33)
(1 R s rv ) osc

osc ng gsc no Rs
ng;V = (1.34)
(1 Rs rv ) osc
and
osc ng gsc no Rs gsc + osc rv
nV = : (1.35)
(1 R s rv ) gsc osc

Substituting Eqs. 1.32, 1.35, 1.27 and 1.28 in Eqs. 1.15 and 1.16, we obtain

gsc no osc ng rv Bo
So = (1.36)
(1 R s rv ) gsc osc

and from Eqs. 1.16, 1.35 and 1.28,

osc ng gsc no Rs Bg
Sg = : (1.37)
(1 R s rv ) gsc osc

Using our saturation constraint, Eq. 1.10, we have

Sw = 1 So Sg (1.38)

or
gsc no osc ng rv Bo + osc ng gsc no Rs Bg
Sw = 1 (1.39)
(1 Rs rv ) gsc osc

If a liquid hydrocarbon phase is present, Eqs. 1.36 and 1.24 require that

So > 0 (1.40)

or
gsc no > osc ng rv ; (1.41)
similarly, presence of a gas phase is indicated if (Eqs. 1.37 and 1.24)

osc ng > gsc no Rs : (1.42)

Finally, at the bubble point, all gas is dissolved in the oil, so


ng osc
Rs (pbub ) = ; (1.43)
gsc no

similarly, at the dew point,


no gsc
rv (pdew ) = ; (1.44)
osc ng

11
Note that phase saturations are now explicit functions of mass concentrations
of oil and gas components and pressure. In terms of our new set of independent
variables, our material balance equations in Cartesian coordinates become
@ @po @ (po + pcgo )
C1 kx o+ rv g +
@x @x @x
@ @po @ (po + pcgo )
ky o + rv g +
@y @y @y
@ @po g @ (po + pcgo ) g
kz o + L + rv g + V =
@z @z 144gc @z 144gc
nw
@no X e o;j (!
+ Q x j) (1.45)
o;sc @t j=1

@ @po @ (po + pcgo )


C1 kx Rs + g o +
@x @x @x
@ @po @ (po + pcgo )
ky Rs o + g +
@y @y @y
@ @po g @ (po + pcgo ) g
kz Rs o + L + g + V =
@z @z 144gc @z 144gc
Xnw
@ng e g;j (!
+ Q x j) (1.46)
g;sc @t j=1

@ @ (po
pcow )
C1 kx w +
@x @x
@ @ (po pcow )
ky w +
@y @y
@ @ (po pcow ) g
kz w + w =
@z @z 144gc
!
@ 1 gsc no osc ng rvBo + osc ng gsc no Rs Bg
@t Bw Bw (1 Rs rv ) gsc osc
nw
X
+ e w;j (!
Q x j) (1.47)
j=1

where
So rv Sg
no = osc + (1.48)
Bo Bg
Sg R s So
ng = gsc + (1.49)
Bg Bo
kro
o (1.50)
o Bo

12
krg
g (1.51)
g Bg

and
krw
w (1.52)
w Bw
Similarly, in cylindrical coordinates, the equations are

1 @ @po @pg
C1 rkr o + rv g +
r @r @r @r
1 @ k @po @pg
o + rv g +
r@ r @ @
@ @po g @pg g
kz o + L + rv g + V =
@z @z 144gc @z 144gc
@no
(1.53)
o;sc @t

1 @ @po @pg
C1 rkr Rs o + g +
r @r @r @r
1 @ k @po @pg
Rs o + g +
r@ r @ @
@ @po g @pg g
kz Rs o + L + g + V =
@z @z 144gc @z 144gc
@ng
(1.54)
g;sc @t

1 @ @pw
C1 rkr w +
r @r @r
1 @ k @pw
w +
r@ r @
@ @pw g
kz w + w =
@z @z 144gc
!
@ 1 gsc no osc ng rvBo + osc ng gsc no Rs Bg
(1.55)
@t Bw Bw (1 Rs rv ) gsc osc

Note that even if a phase disappears, the mass concentration of that phase
continues to exist; also, mass concentrations (like pressure) must be greater than
zero, but are not bounded between 0 and 1, and are not restricted by a saturation
constraint. However, even in this formulation, phase relative permeabilities will
cease to exist when that phase disappears; thus, di¢ culties may still arise when
we are crossing saturation boundaries.

13
Figure 1.1: Schematic of Rectangular Parallelpiped Reservoir

1.3 Discrete Equations


We will generate our …nite di¤erence equations for the system by subdividing
our reservoir into …nite volumes and applying an integral mass conservation of
each ‡owing species on each sub-volume.

1.3.1 Cartesian Coordinates


Suppose we have a sealed parallelepiped reservoir with dimensions Lx Ly Lz
as shown in Fig. 1.1. We subdivide the reservoir length in each coordinate
direction respectively into nx ny nz segments as follows:

0=x 1
2
< x 21 < x 23 < ::: < xnx 3
2
< xn x 1
2
= Lx ; (1.56)
0=y 1
2
< y 12 < y 23 < ::: < yny 3
2
< yny 1
2
= Ly ; (1.57)
0=z 1
2
< z 21 < z 23 < ::: < znz 3
2
< znz 1
2
= Lz : (1.58)
The reservoir is now divided into subregions with vertices are at

x 1
2
; yj 1
2
; zk 1
2
; x 1
2
; yj+ 12 ; zk 1
2
; x 1
2
; yj 1
2
; zk+ 12 ;

x 1
2
; yj+ 21 ; zk+ 12 ; x + 12 ; yj 1
2
; zk 1
2
; x + 12 ; yj+ 12 ; zk 1
2
;

x + 12 ; yj 1
2
; zk+ 12 ; x + 21 ; yj+ 12 ; zk+ 12 ;
and whose centers are at (x ; yj ; zk ) ; for = 0; 1:::nx 1; j = 0; 1:::ny 1;
k = 0; 1:::nz 1: Note that
x + 12 + x 1
2
x = ; (1.59)
2
yj+ 12 + yj 1
2
yj = ; (1.60)
2

14
zk+ 12 + zk 1
2
zk = : (1.61)
2
n+1
We de…ne a sequence of times, tk k=0 at which we approximate our ‡ow equa-
tions as
0 = t0 < t1 < t2 < ::: < tn < tn+1 < ::: (1.62)
We illustrate the derivation of our …nite di¤erence approximations that hold
in the grid block centered at (x ; yj ; zk ) ; at time tn+1 , by integrating Eq. 1.45
over the volume of the grid block as follows:

8
>
>
x + 1 yj+ 1 zk+ 1
< Z 2 Z 2 Z 2 @ @po @ (po + pcgo )
C1 kx o + rv g
>
> @x @x @x
:x 1 yj 1 zk 1
2 2 2

@ @po @ (po + pcgo )


+ ky o + rv g +
@y @y @y
@ @po g @ (po + pcgo ) g
kz o + L + rv g + V dzdydx
@z @z 144gc @z 144gc
x 1 y 1 z 1
Z+ 2 Zj+ 2 Zk+ 2
@no
= +
o;sc @t
x 1 yj 1 zk 1
2 2 2
9
nw
X =
e o;j
Q (!
x j ) dzdydx (1.63)
;
j=1

We illustrate how this volume integral is evaluated by considering the …rst term
in Eq. 1.63. We change the order of integration and integrate analytically over
x …rst to obtain:
yj+ 1 zk+ 1 x 1
Z 2 Z 2 Z+ 2
@ @po @ (po + pcgo )
kx o + rv g dxdydz =
@x @x @x
yj 1 zk 1 x 1
2 2 2
yj+ 1 zk+ 1 2 3
Z 2 Z 2
x +1
x +1
4 kx @po 2 @ (po + pcgo ) 2
5 dydz
o + kx rv g
@x x 1
@x x 1
yj 1 zk 1 2 2
2 2

then we use the mean value theorem: we evaluate the integrand at the block

15
midpoint in the y and z directions, and integrate to obtain
(
@po @po
kx o kx o +
@x + 1 ;j;k @x 1
;j;k
2 2
)
@ (po + pcgo ) @ (po + pcgo )
kx rv g kx rv g y j zk
@x + 12 ;j;k @x 1
2 ;j;k

where we de…ne
x = x + 21 x 1
2
; (1.64)
yj = yj+ 12 yj 1
2
; (1.65)
zk = zk+ 12 zk 1
2
; (1.66)
and we have introduced the following simplifying notation. For a general func-
tion f (x; y; z; t), we de…ne
f n+1
;j;k f x ; yj ; zk ; tn+1 : (1.67)
h i
@po
so, for example, kx o @x is evaluated at the point x + 21 ; yj ; zk : Car-
+ 21 ;j;k
rying out the integration on Eq. 1.63, we obtain the following approximation
(( )
@po @po
C1 kx o kx o y j zk +
@x + 1 ;j;k @x 1
2 2 ;j;k
( )
@ (po + pcgo ) @ (po + pcgo )
kx rv g kx rv g y j zk +
@x + 12 ;j;k @x 1
2 ;j;k
( )
@po @po
ky o ky o x zk +
@y i;j+ 1 ;k @y i;j 1 ;k
2 2
( )
@ (po + pcgo ) @ (po + pcgo )
ky rv g ky rv g x zk +
@y i;j+ 12 ;k @y i;j 12 ;k
(
@po g
kz o + L
@z 144gc i;j;k+ 1
) 2
@po g
kz o + L x yj +
@z 144gc i;j;k 1
2
(
@ (po + pcgo ) g
kz rv g + V
@z 144gc i;j;k+ 1
) 2 )
@ (po + pcgo ) V g
kz rv g + x yj
@z 144gc i;j;k 1
2
!
@no eo
= +Q i;j;k
x y j zk (1.68)
o;sc @t ;j;k

16
Note that the last term in Eq. 1.68 only arises if there is a sink or source term
in block centered at (x ; yj ; zk ) and that we compute the integral on the right
side of Eq. 1.63 using the mean value theorem to evaluate the integrand at the
midpoint of the block.
We approximate spatial derivatives such as that in the x-direction as

@f f n+1
+1;j;k f n+1
;j;k
; (1.69)
@x x ;yj ;zk x + 21
+1
2

where
x + 21 = x +1 x; (1.70)
Similar equations apply for the other coordinate directions. Eq. 1.69 assumes
that a neighbor grid block exists at (x +1 ; yj ; zk ); in the case that no neighbor
grid block exists at (x +1 ; yj ; zk ), and the boundary is sealed at x + 21 ; yj ; zk ,

@f
= 0: (1.71)
@x x ;yj ;zk
+1
2

We discuss the application of other possible boundary conditions later.


Similarly, we approximate the time derivative as

@f f n+1
;j;k
f n;j;k
; (1.72)
@t t
where
t = tn+1 tn (1.73)
We divide Eq. 1.68 by the bulk volume of the block,

Vi;j;k = x y j zk ; (1.74)

and apply the …nite di¤erence approximations to the spatial and time derivatives
to obtain:
12
X h i qoi;j;k
;j;k
Fo ;j;k = zo;` nn+1
o ;j;k nno ;j;k =0 (1.75)
o;sc t Vi;j;k
`=1

where qoi;j;k is the oil rate in scf/day from the block centered at (x ; yj ; zk ) ; and

n+1
zo;1 = Gx + 1 ;j;k o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1
144gc 2

(1.87)
kx
C1 + 1 ;j;k
2
Gx + 1 ;j;k = ; (1.88)
2 x + 21 x 1
2
x +1 x
kx
C1 1 ;j;k
2
Gx 1 ;j;k = ; (1.89)
2 x + 12 x 1
2
x x 1

and the remaining terms involving Gy and Gz are analogous. Note that the
terms Gp ; p = x; y or z involve only geometric terms and rock properties.
The harmonic average permeability terms, e.g., kx 1 , are evaluated in the
+ ;j;k
2
standard manner; i.e.,
xi+1 xi
kx = x 1 xi xi+1 xi+ 21 : (1.90)
+ 1 ;j;k i+ 2
2
+
kx ;j;k kx +1;j;k

18
Finally,
n+1 n+1
m ;j;k + m ;j;k+1
n+1
m = ; for m = L; V (1.91)
;j;k+ 1
2
2
The …nite di¤erence equations for gas and water are similarly given by
12
X h i qgi;j;k
;j;k
Fg ;j;k = zg;` nn+1
g ;j;k nng ;j;k =0 (1.92)
g;sc t Vi;j;k
`=1

with qgi;j;k denoting the gas rate in scf/day from the block centered at (x ; yj ; zk ) ;
and

zg;1 = Gx + 1 ;j;k Rsn+1 n+1


o pn+1
o +1;j;k pn+1
o ;j;k (1.93)
2 + 1 ;j;k + 1 ;j;k
2 2

zg;2 = Gx 1 ;j;k Rsn+1 n+1


o 1 pn+1
o ;j;k pn+1
o 1;j;k (1.94)
2 1 ;j;k ;j;k
2 2

n+1
zg;3 = Gx + 1 ;j;k g 1 pn+1
g +1;j;k pn+1
g ;j;k (1.95)
2 + ;j;k
2

n+1
zg;4 = Gxi 1 ;j;k g 1 pn+1
g ;j;k pn+1
g 1;j;k (1.96)
2 i ;j;k
2

zg;5 = Gy ;j+ 1 ;k Rsn+1 n+1


o pn+1
o pn+1
o ;j;k (1.97)
;j+1;k
2 ;j+ 1 ;k ;j+ 1 ;k
2 2

zg;6 = Gy ;j 1 ;k Rsn+1 n+1


o pn+1
o pn+1
o ;j 1;k (1.98)
2 1 ;k 1 ;k ;j;k
i;j i;j
2 2

n+1
zg;7 = Gy ;j+ 1 ;k g pn+1
g pn+1
g ;j;k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1 1
w 1
g
;j;k
zw;6 = Gz ;j;k 1
n+1
w
@pn+1
w pn+1
w ;j;k + 2
zk 1 A (1.112)
2 ;j;k 1
2
;j;k 1
144gc 2

1.3.2 Cylindrical Coordinates


Figure 1.2 depicts a cylindrical reservoir containing a well with radius rw located
at the center of a cylinder of radius re ; the height of the cylinder is Lz , and the
cylinder is subdivided into nr n nz segments de…ned by

rw = r 1
2
< r 12 < r 32 < ::: < rnr 3
2
< r nr 1
2
= re ; (1.113)

0= 1
2
< 1
2
< 3
2
< ::: < n 3
2
< n 1
2
=2 ; (1.114)
0=z 1
2
< z 21 < z 25 < ::: < znz 3
2
< znz 1
2
= Lz : (1.115)
The reservoir is now divided into subregions with vertices at

ri 1
2
; j 1
2
; zk 1
2
; ri 1
2
; j+ 12 ; zk 1
2
; ri 1
2
; j 1
2
; zk+ 12 ;

ri 1
2
; j+ 12 ; zk+ 21 ; ri+ 12 ; j 1
2
; zk 1
2
; ri+ 12 ; j+ 12 ; zk 1
2
;

ri+ 21 ; j 1
2
; zk+ 12 ; ri 1
2
; j+ 21 ; zk+ 12

and whose centers are at (ri ; j ; zk ) ; for i = 0; 1:::nr 1; j = 0; 1:::n 1;


k = 0; 1:::nz 1:

20
Figure 1.2: Schematic of a Cylindrical Grid.

21
We illustrate the derivation of our …nite di¤erence approximations that hold
in the grid block centered at ri 12 ; j+ 21 ; zk+ 21 ; at time tn+1 , by integrating
Eq. 1.53 over the volume of the grid block as follows:
ri+ 1 1 z 1
Z 2 Zj+ 2 Zk+ 2
1 @ @po @pg
C1 rkr o + rv g +
r @r @r @r
ri 1 j 1 zk 1
2 2 2

1 @
k @po @pg
o + rv g +
r@
r @ @
@ @po g @pg g
kz o + L + rv g + V rdrd dz =
@z @z 144gc @z 144gc
ri+ 1 1 z 1
Z 2 Zj+ 2 Zk+ 2
@no
rdrd dz (1.116)
o;sc @t
ri 1 j 1 zk 1
2 2 2

Carrying out the indicated integrations, we obtain


(( )
@po @po
C1 rkr o rkr o j zk +
@r + 1 ;j;k @r 1
2 2 ;j;k
( )
@ (po + pcgo ) @ (po + pcgo )
rkr rv g rkr rv g j zk +
@r + 12 ;j;k @r 1
2 ;j;k
( ) !
@po @po ri+ 12
k o k o ln zk +
@ i;j+ 1 ;k @ i;j 1 ;k ri 12
2 2
( ) !
@ (po + pcgo ) @ (po + pcgo ) ri+ 12
k rv g k rv g ln zk +
@ i;j+ 21 ;k @ i;j 12 ;k ri 21
(
@po g
kz o + L
@z 144gc i;j;k+ 1
2
)
@po g ri+ 2 + ri 12
1

kz o + L r j+
@z 144gc i;j;k 1 2
2
(
@ (po + pcgo ) g
kz rv g + V
@z 144gc i;j;k+ 1
2
) 9
@ (po + pcgo ) g ri+ 12 + ri 21 =
kz rv g + V r j
@z 144gc i;j;k 1 2 ;
2

!
@no ri+ 12 + ri 1
2
= r j zk (1.117)
o;sc @t i;j;k
2

22
where
r = r + 21 r 1
2
; (1.118)

j = j+ 12 j 1
2
; (1.119)
zk = zk+ 12 zk 1
2
; (1.120)
If we divide Eq. 1.117 by the gridblock volume, Vi;j;k ,
1 2
Vi;j;k = r +1 r2 1 j zk (1.121)
2 2 2

we can write Eq. 1.117 in the same form as Eqs. 1.75 - 1.87 provided we replace
the geometric terms Gx and Gy by Gr and G , where

r + 21 kr
2C1 + 1 ;j;k
2
Gr + 1 ;j;k = ; (1.122)
2
r2+ 1 r2 1
r +1 r
2 2

r 1 kr
2C1 2 1 ;j;k
2
Gr 1 ;j;k = ; (1.123)
2
r2+ 1 r2 1
r r 1
2 2

and the interblock permeability, kr , is given by a harmonic average; i.e.,


+ 1 ;j;k
2

ri+ 1
kr ;j;k kr +1;j;k ln ri
2
1
2
kr = ri+ 1
(1.124)
+ 1 ;j;k
2 ri
kr ;j;k ln ri
2
+ kr +1;j;k ln ri 1
2

and
ri+ 1
2C1 ln ri
2
1
k
2 ;j+ 1 ;k
2
G ;j+ 1 ;k
= ; (1.125)
2
r2+ 1 r2 1 j+ 12 j 1
2
j+1 j
2 2

ri+ 1
2C1 ln ri
2
1
k 1 ;k
2 ;j
2
G ;j 1 ;k = ; (1.126)
2
r2+ 1 r2 1 j+ 12 j 1
2
j j 1
2 2

and the interblock permeability, k , is given by,


;j+ 1 ;k
2

ri+ 1
kr ;j;k kr +1;j;k ln ri
2
1
2
k = ri+ 1
(1.127)
;j+ 1 ;k
2 ri
kr ;j;k ln ri
2
+ kr +1;j;k ln ri 1
2

By using the de…nitions of Eqs. 1.121 - 1.127, the discrete ‡ow equations,
Eqs. 1.75, 1.92 and 1.105 apply equally to Cartesian or cylindrical grids. In

23
fact, we can generalize our discretization to practically any discrete grid system
by appropriately modifying the equations for the geometric terms, Gx ; Gy and
Gz : Before closing this section, we note that it is customary to use the gridding
system suggested by MacDonald and Coats[24] in the radial direction. If the
wellbore radius is denoted by rw , and the external reservoir radius is denoted
by re , the radial grid is de…ned by the following equations:
1
re nr
= (1.128)
rw
i
ri = r i 1 = r0 for i = 1; 2; :::nr (1.129)
rw ln ( )
r0 = (1.130)
1
i
( 1) r0
ri+ 21 = for i = 1; 2; :::nr (1.131)
ln ( )

1.4 PVT Properties


The PVT properties that appear in the discrete equations (Eqs. 1.75, 1.92
and 1.105) are functions of pressure for saturated systems, and pressure and
saturation pressure (or composition) for undersaturated systems. In general,
saturated properties are provided as tables, and PVT properties at particular
values of pressure that are below the in situ saturation pressure are evaluated
by interpolating between points in a table. A given simulation run may require
determining PVT properties at millions of pressure values, so it is essential that
the interpolation routine is as fast and e¢ cient as possible.
Interpolation of tabulated data is a two-step process: …rst, we must locate
the interval in the table where the desired value of independent variable (i.e.,
pressure) exists, then we apply the appropriate interpolation formula on the
interval that brackets the desired value of the independent variable. Each of
these tasks can be time consuming if they are done without care. Tables where
the independent variable increases by a …xed amount for each successive can be
searched very quickly and e¢ ciently. Consider, for example, the following table
where gas formation volume factor and viscosity are tabulated versus pressure.
The constant step size in pressure is 50 psia. If we wish to determine properties
at a pressure of 297 psia, (which lies in the tabulated interval (250, 300)),
…nding the index of the row in the table that contains the largest value of the
independent variable that is smaller than our desired pressure (i.e., 250 psia in
our example) is as simple as determining the integer that results from dividing
the di¤erence between the desired pressure (297) and the …rst pressure in the
table (100) by the step size (50); that is, (29750100) = 3, so the desired pressure
is bracketed by the pressure values in rows 3 and 4 of the table. (If we started
counting our rows at 1 instead of 0, we would add 1 to our result, so the interval
would be between rows 4 and 5.)

24
3
ft
Row Pressure, psia Bg , scf g; cp
0 100 0.000110 0.020
1 150 0.000106 0.021
2 200 0.000097 0.022
3 250 0.000089 0.023
4 300 0.000086 0.024
5 350 0.000079 0.025

The search technique we have described is general; for any table that has
an equal spacing x in the independent variable, the beginning index, j, of the
interval containing a user provided number x
^ is given by

x
^ x0
j = int (1.132)
x

where x0 is the value of the dependent variable in row 0, and int(y) returns the
(truncated) integer part of y. If the row index starts at 1, then the appropriate
formula is
x
^ x1
j = int +1 (1.133)
x
Equation 1.132 describes the fastest method of searching a table, however, it
only applies for tables that have equal step size in the independent variable.
Once the interval is found, we can estimate the required value(s) of the depen-
dent variables by linear interpolation using the following formula

y^ = yj0 (^
x xj ) + yj (1.134)

where
yj+1 yj
yj0 = : (1.135)
xj+1 xj
(In the following section on Object Oriented Design, we describe a table class
that performs table lookup and linear interpolation e¢ ciently.) If the provided
saturated tabular PVT data is not evenly spaced in pressure, an equivalent
even-spaced pressure table should be generated for use in the simulator. If
PVT properties are not measured, Appendix A presents some commonly used
correlations for estimating oil and water PVT properties; these should be used
to generate tables for input to the simulator.
PVT properties of undersaturated oil are dependent on both the pressure
and saturation pressure of the in situ oil mixture (see Figs. 1.3 and 1.4). In
order to compute the in situ saturation pressure, we determine the value of
solution gas-oil ratio if all of the gas component in the block were dissolved; i.e.,
we compute
ng osc
Rs (pbub ) = (1.136)
gsc no

then …nd the bubble point pressure by interpolating the provided saturated so-
lution gas-oil ratio versus pressure tables. As discussed previously, the most

25
e¢ cient way to do this is to create a table of solution gas-oil ratio versus satura-
tion pressure (from the provided PVT tables) that is equally spaced in solution
Gas-oil ratio.
Once the in situ saturation pressure has been determined, the desired un-
dersaturated oil PVT property is determined from

d#
# (p; psat ) = # (psat ; psat ) + (p psat ) (1.137)
dp undersaturated

where # (psat ; psat ) is the value of the (saturated) property at the saturation
pressure, d#
dp is the slope of the property with pressure at un-
undersaturated
dersaturated conditions, and p > psat . Note that gas properties cease to exist
above the bubble point; also water properties depend only on pressure and are
independent of saturation pressure.

1.5 Relative Permeabilities and Capillary Pres-


sures
1.5.1 Two-Phase Relative Permeability
Relative permeability to oil in a water-wet core and gas in an oil-wet core are
usually determined in laboratory displacement tests (see for example, Ref. [17])
where displacement data are …t to a relative permeability model. One of the
most widely used relative permeability models is the power-law model[8]. For
oil-water systems, the power law equations are
nw
krw (Sw ) = krw (1 Sorw ) SwD (1.138)

where krw (Sw ) is the relative permeability to water at the water saturation of
interest (Sw ), Sorw is the residual oil saturation for oil in the presence of water,
krw (1 Sorw ) is the relative permeability to water at the residual oil saturation,
nw is an empirical water exponent, and SwD is a dimensionless water saturation
de…ned as
Sw Swi
SwD = (1.139)
1 Sorw Swi
for Swi Sw 1 Sor : Here Swi is the initial irreducible water saturation.
Similarly, the relative permeability to oil in a water wet rock is given by
no
krow (Sw ) = krow (Swi ) (1 SwD ) (1.140)

where krow (Sw ) is the relative permeability to oil at the water saturation of
interest (Sw ), krow (Swi ) is the relative permeability to oil at the irreducible
water saturation, and no is an empirical oil exponent. The equations for a gas
oil system are analogous; i.e.,
n g
krg (Sg ) = krg (1 Slc ) SgD (1.141)

26
Figure 1.3: Solution Gas-Oil Ratio as a function of pressure and saturation
pressure.

27
Figure 1.4: Oil Viscosity as a function of pressure and saturation pressure

28
where
Sg Sgc
SgD = (1.142)
1 Slc Sgc
and
Slc = Swi + Sorg (1.143)
Also the relative permeability to oil in an oil/gas system is
no
krog (Sg ) = krog (Sgc ) (1 SwD ) : (1.144)

(Note that the oil exponents, no ; in Eqs. 1.140 and 1.144 are unrelated and
distinct.)
As in the case of PVT properties, two-phase relative permeability properties
are stored and used in the simulator as tabulated data that are equally spaced
in saturation. (See the Table class in the following section.)

1.5.2 3-Phase Relative Permeability


Three phase relative permeability curves are usually generated by combining two
sets of two phase relative permeability curves. That is, we start with sets of oil-
water and gas-oil relative permeabilities, and assume that relative permeability
to water is a unique function of water saturation, relative permeability to gas is
a unique function of gas saturation, and relative permeability to oil is a function
of water and gas saturations; i.e.,

krw = krw (Sw ) (1.145)

krg = krg (Sg ) (1.146)


and
kro = kro (Sw ; Sg ) (1.147)
Thus, we obtain water and gas relative permeabilities directly from the two-
phase curves, and we usually obtain oil relative permeability by combining val-
ues from the oil-water and gas-oil curves. One of the most common ways of
estimating three-phase oil relative permeabilities is by applying the models due
to Stone[30], [31].

Stone Model I
Stone de…nes normalized saturations to oil (Son ), water (Swn ), and gas (Sgn ),
as follows
So Sor
Son = ; (1.148)
1 Swi Sor
where Sor is the residual oil saturation in the three-phase system and So Sor ;
Sw Swi
Swn = ; (1.149)
1 Swi Sor

29
for Sw Swi and
Sg
Sgn = =1 Son Swn : (1.150)
1 Swi Sor
The relative permeability to oil in the three-phase system is then determined
using the following formula:

kro (Sw ; Sg ) = krow (Swi ) Son w g (1.151)

where
krow (Sw )
w = (1.152)
krow (Swi ) (1 Swn )
and
krog (Sg )
g = (1.153)
krow (Swi ) (1 Sgn )
Note that it is assumed that

krow (Swi ) = krog (Sg = 0) (1.154)

Stone Model II
This model does not require knowledge of the residual oil saturation in the
three-phase system. The equation is

kro (Sw ; Sg )
=
krow (Swi )
krow (Sw ) krog (Sg )
+ krw (Sw ) + krg (Sg ) (krw (Sw ) + krg (Sg ))
krow (Swi ) krow (Swi )
(1.155)

where the symbols are the same as in the Stone Model I, and kro (Sw ; Sg ) 0;
thus, if a negative value of kro is computed, it is truncated to 0.

1.6 Object Oriented Design


Before we address our …rst software classes, we discuss a practical issue that we
will encounter in writing and maintaining good C++ code; the need for “fast”
execution versus the need for “safe” code. In the following section we describe
one possible approach to this problem. In subsequent sections we discuss design
of our basic classes: Grid, GridblockVariables, Table, PVT properties, classes
for Relative Permeability and capillary pressure and miscellaneous classes.

30
1.6.1 Programming Speed versus Safety
We are faced with two choices in creating arrays in C++ - allocating memory to
pointers using new, or using std::vectors. Using pointers produces the fastest
code, but is inherently unsafe because use of a wrong index value could easily
overwrite memory anywhere in the system. Further, it is up to the user to
delete allocated memory after it has been used, or there will be “memory leaks”
during and after a run. In contrast, use of std::vectors is safe since the indices are
checked to ensure that they are within the array bounds; however, because of this
extra checking, std::vectors are much slower than pointers. Further advantages
of using std::vectors are that they can be easily resized and are automatically
deleted after a run, so there are no memory leaks. In a large reservoir simulator,
speed is critically important, however in developing a simulator, “safe arrays”
are invaluable in helping to debug the program.

DFLEXARRAY de…nition and implementation


We suggest the following: de…ne a DFLEXARRAY as
#ifdef __DEBUG_MODE
typedef std::vector<double> DFLEXARRAY;
#else
typedef double * DFLEXARRAY;
#endif
Then de…ne the following functions to create and delete the DFLEXAR-
RAYs.
void CreateArray(int n, DFLEXARRAY* pArray)
{//@CODE_26
#ifdef __DEBUG_MODE
(*pArray).resize(n);
#else
(*pArray) = new double [n];
#endif
}

void DeleteArray(DFLEXARRAY* pArray)


{//@CODE_30
#ifdef __DEBUG_MODE
(*pArray).clear();
#else
delete [] (*pArray);
#endif
}
In this way, we have the ‡exibility of choosing whether to work with std::vectors
or with pointers in our program by simply de…ning (or unde…ning) __DE-

31
BUG_MODE. Note that similar de…nitions can be made for multidimensional
arrays or arrays of di¤erent types. This is illustrated in the following.

D2FLEXARRAY de…nition and implementation


We de…ne a D2FLEXARRAY as:
#ifdef __DEBUG_MODE
typedef std::vector< std::vector<double> > D2FLEXARRAY;
#else
typedef double ** D2FLEXARRAY;
#endif
Creation and destruction of D2FLEXARRAYs is achieved using the follow-
ing code.
// 2-D double precision array
bool CreateFlexArray(D2FLEXARRAY & pArray, int ncol, int nrow)
{
int i;
#ifdef __DEBUG_MODE
if (ncol)
{
pArray.resize(ncol);
for (i = 0; i < ncol; i++)
{
pArray[i].resize(nrow);
}
}
return true;
#else
if (pArray)
{
throw "In CreateFlexArray - trying to create an already created array";
}
if (ncol)
{
pArray = new double * [ncol];
if (!pArray)
{
return false;
}else{
for (i = 0; i < ncol; i++)
{
pArray[i] = new double [nrow];
if (!pArray[i])
{

32
return false;
}
}
return true;
}
}else{
pArray = NULL;
return true;
}
#endif
}
// delete 2-D array
template <class T >
void Delete2DFlexArray(T & pArray, int ncol)
{
int i;
#ifdef __DEBUG_MODE
if (pArray.size())
{
for (i = 0; i < ncol; i++)
{
pArray[i].clear();
}
pArray.clear();
}
#else
if (pArray)
{
for (i = 0; i < ncol; i++)
{
if (pArray[i])
{
delete [] pArray[i];
pArray[i] = NULL;
}
}
delete [] pArray;
pArray = NULL;
}
#endif
}
Note that the above destructor can be applied to any type 2-D ‡exible array.

D3FLEXARRAY de…nition and implementation


We de…ne a D3FLEXARRAY as:

33
// 3-D double array
bool CreateFlexArray(D3FLEXARRAY & pArray, int n0, int n1, int n2)
{
// creates array with dimensions n0 * n1 * n2
int i, j;
#ifdef __DEBUG_MODE
if (n0)
{
pArray.resize(n0);
for (i = 0; i < n0; i++)
{
pArray[i].resize(n1);
for(j = 0; j < n1; j++)
{
pArray[i][j].resize(n2);
}
}
}
return true;
#else
if (pArray)
{
throw "In CreateFlexArray - trying to create an already created D3FLEXARRAY \n";
}
if (n0)
{
pArray = new double ** [n0];
if (!pArray)
{
return false;
}else{
for (i = 0; i < n0; i++)
{
pArray[i] = new double *[n1];
if (!pArray[i])
{
return false;
}else{
for (j = 0; j < n1; j++)
{
pArray[i][j] = new double [n2];
if (!pArray[i][j])
{
return false;
}
}

34
}
}
return true;
}
}else{
pArray = NULL;
return true;
}
#endif
}
We delete 3-D arrays using:
// delete 3-D array
template <class T >
void Delete3DFlexArray(T & pArray, int n0, int n1)
{
int i, j;
#ifdef __DEBUG_MODE
if (pArray.size())
{
for (i = 0; i < n0; i++)
{
for (j = 0; j < n1; j++)
{
pArray[i][j].clear();
}
pArray[i].clear();
}
}
pArray.clear();
#else
if (pArray)
{
for (i = 0; i < n0; i++)
{
for (j = 0; j < n1; j++)
{
if (pArray[i][j])
{
delete [] pArray[i][j];
pArray[i][j] = NULL;
}
}
if (pArray[i])
{
delete [] pArray[i];

35
FiniteDifferenceGrid
# BlockPerm_0 : DFLEXARRAY
# BlockPerm_1 : DFLEXARRAY
# BlockPerm_2 : DFLEXARRAY
# BlockVolumes : DFLEXARRAY
# DZ : DFLEXARRAY
# FDTerm_0 : DFLEXARRAY
# FDTerm_1 : DFLEXARRAY
# FDTerm_2 : DFLEXARRAY
# nGrid_0 : int
# nGrid_1 : int
# nGrid_2 : int
# Porosity : DFLEXARRAY
# X0 : DFLEXARRAY* = NULL
# X0H : DFLEXARRAY* = NULL
# X1 : DFLEXARRAY* = NULL
# X1H : DFLEXARRAY* = NULL
# X2 : DFLEXARRAY* = NULL
# X2H : DFLEXARRAY* = NULL
+ <<Abstract>> ComputeGeometricTerms() : void

Figure 1.5: Main members and methods for a Finite Di¤erence Class

pArray[i] = NULL;
}
}
delete [] pArray;
}
#endif
}

1.6.2 The Grid Class


The discrete forms of the ‡ow equations in Cartesian and cylindrical coordinates
suggest that we can encapsulate the behavior of (regular) …nite di¤erence grids
in a F initeDif f erenceGrid class which contains the following members and
functionality (see Fig. 1.5).

Members
1. nGrid_0; nGrid_1; nGrid_2 (int) - the number of gridblocks in each
coordinate direction.
2. BlockV olumes (DFLEXARRAY) - the bulk volumes of each gridblock
(see Eq. 1.74 or 1.121). (ft3 ).
3. DZ (DFLEXARRAY) - array containing the heights of each gridblock;
(this is used in computation of the gravity terms - see for example, Eqs.
1.86 and 1.87).

36
4. BlockP erm_0, BlockP erm_1, BlockP erm_2 (DFLEXARRAY) - Ar-
rays containing the absolute permeabilities of each gridblock in each co-
ordinate direction (md).
5. F DT erm_0, F DT erm_1, F DT erm_2 (DFLEXARRAY) - Arrays con-
taining the geometric components of the interblock transmissibilities in
each coordinate direction (e.g., Eqs. 1.88, 1.89, 1.122, 1.123, 1.125, 1.126).
In the Cartesian coordinate system, F DT erm_0 is an array of size ((nGrid_0 + 1)
nGrid_1 nGrid_2), F DT erm_1 is dimensioned (nGrid_0 (nGrid_1 + 1)
nGrid_2) and F DT erm_2 is dimensioned (nGrid_0 nGrid_1
(nGrid_2 + 1)). The dimensions of the arrays in the cylindrical system
would be similar, except in the angular direction; if the reservoir is a
complete cylinder, the dimension of F DT erm_1 is (nGrid_0 nGrid_1
nGrid_2) since the block boundaries at = 0 and = 2 coincide.
6. P orosity (DFLEXARRAY) - array dimensioned nGrid_0 nGrid_1
nGrid_2 containing the porosities of each gridblock.
7. X0, X1, X2 (DFLEXARRAY) - Arrays containing the positions of the
gridblock centers in each coordinate direction.
8. X0H, X1H, X2H (DFLEXARRAY) - Arrays containing the positions of
the gridblock boundaries in each coordinate direction.

Functionality
Aside from o¤ering the user the ability to get any of the member arrays, this
class must provide an internal ability to compute all geometric terms based on
the coordinate system.

1. ComputeGeometricT erms - Given the coordinate direction, k, (i.e., 0, 1


or 2), compute F DT erm_0, F DT erm_1, F DT erm_2 and DZ.

Two specialized children of the F initeDif f erenceGrid class would be


CartesianGrid and CylindricalGrid.

1.6.3 The GridblockVariables Class


Associated with each gridblock in the …nite di¤erence grid are (oil) pressures,
water and gas saturations, concentrations of oil and gas and the water term,
w , see Eq. 1.106. In addition, we will have to keep track of the saturation
pressures in each gridblock. This class therefore contains the following (public)
members (see Fig. 1.6).

Members
1. n (int) - the number of gridblocks.
2. P (DFLEXARRAY) - array dimensioned n of block oil pressures.

37
GridblockVariables
# n : int = 0
+ BetaW : DFLEXARRAY
+ ng : DFLEXARRAY
+ no : DFLEXARRAY
+ P : DFLEXARRAY
+ PSat : DFLEXARRAY
+ Sg : DFLEXARRAY
+ Sw: DFLEXARRAY
+ EquateTo() : void
+ InputVariables() : void
+ OutputVariables() : void
+ Swap() : void

Figure 1.6: Members and Functionality of the Gridblock Variables class (struc-
ture).

3. P sat (DFLEXARRAY) - array dimensioned n of block saturation pres-


sures.
4. Sw (DFLEXARRAY) - array dimensioned n of block water saturations.
5. Sg (DFLEXARRAY) - array dimensioned n of block gas saturations.
6. no (DFLEXARRAY) - array dimensioned n of block oil mass concentra-
tions.
7. ng (DFLEXARRAY) - array dimensioned n of block gas mass concentra-
tions.
8. Betaw (DFLEXARRAY) - array dimensioned n of block water terms (
Eq. 1.106).

Functionality
1. InputV ariables - given a std :: if stream object, read in values of all
arrays. This is used in initializing the simulator when we want to restart
from a previous run.
2. OutputV ariables - given a std :: of stream object, write values of all
arrays. Consider writing as binary …les for faster input/output.
3. EquateT o - given a (pointer to a) GridblockVariables object, equate all
elements of each array to the given object arrays.

4. Swap - given a (pointer to a) GridblockVariables object, swap all arrays.

38
Table
# noDependentVariables : int
# noValues : int
# X: DFLEXARRAY
# XStep : double
# YSlopes : D3FLEXARRAY
+ <<Virtual>> getInterpolatedValues() : bool
+ <<Virtual>> OutputTable() : void
+ <<Virtual>> ReturnPointerToIndependentVariable() : DFLEXARRAY*
+ <<Virtual>> ReturnPointerToTableColumn() : DFLEXARRAY*
# FillYSlopes() : void
- locate() : int

Figure 1.7: Members and functionality of the Table class.

1.6.4 The Table Class


As mentioned in previous sections, the most e¢ cient way to search and interpo-
late tabulated data is to use tables that are equally spaced in the independent
variable. The members and functionality of this class are shown in Fig. 1.7.

Members
1. noV alues (int) - the number of values (rows) in the table.
2. noDependentV ariables (int) - the number of columns (excluding the in-
dependent variable column) in the table.
3. X (DFLEXARRAY) - array dimensioned noV alues containing equally
spaced values of the independent variable.
4. XStep (double) - Size of the constant increment in the independent vari-
able array.
5. Y Slopes (D3FLEXARRAY) - three dimensional array (dimensioned 2
noDependentV ariables noV alues). Y Slopes[0][i][j] contains the value
of the ith dependent variable corresponding to X[j]; Y Slopes[1][i][j] con-
tains the …rst derivative of the ith dependent variable with respect to the
independent variable corresponding to X[j]:

Functionality
1. getInterpolatedV alues - given an array of user provided values of the in-
dependent variable, return interpolated values (and slopes). This function
is polymorphic.

2. OutputT able - given a std :: of stream object, write values of the table to
a …le. Consider writing as binary …les for faster input/output.

39
3. ReturnP ointerT oIndependentV ariable (DFLEXARRAY *) - sometimes
we need to work with the values in the independent variable array directly.
This function provides access to that array.
4. ReturnP ointerT oT ableColumn (DFLEXARRAY *) - sometimes we need
to work with a single column in the table of dependent variables; this
function provides access to that column.
5. F illSlopes - given the dependent variable tables, compute slopes of the
dependent variables with respect to the independent variable.
6. locate (int) - this function works with arbitrarily spaced tables of the
independent variable and is described below.

If our available tables are not equally spaced in the independent variable,
we must …rst create equally spaced tables by using conventional search and
interpolation routines on the input tables. The algorithm for doing this is as
follows:

1. Read in the given array of the independent variable (double * xactual) and
the dependent variables, (double **yactual), as well as the actual sizes of
the arrays. (xactual[nrows], yactual[ncolumns][nrows]). Store the actual
minimum and maximum values of the independent variable (double xmin,
double xmax).
2. Set a desired step size for the equally-spaced dependent variable array
(double xstep_desired).
3. Compute the actual number of values (int nV al) in the equally-spaced
arrays as

nV al = int (ceil (fabs (xmax xmin) =xstep_desired)) + 1 (1.156)

where int (x) returns the truncated integer part of the double precision
number x, ceil (x) returns the smallest double precision integer value that
is greater than or equal to x and fabs (x) returns the absolute value of x:
4. Compute the actual value of the constant step in the independent vari-
ables; double xstep = (xmax xmin)/(nV al 1).
5. Create arrays for the equal-spaced independent variables; double *x =
new double[nV al]. Also create arrays for the dependent variables and
the slopes of the dependent variables, e.g., double ** y = new double
*[ncolumns]; double ** yslope = new double *[ncolumns]; double *y[i]
= new double[nV al]; double *yslope[i] = new double[nV al].
6. Fill the array of independent variables; x[0] = xmin; x [i] = x [i 1] +
xstep for i = 1; 2:::nV al 1.

40
7. Fill the dependent variable and slope arrays by looking up and interpolat-
ing the input data set. The algorithm for searching the actual independent
variable array is described next.

In the following, we describe an algorithm (see Ref. [42]) to locate the index
l in a monotonically increasing or decreasing array x of size n, such that a given
value x^ is between x [l] and x [l + 1] :

1. Set lower and upper limits on the array indices: int jlow = 1; int jhi = n.
2. While jhi jlow > 1 do

(a) Calculate the midpoint index of the interval: int jm = (jhi+jlow)=2;


(b) For an increasing x-sequence, check whether x
^ > x [jm]; if true, set
jlow = jm; otherwise set jhi = jm; (treat decreasing sequences in
an analogous manner.)

3. Return l = jlow:

Having found the interval containing x [k] ; 0 < k < nV al, compute the
interpolated dependent variables and the slope using

yactual [i] [l + 1] yactual [i] [l]


yslope[i] [k] = for i = 0; 1::ncolumns (1.157)
xactual [l + 1] xactual [l]

y [i] [k] = yactual [i] [l] + yslope[i] [k] (x [k] xactual [l]) (1.158)
The algorithm for searching the equally space table and interpolating has
been described previously in Eqs. 1.132 - 1.135.

1.6.5 The PVTProperties Class


The class members and functionality for the PVTProperties class are summa-
rized in Fig. 1.8.

Members
1
1. Cw (double) - isothermal compressibility of water (psi ).
2. dM uodP (double) - derivative of oil viscosity with respect to pressure for
undersaturated oil. (cp/psi).
3. nP ress (int) - number of pressures at which PVT properties would be
evaluated.
4. P min, P max (double) - minimum and maximum values of pressures in
the pressure tables (psia).

41
PVTProperties
# Cw: double
# dMuodP : double
# nPress : int
# Pmax : double
# Pmin : double
# Pressures : DFLEXARRAY
# PSatVsRsTable : Table* = NULL
# Pstep : double
# PVTTable : Table* = NULL
# UndersatdCo : double
# UnderSaturatedIndices : IFLEXARRAY
# WaterTable : Table* = NULL
+ <<Virtual>> CreatePSatVsRsTable() : void
+ <<Virtual>> getFluidProperties() : bool
+ <<Virtual>> getSaturationPressure() : bool

Figure 1.8: Members and Functionality of the PVT Properties class.

5. P ressures (DFLEXARRAY) - Internal array to store pressures at which


PVT properties will be evaluated.
6. P V T T able (Table *) - table of PVT data that will be interpolated.
7. P SatV sRsT able (Table *) Table of saturation pressures versus solution
gas-oil ratio at saturated conditions.
8. P Step (double) - constant pressure step in the PVT tables.
9. U ndersatdCo (double) - isothermal compressibility of undersaturated oil
(psi 1 ).
10. W aterT able (Table *) - Table of water properties.

Functionality
1. CreateP satV sRsT able - given arrays of saturated solution gas-oil ra-
tio versus pressure, create a table of saturation pressure versus (equally
spaced) solution gas-oil ratio data.
2. getF luidP roperties - given an array of input pressures and saturation
pressures (or oil and gas concentrations), compute PVT properties and
slopes of PVT properties.
3. getSaturationP ressure - given in situ solution gas-oil ratios (or in situ
oil and gas concentrations), return saturation pressures by interpolating
the P SatV sRsT able.

42
RelativePermeability
# Kr : DFLEXARRAY
# RelPermTable : Table* = NULL
+ <<Abstract>> CreateTable() : void
+ <<Virtual>> getRelativePermeability() : bool
+ <<Virtual>> OutputTables() : void

Figure 1.9: Members and Methods for the 2-phase Relative Permeability Class.

1.6.6 Relative permeability and Capillary Pressure Classes


We have three classes to handle the determination of relative permeability data:
a two phase Relative permeability class; a capillary pressure class, and a three-
phase relative permeability and capillary pressure class. We will consider each
of these in turn.

RelativePermeability Class
This (generic) class handles two-phase relative permeabilities. An overview of
the members and methods is shown in Fig. 1.9.

Members
1. RelP ermT able (Table *) - table of relative permeabilities versus phase
saturation.
2. Kr (DFLEXARRAY) - internal relative permeability table that is used if
we need results at only a single saturation.

Functionality
1. CreateT able (abstract) - function to create the 2-phase relative perme-
ability tables. This must be supplied in derived classes.
2. GetRelativeP ermeability - given phase saturation or an array of phase
saturations, return relative permeabilities and derivatives of relative per-
meability with respect to phase saturation.

3. OutputT ables - given a std :: of stream object, write values of all arrays.
Consider writing as binary …les for faster input/output.
Possible child classes include a TabularRelativePermeability Class (where
input data are provided in the form of relative permeability tables) and a Pow-
erLawRelativePermeability Class where the tables are generated from power-law
functions.

43
ThreePhaseRelativePermeabilityCapPress
# Krog : RelativePermeability* = NULL
# Krow: RelativePermeability* = NULL
# Pcgo : CapillaryPressure* = NULL
# Pcow: CapillaryPressure* = NULL
+ <<Virtual>> UpdateCapillaryPressure() : bool
+ <<Abstract>> updateProperties() : bool
# <<Virtual>> SetupRelativePermeability() : void

Figure 1.10: Members and Methods for the Three Phase Relative Permeability
Class.

CapillaryPressure Class
Like the 2-phase relative permeability class, more sophisticated simulators may
work with tabulated capillary pressure versus saturation data; in this case, a
Table pointer would be a class member. In our implementation, straight line
capillary pressure curves are employed. For these, it su¢ ces to have a slope and
intercept of the capillary pressure “curve” as members. The sole method for
this class would be a getCapillaryPressure function that would return capillary
pressures for a given input phase saturation array.

ThreePhaseRelativePermeabilityCapPress Class
This generic class typically interacts with two phase relative permeability and
capillary pressure objects to create three-phase data. An overview of the mem-
bers and methods is presented in Fig. 1.10.

Members
1. Krog, Krow (RelativePermeability *) - two-phase relative permeability
objects for gas-oil and oil-water systems respectively.
2. P cgo, P cow (CapillaryPressure *) - two-phase capillary pressures for gas-
oil and oil-water systems respectively.

Functionality

1. updateP roperties - given arrays of water and gas saturation, return rel-
ative permeabilities, capillary pressures and their partial derivatives with
respect to the phase saturations.
2. U pdateCapillaryP ressure - same as above, but only capillary pressures
are updated.
3. SetupRelativeP ermeability - a function to create required relative per-
meability and capillary pressure objects form an input data …le.

44
Miscellaneous
+ const_strip_comments() : int
+ InnerProduct() : double
+ locate() : int
+ Norm2() : double
+ InnerProduct() : double
+ Norm2() : double

Figure 1.11: Member Functions for the miscellaneous Class.

Child classes of this generic class would include classes that implement the
Stone I and Stone II models[30], [31].

1.6.7 Miscellaneous Class


There are various functions that are used in a wide variety of situations. We
collect them all in a M iscellaneous class; the member functions are summarized
in Fig. 1.11. A listing of the C++ code for this class is provided in Appendix
C.

Functionality
1. strip_comments - input to the simulator is provided by a set of input data
…les; in order to facilitate reading and navigation through these …les, we
use commented data …les, such that lines beginning with “c ”or “C ”are
treated as comments and are ignored. This function reads the commented
data …les, removes the comments, and writes only the required data to a
text …le.
2. InnerP roduct - computes the inner product of two vectors of size n.
Pn
xi yi
x; y = i=1
n

3. locate - see description in Table class.

4. N orm2 - computes the L2 norm of a vector of size n.


r Pn
2
i=1 xi
kxk =
n

45
Chapter 2

Implicit Solution using


Newton’s Method

The discrete equations presented in the previous chapter are highly nonlinear, so
any solution method requires that the equations must be linearized. In this sec-
tion we develop the linearized equations for solution using Newton’s method. In
our implementation of the problem solution, we use the error oriented descent
restricted Newton step approach as described by P. Due‡hard[15]. For com-
pleteness, we present Due‡hard’s algorithm in Appendix B. Application of the
algorithm requires that we compute the derivatives of each of the ‡ow equations
with respect to the dependent variables in order to compute the Jacobian ma-
trix. To maximize e¢ ciency, we compute the Jacobian semi-analytically; that is,
we obtain analytical expressions for the required partial derivatives in terms of
derivatives of PVT properties with respect to pressure and relative permeabili-
ties with respect to saturation. In general, the derivatives of the PVT properties
and relative permeabilities cannot be e¢ ciently determined analytically, so we
resort to e¢ cient numerical di¤erentiation to complete the Jacobian.
Following standard procedure, we expand Eqs. 1.75, 1.92 and 1.105 about a
prior estimate of each of the dependent variables in the set

poi+`;j;k ; poi;j+`;k ; poi;j;k+` ; noi+`;j;k ; noi;j+`;k ; noi;j;k+` ;


1
ngi+`;j;k ; ngi;j+`;k ; ngi;j;k+` `= 1

46
using truncated Taylor series[20] expansion to give
1
X n+1; 1
X n+1;
n+1;
@Fmi;j;k
@Fmi;j;k
0 = Fm + poi+`;j;k + poi;j+`;k +
i;j;k
@poi+`;j;k @poi;j+`;k
`= 1 `= 1;`6=0
1
X n+1; 1
X n+1;
@Fmi;j;k
@Fmi;j;k
poi;j;k+` + noi+`;j;k +
@poi;j;k+` @noi+`;j;k
`= 1;`6=0 `= 1
1
X n+1; 1
X n+1;
@Fmi;j;k
@Fmi;j;k
noi;j+`;k + noi;j;k+` +
@noi;j+`;k @noi;j;k+`
`= 1;`6=0 `= 1;`6=0
1
X n+1; 1
X n+1;
@Fmi;j;k
@Fmi;j;k
ngi+`;j;k + ngi;j+`;k +
@ngi+`;j;k @ngi;j+`;k
`= 1 `= 1;`6=0
1
X n+1;
@Fmi;j;k
ngi;j;k+` (2.1)
@ngi;j;k+`
`= 1;`6=0

for m = o; g or w. Here
+1
f f f (2.2)
where f is our last estimate of the variable, for

f 2 poi+`;j;k ; poi;j+`;k ; poi;j;k+` ; noi+`;j;k ; noi;j+`;k ;


1
noi;j;k+` ; ngi+`;j;k ; ngi;j+`;k ; ngi;j;k+` `= 1

If we expand each ‡ow equation at each gridblock about the previous estimate
of the gridblock variables, write the resulting equations in matrix form

Derivatives of Mobilities and Phase Densities


As discussed previously, ‡uid PVT properties depend on both the pressure and
saturation pressure of the in situ mixture. If the local mixture is saturated, i.e.,
po psat , then PVT properties are uniquely dependent on pressure; conversely,
if the local ‡uid is undersaturated, i.e., po > psat ; PVT properties depend both
on pressure and saturation pressure, and since the latter is dependent on local
composition of oil and gas components, undersaturated PVT properties depend
on concentrations of oil and gas. We saw previously that at the saturation point
ng osc
Rs;sat = Rs (pbub ) = : (2.3)
gsc no

From the de…nition of total derivative [9] the following relationships must be
valid:
@Rs;sat @Rs;sat
dRs;sat = dno + dng
@no @ng
dRs;sat
= dpsat (2.4)
dpsat

47
From this we can write
dRs;sat @psat osc Rs;sat
= = : (2.5)
dpsat @ng gsc no ng
or
@psat Rs;sat
= dR
(2.6)
@ng ng dps;sat
sat

and similarly
@psat Rs;sat
= dRs;sat
(2.7)
@no no dpsat

Saturated Systems For saturated systems, kro = kro (Sw ; Sg ) and PVT
properties are uniquely dependent on pressure, so from the de…nitions of Eqs.
1.50 - 1.52, the partial derivatives of phase mobility with respect to our solution
variables are given by

@ o 1 @kro @Sg @kro @Sw kro d o dBo


= + 2 Bo + o (2.8)
@po o Bo @Sg @po @Sw @po ( o Bo )
dpo dpo

@ g 1 dkrg @Sg krg d g dBg


= 2 Bg + g (2.9)
@po g Bg dSg @po dpo dpo
g Bg

@ o 1 @kro @Sg @kro @Sw


= + (2.10)
@no o Bo @Sg @no @Sw @no
@ g 1 dkrg @Sg
= (2.11)
@no g Bg dSg @no

@ o 1 @kro @Sg @kro @Sw


= + (2.12)
@ng o Bo @Sg @ng @Sw @ng
@ g 1 dkrg @Sg
= (2.13)
@ng g Bg dSg @ng

@ w 1 dkrw @Sw krw d w dBw


= 2 Bw + w (2.14)
@po w Bw dSw @po ( w Bw )
dpo dpo
@ w 1 dkrw @Sw
= (2.15)
@no w Bw dSw @no
@ w 1 dkrw @Sw
= (2.16)
@ng w Bw dSw @ng

Note that the above equations suggest that we must determine derivatives of
relative permeability with respect to saturation. This is straightforward for gas
(vapor) and water, since these relative permeabilities are uniquely dependent on
the corresponding phase saturations; thes derivatives can be obtained directly
from the slopes of the relative permeability tables. For the hydrocarbon liquid

48
phase, relative permeability depends on both gas and water saturations, so the
the form of the partial derivatives depends on the model used for three-phase
relative permeability.
From Eqs. 1.36 - 1.39, the partial derivatives of phase saturations with
respect to pressure and oil and gas concentrations are given by the following
expressions.

@So So dBo ng B o drv So rv dRdp + Rs dp


s drv

= +
@po Bo dp (1 R s rv ) gsc dp (1 Rs rv )
dRs drv
S o rv B g Sg B o
So dBo dp dp
= + (2.17)
Bo dp (1 Rs rv ) Bg

@Sg Sg dBg no B g dRs Sg rv dR


dp + Rs dp
s drv

= +
@po Bg dp (1 R s rv ) osc dp (1 Rs rv )
drv dRs
Sg R s B o So B g
Sg dBg dp dp
= + (2.18)
Bg dp (1 Rs rv ) Bo

@Sw @So @Sg


= (2.19)
@po @po @po
@So Bo
= (2.20)
@no (1 R s rv ) osc
@Sg Rs B g
= (2.21)
@no (1 R s rv ) osc
@Sw Rs B g B o
= (2.22)
@no (1 Rs rv ) osc
@So rv B o
= (2.23)
@ng (1 R s rv ) gsc

@Sg Bg
= (2.24)
@ng (1 R s rv ) gsc

@Sw rv B o B g
= (2.25)
@ng (1 Rs rv ) gsc
Finally from Eqs. 1.27 and 1.28,
d L gsc dRs dBo
L
= (2.26)
dpo Bo dpo Bo dpo
d V drv V dBg
= osc (2.27)
dpo Bg dpo Bg dpo

49
Undersaturated Systems Note that for undersaturated systems, PVT prop-
erties are functions of both pressure and saturation pressure (i.e., pressure and
composition), so the total derivative of a arbitrary PVT property, ; is given
by
@ @
d = dp + dpsat : (2.28)
@p psat @psat p
Thus, the partial derivative with respect to oil concentration is
@ @ @psat
= (2.29)
@no p;ng @psat p @no p;ng

@psat @
where @no is given by Eq. 2.7, and @psat is a saturated derivative,
p;ng p
i.e., the derivative of the property at saturated conditions. Similar formulas
apply for the derivative with respect to ng :
For undersaturated systems, Sg = g = 0; kro = kro (Sw ) ; and Eqs. 2.8 -
2.27 assume the following forms
!
@ o 1 dkro @Sw kro @ o @Bo
= 2 Bo + o
@po o Bo dSw @po ( o Bo ) @po p+ @po p+
sat sat
(2.30)
@ o @Bo
where @po + and @po + are derivatives of the properties above the bub-
psat psat
ble point.
@ g
=0 (2.31)
@po
!
@ o 1 @kro @Sw kro @ o @Bo
@psat
= 2 Bo + o
@no o Bo @Sw @no ( o Bo ) @psat
p p @no@psat
(2.32)
@ o @Bo
where @psat and @psat are derivatives of the saturated properties.
p p

@ g
=0 (2.33)
@no
!
@ o 1 @kro @Sw kro @ o @Bo @psat
= 2 Bo + o
@ng o Bo @Sw @ng ( o Bo )
@psat p @psat p @ng
(2.34)
@ g
=0 (2.35)
@ng
From Eqs. 1.36 - 1.39,
@So So @Bo
= (2.36)
@po Bo @p p+
sat

@Sg
=0 (2.37)
@po

50
@Sw @So
= (2.38)
@po @po

!
@So So @Bo @psat
= +
@no Bo @psat p @no

@rv @psat
gsc osc ng @psat @no Bo
p
+
(1 R s rv ) gsc osc

@Rs @psat @rv @psat


So rv @psat @no + Rs @psat @no
p p
(2.39)
(1 R s rv )
@psat
where @no is given by Eq. 2.7.

@Sg
=0 (2.40)
@no
@Sw @So
= (2.41)
@no @no

!
@So So @Bo @psat
=
@ng Bo @psat p @ng

@rv @psat
osc rv + n g @psat @ng Bo
p
+
(1 R s rv ) gsc osc

@Rs @psat @rv @psat


So rv @psat @ng + Rs @psat @ng
p p
(2.42)
(1 R s rv )
@psat
where @ng is given by Eq. 2.6.

@Sg
=0 (2.43)
@ng

@Sw @So
= (2.44)
@ng @ng
Finally from Eqs. 1.27 and 1.28,

d L L @Bo
= (2.45)
dpo Bo @po p+
sat

d V
=0 (2.46)
dpo

51
d L L @Bo @psat gsc @Rs @psat
= + (2.47)
dno Bo @psat p @no Bo @psat p @n0
d V
=0 (2.48)
dno
d L L @Bo @psat gsc @Rs @psat
= + (2.49)
dng Bo @psat p @n g B o @psat p @ng
d V
=0 (2.50)
dng
In Eqs. 2.6 - 2.45, derivatives of the PVT properties with respect to pressure
below the saturation pressure and derivatives of phase relative permeability
with respect to saturation are determined numerically from the slopes of the
tabulated PVT and relative permeability data.
If we are dealing with retrograde condensate gases above the dew point,
equations analogous to Eqs. 2.30 - 2.45 must be derived.

2.1 Evaluation of the Components of the Jaco-


bian Matrix
2.1.1 Oil Equation
Considering Eqs. 1.75 and 1.76 - 1.87, we have
12
X
@Fon+1
i;j;k @zo;`
= (2.51)
@poi 1;j;k
@poi 1;j;k
`=1

In the following, we introduce the following notation


1 if ‡ow is from Dm to Dn
D;P;m;n = (2.52)
0 otherwise
where D indicates the direction of interest, D 2 fx; y; zg or D 2 fr; ; zg, P
indicates the phase of interest, P 2 fo; w; gg and m and n are neighboring
block indices in the direction of interest. For example, for ‡ow of oil (liquid) in
the x-direction from the block centered at (x ; yj ; zk ) to the block centered at
(x +1 ; yj ; zk ) ;
x;o;i;i+1 = 1 (2.53)
and
x;o;i+1;i = 0: (2.54)
The required derivatives are as follows:
0 1
n+1
@zo;2 @ o
= Gx 1 ;j;k @ n+1
o 1 x;o;i 1;i pn+1
o ;j;k pn+1
o 1;j;k
1;j;k
A
@poi 1;j;k 2
2
;j;k @poi 1;j;k

(2.55)

52
Note that ( n+1
o for ‡ow from x 1 to x
n+1
o = 1;j;k
n+1
1 ;j;k
2 o for ‡ow from x to x 1
;j;k

( !
@zo;4 dpn+1
cgo @Sg
= Gx 1 ;j;k rvn+1 n+1
g 1+ 1;j;k 1;j;k

@poi 1;j;k 2 1 ;j;k


2
1 ;j;k
2
dSg 1;j;k
@poi 1;j;k
0 19
n+1
@ g drvn+1 =
x;g;i 1;i pn+1
g ;j;k pn+1
g 1;j;k
@rvn+1 1;j;k
+ n+1
g
1;j;k
A
1;j;k @poi 1;j;k
1;j;k dpoi 1;j;k
;
(2.56)
@zo;`
=0 (2.57)
@poi 1;j;k `6=2;4
12
X
@Fon+1
i;j;k @zo;`
= (2.58)
@poi;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 144gc @poi;j;k
0 n+1
1 1
L g @ n+1
B C o
;j;k C
;j;k+ 1
+ z;o;k;k+1 @pn+1
o ;j;k+1 pn+1
o ;j;k +
2
zk+ 21 A A (2.87)
144gc @poi;j;k

0 0 1
n+1
@zo;10 1 z 1g @ L
k 2
= Gz ;j;k 1
@ n+1o
@1 + ;j;k
A
@poi;j;k 2 ;j;k 1
2
2 144g c @p oi;j;k

0 n+1
1 1
L g @ n+1
B n+1 ;j;k 1 C o ;j;k C
z;o;k;k 1 @po pn+1
o ;j;k 1 +
2
zk 21 A A (2.88)
;j;k 144gc @poi;j;k

@zo;11
=
@poi;j;k
8 0 1
< n+1
dpn+1 @Sg ;j;k
@1 + cgo ;j;k 1 zk+ 12 g @ V ;j;k A
Gz ;j;k+ 1 rvn+1 n+1
g
2 : ;j;k+ 1 ;j;k+ 1 dSg ;j;k @poi;j;k 2 144gc @poi;j;k
2 2
0 n+1
1
V g
B ;j;k+ 1 C
+ z;g;k;k+1 @pn+1
g pn+1
g ;j;k + 2
zk+ 21 A
;j;k+1 144gc
0 19
n+1
@ g drvn+1 =
@rvn+1 ;j;k
+ n+1
g
;j;k
A (2.89)
;j;k @poi;j;k ;j;k dpoi;j;k ;

@zo;12
=
@poi;j;k
8 0 1
< n+1
1g @ V
n+1 z
dp cgo @S g 1 k
Gz ;j;k 1 rvn+1 n+1
g
@1 + ;j;k ;j;k
+ 2 ;j;k
A
2 : ;j;k 1 ;j;k 1 dS g @p o 2 144g c @p o
2 2 ;j;k i;j;k i;j;k

0 n+1
1
V g
B n+1 ;j;k 1
C
z;g;k;k 1 @pg pn+1
g ;j;k 1 +
2
zk 21 A
;j;k 144gc
0 19
n+1
@ g drvn+1 =
@rvn+1 ;j;k
+ n+1
g
;j;k
A (2.90)
;j;k @poi;j;k ;j;k dpoi;j;k ;

Turning to the partial derivatives with respect to no , we have

57
12
X
@Fon+1
i;j;k @zo;`
= (2.91)
@noi 1;j;k
@noi 1;j;k
`=1
where
n+1
@zo;2 @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k
0 n+1
1 1
V g @ n+1
n+1 B n+1 ;j;k 1 C g ;j;k C
z;g;k;k 1 rv @pg pn+1
g ;j;k + 2
zk 21 A A (2.127)
;j;k ;j;k 1
144gc @noi;j;k

Finally, the partial derivatives with respect to ng are given by Eqs. 2.91 -
2.127, provided we replace no by ng ; the sole exception to this rule is Eq. 2.115,
which is replaced by
X12
@Fon+1;
i;j;k @zo;`
= : (2.128)
@ngi;j;k @ngi;j;k
`=1

2.1.2 Gas Equation


The partial derivatives of Fg ;j;k with respect to oil pressures and oil and gas
mass concentrations are presented next.
Considering Eq. 1.92, we have
12
X
@Fgn+1
i;j;k @zg;`
= (2.129)
@poi 1;j;k
@poi 1;j;k
`=1

The required derivatives are as follows:

@zg;2
= Gx 1 ;j;k Rsn+11 ;j;k n+1
o 1
@poi 1;j;k 2 i
2 2
;j;k
0 11
n+1
@ o @Rsn+1
i 1 ;j;k
x;o;i 1;i pn+1
o ;j;k pn+1
o 1;j;k
@Rn+1 1;j;k
+ n+1
o
AA
si 1 ;j;k
@poi 1;j;k
1;j;k @poi 1;j;k

(2.130)

( !
@zg;4 n+1
dpn+1
cgo 1;j;k
@Sg 1;j;k
= Gx 1 ;j;k g 1 1+
@poi 1;j;k 2
2
;j;k dSg 1;j;k
@poi 1;j;k
9
n+1 =
@ g
x;g;i 1;i pn+1
g ;j;k pn+1
g 1;j;k
1;j;k
(2.131)
@poi 1;j;k
;

@zg;`
=0 (2.132)
@poi 1;j;k `6=2;4

12
X
@Fgn+1
i;j;k @zg;`
= (2.133)
@poi;j 1;k
@poi;j 1;k
`=1

62
where

@zg;6
= Gy ;j 1 ;k Rsn+1 1
n+1
o
@poi;j 1;k 2 i ;j 2 ;k 1 ;k
;j
2
0 11
n+1
@ o @Rsn+1
@Rn+1 i ;j 1;k AA
y;o;j 1;j pn+1
o pn+1
o ;j 1;k si ;j 1;k
;j 1;k
+ n+1
o
;j;k @poi;j 1;k
;j 1;k @poi;j 1;k

(2.134)

( !
@zg;8 n+1
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
@zg;10 1 zk 21 g @ L ;j;k
= Gz ;j;k 1
@ Rn+1 1
n+1
o
@1 + A
@poi;j;k 2
s ;j;k i 2 1 2 144gc @poi;j;k
;j;k
2
0 n+1
1
L g
B n+1 ;j;k 1
C
z;o;k;k 1 @po ;j;k pn+1
o ;j;k + 2
zk 21 A
1
144gc
0 11
n+1
@ o @Rsn+1
@Rn+1 ;j;k n+1 i ;j;k AA (2.163)
si ;j;k + o
@poi;j;k ;j;k @poi;j;k

@zg;11
=
@poi;j;k
8 0 1
< n+1
n+1
dpn+1 @Sg ;j;k
@1 + cgo ;j;k 1 zk+ 12 g @ V ;j;k A
Gz ;j;k+ 1 g
2 : ;j;k+ 1
2
dSg ;j;k @poi;j;k 2 144gc @poi;j;k
0 n+1
1 9
V g @ n+1 =
B n+1 ;j;k+ 1 C g
+ z;g;k;k+1 @pg ;j;k+1 pn+1
g ;j;k + 2
zk+ 12 A ;j;k
(2.164)
144gc @poi;j;k ;

67
@zg;12
=
@poi;j;k
8 0 1
< n+1
1g @ V
n+1 z
dp cgo @S g 1 k
Gz ;j;k 1 n+1
g
@1 + ;j;k ;j;k
+ 2 ;j;k
A
2 : ;j;k 1 dSg ;j;k @poi;j;k 2 144gc @poi;j;k
2
0 n+1
1 9
V g @ n+1 =
B n+1 ;j;k 1
C g
z;g;k;k 1 @pg pn+1
g ;j;k 1 +
2
zk 21 A ;j;k
(2.165)
;j;k 144gc @poi;j;k ;

Turning to the partial derivatives with respect to no , we have


12
X
@Fgn+1
i;j;k @zg;`
= (2.166)
@noi 1;j;k
@noi 1;j;k
`=1

where
n+1
@zg;2 @ o
= x;o;i 1;i Gx 1 ;j;k pn+1
o ;j;k pn+1
o 1;j;k Rsn+1
i 1 ;j;k
1;j;k
(2.167)
@noi 1;j;k 2 @noi 1;j;k

(
@zg;4 n+1
dpn+1
cgo 1;j;k
@Sg 1;j;k
= Gx 1 ;j;k g 1
@noi 1;j;k 2
2
;j;k dSg 1;j;k
@noi 1;j;k
9
n+1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;j 1 ;k
2
dSg ;j;k @noi;j;k
1
n+1
@ g
y;g;j;j 1 pn+1
g pn+1
g ;j 1;k
;j;k
A (2.198)
;j;k @noi;j;k

71
@zg;9
=
@noi;j;k
0 n+1
1
L g @ n+1
B n+1 ;j;k+ 1 C n+1 o
z;o;k;k+1 Gz ;j;k+ 1
@po pn+1
o ;j;k + 2
z k+ 21 A Rsi ;j;k
;j;k

2 ;j;k+1 144gc @noi;j;k

(2.199)

@zg;10
=
@noi;j;k
0 n+1
1
L g @ n+1
B n+1 ;j;k 1
C n+1 o
z;o;k;k 1 Gz 1 @po pn+1
o ;j;k + 2
zk 1AR
si ;j;k
;j;k
;j;k
2 ;j;k 1
144gc 2 @noi;j;k

(2.200)

@zg;11 n+1
dpn+1
cgo ;j;k @Sg ;j;k
= Gz ;j;k+ 1 g
@noi;j;k 2 ;j;k+ 1
2
dSg ;j;k @noi;j;k
0 n+1
1 1
V g @ n+1
B n+1 ;j;k+ 1 C g C
+ z;g;k+1;k @pg ;j;k+1 pn+1
g ;j;k +
2
zk+ 21 A ;j;k
A (2.201)
144gc @noi;j;k

@zg;12 n+1
dpn+1
cgo ;j;k @Sg ;j;k
= Gz ;j;k 1 g
@noi;j;k 2 ;j;k 1
2
dSg ;j;k @noi;j;k
0 n+1
1 1
V g @ n+1
B n+1 ;j;k 1
C g C
z;g;k;k 1 @pg pn+1
g ;j;k + 2
zk 1 A
;j;k
A (2.202)
;j;k 1
144gc 2 @noi;j;k

2.1.3 Water Equation


The partial derivatives of Fw ;j;k (see Eq. 1.105) are presented next.

@Fw ;j;k 6
X @zw;`
= (2.203)
@poi 1;j;k
@poi 1;j;k
`=1
where
( !
@zw;2 n+1
dpn+1
cow 1;j;k
@Sw 1;j;k
= Gx 1 ;j;k w 1
@poi 1;j;k 2 1 ;j;k
2
dSw 1;j;k
@poi 1;j;k
9
n+1 =
@ w
x;w;i 1;i pn+1
w ;j;k pn+1
w 1;j;k
1;j;k
(2.204)
@poi 1;j;k
;

72
@zw;`
=0 (2.205)
@poi 1;j;k `6=2

6
X
@Fwn+1
i;j;k @zw;`
= (2.206)
@poi;j 1;k
@poi;j 1;k
`=1

where
( !
@zw;4 n+1
dpn+1
cow ;j 1;k
@Sw ;j 1;k
= Gy ;j 1 ;k w 1
@poi;j 1;k 2 ;j 1 ;k
2
dSw ;j 1;k
@poi;j 1;k
9
n+1 =
@ w
y;w;j 1;j pn+1
w pn+1
w ;j
;j 1;k
(2.207)
;j;k 1;k
@poi;j 1;k
;

@zw;`
=0 (2.208)
@poi;j 1;k `6=4

6
X
@Fwn+1;
i;j;k @zw;`
= (2.209)
@poi;j;k 1
@poi;j;k 1
`=1

where

@zw;6
= Gz ;j;k 1
@poi;j;k 1 2

n+1 !
1 zk 12 g @ w ;j;k 1
n+1
n+1
dpcow ;j;k 1
@Sw ;j;k 1
w 1
;j;k 1
2
dSw ;j;k 1
@poi;j;k
1
2 144gc @poi;j;k 1
0 n+1 1 1
w g @ n+1
w
;j;k 1
z;w;k 1;k
@pn+1
w pn+1
w ;j;k + 2
zk 12 A ;j;k 1
A (2.210)
;j;k 1
144gc @poi;j;k 1

@zw;`
=0 (2.211)
@poi;j;k 1 `6=6

6
X
@Fwn+1
i;j;k @zw;`
= (2.212)
@poi+1;j;k @poi+1;j;k
`=1

where
( !
@zw;1 n+1
dpn+1
cow +1;j;k @Sw +1;j;k
= Gx + 1 ;j;k w 1
@poi+1;j;k 2 + 1 ;j;k
2
dSw +1;j;k @poi+1;j;k
9
n+1 =
@ w
+ x;w;i+1;i pn+1
w +1;j;k pn+1
w ;j;k
+1;j;k
(2.213)
@poi+1;j;k ;

73
@zw;`
=0 (2.214)
@poi+1;j;k `6=1

6
X
@Fwn+1
i;j;k @zw;`
= (2.215)
@poi;j+1;k @poi;j+1;k
`=1

where
( !
@zw;3 n+1
dpn+1
cow ;j+1;k @Sw ;j+1;k
= Gy ;j+ 1 ;k w 1
@poi;j+1;k 2 ;j+ 1 ;k
2
dSw ;j+1;k @poi;j+1;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n+1 =
@ w
+ y;w;j;j+1 pn+1
w pn+1
w ;j;k
;j;k
(2.225)
;j+1;k @poi;j;k ;

( !
@zw;4 n+1
dpn+1
cow ;j;k @Sw ;j;k
= Gy ;j 1 ;k w 1
@poi;j;k 2 ;j 1 ;k
2
dSw ;j;k @poi;j;k
9
n+1 =
@ w
y;w;j;j 1 pn+1
w pn+1
w ;j
;j;k
(2.226)
;j;k 1;k
@poi;j;k ;

n+1 !
@zw;5 dpn+1
n+1 cow ;j;k @Sw ;j;k 1 zk+ 12 g @ w ;j;k
= Gz ;j;k+ 1 1 w
@poi;j;k 2 ;j;k+ 1
2
dSw ;j;k @poi;j;k 2 144gc @poi;j;k
0 n+1 1 1
w 1
g @ n+1
w
;j;k+
+ z;w;k;k+1 @pn+1
w ;j;k+1 pn+1
w ;j;k +
2
zk+ 12 A ;j;k
A (2.227)
144gc @poi;j;k

@zw;6
= Gz ;j;k 1
@poi;j;k 2

n+1 !
n+1
dpn+1
cow ;j;k @Sw ;j;k 1 zk 12 g @ w ;j;k
w 1 +
;j;k 1
2
dSw ;j;k @poi;j;k 2 144gc @poi;j;k
0 n+1 1 1
w 1
g @ n+1
w
;j;k
z;w;k;k 1
@pn+1
w pn+1
w ;j;k 1 +
2
zk 12 A ;j;k
A (2.228)
;j;k 144gc @poi;j;k

75
Turning to the partial derivatives with respect to no , we have
6
X
@Fwn+1
i;j;k @zw;`
= (2.229)
@noi 1;j;k
@noi 1;j;k
`=1

where
(
@zw;2 n+1
dpn+1
cow 1;j;k
@Sw 1;j;k
= Gx 1 ;j;k w
@noi 1;j;k 2 1 ;j;k
2
dSw 1;j;k
@noi 1;j;k
9
n+1 =
@ w
x;w;i 1;i pn+1
w ;j;k pn+1
w 1;j;k
1;j;k
(2.230)
@noi 1;j;k
;

@zw;`
=0 (2.231)
@noi 1;j;k `6=2
6
X
@Fwn+1
i;j;k @zw;`
= (2.232)
@noi;j 1;k
@noi;j 1;k
`=1

where
(
@zw;4 n+1
dpn+1
cow ;j 1;k
@Sw ;j 1;k
= Gy ;j 1 ;k w
@noi;j 1;k 2 ;j 1 ;k
2
dSw ;j 1;k
@noi;j 1;k
9
n+1 =
@ w
y;w;j 1;i pn+1
w pn+1
w ;j
;j 1;k
(2.233)
;j;k 1;k
@noi;j 1;k
;

@zw;`
=0 (2.234)
@noi;j 1;k `6=4

6
X
@Fwn+1;
i;j;k @zw;`
= (2.235)
@noi;j;k 1
@noi;j;k 1
`=1

where
(
@zw;6 n+1
dpn+1
cow ;j;k 1
@Sw ;j;k 1
= Gz ;j;k 1 w
@noi;j;k 1 2 ;j;k 1
2
dSw ;j;k 1
@noi;j;k 1
0 n+1 1 9
w 1
g @ n+1
w =
;j;k
z;w;k 1;k
@pn+1
w pn+1
w ;j;k + 2
zk 1 A ;j;k 1
(2.236)
;j;k 1
144gc 2 @noi;j;k 1
;

@zw;`
=0 (2.237)
@noi;j;k 1 `6=6

76
6
X
@Fwn+1
i;j;k @zw;`
= (2.238)
@noi+1;j;k @noi+1;j;k
`=1

where

@zw;1 n+1
dpn+1
cow +1;j;k @Sw +1;j;k
= Gx + 1 ;j;k w 1
@noi+1;j;k 2 +
2
;j;k dSw +1;j;k @noi+1;j;k
1
n+1
@ w
+ x;w;i+1;i pn+1
w +1;j;k pn+1
w ;j;k
+1;j;k
A (2.239)
@noi+1;j;k

@zw;`
=0 (2.240)
@noi+1;j;k `6=1

6
X
@Fwn+1
i;j;k @zw;`
= (2.241)
@noi;j+1;k @noi;j+1;k
`=1

where

@zw;3 n+1
dpn+1
cow ;j+1;k @Sw ;j+1;k
= Gy ;j+ 1 ;k w
@noi;j+1;k 2 ;j+ 1 ;k
2
dSw ;j+1;k @noi;j+1;k
1
n+1
@ w
+ y;w;j+1;j pn+1
w pn+1
w ;j;k
;j+1;k
A (2.242)
;j+1;k @noi;j+1;k

@zw;`
=0 (2.243)
@noi;j+1;k `6=3
6
X
@Fwn+1;
i;j;k @zw;`
= (2.244)
@noi;j;k+1 @noi;j;k+1
`=1

where

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;j;k
= Gz ;j;k+ 1 w
@noi;j;k 2 ;j;k+ 1
2
dSw ;j;k @noi;j;k
0 n+1 1 1
w g @ n+1
w
;j;k+ 1
+ z;w;k;k+1
@pn+1
w pn+1
w ;j;k +
2
zk+ 12 A ;j;k
A (2.253)
;j;k+1 144gc @noi;j;k

78
@zw;6 n+1
dpn+1
cow ;j;k @Sw ;j;k
= Gz ;j;k 1 w
@noi;j;k 2 ;j;k 1
2
dSw ;j;k @noi;j;k
0 n+1 1 1
w 1
g @ n+1
w
;j;k
z;w;k;k 1
@pn+1
w pn+1
w ;j;k + 2
zk 1 A ;j;k
A (2.254)
;j;k 1
144gc 2 @noi;j;k

Undersaturated Systems
The derivative expressions that we have developed for the oil, water and
gas components in the previous sections implicitly assume that the reservoir
is saturated. For undersaturated reservoirs, some of these derivatives have to
be modi…ed: in particular, above the bubble point, all terms involving gas
transmissibility (or gas saturation) and its derivatives disappear, but new terms
appear because PVT properties are dependent on composition as well as pres-
sure. Derivitaves of phase transmissibilities below and above the bubble point
have been discussed previously. Here we present the derivative terms that must
be modi…ed above the bubble point.

Oil Equation
The only a¤ected terms in the oil equation are zo;9 (Eq. ??), and zo;10 (Eq. ??)
and only the derivatives with respect to oil and gas concentrations are a¤ected.
These are recorded as follows.

@zo;9
=
@noi;j;k+1
00 n+1
1
L g @ n+1
BB n+1 ;j;k+ 1 C o
z;o;k+1;k Gz ;j;k+ 1
@@po ;j;k+1 pn+1
o ;j;k + 2
zk+ 12 A ;j;k+1
+
2 144gc @noi;j;k+1
1
n+1 n+1
o zk+ 21 g @ L ;j;k+1
;j;k+1
A (2.255)
2 144gc @noi;j;k+1

n+1
@ L
;j;k+1
where @noi;j;k+1 is given by Eq. ??.

00 n+1
1
L g @ n+1
@zo;9 BB n+1 ;j;k+ 1 C o
= z;o;k;k+1 Gz ;j;k+ 1
@@po ;j;k+1 pn+1
o ;j;k + 2
z k+ 12 A
;j;k

@noi;j;k 2 144gc @noi;j;k


1
n+1 n+1
o zk+ 21 g @ L ;j;k
+ ;j;k
A (2.256)
2 144gc @noi;j;k

79
@zo;10
=
@noi;j;k 1
00 n+1
1
L g @ n+1
BB n+1 ;j;k 1
C o
z;o;k 1;k Gz 1 @@po ;j;k pn+1
o ;j;k + 2
zk 1 A
;j;k 1
;j;k
2
1
144gc 2 @noi;j;k 1

1
n+1 n+1
o zk 1 g@ L ;j;k
;j;k 1 2 1
A (2.257)
2 144gc @noi;j;k 1

00 n+1
1
L g @ n+1
@zo;10 BB n+1 ;j;k 1
C o
= z;o;k;k 1 Gz 1 @@po pn+1
o ;j;k + 2
zk 1A
;j;k

@noi;j;k ;j;k
2 ;j;k 1
144gc 2 @noi;j;k
1
n+1 n+1
o zk 1 g@ L ;j;k
;j;k 2 A (2.258)
2 144gc @noi;j;k

The derivatives with respect to ng are analogous.

Gas Equation
The a¤ected terms in the gas equation are zg;1 ; (Eq. 1.93), zg;2 ; (Eq. ??),
zg;5 ; (Eq. ??), zg;6 ; (Eq. ??), zg;9 ; (Eq. ??) and zg;10 ; (Eq. ??). The new
equations are as follows.

@zg;1
=
@noi+1;j;k
0
n+1
@ o
x;o;i+1;i Gx pn+1
o +1;j;k pn+1
o ;j;k
@Rsn+1 +1;j;k
+ 1 ;j;k
2
i+1;j;k
@noi+1;j;k
!
n+1
@Rsn+1
i+1;j;k
+ o (2.259)
+1;j;k @noi+1;j;k

0
n+1
@zg;1 @ o
= x;o;i;i+1 Gx pn+1
o +1;j;k pn+1
o ;j;k
@Rsn+1 ;j;k
+ 1 ;j;k
@noi;j;k 2
i;j;k
@noi;j;k
!
n+1
@Rsn+1
i;j;k
+ o (2.260)
;j;k @noi;j;k

80
0
n+1
@zg;2 @ o
= x;o;i 1;i Gx 1 ;j;k pn+1
o ;j;k pn+1
o 1;j;k
@Rsn+1 1;j;k

@noi 1;j;k 2
i 1;j;k
@noi 1;j;k
!
n+1
@Rsn+1
i 1;j;k
+ o (2.261)
1;j;k @noi 1;j;k

0
n+1
@zg;2 @ o
= x;o;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+1 ;j;k+ 1 C o
z;o;k;k+1 Gz ;j;k+ 1
@@po ;j;k+1 pn+1
o ;j;k + 2
zk+ 12 A @Rsn+1 ;j;k

2 144gc i;j;k
@noi;j;k
! 1
n+1
@Rsn+1 Rsn+1
i;j;k
n+1
o zk+ 12 g @ L ;j;k
+ n+1
o
i;j;k
+ ;j;k
A (2.268)
;j;k @noi;j;k 2 144gc @noi;j;k

@zg;10
=
@noi;j;k 1
00 n+1
10
L g @ n+1
BB n+1 ;j;k 1
C @ n+1 o
z;o;k 1;k Gz ;j;k 1 @@po ;j;k pn+1
o ;j;k + 2
zk 1 A Rsi;j;k
;j;k 1

2
1
144gc 2 1
@noi;j;k 1

! 1
n+1
@Rsn+1 Rsn+1 n+1
o zk 1 g@ L ;j;k
+ n+1
o
i;j;k 1 ;j;k 1 ;j;k 1 2 1
A (2.269)
;j;k 1 @noi;j;k 1
2 144gc @noi;j;k 1

@zg;10
=
@noi;j;k
00 n+1
10
L g @ n+1
BB n+1 ;j;k 1
C o
pn+1 1 A @R
2 n+1 ;j;k
z;o;k;k 1 Gz 1 @@poi;j;k oi;j;k + zk si;j;k
;j;k
2
1
144gc 2 @noi;j;k
! 1
n+1
@Rsn+1 Rsn+1 n+1
o zk 1 g@ L ;j;k
+ n+1
o
i;j;k i;j;k ;j;k 2 A (2.270)
i;j;k @noi;j;k 2 144gc @noi;j;k

Derivatives of PVT properties with respect to no are handled as in Eq. ??.


Derivatives with respect to ng are analogous.

82
Water Equation
The terms in the water equation are the same as for saturated systems, pro-
vided we use appropriate de…nitions of the derivatives of the saturation terms
as de…ned previously.

2.2 Modeling of Wells


From the reservoir perspective, we model a well as a set of interconnected pipe
segments that conduct ‡uid between perforated reservoir gridblocks and the ver-
tical well section. Each pipe segment has distinct properties as follows: a length,
internal diameter, roughness, an angle of inclination from the horizontal, and
a midpoint elevation. Some of the pipe segments intersect reservoir gridblocks,
and are perforated to allow reservoir ‡uids to communicate with wellbore ‡uids.
In general, each pipe segment has the ability to exchange ‡uids with neighbor-
ing pipe segments or with exposed reservoir gridblocks. From the reservoir’s
perspective, each well segment that is perforated and allows reservoir/wellbore
communication is a …nite-length arbitrarily-inclined source or sink.
For each gridblock containing a line sink of length L; inclined at an angle
from the downward vertical and an angle ! from the x-axis (see Fig. 2.1), the
gridblock pressure is related to the ‡owing pressure at the “well radius” of the
sink via the Mochizuki [25] extension to Peaceman’s equation [26]; i.e.,
qoi;j;k
= W I ;j;k n+1
oi;j;k pn+1
o pn+1 n+1
well + rvi;j;k
n+1
gi;j;k pn+1
g pn+1
well
Vi;j;k ;j;k ;j;k

(2.271)
qgi;j;k
= W I ;j;k n+1
gi;j;k pn+1
g ;j;k pn+1
well + Rsn+1 n+1
i;j;k oi;j;k
pn+1
o ;j;k pn+1
well
Vi;j;k
(2.272)
and
qwi;j;k
= W I ;j;k n+1
wi;j;k pn+1
w pn+1
well (2.273)
Vi;j;k ;j;k

where

5:615k 0 L0 ( ; !)
W I ;j;k = (2.274)
rb0 ( ; !)
141:2 ln 0 ( ; !)
+s xi yj zk
rw
with p
k 0 = 3 kx ky kz (2.275)
q
2 2 2
L0 ( ; !) = (L0x ) + L0y + (L0z ) (2.276)
r
0 k0
Lx = L sin cos ! (2.277)
kx

83
z

ω
x

Figure 2.1: Schematic of a well segment

84
s
k0
L0y = L sin sin ! (2.278)
ky
r
k0
L0z = L cos (2.279)
kz
q
0
rw ( ; !) = 02 (x) sin2 cos2 ! + r 02 (y) sin2 sin2 ! + r 02 (z) cos2
rw (2.280)
w w
s r !
0 rw k0 k0
rw (x) = + (2.281)
2 ky kz
r r !
0 rw k0 k0
rw (y) = + (2.282)
2 kx kz
s r !
0 rw k0 k0
rw (z) = + (2.283)
2 ky kx
q
rb0 ( ; !) = rb02 (x) sin2 cos2 ! + rb02 (y) sin2 sin2 ! + rb02 (z) cos2 (2.284)
s
0 e k0 k0
rb (x) = yj2 + zk2 (2.285)
4 ky kz
r
0 e k0 k0
rb (y) = x2i + zk2 (2.286)
4 kx kz
s
0 e k0 k0
rb (z) = x2i + yj2 (2.287)
4 kx ky
Here e is Euler’s constant 0:577: In Eq. 2.274, s is the dimensionless skin
factor associated with the given well segment; i.e., for single phase ‡ow of a ‡uid
with viscosity at at rate q bbl/d,

k 0 L0 ( ; !) pskin
s= (2.288)
141:2q
where pskin is the single phase skin pressure drop. Note that in our formulation
a particular reservoir gridblock may contain many di¤erent sources and/or sinks
corresponding to each (inclined, partially penetrating) perforated section along
the well path.

2.3 Computation of Well/Gridblock Mobility Terms


2.3.1 Fluid Injection
In this section, we address the issue of deliberate or accidental injection of ‡uids
from the wellbore to the reservoir. Flowing “well”pressures are not a¤ected by

85
capillary pressure and because of this, it may be possible for one phase to ‡ow
from the well gridblock to the well while there is simultaneous ‡ow of another
phase from the well to the well gridblock. This introduces a question as to how
the phase transmissibility terms ( n+1
mi;j;k ; m = o; g or w) in Eqs. 2.271 - 2.273
should be evaluated. If ‡ow of a phase is from the gridblock to wellbore, the
phase mobilities are evaluated at the gridblock phase saturation. If ‡ow is in the
opposite direction, under the assumption that “upstream weighting” of phase
saturation most accurately describes the ‡ow phenomenon, phase mobilities
should be evaluated at the wellbore (sandface) saturation. The problem is that
sandface saturations are not routinely computed.

Simultaneous Injection of three phases


If the wellbore is injecting three phases into the reservoir, we assume that ‡ow
in the wellbore adjacent to the sandface is completely mixed and homogeneous,
so that the sandface phase saturations are given by
qo;well
So;well = (2.289)
qo;well + qg;well + qw;well
qg;well
Sg;well = (2.290)
qo;well + qg;well + qw;well
qw;well
Sw;well = (2.291)
qo;well + qg;well + qw;well
where qo;well , qg;well and qw;well are the in situ volumetric ‡ow rates of oil
gas and water, respectively, along the pipe segment. In this case, injection
rates and pressures depend mainly on sandface saturations and are only slightly
dependent on saturation conditions in the reservoir gridblock. (Since phase ‡ow
rate depends on phase block pressure, which in turn depends on phase block
saturation, there is still a small dependence of injection phase rate on the block
saturation.) The phase injection rates for this case are given by
qoi;j;k
= W I ;j;k n+1
owell pn+1
o pn+1 n+1
well + rvwell
n+1
gwell pn+1
g pn+1
well
Vi;j;k ;j;k ;j;k

(2.292)
qgi;j;k
= W I ;j;k n+1
gwell pn+1
g pn+1 n+1
well + Rswell
n+1
owell pn+1
o pn+1
well
Vi;j;k ;j;k ;j;k

(2.293)
and
qwi;j;k
= W I ;j;k n+1
wwell pn+1
w pn+1
well (2.294)
Vi;j;k ;j;k

Note that in this case, the transmissibility terms ( n+1


mwell , m = o; g or w) are
evaluated at wellbore conditions. In this case, the resulting partial derivatives
with respect to block pressure are:

86
@ qoi;j;k n+1
= W I ;j;k owell +
@pn+1
o ;j;k Vi;j;k
!)
dpn+1 n+1
cgo ;j;k @Sg ;j;k
rvn+1 n+1
well gwell
1+ (2.295)
dSgn+1 n+1
;j;k @po ;j;k

( !
@ qgi;j;k n+1
dpn+1 n+1
cgo ;j;k @Sg ;j;k
= W I ;j;k gwell 1+ +
@pn+1
o ;j;k Vi;j;k dSgn+1 n+1
;j;k @po ;j;k

Rsn+1
well
n+1
owell (2.296)

and
!
@ qwi;j;k n+1
dpn+1 n+1
cow ;j;k @Sw ;j;k
= WI ;j;k wwell 1 : (2.297)
@pn+1
o ;j;k Vi;j;k n+1
dSw ;j;k @pn+1
o ;j;k

Similarly,

@ qoi;j;k dpn+1 n+1


cgo ;j;k @Sg ;j;k
= W I ;j;k rvn+1 n+1
gwell (2.298)
@nn+1
o ;j;k Vi;j;k well
dSgn+1 n+1
;j;k @no ;j;k

@ qgi;j;k n+1
dpn+1 n+1
cgo ;j;k @Sg ;j;k
= W I ;j;k gwell (2.299)
@nn+1
o ;j;k Vi;j;k dSgn+1 n+1
;j;k @no ;j;k

and
@ qwi;j;k n+1
dpn+1 n+1
cow ;j;k @Sw ;j;k
= W I ;j;k wwell : (2.300)
@nn+1
o ;j;k Vi;j;k n+1
dSw n+1
;j;k @no ;j;k

Finally,

@ qoi;j;k dpn+1 n+1


cgo ;j;k @Sg ;j;k
= W I ;j;k rvn+1 n+1
gwell (2.301)
@nn+1
g ;j;k Vi;j;k well
dSgn+1 n+1
;j;k @ng ;j;k

@ qgi;j;k n+1
dpn+1 n+1
cgo ;j;k @Sg ;j;k
= W I ;j;k gwell (2.302)
@nn+1
g ;j;k Vi;j;k dSgn+1 n+1
;j;k @ng ;j;k

and
@ qwi;j;k n+1
dpn+1 n+1
cow ;j;k @Sw ;j;k
= W I ;j;k wwell : (2.303)
@nn+1
g ;j;k Vi;j;k n+1
dSw n+1
;j;k @ng ;j;k

87
Injection of a Single Phase
If a single phase (e.g., water or gas) is being injected into the reservoir, the
saturation of that phase at the sandface is assumed to be 1, and the phase
transmissibility terms are evaluated at the endpoint saturation. The transmis-
sibilities of the other phases at the sandface are set to zero and the expressions
derived above are valid.

Fluid Production
For ‡uid production from a gridblock, the transmissibility terms are dependent
on the gridblock variables, so the derivatives of the sink terms must re‡ect this
dependence. The derivatives of the sink (production) terms with respect to the
gridblock variables are as follows.

@ qoi;j;k n
n+1
= W I ;j;k oi;j;k +
@pn+1
o ;j;k Vi;j;k
n+1
@ oi;j;k
+ pn+1
o pn+1
well n+1
;j;k @po ;j;k
!
dpn+1 n+1
cgo ;j;k @Sg ;j;k
rvn+1 n+1
i;j;k gi;j;k
1+ +
dSgn+1 n+1
;j;k @po ;j;k
!)
n+1
@gi;j;k drvn+1
pn+1
g pn+1
well rvn+1 n+1 + n+1
gi;j;k
i;j;k
(2.304)
;j;k i;j;k
@po ;j;k dpn+1
o ;j;k

(
n+1
@ qoi;j;k @ oi;j;k
= W I ;j;k pn+1
o pn+1
well +
@nn+1
o ;j;k Vi;j;k ;j;k @nn+1
o ;j;k

dpn+1 n+1
cgo ;j;k @Sg ;j;k
rvn+1 n+1
gi;j;k +
i;j;k
dSgn+1 n+1
;j;k @no ;j;k
)
n+1
@ gi;j;k
pn+1
g ;j;k pn+1
well rvn+1 (2.305)
i;j;k
@nn+1
o ;j;k

(
n+1
@ qoi;j;k @ oi;j;k
= W I ;j;k pn+1
o pn+1
well +
@nn+1
g ;j;k Vi;j;k ;j;k n+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ow ;j;k @Sw ;j;k
= W I ;j;k wi;j;k +
@nn+1
o ;j;k Vi;j;k n+1
dSw n+1
;j;k @no ;j;k
)
n+1
@ wi;j;k
pn+1
w ;j;k pn+1
well (2.311)
@nn+1
o ;j;k

89
(
@ qwi;j;k n+1
dpn+1 n+1
cow ;j;k @Sw ;j;k
= W I ;j;k wi;j;k +
@nn+1
g ;j;k Vi;j;k n+1
dSw n+1
;j;k @ng ;j;k
)
n+1
@ wi;j;k
pn+1
w pn+1
well (2.312)
;j;k @nn+1
g ;j;k

Mixed Production/Injection
In some cases it may be possible that one of the phases is injecting into the
reservoir while the other two are producing. For these cases we use a combina-
tion of the expressions that we derived before: for the phase that is injecting, we
evaluate transmissibility at the wellbore for the phase in question using the well-
bore saturation of that phase and using the expressions for partial derivatives
for injection of that phase. Computation of wellbore phase saturations in this
case is still an unresolved issue. For the producing phases, we compute trans-
missibilities at the gridblock and use the derivative expressions for a producing
well.

2.3.2 Application of Speci…ed Production Conditions


In this section we discuss application of speci…ed wellbore conditions at the
sink/source points in the reservoir. We have two cases to consider: production
at a speci…ed well pressure and production a speci…ed rate. In the latter case, a
single phase rate, a total mass rate or a total volumetric rate can be speci…ed.
Suppose we specify a rate qs at the well gridblock, where

qs = qoi;j;k + qgi;j;k + qwi;j;k (2.313)

where ; ; and are constants, and qoi;j;k ; qgi;j;k ; and qwi;j;k are given by Eqs.
2.271 (or 2.292), 2.272 (or 2.293) and 2.273 (or 2.294) respectively. Thus, for
example, if qs is a total mass rate, then

= o;sc ; = g;sc ; = w;sc ;

while if it is an oil rate,


= 1; = = 0:
De…ne

= + Rsn+1
i;j;k
n+1
oi;j;k + rvn+1
i;j;k
+ n+1
gi;j;k + n+1
wi;j;k ; (2.314)

= pn+1
cgo ;j;k
n+1
gi;j;k rvn+1
i;j;k
+ pn+1
cow ;j;k
n+1
wi;j;k (2.315)

(Note that if a particular phase in injecting instead of producing, the transmis-


sibility term for that phase would be evaluated at the wellbore.)

90
We can combine our rate expressions (i.e., Eqs. 2.271 (or 2.292), 2.272 (or
2.293) and 2.273 (or 2.294)) to obtain an expression for the ‡owing well pressure
associated with this rate as
qs
Vi;j;k W I + pn+1
o +
pn+1
;j;k ;j;k
well = : (2.316)

Each individual phase rate can be determined by using Eq. 2.316 in the appro-
priate phase rate expression. Of course, if the wellbore pressure is speci…ed, the
phase rates can be determined directly by inserting the speci…ed pressure into
the rate equations.
For completeness, we summarize simpli…cations to the expressions for some
of the most common producing conditions.

Oil Rate Speci…ed


If the oil rate is speci…ed, then in Eq. 2.313,

= 1; = = 0: (2.317)

and,

@ qoi;j;k @ qoi;j;k @ qoi;j;k


= = =0 (2.318)
@pn+1
o ;j;k Vi;j;k @non+1
;j;k
Vi;j;k @nn+1
g ;j;k Vi;j;k

Gas Rate Speci…ed


If the gas rate is speci…ed, then in Eq. 2.313

= 1; = = 0: (2.319)

and,

@ qgi;j;k @ qgi;j;k @ qgi;j;k


= = =0 (2.320)
@pn+1
o ;j;k Vi;j;k @non+1
;j;k
Vi;j;k @nn+1
g ;j;k Vi;j;k

Water Rate Speci…ed


If the water rate is speci…ed, then in Eq. 2.313

= 1; = = 0: (2.321)

and,

@ qwi;j;k @ qwi;j;k @ qwi;j;k


= = =0 (2.322)
@pn+1
o ;j;k Vi;j;k @non+1
;j;k
Vi;j;k @nn+1
g ;j;k Vi;j;k

In all other cases, the complete expressions for the partial derivatives must
be used.

91
2.4 Boundary Conditions
In order to compute solutions to the ‡ow problem, we must specify conditions at
the reservoir boundaries. For the Cartesian coordinate system, these boundaries
are at x = 0, x = Lx , y = 0, y = Ly , z = 0 (i.e., the bottom of the reservoir)
and z = Lz : For the …nite di¤erence grid that we speci…ed in Eqs. 1.56 - 1.58,
we must specify conditions for gridblocks that have faces that fall on one or
more of these boundaries. This is easy to do if the faces are sealed (i.e., no-‡ow
boundaries), but requires considerably more work if there is any ‡ow across the
boundary, i.e., at speci…ed rate or pressure. Note that the following discussion
is applicable to each block on the reservoir boundary; since a boundary is made
up of many blocks, it is possible to have a reservoir boundary that is partially
sealed, partially at constant pressure and partially at speci…ed rate all at the
same time.

2.4.1 Sealed Boundary Block


Suppose we have a closed boundary at x = 0 for the block centered at (xi ; yj ; zk )
for i = 0; we can easily impose the no ‡ow condition by setting
n+1 n+1 n+1
o 1 = g 1 = w 1 = 0 for i = 0 (2.323)
;j;k ;j;k ;j;k
2 2 2

in Eqs. 1.75, 1.92 and 1.105 and in all their associated derivatives. This ensures
that pressures on the sealed reservoir boundary do not enter into the ‡ow equa-
tion. Note that this technique is general, and can be applied anywhere in the
reservoir, for example to simulate a sealing fault. Applying no-‡ow conditions
along the remaining reservoir boundaries is accomplished in the same manner.

2.4.2 Speci…ed Rate or Pressure Boundary


Suppose we have a speci…ed rate qs at the boundary x = 0 for the block centered
at (x0 ; yj ; zk ); here
qs = qo0;j;k + qg0;j;k + qw0;j;k (2.324)
and speci…cation of the constants ; and determine the type of rate speci…-
cation. (Note that the phase rates in Eq. 2.324 are scf/day.) Thus, for example
if a water rate were speci…ed,

= = 0; and = 1:

92
From Darcy’s law, the speci…ed rate at the boundary is expressed in discrete
form as

qs = Gx 1 ;j;k V0;j;k n+1


o pn+1
o0;j;k pn+1
1
;j;k
+
2 1 ;j;k 2
2

rvn+1 n+1
g pn+1
g0;j;k pn+1
1
;j;k
+
1 ;j;k 1 ;j;k 2
2 2

Rsn+1 n+1
o pn+1
o0;j;k pn+1
1
;j;k
+
1 ;j;k 1 ;j;k 2
2 2

n+1
g pn+1
g0;j;k pn+1
1
;j;k
+
1 ;j;k 2
2

n+1
w 1 pn+1
w0;j;k pn+1
1
;j;k
(2.325)
;j;k 2
2

Here pn+1
1 denotes the pressure at the boundary x = 0 - (note that capillary
2 ;j;k
pressure does not a¤ect the boundary pressure) - and we have approximated
the derivative of pressure at the boundary as

@p p0 p 1
2
(2.326)
dx x=0 x0 x 1
2

where p0 is the pressure at the gridblock center, p 12 is the pressure at the


boundary, x0 is the location of the gridblock center and x 12 = 0: With this
approximation,
C1 kx0;j;k
Gx 1 ;j;k = : (2.327)
2 x 12 x 21 x0 x 21
Note that the absolute permeability that appears in the above equation is the
gridblock permeability; i.e., there is no neighbor gridblock for permeability av-
eraging. In Eq. 2.325, transmissibilities (e.g., n+1o ) are computed based
1 ;j;k
2
on upstream weighting; for ‡ow from the block to the boundary, transmissi-
bility is computed based on gridblock saturations and pressures; for ‡ow into
the gridblock, transmissibilities are computed based on boundary pressures and
saturations; i.e., if we are injecting ‡uid at the boundary, we must specify (or
have a method of computing) boundary saturations.

93
Equation 2.325 can be rearranged to solve for the boundary pressure as

pn+1
1
;j;k
=
2

+ rvn+11 n+1
g
1 ;j;k
+ + Rsn+11 n+1
o
1 ;j;k
+ n+1
w
1 ;j;k
;j;k ;j;k
2 2 2 2 2

+ rvn+1 n+1
g pn+1
g0;j;k +
1 ;j;k 1 ;j;k
2 2

+ Rsn+1 n+1
o pn+1
o0;j;k +
1 ;j;k 1 ;j;k
2 2
)
n+1 qs
w 1 pn+1
w0;j;k + (2.328)
2
;j;k Gx 1 ;j;k V0;j;k
2

This expression is substituted into the ‡ow equations (Eqs. 1.76 - 1.112) for
the blocks adjacent to the speci…ed rate boundary to obtain ‡ow equations that
include boundary ‡ow. For example, for our problem, Eq. 1.77 would assume
the form
n+1
zo;2 = Gx 1 ;j;k o 1 pn+1
o ;j;k
2 ;j;k
2

+ rvn+11 n+1
g 1 + + Rsn+11 n+1
o 1 + n+1
w 1
;j;k ;j;k ;j;k ;j;k ;j;k
2 2 2 2 2

+ rvn+1 n+1
g 1 pn+1
g0;j;k +
1 ;j;k ;j;k
2 2

+ Rsn+1 n+1
o 1 pn+1
o0;j;k +
1 ;j;k ;j;k
2 2
)!
n+1 qs
w 1 pn+1
w0;j;k + (2.329)
2
;j;k Gx 1 ;j;k V0;j;k
2

Derivatives of this equation with respect to the reservoir gridblock variables


can be obtained in the normal way. Although this process is tedious, the re-
sulting expressions do not a¤ect the overall structure of the Jacobian matrix -
only the magnitudes of the individual Jacobian entries. Thus, the discussion
on matrix ordering and structure in the next section is valid whether or not we
consider ‡ow across boundaries.
Note that if the boundary pressure is speci…ed, the problem becomes simpler
since we only have to substitute the known boundary pressure in the ‡ow equa-
tions for blocks adjacent to the boundary. Thus, for example, for our problem,
Eq. 1.77 would assume the form
n+1
zo;2 = Gx 1 ;j;k o 1 pn+1
o ;j;k pspecif ied : (2.330)
2 ;j;k
2

94
Note that treatment of conditions at other reservoir boundaries is analogous.
Finally, although we do not speci…cally address cylindrical coordinates in
this section, the preceding method is the most accurate way for prescribing ‡ow
across the boundary at the wellbore radius.

2.5 Matrix Ordering and Structure


In this section, we focus on determining the matrix structure for ‡ow in an
arbitrary Cartesian reservoir. The structure for cylindrical reservoirs is almost
the same, however, modi…cations must be made in the direction since the
left boundary of the …rst gridblock in this direction is identical to the right
boundary of the last gridblock, (assuming that the reservoir is a complete circle
in the horizontal plane). These modi…cations are left as an exercise for the
reader.
Our unknowns for the ‡ow problem at any time level are the set of pressures,
oil and gas mass concentrations at each gridblock. We order our unknowns as
n ony 1 nz 1
nx 1
poi;j;k ; noi;j;k ; ngi;j;k i=0
:
j=0 k=0

and the gridblocks are ordered from 0 to (nx ny nz ) 1, …rst in the x-direction,
then in the y-direction and …nally in the z-direction. Thus, the index I of the
gridblock at location (xi ; yj ; zk ) is given by

I = i + nx (j + kny ) (2.331)

Similarly, a vector of unknowns dimensioned 3 nx ny nz will have oil


pressure, oil mass concentration and gas mass concentration at each reservoir
gridblock. For the gridblock at location (xi ; yj ; zk ) the index Iu of an element
in this vector, given by

Iu = l + 3 (i + nx (j + kny ))
= l + 3I (2.332)

points to a gridblock variable for that block such that l = 0 corresponds to


poi;j;k ; l = 1 corresponds to noi;j;k ; and l = 2 corresponds to ngi;j;k :
The matrix associated with the ‡ow problem, see Eq. 2.1, will have 3 nx
ny nz rows and columns. If we denote this matrix by A, using our ordering
system, the matrix entry A (m; n), i.e., the element in the mth row and nth
column of A, will correspond to the coe¢ cient of unknown lr in gridblock Ir for
the ‡ow equation of component lc in gridblock Ic where
m
Ir = (2.333)
3
lr = m modulo 3 (2.334)
n
Ic = (2.335)
3

95
lc = n modulo 3 (2.336)
In Eqs. 2.333 and 2.335, the result of the division is truncated to an integer
(without rounding), and the operation a modulo b is the remainder resulting
from the division. Here 8
< 0 = poi;j;k
lr = 1 = noi;j;k (2.337)
:
2 = ngi;j;k
and 8
< 0 Oil Flow
lc = 1 Gas Flow (2.338)
:
2 Water Flow

2.5.1 Number of Non-zeros


The matrix associated with the ‡ow problem, Eq. 2.1, is sparse. Here we
describe the positions of the nonzero entries in the matrix.
In general, a given interior reservoir gridblock (with index (i; j; k)) will have
6 gridblock neighbors, and the ‡ow equation for the gridblock will have a max-
imum of 21 nonzero entries. For 0 < i < nx 1; 0 < j < ny 1; 0 < k < nz 1,
the column locations in row, r,

r = l + 3 (i + nx (j + kny )) (2.339)

of the nonzero matrix elements are:


2 2
f`c + 3 ((i 1) + nx (j + kny ))g`c =0 , f`c + 3 (i + nx ((j 1) + kny ))g`c =0 ,
2 2
f`c + 3 (i + nx (j + (k 1) ny ))g`c =0 , f`c + 3 (i + nx (j + kny ))g`c =0 ,
2 2
f`c + 3 (i + nx (j + (k + 1) ny ))g`c =0 , f`c + 3 (i + nx ((j + 1) + kny ))g`c =0
2
and f`c + 3 ((i + 1) + nx (j + kny ))g`c =0 :
Thus, the total number of nonzero coe¢ cients for this type of gridblock is
given by
N1 = 21 (nx 2) (ny 2) (nz 2) : (2.340)
In all other cases, a given gridblock will have less than 6 neighbors; if in com-
puting the above column locations, any of the terms (i 1) ; (j 1) and (k 1)
become negative, the column index is eliminated, and the number of nonze-
roes for the row is reduced by 3 for each column index eliminated. Similarly,
if in computing the above column locations, any of the terms (i + 1) > nx 1;
(j + 1) > ny 1 and/or (k + 1) > nz 1; the column index is eliminated, and
the number of nonzeroes for the row is reduced by 3 for each column index
eliminated.
Although the matrix is not symmetric in general, the nonzero entries are
symmetrically located relative to the main diagonal. The matrix is stored in
compressed column format (standard for Matlab[1] and UMFPACK[12], [13])
using 3 vectors as follows:

96
An integer vector Ap dimensioned 3 nx ny nz + 1 such that Ap[0]
i 1
X
= 0; Ap[i] = number of nonzero coe¢ cients in column l; Ap[3 nx
l=0
ny nz ] = total number of nonzero coe¢ cients in the matrix nnz :
An integer vector Ai dimensioned nnz containing the row index of each
successive nonzero entry in the successive columns of the matrix.
A real vector Ax dimensioned nnz containing the values of each nonzero
coe¢ cient in the successive columns of the matrix.

For example, with nx = 3; ny = 2; nz = 1; the matrix would contain 18


rows, and the structure would be as follows:
2 3
0 0 0 0 0 0 0 0 0
6 0 0 0 0 0 0 0 0 0 7
6 7
6 0 0 0 0 0 0 0 0 0 7
6 7
6 0 0 0 0 0 0 7
6 7
6 0 0 0 0 0 0 7
6 7
6 0 0 0 0 0 0 7
6 7
6 0 0 0 0 0 0 0 0 0 7
6 7
6 0 0 0 0 0 0 0 0 0 7
6 7
6 0 0 0 0 0 0 0 0 0 7
6 7
6 0 0 0 0 0 0 0 0 0 7
6 7
6 0 0 0 0 0 0 0 0 0 7
6 7
6 0 0 0 0 0 0 0 0 0 7
6 7
6 0 0 0 0 0 0 7
6 7
6 0 0 0 0 0 0 7
6 7
6 0 0 0 0 0 0 7
6 7
6 0 0 0 0 0 0 0 0 0 7
6 7
4 0 0 0 0 0 0 0 0 0 5
0 0 0 0 0 0 0 0 0
For this matrix,

Ap = 0 9 18 27 39 51 63 72 81 90 99
108 117 129 141 153 162 171 180 (2.341)
The …rst 19 entries of Ai (dimensioned 180) are
0 1 2 3 4 5 9 10 11 0 1 2 3 4 5 9 10 11 0
(2.342)
and the …rst 10 entries of Ax (dimensioned 180) are
A0;0 A1;0 A2;0 A3;0 A4;0 A5;0 A9;0 A10;0 A11;0 A0;1 (2.343)
where the …rst subscript index refers to the row of the entry, and the second
refers to the column.
We use UMFPACK[13] and GotoBLAS[18] to solve the matrix problem.

97
2.6 Saturation and Pressure Initialization
There are several options for initializing the simulator: We can initialize from
given average conditions; we can read in initial depths to gas-oil and water-oil
contacts or we can read in gridblock data from a previous run.

2.6.1 Initialization from Average Data


We assume that we are given initial stock-tank barrels of oil, No STB; and scf
of gas in the reservoir, Gt , along with average reservoir (oil) pressure and initial
saturation pressure. We compute PVT properties at the average pressure, and
compute average saturations of oil and gas from
5:615No Boi
So = (2.344)
PV
(Gt No Rsi ) Bgi
Sg = (2.345)
PV
and average water saturation from

Sw = 1 So Sg (2.346)

Here, P V is the total reservoir pore volume in cubic feet. We initialize all
gridblocks to the average values then run the simulator with no sources or sinks
until all intergridblock ‡ow ceases. The …nal result from this run represents
the initial saturation/pressure distribution in the reservoir. This condition can
be saved by writing all gridblock variables to a …le which can be re-opened
and used as an initial condition for all future simulation runs. Alternatively,
the initial average saturations of oil and gas can be speci…ed, (along with the
average pressure) and the initialization run could be made as before.

2.6.2 Initialization from Gridblock Data


If we have a …le containing the values of all gridblock variables (e.g., from a
previous simulator run), this data can be read in to the simulator and used as
initial data for the current run. This method is used to restart the simulator
from a previous run.

2.6.3 Initialization from GOC and WOC Data


As a …nal possibility we can read in depths to the Gas-oil contact (GOC) and
water-oil contacts (WOC) along with oil pressure at a reference depth. For reser-
voir gridblocks above the GOC, the saturation of water is set to the connate
water saturation and gas saturation is set to 1 minus the connate water satura-
tion. At depths below the WOC, water saturation is set to 1. At depths between
the GOC and WOC, water saturation is set to residual water saturation and oil
saturation is set to one minus this value. If the GOC or WOC do not fall exactly

98
UMFSparseMatrix
- Ai : IFLEXARRAY
- Ap : IFLEXARRAY
- Ax : DFLEXARRAY
- Control[UMFPACK_CONTROL] : double
- Info[UMFPACK_INFO] : double
- Numeric : void* = NULL
- Symbolic : void* = NULL
- W : DFLEXARRAY
- Wi : IFLEXARRAY
# n : int = 0
# nnz : int = 0
+ ScaleColumns() : void
+ <<Virtual>> Solve() : int
+ <<Virtual>> SolveMultiple() : int
+ <<Virtual>> SolveTranspose() : int
+ <<Virtual>> SolveTransposeMultiple() : int
+ zeroElements() : void
+ <<Virtual>> operator ()() : double&

Figure 2.2: Members and Functionality of the Sparse Matrix class.

on a gridblock boundary, the phase saturations in the gridblock are computed as


the volumetric average of the phase saturations in the gridblock. Pressures are
computed in the vertical direction by starting at the reference depth and tra-
versing the reservoir in the vertical direction using the density of the continuous
phase in each gridblock to adjust the pressure to ensure hydrostatic equilibrium.
Note that this method does not honor capillary pressure equilibrium, however,
it is a good approximation for starting the simulator without doing a lengthy
initialization run with no sources and sinks.

2.7 Simulator Objects


Here we describe the classes that comprise the simulator; we give a brief de-
scription of the main members and their functionality.

2.7.1 UMFSparseMatrix Class


This class o¤ers functionality for building, …lling and solving a sparse matrix
linear algebra problem using UMFPACK[14], [13]. An overview of the class
members and functionality is shown in Fig. 2.2; see also the previous section on
“Matrix Ordering and Structure”.

Members
1. n (int) - number of rows in the matrix.

99
2. nnz (int) - number of non-zero elements in the matrix.
3. Ai (IFLEXARRAY) - Array (dimensioned nnz) containing row indices for
each non-zero entry.
4. Ap (IFLEXARRAY) - Array (dimensioned n + 1) containing the indices
of the …rst non-zero entry in each column.
5. Ax (DFLEXARRAY) - Array (dimensioned nnz) containing the non-zero
entries in the sparse matrix.
6. W (DFLEXARRAY) - Work array (dimensioned 6 n)
7. W i (IFLEXARRAY) - Work array (dimensioned n)
8. Symbolic (void *) - Used by UMFPACK.
9. N umeric (void *) - Used by UMFPACK.
10. Control, Inf o - UMFPACK arrays; see Ref. [14].

Functionality
1. operator()() - provides the functionality of being able to assign values to
the elements of the sparse matrix using statements similar to A(i; j) = x;
results in an error condition if the element is not a pre-designated non-zero
element.
2. Solve, SolveM ultiple, SolveT ranspose, SolveT ransposeM ultiple - front
ends for the UMFPACK solution routines.

2.7.2 RelativePermCapPressData Structure


This is a structure (i.e., class with public members) containing arrays of rel-
ative permeabilities, capillary pressures and their derivatives at each reservoir
gridblock. An overview of the structure is shown in Fig. 2.3. The names of the
members describe their contents.

2.7.3 FlowEquationBuilder Class


As the name suggests, this class is responsible for building the Jacobian ma-
trix for the particular system under study. A summary of the members and
functionality is shown in Fig. 2.4.

Members
1. nBlocks (int) - number of reservoir gridblocks.
2. nEquations (int) - number of ‡ow equations (3 * nBlocks).
3. F (PVTProperties *) - provides PVT properties and derivatives.

100
RelativePermCapPressData
+ dKrgdSg : DFLEXARRAY
+ dKrgodSg : D2FLEXARRAY
+ dKrodSg : DFLEXARRAY
+ dKrodSw: DFLEXARRAY
+ dKrwdSw: DFLEXARRAY
+ dKrwodSw: D2FLEXARRAY
+ dPcgodSg : D2FLEXARRAY
+ dPcowdSw: D2FLEXARRAY
+ Krg : DFLEXARRAY
+ Krgo : D2FLEXARRAY
+ Kro : DFLEXARRAY
+ Krw: DFLEXARRAY
+ Krwo : D2FLEXARRAY
+ nData : int
+ Pcgo : D2FLEXARRAY
+ Pcow: D2FLEXARRAY

Figure 2.3: Members of the Relative Permeability/Capillary Pressure Structure.

FlowEquationBuilder
# F : PVTProperties* = NULL
# g : FiniteDifferenceGrid*
# M: UMFSparseMatrix
# nBlocks : int
# nEquations : int = 0
# PVTProps : D2FLEXARRAY
# PVTSlopes : D2FLEXARRAY
# R : ThreePhaseRelativePermeabilityCapPress*
# RHS : DFLEXARRAY
# RPD : RelativePermCapPressData*
# Solution : DFLEXARRAY
# Tg : D2FLEXARRAY
# To : D2FLEXARRAY
# Tw: D2FLEXARRAY
# WaterProps : D2FLEXARRAY
# WaterSlopes : D2FLEXARRAY
+ ScaleJacobianMatrix() : void
+ SolveFlowEquations() : bool
+ UpdateFlowEquations() : bool
+ UpdateResidualEquations() : bool

Figure 2.4: Members and Functionality of the Flow Equation Builder Class

101
4. g (FiniteDi¤erenceGrid *) - provides geometric information, di¤erence op-
erators, block volumes, porosities, permeabilities, etc.
5. M (UMFSparseMatrix) - storage and solution methods for the sparse Ja-
cobian matrix.

6. P V T P rops, W aterP rops (D2FLEXARRAY) - 2-D arrays containing PVT


properties at all reservoir gridblocks.
7. P V T Slopes, W aterSlopes (D2FLEXARRAY) - 2-D arrays containing
slopes of PVT properties at all reservoir gridblocks.
8. R (ThreePhaseRelativePermeabilityCapPress *) - provides relative per-
meability and capillary pressure data and derivatives.
9. RP D (RelativePermCapPressData *) - relative permeability and capillary
pressure data and derivatives for all reservoir gridblocks.
10. T o, T g, T w (D2FLEXARRAY) - arrays dimensioned (2, 4) containing
phase transmissibilities (see Eqs. 1.50 - 1.52) and derivatives of phase
transmissibilities with respect to oil pressure, oil concentration and gas
concentration at the “left” and “right” block faces.
11. RHS (DFLEXARRAY) - array (dimensioned nEquations) of residuals of
the ‡ow equations.
12. Solution (DFLEXARRAY) - array (dimensioned nEquations) of Newton
corrections obtained by solving the Jacobian matrix problem.

Functionality
1. U pdateResidualEquations - computes the residual of the ‡ow equation
at the current solution guess; (see Eqs. 1.75, 1.92 and 1.105).
2. U pdateF lowEquations - computes the Jacobian matrix at the current
solution guess.
3. SolveF lowEquations - applies Newton iteration to solve the ‡ow problem
at the current timestep.

2.7.4 Simulator Class


The simulator class orchestrates the interaction between the various objects
that make up the reservoir simulator; its main members and functionality are
summarized in Fig. 2.5. Since all of the members have been described before,
we will not repeat their description here. Instead, we describe its functionality.

102
Simulator
# FEB : FlowEquationBuilder* = NULL
# Fluid : PVTProperties*
# GBVNewIteration : GridblockVariables* = NULL
# GBVOldIteration : GridblockVariables* = NULL
# GBVOldTstep : GridblockVariables* = NULL
# Grid : FiniteDifferenceGrid* = NULL
- h2oProps : DFLEXARRAY
- pvtProps : DFLEXARRAY
# RelPerm : ThreePhaseRelativePermeabilityCapPress* = NULL
+ DumpRestartData() : void
+ OutputResults() : void
+ RunSimulation() : void
+ SolveFlowProblem() : bool
+ UpdateGridblockVariables() : void
# Initialize() : void
# InitializeFromFluidContactData() : void
# ReadInitializiationData() : void

Figure 2.5: Members and Functionality of the Simulator class.

Functionality
1. Initialize - sets all gridblocks to initial values either using average data,
data from a previous run (ReadInitializationData), or gas-oil and water-
oil contact data (InitializeF ormF luidContactdata).
2. RunSimulation - sets the timestep and calls SolveF lowP roblem; respon-
sible for checking convergence, adjusting timesteps and outputting results.
3. SolveF lowP roblem - interacts with the F lowEquationBuilder object to
solve the problem using Newton’s method.
4. OutputResults - writes results from the timestep to a …le.
5. DumpRestartData - writes variables at all gridblocks to a …le that can
be later read in to initialize the simulator.

2.8 Overview of a Simulator Run


The ‡ow of a typical simulator run is as follows:
1. Read PVT data and create a PVTProperties object.
2. Read relative permeability and capillary pressure data and create a Three-
PhaseRelativePermeabilityCapPress object.

103
3. Read simulator data and create all simulator objects - i.e., the FiniteDif-
ferenceGrid object, the FlowEquationBuilder object, etc.
4. Initialize all gridblock variables; set the old time value to 0.
5. Set the initial timestep.

6. Set the current time value to the old time plus the current time step. If
the current time is greater than the required simulation time, stop.
7. Try to solve the ‡ow problem at the current timestep. If this fails, cut the
timestep to 70% of its original value and try again. Stop the simulation
if we make more than 5 consecutive timestep cuts, or if the timestep falls
below a threshold value.
8. If the solution is successful, output the results and update the values of
the gridblock variables at the old timestep to their current values. Update
the old time to the current time.
9. Set the new time step. (For simplicity we can use a geometric sequence of
timesteps, i.e.,
tn+1 = tn+1
where > 1:) Go to step 6.

104
Chapter 3

The Well Model

3.1 Introduction
Up to this point we have treated the well as a set of sources or sinks in the
reservoir simulator gridblocks without regard to ‡ow in the well. Note that in
addition to conducting ‡uids along a path to the surface, the physical wellbore
enables hydraulic contact (and potential ‡ow) between non-adjacent reservoir
gridblocks. We could try to incorporate the wellbore into the reservoir simulator
in a fully implicit formulation, however, this approach presents some serious
drawbacks: (i) the structure of the Jacobian matrix will depend on the path
of the well and the positions of the perforations. This means that the sparse
matrix structure will not be easily predictable, and will vary from case to case.
Writing a general program in this case would be di¢ cult. (ii) The elements of the
Jacobian matrix for reservoir ‡ow can be calculated e¢ ciently using analytical
formulae and table lookups; this is not the case for pipe ‡ow. In general, partial
derivatives of the equations governing pipe ‡ow must be determined numerically.
This would be extremely ine¢ cient in a fully coupled well/reservoir system. In
view of the stated drawbacks, we will model our wellbores separately, then
couple the reservoir and well systems externally. We will detail this coupling in
the following chapter.
In real wells, the well trajectory through the reservoir is often neither vertical
nor horizontal, and the well path will not in general run parallel to any of the
reservoir axes. Further, the well may be completed using advanced techniques
aimed at controlling the in‡ow of sand and coning of gas and water. The
resulting ‡ow in the wellbore may be much more complex than simple ‡ow
in a straight pipe with the well exchanging ‡uids with the reservoir along the
length of the wellbore. In this section, we focus on wells that can be viewed as
single pipes with perforations at various points along their lengths. Although
this system is very simple and can be modeled in an equally simple manner,
we will introduce pipe ‡ow modeling concepts that can be applied to much
more complicated well completions, so that reservoirs incorporating wells with

105
advanced completions could be modeled in a similar manner.

3.2 Simplifying Assumptions


We assume that ‡ow in the wellbore and the well completions is isothermal and
at steady state; i.e., constant mass ‡ow rate. That is, we assume that transient
times in the wellbore are much more rapid than transient times in the reservoir,
so that at any instant of time, the wellbore is not storing ‡uids. Note that
this assumption will not be valid for simulation runs where we wish to study
the early-time pressure transient behavior of a well, but for …eld studies where
we are interested in the long-term behavior of the system, the assumption is
reasonable.
Multiphase ‡ow in a well can be very complicated since the phases will
distribute themselves in di¤erent ‡ow patterns in the pipe, and the resulting
pressure losses can vary widely depending on the existing ‡ow pattern[7], [27];
this situation is complicated further by ‡uids entering and leaving the pipe at
the perforated intervals. We assume that ‡uids in the pipe adjacent to the
reservoir are completely mixed and homogeneous, so that pressure losses are
independent of multiphase ‡ow patterns, and ‡ow of the homogeneous mixture
can be treated like ‡ow of a ‡uid with averaged PVT properties. This is referred
to as a “Homogeneous no-slip model”[27]. This assumption is not necessary to
formulate and solve the problem, however, it signi…cantly simpli…es solution of
the pipe ‡ow problem since ‡ow pattern approaches to multiphase ‡ow often
exhibit derivative discontinuities at ‡ow pattern transition boundaries[7].

Figure 3.1 shows a simpli…ed schematic of the horizontal section of a well;


(for production, ‡ow is from the “toe” to the “heel” of the well. The black
dots represent “nodes” or points at which di¤erent ‡ow paths meet. The lines
represent “arcs” or ‡ow conduits. In the …gure ‡uid can enter (or exit) the
basepipe through perforations (vertical lines or arcs) from (or to) the reservoir.
Each arc can provide a unique relationship between volumetric ‡ow rate and
pressure loss.

3.3 Flow Equations

3.3.1 Single Phase Flow


Suppose that we specify pressures at node “a” and nodes “f” through “i”. We
order the nodes in Fig. 3.1 from “a”to “i”and the arcs from 0 to 7; see Fig. 3.2.
Since the system is at steady state, it is clear that the sum of masses entering
and exiting any of the internal nodes (i.e., nodes “b”through “e”) must be zero.
So, for example, if we assume that the direction of ‡ow is from top to bottom
and right to left, at nodes “b” - “e” we must have
m
_0 m
_1=m
_4 (3.1)

106
Reservoir Node

Heel Toe
Base Pipe

Figure 3.1: Schematic of connections between a simple well and a reservoir.

f g h i

4 5 6 7

a 0 b 1 c 2 d 3 e

Figure 3.2: Ordered nodes and arcs for the simple well.

m
_1 m
_2=m
_5 (3.2)
m
_2 m
_3=m
_6 (3.3)
m
_3=m
_7 (3.4)
Note that if the mass rates in arcs 4 - 7 are known, all arc rates are known. In
order to solve for the mass rates in arcs 4-7, we need 4 pressure loss equations;
these are:
pf p4 (m_ 4) p0 (m_ 0 ) pa = 0 (3.5)

pg p5 (m
_ 5) p1 (m
_ 1) p0 (m
_ 0) pa = 0 (3.6)

ph p6 (m
_ 6) p2 (m
_ 2) p1 (m
_ 1) p0 (m
_ 0) pa = 0 (3.7)
and

pi p7 (m
_ 7) p3 (m
_ 3) p2 (m
_ 2)
p1 (m
_ 1) p0 (m
_ 0) pa = 0 (3.8)
Equations 3.1 - 3.8 are 8 equations (4 of which are nonlinear) in the unknown
7
mass rates fm_ i gi=0 : The nonlinear equations can be solved using the restricted
step Newton algorithm of Due‡hard[15]; see Appendix C. The algorithm for
solving the system of equations is as follows:

107
1. Guess the mass rates in arcs 4-7; e.g., 1000 lbm/day.
2. Compute all remaining mass rates from Eqs. 3.1 - 3.4.
3. Compute the residuals of Eqs. 3.5 - 3.8, and compute the Newton cor-
7
rections for fm
_ i gi=4 : If the sizes of these corrections is su¢ ciently small
stop.
4. Update the mass rates in arcs 4 - 7 and go to step 2.

3.3.2 Multiphase Flow


The above approach is su¢ cient if there is only a single ‡uid ‡owing in each arc
of the wellbore. In actual production scenarios, this may not be the case; we
may have gas or water breakthrough at some point along the wellbore, and this
would cause the compositions of the ‡uids ‡owing to change with location. If
the ‡uids ‡owing through the wellbore are compressible (e.g., gas) or if multiple
phases ‡ow simultaneously, the problem becomes more complicated, since pres-
sure drops in the arcs depend on the PVT properties of the ‡uids ‡owing in each
arc, and these depend on the composition of the ‡uid ‡owing and the average
pressure in the arc. Regardless of the type of ‡ow (i.e., single or multiphase),
the mass balance equations are valid; for multiphase ‡ow, these mass balance
equations may be applied to total mass ‡ow rate or the mass rate of each ‡owing
component. In the case of multiphase ‡ow, there are additional unknowns: in
particular, the manner in which the phases are distributed in the arcs. Thus, if
we have three components ‡owing (e.g., oil, water and gas), in addition to the
total mass ‡ow rates in each reservoir/wellbore arc, we also must determine the
mass ‡ow rates of two of the components (e.g., oil and water). This requires
that we impose additional constraints: i.e., two for each reservoir/wellbore con-
nection for the ‡ow of three components. These constraints are the inlet gas-oil
ratio and water-oil ratio at reservoir nodes. Once these are known, the mass
rates of each component entering each point in the wellbore are known, and the
‡uid compositions at every point in the wellbore are uniquely de…ned.
As mentioned previously, a …nal complication in handling multiphase ‡ow is
that PVT properties (and as a consequence phase velocities) are dependent on
absolute pressure in each arc. Solution of the rates from the nonlinear pressure
equations (described in the previous section) is an iterative process, and the
successful convergence of these calculations depends on the direction in which we
perform the calculations. Thus, for example, if we have not arrived at a solution,
the result of computing pressures starting at node “i”in Fig. 3.2 and ending at
node “a” would be completely di¤erent than that obtained by starting at node
“a” and ending at “i”. We have found that to obtain successful convergence of
the calculations for multiphase ‡ow, at least one pressure calculation must be
done in the opposite direction of the others during the iterative process. This
for example, in Fig. 3.2, we could compute pressure equations for nodes “f” to
“h” (Eqs. 3.5 - 3.7) by working towards node “a”, while for the …nal equation,
(Eq. 3.8), we would start at node “a” and work towards node “i”.

108
3.3.3 Speci…ed Heel Rate
The discussion we have presented so far implicitly assumed that the pressure was
speci…ed at the heel of the well. The problem changes slightly if rate is speci…ed
at the heel of the well. In this case, there is one less unknown mass rate and one
less pressure equation. For the system in Fig. 3.2, the pressure equations are
obtained by eliminating the outlet pressure from three of the equations, e.g., by
di¤erencing Eqs. 3.5 and 3.6, and 3.6 and 3.7 to obtain

pf pg + p5 (m
_ 5) p4 (m
_ 4) + p1 (m
_ 1) = 0 (3.9)

pg ph + p6 (m
_ 6) p5 (m
_ 5) + p2 (m
_ 2) = 0 (3.10)
and

pi p7 (m
_ 7) p3 (m
_ 3) p2 (m
_ 2)
p1 (m
_ 1) p0 (m
_ 0) pa = 0 (3.11)
Note that Eqs. 3.9 and 3.10 do not include the heel pressure (which is unspec-
i…ed) but we retain Eq. 3.8. We compute Eqs. 3.9 and 3.10 by starting at
the reservoir node “f”(or “g”), computing the pressure drop in the direction of
‡ow to the outlet node “a”, then working backward to the neighboring reservoir
node “g” (or “h”). For Eq. 3.8, we use the last available estimate of the well
heel pressure and work backwards to the reservoir node “i”. We have found
that this procedure facilitates convergence of the nonlinear equations.
To complete this section we describe modi…cations to the total mass rate
equations under di¤erent speci…ed rate conditions.

Speci…ed Oil Rate


If the oil rate at the outlet is speci…ed as qo;sp eci…ed ; STB/d, the oil mass rate
at the outlet is given by
m
_ o;outlet = qo;sp eci…ed o;sc (3.12)
where o;sc is the density of the stock tank oil in lbm/STB. At inlet reservoir
node i, the total mass rate m
_ i is related to the oil rate at that node via
GLRi (1 + W ORi ) g;sc W ORi
m
_i=m
_ o;i 1 + + w;sc (3.13)
o;sc o;sc
so
m
_i o;sc
m
_ o;i = (3.14)
o;sc + GLRi (1 + W ORi ) g;sc + W ORi w;sc
and our mass constraint equation becomes
NX
RES
m_i
= qo;sp eci…ed (3.15)
i=1 o;sc + GLRi (1 + W ORi ) g;sc + W ORi w;sc

109
where NRES is the number of reservoir nodes that admit ‡ow to the network.
For our example network, we would write

m
_ 15
=
o;sc + GLR n (1 + W OR n) + W ORn w;sc
g;sc
m
_ 16
qo;sp eci…ed
o;sc + GLR o (1 + W OR o ) g;sc + W ORo w;sc
m_ 17
o;sc + GLRp (1 + W ORp ) g;sc + W ORp w;sc
m_ 18
(3.16)
o;sc + GLRq (1 + W ORq ) g;sc + W ORq w;sc

Speci…ed Gas Rate


For speci…ed gas rate qg;sp eci…ed ; scf/d, the gas mass rate at the outlet is given
by
m_ g;outlet = qg;sp eci…ed g;sc (3.17)
where g;sc is the density of the produced gas in lbm/scf. At inlet reservoir node
i, the total mass rate m
_ i is related to the gas rate at that node via

o;sc W ORi w;sc


m
_i=m
_ g;i +1+ (3.18)
GLRi (1 + W ORi ) g;sc GLRi (1 + W ORi ) g;sc

or
m_ i GLRi (1 + W ORi ) g;sc
m
_ g;i = (3.19)
o;sc + GLR i (1 + W ORi ) g;sc + W ORi w;sc

In this case, our constraining equation becomes


NX
RES
m_ i GLRi (1 + W ORi )
= qg;sp eci…ed (3.20)
i=1 o;sc + GLR i (1 + W ORi ) g;sc + W ORi w;sc

Speci…ed Water Rate


For speci…ed water rate qw;sp eci…ed ; scf/d, the water mass rate at the outlet is
given by
m_ w;outlet = qw;sp eci…ed w;sc (3.21)
where w;sc is the density of the produced water in lbm/STB. At inlet reservoir
node i, the total mass rate m
_ i is related to the water mass rate at that node via

o;sc GLRi (1 + W ORi ) g;sc


m
_i=m
_ w;i + +1 (3.22)
W ORi w;sc W ORi w;sc
so
m_ i W ORi w;sc
m
_ w;i = (3.23)
o;sc + GLRi (1 + W ORi ) g;sc + W ORi w;sc

110
and our constraint equation assumes the form
NX
RES
m
_ i W ORi
= qw;sp eci…ed (3.24)
i=1 o;sc + GLR i (1 + W ORi ) g;sc + W ORi w;sc

Speci…ed Liquid Rate


For speci…ed liquid rate (qo + qw )sp eci…ed ; we have from Eqs. 3.14 and 3.23,
NX
RES
m _ i (1 + W ORi )
= (qo + qw )sp eci…ed
i=1 o;sc + GLRi (1 + W ORi ) g;sc + W ORi w;sc
(3.25)

Speci…ed Mass Rate


For speci…ed total mass rate, the constraint is simply
NX
RES

m
_i=m
_ sp eci…ed (3.26)
i=1

The approach of solving the well model can be generalized to very complex
well completions; see Ref. [33].

3.3.4 Calculation of Pipe Pressure Drops

For simplicity, we assume that there is no pressure drop in the perforations. Here
we summarize the basic equations for computing pressure drops in pipes[27].
The pressure gradient due to ‡uid ‡ow in a pipe is made up of three compo-
nents: the gravitational gradient (due to pipe inclination from the horizontal),
the frictional component resulting from shear resistance to ‡ow and the ac-
celeration component which results from velocity changes due to expansion or
contraction of the ‡uids (e.g., for ‡ow through nozzles or expansion …ttings).
For ‡ow in pipes with constant diameter, acceleration gradients are small, and
they will be neglected.
The gravitational gradient for a homogeneous mixture is given by
dp mix g
= sin psi/ft (3.27)
dL g 144gc
lbm
where mix is the homogeneous mixture density, f t3 , g is the acceleration due
ft 2 2
to gravity, 32.2 sec2 ;
144 converts f t to inch , gc is a units conversion factor
lbm f t
(32.2 lbf sec2 ), and (radian) is the angle of inclination of the pipe segment
from the horizontal in the direction of ‡ow. For a three-phase mixture, the
homogeneous mixture density is computed using

mix = o o + w w + (1 o w) g (3.28)

111
where o and w are the “no-slip”holdups of oil and water respectively. These
are de…ned as
qo
o = (3.29)
qt
and
qw
w = (3.30)
qt
where qo , qw and qg are the in situ volumetric rates of oil water and gas respec-
f t3
tively (all in the same units, e.g., day ), and

qt = qo + qw + qg : (3.31)

The frictional gradient is obtained from

dp f mix v 2t
= psi/ft (3.32)
dL f 288gc D

where f is the Moody friction factor at average conditions in the pipe segment,
D is the pipe diameter (f t) and v t is the average mixture velocity in the segment
ft f t3
sec : For phase rates (qo , qw and qg ) in day ,

qt
vt = : (3.33)
D 2
86400 2

The Moody friction factor is a function of the dimensionless Reynolds Number,


NRe , and the pipe roughness, " (f t) : Here

1488 mix v t D
NRe = ; (3.34)
mix

mix is the mixture viscosity in cp, given by

mix = o o + w w + (1 o w) g (3.35)

where m ; m = o; w; or g refers to the phase viscosity in cp.


There are many correlations for obtaining the Moody friction factor; one of
the most widely used for turbulent ‡ow is the Colebrook equation[10], [11]:

" 18:7
f = 1:74 2 log10 + p (3.36)
D NRe f

Note that this equation is nonlinear; it is easily solved using the following algo-
rithm.

1. Guess the friction factor; e.g., fguess = 0:01:


2. Substitute fguess in the right side of Eq. 3.36, and compute a new value
of f , fnew :

112
3. Check whether jfguess fnew j < ; where is a small tolerance, e.g., 10 8 :
If the inequality is satis…ed, the required friction factor is fnew ; otherwise,
set fguess = fnew and go to step 2.

The algorithm for computing pressure drop in a pipe with a given rate is as
follows:

1. Starting with a known pressure at one end of the pipe, guess the pressure
at the other end. (To start we could set outlet pressure equal to inlet
pressure.)
2. Compute the average pressure in the segment
pin + pout
p= (3.37)
2

3. Compute PVT properties at the average pressure, and the in situ phase
‡ow rates.
4. Compute the Reynolds number and friction factor at average conditions.
Calculate the pressure gradient using

dp dp dp
= + (3.38)
dL total dL g dL f

5. Compute the pressure at the pipe outlet (or inlet)

dp
pout = pin L (3.39)
dL total

where L is the length of the pipe segment in f t.


6. Compare the calculated and guessed value of outlet pressure; if they are
close, the problem is solved. Otherwise replace the guessed value of outlet
(or inlet) pressure with the calculated value and proceed to step 2.

The design of the classes used to model the well is left as an exercise for the
reader.

113
Chapter 4

Coupling of the Reservoir


and Well Models

4.1 Introduction
At this point, we have described two independent models: the …rst for a reservoir
simulator that produces ‡uids via an arbitrarily located set of sinks, and the
second for a steady-state wellbore that exchanges ‡uid along its length with
an external source (i.e., the reservoir). We are now faced with the problem of
coupling the two disparate models at the points where they physically connect
(i.e., at the perforations). The …rst problem that we must address is the fact that
the geometries of the two systems need not match in any way; that is, wellbores
are usually made up of connected pipe joints which are typically about 40 ft
long that may meander in almost any direction; reservoir gridblocks can have
almost any dimensions depending on the …neness of the scale that we wish to
simulate and the faces of the gridblocks are aligned with the principal axes.
Our …rst problem is therefore: given the well trajectory as a sequence of spatial
coordinates, determine how the reservoir gridblocks dissect the well path and
break it into segments that …t exactly into each intercepted gridblock. During
this process, we must generate a mapping of wellbore arc indices to reservoir
gridblock indices and vice versa. Fig. 4.1 illustrates the problem for an arbitrary
horizontal well path through a two-dimensional grid. Clearly the reservoir grid
does not automatically coincide with the wellbore trajectory, so that parts of
a given 40-ft well segment will lie in one gridblock, while other parts will be
in completely di¤erent gridblocks. Further, it is possible that a single reservoir
gridblock may contain several pieces of di¤erent pipe segments. Note that in
3-dimensional problems, the well path is also three dimensional, so the path
may also intersect di¤erent vertical gridblocks.
Once the geometric mapping between well segments and reservoir gridblocks
has been obtained, we must devise a scheme to hydraulically connect the well
segments with the corresponding perforated gridblocks. To do this e¢ ciently,

114
Well path

Figure 4.1: Schematic of the path of a well through a two-dimensional reservoir.

we employ a scheme suggested in Refs. [6] and [5].

4.2 Mapping Well Segments to Gridblocks


Figure 4.2 shows an arbitrary (40 ft long) well segment with endpoint coordi-
nates Xps and Xpe ; where

Xps = (xps ; yps ; zps ) (4.1)

Xpe = (xpe ; ype ; zpe ) (4.2)


that passes through a reservoir gridblock with faces at

x = xi 1
2
; x = xi+ 21 ;

y = yj 1
2
; y = yj+ 12 ;
z = zk 1
2
; z = zk+ 12 :
There are three possibilities: (A) the well segment lies totally within the grid-
block; (B) the well segment cuts a single face of the block; (C) the well segment
cuts two gridblock faces. (It is not physically possible for a straight line to
cut three faces of a rectangular parallelepiped gridblock.) The length of the
segment that is within the gridblock obviously depends on the number of cuts
and their coordinates. We can view the well path as a list of segment endpoint
coordinates, and our task is to subdivide this list into a new list of endpoint

115
yj+1/2 Xpe

B
Xpe
X ps
xi-1/2 xi+1/2
A
Xpe
X ps

yj-1/2 C
X ps

Figure 4.2: 2-D Schematic of a well segment in a reservoir gridblock

coordinates such that each sub-segment exactly …ts in a reservoir gridblock. In


the process, we will be able to create a mapping of well sub-segments to reser-
voir gridblocks. The following assumes that xpe xps ; ype yps and zpe zps .
Slight modi…cations to the algorithm are necessary if any of the preceding con-
ditions are violated. The algorithm for doing this is as follows:

1. For each segment in the well trajectory:

(a) Set coordinates X ^ ps = Xps and X


^ pe = Xpe :
(b) Do while X^ ps 6= X
^ pe :
i. Locate the indices (is ; js ; ks ) in the reservoir grid such that xis 21
x
^ps < xis + 12 ; yjs 21 y^ps < yjs + 12 and zks 12 z^ps < zks + 12 ;
also locate (ie ; je ; ke ) in the reservoir grid such that xie 21
x
^pe < xie + 12 ; yje 21 y^pe < yje + 12 and zke 21 z^pe < zke + 12 :
ii. Check to see if no faces are cut: this is the case if is = ie ; js = je
and ks = ke : If this is true, map the well segment to the reservoir
gridblock and proceed to the next segment. Otherwise, if is 6= ie ;
one of the x-faces is cut, if js 6= je ; one of the y-faces is cut and
if ks 6= ke ; one of the z-faces is cut. At this stage we know
the number of cuts and which faces; i.e., if is < ie ; the face at
xie 21 = xis + 12 was cut and if is > ie ; the face at xis 21 = xie + 21
was cut. Similar logic applies to the remaining faces.
iii. For each face that is cut:

116
A. Determine the coordinates of the intersection point of the
line and the face. From basic analytic geometry[4], if a point
lies on the line connecting Xps and Xpe , we must have
x xps = t (xpe xps ) ; (4.3)
y yps = t (ype yps ) ; (4.4)
and
z zps = t (zpe zps ) ; (4.5)
where t is a parameter. If, for example, we know that the
line intersects the plane at x = xis 21 ; we can compute t from
xis 1
2
xps
t= (4.6)
xpe xps
and compute the y and z coordinates of the intercept
using Eqs. 4.4 and 4.5. Similar logic applies to the other
planes. Denote the coordinates of the intercept point by
XpInt :
B. Map the well sub-segment that lies between X ^ ps and XpInt
^
to the reservoir gridblock, and set Xps = XpInt :
iv. Continue
(c) Continue
2. Continue
At this stage we have a mapping of all the well sub-segments in the reservoir
gridblocks. We now recreate the well trajectory so that it re‡ects well segments
that …t exactly into reservoir gridblocks; there is now one to one correspondence
between well segments and reservoir gridblocks. We use the generated set of
well subsegments to set up sinks (or sources) in the reservoir using the methods
described in Chapter 2.

4.3 Reservoir/Wellbore Interface

We assume that from the reservoir point of view, the pressure along a single pipe
subsegment is uniform and equal to the average pressure in that subsegment.
Fluid transfer between the reservoir gridblocks and the well subsegment is cal-
culated based on the average subsegment pressure; in this way we account for
varying ‡uid transfer along an actual pipe segment from areas with low or high
transmissibilities. We link the wellbore and reservoir simulators by requiring
that the pressures at their interfaces be the same, and solving both simulators
iteratively for the required rates. There are several possible methods for doing
this; here we describe an algorithm based on the method employed by Refs. [6]
and [5].

117
1. Initialize the simulator by setting a small mass ‡ow rate (e.g., 1000 lbm/d)
at each well subsegment. This is done to obtain initial estimates of the
interface pressures between the reservoir and the wellbore as well as the
‡owing gas-oil and water oil ratios, all of which are needed for the wellbore
model run.

2. Using the pressures and GORs and WORs from the simulator, run the
wellbore model to obtain the mass rates at each reservoir node. Compute
the di¤erences between the reservoir and network rates at the connecting
nodes using
v
unconnections
u X 2
=t (mReservoir;j mW ellbore;j ) (4.7)
j=1

3. If tolerance, accept the solution. Otherwise, set the reservoir rates


equal to the last network rates (or a weighted average between the reservoir
and wellbore rates) and run the simulator. Go to step 2.
4. If there is no convergence after a speci…ed number of iterations, cut the
timestep and try again.

This method is fast and simple, and usually converges to the correct solution.
Other methods of coupling the simulators are much more calculation intensive,
and are beyond the scope of this course. The design of the object code for the
interface is left as an exercise for the reader.

118
Bibliography

[1] MATLAB software, The MathWorks, http://www.mathworks.com.


[2] Maxima, a computer algebra system, http://maxima.sourceforge.net/,
April 2009, v. 5.18.1.
[3] M.H. Gonzalez A.L. Lee and B.E. Eakin, The viscosity of natural gases,
Journal of Petroleum Technology (1966), 997.
[4] Adrian Albert, Solid analytic geometry, McGraw-Hill Book Company, Inc.,
1949.
[5] Kristian Brekke, Horizontal well productivity and risk assessment, Ph.D.
thesis, The University of Tulsa, 1996.
[6] T. E. Johansen Brekke K. and R. Olufsen, A new modular approach to com-
prehensive simulation of horizontal wells, Paper SPE 26518, Proceedings
of the 68th. SPE Annual Technical Conference and Exhibition (Houston),
1994.
[7] James P. Brill and Hemanta Mukherjee, Multiphase ‡ow in wells, Society
of Petroleum Engineers, Richardson, Texas, 1999.
[8] R. H. Brooks and Corey A. T., Properties of porous media a¤ ecting ‡uid
‡ow, Journal of the Irrigation and Drainage Division, Proceedings of the
½
American Society of Civil Engi- neers 92 (1966), no. IR2, 61U86.
[9] Herbert B. Callen, Thermodynamics and an introduction to thermostatis-
tics, second ed., John Wiley and Sons Inc., 1985.
[10] C. F. Colebrook, Turbulent ‡ow in pipes, with particular reference to the
transition region between smooth and rough pipe laws, Journal of the Insti-
tution of Civil Engineers 12 (1939), 393–422.
[11] C.F. Colebrook and C.M. White, Experiments with ‡uid-friction in rough-
ened pipes, Proceedings Royal Society, London 161 (1937), 367–381.
[12] T. A. Davis, A column pre-ordering strategy for the unsymmetric-pattern
multifrontal method, ACM Transactions on Mathematical Software 30
(2004), no. 2, 165–195.

119
[13] Timothy A. Davis, Algorithm 832: UMFPACK v4.3— an unsymmetric-
pattern multifrontal method, ACM Transactions on Mathematical Software
(TOMS) 30 (2004), no. 2, 196–199.
[14] , UMFPACK version 5.4.0 user guide, Tech. report, Dept. of
Computer and Information Science and Engineering Univ. of Florida,
Gainesville, FL, May 2009.
[15] P. Deu‡hard, Newton methods for nonlinear problems - a¢ ne invariance
and adaptive algorithms, Springer Series in Computational Mathematics,
Springer-Verlag Berlin Heidelberg, 2004.
[16] P. M. Dranchuk and J. H. Abou-Kassem, Calculations of z-factors for nat-
ural gases using equations of state, Journal of Canadian Petroleum Tech-
nology 14 (1975), no. 3, 34.
[17] D.P. Bossler E.F. Johnson and V.O. Naumann, Calculation of relative per-
meability from displacement experiments, JPT (1959), 61–63.
[18] K. Goto, GotoBLAS (basic linear algebra subroutines),
http://www.tacc.utexas.edu/resources/software.
[19] K. R. Hall and L. Yarborough, A new EOS for z-factor calculations, Oil
and Gas Journal (1973), 82.
[20] Jr. J.E. Dennis and Robert B. Schnabel, Numerical methods for uncon-
strained optimization and nonlinear equations, Classics In Applied Mathe-
matics, SIAM, Philadelphia, 1996.
[21] T. Kartoatmdojo and Z. Schmidt, New correlations for crude oil physical
properties, paper SPE 23566, June 1991.
[22] E.F. Nelson K.M. Watson and G.B. Murphy, Characterization of petroleum
fractions, Ind. Eng. Chem. 27 (1935), 1460.
[23] K. Lucas, Die druckabhangigkeit der viskositat von ‡ussigkeiten - ein ee-
infache abschatzung (pressure dependence of viscosity of liquids - a simple
estimate), Chem. Eng. Tech. 53 (1981), 959.
[24] R.C. MacDonald and K.H. Coats, Methods for numerical simulation of
water and gas coning, SPEJ (1970), 425–436.
[25] S. Mochizuki, Well productivity for arbitrarily inclined well, SPE Reservoir
Simulation Symposium, 12-15 February 1995.
[26] D. W. Peaceman, Interpretation of well-block pressures in numerical reser-
voir simulation with nonsquare grid blocks and anisotropic permeability,
SPEJ (1983), 531–543, Paper SPE 10528.
[27] Ovadia Shoham, Mechanistic modeling of gas-liquid two-phase ‡ow in pipes,
Society of Petroleum Engineers, 2005.

120
[28] M. B. Standing, Volumetric and phase behavior of oil …eld hydrocarbon
systems, 9th ed., Society of Petroleum Engineers, Richardson, Texas, 1981.
[29] M.B. Standing and D.L. Katz, Density of natural gases, Transactions of
AIME 146 (1942), 140.

[30] H.L. Stone, Probablility model for estimating three-phase relative perme-
ability, Journal of Petroleum Technology (1970), 214.
[31] , Estimation of three-phase relative permeability and residual oil
data, Journal of Canadian Petroleum Technology 12 (1973), no. 4, 53.
[32] R.P. Sutton, Compressibility factors for high-molecular weight reservoir
gases, paper SPE 14265 presented at the 1985 SPE Annual Technical Con-
ference and Exhibition, 22-25 September 1985.
[33] Leslie Thompson and Kristian Brekke, Modeling of ‡ow in a near-wellbore
network, Proceedings of the ASME 2009 28th International Conference on
Ocean, O¤shore and Arctic Engineering, May 31st - June 5th 2009.
[34] Jamal H. Abou-Kassem Turgay Ertekin and Gregory R. King, Basic ap-
plied reservoir simulation, SPE Textbook Series Vol., Society of Petroleum
Engineers, Richardson, Texas, 2001.
[35] M. Vazquez and H. D. Beggs, Correlations for ‡uid physical property pre-
diction, Journal of Petroleum Technology (1980), 650.
[36] K.M. Watson and E.F. Nelson, Improved methods for approximating critical
and thermal properties of petroleum, Ind. Eng. Chem. 25 (1933), no. 8, 880.
[37] L. Weimann, Error based damped newton algorithm,
http://www.zib.de/Numerik/numsoft/NewtonLib, June 2006.
[38] , Error based quasi-newton algorithm,
http://www.zib.de/Numerik/numsoft/NewtonLib/qnerr/qnerr.c, June
2006.
[39] Curtis H. Whitson and Michael R. Brule, Phase behavior, Henry L. Doherty
Series, Society of Petroleum Engineers, Richardson, Texas, 2000.
[40] E. Wichert and K. Aziz, Calculate zs for sour gases, Hydrocarbon Process-
ing (1972), 119–122.
[41] Jr. William D. McCain, The properties of petroleum ‡uids, 2nd ed., Pen-
nWell Publishing Company, Tulsa, Oklahoma, 1990.

[42] William T. Vetterling William H. Press, Saul A. Teukolsky and Brian P.


Flannery, Numerical recipies in c - the art of scienti…c computing, Cam-
bridge University Press, 1992.

121
Appendix A

PVT Correlations

Here we summarize some of the most common correlations used by the oil
industry to generate black oil PVT properties in the absence of actual laboratory
data; a more complete set may be found in Appendix B of Ref. [7] and in Ref.
[39].

A.1 Solution Gas-Oil Ratio


Solution gas-oil ratio is de…ned as the standard volume of gas (scf ) dissolved
in a standard volume of oil (ST B) at reservoir pressure and temperature. In
scf
…eld units, it is measured in ST B : The following correlations are for saturated
solution gas-oil ratios; solution gas-oil ratio above the saturation pressure is
equal to the value at the saturation pressure, i.e.,

Rs = Rs;bub for p pbub (A.1)

A.1.1 Standing[28]
The Standing correlation for computing solution gas-oil ratio (scf/STB) is
h p i1:2048
Rs = g + 1:4 100:0125AP I 0:00091T (A.2)
18:2
where g is the gas speci…c gravity (air = 1), p is the pressure in psia, AP I is
the stock tank oil API gravity (water = 10) and T is the system temperature
in o F.

A.1.2 Vazquez and Beggs[35]


The Vazquez and Beggs PVT correlation are all based on a normalized separator
gas speci…c gravity at 100 psig, g100 given by

5 psep
g100 = g 1 + 5:912 10 (AP I) T log (A.3)
114:7

122
where g is the separator gas speci…c gravity, AP I is the stock tank oil API
gravity, Tsep is the separator temperature in o F and psep is the separator pressure
in psia. Their correlation for solution gas-oil ratio is

C2 C3 AP I
Rs = C1 g100 p exp (A.4)
T + 460
where p is the pressure in psia and T is the system temperature in o F and
Coe¢ cient AP I 30 AP I > 30
C1 0.0362 0.0178
C2 1.0937 1.1870
C3 25.7245 23.931

A.1.3 Kartoatmodjo and Schmidt[21]


Similar to the Vazquez and Beggs correlations, the Kartoatmodjo and Schmidt
correlations are based on a corrected separator gas gravity at a pressure of 100
psig. Their equation for corrected gas gravity, g100 is
psep
g100 = g 1 + 0:1595AP I 0:4078 Tsep:02466 log (A.5)
114:7
where g is the separator gas speci…c gravity, AP I is the stock tank oil API
gravity, Tsep is the separator temperature in o F and psep is the separator pressure
in psia. Their correlation for solution gas-oil ratio is
4 C AP I
C2 C3
Rs = C1 g100 p 10
(T +460) (A.6)

where p is the pressure in psia and T is the system temperature in o F and


Coe¢ cient AP I 30 AP I > 30
C1 0.05958 0.03150
C2 0.7972 0.7587
C3 1.0014 1.0937
C4 13.1405 11.289

A.2 Oil Formation Volume Factor


Oil formation volume factor is de…ned as the volume of oil at reservoir condi-
tions required to yield a unit volume at standard conditions; in …eld units, it
bbl
is measured in ST B : The presented correlations are for saturated oils (i.e., for
pressures below the bubble point pressure). Oil formation volume factors at
pressures above the bubble point are calculated from

Bo = Bob exp (co (pbub p)) (A.7)

where Bob is the oil formation volume factor at the saturation pressure, co is the
coe¢ cient of isothermal compressibility for the oil psi 1 ; pbub is the saturation
pressure, psia and p is the system pressure, psia.

123
A.2.1 Standing[28]
At pressures below the bubble point pressure, the Standing correlation is given
by
" #1:2
0:5
g
Bo = 0:9759 + 0:00012 Rs + 1:25T (A.8)
o

where g is the gas speci…c gravity (air = 1), o is the oil speci…c gravity (water
scf
= 1), Rs is the solution gas-oil ratio in ST B and T is the system temperature
o
in F.

A.2.2 Vazquez and Beggs[35]


The Vazquez and Beggs correlation is expressed as

AP I
Bo = 1 + C1 Rs + (T 60) (C2 + C3 Rs ) (A.9)
g100

where g100 is given by Eq. A.3, AP I is the oil API gravity (water = 10), Rs
scf o
is the solution gas-oil ratio in ST B and T is the system temperature in F and
Coe¢ cient AP I 30 AP I > 30
C1 4.677 10 4 4.670 10 4
C2 1.751 10 5 1.100 10 5
C3 -1.811 10 8 1.337 10 9

A.2.3 Kartoatmodjo and Schmidt[21]


The Kartoatmodjo and Schmidt correlation is

Bo = 0:98496 + :0001F 1:5 (A.10)

where
F = Rs0:755 0:25
g100 o
1:5
+ 0:45T (A.11)
and g100 is given by Eq. A.5, o is the oil speci…c gravity (water = 1), Rs is
scf o
the solution gas-oil ratio in ST B and T is the system temperature in F.

A.3 Oil Viscosity


The following correlations provide the viscosity of saturated oil in centipoise.
Whitson[39] notes that this is the most unreliable PVT property to predict using
correlations, since it is heavily dependent on the oil type. At pressures above
saturation pressure, the viscosity is computed using
d o
o = o;bub + (p pbub ) (A.12)
dp

124
where o;bub is the viscosity at the saturation pressure, pbub , ddpo is the derivative
cp
of oil viscosity with respect to pressure above the saturation pressure ( psi ) and
p is the pressure of interest, psia, with p pbub: This is a deviation from the
standard PVT correlations which provide corrections from saturated to under-
saturated conditions. For the purpose of reservoir simulation we assume that
the above correction is adequate.

A.3.1 Standing[28],[39]
Whitson[39] recommends the following correlation due to Standing for deter-
mining “dead” oil viscosity i.e., viscosity of oil with no dissolved gas, when the
Watson characterization factor[36],[22], Kw is known,

oD 1
log = 2:17 (A.13)
8:24
o A3 Kw + 1:639A2 1:059
o

where
(2:87A1 1) o
A3 = 0:1285 (A.14)
2:87A1 o
T + 460
A2 = 1 + 0:554 log (A.15)
560
T + 460
A1 = 1 + 8:69 log (A.16)
560
gm
and o is the oil speci…c gravity (water = 1), o is the oil density ( cm3 ), and T
o
is the system temperature in F. The dead oil viscosity is converted to viscosity
at saturated conditions using[28]
a2
o = a1 oD (A.17)
where 4 7
7:4 10 Rs +2:2 10 Rss
a1 = 10 (A.18)
and
0:68 0:25 0:062
a2 = 5R + 3R + 3R (A.19)
108:62 10 s 101:1 10 s 103:74 10 s

scf
where Rs is the solution gas-oil ratio in ST B :

A.3.2 Kartoatmodjo and Schmidt[21]


The Kartoatmodjo and Schmidt correlation for “dead” oil viscosity, oD , is
5:7526 log(T ) 26:9718
oD = 16 108 T 2:8177
(log (AP I)) (A.20)
where AP I is the oil API gravity (water = 10) and T is the system temperature
in o F. To obtain the oil viscosity at saturated conditions, the authors use the
following equation

o = 0:06821 + 0:9824f + 0:0004034f 2 (A.21)

125
where
0:000845Rs 0:43+0:5165y
f = 0:2001 + 0:8428 10 oD (A.22)
and
0:00081Rs
y = 10 (A.23)

A.4 Gas Critical Properties


Gas critical pressure, pc ; (psia) and temperature, Tc , (o R) are used to compute
the reduced gas properties, Tr and pr where
T + 460
Tr = (A.24)
Tc
for temperature T in o F; and
p
pr = (A.25)
pc
for pressure in psia. The following correlations are used to estimate gas critical
properties when the gas composition is unknown.

A.4.1 Sutton[32]
Given the speci…c gravity of the reservoir gas, g , its critical properties are
estimated from
Tc = 169:2 + 349:5 g 74 2g (A.26)
and
2
pc = 756:8 131 g 3:6 g (A.27)

A.4.2 Standing[28]
Standing provides two sets of correlations for hydrocarbon gases. For dry hy-
drocarbon gases, g < 0:75, the equations are
2
Tc = 168 + 325 g 12:5 g (A.28)

and
2
pc = 667 + 15 g 37:5 g (A.29)
For wet gases, the appropriate equations are
2
Tc = 187 + 330 g 71:5 g (A.30)

and
2
pc = 706 51:7 g 11:1 g (A.31)

126
A.4.3 Acid Gas Correction[40]
For sour hydrocarbon gases, the critical properties estimated using the equations
above must be adjusted to account for the presence of hydrogen sul…de and/or
carbon dioxide. This is a three step process; …rst, the speci…c gravity of the gas
without non-hydrocarbons () must be calculated using

(MH2 S yH2 S +MN2 yN2 +MCO2 yCO2 )


g Mair
gHC = (A.32)
1 yH2 S yN2 yCO2

where yH2 S ; yN2 and yCO2 are respectively the mole fractions of hydrogen sul…de,
nitrogen and carbon dioxide in the mixture and MH2 S (34.08), MN2 (28.0134),
MCO2 (44.01) and Mair (28.9625) are the molecular weights of hydrogen sul-
…de, nitrogen, carbon dioxide and air respectively. Hydrocarbon gas critical
properties (TcHC and pcHC )are calculated based on gHC using the previous
correlations. Non-hydrocarbon gas components are reincorporated into the
mixture using the following equations:

Tc = (1 yH2 S yN2 yCO2 ) TcHC + TcH2 S yH2 S + TcN2 yN2 + TcCO2 yCO2 ;
(A.33)
where where TcH2 S (672.32 o R); TcN2 (227.36 o R) and TcCO2 (547.78 o R) are
respectively the critical temperatures of hydrogen sul…de, nitrogen and carbon
dioxide.

pc = (1 yH2 S yN2 yCO2 ) pcHC + pcH2 S yH2 S + pcN2 yN2 + pcCO2 yCO2 ;
(A.34)
where where pcH2 S (1300. psia); pcN2 (493.1 psia) and pcCO2 (1071. psia)
are respectively the critical pressures of hydrogen sul…de, nitrogen and carbon
dioxide.
Finally, Aziz and Wichert introduced a temperature correction, ",
0:9 1:6 0:5 4
" = 120 (yH2 S + yCO2 ) (yH2 S + yCO2 ) + 15 yH 2S
yH 2S
(A.35)

The corrected critical properties are then calculated from the uncorrected values
using
Tcc = Tc " (A.36)
and
pc Tcc
pcc = (A.37)
Tc + yH2 S (1 yH2 S ) "

A.5 Gas Compressibility (z) Factor


The industry standard for predicting the volumetric behavior of hydrocarbon
gases is the Standing-Katz[29] z-factor chart, which plots gas compressibility
factor as a function of reduced pressure and temperature. In the following, we
present two commonly used functional representations of this chart.

127
A.5.1 Hall and Yarborough[19]
The z-factor is computed from the reduced pressure and temperature as
2
exp 1:2 (1 t)
z = 0:06125pr t (A.38)
y
where
1
t= (A.39)
Tr
and y is the root of the equation

f (y) = a + b + c + d = 0 (A.40)

where
2
a= 0:06125pr t exp 1:2 (1 t) (A.41)

((( y + 1) y + 1) y + 1) y
b= 3 (A.42)
(1 y)
c= ((4:58t 9:76) t + 14:76) ty 2 (A.43)
2:18+2:82t
d = ((42:4t 242:2) t + 90:7) ty (A.44)
We solve Eq. A.40 using Newton’s method via

f (y o )
yn = yo (A.45)
f 0 (y o )

where
f 0 (y) = + + (A.46)
and
((((y 4) y + 4) y + 4) y + 1)
= 4 (A.47)
(1 y)
= ((9:16t 19:52) t + 29:52) ty (A.48)
1:18+2:82t
= (2:18 + 2:82t) ((42:4t 242:2) t + 90:7) ty (A.49)
As a …rst guess form the root, we use
2
y o = 0:06125pr t exp 1:2 (1 t) (A.50)

128
A.5.2 Dranchuk and Abu Kassem[16]
The Dranchuk and Abu Kassem implicit equation for gas z-factor is given by

f (z) = + + + +1 z=0 (A.51)

where
A2 A3 A4 A5
= A1 + + 3 + 4 + 5 r (A.52)
Tr Tr Tr Tr
A7 A8 2
= A6 + + 2 r (A.53)
Tr Tr
A7 A8 5
= A9 + 2 r (A.54)
Tr Tr
2
2 r 2
= A10 1 + A11 r exp A11 r (A.55)
Tr3
and r is the reduced density given by
0:27pr
r = ; (A.56)
zTr
that is, z is the root of Eq. A.51. The coe¢ cients A1 A11 are given by
A1 = 0:3265 A7 = 0:7361
A2 = 1:07 A8 = 0:1844
A3 = 0:5339 A9 = 0:1056
A4 = 0:01569 A10 = 0:6134
A5 = 0:05165 A11 = 0:721
A6 = 0:5475
Equation A.51 is solved using Newton’s method. The derivative function
f 0 (z) is given by
d
f 0 (z) = (a + b + c) r 1 (A.57)
dz
where
A5 A6 r A4 A3
a=2 + 4 + 3 + A8 2 5A9 3r r2 (A.58)
Tr5 Tr Tr Tr
A7 2 5A9 3r r + A2
b= + A1 (A.59)
Tr
2 4 2
2A10 A11 r A11 r +1 r exp A11 r
c= (A.60)
Tr3
and
d r r
= (A.61)
dz z
The initial guess for the z-factor is z = 1:

129
A.6 Gas Formation Volume Factor
The gas formation volume factor is de…ned as the reservoir volume of gas re-
f t3
quired to yield a unit volume at standard conditions; units are scf : It is calcu-
lated from
0:0282z (T + 460)
Bg = (A.62)
p
where temperature is in o F and pressure is in psia. The z-factor is determined
using one of the previous correlations.

A.7 Gas Viscosity


The following correlations for gas viscosity are the most used in the oil industry.

A.7.1 Lee-Gonzalez[3]
According to Whitson[39], this is the correlation most used by PVT laboratories
to report gas viscosity. The equations are
4 A3
g = A1 10 exp A2 g (A.63)

where
(9:379 + 0:01607Mg ) T 1:5
A1 = (A.64)
(209:2 + 19:26Mg + T )
986:4
A2 = 3:448 + 0:01009Mg + (A.65)
T
and
A3 = 2:447 0:2224A2 (A.66)
gm
where Mg is the molecular weight of the gas, g is the gas density in cm3 and
temperature, T is in o R:

A.7.2 Lucas[23]
The following viscosity correlation is valid in the range 1 < Tr < 40 and 0 <
pr < 100 :
g A1 p1:3088
r
=1+ 1 (A.67)
gsc A2 pA
r + 1 + A3 pr
5 A4

where
3 0:3286
1:245 10 exp 5:1726Tr
A1 = (A.68)
Tr
A2 = A1 (1:6553Tr 1:2723) (A.69)
37:7332
0:4489 exp 3:0578Tr
A3 = (A.70)
Tr

130
7:6351
1:7368 exp 2:2310Tr
A4 = (A.71)
Tr
A5 = 0:9425 exp 0:1853Tr0:4489 (A.72)

gsc = 0:807Tr0:618 0:357 exp ( 0:449Tr ) + 0:340 exp ( 4:058Tr ) + 0:018


(A.73)
and 1
Tc 6
= 9490 (A.74)
Mg3 p4c
Here Tr and pr are the reduced pressure and temperature, and Tc and pc are
the gas (pseudo)critical properties in o R and psia respectively. Whitson[39]
recommends use of the Lucas equations because of its high range of applicability.
Whitson[39] also provides corrections for gas viscosity using this correlation
when acid gases and/or nitrogen are present.

A.8 Water Properties[41]


McCain suggests the following correlations for computing the properties of oil-
…eld water. (We assume that hydrocarbons are insoluble in water.)

A.8.1 Formation Volume Factor


For reservoir temperature, T in o F and pressure, p in psia calculate
7 4 2
VwT = (5:50654 10 T + 1:33391 10 )T 1:0001 10 (A.75)

and

9 13
Vwp = ((1:95301 10 +1:72834 10 p)T +(3:58922e 7+2:25341 10 10 p))p:
(A.76)
Then
Bw = (1 + VwT )(1: + Vwp ): (A.77)

A.8.2 Viscosity
For a given water salinity, S (weight percent solids), we …rst calculate the water
viscosity (in centipoise) at atmospheric pressure, w;atm ; as follows:

w;atm = AT B (A.78)

where T is temperature in o F, and


3
A = ((8:72213 10 S + 0:313314)S 8:40564)S + 109:574 (A.79)

131
and
6 5 4 2
B = (((1:5586 10 S 5:47119 10 )S 6:79461 10 )S+2:63951 10 )S 1:12166:
(A.80)
The viscosity (cp) at reservoir pressure is then computed using

w =C w;atm (A.81)

where
5 9
C = 0:9994 + p(4:0295 10 + 3:1062 10 p) (A.82)
and pressure is in psia.

A.8.3 Density
Water density at standard conditions ( lbm
f t3 ) is estimated using

3
wsc = 62:368 + (0:438603 + 1:60074 10 S)S (A.83)

where S is the salinity, (weight percent solids). The standard density is corrected
to reservoir conditions using the formation volume factor (see above) via

wsc
w = : (A.84)
Bw

132
Appendix B

Solution of Systems of
Nonlinear Equations Using
Error Oriented Descent

Our solution method for the system of nonlinear equations closely follows the
algorithm in Ref. [15] (page 148) and the code in Ref. [37]. Here we provide a
brief outline of the solution algorithm.
Given a system of n nonlinear equations F (x) ; our goal is to …nd the solu-
tion, xS ; such that
F (x) = 0 (B.1)
The L2 -norm of the vector x is de…ned as
r Pn
i=1 x2i
kxk2 = (B.2)
n

B.1 Restricted Step Newton Algorithm


Suppose that we have an initial estimate of the solution, x0 :

1. Evaluate F x0 :
2. Set a damping factor, 0 = 0:1; set a tolerance su¢ ciently above the
machine precision (e.g., =FLT_EPSILON); set a minimum allowable
dampening factor, min
3. For iteration index k = 0; 1; :::: do

(a) Evaluate the Jacobian matrix, F 0 xk


(b) Solve the linear system

F 0 xk xk = F xk (B.3)

133
where
xk = xk+1 xk (B.4)

(c) If xk < ; stop; the solution is


2

xS = xk + xk (B.5)

(d) If k > 0; compute a predicted dampening factor

k = min (1; k) (B.6)

where
k
xk 1
x
2 2
k = k k 1: (B.7)
k k 1
x x x
2 2
i. if k < min ; stop; the algorithm failed to converge.
(e) Compute the trial iterate

xk+1 = xk + k xk (B.8)

and evaluate F xk+1 :


(f) Solve the linear system
k+1
F 0 xk x = F xk (B.9)

(g) Compute the monitoring quantities


k+1
x
2
k = (B.10)
xk
2

and
2
xk k
0 2
k = k+1
(B.11)
2 x (1 k) xk
2

(h) If k 1; set
0 0 1
k = k = min k; k (B.12)
2
i. if k < min ; stop; the algorithm failed to converge.
ii. Go to step (3e.)
Otherwise, let
0 0
k = min (1; k) (B.13)
0
(i) If k = k =1

134
k+1
i. If x < ; stop; the solution is
2
k+1
xS = xk+1 + x (B.14)
ii. if k < 12 , switch to the Quasi-Newton algorithm below.
0 0
Otherwise, if k 4 k, set k = k and go to step (e).
k+1
(j) Accept x as the new iterate and go to step (3) with k ! k + 1:

In our applications, we have found that in applying step (3i), recomputing


a trial iterate with k = 0k seldom yields and acceptable result, so we choose
not implement this step.

B.2 Quasi-Newton Algorithm[15], [38]


The following outlines the quasi-Newton algorithm for solving a system of non-
linear equations.
Suppose that we have an initial estimate of the solution, x0 :
1. Evaluate and store F x0 :

2. Evaluate the Jacobian matrix, F 0 x0


3. Solve the linear system
F 0 x0 x0 = F x0 ; (B.15)
compute
2
0 = x0 2
: (B.16)
Store x0 and 0:

4. For k = 0; 1; 2:::::kmax

(a) Compute the new iterate


xk+1 = xk + xk ; (B.17)
evaluate F xk+1 and solve

F 0 x0 v = F xk+1 (B.18)

(b) If k > 0
i. For i = 1; 2; :::k, compute
vT xi 1
= (B.19)
i 1

and set
v ! v+ xi (B.20)

135
(c) Compute
vT xk
k+1 = (B.21)
k
s
vT v
k = (B.22)
k

1
(d) If k > 2 stop; the algorithm failed to converge.
(e) Compute and store
v
xk+1 = (B.23)
1 k+1
2
k+1 = xk+1 (B.24)
2
p
(f) If k+1 stop. the solution is

xS = xk+1 + xk+1 (B.25)

(g) Set k ! k + 1 and go to step 4.

136
Appendix C

C++ listing for the


Miscellaneous Class

C.1 Miscellaneous.h
/******************************************************************************\
*
* File: Miscellaneous.h
* Creation date: April 25, 2009 08:11
* Latest update: May 21, 2009 11:34
* Author: Leslie G. Thompson
* XXXX
* Purpose: Declaration of class ’Miscellaneous’
* CB version: ClassBuilder Version 2.9 (PR523)
*
\******************************************************************************/
#ifndef _MISCELLANEOUS_H
#define _MISCELLANEOUS_H
//@START_USER1
//@END_USER1
/*@NOTE_238
Collection of miscellaneous (static) functions
*/
/// Collection of miscellaneous (static) functions
class Miscellaneous
{
//@START_USER2
//@END_USER2

public:
/// Constructor method.

137
Miscellaneous();
/// Destructor method.
virtual ~Miscellaneous();
/// Sorts a vector in ascending or descending order using a bubble sort
/// algorithm - suitable for small vectors
static void BubbleSort(IFLEXARRAY& v, int size, bool Ascending = true);
/// function strips comments from a data file and returns number of lines of data
static int const_strip_comments(const char* name,
const char* filebak = "data.bak");
/// Computes the inner product of two vectors of size n
static double InnerProduct(DFLEXARRAY x, D2FLEXARRAY& y, int iCol, int n);
/// Computes the inner product of two vectors of size n
static double InnerProduct(DFLEXARRAY x, DFLEXARRAY& y, int n);
/// Based on "Numerical Recipes" by Press, Flannery, Teukolsky and Vetterling
/** (Cambridge University Press) p. 90 Given an array XX of length N and a given
value X, returns a value J such that X is between XX(J) and XX(J+1). XX must be
monotonic, either increasing or decreasing. -1 or N-1 is returned to indicate
that X is out of range. initialize upper and lower limits. if we are not yet
done, compute a midpoint and replace either the lower limit or upper limit as
appropriate. */
static int locate(DFLEXARRAY& xx, double x, int n);
/// Computes the 2-Norm of a given array of size n
static double Norm2(DFLEXARRAY& v, int n);
/// Computes the 2-Norm of a given array of size n
static double Norm2(D2FLEXARRAY& v, int iCol, int n);
/// Given an ASCII file, read and return the integer value in the last line
static int ReadLastLineOfFile(const char* InputFile);
/// Replaces a designated character in a character array with blank
static void RemoveCharacterFromString(char c, char* CharArray,
int ArrayLength);
};
#endif // ndef _MISCELLANEOUS_H
#ifdef CB_INLINES
#ifndef _MISCELLANEOUS_H_INLINES
#define _MISCELLANEOUS_H_INLINES
//@START_USER3
//@END_USER3
#endif // ndef _MISCELLANEOUS_H_INLINES
#endif // def CB_INLINES

C.2 Miscellaneous.cpp
/******************************************************************************\
*

138
* File: Miscellaneous.cpp
* Creation date: April 25, 2009 08:11
* Latest update: May 21, 2009 11:34
* Author: Leslie G. Thompson
\******************************************************************************/
//@START_USER1
//@END_USER1
#include "Miscellaneous.h"
//@START_USER2
#include <string.h>
//@END_USER2
/*@NOTE_243
Constructor method.
*/
Miscellaneous::Miscellaneous() //@INIT_243
{//@CODE_243
}//@CODE_243
/*@NOTE_239
Destructor method.
*/
Miscellaneous::~Miscellaneous()
{//@CODE_239
}//@CODE_239
/*@NOTE_3218
Sorts a vector in ascending or descending order using a bubble sort
algorithm - suitable for small vectors
*/
void Miscellaneous::BubbleSort(IFLEXARRAY& v, int size, bool Ascending)
{//@CODE_3218
int i, n;
n = size;
bool sorted = false;
while (!sorted)
{
sorted = true;
if (Ascending)
{
for (i = 0; i < n - 1; i++ )
{
if(v[i] > v[i+1] )
{
int temp = v[i];
v[i] = v[i+1];
v[i+1] = temp;
sorted = false;
}

139
}
// largest element is at the bottom
}else{
for (i = 0; i < n; i++ )
{
if(v[i] < v[i+1] )
{
int temp = v[i];
v[i] = v[i+1];
v[i+1] = temp;
sorted = false;
}
}
// smallest element is at the bottom
}
n = n - 1;
}
}//@CODE_3218
/*@NOTE_247
function strips comments from a data file and returns number of lines of data
*/
int Miscellaneous::const_strip_comments(const char* name, const char* filebak)
{//@CODE_247
// function strips comments from a data file and returns
// number of lines of data
// open input and output files
ifstream file1;
file1.open(name, ios_base::in);
ofstream file2;
file2.open(filebak, ios_base::out);
char ch[511]; // temporary data buffer
int count;
int nonBlank;
count = 0;
while (file1) { // read until end-of-file
file1.getline(ch, 511);
if(file1)
{
if (*ch != ’c’ && *ch != ’C’)
{ // write numeric data to DATA.BAK
int length = (int) strlen(ch);
nonBlank = 0;
for (int j = 0; j < length; j++)
{
// check to ensure that the line contains alphanumeric data
if (isalnum(int (ch[j])))

140
{
nonBlank++;
break;
}
}
if (nonBlank)
{
// remove commas from the line
RemoveCharacterFromString(’,’, ch, length);
file2 << ch << ’\n’;
count++;
}
} /* if ch */
}
} /* while ! file1 */
file1.close();
file2.close();
return count;
}//@CODE_247
/*@NOTE_1911
Computes the inner product of two vectors of size n
*/
double Miscellaneous::InnerProduct(DFLEXARRAY x, D2FLEXARRAY& y, int iCol,
int n)
{//@CODE_1911
double value = 0;
for (int i = 0; i < n; i++)
{
value += x[i] * y[iCol][i];
}
value /= n;
return value;
}//@CODE_1911
/*@NOTE_1916
Computes the inner product of two vectors of size n
*/
double Miscellaneous::InnerProduct(DFLEXARRAY x, DFLEXARRAY& y, int n)
{//@CODE_1916
double value = 0;
for (int i = 0; i < n; i++)
{
value += x[i] * y[i];
}
value /= n;
return value;
}//@CODE_1916

141
/*@NOTE_3386
Based on "Numerical Recipes" by Press, Flannery, Teukolsky and Vetterling
(Cambridge University Press) p. 90 Given an array XX of length N and a given
value X, returns a value J such that X is between XX(J) and XX(J+1). XX must be
monotonic, either increasing or decreasing. -1 or N-1 is returned to indicate
that X is out of range. initialize upper and lower limits. if we are not yet
done, compute a midpoint and replace either the lower limit or upper limit as
appropriate.
*/
int Miscellaneous::locate(DFLEXARRAY& xx, double x, int n)
{//@CODE_3386
/* Based on "Numerical Recipes" by Press, Flannery, Teukolsky and
* Vetterling (Cambridge University Press) p. 90 Given an array XX of
* length N and a given value X, returns a value J such that X is between
* XX(J) and XX(J+1). XX must be monotonic, either increasing or
* decreasing. -1 or N-1 is returned to indicate that X is out of range.
* initialize upper and lower limits. if we are not yet done, compute a
* midpoint and replace either the lower limit or upper limit as
* appropriate. */
int jl = 0;
int ju = n - 1;
while (ju - jl > 1)
{
int jm = (ju + jl) / 2;
if ((xx[n - 1] > xx[0]) == (x > xx[jm]))
{
jl = jm;
} else {
ju = jm;
}
}
/* repeat until the test condition is satisfied, then set the output and
* return */
return jl;
}//@CODE_3386
/*@NOTE_1908
Computes the 2-Norm of a given array of size n
*/
double Miscellaneous::Norm2(DFLEXARRAY& v, int n)
{//@CODE_1908
double value = 0;
int i;
for (i = 0; i < n; i++)
{
value += v[i] * v[i];
}

142
value = sqrt(value / n);
return value;
}//@CODE_1908
/*@NOTE_1921
Computes the 2-Norm of a given array of size n
*/
double Miscellaneous::Norm2(D2FLEXARRAY& v, int iCol, int n)
{//@CODE_1921
double value = 0;
int i;
for (i = 0; i < n; i++)
{
value += v[iCol][i] * v[iCol][i];
}
value = sqrt(value / n);
return value;
}//@CODE_1921
/*@NOTE_3516
Given an ASCII file, read and return the integer value in the last line
*/
int Miscellaneous::ReadLastLineOfFile(const char* InputFile)
{//@CODE_3516
int value;
ifstream fin(InputFile, ios_base::in);
char ch[512], chold[512]; // temporary data buffer
while (fin) { // read until end-of-file
fin.getline(ch, 512);
if (strlen(ch))
{
strcpy(chold, ch);
}
}
char *StopString;
value = strtol(chold, &StopString, 10);
fin.close();
return value;
}//@CODE_3516
/*@NOTE_775
Replaces a designated character in a character array with blank
*/
void Miscellaneous::RemoveCharacterFromString(char c, char* CharArray,
int ArrayLength)
{//@CODE_775
int i;
for(i = 0; i < ArrayLength; i++)
{

143
if(CharArray[i] == c)
{
CharArray[i] = ’ ’;
}
}
}//@CODE_775

144

You might also like