1 Introduction

The computational modeling of two-phase fluid flow equations in heterogeneous porous media has established itself as a challenge in numerous applications in petroleum engineering and hydrogeology [1], chemical engineering, and nuclear safety [2]. These equations are essential for analyzing reservoirs, as they provide a model for the fluid flow through the porous media that form it. We know that fluids present in a reservoir interact with each other and with the environment. This interaction depends on the characteristics of the medium, such as porosity and permeability, as well as the characteristics of the fluids involved in the process, including their viscosity and specific mass. These properties are essential factors in determining the amount of fluid in the rock as well as knowing how that fluid can move through those underground spaces. These physical quantities are often modeled in a probabilistic framework when no complete information exists. As an example, the porosity and permeability fields can be modeled employing random variables [3]. The main difficulty is in employing a multi-random function approach to generate permeability and porosity fields that are dependent on dynamic data, such as well production data. Due to the nonlinearity involved in estimating flow and transport in reservoirs, calculating this probability distribution is typically challenging. Given that the porosity and permeability fields are specified into blocks in numerical discretization, they must be properly sampled in this situation.

The Markov Chain Monte Carlo (MCMC) simulation is a widely employed global optimization algorithm, commonly used for inferring permeability and porosity fields [4, 5]. The MCMC method often demands a large number of random input realizations to generate a set of model outputs. To address this challenge, local search algorithms come into play to reduce the required number of realizations. We employ the Random Walk (RW) algorithm to select the initial model. This algorithm enables the straightforward incorporation of random parameters using Bayesian inference with focus on a local region of the search space, where they iteratively improve the current solution by considering neighboring solutions. The resulting model is subsequently refined with the Levenberg–Marquardt (LM) method [6, 7]. The procedure consists of combining the gradient descent method with the Gauss-Newton method [8, 9]. It adjusts the gradient descent method with a modification parameter to handle situations where the Gauss-Newton method may encounter convergence issues. During iterations, the modification parameter is adaptively adjusted, allowing the algorithm to behave more like gradient descent when the current solution is far from optimal and more like Gauss-Newton when the solution is close to optimal.

We will demonstrate the capability of the algorithm to improve the initial estimates and finding the best-fitted model across multiple scales for a Darcy flow equation involving two immiscible fluids. To achieve this, we employ a coupled formulation based on the global pressure and phase saturation formulation to predict the spatial distribution of the pressure and the non-wetting phase saturation. The model consists of coupled pressure and saturation equations in the confined fluid region. For instance, this model can be used to study particle transport in aquifers [10, 11].

The samples of porosity and permeability required by the RW algorithm are obtained from second-order stationary processes with spatial correlation determined by a Gaussian covariance function. We parameterize these fields using the eigenvalues and eigenfunctions obtained from the finite element method using the Karhunen–Loève (KL) expansion [12,13,14]. In this expansion, the most significant functions (those with higher eigenvalues) largely describe the variability of the field, so that we can perform truncation. This can help to simplify the analysis, reduce noise in the data, and facilitate modeling and forecasting of complex systems [12]. A similar study was proposed by Ginting et al. [15], who constructed permeability and porosity fields by KL expansion for the prediction of flows in an oil reservoir. Al-Mamun et al. [16] used the KL expansion for the permeability field in conjunction with a two-stage MCMC, running several MCMC chains. However, the authors do not explore the inversion of the porosity and permeability fields. In contrast with previous works and according to Tartakovsky et al. [17], the random variables of the KL expansion for inversion purposes will be considered as coefficients. This ensures that our methodology can recover both the porosity and permeability fields, enhancing the convergence of the MCMC algorithm through a local search.

We propose the following organization in this article. In Sect. 2, we present a formulation of the Darcy system for modeling flow and transport in heterogeneous porous media. The coupled formulation of the equations based on the global pressure and phase saturation is solved via the MsFV to predict the spatial distribution of the pressure, saturation, and production rate. We solve the pressure by using fully implicit Euler in time and first-order upwind finite-volume in space [18]. Although the pressure solver is linear, it requires successive updating of the total mobility of both fluid phases, which is achieved by the standard Two-Point Flux Approximation (TPFA) [19]. The saturation equation is solved with an adaptive time-stepping strategy combined with an inner Newton–Raphson (NR) iteration loop. Section 3 outlines the inversion procedure proposed. In Sect. 4, we describe the methodology to obtain porosity and permeability samples based on the Karhunen–Loève expansion. In Sect. 5, we build a MCMC for the characterization of the porosity and permeability fields in the inverse problem. For each MCMC proposal, a Multiscale Finite Volume (MsFV) simulation is performed to compute pressure and saturation. Here, the decision to accept or reject the fields is made on the basis of the RW algorithm [3, 20]. Once this set of samples is formed, we compute the solution with minimum error and substitute it into the LM local minimum approach to refine it. Section 6 contains a synopsis of the LM algorithm. Section 7 is dedicated to numerical simulations with a synthetic example where we recover the porosity and permeability inverse solution to the stochastic transport problem using the combined RW-LM algorithm and compare it with the reference solution.

