1 INTRODUCTION

The simulation of multiphase fluid flow in porous media is of interest in many areas of science and engineering, e.g., biodegradation, hydrology and groundwater flow, and oil and gas reservoirs. Among the plethora of publications in the field, some examples can be found in Amani et al. [1], Lyupa et al. [2], Horgue et al. [3, 4], Deng and Wang [5], Pereira [6], Druetta et al. [7], Fernandez-Berdaguer and Savioli [8], and Akangbou et al. [9]. This type of problems requires solving a system of coupled nonlinear partial differential equations. In particular, when addressing oil and gas reservoir cases the black-oil formulation is usually implemented, which is a simplified version of the compositional model, suitable for nonvolatile hydrocarbons. It considers three phases: gas, oil, and water. There is no mass transfer between water and gas and between water and oil. Besides, the oil phase consists of two components: the dissolved gas measured at standard conditions (GAS) and the residual oil (OIL) that remains at standard conditions when this gas is liberated [10].

The black oil formulation is applied to simulate primary and secondary recovery processes. The mathematical models are built by combining each component’s mass conservation equation with the Darcy’s empirical law, which describes flow in porous media for each phase. Along with these governing equations, state equations (thermodynamic model) and a reservoir description (geological model) are included [11]. The state equations are based on the PVT laboratory measurements, that is, the phase’s volume factors and the gas solubility in oil [10].

In order to test the ability of the finite volume method to properly represent the complex process of both compressible and incompressible multiphase flow in porous media we generalized the toolbox porousMultiphaseFoam [3]. This toolbox was recently developed in the OpenFOAM framework and is able to simulate two-phase incompressible flow in porous media, including capillary effects. Regarding flow in porous media, the main difference between the porousMultiphaseFoam and the general OpenFOAM approach is that the later solves a modified Navier–Stokes equation, not taking into account some essential aspects of reservoir simulation, such as phase saturations, relative permeability and capillary models, and some specific boundary conditions.

In this work, we present the first results of an extended version of the porousMultiphaseFoam, the blackOilFoam, that includes the presence of a third phase and considers fluids and rock compressibility, along with several time-step limitations for dealing with the strong nonlinearities of the equations to be solved.

The paper is organized as follows. In Section 2, the mathematical model of the black oil formulation and its implementation in OpenFOAM is described. Then, in Section 3 we present the numerical model, and finally, in Section 4, we validate the simulator over several case studies.

2 MATHEMATICAL MODEL

The black oil model takes into account three flowing phases: water (w), oil (o), and gas (g), which are allowed to be compressible. It also considers three components: OIL, GAS (hydrocarbon liquid and gas at standard conditions), and WATER.

A compressible multiphase flow in porous media requires the solution of the mass conservation equation for each component, which reads

$$\nabla \cdot \left( {{{c}_{{ij}}}{{\rho }_{j}}{\mathbf{v}_{j}}} \right) + {{q}_{i}} = \frac{\partial }{{\partial t}}\left( {\phi {{c}_{{ij}}}{{\rho }_{j}}{{S}_{j}}} \right).$$
(1)

Here, we introduce the subscripts i for the components (i = G, O, W) and j for the phases (j = g, o, w). The source/sink term, \({{q}_{i}}\), represents the rate of addition/substraction of mass of component i per unit of total volume. Besides, \({{\rho }_{j}}\) is the phase j density, \({{c}_{{ij}}}\) determines the mass fraction of component i in phase j, \({\mathbf{v}_{j}}\) is the Darcy velocity of phase j, and \(\phi \) is the rock porosity.

The \({{c}_{{ij}}}\) coefficients are determined using the hypothesis of the black oil model, i.e., there is no mass transfer between water and the other phases and GAS can be dissolved in the oil phase, but OIL cannot be vaporized into the gas phase. Therefore, \({{c}_{{{\text{Ww}}}}} = {{c}_{{{\text{Gg}}}}} = 1\), \({{c}_{{{\text{Wg}}}}} = {{c}_{{{\text{Wo}}}}} = {{c}_{{{\text{Gw}}}}} = {{c}_{{{\text{Ow}}}}} = {{c}_{{{\text{Og}}}}} = 0\) and \({{c}_{{{\text{Go}}}}}\,\,{\text{and}}\,\,{{c}_{{{\text{Oo}}}}}\) are computed using the PVT parameters (volume factors, \({{B}_{j}}\), and gas solubility in oil, \({{R}_{{\text{s}}}}\)), as: \({{c}_{{{\text{Go}}}}} = {{{{R}_{{\text{s}}}}{{\rho }_{{{\text{GS}}}}}} \mathord{\left/ {\vphantom {{{{R}_{{\text{s}}}}{{\rho }_{{{\text{GS}}}}}} {{{B}_{{\text{o}}}}{{\rho }_{{\text{o}}}}}}} \right. \kern-0em} {{{B}_{{\text{o}}}}{{\rho }_{{\text{o}}}}}}\), \({{c}_{{{\text{Oo}}}}} = {{{{\rho }_{{{\text{OS}}}}}} \mathord{\left/ {\vphantom {{{{\rho }_{{{\text{OS}}}}}} {{{B}_{{\text{o}}}}{{\rho }_{{\text{o}}}}}}} \right. \kern-0em} {{{B}_{{\text{o}}}}{{\rho }_{{\text{o}}}}}}\), where \({{\rho }_{{{\text{GS}}}}}\) and \({{\rho }_{{{\text{OS}}}}}\) denote the gas and oil densities at standard conditions [10]. The Darcy phase velocities \({\mathbf{v}_{j}}\) are determined by Darcy’s law

