You are on page 1of 319

Mathematical and Numerical Methods

for Reservoir Fluid Flow Simulation


Doctor Scientiarum thesis

Bjrn-Ove Heimsund
Department of Mathematics
University of Bergen

March 2005

Preface
This work presented herein constitutes my thesis for the partial fulfilment of
the requirements for the degree of Doctor Scientiarum at the University of
Bergen. The studies started in January 2002 and were conducted at both the
Department of Mathematics and the Centre for Integrated Petroleum Research.
Professor Magne S. Espedal has been the principal supervisor of my thesis,
and Professor Kenneth H. Karlsen has been the co-supervisor. Funding has
been provided by the Norwegian research council (NFR) within the program Computational mathematics in Applications (BeMatA) under the project
Robust Numerical Methods for Partial Differential Equations. Some additional
funding has been provided by the Centre for Integrated Petroleum Research.
The overall goal of the BeMatA project is to develop and analyse mathematical
models, numerical techniques, and method oriented software for solving problems
within science and technology. Under that umbrella, I have worked on a project to
develop robust numerical methods for reservoir fluid flow problems, with a focus
on emerging techniques for compositional fluids.
A model for reservoir fluid flow, called a reservoir simulator, provides a tool
for investigating the flow of fluids in the subsurface. In the oil industry, a reservoir simulator can be used to decide the optimal operating policy, or it can be
used to forecast future production. But such a tool can also be used within environmental studies, for instance by predicting impact of contaminants, performing
groundwater management, or remediation of polluted soil.
Reservoir simulation incorporates elements from all main branches of science:
physics, chemistry, geology, biology and mathematics. In this work, I have only
considered certain mathematical aspects which may be of interest to other mathematicians in the field of reservoir flows. The reader will probably notice some
discrepancies between the introductory part of the thesis and the attached papers
(apart from differences in notation). This is because I have found better and clearer
ways, and I wish to present these as well.

Outline of thesis
The thesis consists of three parts. In the first part an overview over the field
of reservoir flow modelling is provided, with emphasis on compositional fluids
and numerical methods. The second part deals with selected aspects of practical
simulation, e.g., software design and fast solvers. In the last part is a collection of
scientific papers which cover several facets of reservoir flows, both mathematical
and numerical.
Part I: Elementary reservoir flow modelling

Chapter 1 provides a broad overview over reservoir flow modelling, with an emphasis on oil recovery. The basics of mathematical modelling conservation
laws are introduced.
Then chapter 2 discusses the fundamental mathematical model for the flow of
fluids in a porous media (permeability, pressure and Darcys law). Classical oneand two-phase flow equations are derived.
These simple models are extended to the flow of multiple chemical species in
chapter 3. A large part of that chapter is devoted to the equilibrium calculations
for determining phase properties from pressure, temperature and composition. A
modern formulation of the classical black-oil model closes the chapter.
Numerical methods for these flow equations are supplied in chapter 4. We
distinguish between two classes; elliptic/parabolic and hyperbolic/parabolic, and
present numerical schemes for both classes.
Part II: Large scale simulation

Since the numerical solution of our flow models can be complicated, chapter 5
provides the outline of a flexible reservoir simulator software design. It is kept
general so that it may serve as a starting point for the development of specific
simulators.
To ensure high performance, parallel computers must often be used. To this
end, chapter 6 discusses domain decomposition parallelisation with an emphasis
on general, black-box type methods. In addition to the classical one-level Schwarz

methods, we present a novel multi-level approach based solely on communication


by boundary conditions. This makes it easier to design parallel codes, and can
offer high performance for typical reservoir flow problems.
Chapter 7 gives an overview over automatic history matching methods. History matching tries to determine uncertain reservoir data (porosity, permeability,
density, etc) to match with known reservoir data (measurements and production
history). The process can be done automatically by creating a loop around a reservoir simulator, and formulating the history matching as an optimisation process.
To ensure fast execution, efficient parameter representations are discussed.
Part III: Papers

Seven papers are included at the end of the thesis. Their content is summarised in
chapter 8, and chapter 9 outlines possible venues for future research work.
Paper A: A Parallel Eulerian-Lagrangian Localized Adjoint Method.
Accepted for publication in Advances in Water Resources.
Paper B: Adjoint methods are particle methods.
Draft manuscript.
Paper C: Multiscale Discontinuous Galerkin Methods for Elliptic Problems
with Multiple Scales.
Accepted for publication in Lecture Notes in Computational Science and
Engineering.
Paper D: Level set methods for a parameter identification problem.
Published in the book Analysis and optimization of differential systems,
pages 189200 by Kluwer Academic Publishers in 2003. Volume 121 of
International Federation for Information Processing (IFIP) series.
Paper E: On a class of ocean model instabilities that may occur when
applying small time steps, implicit methods, and low viscosities.
Published in Journal of Ocean Modelling, volume 7 (2004), pages 135144.
Paper F: A two-mesh superconvergence method with applications for
adaptivity.
Accepted for publication in AMS Contemporary Mathematics.
Paper G: High performance numerical libraries in Java.
Draft manuscript.

Acknowledgements
I would first like to thank my supervisors Magne S. Espedal and Kenneth H.
Karlsen for (perhaps unintentionally) giving me considerable leeway in how to
approach and conduct the research. As a result, I have been able to work on a
diverse selection of topics during my thesis.
I gratefully acknowledge both the financial support provided by the Norwegian
research council under project number 135420 (Robust Numerical Methods for
Partial Differential Equations), and the additional support furnished by the Centre
for Integrated Petroleum Research.
Rainer Helmig was my host during a three month research visit to the Institut
fur Wasserbau, Universitat Stuttgart in the spring of 2004. Thank you for kindling
my interest in mathematical modelling of reservoir flows, and for making my stay
a pleasant and useful one.
Thanks to Helge K. Dahle and Ivar Aavatsmark for many a useful conversation, and to Gunnar E. Fladmark and Erlend ian for the cooperation we had (and
have) on compositional reservoir flow simulation. Many have provided feedback
on this work, including Geir Terje Eigestad and Raymond Martinsen, and with
such help, any remaining faults are entirely my own.
Finally, I would like to thank my family for their support over the years. I
believe a creative work is as much a product of one self as that of ones closest.

Bjrn-Ove Heimsund
Bergen, March 2005.

Contents
I Elementary reservoir flow modelling
1

Reservoir flow modelling overview


1.1 Origin and migration of hydrocarbons
1.1.1 Recovery mechanisms . . . .
1.2 Mathematical modelling . . . . . . .
1.2.1 Conservation laws . . . . . .

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

3
3
5
6
7

Immiscible reservoir flows


2.1 The continuum scale .
2.2 Model parameters . . .
2.2.1 Permeability .
2.2.2 Pressure . . . .
2.2.3 Hysteresis . . .
2.3 Mathematical models .
2.3.1 One phase . . .
2.3.2 Two phases . .
2.3.3 Three phases .

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

11
11
12
13
15
16
17
18
20
24

.
.
.
.
.
.
.
.
.
.
.
.

27
28
28
32
34
35
36
37
39
41
44
45
50

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

Miscible reservoir flows


3.1 Conservation of mass, energy and volume .
3.1.1 Conservation of mass . . . . . . . .
3.1.2 Conservation of energy . . . . . . .
3.1.3 Volume balance . . . . . . . . . . .
3.1.4 System solution strategy . . . . . .
3.2 Thermodynamical equilibrium calculations
3.2.1 The laws of thermodynamics . . . .
3.2.2 Chemical potentials and fugacities .
3.2.3 Equations of state . . . . . . . . . .
3.2.4 Calculating the fugacity coefficients
3.2.5 Iterative flash algorithms . . . . . .
3.2.6 Volume derivatives . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

3.3

Black-oil compositional models . . . . . . . . .


3.3.1 Thermodynamics and mass conservation
3.3.2 Pressure and saturation equations . . . .
3.3.3 Volume factors and solubilities . . . . . .

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

4 Numerical methods
4.1 Preliminaries . . . . . . . . . . . . . . . . . . . . . . .
4.1.1 Solving the discretised equations . . . . . . . . .
4.2 Solving elliptic/parabolic problems . . . . . . . . . . . .
4.2.1 Integral formulation: Finite differences . . . . .
4.2.2 Variational formulation: Finite elements . . . . .
4.2.3 Saddle point formulation: Mixed finite elements
4.2.4 Comparisons . . . . . . . . . . . . . . . . . . .
4.3 Solving hyperbolic/parabolic problems . . . . . . . . . .
4.3.1 Hyperbolic formulations . . . . . . . . . . . . .
4.3.2 Eulerian formulation: Finite volumes . . . . . .
4.3.3 Lagrangian formulation: Characteristic methods

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

51
52
54
55

.
.
.
.
.
.
.
.
.
.
.

57
58
59
60
61
66
70
76
77
78
80
83

II Large scale simulation


5 Design of reservoir simulators
5.1 Foundations . . . . . . . . . . . . . . .
5.1.1 Programming environment . . .
5.1.2 Solution of linear equations . .
5.1.3 Solution of nonlinear equations
5.2 Simulator design . . . . . . . . . . . .
5.2.1 Fluid description . . . . . . . .
5.2.2 Modelling well performance . .
5.2.3 Geometry and mesh . . . . . .
5.2.4 Rock/fluid interaction . . . . .
5.2.5 Field module . . . . . . . . . .
5.2.6 Numerical computations . . . .
5.3 Related issues . . . . . . . . . . . . . .
5.3.1 Table lookup . . . . . . . . . .
5.3.2 Automatic differentiation . . . .
5.3.3 Input and output files . . . . . .

93
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

95
96
96
97
98
99
100
104
107
110
112
114
116
116
116
117

6 Parallelisation of reservoir simulators


119
6.1 Schwarz methods . . . . . . . . . . . . . . . . . . . . . . . . . . 120
6.1.1 Subdomain couplings . . . . . . . . . . . . . . . . . . . . 121

6.2

6.1.2 Convergence behaviour . . . . . . . . . . . . . . . . . . . 122


Multi-level extentions . . . . . . . . . . . . . . . . . . . . . . . . 124
6.2.1 Two-way couplings . . . . . . . . . . . . . . . . . . . . . 125

Parameter estimation
7.1 Parameter representation . . . . . . . . .
7.1.1 Coarse grid representation . . . .
7.1.2 Level set representation . . . . .
7.2 Parameter identification . . . . . . . . . .
7.2.1 Regularisation . . . . . . . . . .
7.2.2 Solving the optimisation problem

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

III Papers

127
128
129
129
131
131
133

137

Summary of the papers

139

Further work
149
9.1 Numerical methods . . . . . . . . . . . . . . . . . . . . . . . . . 149
9.2 Large scale simulations . . . . . . . . . . . . . . . . . . . . . . . 151

A A Parallel Eulerian-Lagrangian Localized Adjoint Method


A.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . .
A.2 Variational formulation . . . . . . . . . . . . . . . . . .
A.3 Numerical integration . . . . . . . . . . . . . . . . . . .
A.4 Parallelization . . . . . . . . . . . . . . . . . . . . . . .
A.4.1 Comparison with other methods . . . . . . . . .
A.4.2 Numerical result . . . . . . . . . . . . . . . . .
A.5 Concluding remarks . . . . . . . . . . . . . . . . . . . .
B Adjoint methods are particle methods
B.1 Introduction . . . . . . . . . . . . . . . . . .
B.2 A scalar equation . . . . . . . . . . . . . . .
B.3 Adjoint/particle relationship in the dual space
B.4 Waves in the primal space . . . . . . . . . . .
B.5 Examples of adjoint characteristics . . . . . .
B.5.1 Shocks: Buckley-Leverett . . . . . .
B.5.2 Rarefactions: Burgers . . . . . . . .
B.5.3 Other issues . . . . . . . . . . . . . .
B.6 Algorithm . . . . . . . . . . . . . . . . . . .
B.7 Numerical results . . . . . . . . . . . . . . .
B.7.1 Stability issues and artificial diffusion

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

153
155
155
157
159
161
162
164

.
.
.
.
.
.
.
.
.
.
.

165
167
167
169
170
172
172
174
176
177
179
180

B.7.2 Burgers equation . .


B.7.3 Buckley-Leverett . .
B.7.4 2D Buckley-Leverett
B.8 Concluding remarks . . . . .

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

181
183
183
185

C Multiscale Discontinuous Galerkin Methods for Elliptic Problems


187
C.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
C.2 Mathematical formulations . . . . . . . . . . . . . . . . . . . . . 191
C.2.1 Discontinuous Galerkin methods . . . . . . . . . . . . . . 191
C.2.2 Finite element methods vs. discontinuous Galerkin methods195
C.3 Multiscale methods for elliptic problems . . . . . . . . . . . . . . 196
C.3.1 The multiscale finite element method . . . . . . . . . . . 198
C.3.2 The mixed multiscale finite element method . . . . . . . . 199
C.3.3 A multiscale discontinuous Galerkin method . . . . . . . 200
C.3.4 On the selection of boundary conditions for the MsFEM . 201
C.4 Numerical results . . . . . . . . . . . . . . . . . . . . . . . . . . 202
C.4.1 Subscale oscillations . . . . . . . . . . . . . . . . . . . . 203
C.4.2 Random coefficients . . . . . . . . . . . . . . . . . . . . 204
C.5 Concluding remarks . . . . . . . . . . . . . . . . . . . . . . . . . 206
D Level set methods for a parameter identification problem
D.1 Introduction . . . . . . . . . . . . . . . . . . . . . . .
D.2 Level set methods . . . . . . . . . . . . . . . . . . . .
D.3 The parameter identification problem . . . . . . . . . .
D.3.1 Calculation of qi L . . . . . . . . . . . . . . .
D.3.2 Calculation of j L . . . . . . . . . . . . . .
D.3.3 Calculation of u L . . . . . . . . . . . . . . .
D.3.4 An algorithm of Lancelot type . . . . . . . . .
D.4 Numerical experiments . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

209
211
211
213
214
214
216
216
220

E On a class of ocean model instabilities


E.1 Introduction . . . . . . . . . . . .
E.2 Stability analysis . . . . . . . . .
E.3 Numerical experiment . . . . . .
E.4 Concluding remarks . . . . . . . .

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

223
225
225
227
232

.
.
.
.

235
237
237
239
241

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

F A two-mesh superconvergence method for adaptivity


F.1 Introduction . . . . . . . . . . . . . . . . . . . . .
F.2 The two-mesh superconvergence method . . . . . .
F.2.1 Mesh adaptivity . . . . . . . . . . . . . . .
F.3 Numerical results . . . . . . . . . . . . . . . . . .

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

F.4

F.3.1 Smooth problem . . . . . . . . . .


F.3.2 Discontinuous coefficients . . . . .
F.3.3 Corner singularity . . . . . . . . .
F.3.4 Mixed Dirichlet/Neumann problem
Concluding remarks . . . . . . . . . . . . .

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

G High performance numerical libraries in Java


G.1 Introduction . . . . . . . . . . . . . . . . . . . .
G.2 Low level functionality . . . . . . . . . . . . . .
G.3 Dense and structured sparse matrices . . . . . . .
G.3.1 Matrix structures in BLAS and LAPACK
G.3.2 Matrix hierarchy . . . . . . . . . . . . .
G.3.3 Matrix factorisations . . . . . . . . . . .
G.4 Unstructured sparse matrices . . . . . . . . . . .
G.4.1 Sparse structures . . . . . . . . . . . . .
G.4.2 Iterative solvers and preconditioners . . .
G.5 Distributed computing . . . . . . . . . . . . . .
G.5.1 Message passing package . . . . . . . .
G.5.2 Distributed matrices . . . . . . . . . . .
G.6 Summary . . . . . . . . . . . . . . . . . . . . .
Bibliography

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.

241
242
247
249
251

.
.
.
.
.
.
.
.
.
.
.
.
.

253
255
257
259
261
264
267
268
268
271
273
274
277
280
283

Part I
Elementary reservoir flow modelling

Chapter 1
Reservoir flow modelling overview
A subsurface reservoir is a trap in which fluids such as oil, gas and water have
accumulated over millions of years by migration from source rocks. The reservoir
rock is typically sedimentary in nature and consists of an interconnected porous
network where fluids may flow, subject to forces such as fluid pressure, capillarity
and gravity.
To recover the oil and gas, wells are drilled into the reservoir, some which
produce oil and other which inject water and gas to provide pressure support.
Since it is costly to drill and operate wells, it is desirable to optimize their number,
placement and operation in the reservoir. For this to be done, a good understanding
of the fluid dynamics in the reservoir is necessary.
In this chapter we provide a brief overview of the main oil/gas recovery mechanisms and where mathematical flow modelling is useful. Later chapters will then
provide the actual flow models for the types of problems discussed herein, and
supplement these with suitable numerical methods. See [237, 207, 123, 112] for
more in-depth information.

1.1

Origin and migration of hydrocarbons

Oils and gases have complex origins, both inorganic and organic. Chemical reactions between carbon containing substances and water can form hydrocarbons,
primarily methane. But the amount of hydrocarbon generated is usually small
compared to the organic generation. The organic origin is from continuous sedimentation of dead plants and animals. At shallow subsurface conditions, bacterial
decay produces methane, water and carbon dioxide, and is primarily a reduction
of the relative oxygen content, leaving hydrocarbon rich kerogen substances. This
process is termed diagenesis.
Kerogen is a family of complex cyclic hydrocarbon molecules bonded with

Reservoir flow modelling overview


Producer

Injector
Reservoir
Gas
Oil and Gas

Water
Seal
Carrier bed
Source rock
Figure 1.1: Hydrocarbons are formed from organic matter in source rock which
has been subjected to high pressure and temperature. As the resulting oil and gas
phases are lighter than water, they are driven through the carrier bed and trapped
in the reservoir. A typical recovery strategy is to inject water below the oil/gas cap
to provide continual pressure support so that the production well can recover as
much hydrocarbons as possible. The horizontal scale can be as large as 100 km,
while the vertical scale can be as small as a few hundred meters.
oxygen, nitrogen and sulfur. Deeper in the subsurface, and at temperatures
between 60 C 120C, kerogen cracks into heavier hydrocarbon components
which form the oil phase, while gas is formed deeper, and at temperatures between
120C 225 C. This process, catagenesis, is believed to be the largest source of
hydrocarbons.
At larger depths, and temperatures excessing 225 C, the kerogen has expelled
most of the hydrocarbons, and the remainder cracks into methane until no hydrogen is left. The remaining carbon forms graphite. This final stage is called
metagenesis.
The generation of hydrocarbons takes place in the source rocks, which are
usually buried far below the surface, see figure 1.1. Primary migration is the
movement of hydrocarbons from the source rocks into the permeable carrier beds,
but the exact nature of this migration is still not fully understood. Once in the
carrier beds, oil and gas will migrate through a water saturated medium by a process termed secondary migration. As oil and gas is less dense than water, the
gravity forces will drive oil and gas above the water and upwards in the reservoir by buoyancy, but during the migration the reservoir is undergoing gradual
compaction which may either limit the upward motion, or force the hydrocarbons
downwards. In addition, capillary and hydrodynamic forces can act against or

1.1 Origin and migration of hydrocarbons

with the migration, or they may redirect it.


Eventually, the oil and gas will be trapped in a reservoir cap, and an accumulation occurs. Gas, being the lightest, is at the top. A mixture of oil and gas exists
below the gas, with a water aquifer on the bottom. Since the reservoir was originally filled with water, the upper parts of the reservoir will still contain residual
traces of water. In the absence of a trap, the oil and gas will leak onto the surface.

1.1.1 Recovery mechanisms


The pressure on the fluids in the reservoir can be very high due to the large top
overburden. By drilling a production well into the oil saturated part of the reservoir, the oil will naturally enter the well since the well pressure is kept lower than
the reservoir pressure. This is called primary production and is the most widely
used recovery method. As oil is drained from the reservoir, the oil pressure can be
maintained by the other fluids:
Water drive The oil and gas exist as a cap above a much larger water reservoir.
When the oil is being produced, this water will flow into the pores previously filled with oil and be a mechanism that maintains pressure support.
Gas expansion Gas is highly compressible, and its volume increases as the reservoir fluid pressure decreases. The gas cap above the oil cap can then displace oil towards the production well.
Gas formation At very high pressures, gas dissolves into oleic liquid (oil). A
lowering of pressure will cause the gas to bubble out of the oil and results
in gas expansion.
However, primary production is very inefficient, resulting in at most a recovery
of 20-25% of the oil and gas in the reservoir, and often far less. To alleviate
this, secondary production uses techniques such as horizontal wells aligned to
the phase layers and/or fluid injecting wells. This provides additional pressure
support and the possibility to place wells along fluid or rock regions. Combined,
this results in a much more efficient displacement of the oil towards the production
wells. A successful injection strategy can result in recovery of more than 50% of
the oil in the reservoir.
There are several reasons for not being able to recover all the oil and gas by
secondary production. One reason is due to the heterogeneous nature of a reservoir. In the parts with larger and better connected pore networks, the fluids flow
much more easily than in finer networks of small pores or poorly connected networks. As a result the injected water establishes a preferred flow pattern through

Reservoir flow modelling overview

the coarse pores, and oil/gas in the finer pores is not pushed towards the production
well.
The hydrocarbon fluids can also be rather immobile, either because of large
viscosity in heavier hydrocarbon mixtures such as asphaltenes, or because of capillary forces binding fluids to the host rock. As the relative saturation of the oil
decreases, the capillary effects can become stronger and trap the oil in place.
Tertiary production is a set of methods designed to address these issues. Some
of the well-known techniques are:
Polymer injection We may add polymer substances to injected water. The polymers increase the viscosity of the water and can also block larger pores.
Consequently, the injected water must chose a different path, and can then
displace oil trapped in smaller pores.
Miscible displacement Gaseous fluids consisting of components such as carbon
dioxide, nitrogen and methane can mix with the oil and form a single phase.
This single phase flow regime between the oil and the gas phase has reduced
interfacial tensions and can result in a more effective displacement.
Surfactant flooding Surfactants are complex chemical compounds designed to
reduce the interfacial tensions between oil and water, resulting in higher
total phase mobility.
Thermal flooding The viscosity of oil can be reduced by heating. Injection of
hot water or steam is a common method. Other methods include igniting
the most viscous of the hydrocarbon banks and carefully controlling the
oxygen supply.
These methods tend to be expensive and their precise effect on the reservoir flow
performance can be hard to ascertain a priori. Consequently, tertiary production
methods induce a fair amount of risk, but still methods such as reinjection of gas
(for miscible displacement) and steam injection are becoming more mainstream.

1.2 Mathematical modelling


It should be clear that the different reservoir flow problems can be highly complex,
consisting of a multitude of different physical effects. However, an understanding
is necessary so that different production scenarios and reservoir interpretations
may be tested. To some degree, this can be done by laboratory experiments, but
these cannot be very large and tend to be expensive to conduct. Instead, the use of
mathematical models has become progressively more prominent in reservoir flow
problems.

1.2 Mathematical modelling

~n

Figure 1.2: A control volume with surface . Every point on the surface has an
outward normal vector ~n.
Using simple mathematical models with analytical solutions, engineers can
provide basic performance predictions. However, for the more advanced models
analytical answers may not be available. Instead numerical methods for simulating the models have become popular, especially with the advent of fast computers.
But there are still trade-offs. In particular, the more detailed the mathematical model, the slower the computer can calculate a solution. Therefore we must
seek fast numerical schemes combined with suitable mathematical models for the
reservoir. And even the geological description of the reservoir may be riddled
with uncertainty, leading us to perform multiple realizations and model calibration based on field production data.

1.2.1 Conservation laws


A cornerstone of mathematical modelling of physical phenomena is the principle
of conservation. Consider a quantity u contained in a fixed control volume (see
figure 1.2). The change of u inside is caused by a boundary flux F~ over
and the possible amount Q of u being generated within . In integral form, the
conservation of u reads
Z
Z
Z
u
(1.1)
dV + F~ n~ dS = Q dV .

Q is here positive for a source, and negative for a sink. Using Gauss divergence
theorem, we may convert the boundary flux integral into a volume integral:
Z
Z
Z
u
~
dV + F dV =
Q dV
(1.2)
t


Z 
u
+ F~ Q dV = 0.
(1.3)
t
Since this must hold for any size of , we may drop the integrals to obtain the
conservation law in differential form:
u
+ F~ = Q.
t

(1.4)

Reservoir flow modelling overview

In reservoir flow modelling the conserved quantity can be the mass of a phase
(water, oil, gas), the mass of a molecular substance, or the thermal energy. We
shall in the following chapters give expressions for u and its flux F~ , and then
provide methods which solve equation (1.4) accurately and efficiently. A topic
we will not discuss in any detail, is the initial generation of a simulation grid (i.e.,
the set of connected control volumes). To accurately capture important geological
features, these grids may be very large, and the need for speed in a numerical
solution scheme is obvious. An actual simulation grid is shown in figure 1.3.

1.2 Mathematical modelling

Figure 1.3: A simulation grid for the PUNQ (Production forecasting with Uncertainty Quantification) model by Elf Exploration, viewed from the top. Oil and gas
will be trapped in the dome in the center of the grid, with water around. Totally
there are 1761 control volumes (cells) in five layers, and each cell has a width and
length of 180m, and a height of around 5m.

Chapter 2
Immiscible reservoir flows
For immiscible fluids the phases do not mix or exchange mass between each other.
This constraint is often quite reasonable when considering oil and water flows at
constant temperature, but with gases or at high temperatures mixing does occur.
However, the equations derived in this chapter will be extended in the next chapter
for miscible non-isothermal reservoir flows.
In this chapter we will briefly cover the primary physical and geological parameters influencing fluid flows in porous media. Then we introduce Darcys law,
which is an empirical relation giving the effective fluid velocity. With this we
provide mathematical models for the immiscible flows of one, two and three
phases along with some common simplifications. Further information can be
found in the books [139, 215, 166, 220, 15, 23, 88, 61].

2.1

The continuum scale

The flow of reservoir fluids in porous media can be described at several different
scales, from the smallest molecular scale up to an averaged continuum scale. For
the purpose of large-scale numerical simulations, a molecular description is too
demanding due to the large number of molecules in even the smallest amount of
fluids (a gram of carbon contains over 1022 atoms).
A continuum scale description of fluids averages the molar masses so that
we get a continuous body of fluid, and its motion is governed by forces acting
between different fluid bodies and the reservoir medium itself. This is all well
described by the Navier-Stokes equations, which are much used for surface and
atmospheric flows. However, when we are dealing with the subsurface we do not
know the actual geometry of the problem as measuring equipment for determining
the pore-networks are still not comprehensive, and even if they were, the geometry
of the pore networks is too complex for mathematical/numerical modelling.

12

Immiscible reservoir flows

REV

Vm
V
VM
Figure 2.1: Volume averaged porosity as a function of the averaging volume size.
Consequently, a reservoir level continuum model averages not just the fluids,
but the whole control volume state (geometry and fluids). Therefore we describe
volume-average properties such as phase saturations, permeabilities, porosities,
etc, which are more amendable to measurements and experiments. The size V
of the averaging volume (also called the representative elementary volume, REV)
must be chosen such that it is larger than the microscopic length Vm , while smaller
than the large scale variations VM :
Vm V VM .

(2.1)

This ensures that the significant microscale variations are smoothed out, and also
ensures that the large scale heterogeneities are preserved, see figure 2.1.
A reservoir model is built from multiple control volumes V , and the larger
their size, the smaller the number of them. In upscaling, the size V is taken to
be of order O(VM ), and special techniques must be taken so that the subscale
information is not lost. This is itself a large topic [226], and we shall briefly
consider it later when discussing numerical solution methods.

2.2 Model parameters


We now describe some of the parameters and variables in a reservoir flow model
in context of the continuum scale. A reservoir is a porous medium, and the ratio
between the size V of an REV and the connected pore volume Vp (i.e., the space
where the fluids may flow) within it is the porosity
=

Vp
.
V

(2.2)

2.2 Model parameters

13

te
m

So

So

Sr

Sg = 1

m
ste
=

Sg

Sr

sy

W
at
er
/g

il

as
s

ys

/o
as
All phases mobile

Sg

Water/oil system

r
Sw = 1 So = So

Sw = Swr So = 1

Figure 2.2: Three phase system diagram. If none of the phase saturations are at
a residual level, we have a full three phase case, but if one phase saturation is
residual it reduces into a two-phase problem. It may also further reduce into a
single phase system (the corners of the triangle).
In the pore space, the different fluid phases such as oil, water and gas exist, each
with their own volume. The phase saturations are
S =

V
,
Vp

= w, o, g,

(2.3)

where the subscripts denote the phases water (w), oil (o) and gas (g), respectively.
Since the pores are always fully saturated, we must have
X
S = 1.
(2.4)

We have implicitly assumed this summation to be over all the phases.

2.2.1 Permeability


The hydraulic conductivity tensor m2/Pa s describes the influence of the fluid
flow density (flow velocity), and is given as
and rock properties on the volumetric
kr
.
(2.5)

 
Here, [Pa s] is the phase viscosity, and K m2 represents the intrinsic or abso K is typically a spatially dependent
lute permeability of the given porous medium.

= K,

14

Immiscible reservoir flows

tensor as the pores have a preferred flow direction and may be (nearly) sealed in
other directions. By Onsagers principle [91], this tensor must always be symmetric and positive definite to ensure a physical consistent conductivity.
The quantity kr [0, 1] is the relative permeability of phase , which depends
on all the phase saturations S . If only a single phase is present, its relative permeability is 1, but when multiple phases flow in a pore, they interfere with each
other and their relative permeabilities decrease. Since kr 0 faster than S 0,
phase gets a zero mobility at a residual saturation Sr > 0. Figure 2.3 illustrates
this by showing that phases with a too low saturation are immobilised.
Single-phase experiments can provide the fluid viscosity , see [227, Chapter
9] and [218, Chapters 3 and 11]. Once the viscosity is known, we can measure the
permeability of a rock species by single-phase flooding experiments. But for the
relative permeabilities we must resort to multiphase experiments by considering
pairs of phases. For each pair of phases, one phase will wet the rock more than the
other phase, and that phase will be referred to as the wetting phase ( = w). The
other phase is then the non-wetting phase ( = n). Normally, water is the wetting
phase in a water-oil system, and oil is the wetting phase in a oil-gas system. For a
two-phase system, we can eliminate the non-wetting phase saturation by
Sw + Sn = 1 Sn = 1 Sw .

(2.6)

Two-phase experiments can now provide two relative permeabilities as functions


of Sw :
krw = krw (Sw ), krn = krn (Sw ).
(2.7)
It is also possible to extend such experiments to three phases, keeping the third
phase saturation constant and varying the other two. This would yield the dependencies
g
g
krw = krw (Sw , So ) , kr = kr (Sw , So ) , kro = kro (Sw , So ) .
(2.8)
Here we use the fact that the saturations sum to one, and Sg is not needed. However, such three phase experiments can be very difficult to conduct.
Some attempts at providing analytical relative permeability functions have
been done. For two-phase problems, Brooks-Corey [49] and Van Genuchten [121]
have suggested some expressions depending only on a few empirical tuning parameters, see figure 2.3. Furthermore, experiments by Lewis and Leverett [177]
have shown that the relative permeability of water is independent on the relative
saturations of gas and oil, so for the three phase case we may assume
krw = krw (Sw ).

(2.9)

For oil and gas three-phase relative permeability functions it has been common to
use the relationships provided by Stone [249, 250]. He built relative permeability
go
functions by a scaled product of the two-phase functions krow and kr . See the
above references for details.

2.2 Model parameters


1

15

Relative permeability

10

0.8

0.6

0.4

0.2

0
0

0.5
Sw

0
0

Capillary pressure

0.5

Sw

Figure 2.3: Some idealised relative permeability and capillary pressure curves.
The blue curves are for the Brooks-Corey model, while the red ones illustrate
the Van Genuchten model, both with some typical parameters. For the relative
permeability, the dotted curves are for the non-wetting phase, while the solid are
for the wetting phase.

2.2.2 Pressure
The phase pressure p [Pa] can be related to the phase density [kg/m3 ] through
the compressibility c [1/Pa]:
1
= c .
(2.10)
p
Ideal fluids have a constant compressibility, so equation (2.10) may be integrated
to obtain

 


(2.11)
ln 0 = c p p0 , p0 = 0 ,



(2.12)
= 0 exp c p p0 .
A special case is that of incompressible fluids with c = 0. Then equation (2.12)
becomes
= 0 .
(2.13)
Real fluids have more complicated pressure/density relationships given by equations of state. We shall return to this in Chapter 3.
Due to interfacial tensions between the different fluids and the rock matrix,
the pressure in the wetting phase is smaller than the pressure in the non-wetting
phase. This difference is the capillary pressure, and it is always at least a function
of saturation:
pc (Sw ) = pn pw .
(2.14)
Likewise, a capillary pressure function is needed to express the third pressure for

16

Immiscible reservoir flows

a three phase problem, so we have


pow
c (Sw , So ) = po pw ,
go
pc (Sw , So ) = pg po .

(2.15)
(2.16)

In addition to the development of analytical relative permeability functions,


analytical capillary pressure functions are needed. For two-phase problems it is
here common to use the simple relations provided by either Brooks-Corey or Van
Genuchten. As for the relative permeability, these depend on a couple of empirical
constants.
Due to the difficulty of correctly determining these functions, attempts have
been made at defining a scaling factor of a given reference capillary pressure
curve, so that capillary pressures for any types of rocks and fluids can be found.
The most prominent has been the Leverett J-function [176], but the large variations in rock and fluid compositions have limited this approach.
Parker [213] has tried to combine two-phase capillary pressure curves to threephase problems in a manner similar to Stones approach for relative permeability
functions. However, the large uncertainties do lead to a preference for empirical
relations instead.

2.2.3 Hysteresis
The capillary pressure and relative permeability relationships have so far been
assumed to only depend on the saturations, but experiments show that they are
also dependent on the flow process itself. A two-phase problem may then have
distinct capillary pressure / relative permeability curves when water is displaced
instead of oil. This is referred to as hysteresis, and makes these parameters history
dependent.
When a process is reversed, we have to switch between different curves. Since
the process is smooth, intermediary scanning curves connecting the two curves are
introduced, see figure 2.4. Nested scanning curves may have to be introduced if
there are multiple reversions in a short time span, but we will not provide details
on their construction. See instead [242, 164, 103].
More physically correct methods treat the capillary pressure saturation relationships to be directly flow dependent, typically [135]
Sw
, > 0,
(2.17)
t
where is an empirical parameter that may be dependent on Sw . During drainage
processes, the change in Sw will be positive and thus the pressure in the nonwetting phase will be relatively larger than the wetting phase pressure when compared to the = 0 case. This may aid in the oil displacement process.
pc (Sw ) = pn pw

2.3 Mathematical models

17

pc

B
Sw
Figure 2.4: Capillary pressure hysteresis for a two-phase problem. The blue curve
is used for drainage (reduction of oil saturation) and the red for imbibition (increase of oil saturation). If the process changes from imbibition to drainage at
A, a scanning curve is followed instead of the primary drainage curve. The same
argument applies at B if the process changes from drainage to imbibition.
The opposite effect occurs if there is an imbibition process (decrease of Sw ).
Then pn becomes relatively smaller and the wetting phase is more rapidly displaced where there are large changes in Sw .
While the hysteretic and dynamic effects in capillary pressure and relative permeability can be significant in some complex flow processes, we shall not discuss
them further in our mathematical models. However, the modification necessary
to incorporate these effects into a numerical model is usually minor, albeit it may
make the model harder to solve.

2.3

Mathematical models

The fundamental law of fluid flow in a porous medium is Darcys law. It gives the
effective flow velocity across a representative elementary volume and thus does
not describe the intrinsic particle velocity, which is typically larger. In differential
form, the law states that the phase volumetric flow density u~ (flow velocity) is
given by
u~ = p .
(2.18)

The equation states that phase will move from high pressure to the regions of
lower pressure, and the velocity is dependent on the medium and phase conductivities. However, since is a tensor, the actual direction of the flow may not

18

Immiscible reservoir flows

necessarily be directly towards the lowest phase pressure.


It is common to extend Darcys law with gravity effects. Let g = 9.81m/s2 be
the gravity acceleration and h(x, y, z) the reservoir height above some reference
plane. Typically h = z when the z axis points upwards. Then
u~ = (p + h) ,
(2.19)

with = g being the specific gravity of phase .


Originally, Darcys law was derived experimentally [90] and was thus considered an empirical law. Derivations of Darcys law based on volume averaging
of the Navier-Stokes momentum equations are given in [30, 273, 274, 31] and
also in [134]. The assumptions needed for the derivation of Darcys law include
low flow speeds and that the pore/fluid friction is a dominating force acting on the
fluid. Also, the porous medium is assumed to be rigid and not compacted due to
fluid flow.
We can now use a conservation law to describe how the phases flow. Starting
from equation (1.4):
u
+ F~ = Q.
(2.20)
t
We have here that the conserved quantity is mass per unit volume:
u = S .

(2.21)

The flux is simply mass density times the velocity:


F~ = u~ = (p + h) .
(2.22)

For each phase we may have distinct sources, so Q = q [kg/s m3 ]. Inserting these
back into the conservation law (2.20) gives

( S )
(p + h) = q .
t

(2.23)

2.3.1 One phase


When only a single phase is present, equation (2.23), with appropriate boundary
and initial conditions, fully describe the subsurface flow. Then S = 1 and the
phase subscripts may be dropped. The conservation law becomes

()
(p + h) = q.
t

(2.24)

No capillary pressure relationships or relative permeabilities are needed, and only


the phase pressure p and its density are unknown. Their determination depends
on the fluid compressibility.

2.3 Mathematical models

19

Incompressible fluid

For an incompressible fluid, is constant. We can therefore define the piezometric


head by
= p + gh,
(2.25)
so that
= p + gh + gh
= p + gh
= p + h.

(2.26)
(2.27)
(2.28)

The flow equation is simplified into


q

= .
t

(2.29)

Assuming the porosity to be constant in time yields


q
= .

(2.30)

This is referred to as a standard elliptic equation.


Compressible fluid

For a compressible fluid, equation (2.12) gives the pressure/density relationship


p =

1
.
c

(2.31)

This is then inserted into equation (2.24) to eliminate the pressure, and we find
the following equation which can be solved for the density:


1
()

+ h = q.
(2.32)
t
c
This may be significantly simplified by assuming horizontal flow (h = ~0) and
time-constant porosity:

(2.33)
= q.
t
c
This is a standard parabolic type of equation, and is similar to the heat equation
[111, Chapter 2].

20

Immiscible reservoir flows

2.3.2 Two phases


There is now one equation (2.23) for each phase. Labelling the phases = w
(wetting) and = n (non-wetting), we obtain the equations

(w Sw )
w w (pw + w h) = qw ,
t


(n Sn )
n n (pn + n h) = qn.
t

(2.34)
(2.35)

The basic constitutive relations for pressure and saturation are


pc = pn pw ,
Sn = 1 Sw ,

(2.36)
(2.37)

and some unspecified equation of state is used for the densities. In the following
we shall first find an equation for the wetting phase pressure pw . Then a saturation
equation for Sw will be provided. By our constitutive relationships Sn and pn are
then automatically found.
Pressure equation

Dividing equation (2.23) by and expanding the time-derivative yields


1 ( S ) 1
q
,
+ ( u~ ) =

S S 1
q
S
+
+
+ ( u~ ) =
.
t
t
t

(2.38)
(2.39)

Summation of this with = w and = n, and using Sw + Sn = 1 gives




1
1
qw qn
Sw w Sn n

+ (w u~w ) + (n u~n ) =
+
+
+ . (2.40)
t
w t
n t
w
n
w n
Notice that the time-derivatives of the saturations have cancelled out. The porosity
and density derivatives are transformed into pressure derivatives by applying the
chain rule;

pw
=
,
t
pw t
w pw
w
=
,
t
pw t


n
n pn n pw pc
.
=
=
+
t
pn t
pn t
t

(2.41)
(2.42)
(2.43)

2.3 Mathematical models

21

Back substitution gives the water pressure equation for pw :


cT

pc 1
1
qw qn
pw
+ Sn cn
+ (w u~w ) + (n u~n ) =
+ ,
t
t w
n
w n

(2.44)

where we have defined the total compressibility cT to be


cT =

1
+ Sw cw + Sn cn ,
pw

c =

1
.
p

(2.45)

The phase compressibilities cw and cn are the same as in equation (2.10).


In (2.44) and in all later pressure equations, we choose the wetting phase pressure pw as the pressure variable. This choice is somewhat arbitrary, as the capillary forces make it possible to use a non-wetting phase pressure instead. Such
approaches are common in the oil industry [235, 78, 79, 77]. Other possibilities
include averaged or global (total) pressure [64, 112].
Saturation equation

Once equation (2.44) has been solved for pw , the Darcy velocity u~w is found:
u~w = w (pw + w h) .

Then we can solve for Sw by its conservation law


(w Sw )
+ (w u~w ) = qw .
t

(2.46)

(2.47)

However, there are some other common saturation equations based on total fluid
velocity u~T . Notice that we can rewrite u~n in terms of u~w as
u~n =

n
u~w n pc + n (w n )h.
w

(2.48)

Then the total volumetric flow density u~T = u~w + u~n is


n
u~T = u~w + u~w n pc + n (w n )h
w



n
u~w n pc + n (w n )h,
=
1+
w

(2.49)
(2.50)

which is solved for u~w :


u~w =

w
(~
uT + n pc n (w n )h) .
n + w

(2.51)

22

Immiscible reservoir flows


1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0

0.1

0.2

0.3

0.4

0.5

Sw

0.6

0.7

0.8

0.9

Figure 2.5: The fractional flow function fw (Sw ) of equation (2.54). The phase viscosities are both set to unity, and we have used the relative permeability functions
from figure 2.3. Blue curve is for Brooks-Corey, and red for Van Genuchten.
Substituting this into the conservation law for the wetting phase gives


(w Sw )
w
+ w
(~
uT + n pc n (w n )h) = qw .
t
n + w

(2.52)

Note that the phase conductivities n and w are directly dependent on Sw , while

pc
Sw .
(2.53)
pc =
Sw
By now defining the fractional flow function
fw (Sw ) =

w
,
n + w

the saturation equation is obtained:





(w Sw )
pc
+ w fw u~T + n
Sw n (w n )h
= qw .
t
Sw

(2.54)

(2.55)

The Buckley-Leverett problem

We will now make some simplifying assumptions to find a set of pressure/saturation equations amendable to analytical solution procedures and thus popular as
reference solutions for numerical schemes. The simplification proceeds by first
assuming that
the two fluids are incompressible,

2.3 Mathematical models

23

there are no sources or sinks, and


the porosity does not change with pressure or time.
The pressure equation (2.44) simplifies to
u~w + u~n = 0

u~T = 0,

(2.56)
(2.57)

and the saturation equation (2.55) turns into


 

pc
Sw
+ fw u~T + n
Sw n (w n )h
= 0.

t
Sw

(2.58)

Expanding the first term of the flux and using equation (2.57) gives
(fw u~T ) = fw u~T + u~T fw = u~T fw .

(2.59)

Then equation (2.58) becomes




 p
Sw
c

= 0.
Sw (w n )h
+ u~T fw (Sw ) + fw n
t
Sw

(2.60)

This is known as the McWhorter saturation equation [192], and is a nonlinear


parabolic equation in Sw . Applying the assumption that
capillary forces are negligible,
we may neglect pc /Sw , and equation (2.60) simplifies to the Buckley-Leverett
equation


Sw

+ u~T fw (Sw ) fw n (w n )h = 0.
(2.61)
t

See [133, 132] for more details. The classical Buckley-Leverett problem [51] is
usually formulated without gravity:

Sw
+ u~T fw (Sw ) = 0.
t

(2.62)

This equation is a nonlinear hyperbolic equation, and it is coupled to the elliptic


equation (2.57) for the total velocity.

24

Immiscible reservoir flows

2.3.3 Three phases


We briefly consider the simultaneous flow of the three phases, water, oil and gas.
The pores are assumed to be completely filled by fluids:
Sw + So + Sg = 1 Sw = 1 So Sg .

(2.63)

Next, the three-phase capillary pressure relationships (2.15)-(2.16) can be used to


find the auxiliary phase pressures
po = pw + pow
c ,
go
go
pg = po + pc = pw + pow
c + pc .

(2.64)
(2.65)

For notational convenience, we introduce


pwc = 0,
poc = pow
c ,
g
go
pc = pc + pow
c .

(2.66)
(2.67)
(2.68)

This allows us to write the Darcy velocity for each phase as



u~ = pw + pc + h .

(2.69)

Conservation laws (2.23) for each of the three phases are then obtained:
w (1 So Sg )



w w (pw + w h) = qw ,
t




(o So )
= qo ,
o o pw + poc + o h
t



(g Sg )
g
g g pw + pc + g h
= qg .
t

(2.70)
(2.71)
(2.72)

A pressure equation can be formulated by summing these equations divided by


their respective phase densities. This will cancel out all time derivatives in the
saturations S , just as we saw for the two phase case.
Total velocity

As earlier, we can now solve for two phase saturations using any two of the three
equations (2.70)-(2.72). However, we shall also provide an alternative formulation based on the total phase velocity [246], as this will prove useful in certain

2.3 Mathematical models

25

numerical methods later. Using the Darcy velocity (2.69), the total three phase
velocity is
X
u~T =
u~
(2.73)


K pw + pc + w h

X
X
= T Kpw +
Kpc + Kh
,

where T =

. Solving for Kpw yields

!
X
X
1
u~T Kh

Kpw =
Kpc .
T

(2.74)
(2.75)

(2.76)

Here, is an auxiliary phase index like . Substituting equation (2.76) for Kpw

into equation (2.69) gives


!
X
X

u~ = f u~T + Kh
( ) +
K pc pc
,
(2.77)

where f = /T is the three phase fractional flow function.


We will not provide any further details because the three phase formulation
assumes no interphase mass transfer. This is particularly aggravating since it is
known that there can be significant miscibility between oil and gas. So while this
three phase formulation is seldomly used, the formulation for the total velocity
will be useful later.

Chapter 3
Miscible reservoir flows
In the last chapter we assumed no mass transfer between the phases. This assumption is mostly valid for two phase flows of water and oil, which is often the case
with primary and secondary production mechanisms. However, it is well known
that gas may boil out of the oil phase as the pressure drops, so we can end up with
three phases and mass transfers. Furthermore, in tertiary production, mass transfer and compositional effects are essential to model correctly as they may become
the driving mechanisms for the flow.
A typical reservoir fluid consists of hundreds of distinct chemical components.
These include inorganic compounds such as helium, argon, krypton, radon, nitrogen and carbon dioxide, and the more organic compounds of hydrogen gas, hydrogen sulfide, and of course the hydrocarbons themselves. It is the hydrocarbons
which are of commercial interest while the others may have adverse effects, particularly hydrogen sulfides which seriously damage production equipment. The
hydrocarbons can be subdivided into three groups:
Alkanes These are simple chained hydrocarbon segments, possibly with
branches (iso-alkanes). All bonds are simple electron bonds. Methane, ethane, propane and butane are common alkanes and are typically gaseous at
surface conditions. Heavier alkanes include pentane, hexane, heptane etc.,
and these are instead usually in the liquid phase.
Cyclo-alkanes are hydrocarbons with simple bonds and ring structures of five or
six carbon atoms and bonded hydrogen. Some common cyclo-alkanes are
cyclopentane and cyclohexane.
Arenes Ring structures with double bounds between the carbon atoms are called
arenes. They tend to be found in heavier oils, with benzene and toluene
being the most common aromatic molecules.

28

Miscible reservoir flows

All these components may exist in a multitude of phases. We have already mentioned the water, oil and gas phases, and typically hydrocarbons do not mix (easily) with water. Other phases include solidified material (asphalt, tar, wax), which
cause problems for flows in reservoir pipes, gas condensate, which is gaseous
in the reservoir but condenses into liquid at surface conditions, and gas hydrates
which are frozen mixtures of water and lighter hydrocarbons.
In this chapter we will present general conservation laws for mass, energy
and volume suitable for this compositional setup. We include energy since the
interphase mass exchange is affected by the temperature. Our derivation is based
on the previous chapter and basic continuum mechanics. Then the chemistry of
interphase mass transfer is described by thermodynamical equilibrium conditions.
As these calculations can be complex, a popular and simplified compositional
model known as the black-oil model is presented at the end of the chapter.
We refer to the books [227, 218, 4, 116, 14] for further background on the
chemical aspects of this chapter, and also to the doctoral theses [59, 245].

3.1 Conservation of mass, energy and volume


We will now provide a set of conservation laws for the mass, energy and volume in
a miscible reservoir flow process. For this we assume that there are three phases;
water, gas and oil, and nc + 1 different molecular components which are indexed
by , of which the first is water. For the sake of brevity, summation of phases and
components will always be over all phases/components unless otherwise explicitly
stated.

3.1.1 Conservation of mass


Since there is transfer of mass between the phases, we cannot formulate conservation laws for components in each phase. Instead, the total mass of each component
summed over the phases is conserved. In providing a component conservation law,
let C be the mass fraction of component in phase , given by
C =

(3.1)

Rewriting equation (1.4)


u
+ F~ = Q,
(3.2)
t
we identify the conserved quantity u as the amount of mass per unit volume,
X
u=
S C .
(3.3)

3.1 Conservation of mass, energy and volume

29

Notice that this is the mass density of a component distributed over all the phases.
We may do the same for the flux, keeping in mind that Darcys law is still assumed
valid:
X
F~ =
u~ C .
(3.4)

Finally, there is a component specific source/sink Q = q [kg/s m3 ]. Assembly of


the conservation law yields

S C


+

!
u~ C

= q .

(3.5)

Conversion to molar units

Later we shall couple the mass conservation equation (3.5) to thermodynamical


models for the computation of phase properties, and then it is more convenient to
use molar units rather than mass units. Therefore, we substitute the mass fractions
and mass densities by mole fractions and mole densities [mol/m3 ]:
C =

(3.6)

The mole densities are related to the mass densities through the component molecular weights M [kg/mol] by

(3.7)
= .
M
Observe now that
C = = M = M C ,

(3.8)

so that equation (3.5) may be divided by M :


S C
t


+

!
u~ C

= q ,

(3.9)

with q = q /M having the unit [mol/s m3 ]. We next wish to clearly identify a set
of primary variables. For this we shall use the mole numbers given in

N
,
=
V

(3.10)

30

Miscible reservoir flows

Taylor diffusion

Stream splitting

Tortuosity effects

Figure 3.1: The three different types of mechanical dispersion of a molecular


component within a porous medium.
with N [mol] being the number of moles of component in phase . Then
X
X

S C =
S
(3.11)

X N

Vp X N V
V
V Vp

1X
=
N
V

(3.12)
(3.13)
(3.14)

1
=
N .
(3.15)
V
The number of moles of component , namely N [mol], will be used as the
primary variable in the mass conservation law
!
X
1 N
+
(3.16)
u~ C = q .
V t

As the presence of N implies molar units, we have here dropped the -notation
on C and q .
Dispersion

In addition to the advective, directional movement of a component described by


the Darcy phase velocity, components may also move due to dispersive forces.
The simplest movement is molecular diffusion by the random Brownian motion
of molecules. Such motion is easy to quantify, and it turns out to be of negligible
importance compared to other forces acting on the fluid.
A more substantial diffusive force is mechanical dispersion. Narrow channel
flows experience parabolic diffusion along the fronts (Taylor diffusion), and irregular pore networks naturally disperse the mass at the microscale, see figure 3.1.

3.1 Conservation of mass, energy and volume

31

Dispersion can also represent small scale movements not captured by the volume
averaging in our mathematical model, but quantifying this macroscale dispersion
is an open problem. It is therefore neglected here, but [108, 169] may provide
further details. The microscale dispersive velocity is given mathematically by
[234, 233]
C
C
u k t e~t .
(3.17)
w~ = d,l k~
u k l e~l d,t k~
~
e
~
e
Here, d,l [m] and d,t [m] are the longitudinal (parallel) and transversal (perpendicular) dispersion coefficients, and e~l and e~t are the unit vectors parallel and
perpendicular to u~ respectively. Typically;
d,l > d,t .

(3.18)

Equation (3.17) can be rewritten in tensor notation as [214]


w~ = d,l k~
u k T C d,t k~
u k (I T ) C ,


where

u~ u~T

(3.19)

T =
.

k~
u k2

(3.20)

D = d,l k~
u k T + d,t k~
u k (I T ) ,

(3.21)

This allows us to define the hydrodynamic dispersion tensor

such that the total dispersive flux for a component is


X
X
F~,disp =
S w~ =
S D C .

(3.22)

The dispersive flux is scaled by S since diffusion of a component within a phase


is restricted by the available phase volume, and gives the amount of mass being
dispersed. Augmenting equation (3.16) to include dispersive forces gives
!

X 
1 N
+
= q .
(3.23)
u~ C S D C
V t

It should be noted that many numerical solution methods add artificial diffusion,
and this artificial diffusion is often of far greater magnitude than the physical
dispersion derived here. When using a naturally diffusive scheme we may hence
neglect physical dispersion altogether [112].

32

Miscible reservoir flows

3.1.2 Conservation of energy


The specific total energy of a phase is denoted e [J/kg], and is given by
e = + +

u~ u~
,
2

(3.24)

for which is the specific internal energy, is the potential energy driving
the volume forces, and the last term is the specific kinetic energy. The sum of
potential and kinetic energy is the mechanical energy. From basic continuum
mechanics (i.e., [271, 104]) we have that the conserved quantity is
u = S e ,

(3.25)

with the energy flux given by


V~ = e u~ + J~ u~ .
(3.26)

Here, J~ [W/m2 ] is the conductive heat flux and [Pa] is the stress tensor. If there
is also interphase energy transfer, Q = qe [W/m3 ], then equation (1.4) becomes

( S e )
+ e u~ + J~ u~ = qe .
t

(3.27)

The terms in the energy flux will now be specified. The conductive heat flux
J~ is usually given by Fouriers law
J~ = T ,
(3.28)

where [W/m K] is the heat conductivity tensor and T [K] is the system temper we assume that the fluid is ideal, that is, it has constant compressibility,
ature. If
Cauchys laws of continuum mechanics simplify the stress tensor into the isotropic
form
= p I.
(3.29)

Before substituting (3.29) into equation (3.27), we note that in the majority of
thermal flooding applications, most of the phase energy is the internal energy
of the heated fluid. Thus, we may neglect the mechanical energies contained in
potential and kinetic terms, and we get the equality
e = .

(3.30)

( S )
+ ( u~ T + p u~ ) = qe .
t

(3.31)

Then equation (3.27) becomes

3.1 Conservation of mass, energy and volume

33

The flux in (3.31) can now be further simplified by



p
u~ T
=
+

= h u~ T .

u~ T + p u~

(3.32)
(3.33)

Here we have introduced the enthalpy h [J/kg], which is a thermodynamical potential that may be computed from an equation of state. Equation (3.31) is now
( S )
+ (h u~ T ) = qe .
t

(3.34)

Since the temperature is assumed equal for all the phases, we may sum (3.34) over
the phases, yielding


+

!
(h u~ T )

= qe .

(3.35)

In this form q e reduces to just the contribution of energy from external sources.
As energy is also contained within the rock phase = r, we include this phase
in the above summation. Convective energy transfer in the rock phase is negligible
~ Furthermore, the internal
compared to its conductive transfer, so we have u~r = 0.
energy of the rock is
pr
r = hr .
(3.36)
r
Assuming further a negligible change in porosity and rock density with time, we
obtain
(r Sr r )
hr T
= (1 )r
.
(3.37)
t
T t
In this equation we also assumed no change in rock pressure with time. Now,
equation (3.35) becomes the porous media temperature equation
hr T
(1 )r
+
T t


 P
6=r S
t

!
(h u~ T )

= qe.

(3.38)
The second time derivative term can be treated implicitly in temperature if we
have a temperature-explicit expression for the specific internal energy . See
[71, 72] for details.

34

Miscible reservoir flows

3.1.3 Volume balance


In the immiscible case, mass and volume conservation are equivalent formulations. Equation (3.23) conserves mass, but it does not ensure that the phases fill
the porous medium at all times. This latter constraint can be written
X
X V
S =
= 1
(3.39)
Vp

X
V = Vp = V .
(3.40)

Define the residual volume R by


R = V

V .

(3.41)

Physically, must have R = 0 for all times. Regarding R as a function of time, a


Taylor expansion gives
R
= 0,
(3.42)
t
While we aim for R(t) = 0, it may not be satisfied due to numerical effects so we
keep it in the equation with the purpose of guiding a numerical solution scheme.
In providing an expression for the residual volume derivative, we note that the
size of the phase volumes are affected by changes in pressure, temperature and
the masses. Furthermore, the reservoir overburden W can cause a reduction in
the porosity, as may the fluid pressures. The overburden has the same unit as
pressure, and at a depth z it is given by
Z zt X
W (z) = Wt + g
S dz.
(3.43)
R(t + t) = R(t) + t

zt is the coordinate at the reservoir ceiling (the seal, see figure 1.1), and Wt is the
overburden there. Naturally, this phase sum should include the rock = r.
Using the chain rule on the residual volume derivative in equation (3.42) yields
the volume balance equation
R(t) R pw R W R T X R N
+
+
+
+
= 0.
(3.44)
t
pw t
W t
T t
N
t

In (3.44) the water pressure, pw , is identified as a primary variable. The time


derivatives of component moles and temperature are directly known from equation (3.23) and (3.38) respectively. Assuming that the porosity has the functional
relationship
= (pw , W ),
(3.45)

3.1 Conservation of mass, energy and volume

35

the residual volume derivatives are


R
pw

X V

V
,
pw
pw

(3.46)

R
=
V,
W
W
X V
R
=
,
T
T

X V
R
=
.
N
N

(3.47)
(3.48)
(3.49)

Balance of phase volumes

By the same approach as for the total volume balance, we can also provide phase
volume balance equations. Since V is dependent on pressure, temperature and
masses, clearly
V V pw V T X V N
=
+
+
.
t
pw t
T t
N
t

(3.50)

Overburden affects the phase volumes through the change in the pressure, so having solved for pressure we may neglect overburden here. The time derivatives
of pressure, temperature, and mass are known from earlier equations. Most of the
physical parameters used in the equations above are functions of saturations rather
than volumes, and using
V = V S ,
(3.51)
we get the compositional saturation equation
1 V pw V 1 T X V 1 N
(S )
=
+
+
.
t
V pw t
T V t
N
V
t

(3.52)

This can be solved for Sw and So , and Sg is found by the relation


Sg = 1 Sw So .

(3.53)

3.1.4 System solution strategy


Having presented all the conservation laws, we briefly comment on how the system can be solved, following the ideas in [268, 12]. As there can be numerous
components in the fluid system, the total number of unknowns N can be too large

36

Miscible reservoir flows

Do for each time step:



pw from equation (3.44)
Solve
Sw and So from equation (3.52)
Calculate Darcy velocities u~

N from equation (3.23)
Solve
T from equation (3.38)
Calculate thermodynamical equilibrium state
While R(t + t) 6= 0
Algorithm 3.1: Typical sequential solution algorithm for the thermal compositional model. This is just for a single time step.
to facilitate a fully coupled implicit method, so we will instead concentrate on decoupled solution techniques as outlined in algorithm 3.1. The sequential approach
also allows us to use customised numerical methods for different equations, rather
than using the same discretisation for all.
An important part of the mass and temperature equations is the Darcy phase
velocity u~ . While it is in general dependent on the whole phase state, it is primarily determined by pressure and saturations, since those will determine most of its
factors (kr , pc ). Therefore it is advantageous to first solve for pw , Sw and So . Then
the Darcy phase velocities u~ can be used in the solution of mass and temperature.
Finally, the phase compositions and volumes can be determined from thermodynamical calculations.
There is a slight disparity in such a formulation. The phase saturations S
which is already computed, will not in general be the same as those found from
an equation of state in the thermodynamics. We can either omit solving equation (3.52), which can affect the accuracy of the Darcy velocities, or we can overwrite the saturations by those found from the thermodynamics. The latter is the
consistent choice, and equation (3.52) need only be solved once per time step.

3.2 Thermodynamical equilibrium calculations


Given pressure pw , total component masses N , and temperature T , the thermodynamical calculations provide us with the phase states, such as phase compositions, volumes and densities. We always assume that the system is in a state of
local equilibrium, and as such the calculations are independent of time. For fast
fluid flows, kinetic reactions also affect the phase properties. But our fluids tends

3.2 Thermodynamical equilibrium calculations

37

to flow slowly, and we neglect kinetic mass transfers entirely.


As the field of thermodynamics is large, we shall make some simplifications
to keep the size of our treatment reasonably small:
The water phase consists of only the H2 O (water) component, and the water
component may not exist in any other phase. This component will have the
index = 0.
Oil and gas may freely exchange mass, and these phases consist of the components = 1, . . . , nc . We assume no other phases such as a solid phase, and
there will be no mass transfer to the water phase.
We will assume that all phase pressures equal the water pressure, pw , and
we drop the phase subscript to let p denote the system pressure. Likewise,
all phase temperatures equal the system temperature T . Note that in cases
of strong capillary forces, the assumption of equal phase pressures may lead
to an inaccurate equilibrium [116, Chapter 2].
Gravity will also be neglected in the equilibrium calculation. This is because the equilibrium calculations are performed locally in the computational grid, and not globally. However, gravity is included in the component
flow equations.
We shall assume that the system moves between phase equilibria through
reversible processes.
Since water has been excluded from the oil/gas mixture, its mole density should
be prescribed as a pressure/temperature dependent function w = w (pw , T ). Then,
from equation (3.10), we find
Vw =

N0
,
w

Nw = N0w = N0 .

(3.54)

3.2.1 The laws of thermodynamics


The first law of thermodynamics states that the change in internal energy, d , of
a phase is given by
d = dQ + dW ,
(3.55)
where dQ is the heat added to the system, and dW is the work done. The added
heat, dQ , can be quantified by the second law
dQ T ds ,

(3.56)

38

Miscible reservoir flows

in which s is the phase entropy (measure of disorder). For a reversible process,


this simplifies to an equality. Furthermore, for a closed system the work equals
the volume changing forces:
dW = p dV .

(3.57)

Assembling all equations, a reversible and closed system satisfies


d = T ds p dV .

(3.58)

However, for a multi-phase system we note that the energy change can also be
affected by the phase composition:
d = T ds p dV +

dN ,

(3.59)

where chemical potentials, , have been introduced. These are given by


=

(3.60)

To find the equilibrium condition, we must consider the total system energy:
dg + do = T (dsg + dso ) p(dVg + dVo ) +


g
g
dN + o dNo .

(3.61)

Clearly dVg = dVo and dNo = dN for a closed system. Then


dg + do = T (dsg + dso ) +


g
g
o dN .

(3.62)

At the equilibrium state there is no change in entropy or total energy, and consequently we must have
g

= o ,

= 1, . . . , nc .

(3.63)

The equality of the chemical potentials for all components in both of the phases
is our thermodynamical equilibrium condition. In the following sections we shall
provide a closed expression for , followed by some solution techniques for
equation (3.63).

3.2 Thermodynamical equilibrium calculations

39

3.2.2 Chemical potentials and fugacities


The chemical potentials are related to the fugacities (from Latin, escaping tendency) by
d = RT d ln f ,
(3.64)
in which f is the fugacity and R = 8.3145 [J/mol K] is the universal gas constant.
Integrating this gives
 
f

0
,
(3.65)
= + RT ln
f0
with 0 being the potential, and f0 being the fugacity, both of a pure component
fluid at ideal (low pressure) conditions. This shows that equality of the chemical
potentials across phases implies that the fugacities should also be equal across
phases:
g
g
= o f = fo .
(3.66)
Hence, we can limit ourselves to just determining the fugacities, and they are
defined through the relation
(3.67)
f = C p ,
where is called the fugacity coefficient which satisfies
lim = lim

p0

p0 C p

= 1.

(3.68)


To determine the fugacity, start by subtracting RT d ln C p from both sides of
equation (3.64):


d RT d ln C p = RT d ln f RT d ln C p = RT d ln .
(3.69)
We can identify d by considering the Gibbs energy function. The Gibbs energy
is defined as the summation of the internal energy, the volume changing work and
the energy loss due to entropy:
G = + pV T s .

(3.70)

dG = d + p dV + V dp T ds s dT
X
dN .
= V dp s dT +

(3.71)

Its differential is given by


(3.72)

As an alternative, we may also regard the differential as a function of pressure,


temperature and phase composition. From this it follows:
X G
G
G
dp +
dT +
dN .
(3.73)
dG =

p
T
N

40

Miscible reservoir flows

Comparing these two expressions for dG , we find


G
= V ,
p
G
= s ,
T
G
= .

(3.74)
(3.75)
(3.76)

It then follows that

2 G
V
2 G
=
=
,
=

p
N p p N
N

(3.77)

and therefore the change in when only the phase composition N can vary is
d =

V
N

(3.78)

dp.

Inserting this into (3.69) gives


RT d ln =

dp

RT
d
ln
C
p
.

(3.79)

With constant phase compositions C , we may simplify the logarithm differential:


d ln C p

=
=

d C p

C p
C dp

C p
dp
=
p
= d ln p,

(3.80)
(3.81)
(3.82)
(3.83)

such that
d ln =

1 V
dp d ln p.
RT N

(3.84)

If the fugacity coefficient can be determined, then the fugacity itself may be found.
To do this requires further pressure/volume/temperature relationship.

3.2 Thermodynamical equilibrium calculations

41

p
Oil
C
Oil and Gas
Gas

T
Figure 3.2: Phase envelope for a given system. Outside the envelope, there is only
a single phase; oil or gas. This is determined by the position relative to the critical
point C in the pressure-temperature diagram. The left portion of the envelope is
called the bubble-point curve, and the right is part is the dew-point curve.

3.2.3 Equations of state


An equation of state provides a relationship between pressure, volume, phase
composition and temperature. For an ideal fluid we have
X
(3.85)
pV = RT
N = RT N ,

or by introducing the molar volume V = V /N ;


pV = RT .

(3.86)

This ideal equation of state only holds in the limit p 0 in which V . In


other cases we instead consider a real fluid system with a dimensionless phase
compressibility factor Z such that
pV = Z RT N .

(3.87)

A real fluid becomes ideal as pressure tends to zero or as the molar volume tends
to infinity. Hence;
lim Z = lim Z = 1.
(3.88)
p0

There are numerous ways to determine Z , and this is a large research area by
itself. Here we shall start by providing pressure-explicit equations of state, and
then Z will be identified. In the classical pressure-explicit form we assume that
p = prep + patt ,

(3.89)

42

Miscible reservoir flows

where prep are the repulsive forces and patt are the attractive forces. Van der Waals
[260] provided a simple expression for these by
a
RT
2,
p=
(3.90)
V b V
in which a and b are empirical parameters that satisfy
p
= 0,
V
2 p
= 0,
V 2

(3.91)
(3.92)

at the critical point of a single-component system. The critical point is where the
system hovers between two phase oil/gas, single phase oil and single phase gas,
see figure 3.2.
The Van der Waals equation of state, although simple, is not used nowadays
since more accurate equations of state are available. We shall here consider the
class of general two-parameter equations
RT
a
(3.93)
p=


,
V b
V 1 b V 2 b
where
1 < 2 < 1

(3.94)

are empirical constants. Notice that Van der Waals equation, while not strictly of
this class, can be considered a special case with the choice 1 = 2 = 0.
The two parameters a and b are given by the general mixing rules
XX
a =
Ci Cj aij (T ),
(3.95)
i

b =

Ci bi ,

(3.96)

(3.97)
for which
aij (T ) =


ai (T )aj (T ) 1 dij .

(3.98)

Here, dij are dimensionless binary interaction coefficients between components,


and they naturally satisfy dij = dji . The following relations are also used:
s !#2
2 "
RTic
T
ai (T ) = a
1 + m(i ) 1
,
(3.99)
c
pi
Tic
bi = b

RTic
pci

(3.100)

3.2 Thermodynamical equilibrium calculations

1
2
a
b
m(i )

Soave-Redlich-Kwong [244]
1
0
1
 3
9 2 1

1 3
21
3
0.48 + 1.574i 0.176i2

43

Peng-Robinson [219]

1 + 2
1 2
0.45724
0.0788
0.37464 + 1.54226i 0.26992i2

Table 3.1: Two common equations of state suitable for hydrocarbon mixtures.
Some new parameters have now been introduced. Tic and pci are the pure component critical temperature and pressure, respectively. Further, a and b can be
determined based on the conditions of the system at the critical point, but they
may be regarded as empirical parameters. Pitzers acentric factor, i , is a measure of the deviation of a molecular substance from a perfect spherical form. The
function m(i ) is then some polynomial fitting function.
It should come as no surprise that there is a vast number of available state
equations. Table 3.1 lists two common methods which are used widely, and their
choice of parameters. More complicated equations of state exists, but these do not
seem to have gained widespread acceptance within the oil industry yet.
Comparing equation (3.87) with the two-parameter form (3.93), we can
identify a phase compressibility factor Z by noting that
Z RT
.
(3.101)
p
Substitution of (3.101) into equation (3.93) yields a cubic algebraic equation in
Z ;
pV = Z RT N V =

Z3 [1 + B (1 + 1 + 2 )] Z2 +


A + B (1 + B ) + 1 + 2 + 1 2 B2 Z =
A B + B2 (1 + B ) 1 2 , (3.102)
with
pa
,
(3.103)
(RT )2
pb
.
(3.104)
B =
RT
In solving the cubic equation, we can find up to three real roots, but we obviously
only need one. To remedy this, note that gas tends to have large volumes, while
oil has smaller volumes. Thus, for the gas phase the largest real root is selected,
which then maximises V . Conversely, the oil phase should use the smallest real
root, minimising its phase volume.
A =

44

Miscible reservoir flows

3.2.4 Calculating the fugacity coefficients


We now return to the computation of the fugacity coefficients. From equation (3.84);
1 V
d ln =
dp d ln p,
(3.105)
RT N
we need to identify pressure derivatives, and our pressure explicit equation of state
will now be used. First, we wish to eliminate the direct pressure dependency in
the second term, d ln p. Start by
pV
,
RT
and note that its differential at fixed temperature is
Z =

dZ =
Division by Z gives

V dp + p dV
.
RT

dZ dp dV
,
= +
Z
p
V

and further
d ln p =

dp dZ dV
.

=
p
Z
V

(3.106)

(3.107)

(3.108)

(3.109)

Next, the first term in (3.84);


V

dp,
(3.110)
N
simplifies by using the fact that the system pressure has the dependencies

p = p V , T , N1 , . . . , Nnc .
(3.111)
The total change in the pressure is
dp =

X p
p
p
dN .
dV +
dT +

V
T
N

(3.112)

Division by dN , and keeping all other quantities except for V fixed yields
0=

p V
p
+
.

V N N

(3.113)

The total derivative on the phase volume, dV , has been changed into a partial
derivative since it is only N that is variable. Rearranging gives
V
N

dp =

p
N

dV .

(3.114)

3.2 Thermodynamical equilibrium calculations

Substituting equation (3.109) and (3.114) into equation (3.84) gives


dZ dV
1 p
dV

d ln =
+

RT N
Z
V

45

(3.115)

ln
V

1 Z
N p
1

+ .
(3.116)

RT N Z V V
This is then to be integrated with respect to V from zero pressure to a fixed
pressure. At zero pressure, V = , and at a fixed pressure the molar volume
is naturally finite. With these integration limits, we use the relations (3.68) and
(3.88), yielding

Z 
1
N p

ln =
dV ln Z .
(3.117)

RT

V
N
V

The pressure derivative can be computed straight from the equation of state (3.93),
and then integration and some simplifications give


Z 2 B

ln = (Z 1) ln (Z B ) +
ln
,
(3.118)
(2 1 ) B
Z 1 B




 A
(Z 1) 
exp

Z 2 B ( 2 1 )B

,
(3.119)
=
Z B
Z 1 B
=

where we introduced the constants

nc

2 X
=
Cj aij ,
a

(3.120)

j=1

i =

bi
.
b

(3.121)

3.2.5 Iterative flash algorithms


Armed with an explicit expression for the fugacity coefficients, , and thus also
the fugacities, f , we will now outline how to split a global composition N into
phase compositions N . This process is usually called the phase split or just the
flash, and since it is quite complex, it will be calculated by numerical methods
[198]. Here we present two such approaches, namely the fast and complicated
Newtons method, and the slow but robust successive substitution.
The criterion for equilibrium is the equality of the fugacities;
g

f = fo ,

= 1, . . . , nc .

(3.122)

Furthermore, the system must always maintain the material mole balance
g

N = N + No ,

= 1, . . . , nc .

(3.123)

46

Miscible reservoir flows

Newtons method

Equation (3.122) is equivalent to


def

G = ln f ln fo = 0,

= 1, . . . , nc .

(3.124)

Choosing N as the unknowns, No may be found from the material balance equation (3.123). A Taylor expansion of equation (3.124) then yields
[n+1]
G

[n]
G +

nc
X
G

G = G

=1 N

with

[n]

g N ,

g [n+1]

N = N

g [n]

N1

g [n]

g [n]

, . . . , Nnc


,

(3.125)

(3.126)

Here, [n] is the nonlinear iteration index. Since our aim is G = 0, , the left hand
side of equation (3.125) may be posed to be zero, and the equation is rewritten
into matrix form:

G1 G1

[n]
G1g
g
g
g
N2
Nnc
G1
N1
1

N
G [n]
G2g G2g G2g N g

N1 N2
Nnc
(3.127)
.. 2 = 2. .
.
.
.
.
.
..
..
.. .
..
.

g
[n]
Gnc
Gnc
Gnc
Nnc
Gnc

g
g
g
N1

N2

Nnc

This should be solved iteratively until convergence. Clearly, we must disallow


solutions with N < 0, = g, o, and this can be done by truncation and/or a careful
implementation. It remains to compute the derivatives of G :
G
g

ln f
g

ln fo
g

(3.128)

Since f = C p , the fugacity derivatives in equation (3.128) can be computed,


yielding
g
g
1 C ln
1 Co ln o
G

(3.129)
g = g
g +
g o
g ,
C Ng
N C N
N
N
where the fraction derivatives are
g

N
Co

C
=
,
Ng

(3.130)

g.

(3.131)

3.2 Thermodynamical equilibrium calculations

47

The fugacity coefficient derivatives are quite messy.


tion (3.118) yields
ln
g
N

g
N

1
Z B




+ A g g

(Z 1) +

A
g
N

g
N

!
Z

(2 1 ) B

Differentiating equa-

g
N

A
(2 1 )2 B2

Z 2 B A
+

ln
Z 1 B
(2 1 ) B
"
B Z 2 B
1
Z
2
g
g
Z 2 B N
N Z 1 B

B
g
N

!#
Z

B
g

.
(3.132)

The derivatives of , , A , B and Z with respect to N must also be found.


The first four are

i
ai a
2 X Cj
=
a

,
(3.133)
ij
g
a j Ng
a Ng
N
i b
=
,
b Ng
p a
=
,
(RT )2 Ng
p b
=
.
RT Ng

i
g

N
A

N
B

(3.134)
(3.135)
(3.136)

The derivative of Z are obtained from equation (3.102):


3Z2

Z
g

+ 2a2 Z

Z
g

+ a1

Z
g

a2

a1

a0

2
g Z

a2

Z
g

g
N

Z2 +

g Z

a1

g
N

Z +

(3.137)

a0

3Z2 + 2a2 Z + a1

(3.138)

The new constants ai are the Z coefficients of equation (3.102):


a2 = 1 B (1 + 1 + 2 ) ,

(3.139)

a1 = A + B (1 + B ) + 1 + 2 + 1 2 B2 ,

(3.140)

a0 = A B B2 (1 + B ) 1 2 .

(3.141)

48

Miscible reservoir flows

It remains to differentiate a and b :


a
g

N
b

Ci

XX
i

Cj

Cj

+ Ci

aij (T ),

X Ci

g bi .

(3.142)

(3.143)

Note that an alternative to analytical derivatives is the numerical approximation


by finite difference methods.
Successive substitution

A simple alternative to Newtons method is the successive substitution method.


To derive the method, we first introduce the gas and oil phase fractions
Pnc

N
=1 N
, = g, o.
(3.144)
=
F = Pnc
N NHC
=1

Since

Ng + No

= NHC , one of these may be eliminated:


Fo = 1 Fg .

(3.145)

Then, divide equation (3.123) by NHC :


g

C = Fg C + Fo Co

g
= Fg C + 1 Fg Co .

(3.146)
(3.147)

From the fugacity equality (3.122) we define the equilibrium ratios


def

K =

o
C
.
=
Co g

(3.148)

Using these, C can be eliminated from equation (3.147):



C = Fg K Co + 1 Fg Co .

(3.149)

This is in turn solved for Co , giving


Co =

C
,
(K 1)Fg + 1

(3.150)

from which it follows that:


g

C = K Co =

K C
.
(K 1)Fg + 1

(3.151)

3.2 Thermodynamical equilibrium calculations

49

Do
Solve the Rachford-Rice equation (3.153) for Fg .
g

Calculate the phase compositions Co and C from the equations (3.150)(3.151).


Solve the cubic equation of state (3.102) for the phase compressibilities
Z .
Calculate the fugacity coefficients from equation (3.119).
Calculate the equilibrium ratios K from equation (3.148) using the computed fugacity coefficients.
g

While f 6= fo ,
Algorithm 3.2: The successive substitution algorithm for a two-phase mixture.
Clearly, the sum of each phase fraction is 1, so their difference must be zero:
X


g
C Co = 0,

(3.152)

and into this we substitute both equation (3.150) and (3.151), getting the RachfordRice equation
nc
X
C (K 1)
= 0.
(3.153)
(K 1)Fg + 1
=1

The successive substitution algorithm is given in algorithm 3.2. To start it, one additional set of inputs compared to the Newton iteration is required, namely initial
estimates on the equilibrium ratios. At low pressures a correlation formula based
on ideal fluid properties can be used, for instance Wilsons formula:



Tc
p
.
K = c exp 5.37 (1 + ) 1
T
p

(3.154)

This is only necessary at the first time step of the reservoir flow process; at later
times we can use the previously computed K values from the same grid block.
The successive substitution is clearly a simple algorithm, and for the twophase problem here it is always convergent [195, 196]. But it is also a slow
method. Therefore one may combine it with Newtons method by alternating
between some successive substitution steps and a Newton step [197].

50

Miscible reservoir flows

3.2.6 Volume derivatives


At the convergence of the flash, phase volumes and densities are simple to find
from the equation of state. In addition, the volume balance method needs phase
volume derivatives with respect to the primary variables pw , T and N . From
equation (3.87) we have
Z RT N
V =
.
(3.155)
pw
For the sake of generality, we shall compute
V
,
x

(3.156)

where x may be pw , T or N . Then it follows that




R Z
T
N
pw Z T N
V

.
=
TN +
Z N +
Z T
x
pw x
x
x
x
pw

(3.157)

The derivative of the phase compressibility Z can be gleamed from (3.138):


Z
=
x

a2 2 a1
a0
Z
+
Z
+

x
x 2 x
3Z + 2a2 Z + a1

(3.158)

The temperature derivative is zero unless differentiating with respect to temperature, in which case the derivative equals 1. Likewise for the pressure. It remains to
compute the mass derivative:
N X N
=
.
x
x

(3.159)

We will use the fugacity equality condition to find these mole mass derivatives.
First note that
g
N N No
=
+
.
(3.160)
x
x
x
If x = pw or T , the left hand side is zero since the mass is an independent variable:
g

N o
N
= .
x
x

(3.161)

If x = N , the delta function is instead obtained:


g

No
N
=
.
N
N

(3.162)

3.3 Black-oil compositional models

51

The total derivative of the fugacities is


df f p f T X f N
=
+
+
.
x
dx
p x T x
N

(3.163)

Starting from the equality f = fo , differentiating with respect to x and substituting into (3.163) yields
!


 g
 g
g
X fg
fo No
f fo p
f fo T f
=

+
x ,
o
g +
x
p
p x
T
T x N
N N

(3.164)
where x = 1 if x = N , and otherwise zero. Defining
Fij

fi
Nj

,
g

ri

(3.165)

fi fio

p
p

!
p
+
x

fi fio

T
T

T fi
x ,
+
x N

(3.166)

we may rewrite the above into the matrix system


N o
1


g
o
F +F

x
N2o
x

..
.

Nnoc
x

= r~ .

(3.167)

As the system matrix is independent of x, factorisation is only required once to


solve for all desired types of derivatives.
The computation of the fugacity derivatives remains, but a very similar computation was done for computing the Jacobian matrix in Newtons method for the
flash calculations. Therefore, these calculations are omitted here.

3.3

Black-oil compositional models

The compositional model described in the preceding sections is a cumbersome


computational task. It consists of solving a coupled system of partial differential
equations for the masses, energy and the volume balance. Further, thermodynamical equilibrium calculations must be performed, which is not a trivial issue.
Keep in mind that the latter calculations must be performed for every cell in the
computational grid.

52

Miscible reservoir flows


XXX
XX
XX Phase
Component XXXXX

Aquatic
Light
Heavy

Water

Gas

Caw = 1
Clw = 0
Chw = 0

Ca = 0
g
Cl = 1
g
Ch = 0

Oil
Cao = 0
Clo = 1 Cho
Cho

Table 3.2: Phase fractions of the classical black-oil model. The light component
may exist in both the gas and the oil phase, as indicated by the fraction Cho .
We may simplify the auxiliary thermodynamical calculation into explicit relationships between pressure, temperature and composition, and this will result in
equations of much the same form as those in Chapter 2. There are two types of
thermodynamical quantities; intensive and extensive, respectively. The former has
point values and are independent of the system size, while the latter is dependent
on the system size.
It is a fundamental postulate that the intensive state of a nc component system
is given by nc + 1 variables, while its extensive state is given by nc + 2 variables.
These variables may be freely chosen, and we use pressure pw , temperature T ,
and system volume V to reduce the number of variables to nc 1 for the extensive
system.

3.3.1 Thermodynamics and mass conservation


The black-oil model uses three components, namely an aquatic water-bound component ( = a), a light hydrocarbon component ( = l), and a heavy hydrocarbon
component ( = h). At surface conditions, the light component evaporates into
the gas phase while the heavy component then forms the oil phase. However, at
reservoir conditions the oil phase consists of a mixture of the light and the heavy
hydrocarbon components, while the gas phase is formed from the remaining light
components.
Table 3.2 lists the component phase fractions of the black-oil model. There are
only two of them that must be determined: the fraction of light component in the
oil phase (Clo ) and the fraction of heavy component in the oil phase (Cho ). Since
P
C = 1, it trivially follows
Clo = 1 Cho .

(3.168)

We now need to find the functional dependencies of Cho . Since the aquatic component is restricted to water, and the hydrocarbon components cannot mix with
water, our system is actually two systems: one pure water system and a hydrocarbon mixture. The hydrocarbon mixture has just two components, and its intensive

3.3 Black-oil compositional models


XXX
XX
XX Phase
Component XXXXX

Aquatic
Light
Heavy

53

Water

Gas

Oil

Caw = 1 Clw
Clw
Chw = 0

Ca = 0
g
Cl
g
g
Ch = 1 Cl

Cao = 0
Clo = 1 Cho
Cho

Table 3.3: Phase fractions of the extended black-oil model with solubility of the
g
light component into the water phase and a volatile heavy component. Clw , Cl
and Cho are now variable.
state can be described by three variables. We chose these three to be pressure pw ,
temperature T and oil saturation relative to total hydrocarbon phase saturation
Sor =

So
.
So + Sg

(3.169)

Therefore;
Cho = Cho (pw , T , Sor ).

(3.170)

The phase mole densities are also intensive state variables, and therefore have
the dependencies


(3.171)
w = w (pw , T ) , g = g pw , T , Cho , o = o pw , T , Cho .
Mass conservation is given by equation (3.16), with one equation for each component:
!
X
1 N
+
u~ C = q , = a, l, h.
(3.172)
V t

Extended black-oil

The classical black-oil model may easily be extended to more complicated mixtures. For instance, the light component group can include substances which are
water soluble, while some of the heavier components may vaporise into the gas
phase. This model is called the extended black-oil, but without hydrocarbon solubility in water, it is instead referred to as just the symmetrical black-oil model.
Since this is a coupled three component problem, we need four variables to
describe the intensive system state, and those will be pw , T , and the phase saturations Sw and So . The phase fractions are tabulated in table 3.3, and we must
prescribe the fractions
Clw = Clw (pw , T , Sw , So ),

Cl = Cl (pw , T , Sw , So ),

Cho = Cho (pw , T , Sw , So ),


(3.173)

54

Miscible reservoir flows

along with the phase densities



g
g
w = w pw , T , Clw , g = g pw , T , Cl , Ch ,


o = o pw , T , Clo , Cho .
(3.174)

3.3.2 Pressure and saturation equations


The primary variables for the black-oil model are water pressure pw , phase saturations Sw and So , and temperature T . Temperature is solved from equation (3.38)
coupled with a functional relationship for the enthalpies:
h = h (pw , T , Sw , So ).

(3.175)

For the pressure and phase saturations we shall simply use the volume balance
equations (3.44) and (3.52). To use these, N /t and T /t are needed along
with phase volume derivatives. The time derivatives of mass and temperature are
known from before, so we are left with calculating V /pw , V /T and V /N .
For the sake of generality, we will consider the extended black-oil model.
Applying the results to the classical black-oil model is then just a matter of zeroing
some terms.
Now, the number of moles of each component is

Na = Vw w ,
X
g

N =
C V
(3.176)
Nl = Clw Vw w + Cl Vg g + Clo Vo o ,

g
o

Nh = Ch Vg g + Ch Vo o .
Solving for the phase volumes gives
Na
,
w
Cho Nl Clw Na Clo Nh
=
g ,
g
g Cl Cho Clo Ch

Vw =

(3.177)

Vg

(3.178)

Vo


g
g
g
Nh Cl Cho Clo Ch + Clo Ch Nl + Clw Na
.
=
g
g
o Cho Cl Cho Clo Ch

(3.179)

Equations (3.177)-(3.179) may now be differentiated with respect to pw , T and


N , and the chain rule must be applied to resolve the dependencies of C and
on pw , T and S . After differentiation, we are left with explicit volume derivative
expressions as functions of pressure, temperature and masses. Since the masses
are not part of our primary unknowns, we use equation (3.176) to eliminate these,
and replace the phase volumes therein by saturations:
V = V S .

(3.180)

3.3 Black-oil compositional models

55

Rs
Bo

pw
BP
BP
pw 1
pw 2
Figure 3.3: Bo and Rs for the classical black-oil model plotted against pressure. o
decreases initially due to dissolution of the light component into the oil phase. At
the bubble point pressure pBP
w , no more of the light component can be dissolved,
and Rs becomes constant at higher pressures while Bo decreases as /pw 0.
The bubble point pressure varied with temperature and composition, and we have
plotted two. The y-axis is not to any particular scale.
Substituting the volume derivatives into equation (3.44) gives the black-oil pressure equation, and substitution into equation (3.52) gives saturation equations for
Sw and So . Temperature is solved from equation (3.38). Notice that there is no
need to solve any of the mass equations (3.16) explicitly anymore.

3.3.3 Volume factors and solubilities


In conventional black-oil models explicit fractions C are not used as input, but
rather ratios between phase densities on the surface relative to the reservoir, and
also the ratio of dissolved light component in the oil phase. The mass densities of
the phases for the extended black-oil model are
w =

Ma w + Ml Clw w ,
|{z}
| {z }
wa

wl

g = Ml Cl g + Mh Ch g ,
| {z } | {z }
g

(3.182)

o = Ml Clo o + Mh Cho o .
| {z } | {z }
ol

(3.181)

(3.183)

oh

Recall that the M s are the component molecular weights, and the s are the
partial phase densities. Furthermore, let SC
be the phase densities at surface
(standard) conditions, and it is understood that the phases there consist of pure

56

Miscible reservoir flows

components, i.e., the water phase consists exclusively of the aquatic component.
Then, define the volume factors
SC
w
,
w
SC
g
,
=
g
SC
= o .
o

Bw =

(3.184)

Bg

(3.185)

Bo

(3.186)

These are clearly all 1 at the surface, but can exhibit different types of behaviours
at reservoir pressure, see figure 3.3. Next, define the dissolution ratios
Rlw

wl
w
g

g
Rh

Rs = Rlo

ol

g
o

wl

,
SC
w
g
h
= Bg SC ,
g
ol
= Bo SC .
o
= Bw

(3.187)
(3.188)
(3.189)

These ratios are zero at surface conditions, and typically increasing downwards in
the reservoir up to a certain point. Using the dissolution ratios and volume factors,
we can solve for C and as needed in our black-oil formulation.

Chapter 4
Numerical methods
Comparably few of the reservoir flow equations provided admit analytical solutions. Under the assumption of homogeneous fluid and medium conditions, the
single phase immiscible equations (2.30) and (2.33) can be solved in some regular domains. For two phases, the Buckley-Leverett problem (2.57), (2.62) can
be solved for a restricted set of fractional flow functions fw . In addition, the
McWhorter problem (2.57), (2.60) can be solved by quasi analytical means, that
is, reduced to an integral expression that can be solved by numerical quadrature.
However, an arbitrary, physical correct problem described by our reservoir
flow equations has in general no known analytical nor quasi analytical solution.
Therefore, we will resort to numerical means by discretising the partial differential
equations into a set of coupled nonlinear equations which in turn are formulated
into a sequence of linear equations by Newtons method. In formulating discretisation methods, we will make use of some canonical forms. From linear partial
differential equation theory [111], the types of partial differential equations may
be classified as
Elliptic Time-independent potential equations:
Ku = q.

(4.1)

Parabolic Time-dependent, diffusive driven equations:


u
Ku = q.
t

(4.2)

Hyperbolic Time-dependent, advective driven equations:


u
+ f~ = q.
t

(4.3)

58

Numerical methods

i4
i4
i1

i3

i1

i3

i
i2
i2

Figure 4.1: 2D regular quadrilateral grid with n = 9 cells.


All of our conservation equations can be written in a parabolic form, since they
have one temporal derivative and two spatial derivatives. Thus, the discretisation of the parabolic equation will constitute a major part of this chapter, and we
present the three common methods finite differences, finite elements and mixed
finite elements along with some extentions. These discretisations must be able
to capture the primary features of parabolic equations, namely infinite propagation speed of perturbations (leading to implicit methods), and a fair degree of
smoothness in the solution (meaning that higher order methods can be suitable).
However, as has been illustrated for the Buckley-Leverett problem, the flow
equations do have a hyperbolic character too. Hyperbolic problems are quite different from the parabolic ones, in that they exhibit finite propagation speeds and
their solutions can develop shock discontinuities. Consequently, we shall also
consider special numerical schemes for such equations.

4.1 Preliminaries
Let be the reservoir domain and the boundary . We subdivide into the
grid cells i , and the number of grid cells will be n . Let i be the surface of i ,
and further subdivide the surface into the subsurfaces ik where k = 1, . . . ni and
ni is the number of faces of i . Thus;
i = i ,

i =

ni
[

ik .

(4.4)

k=1

We let Vi be the volume of i , Ai the surface area of i , and Aik likewise the
surface area of ik . x~i is the centre spatial point in i and x~ik is the midpoint of
ik .

4.1 Preliminaries

59

It is conventional to let all parameters such as permeability and porosity be


cell centred, meaning that they are constant on each element. However, the numerical schemes from which we compute our primary variables (pressure, saturation, temperature, etc) can compute these properties as cell centred, point centred
(the corners of each cell), or a mixture of these. In any case, it must be possible to
evaluate the primary variables in the cell centres to allow the explicit computation
of secondary variables (capillary pressure, relative permeability, viscosity, etc).
Subscripts will be used to denote spatial indices, and superscripts to denote
temporal indices. Superscripts in brackets are nonlinear iteration indices.

4.1.1 Solving the discretised equations


The next sections will discretise the partial differential equations such that a residual equation in each grid block is obtained:
Ri (~
u) = 0,

i = 1, . . . , n ,

(4.5)

where u~ = u1 , . . . , un is the unknown discrete solution. Note that discretisations


which are not cell centred may have more residual equations than the number of
grid blocks. A Taylor expansion yields
X Ri
[t+1]
[t]
uj ,
(4.6)
Ri
Ri +
uj
j

with

[t+1]

ui = ui

[t]

ui ,

(4.7)

in which [t] is the nonlinear iteration index. The goal is to obtain the unknowns
such that Ri = 0, i, and therefore we set the left hand side of equation (4.6) equal
zero, and rearrange into the matrix form:
R1
R1
R1

[t]
u
u1
u2
R1
n
u1
R2
R2
R2
[t]

u1

u2
un u2
R2
.
(4.8)
..
.. .. = .. .
..
.
.
.
.
. .
.
[t]
Rn Rn
Rn
un
Rn
u
u
u
1

After solving equation (4.8), we update the residual and the Jacobian matrix, and
keep on solving the system until the corrections ui are sufficiently close to zero.
Let us here note that most discretisations yield sparse Jacobian matrices, and
then it is recommended to use a Krylov iteration technique, possibly preconditioned [25]. This combined technique often goes under the name of NewtonKrylov methods, and it ranks among the more popular nonlinear solution algorithms [161, 228].

60

Numerical methods

4.2 Solving elliptic/parabolic problems


We will now provide numerical methods for the following model equation:
c

u
K = q.
t

(4.9)

For the incompressible pressure equations, c = 0 and the equation is elliptic. It is


thus important that our numerical methods are applicable to any choice of c. In
this equation there is just one potential, , but the molar mass equations of the
preceding chapter have one for each phase;
= p + h,

= w, g, o,

(4.10)

while the temperature equation also has a T potential. Here we just include one
term for the sake of simplicity. We have also split the conductivity into an
intrinsic media property K and a solution dependent mobility . This distinction
is of some importance to certain numerical methods.
Now, there are roughly three schools for the solution of these types of equations, namely
Finite difference Replaces the derivatives by their finite difference approximations. Since we will use the method in an integral conservation law setting,
it is also coined the control volume or integrated finite difference method.
Finite element Uses a mathematical rigorous variational formulation, and like
the finite volume method it applies to a wide variety of problems.
Mixed finite element An extention of the finite element method which simultaneously computes fluxes and potentials.
Let us here emphasise that in the discretisation we must honour the conservation
law from which the equations were derived. In particular, the flux (K) n~
must be continuous once it is discretised. Failure to do so implies that the amount
of mass leaving from cell i to j may not equal the amount entering j from i.
Another aspect is the treatment of boundary conditions. Boundary conditions
can be used for coupling different spatial regions together, for instance a water
aquifer with an oil reservoir, a production/injection well with the reservoir, or
even the source rock with the carrier bed for secondary oil migration. The two
types of boundary conditions we consider are
Specified flux (Neumann) (K) ~n is given on the boundary. For an inward

flux
(K) ~n < 0,
(4.11)

4.2 Solving elliptic/parabolic problems

61

the boundary mobility must be given, while for an outward flux


(K) n~ > 0,

(4.12)

we can use the mobility on the inside of the domain.


Specified potential (Dirichlet) = 0 is given on the boundary. Then a flux is
computed, and it will be inward if
< 0 ,

(4.13)

where is the inner potential, and outward if


> 0 .

(4.14)

Each of the three discretisation methods have numerous subclasses of methods, and we shall briefly cover some of these, but we make no pretence of a
comprehensive treatment; for that refer to [5] and the references therein.

4.2.1 Integral formulation: Finite differences


We exclusively consider the integrated finite difference methods as they are applicable to general geometries and ensure that the computed fluxes are conservative. The integral formulation of equation (4.9) comes from equation (1.1), and it
is
Z
Z
Z
u
q dV .
(4.15)
c dV (K) ~ni dS =

i
i
i t
Replacing the time derivative by finite differences, and using that our parameters
are cell centred yields
uin+1 uni
Vi ci

Z
i

(K) ~n dS = Vi qi .

(4.16)

Next i is substituted with its subsurfaces ik , yielding


ni
uin+1 uni X

Vi ci
t

k=1 ik

(K) ~n dS = Vi qi .

(4.17)

Let the set of control volumes contributing to the flux integral across ik be given
by the set Mik :
Mik = {i, ik , . . .} .
(4.18)

62

Numerical methods

Then the flux integral can be approximated


Z
X
ij j .
(K) n~ dS ik

ik
jM

(4.19)

ik

The values ij are the transmissibilities for the conductivity tensor K, and we will
show how these can be computed shortly. To ensure stability, the mobility is
evaluated upstream on ik , giving ik . This upstream value is defined by
(
P
i ,
ij j < 0,
PjMik
ik =
(4.20)
ik ,
jMi ij j > 0.
k

This is based on physical reasoning, as the mobility


P of a fluid should be chosen
from the direction it is coming. To determine ij j , the last known value of
should be used. This means that during a Newton iteration, the upstream direction might change. If the potential gradient is the Darcy potential gradient of
equation (4.10), we use
i = (p )i + ( )ik hi ,
(4.21)
where the specific gravity on ik is evaluated by the saturation weighted mean
( )ik =

(S )i + (S )ik
.
(S )i + (S )ik

(4.22)

Note that the upstream weighting causes the fluid to flow preferably along grid
directions [112, Chapter 1]. Substituting equation (4.19) into (4.17) yields
ni
X
uin+1 uni X
ik
+
ij jn+1 = Vi qi .
Vi ci
t

(4.23)

jMik

k=1

Our residual equation for grid block i is then


ni
X
uin+1 uni X
ij j Vi qi .
Ri = Vi ci
ik
+
t
def

k=1

(4.24)

jMik

It is conventional to evaluate the flux potential at the next (unknown) time step
for optimal stability since the elliptic operator has infinite propagation speed.
Two point flux approximation

Consider now the flux integral


Z
fik =
Z
=

K ~n dS

(4.25)

ik

(~n K) dS.

(4.26)

ik

4.2 Solving elliptic/parabolic problems

63

Assuming that is approximated by a constant on either side of ik , we can


then discretely approximate the flux integral on both sides by
i ik
,
fik Aik kKi ~nk
k~
xik x~i k

(4.27)

and

i ik
.
(4.28)
fik Aik kKik ~nk k
k~
xik x~ik k

Here ik is the potential at x~ik on ik . We can eliminate it from the equations by


rewriting them into
i ik =

fik k~
xik x~i k fik 1
,
=
Aik kKi ~nk
Aik Ti,ik

(4.29)

ik ik =

xik x~ik k fik 1


fik k~
,
=
Aik kKik ~nk
Aik Tik ,i

(4.30)

and

where

Ti,ik =

kKi ~nk
.

k~
xik x~i k

(4.31)

Adding together equation (4.29) and (4.30) gives us



fik  1
1
T + Tik ,i .
i ik =
Aik i,ik

(4.32)

Consequently, the transmissibilities for ik are


ii =
iik

Aik

1
Ti,i
+ Ti1
k
k ,i
= ii .

(4.33)
(4.34)

Multipoint flux approximation

The two point flux approximation is only valid when K n~ is orthogonal to the
other normal vectors of the same control volume; i.e., the grid is K-orthogonal
[8]. Skewed grids or a non-diagonal tensor K are typical violations of this. By

approximating the flux on ik by multiple nearby


potentials and conductivities,
we get a discretisation method applicable to many other grids.
In approximating the flux fik , is represented by
X
=
m m (~
x) ,
(4.35)
m

64

Numerical methods

4
2

Figure 4.2: Interaction region for the O-method.


where m are the discrete potential values and m are spatial basis functions. Then
equation (4.25) becomes
X Z
fik =
Km ~n dS
(4.36)
m

ik
m
X

m ~nik K m .
(4.37)
Aik

m
To make the discussion concrete, we consider the O-method in 2D, as shown in
figure 4.2. We wish to find the fluxes across the four half edges included in the
given interaction region, and the potential will be assumed to be linear in each
cell. Consider the lower left cell in the figure, where we represent by
= 1 1 + 1 2 + 4 3 ,

(4.38)

in which 1 equals one in the cell centre and zero in the two mid points, 2 equals
one at 1 and zero in the two other points, and 3 equals one at 4 and it is zero
in the two other points. We do likewise on the other cells. As for the two-point
flux, we wish to eliminate the midpoint potentials by assuming flux continuity.
The half edge flux from cell i to cell j is
fi,j =


Ai,j X
m n~i,j Ki m ,
2 m

i 6= j.

(4.39)

Imposing flux continuity across all edges implies


fi,j = fj,i ,

i 6= j.

(4.40)

4.2 Solving elliptic/parabolic problems

65

which for our case gives the four equations


f1,2
f2,3
f3,4
f4,1

f2,1 ,
f3,2 ,
f4,3 ,
f1,4 .

=
=
=
=

(4.41)
(4.42)
(4.43)
(4.44)

The unknowns here are both the cell centred potentials and the midpoint potentials. We can write the left hand side of these equations in the matrix form
f~ = C ~ D,
~
(4.45)

where ~ is the vector of midpoint potentials and ~ is the vector of cell centred
potentials. By the flux continuity constraints (4.40), we also have
A~ = B ,
~
(4.46)

This equation can be solved for the midpoint potentials, yielding the half edge
fluxes

~
(4.47)
f~ = C A1 B D .
| {z
}
T

Each row in the matrix T corresponds to transmissibilities for each half edge flux
Two interaction regions must be used to construct the
in the interaction region.
whole edge flux transmissibilities in 2D, and four in 3D.
While we have just presented the O-method type of interaction region, other
type of interaction regions must be used for highly skewed grids (the Z-method
[206]), and special care must be taken for faulted grids (O-method for faults
[102, 11]). Furthermore, computationally cheaper multi point flux methods which
couple fewer cells in 3D are also available (the U-method [9, 10]). A recent overview can be found in [7].
Boundary conditions

For a Neumann type boundary condition we know the flux on the boundary ik .
Then in equation (4.19) we insert this specified flux rather than using transmissibilities. The mobilities are still evaluated upstream. This means that for an outward
flux, we use the inner mobility, but if the flux is inward, a boundary mobility must
be supplied.
However, for a Dirichlet boundary condition with specified boundary potential
, we must modify the transmissibility calculation slightly. In the preceding we
have always eliminated the midpoint potentials to arrive at an expression for the
transmissibilities, but since the boundary midpoint potentials are now known, we
can instead insert these into the flux continuity constraints directly, see figure 4.3.

66

Numerical methods

111111111111
000000000000
000000000000
111111111111
2

Figure 4.3: Handling of Dirichlet boundary conditions for the multi point Omethod. 2 and 3 are known potentials, and need not be eliminated by flux
continuity assumptions.

4.2.2 Variational formulation: Finite elements


The finite element method is based on a Galerkin variational integral formulation
of the differential conservation law. Let u be represented by the linear combination
u=

uj j ,

(4.48)

where uj are (unknown) scalars and j are (known) basis functions. We shall
return to the nature of these basis functions later.
To derive the formulation, multiply equation (4.9) by i and integrate over the
whole domain, giving
Z
Z
Z
u
c i dV ( K) i dV = qi dV .
(4.49)

Next, we replace the time differential by finite differences and perform integration
by parts on the flux term:
Z

un+1 un
i dV +
c
t

K i dV

Z
(K ~n) i dS =

qi dV .

(4.50)

Rearranging, we arrive at
Z

c n+1
u i dV +
t

Z
(K) i dV =

Z
Z
c n
u i dV + qi dV + (K ~n) i dS. (4.51)

Inserting the discrete representation (4.48) for u yields the residual equation for

4.2 Solving elliptic/parabolic problems


i1 i

67
i+1

00
1
11111111
1
100000000
1 0
0
1 0
1 0
10

xi2 xi1 xi
xi+1 xi+2
Figure 4.4: Linear hat basis functions in the one dimensional case. These satisfy equation (4.55) in each cell with the (internal) boundary conditions i (xj ) =
ij .
node i:
def

Ri =

Z
ujn+1

Z
c
j i dV + (K) i dV

Z
Z
Z
X
c
n
uj
j i dV qi dV (K n~) i dS. (4.52)
t

The potential is represented similarly to u by


X
=
j j .

(4.53)

As an example, if the potential is the Darcy velocity potential, its gradient is



X
X
=
j j =
(p )jn+1 + hj j .
(4.54)
j

If the pressure is the unknown that is being solved for, it would now be easy to
handle it implicitly.
Basis functions

All that remains is the computation of the integrals in the residual equation Ri .
To do this, we must specify the basis functions i so that the integrals can be calculated. There are many different choices [46, 47, 281], so to limit the exposition
we will only discuss linear finite elements and the multiscale variant.
The linear finite elements, also called hat functions, are the weak (variational) solutions of the elliptic boundary value problem
i = 0

(4.55)


with the (internal) boundary conditions i x~j = ij and consistent (linear)
boundary conditions on the boundaries of each cell. See figure 4.4 for an illustration.

68

Numerical methods
4

3
4

Figure 4.5: Oversampling for the construction of the multiscale basis functions.
First equation (4.56) is solved to find in the oversampled cell (dashed). Then we
restrict and rescale to the actual cell (solid) to find the basis functions , which
capture subscale information, but are free of numerical boundary layers. The
symbols in the corners indicate where the different basis functions equal one.
These basis functions are simple to construct, and they have integrable differentials, which is what is necessary to carry out the integration in the residual
equation (4.52). Depending on the geometry of the cells, the integrals can be
carried out analytically rather than numerically.
However, the numerical simulation grid is usually constructed by upscaling a
much larger geological grid, and the upscaling transforms the fine scale absolute
permeability Kf into the coarse scale tensor K. However, it is clear that accuracy

can be lost. Therefore,


we can construct multiscale
basis functions which are the
weak solutions of
Kf i = 0.
(4.56)

As shown in [146, 147], this method correctly captures fine scale phenomena, and
its convergence was proven for periodic fine scale oscillations. But it was also
demonstrated that the use of the same boundary conditions for the linear case with
the multiscale case gave rise to a oscillatory boundary layer in the basis functions.
Since the thickness of the boundary layer is proportional to the frequency of
the subscale variations, it was proposed to use an oversampling technique which
computes the basis functions on slightly enlarged elements, and then extracts oscillation free multiscale basis functions. Consider the two dimensional case in
figure 4.5. We there first compute the multiscale basis functions j on the enlarged (dashed) cell, then we wish to restrict to the actual cell by
X
i =
cij j ,
(4.57)
j


where cij are scalars chosen such that i x~j = ij . In practice, this means solving
the above linear system where the two sets of basis functions are evaluated in all
the nodes of the actual cell.

4.2 Solving elliptic/parabolic problems

69

Boundary conditions

For Neumann conditions we merely substitute the specified flux (K) n~ into

the boundary integral


Z
(K n~) i dS,
(4.58)

and evaluate this integral using either the inner for outward flux or a specified
outer for an inward flux.
In the case of Dirichlet boundary conditions for the potential , we fix its
coefficients from equation (4.53) so that if i is nonzero on a Dirichlet boundary,
i would be set equal to the boundary potential there. As a result, the above
integral makes no contribution to either the residual or the Jacobian matrix of
equation (4.8), and we can therefore omit its evaluation.

Flux recovery

A problem with the finite element method is that it does not guarantee that the
fluxes are continuous across the cell boundaries. Using the representation of
from equation (4.53), the flux is
X
F~ = K =
j Kj .
(4.59)

j
The finite element method only guarantees continuity in , but not in the flux F~ .
Let us therefore try to find another representation for the flux, and project the
computed flux onto this new representation space. Henceforth, we introduce a
new set of continuous vector basis functions
~j , and represent the flux by
X
K = F~ =
Fj
~j .
(4.60)

j
The vector basis functions weakly satisfy the elliptic equation

1

~j = V1i ,
i = ,
Vi

~j = i ,

(4.61)

with the Neumann boundary conditions

~j n~ =

ij
.
Ai,j

(4.62)

This is a saddle point problem, to be discussed in the next section. However,


since it is rather simple, analytical solutions are easy to find, and in one spatial
dimension they are the hat functions of figure 4.4.

70

Numerical methods

The L2 projection of the discontinuous flux onto the function space spanned
by the functions
~j is
Z

F~
~i dV =

(K)
~i dV .

(4.63)

i,

Inserting our representation for the unknown continuous flux F~ and the known
potential gives
X
j

Z
Fj

~j
~i dV =

X
j

Z
j


Kj
~i dV ,

i.

(4.64)

This is a set of linear equations in the Fj coefficients, and once solved gives a continuous, conservative flux field. If our original problem has Neumann boundary
conditions, then we should fix the Fj values on the boundary to the specified flux.
A few remarks are in order here. There are many other ways to choose the
vector basis functions
~j . For instance, the use of higher order polynomials on
coarser meshes can give much higher accuracy [138] for smooth problems, a phenomenon known as superconvergence. But for non-smooth and nearly singular
problems, this may not be the case.
The continuous flux recovery need not be done globally, it can also be done
locally by just a few
~j functions at a time. While this is cheaper computationally,
the accuracy can also be lower.

4.2.3 Saddle point formulation: Mixed finite elements


An alternative to the post processing for finding the flux is to compute it simultaneously with the pressure. Rewrite equation (4.9) into the coupled system
c

u
+ F~ = q,
t
F~ = K.

(4.65)
(4.66)

We shall now use two sets of basis functions. First we have i for representing u,
and secondly we have
~i which will be used to represent the flux. Multiplying the
first equation by i and integrating gives
Z

c n+1
u i dV +
t

c n
F~ i dV =
u i dV +
t


Z
qi dV .

(4.67)

4.2 Solving elliptic/parabolic problems

71

Next, the second equation is first multiplied by K 1 , then by


~i , and finally it is

integrated:
Z
Z
1 ~
K F
~i dV =
~i dV
(4.68)


Z
Z
=

~i dS
~i n~ dS.
(4.69)

We represent u and its flux F~ by


u =

uj j ,

(4.70)

Fj
~j .

(4.71)

F~ =

X
j

Substituting these representations back gives two sets of residual equations:


Z
Z
X
X

c
n+1
n+1
u def
j i dV +
Fj

~j i dV (4.72)
uj
Ri =

t
j
j
Z
Z
X
c
j i dV qi dV ,
unj

t
j
Z
Z
X
n+1
1
F~ def
K
~j
~i dV
~i dS +
(4.73)
Fj
Ri =

j
Z

~i ~n dS.

Let us here remark that there are no derivatives on anymore, so for the Darcy
flux case we simply use
= p + h.
(4.74)
While the mixed finite element method can guarantee continuous fluxes, it does so
by the introduction of additional variables and the resulting system is much harder
to solve. In fact, the problem can be considered a saddle point type optimisation
problem, thereby the formulations name. There exist many customised iterative methods for solving the discrete saddle point equations, see [34] for a recent
overview. Despite these techniques, the problem is still more computationally
demanding than the other discretisations discussed herein.
Basis functions

The residual equations have no derivatives on the j basis functions, and consequently the simplest choice is to let j (i ) = ij . For the vector basis functions

72

Numerical methods

~j we can use the same type as for the continuous flux recovery for the finite
element method. Notice that with this choice, we can integrate the divergence of

~j , as required in the residual equations (4.72)-(4.73). The method achieved with


this pair of j and
~j basis functions is called the Raviart-Thomas mixed finite
element method of lowest order [225].
As for the finite element method, we can also construct multiscale flux basis
functions. Following [67], we let
~j be the solution of
1
Kf i = ,
Fi

~j = F1i ,

~j = Kf i ,

(4.75)

with the Neumann boundary conditions


j ~n =

ij
.
Ai,j

(4.76)

This must now be solved numerically, for instance by using the Raviart-Thomas
mixed finite element method.
As for the multiscale finite element case, oversampling should be used to remove oscillations from the basis functions. We first compute the basis functions

~ j on extended cells, and recover the actual basis functions


~i by

~i =

cij
~ j.

(4.77)

cij are chosen such that the boundary condition (4.76) holds. However, we cannot
in general enforce this pointwise along the whole cell boundary. Instead we can
let the average value of
~j on i,j equal 1/Ai,j and zero on the other surfaces.
Boundary conditions

Dirichlet boundary conditions have a prescribed value, which means that the
boundary integral in equation (4.73);
Z

~i ~n dS,
(4.78)

should be computed with = 0 .


Neumann type conditions are simpler; fix Fj on the relevant boundary segments to the specified flux. As was the case for the finite element handling of
Dirichlet boundaries, the above boundary integral is in practice eliminated from
the residual and Jacobian matrix in equation (4.8), so its evaluation can be omitted.

4.2 Solving elliptic/parabolic problems

73

Discontinuous finite elements

In some cases it is beneficial to relax the condition of inter element continuity.


This allows us to easily use local high order polynomials for the basis functions,
or a systematic handling of nonconformal (faulted) meshes. Collectively, such
methods are called discontinuous Galerkin methods [21].
Assume now that the basis functions for u and F~ are differentiable on each
element, but not necessarily continuous across element boundaries. Consider the
weak formulation of the saddle point problem
Z
Z
Z
Z

c
c n+1
n
u i dV +
F~ i dV =
u i dV + qi dV , (4.79)

Zt

t
Z
K 1 F~
~i dV =
~i dV .
(4.80)


Since elementwise smoothness is satisfied, integration by parts can be applied,
but the lack of inter element continuity reveals a slightly different set of equations
than earlier:
Z
Z
Z
Z
c n+1
c n
~
u i dV F i dV =
u i dV + qi dV
(4.81)
t
t

nk Z
XX

F~ ~n i dS,
Zk

Z
K 1 F~
~i dV =

l=1 kl


~i dV

nk Z
XX

(4.82)

(
~i n~) dS.

k l=1 kl

The summation over all the boundary segments kl has appeared now because
there is no explicit inter element continuity anymore. For the determination of F~
and on kl the following averaging notations are introduced;
JKk,kl

F~ k,k
l

def

= k ~nk + kl ~nkl ,

def 1 ~
Fk + F~kl ,
=
2

(4.83)
(4.84)

which yield vectors, and


{}k,kl
q y
F~ k,k
l


1
k + kl ,
2
def ~
= Fk ~nk + F~kl n~kl ,
def

(4.85)
(4.86)

74

Numerical methods

which yield scalars. A popular choice of and F~ on the element boundaries is


the Bassi-Rebay [27] method
|k = {}k,kl ,
l

~
F = F~ k,k .
kl

(4.87)
(4.88)

However, for certain grids this method produces singular Jacobian matrices. A
stabilised method [48] is
|k = {}k,kl ,
l

F~ = F~ k,k JKk,kl ,
kl

(4.89)
(4.90)

in which > 0 is a penalty term which is problem and grid dependent. Finally,
we mention the somewhat popular local discontinuous Galerkin (LDG) methods
which have
|k = {}k,kl ~ {}k,kl ,
l
q y

F~ = F~ k,k + ~ F~ k,k JKk,kl .
kl

(4.91)
(4.92)

~ is a vector constant, typically ~ = ~n/2 [75].


Some remarks should be given: The mobility on kl can be chosen either
upstream based on the last known flux F~ , or we can choose it consistently with the
boundary value of . The latter implies an arithmetic mean for the Bassi-Rebay
method.
The basis functions for both the potentials and the fluxes must be differentiable
on each element of the grid. A common choice is then to use linears for both,
but higher order choices are common. Since there is no explicit continuity, we
determine the solution piecewise in each grid cell
u|i =

ui,j j .

(4.93)

Of course, the system is coupled by the grid boundary integrals.


Our exposition has been focused on the saddle point formulation, but we can
also formulate a discontinuous finite element method in the standard variational
form. This proceeds by either eliminating the flux F~ in terms of the potential ,
or by using the variational form (4.51) on each element, keeping in mind the lack
of inter element continuity. See [208] for details.

4.2 Solving elliptic/parabolic problems

75

Multiple fluxes

For the multiphase equations multiple fluxes need to be compute, and for the sake
of conservation, these fluxes must be continuous. We can handle this in a mixed
finite element formulation by ensuring that just the total velocity is continuous
[65, 113].
Consider the idealised multiphase pressure equation:
X

pw
+
t

!
u~

(4.94)

= q.

The total velocity formulation of this is


X

pw
+
t

!
u~

(4.95)

= q,

K 1 u~T =

u~ =


pw + pc + h . (4.96)

The variational formulation of these two equations is mostly straight forward,


by using the fact that the individual phase velocities can be computed from the
total velocity by equation (2.77). However, the weak formulation of the flux in
equation (4.95), after the insertion of the phase velocity, is
Z


f u~T + Kh

( ) +

!



K pc pc

i dV .

(4.97)
The difficulty is here the representation and computation of the Kh and Kpc

terms. If the Raviart-Thomas function space is used, then the divergence


cannot
be transfered to the i function, and consequently terms of the form must

be computable. And, of course, this must be continuous, otherwise the phase


flux
is not continuous.
Perhaps the simplest way to handle this difficulty is by a finite difference approach [101]. Another way is to represent the height h and capillary pressures pc
by different finite elements, such as the Argyris elements which ensure continuity
of the second order derivatives.
But another formulation can be used which circumvent this difficulty. If continuity is enforced on each phase velocity separately, the equations to be solved

76

Numerical methods

are instead
pw
+
t

!
u~

= q,

(4.98)


K 1 u~n = n pw + pnc + n h ,
(4.99)
1
K u~w = w (pw + w h) .
(4.100)

Of course, the mixed formulation of this system gives a much larger number of
unknowns and it can thus be harder to solve.

4.2.4 Comparisons
Let us conclude this section by offering some comparative remarks on the three
distinct discretisation methods presented.
Finite differences

Continuity in all fluxes and explicit representations for all terms of the form
K are enforced. However, the flux is only known on the cell surfaces, not
the cell interior. This is unfortunate for some hyperbolic solvers which
in
rely on a global flux representation.
Convergence has only been proven for some classes of problems (homogeneous conductivity on certain regular grids [165]).
The use of upstream mobility evaluation causes the computed solution to be
grid orientation dependent.
Upstream mobility renders the Jacobian matrices to be unsymmetric, and
cannot be solved by the fastest available iterative methods.
Finite elements

No explicit continuity of the fluxes, so a post processing step must be taken.


The post processing yields a global flux representation.
A comprehensive convergence theory is available.
There are no grid orientation effects.
The discrete system matrices are symmetric, positive definite, and can be
solved very efficiently.

4.3 Solving hyperbolic/parabolic problems

77

Mixed finite elements

Solves both for the fluxes and the potentials, resulting in high accuracy and
global representations for both.
Similar convergence theory as for the finite element methods exists, but it is
not as comprehensive.
No grid orientation effects for the flux.
The introduction of additional unknowns gives a much larger system to
solve. Furthermore, the system matrix is not positive definite.

4.3

Solving hyperbolic/parabolic problems

We now turn to the second major topic of this chapter, namely the hyperbolic
formulation of the conservation laws and the subsequent numerical discretisation. While the discretisation methods of the preceding section can be used for
all of our conservation equations, they miss the advective driven nature of the
flow process and can produce numerical artifacts such as oscillations or excessive smearing. The saturation, mass and temperature equations have advective
fluxes primarily determined by the Darcy velocities, and we shall exploit this to
formulate some different advection-diffusion formulations. Based on these formulations, we present two common discretisation methods, which are
Finite volumes Similar to the control volume method for parabolic equations,
this one computes discrete fluxes across cell interfaces and discretely satisfies the integral conservation law.
Characteristic methods Follows the Lagrangian nature of the advective transport, which allows long time steps and is not affected by grid orientation
issues.
We shall not make use of much of the theory of hyperbolic conservation laws, but
it is necessary to recall the conditions for the existence of a unique solution to the
pure hyperbolic problem (4.3) [6, 145, 175, 174, 159];
u
+ (f (u)~
v ) = 0,
t
where v~ is vector independent of u.

(4.101)

78

Numerical methods

Consider a discontinuity in the solution u with u = uL on one side and u =


uR on the other. Then the Rankine-Hugoniot shock condition stipulates that a
discontinuous (shock) solution has a propagation speed of
=

f (uL ) f (uR )
.
uL uR

(4.102)

However, we need a criterion indicating if the discontinuity should evolve as a


shock or if it instead should be rarefied into a continuous solution. For this purpose
we have Olejniks entropy condition:
f (u) f (uL )
f (u) f (uR )

,
u uR
u uL

u (uL , uR ).

(4.103)

If satisfies this condition, then the solution evolves as a shock. Otherwise


the solution must instead become continuous by the introduction of a rarefaction
wave. With a complex flux function, combination of shocks and rarefactions can
occur.

4.3.1 Hyperbolic formulations


There are numerous different hyperbolic formulations of the flow equations [64],
but we shall just focus on some of the more common ones. To make the discussion reasonably concrete, we consider the advective part of the flux term in the
compositional mass equation (3.23);
X
X

u~ C =
C K pw + pc + h ,
(4.104)

and we shall look into different ways to use the Darcy phase velocity in this flux.
Fluxes in the saturation or temperature equations are similar, albeit usually somewhat simpler. The goal is to arrive at equations of the advection-diffusion form
u
+ (f (u)~
v ) K = q,
(4.105)
t

and to do that, we must identify f and v~. Notice that as earlier, we can and do
have multiple advective and diffusive fluxes.
c

Phase velocity

The very simplest formulation assumes no change in the Darcy velocity u~ while
solving the flow equations. Then each component will have as many advective
directions as there are phases. While this neglects the dependency of u~ on the
changing phase state, it is so easy to apply that the formulation is commonly found
in IMPES (IMplicit Pressure, Explicit Saturations) type simulators.

4.3 Solving hyperbolic/parabolic problems

79

Total velocity

We can instead use the total velocity formulation presented by equation (2.77).
Its assumption is that the total velocity is more slowly changing than the phase
velocities, and it leads to the component fluxes
!
X
X
X

.
(4.106)
C f u~T + Kh
( ) +
K pc pc

We rearrange this into


fT u~T + fh v~h +
| {z }
advective

C f


K pc pc ,

{z
}

(4.107)

diffusive

where
fT =

fh

C f ,

C f

(4.108)

( ) ,

(4.109)

and
v~h = Kh.
(4.110)

We now see that there are just two advective directions. One for the total velocity and another for the gravity direction. Furthermore, the capillary forces now
constitute a diffusive force, just as was the case for the pure parabolic formulation. However, as demonstrated in [246] and [215, Chapter 6], the diffusive forces
are better behaved numerically since the possible large derivatives in the capillary pressure curves are damped by the product of the phase mobilities and the
fractional flow function f [0, 1].
Constant pressure

A more pragmatic hyperbolic formulation can be had by assuming that only the
water phase pressure is constant, allowing the rest to vary. To formulate it, we
rewrite the Darcy phase velocity as
u~ = (p + h)


= K pw + pc + h

= Kpw Kh Kpc .

(4.111)
(4.112)
(4.113)

80

Numerical methods

Defining
v~pw = Kpw ,

(4.114)

we find that
u~ = v~pw v~h Kpc .
(4.115)

This is then substituted into the advective compositional flux term, yielding
X
p
f v~pw fh v~h
(4.116)
C Kpc ,
|
{z
}

advective
{z
}
|
diffusive

where
p

C ,

(4.117)

C .

(4.118)

fh =

This is as simple as the total velocity formulation, with the caveat that the capillary
diffusive forces are not multiplied by as small a factor. This can in turn give
numerical difficulties.

4.3.2 Eulerian formulation: Finite volumes


The finite volume method, like its counterpart for the elliptic/parabolic equations,
is based on the integral formulation of the conservation law in an Eulerian (fixed)
reference frame. The integral formulation of the mixed advection-diffusion equation (4.105) is
Z
Z
Z
u
q dV .
(4.119)
c dV + (f v~ K) n~ dS =

i
i
i t
Replacing the time derivative by a finite difference approximation, and integrating
from t = tn to t = tn+1 yields
Z

Z
n+1

cu

Z tn+1 Z
n

dV dt

cu dV dt+
tn

Z tn+1 Z
(f v~ K) ~n dS dt =

q dV dt.
tn

(4.120)

Using that our parameters are cell centred property, we find


uin+1

= uni

1
ci Vi

Z tn+1 Z
tn

1
(f v~ K) ~n dS dt +
ci

Z tn+1
tn

qi dt.

(4.121)

4.3 Solving hyperbolic/parabolic problems

81

Splitting i into its constituent parts yields


uin+1

uni

1
ci Vi

Z tn+1 X
ni Z
tn

k=1

1
(f v~ K) n~ dS dt +
ci

ik

Z tn+1
qi dt.

(4.122)

tn

Defining
Z tn+1 Z
Fik =

tn

f
(~
v ~n) dS dt =
ci Vi

ik

Z tn+1
g dt,

(4.123)

tn

and using the finite difference approximation (4.19) for the diffusive flux K,

we get
uin+1 +

ni
ni
X
t
t X X
n+1
n
Fik + qi .
ij j = ui
ik
ci Vi
ci
k=1

jMik

(4.124)

k=1

We have here replaced the time integrals on the source term and the diffusive
flux term by first order finite differences. For maximum stability, these should be
treated implicitly. Equation (4.124) can then be cast into residual form and solved
by a Newton iteration as earlier.
Riemann problems

To finish the discretisation, it remains to compute the flux integral Fik from equation (4.123). Since the advective flux is local, we will mostly consider explicit
solution procedures based on solving Riemann problems. The Riemann problem
is the calculation of Fik where u = uL on one side of ik and u = uR on the other.
Thus we may consider g in equation (4.123) to be a function
g = g(uL , uR ),

(4.125)

and we must integrate it from t = tn to t = tn+1 . By satisfying the RankineHugoniot (4.102) and Olejnik (4.103) conditions we get a set of wavespeeds {p }.
Since we assume that g is only dependent on the cells adjacent to ik , all waves
emanating from ik must be contained within i ik . This can be done in one
of two ways:
g can be dependent on the solution state in other cells. The most extreme
case is an implicit solution technique which couples all cells together in
computing g.
We can restrict the time step t so that the waves do not propagate too far
in each step.

82

Numerical methods


* 1


@
 6
@

tmax
@


@
?

3 @
I

 2

ik

ik

ikj

Figure 4.6: Illustration of the CFL limit (4.126). Three waves are emanating from
ik . The fastest has the speed 1 , and in this space-time plot, the point on the time
axis where it intersects ikj gives the largest stable time step.
The first option will not be pursued here, so we shall instead formalise the second.
Let the outward normal distance on ik to the first cell boundary be x. Then to
keep the wave propagation local, we must satisfy
t min
p

x
.
|p |

(4.126)

This is known as the Courant-Friedrichs-Lewy (CFL) limit [81, 82], and by obeying it we can proceed to solve the Riemann problems.
Riemann solvers

There is a wide variety of available solvers for Riemann problems, see [257] for a
recent overview. Here we will just briefly mention some common ones:
Upwind Evaluates g based on the local velocity field:

gi , v~ n~ > 0
=
, Fik = t .
gik , v~ n~ < 0

(4.127)

This method in conjunction with the phase velocity formulation is perhaps


the most common in reservoir applications. An implicit molar mass discretisation based on this can be found in [118, 119].
Godunov While the upwind method can be treated as a simple black-box method,
Godunovs method proceeds by solving the Riemann problem exactly, and
inserting the resulting wave structure into the finite volume scheme. Clearly
the analytical solution of the Riemann problem is not always possible, and
today there exists only solvers for Buckley-Leverett problems and some
black-oil compositional problems [148, 152, 153, 151, 156].
As an alternative, approximative Riemann solvers can be used. Popular
choices include Roes method and Oshers method. See [257, 6] for information.

4.3 Solving hyperbolic/parabolic problems

83

High resolution This encompasses a class of methods trying to attain higher order accuracy in smooth regions. They are all based on the ReconstructSolve-Average (RSA) algorithm:
1. Reconstruct a higher order function u from the cell-centred u.
2. Solve the advective part of the equation by using u as initial data.
3. Average the computed u on each cell to find u at next time step.
The reconstruction step must be careful to avoid the introduction of oscillations near discontinuities of the solution, consequently minimum modulo
type reconstructions into linear or quadratic polynomial are common. When
solving with this higher order u data, approximate Riemann solvers are almost always used.
Central schemes The central schemes is a class of methods combining the simplicity of the upwind scheme with the accuracy of the high resolution methods. The simplest of these is the first order Lax-Friedrichs method [173],
but more recently we have the second order Nessyahu-Tadmor scheme [201]
and further generalisations [168].
Boundary conditions

Flux boundary conditions are treated naturally by prescribing advective fluxes for
f (~
v n~) on the boundary and treating the diffusive fluxes as for the finite difference
method.
Dirichlet type boundary conditions are treated by introducing a set of ghost
cells adjacent to the boundary. In these cells we fix the solution state, and then
the Riemann solver will naturally compute the correct advective boundary flux.
Notice that this may require the evaluation of f outside the boundary, depending
on which kind of Riemann solver is in use.

4.3.3 Lagrangian formulation: Characteristic methods


The finite volume methods discussed were formulated within an Eulerian frame
of reference, and while the methods are robust, they are not without drawbacks.
The two primary drawbacks are small time step sizes and a tendency for grid
orientation dependent results. The former is due to the CFL stability constraint,
and the latter because the advective flux over a cell interface only used the direct
neighbours instead of all adjacent cells (like the multi point flux approximation
does).

84

Numerical methods

Characteristic methods instead consider a Lagrangian frame of reference


which follows the advective flux. This overcomes both stability limitations and
grid orientation problems. To see this, it is useful to introduce the material derivative

= + v~ ,
(4.128)
t
where is the time along the characteristics with advective speed v~. Clearly we
can expect that
u
u

(4.129)

t
holds for large k~
v k, as demonstrated in [150]. Closely tracking the advective field
thus leads to small temporal truncation errors. Furthermore, since the tracking can
be done on an auxiliary streamline grid, the orientation of the Eulerian grid will
have a small effect on the characteristics themselves.
However, we must also consider that the process is driven by multiple fluxes.
Operator splitting is used to decompose a problem with several advective and
diffusive fluxes into one hyperbolic problem for each advective flux, and one collected parabolic problem for the diffusive fluxes. The hyperbolic problems will be
treated here, while a standard technique may be used for the parabolic problem.
To maintain the advantages of the characteristic methods, it may be preferable to
use a highly implicit finite element type discretisation to ensure long time steps
and no grid orientation dependencies.
With this in mind, we will present some classes of characteristic methods
[114], (arbitrarily) classified as:
Streamlines Decouples the multidimensional advection-diffusion process into
multiple 1D streamlines for advection and then a diffusion solver is applied.
Characteristics Splits the advection-diffusion equation into one linearised advection equation and a corrective advection-diffusion equation.
Adjoint characteristics Closely related to the characteristic methods, adjoint
methods are based on a variational framework where the test functions satisfy a dual linear characteristic equation.
Of course, a drawback in most characteristic methods is either a failure to conserve mass or a failure to satisfy the hyperbolic conditions (4.102)-(4.103). These
problems will be discussed for each method.
Streamlines

Perhaps the most popular of the characteristic methods, the streamline philosophy
is to decouple the advection into a set of independent one-dimensional hyperbolic
equations which can be solved efficiently and independently.

4.3 Solving hyperbolic/parabolic problems

85

The method proceeds by splitting the advection-diffusion equation (4.105) into


u 1
+ (f (u)~
v ) = 0,
t c
u
c K = q.
t

(4.130)
(4.131)

Expand the flux in the first equation to


1
1
f
(f (u)~
v ) = v~ f (u) + v~.
c
c
c

(4.132)

The first term gives the advective velocity V~ while the second term can be considered a source/sink term. If v~ is the total velocity, its divergence is zero for
incompressible problems (confer equation (2.57)). Otherwise, we subtract fc v~
from the right hand side of equation (4.131) so that equations (4.130)-(4.131) become
u ~
1
+ V f (u) = 0, V~ = v~,
t
c
u
c K = q f ( v~).
t

(4.133)
(4.134)

Defining the streamline derivative

= V~ ,

(4.135)

u f (u)
+
= 0.
t

(4.136)

equation (4.133) can be written

This one-dimensional hyperbolic equation is solved along the streamlines defined


by the ordinary differential equation system
~
r ~
=V,

(4.137)

that is r~() maps from to the usual (x, y, z) space. The streamline algorithm is
summarised in algorithm 4.1, and most of its steps are now straight-forward.
However, the difficulty lies within step 4, as mapping back to the Eulerian grid
cannot be done uniquely in general since some grid blocks may contain multiple
streamlines, while some may contain none at all. While some possible remedies
are available [256, 29], some mass is usually lost in the transfer.

86

Numerical methods

1. Generate a set of streamlines by solving equation (4.137):


Chose a set of initial conditions r~(0 ) = x~i . The launching points are
usually chosen in and around the injection wells [191].
When integrating equation (4.137) it is necessary to use a global velocity field. If this is lacking, it may be reconstructed [222].
2. Map initial data u0 from the Eulerian grid onto the streamline grid just computed using an interpolation scheme.
3. Solve the one-dimensional hyperbolic equation (4.136) on each streamline
using mapped initial data:
Fast 1D hyperbolic solvers such as front-tracking [145] or a finite
volume method can be used.
Subtimestepping can be used on each streamline if desired.
4. Map the computed solutions on the streamlines back onto the Eulerian grid.
5. Solve the diffusion equation (4.134), taking into account the fc v~ term:
Any of the methods for parabolic equations can be used, but we may
prefer a method without grid orientation problems.
Algorithm 4.1: The streamline algorithm for a single time step.
Method of characteristics

For a linear advection problem, the method of characteristics yields the analytical
solution [111, Chapter 3], but for nonlinear fluxes we encounter issues of nonuniqueness due to shock formations. To apply a characteristic method, we must
create an auxiliary flux function that ensures a unique solution.
As an example, consider the idealised Buckley-Leverett flux function
f (u) =

u2
u2 + (1 u)2

(4.138)

as shown in figure 4.7, and consider a discontinuous state with uR = 0 on one side
and uL = 1 on the other. If we assume that the solution evolves as a pure shock,
then the Rankine-Hugoniot condition (4.102) states = 1, but one may verify that
Olejniks entropy condition (4.103) is nowviolated for some value of u. Instead,
we can verify that a shock with uL = 1/ 2 and uR = 0 and a rarefaction with
uL = 1 and uR = 1/ 2 satisfies the entropy condition.

4.3 Solving hyperbolic/parabolic problems

87

0.8

0.6

0.4

0.2

0.2

0.4
0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

Figure 4.7: Flux function f (u) in blue, the concave envelope fc (u) in green, and
the residual flux fr (u) = f (u) fc (u) in red.
Consequently, a consistent solution scheme must use a modified envelope flux
function fc to ensure convergence to the correct solution to the hyperbolic problem. Therefore we split the advection-diffusion equation (4.101) into the system
u
+ (fc (u)~
v ) = 0,
t

(4.139)

u
+ (fr (u)~
v ) K = q.
t

(4.140)

c
c

Here fr = f fc is the residual flux function. It is only nonzero at shock discontinuities, and it serves to sharpen the front since the flux fc may smear it
[109, 86, 84]. We may now apply the characteristic method to the linear advection
equation (4.139), then we solve the advection-diffusion equation (4.140) using the
solution of the first equation as initial data.
This method is known as the corrected operator splitting [160], in contrast to
other operator splittings which do not take the entropy conditions into considerations, and thus do not end up with a linear advection equation. Let us note that the
construction of the entropy corrected flux fc and its residual fr cannot always be
done analytically, but may instead be approximated by numerical means [160].
To solve equation (4.139) we rewrite it into a canonical form. Using the same
flux expansion as in (4.132), we get
c

u
+ f (u)~
v u = f v~.
t

(4.141)

The total (material) derivative of u along the characteristics parameterised by is


~
x
u u t
=
+ u .
t

(4.142)

88

Numerical methods

Comparing with equation (4.141) we get the coupled ordinary differential equation system

= c,

~
x
(4.143)
= f (u)~
v,

u = f v~.

This system is solved for u, t and x~, using any suitable quadrature rule [130, 131].
However, there are two distinct directions to integrate: forward or backward in
. With forward tracking we chose spatial points x~n , and use un (~
xn , tn ) as initial
conditions to integrate forward.
Backtracking would start at tn+1 in x~n+1 , but as we do not know un+1 yet, a
nonlinear iteration procedure such as a Picard iteration [128] can be used to attain
convergence from an initial guess (un+1 un ).
The advantage of forward contra backward tracking is that all mass can be
accounted for since we can evolve characteristics from every cell at tn . Backward
tracking cannot guarantee that characteristics will hit all cells in tn . However,
forward tracking has the converse problem of not necessarily hitting all the cells in
tn+1 , leading to possible oscillations lest some sophisticated interpolation scheme
is used.
Another issue is treatment of boundary conditions. If a backward tracked
characteristic intersects the outer boundary, it is natural to prescribe a Dirichlet
condition for it. And conversely, if a forward tracked characteristic leaves the
domain a compatible flux condition must be used. These are naturally handled by
the pressure solver when computing the velocity v~. However, the general handling
of boundary conditions with the characteristic method is still somewhat ad hoc
[114].

Method of adjoint characteristics

We will now discuss some alternative characteristic methods which can be applied to both the full advection-diffusion equation (4.105) or the residual equation (4.140). The idea is to use a Petrov-Galerkin finite element formulation,
which chooses test-functions satisfying an adjoint characteristic equation while
using usual finite element bases for the solution itself [229].
Multiply equation (4.105) by some test function wi and integrate both in space

4.3 Solving hyperbolic/parabolic problems

89

t = tn+1

t = tn
Figure 4.8: The test function wi is given as a linear hat function at t = tn+1
and fully aligned to the underlying Eulerian grid (refer figure 4.4). As we move
backwards along the adjoint characteristics equation (4.147) to find wi at t = tn , wi
may no longer be aligned to that mesh.
and time:
Z tn+1 Z
c
tn

u
wi dV dt+
t

Z tn+1 Z
tn

Z tn+1 Z

(f v~ K) wi dV dt =

tn

qwi dV dt.

(4.144)

Applying integration by parts to both terms on the left hand side yields
t=tn+1 Z t=tn+1 Z
Z

wi
dV
cuwi dV
cu
n
t

t=tn
t=t
Z tn+1 Z
(f v~ K) wi dV dt+

tn
Z tn+1 Z
Z tn+1 Z
(f v~ K) wi n~ dS dt =
qwi dV dt,

tn
tn
which is rearranged into
t=tn+1 Z tn+1 Z
Z

K wi dV dt
cuwi dV
n + n

t

t=t

Z t=tn+1 Z 
wi
cu
+ f v~ wi dV dt+
t

t=tn
Z tn+1 Z
Z tn+1 Z
(f v~ K) n~ wi dS dt =
qwi dV dt.

tn
tn

(4.145)

(4.146)

If we make wi satisfy the adjoint equation


cu

wi
+ f v~ wi = 0,
t

wi f
+ v~ wi = 0,
t cu

(4.147)

90

Numerical methods

then we get
Z

t=tn+1

cuwi dV
n +
t=t

Z tn+1 Z
tn

K wi dV dt +

Z tn+1 Z
tn

Z tn+1 Z

(f v~ K) ~n wi dS dt =

tn

qwi dV dt.

(4.148)

The presence of the diffusion term means that u and wi must both have integrable
differentials, and we therefore use the representation (4.48) for u at all times:
X
X
un =
unj j , un+1 =
ujn+1 j ,
(4.149)
j

where uj are scalar coefficients and j are differentiable basis functions, typically
linear hat functions. For a symmetric discretisation we use the same basis for the
wi functions at tn+1 , while wi at tn is given by solving the linear (in wi ) advection
equation (4.147), see figure 4.8.
The diffusive flux integral should be handled fully implicitly, and then it is
treated identically with the finite element method for parabolic problems. We also
treat the mass integral at tn+1 and the source term in the same way as earlier. The
boundary flux integral takes care of boundary condition treatment in a systematic
manner, see [263] for details.
R
Consequently, we only need to evaluate cuwi dV at tn to close the method.
While u at tn is known, wi is not and we must solve equation (4.147) to find it. We
shall use the rest of this section to discuss the nature of the adjoint equation and
its solution.
Notice first that the adjoint method represents mass or particle motion, in contrast to the wave motion induced by the primary characteristics. To see this, we
consider (4.148) without diffusion, sources and away from the boundary:
Z
Z
n+1 n+1
(4.150)
(cu)n win dV .
(cu) wi dV =
n+1
i

ni

in+1 is the subset of in which wi at tn+1 is nonzero, and ni is that domain


backtracked to tn by equation (4.147). What the above equation means is that the
conserved quantity cu in in+1 at tn+1 exactly equals cu in ni at tn . Therefore the
adjoint characteristics must be the particle velocity.
Since distinct particles can never occupy the same (~
x, t) position, the adjoint
characteristics can never intersect one another. This is reflect in the fact that

4.3 Solving hyperbolic/parabolic problems

91






 



 









 




 













 












tn+1

tn

Figure 4.9: Adjoint characteristics at a shock front. The moving front is drawn
in bold. Notice that the adjoint characteristics speed up over the shock. This
corresponds to an increase in particle density.
(4.147) is linear in wi , and contrasts the intersecting wave characteristics. However, the velocity of the adjoint characteristics does depend on the solution u itself,
so its tracking is not trivial.
Let us illustrate by means of a one-dimensional example, and for this purpose
we consider one of the simplest of the nonlinear flux functions, Burgers;
f (u) =

u2
,
2

(4.151)

with c = 1. Then adjoint characteristic equation (4.147) reads


w u w
+
=0
t 2 x

(4.152)

while the primal characteristic equation is


u
+
t x

u2
2


= 0.

(4.153)

Shock Consider the Riemann problem with uL = 1 and uR = 1/2. We can verify
that we get a travelling shock of speed = 3/4. Behind the shock u = 1 and
the adjoint characteristics move with speed 1/2, while ahead of it they have
the speed 1/4, see figure 4.9.
Since the adjoint equation is linear, the adjoint characteristics cannot cross
one another. Instead they bend as they cross the primal shock, thereby
speeding up. Notice that particles move closer to another over the shock,
meaning that the particle density increases (u = 1/2 u = 1).

92

Numerical methods








 



 



  



  



   



   



    




    





tn+1

tn

Figure 4.10: Adjoint characteristics at a rarefaction. While the primal characteristics would form a fan of linear (x, t) vectors, the adjoint characteristics are bent
backwards when entering the rarefaction fan. This corresponds to a decrease in
particle density.
Rarefaction Conversely, let now uL = 0 and uR = 1. This gives us a complete
rarefaction with a linearly interpolated profile:

0, x 0,
x
(4.154)
u(x, t) =
, 0 < x < t,
t
1, x t.
In this rarefaction u changes continuously, and since the adjoint velocity is
u/2, we find the characteristic equations
x u x
t
w
= = ,
= 1,
= 0.
(4.155)
2 2t

This gives x(t) = x0 t in which x0 is the initial position at t0 = 0 of the


adjoint characteristic, see figure 4.10.
While the equation for wi is linear, its dependency on u makes it hard to approximate correctly. A Riemann solver must be used to deduce the correct primal
wave behaviour so that the dual velocity becomes correct. Notice that if the flux
function is linear, f = bu, and the adjoint velocity becomes b. This velocity is the
same as the primal velocity.

Part II
Large scale simulation

Chapter 5
Design of reservoir simulators
A reservoir simulator is a computer program for solving the reservoir flow problems of part I using numerical solution techniques. As digital computers are
a relatively recent development, so are reservoir simulators, with the first versions appearing in the middle of the 1950s [269, 73]. Before that, forecasting
was based on solving analytical models such as the single-phase equations, the
Buckley-Leverett equations [270], or by simple material balance considerations
[88, Chapter 3].
However, from the 1960s and onward, there was a surge of interest in the use
and development of computerised simulation tools [70], with the model of choice
being the black-oil compositional model. As computers grew ever more capable,
complete compositional models were starting to emerge in the 1970s. The need
for general simulators handling many different production scenarios (black-oil,
compositional, thermal, chemical, etc) was soon realised [163], and led to the use
of volume balance type compositional models.
A complementary development was underway in the field of numerical linear
algebra. Early on in the use of computers, matrix equations were solved either by
direct methods (Gauss elimination or Gram-Schmidt orthogonalisation), or crude
iterative methods (Jacobi, Gauss-Seidel or SOR). However, the matrices arising
from the discretised partial differential equations are very sparse, and the current
generation of matrix solvers, the Krylov subspace methods, exploit this expertly.
The first practical Krylov method, conjugate gradients (CG) [142], appeared early
in the 1950s, but it was not until the 1970s that the method saw significant use.
As CG only applies to symmetrical, positive definite matrices, the Krylov methods GMRES [231] and ORTHOMIN [261] were developed for solving general
matrix equations. These methods are all iterative and search for the solution in an
expanding Krylov subspace. To increase their efficiency, many preconditioning
techniques were developed (incomplete decompositions or multigrid smoothers
[25]).

96

Design of reservoir simulators

The current crop of reservoir simulators are necessarily somewhat complex,


as they incorporate many physical effects whilst trying to keep computation time
to a minimum. This has led to several attempts to structure the code in a modular and maintainable manner [28, 52]. It is the aim of this chapter to outline
in some detail how we may structure a compositional reservoir simulator
based on the conservation of mass, energy and volume. The calculation of the
thermodynamical equilibrium and other secondary variables shall also be treated.

5.1 Foundations
Before discussing the simulator itself, we must lay a foundation for its design.
This includes choosing a suitable software development environment, and the construction of associated solvers for linear and nonlinear equations.

5.1.1 Programming environment


In the 1950s, the first generation of programming languages (e.g. Fortran and Algol) sat the standard for imperative programming based on a mathematical syntax.
Code written in these languages were much easier to read than the previous machine coded software due to the semantic match with the mathematical problems
one tried to solve.
But, it would turn out that human readable syntax is not sufficient for a maintainable application (Cobol is an example of this). So the 1960s saw the emergence of structured languages placing an emphasis on modularity and discrete
functions (most prominently; C).
A further step in this direction is object orientation. This design philosophy
models a software system as a set of objects that interact with each other. Syntax
support for object modelling was first provided by Simula, and later appeared in
Smalltalk, Objective-C, C++ and many others.
Lately, managed programming has emerged as the most recent established
innovation. In managed programming, software codes run in a virtual machine
which can check the code for correctness, dynamically optimise the code for the
underlying machine architecture, ensure portability (by virtue of the virtual machine layer), and perform automatic resource management.
By using a managed object oriented programming language, we can achieve
maintainable code (by object designs), and we do not have to spend time on finetuning or needless debugging (because of the virtual machine). Examples of
such languages include Java [155] and C#. Since these two are virtually identical
(primary difference is the software vendors), all code examples herein are given
in Java.

5.1 Foundations

97

5.1.2 Solution of linear equations


In discretising and solving partial differential equations, we almost always work
with matrices, and these matrices tend to be very sparse. For assembling and using
a matrix with a Krylov subspace solver, the following interface is sufficient:
i n t e r f a c e Matrix {
/ / Returns Aij
do ubl e g e t ( i n t i , i n t j ) ;
/ / Aij = value
v o i d s e t ( i n t i , do ubl e j , do ubl e v a l u e ) ;
/ / Aij = Aij + value
v o i d add ( i n t i , do ubl e j , do ubl e v a l u e ) ;
/ / Calculates y~ = A~
x
( Vector x , Vector y ) ;
V e c t o r multAdd
}
This allows us to build the matrix A and compute the matrix/vector product y~ = A~
x

entirely in a black box manner, so that the actual data structure (dense or sparse) of
the matrix is hidden from the user. The benefit is a simple interface and flexibility
to chose different implementations freely. In the same manner, we define the
following vector interface:
interface Vector {
/ / Returns xi
do ubl e g e t ( i n t i ) ;
/ / xi = value
v o i d s e t ( i n t i , do ubl e v a l u e ) ;
/ / xi = xi + value
v o i d add ( i n t i , do ubl e v a l u e ) ;
/ / Calculates the inner product x~ y~
do ubl e d o t ( V e c t o r y ) ;
}
Define now the general iterative solver interface
interface IterativeSolver {
v o i d s e t P r e c o n d i t i o n e r ( P r e c o n d i t i o n e r M) ;

98

Design of reservoir simulators

/ / Computes x~ = A1 ~b approximatively by iteration


V e c t o r s o l v e ( M a t r i x A , V e c t o r b , V e c t o r x ) ;
}
where we made use of an auxiliary preconditioner which the solver may apply
to the computed residual. This provides the basic abstraction necessary for using
sparse matrices in conjunction with Krylov subspace solvers. Note that we may
add more methods to the matrix and vector interfaces both for increased convenience and increased performance.

5.1.3 Solution of nonlinear equations


It is also useful to have an interface for solving nonlinear systems of residual
equations:
~ u) = ~0.
R(~
(5.1)
This is discretised by Newtons method into the matrix equation
~
R
~ u),
~
u = R(~
~
u

(5.2)

which is solved for the correction ~


u, upon which a new residual and residual
derivative is calculated. This procedure is iterated until convergence in u~.
A software framework for solving this must start with a code for calculating
~ and the Jacobian matrix, J = R/~
~ u, for a given u~. Thus we must
the residual, R,

implement this interface:


interface NonlinearAssembler {
/ / Evaluate the Jacobian J for the current solution iterate u~
M a t r i x c a l c J a c o b i a n ( V e c t o r u , M a t r i x J ) ;
~ for the current solution iterate u~
/ / Evaluate the residual R
Vector calcResidual ( Vector u , Vector R) ;
}
An alternative to the analytical calculation of the Jacobian matrix is to compute it
by finite differencing of the residual. This approach is easy and can also be used
to check the analytical Jacobian matrix for possible implementation errors.
~
The actual Newton solver alternates between assembling the system J ~
u=R

and solving it by an iterative method. Since a naive Newton method can often fail
to converge, we should instead use either a damped iteration by truncated linesearch or constructing a trust region. Either method can be represented by the
interface:

5.2 Simulator design

99
Numerics
@
@
R
@

Geometry 


Field



Well -

Fluid

@
@@
R

Rock

Figure 5.1: Reservoir simulator design indicating the six main modules and their
interaction with one another.
i n t e r f a c e NewtonSolver {
~ = 0~ starting from u~
/ / Solves the nonlinear problem R
Vector solve ( NonlinearAssembler R , Vector u ) ;
}

5.2

Simulator design

The simulator design we outline is based on the experiences of [209]. To keep the
exposition general and brief, we will primarily cover the binding interfaces and
only mention implementation details in passing. As such, we hope the design will
prove useful for other simulation development efforts.
All the principal modules of the simulator are shown in figure 5.1, and their
responsibilities are:
Fluid Stores primary component and fluid properties, and is responsible for computing the thermodynamical equilibrium and associated fluid properties
(viscosity, heat conductivity, enthalpy, etc).
Well Connects production and injection wells to the reservoir, and maintains the
internal well fluid state. But, it is the numerical module which must provide
the actual flow solvers inside the wells.
Geometry Provides an interface to the computational mesh, boundary conditions
and spatially varying reservoir parameters (media conductivities, well conditions, etc).
Rock Holds the relative permeability and capillary pressure curves and controls
the fluid/rock interaction that may affect both their values (by hysteresis),
or compact the porous media itself.

100

Design of reservoir simulators

Field The field module stores the complete reservoir system state for a given
time step. This includes all control volumes and associated control surfaces.
Furthermore, the field module performs the initial hydrostatic equilibration
of the fluid state.
Numerics The numerics module performs primary time stepping and stability
control. It has classes for discretising the flow equations, and can be used
with a large number of different numerical methods.
Since the design is somewhat modular, certain parts, such as the fluid or rock modules, can be made into external packages instead of being an intrinsic part of the
simulator itself. This may be useful for researchers who may need to perform thermodynamical calculations as part of an experimental compositional formulation,
but have no need for the complete apparatus.

5.2.1 Fluid description


The fluids consists of multiple chemical components dissolved into several phases.
Our fluid module stores static data and will be able to compute dynamic data
(phase equilibrium, viscosity, etc). We start with an enumeration of the phases:
enum P h a s e {
WATER, GAS , OIL ;
}
This is supplemented by the components;
c l a s s Component {
S t r i n g name ; / / Component name
int index ;
/ / Component index 0
do ubl e M;
/ / Component molecular weight M
do ubl e Tc ; / / Critical temperature Tc
do ubl e pc ; / / Critical pressure pc
do ubl e omega ; / / Pitzers acentric factor
do ubl e [ ] d ; / / Binary interaction coefficients dij
}
which are stored into a component database;
c l a s s Components {
/ / Retrieves a component based on its name

5.2 Simulator design

101

Map<S t r i n g , Component > mapComponent ;


/ / Retrieves a component based on its index
Component [ ] i n d ex Co m p o n en t ;
/ / Returns an iterator over all the components
I t e r a b l e <Component > c o m p o n e n t s ( ) {
r e t u r n mapComponent . v a l u e s ( ) ;
}
}
This is all the static data needed. Dynamic fluid data is associated with a phase,
and the generic data structure;
c l a s s P h a s e D a t a <T> {
T w a t e r ; / / Water property
T gas ;
/ / Gas property
T oil ;
/ / Oil property
T g et ( Phase phase ) ;
v o i d s e t ( P h a s e p h as e , T v a l u e ) ;
}
stores arbitrary phase data-types, including floating point values, arrays, indices,
or compositions:
c l a s s Composition {
/ / N or N
do ubl e [ ] m o l es ;
/ / Summation of the moles
do ubl e t o t a l M o l e s ;
}
Now, we must provide a set of interfaces describing the computation of important
fluid properties from hydrocarbon mixtures. Based on our conservation equations,
we need to compute
the thermodynamical equilibrium, all derived properties and associated
volume derivatives,
phase enthalpies, h ,
phase viscosities, , and

102

Design of reservoir simulators

phase heat conductivities, .


Since the enthalpy is a fundamental thermodynamical property, it will have to be
computed alongside the equilibrium calculation itself. This leaves us with one
interface for phase splitting;
interface EquationOfState {
/ / Given pressure, pw , temperature, T , and the mole composition, N ,
/ / calculates secondary variables from an equation of state,
/ / including phase enthalpies
EOSSecondaries c a l c P h a s e S p l i t (
do ubl e p , do ubl e T , C o m p o s i t i o n N,
EOSSecondaries eos ) ;
}
one for viscosity calculation;
interface Viscosity {
/ / Calculates phase viscosity, , from pressure, temperature,
/ / phase composition and density
P h a s e D a t a <Double > c a l c V i s c o s i t y (
do ubl e p , do ubl e T ,
P h a s e D a t a <C o m p o s i t i o n > N , P h a s e D a t a <Double > x i ,
P h a s e D a t a <Double > mu ) ;
}
and a last one for the finding the phase heat conductivities:
interface HeatConductivity {
/ / Calculates phase heat conductivity, , from pressure, temperature
/ / and phase composition
P h a s e D a t a <Double > c a l c H e a t C o n d u c t i v i t y (
do ubl e p , do ubl e T ,
P h a s e D a t a <C o m p o s i t i o n > N,
P h a s e D a t a <Double > k ap p a ) ;
}
Since the equation of state model has more than a single output, we have collected
them into a secondary variables class:
c l a s s EOSSecondaries {
/ / Volume, composition and density
P h a s e D a t a <Double >
V ; / / V
P h a s e D a t a <C o m p o s i t i o n > N ; / / N
P h a s e D a t a <Double >
x i ; / /

5.2 Simulator design

/ / Volume derivatives with respect to primary variables


P h a s e D a t a <Double >
dVdp ; / / V /pw
P h a s e D a t a <Double >
dVdT ; / / V /T
P h a s e D a t a <do ubl e [ ] > dVdN ; / / V /N
/ / Enthalpy
P h a s e D a t a <Double > h ; / / h
}
The state of the fluid system can now be neatly stored into a fluid state class:
class FluidState {
/ / Primary fluid variables
do ubl e
p ; / / pw
do ubl e
T; // T
C o m p o s i t i o n N ; / / N
/ / Uses the primary variables to compute the secondary
F l u i d M o d e l m o d el s ;
/ / Secondary fluid variables, from the fluid model
EOSSecondaries
eosSec ;
P h a s e D a t a <Double > mu ;
/ /
P h a s e D a t a <Double > k ap p a ; / /
/ / Further derived properties
P h a s e D a t a <Double > S ;
/ / S
P h a s e D a t a <Double > r h o ; / /
}
We store all fluid models into the Fl u i d M o d el class:
c l a s s FluidModel {
/ / System component database
s t a t i c Components C ;
/ / Fluid models
Equat i onOfState eos ;
Viscosity
visc ;
HeatConductivity heatcond ;
}

103

104

Design of reservoir simulators

Methods for computing phase properties can now be added. These would take the
pressure, pw , temperature, T and the global composition, N , as input.
Black-oil fluids

As an alternative to implementing an equation of state based on the model of 3.2,


we can also incorporate black-oil fluid properties into our model. This proceeds
by grouping the components into the three pseudo-components, aquatic, light and
heavy;
X
X
X
Na =
N , Nl =
N , Nh =
N ,
(5.3)
L

where A is the set of components grouped into the aquatic pseudo-component,


and L and H are likewise the same for the light and heavy pseudo-components.
Of course, these sets are disjoint.
Phase splitting can now be done using the explicit C fractions of the black-oil
models. However these will now be functions of pw , T and C instead of saturations. The phase splitting provides Na , Nl , and Nh , and the volume derivatives
are also straight forward to compute. It only remains to map the results given in
terms of pseudo-components back to the actual components.
While there are several ways we could perform the inverse mapping, we shall
here present just a very simple one [59]. The phase fractions are mapped using

Ca/Ca ,

A,
= C
L,
C
h /Ch , H.
Cl/Cl ,

(5.4)

Phase volume derivatives with respect to a component mass become

V
=
N

V/Na ,

A,
L,
V/Nh , H.
V/Nl ,

(5.5)

5.2.2 Modelling well performance


The phase fluid velocity from a grid block and into an adjacent well can be modelled by [217, 216]

uw = WI p pw ,
(5.6)
where WI [m] is the well index taking the place of permeability, and pw [Pa] is the
well fluid pressure. We now find that the mass and temperature fluxes between the

5.2 Simulator design

105

reservoir and the well are


F =

C uw ,

(5.7)

h uw .

(5.8)

FT =

The well fluxes can be specified as either internal boundary conditions or source/sink terms.
Fluid flow inside of a well

Since fluids may flow freely between the well and the reservoir, we need to model
the flow inside the pipeline and couple this with the reservoir flow. A sophisticated
model would take into account the coupling between the wells and the surface
production facilities too [69], but that is beyond the scope of this work. Instead,
we shall only treat decoupled wells.
w
Following [189, 126] we let u i be the interior phase fluid velocity. Then we
may adapt equation (3.16) to give the mass flow equation in the well:
X

1 N
+
V t
x

!
w

C u i

= q ,

(5.9)

where x is the coordinate along the 1D pipeline, and q now corresponds to mass
entering or leaving through perforations of the pipe walls. Energy conservation
from equation (3.38) becomes

+
x

!
w
h u i

= qe,

(5.10)

in which q e is heat loss/gain through the pipeline walls, heat conduction has been
neglected due to assumed high flow velocities, and = 1 inside the pipe. For the
well fluid pressure, pw , we utilise the volume balance equation (3.44):
R(t) R pw R T X R N
+
+
+
= 0.
t
pw t
T t
N
t

Since the residual volume R = V


and is independent of W .

(5.11)

V , the overburden has no impact as = 1

106

Design of reservoir simulators

Control mechanisms
w

For the determination of the interior well velocity u i we may either use either
Eulers equation, Navier-Stokes equation, or more popularly, the drift-flux relationship. The latter is fast and suitable to 1D gas/liquid pipeline flows.
The details of these velocity calculations may be found in the hydrodynamics
literature [104]. Here, we shall consider one aspect peculiar to well flows: the
control mechanisms. These mechanisms will be used as boundary conditions to
determine the well velocity, and we distinguish between two controls:
Pressure fixed at one point (typically bottom) of the well.
Fixed flux rate, where a pressure must be calculated to satisfy the constraint.
The former is a Dirichlet type condition, and a velocity must be found satisfying
it. If instead our well is rate controlled, then we should find a pressure such that
w
the velocity, u i , ensures that the flux computed equals the required production
rate. For an injection well we can limit flux of each phase:
X

C u i = P ,

(5.12)

where P [mol/m2 s] is the phase flux target rate. For a production well it may be
more convenient to impose a constraint on the total mass production:
XX

where P =

C u i = P ,

(5.13)

P .

Well data structure

Each well has a list of geometry indices indicating where it is perforated (completed). For every completion, a well index must be given to indicate how permeable the well is to the surrounding reservoir:
c l a s s WellCompletion {
int [ ]
perforations ;
do ubl e [ ] WI ;
}
The well itself consists of the internal fluid state, the completions, and a production control system:

5.2 Simulator design

107

Figure 5.2: The cells in the left blue layer are connected to the cells in the blue
layer on the right of the fault plane, and is an example of a non-neighbouring
connection. There is negligible flow between the blue and green layers across the
fault.
c l a s s Well {
W e l l C o m p l e t i o n compl ;
WellControl
ctrl ;
/ / State of the fluids at each perforation
FluidState [ ] fluid ;
/ / From the cross-sectional areal of the well we can compute its
/ / volume in each segment
do ubl e a r e a l ;
}
The control system can be a class for fixed pressure control, a class for fixed rate
control, or even a flexible schedule.

5.2.3 Geometry and mesh


The computational mesh can be represented hierarchically by
i n t e r f a c e Mesh {
I t e r a b l e <E l em en t >
elements ( ) ;
I t e r a b l e <I n t e r f a c e >
interfaces ();
I t e r a b l e <C o n n e c t i n g I n t e r f a c e > c o n n e c t i n g I n t e r f a c e s ( ) ;
I t e r a b l e <P o i n t >
points () ;
}

108

Design of reservoir simulators

An element is a geometrical cell of the mesh with a set of interfaces and corner
points. A connecting interface represents grid connections, which usually are
local, but need not be (see figure 5.2).
First, an element allows access to its containing geometry and associated properties:
i n t e r f a c e Element {
I t e r a b l e <I n t e r f a c e >
interfaces ();
I t e r a b l e <C o n n e c t i n g I n t e r f a c e > c o n n e c t i n g I n t e r f a c e s ( ) ;
I t e r a b l e <P o i n t >
points ( );
do ubl e
g et V o l u m e ( ) ;
RockState getRockState ( ) ;
}
The iterators here just return the local interfaces and points, in contrast to the
iterators in the M es h interface. The element has a set of rock properties which
are described in the next section.
An interface has access to its normal vector and potential boundary conditions:
interface Interface {
Element
element ( ) ;
I t e r a b l e <C o n n e c t i n g I n t e r f a c e > c o n n e c t i n g I n t e r f a c e s ( ) ;
I t e r a b l e <P o i n t >
points ( );
do ubl e g e t A r e a l ( ) ;
Vector3 getNormal ( ) ;
/ / If this is a boundary, the boundary conditions can be retrieved
boolean isBoundary ( ) ;
MassBC getMassBC ( ) ;
HeatBC g et H eat BC ( ) ;
}
We distinguish three boundary conditions: Dirichlet (specified potential), Neumann (specified flux), or well. The latter will only exists if wells are modelled
as boundary conditions, and the numerical solver must then take the well flow
into account. The specific details depend on the type of well flow and its control
mechanism.
The actual grid connections are represented through the interface
interface ConnectingInterface {
I n t e rf a ce here ( ) ;
Interface there () ;

5.2 Simulator design

Cartesian grid

109

Radial grid

Unstructured grid

Figure 5.3: Three types of 2D meshes.

do ubl e g e t F l u x M u l t i p l i e r ( ) ;
}
This couples two interfaces, which need not be geometrically adjacent. A flux
multiplier can also be given on the connections, and can be used to model flow
reduction through partially blocked pores.
Finally, we have the simple spatial points
interface Point {
I t e r a b l e <E l em en t >
elements ( ) ;
I t e r a b l e <I n t e r f a c e > i n t e r f a c e s ( ) ;
do ubl e getX ( ) ;
do ubl e getY ( ) ;
do ubl e g e t Z ( ) ;
}
Its iterators return the set of elements and interfaces which have the point as a
corner point.
Some examples of mesh implementations are (see figure 5.3):
Cartesian A grid given by x, y, and z arrays. Elements can be accessed
by the indices (i, j, k). Cartesian grids are suitable for modelling simple
sedimentary (non-faulted) reservoirs.
Radial Inflow to production wells is usually radial, and using cylindrical coordinates is here appropriate. The grid is then specified by r (radial increment),
(x-y plane angle increment) and z (height increment).
It may be convenient to formulate the equations in radial (r, , z) rather than
Cartesian (x, y, z) coordinates when using radial grids. This also converts
the non-conformal grid cells in the radial grid into conformal ones.

110

Design of reservoir simulators

Unstructured This type of grid is specified by connections and spatial coordinates of every point. The popular corner point geometry found within reservoir simulation can be converted into a conformal unstructured grid by subdivision of non-conformal quadrilaterals into conformal multilaterals.

5.2.4 Rock/fluid interaction


The current rock state are stored in the class
c las s RockState {
RockData
data ;
RockRegion r e g i o n ;
}
The rock data is different for every grid block of the mesh, while the rock region
encompasses properties spanning a number of grid blocks. We therefore define
the Ro ck D at a class;
c l a s s RockData {
/ / Porosity and its derivatives
do ubl e p h i ;
//
do ubl e d Ph i d P ; / / /pw
do ubl e dPhidW ; / / /W
do ubl e W;
/ / Overburden W
do ubl e r h o ; / / Rock density r
do ubl e c ;
/ / Rock heat capacity hr /T
/ / Symmetrical tensors storing media conductivities
Tensor K ;
/ / Absolute permeability K
T e n s o r k ap p a ; / / Rock heat conductivity r

/ / Component dispersion
P h a s e D a t a <do ubl e [ ] > d l ; / / Longitudinal dispersion d,l
P h a s e D a t a <do ubl e [ ] > d t ; / / Transversal dispersion d,t
P h a s e D a t a <Double > k r ; / / Relative permeability kr
go
do ubl e pcow , pcgo ;
/ / Capillary pressure pow
c and pc
}
and the Ro ck Reg i o n class;
c l a s s RockRegion {

5.2 Simulator design

111

Co m p act i o n c o m p a c t i o n ;
/ / Hysteresis models
R e l P e r m H y s t e r e s i s g e t R e l P e r m ( ) ; / / kr
go
C a p P r e s H y s t e r e s i s g e t C a p P r e s ( ) ; / / pow
c and pc
}
The models herein compute and change the stored rock data depending on how
the reservoir state evolves. Compaction primarily affects porosity, absolute permeability and rock density, and is dependent on the fluid pressure, pw , and the
reservoir overburden, W (3.45):
i n t e r f a c e Co m p act i o n {
do ubl e c a l c P o r o s i t y
( do ubl e p , do ubl e W, do ubl e p h i ) ;
do ubl e c a l c P o r o s i t y D e r i v P
( do ubl e p , do ubl e W, do ubl e p h i ) ;
do ubl e c a l c P o r o s i t y D e r i v W
( do ubl e p , do ubl e W, do ubl e p h i ) ;
Tensor c a l c P e r m e a b i l i t y
( do ubl e p , do ubl e W, T e n s o r K ) ;
do ubl e c a l c R o c k D e n s i t y
( do ubl e p , do ubl e W, do ubl e r h o ) ;
}
The relative permeability and capillary pressures are history dependent, so the objects must maintain an internal history. When calculating new relative permeabilities / capillary pressures, the latest phase saturations must be provided:
interface RelPermHysteresis {
P h a s e D a t a <Double > c a l c R e l P e r m
( do ubl e Sw , do ubl e So , P h a s e D a t a <Double > k r ) ;
}
interface CapPresHysteresis {
do ubl e c a l c P c o w ( do ubl e Sw , do ubl e So ) ; / / pow
c
go
do ubl e c a l c P c g o ( do ubl e Sw , do ubl e So ) ; / / pc
}

112

Design of reservoir simulators

5.2.5 Field module


The field module stores the complete system state at a time step and has functions
to calculate secondary variables. Its definition is:
class Field {
Mesh mesh ;
do ubl e t ; / / Current time
Well [ ] w e l l ;
CV [ ]
cv ;
/ / Control volumes
CS [ ]
cs ;
/ / Control surfaces
}
In our cell centred mesh, the control volume stores all the dynamic grid block
properties during a simulation run:
c l a s s CV {
E l e m e n t e l e m e n t ; / / Associated geometrical element
FluidState fluid ;
RockState rock ;
}
Velocities, however, are natural control surface properties:
c l a s s CS {
I n t e r f a c e i n t f ; / / Associated geometrical interface
P h a s e D a t a <Double > u ; / / Outward normal Darcy velocity u~ n~
}

Equilibrium initialisation

To start the simulation, we need initial values for the fluid state in the control
volumes. We can either get these values from a previous simulation run or we
can calculate a global equilibrium state such that all fluids are at rest. The former
corresponds to a hydrodynamic equilibrium, since fluids may flow, while the latter
is a hydrostatic equilibrium since the weight of the fluids balances with the phase
pressures:
p
= .
(5.14)
h

5.2 Simulator design

113

S
Sw

So
Sg

WOC

Height

GOC

Figure 5.4: Phase saturations as functions of depth at equilibrium. The size of the
transition zone between the phases is determined by the strength of the capillary
forces. In this case, these forces are quite strong.
This is the hydrostatic condition, and using it we clearly have that all fluids are at
rest since
(5.15)
u~ = (p + h) = ~0.
| {z }
=~0

However, the volume balance must always be satisfied, meaning


R = V

V = 0.

(5.16)

In defining the equilibrium, we use reservoir measurements which provide the


water/oil contact (WOC) and the gas/oil contact (GOC). WOC is the depth at
which oil is first observed, and GOC is the depth at which gas is first observed.
Above GOC, water is at a residual saturation, see figure 5.4.
The phase compositions, C , are functions of depth, and the reservoir temperature is usually set to a constant or to a linear depth-dependent profile. We must
also have the water pressure, pw , given in at least one depth. Then we shall determine the amount of moles, N , in each phase and the pressure, pw , everywhere
in the reservoir, subject to the constraints (5.14) and (5.16). This is four degrees
of freedom with four constraints in each grid-block. Boundary conditions for the
equilibration is
Sw (WOC) = 1,

So (WOC) = 0,

Sg (WOC) = 0,

(5.17)

and
Sw (GOC) = Swr ,

So (GOC) = 1 Swr ,

Sg (GOC) = 0.

(5.18)

We remark that hysteresis-free capillary pressure curves should be used for the
initialisation, since there is no actual fluid flow taking place, and therefore no flow
history.

114

Design of reservoir simulators

n 0, F n+1 F n
While tn+1 < tmax
Output F n+1 if desired
Do
Check CFL conditions for all explicit discretisations
Call all solvers in sequence, yielding the primary variables in F n+1
Calculate secondaries in F n+1
Until Rn+1 = 0
F n F n+1 , n n + 1
Algorithm 5.1: The time stepping algorithm in the Ti m eSt ep p er class. F n denotes the field state at time step tn .

5.2.6 Numerical computations


The numerical part of the simulator will encompass all the methods described in
chapter 4 applied to our reservoir flow model coupled to the well flow. To keep
it general, we have a main administrator class, which performs general time stepping, stability and convergence checks, and data output. This class, Ti m eSt ep p er, is:
c l a s s TimeStepper {
/ / The only public method: takes the initial state forward to the end time
F i e l d doTimeStepping ( F i e l d f i e l d ) ;
}
The Ti m eSt ep p er does not perform any discretisations itself. That is left to
particular Ti m eD i s cret i s at i o n objects:
interface TimeDiscretisation {
/ / An explicit discretisation has a CFL limit (4.126)
boolean i s E x p l i c i t ( ) ;
do ubl e getCFL ( F i e l d f i e l d ) ;
/ / Takes the current state and finds the next
Field step ( Field current , Field next ) ;
}
In general, we may have several of these objects. A classical choice is to have
one solving for pressure implicitly, then one solving for the masses explicitly.
This corresponds to the IMPES method. Another possibility is to have just one
instance which solves simultaneously for all primary variables (pw , T and N ).
This is the fully implicit method.

5.2 Simulator design

115

The Ti m eSt ep p er has a list of Ti m eD i s cret i s at i o n objects which are


called in sequence to find the field state at next time step. Algorithm 5.1 describes
the inner workings of the d o Ti m eSt ep p i n g method. In the algorithm, two system states are always stored, the current F n and the next F n+1 . This provides
some benefits:
The discretisations can use system values at either time step.
The relationship between primary variables (pw , T , N ) and secondary variables is unambiguous.
If a time step fails, we can reinitialise F n+1 to F n without performing any
secondary calculations whatsoever.
It is the task of the Ti m eSt ep p er to find suitable step-lengths, t. This
choice is subject to CFL constraints on explicit solvers and convergence of the
implicit solvers. An implicit discretisation yields a matrix equation, and if the
iterative solver fails to converge, the Ti m eSt ep p er must reduce t, and restart
the iteration. The Ti m eSt ep p er may also increase the time step size if convergence is rapid, and conversely reduce it if the computed change in pressure or
saturations exceeds supplied thresholds. For the latter case, we need not recompute the given state, F n+1 , but only use a smaller time step for the next iterate,
F n+2 .
Let us briefly comment on Ti m eD i s cret i s at i o n implementations. An implementation must choose which equations to solve (pressure, mass, temperature,
etc), and how to discretisation them (finite difference, finite element, mixed finite
element), and possibly also couplings between the equations if a non-sequential
solution approach is to be used. The programming of finite element and mixed
finite element methods are described in [170, 171]. For a finite difference discretisation we must compute transmissibilities:
interface TransmissibilityComputer {
void c a l c T r a n s m i s s i b i l i t i e s
( Conductivity conductivity );
I t e r a b l e <T r a n s m i s s i b i l i t y > g e t T r a n s m i s s i b i l i t i e s
( Interface intf );
}
The conductivity interface returns the conductivity tensor for a given element.
This allows us to us the same transmissibility calculation (TPFA, O-MPFA, ZMPFA, etc) for the absolute permeability, the rock heat conductivity, or the molar
dispersion tensors. The Tran s m i s s i b i l i t y class is

116

Design of reservoir simulators

class Transmissibility {
do ubl e k ; / / Transmissibility coefficient
do ubl e j ; / / Associated control volume index
}

5.3 Related issues


Before closing this chapter, we shall cover some related implementation issues
relevant to compositional reservoir simulators. These issues are table lookup for
multidimensional data, automatic differentiation, and easy input/output handling.

5.3.1 Table lookup


Tabular input is often used for relative permeability, capillary pressure, viscosity
and phase component fractions (for black-oil fluids). The tables are multidimensional, and interpolation must be used to find output values for a given input. If
the entries are evenly spaced, then the lookup can be done in constant time, but
for unevenly spaced data the complexity equals the number of entries along each
coordinate axis. This situation is even more difficult for scattered data, where a
finite element type interpolation is necessary.
Consequently, we recommend evenly spaced tabular input as this is easy to
implement and offers fast lookup performance.

5.3.2 Automatic differentiation


Function derivatives are tedious to find and compute, in particular the volume
derivatives from 3.2.6 are error prone to implement correctly. An alternative to
compute f (x) by its definition
f (x + x) f (x)
,
x0
x

f (x) = lim

(5.19)

is to use an automatic approach. There are roughly three classes:


Finite differences Approximates equation (5.19):
f (x)

f (x + x) f (x)
,
x

x > 0.

(5.20)

Other differencing schemes are also common, including central differences


and backward differences [89].

5.3 Related issues

117

Symbolic differentiation An algebraic specification of f (x) is differentiated to


produce f (x). This is performed by computer algebra software such as
Maple [190] or Mathematica [275], and the output is then converted into
computer code.
Automatic differentiation Takes a computer code for f (x), and generates computer code for f (x) by applying basic rules of differentiation. Some software for automatic differentiation is available [255].

5.3.3 Input and output files


The input file to the simulator provides all parameters needed to perform a simulation. This includes geometrical grid data, grid parameters (porosity, permeability,
etc), which fluid and rock model to use, which numerical solvers to apply, the
production schedule for the wells, etc. For the programmer, it is easy to read in a
configuration file with a fixed order, such that permeability data follows porosity
data, but this is inconvenient for the user, not to mention error-prone.
Instead, the input file can be stored in a hash map where the key is the keyword
(e.g. porosity or permeability) and the value follows directly thereafter. The
simulator can then retrieve values from the hash map without being dependent on
the ordering of keywords/values in the input file. As an extension, we can allow
a hierarchy where the value of a keyword expands to a hash map in itself. This
is useful when configuring objects such as thermodynamical models, where the
input for a cubic equation of state is quite different from that of a black oil model,
but both can get their configurations by requesting a hash map with the key eos.
On the output side, it is conventional to print selected primary and secondary variables from the system state. When we have a large number of different
variables (i.e., the whole Fl u i d St at e and Ro ck St at e objects), the job of outputting the values becomes a burden. A simpler mechanism is to perform a binary
output of the object data. Modern programming environments such as Java support this by object serialisation. The serialised data can be stored as a binary file,
which may be read in by a visualisation program at the conclusion of the simulation. Not only is this easy to implement, it is also highly efficient since the output
is binary.

Chapter 6
Parallelisation of reservoir
simulators
Numerical simulators are notoriously demanding computer applications, with an
essentially unbounded need for more power (faster processors, more memory,
etc). The reason is that we can always increase the spatial or temporal resolution, or we can use more advanced numerical / physical models.
One answer to this ever-growing demand for speed lies in faster and more efficient discretisations, another lies in the use of parallel computers. As the name
indicates, a parallel computer has numerous processing units and several associated banks of memory.
Since the advent of parallel computers in the 1980s, much effort has been applied to develop algorithms for solving partial differential equations on these machines. It turns out that most such algorithms are captured within the framework
of domain decomposition methods [243, 258, 224]. A domain decomposition algorithm splits the spatial domain into pieces, and each piece is solved on a single
processor. To attain global convergence, the processors must communicate with
one another, and the way this is done is an important differentiator between the
specific methods.
Many of the common domain decomposition methods are algebraic, meaning
that they work as parallel solvers for the discretised matrix equation
A~
x = ~b.
(6.1)

While this approach is appealing, it has the drawback of intrinsically linking the
discretisation method to the parallelisation approach. This leads to rigid software
that is hard to maintain. Software which is hard to maintain, is also hard to extend,
and consequently may not be suitable for emerging applications.
We therefore wish to present a parallelisation method which clearly separates
the flow simulation from parallelisation. This allows us to parallelise a sequential

120

Parallelisation of reservoir simulators

Figure 6.1: The union between the circle and the rectangle forms the computational domain, with the green region indicating the overlapping part.
simulator without material change to that code. A further benefit is that a change
of discretisation will not affect the manner in which parallelisation is conducted.

6.1 Schwarz methods


Perhaps the first application of domain decomposition methods was by Schwarz.
In [236] a solution to an elliptic partial differential equation on the union of a
circle and a rectangle (figure 6.1) was constructed by alternating between solving
on the two overlapping domains. Let the circular domain be denoted 1 and the
rectangular domain be 2 , and we are to solve the partial differential equation

Lu = q, in ,
(6.2)
u = g, on ,
where = 1 2 , and L is a general differential operator. Further letting
12 = 1 2

(6.3)

be the boundary of the circle that intersects the rectangle, and


21 = 2 1

(6.4)

be the boundary of the rectangle which intersects the circle, Schwarzs method
alternates between solving

[t]

in 1 ,

Lu1 = q,
[t]

u1 = g,
[t]

[t1]

u1 = u2

on \ 12 ,
, on 12 ,

(6.5)

6.1 Schwarz methods

121

u[0]
[1]

u1

[1]

u2
[2]

u1

[2]

u2

1
1 2
2
Figure 6.2: Geometric convergence proof of the Schwarz method for a onedimensional Laplace problem (L = 2 /2 x, q = 0, g = 0). Starting with u[0] , the
[1]
[1]
solution in 1 yields u1 , and is followed by the solution in 2 yielding u2 .
Notice the gradual descent to u = 0, the exact solution.
and

[t]

Lu2 = q,

[t]
u2
[t]
u2

= g,
[t]

in 2 ,
on \ 21 ,

(6.6)

= u1 , on 21 .

Problem (6.2) can be hard to solve because of the complicated geometry. The
splitting into the two subproblems (6.5) and (6.6) gives us geometrically regular
domains (a circle and a rectangle). Equipped with analytical solution methods
applicable only to regular domains, this splitting was a necessity. A geometrical
convergence proof is sketched in figure 6.2.
Nowadays, the advantage of the splitting is different: the solution of (6.5) can
be quite decoupled from the solution of (6.6). The domains only need to communicate with one another by passing updated internal boundary conditions. Consequently one processor may solve on 1 , another on 2 , and they communicate
the latest available boundary conditions. The solver on the subdomains can be
unmodified sequential codes [50]. Since the subdomain solvers in our case can be
very complicated, the fact that we can reuse them in a parallel setting by merely
updating boundary conditions, is a significant advantage.

6.1.1 Subdomain couplings


The splitting used between problem (6.5) and (6.6) is multiplicative or sequential.
This is because the specification of problem (6.6) requires the very latest solution

122

Parallelisation of reservoir simulators

Figure 6.3: A domain split into 16 subdomains. Domains of equal colour can
be solved independently of each other by the parallel Schwarz method, while domains of different colour can be solved in sequence by the sequential Schwarz
method. In this case, four processor can solve the problem in parallel.
[t]

of (6.5), namely u1 on 21 . Clearly the sequential coupling is unfortunate for a


parallel implementation, so we can instead use the additive or parallel coupling,
where the subdomain solvers take boundary conditions from the previous iteration
[t1]
(ui ).
The sequential Schwarz algorithm can be interpreted as a block Gauss-Seidel
method, while the parallel Schwarz algorithm is like the Jacobi method. As such,
the sequential method has almost double the rate of convergence compared to the
parallel [92]. But it is possible to combine the attributes of these two methods by
colouring the subdomains such that some may be solved sequentially, and some
in parallel, see figure 6.3.
Subdomains are also coupled by the type of internal boundary conditions. The
classical choice is to use the specified potential (Dirichlet) type boundary conditions, but for flow problems flux conditions (Neumann and Robin) may also be
posed. The global rate of convergence can be improved by a judicious choice of
these internal boundary conditions [254].

6.1.2 Convergence behaviour


In addition to the treatment of the internal boundary conditions, the convergence
behaviour is also influenced by the number of subdomains and the amount of
overlap between them.
Diffusion dominated problems

For an elliptic or diffusion dominated parabolic problem, we have that [243]

6.1 Schwarz methods

123

the larger the number of subdomains, the slower the global convergence is,
while
greater overlap between the subdomains leads to faster convergence.
To see this, consider Poissons elliptic equation

u = q, in ,
u = g, on .
We can express its solution, u, by Greens function [111, 2.2.4]:
Z
Z
y )G(~
x, y)
~ dV (~
y)
g(~
y )y G(~
x, y~) n~ dS(~
y)
u(~
x) = q(~

(6.7)

(6.8)

Greens function, G, is the solution of



G = x , in ,
G = 0, on ,

(6.9)

where x equals one in x~ and zero elsewhere. This implies that Greens function
has a peak at x~, but rapidly decays to zero away from x~. From equation (6.8)
we see that any internal changes in q or boundary data, g, implies changes everywhere in u. However, the rapid decay of Greens function means that the effect is
primarily local.
Now, the overlap between the subdomains is used to capture the local effect of
Greens function. However, when we have many subdomains, the global effect of
Greens function is not captured very well. The updated information computed in
one subdomain is conveyed to another subdomain only by passing through all the
intermediary subdomains. For the domain splitting in figure 6.3, this can mean
that four Schwarz iterations may have to be done for information in one corner to
travel to an opposite corner.
Advection dominated problems

Hyperbolic or advective dominated parabolic problems have solutions which are


predominantly determined by local phenomena (temporal and spatial). Consequently, only a modest amount of overlap is necessary. For the finite volume
methods, just a minimal overlap is needed, but for the characteristics methods,
additional grid blocks may have to overlap to allow for large time steps.
The local nature of the advection also implies that convergence rate is independent of the number of subdomains. This means that parallel Schwarz couplings
may be used even with an enormous number of subdomains [157, 158].

124

Parallelisation of reservoir simulators

13

12
2

14
4

Figure 6.4: The computational domain is initially partitioned into a set of non i }. Each of these domains are extended to form a set
overlapping domains {
of overlapping subdomains {i }. The internal boundary of 1 , 1 = 1 \ is
split into parts 12 , 13 and 14 given by the intersection with the non-overlapping
i }.
subdomains {

6.2 Multi-level extentions


Of the reservoir equations, the pressure equations are primarily diffusion dominated, and for incompressible fluids they become elliptic. Then, a large change in
the local pressure field will have global impact, which can severely degrade the
performance of the Schwarz domain decomposition algorithms. Changing production scenarios (i.e., shutting off or opening wells) is perhaps the most common
cause of an immediate global pressure change.
The remedy is to supplement problem (6.2) with the same type of problem, but
on a coarser scale. Using a coarser grid allows us to solve the problem quickly,
and the solution can be used as a coarse scale correction of the fine scale solution
we seek. Mathematically, the coarse scale resolves the smallest frequencies of the
error, leaving the fine scale error frequencies to be resolved on the primary, fine
scale grid.
If the fine scale mesh is very detailed with many grid cells, it may be preferable
to use a sequence of successively coarser grids. This in turn resolves progressively
larger scales of the equation error. Amongst the most popular of algorithms in this
class are the multigrid algorithms. While well tested and widely used, they have
an unfortunate drawback: the coarse scale corrections are done on the algebraic
level of equation (6.1). This locks parallelisation to discretisation, which may not
be desirable.
Instead we shall outline a multi-level coupling that may be conducted in a
black-box manner, e.g. only by changing boundary conditions. The method proposed is an extention of the cascadic multigrid algorithm [45, 239].

6.2 Multi-level extentions

125

6.2.1 Two-way couplings


The cascadic algorithm starts with solving on the coarsest mesh, and interpolates
the solution there onto the next finer mesh. This is the starting point for finding
the solution on this mesh. The algorithm cascades down until the finest mesh, and
once convergence has been attained there, the iteration is stopped.
For time dependent flow problems, we can adapt this cascadic approach by
using the coarse scale solution as boundary conditions on the finer meshes. These
boundary conditions are used as initial estimates for the subdomain couplings at
the finer scale, and will of course be overwritten as the fine scale Schwarz iteration
proceeds to attain convergence.
Since our problems are time dependent, we can improve on this simple algorithm. Let vfn be the internal fine boundary data and let vcn be the coarse internal
boundary data, both given at time tn . By the above algorithm, we first calculate
vcn , and start the fine scale iteration by
vfn vcn .

(6.10)

A better initial estimate of vfn can be found by using the last fine boundary data
vfn1 . Clearly
vfn1 = vcn1 + vfn1 ,

(6.11)

which can be solved for the fine scale correction, vfn1 , giving
vfn1 = vfn1 vcn1 .

(6.12)

Then we may replace (6.10) by


vfn vcn + vfn1 .

(6.13)

Another problem is that there is no information passing from the fine scale
to the coarse scale. If the coarse scale model is not adequate, its solution may
drift away from the fine scale solution, and the boundary data, vcn , it produces can
become progressively more incorrect. A simple remedy is to replace the initial
conditions of the coarse scale model by the converged fine scale solution.

Chapter 7
Parameter estimation
An important prerequisite for useful production forecasting with a reservoir simulator, is accurate and comprehensive input data. Parameter estimation or history
matching is the process of finding missing field data which matches the production
history of the reservoir. The known data that we must match include:
pressure and fluid data in and around wells,
production history (ratio of oil to water, ratio of gas to oil),
tracer tests and recorded water break through, and
core samples.
These measurements are usually quite accurate, but may contain errors, and are
also spatially restricted to the well regions. Other data include reservoir interpretations based on geological insight and seismic measurements. While not as
tangible, they serve as an initial estimate of the reservoir and its properties, and
can help to steer the parameter estimation away from obvious dead ends.
Now, the type of fluids and their properties can be readily determined from
laboratory experiments of reservoir fluid samples. What we must match is primarily rock data:
porosity and absolute permeability,
rock compressibility,
relative permeability and capillary pressure,
identification of fluid contact regions (WOC and GOC), and
specific geological features, such as faults.

128

Parameter estimation

Figure 7.1: A simulation grid with about 10 distinct geological layers and three
major faults. Taken from the Visund geometry.
The core samples provide this data in selected parts of the reservoir, but it is our
task to determine these properties everywhere.
It is conventional to carry out parameter estimation manually. Then, one starts
with a reservoir interpretation, and performs simulation runs with this model. The
output of the model is compared with measured well data, and the reservoir data
is modified until a match in all parameters is achieved. Naturally, this is very time
consuming and error prone, hence the proverb a good history match is obtained
when you run out of time or money.
Instead, by formulating the history matching as an optimisation problem, we
can make the process automatic. In the optimisation we use the measurements
as solution constraints, while reservoir interpretations are used as initial estimates of the subsurface conditions. As a part of the optimisation, numerous flow
simulations must be conducted, and these must clearly be fast and capable of incorporating a highly detailed geo-description.

7.1 Parameter representation


The amount of objective data (i.e., the data to be matched) is almost always
dwarfed by the amount of data we seek. A simulation grid can consists of over
105 grid cells, and with a cell centred representation of the parameters, we have
a severely under-determined problem. Consequently we must represent the unknown rock parameters such that their degree of freedom better matches that of

7.1 Parameter representation

129

the measured data set.


Since reservoirs are formed by continuous sedimentation, they have a highly
layered geological description. Within a layer we may then assume relatively
homogeneous media properties. If we have nx ny nz grid blocks, we can then
reduce the amount of parameters to just O(nz ).
But life is not so simple, since structural mechanical forces produce fractures
and larger faults within the reservoir. This results in grid distortions as seen in
figure 7.1. While the amount of parameters is still relatively small, their spatial
placement is now somewhat hard to capture a priori.

7.1.1 Coarse grid representation


Perhaps the simplest approach is to use an auxiliary coarser grid for determining
the sought parameters [202, 204]. Since our rock parameters are constant on each
grid block, the interpolation onto the primary simulation grid is simple.
While conceptually simple, this representation has the drawback of being rigid and hard to adapt to complicated geometries. While grid adaption could be
applied, that would defeat the purpose of the coarse grid representation.

7.1.2 Level set representation


What we really want to do is to capture the boundaries of the distinct regions and
to determine the (essentially) homogeneous media properties within each region.
A level set representation [211, 212] furnishes a way to accomplish just this. To
illustrate, let be a closed curve within the domain, . We define the associated
level set function as the signed distance function, , relative to the interface :

distance(~
x, ),
x~ interior of ,
(~
x) =
(7.1)
distance(~
x, ),
x~ exterior of .
With this construct, we clearly have

> 0,
(~
x)
= 0,

< 0,

x~ interior of ,
x~ ,
x~ exterior of .

(7.2)

To use this level set function for parameter representation, we shall utilise the
Heaviside function

0, x 0,
H (x) =
(7.3)
1, x > 0.
Clearly H () = 1 inside of and zero elsewhere.

130

Parameter estimation

++
+

Figure 7.2: Two curves divide the domain into four regions. If the curves do
not overlap, ++ will disappear, and we would have three regions left.
Let our unknown parameter be a, and assume for simplicity that it has only
two values, a1 inside and a2 outside of . Then

a = a1 H () + a2 1 H () .
(7.4)
This reduces the identification of a to just identifying a1 , a2 and . And to find
, we only have to move the zero level set of the level set function . This is a
substantial gain over identifying a in every grid block.
This approach may be generalised to multiple level sets following the idea in
[60]. Consider two closed curves 1 and 2 with associated level set functions 1
and 2 . These will partition into four distinct regions, see figure 7.2, where
++
+
+

=
=
=
=

{~
x : 1 (~
x) > 0, 2 (~
x) > 0} ,
{~
x : 1 (~
x) > 0, 2 (~
x) < 0} ,
{~
x : 1 (~
x) < 0, 2 (~
x) > 0} ,
{~
x : 1 (~
x) < 0, 2 (~
x) < 0} .

(7.5)
(7.6)
(7.7)
(7.8)

If a assumes distinct values in each of these regions, we may represent it by


a = a1 H (1 )H (2 ) +

a2 H (1 ) 1 H (2 ) +

a3 1 H (1 ) H (2 ) +


a4 1 H (1 ) 1 H (2 ) .

(7.9)
(7.10)
(7.11)
(7.12)

In general, with n level set functions, up to 2n distinct regions may be represented


by allowing these functions to overlap. The representation easily allows for degenerate cases where level sets do not overlap, or that a level set function is of a
single sign. As such, we can provide an upper estimate on the number of distinct
regions of the reservoir before the history matching process is started.

7.2 Parameter identification

131

The general representation of the parameter a with n level set functions is


a = a1 H (1 )H (2 ) H (n ) +

a2 1 H (1 ) H (2 ) H (n ) +
..
.



a2n 1 H (1 ) 1 H (2 ) 1 H (n ) .

7.2

(7.13)
(7.14)
(7.15)
(7.16)

Parameter identification

We now have a representation of our parameters. Since there is usually more than
a single parameter to find, we may use the same representation for each (i.e., the
same coarse grid or the same set of level set functions).
The parameter identification procedure must find parameters a and solution u
such that the equation errors ei in each of the reservoir flow equations E is zero:
ei (u; a) = 0,

i E.

(7.17)

But at the same time, we must honour measured data


u(~
x, t) = u(~
x, t),

x~ .

(7.18)

is the subset of
The function u can contain noise or other uncertainties, and
where the measurements were taken. The solution of equations (7.17)-(7.18) can
be formulated as an output least-squares problem:

minimise ku(~
x, t) u(~
x, t)k ,
(7.19)
subject to ei (u; a) = 0, i E.
Another possibility is the total least-squares formulation:
X
minimise ku(~
x, t) u(~
x, t)k +
kei (u; a)k .

(7.20)

iE

Any norm can be used in either (7.19) or (7.20), but it is common to use the L2
norm. To facilitate an easier differentiation, the norms are often squared. This
squaring does not change the solution of the optimisation problem, however.

7.2.1 Regularisation
Hadamards definition [129] of a well-posed problem is that
1. it must have a solution,

132

Parameter estimation

2. the solution must be unique, and


3. the solution must depend continuously on data and parameters.
The solution of a parameter identification problem is u and a. As it turns out,
the reservoir flow equations can yield essentially the same solution, u, for many
different parameters, a, and can be highly sensitive to small perturbations. Consequently, our parameter identification problem is ill-posed [76].
A partial solution to this is to regularise the problem [105]. The forward problem of solving for u given a is well-posed, and it need not be regularised. But the
inverse problem of finding a given u is not, and hence must be regularised.
Tikhonov regularisation

Tikhonov regularisation [124] minimises the norm of the parameter a or any of its
derivatives. As such, we augment either of the minimisation problems (7.19) or
(7.20) with


n a ,
(7.21)
where > 0 is some scalar weighting the regularisation against the least squares
optimisation, and n 0 is an integer. With n = 0, we try to keep a small, with
n = 1, we instead wish to minimise the total variation, and with n = 2, it is the
curvature that should be minimised.
If we have some estimate a of what a should be, we can supplement (7.21)
with


n a n a ,
(7.22)
where > 0 is another scalar weighting factor.
Level set specific regularisation

The Tikhonov regularisation (7.21) can be applied directly to the level set parameter representation. For n = 1 this gives

X

j .

(7.23)

Here, is the Dirac delta function which equals one if its argument is zero, and
zero if not. Therefore we can interpret
the above as the area of the j surfaces in

some suitable norm, since j = 1 only if j = 0, and this in turn occurs only
on j .

7.2 Parameter identification

133

7.2.2 Solving the optimisation problem


We have now representations for the sought parameter a, some least-squares formulations and suitable regularisation methods. The only remaining component is
a solution algorithm for the optimisation problem that we are left with.
The total least squares problem (7.20) is an unconstrained problem, while the
output least squares problem (7.19) has equality constraints. We may prefer the
latter since it guarantees that all constitutive relationships are satisfied. However,
its solution can usually only be found by recasting the constrained optimisation
problem into a sequence of unconstrained optimisation problems.
Methods for unconstrained optimisation problems

Consider first the general unconstrained optimisation problem, with s~ representing


both u and a:
min f (~
s).
(7.24)
There are numerous methods for solving this problem [205, 37, 117]. The simplest
~
are perhaps the line search methods. They first determine a descent direction, d,
then find a step length, , such that


f s~[k] + d~[k] < f s~[k] ,
(7.25)
where k is the iteration index, > 0 is chosen to give sufficient descent at each
step, and d~[k] must satisfy



d~[k] f s~[k] < 0, d~[k] = 1.
(7.26)
This ensures that d~[k] is a unit vector and that it points towards a descent direction.
Popular choices of d~[k] include the steepest descent method

d~[k] = f s~[k]
(7.27)
or a conjugate gradient direction [205, Chapter 5]. Another classical line search
method is Newtons method, which approximates



 1
f s~[k] + d~[k] f s~[k] + d~[k] f s~[k] + d~[k] 2 f s~[k] d~[k] .
2

(7.28)

We seek d~[k] which minimises the right hand side, and by differentiation, we get


(7.29)
2 f s~[k] d~[k] = f s~[k] .
This linear matrix system can be solved to yield d~[k] .

134

Parameter estimation

Methods for constrained optimisation problems

Now consider the solution of


min f (~
s)

(7.30)

under the equality constraints


ei (~
s) = 0,

i E.

(7.31)

The Karush-Kuhn-Tucker (KKT) [167] condition states that if s~ is a solution,


then
 X

f s~ =
i ei s~ .
(7.32)
iE

The scalars
are the Lagrangian multipliers at the optimum, and are additional
unknowns to be determined during the solution process. From this we define the
Lagrangian functional
X

~ = f (~
L s~,
s)
i ei (~
s),
(7.33)
iE

and it is clear that the KKT condition can be restated into



~ = 0.
s~L s~ ,

(7.34)

We wish to design an algorithm which minimises L with respect to s~. To


create a functional algorithm that penalises deviations from (7.31), we augment
the Lagrangian functional with a penalty term [141, 221]:
X


~ = L s~,
~ + 1
LA s~, ;
ei (~
s) 2 ,
2

(7.35)

iE

where is a some small and positive barrier parameter. The last term is always
positive, and an unconstrained optimiser must try to ensure ei = 0 if LA is to be
minimised. Differentiating LA with respect to s~ yields
~
s~LA s~, ;

1X
ei (~
s) ei (~
s)

iE
iE

X
ei (~
s)
ei (~
s) .
= f (~
s)
i

= f (~
s)

i ei (~
s) +

(7.36)
(7.37)

iE

Comparing this with the KKT conditions (7.32) indicates that the optimal Lagrangian multiplier can be approximated by
i i

ei (~
s)
.

(7.38)

7.2 Parameter identification

135

~[0] and a barrier parameter [0] > 0


Given a starting point s~[0] ,
for k = 0, 1, 2, . . .

k+1 of L
~[k] ; [k] , starting with s~[k]
Find
an
approximative
minimiser
s
~
s
~
,

A


~[k] ; [k] <
if s~LA s~[k+1] ,
return with the approximative solution s~[k+1]

[k+1]

[k]

Update the Lagrangian multipliers i


= i

Reduce the barrier parameter [k+1] 0, [k]
end

ei s~[k+1]
[k]

Algorithm 7.1: The augmented Lagrangian algorithm for solving an optimisation


problem with equality constraints. An unconstrained minimisation algorithm can
be used for minimising LA with respect to s~.
This in turn suggests that we can update the Lagrangian multipliers in the iterative
manner

[k]
s
~
e
i
[k+1]
[k]
i
= i
.
(7.39)
[k]
Rearranging shows



[k]
[k+1]
,
(7.40)
ei s~[k] = [k] i i
and by driving towards zero, this updating of ensures that the constraint violation is very small as the above is the product of two small numbers. A method
based on this augmented Lagrangian approach is given in algorithm 7.1.

Part III
Papers

Chapter 8
Summary of the papers
Seven papers are included as part of this thesis. Two of the papers have been
accepted for journal publication, three will be included in conference proceedings,
and two are as of yet in a draft state.
The papers cover a broad range of topics in computational mathematics. In
this chapter we provide a summary of the contents of each paper, and list the main
contributions.

140

Summary of the papers

Paper A
A Parallel Eulerian-Lagrangian Localized Adjoint Method
Bjrn-Ove Heimsund and Magne S. Espedal
This paper considers parallelisation aspects of the adjoint characteristic
method introduced in 4.3.3. Parallelisation of characteristic methods has been
studied in several other papers [265, 253], but the algorithms proposed there are
usually somewhat complicated and/or inconsistent with the discretisation from the
sequential case.
Our goal was to perform a parallel discretisation such that the matrix equation
in the parallel case coincided with the matrix equation in the sequential setup.
In the paper, we considered a linear advection-diffusion problem, and recall that
the adjoint characteristic method must then solve the adjoint characteristic equation (4.147)
w
+ v~ w = 0.
(8.1)
t
Since this is a purely hyperbolic equation, it does not depend upon the global system state, and can be solved locally in each subdomain. At subdomain boundaries
with adjacent processors, we only have to communicate the local velocity field v~
for the solution of the adjoint equation.
This results in a matrix equation
A~
x = ~b
(8.2)

which is identical to the sequential discretisation. A parallel matrix solver must


be utilised to ensure a fully parallel method.
Main results of the paper:

Developed a simple and robust parallelisation scheme for advectiondiffusion equations by the adjoint characteristic method.
Discussed implementation aspects of this method on different parallel architectures.
Provided comparisons of the new method with other parallelisation method
for adjoint characteristic methods, and performed a simple scalability test
on a parallel computer.

141

Paper B
Adjoint methods are particle methods
Thomas F. Russell, Bjrn-Ove Heimsund, Helge K. Dahle and Magne S. Espedal
The adjoint methods were originally developed for linear advection-diffusion
problems. For that class of problems, the adjoint method is very efficient since
it allows essentially arbitrary long time steps [58]. In this paper we study the
application of the adjoint characteristics method to nonlinear advection problems.
It turns out that the adjoint equation corresponds to particle motion instead
of wave motion. Particles can always be traced, and there is never problems of
non-uniqueness. A wave shock only affects particles by speeding them up.
Based on this particle interpretation, we designed a numerical algorithm for
solving the one-dimensional adjoint particle equation (4.147)
w f (u) w
+
= 0.
(8.3)
t
u x
This linear advection equation gives the particle speed once we have the primary
solution u. To effectively predict the evolution of u, we used Riemann solvers.
This works well for shocks, but at rarefactions we experienced difficulties due to
the continuous change in u. We were able to overcome some of these difficulties
by introducing a small amount of artificial diffusion. The introduction of this
diffusion can be motivated by the mass dispersion present in compositional flows,
see equation (3.23).
We extended the one-dimensional algorithm to two dimensions by splitting the
advection field into decoupled streamlines. Along each streamline we could then
apply our one-dimensional algorithm. Since we assumed that the dispersion is
mostly longitudinal and not transversal, there was no need to map the streamline
solution back onto the original Cartesian grid.
Main results of the paper:

Established that an adjoint method corresponds to mass motion, and that the
adjoint characteristics are particle paths.
Developed a numerical algorithm for solving nonlinear advection-diffusion
equations in one spatial dimension. The algorithm relies on a Riemann
solver to ensure accurate particle tracing. Extended the algorithm to two
dimensions by a streamline splitting.
Numerical results for one and two dimensional problems showed that the
method provided accurate solutions with time steps far greater than the explicit CFL limit.

142

Summary of the papers

Paper C
Multiscale Discontinuous Galerkin Methods for Elliptic Problems
with Multiple Scales
Jrg Aarnes and Bjrn-Ove Heimsund
The discontinuous finite element method has gained popularity within the
fields of fluid- and structural mechanics [74]. This paper investigates their potential use within reservoir mechanics with a special emphasis on the multiscale
structure of the medium permeability.
4.2.2-4.2.3 introduced both the multiscale finite element method and the discontinuous finite element discretisation. The paper combines these two, motivated by the potential higher accuracy of the discontinuous finite element method
and the possibility of capturing subgrid effects in permeability offered by the
multiscale methods.
The resulting method was applied to the single phase equation (2.30)
K = q

(8.4)

with a highly oscillatory permeability field K. Compared to other multiscale


methods (finite element and mixed finite element), our new method offers competitive flux results, with highly accurate potentials.
To get this accuracy, we had to make a judicious choice of numerical fluxes.
The paper used the numerical flux functions (4.89)-(4.90)
|k = {}k,kl ,
l

~
F = F~ k,k JKk,kl ,
kl

(8.5)
(8.6)

which make the solution dependent on the free parameter . Theoretical results
for isotropic and homogeneous problems show that convergence is achieved for
 
1
,
(8.7)
>O
h
where h is the grid size [57]. But for realistic problems, no such results seem to be
available. Indeed, it is common to use = 0, even if that may give non-convergent
methods [48, 27].
Through several numerical tests the paper illustrates the impact of , and it is
clearly established that an un-optimal choice (i.e., = 0) leads to errors of order
O(1). Larger values of gives better results, but too large values may ruin the
accuracy.

143

Main results of the paper:

Combined the multiscale and discontinuous finite elements into a new discretisation method for elliptic equations with rapidly varying subscale permeability.
Established the potential performance of the method on some problems with
a highly oscillatory subscale permeability.
Provided a numerical convergence comparison between multiscale and
monoscale methods, of finite element, mixed finite element and discontinuous finite element type.

144

Summary of the papers

Paper D
Level set methods for a parameter identification problem
Bjrn-Ove Heimsund, Tony Chan, Trygve K. Nilssen and Xue-Cheng Tai
This paper shows how to apply the level set representation to parameter identification problems. Along with [149], it was the first paper to consider level set
methods for this purpose.
As shown in chapter 7, the level set representation of a piecewise constant
parameter is done by an implicit representation of the boundary interface between
the distinct regions. So when trying to identify this parameter, we do not have to
determine its value cell by cell. Instead we only have to determine the boundary
interface. By regularising the size of the interface (to avoid folding), we achieve
a large reduction in the degrees of freedom of the problem.
In the paper we considered the single phase pressure equation (2.30)
K = q.

(8.8)

The task was to identify the scalar permeability K given measurements of the
potential in selected nodes. Using an output least-squares formulation, the resulting minimisation problem was solved by the augmented Lagrangian method.
Main results of the paper:

Formulated the elliptic parameter identification problem using a level set


representation of the parameters.
Calculated analytical derivatives of the output least-squares functional such
that efficient conjugate gradient methods can be used.
Performed numerical experiments which indicated good performance, even
with noisy data on . However, a relatively larger number of observations
was used.
The performance of the level set representation is superior to the coarse grid
representation of the permeability [203].

145

Paper E
On a class of ocean model instabilities that may occur when applying
small time steps, implicit methods, and low viscosities
Bjrn-Ove Heimsund and Jarle Berntsen
With more efficient numerical methods and faster computers, it has become
feasible to perform simulation studies with reduced or omitted artificial diffusion.
In ocean modelling, artificial diffusion can be introduced by increasing the viscosity of water.
It has been observed that with physical viscosity, the time stepping procedure
fails to converge, even if the time step size t 0 [115]. These difficulties are
not peculiar to ocean physics, they may very well occur in sophisticated reservoir
simulation tools.
Therefore we tried to find a possible explanation for this counter-intuitive phenomenon. The paper considers the ordinary differential equation (ODE)
u
= u,
t

C.

(8.9)

An ODE solver is absolutely stable if it produces bounded solutions to this equation as t . Now, some solvers have a stability region of values in the complex plane that includes part of the right (positive) half plane. A combination of
negligible diffusion and specific implicit ODE solvers can give stable solutions
for t > . But if t < , these methods produce unbounded oscillations. The
paper properly identifies the conditions for these instabilities so that they may be
avoided.
Main results of the paper:

Furnished stability requirements for some common multistage and multistep ordinary differential equation integrators.
Tested multistep, multistage (Runge-Kutta) and implicit ODE solvers on the
linearised 2D shallow water equations.
Obtained perfect match between theoretical and numerical results.
The analysed implicit ODE solver has been implemented in the Bergen
Ocean Model [36].

146

Summary of the papers

Paper F
A two-mesh superconvergence method with applications for adaptivity
Bjrn-Ove Heimsund and Xue-Cheng Tai
The flux recovery method for finite element discretisations has been explained
in 4.2.2, and it is known that the recovered flux can be more accurate than the
original flux, a phenomenon known as superconvergence [282]. As a follow-up to
[138], this paper considers the flux recovery method as a mesh refinement indicator.
Large discrepancies between the computed flux of the finite element method
and the recovered flux can be used to indicate regions where the mesh should be
refined. The equation studied is
K = q.

(8.10)

A large emphasis is placed on numerical results, hence we consider several different permeability fields K, sources q and domains . Non-convex domains and
singular problems were also considered to test the method to its limits.
The refinement is compared to the classical jump indicator [107, 154]
v
u ni
uX
2
(8.11)
EJ (i ) = |i | kqki + t |ik |2 ~nik (K)
k=1

which is based on an error estimate for the computed flux. In the paper we
show that our flux recovery based method is superior to this classical indicator
for smooth problem. For less regular problems, the recovered gradient computed
from the flux recovery adaptivity is generally the most accurate.
Main results of the paper:

Gave an error indicator for mesh adaptivity based on flux recovery.


Compared this method to the classical jump error indicator with a large set
of numerical studies.
Compared to the classical jump error indicator, this method gave superior
potential and flux approximations for smooth problems.
Obtained good flux approximations even for non-smooth problems.

147

Paper G
High performance numerical libraries in Java
Bjrn-Ove Heimsund
In the last paper we consider the construction of a set of software components
for scientific computing. Aside from basic arithmetics, the fundamental software
component for scientific calculations is a comprehensive matrix library. Such a
library must provides matrix factorisations and solvers, and should preferably be
efficient to program with and efficient in terms of computer time.
As argued for in chapter 5, modern programming environments such as Java
can significantly enhance the productivity of the programmer by removing much
of the burden of code tuning and debugging. Consequently, we want to provide
matrix tools which are easily usable from Java whilst not compromising performance.
Starting from basic vector and matrix operations, the paper builds up a matrix
library with useful abstractions to the underlying machine architecture and matrix
data structures, while providing consistently high performance through a range of
industry standard benchmarks. In particular, the matrices arising from the discretisation of partial differential equations tend to be very sparse, so we designed a
sparse matrix data structure with an easy interface. In standard benchmarks, our
implementation outperformed established sparse matrix software.
The design of the matrix toolkit was so flexible that an extention to parallel architectures was implemented. The implementation includes parallel matrix
solvers and preconditioners, and good scalability was demonstrated.
Main results of the paper:

Contrary to popular belief, our Java matrix library was able to perform on
par or better than counterpart software written in C or C++.
Provided the design schematics of an extensible matrix library.
Demonstrated auxiliary functions such as iterative solvers and matrix factorisations.
Showed parallel extentions, along with suitable distributed matrix data
structures.

Chapter 9
Further work
Based on the two introductory parts and the papers, we can identify some areas
of future research. This includes a further investigation of numerical methods
with model formulations, and development of techniques for practical large scale
simulations.

9.1

Numerical methods

In 4.3.1 we provided several different ways to formulate the hyperbolic/parabolic flow equations. Essentially, we identified several
choices for f (u) and v~ in the flux
Hyperbolic formulations

(f (u)~
v) .

(9.1)

The goal should be a velocity v~ which changes as little as possible when the solution u changes. Furthermore, if the velocity is divergence free, v~ = 0, and
(f (u)~
v ) = v~ f (u).

(9.2)

This removes a potentially troublesome source term. Capillary forces can be ill
behaved with large gradients. To avoid numerical difficulties, the capillary pressure gradient pc should be multiplied with a damping factor. The total velocity
formulation multiplies pc by the product of the relative permeabilities, and this
leads to enhanced numerical stability [246, 215].
Different hyperbolic formulations have been investigated in [64, 39], but not
comprehensively. In particular, we should seek a formulation that closely satisfies
the above conditions. Then we will have a numerically stable discretisation, and
the flux computation can be done accurately with a Riemann solver for f (u).

150

Further work

The mixed finite element


method does not seem to have been applied to compressible multiphase problems with capillarity and gravity. Perhaps the closest is in [101], where a finite
difference method was coupled to the mixed finite element discretisation. Under
varying simplifying assumptions, [65] applied the mixed method to many kinds
of porous media flows, but the general case was not treated.
Equations (4.98)-(4.100) in 4.2.3 show a simple extention of the mixed finite
element method to multiple phases under no particular simplifying assumptions.
The solution of that formulation will provide conservative fluxes for all phases
simultaneously. However, some conditions must be imposed on the approximation spaces for the potential and the fluxes to ensure convergence. Furthermore,
that system will also be hard to solve numerically, but an investigation of this
formulation ought to be carried out.
Mixed finite element method for multiple fluxes

All the convergent numerical


fluxes for the discontinuous finite element method involve the choice of some
scalar tuning parameters [21]. For many applications, one can find a good choice
of these parameters which are suitable for a large range of problems. But in our
paper on multiscale discontinuous finite elements, we saw a strong dependency
of the tuning parameter on the accuracy of the method. An optimal choice of
the parameter was found by an exhaustive search, and this did give good results.
Therefore, it should be worthwhile to find a priori criteria on how to chose good
values for the parameter(s).
Convergence of discontinuous finite elements

Adjoint characteristics applied to compositional systems

servation of a component within a phase (3.9):



S C

+ u~ C = q .
t

Consider the con-

(9.3)

Here, q is the mass transfer of a component between phases. This equation can
be solved for the fraction C by tracking the flux u~ . In a particle (adjoint)
formulation, we solve the adjoint equation
1
w
+
u~ w = 0.
t
S

(9.4)

Notice that this adjoint equation is only dependent on phase properties, not component properties. This means that for a three-phase, multi-component system,
only three equation (9.4) are needed for every particle to be traced, and this can
result in large computational savings.

9.2 Large scale simulations

151

But we must determine or be able to approximate q . It can be considered as


the amount of mass of component leaving or entering phase due to changes in
the thermodynamical equilibrium. The performance of the method may very well
hinge on this source term, and an investigation is warranted.

9.2

Large scale simulations

In chapter 5 the design of a compositional


reservoir simulator was outlined in some detail. In implementing it, we should try
to have the different modules as decoupled as possible. This can turn the resulting
software into a useful numerical laboratory for mathematicians and engineerings
working on porous media flows.
For instance, there can be a general fluid state package, a rock properties package, and a geometry package. Furthermore, general discretisations of the methods
in chapter 4 can be made to function on the canonical equations therein. From this,
we can build a two-phase incompressible simulator by leaving out the fluid state
calculations, but keeping the numerics, the geometry, and the rock properties. A
black-oil simulator can use the same pieces, but add fluid state calculations and a
slightly different set of primary equations. A compositional simulator would need
all pieces, but could require more sophisticated solvers.
The advantage is a large amount of reuse, while making the software accessible to users at different levels (from basic research to novel field applications).
A side benefit in the modularisation is the ease of maintenance, since there is no
large monolithic software to comprehend.
Numerical simulation laboratory

The parallelisation presented in our paper on adjoint


characteristic methods can be considered as a precursor to the ideas in chapter 6.
In the paper, we relied on a parallel matrix solver to ensure full parallelisation
throughout the code, but the black-box multi-level approach seems a promising
way to ensure scalability without the need for sophisticated methods.
Also, the use of just boundary conditions to communicate between subdomains makes it easy to construct maintainable software, and the result fits nicely
with the philosophy of the numerical simulation laboratory. This is because researchers carrying out parallelisation can consider the subdomain solvers as blackboxes, and conversely the discretisation can consider the parallelisation as a blackbox.
Black-box parallelisation

Parameter identification
by optimisation and level set representations have so far only been carried out
Parameter estimation for compositional problems

152

Further work

for one- and two-phase problems. Typically, it is only porosity and permeability which are the unknown parameters. Therefore it would be useful to study
automatic history matching with a complete compositional model. Such a model
incorporates much more fluid data, and the fluid data can be assumed known.
Consequently, we get much more known data into the problem compared to
one- and two-phase problems, but the amount of unknowns ( and K) are the
same. It should then be expected that better results can be achieved by using the
more sophisticated forward model.

Paper A
A Parallel Eulerian-Lagrangian
Localized Adjoint Method
Bjrn-Ove Heimsund and Magne S. Espedal
Abstract
We describe an approach to parallelize Eulerian-Lagrangian localized adjoint
methods such that no errors are introduced compared to the sequential case. This
parallelization approach fully captures the hyperbolic features of the underlying
problem. It uses an overlapping domain decomposition technique, and does not
involve the introduction of artificial boundary conditions between subdomains.
Implementation details on different parallel architectures are discussed.

Accepted for publication in Advances in Water Resources

A.1 Introduction

A.1

155

Introduction

The Eulerian-Lagrangian localized adjoint method (ELLAM) is a method developed by Celia, Russell, Herrera and Ewing [58] to solve linear advectiondiffusion equations. Later works by Binning and Celia [38, 40] have extended
the method to multiple spatial dimensions. A general overview of ELLAM is
found in [229], while [263] contains numerous implementation details.
Advection-diffusion equations arise in applications such as groundwater flows
and reservoir flooding. In many cases, the size of these problems are such that
parallelization is necessary, both to increase accuracy by mesh refinement and
to decrease the solution time. Much effort has been applied to extend domain
decomposition methods [243], originally developed as a preconditioner for elliptic
and parabolic problems, to solve advection-diffusion equations. See [253, 262,
264] and the references therein for more information.
Those approaches subdivided the computational domain into disjoint pieces
and solve nested advection-diffusion problems on each subdomain. The domains
are joined together by choosing artificial boundary conditions which tries to capture the flow direction. However, no analysis has been done to analyze the errors
which are introduced.
In this work we will propose a method for parallelization of the ELLAM such
that no errors are introduced, and with a theoretically nearly linear scalability,
as we will argue for. No artificial boundary conditions are introduced between
subdomains, instead characteristic information is passed between the subdomains
to fully capture the hyperbolic nature of the problem.
The outline is as follows. Section A.2 gives a variational formulation of the
continuous equation to derive the basic ELLAM formulation, and briefly discusses
the choice of a basis for the approximation space and the test-space. Section A.3
is on how to perform the numerical integration and characteristic tracking. With
this background, parallelization is discussed in Section A.4, followed by a brief
comparison and a numerical example.

A.2

Variational formulation

Let U be an open, bounded subset of Rn , and set UT = U (0, T ], T > 0. We will


consider the linear advection-diffusion equation
u
+ (V u Du) = 0 in UT .
t

(A.1)

The functions V : UT Rn and D : UT Rnn are given, and the unknown is


u : UT R. We will assume the range of D to be symmetrical and positive definite.

156

A Parallel Eulerian-Lagrangian Localized Adjoint Method

To this equation we add Dirichlet, Neumann


specified as
u = gD ,
Du n = g N ,
(V u Du) n = g R ,

and/or Robin boundary conditions


on U D [0, T ]
on U N [0, T ]
on U R [0, T ],

(A.2)

where g i : U i [0, T ] R, i = {D, N, R}, and U D U N U R = U. The


intersections of these sets have zero measure in Rn1 . In addition, we specify
initial conditions by
u = u0 on U {0}.
(A.3)
Equation (A.1) with the conditions of (A.2)-(A.3) is a fully specified linear parabolic problem, and its existence/uniqueness properties are described in for instance [111]. To give a weak formulation for Equation (A.1), multiply it with a
test-function w, and integrate over UT :
Z
Z
u
(V u Du) w dxdt = 0.
w dxdt +
UT
UT t

The first term is integrated by parts with respect to t, while the other term is
integrated by parts in x, giving
t=T Z
Z
Z

w

(V u Du) w dxdt
u dxdt
uw dx
UT
U
UT t
t=0
Z
(V u Du) nw dsdt = 0,
+
UT

which is then rearranged into


t=T Z
Z
Z

(V u Du) nw dsdt
u Dw dxdt +
uw dx
+
U
U
U
t=0
T

Z T
w
u

+ V w dxdt = 0.
t
UT
Next, we partition the time-domain into finite intervals of size t = tn+1 tn , and
in each time-interval, w satisfies the localized adjoint equation
w
+ V w = 0.
(A.4)
t
Using this, our variational formulation becomes

Z
Z

u Dw dxdt
uw dx
n+1 +
UT n+1
U
t
n

Z
Z

(A.5)
(V u Du) nw dsdt =
uw dx
+
.
UT n+1
n

t=tn

A.3 Numerical integration

157

tn+1

tn
Figure A.1: Here the test-function wi is given as a hat-function. At tn+1 it is
aligned to the Eulerian mesh, but as we move back to tn , it follows the Lagrangian
nature of the problem, and it may no longer be properly aligned. The dashed lines
refer to the spatial representation, while the dotted lines show the time-evolution.
We choose spatially dependent basis-functions {i }M
i=1 where M is the number of
n
spatial nodes, and represent u at t = t by
u(tn ) = un =

M
X

in i ,

i=1

where in R are the coefficients of the discrete representation of u(tn ). For each
i , we associate a test-functionwi which
equals i at t = tn+1 , but satisfies Equa
tion (A.4) in the time interval tn , tn+1 . Consequently, wi is constant along the
characteristic
dx
=V,
(A.6)
dt
andwe can backtrack to find the value of wi anywhere in the time interval. For
t 6 tn , tn+1 , we set wi = 0. See Figure A.1.
Note that u is defined by a fixed (Eulerian) grid. wi is also defined by a fixed
grid, but only at tn+1 . As we backtrack, wi follows the Lagrangian characteristics
of the problem and may not be aligned to the Eulerian grid at tn .

A.3

Numerical integration

Having chosen a discrete representation of the solution and the test-functions, we


now outline how to compute the integrals in (A.5) numerically. However, our
treatment will be brief, and for more details the reader is referred to [136] and
[263].
All the integrals will be assembled into a linear system of the form
A n+1 = b,
where A RMM , b RM , n+1 RM . The components of n+1 are in+1 , the
coefficients of the discrete representation of u at t = tn+1 . Depending on the basis

158

A Parallel Eulerian-Lagrangian Localized Adjoint Method

functions, such a system may be very sparse and iterative linear solvers can be
used.
The first integral on the left hand side of (A.5) gives a mass-matrix. Both u and
wi will be on the same fixed mesh at tn+1 , and one can in fact compute this integral
analytically, as is done in standard finite element formulations. This addition is
added into the system matrix A.
On the right hand side there is also a mass integral, but it represents the mass
at the previous time t = tn . While it is possible to treat it analytically for some
special velocity fields V , in general, a numerical approach must be used.
The numerical approach we use here is forward-tracking. We choose quadrature points at t = tn , and forward track them using Equation (A.6) to t = tn+1 ,
where we can evaluate wi . A simple prediction tracking of a point xn is given by

xn+1 = xn + V xn , tn t,
(A.7)
and uses only information on V at the time tn . A better tracking is the predictorcorrector method
( n+1
x0
= xn + V (xn , tn ) t


(A.8)
n+1
xj+1
= xn + 21 V (xn , tn ) + V xjn+1 , tn+1 t, j = 0, 1, 2, . . .
The initial prediction is corrected iteratively using the average of the initial velocity and the velocity at the predicted spatial point at t = tn+1 . This corrective
cycle typically converges after only a few iterations. Depending on the form of V
and the time-stepping procedure used, it is also possible to use more sophisticated
tracking schemes, see [13, 125, 136].
Having chosen a tracking scheme, we proceed to evaluate the mass-integral
by performing element-wise integration


Z

XZ


=
uw
dx
uw dx
.
n
n
U
U
t=t
g
g
t=t

Here g loops over all the elements of the grid. Next, we choose a quadrature rule
with p integration points, and approximate the integral by


XX g g
XZ
g

Wp u(xp , tn )w(xp , tn ).
uw dx
n
Ug
g p
g
t=t

Wp are integration weights of the chosen quadrature rule, and xp are the integration points. At t = tn , u is known and can be substituted into the integration.
g
g
g
To evaluate w, we forward-track each xp to t = tn+1 , giving xp . At xp we note

A.4 Parallelization

159
t = tn+1

t = tn
Ui

Uj

Figure A.2: A part of the spatial domain has been divided into Ui and Uj . The
forward-tracked characteristic from Ui enters the domain Uj .
which wi are non-zero, and add an integral contribution to row i of the right-hand
side vector b.
Returning to the left hand side of Equation (A.5), we have the diffusion term.
It may be approximated by an implicit Euler

Z
Z

u Dw dxdt t u Dw dx
,

UT b
a

t=tn+1

which makes it possible to handle the spatial integral analytically. To achieve


higher accuracy, a trapezoidal rule can be used, such as


Z
Z
Z


t

+
u

Dw
dx
u Dw dx
u Dw dxdt
n .
n+1
2
U
U
U b
t=t
t=t
Ta

We note here that a tracking procedure is needed to evaluate w at t = tn , as described above.


The final integral is the boundary integral. It may also be approximated using
some implicit Euler or some other time integration rule. Since this term is of
peripheral interest in this paper, we refer the interested reader to [86] and also
[263] for a comprehensive treatment.

A.4

Parallelization

Our method to parallelize the solver for (A.5) is to assemble the matrix A and the
vector b in parallel, so as to achieve both data and computational parallelization.
To do this we partition the spatial domain U into the set {Ui }Pi=1 such that Pi=1 Ui =
U. The coefficients V and D are also given on the same spatial partition, and by
associating one processor on each subdomain, that processor will only have access
to its local coefficients and local solution state u(tn ).
Consider Figure A.2. Using Equation (A.7) to predict the characteristic,
its path may enter neighbouring subdomains. Correcting the path using Equation (A.8) is now not possible unless V in Uj is made available to the solver

160

A Parallel Eulerian-Lagrangian Localized Adjoint Method


t = tn2
t = tn1

Ui

1111
0000
0000
1111
Overlap

Uj

t = tn

Figure A.3: The characteristic at t = tn forward-tracks from Ui into Uj . For the


given overlap region, we see that we cannot integrate further than t = tn1 , as that
would require information not available to Ui .
operating in Ui . The key to parallelization then lies in making this velocity field
available across the subdomains.
A simple approach is to let each subdomain solver have a copy of the global
velocity field V . However, this can require a substantial amount of memory, and
will require a possible tremendous amount of subdomain-communication every
time a new velocity field is generated. Especially for more realistic cases, where
the velocity field is influenced by additional physical parameters, the scalability
of the parallel solver can be severly hampered.
Instead, we propose to use a small overlap region between the subdomains
where V is made available to neighbouring sub-solvers. For a given point x on
the boundary ij between Ui and Uj , the characteristic starting at x in Ui extends
V (x) nij t =

(A.9)

into Uj . nij is the outward normal on ij from Ui to Uj . This is only an estimate


of the length, since the velocity field at the predicted spatial point may change the
final path. Furthermore, this estimate is only valid for a given spatial point x, not
the whole boundary of the subdomain.
However, we can use Equation (A.9) to either estimate the needed size of the
overlap for a fixed t, or, for a fixed overlap the maximal t can be found.
See Figure A.3. As an alternative, one can also use the Courant number of the
physical problem to get an upper bound on the overlap size , and use this overlap
between every subdomain.
By evenly distributing the workload of the system assembly between the subdomains, linear scalability in the assembly process is possible. Parallelization of
the solver of the resulting linear system is easy, as a Krylov-subspace method
can be used. These solvers have matrix-vector products as their computational
core, and such operations are easy to parallelize and can attain linear scalability

A.4 Parallelization

161

[25]. Furthermore, preconditioning is seldom necessary, as it is well-known that


advection-diffusion problems have only high-frequency errors which are quickly
damped by most iterative solvers.
Some remarks are in order:
1. All current parallel computers can be classified as either a shared- or a distributed memory system. The former implies that any processor can access
all the memory for any other processor, and for the latter memory is local
to each processor and explicit communication (or message-passing) must
occur between processors to exchange memory.
On a shared memory computer, all information is available to all nodes,
and the parallelization becomes a triviality if one already has code to solve
(A.5). No communication is necessary, we merely have to ensure each processor only performs assembly on its assigned subdomain.
This means that only distributed memory machines require overlap as described herein. Here one needs a distributed matrix and vector to hold the
assembled system, a distributed parallel Krylov-subspace solver, and a message passing library to exchange the velocity field V . We refer to [243] and
its references.
2. If only the prediction tracking (A.7) is used, parallelization becomes easy
as no overlap is needed. Since we use forward-tracking, every tracked characteristic will only need one value of V , the value at the quadrature point.
Thus only the local V is needed, and overlap is superfluous. Of course, using only a prediction tracking can result in insufficient accuracy when there
is significant time variation in velocity.
Also, it is possible to use a tracking scheme which uses V from earlier
timesteps t < tn , using a modified definition of w. For this case it again
becomes necessary to use overlapping subdomains. We shall not provide
any details.
3. The discretized equations for the sequential ELLAM are the same as those
we find with this parallelized ELLAM. Consequently our method enjoys
the same benefits as ELLAM does, namely mass conservation, symmetrical
positive definite matrices, rigorous treatment of boundary conditions, and,
depending on the overlap size , large timesteps.

A.4.1 Comparison with other methods


Another recent approach to parallelize the ELLAM solver has been proposed in
the works of Wang [262, 264]. There a substructuring domain decomposition

162

A Parallel Eulerian-Lagrangian Localized Adjoint Method

Outflow, Ui

Inflow, Uj

Figure A.4: The characteristic from Ui flows across Uij into Uj .


approach was used to solve the ELLAM equations. The spatial domain was divided into non-overlapping subdomains {Ui }Pi=1 . On each subdomain, a closed
advection-diffusion equation was formulated just like to global equation, but on
the subdomain boundaries, artificial boundary conditions were imposed.
For every subdomain Ui , its internal boundary condition is classified as either
inflow, outflow or noflow by


UiI = x | x Ui , V (x) nij < 0 ,


UiO = x | x Ui , V (x) nij > 0 ,


UiN = x | x Ui , V (x) nij = 0 .
On inflow boundaries, Robin boundary conditions are imposed with

giR = (V u Du) nji j ,
that is, the boundary data is taken from the adjacent subdomain. At outflow boundaries, a Dirichlet condition is used with
giD = u|j ,
and finally, on noflow boundaries, a zero Neumann condition is used. See Figure A.4.
Since this approach introduces artificial boundary conditions, the computed
parallel solution will contain additional errors compared with the sequential case.
To keep the errors small, the timestep used in the numerical tests was also small.
This is in contrast to our proposed scheme, which incurs no additional errors at
all and does not limit the timestep artificially. Furthermore, this domain decomposition approach requires the same amount of subdomain communication as our
approach when using one element of overlap.

A.4.2 Numerical result


To demonstrate the parallel performance, we have coded a very simple shared
memory implementation for solving the linear advection-diffusion equation. It is

A.4 Parallelization

163

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0
0

0.2

0.4

0.6

(a) t = 0

0.8

0
0

0.2

0.4

0.6

0.8

(b) t = 0.8

Figure A.5: Advection-diffusion problem. The intersection in the x-y plane is


shown for both the initial state and at a later stage. Diffusion is negligible and there
is advection in only the x-direction. The solution is the same for both sequential
and parallel cases.
not our intention to demonstrate the numerical performance of ELLAM in general,
but rather to briefly illustrate scalability. We refer to [40] for up-to date examples.
Here we use a computational domain of 100 100 100 elements on a unitcube in 3D, with piecewise tri-linear hat-functions as spatial basis functions.
Numerical time-integration was done using the implicit Euler integration with a
timestep of t = 0.1. Spatial integration was performed using a 3D Simpsons rule,
and the predictor-corrector method (A.8) was used for characteristic-tracking.
The velocity field V and diffusion tensor D are

1
1 0 0
V = 0 , D = 105 0 1 0 .
0
0 0 1
This corresponds to advection in the positive x-direction, and homogeneous, isotropic diffusion of small magnitude. This velocity field and our choice of x
and t gives an integer Courant number of 10, thus there should not be any additional numerical diffusion due to interpolation errors. No-flow (zero Robin)
boundary conditions were used on the whole boundary, which in effect eliminates
the boundary integral.
The initial value of u is zero everywhere, except in x [0.05, 0.1], y
[0.3, 0.7], z [0.2, 0.8] where u = 1. This initial state is then propagated forward
from t = 0 to t = 0.8, see Figure A.5.

164

A Parallel Eulerian-Lagrangian Localized Adjoint Method


# CPUs
1
2
3
4

Time (sec)
1782
961
665
548

Speedup
1
1.854
2.680
3.252

Table A.1: Scalability results for the problem in Figure A.5. To reduce spurious
variations, the elapsed times reported are the average of times of 10 runs.
We solved this problem on a shared memory supercomputer, an IBM p690
Regatta with 32 Power4 processors each running at 1.3GHz and with 32MB of
cache. While our implementation is not tuned for performance, it still shows good
scalability, see Table A.1 for some timings. Due to our choice of a shared memory
implementation, the scalability for our code is mostly unchanged when varying V
and t.

A.5

Concluding remarks

The parallelization discussed here is a natural approach for characteristic based


solvers, and tuned distributed memory implementations should attain nearly linear scalability. Furthermore, the implementation difficulty for shared memory
implementations is minimal, and even for distributed memory implementations
there is little extra work needed.
While we have focused on ELLAM in this paper, many other characteristic
based methods may be parallelized in this very same manner.

Acknowledgements
Bjrn-Ove Heimsund is grateful to The Research Council of Norway (Computational mathematics in applications) for support. Thanks to Philip Binning for
reading an early draft of the manuscript, and to Hong Wang and Thomas Russell
for useful remarks.

Paper B
Adjoint methods are particle
methods
Thomas F. Russell, Bjrn-Ove Heimsund, Helge K. Dahle and Magne S. Espedal
Abstract
We extend the Eulerian-Lagrangian localized adjoint method (ELLAM) to nonlinear hyperbolic equations. The adjoint to the hyperbolic operator is shown to
be a linear advection operator which corresponds to a mass transfer equation.
Couplings between these operators are illustrated for some classical examples,
and a numerical algorithm is developed which exploits this adjoint framework.
Some numerical examples are provided.

Draft manuscript

B.1 Introduction

B.1

167

Introduction

The Eulerian-Lagrangian localized adjoint method (ELLAM) [58] is an efficient


method developed for linear advection-diffusion equations. It does not have any
CFL restrictions on the timestep, it handles all kinds of boundary conditions
rigorously, it is fully mass conservative and its adjoint nature symmetrizes the
advection-diffusion operator. See [229] and the references therein for more information.
ELLAM is often used for simulating flows in porous media, and in many types
of reservoir flows strong non-linear flux functions are found, the prominent example being the Buckley-Leverett equation for two-phase immiscible flow. Problems with non-linear fluxes are computationally demanding, and efficient methods
are necessary for handling large-scale cases. Work on extending ELLAM to the
Buckley-Leverett equation [85, 86] have used particular splittings of the flux function [109] in order to handle non-linear features.
In this paper we explore a natural adjoint formulation, closely related to the
linear ELLAM schemes. The approach is natural in the adjoint framework, and
does not involve any splittings. Section B.2 develops the formulation for a scalar
multidimensional equation, and Section B.3 gives a physical interpretation of the
resulting adjoint operator. The relationship between the primal and dual formulations is then given in Section B.4, and all these concepts are illustrated in some
examples given in Section B.5, focusing on the interaction between the primal
waves and the particle motion. Next, Section B.6 outlines an algorithm for the
solution of general hyperbolic 1D equations, and this algorithm is illustrated in
the proceeding section with results for both the Burgers and the Buckley-Leverett
equations. Also, a 2D Buckley-Leverett equation is solved using the 1D algorithm
on streamlines.

B.2

A scalar equation

The difficulties of extending Eulerian-Lagrangian methods to nonlinear equations


and systems, and the insights needed to overcome these difficulties, can be explained with a minimum of extraneous details in the context of a scalar equation
in multiple space dimensions:
Au

(g(u)) + V~ f (u) = 0,
t

x~ ,

t J = [t0 , t1 ],

(B.1)

with appropriate initial and boundary conditions. Here u(~


x, t) is the unknown,
g(u) is a conserved quantity that may include storage and sorption terms, V~ (~
x, t)
is a known velocity field, f (u) is an advective fractional flux, and and J are

168

Adjoint methods are particle methods

bounded spatial and temporal domains, respectively. In general, V~ could itself


be an unknown that is determined along with u by (B.1) and another coupled
equation, as in sequential methods for multiphase subsurface systems. For our
purpose in this section, we take V~ as known.
To obtain a weak form and an adjoint equation, multiply (B.1) by a test function w(~
x, t), integrate over J , and use the product rule:
Z t1 Z
hAu, wi =
[(g(u)w)t g(u)wt + (V~ f (u)w) V~ f (u) w] d~
x dt = 0,
t0

Z
1

Z t1 Z
V~ n~ f (u) w ds dt

(g(u)w) d~
x+
t0

Z t1 Z

(g(u)w) d~
x+

t0

(g(u)wt + V~ f (u) w) d~
x dt.

(B.2)

Thus, if w(~
x, t) satisfies the adjoint equation
Au w g(u)wt + V~ f (u) w = 0,
the unknown u(~
x, t) will be the solution of the weak form
Z
Z
Z t1 Z
1
~
V ~n f (u) w ds dt = (g(u)w)0 d~
x.
(g(u)w) d~
x+

t0

(B.3)

(B.4)

Note that (B.4) has no advective term; the advection is tacitly represented by the
test function via (B.3), so that the t0 mass on the right-hand side of (B.4) advects
to the t1 mass on the left-hand side.
Next, rewrite the adjoint equation (B.3) in the form
wt + v~ w = 0,
where

(B.5)

f (u)
.
(B.6)
v~(~
x, t, u) = V~ (~
x, t)
g(u)
It is evident that (B.5) is a linear equation for w with a velocity v~ that depends
nonlinearly on u, in contrast with the nonlinear equation (B.1) for u. We observe
that v~(~
x, t, u) is a particle velocity, the velocity of movement of a fluid particle
governed by (B.1). To see this, note that if the particle velocity were V~ , the
volume flux across a unit cross-section per unit time would be V~ n~, hence the
flux of the conserved quantity would be g(u)V~ ~n. The actual flux is f (u)V~ n~, so
that the correct particle velocity is obtained by multiplying V~ by f (u)/g(u), as in
(B.6). The next section is devoted to an explanation of why the adjoint velocity
should be a particle velocity.

B.3 Adjoint/particle relationship in the dual space

B.3

169

Adjoint/particle relationship in the dual space

The key to this relationship is the understanding that the test function w(~
x, t) is

really a linear functional belonging to the dual space X of the primal space X
that contains the solution u(~
x, t). We need not specify X precisely for the purpose
of this discussion. The duality pairing is the angle bracket hAu, wi in (B.2), and
the formal adjoint of the nonlinear operator A on X is the linear operator Au on
X in (B.3). When Au w = 0 as in (B.3), the weak form of (B.1) involves nothing
but the boundary terms (at t0 , t1 , and ) of the adjoint relation, as in (B.4).
We are interested in advection of mass, and the term is peripheral to our
concerns if necessary, assume that the mass in question is far from the boundary. Then (B.3) implies that the mass-conservation equation (B.4) is
Z
Z
1
(g(u)w) d~
x = (g(u)w)0 d~
x,
(B.7)

t0

i.e., mass at is purely advected by w to mass at t1 . Suppose that w 1 w( , t1 ) is


the indicator (characteristic) function of a subdomain 1 , so that
Z
Z
1
g(u(~
x, t1 ))d~
x.
(g(u)w) d~
x=

View w 1 as a linear functional belonging to the dual space X1 of the primal space
X1 that contains the solution u1 u( , t1 ), and analogously view w 0 w( , t0 ) as
an element of X0 . Then w 1 evaluates the mass in 1 at time t1 , w(~
x, t) propagates
0
0
the mass, and w evaluates the conserved mass at time t that has been propagated
forward in time from a set 0 to 1 . Note that, like w 1 , the values of w(~
x, t) are 0
and 1, easily seen by (B.5). Thus, w 0 is the indicator function of 0 .
View the determination of 0 from 1 , or equivalently w 0 from w 1 , as the
action of a linear operator T : X1 X0 , so that w 0 = T w 1 . Then T tracks
sets, or equivalently the functionals that evaluate the mass in them, backward in
time. We can write (B.7) in terms of duality pairings as follows:
hg(u1 ), w 1 iX1 ,X1 = hg(u0 ), T w 1 iX0 ,X0 .

(B.8)

The mass in 1 at t1 (integrated via w 1 ) came from 0 at t0 (integrated via w 0 =


T w 1 ) and is conserved.
If we shrink 1 toward a point x~1 , then 0 shrinks toward the point x~0 = T x~1
(by an abuse of notation). Thus, mass at x~1 comes from mass at x~0 in a conserved
fashion. This is equivalent to tracking of mass particles from x~0 to x~1 according
to w, using the adjoint velocity v~ in (B.5). The evaluation of T w 1 is by forward
tracking,
(T w 1 )(~
x0 ) = w 1 (~
x1 ).
(B.9)
To summarize:

170

Adjoint methods are particle methods

Mass particles propagate at the adjoint velocity because they are represented by limits of masses in sets (finite volumes), which correspond to indicator test functions, which are linear functionals in the
dual space, which track via the linear operator T associated with the
dual adjoint equation (B.5).
Since (B.5) is linear in w, its solution always exists in the classical sense of generalized solutions characteristics do not intersect, and shocks do not form. This
matches the physical interpretation of particle propagation trailing particles do
not overtake leading ones, and particles do not vanish into a shock. The dual
space is the natural framework for a particle equation that propagates sets to sets
and always makes sense physically. Adjoint methods like ELLAM operate in this
framework.

B.4

Waves in the primal space

The solution u(~


x, t) belongs to the primal space X, where the direct equation (B.1)
represents wave propagation. Direct methods like MMOC are formulated in this
framework. We take a nondivergence form of (B.1):
g (u)ut + f (u)V~ u = 0,

(B.10)

where f (u) V~ is assumed to be zero or could be placed on the right-hand side;


these details are not important here. We define the total derivative
Du
f (u)
ut + V~ u ut + ~ u
Dt
g (u)
with the wave velocity

f (u)
~ (~
x, t, u) = V~ (~
x, t) .
g (u)

(B.11)

Then (B.10) becomes


g (u)

Du
= 0.
Dt

(B.12)

Ignoring the boundary as in Section B.3, MMOC multiplies (B.12) by the


test function w(~
x, t) and integrates over , approximating the total derivative by a
backward difference:



Z
g (u(~
x, t1 ))
f (u) ~
1
0
u(~
x, t ) u x~ V t, t
w(~
x, t1 ) d~
x = 0,
(B.13)
t
g
(u)

B.4 Waves in the primal space

which we can rewrite in the form analogous to (B.7),




Z
Z
f (u) ~
1 1 1
1 0
x.
g (u )u w d~
x = g (u )u x~ V t w 1 d~
g (u)

171

(B.14)

Here, u1 and u0 directly represent mass, rather than evaluating it on sets as w 1 and
w 0 did in Section B.3. View the propagation of mass from t0 to t1 as the action of
a nonlinear operator T : X0 X1 , where


f (u) ~
0
0
(B.15)
(T u )(~
x) = u x~ V t .
g (u)
T tracks mass forward in time at the wave velocity ~ , and T u0 is evaluated via
backtracking as in (B.15). In terms of duality pairings, (B.14) becomes
hg (u1 )u1 , w 1 iX1 ,X1 = hg (u1 )T u0 , w 1 iX1 ,X1 .

(B.16)

The details of the evaluation of the nonlinear coefficients in (B.13)(B.16) are


major practical issues, but tangential to the ideas here.
Remarks:
1. The primal forward operator T is the usual hyperbolic advection, addressed by algorithms for hyperbolic conservation laws of wave propagation. Shocks, rarefactions, Riemann problems, entropy conditions, etc., are
issues. The solution may exist only in a weak sense, and in systems that
change type or are not genuinely nonlinear, there may even be questions of
well-posedness. The dual backward operator T relates to particle propagation and does not experience such phenomena (though the primal solution u
appears in the particle-velocity coefficient of T ).
2. The wave velocity in (B.11) approximates the Rankine-Hugoniot shockwave velocity, which would result from chord slopes on the f and g curves.
This is different from the particle velocity in (B.6). The conservation equation (B.1) propagates mass at the particle velocity, and propagates solution
values at the wave velocity.
3. Global mass conservation is easily achieved numerically in the dual adjoint
framework, by taking w 1 1 in (B.8), i.e., 1 = . Then T w 1 1 (0 =
). The mass at time t0 on the right-hand side of (B.8) is integrated exactly
because g(u0 ) conforms to the solution grid. In the primal direct framework
of (B.16), this is not possible in general, because T u0 does not conform to
the grid.

172

Adjoint methods are particle methods

4. Constant solutions are easily preserved without developing oscillations in


the primal framework, by taking u0 1 in (B.16). Then T u0 1, and (B.16)
yields u1 1. This is difficult in the dual framework of (B.8), since T w 1
does not conform to the grid when w 1 is the indicator function of a cell,
resulting in errors in the distribution of mass among cells. One strategy for
this difficulty is to backtrack grid points x~i at t1 to T x~i (abuse of notation)
at t0 and add T x~i to the grid used for numerical integration on the righthand side of (B.8), creating an integration grid to which T w 1 conforms.
This is complex in multiple dimensions.
The remainder of this paper seeks to exploit the advantages of the dual adjoint
formulation. With its connection to particle propagation, it should be generalizable to complex transport systems, because such systems can always be viewed
as propagating mass particles. In multiphase flows, these particles propagate in
phases; each phase will have an adjoint equation and test function, and the overall
formulation will superpose the phases.

B.5

Examples of adjoint characteristics

We will now illustrate how the adjoint characteristics interact with the primal
waves in some simple settings. We will consider both shocks and rarefactions,
and the effects of an improper numerical treatment.

B.5.1 Shocks: Buckley-Leverett


Consider the Buckley-Leverett model of 1D incompressible two-phase flow of oil
and water, neglecting capillary effects,
 u
x R, t > 0,
t + x f (u) = 0,
(B.17)
0
u(x, 0) = u (x), x R,
where u [0, 1] is the water saturation and f (u) [0, 1] is the fractional flow
(ratio of water flux to total flux), typically an S-shaped increasing function with
f (0) = 0, f (1) = 1. The following data will illustrate some of the challenges in a
simple setting:

0,
0 u 1/2,
f (u) =
2u 1, 1/2 u 1,
with the initial condition

u(x, 0) =

1, x < 0,
1/2, x > 0.

B.5 Examples of adjoint characteristics

173

f (u) 6
1

1/2

Figure B.1: Fractional-flow function


u(x, t) 6
1
1
2

2t
Figure B.2: Shock wave

See Figures B.1-B.2.


The solution propagates the initial shock with Rankine-Hugoniot velocity =
(f (1) f (1/2))/(1 1/2) = 2:

1, x < 2t,
u(x, t) =
(B.18)
1/2, x > 2t.
The particle velocity is
f (u)
v=
=
u

1, x < 2t,
0, x > 2t.

Note that all particles propagate more slowly than the wave. The characteristics
of the adjoint equation like (B.5),
wt + vwx = 0,
are shown in Figure B.3.
The dual (ELLAM) weak form of (B.17) will be, as in (B.7),
Z
Z
1 1
u w dx = u0 w 0 dx
R

(B.19)

(B.20)

174

Adjoint methods are particle methods


S












x + 2t

t1

t0

Figure B.3: Characteristics of adjoint equation


if and only if w(x, t) satisfies (B.19).
For example, suppose that w 0 is the indicator function of the set S depicted in
Note that S is half
Figure B.3. By (B.9), w 1 is the indicator function of the set S.
1

as long as S, so that for (B.20) to hold, u on S is twice the value of u0 on S. That


precisely as (B.18) says.
is, u(x, t0 ) = 1/2 on S and u(x, t1 ) = 1 on S,
The characteristics of (B.19) do not intersect, because (B.19) is linear. However, the dependence of v on u, and the shock discontinuity in u, cause v to be
discontinuous in space-time. This leads to the non-smooth characteristics in Figure B.3. The challenge for Lagrangian numerical methods based on this adjoint
formulation is to approximate these bent characteristics accurately: given S, find
or vice versa. Neither the initial characteristics at t0 nor the final ones at t1 , by
S,
themselves, provide good approximations. Failure to approximate these characteristics may result in incorrect shock speeds and particles massing up behind the
shock, resulting in oscillations. An algorithm that takes advantage of the wave velocity, either directly or tacitly, to approximate the picture in Figure B.3 is needed.

B.5.2 Rarefactions: Burgers


For the converse problem of rarefactions, we will examine the 1D Burgers equation for inviscid fluid flow,
 2
(
u

u
= 0,
x R, t > 0,
t + x 2
(B.21)
0
u(x, 0) = u (x), x R.
The flux-function f (u) = u2 /2 is given in Figure B.4. The wave velocity (B.11)
and particle velocity (B.6) here are
(u) = f (u) = u,
f (u) u
v(u) =
= .
u
2

B.5 Examples of adjoint characteristics

175

f (u) 6
1

Figure B.4: Burgers flux function


Thus the waves move at exactly twice the speed of the particles.
To create a simple rarefaction wave, we use an initial condition of

u(x, 0) =

0, x < 0,
1, x > 0,

illustrated in Figure B.5. By the entropy conditions, the solution is given explicitly
by

0, x < 0,
x
u(x, t) =
, 0 < x < t,
t
1, x > t.
As u changes continuously through the rarefaction, both the wave and particle
velocities will also change continuously. In the rarefaction, the velocity of the
particles are given by
dx u x
= = .
dt 2 2t
This can be solved for x(t) to give

x(t) = C t,

(B.22)

where C is determined by the initial position of the particle. Behind the rarefaction
x (t) = 0, and ahead of it x (t) = 1/2.
In contrast to the shock, the particle paths going into a rarefaction changes
continuously, see Figure B.6. This is a much harder problem than that of a shock
where a single bending will suffice. Tangential approximations will overestimate
the particle speed, and leads to a slower development of the rarefaction.
Another problem is that ELLAM has no mechanism to ensure that it computes
the correct entropy solution. For example, in Figure B.5, both a rarefaction and

176

Adjoint methods are particle methods


u(x, t) 6
1

Figure B.5: Initial wave (solid) and the resulting rarefaction (dotted)
t








 



 



  



  




   



   


    





    


Figure B.6: Characteristics of the adjoint Burgers equation. Parabolas given by


Equation (B.22) fill the whole rarefaction region
a shock are weak solutions, but only the rarefaction case is the correct entropy
solution. Adding artificial diffusion solves this:
 
u u2
2 u
= 2 , > 0.
+
(B.23)
t x 2
x
However, adding diffusion will necessarily change the computed solution, so we
must keep as small as possible.

B.5.3 Other issues


The velocity field in non-linear hyperbolic problems depends directly on the computed solution at any given time. Consequently errors introduced during the
course of the computations may amplify themselves as the velocity accumulates
the errors. Problems in the trackings across shocks and rarefactions are two
sources for these errors; other sources include Gibbs oscillations and roundoffs.
The L2 projections used in the mass-integrals of ELLAM are a source of Gibbs
oscillations, as is well known from solving linear advection equations. Techniques

B.6 Algorithm

177

such as lumping the whole or parts of the mass matrix have been used; however,
this can lead to excessive smearing, and for the non-linear case can lead to a very
incorrect shock value u, which in turn gives large errors in the shock velocity.
Round-off errors when solving the linear systems in ELLAM adds a small
error in every timestep. While of small magnitude, the non-linear features of the
hyperbolic equation can magnify this error to such large proportions as to render
the solution unusable. We shall return to this in Section B.7 when we perform
numerical experiments.
The most reliable way to stabilize a non-linear ELLAM solver is to incorporate
artificial numerical diffusion as in Equation (B.23). Its magnitude must be as
small as possible, while ensuring that oscillations do not occur.

B.6

Algorithm

We will now outline an algorithm for the solution of a simplified variant of Equation (B.1)
ut + f (u)x = Duxx ,
(B.24)
with the adjoint equation
wt +

f (u)
wx = 0.
u

(B.25)

The weak formulation is


Z
Z
Z
n+1
Dux wx dxdt = uw|n dx,
uw| dx +

(B.26)

where we assume periodic boundary conditions. For details on how to solve linear
equations with ELLAM, see [40, 263]. Here our focus will be on the differences
between a linear ELLAM and the non-linear formulation.
Algorithm 1 (Non-linear ELLAM) Solves Equation (B.26) from t = tn to t =
tn+1 using a timestep of size t = tn+1 tn .
1. For every element i, do
(a) Compute the elemental mass integral at t = tn+1
Z
un+1 w dx, w
i

and add to the matrix A.

178

Adjoint methods are particle methods

(b) Compute the elemental diffusion implicitly


Z
Duxn+1 wx dx, w
t
i

and add to the matrix A.


(c) Numerically compute (by forward tracking quadrature points) the
mass integral at t = tn
Z
un w dx, w
i

and add to the vector b.


2. Solve Aun+1 = b for un+1
In step 1(c) we need to solve Equation (B.25). To do so, we approximate the
mass-integral using a quadrature rule specified by
Z
n

u wdx

m
X

Wj un (xj )w(xj )x,

j=1

where Wj are the quadrature weights and xj are the quadrature points. To evaluate
w(xj ), we use forward-tracking to tn+1 of xj to xj . The particle speeds are given
by
dx f (u)
=
,
dt
u
and are easily approximated using prediction tracking
x t

f (un )
,
un

un = u(t = tn ).

However, as we explained earlier, this is insufficient to handle hyperbolic equations. Another approach is the prediction-correction tracking


t f (un ) f (un+1 )
x
+ n+1
2
un
u
The first step of this scheme is to compute an approximation u n+1 to un+1 using
the prediction tracking. This approximation is then inserted into the predictioncorrection tracking to produce a correction of un+1 . Further corrections can be
applied until the computed un+1 converges.

B.7 Numerical results

179

However, since the simple prediction tracking can have low accuracy, there is
little reason to believe that the prediction-correction tracking will be more accurate
in the presence of strong non-linear behavior. For problems with a fixed velocity
field such a tracking works well, however.
What is necessary is to incorporate the information from the primal waves
into the adjoint tracking. The idea is to use a Riemann solver at discontinuities to
resolve the primal wave structures into shocks and rarefaction waves. Assuming
piecewise linear basisfunctions for u, discontinuity detection is done numerically
by checking for large numbers of jumps, that is all indices i such that
uni+1 uni > s ,

where s is some specified tolerance. We then solve a Riemann problem using uni
as left state and uni+1 as right state. If the solution of the Riemann problem gives
us a shock wave, we store the shock saturation u , its speed and origin from t = tn .
This information is then used in the particle tracking. We start by performing a
prediction
 tracking, and if we detect that a particle path intersects a shock (at point
xj , tj , say), then we use the shock value of u = u , giving us the scheme
 f (u(xi ))
 f (u )
+ tn+1 tj
.
u(xi )
u
The generalization to the case of multiple shock-crossings is straight forward.
Rarefactions are harder, as the particle path bends continuously. A natural
approach is to Taylor-expand
f (u(x, t))
u(x, t)
in the variables x, t, starting at xi , tn . A major motivation of ELLAM is the possibility to use long timesteps, and it is well known that Taylor expansions with few
terms are only valid in a small vicinity of the starting point. Thus such expansions
are likely to be expensive and potentially unstable.
Instead, we use the results of the Riemann solver to determine the presence of
a rarefaction. If a rarefaction is found, we increase the number of particles tracked
forward in time, which increases the accuracy of the numerical integral slightly.
As the Riemann solver is only used on distinct discontinuities, this will only help
in the initial development of a rarefaction; in practice we use artificial diffusion to
distribute mass properly.
xj = xi + tj tn

B.7

Numerical results

We will compare our non-linear ELLAM formulation with a simple upwinding finite volume scheme. The ELLAM used a simple forward-tracking and an adaptive
composite Simpson 1/3 rule, and piecewise linear basis functions were used.

180

Adjoint methods are particle methods

10

10

10

10

15

10

0.5

1.5

2.

Figure B.7: Stability of the solution of Burgers equation with an initial condition
of u = 1 on an infinite domain. The curve depicts Equation (B.27) as a function of
time. The y-axis is logarithmic.

B.7.1 Stability issues and artificial diffusion


First, we wish to illustrate the need for artificial diffusion as a means to stabilize
the non-linear ELLAM. Sources for oscillations are L2 projections of discontinuous data onto continuous splines and also the feedback loop between computing a
new solution, and then using that solution to generate a new velocity field. Errors
introduced when computing a solution will turn into errors in the velocity field,
which may in turn may further amplify errors in later timesteps.
Gibbs phenomena in the L2 projections are well understood in the literature
surrounding ELLAM for linear problems, and are no different in our context. The
solution to such oscillations are by either lumping the system matrix, or adding artificial diffusion. The new element of instability is the potential negative feedback
between the computed solution and the velocity field.
To illustrate these effects, we solve the Burgers equation (B.21) with an initial
u = 1 everywhere and with an infinite domain. It is clear that the analytical solution
will be u = 1 for all times, however the computed solution starts to grow, develops
oscillations and breaks down after awhile. Figure B.7 plots
max |u(x, t)| min |u(x, t)|
x

(B.27)

as a function of t. The grid used has the spacings x = 1/100 and t = x. We see
that just before t = 2, the oscillations have grown to order O(1), and the solution
s = 1 has been destroyed. The errors introduced are solely due to round-off errors
in the course of the computation, and the propagation of errors into the velocity
field and the solution. L2 projection errors do not play a part here.

B.7 Numerical results

181

0
0.2

0.6

Figure B.8: Initial condition for solving the discretized Burgers equation
Adding diffusion of size D = 103 completely damped the resulting oscillations in this case. We have not found a functional relationship between the needed
stabilizing diffusion and the discretized problem (x, t, f (u), etc), so in our remaining numerical experiments, we have experimentally determined D. We note
here that lumping the mass-matrix did work for t = x, but for larger stepsizes
lumping could not prevent the rising instability.

B.7.2 Burgers equation


Next, we proceed to solve Burgers equation with a setup that produces both shocks
and rarefactions. Again we assume full periodicity so that we avoid any complications arising from boundary conditions, and restrict our domain to [0, 1]. Herein,
an initial u is given as

0, x < 15 ,
u(x, 0) =
1, 51 x 35 ,

0, x > 35 .
This domain is discretized using x = 1/100, see Figure B.8. We compare a
simple conservative upwinding method [174]
uin+1 = uni


t
f (uni ) f (uni1 ) ,
x

against our non-linear ELLAM. The results of the upwind method is given in
Figure B.9 with the analytical solution overlaid. It used t = x/10.
Next, we solve using ELLAM, with an artificial diffusion of D = 2 103 and
a timestep of t = 5x. The computed result without the frontal Riemann solver
is shown in Figure B.10, and the results with a Riemann solver is in Figure B.11.

182

Adjoint methods are particle methods

0
0.2

0.7

0.85

Figure B.9: Solution of the Burgers equation with a simple upwinding scheme.
The dashed line is the analytical solution and the solid line is the computed, both
displayed at t = 1/2.
1

0
0.2

0.7

0.85

Figure B.10: ELLAM without Riemann solver. As particles in front of the shock
move too slowly, the result is oscillations.
1

0
0.2

0.7

0.85

0.2

0.7

0.85

Figure B.11: ELLAM with Riemann solver. The left figure uses a diffusion coefficient of D = 2 103 , and the right uses the double D = 4 103 .

B.7 Numerical results

183

Without shock handling oscillations occur, and the accuracy is rather degenerate. Particles in front of the shock do not speed up properly, and contribute mass
behind the shock, leading to excessive mass build-up and oscillations. However
the results using a Riemann solver are much better, and quite comparable to the
upwinding method. The hump in the rarefaction is caused by the tangential approximation to the particle paths, adding more diffusion will smear this out, at the
cost of also smearing the shock front.

B.7.3 Buckley-Leverett
A more challenging problem than Burgers is the Buckley-Leverett equation for
two-phase flooding of a reservoir. Instead of the simple variant considered earlier,
we will now solve for the full form:
u
+ f (u) = 0, x (0, 1), t > 0,

t x
u(x, 0) = 0, x (0, 1],
(B.28)

u(0, t) = 1, t 0,

f (u(1, t)) n = 0, t 0.
The flux-function is

u2
.
(B.29)
u2 + (1 u)2
For the upwinding method, the same discretization is used as for the Burgers
case (x = 1/100, t = x/10). Its results are in Figure B.12. The ELLAM now
needs an artificial diffusion of D = 102 , and uses x = 1/100, t = 5x. See
Figure B.13 for the computed results. The solution states are shown at t = 1/2
with the analytical solution overlaid.
f (u) =

B.7.4 2D Buckley-Leverett
We proceed to solve the 2D Buckley-Leverett equation on a rotational velocity
field:

u
+ V~ f (u) = 0, x~ , t > 0,
(B.30)
t
where the velocity is spatially dependent
V~ (~
x) = 2 [y, x] ,
and the flux function is given in Equation (B.29). Using the polar coordinates r
and , the spatial domain is = {r, | r < 2}. Initial conditions are

1, (0, /2)
u(r, ) =
0, [/2, 2].

184

Adjoint methods are particle methods

0.7071

0
0

0.6036

Figure B.12: Upwinding solution of the BuckleyLeverett equation (B.28).


Dashed line is the analytical solution, and the solid line represents the numerical
solution. The results are given at t = 1/2.

0.7071

0
0

0.6036

Figure B.13: Non-linear ELLAM solution for the BuckleyLeverett equation


(B.28). A frontal Riemann solver was used.

B.8 Concluding remarks

185

We cannot simply extend Algorithm 1 to 2D, as complications occur in handling


the intersection between a shock-plane and particle paths. To simplify matters,
we will use a streamline approach [22] where we compute the streamlines of V~
and solve 1D non-linear Buckley-Leverett equations on each. Rewriting Equation (B.30)
u
+ f (u) V~ + V~ f (u) = 0,
t
then using that the velocity field is incompressible, that is V~ = 0, we get
u ~
+ V f (u) = 0.
t

(B.31)

We introduce the directional derivative

= V~

along the streamlines


v ~
=V,

(B.32)

and then rewrite Equation (B.31) using these streamline coordinates:


u f (u)
+
= 0.
t

(B.33)

The streamlines (B.32) are computed by an ODE solver, and the computation
is only done initially as the velocity field is fixed in time. After computing the
streamlines, which here are closed circles, Equation (B.33) is solved using our 1D
non-linear algorithm.
30 streamlines positioned at (r = ri , = 0) are traced by solving Equation (B.32), and for the 1D Buckley-Leverett problem we use the same discretization as before. The results are shown in Figure B.14. We see that the streamline
approach has successfully reduced the 2D problem into 1D problems with good
accuracy.

B.8

Concluding remarks

In this paper we have developed a non-linear Eulerian-Lagrangian localized adjoint method for solving hyperbolic equations in multiple spatial dimensions.
The adjoint formulation is simple and a natural extension of the linear case, and
we have provided several examples to illustrate its performance, both analytical
(B.5) and numerical (B.7).

186

Adjoint methods are particle methods

0
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1

-1

-2
-2

-1

(a) Initial at t = 0

1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1

-1

-2
-2

-1

(b) Final at t = 1

Figure B.14: Streamline ELLAM solution for the 2D BuckleyLeverett equation


(B.30). The motion is clockwise, and the computed front at t = 1 has been slightly
smeared as in the 1D case, and there is a trailing rarefaction both after the shockwave and trailing the main mass.
The analytical examples illustrate challenges in handling shocks and rarefactions, and the numerical cases shows these issues in practice. Also, in all our
numerical experiments, we used a timestep of t = 5x, much larger than the
CFL limit imposed on traditional schemes. The accuracy of our method is also
comparable to the popular upwinding method for non-linear hyperbolic equations.
A subject for future research is a better way to handle rarefaction waves, our
current approach of using artificial diffusion and an increased number of particle
trajectories does not properly handle the particle bendings that occur. Semianalytical methods or selective diffusion are possible ways.
Another subject is to examine the application of this ELLAM to complex multiphase systems. The combination of our non-linear formulation and the streamline multidimensional reduction can yield improvements in the computational
speed and accuracy of such large scale simulations.

Paper C
Multiscale Discontinuous Galerkin
Methods for Elliptic Problems with
Multiple Scales
Jrg Aarnes and Bjrn-Ove Heimsund
Abstract
We introduce a new class of discontinuous Galerkin (DG) methods for solving
elliptic problems with multiple scales arising from e.g., composite materials and
flows in porous media. The proposed methods may be seen as a generalization of
the multiscale finite element (FE) methods. In fact, the proposed DG methods are
derived by combining the approximation spaces for the multiscale FE methods and
relaxing the continuity constraints at the inter-element interfaces. We demonstrate
the performance of the proposed DG methods through numerical comparisons
with the multiscale FE methods for elliptic problems in two dimensions.

Accepted for publication in Lecture Notes in Computational Science and Engineering, Springer

C.1 Introduction

C.1

189

Introduction

We consider solving the second-order elliptic equation

(a(x)u) = f,
u = 0,

a(x)u n = 0,

in Rd ,
on D ,
on N = \D ,

(C.1)

where is bounded, is Lipschitz, n is the outward unit normal on and


a(x) = (aij (x)) is a symmetric positive definite tensor with uniform upper and
lower bounds:
0 < |y|2 yT a(x)y |y|2 < ,

x , y Rd , y 6= 0.

We will interpret the variable u as the (flow) potential and q as the (flow) velocity. The homogeneous boundary conditions are chosen for presentational brevity.
General boundary conditions can be handled without difficulty.
Equation (C.1) may represent incompressible single-phase porous media flow
or steady state heat conduction through a composite material. In single-phase flow,
u is the flow potential, q = a(x)u is the Darcy filtration velocity and a(x) is
the (rock) permeability of the porous medium. For heat conduction in composite
materials, u, q and a(x) represents temperature, heat flow density, and thermal
conductivity respectively. These are typical examples of problems where a(x) can
be highly oscillatory and the solution of (C.1) displays a multiscale structure. This
leads to some fundamental difficulties in the development of robust and reliable
numerical models.
In this paper we introduce a new class of DG methods for solving this particular type of multiscale elliptic problems. Until recently, DG methods have been
used mainly for solving partial differential equations of hyperbolic type, see e.g.
[74] for a comprehensive survey of DG methods for convection dominated problems. Indeed, whereas DG methods for hyperbolic problems have been subject
to active research since the early seventies, it is only during the last decade or
so that DG methods have been applied to purely elliptic problems, cf. [21] and
the references therein. The primary motivation for applying DG methods to elliptic problems is perhaps their flexibility in approximating rough solutions that
may occur in elliptic problems arising from heterogeneous and anisotropic materials. However, to our knowledge, previous research on DG methods for elliptic
problems has been confined to solving elliptic partial differential equations with
smooth coefficients.
DG methods approximate the solution to partial differential equations in finite
dimensional spaces spanned by piecewise polynomial base functions. As such,

190

Multiscale Discontinuous Galerkin Methods for Elliptic Problems

they resemble the FE methods, but, unlike the FE methods, no continuity constraints are explicitly imposed at the inter-element interfaces. This implies that
the weak formulation subject to discretization must include jump terms across interfaces and that some artificial penalty terms must be added to control the jump
terms. On the other hand, the weak continuity constraints give DG methods a
flexibility which allows a simple treatment of, e.g., unstructured meshes, curved
boundaries and h- and p- adaptivity. Another key feature with DG methods is their
natural ability to impose mass conservation locally. Moreover, the local formulation of the discrete equations allows us us to use grid cells of arbitrary shapes
without difficulty. We may therefore choose the gridlines to be aligned with sharp
contrasts in, for instance, underlying heterogeneous materials.
The multiscale FE methods (MsFEMs) introduced in [67, 146] have been successfully applied to multiscale elliptic problems, but their accuracy is to some
degree sensitive to the selection of the boundary conditions that determine the FE
base functions. If, for instance, strong heterogeneous features penetrate the intercell interfaces, then simple, e.g. linear, boundary conditions may be inadequate.
In such situations, oversampling strategies or other techniques for the generation
of adaptive boundary conditions must be used to recover the desired order of accuracy. This sensitivity to the selection of boundary conditions is partly due to the
strong continuity requirements at the inter-element interfaces implicit in the FE
methods.
Here we propose a class of multiscale DG methods (MsDGMs) for solving
elliptic problems with multiple scales. One of the primary motives for developing
MsDGMs is to generate multiscale methods that are less sensitive to the selection
of boundary conditions for the base functions than is the case for the MsFEMs.
Another nice feature with MsDGMs is that they produce solutions for both the
potential variable (e.g. pressure or temperature) and the velocity variable (e.g.
phase velocity or thermal flux density) that reflect important subgrid variations
in the elliptic coefficients. We will demonstrate the benefit of using multiscale
methods in comparison with ordinary monoscale numerical methods and perform
numerical experiments to display the performance of the MsDGMs relative to
the original and mixed MsFEMs. We therefore attempt to reveal that there is
a need for multiscale methods, and to demonstrate under what circumstances it
may be advantageous to relax the inter-element continuity assumptions implicit in
the MsFEMs.
The paper is organized as follows. We give the general mathematical setting
for the DG methods in Section C.2 and show how they are related to the more
familiar FE methods. In particular we show that both standard and mixed FE
methods may be viewed as special DG methods. This observation allows us to
extend this type of FE methods to corresponding DG methods. In Section C.3
we outline the MsFEMs introduced in [146] and [67] and exploit the relationship

C.2 Mathematical formulations

191

between FE methods and DG methods to derive a corresponding class of MsDGMs. Finally, Section C.4 contains the numerical experiments and we conclude
with a discussion of the results in Section C.5.

C.2

Mathematical formulations

In Subsection C.2.1 we give the mathematical formulation of the DG methods for


(C.1) and discuss the selection of the so-called numerical fluxes that are used to
force weak continuity of the solution across inter-element interfaces. In Subsection C.2.2 we show how the conforming and mixed FE methods may be viewed
as special DG methods, and describe how such FE methods can be extended to
corresponding DG methods.

C.2.1 Discontinuous Galerkin methods


To define the DG methods we split (C.1) into the first order system,
q
q
u
q n

=
=
=
=

a(x)u,
f,
0,
0,

in ,
in ,
on D ,
on N .

Furthermore, define the following approximation spaces:


QN = {p (H 1 ())d : p n = 0 on N },
UD = {v H 1 () : v = 0 on D }.
Upon integration by parts, we now deduce the weak formulation: Find q QN
and u UD such that
R
R 1
a
q

p
dx
=
u p dx p QN ,

q v dx =

fv dx

v UD .

In the DG methods, a similar set of equations is derived for each grid cell.
However, for the grid cell equations it is not natural to impose homogeneous
boundary conditions. The boundary conditions are therefore approximated from
neighboring values of the unknown solution. Essentially we want to ensure that
the potential u and the velocity q are almost continuous at the interfaces. Since
we do not want to enforce continuity by imposing constraints on the approximation spaces as the FE methods do, we have to penalize the deviation from continuity by introducing an artificial penalty term. To understand the mechanism behind

192

Multiscale Discontinuous Galerkin Methods for Elliptic Problems

the penalty term, we digress for a moment in order to consider an example that
illustrates the basic principle.
Example: Consider the Poisson equation with Dirichlet data,

u = f, in ,
u = g, on ,
and for each > 0, let u H 1 () be the solution to the regularized problem
Z
Z
Z
1
(u g)v ds = fv dx v H 1 ().
(C.2)
u v dx +

Here ds denotes the surface area measure. This problem corresponds to perturbing
the boundary data so that instead of u = g we have u + u n = g on . One can
show that (C.2) is well posed and that u u H01 () as 0 [181]. Hence, we
see that the extra penalty term is added in order to force, in the limit 0, the
satisfaction of the boundary conditions.
Just as the satisfaction of the Dirichlet boundary data was imposed weakly
in (C.2), so can inter-element continuity be attained in a similar fashion. It was
this observation that originally led to the development of the interior penalty (IP)
methods [20, 83, 272]. Arnold et al. [21] recently recognized that the IP methods,
along with several other methods with discontinuous approximation spaces, can
be classified as DG methods. These methods differ in the flux approximating
schemes used to force continuity at the inter element interfaces. We now describe
the general framework for the DG methods with respect to the elliptic problem
(C.1).
Let T () = {T T } be a family of elements in a partitioning of and define
T = {T : T T }, = T \ and ij = Ti Tj , Ti , Tj T . Next, introduce
an approximation space Qh U h (H 1 (T ))d H 1 (T ) where
H k (T ) = {w L2 () : w H k (T ), T T }.
The DG method then seeks q h QhN = Qh QN and uh UDh = U h UD such that
Z
Z
Z
1 h
h
(C.3)
a q p dx = u p dx
u p nT ds
p QhN ,
TZ
TZ
T
Z
h
(C.4)
q v dx = fv dx +
v q nT ds
v UDh ,
T

for all T T . Here nT is the outward unit normal on T and (q,


u)
are the so called
numerical fluxes which represent an approximation to (q, u) on T .

C.2 Mathematical formulations

193

The numerical fluxes

The perhaps simplest and most natural choice of numerical fluxes is to set
(q,
u)
=


1 h h
(q , u )|Ti + (q h , uh )|Tj
2

on ij .

We see that this option, which was considered by Bassi and Rebay in [27], does
not involve a penalty term and simply computes the fluxes by taking the average
of the functional limits on each side of the inter-element interfaces ij . Though
this option seems attractive, the lack of a penalty term renders the method unstable
and may lead to a singular discretization matrix on certain grids. It is therefore
clear that the stabilization of the DG methods via the inclusion of a penalty term
is crucial. In fact, without it, not only stability is affected, but convergence is
degraded or lost [21].
To define the numerical fluxes that will be used in this paper, it is convenient
to introduce, for q Qh , u U h , and x ij , the mean value operators
1
(ui (x) + uj (x)),
2
1
{q}(x) =
(qi (x) + qj (x)),
2
{u}(x) =

and the associated jump operators


1
(ui (x) uj (x))nij ,
2
1
(qi (x) qj (x)) nij .
[q] (x) =
2
[u] (x) =

Here (qk , uk ) = (q, u)|Tk and nij is the unit normal on ij pointing from Ti to Tj .
We shall employ the numerical fluxes associated with the method of Brezzi et al.
[48], which are
u = {uh },

q = {q h } [uh ].

(C.5)

These numerical fluxes have been analyzed in [57] in the wider context of LDG
(Local Discontinuous Galerkin) methods, and gives a stable, convergent method
when = O(1/h). While there are many other numerical fluxes that has been proposed for DG methods, see e.g., [21], we have chosen to use the Brezzi fluxes
(C.5) because they are simple, stable, and consistent, and give the same rate of
convergence (at least for elliptic problems with smooth coefficients) as more elaborate DG methods.

194

Multiscale Discontinuous Galerkin Methods for Elliptic Problems

The primal formulation

The need to construct approximation spaces for both the potential variable and
the velocity variable leads to a relatively large number of degrees of freedom per
element. However, it is standard procedure in the literature on DG methods to
eliminate the velocity variable from the discretized equations. This elimination
leads to the primal formulation:
Z
h h
B (u , v) = fv dx, v U h ,
(C.6)

where the primal form B h ( , ) is defined by


R
R
[v]) ds
B h (uh , v) := uh av dx + T ([u uh ] {av} + {q}
+

R
T \

(C.7)

({u uh }[av] + [q]{v})

ds,

and q = q(u
h , q h ) is defined with the understanding that q h satisfies
R
R
R
a1 q h p dx = uh p dx + T [u uh ] {p} ds
+

(C.8)

h
T \ {u u }[p] ds.

If the unknowns associated with the velocity variable q h are numbered sequentially, element by element, then the matrix block that stems from the term on the
left hand side of (C.8) becomes block diagonal. This allows us to perform a Schurelimination of the discretization matrix to give the reduced form corresponding to
B h ( , ) at a low cost. Thus, to compute uh using the primal formulation, we
eliminate first the velocity variable by Schur-elimination. The next step is to solve
(C.6) for uh . Finally one obtains an explicit expression for the fluxes by backsolving for q h in (C.8).

For the numerical fluxes considered in this paper, we have u = uh . Thus,
since q is conservative, i.e., unit valued on T , the integral over T \ in
B h (uh , v) vanishes, and the primal form reduces to
Z
Z
h h
h
B (u , v) := u av dx
([uh ] {av} {q}
[v]) ds.
(C.9)
T

Finally, inserting q = {q h } [uh ] into (C.9) gives


Z
Z
h h
h
B (u , v) = u avdx
[uh ] {av} ({q h } [uh ]) [v]ds.

(C.10)

C.2 Mathematical formulations

195

A rigorous analysis of the primal form (C.10) in the case of polynomial elements
can be found in [21]. There it was shown that the bilinear form (C.10) is bounded
and stable, provided that the stabilizing coefficient is chosen sufficiently large.
Hence, the same type of constraint applies to either we formulate the DG method
using the mixed formulation (C.3)(C.4) or the primal formulation (C.6) and (C.8)
using the primal form (C.10).

C.2.2 Finite element methods vs.


methods

discontinuous Galerkin

The standard conforming FE discretization of (C.1) approximates the solution in


a finite dimensional subspace V h of H 1 (). Though H 1 () is not in general
the discrete FE approximation spaces are. This implies in
embedded in C(),
particular that the corresponding FE methods approximates a possible irregular
solution with a continuous one. This continuity assumption can be relaxed, as
the non-conforming FE methods do, but they still restrain the solution by putting explicit restrictions on the approximation space. This is in a sense the main
difference between FE methods and the DG methods which impose continuity
implicitly in a weak sense.
In order to clarify the differences, or perhaps rather the similarities, between
FE methods and DG methods for equation (C.1), we first review the concept behind FE methods. In the standard FE formulation of (C.1) we define a finite
and seek u U h () = {u U h : u =
dimensional subspace U h H 1 () C()
D
0 on D } such that
Z
Z
h T
(u ) av dx = fv dx v UDh .

we know that uh is continuous. Hence, it makes sense to


Now, since U h C()
let u = uh in (C.7). We then deduce that the primal form (C.7) reduces to
Z
Z
h h
h T
B (u , v) = (u ) av dx +
[q]{v}.

(C.11)

T \

Thus, if the numerical flux q is conservative, i.e. if q is single valued on T \,


then the last term on the right hand side of (C.11) vanishes. Thus, for any approximation space Qh , the primal formulation of DG methods with a conservative

numerical flux for the velocity variable and an approximation space U h C()
reduces to the standard FE variational formulation.
Similarly, in mixed FE methods one seeks a solution (q h , uh ) of the elliptic
problem (C.1) in a finite dimensional subspace QhN UDh of H (div, ) L2 ().

196

Multiscale Discontinuous Galerkin Methods for Elliptic Problems

The subscripts N and D indicate that functions in QhN and UDh satisfy the homogeneous Neumann and Dirichlet conditions on N and D respectively. The
mixed FE solution is defined by the following mixed formulation:
Z
Z
1 h
a q p dx = uh p dx,
p QhN ,
Z
Z
q h v dx = fv dx,
v U h ,

where n is the outward unit normal on .


For many standard mixed FE methods for equation (C.1), such as the RaviartThomas method [225], the approximation space for the velocity consists of functions that are continuous across the interfaces ij in the
R direction of the coordinate
unit normal nij . For this type of methods we have ij [q]ds = 0 for all ij

and q Qh . Thus, by setting q = q h on and q n = 0 on N we find that the


second equation above transforms, upon integration by parts, to equation (C.4).
Moreover, if the numerical flux u for the potential is single-valued on , then the
first equation in the mixed formulation coincides with equation (C.3). This shows
that also mixed FE methods for equation (C.1) can be viewed as special DG methods for which the numerical fluxes are determined by continuity conditions imposed on the approximation spaces. We may therefore view the DG methods as
special FE methods that impose weak continuity of the numerical solution without
putting explicit constraints on the approximation space.

C.3

Multiscale methods for elliptic problems

Many areas of science and engineering face the problem of unresolvable scales.
For instance, in porous media flows the permeability of the porous medium is
rapidly oscillatory and can span across many orders of magnitude across short
distances. By elementary considerations it is impossible to do large scale numerical simulations on models that resolve all pertinent scales down to, e.g., the scale
of the pores. The standard way of resolving the issue of unresolvable scales is to
build coarse scale numerical models in which small scale variations in the coefficients of the governing differential equations are homogenized and upscaled to
the size of the grid blocks. Thus, in this approach small scale variations in the
coefficients are replaced with some kind of effective properties in regions that
correspond to a grid block in the numerical model.
Multiscale methods have a different derivation and interpretation. In these
methods one tries to derive coarse scale equations that incorporate the small scale
variations in a more consistent manner. Here we present three different types of

C.3 Multiscale methods for elliptic problems

197

multiscale methods; the multiscale FE method (MsFEM) developed by Hou and


Wu [146], the mixed MsFEM developed by Chen and Hou [67], and a new class
of multiscale DG methods (MsDGM). In these multiscale methods one does not
alter the differential coefficients, but instead one constructs coarse scale approximation spaces that reflect subgrid structures in a way which is consistent with the
local property of the differential operator. They are therefore more amenable to
mathematical analysis, and provides a more flexible approach to solving partial
differential equations with multiple scales.
One of the motives for using multiscale methods is reduced complexity.
Hence, by introducing a rigorous mathematical formalism where one derives a
coarse grid model in which subgrid oscillations in the elliptic coefficients are
handled in a mathematical consistent manner, one aims toward a reward in terms
of computational efficiency. The computational complexity of the methods proposed below scales linearly with the number of cells in the subgrid model. Hence,
the complexity is comparable to the (theoretical) complexity of solving the full
system of equations at the subgrid level using an efficient multigrid method. Thus,
for these methods it appears that we do not gain much. However, for multiscale
problems there are additional considerations.
First, in equations of the form (C.1) that arise from flows in porous media, the
elliptic coefficient function a(x) can vary more than 10 orders of magnitude across
short distances. With this extreme span of scales it can be very difficult to obtain
linear complexity, or even convergence, using multigrid methods, in particular for
linear systems that arise from mixed FE methods. In multiscale methods, like the
MsFEM, variations in the coefficients that occur on a subgrid scale appear in the
corresponding linear system only as quantities that are integrated over coarse grid
blocks. This implies that the impact of the oscillating coefficients on the condition
number of the linear system is less severe than for the associated linear system at
the subgrid level. In other words, by using a multiscale method we are implicitly
doing a preconditioning of the system of subgrid equations. As a consequence,
the proposed multiscale methods can be used to obtain quite accurate solutions at
the subgrid level for elliptic problems with a range of scales that push the limits,
or go beyond the capabilities of multigrid methods.
Another arena where the multiscale methods outlined below can prove useful,
also from a computational complexity point of view, is multiphase flow simulation. In a sequential IMPES (IMplicit Pressure Explicit Saturation) formulation
of the equations governing incompressible flows in porous media, the pressure
equation is basicly elliptic, and is non-linearly coupled with a set of (fluid) transport equations. This implies that the pressure equation must be solved repeatedly
during a multiphase flow simulation. Fortunately, when simulating fluid flows,
for instance flow of oil and water in a heterogeneous oil reservoir, the pressure
equation is only weakly coupled to the transport equations. This means that the

198

Multiscale Discontinuous Galerkin Methods for Elliptic Problems

flow velocity field varies slowly in time away from the propagating saturation
front. In such situations the base functions for the proposed multiscale methods
need only be generated once, or perhaps a few times during the simulation [2].
In other words, all computations at the subgrid level become part of an initial
preprocessing step.

C.3.1 The multiscale finite element method


We associate with each element T a set of functions kT H 1/2 (T ) that play the
role of Dirichlet boundary conditions. We then define corresponding multiscale
base functions kT by
Z
kT av dx = 0, v H01 (T ),
(C.12)
T

and the associated boundary conditions


kT = kT ,

on T \,

kT = 0,

on D T ,

akT n = 0,

on N T .

To ensure that the base functions are continuous, and hence belong to H 1 (),
we require that kTi = kTj on all non-degenerate interfaces ij . The MsFEM now
P
seeks ums U ms = span{k : k = T kT } such that
Z
Z
ms
u av dx = fv dx v U ms .
(C.13)

Since the base functions are determined by the homogeneous equation (C.12),
it is clear that the properties of the approximation space U ms , and hence of the
accuracy of the multiscale solution ums , is determined by the boundary data kT
for the multiscale base functions kT .
In [146, 147] it was shown using homogenization theory that for elliptic problems in two dimensions with two-scale periodic coefficients, the solution ums tends
to the correct homogenized solution in the limit as the scale of periodicity tends to
zero, 0. For a positive scale of periodicity, a relation between and the discretization scale h was established for linear boundary conditions. Moreover, using
multiscale expansion of the base functions they showed that with linear boundary
conditions kT at the interfaces, the resulting solution exhibits a boundary layer
near the cell boundaries and satisfies
ku ums kL2 () = O(h2 + /h).

C.3 Multiscale methods for elliptic problems

199

This shows that when and h are of the same order, a large resonance error is
introduced. To reduce the resonance effect, which is caused by improper boundary
conditions, Hou and Wu introduced also an oversampling technique motivated
by the observation that the boundary layer has a finite thickness of order O().
However, for further details about this oversampling technique we refer the reader
to the article by Hou and Wu [146].

C.3.2 The mixed multiscale finite element method


1/2 ( )
For each
ij
R interface ij , define a Neumann boundary condition ij H
with ij ij ds = 1. Furthermore, for each interface let the corresponding base
function ij for the mixed MsFEM be defined by

ij = a
ij , in Ti Tj ,

|Ti |1
in Ti ,
ij =
1
|Tj |
in Tj ,

(C.14)

and the following boundary conditions:


ij nij = ij ,
ij = 0,
ij n = 0,

on ij ,
on (Ti Tj ) D ,
on (Ti Tj )\(ij D ).

Here nij is the coordinate unit normal to ij pointing from Ti to Tj and n is the
outward unit normal on (Ti ij Tj ). We now define Qms = span{ij : ij }
and seek (q ms , u) Qms P0 (T ) which solves
Z
Z
1 ms
a q p dx = u p dx,
p Qms ,
Z
Z
ms
v q dx = fv dx,
v P0 (T ).

Again we see that the method is determined by the local boundary conditions for
the base functions.
It is also possible to choose the right hand side of the equations (C.14) differently, and in some cases it would be natural not to do so. For instance, in reservoir
simulation the right hand side of equation (C.1) represent wells and wells give rise
to source terms that are nearly singular. For simulation purposes it is important
that the velocity field is mass conservative. To this end, the right hand side of
equation (C.14) in the well blocks must be replaced with a scaled source term at
the well location, see [2] for further details.

200

Multiscale Discontinuous Galerkin Methods for Elliptic Problems

A rigorous convergence analysis for the mixed MsFEM has been carried out
in [67] for the case of two-scale periodic coefficients using results from homogenization theory. There it was shown that
 p 
ms
ms
kq q kH (div,) + ku u kL2 () = O h + /h .
Hence, again we see that a large resonance error is introduced when /h = O(1).
As for the MsFEM method, the possibility of using oversampling as a remedy
for resonance errors was explored, and it was shown that oversampling can indeed be used to reduce resonance errors caused by improper boundary conditions.
The need for oversampling strategies to reduce resonance errors is, however, a
drawback with the MsFEMs since oversampling leads to additional computational
complexity.

C.3.3 A multiscale discontinuous Galerkin method


We now exploit the relationship between DG methods and FE methods that was
established in Subsection C.2.2. To derive the MsDGM proposed below, we
merge first the approximation spaces constructed in the original and mixed
MsFEMs to create a pair of approximation spaces for the MsDGM. Thus, select suitable boundary conditions kT H 1/2 (T ) and ij H 1/2 (ij ) and define
base functions kT and ij by (C.12) and (C.14) respectively. The approximation
spaces for the MsDGM are then defined by
X
U ms = span{k : k =
kT } and Qms = span{ij : ij }.
T

Thus, the corresponding DG method, henceforth called the MsDGM, reads:


Find (q ms , ums ) Qms U ms so that for each T T we have
Z
Z
Z
1 ms
ms
a q p dx = u p dx
up
nT ds,
p Qms ,
(C.15)
TZ
TZ
T
Z
ms
q v dx = fv dx +
v q nT ds,
v U ms .
(C.16)
T

In addition to the selection of boundary conditions for the base functions, this
method is determined by the choice of numerical fluxes. As indicated in Subsection C.2.1 we limit our study to the numerical fluxes (C.5) of Brezzi et al.
We observe that MsDGMs have much in common with the mortar FE methods.
Indeed, here as in the mortar methods, we construct the base functions locally in a
manner which corresponds to the underlying partial differential equation, and glue
the pieces together using a weak formulation at the interfaces. The new element

C.3 Multiscale methods for elliptic problems

201

here is that we derive the above formulation directly from the original and mixed
MsFEMs.
Apart for imposing inter-element continuity weakly, the MsDGMs differ from
the MsFEMs by using multiscale approximation spaces for both the velocity variable and the potential variable. Another motive for introducing a new multiscale
method for elliptic problems is that the accuracy of MsFEMs solutions can be
sensitive to the boundary conditions for the base functions. Indeed, previous numerical experience [2, 1] shows that the MsFEMs with simple boundary conditions may produce solutions with poor accuracy when strong heterogeneous features penetrate the inter-element interfaces. Thus, by introducing a MsDGM we
aim toward a class of multiscale methods that are less sensitive to resonance errors
caused by improper boundary conditions for the multiscale basis functions.

C.3.4 On the selection of boundary conditions for the MsFEM


Consider the following homogeneous boundary value problem,
(a(x)ux )x = f, in = (0, 1),
u = 0, on = {0, 1}.

(C.17)

and let x = {xi : 0 = x0 < x1 < . . . < xN = 1} be a corresponding set of finite


element nodal points. Now let V = H01 (\x) and define
U = {u H01 () : (a(x)ux )x = 0 weakly on \x, u = 0 on }.
Then it is easy to see that H01 () = U + V and that U and V are orthogonal with
respect to the energy norm, i.e.,
Z
a(u, v) := a(x)ux vx dx = 0 u U, v V .

Thus, since U ms coincides with U, it follows from the projection property of the
FE method that ums = uI where uI is the interpolant of the exact solution u on x in
U ms = U. This property is due to the fact that there is no resonance error caused by
improper boundary conditions and implies that the conforming MsFEM induces
an ideal domain decomposition preconditioner for elliptic problems in one spatial
dimension.
In higher dimensions the choice of boundary conditions is no longer insignificant. In fact, the MsFEM may be viewed as an extension operator acting on .
Hence, the restriction of the solution ums to must lie in the space spanned by
the boundary conditions for the base functions. To clarify the relation between

202

Multiscale Discontinuous Galerkin Methods for Elliptic Problems

the approximation properties for the MsFEM and the selection of boundary conditions, we consider the following homogeneous boundary value problem: Find
u H01 () such that
Z
Z
a(u, v) := u a(x)v dx = fv dx, v H01 ().

Now, let M = H01 ()| and define the following extension operator
H : M H01 (),

a(H, v) = 0,

v H01 (\).

(C.18)

This extension operator induces a norm on M defined by kk2M = a(H, H).


Clearly, by definition we find that U ms is a subspace of W = H (M), the space
of generalized harmonic functions. In fact, if M ms = span{kT }, then M ms M
and U ms = H (M ms ). Thus, since ums in (C.13) is the orthogonal projection of the
exact solution u onto U ms with respect to a( , )1/2 , it follows that ms = ums | is
the orthogonal projection of = u| onto M ms with respect to k kM . This shows
that the MsFEM also defines an orthogonal projection onto the space of interface
variables with respect to the relevant norm k kM , and hence induces an optimal
coarse solver for nonoverlapping domain decomposition methods. The properties
of the MsFEM as a coarse solver in domain decomposition methods has been
further analyzed in [1, 3].

C.4

Numerical results

Let = (0, 1) (0, 1) be the computational domain. A uniform finite element


mesh T is constructed by dividing into N N squares. The multiscale methods further subdivide each element into M M square elements. A reference
solution is computed on the full resolved NM NM mesh. The global boundary
conditions are specified by setting D = and N = .
We will test six methods, three monoscale numerical methods and three
multiscale methods. The first monoscale method is the FE method (FEM) on
quadrilateral grids with bilinear basis functions. The second method is the
Raviart-Thomas mixed FEM [225] (MFEM) of lowest order on regular quadrilateral grids. This method uses piecewise constant basis functions for the potential
and piecewise linear basis functions for the velocity. The last monoscale method
is the DG method (DGM) which uses bilinear basis functions for potential and linear basis functions for the velocity. These monoscale methods will be compared
with their multiscale variants defined in Section C.3, i.e., with the MsFEM, the
mixed MsFEM (MsMFEM), and the MsDGM. For these multiscale methods we
use the FEM with bilinear basis functions to compute the base functions that span

C.4 Numerical results

203

the approximation space U ms for the potential variable u and the Raviart-Thomas
mixed FEM to compute the basis functions that span the approximation space Qms
for the velocity variable q. Finally, the reference solution is computed using the
Raviart-Thomas mixed FEM. We assess the accuracy of the tested methods with
the weighted error measures
y
y !
x
x
1 kqh qr k2 kqh qr k2
kuh ur k2
+
,
E(qh ) =
.
E(uh ) =
y
kur k2
2
kqrx k2
kqr k2
Here k k2 is the L2 ()-norm, the subscript h denotes computed solutions, the
subscript r refers to the reference solution and the superscripts x and y signifies velocity components. When comparing velocity fields we do not include the
FEMs since these methods are not conservative.

C.4.1 Subscale oscillations


We apply the methods to equations (C.1) with
2 + P sin(2x/) 2 + P sin(2y/)
+
,
2 + P sin(2y/) 2 + P cos(2x/)
f (x, y) = 2 2 cos(x) cos(y).
a(x, y) =

This type of coefficients a(x, y) give rise to spurious oscillations in the velocity
field, and the source term f (x, y) exerts a low frequent force. We shall fix P = 1.8,
NM = 512 and = 1/64 for our numerical test cases. We thus get significant
subgrid variation for N < 64 while the resonance is greatest at N = 64. When
N > 64 the characteristic scale of variation is resolved by the coarse mesh and the
use of multiscale methods are no longer necessary.
Table C.1 shows errors E(uh ) in the potential for all the methods. We see that
none of the monoscale methods perform particularly well, as they cannot pick up
subgrid variations in the coefficients, but the DGM is somewhat more accurate
than the other methods. The multiscale methods, on the other hand, generate
quite accurate potential fields. The MsFEM is most accurate here, but MsDGM
is nearly as accurate, and for very coarse meshes it is the most accurate method.
The least accurate multiscale method is the MsMFEM. This is probably due to
the fact that piecewise constant functions are used to approximate the potential.
The results shown in Table C.2 demonstrate that the monoscale methods tend to
give more accurate velocity fields than potential fields, but we still see that the
multiscale methods give much higher accuracy. We observe also that for this test
case the MsMFEM gives more accurate velocity fields than the MsDGM.
The accuracy of the DG methods depend on the parameter in (C.5). The
results in Table C.1 and Table C.2 correspond to the value of = that produced

204

Multiscale Discontinuous Galerkin Methods for Elliptic Problems


N
8
16
32
64

M FEM MFEM DGM MsFEM MsMFEM MsDGM


64 0.9355 1.150 0.6905 0.1161
0.3243
0.08239
1.100 0.5674 0.03845
0.1733
0.03776
32 1.043
1.086 0.4998 0.02862
0.1127
0.06817
16 1.072
8 0.7119 0.712 0.7117 0.04422
0.1508
0.1269

Table C.1: Potential errors for oscillatory coefficients. For the DGM and the MsDGM, the numbers presented correspond to the choice of that gave the smallest
error.
N M MFEM DGM MsMFEM MsDGM
8 64 0.5533 0.6183
0.2985
0.4291
16 32 0.5189 0.5388
0.2333
0.2842
0.2377
0.2579
32 16 0.5093 0.5144
0.2866
0.3177
64 8 0.5058 0.5079
Table C.2: Relative velocity errors for oscillatory coefficients. For the DG methods the numbers presented correspond to the choice of that gave the smallest
error.
the best solutions. Since we do not know a priori what is, it is natural to ask
how the error behaves as a function of , and, in particular, how sensitive the
DG methods are to the penalty parameter . We have therefore plotted E(uh )
and E(qh ) for both the DG method and the MsDGM in Figures C.1 and C.2 as
functions of . We see that the DG method only converges for a succinct choice of
, except for N = 64. In contrast, the MsDGM converges with good accuracy for
sufficiently large . These plots thus demonstrate that; (1): for elliptic problems
with oscillating coefficients the MsDGM is less sensitive to than the monoscale
DG methods, and (2): the convergence behavior for the MsDGM seem to be in
accordance with the convergence theory for DG methods for elliptic problems
with smooth coefficients.

C.4.2 Random coefficients


In the second experiment the elliptic coefficient function a(x, y) take random values in the interval (0, 1). Thus, for each grid cell in the fine mesh the value of
a is selected at random from this interval. We now only consider the multiscale
methods, and compare the MsDGM with the MsFEM and the MsMFEM. The
corresponding errors are shown in Table C.3. We observe that for this test case

C.4 Numerical results

205

N=8

10

10

10

10

10

10

10

10

10

N=32

10

10

10

10

10

10

10

10

N=64

10

10

10

10

10

N=16

10

10

10

10

10

10

10

10

10

10

10

10

10

10

Figure C.1: Errors induced by the DG method as functions of . The solid line is
the potential error, and the dashed line is the velocity error.
N=8 M=64

10

10

10

10

10

10

10

10

10

N=32 M=16

10

10

10

10

10

10

10

10

N=64 M=8

10

10

10

10

10

N=16 M=32

10

10

10

10

10

10

10

10

10

10

10

10

10

10

Figure C.2: Errors induced by the MsDGM as functions of . The solid line is
the potential error, and the dashed line is the velocity error. Note that the error
decreases monotonically as increases, and that the method converges for >
O(1/h).

206

Multiscale Discontinuous Galerkin Methods for Elliptic Problems


N
8
16
32
64

M
64
32
16
8

MsFEM MsMFEM MsDGM


0.4458 0.3290
0.1394
0.3827 0.1839 0.07163
0.3589 0.1510 0.03766
0.3335 0.2074 0.02539

MsMFEM
0.3375
0.2851
0.2941
0.3346

MsDGM
0.4849
0.3716
0.3472
0.3624

Table C.3: Potential errors E(uh ) (left) and Velocity errors E(qh ) (right) for an
elliptic problem with random coefficients.
the MsDGM generates the by far most accurate potential field, in fact, by almost
an order of magnitude. The MsMFEM still produces the most accurate velocity
field, but the MsDGM produces a velocity field with comparable accuracy. These
results are representative for the results we obtained for a variety of different random coefficient functions. Again the parameter for the MsDGM numerical flux
function q was attempted optimized in order to give best results.
The results in Table C.3 indicate that the MsDGM may be more robust than
the MsFEM. Unfortunately, for this case the MsDGM was more sensitive to than
what we observed in Subsection C.4.1, and choosing too large can deteriorate
the convergence, see Figure C.3. However, the optimal for potential ( 13,
34, 83 and 188 for h = 8, 16, 32 and 64 respectively) still scales like O(1/h).
This suggest that good accuracy should be obtained by choosing /h for some
fixed O(1).

C.5

Concluding remarks

In this paper, we have used approximation spaces for two different multiscale
finite element methods in order to develop a multiscale discontinuous Galerkin method for elliptic problems with multiple scale coefficients. Unlike the
multiscale finite element methods, the multiscale discontinuous Galerkin method
introduced in this paper provides detailed solutions for both velocity and potential that reflect fine scale structures in the elliptic coefficients. This makes the
multiscale discontinuous Galerkin method an attractive tool for solving, for instance, pressure equations that arise from compressible flows in heterogeneous
porous media. Indeed, in compressible flow simulations it is not sufficient to resolve the velocity field well, an accurate pressure field is also needed.
Numerical comparisons with both monoscale- and multiscale methods have
been given. The results show that monoscale numerical methods are inadequate
when it comes to solving elliptic problems with multiple scale solutions. We have
further demonstrated that the multiscale discontinuous Galerkin method produce

C.5 Concluding remarks

207

N=8 M=64

10

10

10

10

10

10

10

10

10

N=32 M=16

10

10

10

10

10

10

10

10

N=64 M=8

10

10

10

10

10

N=16 M=32

10

10

10

10

10

10

10

10

10

10

10

10

10

10

Figure C.3: Logarithmic plot of errors for the MsDGM for random coefficients.
The plots should be compared with the results depicted in Figure C.2.

solutions with comparable or higher accuracy than solutions produced by corresponding multiscale finite element methods. To summarize the results for the
multiscale methods, we plot errors for all the multiscale methods in Figure C.4.
This figure shows that the velocity solutions obtained with the multiscale discontinuous Galerkin method have comparable accuracy with the velocity solutions
obtained with the corresponding mixed multiscale finite element method. The potential solutions produced by the multiscale discontinuous Galerkin method, on
the other hand, are equally or more accurate than the potential solutions obtained
with both of the multiscale finite element methods.
In the present paper we have not provided any convergence theory, but it is
likely that convergence results can be obtained using results from homogenization theory in conjunction with the convergence theory for discontinuous Galerkin methods for elliptic problems with smooth coefficients. However, since
the discontinuous Galerkin methods appear to give comparable accuracy to the
multiscale mixed finite element methods for which error estimates based on the
homogenization theory have been established, one can expect the discontinuous
Galerkin methods to enjoy similar error estimates. We have also shown that the
multiscale discontinuous Galerkin method appears to converge for values of the
penalty parameter in the numerical flux function that is in accordance with the
convergence theory for Galerkin methods for elliptic problems with smooth coef-

208

Multiscale Discontinuous Galerkin Methods for Elliptic Problems


0

10

10

MsMFEM
1

MsDGM

10

MsDGM
MsMFEM
MsFEM
2

10

16

32

64

10

16

32

64

10

10
MsFEM

MsDGM
MsMFEM

10

MsMFEM
MsDGM
2

10

16

32

64

10

16

32

64

Figure C.4: Plot of the errors as functions of grid size for oscillatory (top) and
random coefficients (bottom) respectively. The left figures show potential errors,
and the right figures show the velocity errors. The MsDGM is the solid line, the
MsMFEM is the dashed line, and the MsFEM is the dashed and dotted line.
ficients. A rigorous convergence analysis of the multiscale discontinuous Galerkin
methods is a topic for further research.
Acknowledgments

We would like to thank Kenneth H. Karlsen and Ivar Aavatsmark for useful comments. The second author would also like to thank the Research Council of Norway for financial support.

Paper D
Level set methods for a parameter
identification problem
Bjrn-Ove Heimsund, Tony Chan, Trygve K. Nilssen and Xue-Cheng Tai
Abstract
We present a level set based method for recovering piecewise constant diffusion
coefficients from an elliptic equation. The level set method is used to represent
the coefficients and the augmented Lagrangian method is used to solve the outputleast-squares functional with the equation as a constraint. We do not assume that
the number of the different constant coefficients are known a priori it suffices
to know only an upper bound on the number of the constant values. For a maximum of n different coefficient values, only log2 n level set functions are needed.
The geometry of the different constant coefficient regions are automatically determined by the level set method.

Published in the book Analysis and optimization of differential systems, pages 189200 by Kluwer
Academic Publishers in 2003. Volume 121 of International Federation for Information Processing
(IFIP) series

D.1 Introduction

D.1

211

Introduction

Consider the partial differential equation



(q(x)u) = f in Rd ,
u = 0 on .

(D.1)

We want to use observations of the solution u to recover the coefficient q(x).


We shall especially treat the case that q(x) has discontinuities and is piecewise
constant.
In this work, we shall combine the ideas used in [149] and [60] to use level set
methods to estimate the coefficient q(x). The level set method was first proposed
in Osher and Sethian [211]. This method associate a two-dimensional closed
curve with a two-dimensional function. Extensions to higher dimensions are also
easy, see Ambrosio and Soner [16]. The advantage of using level set method is
that it gives a better tool for evolving curves that may disappear, merge with each
other, or pinch off with each other.
The level set method has been used for some inverse problems in [93, 232],
etc. The work of [149] seems to the first one to apply the level set idea to estimate
the coefficient q(x) from the equation (D.1). The work of [149] only works when
the coefficient q(x) takes two constants values, i.e. they can only handle one level
set function. Several approaches have been proposed to use multiple level set
functions (not for inverse problems, but for fluid and image problems) [60, 279].
The approach of [60] is easy to implement and has been well tested for image
segmentation problems. In this work, we are trying to use the idea of [60] for
the parameter estimation problem. See also [188, 187] for some related works in
using Heaviside functions to identify shapes and boundaries.

D.2

Level set methods

Here, we state some of the details of the level set idea. Let be a closed curve in
. Associated with , we define as a signed distance function by

distance(x, ),
x interior of ,
(x) =
distance(x, ),
x exterior of .
In many applications, the movement of the curve can be described by a partial differential equation of the function . The function is called a level set
function for . In fact, is the unique viscosity solution for the following partial
differential equation
|| = 1, in .
(D.2)

212

Level set methods for a parameter identification problem

In this work, we shall use the level set method to identify the coefficient q
which is assumed to be piecewise constant. First look at a simple case, i.e. assume
that q has a constant value q1 inside a closed curve and is another constant q2
outside the curve . Utilizing the Heaviside function H (), which is equal to 1
for positive and 0 elsewhere, it is easy to see that q can be represented as
q = q1 H () + q2 (1 H ()) .

(D.3)

In order to identify the coefficient q, we just need to identify a level set function
and the piecewise constant values qi .
If a function has many pieces, then we need to use multiple level
set functions. This idea was introduced in Chan and Vese [60]. Assume that we have two closed curves 1 and 2 , and we associate the
two level set functions j , j = 1, 2 with these curves.
Then the domain is divided into the four parts ++ = {x, 1 > 0, 2 > 0},
+ = {x, 1 > 0, 2 0},
+ = {x, 1 0, 2 > 0},
= {x, 1 0, 2 0}.
Allowing some of the subdomains defined above to be empty, we can easily
handle the case that the zero level set curves could merge, split or disappear. Using
the Heaviside function again, we can express q with possibly up to four pieces with
constant values as
q = q1 H (1 )H (2 ) + q2 H (1 )(1 H (2 ))+
+q3 (1 H (1 ))H (2 ) + q4 (1 H (1 ))(1 H (2 )).

(D.4)

By generalizing, we see that n level set functions give the possibility of 2n


regions. In that case, q would look like
q = q1 H (1 ) H (2 ) H (n ) +
+q2 (1 H (1 )) H (2 ) H (n ) +
..
.

(D.5)

+q2n (1 H (1 )) (1 H (2 )) (1 H (n )) .
Even if we need less than 2n distinct regions, we can still use n level set functions
since some subdomains may be empty. In using such a representation, we need to
determine the maximum number of level set functions we want to use before we
start.
For many practical applications, such kind of priori information is often available or is chosen according the measurements that are available to us. Also, to
ensure ellipticity of equation (D.1), we need each qi to be positive, that is, we assume that there exist 0 < ai < bi < that are known a priori such that qi [ai , bi ].

D.3 The parameter identification problem

D.3

213

The parameter identification problem

We shall try to identify the coefficient q from a measurement of u on a subdomain


We shall perform the numerical tests both for the case that
= and the case
.
. In case that
= , existence and uniqueness of the inverse problem
that
is already known. For general cases, studies about existence and uniqueness are
still missing in the literature. In this work, the parameter identification problem is
formulated as a least-square minimization problem and then we propose to use the
augmented Lagrangian method to solve the least-squares minimization problem
with the equation as constraint.
We start by defining the equation error of equation (D.1) as e = e(q, u) H01 ()
which is the variational solution of
(e, v) = (qu, v) (f, v) ,

v H01 ().

(D.6)

Here and later ( , ) denotes the L2 -innerproduct over . We will also use the
notation k k to denote the associated norm. For a given q and a given u, we say
that they satisfy the equation (D.1) if and only if e(q, u) = 0. In order to solve our
inverse problem, we shall try to find a q and u such that e(q, u) = 0 and also fits
the measurements u best among all admissible functions q and u. Using the level
set functions, the coefficient q will be represented as functions of the level set
functions j and the piecewise values qi and the minimization problem we need
to solve takes the form
!
n Z
X

1
min
ku uk
22 +
|H j |dx ,
L ()
qi ,j ,u 2
(D.7)

i=1

under the conditions e(q, u) = 0,

|j | = 1, j.

In the above q is a function of j and qi . The constraint e(q, u) = 0 makes sure


the equation error is zero. The first termPtriesRto minimize
 the deviation between
the calculated u and measured u,
while ni=1 |H j |dx in the second term
is referred
to as aregularization term. In case that is a one-dimensional domain,
R
then |H j |dx equals to the number of points that the level set functions j
equals zero. If is two-dimensional, it is the length of the zero level set curves of
j . For three-dimensional cases, then it is the area of the zero level set surfaces of
j .
To solve (D.7), we use the augmented Lagrangian formulation, and the corresn
ponding Lagrangian functional L : R2 [Lip()]n H01 () H01 () 7 R is
1
L(qi , j , u, ) = ku u k2 2 +
L ()
2
n Z
X
c
+
|H (j )|dx + kek2 (, e) .
2

j=1

(D.8)

214

Level set methods for a parameter identification problem

The Lagrangian multiplier is only trying to enforce the equation constraint


e(q, u) = 0. The other constraints |j | = 1 will be enforced by some other methods well developed for the level set methods. Due to the fact that the j s are the
viscosity solutions for the Eikonal equation, it is not easy to enforce them by the
Lagrangian multiplier method.
In order to find a minimizer for the minimization problem (D.7), we shall use
an algorithm of the type of the Lancelot method which will be given later in this
section. The algorithm needs the derivatives of the Lagrangian functional with
respect to the minimization variables.

D.3.1 Calculation of qi L
The derivative of L with respect to qi is
 
 


e
e
e
L
,
= , (ce ) .
= c e,
qi
qi
qi
qi
From (D.6), it follows that the derivative of e with respect to qi is

 

e
q
, v =
u, v .
qi
qi
Taking v to be ce gives
L
=
qi


q
u, (ce ) .
qi

It is trivial to calculate the derivative of q with respect to qi when using equation


(D.5).

D.3.2 Calculation of j L
For clarity of the presentation, we shall first calculate the Gauteaux derivative
of the regularization term, i.e. we first calculate the Gauteaux derivative for the
following functional
Z
Z
R(j ) = |H (j )|dx = (j )|j |dx.

Here and later, denotes the Dirac-function. To get the derivative of R with
respect to j in the direction j , we proceed
Z
Z
j
R

j = (j )j |j |dx + (j )
j dx.
j
|j |

D.3 The parameter identification problem

215

Applying Greens formula to the last term which can be theoretically verified by
replacing the delta function by a smooth function and then passing to the limit, we
will get that


Z
Z
j
R

j dx
j = (j )j |j |dx (j )
j
|j |

!
Z
Z
2
|
|

j
j
(D.9)
(j )
= (j )j |j |dx
dx
j +(j )j
|j |
|j |

Z
j
= (j )j
dx,
|j |

which indicates that

j
R
= (j )
.
j
|j |

Denote the Gauteaux derivative of L with respect to j in the direction j as


L
j j . The Gauteaux derivative in this case is


 


L
R
e
e
j = c e,
j
,
j
+
j
j
j
j
j


R
e
j , ce +
j .
=
j
j
The derivative of e with respect to j in the direction j is

 

 
q
e
j , v =
j u, v ,

j
j
Taking v to be ce , we get that


R
q
L
j =
j , u (ce ) +
j .
j
j
j

(D.10)

q
From (D.5), it is easy to calculate the Gauteaux derivative
j . For simplicity
j
of the presentation, let us take the case that we only have two level set functions.
Then q takes the form (D.4). Consequently, the Gauteaux derivative for the function j in a direction j is



q
1 = (q1 q3 )H (2 ) + (q2 q4 )(1 H (2 ) (1 )1
1


q
2 = (q1 q2 )H (1 ) + (q3 q4 )(1 H (1 ) (2 )2 .
2

(D.11)
(D.12)

216

Level set methods for a parameter identification problem

D.3.3 Calculation of u L
We perturb u to u + w and try to calculate the Gauteaux derivative of L with u in
the direction w. First note that
 


e

w , v = (qw, v), v H01 (),


u
and


 


e
e
L
w = (u u,
w)L2 ()
w
,
w
+ c e,
u
u
u



e
= (u u,
w)L2 ()
w
.
+ (ce ),
u
Combining the above two equalities, it is true that
L
w = (u u,
w)L2 ()
+ ((ce ), qw) .
u
This indicates that
L
= (u u)
(q(ce )),
u

where is the characteristic function for the subdomain ,

(x) = 1 if x and (x) = 0 if x 6 .

i.e.

D.3.4 An algorithm of Lancelot type


To solve the minimization problem (D.8) we will use a Lancelot type algorithm,
as described in Conn, Gould and Toint [80]. In our case, the algorithm can be
written as follows
Algorithm 1 Choose qi0 , 0j , u0 as initial guess for the solution, and set 0 =
0, k = 0. Also chose initial tolerances m > 0, e > 0, and the parameters c >
0, > 0, > 1.
Then iteratively do the following steps:


k+1 k+1 k+1
1. Find an approximative minimum qi , j , u
of equation (D.8) such




that qk+1,k+1 ,uk+1 L m .
i



2. If kek < e , update by k+1 = k ce qik+1 , jk+1 , uk+1 ,
else update c by c c.

D.4 Numerical experiments

217

3. Decrease m , e , and set k k + 1.


In the first step of the iteration, we actually try to solve the minimization problem. Since is not solved for, neither do we need to drive kLk to zero. The
second step checks to see if the equation error is sufficiently small, and if so is the
case, may be updated. Should the error not be small, the penalty parameter c is
increased, making the augmented Lagrangian functional more dominated by the
kek2 term. With these steps, we can decrease the tolerances, and go to the next
iteration.
For the minimization problem, one may chose any suitable method for nonlinear, unconstrained problems, such as the method of steepest descent, the nonlinear conjugate gradients, or the Quasi-Newton methods. Steepest descent methods, while being simple to implement, are known for giving low performance, and
the Quasi-Newton methods needs careful implementation and provisions to limit
memory usage, but they often yield excellent performance. In our case, the nonlinear conjugate gradients method was found suitable. It has good performance,
low memory usage, and is easy to implement. See [205] for more information
regarding these methods.
There are some aspects of our minimization that require additional explanation. We compute the composite derivative of L, that is a vector consisting of
qk,l , then k,l and finally uk,l . This makes us minimize L with all the uni
j
knowns simultaneously. The reason for doing this instead of optimizing each
unknown separately is that the latter approach is equivalent to a coordinate descent method, giving poor convergence. However, there may be problems finding
an optimal steplength for this composite search direction, ie. j may require a
smaller steplength than u. By defining
u = su, s > 0,
and using u in the optimization, the rate of convergence may be improved. We
have in our experiments chosen s experimentally.
We also need to enforce constraints on qi and j . The former is just to set
qi = min{max{qi , ai }, bi }, while for the latter we would try to ensure that
|jk+1 | = 1,

jk+1 = 0 on kj .

For a one-dimensional problem, this can easily be done, but in higher dimensions
we can use methods described in Osher and Fedkiw [210], and Smereka, Sussman, Fatemi and Osher [252]. There are fast and cheap algorithms to solve this
problem, see [252, 210].

218

Level set methods for a parameter identification problem

0.9

0.9

0.8

0.8

0.7

0.7

0.6

0.6

0.5

0.5

0.4

0.4

0.3

0.3

0.2

0.2

0.1

0.1

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

0.1

0.2

0.3

(a) Initial

0.4

0.5

0.6

0.7

0.8

0.9

(b) Final

Figure D.1: The first case. Convergence was attained after about 300 iterations.
Also, kuh uk2 1.1906 104 at time of convergence.

0.9

0.9

0.8

0.8

0.7

0.7

0.6

0.6

0.5

0.5

0.4

0.4

0.3

0.3

0.2

0.2

0.1

0.1

0.1

0.2

0.3

0.4

0.5

0.6

0.7

(a) Convergence for q

0.8

0.9

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

(b) Convergence for q +

Figure D.2: This is the second case, with perturbed qi s and we start with the
same initial levelsets as in the first case. For q , it took about 350 iterations to
converge, and kuh uk2 1.3027 104 at that time, while for q + it only took
about 100 iterations, and here kuh uk2 1.1182 104 . Since the discontinuities
are smaller in this latter case, this quicker convergence is expected.

D.4 Numerical experiments

219

0.9

0.9

0.8

0.8

0.7

0.7

0.6

0.6

0.5

0.5

0.4

0.4

0.3

0.3

0.2

0.2

0.1

0.1

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

0.1

(a) Noise amplitude 102

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

(b) Noise amplitude 5 103

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

(c) Noise amplitude 103

Figure D.3: Here is the third case, with noise added to u . After about
100 iterations, we had convergence, and the error kuh uk2 was about
1.7251 104 , 1.5019 104 and 1.4223 104 for noise amplitudes of 102 , 5 103
and 103 respectively. More noise made it generally impossible to get convergence, and with less noise the solution was not distinguishable from the case
without noise.

220

D.4

Level set methods for a parameter identification problem

Numerical experiments

In our numerical tests, we will consider three cases. First, the qi s are all known,
and we try to identify j and u; then we perturb qi , and attempt to identify j and
u with qi fixed. Thirdly, we add noise to u,
and try to identify j and u while qi is
known.
The equation we will use is
(qu) = 2 2 sin(x) sin(y), in
u = 0,
on .

(D.13)

Here, = (0, 1) (0, 1). All experiments are done with a uniform, 2D mesh of
, with 24 24 elements. The numerical parameters used are = 107 , c =
5 106 , = 1.1, s = 25.
We shall use q given by two level set functions as follows. q1 = 1 when
1 , 2 0, q2 = 1 + 21/3 when 1 0, 2 > 0, q3 = 1 + 22/3 when 1 > 0, 2 0,
and finally q4 = 3 when 1 , 2 > 0. 1 is positive within the union of the following
rectangles
{x, y:3/4<x<7/8, 1/8<y<7/8} {x, y : 1/8<x<7/8, 3/4<y<7/8},
and 2 is likewise positive within this union
{x, y:1/8<x<1/4, 1/8<y<7/8} {x, y : 1/8<x<7/8, 1/8<y<1/4}.
In all the figures, we draw the zero level set curves of the level set functions.
The dashed lines are for solution, and the solid lines are for the computed solution. Furthermore, 1 and its computed approximation is in the upper-right of the
figures, while 2 is in the lower-left.
extend from the boundary of and into the interior by
In all cases, we let
be a coarser than
a length of 1/3 from all sides. In the remainder, we let
by a factor of two. Thus we have complete observations u along the boundary,
and coarser observations in the interior. Note that kuk 0 near the center of .
Because of this, we cannot easily identify q in the center since for kuk = 0, q is
no longer unique.
Solving for the first case yields the results in Figure D.1, and are quite accurate.
For the second case, we will use the two sets of qi coefficients q and q + ,
and they are given as follows. q1 = q1 0.1, q2 = q2 0.05, q3 = q3 0.05,
q4 = q4 0.1.
Note that the perturbations in q create larger jumps, while in q + the jumps
are smaller. The results are in Figure D.2, and we see that it is easier to identify q +
rather than q due to smaller jumps. Also note that the deviations from Figure D.1
are small.

D.4 Numerical experiments

221

We now come to the third case where we will add noise to our observations,
and try find j and u. Adding normally distributed noise of varying magnitude
gives us the results in Figure D.3. Having larger noise-magnitude than 102 makes
it generally hard to get convergence, while a noise-magnitude of less than 103
hardly makes much of an impact on our case.

Paper E
On a class of ocean model
instabilities that may occur when
applying small time steps, implicit
methods, and low viscosities
Bjrn-Ove Heimsund and Jarle Berntsen
Abstract
The horizontal grid size in ocean models may be gradually reduced with increasing computer power. This allows simulations with less viscosity. The hyperbolic,
free wave nature of the problem will become more dominant. However, as viscosities are reduced, instabilities may more easily occur. To avoid such instabilities,
it is well known from the literature on numerical methods for ordinary differential
equations that implicit methods have attractive stability properties. Therefore, it
may be tempting to add implicitness into the time stepping also in low viscosity
ocean modelling to improve the robustness. However, when using methods with
implicit features and low viscosity, it may happen that models are stable for longer
time steps, but become unstable as the time step is reduced. In the present paper,
an explanation for this phenomenon is given. It is shown that the explanation may
be valid when solving the shallow water equations on a C-grid.

Published in Journal of Ocean Modelling, volume 7 (2004), pages 135144

E.1 Introduction

E.1

225

Introduction

Ocean modellers often experience instabilities, especially in cases with little or


no friction. Often the viscosities have to be chosen larger than we would like to
from physical considerations to avoid instabilities, see for instance [35]. Some
instabilities are well understood like those associated with the CFL-criterion, and
the remedies to avoid them are obvious. Others are more subtle in nature, and
it may be difficult to find a reasonable method to avoid unphysical growth. In
particular, one may experience in low-viscosity studies that the models are stable
for longer time steps, but they may become unstable when the time steps are
reduced. One such case is recently reported in [115] for the ROMS model ([240]).
Without external forcing, the energy of the systems described by the primitive
equations for oceanic flow should not be growing. After discretising the partial
differential equations in space only, the system may be described as a system of
ordinary differential equations (ODEs). To maintain the no-growth property, the
eigenvalues of the propagation matrix in the system of ODEs, should be on the
imaginary axis or in the left half plane of the complex plane. However, spatial
discretisation errors may move one or more of the eigenvalues slightly into the
right half plane. The exact solution of the system of ODEs will then be growing.
If one, in addition, applies a time stepping technique with a region of stability, see
[130], that include parts of the positive half plane, the model may still run stably
for longer time steps. However, the solution will grow to infinity for small enough
time steps.
Real ocean models typically involve more than 106 variables, and it will not
be feasible to set up and analyse the full propagation matrix. Therefore, to demonstrate that the explanation for some instabilities given above, may be relevant for
ocean models, we have studied the numerical solution of the linear shallow water
equations discretised on a C-grid with only three ocean cells.

E.2

Stability analysis

Stability analysis of ordinary differential equations (ODEs) is a classic topic in


numerical analysis. This sections contains a brief application of that theory to
some selected methods, see [87, 140, 120, 130, 131].
Let us consider the ODE
u
= u
t
for some C. A numerical scheme applied to this ODE is defined to be absolutely stable if it produces bounded solutions as t . The theta method applied

226

On a class of ocean model instabilities

to the given ODE may be written



un+1 = un + t (1 )un + un+1 ,

[0, 1].

A polynomial solution is assumed, with un = n . The previous equation becomes



n+1 = n + z (1 ) n + n+1 ,
where z = t. After division by n the equation becomes
= 1 + z ((1 ) + ).
The solution is

1 + (1 )z
.
1 z
Since the solution is assumed to be n , it will be bounded if || 1. The set of
zvalues which give bounded solutions, is the stability region of the method. As
an example, for = 0 the method is the forward Euler method, and
=

= 1 + z,
which gives a stability region given by z = r exp(i) 1, = [0, 2), r = [0, 1].
This is the interior of a unit-circle centred at z = 1. For = 1/2, the method is
the trapezoidal method, and
2+z
=
.
(E.1)
2z
For this method the stability region is the negative half of the complex plane, z 0.
An often used ODE solver is the multistage Runge-Kutta 4 (RK4),
1
un+1 = un + (a + 2b + 2c + d),
6
with
a = zun , b = z(un + a/2) , c = z(un + b/2) , and d = z(un + c).
Assuming polynomial solution n , we get
1
1
1
= 1 + z + z2 + z3 + z4 .
2
6
24

(E.2)

This is evaluated numerically, and the boundary of the stability region is given in
Figure E.1.
The third method to be considered is the Leapfrog predictor, Adams-Moulton
2-step corrector scheme (AM2+LF), as used in ROMS,
( n+1
u
= un1 +2zun

un+1 = un + z a1 un+1 + a2 un + a3 un1 .

E.3 Numerical experiment

227
3

2.5

1.5

0.5

Figure E.1: Stability region for the RK4 method. The real axis range from 3
to 0.5, and the imaginary axis range from 3 to 3. is exactly equal to one
in magnitude along the drawn lines, and the magnitude is smaller than one on
the inside. Note that parts of the positive half-plane are included in the stability
region.
The coefficients are a1 = 5/12, a2 = 2/3 and a3 = 1/12. To analyse stability, we
insert the predictor into the corrector, getting

un+1 un = 2a1 un z2 + a2 un + (a1 + a3 )un1 z.
Assuming polynomial solution un = n , the previous equation may be written as
( 1) = 2a1 z2 + (a2 + a1 + a3 ) z.

(E.3)

For each value of z, the equation yields two roots in . As is known from the
theory of multi-step methods, both roots must satisfy || 1 or || < 1 if they are
equal. Using numerical evaluation, the outline of the stability region is given in
Figure E.2.

E.3

Numerical experiment

Let f be the Coriolis parameter, g the gravity constant, U and V the depth integrated transports in x and y directions, respectively, the sea surface elevation

228

On a class of ocean model instabilities

1.5

0.5

1.2

0.8

0.6

0.4

0.2

0.5

1.5

Figure E.2: Stability region for the AM2+LF predictorcorrector method. The
real axis range from 1.2 to 0.075, and the imaginary axis range from 1.6 to 1.6.
is exactly equal to one in magnitude along the drawn line, and the magnitude
is smaller than one on the inside. As for the RK4 method, parts of the positive
half-plane are included in the stability region.
and H the undisturbed water depth. The linearised shallow water equations in
Cartesian coordinates (x, y) may then be written
U

= gH + fV
t
x

V
= gH fU
t
y

U V
=

.
t
x y

(E.4)

After discretisation in space only, the system of partial differential equations


is transformed to a system of ordinary differential equations
d
w(t) = Aw(t),
(E.5)
dt
where all the discrete variables are gathered in w(t) and A is the propagation
matrix.
The numerical solution of Equations (E.4) was discussed in [110]. The main
conclusion was that with a C-grid, variable depth, and 1/4-weighting when estimating Coriolis terms, the spatial discretised system (E.5) will have growing

E.3 Numerical experiment

229

modes. A theoretical explanation was also given, and three case studies were
presented. To illustrate the main point, the case with the simplest possible C-grid
ocean model involving both U, V and points is repeated below, see Figure E.3.

1
V

Figure E.3: Variables in the 3-cell case.


Applying central differences for the spatial derivatives and 1/4-weighting to
estimate V in the U-point and vice-versa, the matrix-vector product Aw(t) becomes

f
gHu
gHu
0

0
U
x
x
4
gHv
f
v

0
0 gH

y
y
4
V

0
0
0
0

1 ,
y

1
1
x y
0
0
0 2
1
3
0
0
0
0
x

where Hu and Hv are the depths in the U and V points respectively, x and y
are the lengths of the grid cells in two directions. In the experiment g = 9.81 ms2 ,
f = 1.3 104 s1 , x = y = 20000.0 m, Hu = 200.0 m and Hv = 2000.0 m .
The initial values are 1 = 3 = 0.0 m, 2 = 1.0 m, U = V = 0.0 m2 s1 . For the
values of the parameters given above, the 5 eigenvalues of the matrix A above are:
1,2 = 0.7665 105 0.0100i, 3,4 = 0.7665 105 0.0026i, 5 = 0.0. From
the initial values, the eigenvectors, and the eigenvalues, the exact solution after

230

On a class of ocean model instabilities

120 hours is computed and it is: 1 = -10.0209 m, 2 = 11.2886 m, 3 = -0.2677m,


U = 89.4103 m2 s1 , and V = 1790.1407 m2 s1 .
v
The relationship H
Hu = 10 in the present study, and this may seem large. The
solution of the spatial discretised problem will grow as long as this fraction is not
equal to 1. The growth will become stronger for larger values of the fraction, see
[110]. Any fraction different from 1 would have sufficed to demonstrate exponential growth for small time steps. In addition, with x = 20000.0 m there are areas
along the shelf edges where one grid point will be on the shelf, approximately
200m deep, and the neighbouring point will be in the deep ocean, maybe 2000m
deep. One such area is located along the shelf slope outside the northern part of
Norway. Thus for larger values of t and steep slopes, the given relationship may
occur.
The solution is propagated forward in time for 120 hours using
1. the trapezoidal method of order 2,
2. the RK4 method of order 4, and
3. the two step AM2+LF method of order 3,
for different choices of time step, t . When applying the multi-step AM2+LF
method, the first time step is taken with the RK4 method. Some results from the
experiments are given in tables 1 to 3.
From the tables we notice that the numerical solutions converge to the exact
solution of the spatially discretised problem when t tend to zero. This solution
5
grows with e0.766510 t , and it is unacceptable as a solution of the underlying
physical problem. The convergence rate depend on the order of the method, and
for the highest order method, RK4, very good approximations are achieved with
much longer time steps than with the trapezoidal method, which has lowest order.
For the trapezoidal method, the stability region does not include parts of the
right half complex plane, and the numerical solution grows for all values of the
time step. In [110] a new Coriolis weighting is suggested that does not introduce
false positive real eigenvalues. It is further demonstrated on three cases, including
the three cell case and a more realistic study for the North Sea, that by using the
trapezoidal method and the new weighting, the artificial growth is avoided.
For the two other methods, the stability region does include parts of the right
half complex plane. Therefore, the products t may all be brought inside the
stability region by choosing t properly. When applying the RK4 method, this
happens for t = 256s and t = 128s. When applying the AM2+LF method,
this happens when the time step is 256s, 128s, 64s, or 32s. In these cases, the
numerical solutions tend to zero with time. When reducing the time step in these
cases, t will move out of the stability region, and the solution will converge

E.3 Numerical experiment

231

t
2
U
V
||
256.0 -0.61386 17.570
297.81 1.000740577
128.0 -4.5845
28.611
457.13 1.000694774
64.0
0.3028 -108.953 -2013.9 1.000444791
32.0 -1.3130 135.981 2505.6 1.000239146
16.0 -8.9838 -102.860 -2022.0 1.000121864
8.0
-0.3633 -146.604 -2727.7 1.000061224
4.0
14.618
9.495
350.1 1.000030649
2.0
12.528
71.245
1468.8 1.000015329
1.0
11.621
85.031
1713.1 1.000007665
0.5
11.373
88.327
1771.1 1.000003833
0.25
11.310
89.141
1785.4 1.000001916
Table E.1: Results for the trapezoidal method. The values are from left to right:
the time step in s, 2 in m, U and V in m2 s1 , after 120 hours. In the last column
|| is given, computed using the eigenvalue of A with positive real part, the given
time step, and Equation (E.1). The method is stable for || 1.
t
512.0
256.0
128.0
64.0
32.0
16.0
8.0
4.0
2.0
1.0
0.5

2
U
V
||
Infinite values after 31.57 hours 24.30160691
0.3327 -0.1823
0.0985
0.5534924853
0.3383 0.0420
-0.0233
0.9758215121
0.2385 6.478
116.66
1.000024747
12.605 36.552
826.65
1.000237683
11.472 86.281
1734.4
1.000122527
11.301 89.224
1786.8
1.000061321
11.289 89.400
1790.0
1.000030661
11.289 89.411
1790.1
1.000015330
11.289 89.411
1790.2
1.000007665
11.289 89.411
1790.2
1.000003833

Table E.2: Results for the RK4 method. The values are from left to right: the time
step in s, 2 in m, U and V in m2 s1 , after 120 hours. In the last column || is
given, computed using the eigenvalue of A with positive real part, the given time
step, and Equation (E.2). The method is stable for || 1.
to the exact solution. When increasing the time step, the Courant number will
become greater than 1, and the solution will soon tend to infinity.

232

On a class of ocean model instabilities

t
512.0
256.0
128.0
64.0
32.0
16.0
8.0
4.0
2.0
1.0
0.5

2
U
V
Infinite values after 32.49 hours
0.33329 0.01239 -0.00668
0.33329 0.01239 -0.00668
0.33618 0.11061 -0.06006
0.33813 0.11501 -0.06706
1.6016 23.967
457.56
8.9737 74.424
1483.8
10.980 87.200
1745.4
11.250 89.120
1784.3
11.284 89.374
1789.4
11.288 89.407
1790.1

|max |
4.70350655
0.910921537
0.910921537
0.990509169
0.999365416
1.000060768
1.000057326
1.000030409
1.000015314
1.000007664
1.000003832

Table E.3: Results for the AM2+LF method. The values are from left to right: the
time step in s, 2 in m, U and V in m2 s1 , after 120 hours. In the last column max
|i |, i = 1, 2 is given. The maximum is computed using the eigenvalue of A with
positive real part, the given time step, and Equation (E.3). The method is stable
for |max| 1.

E.4

Concluding remarks

The stability properties of numerical methods are often studied with the Fourier
method. This method is only applicable to linear equations and constant parameters i.e. constant depth of the ocean and constant Coriolis parameter.
Based on studies for these simplified cases, methods are often selected for
application on more realistic problems involving non-linearities, variable coefficients and coupled systems of equations. In [110] it was demonstrated that even
for the relatively simple and well studied linear shallow water equations, it would
be enough to introduce variable depth or variable Coriolis parameter to make the
space discretised system unstable. If a time stepping method with a region of stability that includes parts of the right half complex plane is applied, the models
may still run stably for longer time steps. However, as the time steps are reduced,
the solution will grow with the growth rate given by the positive real parts of the
eigenvalues of the propagation matrix. This may explain that models for complicated sets of equations may become more unstable as the time steps are reduced.
With increasing computer power, it will be feasible to apply higher spatial resolution. This may allow simulations with smaller viscosities, and the hyperbolic
wave nature of the solutions will become more dominant and realistic. However,
in [110] it is shown that the spatial discretisations may force us to increase the

E.4 Concluding remarks

233

viscosities more than one would like from physical considerations to move the
eigenvalues of the propagation matrices out of the right half complex plane.
An alternative to increase the viscosity, when encountering this growth, is to
introduce time stepping methods with implicit features. This is typically methods
with regions of stability that includes parts of the positive half complex plane. The
models may then run stably for longer time steps, but for consistent methods the
instabilities will appear for small enough time steps. This is demonstrated here
for the RK4 method and AM2+LF method.
Even if one may achieve stability by applying implicit methods and longer
time steps, the price may be that the waves become more damped than they should
be. Thus it is not clear that it is physically more correct to add implicitness instead
of increasing the viscosities when encountering instabilities.
The spatial discretisations should be chosen such that the non-growth property of the underlying partial differential equations is maintained. A new Coriolis
weighting is suggested in [110] that brings all the eigenvalues of the present problem without friction on to the imaginary axis, and therefore non-growing wave
solutions are obtained.
An alternative to applying this linear algebra or eigenvalue approach is to apply the energy method. The task is then to construct discrete spatial operators such
that for instance energy and potential enstrophy are conserved, see [18] and [19].
The schemes produced with the energy method are rather complicated involving
large computational stencils and may be difficult to apply in practise, see [200].
The [110] method only involves the same four points as in the usual 1/4 weighting, but accuracy and conservation of potential enstrophy properties of the method
has not been studied. Thus, the two approaches give energy conserving methods
that are different. Systematic comparisons of other properties of the Espelid and
Arakawa discretisations remain to be done.
It should be noted that ROMS does not apply the 1/4-Coriolis weighting given
here. However, there may be other spatial discretisation errors that moves the
eigenvalues into the right half plane. It is for instance well known that the errors
in the internal pressure gradients in -coordinate ocean models may grow, see
[33, 193].
For full size ocean models it is not feasible to analyse the propagation matrices.
However, the technique illustrated here may be applied to more complicated equations for cases involving a limited number of grid cells. A necessary condition for
stability will be that the model is stable also in cases involving a few cells.
For non-linear systems of equations, the propagation matrices will vary in
time. For these systems one may set up the space and time discretised system
wn+1 = A(n)wn,
and at each time step analyse the eigenvalues of the time dependent propaga-

234

On a class of ocean model instabilities

tion matrix A(n). The eigenvalues of A(n) should, in some average sense, be on
or inside the unit circle in the complex plane to ensure stability. This may also
be studied for problems involving small numbers of grid cells. The method for
analysing time and space discretised problems indicated here has recently been
applied to investigate two way nesting techniques for the linearised shallow water
equations [137].

Acknowledgements
BjrnOve Heimsund is grateful to The Research Council of Norway (Computational mathematics in applications) for support. Thanks to Tal Ezer, Hernan
Arango, Alexander F. Shchepetkin, Terje O. Espelid, and two anonymous referees
for useful remarks.

Paper F
A two-mesh superconvergence
method with applications for
adaptivity
Bjrn-Ove Heimsund and Xue-Cheng Tai
Abstract
A two-mesh superconvergent gradient recovery mechanism for elliptic equations
is presented. The method first computes the gradient over a fine mesh and then
project it to a coarser mesh. This projected gradient has superconvergence properties for general unstructured meshes. The difference between the computed and
projected gradient is used as the error indicator in refining a mesh adaptively. This
new superconvergence mesh refinement technique is easy to implement and can
be used for a large class of problems. Numerical experiments for smooth and singular elliptic problems given in this work show the efficiency of this technique.
Comparisons with a classical mesh adaptivity method is also given here to show
the advantages.

Accepted for publication in AMS Contemporary Mathematics

F.1 Introduction

F.1

237

Introduction

In recent years, adaptive algorithms for finite element approximation have been
extensively investigated. When producing the mesh, different indicators could be
used to refine it [63, 107, 199, 282, 178, 277, 56, 55, 143, 144]. One of the popular
indicators is the superconvergence indicator. The well-known ZZ [282] method
has been intensively tested and studied for different kind of applications. Recently,
we have extended the original ZZ method to a method called MZZ (modified ZZ)
method [138]. For the MZZ method, it normally works with two meshes. One
is called the master mesh which is coarser and one is called the slave mesh
which is produced by refining the master mesh. The finite element solution is
computed on the finer slave mesh. After the computation of the finite element
solution, we project the gradient or the solution itself to a finite element space of
equal or higher order on the master coarser mesh. It is proved that such a procedure gives a solution having superconvergence properties [266, 267]. Contrary
to many other superconvergence methods, this procedure does not need to impose
uniformity or geometrical symmetry on the mesh. Thus, we use such an indicator
to do mesh refinement, and we do not need to impose any conditions on how to
refine the mesh. Compared with other adaptive mesh methods [178, 179, 278,
280, 186, 185, 276, 184, 183, 182, 100, 277, 66, 62, 68, 54, 56, 53, 55, 32, 143],
our method is easy to implement and can be used for a large class of problems.

F.2

The two-mesh superconvergence method

The method can be used for different kind of applications. We shall consider the
model problem:
d
X

j (aij i u) +

d
X

bi i u + cu = f

i=1

i,j=1

in Rd ,

(F.1)

where a = (aij )di,j=1 is the coefficient tensor which is symmetric, bounded, and
uniformly positive definite in a polygonal domain Rd with measurable entries
aij = aij (x). The other coefficients b = (bi (x))di=1 and c = c(x) are assumed to
ensure a uniqueness of solutions for (F.1) such that u H 1 () and u = g on .
The method is also correct for other kind of boundary conditions.
Let
a(u, v) =

d Z
X
i,j=1

aij i uj v dx +

d Z
X
i=1

Z
bi i uv dx +

cuv dx

238

A two-mesh superconvergence method for adaptivity

be a bilinear form defined in H 1 () H 1 (). A weak form for the problem (F.1)
seeks a function u H 1 () such that u = g on and
a(u, v) = (f, v)

v H01 ().

(F.2)

Here we have assumed that the boundary data g H 1/2 ().


As we have mentioned, we need two meshes for our superconvergence
method. We denote T the coarser master finite element partition of . This
partition will be used for the post-processing process. The slave finer mesh Th is
always produced by refining the coarser mesh T . This mesh will be used to solve
the finite element solution. Corresponding to the two meshes, we also need to two
finite element spaces Sh and L . The space Sh is a scalar finite element space of
piecewise polynomials of a given order k 1 over the partition Th . The space L
is a vector finite element space of piecewise polynomials of order r 0 over the
partition T . Normally, L has higher order, i.e. r k. For problem (F.1), we
shall require that Sh H 1 (). The finite element solution of (F.2) is a function
uh = uh (x) in the space Sh H 1 () such that uh (x) = gh (x) for all x and
a(uh , v) = (f, v)

v Sh0 .

(F.3)

Here Sh0 = H01 () Sh and gh is a certain approximation of the Dirichlet boundary


data g.
The project space L can be continuous or discontinuous. Our numerical experiments indicate that the computational cost associated with continuous projection spaces is rather cheap and the recovered solution is normally better than
discontinuous projection spaces. Assume that L C (). Our analysis [138]
indicates that bigger will give better accuracy for the recovered solution. However, it is not practical to construct finite elements space with 1. Normally, we
have = 0.
Once the finite element solution is obtained, we shall do a L2 projection for
the flux qh = auh to L . The projected flux Q qh L is the solution of

a1 Q qh , = (uh , ) ,

L .

(F.4)

Let q = au. Under some conditions, the projected flux has superconvergence.
In order to get superconvergence, we need to assume that there is a fixed real
number 1 < s k + 1. The dual problem and the projection finite element space
should have some properties. First, the dual problem of (F.2) has H s -regularity in
the sense that for any given f H s2 (), the following problem
a(v, w) = (f, v)

v H01 ()

F.2 The two-mesh superconvergence method


has a unique solution w H01 () H s () such that


w

kwks +
na 3 Ckfks2 ,
s ,

239

(F.5)

w
= (aw) n denotes the
where n is the unit outward normal vector of and n
a
normal component of the flux variable on the boundary for the dual solution
w. Second, the projection space L need to have the following regularity

L [H s1 ()]d .

(F.6)

Under those conditions, it can be proved that the projected flux has the following superconvergence property [138]:
kq Q qh k0 C r+1 kqkr+1, + C(h 1 )s1 ku uh k1 .

(F.7)

Since s > 1, h 1 1, we have kq Q qh k0 kuuh k1 if we choose the polynomial order r sufficiently high and the mesh size sufficiently coarse. Accordingly,
we have
kQ qh qh k0
= kq qh k0 ,
which means that we could use kQ qh qh k as an indicator to do mesh refinement.

F.2.1 Mesh adaptivity


In our computations, only the coarse mesh T will be produced adaptively. The
fine mesh Th is always a refinement of T . We also take Sh and L to be linear
finite element spaces over Th and T respectively. Each element of T is refined
into four equal elements to get the mesh Th . Thus, we only need to store the
information of mesh T in the computer, the mesh Th is known from the mesh
structure of T .
For a given tolerance , we want to adaptively produce the meshes such that
kQ qh qh k .

(F.8)

To this end, for a given coarse mesh L , we compute the maximum value of
the left hand side of Equation (F.8) over all the coarse mesh elements:
= max kQ qh qh k0,K .
KT

We choose a parameter (0, 1). For a given coarse mesh element K T , we


refine K if
kQ qh qh k0,K .

240

A two-mesh superconvergence method for adaptivity

The refinement process is stopped if either (F.8) is satisfied, the memory limit has
been reached, or the change of the computed solution in the energy norm is less
than a given tolerance. More formally, this indicator function will be refered to as
EG (K) = kQ qh qh k0,K ,
meaning that the element K T is refined if
EG (K) max EG (e).
eT

In order to show the efficiency of our error indicator, we shall compare the
mesh produced by our method with the jump error indicator of [107, 154]. The
error indicator of [107, 154] is based on the homogeneous Dirichlet problem for
u = f,
where one can show that a computed finite element solution of the flux qh satisfied
the error estimate

kqh qk0,K

v
u

2
u X
u
h
,
|i |2
khfkK + t
ni
i K

where [ ] is the jump on the edge i of K h and and are mesh independent
constants. When the conductivity is non-constant, and we solve for
(au) = f,
the error indicator
EJ (K) = khfkK +

s X
i K


2
|i|2 ni qh

(F.9)

is used instead. This method does not need to work on two meshes simultaneously.
As earlier, an element K h is then refined if
EJ (K) max EJ (e).
eTh

In the numerical experiments, the indicators EG (K) and EJ (K) will be compared.

F.3 Numerical results

F.3

241

Numerical results

To illustrate the performance of our flux recovery method and its use in mesh
adaption, we will compare our indicator EG (K) with the standard mesh adaption technique of [107, 154] given by EJ (K). Comparisons with other recovery
schemes has been provided in [138] and will not be repeated here.
The function value errors are computed by
v
uX Z
u
kuh uk0 = t
(uh u)2 dx dy.
(F.10)
KTh K

and the gradient error is computed by


v
uX Z h
2 i
u
dx dy.
((uh )x ux )2 + (uh )y uy
kuh uk0 = t
KTh

(F.11)

The integration over each element is computed by a sixth order quadrature rule.
Furthermore, we set = = 0.15 in Equation (F.9). The tolerance is chosen
experimentally on a case by case basis to ensure a smooth refinement, typically
= 0.4.
In the error-plots, we always use logarithmic axis in which the x-axis is the
degrees of freedom (DoF) of the triangulation, while the y-axis is either the function error or the gradient error. A solid line will denote the error computed on the
mesh produced by EG , dashed line is for the error by EJ and the dashed-dotted
line is for the error of the recovered gradient Q qh .
We shall also measure the rate of convergence of the gradients. The convergence rate is evaluated using the following formula:
order =

log10 error(k) log10 error(0)


,
log10 DoF(k) log10 DoF(0)

(F.12)

in which error(0) is the first computational gradient error, while error(k) is the
last. DoF(0) and DoF(k) are the corresponding degrees of freedoms.

F.3.1 Smooth problem


As a reference case, we will show the performance of the indicators applied to the
smooth problem
u = 2 2 sin(x) sin(y),

in = (0, 1) (0, 1),

242

A two-mesh superconvergence method for adaptivity

10

10

10

10

10

10

10

10

10

10

10

10

10

(a) Function error (F.10)

10

10

10

(b) Gradient error (F.11)

Figure F.1: Error plots for the smooth problem in F.3.1, The rate of convergence
of the recovered gradient using EG is 0.85, while the rate is 0.53 using EG .
with zero Dirichlet boundary conditions. The solution to this problem is obviously
u = sin(x) sin(y).
The functional error and gradient errors are shown in Figure F.1, and the meshes
produced by the two indicator functions are presented in Figure F.2. The convergence rate for the recovered gradient using EG is clearly better than those
recovered by EJ , while the functional error is generally smaller for the mesh
produced by the EG indicator.
It is also instructive to investigate the error distribution of the gradients on the
different meshes. In Figures F.3-F.4 we have plotted the pointwise error
q
2
2
uhx ux + uhy uy
in which uhx and uhy are the computed solution derivatives. From the figure, it is
clear that the recovered gradient on the mesh produced by the EG indicator is
overall smaller, while the EJ mesh has a gradient with larger errors near the four
corners.

F.3.2 Discontinuous coefficients


A problem which has a singularity due to a discontinuous conductivity coefficient
is
(a(x, y)u) = 0, in = (0, 1) (0, 1),
(F.13)

F.3 Numerical results

243

0.9

0.9

0.8

0.8

0.7

0.7

0.6

0.6

0.5

0.5

0.4

0.4

0.3

0.3

0.2

0.2

0.1
0
0

0.1

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

(a) Mesh produced by EG

0
0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

(b) Mesh produced by EJ

Figure F.2: Meshes for the smooth problem of F.3.1. The left mesh has 2513
nodes and a gradient error of 9.309 103 , while the right has 2589 nodes with a
gradient error of 5.7 102

(a) EG gradient error distribution

(b) EJ gradient error distribution

Figure F.3: The distribution of the gradient errors on some coarser meshes produced by the two indicators for the smooth problem of F.3.1. The EG mesh has
1153 nodes with largest pointwise error of 0.060982, while the EJ mesh has 1337
nodes and largest error of 0.144607. Dark areas have large errors, while light
areas have small errors.

244

A two-mesh superconvergence method for adaptivity

0.14

0.14

0.12

0.12

0.1

0.1

0.08

0.08

0.06

0.06

0.04

0.04

0.02

0.02

0
1

0
1
0.8

1
0.6

0.8
0.6

0.4

0.4

0.2

0.8

1
0.6

0.8
0.4

0.2

0.2
0

0.6

0.4
0.2
0

(a) EG gradient error distribution

(b) EJ gradient error distribution

Figure F.4: 3D plot of the same data as in Figure F.3. Note that the recovered
gradient is piecewise linear and globally continuous, while the gradient produced
by the linear finite element method is piecewise constant.
where a(x, y) is scalar-valued and equal 1 in the first and third quadrants, and
equal R in the other two quadrants. The solution in polar coordinates is u(r, ) =
r (), and is due to [162]. It is

 
 

cos

cos

2
2

cos () cos (( + ) ) ,
() =

cos () cos(( ) ) ,

 

cos 2 cos 3
2 ,

3
2

< 2
<
< 3
2
< 2

in which the numbers , , and R satisfy the conditions


 
R = tan 2 cot () ,
1
R = tan () cot () ,  
R = tan () cot 2 ,

(F.14)

along with the inequalities


0 <

< 2,
max(0, ) < 2 < min(, ),
max(0, ) < 2 < min(, 2 ).

(F.15)

F.3 Numerical results

245

10

10

10

10

10

10

10

(a) Function error (F.10)

10

10

10

(b) Gradient error (F.11)

Figure F.5: Plots of the errors (F.11) for the problem in F.3.2 with = 0.5. The
convergence rate for the gradients is slower here, and it is clear that the EJ indicator does a rather better job than the EG indicator. The rate of convergence of the
EJ indicator is 0.55, while EG has a convergence rate of 0.36.

For a given value of , Equations (F.14)-(F.15) can be solved for , and , and in
[162] several solutions were provided where = /4. Here we will consider

= 0.5,
R 5.8284271247461907,
2.3561944901923448.

(F.16)

Adaptive finite element methods for this problem has been studied [63, 199], however their goal was reducing the error kuh uk0 and not necessarily the error in the
gradient. Applying the two indicator functions to this problem gives the computational results in Figure F.5 along with the produced meshes in Figure F.6. We see
that the function errors are steadily decreased, while the reduction of the gradient
error is slower. Also, the classical indicator EJ consistently outperforms the EG
indicator, even for the gradient.
Figure F.7 shows the gradient error distributions as was shown for the smooth
problem in F.3.1. While the EJ indicator has a small error in large portions of
the domain, however it has a larger error at origin. As the mesh is further refined,
the error in the origin is dominating.

246

A two-mesh superconvergence method for adaptivity

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0.2

0.2

0.4

0.4

0.6

0.6

0.8

0.8

1
1

0.8

0.6

0.4

0.2

0.2

0.4

0.6

0.8

(a) Mesh produced by EG

1
1

0.8

0.6

0.4

0.2

0.2

0.4

0.6

0.8

(b) Mesh produced by EJ

Figure F.6: Meshes produced by the EG and EJ error indicators used on the problem in F.3.2 with = 0.5. The meshes for the other values of do not differ
much. The EG mesh is with 7993 nodes and a gradient error of 8.196 102 after
the gradient recovery has been applied. The indicator EJ produced a mesh with
8715 degrees of freedom and a gradient error of 4.325 102 .

(a) EG gradient error distribution

(b) EJ gradient error distribution

Figure F.7: Gradient error distribution plot for the discontinuous coefficient problem of F.3.2. The left mesh has 909 nodes with maximum error of 2.105516 and
the right mesh has 826 nodes and a max error equal 4.148048.

F.3 Numerical results

247

10

10

10

10

10

10

10

10

10

10

10

(a) Function error (F.10)

10

10

10

(b) Gradient error (F.11)

Figure F.8: Plots of the errors for the corner singularity problem in F.3.3 with
= 4/3, giving the meshes in Figure F.9. The rate of convergence of the recovered
gradient is 0.84, while the rate of convergence of the gradient produced by the
standard adaption is 0.51.

F.3.3 Corner singularity


The next problem has a singularity induced by a reentrant corner, and is
u = 0,
u = u0 ,
in which


=

in ,
on ,

(r, ) : 0 < r < 1, 0 < < 2


.

The exact solution is u(r, ) = r sin () and the boundary data u0 is taken to be
consistent with the analytical solution. It is easy to see that the regularity of the
solution depends directly on . We will consider the case with = 4/3 and = 2/3,
u H 2 for the former choice, but not for the latter.
The meshes produced for the case of = 4/3 are shown in Figure F.9, and
plots of the error (F.11) are in Figure F.8. This can be compared with the case
of = 2/3 given in Figures F.10-F.11. In both cases we see that the recovered
gradient is clearly superconvergent, while the function errors comparing the two
meshes are comparable to one another.
We note that this particular corner singularity problem has been studied earlier
in [106] where an indicator function based on the jumps of the gradient across the
edges of each element was used. The tests here show clearly that our method can

248

A two-mesh superconvergence method for adaptivity

0.9

0.9

0.8

0.8

0.7

0.7

0.6

0.6

0.5

0.5

0.4

0.4

0.3

0.3

0.2

0.2

0.1

0.1

0
0.8

0.6

0.4

0.2

0.2

0.4

0.6

0.8

0
0.8

0.6

(a) Mesh produced by EG

0.4

0.2

0.2

0.4

0.6

0.8

(b) Mesh produced by EJ

Figure F.9: Meshes produced by the mesh adaptivity schemes applied to the corner
singularity problem of F.3.3 with = 4/3. The mesh given by EG is shown with
2144 nodes and has a recovered gradient error of 2.967 103 while the mesh
produced with EJ is with 1925 nodes and an error of 9.313 103 .

10

10

10

10

10

10

10

(a) Function error (F.10)

10

10

10

10

10

(b) Gradient error (F.11)

Figure F.10: Plots of the errors for the corner singularity problem in F.3.3 with
= 4/3, with the associated meshes of Figure F.11. Here the convergence rate
of the recovered gradient using EG is 1.12, and it has a rate of 0.69 for the EJ
indicator.

F.3 Numerical results

249

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0.2

0.2

0.4

0.4

0.6

0.6

0.8

0.8

1
1

0.8

0.6

0.4

0.2

0.2

0.4

0.6

(a) Mesh produced by EG

0.8

1
1

0.8

0.6

0.4

0.2

0.2

0.4

0.6

0.8

(b) Mesh produced by EJ

Figure F.11: Meshes produced by the mesh adaptivity schemes applied to the
corner singularity problem of F.3.3 with = 2/3. Left mesh has 1297 nodes
with a recovered gradient error of 1.03 102 and the right has 1473 nodes and a
gradient error of 2.127 102 .
handle this problem better than the EJ indicator, especially with regards to the
accuracy of the recovered gradient.

F.3.4 Mixed Dirichlet/Neumann problem


The last problem we shall consider is the mixed Dirichlet/Neumann problem, also
studied in [106]. It is
u = 0, in ,
u
on 1 ,
n = 0,
u = u0 , on 2 ,
where
= {(r, ) : 0 < r < 1, 0 < < } ,
1 = {(r, ) : 0 < r 1, = } ,
2 = \ 1 .


The analytical solution is u(r, ) = r sin 2 and the Dirichlet boundary data is
chosen consistent with this solution. Note that u is singular as |x|, |y| 0.
Error-plots are given in Figure F.12 followed by the corresponding meshes in
Figure F.13. Again, note the superconvergence behaviour of the recovered gradient. This time around, the EJ indicator produces the smallest functional error, but
the recovered gradient given by EG is an order of magnitude more accurate than
the regular gradient.

250

A two-mesh superconvergence method for adaptivity

10

10

10

10

10

10

10

10

10

10

10

(a) Function error (F.10)

10

(b) Gradient error (F.11)

Figure F.12: Plots of the errors for the mixed Dirichlet/Neumann problem in
F.3.4. The rate of convergence for the recovered gradient for EG is 1.12, while
EJ indicator has a rate of 0.72.

0.9

0.9

0.8

0.8

0.7

0.7

0.6

0.6

0.5

0.5

0.4

0.4

0.3

0.3

0.2

0.2

0.1

0.1

0
1

0.8

0.6

0.4

0.2

0.2

0.4

0.6

(a) Mesh produced by EG

0.8

0
1

0.8

0.6

0.4

0.2

0.2

0.4

0.6

0.8

(b) Mesh produced by EJ

Figure F.13: Meshes produced by the different mesh adaptivity schemes applied to
the mixed Dirichlet/Neumann problem of F.3.4. The mesh for the EG indicator is
shown with 1447 nodes and a projected gradient error of 7.671 103 while the EJ
produced mesh has 1565 degrees of freedom and a gradient error of 2.078 102 .

F.4 Concluding remarks

F.4

251

Concluding remarks

Mesh adaptivity has been widely studied in the literature. We have proposed a
two-mesh superconvergence method which provides both a much more accurate
gradient than classical methods, and offers an associated mesh refinement indicator.
The advantages of this scheme is that it can be easily used for a wide range
of problems. The implementation for different kind of problems is easier than
other approaches. Our numerical experiments show that the method works well
for smooth problems as well as for problems with singularities.

Paper G
High performance numerical
libraries in Java
Bjrn-Ove Heimsund
Abstract
In this paper we outline a set of numerical libraries for high performance scientific
computing. The libraries are implemented in the Java programming language,
which offers modern features such as clean object orientation, platform independence, garbage collection and more. Java has been regarded as unsuitable for high
computing due to its conceived low performance. In this article we show how our
design has resulted in a set of libraries which match the performance of native
numerical libraries implemented in Fortran and C++, while offering better ease of
use.

Draft manuscript

G.1 Introduction

G.1

255

Introduction

In the last few years there have been several attempts at creating structured, extensible and user-friendly numerical software to supplement the large existing base of
Fortran codes. Fortran 77 has been a preferred language for numerical calculations due to its high-performance compilers and intrinsic support for matrices
and mathematical functions, however with the increasing complexity of application and library codes, it has become necessary with more sophisticated language
constructs in order to better manage this complexity.
One of the chief developments have been in object oriented (OO) programming, which is based on the principles of object polymorphism and reuse. Polymorphism allows the use of one interface but with multiple different implementations, and reuse is a mechanism to extend an object to either change its intrinsic
behaviour or to implement other interfaces. For example, we could create a matrix interface, and define dense and banded matrix objects. An end-user can thus
use either storage type without changing the application code. Other examples
lie in iterative system solvers, where the user can easily change between different
algorithms. Furthermore, by extending the dense matrix, we can create a custom
algorithm implementation without creating a new matrix structure from scratch.
We could for example implement the Strassen matrix/matrix product for easy performance comparisons.
Another, perhaps more important development, is the use of automatic garbage
collectors. In traditional programming, programmers are forced to perform both
resource allocation and deallocation themselves, and there are numerous pitfalls
when deallocating resources, such as freeing memory twice or forgetting to free
causing a memory leak. Studies [42] have shown that 30% to 40% of the development time is spent on storage management, and this estimate does not include the
time used debugging memory related errors. Garbage collectors circumvent the
whole issue by moving resource deallocation away from the programmer into the
runtime environment. Modern garbage collectors are also highly concurrent and
can approach the performance of manual memory management [43, 283].
Also there has been an increased focus on portability of both codes and compiled applications. While standards such as POSIX (Portable Operating System
Interface) provides a common interface across a wide range of computers, it does
not expose much of the advanced functionality available, and consequently there
are many applications which uses more functions than are found in POSIX and
are not easily ported. Furthermore, commercial software is seldom delivered with
source codes, and may often require much time before it can be made available
on new architectures. It has therefore been an increased interest in binary compatibility by the use of a virtual machine (VM), which provides a rich and uniform
interface to underlying operating systems. In the last decade many VMs have

256

High performance numerical libraries in Java


Cluster

DMT

I
6 @

MPP

SMT

I
6 @

Java VM

MVIO

MT

I
6 @

JLAPACK

NNI
Machine
dependent

LAPACK
6

BLAS
Figure G.1: Hierarchy of the main components presented in this paper with their
interdependencies. Components in italic are external.
gained prominence, examples being Sun Java and Microsoft .Net. Of these, the
Java VM is available on almost every combination of hardware and operating system.
In this paper we will describe a set of numerical libraries which is built using
the Java programming language. Java is a modern language offering the full benefits of objects oriented programming while providing features such as garbage
collection and complete binary portability. Preliminary versions of Java gained
a reputation for slow execution speed, however newer releases have added advanced techniques in order to provide highly optimized performance. The most
prominent improvements have been the addition of just-in-time (JIT) compilers
which recompiles Java code into optimized assembly code fully on the fly without
compromising portability. A JIT compiler has several advantages over a traditional compiler, one of which is that it can examine program execution and detect performance bottlenecks (hotspots) as they occur, and then apply aggressive
optimization selectively. Another advantage is code elimination of checks and
synchronisations that can be proven redundant during execution (that is, a given
bounds check will never fail or that there will never be any contentions on a given
synchronisation lock). A JIT compiler can also perform other types of optimisations, for example function call inlining and automatic data-alignment.
Our aim is to show that the performance of our numerical libraries are competitive with the best numerical libraries currently available, while offering substantial benefits due to garbage collection and portability. We will first describe the
basic libraries, then add and extend functionality such that we end up with a set
of objects suitable for solving large scale numerical problems on supercomputers
and clusters of computers, see Figure G.1. During the course of this development, we will compare against basic libraries such as BLAS [172, 97, 96, 94, 95],

G.2 Low level functionality

257

Sparskit [230], and more sophisticated libraries such as [99, 98, 24, 241]. Both
performance and functionality will be compared.

G.2

Low level functionality

One of the most significant developments in numerical linear algebra software


has been the Basic Linear Algebra Subroutines (BLAS) and the Linear Algebra
Package (LAPACK) which builds on BLAS, both written in traditional Fortran 77.
The BLAS contains fundamental operations for working with matrices and vectors, such as addition, multiplication, rank-updates and triangular solvers, and this
functionality is available for several types of matrices, including general dense,
banded, symmetrical and others.
Since the BLAS has become an important part of many numerical libraries,
vendors have created highly tuned versions which can exploit hardware specific
details which that cannot be done from typical application codes. Such optimized
BLAS can achieve theoretical optimal performance, especially for demanding operations as matrix/matrix multiplications.
LAPACK [17] builds on BLAS by adding many common matrix solvers
and factorisations, including LU and Cholesky solvers, least squares methods
and eigenvalue and singular value decompositions. The algorithms used by the
LAPACK subroutines are typically the state of the art, and most other matrix software uses portions of it. LAPACKs performance depends on a tuned BLAS; using
a standard BLAS can often reduce performance by an order of magnitude.
As both BLAS and LAPACK are large bodies of code (over 500,000 lines
of code in hundreds of interdependent functions), it is impractical to create a replacement in Java, instead we need a means to call such codes from the Java environment. The Java Native Interface [180] (JNI) provides a portable mechanism
to accomplish this, whereby one creates a Java method signature without implementation, then provide an implementation of that method in a separate C source
file. See Figure G.2 for an example on calling the BLAS 2-norm subroutine.
A complete interface to the whole of BLAS and LAPACK libraries has been
implemented in the Native Numerical Interface (NNI). It calls the native BLAS
and LAPACK, and if a high-performance BLAS has been installed, both the BLAS
and LAPACK routines available to Java will be fast.
Since NNI uses JNI, it will have to be recompiled on every target platform,
as JNI relies on compiled C codes. This can compromise the portability of Java,
and as an alternative to NNI there is the JLAPACK [238] libraries. JLAPACK is
a machine translation of the whole set of BLAS and LAPACK into Java using the
tool f2j (Fortran to Java). As JLAPACK cannot take advantage of an optimized
BLAS (it uses the reference Netlib BLAS), it is typically slower than NNI, espe-

258

High performance numerical libraries in Java

Java code
public class BLAS {
public static native double norm2(int N, double[] X, int incX);
// ...
}
C code
JNIEXPORT jdouble JNICALL Java_BLAS_norm2
(JNIEnv *env, jclass clazz, jint N, jdoubleArray X, jint incX) {
jdouble *Xl = NULL, ret = 0;
Xl = (*env)->GetPrimitiveArrayCritical(env, X, NULL);
ret = cblas_dnrm2(N, Xl, incX);
(*env)->ReleasePrimitiveArrayCritical(env, X, Xl, JNI_ABORT);
return ret;
}

Figure G.2: Example of calling the BLAS subroutine nrm2 from Java. Notice that
the method in the Java source has the keyword native and does not include an
implementation. A corresponding C code does the call to the C BLAS. The use of
the GetPrimitiveArrayCritical function returns a pointer to the Java array X,
and this pointer is then passed on to the BLAS subroutine.
cially for larger problems. Despite this, JLAPACK is useful for prototyping, small
dense matrix problems, and also for certain large-scale problems involving large
numbers of small matrices or vectors.
We will now illustrate the performance differences between the libraries we
have discussed. BLAS has three types of operations, those acting on vectors (level
1), those acting on matrices and vectors (level 2) and operations solely for matrices
(level 3). We test the performance of one routine from each level, comparing
different implementations.
From level 1 we chose daxpy which is the vector update operation
y = x + y,

x, y Rn ,

R.

The level 2 routine is matrix/vector multiplication operation dgemv


y = Ax + y,

A : Rn 7 Rn ,

x, y Rn ,

, R.

Lastly, we will also test with the classical level 3 routine dgemm for dense matrix/matrix multiplication:
C = AB + C,

A, B, C : Rn 7 Rn ,

, R.

The measure of performance is the number of floating points per second (flops),
and by assuming that addition and multiplication consumes one flop each and
disregarding memory performance issues, the three BLAS routines require the

G.3 Dense and structured sparse matrices

259

following number of flops:


daxpy : 2n
dgemv : 2(n + 1)n
dgemm : 2(n + 1)n2

We compare a plain C version, a plain Java version, JLAPACK, a native optimized


BLAS and also the corresponding NNI version. The tests were run on an AMD
Opteron 1.8GHz machine, and the results are shown in Figure G.3-G.5 for each
of the three BLAS operations.
Several conclusions may be drawn from the results. The first is that the number of megaflops increases when going from low-level BLAS level 1 to BLAS
levels 2 and particularly 3. This is because the relative number of floating point
operations to memory operations increase as we operate on larger chunks of data,
and tuned dgemm implementations can attain the theoretical maximum number of
flops possible on a given computer due to this [92].
Furthermore, we see that there is little difference between the BLAS versions and the pure Java/C versions for daxpy, however the difference increases
alot when considering dgemv and especially dgemm. The performance difference
between Java and C is negligible, both for the pure versions and for the BLAS
versions.
Lastly, we see that JLAPACK is somewhat slower than the pure Java version.
This may be caused by its somewhat simple Fortran translated kernels which have
not been optimized.
As a consequence of these experiments, we have used the level 2 and 3 of
BLAS for the types of matrices supported by BLAS and LAPACK, but the BLAS
level 1 vector operations have been implemented in pure Java. In this way we get
the highest possible performance.

G.3

Dense and structured sparse matrices

BLAS and LAPACK has similar functions for a range of different types of
matrices. For instance, LAPACK offers optimized equation solvers for Ax = b
depending on whether A is symmetrical, positive definite, just symmetrical, triangular, or general. These algebraic properties help LAPACK chose more efficient
algorithms. Furthermore, LAPACK can also exploit some types of sparsity, such
as banded, triangularity, and tridiagonal matrices, all of which help save memory.
When using BLAS and LAPACK directly, the user must handle all the details
of matrix-storage, which can be non-trivial for some of the sparse formats, and

260

High performance numerical libraries in Java

1800
BLAS
C
NNI
Java
JLAPACK

1600
1400
1200
1000
800
600
400
200
0
0

2000

4000

6000

8000

10000

Figure G.3: Millions of floating point operations per second in computing y =


x + y as a function of the vector length.

1500
BLAS
C
NNI
Java
JLAPACK
1000

500

0
0

200

400

600

800

1000

Figure G.4: Millions of floating point operations per second in performing y =


Ax + y as a function of matrix/vector size.

G.3 Dense and structured sparse matrices

261

4000
3500
3000
BLAS
C
NNI
Java
JLAPACK

2500
2000
1500
1000
500
0
0

100

200

300

400

500

Figure G.5: Millions of floating point operations per second in performing dense
matrix/matrix multiplication C = AB + C as function of the matrix size.

must also find the most optimal method for the given combination of algebraic
properties and storage format.
It is obvious that we can create a set of matrices with a common interface that
masks all the differences. These matrices should encapsulate matrix properties
such as symmetry or triangularity, but also space-savings such as bandedness and
packed layouts. In good object-oriented style, we will try to maximise reuse by
designing a hierarchy.
In what follows, we will outline the Matrix Toolkit (MT) which provides a
convenient high-level Java interface to BLAS and LAPACK. It has generic BLAS
and LAPACK interfaces, and upon startup a check is made to see if NNI is available for use. If so, its used, and otherwise JLAPACK is used instead. This ensures high performance without compromising portability. The overhead of an
extra function call to NNI or JLAPACK is negligible, see Figure G.6.

G.3.1 Matrix structures in BLAS and LAPACK


In what follows is a brief overview of the different matrices in BLAS and
LAPACK. The discussion is adapted from [17].

262

High performance numerical libraries in Java

4000
3500
3000
2500
2000
1500
1000
500
0
0

BLAS
MT
100

200

300

400

500

Figure G.6: Performance comparison of calling dgemm from C BLAS and from
the Matrix Toolkit. The differences are negligible.
Conventional storage

The conventional dense storage is based on the Fortran matrix construct. Since
Fortran 77 lacks the means to create user-defined structures and classes, it provides
a small set of useful high-level mathematical types, such as complex numbers and
matrices. A Fortran matrix can be accessed as follows:
DOUBLE PRECISION A(M, N)
DO J=1:N
DO I=1:M
A(I,J) = ...
END DO
END DO

Matrices are laid out column major, that is, columns follow each other sequentially
in memory. For example, the above code fragment has an inner loop moving down
one column at the time, which is the optimal way to traverse a Fortran matrix.
Since computers only operate on linear memory segments (vectors), A(I,J)
is actually accessed as
Aij = A [i + jn],

A : Rm 7 Rn .

In our Java codes, we create one long array of double precision numbers and access them as column major constructs. This results in full Fortran interoperability.

G.3 Dense and structured sparse matrices

a11

Matrix
a12 a13 a14
a22 a23 a24
a33 a34
a44

263
Array

a11 a12 a22 a13 a23 a33 a14 a24 a34 a44
|{z} | {z } | {z }

Figure G.7: Upper triangular matrix stored in the packed format.

Matrix

a11
a21 a22

a31 a32 a33

a41 a42 a43 a44

Array
a11 a21 a31 a41 a22 a32 a42 a33 a43 a44
| {z } | {z } |{z}

Figure G.8: Lower triangular matrix stored in the packed format.


Special matrices such as symmetrical and triangular can use this conventional
Fortran storage too. They access only either the lower or upper triangular portion
and ignore the other part which is assumed to be either symmetrical or zero. This
other part is never actually accessed, so it may in fact be different from the assumptions without causing any ill effects. A unit triangular matrix also assume
the main diagonal to be one, but it is never accessed.
Packed matrices

It is clear that a more economical storage is possible for symmetrical and triangular matrices. By packing the relevant triangle by columns into a one dimensional vector we get the packed matrix format. For upper triangular/symmetrical
matrices, A(I,J) is accessed as (see Figure G.7)


(j + 1)j
Aij = A i +
, A : Rn 7 Rn ,
2
and lower triangular/symmetrical matrices are accessed by (see Figure G.8)


(j 1)j
, A : Rn 7 Rn .
Aij = A i + jn
2
Unit triangular matrices can also be stored in the packed format, but the main
diagonal is still stored, however it is not accessed.

264

High performance numerical libraries in Java

a11
a21

a31

Banded matrix
a12
a22 a23
a32 a33 a34
a42 a43 a44 a45
a53 a54 a55

a11

a21

a31

Fortran matrix
a12
a22
a32
a42

a23 a34 a45


a33 a44 a55

a43 a54
a53

Array
a11 a21 a31 a12 a22 a32 a42 a23 a33 a43 a53 a34 a44 a54 a45 a55
| {z } | {z } | {z } | {z } | {z }
Figure G.9: Matrix stored in the banded format. It has one upper diagonal (ku = 1)
and two lower diagonals (kl = 2). denotes entries that are not accessed but still
stored. The linear array shows how the matrix is laid out in memory.
Banded matrices

An n n matrix with kl n lower diagonals and ku n upper diagonals can


be stored very compactly in a banded format. Columns of the banded matrix are
stored continuously in a vector, and the matrix is accessed by
Aij = A [ku + i j + j(kl + ku + 1)] ,

A : Rn 7 Rn .

Figure G.9 provides an example.


When storing lower triangular or symmetrical matrices, ku can be set equal
zero as the upper part is never accessed. Likewise, kl = 0 for upper triangular/symmetrical banded matrices. However, the main diagonal is always stored,
so unit triangular matrices are not any cheaper.
Tridiagonal matrices

As tridiagonal matrices often occur in applications, its beneficial to store them


efficiently. While the banded format is a possibility (with kl = ku = 1), it is easier
and more efficient to use a linear array for each diagonal.
Assuming we have an n n matrix, the main diagonal is stored in a vector
of length n and the two off-diagonals are stored in vectors of length n 1. For
symmetrical matrices, we only have to store one off-diagonal.

G.3.2 Matrix hierarchy


To best reflect the structures in BLAS and LAPACK, while also obtaining generic
interfaces and maximum reuse, we design a hierarchy given in Figure G.10. At

G.3 Dense and structured sparse matrices

265

Matrix
AbstractMatrix
AbstractDenseMatrix
DenseMatrix
TriangDenseMatrix
SymmDenseMatrix

AbstractPackMatrix
TriangPackMatrix
SymmPackMatrix

AbstractBandMatrix
BandMatrix
TriangBandMatrix
SymmBandMatrix

Figure G.10: The main parts of the matrix hierarchy. The topmost Matrix is an
abstract interface which specifies the available methods, but not their implementation. AbstractMatrix implements the methods in Matrix by means of generic
algorithms using iterators and elemental access operations. However it does not
specify the storage layout. Extending AbstractMatrix is a number of abstract
structures which specify actual storage layout. Finally, concrete matrices add
BLAS and LAPACK algorithms to override and complement the algorithms in
AbstractMatrix while using the specified storage layout
the top is the generic Matrix interface. It specifies methods which retrieve entries,
sets entries, multiplies the matrix and so forth.
AbstractMatrix implements the Matrix interface, but does not specify how the
matrix is stored. Instead, is provides implementations of most of the methods
specified by means of elemental access operations and iterators. This allows subclasses to only implement those methods which they can perform efficiently, while
delegating the rest to AbstractMatrix.
Further extending the AbstractMatrix are a set of matrices which specify the
storage layout and elementary access operations, but not the algorithms themselves. These provide get and set methods for working with the entries of the
matrix. So whether the matrix is banded, packed or dense,
double Matrix.get(int i, int j);

always retrieves Aij , reliving the user of the sometimes complicated underlying
details.
LAPACK and BLAS algorithms are chosen by specific matrices such as
DenseMatrix or TriangPackMatrix. For instance, direct solvers are different for
these formats, the former must use a general LU with partial pivoting, while the
latter can be solved for without factorising. As always, the underlying differences
are masked away, and one can solve Ax = b by calling
Vector Matrix.solve(Vector b, Vector x);

266

High performance numerical libraries in Java


void scale(Matrix A, double alpha) {
for (int i=0; i<A.numRows(); ++i)
for (int j=0; j<A.numColumns(); ++j)
A.set(i, j, alpha * A.get(i, j));
}

void scale(Matrix A, double alpha) {


for (MatrixEntry e : A)
e.set(alpha * e.get());
}

Figure G.11: Two implementations of a matrix scaling operations A A, one


using elemental access operations, the other using an iterator. Note the use of the
for-each loop.
The corresponding LAPACK calls are more involved, and are different for each
matrix type.
Figure G.10 only shows a small part of the whole hierarchy. Omitted are the
tridiagonal matrices, many intermediary classes and further specialised classes.
However the figure does give a representative overview nevertheless.
Matrix iterators

An important part of the matrix implementations are the matrix iterators. A matrix
iterator passes over all the stored matrix entries, returning one entry at a time,
however the details of the traversal are matrix specific.
Iterators are very useful in constructing generic algorithms [247, 248], and
have been used with much success in constructing high performance generic matrix operations [241]. Furthermore, sparsity is naturally exploited by iterators since
they only traverse the relevant parts of the matrix.
Figure G.11 shows two implementations of the matrix scaling operation
A A,
one using get and set operations, the other using an iterator. There are many
differences, firstly the syntax for the iterator is very clear and concise, resulting
in more maintainable code. Secondly, the iterator correctly exploits any kind of
sparsity while the elemental operations loop over the whole of the matrix. Thirdly,
and most important, iterators can be much faster when traversing very sparse
structures such as narrow banded and tridiagonal matrices.
The matrix entry returned at each step in the iterator is typically reused for
higher performance. Also, it contains current row and column indices as well.
Vectors

Vectors are supported in a similar way as matrices. There is a general Vector


interface which specifies the applicable methods, an AbstractVector with generic
implementations, and a DenseVector which is specialised for a dense array.

G.3 Dense and structured sparse matrices

267

double[][] data = {{1,2,3},{4,5,6},{7,8,10}};


Matrix A = new DenseMatrix(data);
Vector b = Matrices.random(3);
Vector x = A.solve(b, b.copy());
Vector r = A.multAdd(x, -1, b, b.copy());
double rnorm = r.norm(Vector.Norm.Infinity);

Figure G.12: Code snippet for solving a linear 3 3 system and computing the
final residual. An LU decomposition is used from LAPACK when calling the
solve method
Due to the results in Figure G.3, DenseVector does not call BLAS for any
of its operations, instead they are all implemented in pure Java. We have not
registered any performance degradation due to this in practical applications.
Finally, vectors also have iterators which works in the same way as that of the
matrices, with the only difference that they only traverse one dimension. While an
iterator is not so useful for a dense vector, they are much used for sparse vectors
introduced later on.

G.3.3 Matrix factorisations


In addition to typical matrix algebraic operations such as additions and multiplications, MT also offers a number of matrix factorisations from LAPACK. The factorisations include general LU with partial pivoting, Cholesky for symmetrical
positive definite systems, QR factorisations and eigenvalue and singular value
computations.
Most of their details are given in the LAPACK manual [17], here we will
only comment on some notable usability features. Each type of factorisation is
a distinct class, and the factorisation is created by calling its constructor with
a suitable matrix. In LAPACK, the factorisation always overwrites the passed
matrix, but this may not always be desirable. Therefore, a flag can be passed
to the constructor specifying whether or not to overwrite the passed matrix (the
default is not to overwrite). A copy is made if no overwriting is to be done.
Also, the interface is simplified compared to the LAPACK interface. Context
information is handled transparently, and the optimal algorithm to use is chosen
at runtime. For instance, a symmetrical matrix would use a faster eigenvalue
computation than for a general dense matrix.
We close this section on the Matrix Toolkit with an illustration on how to solve
a linear system, see Figure G.12. The function solve is fully polymorphic and
calls the most optimal factorisation, and does not overwrite the calling matrix.
The residual is computed with the norm.

268

G.4

High performance numerical libraries in Java

Unstructured sparse matrices

For application codes involving the discretisation of partial differential equations,


unstructured sparse matrices arise naturally. Their bandwidth often varies so much
that the simple banded storage offered in LAPACK would require a too large
band to be practical. Instead, special matrix structures are necessary to efficiently
handle such cases.
Additionally, special solvers are required for these matrices. Since sparse
matrices can be very large, the dense solvers in LAPACK are unsuitable since they
would consume too much memory and do not exploit sparsity. Instead, iterative
solvers based on Krylov subspaces are very suitable for general sparse matrices
[25]. A Krylov method only accesses the matrix through a matrix/vector product,
and it is possible to code very efficient multiplication algorithms for most types of
sparse matrices.
In what follows, we outline an extension of MT, the Sparse Matrix Toolkit
(SMT) which includes many sparse matrix structures, a large selection of iterative
solvers and some common preconditioners. SMT uses the same interfaces as MT,
so the complex details of handling a sparse matrix are entirely hidden from the
user.

G.4.1 Sparse structures


There is a very large number of different sparse matrix structures. Here we will
describe the most common and our implementation of them. See [26, 25, 41] for
more in-depth details.
Common for all the sparse matrices is that elemental access can be very slow.
To alleviate this, the matrices implement very efficient iterators which are then
used in the construction of many of the generic algorithms. Performance critical
codes such as matrix/vector products do not use iterators, but are handcoded for
optimal efficiency.
Coordinate storage

The most simple matrix is the coordinate format. It uses three arrays, rows,
columns and entries, each of the same length, see Figure G.13. When retrieving
an entry from the matrix, the arrays must be search linearly for a match which can
be very slow. For the converse case of adding a new entry, a search must first be
done to see if the entry is already in the matrix. If it is not there, the new entry can
be appended to the end of the three arrays, possibly after performing a reallocation. It is clear that the coordinate format does not offer very good performance,
and is it also not the most memory efficient.

G.4 Unstructured sparse matrices

a11
a21

a31

Matrix
a13
a22
a24
a33
a44

269

Arrays

entries a11
columns 0
rows
0

a13
1
0

a21
0
1

a22
1
1

a24
3
1

a33
0
2

a33
2
2

a44
3
3

a33
0
5

a33
2

a44
3
7

Figure G.13: Storage of a matrix in the coordinate format.

a11
a21

a31

Matrix
a13
a22
a24
a33
a44

Arrays

entries a11
columns 0
rowP
0

a13
1

a21
0
2

a22
1

a24
3

Figure G.14: Storage of a matrix in the compressed row format. The rowP array
is compressed, its formatting used here is for simplicity.
Compressed storage

The compressed storage is the most common layout found in practice. For the row
oriented type, three arrays are used, one for the column indices, one for the entries
and a third which stores the offsets of each row, see Figure G.14. Retrieval can
now be done more efficiently. First the correct row is found by looking at rowP,
then the column indices of that row is searched. By keeping the column indices
within a row sorted, the performance is further increased.
When adding an entry, we also do an initial search to see it it is already there.
But if the entry is not found the resulting reallocation can be very expensive as
the column and entry arrays must be recreated. However, by preallocating reserve
storage this expensive operation may not be necessary.
Vector storage

A third popular format is to store each row of the matrix as a sparse vector. The
advantage of this is that reallocation is cheap, only the relevant row needs to be
allocated again and not the whole matrix. A minor drawback is that the extra layer
of abstraction may reduce performance slightly.
The Sparse Matrix Toolkit provides two sparse vectors, one which stores indices and entries in sorted arrays much like the coordinate storage, and another
backed by a custom high performance hashmap. The hashmap is often faster for

270

High performance numerical libraries in Java

y=0
for i = 1 : nnz
y(rows(i)) = y(rows(i)) + entries(i) x(columns(i))

for i = 1 : m
y(i) = 0
for j = rowP(i) : rowP(i + 1)
y(i) = y(i) + entries(j) x(columns(j))

for i = 1 : m
y(i) = row(i)T x
Figure G.15: Pseudocodes for the matrix/vector product y = Ax for the three
sparse matrix formats. The topmost is the coordinate, second is the compressed,
and the last is the vector storage.
frequent retrieval operations, but has some extra overhead in terms of memory
usage compared to the sparse array based vector.

Comments and comparisons

When the sparsity pattern is known, a compressed format is usually the fastest in
both assembly and when performing matrix/vector products. However, for changing memory requirements, a flexible vector format can be preferable instead.
Matrix/vector product pseudocodes are given in Figure G.15. Comparing them
we see that the coordinate format traverses the vectors x and y unordered. The
compressed has ordered traversal of y which may help performance. Most interesting is the vector storage, where the product can be expressed as a simple vector
innerproduct where one of the vectors is sparse.
To compare the performance of the matrices, we run a simple application
which firsts inserts entries into an empty matrix and times how long it takes to
insert all the entries. While this test can be run without preallocation, this is very
slow so we instead preallocate sufficient storage for all entries. Next, the numerical values of the matrix are zeroed (but the index structure is preserved) and
the entries are reinserted. This measures any benefit of structural reuse. Lastly,
matrix/vector performance is also measured. See Table G.1.

G.4 Unstructured sparse matrices

Compressed
Vector
Hash
Sparse

271

Initialisation Assembly y = Ax
9.62
6.6589
265
34.467
13.979

7.619
7.378

88
198

Table G.1: Performance of the sparse matrices for assembly and in matrix/vector
products. Initialisation refers to creating the matrix entries (indices and numerical
values) starting from a preallocated storage. Assembly refers to just inserting the
numerical values into an existing sparse matrix. These two tests are reported in
seconds, while the last test is in millions of floating point operations per second.
The matrix is a 100.000 100.000 matrix with 100 nonzero entries on every row.

G.4.2 Iterative solvers and preconditioners


The library provides the iterative solvers given in [25]. This includes
Biconjugate gradients (BiCG)
BiCG stabilised (BiCGstab)
Conjugate gradients (CG)
CG squared (CGS)
Chebyshev
Generalised minimal residuals (GMRES)
Iterative refinement (IR)
Quasi minimal residuals (QMR)
All these solvers can be preconditioned, and the following common preconditioners are provided:
Diagonal (Jacobi)
Symmetric Successive Overrelaxation (SSOR)
Incomplete LU without fill-in (ILU)
Incomplete Cholesky without fill-in (ICC)

272

High performance numerical libraries in Java


r0 = b Ax0
for i = 1, 2, . . .
check convergence
solve Mzi1 = ri1
T
i1 = ri1
zi1
if i = 1
p1 = z0
else
i1 = i1 /i2
pi = zi1 + i pi1
end if
qi = Api
i = i1 /pTi qi
xi = xi1 + i pi
ri = ri1 i qi
end

A.multAdd(-1, x, b, r);
for (iter.setFirst();
!iter.converged(r, x); iter.next()) {
M.apply(r, z);
rho = r.dot(z);
if (iter.isFirst())
p.set(z);
else {
beta = rho / rho_1;
p.add(z, beta);
}
A.mult(p, q);
alpha = rho / p.dot(q);
x.add(alpha, p);
r.add(-alpha, q);
rho_1 = rho;
}

Figure G.16: The mathematical PCG algorithm and its implementation in SMT.

Figure G.16 compares the mathematical description of the preconditioned CG


(PCG) against the SMT Java implementation. Notable features of the library implementation is the separation of the iteration state (monitoring and convergence)
into a separate iter object [241] and the relative brevity of the implementation.
While the lack of operator overloading makes the code somewhat less intuitive
than that in [98], it is still rather close to the mathematical formulation.
A more important metric for users is the performance. We measure the number of iterations per second when running the PCG with a diagonal preconditioner for some sparse example matrices. Our library is compared against the
C++ Sparselib [98] which implements high quality sparse matrix structures and algorithms. Table G.2 shows the performance of these two codes against each other.
SMT is in general faster than Sparselib, and the authors of Sparselib provided a
comparison in [98] showing that it performed as well as the Fortran Sparskit [230].
In the sparse matrix/vector multiplications, we have the option to use threads
to parallelise the products. The resulting speedup is also given in the table. All
runs were performed on a machine with two AMD Opteron 2.4GHz processors
using Sun Java 5 and GCC 3.3.

G.5 Distributed computing

273

SMT
Sparselib 1 thread 2 threads
MEMPLUS, 126150 entries
326
573
0%
FIDAPM37, 765944 entries
173
199
61%
FIDAP011, 1091362 entries
109
120
62%
S3DKQ4M2, 4427725 entries

29
67%
Table G.2: Number of iterations per second for the PCG method. The C++
Sparselib is compared against the Java SMT library for some selected matrices
from [44]. The speedup of the threaded SMT is also shown in percent. Matrix
S3DKQ4M2 was not compatible with Sparselib.

G.5

Distributed computing

While SMT provides a small degree of parallelization, it may be insufficient for


grand scale applications involving the solution of huge multidimensional differential equations with several millions of degrees of freedom. For such problems,
clusters and supercomputers are a necessity, and the best way to program these
machines is to use a message passing system.
In message passing programming there are separately running processes
which communicate by sending messages between one another. The message may
be computational data or instructions on how to proceed in the execution. Since
these messages can be transported over both internal interconnects and across networks, a message passing program can easily be adapted to most clusters, providing a large potential scalability.
The prevalent standard is MPI [194], but there are also other popular alternatives [251]. In the last few years, Java implementations and wrappers to these have
been constructed, but their performance has often been lackluster [122]. Fortunately, a high-performance network aware communication library, NIO, has been
added to Java recently. Most typical I/O mechanisms are stream oriented, but NIO
is explictly blocked with low-level buffers and a I/O channels. Initial experience
with NIO for message passing has been very promising [223].
In this section we describe the Java Message Passing Package (MPP), which
implements a common subset of the MPI 1.2 standard. Its performance is compared against other MPI implementations. Then we describe a fully parallelised
sparse matrix library, the Distributed Matrix Toolkit (DMT), and examine its parallel scalability on some problems.

274

High performance numerical libraries in Java

Switch
 

 
 
 

6
?

6 KA A
A A
A A
? A AU

Node1 Node2 Node3 Node4


(a) Directly connected by switch

Node1

- Node2

6
?

Node3

?
- Node4

(b) Cartesian grid

Figure G.17: Two typical scenarios for connecting compute nodes. The switch
based network allows direct communication between nodes, while the grid requires node to pass information along using tagged messages.

G.5.1 Message passing package


In designing a message passing package for Java, we chose to target fully connected clusters where each node can communicate with any other node through a
switch (Figure G.17(a)). This results in a number of simplifications over the more
classical MPI. In the following, we use a Communicator object for handling all
the message passing details.
Point to point communications

The sending and receiving primitives in MPP are


void Communicator.send(byte[] data, int offset, int length, int peer);
void Communicator.recv(byte[] data, int offset, int length, int peer);

These send or receive to/from the given peer node. Similar functions are provided
for all primitive arrays (char, short, int, long, float and double).
The most important difference from MPI is the lack of a message tag. Messages needs to be tagged when nodes cannot communicate directly with one another, but must send messages in stages. For example, consider the case of Figure G.17(b). If node 1 is to send a messages to node 4, it can be routed either
through node 2 or 3. Now, if multiple distinct messages are sent from 1 to 4,
each message must have a unique tag to distinguish them from one another. The
point-to-point nature of Figure G.17(a), guarantees that messages are delivered in
the correct order and consequently does not need any tags.
A further simplification we can make lies in the communication of large datasets. In the grid case, suppose node 1 is to send a large array of data to node 4
in a single message. The intermediary node (say 2) has two options: wait until

G.5 Distributed computing

275

node 4 is ready to receive and then start streaming data from 1 and to 4, or locally store the data from node 1, passing it on to 4 when 4 is ready. For the fully
connected network, sends do not need to wait until matching receives have been
posted. Instead sends are processed immediately and the underlying operating
system handles all the buffering details.
As our implementation is rather simple, we will show the core send and receive
methods as implemented. The code for send is as follows:
void send(byte[] data, int offset, int length, int peer) {
while (length > 0) {
// Determine how many bytes to write
int cLength = Math.min(length, outputBuffer.capacity());
// Fill buffer with data from current offset
outputBuffer.clear();
outputBuffer.put(data, offset, cLength);
// Write the buffer to the channel
int num = cLength;
outputBuffer.flip();
while (num > 0)
num -= outputChannel[peer].write(outputBuffer);
// Advance offsets
offset += cLength;
length -= cLength;
}
}

Some comments are in order. outputBuffer is a java.nio.ByteBuffer which


holds a byte array mapped to an operating system buffer. Thus outputBuffer
allows an easy and efficient means to transfer data between the array data and
the underlying operating system. So the above code puts as much data into the
buffer as possible. Next, the buffer is written out to a channel. The channel is a
high performance network socket for sending blocks of data, and we use it to send
to the given peer. Finally, the offsets into data are advance, and the process is
repeated until no more data is to be sent.
The code for the receive operation is very similar; first the corresponding channel reads data into a buffer, and the buffer then outputs its contents into a Java
array. It is as follows:
void recv(byte[] data, int offset, int length, int peer) {
while (length > 0) {
// Determine how many bytes to read
int cLength = Math.min(length, inputBuffer.capacity());
// Read data from corresponding channel
int num = cLength;

276

High performance numerical libraries in Java

inputBuffer.clear();
while (num > 0)
num -= inputChannel[peer].read(inputBuffer);
// Get data from the buffer
inputBuffer.flip();
inputBuffer.get(data, offset, cLength);
// Advance
offset += cLength;
length -= cLength;
}
}

Asynchronous operations

Asynchronous sends and receives runs the operations in the background, freeing
the application to perform other tasks simultaneous. This is useful for effectively
implementing collective operations and for overlapping computation with communication in numerical codes. The signatures for these sends and receives are:
Future Communicator.isend(byte[] data, int offset, int length, int peer);
Future Communicator.irecv(byte[] data, int offset, int length, int peer);

To wait for an operation to finish, an await method may be called:


void Communicator.await(Future f);

The asynchronous operations are implemented by running a synchronous operation in a separate thread. For efficiency, a pool of worker threads are used to run
all the asynchronous tasks. Since new threads are recycled rather than recreated,
this results in a very low latency.
Collective operations

The most common collective operations found in MPI 1.2 are implemented. The
list includes
fast cyclic barriers,
one-to-all broadcast,
all-to-one reductions and prefix scans,
all-to-one gathers and vectorised gathers,
one-to-all scatters and vectorised scatters,
all-to-all personalised communications.
The operations are coded for the fully connected network model, and we will not
provide details, see [127] instead.

G.5 Distributed computing

277

10

10

10

MPP
LAM

10

10

10

10

10

Figure G.18: Bandwidth performance comparison between MPP and LAM. The
curve plotted is the number of bytes transmitted per second from one node to
another as function of the array size.
Performance comparisons

To verify the performance of MPP we compare it against LAM (Local Area Multicomputer, a freely available MPI library). Here we will test bandwidth and
latency characteristics for the point to point operations.
Bandwidth is measured at how many bytes per second one node is able to
send to another node using a synchronous transfer mode. Latency is how many
milliseconds it takes before a message arrives at the other node. For both tests, we
vary the number of bytes transmitted. Results are plotted in Figures G.18-G.19 for
a switched gigabit network. It is clear that MPP offers performance competitive
with LAM.
Instead of performing microbenchmarks for the collective and asynchronous
operations, we will instead introduce the Distributed Matrix Toolkit (DMT) and
run large scale benchmarks using it. DMT uses many of the asynchronous and
collective operations, and it is therefore suitable as a benchmark tool.

G.5.2 Distributed matrices


The Distributed Matrix Toolkit is a simple extension of SMT to a message passing
paradigm. In designing a distributed matrix structure, we have three goals:
1. Full data parallelization.
2. Maximise communication/computation overlap.
3. Create parallel preconditioners.

278

High performance numerical libraries in Java


4

10

10

10

10

MPP
LAM
2

10

10

10

Figure G.19: Latency performance comparison between MPP and LAM. Plots the
number of transactions per millisecond as a function of the array size.
A1
A2
A3
A4
(a) Row-wise partition

B1

A1
A2
B3
B4

A 1

B2

A 2
A 3

A3

A 4

A4

(b) Block diagonal


partition

(c) Overlapping preconditioner matrix

Figure G.20: Partition of the global system matrix A onto four nodes. Ai and
Bi are local to node i. Note that Bi is exactly zero in the block Ai occupies. A
corresponding overlapping preconditioner matrix is easy to construct.
Our aim is to use the Krylov subspace iterative methods, and we thus consider
computing the matrix/vector product
y = Ax,

A : RN 7 RN ,

x, y RN ,

(G.1)

efficiently. To enable data parallelization, we partition the global system matrix A


row-wise such that each node stores a continuous subset of the global rows, see
Figure G.20(a). Consider one such subset, Ai : Rn 7 RN and partition the vector
x into xi Rn where n < N is the local size. Since Ai maps from the local subset

G.5 Distributed computing

279

1. Compute z = Bi xi for a z RN .
2. Send the non-zero entries of z to the relevant nodes.
3. Compute yi = Ai xi .
4. Add into yi the values of z computed from other nodes
Figure G.21: Algorithm for computing y = Ax with the distributed matrix format
given in Figure G.20(b). The communication started in step 2 can be overlapped
with the computation in step 3.
to the global set, Equation (G.1) can be rewritten locally as
+

y = Ai xi .

(G.2)

The symbol = means that locally computed results are added into the global vector. There are two problems with this simple decomposition, we have to have
access to the whole of y on every node, and we cannot overlap computations and
communications. To overcome these issues, we split Ai into a block diagonal part
Ai and a remainder Bi :
Ai = Ai + Bi ,

Ai : Rn 7 Rn ,

Bi : Rn 7 RN .

Is is assumed Bi = 0 where it overlaps Ai , see Figure G.20(b). Rewriting Equation (G.2) to use this decomposition gives
yi = Ai xi ,

y = Bi xi ,

yi Rn .

(G.3)

Now all communications have been isolated in the computation Bi xi . In most


partial differential equation discretizations, many of the entries fall close to the
main diagonal, and the matrix becomes sparser further away from it. This means
that Bi can be very sparse. The entries of y affected by Bi xi correspond to the
columns of Bi which contains non-zero entries, and since Bi usually have few
such columns, consequently few entries of y are affected. Thus not much work is
needed in computing Bi xi and there is also not a large communication overhead
either. An algorithm based on this is given in Figure G.21.
The third goal was to be able to construct efficient parallel preconditioners.
The prevalent choice is domain decomposition methods [243] which includes
one-level, two-level, multilevel (multigrid) and Schur-complement methods. The
chosen decomposition makes the construction of both non-overlapping and overlapping one-level preconditioners easy to construct. The former is trivial, while

280

High performance numerical libraries in Java


2 nodes
4 nodes
FIDAPM37, 765944 entries
286 (72%) 350 (44%)
FIDAP011, 1091362 entries
228 (95%) 288 (60%)
S3DKQ4M2, 4427725 entries 58 (100%) 98 (85%)

Table G.3: Number of iterations per second on average for the PCG method when
using the Distributed Matrix Toolkit (DMT). Percentage of optimal scalability,
compared to Table G.2, is given in parenthesis.
the latter requires that we create an augmented matrix A i which contains some
rows and columns of Bj , j = {i 1, i, i + 1} and Aj , j = {i 1, i + 1}. See Figure G.20(c). Sequential subdomain solvers such as ILU or ICC can then be applied.
To test DMT, we solve the preconditioned Conjugate Gradients (PCG) problem again as we did for SMT. The only difference is that we now use distributed
memory matrices and vectors. Results are given in Table G.3.
Finally, we mention that our design has been inspired by [259, 24], however it
is somewhat more flexible since we allow any kind of subdomain matrices Ai and
Bi , not just a compressed row storage.

G.6

Summary

We have presented a comprehensive set of numerical libraries for scientific computing in Java. Performance figures shows it to be competitive with other libraries
while offering many of the benefits of Java such as object orientation and a comprehensive runtime environment. Also, all the software presented in this paper is
freely available at
http://www.math.uib.no/bjornoh/mtj

Only the most noteworthy features of the libraries have been presented herein.
Some omissions are column-oriented sparse formats, sparse eigenvalue solvers,
solvers for saddle point problems and nested parallelization (combining SMT and
DMT for multilevel parallelization).
There are some limitations of our implementation. The first is the almost
exclusive use of double precision as underlying numerical format. Complex numbers and extended precision are not supported, but may be if proper template
mechanisms are added into Java. Another limitation is that Java arrays are addressed with signed 32bit integers. Since an array has only positive entries, this
limits us to arrays of length 231 . While this may seem like a lot, dense matrices

G.6 Summary

281

are stored
as one long array, and a quadratic n n matrix can then not exceed
p
n = 231 = 46341, which is not a particularly large number. It is hoped that true
64bit addressing is added before this becomes problematic.

Bibliography
[1] J. Aarnes. Efficient domain decomposition methods for elliptic problems
in heterogeneous porous media. To appear in Computing and Visualization
in Science.
[2] J. Aarnes. On the use of a mixed multiscale finite element method for
greater flexibility and increased speed or improved accuracy in reservoir simulation. SIAM Journal on Multiscale Modeling and Simulation,
2(3):421439, 2004.
[3] J. Aarnes and T. Y. Hou. Multiscale domain decomposition methods for
elliptic problems with high aspect ratios. Acta Mathematica Applicatae
Sinica, 18(1):6376, 2002.
[4] I. Aavatsmark. Mathematische Einfuhrung in die Thermodynamik der
Gemische. Akademie Verlag, 1995.
[5] I. Aavatsmark. Bevarelsesmetoder for elliptiske differensialligninger. Technical report, Institutt for Informatikk, University of Bergen, 2004.
[6] I. Aavatsmark. Bevarelsesmetoder for hyperbolske differensialligninger.
Technical report, Institutt for Informatikk, University of Bergen, 2004.
[7] I. Aavatsmark. Mehrpunktflussverfahren. Technical report, Institut fur
Wasserbau, Universitat Stuttgart, 2004.
[8] I. Aavatsmark. Interpretation of a two-point flux stencil for skew parallelogram grids. Submitted to Computational Geosciences, 2005.
[9] I. Aavatsmark, T. Barkve, . Be, and T. Mannseth. Discretization on unstructured grids for inhomogeneous, anisotropic media. Part I: Derivation
of the methods. SIAM Journal on Scientific Computing, 19:17001716,
1998.

284

Bibliography

[10] I. Aavatsmark, T. Barkve, . Be, and T. Mannseth. Discretization on unstructured grids for inhomogeneous, anisotropic media. Part II: Discussion
and numerical results. SIAM Journal on Scientific Computing, 19:1717
1736, 1998.
[11] I. Aavatsmark, E. Reiso, and R. Teigland. Control-volume discretization
method for quadrilateral grids with faults and local refinement. Computational Geosciences, 5(1):123, 2001.

[12] G. Acs,
S. Doleschall, and E. Farkas. General purpose compositional
model. SPE, 10515, 1985.
[13] M. Al-Lawatia, R. C. Sharpley, and H. Wang. Second order Characteristic
Methods for Advection-Diffusion Equations and Comparisons to Other
Schemes. Advances in Water Resources, 22(7):741768, 1999.
[14] M. B. Allen. Collocation Techniques for Modeling Compositional Flows in
Oil Reservoirs, volume 6 of Lecture Notes in Engineering. Springer, 1984.
[15] M. B. Allen, G. A. Behie, and J. A. Trangenstein. Multiphase Flow in
Porous Media, volume 34 of Lecture Notes in Engineering. Springer, 1988.
[16] L. Ambrosio and H. M. Soner. Level set approach to mean curvature flow in
arbitrary codimension. Journal on Differential Geometry, 43(4):693737,
1996.
[17] E. Anderson, Z. Bai, C. Bischof, S. Blackford, J. Demmel, J. Dongarra,
J. D. Croz, A. Greenbaum, S. Hammarling, A. McKenney, and D. Sorensen.
LAPACK Users Guide. SIAM, third edition, 1999.
[18] A. Arakawa. Computational Design for Long-Term Numerical Integration
of the Equations of Fluid Motion: Two-Dimensional Incompressible Flow.
Part I. Journal of Computational Physics, 1:119143, 1966.
[19] A. Arakawa and V. Lamb. A Potential Enstrophy and Energy Conserving
Scheme for the Shallow Water Equations. Monthly Weather Review,
109:1836, 1981.
[20] D. Arnold. An interior penalty finite element method with discontinuous
elements. SIAM Journal on Numerical Analysis, 19(4):742760, 1982.
[21] D. N. Arnold, F. Brezzi, B. Cockburn, and L. D. Marini. Unified analysis
of discontinuous Galerkin methods for elliptic problems. SIAM Journal on
Numerical Analysis, 39(5):17491779, 2002.

Bibliography

285

[22] A. K. Ask, H. K. Dahle, K. H. Karlsen, and H. F. Nordhaug. A local


streamline Eulerian-Lagrangian method for two-phase flow. In Computational Methods in Water Resources, volume 2, 2000.
[23] K. Aziz and A. Settari. Petroleum Reservoir Simulation. Applied Science
Publishers, 1979.
[24] S. Balay, W. D. Gropp, L. C. McInnes, and B. F. Smith. PETSc Users
Manual. Technical Report ANL-95/11 - Revision 2.1.5, Argonne National
Laboratory, 2003.
[25] R. Barrett, M. Berry, T. F. Chan, J. Demmel, J. Donato, J. Dongarra, V. Eijkhout, R. Pozo, C. Romine, and H. van der Vorst. Templates for the Solution
of Linear Systems: Building Blocks for Iterative Methods. SIAM, second
edition, 1994.
[26] Basic Linear Algebra Subprograms Technical Forum. Basic Linear Algebra
Subprograms Technical Forum Standard, 2001.
[27] F. Bassi and S. Rebay. A high-order accurate discontinuous finite element
method for the numerical solution of the compressible Navier-Stokes equations. Journal of Computational Physics, 131:267279, 1997.
[28] P. Bastian. Numerical computation of multiphase flows in porous media. Habilitationsschrift vorlegt an der Technischen Fakultat der ChristianAlbrechts-Universitat Kiel, June 1999.
[29] R. P. Batycky. A Three-Dimensional Two-Phase Field Scale Streamline
Simulator. PhD thesis, Stanford University, January 1997.
[30] J. Bear. Dynamics of Fluids in Porous Media. Elsevier, 1972.
[31] J. Bear and Y. Bachmat. Macroscopic modelling of transport phenomena
in porous media. 2: applications to mass, momentum and energy transport.
Transport in Porous Media, 1:221269, 1986.
[32] R. Becker and R. Rannacher. An optimal control approach to a posteriori
error estimation in finite element methods. Acta Numerica, 10:1102, 2001.
[33] A. Beckmann and D. Haidvogel. Numerical simulation of flow around a
tall isolated seamount. Part I: Problem formulation and model accuracy.
Journal of Physical Oceanography, 23:17361753, 1993.
[34] M. Benzi, G. H. Golub, and J. Liesen. Numerical solution of saddle point
problems, volume 14 of Acta Numerica. Cambridge University Press, 2005.

286

Bibliography

[35] J. Berntsen. Internal pressure errors in sigma-coordinate ocean models.


Journal of Atmospheric and Oceanic Technology, 19(9):14031414, 2002.
[36] J. Berntsen. Users guide for a modesplit -coordinate numerical ocean
model. Technical report, Department of Mathematics, University of Bergen, 2004.
[37] D. P. Bertsekas. Nonlinear Programming. Athena Scientific, 1995.
[38] P. Binning and M. A. Celia. A finite volume Eulerian-Lagrangian localized adjoint method for solution of the contaminant transport equations
in two-dimensional multiphase flow systems. Water Resources Research,
32(1):103114, 1996.
[39] P. Binning and M. A. Celia. Practical implementation of the fractional flow
approach to multiphase flow simulation. Advances in Water Resources,
22(5):461478, 1999.
[40] P. Binning and M. A. Celia. A forward particle tracking EulerianLagrangian Localized Adjoint Method for solution of the contaminant
transport equation in three dimensions. Advances in Water Resources,
25(2):147157, 2002.
[41] L. S. Blackford, J. Demmel, J. Dongarra, I. Duff, S. Hammarling, G. Henry,
M. Heroux, L. Kaufman, A. Lumsdaine, A. Petitet, R. Pozo, K. Remington,
and R. C. Whaley. An Updated Set of Basic Linear Algebra Subprograms
(BLAS). ACM TOMS, 28(2):135151, June 2002.
[42] H. Bohem. Advantages and Disadvantages of Conservative Garbage Collection. Technical report, Hewlett-Packard, 2004.
[43] H. Bohem, A. J. Demers, and S. Shenker. Mostly Parallel Garbage Collection. In Proceedings of the ACM SIGPLAN 91 Conference on Programming Language Design and Implementation, pages 157164, 1991.
[44] R. F. Boisvert, R. Pozo, and K. A. Remington. The Matrix Market Formats:
Initial Design. Technical report, Applied and Computational Mathematics
Division, NIST, 1996.
[45] F. A. Bornemann and P. Deuflhard. The cascadic multigrid method for
elliptic problems. Numerische Mathematik, 75(2):135152, 1996.
[46] D. Braess. Finite elements. Cambridge University Press, 1997.

Bibliography

287

[47] S. C. Brenner and L. R. Scott. The Mathematical Theory of Finite Element


Methods. Springer, 1996.
[48] F. Brezzi, M. Manzini, D. Marini, P. Pietra, and A. Russo. Discontinous
finite elements for diffusion problems. In Atti Convegno in onore di F. Brioschi, pages 197217. Instituto Lombardo, Accademia di Scienze e Lettere,
Milan, Italy, 1997.
[49] R. H. Brooks and A. T. Corey. Hydraulic properties of porous media. In
Hydrological Papers, volume 3. Colorado State University, 1964.
[50] A. M. Bruaset, X. Cai, H. P. Langtangen, and A. Tveito. Numerical Solution of PDEs on Parallel Computers Utilizing Sequential Simulators. In
Y. Ishikawa et al., editors, Scientific Computing in Object-Oriented Parallel Environment, volume 1343 of Lecture Notes in Computer Science, pages
161168. Springer, 1997.
[51] S. E. Buckley and M. C. Leverett. Mechanism of fluid displacements in
sands. Transactions of the AIME, 146:107116, 1942.
[52] H. Cao. Development of techniques for general purpose simulators. PhD
thesis, Stanford University, June 2002.
[53] C. Carstensen. Some remarks on the history and future of averaging techniques in a posteriori finite element error analysis. Zeitschrift fur Angewandte Mathematik und Mechanik, 84(1):321, 2004.
[54] C. Carstensen and G. Dolzmann. An a priori error estimate for finite element discretizations in nonlinear elasticity for polyconvex materials under
small loads. Numerische Mathematik, 97(1):6780, 2004.
[55] C. Carstensen and R. Klose. A posteriori finite element error control for
the p-Laplace problem. SIAM Journal on Scientific Computing, 25(3):792
814, 2003.
[56] C. Carstensen and S. A. Sauter. A posteriori error analysis for elliptic
PDEs on domains with complicated structures. Numerische Mathematik,
96(4):691721, 2004.
[57] P. Castillo and D. S. B. Cockburn, I. Perugia. An a priori error analysis
of the Local Discontinuous Galerkin Method for Elliptic Problems. SIAM
Journal on Numerical Analysis, 38(5):16761706, 2000.

288

Bibliography

[58] M. A. Celia, T. F. Russell, I. Herrera, and R. E. Ewing. An Eulerian


Lagrangian localized adjoint method for the advectiondiffusion equation.
Advances in Water Resources, 13:187206, 1990.
[59] M. Chaib. Implicit Molar Mass Formulations in Secondary Oil Migration.
PhD thesis, University of Bergen, 2002.
[60] T. F. Chan and L. A. Vese. A new multiphase level set framework for
image segmentation via the Mumford and Shah model. Technical Report
01-25, Computational and applied mathematics, University of California,
Los Angeles, April 2001.
[61] G. Chavent and J. Jaffre. Mathematical Models and Finite Elements for
Reservoir Simulation. North Holland, 1978.
[62] Z. Chen and S. Dai. Adaptive Galerkin methods with error control for a
dynamical Ginzburg-Landau model in superconductivity. SIAM Journal on
Numerical Analysis, 38(6):19611985, 2001.
[63] Z. Chen and S. Dai. On the efficiency of adaptive finite element methods for elliptic problems with discontinuous coefficients. SIAM Journal on
Scientific Computing, 24(2):443462, 2002.
[64] Z. Chen and R. E. Ewing. Comparison of various formulations of threephase flow in porous media. Journal of Computational Physics, 132:362
373, 1997.
[65] Z. Chen and R. E. Ewing. From single-phase to compositional flow: applicability of mixed finite elements. Transport in Porous Media, 57:225242,
1997.
[66] Z. Chen and J. Feng. An adaptive finite element algorithm with reliable
and efficient error control for linear parabolic problems. Mathematics of
Computation, 73(247):11671193, 2004.
[67] Z. Chen and T. Y. Hou. A mixed multiscale finite element method for elliptic problems with oscillating coefficients. Mathematics of Computation,
72(242):541576, 2002.
[68] Z. Chen and R. H. Nochetto. Residual type a posteriori error estimates for
elliptic obstacle problems. Numerische Mathematik, 84(4):527548, 2000.
[69] B. K. Coats, G. C. Fleming, J. W. Watts, M. Rame, and G. S. Shiralkar. A
generalized wellbore and surface facility model, fully coupled to a reservoir
simulator. SPE, 87913, 2004.

Bibliography

289

[70] K. H. Coats. Use and misuse of reservoir simulation models. SPE, 2367,
1969.
[71] K. H. Coats. Simulation of steamflooding with distillation and solution gas.
SPE, 5015, 1976.
[72] K. H. Coats. A highly implicit steamflood model. SPE, 6105, 1978.
[73] K. H. Coats. Reservoir simulation: State of the art. SPE, 10020, 1982.
[74] B. Cockburn, G. Karniadakis, and C.-W. Shu, editors. Discontinuous
Galerkin Methods. Theory, Computation and Applications, volume 11 of
Lecture Notes in Computational Science and Engineering. Springer, 2000.
[75] B. Cockburn and C.-W. Shu. The local discontinuous Galerkin method for
time-dependent convection-diffusion systems. SIAM Journal on Numerical
Analysis, 35:24402463, 1998.
[76] D. Colton, R. Ewing, and W. Rundell. Inverse Problems in Partial Differential Equations. SIAM, 1992.
[77] Computer Modelling Group. GEM: Advanced Compositional Reservoir
Simulator.
[78] Computer Modelling Group. IMEX: Advanced Oil/Gas Reservoir Simulator.
[79] Computer Modelling Group.
Reservoir Simulator.

STARS: Advanced Process and Thermal

[80] A. R. Conn, N. I. M. Gould, and L. P. L. Toint. LANCELOT, a FORTRAN


package for Large-scale nonlinear optimization (Release A). Number 17 in
Computational Mathematics. Springer, 1992.

[81] R. Courant, K. O. Friedrichs, and H. Lewy. Uber


die partiellen Differenzengleichungen der mathematischen Physik. Mathematische Annalen,
100:3274, 1928.
[82] R. Courant, K. O. Friedrichs, and H. Lewy. On the partial difference equations of mathematical physics. IBM Journal, 11:215234, 1967.
[83] J. D. Douglas and T. Dupont. Interior Penalty Procedures for Elliptic
and Parabolic Galerkin Methods, volume 58 of Lecture Notes in Physics.
Springer, 1976.

290

Bibliography

[84] H. K. Dahle. Adaptive Characteristic Operator Splitting Techniques for


Convection-Dominated Diffusion Problems in One and Two Space Dimensions. PhD thesis, University of Bergen, December 1988.
[85] H. K. Dahle. ELLAM-based Operator-Splitting for Nonlinear AdvectionDiffusion Equations. Technical Report 98, Department of Mathematics,
University of Bergen, June 1995.
[86] H. K. Dahle, R. E. Ewing, and T. F. Russell. EulerianLagrangian localized
adjoint methods for a nonlinear advectiondiffusion equation. Computer
Methods in Applied Mechanics and Engineering, 122:223250, 1995.
[87] G. Dahlquist. 33 years of numerical instability, part 1. BIT, 25:188204,
1985.
[88] L. P. Dake. Fundamentals of Reservoir Engineering. Elsevier Scientific
Publishing Company, 1978.
[89] S. Daniel Conte and C. de Boor. Elementary numerical analysis. McGrawHill, third edition, 1980.
[90] H. Darcy. Les Fontains Publiques de la Ville de Dijon. Victor Dalmont,
Paris, 1856.
[91] S. R. de Groot and P. Mazur. Non-equilibrium thermodynamics. Dover,
1984.
[92] J. W. Demmel. Applied Numerical Linear Algebra. SIAM, 1997.
[93] D. C. Dobson and F. Santosa. An image enhancement technique for electrical impedance tomography. Inverse problems, 10:317334, 1994.
[94] J. Dongarra, J. D. Croz, I. S. Duff, and S. Hammarling. A set of Level 3
Basic Linear Algebra Subprograms. ACM TOMS, 16:117, 1990.
[95] J. Dongarra, J. D. Croz, I. S. Duff, and S. Hammarling. Algorithm 679: A
set of Level 3 Basic Linear Algebra Subprograms. ACM TOMS, 16:1828,
1990.
[96] J. Dongarra, J. D. Croz, S. Hammarling, and R. J. Hanson. Algorithm 656:
An extended set of FORTRAN Basic Linear Algebra Subprograms. ACM
TOMS, 14:1832, 1988.
[97] J. Dongarra, J. D. Croz, S. Hammarling, and R. J. Hanson. An extended set
of FORTRAN Basic Linear Algebra Subprograms. ACM TOMS, 14:117,
1988.

Bibliography

291

[98] J. Dongarra, A. Lumsdaine, R. Pozo, and K. Remington. A Sparse Matrix


Library in C++ for High Performance Architectures. In Proceedings of the
Second Object Oriented Numerics Conference, pages 214218, 1994.
[99] J. Dongarra, R. Pozo, and D. Walker. LAPACK++: A Design Overview of
Object-Oriented Extensions for High Performance Linear Algebra. In Proceedings of Supercomputing 93, pages 162171. IEEE Computer Society
Press, 1993.
[100] L. Du and N. Yan. Gradient recovery type a posteriori error estimate for
finite element approximation on non-uniform meshes. Advances in Computational Mathematics, 14(2):175193, 2001.
[101] L. J. Durlofsky and M. C. H. Chien. Development of a mixed finite element
based compositional reservoir simulator. SPE, 25253, 1993.
[102] G. T. Eigestad, I. Aavatsmark, E. Reiso, and H. Reme. MPFA for faults
with crossing grid lines and zig-zag patterns. In Proceedings of ECMOR
VIII, 2002.
[103] G. T. Eigestad and J. A. Larsen. Numerical modelling of capillary transition
zones. SPE, 64374, 2000.
[104] L. E. Engevik. Forelesninger i Kontinuumsmekanikk. Department of Mathematics, University of Bergen, 1980.
[105] H. W. Engl, M. Hanke, and A. Neubauer. Regularization of Inverse Problems. Kluwer, 1996.
[106] K. Eriksson and C. Johnson. An adaptive finite element method for linear
elliptic problems. Mathematics of Computation, 50(182):361383, 1988.
[107] K. Eriksson and C. Johnson. Adaptive finite element methods for parabolic
problems I: A linear model problem. SIAM Journal on Numerical Analysis,
28:4377, 1991.
[108] M. S. Esepdal, P. Langlo, O. Svareid, E. Gislefoss, and R. Hansen. Heterogeneous reservoir models: Local refinement and effective parameters.
SPE, 21231, 1991.
[109] M. S. Espedal and R. E. Ewing. Characteristic Petrov-Galerkin subdomain
methods for two-phase immiscible flow. Computational Methods in Applied Mechanics and Engineering, 64:113135, 1987.

292

Bibliography

[110] T. Espelid, J. Berntsen, and K. Barthel. Conservation of energy for schemes


applied to the propagation of shallow-water inertia-gravity waves in regions
with varying depth. International Journal for Numerical Methods in Engineering, 49:15211545, 2000.
[111] L. C. Evans. Partial Differential Equations, volume 19 of Graduate Studies
in Mathematics. AMS, 1998.
[112] R. E. Ewing, editor. The Mathematics of Reservoir Simulation, volume 1
of Frontiers in Applied Mathematics. SIAM, 1983.
[113] R. E. Ewing, Z. Chen, and G. Qin. Analysis of a compositional model
for fluid flow in porous media. SIAM Journal on Applied Mathematics,
60:747777, 2000.
[114] R. E. Ewing and H. Wang. A summary of numerical methods for timedependent advection-dominated partial differential equations. Journal of
Computational and Applied Mathematics, 128:423445, 2001.
[115] T. Ezer, H. Arango, and A. Shchepetkin. Developments in terrain-following
ocean models: intercomparisons of numerical aspects. Ocean Modelling,
4:249267, 2002.
[116] A. Firoozabadi. Thermodynamics of Hydrocarbon Reservoirs. McGrawHill, 1999.
[117] R. Fletcher. Practical Methods of Optimization. John Wiley & Sons, 1987.
[118] I. Garrido, G. E. Fladmark, and M. S. Espedal. An improved numerical
simulator for multiphase flow in porous media. International Journal for
Numerical Methods in Fluids, 44(4):447461, 2004.
[119] I. Garrido, E. ian, M. Chaib, G. E. Fladmark, and M. S. Espedal. Implicit treatment of compositional flow. Computational Geosciences, 8:119,
2004.
[120] C. Gear. Numerical Initial Value Problems in Ordinary Differential Equations. Prentice-Hall, 1971.
[121] M. T. V. Genuchten. A closed-form equation for predicting the hydraulic
conductivity of unsaturated soils. Soil Science Society of America Journal,
44:892898, 1980.
[122] V. Getov and M. Philippsen. Java communications for large-scale parallel
computing. Lecture Notes in Computer Science, 2179:3346, 2001.

Bibliography

293

[123] J. Gluyas and R. Swarbrick. Petroleum geoscience. Blackwell publishing,


2004.
[124] G. H. Golub, P. C. Hansen, and D. P. OLeary. Tikhonov regularization and
total least squares. SIAM Journal on Matrix Analysis and Applications,
21(1):185194, 1999.
[125] D. J. Goode. Particle velocity interpolation in block-centred finite difference groundwater flow models. Water Resources Research, 26(5):925940,
1990.
[126] Govier and Aziz. The flow of Complex Mixtures in Pipes. Van Nostrand
Reinhold Company, 1972.
[127] A. Grama, A. Gupta, G. Karypis, and V. Kumar. Introduction to Parallel
Computing. Addison-Wesley, second edition, 2003.
[128] D. H. Griffel. Applied functional analysis. Ellis Horwood, 1985.
[129] J. S. Hadamard. Four Lectures on Mathematics. Columbia University
Press, 1915.
[130] E. Hairer, S. P. Nrsett, and G. Wanner. Solving Ordinary Differential
Equations I, Nonstiff problems. Springer, 1987.
[131] E. Hairer and G. Wanner. Solving Ordinary Differential Equations II, Stiff
and Differential-Algebraic problems. Springer, 1991.
[132] R. Hansen. On the Numerical Solution of Nonlinear Reservoir Flow Models
with Gravity. PhD thesis, University of Bergen, May 1993.
[133] R. Hansen and M. S. Espedal. On the numerical solution of nonlinear flow
models with gravity. International Journal for Numerical Methods in Engineering, 38:20172032, 1995.
[134] M. Hassanizadeh and W. G. Gray. General conservation equations for multiphase systems 2: Mass momentum energy equations. Advances in Water
Resources, 3:2540, 1980.
[135] S. M. Hassanizadeh, M. A. Celia, and H. K. Dahle. Dynamic Effect in the
Capillary Pressure Saturation Relationship and its Impacts on Unsaturated
Flow. Vadose Zone Journal, 1:3857, 2002.
[136] R. W. Healy and T. F. Russell. A Finite-Volume Eulerian-Lagrangian Localized Adjoint Method for Solution of the Advection-Dispersion Equation.
Water Resources Research, 29(7):23992413, 1993.

294

Bibliography

[137] Y. Heggelund and J. Berntsen. A method for analysing nesting techniques


for the linearized shallow water equations. International Journal for Numerical Methods in Fluids, 38:163185, 2002.
[138] B.-O. Heimsund, X.-C. Tai, and J. Wang. Superconvergence for the gradient of finite element approximations by L2 projections. SIAM Journal on
Numerical Analysis, 40(4):12631280, 2002.
[139] R. Helmig. Multiphase Flow and Transport Processes in the Subsurface.
Springer, 1997.
[140] P. Henrici. Discrete Variable Methods in Ordinary Differential Equations.
Wiley, 1962.
[141] M. R. Hestenes. Multiplier and gradient methods. Journal of Optimization
Theory and Applications, 4:303320, 1969.
[142] M. R. Hestenes and E. Stiefel. Methods of conjugate gradients for solving
linear systems. Journal of Research of the National Bureau of Standards,
49:409436, 1952.
[143] V. Heuveline and R. Rannacher. Duality-based adaptivity in the hp-finite
element method. Journal of Numerical Mathematics, 11(2):95113, 2003.
[144] W. Hoffmann, A. H. Schatz, L. B. Wahlbin, and G. Wittum. Asymptotically exact a posteriori estimators for the pointwise gradient error on each
element in irregular meshes. Mathematics of Computation, 70:897909,
2001.
[145] H. Holden and N. H. Risebro. Front tracking for hyperbolic conservation
laws. Springer, 2002.
[146] T. Y. Hou and X.-H. Wu. A multiscale finite element method for elliptic
problems in composite materials and porous media. Journal of Computational Physics, 134:169189, 1997.
[147] T. Y. Hou, X.-H. Wu, and Z. Cai. Convergence of a multiscale finite element
method for elliptic problems with rapidly oscillating coefficients. Mathematics of Computation, 68(227):913943, 1999.
[148] E. L. Isaacson. Global solution of a Riemann problem for a non-strictly
hyperbolic system of conservation laws arising in enhanced oil recovery.
Technical report, The Rockefeller University, New York, 1980.

Bibliography

295

[149] K. Ito, K. Kunisch, and Z. Li. Level-set function approach to an inverse


interface problem. Inverse Problems, 17:12251242, 2001.
[150] J. Jim Douglas and T. F. Russell. Numerical methods for convectiondominated diffusion problems based on combining the method of characteristics with finite element or finite difference procedures. SIAM Journal
on Numerical Analysis, 19(5):871885, 1982.
[151] T. Johansen, A. Tveito, and R. Winther. A Riemann solver for a twophase multicomponent process. SIAM Journal on Scientific Computing,
10(5):846879, 1989.
[152] T. Johansen and R. Winther. The solution of the Riemann problem for a
hyperbolic system of conservation laws modeling polymer flooding. SIAM
Journal on Mathematical Analysis, 19(3):541566, 1988.
[153] T. Johansen and R. Winther. The Riemann problem for multicomponent
polymer flooding. SIAM Journal on Mathematical Analysis, 20(4):908
929, 1989.
[154] C. Johnson. Numerical solution of partial differential equations by the finite
element method. Cambridge University Press, 1987.
[155] B. Joy, G. Steele, J. Gosling, and G. Bracha. Java Language Specification.
Addison-Wesley, third edition, 2005.
[156] R. Juanes and K.-A. Lie. A front-tracking method for efficient simulation
of miscible gas injection processes. SPE, 93298, 2005.
[157] T. Kaarstad. Massively parallel algorithms in reservoir simulation. PhD
thesis, University of Bergen, September 1993.
[158] T. Kaarstad, J. Fryen, P. E. Bjrstad, and M. S. Espedal. A massively
parallel reservoir simulator. SPE, 29139, 1995.
[159] A. S. Kalasnikov. Postroenie obobsc ennyh resenij kvazilinejnyh uravnenij
pervogo porjadka bez uslovija kak predelov resenij paraboliceskih uravnenij s malym parametrom. Doklady Akademii Nauk SSSR, 127:2730,
1959.
[160] K. H. Karlsen and N. H. Risebro. Corrected operator splitting for nonlinear parabolic equations. SIAM Journal on Numerical Analysis, 37(3):980
1003, 2000.

296

Bibliography

[161] C. T. Kelley. Iterative Methods for Linear and Nonlinear Equations,


volume 16 of Frontiers in Applied Mathematics. SIAM, 1995.
[162] R. B. Kellogg. On the Poisson equation with intersecting interface. Applicable Analysis, 4:101129, 1975.
[163] R. P. Kendall, G. O. Morell, D. W. Peaceman, W. J. Silliman, and J. W.
Watts. Development of a multiple application reservoir simulator for use
on a vector computer. SPE, 11483, 1983.
[164] A. Kjsavik, J. Ringen, and S. M. Skjveland. Relative permeability correlation for mixed-wet reservoirs. SPE, 77328, 2002.
[165] R. A. Klausen and R. Winther. Convergence of multi point flux approximations on quadrilateral grids. Technical report, Center for Mathematics in
Applications, University of Oslo, 2005.
[166] H. Kleppe. Reservoir simulation. Stavanger University College, 2004.
[167] H. W. Kuhn and A. W. Tucker. Nonlinear programming. In J. Neyman,
editor, Proceedings of the Second Berkeley Symposium on Mathematical
Statistics and Probability, pages 481492. University of California Press,
1951.
[168] A. Kurganov and E. Tadmor. New high-resolution central schemes for nonlinear conservation laws and convection-diffusion equations. Journal of
Computational Physics, 160:241282, 2000.
[169] P. Langlo. Macrodispersion for 2-phase, Immiscible Flow in Heterogeneous Media. PhD thesis, University of Bergen, September 1992.
[170] H. P. Langtangen. Computational Partial Differential Equations - Numerical Methods and Diffpack Programming, volume 1 of Texts in Computational Science and Engineering. Springer, second edition, 2003.
[171] H. P. Langtangen and A. Tveito, editors. Advanced Topics in Computational Partial Differential Equations, Numerical Methods and Diffpack
Programming, volume 33 of Lecture Notes in Computational Science and
Engineering. Springer, 2003.
[172] C. L. Lawson, R. J. Hanson, D. Kincaid, and F. T. Krogh. Basic Linear Algebra Subprograms for FORTRAN usage. ACM TOMS, 5:308323, 1979.

Bibliography

297

[173] P. D. Lax. Weak solutions of nonlinear hyperbolic equations and their numerical computation. Communications on Pure and Applied Mathematics,
7:159193, 1954.
[174] R. J. LeVeque. Numerical Methods for Conservation Laws. Birkhauser,
1992.
[175] R. J. LeVeque.
Finite Difference Methods for Differential Equations. http://www.amath.washington.edu/rjl/booksnotes.html,
1998. Unpublished text.
[176] M. C. Leverett. Capillary behaviour in porous solids. Transactions of the
AIME, 142:159172, 1941.
[177] W. B. Lewis and M. C. Leverett. Steady flow of gas-oil-water mixtures
through unconsolidated sands. Transactions of the AIME, 142:107116,
1941.
[178] R. Li, T. Tang, and P. Zhang. Moving mesh methods in multiple dimensions
based on harmonic maps. Journal on Computational Physics, 170(2):562
588, 2001.
[179] R. Li, T. Tang, and P. Zhang. A moving mesh finite element algorithm for
singular problems in two and three space dimensions. Journal on Computational Physics, 177(2):365393, 2002.
[180] S. Liang. Java Native Interface: Programmers Guide and Specification.
Addison-Wesley, 1999.
[181] J.-L. Lions. Probl`emes aux limites non homog`enes a` donees irreguli`eres:
Une method dapproximation. In Numerical Analysis of Partial Differential
Equations, pages 283292. CIME, 1968.
[182] W. Liu and N. Yan. Quasi-norm a priori and a posteriori error estimates
for the nonconforming approximation of p-Laplacian. Numerische Mathematik, 89(2):341378, 2001.
[183] W. Liu and N. Yan. Quasi-norm local error estimators for p-Laplacian.
SIAM Journal on Numerical Analysis, 39(1):100127, 2001.
[184] W. Liu and N. Yan. Some a posteriori error estimators for p-Laplacian
based on residual estimation or gradient recovery. Journal of Scientific
Computing, 16(4):435477 (2002), 2001.

298

Bibliography

[185] W. Liu and N. Yan. On quasi-norm interpolation error estimation and a


posteriori error estimates for p-Laplacian. SIAM Journal on Numerical
Analysis, 40(5):18701895, 2002.
[186] W. Liu and N. Yan. A posteriori error estimates for optimal control
problems governed by parabolic equations. Numerische Mathematik,
93(3):497521, 2003.
[187] W. B. Liu, P. Neittaanmaki, and D. Tiba. Existence for shape optimization
problems in arbitrary dimension. SIAM Journal on Control and Optimization, 41(5):14401454, 2003.
[188] W. B. Liu, P.Neittaanmaki, and D. Tiba. Sur les problemes doptimisation
structurelle. CRAS Serie I Math., 331:101106, 2000.
[189] R. J. Lorentzen. Higher Order Numerical Methods and Use of Estimation Techniques to Improve Modeling of Two-Phase Flow in Pipelines and
Wells. PhD thesis, University of Bergen, April 2002.
[190] Maplesoft, a division of Waterloo Maple. Maple.
[191] S. F. Matringe. Accurate streamline tracing and coverage. Masters thesis,
Stanford University, June 2004.
[192] D. B. McWhorter and D. K. Sunada. Exact integral solutions for two-phase
flow. Water Resources Research, 26(3), 1990.
[193] G. Mellor, L.-Y. Oey, and T. Ezer. Sigma coordinate pressure gradient
errors and the seamount problem. Journal of Atmospheric and Oceanic
Technology, 15:11221131, 1998.
[194] Message Passing Interface Forum. MPI: A Message-Passing Interface
Standard, June 1995.
[195] M. L. Michelsen. The isothermal flash problem, part II: Phase split calculation. Fluid Phase Equilibria, 9:2140, 1982.
[196] M. L. Michelsen. The negative flash. Fluid Phase Equilibria, 53:5171,
1989.
[197] M. L. Michelsen. Phase equilibrium calculations. What is easy and what is
difficult? Computers & Chemical Engineering, 17(56):431439, 1993.
[198] M. L. Michelsen. Speeding up the two-phase PT-flash, with applications
for calculation of miscible displacement. Fluid Phase Equilibria, 143:1
12, 1998.

Bibliography

299

[199] P. Morin, R. H. Nochetto, and K. G. Siebert. Data oscillation and convergence of adaptive FEM. SIAM Journal on Numerical Analysis, 38:466488,
2000.
[200] I. Navon. Implementation of a posteriori methods for enforcing conservation of potential enstrophy and mass in discretized shallow-water equations
models. Monthly Weather Review, 109:946958, 1981.
[201] H. Nessyahu and E. Tadmor. Non-oscillatory central differencing for hyperbolic conservation laws. Journal of Computational Physics, 87:408463,
1990.
[202] T. K. Nilssen. Parameter estimation with the augmented Lagrangian
method and a study of some fourth order problems. PhD thesis, University of Bergen, October 2001.
[203] T. K. Nilssen, 2002. Personal communications.
[204] T. K. Nilssen and X.-C. Tai. Parameter estimation with the augmented Lagrangian method for a parabolic equation. Journal of Optimization Theory
and Application, 124(2), February 2005.
[205] J. Nocedal and S. J. Wright. Numerical Optimization. Springer, 1999.
[206] J. M. Nordbotten and G. T. Eigestad. Discretization on quadrilateral grids
with improved monotonicity properties. Journal of Computational Physics,
203(2), 2004.
[207] F. K. North. Petroleum geology. Allen & Unwin, 1985.
[208] J. T. Oden, I. Babuska, and C. E. Baumann. A discontinuous hp finite
element method for diffusion problems. Journal of Computational Physics,
146:491519, 1998.
[209] E. ian. Modeling of Flow in Faulted and Fractured Media. PhD thesis,
University of Bergen, March 2004.
[210] S. Osher and R. R. Fedkiw. Level set methods. Technical Report 0008, Computational and applied mathematics, University of California, Los
Angeles, February 2000.
[211] S. Osher and J. A. Sethian. Fronts propagating with curvature dependent speed: Algorithms based on Hamilton-Jacobi formulations. Journal of
Computational Physics, 79:1249, 1988.

300

Bibliography

[212] S. J. Osher and R. P. Fedkiw. Level Set Methods and Dynamic Implicit
Surfaces. Springer, 2002.
[213] J. C. Parker and R. J. Lenhard. A Model for Constitutive Relations Governing Multiphase Flow in Prorus Media 1. Saturation-Pressure Relations.
Water Resources Research, 12(23):21872196, 1987.
[214] D. W. Peaceman. Improved treatment of dispersion in numerical calculation of multidimensional miscible displacement. SPE, 1362, 1965.
[215] D. W. Peaceman. Fundamentals of Numerical Reservoir Simulation. Elsevier Scientific Publishing Company, 1977.
[216] D. W. Peaceman. Interpretation of well-block pressures in numerical reservoir simulation. SPE, 6893, 1978.
[217] D. W. Peaceman. A new method for calculating well indexes for multiple wellblocks with arbitrary rates in numerical reservoir simulation. SPE,
79687, 2003.
[218] K. S. Pedersen, A. Fredenslund, and P. Thomassen. Properties of Oils
and Natural Gases, volume 5 of Contributions in Petroleum Geology and
Engineering. Gulf Publishing Company, 1989.
[219] D.-Y. Peng and D. B. Robinson. A new two-constant equation of state.
Industrial & Engineering Chemistry Fundamentals, 15(1):5964, 1976.
[220] . Pettersen. Grunnkurs i Reservoarmekanikk. Department of mathematics, University of Bergen, 1990.
[221] M. J. D. Powell. A method for nonlinear constraints in minimization problems. In R. Fletcher, editor, Optimization, pages 283298. Academic Press,
New York, 1969.
[222] M. Prevost. Accurate Coarse Reservoir Modeling Using Unstructured
Grids, Flow-Based Upscaling and Streamline Simulation. PhD thesis,
Stanford University, December 2003.
[223] W. Pugh and J. Spacco. MPJava: High-Performance Message Passing in
Java using Java.nio. Presented at Languages and Compilers for Parallel
Computing, 2003.
[224] A. Quarteroni and A. Valli. Domain Decomposition Methods for Partial
Differential Equations. Oxford University Press, 1999.

Bibliography

301

[225] P. Raviart and J. Thomas. A mixed finite element method for second order
elliptic equations. In I. Galligani and E. Magenes, editors, Mathematical
Aspects of Finite Element Methods, pages 292315. Springer, 1977.
[226] V. Reichenberger, H. Jakobs, P. Bastian, R. Helmig, and J. Niessner. Complex Gas-Water Processes in Discrete Fracture-Matrix Systems. Upscaling,
Mass-Conservative Discretization and Efficient Multilevel Solution and Efficient Multilevel Solution. Technical Report 130, Institut fur Wasserbau,
Universitat Stuttgart, 2004.
[227] R. C. Reid, J. M. Prausnitz, and T. K. Sherwood. The Properties of Gases
and Liquids. McGraw-Hill Book Company, third edition, 1977.
[228] W. C. Rheinboldt. Methods for solving systems of nonlinear equations.
SIAM, second edition, 1998.
[229] T. F. Russell and M. A. Celia. An overview of research on Eulerian
Lagrangian localized adjoint methods (ELLAM). Advances in Water Resources, 25(812):12151231, 2002.
[230] Y. Saad. SPARSKIT: a basic tool for sparse matrix computations, second
edition, June 1994.
[231] Y. Saad and M. H. Schultz. GMRES: A generalized minimal residual algorithm for solving nonsymmetric linear systems. SIAM Journal on Scientific and Statistical Computing, 7:856869, 1986.
[232] F. Santosa. A level-set approach for inverse problems involving obstacles.
European Series in Applied and Industrial Mathematics. Controle, Optimisation et Calcul des Variations, 1:1733, 1995/96.
[233] A. E. Scheidegger. General theory of dispersion in porous media. Journal
of Geophysical Research, 66(10):32733278, 1961.
[234] A. E. Scheidegger. The physics of flow through porous media. University
of Toronto Press, third edition, 1974.
[235] Schlumberger. ECLIPSE: Technical Description.
[236] H. A. Schwarz. Gesammelte mathematische abhandlungen. Vierteljahrsschrift Naturforschenden Gesellschaft Zurich, 15:272286, 1870.
[237] R. C. Selley. Elements of petroleum geology. W. H. Freeman and Company,
1985.

302

Bibliography

[238] K. Seymour and J. Dongarra. Automatic Translation of Fortran to JVM


Bytecode. Concurrency: Practice and Experience, 15(3-5):207222, 2003.
[239] V. V. Shaidurov. Some estimates of the rate of convergence for the cascadic
conjugate-gradient method. Computers & Mathematics with Applications,
31(45):161171, 1996.
[240] A. Shchepetkin and J. McWilliams. The Regional Ocean Modeling System: A Split-Explicit, Free-Surface, Topography-Following-Coordinate
Oceanic Model, 2003. Institute of Geophysics and Planetary Physics, University of California, Los Angeles.
[241] J. G. Siek and A. Lumsdaine. The Matrix Template Library: Generic Components for High-Performance Scientific Computing. Computing in Science and Engineering, pages 7078, Nov/Dec 1999.
[242] S. M. Skjveland, L. Siqveland, A. Kjsavik, W. H. Thomas, and
G. Virnovsky. Capillary pressure correlation for mixed-wet reservoirs.
SPE, 60900, 2000.
[243] B. Smith, P. Bjrstad, and W. Gropp. Domain Decomposition. Parallel
Multilevel Methods for Elliptic Partial Differential Equations. Cambridge
University Press, 1996.
[244] G. Soave. Equilibrium constants from a modified Redlich-Kwong equation
of state. Chemical Engineering Science, 27:11971203, 1972.
[245] I. Sreide. Improved Phase Behavior Predictions of Petroleum Reservoir
Fluids from a Cubic Equation of State. PhD thesis, University of Trondheim, 1989.
[246] A. G. Spillette, J. G. Hillestad, and H. L. Stone. A high-stability sequential
solution approach to reservoir simulation. SPE, 1542, 1973.
[247] A. A. Stepanov. Generic programming. Lecture notes in Computer Science,
1181, 1996.
[248] A. A. Stepanov and M. Lee. The Standard Template Library. Technical
Report X3J16/94-0095, WG21/N0482, ISO Programming Language C++
Project, May 1994.
[249] H. L. Stone. Probability model for estimating three-phase relative permeability. Transactions SPE of AIME, 249:214218, 1970.

Bibliography

303

[250] H. L. Stone. Estimation of three-phase relative permeability and residual


oil data. Journal of Canadian Petroleum Technology, 4(12):5361, 1973.
[251] V. S. Sunderam. PVM: A Framework for Parallel Distributed Computing.
Concurrency: Practice and Experience, 2(4):315339, December 1990.
[252] M. Sussman, P. S. E. Fatemi, and S. Osher. An improved level set method
for incompressible two-phase flow. Computers and Fluids, 27:663680,
1998.
[253] X.-C. Tai, T. O. W. Johansen, H. K. Dahle, and M. S. Espedal. A characteristic domain splitting method. In Domain decomposition methods in science and engineering, 8th international conference, Beijing, China, pages
308317. John Wiley and Sons, England, 1997.
[254] W. Tang. Generalized Schwarz Splittings. SIAM Journal on Scientific and
Statistical Computing, 13(2):573595, 1992.
[255] www.autodiff.org.
[256] M. R. Thiele. Modeling Multiphase Flow in Heterogeneous Media Using
Streamtubes. PhD thesis, Stanford University, December 1994.
[257] E. F. Toro. Riemann Solvers and Numerical Methods for Fluid Dynamics.
Springer, second edition, 1999.
[258] A. Toselli and O. Widlund. Domain Decomposition Methods - Algorithms
and Theory, volume 34 of Springer Series in Computational Mathematics.
Springer, 2005.
[259] R. S. Tuminaro, J. N. Shadid, and S. A. Hutchinson. Parallel Sparse Matrix
Vector Multiply Software for Matrices with Data Locality. Concurrency:
Practice and Experience, 1997.
[260] J. D. van der Waals. Over de Continuteit van den Gas- en Vloeistoftoestand. PhD thesis, Universiteit Leiden, 1873.
[261] P. K. W. Vinsome. Orthomin, and iterative method for solving sparse banded sets of simultaneous linear equations. SPE, 5729, 1976.
[262] H. Wang and M. Al-Lawatia. An EulerianLagrangian Substructuring
Domain Decomposition Method for UnsteadyState AdvectionDiffusion
Equations. Numerical Methods for Partial Differential Equations, 2(3):1
20, 1994.

304

Bibliography

[263] H. Wang, H. K. Dahle, R. E. Ewing, M. S. Espedal, R. C. Sharpley, and


S. Man. An Ellam scheme for advection-diffusion equations in two dimensions. SIAM Journal on Scientific Computing, 20(6):21602194, 1999.
[264] H. Wang, J. Lie, M. S. Espedal, and R. E. Ewing. An Eulerian
Lagrangian Substructuring Domain Decomposition Method for Multidimensional, UnsteadyState AdvectionDiffusion Equations. In Fluid Flow
and Transport in Porous Media: Mathematical and Numerical Treatment,
volume 295 of Contemporary mathematics. AMS, 2001.
[265] H. Wang, J. Liu, M. S. Espedal, and R. E. Ewing. A characteristic nonoverlapping domain decomposition method for multidimensioal advectiondiffusion equations. Numerical Methods for PDEs, 21(1):89103, 2005.
[266] J. Wang. A superconvergence analysis for finite element solutions by
the least-squares surface fitting on irregular meshes for smooth problems.
Journal of Mathematical Study, 33(3):229243, September 2000.
[267] J. Wang and X. Ye. Superconvergence of finite element approximations for
the Stokes problem by projection methods. SIAM Journal on Numerical
Analysis, 39:10011013, 2001.
[268] J. W. Watts. A compositional formulation of the pressure and saturation
equations. SPE, 12244, 1986.
[269] J. W. Watts. Reservoir simulation: Past, present, and future. SPE, 38441,
1997.
[270] H. J. Welge. A simplified method for computing oil recoveries by gas or
water drive. Transactions of the AIME, 195:9198, 1952.
[271] J. R. Welty, C. E. Wicks, and R. E. Wilson. Fundamentals of Momentum,
Heat, and Mass Transfer. John Wiley & Sons, third edition, 1984.
[272] M. F. Wheeler. An elliptic collocation-finite element method with interior
penalties. SIAM Journal on Numerical Analysis, 15:152161, 1978.
[273] S. Whitaker. Flow in Porous Media I: A Theoretical Derivation of Darcys
Law. Transport in Porous Media, 1:325, 1986.
[274] S. Whitaker. Flow in Porous Media II: The governing equations for immiscible two-phase flow. Transport in Porous Media, 1:105125, 1986.
[275] S. Wolfram. The Mathematica Book. Cambridge University Press and
Wolfram Media, third edition, 1996.

Bibliography

305

[276] N. Yan. A posteriori error estimators of gradient recovery type for elliptic
obstacle problems. Advances in Computational Mathematics, 15(1-4):333
362 (2002), 2001.
[277] N. Yan and A. Zhou. Gradient recovery type a posteriori error estimates for
finite element approximations on irregular meshes. Computer Methods in
Applied Mechanics and Engineering, 190(32-33):42894299, 2001.
[278] Z. Zhang. Polynomial preserving gradient recovery and a posteriori estimate for bilinear element on irregular quadrilaterals. International Journal
of Numerical Analysis and Modeling, 1(1):124, 2004.
[279] H.-K. Zhao, T. F. Chan, B. Merriman, and S. Osher. A variational level
set approach to multiphase motion. Journal on Computational Physics,
127(1):179195, 1996.
[280] A. Zhou, editor. A posteriori error estimation and adaptive computational
methods, volume 15. Kluwer Academic Publishers, 2002.
[281] O. C. Zienkiewicz and R. L. Taylor.
The finite element method.
Butterworth-Heinemann, fifth edition, 2000.
[282] O. C. Zienkiewicz and J. Z. Zhu. The superconvergent patch recovery and
a posteriori error estimates, parts 1 and 2. International Journal for Numerical Methods in Engineering, 33:13311364 and 13651382, 1992.
[283] B. G. Zorn. The measured cost of conservative garbage collection. Software
- Practice and Experience, 23(7):733756, 1993.

You might also like