2 The mathematical model for two-phase flow in heterogeneous porous media

In this section, we present a mathematical model that governs two-phase flow in a dynamically heterogeneous porous media, neglecting the gravitational and capillary pressure terms. As our primary approach, we rely on the governing global pressure equation and the nonlinear non-wetting phase saturation equation formulated in a fractional form that is derived from the classical coupled formulation as, e.g., in [21]. The pressure and saturation solvers are both implicit in time, implying unconditional stability regardless of the magnitude of the selected time step. They are first calculated by solving the flow equation and then held fixed as saturation advances according to the transport equation.

The pressure-saturation formulation does not require any variable switching, enabling a convenient implementation and analysis of the sequential-implicit method. As described, the sequential-implicit method is iteratively coupled until both the flow pressure and saturation equations reach a specified tolerance level.

2.1 Coupled formulation

Let \({\mathcal {R}} \subset {\mathbb {R}}^2\) be open and bounded, and the time domain be [0, T], where \(T > 0\). As described in Helmig [21], the dynamics of two incompressible and immiscible fluids in porous media can be described by a system of differential equations, consisting of the subphases Darcy laws:

$$\begin{aligned} \left. \begin{gathered} {\textbf{v}}_j = - \frac{\kappa _{rj}(S)}{\mu _j} {{\textbf {K}}}\nabla P \end{gathered} \qquad \right. \quad \begin{gathered} \text {in } {\mathcal {R}}, \quad \end{gathered} \end{aligned}$$
(1)

where, for each phase index \(j\in \{w,o\}\) (w and o denote the wetting and non-wetting phases, respectively), \({\textbf{v}}_j\) is the phase velocity, \({{\textbf {K}}}\) is the permeability tensor, \(\kappa _{rj}\) is the relative permeability, \(\mu _j \in {\mathbb {R}}\) is the dynamic viscosity, S is the wetting phase saturation and P is the pressure. We assume a simplified Corey model with exponent 2 and zero residual saturation, i.e., \(\kappa _{rw} = S^2\) and \(\kappa _{ro} = (1-S)^2\) [19].

The pressure, P, and the saturation, S, are governed by equations:

$$\begin{aligned} \nabla \cdot (\lambda _t(S){{\textbf {K}}}\nabla P ) =q \end{aligned}$$
(2)
$$\begin{aligned} \phi \frac{\partial S}{\partial t} + {\textbf{v}}\cdot \nabla (f_w(S)) =-q_w, \end{aligned}$$
(3)

where \({\textbf{v}} = {\textbf{v}}_w + {\textbf{v}}_o = \lambda _t(S){{\textbf {K}}}\nabla P\) and \(f_w(S)\) represents the saturation-dependent fractional flow function for the wetting phase defined by:

$$\begin{aligned} f_w(S) = \frac{\lambda _w(S)}{\lambda _t(S)}. \end{aligned}$$
(4)

The parameter \(\lambda _t\) in Eq. (2) represents the total mobility, which is given by \(\lambda _t= \lambda _w + \lambda _{o}\), where the phase mobility \(\lambda _j\) is given by \(\lambda _j = k_{rj} / \mu _j\), \((j=w,o)\). The parameter \(\phi\) is the rock porosity and q is a source or sink term. We assume that the permeability tensor \({{\textbf {K}}}\) is isotropic, i.e., \({{\textbf {K}}} = \kappa ({{\textbf {x}}}) {{\textbf {I}}}\), where \({{\textbf {I}}}\) is the identity matrix and \(\kappa ({{\textbf {x}}})\) is a scalar permeability function.

2.2 Numerical discretization

We apply the MsFV method to Eq. (2) to obtain the velocity field on the coarse grid. Subsequently, we utilize the solution obtained on this grid to solve the saturation by Eq. (3).

Following the steps from [22], let us define a primal grid \({\mathcal {M}}\) with coarse cells \(D^k \in {\mathcal {M}}\) formed by the vertices \({\varvec{x}}_{i}\) and a dual grid \(\tilde{{\mathcal {M}}}\) with dual cells \({\tilde{D}}^e \in \tilde{{\mathcal {M}}}\) formed by the vertices \(\tilde{{\varvec{x}}}_{i}\). The centers of the primal and dual cells are located at the points \(\tilde{{\varvec{x}}}_{D^k}\) and \({\varvec{x}}_{{\tilde{D}}^e}\), respectively, as illustrated in Fig. 1.

Fig. 1
figure 1

Coarse cells are represented by primal (bold black) and dual (dashed blue) cells. Fine cells that belong to a dual cell are highlighted in light gray. The coarse nodes (vertices) are denoted by blue dots. The central point of the dual cell \({\tilde{D}}^e\) located at the center of the figure (with gray shading) is \({\varvec{x}}_{{\tilde{D}}^e}={\varvec{x}}_5\)