$${\mathbf{v}_{j}} = - \mathbf{K}\frac{{{{k}_{{rj}}}}}{{{{\mu }_{j}}}}\left( {\nabla {{p}_{j}} - {{\rho }_{j}}g\nabla D} \right).$$
(2)

In Eq. (2), \({{k}_{{rj}}}\) and \({{\mu }_{j}}\) are the relative permeability and viscosity of phase j, D is the depth, and K is the rock absolute permeability tensor.

Combining Eqs. (1) and (2) and dividing by the corresponding component density, the governing equations for gas, oil, and water components result in

$$\nabla \cdot \left( {\mathbf{K}\frac{{{{k}_{{{\text{rg}}}}}}}{{{{\mu }_{{\text{g}}}}{{B}_{{\text{g}}}}}}\left( {\nabla {{p}_{{\text{g}}}} - {{\rho }_{{\text{g}}}}g\nabla D} \right) + \mathbf{K}\frac{{{{k}_{{{\text{ro}}}}}{{R}_{{\text{s}}}}}}{{{{\mu }_{{\text{o}}}}{{B}_{{\text{o}}}}}}\left( {\nabla {{p}_{{\text{o}}}} - {{\rho }_{{\text{o}}}}g\nabla D} \right)} \right) + q_{{\text{G}}}^{{{\text{SC}}}} = \frac{\partial }{{\partial t}}\left[ {\phi \left( {\frac{{{{S}_{{\text{g}}}}}}{{{{B}_{{\text{g}}}}}} + \frac{{{{R}_{{\text{s}}}}}}{{{{B}_{{\text{o}}}}}}{{S}_{{\text{o}}}}} \right)} \right],$$
(3a)
$$\nabla \cdot \left( {\mathbf{K}\frac{{{{k}_{{{\text{ro}}}}}}}{{{{\mu }_{{\text{o}}}}{{B}_{{\text{o}}}}}}\left( {\nabla {{p}_{{\text{o}}}} - {{\rho }_{{\text{o}}}}g\nabla D} \right)} \right) + q_{{\text{O}}}^{{{\text{SC}}}} = \frac{\partial }{{\partial t}}\left( {\frac{\phi }{{{{B}_{{\text{o}}}}}}{{S}_{{\text{o}}}}} \right),$$
(3b)
$$\nabla \cdot \left( {\mathbf{K}\frac{{{{k}_{{{\text{rw}}}}}}}{{{{\mu }_{{\text{w}}}}{{B}_{{\text{w}}}}}}\left( {\nabla {{p}_{{\text{w}}}} - {{\rho }_{{\text{w}}}}g\nabla D} \right)} \right) + q_{{\text{W}}}^{{{\text{SC}}}} = \frac{\partial }{{\partial t}}\left( {\frac{\phi }{{{{B}_{{\text{w}}}}}}{{S}_{{\text{w}}}}} \right),$$
(3c)

where \(q_{i}^{{{\text{SC}}}}\) denotes the volumetric injection or production rate per unit of total volume of each component i. Eqsuations (3) are then reformulated by replacing Eq. (3a) by the sum of Eqs. (3a)–(3c), and this latter equation is called the pressure equation.

In order to simplify the pressure equation formulation, we first adopt the notation in [3], defining the phase mobility \({{{\mathbf{M}}}_{j}} = {{{\mathbf{K}}{{k}_{{rj}}}} \mathord{\left/ {\vphantom {{{\mathbf{K}}{{k}_{{rj}}}} {{{\mu }_{j}}{{B}_{j}}}}} \right. \kern-0em} {{{\mu }_{j}}{{B}_{j}}}}\) and the gravitational contribution \({{{\mathbf{L}}}_{j}} = {{{\mathbf{M}}}_{j}}{{\rho }_{j}} \), both in SC (standard condition).

Secondly, we relate the phase pressures using capillary pressures, which depend on phase saturations. In a two-phase system, the capillary pressure is defined as the difference between the nonwetting and wetting phase pressures. Therefore, in a gas–oil–water system there are two independent capillary pressures, \({{p}_{{{\text{cow}}}}}\) and \({{p}_{{{\text{cgo}}}}}\). For water-wet rocks, \({{p}_{{{\text{cow}}}}} = {{p}_{{\text{o}}}} - {{p}_{{\text{w}}}}\) and \({{p}_{{{\text{cgo}}}}} = {{p}_{{\text{g}}}} - {{p}_{{\text{o}}}}\) (gas phase is always nonwetting).

Finally, we group all source/sink terms together, defining \(q_{{\text{T}}}^{{{\text{SC}}}} = q_{{\text{W}}}^{{{\text{SC}}}} + q_{{\text{O}}}^{{{\text{SC}}}} + q_{{\text{G}}}^{{{\text{SC}}}}\). The resulting pressure equation then reads

