1 Introduction

Continuum scale simulation of multi-component multi-phase (MCMP) flow in porous media is often used to better understand a range of reservoir pore-space exploitation problems including petroleum production, geothermal energy, groundwater management and waste disposal. Generally, it is assumed that multiple fluid phases co-exist as volume fractions of an infinitesimal volume. These phases typically include aqueous liquid, non-aqueous liquid, gas and solid. Each phase can represent a mixture of multiple components (e.g., \(\hbox {H}_2\hbox {O}\), \(\hbox {CO}_2\) and \(\hbox {CH}_4\)). The volume fraction of the jth phase is mathematically represented as a volume fraction of the pore space, often referred to as the saturation, \(S_j\) [–]. Multiple components are then considered as mass fractions of the various phases. For example, \(X_{ij}\) would denote the mass fraction of the ith component in the jth phase.

Mathematical simulation of such problems involves solving a coupled set of conservation equations for each component (Orr 2007). Equations of state (EOS) are required to understand how the components partition into different phases. This is particularly important because the mobilities of the components are strongly controlled by their distribution between the present fluid phases. Firstly, component mass fractions, \(X_{ij}\), affect the viscosity of the phases (Centeno et al. 2011). Secondly, the permeability available to each phase is a nonlinear function of the phase saturations, \(S_j\) (Mathias et al. 2013).

In the absence of diffusion and capillary pressure, this problem is governed by a set of coupled hyperbolic and parabolic transport equations. Hyperbolic equations frequently give rise to the formation of shocks, leading to difficulties with regard to obtaining accurate solutions. Problems associated with one-dimensional transport of incompressible fluids, in the absence of capillary pressure and under isothermal conditions, can be solved exactly using the method of characteristics (Orr 2007). However, even under these restricting conditions, great care must be taken when considering nonzero initial conditions and non-unity boundary conditions (e.g., see Section 4.3 of Orr (2007)).

Alternative techniques involve the application of approximate methods. The spatial dimension is typically treated using conservative methods such as finite volume (Chen et al. 2006, p. 128). Alternatively, one can consider the use of finite elements (Chen et al. 2006, p. 94) or pseudospectral methods (van Reeuwijk et al. 2009). Such spatial schemes give rise to either stability problems or numerical diffusion due to truncation terms associated with the Taylor’s expansion, the latter of which can be reduced using flux limiters or their variants (e.g., Mallison et al. 2005).

Handling of the temporal term, which is critical to resolving the nonlinear nature of the problem, generally revolves around the choice of explicit or implicit treatment. Fully explicit treatment, although easier to implement, can run into severe time-step limitations due to the well-known Courant–Friedrichs–Lewy (CFL) condition. Fully implicit treatment leads to an unconditionally stable solution (as far as time stepping is concerned), but leads to additional numerical diffusion. Furthermore, implementation of the solution is significantly more challenging.

Popular approaches for solving MCMP problems in this context are the so-called semi-implicit methods, the most common variant of which is referred to as implicit pressure explicit saturation (ImPES) (Chen et al. 2006) or implicit pressure explicit mass (ImPEM). In ImPES, the governing equations are rearranged to identify a transport equation of hyperbolic (or nearly hyperbolic) nature and a pressure equation (of parabolic or elliptic character). The pressure equation is solved implicitly which allows for larger time steps. The transport equation is solved explicitly, allowing easier implementation and reduced computational memory requirements, hence the semi-implicitness. Both the implicit time stepping and explicit time stepping typically employ simple first-order schemes.

Multi-step multi-order time integration algorithms (Shampine and Reichelt 1997) represent an alternative method, which treats the temporal term in a more accurate fashion. These techniques maintain a specific time integration error while maximizing the time-step size. Moreover, due to the wide availability (e.g., MATLAB or FORTRAN with NAG) of high-quality solvers and simplicity of implementation, there is no need to redevelop the sophisticated solution algorithms. Rather, the so-called method of lines (MOL) approach can be taken. In this case, the partial differential equations (PDE) are discretized in space to form a set of coupled ordinary differential equations (Wouwer et al. 2005). These can then be solved simultaneously using any ordinary differential equation (ODE) solver of choice.

For two-phase immiscible flow, where one of the phases is treated as inviscid, the MCMP problem reduces to a single PDE often referred to as Richards’ equation (RE). This equation is commonly solved to better understand hydrological problems associated with unsaturated soils. Numerical studies by Farthing et al. (2003) and Kees and Miller (2002) have shown that applying MOL with higher-order time integration to the solution of RE leads to both improved accuracy and computational efficiency. Indeed, there are many recent articles (Mathias et al. 2006, 2008b; Ireson et al. 2009) reporting MOL solutions of RE using the MATLAB ODE solver, ODE15s, which is particularly suitable for stiff systems of ODEs (Shampine and Reichelt 1997). ODE15s has also been found to provide useful solutions to non-Darcian flow problems (Mathias et al. 2008a; Mathias and Wen 2015; Wen et al. 2009) and two-phase immiscible flow problems (Mathias et al. 2009).

Often when dealing with partial differential equations, it is useful to distinguish between dependent and independent variables (Stroud and Booth 2007, p. 122). In this case, time and space are independent variables. All other variables are dependent variables.