Initially, we build basis functions \({\tilde{\psi }}^e\) in each dual cell \({\tilde{D}}^e\) to calculate the pressure at the vertices of the coarse grid \({\mathcal {M}}\). Denoting the pressure in \({\mathcal {M}}\) by \(P^c\), we can obtain it by interpolating the basis functions \({\tilde{\psi }}_i^e\) at each vertex \(\tilde{{\varvec{x}}}_{i}\) of \({\tilde{D}}^e\) through the following expression:

$$\begin{aligned} P^c({\varvec{x}}_{{\tilde{D}}^e})= \sum _{i = 1}^{N_e}P_i{\tilde{\psi }}_i^e({\varvec{x}}_{{\tilde{D}}^e}),\quad \quad \end{aligned}$$
(5)

where \(N_e\) is the number of coarse nodes on the dual-cell boundary \({\tilde{D}}^e\) and \(P_i\) is pressure on the nodes \(\tilde{{\varvec{x}}}_{i}\). Each basis function is solution of the local problems:

$$\begin{aligned} \begin{aligned} \nabla \cdot (-\lambda _t\nabla {\tilde{\psi }}_i^e )&=0 \quad in\ {\tilde{D}}^e\\ \end{aligned} \end{aligned}$$
(6)

for each node \(\tilde{{\varvec{x}}}_{i}\). Boundary conditions are given at the corners \(\tilde{{\varvec{x}}}_{i}\) by \({\tilde{\psi }}_i^e(\tilde{{\varvec{x}}}_{k})=\delta _{ik}\) and at the faces

$$\begin{aligned} \begin{aligned} \nabla _{\bot } \cdot (-\lambda _t\nabla {\tilde{\psi }}_i^e )_{\bot }&=0 \quad \text{ on }\ \partial {\tilde{D}}^e\setminus \{\tilde{{\varvec{x}}}_{i}\}\\ \end{aligned} \end{aligned}$$
(7)

where the subscript \(\bot\) represents the vector component normal to \(\partial {\tilde{D}}^e\) [23].

Once these basis functions are computed, the approximate coarse-scale pressure \(P^c\) is obtained and used to reconstruct a fine-scale pressure field \(P^f\) in each coarse cell \(D^k\), by superposition of the primal basis functions \(\psi _i^k\) at each vertex \({\varvec{x}}_{i}\) of \(D^k\):

$$\begin{aligned} P^f= \sum _{i=1}^{N_M}P_i^c\psi _i^k\quad \quad \end{aligned}$$
(8)

in that \(N_M\) is the number of cells in \(D^k\). The set of basis functions \(\psi _i^k\) is constructed on \(D^k\cap {\tilde{D}}^e \ne \emptyset\) and an elliptic problem is solved on \(D^k\):

$$\begin{aligned} \begin{aligned} \nabla \cdot (-\lambda _t\nabla \psi _i^k )&=s_f \quad in\ D^k,\\ \psi _i^k&=0 \quad on\ \partial D^k, \end{aligned} \end{aligned}$$
(9)

where \(s_f\) is a source term that distributes uniformly throughout the coarse volume [22]. Then, a fine-scale velocity field \({\textbf{v}}\) is obtained from the fine-scale pressure field \(P^f\) through the Darcy system (1). Afterwards, we use \({\textbf{v}}\) to update the saturation field on the fine-grid:

$$\begin{aligned} \phi \frac{\partial S}{\partial t} + {\textbf{v}}\cdot \nabla (f_w(S)) =0. \end{aligned}$$
(10)

Equation (2) is discretized in space by TPFA cell-centered finite volume scheme such that \(\lambda _t(S)\) is iteratively updated from Eq. (10) using an inner Newton–Raphson (NR) iteration loop [19].

For the time discretization of Eq. (10), we consider the partition \(0 \le t_0< t_1<\ldots < t_{N_t} = T\), \(t_n = n\Delta t\), where \(N_t\) is the number of time discretization steps and \(\Delta t\) is the time step. We use backward Euler to discretize in time [19, page 295] and find a numerical solution \(S^{n+1}\), where superscript \(n + 1\) indicates the solution at time \(t_{n+1}\). The following semi-discretized equation is satisfied:

$$\begin{aligned} \frac{ (\phi S)^{n+1}-(\phi S)^{n}}{\Delta t_{n+1}} = -({\textbf{v}})^{n+1}\cdot \nabla (f_w(S)^{n+1}). \end{aligned}$$
(11)

3 Inversion procedure

Let us state the inverse problem associated with the flow model (1)–(4). Given a set of \(N_w\) production wells, the observation data is represented as follows:

$$\begin{aligned} {\textbf{d}}^{\text {ref}}= & [{\textbf{d}}^{\text {ref}}_1, \ldots , {\textbf{d}}^{\text {ref}}_{N_w}]^T, \nonumber \\ {\textbf{d}}^{\text {ref}}_i= & [p_{1i}, \ldots , p_{N_ti}, S_{1i}, \ldots , S_{N_ti}]^T, \quad i = 1, \ldots , N_w. \end{aligned}$$
(12)