$$\begin{gathered} \nabla \cdot \left\{ {\left[ {{{M}_{{\text{g}}}} + \left( {1 + {{R}_{{\text{s}}}}} \right){{M}_{{\text{o}}}} + {{M}_{{\text{w}}}}} \right]\nabla {{p}_{{\text{o}}}} + {{M}_{{\text{g}}}}\nabla {{p}_{{{\text{cgo}}}}} - {{M}_{{\text{w}}}}\nabla {{p}_{{{\text{cow}}}}} - \left[ {{{L}_{{\text{g}}}} + \left( {1 + {{R}_{{\text{s}}}}} \right){{L}_{{\text{o}}}} + {{L}_{{\text{w}}}}} \right]g\nabla D} \right\} \\ + \,\,q_{{\text{T}}}^{{{\text{SC}}}} = \frac{\partial }{{\partial t}}\left[ {\phi \left( {\frac{{{{S}_{{\text{g}}}}}}{{{{B}_{{\text{g}}}}}} + \frac{{1 + {{R}_{{\text{s}}}}}}{{{{B}_{{\text{o}}}}}}{{S}_{{\text{o}}}} + \frac{{{{S}_{{\text{w}}}}}}{{{{B}_{{\text{w}}}}}}} \right)} \right]. \\ \end{gathered} $$
(4)

Besides, since the saturation of each phase represents its volume fraction in the poral volume, it follows that

$${{S}_{{\text{g}}}} + {{S}_{{\text{o}}}} + {{S}_{{\text{w}}}} = 1.$$
(5)

Hence, we end up with the problem of solving Eqs. (3b), (3c), (4), and (5).

2.1 Rate Calculations

There are different methods to represent a well, and one of them is using the source/sink terms in Eqs. (3) and (4). In blackOilFoam an injector well is simply considered as a source term defined by a volumetric injection rate at SC of a given component (G, O, or W). On the other hand, a production well is represented as a sink term, subjected to a fixed rate or pressure constraint.

The rate constraints involve a constant oil rate or total fluid rate, meaning that \(q_{{\text{O}}}^{{{\text{SC}}}}\) is either given or computed as \(q_{{\text{O}}}^{{{\text{SC}}}} = \left( {{{{{\lambda }_{{\text{o}}}}} \mathord{\left/ {\vphantom {{{{\lambda }_{{\text{o}}}}} {{{\lambda }_{{\text{T}}}}}}} \right. \kern-0em} {{{\lambda }_{{\text{T}}}}}}} \right){{q_{{\text{T}}}^{{{\text{RC}}}}} \mathord{\left/ {\vphantom {{q_{{\text{T}}}^{{{\text{RC}}}}} {{{B}_{{\text{o}}}}}}} \right. \kern-0em} {{{B}_{{\text{o}}}}}}\), with \({{\lambda }_{j}} = {{{{k}_{{rj}}}} \mathord{\left/ {\vphantom {{{{k}_{{rj}}}} {{{\mu }_{j}}}}} \right. \kern-0em} {{{\mu }_{j}}}}\) and \({{\lambda }_{{\text{T}}}} = {{\lambda }_{{\text{g}}}} + {{\lambda }_{{\text{o}}}} + {{\lambda }_{{\text{w}}}}\). Note that the total rate is given in RC (reservoir condition), and can be expressed in SC as

$$q_{{\text{T}}}^{{{\text{SC}}}} = \left( {{{{{\lambda }_{{\text{g}}}}} \mathord{\left/ {\vphantom {{{{\lambda }_{{\text{g}}}}} {{{B}_{{\text{g}}}}}}} \right. \kern-0em} {{{B}_{{\text{g}}}}}} + (1 + {{R}_{{\text{s}}}}){{{{\lambda }_{{\text{o}}}}} \mathord{\left/ {\vphantom {{{{\lambda }_{{\text{o}}}}} {{{B}_{{\text{o}}}}}}} \right. \kern-0em} {{{B}_{{\text{o}}}}}} + {{{{\lambda }_{{\text{w}}}}} \mathord{\left/ {\vphantom {{{{\lambda }_{{\text{w}}}}} {{{B}_{{\text{w}}}}}}} \right. \kern-0em} {{{B}_{{\text{w}}}}}}} \right){{q_{{\text{T}}}^{{{\text{RC}}}}} \mathord{\left/ {\vphantom {{q_{{\text{T}}}^{{{\text{RC}}}}} {{{\lambda }_{{\text{T}}}}}}} \right. \kern-0em} {{{\lambda }_{{\text{T}}}}}}.$$

On the other hand, when the well is under a pressure constraint, a flowing bottomhole pressure \(\left( {{{p}_{{{\text{wf}}}}}} \right)\) and a wellbore index (WI) have to be specified. Then the oil rate is computed as \(q_{{\text{O}}}^{{{\text{SC}}}} = \left( {{{{{\lambda }_{{\text{o}}}}} \mathord{\left/ {\vphantom {{{{\lambda }_{{\text{o}}}}} {{{B}_{{\text{o}}}}}}} \right. \kern-0em} {{{B}_{{\text{o}}}}}}} \right){\text{WI}}\left( {p - {{p}_{{{\text{wf}}}}}} \right),\,\,\,\,p > {{p}_{{{\text{wf}}}}}\), where p refers to the pressure of the cell that contains the well.