Application of MATLAB ODE solvers to multi-component partially miscible problems has proven more challenging. Consider \(N_c\) components residing in \(N_p\) phases. The problem will be defined by \(N_c\) mass conservation equations. However, considering the various values of \(S_j\) and \(X_{ij}\), it can be understood that there will be at least \((N_c+1)N_p\) dependent variables. It is therefore necessary to choose \(N_c\) dependent variables to solve for. Special care should be taken to ensure that the dependent variables selected are persistent (Amaziane et al. 2012; Bourgeat et al. 2013). This selected set of dependent variables is hereafter referred to as the primary dependent variables (PDV).

When using an ODE solver, the user must construct an ODE function. Within this function, a scalar value of time is provided as an input along with an associated vector of the PDVs. The user must define the ODE function such that it calculates the derivatives of the PDVs with respect to time, which generally involves using a combination of chain rule and product rule differentiation. This results in a need to evaluate the partial derivatives of the bulk fluid mass per unit pore space, F [\(\hbox {ML}^{-3}\)], with respect to each component mass fraction, \(z_i\) [–] (these terms will be mathematically defined later in the article). For conventional first-order time stepping, it is arguably acceptable to evaluate these derivatives using first or second-order finite differencing. However, given the high accuracy associated with the use of MATLAB’s ODE solvers, it is pertinent to obtain these derivatives in exact form wherever possible.

There are many detailed works concerning applications of MOL for immiscible two-phase flow and two-component two-phase flow problems (e.g., Amaziane et al. 2012; Vohralik and Wheeler 2013; Bourgeat et al. 2013; Mathias et al. 2014). Mallison et al. (2005) present a numerical simulation of an MCMP problem using MOL in conjunction with a 3rd- and 4th-order Runge–Kutta time integration method. However, Mallison et al. (2005) provide no discussion concerning the casting of equations in terms of PDVs. Indeed, little information is available as to how to obtain exact equations to describe the necessary partial derivatives, \(\partial F/\partial z_i\), needed to solve MCMP problems for situations concerning more than two components. In this article, we focus on obtaining such expressions for three-component two-phase problems. These are implemented within a radial flow simulator using MATLAB. Comparisons are then made, in the context of enhanced gas recovery by \(\hbox {CO}_2\) injection, with an associated analytical solution, previously presented by Hosseini et al. (2012).

2 Governing Equations

Consider three components: \(\hbox {CO}_2\), \(\hbox {CH}_4\) and \(\hbox {H}_2\hbox {O}\), denoted hereafter as \(i=1\), 2 and 3, respectively. The three components can partition into a gas phase and an aqueous liquid phases, denoted hereafter as \(j=1\) and 2, respectively. A horizontally orientated, homogeneous and isotropic cylindrical reservoir of radius, \(r_e\) [L], and formation thickness, H [L], is invoked. The reservoir is initially filled with a mixture of \(\hbox {CH}_4\) and \(\hbox {H}_2\hbox {O} \cdot \) \(\hbox {CO}_2\) is injected into the center of the reservoir via a fully completed vertically orientated injection well of radius, \(r_w\) [L]. Fluid flow is assumed to be one-dimensional such that the problem reduces to the following set of one-dimensional radially symmetric conservation equations:

$$\begin{aligned} \frac{\partial G_i}{\partial t} = -\frac{1}{r}\frac{\partial (rH_i)}{\partial r}, \quad i=1,2,\ldots N_c \end{aligned}$$
(1)

where t [T] is time, r [L] is radial distance from the injection well, \(N_c\) [–] is the number of components considered, and \(G_i\) [\(\hbox {ML}^{-3}\)] and \(H_i\) [\(\hbox {ML}^{-2}\hbox {T}{-1}\)] are the mass of component i per unit volume of rock and mass flux of component i, respectively, found from:

$$\begin{aligned} G_i= & {} \phi \sum _{j=1}^{N_p} \rho _j X_{ij} S_j \end{aligned}$$
(2)
$$\begin{aligned} H_i= & {} \sum _{j=1}^{N_p} \rho _j X_{ij} q_j \end{aligned}$$
(3)

where \(\phi \) [–] is the reservoir porosity, \(N_p\) [–] is the number of phases considered, \(\rho _j\) [\(\hbox {ML}^{-3}\)], \(S_j\) [–] and \(q_j\) [LT\(^{-1}\)] are the density, saturation (a volume fraction of the pore space) and volumetric fluid flux of phase j, respectively, and \(X_{ij}\) [–] is the mass fraction of component i in phase j. Note that \(\sum _{{i=1}^{N_c}}{ X_{ij}} =1\) and \(\sum _{{j=1}^{N_p}} {S_j}=1\).

The volumetric fluxes are calculated using Darcy’s law:

$$\begin{aligned} q_j={-\,k\frac{k_{rj}}{\mu _j}}{\frac{\partial P_j}{\partial r}} \end{aligned}$$
(4)

where k [L\(^2\)] is the reservoir permeability and \(k_{rj}\) [–], \(\mu _j\) [\(\hbox {ML}^{-1}\hbox {T}^{-1}\)] and \(P_j\) [\(\hbox {ML}^{-1}\hbox {T}^{-2}\)] are the relative permeability, dynamic viscosity and pressure of the jth phase, respectively.

For two-phase flow, without loss of generality, the relative permeability functions are assumed to take the form of power laws (Mathias et al. 2013):

