# Application of automatic differentiation for the simulation of nonisothermal, multiphase flow in geothermal reservoirs Page: 4 of 8

This
**article**
is part of the collection entitled:
Office of Scientific & Technical Information Technical Reports and
was provided to Digital Library
by the UNT Libraries Government Documents Department.

#### Extracted Text

The following text was automatically extracted from the image on this page using optical character recognition software:

to provide an analytically computed Jacobian matrix.

The selected simulator is the TOUGH2 code (Pruess,

1991), developed at the Lawrence Berkeley National

Laboratory. TOUGH2 is one of the most widely used

nonisothermal, multiphase flow simulators with

applications in geothermal, oil, and gas reservoir

engineering, nuclear waste isolation, environmental

assessment and remediation, and unsaturated zone

hydrology. Benchmark data comparing the

performance of AD and FD methods in TOUGH2 are

presented.

After a brief description of the AD technique

(Section 2) and the TOUGH2 model (Section 3), we

discuss the implementation scheme of TOUGH2-AD

in Section 4. The numerical experiments are

described in Section 5 where we evaluate each

differentiation method with typical geothermal test

cases. We conclude with a brief description of future

work.

AUTOMATIC DIFFERENTIATION

AD is an efficient approach relying on the fact that

the derivatives of a function, no matter how

complicated, can be computed by repeatedly applying

the chain rule of derivative calculus to the sequential

elementary operations of a coded function. For

example, if a function R is computed through the

elementary functional operations of y(x) and z(x), the

chain rule can be applied to compute the partial

derivative of function R to the independent variable x

as follows:DR{y(x),z(x)} aR ay aR az

ax ayax Dazax(3)

In this equation, truncation or round-off errors are of

the derivative calculation are eliminated, because all

the involved partial derivatives of elementary

functional operations can be computed analytically

by an AD-generated code. By applying the chain rule

repeatedly, we can compute analytical derivatives of

any computational function, because the computer

code representing the function is the composition of

elementary operations. Note that AD allows

augmenting any computer program written in

Fortran, C, or C++ for derivative computations.

Various implementation techniques for AD

processing have been developed. Juedes (1991)

provided an extensive survey for available AD tools.

Two basic implementation approaches are applied in

AD tools, referred to as the forward and reverse

modes. In forward mode, derivatives of intermediate

functional values are computed with respect to the

input primary parameters. It is known from the

linearity of differentiation that the computational

effort required in this mode is approximately the

number of input parameters multiplied by the runtime

and memory of the original program.In reverse mode, AD propagates derivatives of the

final result with respect to intermediate variables (or

quantities), known as adjoints. The program flow is

reversed to be able to keep all of the adjoints that

impact the final result. Because all of the involved

intermediate values must be stored or recomputed, it

is difficult to estimate the storage requirement using

the reverse mode of AD. Recent activities of AD

research have been centered on hybrid modes to

combine the best features of the forward and reverse

mode.

In this study, we use the ADIFOR tool (Bischof et al.,

1998) developed by Argonne National Laboratory

and Rice University, which employs a hybrid

forward/reverse mode approach to generating

derivatives. Given a Fortran routine of function

computation and a control description, of which

variables correspond to independent and dependent

parameters, ADIFOR produces portable Fortran code

that allows the computation of the partial derivatives

of the dependent variables with respect to the

independent variables, as shown in Figure 1.

Fortran 77 Code to compute

code ADIFOR - derivatives

Control

Script& Link

Figure. 1. Schematic diagram of the use of an

automatic differentiation tool to generate

a new code for derivative computations.

TOUGH2 SIMULATOR

TOUGH2 is a numerical simulator that solves the

coupled equations of fluid and heat flow in a

geothermal reservoir. For a given arbitrary

subdomain V, bounded by the surface F,, the mass-

and energy-balance equations solved in TOUGH2

model can be written in the general form (Pruess,

1991):f M kdv = f e-d+ fqkdv

V, F. V(4)

where each mass component is labeled by k = 1,...,

NK. The quantity M in the accumulation term of this

equation represents mass (m) or internal energy (h)

per unit reservoir volume:MA =#(SI Px +Sgpgxg)

(5)

Mh =0(Si p1 u1 +SgPgug)+(1-)PRCRT (6)

where 0 is porosity, S is phase saturation, p is

density, u is internal energy, C is specific heat, T is

temperature, and x is the mass fraction of

component k existing in each phase #. The subscripts

1, g, and R indicate the phases of liquid, gas, and

## Upcoming Pages

Here’s what’s next.

## Search Inside

This article can be searched. **Note: **Results may vary based on the legibility of text within the document.

## Tools / Downloads

Get a copy of this page or view the extracted text.

## Citing and Sharing

Basic information for referencing this web page. We also provide extended guidance on usage rights, references, copying or embedding.

### Reference the current page of this Article.

Kim, Jong G. & Finsterle, Stefan. Application of automatic differentiation for the simulation of nonisothermal, multiphase flow in geothermal reservoirs, article, January 8, 2002; Berkeley, California. (digital.library.unt.edu/ark:/67531/metadc736480/m1/4/: accessed August 17, 2018), University of North Texas Libraries, Digital Library, digital.library.unt.edu; crediting UNT Libraries Government Documents Department.