In both cases, however, water and gas rates are computed as \(q_{{\text{W}}}^{{{\text{SC}}}} = \left( {{{{{\lambda }_{{\text{w}}}}{{B}_{{\text{o}}}}} \mathord{\left/ {\vphantom {{{{\lambda }_{{\text{w}}}}{{B}_{{\text{o}}}}} {{{\lambda }_{{\text{o}}}}{{B}_{{\text{w}}}}}}} \right. \kern-0em} {{{\lambda }_{{\text{o}}}}{{B}_{{\text{w}}}}}}} \right)q_{{\text{O}}}^{{{\text{SC}}}}\) and \(q_{{\text{G}}}^{{{\text{SC}}}} = \left( {{{{{\lambda }_{{\text{g}}}}{{B}_{{\text{o}}}}} \mathord{\left/ {\vphantom {{{{\lambda }_{{\text{g}}}}{{B}_{{\text{o}}}}} {{{\lambda }_{{\text{o}}}}{{B}_{{\text{g}}}}}}} \right. \kern-0em} {{{\lambda }_{{\text{o}}}}{{B}_{{\text{g}}}}}} + {{R}_{{\text{s}}}}} \right)q_{{\text{O}}}^{{{\text{SC}}}}\), respectively.

3 NUMERICAL MODEL

We developed a solver based on the philosophy of the opensource platform OpenFOAM [12]. As a collocated finite volume-based code, all variables are calculated in the cell center, and interpolated to the faces of the cell when needed.

In order to simplify even further the formulation presented in Section 2, we use the notation in [3] and define three different fluxes that depend on pressure gradient, gravity, and capillary pressure, namely

$${\boldsymbol{\psi }_{{\text{p}}}} = {{{\mathbf{M}}}_{{{{{\text{w}}}_{{{\text{c}} \to {\text{f}}}}}}}} + \left( {1 + {{R}_{{\text{s}}}}} \right){{{\mathbf{M}}}_{{{{{\text{o}}}_{{{\text{c}} \to {\text{f}}}}}}}} + {{{\mathbf{M}}}_{{{{{\text{g}}}_{{{\text{c}} \to {\text{f}}}}}}}}\nabla {{p}_{{\text{o}}}} \cdot {{{\mathbf{S}}}_{{\text{f}}}},$$
(6a)
$${\boldsymbol{\psi }_{{{\text{gr}}}}} = {{{\mathbf{L}}}_{{{{{\text{w}}}_{{{\text{c}} \to {\text{f}}}}}}}} + \left( {1 + {{R}_{{\text{s}}}}} \right){{{\mathbf{L}}}_{{{{{\text{o}}}_{{{\text{c}} \to {\text{f}}}}}}}} + {{{\mathbf{L}}}_{{{{{\text{g}}}_{{{\text{c}} \to {\text{f}}}}}}}}g\nabla D \cdot {{{\mathbf{S}}}_{{\text{f}}}},$$
(6b)
$${\boldsymbol{\psi }_{{{\text{pc}}}}} = {\boldsymbol{\psi }_{{{\text{pcow}}}}} - {\boldsymbol{\psi }_{{{\text{pcgo}}}}} = \left[ {{{{\mathbf{M}}}_{{\text{w}}}}\left( {\frac{{d{{p}_{{{\text{cow}}}}}}}{{d{{S}_{{\text{w}}}}}}\nabla {{S}_{{\text{w}}}}} \right) - {{{\mathbf{M}}}_{{\text{g}}}}\left( {\frac{{d{{p}_{{{\text{cgo}}}}}}}{{d{{S}_{{\text{g}}}}}}\nabla {{S}_{{\text{g}}}}} \right)} \right] \cdot {{S}_{{\text{f}}}}.$$
(6c)

Here, \({{{\mathbf{S}}}_{{\text{f}}}}\) is the outward normal vector of the cell face, whose magnitude is the face area. The operator c → f implies that the cell-centered value of the variable is interpolated to obtain the face-centered value of the variable in each face of the computational grid. Customary interpolation schemes are upwind for relative permeabilities and harmonic for absolute permeability.

The global flux is then \(\psi = {\boldsymbol{\psi }_{{\text{p}}}} - {\boldsymbol{\psi }_{{{\text{gr}}}}} - {\boldsymbol{\psi }_{{{\text{pc}}}}}\) and the fluxes for each phase may be written as

$${\boldsymbol{\psi }_{{\text{w}}}} = \frac{{{{{\mathbf{M}}}_{{{{{\text{w}}}_{{{\text{c}} \to {\text{f}}}}}}}}}}{{{{{\mathbf{M}}}_{{\text{f}}}}}}{\boldsymbol{\psi }_{{\text{p}}}} - \frac{{{{{\mathbf{L}}}_{{{{{\text{w}}}_{{{\text{c}} \to {\text{f}}}}}}}}}}{{{{{\mathbf{L}}}_{{\text{f}}}}}}{\boldsymbol{\psi }_{{{\text{gr}}}}} - {\boldsymbol{\psi }_{{{\text{pcow}}}}},\,\,\,\,{\boldsymbol{\psi }_{{\text{o}}}} = \frac{{{{{\mathbf{M}}}_{{{{{\text{o}}}_{{{\text{c}} \to {\text{f}}}}}}}}}}{{{{{\mathbf{M}}}_{{\text{f}}}}}}{\boldsymbol{\psi }_{{\text{p}}}} - \frac{{{{{\mathbf{L}}}_{{{{{\text{o}}}_{{{\text{c}} \to {\text{f}}}}}}}}}}{{{{{\mathbf{L}}}_{{\text{f}}}}}}{\boldsymbol{\psi }_{{{\text{gr}}}}},\,\,{\text{and}}\,\,{\boldsymbol{\psi }_{{\text{g}}}} = \psi - {\boldsymbol{\psi }_{{\text{w}}}} - {\boldsymbol{\psi }_{{\text{o}}}},$$