$$\begin{aligned} k_{r1}= & {} k_{{r1}_0}\left( \frac{S_1-S_{1c}}{1-S_{1c}-S_{2c}}\right) ^{n_1}, \quad S_{1c}\le S_{1}\le 1-S_{2c} \end{aligned}$$
(5)
$$\begin{aligned} k_{r2}= & {} k_{{r2}_0}\left( \frac{S_2-S_{2c}}{1-S_{1c}-S_{2c}}\right) ^{n_2}, \quad S_{2c}\le S_{2}\le 1-S_{1c} \end{aligned}$$
(6)

where \(S_{jc}\) [–], \(k_{{rj}_0}\) [–] and \(n_j\) [–] are the critical saturation, end-point relative permeability and power-law exponent for phase j, respectively.

Furthermore, it is assumed that the following density mixing rule applies (Orr 2007)

$$\begin{aligned} \rho _j=\left( \sum _{i=1}^{N_c}\frac{X_{ij}}{\rho _{ij}}\right) ^{-1} \end{aligned}$$
(7)

where \(\rho _{ij}\) [\(\hbox {ML}^{-3}\)] is the density of the ith component in the jth phase.

3 Recasting in Terms of Primary Dependent Variables

An appropriate choice of primary dependent variables (PDVs) to solve for is the global fluid pressure, P [\(\hbox {ML}^{-1}\hbox {T}^{-2}\)], defined in this case by Chen et al. (2006), p. 342

$$\begin{aligned} P=\sum _{j=1}^{N_p} S_jP_j \end{aligned}$$
(8)

and the bulk mass fraction of each component, \(z_i\) [–], defined by

$$\begin{aligned} z_i=G_i/F \end{aligned}$$
(9)

where F [\(\hbox {ML}^{-3}\)] is the bulk fluid mass per unit volume of rock

$$\begin{aligned} F=\sum _{i=1}^{N_c} G_i=\phi \sum _{j=1}^{N_p} \rho _jS_j \end{aligned}$$
(10)

Note that \(\sum _{i=1}^{N_c} z_i = 1\).

In some previous studies, the mass of each component per unit volume of rock, \(G_i\), has also proven effective as PDVs in this context (Amaziane et al. 2012; Bourgeat et al. 2013). However, an advantage of using P and \(z_i\) (for \(i=1,2,\ldots N_c-1\)) as PDVs (as opposed to say \(G_i\)) is that \(z_i\) are independent of P. For a given volume of fluid mixture, the mass fractions of each component, \(z_i\), will not change with pressure. However, the associated mass of each component per volume of rock, \(G_i\), may change with pressure, depending on how the individual component mass densities, \(\rho _{ij}\), vary with pressure. Furthermore, \(z_i\) are the variables used in the ternary diagram (discussed later in the article), which determine the equilibrium properties of the three-component fluid mixture.

Differentiating Eq. (9) with respect to time leads to

$$\begin{aligned} \frac{\partial z_i}{\partial t}=\frac{1}{F}\left( \frac{\partial G_i}{\partial t}-z_i\frac{\partial F}{\partial t}\right) \end{aligned}$$
(11)

where, from Eqs. (1) and (10)

$$\begin{aligned} \frac{\partial F}{\partial t}=-\frac{1}{r}\sum _{i=1}^{N_c} \frac{\partial (rH_i)}{\partial r} \end{aligned}$$
(12)

Application of the chain rule to Eq. (10) and rearranging leads to

$$\begin{aligned} \frac{\partial P}{\partial t}=\left( \frac{\partial F}{\partial P}\right) ^{-1}\left( \frac{\partial F}{\partial t}- \sum _{i=1}^{N_c-1} \frac{\partial F}{\partial z_i}\frac{\partial z_i}{\partial t}\right) \end{aligned}$$
(13)

The main focus of this article is the derivation and application of exact formulae for the relationships defining \(\partial F/\partial P\) and \(\partial F/\partial z_i\) for \(i=1,2,\ldots , N_c-1\). Note that Eqs. (11)–(13) are important because they directly relate the time derivatives of the PDVs to the original mass conservation statements.

4 Differentiating the F Function

Considering the identity in Eq. (10), the total derivative of F can be written as

$$\begin{aligned} dF=F\frac{d\phi }{\phi }+\phi \sum _{j=1}^{N_p}S_j\rho _j\left( \frac{d\rho _j}{\rho _j} + \frac{dS_j}{S_j}\right) \end{aligned}$$
(14)

When there are only two phases, \(S_2=1-S_1\). From Eqs. (2 3), (9) and (10), it can then be understood that

$$\begin{aligned} S_1=\left[ 1-\frac{\rho _1(z_i-X_{i1})}{\rho _2(z_i-X_{i2})}\right] ^{-1} \end{aligned}$$
(15)

which on differentiation leads to

$$\begin{aligned} \frac{dS_1}{S_1}=S_2\sum _{j=1}^2(-1)^j\left[ \frac{d\rho _j}{\rho _j} +\left( \frac{dz_i-dX_{ij}}{z_i-X_{ij}}\right) \right] \end{aligned}$$
(16)

Invoking Eq. (7), it can also be shown that

$$\begin{aligned} \frac{d\rho _j}{\rho _j}=\rho _j\sum _{i=1}^{N_c}\frac{X_{ij}}{\rho _{ij}}\left( \frac{d\rho _{ij}}{\rho _{ij}}-\frac{dX_{ij}}{X_{ij}}\right) \end{aligned}$$
(17)

