# Parallel Reservoir Simulation with OpenACC and Domain Decomposition
## 3 Materials and Methods
### The Black-Oil Model Reservoir Simulation  
The main task of reservoir simulation is to analyze the exact distribution of the underground remaining oil, more exactly adjusting the wells' locations using simulating the fluid dynamics. The procedure of a reservoir simulation is illustrated in Figure 1. Noted that the reservoir simulation is based on the finite difference method (FDM). As we can see, the simulation procedure consists of three parts:  
1. (Initialization) This part inputs and initializes the raw data (i.e., oil reservoir data records) and parameters, it belongs to a preprocessing stage for black-oil reservoir simulation.
2. (Computation) This part is the key of reservoir simulation which repeatedly builds a Jacobian matrix and solves the linear equation. One common method is using [PERSON]'s method to convert the nonlinear equations into linear equations, then solve the linear equations. In each time step, the procedure of solving equations is performed first in the Jacobian matrix and solved until the computing result is convergent. Then the parameter is updated timely. The iteration mentioned above is carried out until the loop termination condition is satisfied.
3. (Output) This part outputs the final computation results.  
Considering a three-phase (oil, gas and water) black-oil system, assuming the gas component can exist in both the gas and the oil phases, and oil and water components can only exist in their own phases. The differential equations for oil, gas and water components can be respectively written as:  
_Oil component:_  
\[\
abla\left[\frac{\mathbb{K}\kappa_{ro}\rho_{o}}{\mu_{o}}(\
abla p_{o}-\gamma_{ og}\
abla D)\right]=\frac{\partial(\phi_{o}S_{o})}{\partial t} \tag{1}\]  
where \(K\) is the absolute permeability, \(K_{ro}\) means the relative permeability of phase oil, \(\rho_{o}\) is the density of phase oil, \(\mu_{o}\) represents the viscosity of phase oil, \(\rho_{o}\) is the pressure of phase oil, \(\gamma_{og}\) is the unit weight, D is the depth, \(S_{o}\) is the saturation of phase oil, and \(\
abla\) is the gradient operator.  
Similarly, the differential equations for gas and water components can be respectively written as, _Gas and Water component:_  
\[\
abla[\frac{KK_{\pi\rho gd}}{\mu_{o}}(\
abla P_{o}-\gamma_{gg} \
abla D)+\frac{KK_{\pi\rho g}}{\mu_{g}}(\
abla P_{g}- \tag{2}\] \[\gamma_{g}\
abla D)]=\frac{\partial\left(\phi_{\rho gd}S_{o}+ \phi_{g}S_{g}\right)}{\partial t}\] (3) \[\
abla\left[\frac{KK_{\pi\rho g}}{\mu_{o}}(\
abla P_{w}-\gamma_{ w}\
abla D)\right]=\frac{\partial\left(\phi_{\rho g}S_{w}\right)}{\partial t}\]  
where \(K_{\pi g}\), \(K_{\pi}w\) mean the relative permeability of phase gas and water, \(\rho_{gd}\), \(\rho_{g}\) and \(\rho_{w}\) are respectively the density of gas component in oil phase, gas phase, water. \(P_{g}\), \(P_{w}\) are the pressure of phase gas and water, \(S_{g}\), \(S_{w}\) mean the saturation of phase gas and water.  
In addition, the black-oil model involves 6 unknowns: \(P_{o}\), \(P_{g}\), \(P_{w}\), \(S_{o}\), \(S_{w}\), \(S_{g}\), but there are three equations above, so three auxiliary equations are introduced here.  
This is the Saturation Constraint,  
\[S_{o}+S_{w}+S_{g}=1 \tag{4}\]  
Figure 1: The flowchart of reservoir simulation.  
and the remaining two equations are the Capillary Pressures Constraint,  
\[\left\{\begin{array}{l}P_{w}=P_{o}-P_{cow}\\ P_{g}=p_{o}+p_{cog}\end{array}\right. \tag{5}\]  
where \(P_{cow}\) is the capillary pressure of oil and water system, meanwhile \(P_{cog}\) notes the capillary pressure of oil and gas system.  
The black-oil model is built, it is basis of reservoir simulation.