where \({{{\mathbf{M}}}_{{\text{f}}}} = {{{\mathbf{M}}}_{{{{{\text{w}}}_{{{\text{c}} \to {\text{f}}}}}}}} + (1 + {{R}_{{\text{s}}}}){{{\mathbf{M}}}_{{{{{\text{o}}}_{{{\text{c}} \to {\text{f}}}}}}}} + {{{\mathbf{M}}}_{{{{{\text{g}}}_{{{\text{c}} \to {\text{f}}}}}}}}\) and \({{{\mathbf{L}}}_{{\text{f}}}} = {{{\mathbf{L}}}_{{{{{\text{w}}}_{{{\text{c}} \to {\text{f}}}}}}}} + (1 + {{R}_{{\text{s}}}}){{{\mathbf{L}}}_{{{{{\text{o}}}_{{{\text{c}} \to {\text{f}}}}}}}} + {{{\mathbf{L}}}_{{{{{\text{g}}}_{{{\text{c}} \to {\text{f}}}}}}}}\).

The resulting system of nonlinear equations is treated by a sequential approach: the IMPES method [10, 13, 14]. In this scenario, saturations and pressure are decoupled. One of the biggest problems that arise when simulating three-phase flow is that the sum of the phase saturations rarely adds up to unity, leading to material balance errors. The usual practice is to calculate N −1 phase saturations, leaving the last one to comply with the restriction of unitary total sum. The drawback of this procedure is that it leads to saturations which are inconsistent with the pressure field.

To overcome this problem, we used the following technique described in [15]. The pressure equation (Eq. (4)) is first solved implicitly and then the saturation equations (Eqs. (3)) are solved explicitly. Let \(\Delta S = 1 - \sum\nolimits_{i = 1}^N {{{S}_{i}}} \) be the saturation residual, related to a pressure change through a secant iteration procedure. Then,

$${{p}^{{k + 1}}} = {{p}^{k}} - \frac{{{{p}^{k}} - {{p}^{{k - 1}}}}}{{\Delta {{S}^{k}} - \Delta {{S}^{{k - 1}}}}}\Delta {{S}^{k}},$$
(6)

where \({{p}^{{k + 1}}}\) represents the pressure at which the saturation residual satisfies a specified tolerance limit. Given the three-point calculation (k − 1, k, and k + 1), an initial guess for the pressure is required. A sound approximation is given by \({{p}^{1}} = {{p}^{0}} \pm 0.1\left| {\delta p} \right|\), with \(\delta p\) the original pressure change during the time step. Then, the pressure needs to be updated and the saturations corrected simultaneously in order to maintain the consistency between the fields.

It is important to point out that the fluxes calculated at the cell faces at the beginning of the time step remain unaltered throughout this iterative process. In this way we manage to reduce the mass balance errors while preserving the consistency of the calculations (i.e., we correct the mass computation of each component while calculations remain volume-conservative). Other simulators, such as public domain software BOAST [11], compute a simple material balance based on the volumes-in-place at the beginning and the end of the time step, considering the injected and produced fluids, and simply report the results without correcting these imbalances.

Furthermore, given the strong nonlinearities mostly due to the relative permeabilities and capillary pressure functions, the explicit treatment of some terms leads to numerical instabilities. Therefore, time-step limitations are required and three restrictions have been implemented. The first two are simply user-defined fixed \(\Delta {{t}_{{\max }}}\) and \(\Delta {{S}_{{\max }}}\). For the third restriction, the user is required to choose the preferred method between the following three: the first one related to the Courant number [16], the second one based on fluxes computations including fluid and reservoir properties [17], and the third one associated with the stability criterion of Todd et. al. [18]. Note that these restrictions correspond to those in [3], and are generalized in the solver for three-phase calculations.

4 RESULTS

As a preliminary and almost obligated test of blackOilFoam, we addressed the classical Buckley–Leverett displacement problem: a 1D two-phase incompressible case with semi-analytical solution, in which water is injected at one end displacing the oil originally present in the domain [19]. Although we skip here most of the details for brevity purposes, it is important to say that the solution is characterized by a discontinuity representing the sharp front of saturation of the displacing fluid. In a numerical solution, however, the front is usually somehow diffused, making this difference a suitable candidate for comparison purposes. Our solver had no difficulties in dealing with this problem, producing results in which the front lies within a 5% error (\({{L}_{2}}\)-norm) from the semi-analytical solution.

After this preliminary step turned successful, we were able to approach more complex cases involving the three phases the code should be able to deal with. We started by simulating Example 1 in [20], a 1D saturated case with three-phase compressible flow, nonnegligible formation compressibility, and capillary effects. Then, we engaged a 2D problem discussed in [21], considering gas-oil compressible flow and the presence of a third irreducible water phase, with negligible rock compressibility and capillary effects. Finally, we focused on the 1st SPE comparative case, which consists in a 3D three-phase compressible problem with gas injection [22].