It is now assumed that component densities are unaffected by composition such that \( \partial \rho _{ij}/\partial z_i=0\). Additionally noting that

$$\begin{aligned} \frac{\partial z_i}{\partial z_k }=0, \quad i\ne k \end{aligned}$$
(18)

the remaining challenge is to define the \(dX_{ij}\) terms.

The terms \(X_{ij}\) can be further defined by:

$$\begin{aligned} X_{ij}=\left\{ \begin{array}{ll} z_i, &{} S_1=0,1 \\ x_{ij}, &{} 0< S_1< 1 \end{array}\right. \end{aligned}$$
(19)

where \(x_{ij}\) [–] are the equilibrium mass fractions of the ith component in the jth phase within the two-phase region. Then \(dX_{ij}\) is given by:

$$\begin{aligned} \frac{\partial X_{ij}}{\partial z_i}= & {} \left\{ \begin{array}{l@{\quad }l} 1, &{} S_1=0,1 \\ \displaystyle \frac{\partial x_{ij}}{\partial z_i} , &{} 0< S_1< 1 \end{array}\right. \end{aligned}$$
(20)
$$\begin{aligned} \frac{\partial X_{ij}}{\partial P}= & {} \left\{ \begin{array}{l@{\quad }l} 0, &{} S_1=0,1 \\ \displaystyle \frac{\partial x_{ij}}{\partial P} , &{} 0< S_1< 1 \end{array}\right. \end{aligned}$$
(21)

It is important to note that for two-component two-phase problems, \(x_{ij}\) only varies with pressure. However, for three-component two-phase systems, the problem is much more complicated because the equilibrium constants, \(x_{ij}\), are no longer constant with composition (i.e., \(z_1\) and \(z_2\)).

EOSs for the binary mixtures of \(\hbox {CO}_2\)\(\hbox {H}_2\hbox {O}\) and \(\hbox {CH}_4\)\(\hbox {H}_2\hbox {O}\) are well characterized by relatively simple sets of equations. In this work, the binary mixture properties of \(\hbox {CO}_2\)\(\hbox {H}_2\hbox {O}\) and \(\hbox {CH}_4\)\(\hbox {H}_2\hbox {O}\) were obtained using expressions provided by Spycher et al. (2003) and Duan and Mao (2006), respectively. These can be joined together to form a ternary system by assuming that the equilibrium ratios, \(K_i\) [–], defined as

$$\begin{aligned} K_i=\frac{x_{i1}}{x_{i2}}, \end{aligned}$$
(22)

for components 1 and 2 (but not 3) do not vary with composition.

When \(K_1\) and \(K_2\) are constant, the two-phase region, for a given temperature and pressure, is defined by two straight lines on a ternary diagram (see Fig. 1). Consequently, following the work of Juanes (2008), it can be shown that values of \(x_{ij}\) can be related back to their values obtained from the binary mixtures, \(a_{ij}\), by the set of linear equations:

$$\begin{aligned} x_{1j}=Aa_{1j} \quad \hbox {and} \quad x_{2j}=(1-A)a_{2j} \end{aligned}$$
(23)

where \(a_{1j}=x_{1j}\) when \(z_2=0\), \(a_{2j}=x_{2j}\) when \(z_1=0\) and A [–] is a weighting parameter that linearly interpolates between the bounding tie-lines that coincide with the \(z_2\) and \(z_3\) axes of the ternary diagram. Writing out Eq. (23) for components 1 and 2 and eliminating A lead to:

$$\begin{aligned} a_{i1}x_{i2}=a_{i2}x_{i1} \quad \hbox {and} \quad x_{2j}=(a_{1j}-x_{1j})a_{2j}/a_{1j} \end{aligned}$$
(24)

Similarly it can be said that, on a given tie-line in the two-phase region,

$$\begin{aligned} z_i=Bx_{i1}+(1-B)x_{i2} \end{aligned}$$
(25)

where B [–] is a weighting parameter that linearly interpolates between the bounding lines that define the two-phase region of the ternary diagram. Writing Eq. (25) out for components 1 and 2 and then eliminating B lead to

$$\begin{aligned} (z_1-x_{12})(x_{21}-x_{22})=(z_2-x_{22})(x_{11}-x_{12}) \end{aligned}$$
(26)
Fig. 1
figure 1

Illustration of a two-phase three-component system on a ternary diagram. Tie-lines are shown as dashed lines. The barycentric coordinates of points of the ternary diagram correspond to the total composition of the fluid mixture

Note that the equilibrium ratio for \(\hbox {H}_2\hbox {O}\) (component 3) is not necessarily constant and is defined by the relationship

$$\begin{aligned} K_3=\frac{1-x_{11}-x_{21}}{1-x_{12}-x_{22}} \end{aligned}$$
(27)

Using Eq. (24) to eliminate the \(x_{i2}\) and \(x_{2j}\) terms yields the quadratic equation

$$\begin{aligned} 0=T_2x_{11}^2+T_1x_{11}+T_0 \end{aligned}$$
(28)

where

$$\begin{aligned} T_0= & {} (a_{21}-a_{22})a_{11}z_1 \end{aligned}$$
(29)
$$\begin{aligned} T_1= & {} (a_{11}-a_{12})(a_{22}-z_2)-(a_{21}-a_{22})(a_{12}+z_1) \end{aligned}$$
(30)
$$\begin{aligned} T_2= & {} (a_{12}a_{21}-a_{11}a_{22})/a_{11} \end{aligned}$$
(31)

which has the solutions

$$\begin{aligned} x_{11}=\frac{-T_1\pm \sqrt{T_1^2-4T_0T_2}}{2T_2} \end{aligned}$$
(32)

Equation (32) gives an explicit expression for \(x_{11}\) with respect to \(z_1\) and \(z_2\). Furthermore, from Eq. (28) we have the total derivative of \(x_{11}\):

$$\begin{aligned} dx_{11}=-\frac{x_{11}^2dT_2+x_{11}dT_1+dT_0}{2T_2x_{11}+T_1} \end{aligned}$$
(33)

where

$$\begin{aligned} dT_0= & {} (da_{21} -da_{22})a_{11z_1}+(a_{21}-a_{22})(a_{11}dz_1+da_{11}z_1) \end{aligned}$$
(34)
$$\begin{aligned} dT_1= & {} (da_{11}-da_{12}) (a_{22}-z_2)+(a_{11}-a_{12})(da_{22}-dz_2)\nonumber \\&-\,(da_{21}-da_{22}) (a_{12}+z_1)-(a_{21}-a_{22})(da_{12}+dz_1) \end{aligned}$$
(35)
$$\begin{aligned} dT_2= & {} da_{12}\frac{a_{21}}{a_{11}}+ da_{21}\frac{a_{12}}{a_{11}}-da_{11}\frac{a_{12}a_{21}}{a_{11}^2}-da_{22} \end{aligned}$$
(36)

which, in conjunction with Eq. (24), provides expressions for all the other derivatives, \({d x_{ij}}\). Expressions for \(dX_{ij}\) can then be obtained from Eqs. (21) and (20).

5 Additional Considerations Required for Accommodating Capillary Pressure

When capillary pressures can be assumed negligible, the information in this section can be ignored. However, for non-negligible capillary pressure, the fluid properties \(x_{ij}\) and \(\rho _{ij}\) should be calculated from the phase pressure, \(P_{j}\), as opposed to the global pressure, P. An equation of state can provide derivatives of these variables with respect to \(P_j\). But to obtain derivatives with respect to P, the following transformations must be applied:

$$\begin{aligned} \frac{\partial x_{ij}}{\partial P}= & {} \frac{\partial P_j}{\partial P}\frac{\partial x_{ij}}{\partial P_j} \end{aligned}$$
(37)
$$\begin{aligned} \frac{\partial \rho _{ij}}{\partial P}= & {} \frac{\partial P_j}{\partial P}\frac{\partial \rho _{ij}}{\partial P_j} \end{aligned}$$
(38)

For two-phase flow systems, Eq. (8) reduces to

$$\begin{aligned} P_j=P-(-1)^j(1-S_j)P_c \end{aligned}$$
(39)

where \(P_c=P_1-P_2\) is the capillary pressure.

Noting that \(P_c\) is generally expressed uniquely as a function of \(S_1\) (e.g., van Genuchten 1980) and that \(dS_1=-dS_2\), differentiating Eq. (39) with respect to P leads to

$$\begin{aligned} \frac{\partial P_j}{\partial P}=1-\left( P_c+(-1)^j(1-S_j)\frac{\partial P_c}{\partial S_1}\right) \frac{\partial S_1}{\partial P} \end{aligned}$$
(40)

Recalling Eq. (16) and that \(z_i\) are independent of P, it can be said that

$$\begin{aligned} \frac{1}{S_1}\frac{\partial S_1}{\partial P}=S_2\sum _{j=1}^2Y_j\frac{\partial P_j}{\partial P} \end{aligned}$$
(41)

where

$$\begin{aligned} Y_j=(-1)^j\left[ \frac{1}{\rho _j}\frac{\partial \rho _j}{\partial P_j} -\frac{1}{(z_i-X_{ij})}\frac{\partial X_{ij}}{\partial P_j}\right] \end{aligned}$$
(42)

from which we obtain

$$\begin{aligned} \frac{\partial S_1}{\partial P}=\left[ \frac{1}{S_1S_2}+\sum _{j=1}^2 \left( P_c+(-1)^j(1-S_j)\frac{\partial P_c}{\partial S_1}\right) Y_j\right] ^{-1} \sum _{j=1}^2 Y_j \end{aligned}$$
(43)

6 Numerical Solution

A weighted essentially non-oscillatory (WENO) scheme (Shu 2009) was used to approximate the flux, \(H_i\), in Eq. (1). For more details on the WENO method and its applications, the reader is referred to Coralic and Colonius (2014), Noelle et al. (2007) and Zhang and Shu (2012) and references therein. The WENO scheme implemented here uses a 2nd-order stencil to approximate the flux at the mid-points (\(k+1/2\) and \(k-1/2\)). A central difference approximation is then used to evaluate the derivative of the flux at grid point k, which is 3rd-order accurate in space (Shu 2009):

$$\begin{aligned} \left( \frac{\partial G_i}{\partial t}\right) _k=-\frac{1}{r_k} \left[ \frac{r_{k+\frac{1}{2}}(H_i)_{k+\frac{1}{2}} - r_{k-\frac{1}{2}}(H_i)_{k-\frac{1}{2}}}{r_{k+\frac{1}{2}}-r_{k-\frac{1}{2}}}\right] \end{aligned}$$
(44)

The pressure derivative contained within the \((H_i)_{k+\frac{1}{2}}\) term was approximated using the following central difference expression:

$$\begin{aligned} \left( \frac{\partial P}{\partial r}\right) _{k+\frac{1}{2}}=\frac{P_{k+1}-P_k}{r_{k+1}-r_k} \end{aligned}$$
(45)

The Jacobian matrix is a matrix describing the dependencies of each equation in the system of equations on every other equation. In this problem, we are solving for three PDVs, which, by virtue of the discretised conservation equations, are mutually dependent on one another. Conventional second-order finite difference approximations of second-order derivatives at a grid point, k, will depend on three points, namely \(k-1\), k and \(k+1\). However, when using the WENO scheme described above, additional information from \(k-2\) and \(k+2\) is required, leading to a penta-diagonal structure for the Jacobian matrix. For systems of equations with more than one PDV, a so-called block-diagonal structure is formed.

Fig. 2
figure 2

Block penta-diagonal Jacobian pattern for the sparse system for n = 10 grid points and 3 PDVs (nz number of nonzero elements)

In MATLAB, it is possible to provide the ODE solver with the Jacobian pattern as a sparse matrix of zeros and ones to indicate where the Jacobian matrix is nonzero. This tells the solver to only evaluate the sparse system and not the full matrix. In stiff problems with non-constant Jacobian matrices, specifying the Jacobian pattern a priori can lead to significant savings in computation time. A pictorial representation of the Jacobian pattern for the problem discussed in this article is presented in Fig. 2.

Spatial grids were locally refined near the well bore and gradually coarsened away from the injection well to ensure simulation stability. Simulation time steps are refined automatically using MATLAB’s ODE15s adaptive time stepping scheme. ODE15s is particularly suitable for stiff problems where the governing equations include a combination of terms that lead to rapid variation in the solution and terms that vary slowly. For the problem described in this article, compositions propagate very slowly thorough the reservoir compared to the pressure waves, which move much more rapidly.

ODE15s is a multi-order multi-step solver. The scalar relative error tolerance and the absolute error tolerance are set to MATLAs default values, \(10^{-3}\) and \(10^{-6}\), respectively. For more information about how the solver is implemented, readers are referred to Shampine and Reichelt (1997) and Shampine and Thompson (2001).

7 Model Verification

Results from the numerical solution (implemented in MATLAB) were compared against results from the analytical solution by Hosseini et al. (2012). Both models assume a fully completed well at the center of a 1D radially symmetric flow field of radial extent, \(r_e\). Capillary pressure, molecular diffusion and gravity effects were neglected. Initial and boundary conditions were applied as follows:

$$\begin{aligned} z_1= & {} 0, \quad r_w \le r \le r_e, \quad t=0\nonumber \\ S_1= & {} S_{10}, \quad r_w \le r \le r_e, \quad t=0\nonumber \\ P= & {} P_0, \quad r_w \le r \le r_e, \quad t=0\nonumber \\ H_1= & {} M_0/ (2\pi r_w H), \quad r=r_w, \quad t>0\nonumber \\ H_2= & {} 0, \quad r=r_w, \quad t>0\nonumber \\ H_3= & {} 0, \quad r=r_w, \quad t>0\nonumber \\ H_1= & {} 0, \quad r=r_e, \quad t>0\nonumber \\ H_2= & {} 0, \quad r=r_e, \quad t>0\nonumber \\ H_3= & {} 0, \quad r=r_e, \quad t>0 \end{aligned}$$
(46)

where \(S_{10}\) [–] is the initial gas saturation and the other parameters are as specified in Tables 1 and 2.

Table 1 Model parameters used for verification of the numerical simulation
Table 2 Relative permeability model parameters used in Eqs. (5) and (6)
Fig. 3
figure 3

a Comparison of gas saturation profiles between the analytical and numerical simulation of \(\hbox {CO}_2\) injection into a deep reservoir with initial gas saturation, \(S_{10}=0.1\), after 10, 100 and 1000 days. b Corresponding pressure profiles for deep reservoir. c Gas saturation profiles for a shallow reservoir. d Corresponding pressure profiles for a shallow reservoir. A total of 300 nodes were used for the numerical simulation

Fig. 4
figure 4

The same as Fig. 3 but only showing profiles after 1000 days and assuming initial gas saturations, \(S_{10}\), of 0.02, 0.05 and 0.1

Figure 3 shows gas saturation profiles for \(\hbox {CO}_2\) injection into deep (Fig. 3a, b) and shallow (Fig. 3c, d) reservoirs with 10 % residual \(\hbox {CH}_4\), during a simulation period of 1000 days. The solid lines and dashed lines represent results from the analytical solution and numerical solution, respectively.

The high gas saturation around the injection well, often referred to as a dry-out zone (Mathias et al. 2011), is due to the vaporization of the residual water saturation by the injected \(\hbox {CO}_2\). A \(\hbox {CH}_4\) bank with about 22 \(\%\) gas saturation in front of the \(\hbox {CO}_2\) plume develops. The length of the \(\hbox {CH}_4\) bank increases with time. Correspondence between the analytical solution and the numerical solution is very good for both gas phase saturation and pressure buildup. The numerical solution is seen to accurately locate the associated shock fronts while considering the partial miscibility of both \(\hbox {CO}_2\) and \(\hbox {CH}_4\) in \(\hbox {H}_2\hbox {O}\).

Fig. 5
figure 5

Mean absolute normalized error (MANE) between the numerical and analytical pressure and gas saturation values for different times, plotted against the number of grid cells used for the shallow reservoir case previously depicted in Fig. 3c and d

For the shallow reservoir, just ahead of the \(\hbox {CH}_4\) bank, it can be seen that the numerical solution predicts a slightly lower gas saturation as compared to the analytical solution. This is due to the fact that the analytical solution assumes constant fluid properties and hence is not capturing volume change effects due to pressure change. This discrepancy is not noticeable for the deep reservoir because the gas compressibility is a lot lower at 34 MPa.

The possibility that the above-mentioned discrepancy was due to insufficient mesh refinement was investigated by comparing simulation results using a 600 point grid and a 900 point grid. The comparison study confirmed that the discrepancy was not due to numerical error.

Similar simulations but with different initial gas saturations are compared in Fig. 4. It is found that the extent of the dry-out region is insensitive to the initial gas saturation. The extent of the dry-out region is smaller for the shallow reservoir, and the volume of the gas plume is larger. The reduced dry-out region, in this case, is due to the reduced evaporation that occurs at cooler temperatures. The increased gas volume is due to the reduced gas density that occurs at lower pressures. Again it can be seen that the numerical solution is able to accurately predict the analytical results of Hosseini et al. (2012).

7.1 Numerical Solution Performance

The performance of the MOL numerical solution was explored further through a grid convergence study. The shallow reservoir scenario, depicted in Fig. 3c, d, was repeated using different numbers of grid cells. Numerical solution performance was quantified by calculating the mean absolute normalized error (MANE) between results (from each grid cell) from the numerical solution and those from the analytical solution for a given time. Figure 5 shows a plot of MANE for gas saturation and pressure for the different times previously presented in Fig. 3c, d. Grid convergence can be seen to have been achieved at around 300 grid cells.

The converged MANE for pressure is around 0.02 %. However, the converged MANE for gas saturation is quite high at around 0.25 %. This is due to conceptual differences between the numerical solution and the analytical solution. Recall that the analytical solution assumes constant fluid properties, whereas the numerical solution is allowing for variations of fluid properties with pressure and composition, as discussed above. Hosseini et al. (2012) were able to achieve a very similar level of accuracy for a very similar set of simulations using the commercial reservoir simulator, CMG GEM (Computer Modeling Group Ltd. 2015) (see Fig. 5 of Hosseini et al. (2012)). GEM uses an adaptive-implicit solver as described by Collins et al. (1992).

In terms of computation time, the 300 grid cell numerical solution using our new MOL approach was able to simulate 1000 days of gas injection in around 5 min using an Intel Xeon CPU E5-2630 2.30 GHz (2 processors). For comparison, the GEM simulations undertaken by Hosseini et al. (2012) took around 2 h on an Intel Xeon CPU E5-2687 3.10 GHz (2 processors) (Hosseini, 2015, Personal Communications). Clearly, our new MOL solution has the potential to offer significant computation time savings in this context.

8 Effect of Initial Gas Saturation

As was shown in the previous section, numerical simulations of \(\hbox {CO}_2\) injection into a reservoir containing \(\hbox {CH}_4\) predict the accumulation of a \(\hbox {CH}_4\) bank at the head of the \(\hbox {CO}_2\) plume (Oldenburg and Doughty 2011; Battistelli and Marcolini 2009; Taggart 2010).

The system in discussion can be differentiated into three regions (Hosseini et al. 2012). These regions, starting from the injection point and moving outward, are:

  1. 1.

    a single-phase, dry-out region around the well bore filled with pure \(\hbox {CO}_2\).

  2. 2.

    a two-phase, two-component system containing \(\hbox {CO}_2\) and \(\hbox {H}_2\hbox {O}\).

  3. 3.

    a two-phase, two-component system containing \(\hbox {CH}_4\) and \(\hbox {H}_2\hbox {O}\).

Within the two-phase mixture, each phase propagates at a rate according to its mobility. The mobility of each phase varies from one region to another due to associated compositional changes. As a consequence, a trailing shock forms at the contact between regions (1) and (2) and a leading shock forms at the contact between regions (2) and (3).

The development of the \(\hbox {CH}_4\) bank ahead of the \(\hbox {CO}_2\) has been explained as follows (Taggart 2010; Oldenburg and Doughty 2011; Hosseini et al. 2012). As \(\hbox {CO}_2\) is injected, it partitions into the gas phase and the aqueous phase. The initially dissolved \(\hbox {CH}_4\) exsolves immediately and is then pushed ahead of the growing \(\hbox {CO}_2\) plume leading to the development of a \(\hbox {CH}_4\) bank (Oldenburg and Doughty 2011). Mathematically, the system is constrained to constantly enter and leave the two-phase region along the tie-lines representing the injection and initial compositions; therefore, the leading \(\hbox {CH}_4\) bank is free from injected gas, \(\hbox {CO}_2\) (Taggart 2010).

Intuitively, it is expected that the amount of \(\hbox {CH}_4\) initially present should affect the methane bank saturation; the more the initial \(\hbox {CH}_4\) saturation, the higher the bank saturation. However, numerical simulation of \(\hbox {CO}_2\) injection for different initial gas saturations (everything else being the same), shows that the bank saturation is independent of the initial \(\hbox {CH}_4\) saturation (see Figs. 4, 7). In fact, Hosseini et al. (2012) showed mathematically that the \(\hbox {CH}_4\) bank saturation is independent of the initial gas saturation.

This can be further explained using the principles of fractional flow theory (Pope 1980; Orr 2007). Because of the differences in phase viscosities in the two-phase region (i.e., between mixtures of \(\hbox {CO}_2\)\(\hbox {H}_2\hbox {O}\) and \(\hbox {CH}_4\)\(\hbox {H}_2\hbox {O}\)), flow occurs on different fractional flow curves in the two-phase region (Fig. 7). Figure 7a, c and e shows the fractional flow curves (plots of \(H_i/\rho _{i1}\) against \(G_i/\rho _{i1}\)) for \(\hbox {CO}_2\) and \(\hbox {CH}_4\) along with the locations of the shock fronts for different initial gas saturations.

The partial derivative \(\partial H_i/\partial G_i\) represents the wave velocity of the system. The wave velocities of the shock fronts are found from the gradients of straight lines that link the two conditions on either side of the shock. Fractional flow theory dictates that valid solutions should satisfy both the velocity constraint and the so-called entropy constraint (Orr 2007). The velocity constraint implies that wave velocity should always decrease with increasing distance from the injection boundary. The entropy constraint implies that the shock wave velocity should be equal to the gradient of the fractional flow curve immediately upstream of the shock.

Due to the zero initial condition for \(G_1\), the only valid path on the \(\hbox {CO}_2\) fractional flow curve is a tangent (i.e., (0,0) to L). On the other hand, velocities must be equal at the contact between a pair of different fluids (Pope 1980) (i.e., points G and L in Fig. 6). This means that the gas bank saturation (point G) is dictated by the intersection of the tangent to the \(\hbox {CO}_2\) curve with the \(\hbox {CH}_4\) curve.

Fig. 6
figure 6

Schematic diagram illustrating the three-region system associated with \(\hbox {CO}_2\) injection into a reservoir initially containing \(\hbox {CH}_4\) and \(\hbox {H}_2\hbox {O}\). Jinjection, Ttrailing shock, L leading shock, G gas bank, I initial

Figure 7b, d and f shows the corresponding saturation profiles for different initial gas saturations. The level of saturation at point G is always determined by the tangent from (0,0) to point L. Physically, this implies that the bank saturation is only dependent on how fast the injected gas propagates. The solid and dashed lines in Fig. 7b, d and f are from the analytical solution and numerical solution, respectively. There is an excellent correspondence between the two. The analytical solution was developed on the basis of the fractional theory described above. The numerical solution therefore further confirms the finding of Hosseini et al. (2012) that the \(\hbox {CH}_4\) bank saturation is independent of the initial gas saturation.

Fig. 7
figure 7

Illustration of \(\hbox {CH}_4\) bank saturation independence of initial \(\hbox {CH}_4\) mass fraction for the deep reservoir scenario after 1000 days of injection (with parameters as set in Table 1): a and b \(S_{1_I}<S_{1_G}\),   c and d \(S_{1_I}=S_{1_G}\),  e and f \(S_{1_I}>S_{1_G}\)

However, if the initial gas saturation is sufficiently high it may not be possible to build a solution that travels from the initial condition (point I in Fig 6) to the intersection point of the tangent line with the \(\hbox {CH}_4\) fractional flow curve (point G in Fig 6). As a consequence, a \(\hbox {CH}_4\) bank will no longer be present. Therefore, it should be noted that the existence of the \(\hbox {CH}_4\) bank is dependent on the initial gas saturation (LaForce and Johns 2010). Nevertheless, providing the \(\hbox {CH}_4\) bank exists, the \(\hbox {CH}_4\) bank saturation is independent of the initial gas saturation.

9 Summary and Conclusions

A numerical simulator was developed for 1D, compressible, two-phase, three-component, radially symmetric flow using the method of lines (MOL) and a 3rd-order accurate spatial discretization using weighted essentially non-oscillatory (WENO) scheme. The MOL implementation enabled application of the state-of-the-art MATLAB ODE solver, ODE15s, for time integration. Pressure and overall component mass fraction (\(z_i\)) were selected as the primary dependent variables (PDV). The sparsity of the system of equations was taken advantage of by provision of a penta-diagonal Jacobian pattern for the ODE solver. Simulation examples were developed in the context of \(\hbox {CO}_2\) into a reservoir containing a mixture of \(\hbox {CH}_4\) and \(\hbox {H}_2\hbox {O}\).

Following an assumption of constant equilibrium ratios (\(K_i\)) for \(\hbox {CO}_2\) and \(\hbox {CH}_4\), it was possible to derive a ternary flash calculator by deriving closed-form relationships for exact interpolation between equations of state for \(\hbox {CO}_2\)\(\hbox {H}_2\hbox {O}\) and \(\hbox {CH}_4\)\(\hbox {H}_2\hbox {O}\) binary mixtures. This helped ensure improved stability and mass conservation and led to reduced computational requirements associated with multi-dimensional lookup tables. The numerical code was successfully tested and verified for a range of scenarios by comparison with an existing analytical solution.