The data entries are the pressure \(p_{ni}\) and saturation \(S_{ni}\), where \(n = 1, \ldots , N_t\), \(i = 1, \ldots , N_w\). Thus, the total number of observations is \(N_d = 2N_t \cdot N_w\). Similarly, the pressure and saturation measures obtained as in Sect. 2 are

$$\begin{aligned} {\textbf{d}}(\phi ,\kappa )= & [{\textbf{d}}_1(\phi ,\kappa ), \ldots , {\textbf{d}}_{N_w}(\phi ,\kappa )]^T, \nonumber \\ {\textbf{d}}_i(\phi ,\kappa )= & [p_{1i}(\phi ,\kappa ), \ldots , p_{N_ti}(\phi ,\kappa ), S_{1i}(\phi ,\kappa ), \ldots , S_{N_ti}(\phi ,\kappa )]^T, \quad i = 1, \ldots , N_w, \end{aligned}$$
(13)

where \(\phi\) and \(\kappa\) are the porosity and the permeability fields, respectively. The nonlinear least-squares problem consists of finding the porosity and the permeability that minimize the misfit function

$$\begin{aligned} f(\phi ,\kappa ) =\frac{\sum _{i=1}^{N_d} (d^{ref}_i - d_i(\phi ,\kappa ))^2}{\sum _{i=1}^{N_d} (d^{ref}_i)^2}, \end{aligned}$$
(14)

The optimal parameters \(\phi\) and \(\kappa\) are estimated under a global point of view in the RW algorithm, and subsequently in a local point of view in the LM algorithm.

4 Parameterization of the fields

With the purpose of generating random samples of porosity and permeability to be effective minimizer candidates, we initially derive them from second-order stationary random fields that depend on the same covariance function, so that we can represent them using random fields Y whose KL expansion [13] is

$$\begin{aligned} Y({\varvec{x}};\omega ) = E(Y) + \sum _{k = 1}^\infty \sqrt{\lambda _{k}}f_{k}({\varvec{x}})\xi ^k(\omega ), \end{aligned}$$
(15)

where E(Y) is the mean of Y and \(\xi ^1(\omega ), \xi ^2(\omega ), \ldots\) are independent random variables. However, in the inversion procedure we will follow the ideas from Tartakovsky et al. [17], and consider the \(\xi ^k\)’s with \(k=1, \ldots ,\) not as random variables but as ‘coefficients’ of KL expansion. Thus, we aim to represent the permeability and porosity fields as a function that fits the observed data in terms of these coefficients.

The expressions \(\lambda _{k}\) and \(f_{k}({\varvec{x}})\) are respectively the eigenvalues and eigenfunctions obtained from the Fredholm integral equation of second kind

$$\begin{aligned} \int _{{\mathcal {R}}}C_{Y}({\varvec{x}}, {\varvec{y}})f_{k}({\varvec{y}})\,d{\varvec{y}} = \lambda _{k}f_{k}({\varvec{x}}), \quad k = 1, 2,\ldots . \end{aligned}$$
(16)

where \(C_Y\) is the covariance function. This approximation has been widely used in uncertainty quantification methods [13, 24, 25]. In practice, the series (15) is truncated and only few terms are needed when the eigenvalues decay fast. Assuming \(E(Y)= 0\), we rewrite the truncated expression of (15) as

$$\begin{aligned} Y_M({\varvec{x}};\varvec{\xi }) = \sum _{k = 1}^M \sqrt{\lambda _{k}}f_{k}({\varvec{x}})\xi ^k. \end{aligned}$$
(17)

The eigenvalues \(\lambda _{k}\) and eigenfunctions \(f_k\), \(k=1,\ldots ,M\) can be determined by a numerical approximation of the eigenvalue problem (16) by the piecewise-constant finite element method [14, 26].

We consider the Gauss covariance function

$$\begin{aligned} C_{Y}({{\textbf {x}}},{{\textbf {y}}}) = \sigma _Y^2\exp \left( -\frac{\Vert {{\textbf {x}}}-{{\textbf {y}}}\Vert _2^2}{2\ell ^2}\right) . \end{aligned}$$
(18)

where \(\ell\) is the correlation length and \(\sigma _Y^2 = E(Y^2)\) is the variance. The larger the correlation length, the faster the decay rate of the eigenvalue to zero, and the fewer terms needed in the KL expansion, while for a relatively small correlation length, a larger number of terms are needed to approximate Y with a reasonable accuracy.

Following [4], we define the porosity \(\phi\) as

$$\begin{aligned} \phi ({\varvec{x}},\varvec{\xi }_\phi ) = 0.24\cdot \exp (0.16\cdot Y_M({\varvec{x}},\varvec{\xi }_\phi )) \end{aligned}$$
(19)

and permeability field \(\kappa\) as

$$\begin{aligned} \kappa ({\varvec{x}},\varvec{\xi }_\kappa ) = 4.2\times 10^{-14}\cdot \exp (Y_M({\varvec{x}},\varvec{\xi }_\kappa )), \end{aligned}$$
(20)