4.1 1D Compressible Case

Example 1 in [20] considers a linear compressible formation of length \(L = 1000\,\,{\text{m}}\) with three-phase compressible flow. Pressure is set as constant Dirichlet conditions at both ends, being \(p(0) = 19\,\,{\text{MPa}}\) and \(p(L) = 16\,\,{\text{MPa}}\), with the initial saturation profiles \({{S}_{{{\text{gi}}}}}\), \({{S}_{{{\text{oi}}}}}\), and \({{S}_{{{\text{wi}}}}}\) shown in Fig. 1.

Fig. 1.
figure 1

Water, oil and gas saturations at 0, 100, 500, and 1000 days: 1D compressible case.

Given the compressible nature of the phases, we use the PVT parameters given in [20], modeled as \({{R}_{{\text{s}}}} = 7.25 \times {{10}^{{ - 6}}}{{p}_{{\text{o}}}}\), \({{B}_{{\text{w}}}} = 1 - 2.61 \times {{10}^{{ - 9}}}{{p}_{{\text{o}}}}\), \({{B}_{{\text{o}}}} = 1 + 2.17 \times {{10}^{{ - 8}}}{{p}_{{\text{o}}}}\), and \({{B}_{{\text{g}}}} = {{\left( {6 + 8.7 \times {{{10}}^{{ - 6}}}{{p}_{{\text{o}}}}} \right)}^{{ - 1}}}\), where \({{p}_{{\text{o}}}}\) is in [Pa], \({{B}_{j}}\) in \(\left[ {{{{{{\text{m}}}^{{\text{3}}}}{\text{RC}}} \mathord{\left/ {\vphantom {{{{{\text{m}}}^{{\text{3}}}}{\text{RC}}} {{{{\text{m}}}^{{\text{3}}}}{\text{SC}}}}} \right. \kern-0em} {{{{\text{m}}}^{{\text{3}}}}{\text{SC}}}}} \right]\) and \({{R}_{{\text{s}}}}\) in \(\left[ {{{{\text{m}}_{{{\text{gas}}}}^{3}{\text{SC}}} \mathord{\left/ {\vphantom {{{\text{m}}_{{{\text{gas}}}}^{3}{\text{SC}}} {{\text{m}}_{{{\text{oil}}}}^{3}{\text{SC}}}}} \right. \kern-0em} {{\text{m}}_{{{\text{oil}}}}^{3}{\text{SC}}}}} \right]\). Besides, the phase viscosities are given in [cp] by \({{\mu }_{{\text{o}}}} = 0.35\), \({{\mu }_{{\text{g}}}} = 0.012 + 4.35 \times {{10}^{{ - 9}}}{{p}_{{\text{o}}}}\), and \({{\mu }_{{\text{w}}}} = 0.8 - 1.45 \times {{10}^{{ - 8}}}{{p}_{{\text{o}}}}\), and the formation compressibility is accounted for by using a porosity linearly dependent on pressure, i.e., \(\phi = 0.2 + 2.9 \times {{10}^{{ - 10}}}{{p}_{{\text{o}}}}\).

Rankin and Riviere [20] assume \(K = 100\,{\text{mD}}\) and the following relative permeability and capillary pressure (in Pa) functions:

$${{k}_{{{\text{rw}}}}} = S_{{\text{w}}}^{2},\,\,\,\,{{k}_{{{\text{rg}}}}} = S_{{\text{g}}}^{2},\,\,\,\,{{k}_{{{\text{ro}}}}} = \left( {1 - {{S}_{{\text{w}}}} - {{S}_{{\text{g}}}}} \right)\left( {1 - {{S}_{{\text{w}}}}} \right)\left( {1 - {{S}_{{\text{g}}}}} \right),$$
$${{p}_{{{\text{cow}}}}} = \frac{{43{\kern 1pt} 437}}{{\ln \left( {\frac{{0.01}}{{1 - {{S}_{{{\text{wc}}}}}}}} \right)}}\ln \left( {\frac{{{{S}_{{\text{w}}}} - {{S}_{{{\text{wc}}}}} + 0.01}}{{1 - {{S}_{{{\text{wc}}}}}}}} \right),\,\,\,\,{{p}_{{{\text{cgo}}}}} = \frac{{26{\kern 1pt} 889.6}}{{\ln \left( {\frac{{0.01}}{{1 - {{S}_{{{\text{wc}}}}} - {{S}_{{{\text{gc}}}}}}}} \right)}}\ln \left( {\frac{{1 - {{S}_{{\text{g}}}} - {{S}_{{{\text{wc}}}}} - {{S}_{{{\text{or}}}}} + 0.01}}{{1 - {{S}_{{{\text{wc}}}}} - {{S}_{{{\text{or}}}}}}}} \right).$$

For this case both the irreducible water and the residual oil saturations are \({{S}_{{{\text{wc}}}}} = {{S}_{{{\text{or}}}}} = 0\).

