OBJECT ORIENTED PROGRAMMING TECHNIQUES AND FAC METHOD IN NUMERICAL RESERVOIR SIMULATION MAZEN SAAD AND HUILONG ZHANG y
Abstract. Flexible gridding has the potential of increasing the accuracy in numerical simulation of ow through hydrocarbon reservoirs within limitations in computing time and memory space. This paper is devoted to the description of a computational algorithm for two-phase immiscible, incompressible ows in an adaptive composite grid. An IMPES approach is applied. The pressure equation is discretized on locally re ned grids with nite volume scheme. To solve this equation, a FAC method outlined by McCormick is used. For the transport equation, we propose the nite dierence schemes : upwind are MUSCL. An object oriented programming language C++ is selected for the implementation. It provides a dynamic memory management and a convenient data structure for evolutive problems. Results for some examples illustrate the eciency of proposed algorithm. Key words. Fast Adaptive Composite method, Porous media. AMS subject classi cations. 65C20
1. Introduction. In this paper, we present computations that use adaptive mesh re nement to solve two dimensional, time dependent shock hydrodynamics problems. These consist of solution of the conservation equations whichs govern the motion of uid through the reservoir and form a coupled system of partial dierential equations, where elliptic and hyperbolic types occur simultaneously. This problem is arised on petroleum recovery processes by water ooding methods. Fluids are injected into some wells in a reservoir while the resident hydrocarbons produced from other wells, designed production wells. It is a two{phase incompressible ow in porous media. The choice of a computational method is strongly in uenced by the possible occurrence of saturation shocks propagating through the reservoir. Combining the need for an accurate approximation of these moving features with the need to economize on computational work points to a numerical method based on multigrid method with adaptive local mesh re nement. A splitting method named IMPES (implicit in pressure, explicit in saturation) allows to some degree, separate treatment of elliptic equation and the hyperbolic equation. A convergent and conservative nite volume scheme is proposed for the rst equation. It enables to check the ux continuity at the interface. Two scheme : Up-wind and MUSCL are described and compared for the second equation. The moving features that require dynamic local re nement are dictated by hyperbolic part. For the elliptic part, the FAC (fast adaptive composite grid method) proposed by McCormick [10] is applied. Software design aspects have so far been neglected in scienti c discussion of numerical methods. As mentioned in Ruede [13], we believe that development of adaptive grid techniques must take into account the rapid development of advanced computer architectures and use of performance programming language. This paper attempts to present algorithmic aspects together with an discussion of data structures based on the objet oriented programming (OOP) techniques [17]. We can see that the OOP techniques are particularly interesting for adaptive multigrid method. Version March 27, 1997 y MAB, ERS CNRS 123, Universite de Bordeaux I, 351 cours de la Liberation, 33405 Talence
Cedex, France |
[email protected]
1
2
M. SAAD AND H. ZHANG
All numerical results were obtained with a prototype reservoir simulator, based on very simple ash calculations. 2. Formulation. In this section, we brie y state the basic equations underlying the prototype simulator, for which numerical results are given in the nal section. The equation model incompressible two phase ow in a homogeneous porous medium. It consists of conservation equations of oil and water. The phase velocity is given by Darcy's law [1]. Let =]0; L[]0; l[ denote the domain of the study, with boundary ? = @ which is divided as follows : ? = ?in [ ?out [ ?imp and ?a \ ?b = ; if a 6= b. ?in : water injection boundary ?out : uid production boundary ?imp : impervious boundary The capillary and gravitational eects are negligible, for an incompressible ow. The problem is equivalent to nding (P; S ) a solution of the following nonlinear partial dierential system : 8 div(?KM (S )rP ) = 0 > > < @t S + div(Vf (S )) = 0 (1) > V = ?KM (S )rP > : 0S1 where S the saturation of the water phase, P the pressure, K the permeability tensor of the porous medium, the porosity, M (S ) the total mobility, f (S ) the fractional ux and V the total velocity. For example, the model with square relative permeabilities gives 2 f (S ) = S 2= +S (1=?w S )2 = ; M (S ) = S 2=w + (1 ? S )2 =o w o where w (resp. o ) the water (resp. oil) viscosity.
In order to deal separately with the two dierent mathematical equations of this system, a splitting method is used which leads to solving an elliptic and hyperbolic equations. It is based on an IMPES method ([1], [9], [4]) on a composite grid. This algorithm is described in section 4. For more clarity, we are interested in discretizing two prototypical problems : Elliptic problem. For M (x; y) a continous and positive function in , nd P which is a solution of : 8 > ?div(M (x; y)rP ) = 0 in
> < rP:n = 0 on ?imp (2) > P = Pin on ?in > : P = Pout on ?out Here n is the outward unit normal vector de ned on ?.
OOP and FAC method in reservoir simulation
3
Hyperpolic problem. For V(x; y) a given vector in that satis es divV = 0, nd S which is a solution of 8 > < @t S + div(Vf (S )) = 0 in
(3) y; t) = Sin on ?in > : SS ((x; x; y; 0) = S0(x; y) on : where f has C 1 [0; 1] regularity and is an increasing function. Wells modeling. The wells are modelized by the Dirac's mass at the region where they are imposed. By adding the source terms qw + qo (resp. qw ) in the pressure equation (resp. saturation equation), the system (1) is replaced by ( div(?KM (S )rP ) = q + q w o (4) @t S + div(Vf (S )) = qw The source terms are of the form :
q=
X
qi(xi ; yi)
where (xi ; yi ) represents the Dirac mass at point (xi ; yi ). Then the right hands of system (4) are zero except at wells. 3. Mesh description and data structure. In this section we de ne the class of cells that will be used, outline how a nested composite grid is constructed, and introduce pointers needed to code a computer program. Later in the section 6, we will add the object oriented programming techniques to these data structures. The coarsest grid in the class is xed during simulation time and consists of a rectangular, possible not equidistant grid with interfaces paralleled to the x- and yaxes, of a Cartesian coordinate system. The total class of mesh consists of this coarsest grid and all grids that can be obtained from it by basic re nement, which re nes one block into four identical smaller ones. It appears clear that if the number of neighbors for a cell is too great, the writing of the scheme will be dicult. A great rate of re nement between two neighbors will deteriorate discretization precision. To avoid the occurrence of such cases, a certain re nement rule is established at the end of this section. The level of a cell is the level of re nement to which it belongs, coarse grid cells are allocated to level 1. A cell is identi ed by its geometrical position (i.e. the coordinate of its barycenter), its four edges, its size and its level. It is surrounded by several cells, called neighbors. Precisely, two cells are said to be neighbors if they have a edge in common. Sometimes, one or two of these neighbors can reduce to a boundary of the discretization domain. Let's proceed a classi cation for every cell in a composite mesh. Given a cell of level l, ve classes are distinguished as following : Regular (R). The most simple cell. If the neighbors in 4 directions (some of these directions can reduce to a boundary) are in the same level as it. Coarse Fine (CF). A bigger cell in the interface of two levels, i.e. at least one neighbor is of level l + 1, the others of level l. Fine Coarse (FC). A ner cell in the interface of two levels, i.e. at least one neighbor is of level l ? 1, the others of level l. Middle (MD). A interface cell among 3 level : l ? 1, l and l + 1, i.e. at least one neighbor is of level l + 1, and one neighbor is of l ? 1.
4
M. SAAD AND H. ZHANG
Corner (CN). Two neighbors are of MD type cells and the other neighbors are of FC R
FC CF
R
FC
R
FC
FC
FC
CF
FC
FC
MD
R
CF
R
CN FC FC
CF
MD FC FC
CF FC
R
CF
R
. Regular R, Coarse Fine CF, Fine Coarse FC, Middle MD and Corner CN
Fig. 1
The cells of classes CF, FC, MD and CN nd themselves only in the interfaces of dierent re nement regions. Particularly, MD and CN appear only when the level of composite grids is superior or equal to 3. For a given composite mesh of level l, the re nement rule for the construction to a composite mesh of level l + 1 is that only the regular cell of level l can be re ned. Using the discretization scheme and multigrid techniques described in the next sections, two kind of pointers are needed. Neighbor pointers:. These pointers permit a cell to access and to obtain the informations from its neighbors. They are used for instance in relaxation. Cells of dierent classes have dierent pointers that point to their neighbors. A R cell has in general 4 pointers, where a CF has between 5 and 8 pointers. To be more precise, we illustrate in the Figure 2 the pointers (designed by ?!) associated to some underling cells presented in Figure 1.
CF
R
. neighbors pointers
Fig. 2
Descendant pointers:. These pointers are used in particular to transmit information between two grid levels in multigrid method, (e.g. prolongation and restriction).
OOP and FAC method in reservoir simulation
5
There are 4 or 1 pointers according to that the cell is re ned or not.
. Descendant pointers
Fig. 3
The implementation of the pointers will be described in section 6 4. Discretization. In this section we will discuss a discretization scheme of equation (2) and (3) on a composite mesh. We apply the nite volume method to get a convergent and conservative scheme for the elliptic equation (2) ; we present also two monotone and consistent nite dierence schemes to approach the hyperbolic equation (3). Numerical tests are presented, in section 7, for simple problems to validate proposed schemes. 4.1. Discretization of elliptic equation on a composite grid. We use a cell-centered grid to discretize the computational domain and a nite volume method to approach the elliptic problem (2). The reasons for this choice include its ability to be faithful to the physical situation in general and conservation in particular. We will described our scheme, without loss of generality, for the case of a Coarse Fine cell depicted in Figure 4. Suppose C is a given cell called control volume in
with boundary ?C as showed in Figure 4. Using the divergence theorem (5)
Z
C
div(M rP )d! =
Z
?C
M rP:nd = fl(C ) = 0
where fl(C ) is a sum of four ux corresponding to four edges of the cell. The equation (5) can thus be interpreted as a conservation law for volume C which states that the net ow rate of the uid across the surface ?C balances with the net
ow rate from the interior source which is zero. Let's denote by capital letters N, W, EN, ES, SW and SE (resp. small letters n, w, en, es, sw and se) the neighbors (resp. the edges) of the cell C. They designate also the center of the cell (resp. the midlle of the edge). The total ux fl(C ) is then written : (6)
fl(C ) = fle(C ) + flw (C ) + fln(C ) + fls(C )
where fli (C ) refers to the ux across the edge i of C (i = n; w; en; es; sw and se). In other words
fli(C ) =
Z
?i (C )
M rP nd i:
As above Mi ; i = n; w; en; es; sw and se represent the value of the mobility at the middle of the common edge between cell C and its neighbors. These ux can be
6
M. SAAD AND H. ZHANG
approached by
fli(C ) = Mi
Z ?i (C )
rP n d i :
The gradient rP will be discretized by nite dierence. N
EN W
C ES
SW
SE
. Regular and Coarse Fine cells
Fig. 4
The cells in the north and west directions being non re ned, the expression of ux across the north and west edges is exactly the same as in the case of regular cells, that is,
fln(C ) = Mn(PN ? PC ) and flw (C ) = ?Mw (PC ? PW ): To obtain a convenient expression for the east ux, we assume that the pressure is a linear function between the cell C and its neighbors. Moreover, to ensure the total
ux conservation at the east face of the cell C , we impose
fle(C ) = ?flw (EN ) ? flw (ES ); where, flw (EN ) (resp. flw (ES )) designate the ux across the west edge of the cell EN (resp. ES). Some slave nodes obtained by linear interpolation are then introduced to compute the last two ux. Precisely, to calculate the ux flw (EN ) a slave node named P2 is de ned by P2 = 43 PC + 41 PN so that, 1 P ? P h 1 2 2 EN flw (EN ) ' ?Men 3h 2 = ?Men 2 PC + 6 PN ? 3 PEN 4 To approach the ux flw (ES ), two slave nodes P4 and P are considered
P4 = 21 PSW + 12 PSE ; and P = 32 PC + 13 P4 = 32 PC + 61 PSW + 16 PSE
7
OOP and FAC method in reservoir simulation
therefore,
4 P ? P h 1 1 2 ES
flw (ES ) ' ?Mes 3h 2 = ?Mes 9 PC + 9 PSW + 9 PSE ? 3 PES 4
Similarly, with some other slave nodes, we have
1 2 1 fls(C ) = ?fln(SW 4 ) ? fl1n(SE ) '1 ?Msw 2 2 PC + 6 PW ? 3 PSW ?Mse 9 PC + 9 PEN + 9 PES ? 3 PSE
Finally, the stencil for this Coarse Fine type cell can be written as 0 ?Mn + 16 Men
BB BB ?Mw + 1 Msw 6 B@
? 1 2 9 Mes ? 3 Msw
1 2 9 Mes ? 3 Mse
1 ? 32 Men + 91 Mse C CC CC 1 2 ? 3 Mes + 9 Mse A
The surface of the boundary control volumes coincide with the boundary of the computational domain, so the boundary condition for problem (2) is easily incorporated into their equations and conservation for the entire domain is therefore assumed. For example, if the west side of the cell C coincides with the boundary domain, we simply let fw (C ) = 0 to impose a homogeneous Neumann condition or fw (C ) = 21 Mw (PC ? Pimposed ) to impose a Dirichlet condition. The proposed scheme is conservative by its construction. Several authors have studied the properties of nite volume schemes in the case of composite mesh ([3]). It is obvious that the scheme is not consistent. Nevertheless, one can prove the convergence of this scheme by using the same method in ([3], [2]). In particular, one gets that the order of convergence is locally 1 (resp. 2) for a interface cell (resp. regular cell). 4.2. Discretization of hyperbolic equation on a composite grid. In this subsection, nite dierences schemes are used to discretize the hyperbolic equation (3) on a composite grid. We suppose that the velocity eld is given by the solution of (2). The scheme widely used for this kind of hyperbolic equation in petroleum engineering is a upwind scheme, it is based on decentered of mobility of each phase according to its own velocity (see Aziz et al. [1], Forsyth [4], Liu et al. [9], Hermitte [6]). This scheme, which is of rst order, presents a principal undesirable behavior : numerical diusion. This phenomenon increases near the shock fonts. A possible improvement can be obtained by using a second order scheme such as slope-limiter and ux-limiter schemes (Yee [18], Roe's second order scheme) or an anti-diusion scheme (Harten [5]). It is known, in general, that a higher order scheme becomes rst order on a composite mesh. Hence, we propose a upwind scheme based on fractional ux. It is assumed that the uid speed propagation is the total velocity, and this leads to a simple hyperbolic equation. In order to diminish the numerical diusion introduced by the upwind schemes, we propose then a MUSCL method (see Van Leer ([8], [7]), Randall et al. [11]). As we will see in sections 5 and 7, the front tracking method allows a local re nement near the shocks by a certain criterion, which reduces considerably the numerical diusion. Consider the hyperbolic equation (7) @tS + V:rf (S ) = @t S + u@xf (S ) + v@y f (S ) = 0:
8
M. SAAD AND H. ZHANG
where V(x; y) = (u(x; y); v(x; y))T is a given function satisfying divV = 0; and f is a monotone increasing function. Let nh be a composite grid and Shn a saturation vector on this grid. Our goal is to establish an explicit nite dierence scheme to obtain Shn+1 in the same grid. The construction of the composite grid nh at the time tn is described in the section 5. Here, we suppose that nh and Shn are given. Denote SCn a component of Shn representing an approximation of the exact solution associated to the cell C at time tn . The Euler time scheme implies (8)
S n+1 ? S n + V:rf (S n) = 0: t
In order to present the discretization of equation (8), we consider, without loss of generality, a Coarse-Fine cell depicted in gure 5. N
* W
*
*
EN
*
ES
C
* S
Fig. 5. General composite grid for two{level re nement. () represent the points where piecewise linear solution do not create a local extremum for the MUSCL scheme.
We denote by Vi = (ui ; vi )T (i = s; w; es; en; n), the average velocity at the common face between the cell C and its neighbors. Upwind scheme. The approximate solution is considered to be piecewise constant. The second term of equation (8) can be considered as a sum of four quantities corresponding to contribution of each side. We approach the ux gradient across the south, west and north edges by the upwind scheme usually used in the literature ([5], [12], [14]). Hence,
SCn+1 ? SCn + F (C ) + F (C ) + F (C ) + F (C ) w e t n s n nn (9) n +1 n n fC + u+ fCn ? fWn + F (C ) = 0 = SC ?t SC + vs+ fC ?h fS + vn? fN ? e w h h where + = + jj , ? = ? jj for 2 R.
2 2 There are two contributions corresponding to the east{north (EN) and the east{ south (ES) cells so that the east ux Fe (C ) is expressed as follows n n n n (10) Fe(C ) = 21 (u?en fEN3 ?h fC + u?es fES3?h fC ): 4 4
OOP and FAC method in reservoir simulation
9
Under a CFL condition the scheme (9){(10) is L1 -stable. Moreover, the scheme is of rst order [15]. MUSCL scheme. The basic idea is to replace piecewise constant representation of the solution by some accurate representation, say piecewise linear. Methods of this type were rst introduced by Van Leer in a series of papers ([7], [8],...) where he develops the MUSCL scheme (standing for 'Monotonic Upstream{ centered Scheme for Conservations Laws'). In two{dimensional space and on an irregular grid the MUSCL methods are more dicult to put in place. We give now an algorithm of the MUSCL schemes employed on our composite grid. The proposed scheme is based on a gradient-limiter method. Give data fSCn gC a vector on the composite grid nh . We replace the piecewise constant solution by a more accurate reconstruction, taking the piecewise linear function : ?!
S~Xn = SCn + QnC CX; where QnC is an approximation of the gradient on the cell C which is based on the data fSCn gC . The most interesting question is how do we choose the gradients? A classical way is to limit the gradients QnC by a coecient Cn with 0 Cn 1. This coecient is chosen such that the saturations on the interfaces, precisely where the ux will be evaluated, do not create a local extremum with respect to the saturations of neighbors cells. Denote by Smax (resp. Smin ) the highest (resp. lowest) admissible value of the saturation on the interface, and S~Xn the saturation of X on an interface of cell C : ?! S~Xn = SCn + Cn QnC CX . The algorithm to compute Cn is as follows : Choose Cn = 1. In the case where S~Xn > Smax , the gradient of the cell C is then limited by Cn = (Smax ? SC )=(S~Xn ? Sc), and if S~Xn < Smin then Cn = (Smin ? SC )=(S~Xn ? Sc). We give now the MUSCL scheme for the situation in gure 5. A natural approximation of gradient of cell C is QnC = (AnC ; BCn ) with
AnC =
n + Sn SEN ES ? S n
2
7h 4
W
n n ; BCn = SN 2?h SS :
Smax and Smin are considered to be Smax = max S n; Smin = min S n; I = fC; N; W; S; EN; ES g: I I I I The coecient Cn is limited such that the saturations on the middle of the common faces between the cell C and its neighbors, denoted by in the gure 5, remain in the interval [Smin ; Smax ]:
10
M. SAAD AND H. ZHANG
Finally, to compute the cell averages SCn+1 , the scheme (9){(10) is replaced by :
SCn+1 ? SCn + v+ f (SCn + h2 Cn BCn ) ? f (SSn + h2 SnBSn) s t h n ? h n B n ) ? f (S n ? h n B n ) f ( S + vn? N 2 N N h C 2 C C f (S n + h n An ) ? f (S n + h n An ) + u+w C 2 C C h W 2 W W (11) f (S n ? h n An ) ? f (S n ? h n An + h n B n ) + 21 u?en EN 4 EN EN 3 C 4 C C 4 C C 4h f (S n ? h n An ) ? f (S n ? h n An ? h n B n ) + 21 u?es ES 4 ES ES 3 C 4 C C 4 C C = 0: 4h Note that taking QnC = 0 for every cell C , the MUSCL scheme reduces to the upwind scheme (9){(10). Even if the scheme (11) remains of rst order on the composite grid, the numerical results presented in section 6 show that the MUSCL scheme diminishes considerably the numerical diusion introduced by the upwind schemes.
5. Algorithm for solving two-phase ow by adaptive mesh. The whole idea of the adaptive method is to produce a stable, physically reasonable solution while saving computational work. The adaptivity of the local re nement methods must be driven both by rapid changes in solution properties and by a simple and inexpensive method of mesh construction techniques. Now, we are going to describe the algorithm for the resolution of the system (1) by adaptive techniques. An IMPES method (implicit in pressure, explicit in saturation) is used ([1], [4] , [9]). Denote H a xed coarse grid, nhl a composite grid at time tn where (hl = H=2l?1 ) is the space step of discretization of top level l, and (Phnl ; Shnl ) is a given grid vector in this composite grid. The goal of the algorithm is to construct a new composite grid
nhl+1 at time tn+1 and the associated solution (Phnl+1 ; Shnl+1 ). The triplet ( nhl+1 ; Phnl+1 ) is to be carried by l step. The diculty in the case of self{adaptive methods is to pass information from 0
0
one composite grid to another. For this, an interpolation operator I hh is introduced. This operator designates prolongation or restriction of a grid vector from h to 0h0 . We start by a regular coarse grid nh1+1 = H , independent of nhl . Then, the IMPES scheme is applied to the coarse grid. A criterion based on truncation error permits us to nd re nement regions, therefore a composite grid nh2+1 is constructed. In the same way, the IMPES scheme is used on the new composite grid (see system (12)). Hence, composite grids nhk+1 for k = 1; :::; l are successively constructed. We note that nhk+1 is constructed by re ning only the regular type cells, which nd themselves in the interior of re ned regions of nhk+1?1 . So, for an arbitrary nhk+1, the IMPES scheme consists of the following algorithm :
OOP and FAC method in reservoir simulation
(12)
11
8 n+1 > n = I nhk S n ^ > S hk
hk hk > > > > < ?div(M (S^hnk )rPhnk+1) = 0 > Vhnk+1 = ?M (S^hnk )rPhnk+1 > > > > Shnk+1 ? S^hnk > : + Vhn+1 rf (S^hn ) = 0
k k t The advantages of the proposed algorithm is to enable us to treat a complex problem, for example where the solution changes radically from step to step (appearance picks, turbulence, ...). The successive mesh construction induces a more accurate localization of the regions where re nement will be needed ; therefore, a better pro le of the front can be captured. The solution of the pressure equation, which represents the most time{ consuming part of the algorithm, is eciently and accurately obtained by the FAC method described in the next section. We remark that the mesh construction strategy described here is particularly coherent with full multigrid version of the FAC method. A widely used heuristic a posteriori criterion based on the magnitude of the discretization truncation error is applied. It is a local computation, which takes little time. Using a simple threshold decision rule, we decide whether this point is going to be re ned or not. Notice that the nested iteration of our algorithm oers a numerically cheap way to estimate the local truncation error. In practice this simple criterion appears to be quite ecient and reliable. The following method is used to switch cells :
max jSCn+1 ? SIn+1j < tol; for I 2 neighbors C: I
6. FAC method and object oriented programming implementation. In the FAC method introduced in Mccormick [10], a composite grid is a family of uniform locally nested grids h. i.e. h = h [ 2h [ [ H and 2h = 2h [ 4h [ [ H . Where kh and ukh k = 1; 2; 4; mean the local mesh paths and their vector values repectively. The objective is to solve a linear system based on a composite grid. Lhuh = f h In the case of two level, the FAC algorithm is represented by uh ? FACh (uh ; f h ) Step 1 . Set f 2h = Ih2h (f h ? Lhuh ); u2h ? (L2h )?1 f 2h; uh ? uh + I2hh u2h Step 2 . Set f h = Ihh(f h ? Lh uh ); uh ? (Lh )?1 f h ; uh ? uh + Ihh uh Multigrid version is given in Section 4.3 Page 94 in [10]. Notice that the direct solver of subgrid equation is usually replaced by iteration method. The programming language FORTRAN 90 and C are becoming used in scienti c computation. They provide so{called Abstract Data Types (ADT). Particularly, by means of struct, (module in F90), pointer and list, one can construct some speci c ADT data structure, adapted to the discretization. Furthermore the allocation of memory in these languages can be dynamic, i.e. variables of any type can be allocated or deleted during execution. The language C++ invented at Bell labs by B. Stroustrup [17] is an extension of the C programming language that provides an
12
M. SAAD AND H. ZHANG
ecient implementation of object oriented programming techniques. Thanks to its qualities of modularity, exibility and extensibility, this language is widely used in applied computer sciences, such as image processing, telecommunication, etc, in which the preoccupation to limite the calculate time and memory is quite as important as in scienti c computation. An interesting discussion about application of this language in multigrid method can be found in Ruede [13]. We now explain how the FAC method be implemented by using OOP techniques, based on the data structure de ned in Section 3. Classes and derived classes. What is truly novel about C++ is its aggregate ADT type classes. A class is an extension of the idea of struct in traditional C. A code fragment for the de nition of regular cell is shown in Table 1. It implements the topological features of a R cell de ned in section 3. For any regular cell x = (x; y) in the constructed composite grid, the pointers S, W, E and N contain the addresses of its neighbors, each of which is represented itself by same type of structure. If one or several of these neighbors do not exist (e.g. at the boundary), then the corresponding pointers will be assigned to NULL. In the language like FORTRAN 77, these pointers are de ned by using integer indices [16]. Table 1
Class : Regular cell class R { public: int x, y; /* coordinate of barycenter */ int size; /* cell size */ double pressure, saturation; /* physique value */ R *N, /* neighbor pointers */ *W, *E, *S; R *Son_SW, *Son_SE, /* Decendant pointers */ *Son_NW, *Son_NE; R *Son; double n, /* matrix coefficients */ w, c, e, s; R *next; R(); void ErrorCriteria(); void Refinement(); ... virtual void Matrix(); virtual void Calcul_Saturation(); ... };
A regular cell is the most simple case to treat. But in one or several directions, a complex cell can have the same geometry con guration as a regular cell. For instance, in Figure 4, a CF cell can be considered as a regular cell when we regard the north
OOP and FAC method in reservoir simulation
13
or west direction. Based on this observation, we construct a hierarchy ADT classes of cell by using derived class. The derived class mechanism is called inheritance and is an important tool for object oriented modularization and program development. As a derived class of R, A CF cell has by default all the structure as a R cell, but it is in possession of its speci c data. Table 2 shows declaration code fragment of the CF type cell. Eight pointers SW, SE, WS, WN, ES, EN, NW and NE are necessary to treat all the possible con gurations. They stock the addresses of the neighbors whose level is inferior. Table 2
Class : Coarse Fine cell class CF : public R { public: R
*NW, *WN, *WS, *SW,
double nw, wn, ws, sw,
*NE,
/* pointers of its neighbors */
*EN, *ES, *SE; ne,
/* matrix coefficients */
en, es, se;
CF(); void Matrix(); void Calcul_Saturation(); ... };
Linked lists. The linked list is an alternative of the vector used in FORTRAN 77. It has the advantage to be exible : its creation, its size, the insertion and deletion of an element can decided at execution time. Mesh paths covering exible geometry regions (sometimes even not connected) that are composed by uniform cell are aranged in linked lists. As a result, a composite grid h is union of a series of lists. The pointer next in class R is reserved to the construction of chained lists. This is used mainly as a counter for iteration to treat operation in the FAC method, such as local relaxation and correction. Member fuction and overloaded member function. The inheritance mechanism provides the means for implementing a user{de ned associated functions and operators. They allow the ADT to have particular functions act on its private representation. Furthermore, it supports virtual member functions, these are functions declared in the base class and overloaded in a derived class. By accessing virtual function through pointers, C++ selects the appropriate overloaded function at run{time. For instance, to calculate the matrix coecients, the functions both named Matrix() in the two structures, have dierent codes in R and CF respectively, and the second one can share partially the codes of the rst. For example, in the case of a CF cell
14
M. SAAD AND H. ZHANG
shown in Figure 4, the member function Matrix() of CF class will call Matrix() of its base class R to calculate the coecients w and n corresponding to the west and north directions respectively. The distinction is made dynamically, each class "knows" which one will be loaded. The function declarations R() and CF() are constructor, essentially containing the dynamic storage allocation of a single cell. The ADTs for the others type of cell are omitted. Note that it is convenient to declare the MD cell as a derive class of FC. We conclude this section by pointing out that the language C++ can be used to develop an ecient and modular implementation of the ADT for scienti c computation, in particular for adaptive mesh problem. Maximal exibility and extensibility can be achieved. A good construction of the ADT hierarchy plays an important role in getting an ecient implementation. 7. Computational results. Several examples are presented. The rst example validates the scheme described in subsection 4.1. The others examples treat models of water ooding in porous media. In the second test a comparison is given between the upwind scheme and the MUSCL scheme presented in subsection 4.2. 7.1. Poisson equation. The rst example demonstrates the eciency of the FAC method on a composite grid. To test this algorithm we solve numerically a classical equation of Poisson by a the FAC method on a composite mesh and classic FMGM (Full multigrid method) on global regular mesh :
(
where
?u = 0 u? = g(x; y)
in = (0; 1) (0; 1) on ? = @
(x + y + 2)) : g(x; y) = cos(4(x ? y)) sinh(4sinh(16 )
The analytic solution is u(x; y) = g(x; y) in . The solution is localized around the point (1; 1). In the FAC method, the full multigrid scheme is applied where the switching re nement criterion is based on truncation error. A V (2; 2) cycle is used in both of the methods
. Poisson equation, composite mesh of 5 levels and solution (Number of cells = 1231)
Fig. 6
Figure 6 depicts the composite mesh of 5 levels, the coarse grid is 10 10 grids. A linear interpolation is used to draw the composite solution on a 160 160 mesh. Note that the re ned composite grid localizes and closes to the solution.
OOP and FAC method in reservoir simulation
15
Table 3
Run statistics for Poisson equation
levels L 3 4 5
Num of cells FAC FMGM 226 40 40 544 80 80 1231 160 160
CPU time FAC FMGM 0:40 3:32 0:99 8:64 4:45 54:26
Max{error 10?3 Conv Factor FAC FMGM FAC FMGM 5:43 5:44 0.108 0.108 1:70 1:75 0.110 0.112 0:50 0:56 0.115 0.117
The Table 3 gives the run statistics and convergence factors to compare the FAC method on composite grids and the FMGM method on regular grids. The maximum error between the FAC method (resp. FMGM) and the analytic solutions are also tabulated. It is clear that the gain in CPU time is more important when the levels of re nement increase, moreover the quality of obtained composite solution favor the adaptive method.
7.2. Well examples. We have tested two examples treating models of water ooding for a two{phase ow in porous media typical in reservoir simulation [1]. As in the above test, a full multigrid V (2; 2) cycle is used. Saturation equations are computed by MUSCL scheme, but, in the rst test a comparison of upwind and MUSCL scheme is carried out. Two well model. In the region 0 < x < 10, 0 < y < 10 there is one well at x = y = 0+ and one at x = y = 10? with constant water injection and water{oil production rate (4 cm/day) respectively. The data is summarized in table 4. The initial water saturation is the critical saturation (i.e. it is considered to be zero). Table 4
Data of Wells examples
Absolute permeability Porosity Viscosities Relative permeability Pressure of water injection Pressure of production
kx = 10?13 m2 , ky = 10?13 m2 = 0:206 w = 1:0 10?3 pa:s; o = 4:0 10?3 pa.s kw = S 2 ; ko = (1 ? S )2 ; 1500 kpa 1000 kpa
The coarse mesh is 11 11 grids, and four levels are used. The gures 7{8 show the water saturation contours and the composite grid at time 15.0 and 20.0 days. The number of cells on composite grids are compared to 88 88 cells. Note that the location of the re ned area tracks the shock front quite closely during the time. One can remark also that the number of cells in the composite grids is far less then the number of cells in the nest grid. These numbers seem to be sucient to obtain a good approximation for the solution.
16
M. SAAD AND H. ZHANG Table 5
Run statistics for two wells example
Times t 4:0 9:0 15:0 20:0 30:0
Number of cells FAC FMGM 643 88 88 964 88 88 1126 88 88 1513 88 88 2032 88 88
CPU time FAC FMGM 1:01 16:90 1:69 16:94 1:90 16:87 2:53 17:10 3:65 17:05
The run statistics illustrated in Table 5 reveal the gain of adaptive method in computer memory and in CPU time.
Fig. 7. Water saturation contours and composite grid for the two well example, time = 15.0 days, number of cells = 1126
Fig. 8. Water saturation contours and composite grid for the two example, time = 20.0 days, number of cells = 1513
Figure 9 shows a comparison of the saturations, at time 15.0 days, computed by the upwind and MUSCL schemes. Note that the interface water{oil (shock) is better localized by the second scheme.
OOP and FAC method in reservoir simulation
17
Fig. 9. Comparison between upwind (left) and MUSCL (right) schemes on the composite grid, time = 15 days
Five wells model. In this example, ve wells are imposed. We use the same data as the above example. Water is injected (2 cm/day) at the well x = y = 5, The production wells are localized at (x = y = 0+ ), (x = 10? ; y = 0+ ), (x = 0+ y = 10? ) and (x = y = 10? ) respectively, with rate (0.5 cm/day).
The coarse mesh is 21 21 grids and level of re nement is three. Figure 10{11 depict the water saturation contours and the composite grids at times 15 and 60 days respectively. As in the above example, the composite grids track the moving front.
Table 6
Run statistics of ve wells example
Times t 7:0 9:0 15:0 30:0 60:0
Number of cells FAC FMGM 894 84 84 1068 84 84 1311 84 84 1407 84 84 2130 84 84
CPU time FAC FMGM 2:24 17:11 2:63 16:92 3:24 16:99 3:54 17:13 5:21 17:10
Table 6 shows the performance of the adaptive method. One can note that the gain in CPU time is relatively less important than that of the two wells example. It is due to that the shock front is less detached.
18
M. SAAD AND H. ZHANG
Fig. 10. Water saturation contours and composite grid for the ve wells example, time = 15.0 days, number of cells = 1311
Fig. 11. Water saturation contours and composite grid for the ve wells example, time = 60.0 days, number of cells = 2130
We tabulate the average convergence factors in Table 7. To illustrate the eciency of coarse grids correction of multigrid algorithm, we have also proceed Gauss{Seidel relaxation solely on last level. In particular, after the construction of composite grids (by usual way), 4 relaxation are done without coarse grid corrections. The same procedure is eected on the last nest global regular grids. Table 7
Average convergence Factors
Two wells Multigrid FAC FMGM correction 0.236 0.198 Relaxation Composite Finer only 0.892 0.845
Five wells FAC FMGM 0:243 0:204 Composite Finer 0:907 0:912
REFERENCES [1] K. AZIZ and A. SETTARI. Petroleum reservoir simulation. Applied Science Publisher LTD, London, 1979.
OOP and FAC method in reservoir simulation
19
[2] R.E. EWING, B.A. BOYETT, D.K. BABU, and R.F. HEINEMANN. Ecient use of locally re ned grids for multiphase reservoir simulation. SPE 18413, February 1989. [3] R.E. EWING, D. LAZRAROV, and P.S. VASSILEVSKI. Local re nement technics for elliptic problems on cell{centered grids. Technical Report 16, Inst. Sci. Comp. University of Wyoming, 1988. [4] P.A. FORSYTH. Adaptive implicit criteria for two-phase ow with gravity and capillary pressure. SIAM Journal on Scienti c and Statistical Computing, 10(2):227{252, March 1989. [5] A. HARTEN. High resolution schemes for hyperbolic conservation laws. Journal of Computational Physics, 49:357{393, 1983. [6] T. HERMITTE. Maillage adaptatif en espce dans le simulations de gisements petroliers. PhD thesis, Universite de Provence Aix{Marseille I, 1993. [7] B. VAN LEER. Towards the ultimate conservative scheme III, upstream-centered nite dierence schemes for ideal compressible ow. Journal of Computational Physics, 23:263{275, 1977. [8] B. VAN LEER. Towards the ultimate conservative scheme IV, a new approach to the numerical convection. Journal of Computational Physics, 23:276{299, 1977. [9] C. LIU and S. McCORMIC. An ecient multigrid scheme for poisson's equation with jump discontinuities. In Preminlairy proceedings of 4 Cooper Mountain in multigrid method, 1991. [10] S.F. McCORMICK. Multilevel Adaptive Methods for Partial Dierential Equations, volume 6 of Frontiers in Applied Mathematics. SIAM, Philadelphia, 1989. [11] J. L. RANDALL. Numerical Methods for Conservation Laws. Lectures in mathematics. Birkhauser, 1990. [12] P. L. ROE. Approximate riemann solvers, parameter vectors, and dierence schemes. Journal of Computational Physics, 43:357{373, 1981. [13] U. RU EDE. Mathematical and computational techniques for multilevel adaptive methods, volume 13 of Frontiers in Applied Mathematics. SIAM, Philadelphia, 1993. [14] M. SAAD. An accurate numerical algorithm for solving three-phase ow in porous media. Technical Report 96004, Mathematiques Appliquees de Bordeaux, Universite de Bordeaux I, January 1996. [15] M. SAAD and H. ZHANG. Front tracking for two-phase ow in reservoir simulation by adaptive mesh. Numerical methods for P.D.E. to appear. [16] G. H. SCHMIDT and F. J. JACOBS. Adaptive local re nement and multi-grid in numerical reservoir simulation. Journal of Computational Physics, 77:140{165, 1988. [17] D.W. STROUSTRUP. The C++ Programming Language. Addison{Wesley, New York, 1991. [18] H. C. YEE. Construction of explicit and implicit symmetric tvd schemes and their applications. Journal of Computational Physics, 68:151{179, 1987.