where \(Y_M\) is of the form (17), but \(\phi\) and \(\kappa\) have separate sets of coefficients, which are denoted as \(\xi ^k_\phi\) and \(\xi ^k_{\kappa }\) (\(1\le k\le M\)), respectively. Thus, omitting the spatial parameter \({\varvec{x}}\), we can rewrite the porosity \(\phi\) and permeability \(\kappa\) as follows:

$$\begin{aligned} \begin{aligned} \phi (\varvec{\xi }_\phi )&= \phi (\xi ^1_\phi , \ldots , \xi ^M_\phi ),\\ \kappa (\varvec{\xi }_\kappa )&= \kappa (\xi _\kappa ^1, \ldots , \xi ^M_\kappa ). \end{aligned} \end{aligned}$$
(21)

where \(\varvec{\xi }_\phi\) and \(\varvec{\xi }_\kappa\) are independent vectors in \({\mathbb {R}}^{M}\).

4.1 Dimensionality reduction

As described by [17], the bulk variance is given by

$$\begin{aligned} \int _{\mathcal {R}} Var(Y({\varvec{x}}))d{\varvec{x}} = \sum _{k = 1}^\infty \lambda _{k}. \end{aligned}$$
(22)

This equation enables the reduction of spatial dimensionality in field parameterization by choosing the lowest integer M such that

$$\begin{aligned} \sum _{k=1}^{M} \lambda _k \ge \gamma \sum _{k=1}^{\infty } \lambda _k, \end{aligned}$$
(23)

where \(0 < \gamma \le 1\) represents the desired confidence level. Inequality (23) implies that M is selected such that the sum of the first M eigenvalues captures a significant portion of the total variance. The decay of the eigenvalues, i.e., how quickly they decrease in magnitude, affects the value of M. If the eigenvalues decay rapidly, fewer modes (a smaller M) are needed to capture most of the variance. Conversely, if the eigenvalues decay slowly, a larger M may be required.

5 Markov Chain Monte Carlo

Following [3], we discuss how to obtain the porosity and permeability fields using the pressure and saturation data from the monitoring wells of the reservoir within the framework of Bayesian inverse theory.

Let us denote the pressure and saturation dataset as \({\mathcal {F}}^{ref} = \{p^{ref}, S^{ref}\}\). The corresponding estimated pressure and saturation set is defined by \({\mathcal {F}}^{est}= \{p^{est}, S^{est}\}\). In this case, we want to measure conditional probability between the vector \(\varvec{\xi } = \{\varvec{\xi }_\phi , \varvec{\xi }_\kappa \} \in {\mathbb {R}}^{2\,M}\) and the error measure of the sets \({\mathcal {F}}^{ref}\) and \({\mathcal {F}}^{est}\). To generate a new proposed sample \(\varvec{\xi }\), we define \(\varvec{\xi }^{(k)} = \varvec{\xi } + (-1)^{k-1}\tau {\varvec{u}}_k\), where \(\varvec{\xi }\sim U({\varvec{0}}, {\varvec{I}})\), \({\varvec{u}}_k\sim U(0,\Delta \varvec{\xi })\), and \(\Delta \varvec{\xi } = \min (\varvec{\xi }-\varvec{\xi }^{min},\varvec{\xi }^{max}-\varvec{\xi })\). Here, \(\tau \in (0, 1]\) is referred to as the tuning parameter. In our experiments, we set \(\tau = 0.25\). Further details on the selection of \(\tau\) are discussed in [27].

Using the Bayes’s theorem, we can write the posterior probability combined with prior information by

$$\begin{aligned} \pi (\varvec{\xi })\propto P(\{{\mathcal {F}}^{ref}, {\mathcal {F}}^{est}\}|\varvec{\xi })P(\varvec{\xi }). \end{aligned}$$
(24)

where \(P(\{{\mathcal {F}}^{ref}, {\mathcal {F}}^{est}\}|\varvec{\xi })\) is the likelihood function and \(P(\varvec{\xi })\) represents the prior distribution. The normalizing constant is ignored due to the iterative search in the MCMC algorithm.

In our experiments we admit that the likelihood function is a Gaussian distribution defined by

$$\begin{aligned} P\left( \{{\mathcal {F}}^{ref},{\mathcal {F}}^{est}\}|\varvec{\xi }\right) \propto \exp \left( -\frac{f(\phi (\varvec{\xi }_\phi ), \kappa (\varvec{\xi }_\kappa ))}{\sigma _{\varvec{\xi }}^2}\right) , \end{aligned}$$
(25)

where \(\sigma _{\varvec{\xi }}\) is a precision parameter for each porosity and permeability distribution into \(\varvec{\xi }\), and \(f(\phi (\varvec{\xi }_\phi ), \kappa (\varvec{\xi }_\kappa ))\) is the misfit function of pressure and saturation defined in (14).

In order to compute the posterior distribution as the target distribution, we adopt a MCMC method employing the RW algorithm. In this method, the proposed sample \(\varvec{\xi }\) can be accepted or rejected with probability:

$$\begin{aligned} \nu (\varvec{\xi },\varvec{\xi }^{(n)}) = \min \left\{ 1,\frac{f(\phi (\varvec{\xi }_\phi ^{(n)}), \kappa (\varvec{\xi }_\kappa ^{(n)}))}{ f(\phi (\varvec{\xi }_\phi ), \kappa (\varvec{\xi }_\kappa )))}\right\} . \end{aligned}$$
(26)

If the proposal is not accepted, then the current value of \(\varvec{\xi }\) is retained. A summary of the RW algorithm is given below:

Algorithm 1
figure a

Random Walk algorithm

In this instance, the terms \(N_c\) and \(N_{s}\) refer to the number of chains and samples used in the experiment, respectively. It is important to highlight that this algorithm only requires a proposal distribution, a function for generating random numbers, and a function for calculating the probability density of each proposal.

6 Levenberg–Marquardt algorithm

The initial coefficient \(\varvec{\xi }^{(0)} = \{\varvec{\xi }_\phi ^{(0)}, \varvec{\xi }_\kappa ^{(0)}\}\) obtained from RW algorithm can be refined by solving the following nonlinear least-squares problem

$$\begin{aligned} g(\varvec{\xi }) = \min _{\varvec{\xi }\in {\mathbb {R}}^{2M}}\frac{1}{2}\Vert {{\textbf {d}}}(\phi (\varvec{\xi }_\phi ), \kappa (\varvec{\xi }_\kappa ))-{\textbf{d}}^{\text {ref}}\Vert _2^2. \end{aligned}$$
(27)

To determine the numerical solution to this problem, we employ the classical Levenberg–Marquardt (LM) method [28]:

$$\begin{aligned} \left( ({{\textbf {J}}}^{(k)})^T{{\textbf {J}}}^{(k)}+\mu _k{{\textbf {I}}}\right) {{\textbf {p}}}^{(k)}= & -({{\textbf {J}}}^{(k)})^T{{\textbf {d}}}^{(k)}\end{aligned}$$
(28)
$$\begin{aligned} \varvec{\xi }^{(k+1)}= & \varvec{\xi }^{(k)} + \alpha _k {{\textbf {p}}}^{(k)}, \end{aligned}$$
(29)

where \({{\textbf {d}}}^{(k)} = {{\textbf {d}}}(\phi (\varvec{\xi }_\phi ^{(k)}), \kappa (\varvec{\xi }_\kappa ^{(k)}))-{\textbf{d}}^{\text {ref}}\). Here, \(\mu _k > 0\) is referred to as the damping parameter, ensuring the invertibility of the matrix \(({{\textbf {J}}}^{(k)})^T{{\textbf {J}}}^{(k)}+\mu _k{{\textbf {I}}}\), and \(\alpha _k > 0\) represents the step size. The entries of \({{\textbf {J}}}^{(k)}\) are given as follows (see [29]):

$$\begin{aligned} J^{(k)}_{ij}=\displaystyle {\frac{\partial d_i}{\partial \xi _j}(\phi (\varvec{\xi }_\phi ^{(k)}), \kappa (\varvec{\xi }_\kappa ^{(k)}))} \quad (1\le i\le \ N_d,\quad 1\le j\le \ 2M). \end{aligned}$$
(30)