We analyzed the evolution of the problem for a period of 1000 days with a uniform mesh of 400 cells using an initial and maximum ∆t = 0.005 days. This ∆t remained constant throughout the run, verifying the stability restrictions imposed in the software. Figure 1 shows that the saturations obtained with the blackOilFoam reproduce the shape of the profiles with great accuracy, specifically the location of the maximum and minimum of the oil and gas saturations, respectively. Errors are, as expected, greater for the gas saturation and differ up to a 2.2% (\({{L}_{2}}\)-norm) from [20].

4.2 2D Compressible Case

In this case we compared the performance of the blackOilFoam with the Single Well simulator developed in [21] and the public domain simulator BOAST [11]. We simulated the radial flow of oil and gas towards a well in an initially undersaturated reservoir \(\left( {{{S}_{{\text{o}}}} = 0.88} \right)\) with water present as a third immobile phase \(\left( {{{S}_{{{\text{wc}}}}} = 0.12} \right)\). Geometric and fluid properties are as follows: \(h = 9.144{\text{m}}\) is the reservoir thickness; \({{r}_{e}} = 233.87\,{\text{m}}\) and \({{r}_{{\text{w}}}} = 0.10\,{\text{m}}\) are the external and well radii, respectively; \({{S}_{{{\text{or}}}}} = 0.40\) and \({{S}_{{{\text{gc}}}}} = 0.01\) are the residual oil and critical gas saturations; and \({{P}_{{\text{b}}}} = 27.67\,\,{\text{MPa}}\) is the bubble point pressure. The reservoir is initially at \({{p}_{{\text{o}}}} = 31.02\,\,{\text{MPa}}\). Regarding the rock parameters, Savioli and Bidner [21] assume a porosity \(\phi = 0.30\) and an absolute permeability \(K = {{10}^{{ - 13}}}\,\,{{{\text{m}}}^{2}}\,\,(100\,\,{\text{mD}})\).

The PVT parameters and the gas and oil viscosities are listed in Table 1. The relative permeabilities of the gas and oil phases are defined by

$${{k}_{{{\text{ro}}}}} = k_{{{\text{ro}}}}^{*}{{\left( {\frac{{{{S}_{{\text{o}}}} - {{S}_{{{\text{or}}}}}}}{{1 - {{S}_{{{\text{or}}}}} - {{S}_{{{\text{gc}}}}} - {{S}_{{{\text{wc}}}}}}}} \right)}^{{{{n}_{{\text{o}}}}}}},\,\,\,\,{{k}_{{{\text{rg}}}}} = k_{{{\text{rg}}}}^{*}{{\left( {\frac{{1 - {{S}_{{\text{o}}}} - {{S}_{{{\text{gc}}}}} - {{S}_{{{\text{wc}}}}}}}{{1 - {{S}_{{{\text{or}}}}} - {{S}_{{{\text{gc}}}}} - {{S}_{{{\text{wc}}}}}}}} \right)}^{{{{n}_{{\text{g}}}}}}}$$
Table 1. Fluid properties of the 2D compressible case

for the specific values \(k_{{{\text{ro}}}}^{*} = 0.92\), \(k_{{{\text{rg}}}}^{*} = 0.272\), \({{n}_{{\text{o}}}} = 1.654\), and \({{n}_{{\text{g}}}} = 1.960\). Capillary pressure and rock compressibility are considered null.

From the cases shown in [21], we approached the one with a total production rate of \(q_{{\text{T}}}^{{{\text{RC}}}} = 0.00055\,\,{{{{{\text{m}}}^{3}}} \mathord{\left/ {\vphantom {{{{{\text{m}}}^{3}}} {\text{s}}}} \right. \kern-0em} {\text{s}}}\) (300 barrels/day).

It is important to point out that the grids adopted by all three simulators are different. BOAST only handles Cartesian coordinates, and therefore, to simulate a radial flow towards a well, it considers a 41 × 41 × 1 grid, with the producer located in the center cell. The considered area is equivalent to that of the radial case. The Single Well simulator, in turn, makes use of a 1D approach with a logarithmic-scaled grid, with smaller cells towards the producer’s end of the domain. Finally, as blackOilFoam is able to work with any coordinate system, it adopted cylindrical coordinates, defining 51 cells equally distributed along the radial direction.

The evolutions of pressure and oil saturation in the well are shown in Figs. 2 and 3, respectively. We observe that during the first 50 days, period in which the case responds to single-phase flow, both blackOilFoam and Single Well simulators coincide with the analytical solution. BOAST, in turn, shows a slower pressure decrease, probably due to the coarser grid. After that, the pressure reaches the bubble point value and gas is liberated. The pressure solution for the two-phase problem, however, is now slightly higher for blackOilFoam than for Single Well and BOAST, and consequently, so is the oil saturation. It seems natural to expect that the finer the grid, the more detailed the solution, and for the Single Well simulator it appears to be the case. Moreover, even though BOAST works with a coarser grid than blackOilFoam, it also reported a nonnegligible material imbalance: a 7.75% decrease of oil and a 5.8% increase of gas phase volumes. These imbalances led to higher gas saturations and, consequently, to lower pressure. It is important to highlight, however, that, even though Figs. 2 and 3 show the deviations in detail, the errors in \({{L}_{2}}\)-norm lie within 1.25 and 2.4% for pressure and 1% and 2.6% for saturation, from BOAST and Single Well, respectively.

Fig. 2.
figure 2

Evolution of the bottomhole pressure in the wellbore cell: 2D compressible case.

