## 8 Stochastic Inversion Algorithm to Decipher Dual-Porosity Sandstones  
As implemented by [PERSON] et al. [17], we utilize the same optimization engine (VFSA) to minimize the objective function (see Appendices A and B for details). In this paper, an objective function is defined as the root mean square of differences between simulated and observed well logs including density, resistivity, and P- and S-wave slowness logs (DTCO and DTSM). Two sets of parameters are defined in the optimization workflow. Global parameters consist of matrix density, matrix bulk and shear moduli, salinity, critical porosity, intergranular lithology exponent for resistivity, and intergranular L parameter (length scales) for bulk and shear moduli. Global parameters remain constant over the depth interval of interest. The micropore lithology exponent for resistivity is set to 0.75 based on previously published results [3]. Micropore L parameters for bulk and shear moduli are set to 1.0 based on the previously published results [3]. In VFSA optimization structure, we evaluate the global error function to update the global model parameters. Local model parameters changing as functions of depth include intergranular porosity (\(\varphi_{i}\)), microporosity (\(\varphi_{m}\)), total porosity (\(\varphi_{t}\)), and water saturation (\(S_{w}\)) at each depth interval. In VFSA structure, we evaluate the local error function to update the local model parameters in the corresponding depth interval. We design an objective function that has four terms. The first term is the difference between bulk density well-log data (\(\rho_{b}^{obs}\)) and modeled bulk density (\(\rho_{b}^{sim}\)) using the mass balance equations. The second term is the difference between resistivity well-log data (\(R^{obs}\)) and modeled resistivity (\(R^{sim}\)) using the PCM methodology. The third and fourth terms are the difference between DTCO and DTSM well-log measurements (\(DTCO^{obs}\) and \(DTSM^{obs}\)) and their corresponding simulated logs using the SDEM model (\(DTCO^{sim}\) and \(DTSM^{sim}\)). Note that all the terms are normalized to the summation of well-log observations and simulated well-log responses. This will facilitate the quality control of error (objective or cost) function. \[ \begin{split}\Delta E=\frac{\sum_{i=1}^{n}\left(\rho_{b}^{sim}- \rho_{b}^{obs}\right)^{2}}{\sum_{i=1}^{n}\left(\rho_{b}^{sim}+\rho_{b}^{obs} \right)^{2}}+\frac{\sum_{i=1}^{n}\left(R^{sim}-R^{obs}\right)^{2}}{\sum_{i=1}^ {n}\left(R^{sim}+R^{obs}\right)^{2}}+\frac{\sum_{i=1}^{n}\left(DTCO^{sim}-DTCO^ {obs}\right)^{2}}{\sum_{i=1}^{n}\left(DTCO^{sim}+DTCO^{obs}\right)^{2}}\\ +\frac{\sum_{i=1}^{n}\left(DTSM^{sim}-DTSM^{obs}\right)^{2}}{\sum_{i=1}^ {n}\left(DTSM^{sim}+DTSM^{obs}\right)^{2}}\end{split}  \tag{8}\]  
To converge the VFSA optimization and to obtain meaningful physical model parameters, we apply several constraints. Some of the important ones follow:  
1. In each depth interval, the microporosity and intergranular porosities are smaller or equal to given total porosities. \[\varphi_{i}\leq\varphi_{t}\] (9) \[\varphi_{m}\leq\varphi_{t}\] (10)
2. In each depth interval, the sum of microporosity and intergranular porosity should be equal to total porosities. \[\varphi_{i}+\varphi_{m}=\varphi_{t}\] (11)
3. The lower search bounds on total porosity are computed from the density log. Initial upper and lower bounds are first computed using a heavy mixture (heavy grain and water) and a light mixture (light grain and hydrocarbon), respectively. Then, safety factors in percentage are added to and subtracted from initial upper and lower bounds, respectively, to form conservative search bounds (Figure 8). In Figure 9, a single realization of true and inverted petrophysical properties and associated well-log responses are overlaid in different panels. The inversion workflow is capable of matching the data for the three portions of carbonate formation (oil column, water leg, and transition zone) and retrieving intergranular, micro, total, and water-filled porosities with high precision.