Following [28, 30], the damping parameter is given by \(\mu _k:= \Vert {{\textbf {d}}}(\phi (\varvec{\xi }_\phi ^{(k)}), \kappa (\varvec{\xi }_\kappa ^{(k)})-{\textbf{d}}^{\text {ref}}\Vert _2^2\), for all \(k \ge 0\), while the step \(\alpha _k\) is determined by Armijo’s Criterion. Given the scalars \(0< \nu , \eta < 1\), this step is chosen as the smallest non-negative integer m that satisfies:

$$\begin{aligned} g(\varvec{\xi }^{(k)} + \eta ^m {{\textbf {p}}}^{(k)}) - g(\varvec{\xi }^{(k)}) \le \nu \eta ^m \nabla g(\varvec{\xi }^{(k)})^T {{\textbf {p}}}^{(k)}, \end{aligned}$$
(31)

so that \(\alpha _k = \eta ^m\). The method terminates when the specified number of iterations or tolerance is achieved. In the following, we provide a summary of the LM algorithm into Algorithm 2.

Algorithm 2
figure b

LM algorithm

7 Numerical experiments

In this section, we consider a synthetic two-dimensional reservoir model coupled with transient pressure and saturation data governed by Eqs. (1) to (4) in a square domain \({\mathcal {R}} = [0, 1000\,m] \times [0, 1000\,m]\), partitioned by a uniform grid. The fine-scale models have dimensions of \(50 \times 50\) cells, while the coarse-scale models, obtained through a uniform coarsening of the mesh using the dual grid, consist of \(5 \times 5\) cells.

Using realizations of porosity and permeability fields generated as in Sect. 4, we build independent samples of these fields. The quality of these realizations is examined by comparing the simulated solution with the specified reference solution on \(50 \times 50\) cells. Following Ginting et al. [15], we fix the value of the \(\sigma _{\varvec{\xi }}\) in the likelihood function (25), since treating this parameter as random can cause unrealistic estimates to the model. In our application, we specify \(\sigma _{\varvec{\xi }} = 0.3\).

In our experiments the covariance was computed in a separate subroutine on a \(50\times 50\) grid in blocks of unit length. We conducted experiments using the parameter sets \(\{\sigma _Y, \ell \} = \{1, 400\}\), \(\{\sigma _Y, \ell \} = \{1, 200\}\), and \(\{\sigma _Y, \ell \} = \{2, 200\}\). Using Eq. (23), we found that more than \(\gamma = 95\%\) of the variance in the KL expansion is captured by the first 20 dominant eigenvalues in all experiments. Consequently, \(M = 20\) is sufficient for the size of the stochastic dimension. Moreover, the scalars defining the Armijo step (31) are chosen as \(\nu = 0.01\) and \(\eta = 0.7\) (see [30]).

To validate our methodology, we investigate the impact of injection and production procedures on porosity and permeability fields using the well-known five-spot problem. In this case, oil is extracted using saltwater injection. Four production wells, labeled as \(W_1\), \(W_2\), \(W_3\), and \(W_4\), are symmetrically positioned at the vertices of an injection well, labeled as I, positioned in the center of the square domain. Initial conditions are applied to saltwater injection and oil production, considering saturation values of \(S=1\) and \(S=0\), respectively, while the initial pressure is zero. Additionally, Dirichlet conditions are directly imposed through the definition of injection and production wells, and Neumann conditions are applied using impermeable boundaries represented by \(\Gamma _{noflow}\). For more details on initial and boundary conditions see [19]. We use data from the four production wells in a simulation period of \([0, T] = [0, 300]\) days divided into five equally-spaced intervals. The reservoir parameters, production data, and other extra parameters for particle release, transport, and capture are given in Table 1. An illustration of the boundary and initial conditions can be found in Fig. 2.

Table 1 Summary of the reservoir properties for the oil–salt water model
Fig. 2
figure 2

Initial and boundary conditions for the five-spot scheme in the case study

The aim of this numerical experiment is to simulate the production of an initially over pressured fluid trapped in a underground. To begin the inversion procedure, we first select prior samples for the KL coefficients of porosity and permeability using a uniform distribution ranging between 0 and 1, as described in Algorithm 1.

To establish our initial estimate, we rely on 5000 realizations in RW simulations with \(N_c = 4\) chains, generated from different seeds. Subsequently, we employ the LM algorithm to enhance the precision of the field. The computation was performed on a personal computer (11th Gen Intel(R) Core(TM) i7-1165G7 CPU @ 2.80 GHz, 1.69 GHz, with 16 GB of RAM) and the codes were written in a separate module within the open-source Matlab Reservoir Simulation Toolbox (MRST) [19]. The version of the MATLAB code used in this article is available as a Supplementary File.

Using Eq. (14), we compute the misfit from pressure and flow saturation in terms of the iterations in the RW algorithm, where we search for the best RW vector \(\varvec{\xi }^{(0)}\) as the initial model among all chains. In this case, the misfit was reduced from 5.1485 to 0.3766, while in the LM algorithm, it decreased further from 0.3766 to 0.0053 over 25 iterations. In contrast, when using the LM algorithm directly from the initial guess, the error was 1.3975 after the same number of iterations. This number of iterations was chosen to reach a tolerance of 0.01 in the misfit and was then fixed for the subsequent experiments. Additionally, the relative errors of porosity and permeability were computed using the Root Mean Square Error (RMSE) metric across the entire domain. These results, along with the CPU times are summarized in Table 2 and indicate that the RW algorithm could provide useful initial models for the LM local algorithm. Hence, the RW algorithm could serve as an effective starting point for the LM local algorithm.

Table 2 RMSE for porosity and permeability using initial guess, RW, LM, and RW-LM, and CPU time considering \(\sigma _Y =1\) and \(\ell = 400\)

Figures 3 and 4 compare the reference data, initial data, and the best-fitted porosity and permeability fields obtained from RW, LM, and RW-LM simulations for production wells and saturation over a time period spanning from 0 to 300 days. In the case of LM, the initial guess was used, while in the RW-LM combination, the fields selected from RW were refined through the LM algorithm. The dashed lines represent the initial and the best fitted models. The pressure and saturation solutions obtained in all wells by new combined RW-LM algorithm are much closer to target solution.

Fig. 3
figure 3

Production rates of the water production rate versus time for \(\sigma _Y = 1\) and \(\ell = 400\), associated with production wells \(W_1\) (a), \(W_2\) (b), \(W_3\) (c) and \(W_4\) (d). Solid lines denote the reference solution and dashed line the initial, optimal approximation from RW and RW-LM

Fig. 4
figure 4

Fluid saturation versus time for \(\sigma _Y = 1\) and \(\ell = 400\), associated with production wells \(W_1\) (a), \(W_2\) (b), \(W_3\) (c) and \(W_4\) (d). Solid lines denote the reference solution and dashed line the initial, optimal approximation from RW and RW-LM

Figure 5 displays the porosity fields of initial state and reference, along with the fields numerically approximated by RW, LM and the proposed RW-LM, accompanied by their respective relative errors. After conducting a sufficient number of iterations, the MCMC approach selects fields that best fit the model. Figures 5c, d do not show a good correspondence with the reference field illustrated in Fig. 5a. However, a significant improvement in the porosity field is observed when the LM algorithm is applied after RW (see Fig. 5e). Similar behavior was observed in the permeability fields, as illustrated in Figure  6.

Fig. 5
figure 5

(a) Reference and (b) initial porosity field. Numerical approximation using (c) RW, (d) LM, and (e) RW-LM algorithms for the porosity field for \(\sigma _Y = 1\) and \(\ell = 400\)

Fig. 6
figure 6

(a) Reference and (b) initial log-permeability field. Numerical approximation using (c) RW, (d) LM, and (e) RW-LM algorithms for the log-permeability field for \(\sigma _Y = 1\) and \(\ell = 400\)

In this second experiment, we aim to investigate the behavior of the proposed methodology by varying the variance and reducing the correlation length to obtain less smooth fields. We will consider the variation of parameters for \(\sigma _Y = 1\) and \(\ell = 200\) as well as \(\sigma _Y = 2\) and \(\ell = 200\). The relative errors associated with the porosity and permeability fields, along with the misfit and CPU times, are presented in Table 3. It is noteworthy that the RMSEs of the LM solution are mostly higher than those of the initial guess. On the other hand, the direct application of the LM method to the initial guess improved the misfit, as expected. We emphasize that the misfit is evaluated at the production wells only, while the RMSEs consider the entire domain.

Table 3 RMSE for porosity and permeability using initial guess, RW, LM, and RW-LM, and CPU time, considering the pairs (\(\sigma _Y = 1\), \(\ell = 200\)) and (\(\sigma _Y = 2\), \(\ell = 200\))

To better illustrate the data presented in Table 3, Figs. 7 and 8 display the reference fields alongside the approximation fields of porosity and permeability, respectively considering \(\sigma _Y = 1\) and \(\ell = 200\). As in the first experiment, it can be observed that the RW-LM combination yielded porosity and permeability fields that closely approximate the reference fields, in contrast to those derived from RW and LM originating from the initial guess. Nonetheless, the RW method succeeded in establishing a robust initial guess for this set of parameters. However, upon increasing the variability of the model, the approximated fields failed to converge to the reference fields of porosity and permeability (see Figs. 9-10). This result suggests that a greater number of samples in the RW method and an increased number of iterations in the LM algorithm may be required to achieve convergence.

Fig. 7
figure 7

(a) Reference and (b) initial porosity field. Numerical approximation using (c) RW, (d) LM, and (e) RW-LM algorithms for the porosity field for \(\sigma _Y = 1\) and \(\ell = 200\)

Fig. 8
figure 8

(a) Reference and (b) initial log-permeability field. Numerical approximation using (c) RW, (d) LM, and (e) RW-LM algorithms for the log-permeability field for \(\sigma _Y = 1\) and \(\ell = 200\)

Fig. 9
figure 9

(a) Reference and (b) initial porosity field. Numerical approximation using (c) RW, (d) LM, and (e) RW-LM algorithms for the porosity field for \(\sigma _Y = 2\) and \(\ell = 200\)

Fig. 10
figure 10

(a) Reference and (b) initial log-permeability field. Numerical approximation using (c) RW, (d) LM, and (e) RW-LM algorithms for the log-permeability field for \(\sigma _Y = 2\) and \(\ell = 200\)

Remark 1

The misfit \(f(\phi , \kappa )\) was tested with \(L_1\) and \(L_\infty\) norms. Due to the particular boundary configurations in our examples, the misfit computed from different norms do not have significant difference and therefore will not be presented.

Remark 2

We have not presented any statistics of the porosity and permeability models. It is not clear how the LM method could possibly contribute to the statistics of the inverted parameters, as it is a deterministic approach. However, statistics may be derived from the samples generated during the RW algorithm [27]. These statistics could be useful to validate the RW-LM solution.

8 Conclusion

This study focused on a robust combined RW-LM algorithm, capable of efficiently solving inverse problems in highly heterogeneous porosity and permeability fields. The proposed methodology utilizes Markov chains with Gaussian covariance to control the acceptance or rejection of heterogeneous fields within the MsFV. The solution is then refined by LM, using a local minimum algorithm. Moreover, the method was capable to highlight characteristics of the target fields in the numerical experiments. Additionally, only a few iterations were used in the local search to achieve convergence. Another crucial observation is that it facilitates the extension of characterization to multiple independent fields and provides a close approximation of numerical pressure and saturation solutions.