Fig. 3.
figure 3

Evolution of the oil saturation in the wellbore cell: 2D compressible case.

4.3 3D Compressible Case

The 1st SPE case study gathered several oil companies to test and compare their solvers using a three-dimensional three-phase compressible problem [22]. It consists of an initially undersaturated three-layered anisotropic reservoir, with gas injection and oil production. Water is also present, only as an immobile phase. We considered the case with constant bubble-point pressure, set equal to the original value (Case 1).

The structured grid consists of 300 uniform cells (10 × 10 × 3), with ∆x = ∆y = 304.8 m (1000 ft). The wells are located in opposite corners of the reservoir: the injector in (1, 1, 1) and the producer in (10, 10, 3). Data and constrains of the case are given in Tables 2 and 3, whereas the PVT functions and the relative permeabilities are shown in Tables 4–7.

Table 2. Stratification and reservoir properties of the 3D compressible case
Table 3. Reservoir data and constraints of the 3D compressible case
Table 4. Saturated Oil and Water PVT Functions of the 3D compressible Case
Table 5. Undersaturated oil and water PVT functions of the 3D compressible case
Table 6. Gas PVT functions of the 3D compressible case
Table 7. Relative permeability data of the 3D compressible case

In this case, the producer operates at constant oil rate (\(0.0368\,\,{{{{{\text{m}}}^{3}}} \mathord{\left/ {\vphantom {{{{{\text{m}}}^{3}}} {\text{s}}}} \right. \kern-0em} {\text{s}}}\), or \(20{\kern 1pt} 000\,{{{\text{STB}}} \mathord{\left/ {\vphantom {{{\text{STB}}} {\text{D}}}} \right. \kern-0em} {\text{D}}}\)) until the corresponding computed bottomhole pressure reaches the minimum value of \(6.895\,\,{\text{MPa}}\) \((1000\,\,{\text{psi}})\). From that moment on, the well production condition changes to constant bottomhole pressure, equal to that minimum value. The initial and maximum \(\Delta t\) are \(\Delta t = 0.005\) days and \(\Delta {{t}_{{\max }}} = 0.5\) days, respectively.

Results were compared to those reported by [22]. Given that the companies were asked to report their results annually, we also ran the case using the public domain simulator BOAST [11] in order to get a more detailed historic evolution to compare with.

In Fig. 4 we show the evolution of pressure in both the injector and the producer well cells. From the seven companies that participated in [22] we chose to compare our results with only those of Shell, Intercomp and Mobil to enhance the readability of the figures. The first two are based on the IMPES method, while the latter is a fully implicit solver.

Fig. 4.
figure 4

Evolution of pressure at producer and injector: 3D compressible case.

A similar behavior for the pressure evolution is observed in all five simulators. However, the fully implicit solver reached a lower pressure maximum, while the IMPES solvers, including the blackOilFoam, obtained higher values throughout the 10-year period.

It is important to remember that wells are modelled as source/sink terms and that the pressure in the well is not calculated explicitly from the flow rates. However, they do impact on the pressure of the cell that contains the well. Given that the pressure we report is that of the cell and not of the well itself, this difference may account for the slight deviation of our results. In addition, the cumulative material balance error in BOAST of nearly 8.5% increase of the gas phase volume certainly favored the early arrival of gas to the producer and hence, the pressure to peak sooner. There is no available information about this subject for the other solvers.

Finally, gas saturation and gas-oil ratio in the producer are displayed in Figs. 5 and 6, respectively. These results are in excellent agreement with those reported in [22] and the ones obtained using BOAST. The deviations between years 1 and 3 in both figures are probably due to two main reasons. The first one is that Shell, Intercomp and Mobil reported yearly results, but fail to explain the interpolation method used to determine the curve, thus making it impossible to know reliably the moment the gas arrives at the producer. The second reason, in turn, is tied to the pressure evolution, i.e., the pressure drops once gas saturation appears at the producer. Since the blackOilFoam solver reached the pressure maximum later, it is natural that the gas saturation and GOR are delayed as well.

Fig. 5.
figure 5

Evolution of gas saturation at the producer: 3D compressible case.

Fig. 6.
figure 6

Evolution of gas-oil ratio (GOR) at the producer: 3D compressible case.

5 CONCLUSIONS

The formulation of blackOilFoam, a new OpenFOAM application to address black-oil problems, was presented and successfully tested in several cases. The solver is able to deal with three-phase flow in porous media including fluids and rock compressibility. Aside from the classical Buckley–Leverett testing problem, three different cases were considered, namely

a three-phase compressible flow in a saturated 1D reservoir, with nonnegligible capillary effects and rock compressibility;

a radial two-phase compressible flow, in the presence of a third irreducible phase, in an initially undersaturated reservoir; and

a three-phase compressible flow, with gas injection, in an initially undersaturated 3D reservoir.

The comparison against semi-analytical solutions and results from other authors has proven the solver to successfully represent both compressible and incompressible multiphase flow in porous media.

Furthermore, even though OpenFOAM has the versatility to work with grids of wide range of complexity, the simple coarse grids used in the different cases have proven to give sound and accurate solutions, thus demonstrating the robustness of the solver.

As future work we expect to condition the code for public release and make further developments to include multiphase flow in fractured porous media.