Reservoir Simulation With Python (Notes - Math - Code)
Reservoir Simulation With Python (Notes - Math - Code)
Python
Divyanshu Vyas
(Petroleum Data Scientist)
Topics Covered
1. Introduction to Reservoir Simulation.
2. Procedure and Workflow.
3. Theoretical Aspects.
4. Mathematics – The Diffusivity Equation
❑ Numerical Methods – Finite Difference Methods (Space – Time
Discretization).
❑ Explicit Method
❑ Implicit Method
5. Solving the HEAT Equation (PDE) in Python.
6. Solving Pressure Diffusivity Equation (From Scratch) in Python.
7. Understanding the Work-Flow of a Commercial Simulator.
8. History Matching
1. Introduction to Reservoir
Simulation
• The Primary Goal of Building a Reservoir Model or a Simulation is to
choose between a set of Field Development Options. The Choice
suggested by the Simulation is believed to be the most efficient amongst
all.
• It can help answer questions like How much Oil can the reservoir
Produce? What’s the best way to produce? How to be the most
economic? What’s the Best EOR scheme? Why is the reservoir not
behaving like expected? From what Portion of the reservoir is the
production coming? What’s the portion of the reservoir that can be
considered as inactive?
• The main feature that a Simulation captures is the Reservoir
Heterogeneity. And that helps develop practical realisations rather than
ideal realisations.
• So Basically, a simulator can help us give the quantitative effects of the
inputs that we provide to it. Example – What if I change this well from a
producer to an injector? What’s the effect on Ultimate Oil Recovery?
1.1 Inputs that Go into a
Simulator
• Geometry and Structural Attributes – These correspond to the Grid
Configuration, which is driven by the inputs of Geological Team. This
along with the structural attributes – Horizons, faults, compartments
etc (driven by Geophysical team) gives us a structural model.
• Petro-physical data – porosity, saturation etc. These go into the Static
Grid Blocks and give us the Initialized Static Model.
• Well Test and PVT data – This can be obtained by Formation Testers
etc (While Drilling) or by Laboratory experiments, to ultimately be
used as inputs. Fluid Viscosity, FVF (B), Compressibility, Permeability
etc.
• Reservoir Engineering Parameters – All the fluid flow models to be
used, they enter as inputs by the RE team. This makes the model a
dynamic model since now fluid flow is considered.
• Well Models, Completion history etc.
2. Procedure and Work-Flow
Reservoir Simulation is not a Stage-wise process.
Almost All the teams from E&P work in sync.
Geology
Petro-
Geophysics
physics
Production Reservoir
Engineering Engineering.
4. Mathematics
• Just like the heat equation (2nd order in space and 1st order in time)
gives us the way Heat travels and Temperature Varies in the system,
• The Diffusivity Equation (2nd order in space and 1st order in time)
gives us the way a disturbance due to fluid-production travels and
Pressure varies in a space-time domain in the reservoir. And That’s
the heart of Reservoir Simulation.
• All the parameters – Like Saturation, Porosity, Viscosity,
compressibility are somehow a function of Pressure. Some are
strong functions and some are weak functions of P. But the
Important part is, If we can model the solution – The way the
Pressure varies in the reservoir as a function of space and time,
we can actually model the way the Saturation would vary as a
function of space and time.
• And this is of immense importance, because that’s what the goal is.
• Which process/scheme would give a Pressure solution that results
in the most efficient path to a irreducible (non-recoverable) oil
saturation.
4.1 Basic Methodology
• Diffusivity Equation
PDE
• Can be solved analytically by FFT/Laplace Transforms etc.
• Discretization in Space.
Grids – • Discretization in Time
Numerical Soln.
t
kA P V
→ x + q ' =
x B x t B
P B
2
c P
→ 2 + q ' + =
x kAx k t
• Discretized in space version-
Pi +1 − 2 Pi + Pi −1 B c P
→ + q ' =
x kAx k t
2
P t
• Explicit- → i+1 − 2 P t
+ P t
B c P t +1
− P t
i i −1
+ q ' =
kAx k t
i i
x 2
• Here, In Explicit-Methodology, we can fine the new pressure
at every new time step for every grid block.
• This method is computationally easier, as the LHS gives a new
value based on the RHS. The relation is not recurrent.
• However, the Explicit methodology involves a limitation.
• It is not always stable. It cannot give accurate results for large
time steps.
t
0.5
x 2
− 1.203 1 0 0 P1t +1 − 85
1
− 2.0213 1 0 P2t +1 113.2
→ * t +1 =
0 1 − 2.0213 1 P3 − 85
t +1
0 0 2 1 P4 − 85
−1
P1t +1 − 1.203 1 0 0 − 85
t +1
P2 1 − 2.0213 1 0 113.2
→ t +1 =
P3 0 1 − 2.0213 1 − 85
t +1
P4 0 0 2 1 − 85
5. Solving the Heat Equation in
Python
• The Heat Equation is the same PDE as the
Diffusivity Equation.
u2
u
= (1 / )
x 2
t
→ u = T ( x, t )
• Step 1 – Initializing Properties.
• Step 2 – Solving for Temperature variation.
5. Solving the Pressure-Diffusivity Equation in Python
Step 1: Initializing Rock-Fluid Properties
Step 1: Initializing Rock-Fluid Properties
Step 2 : Setting Initial Pressure Conditions.
Step 4: Solving the
System for P(x,t).
SIMULATION
OUTPUT
5.1 Solving the Pressure-Diffusivity Equation in Python using a PDE.
solver
• Discretization in space
GRID
• Used Later in life of a Simulation Project, to tweak parameters in order to obtain a ‘History Match’.
EDIT*
• Add RCAL/SCAL/PVT/Fluid-Tables.
PROPS
SOLUTION-
• Define Equilllibrium states. Fluid contacts etc.
STATES
Source: https://www.aogr.com/magazine/editors-choice/dynamic-reservoir-model-supports-reservoir-management
Appendix: Other Relevant procedures covered-
1. Well Tests are a key step, that help get Permeability values for a considerable depth
of investigation.
Code - https://github.com/Divyanshu-ISM/Oil-and-Gas-data-analysis/blob/master/Well_Test_Analysis.ipynb
2. Algebraically Solving for Pressures (from Scratch) using the Transmissibility form of grid-
block flow equation. (Abou Kassem et al.)
Code - https://github.com/Divyanshu-ISM/Oil-and-Gas-data-analysis/blob/master/SinglePhaseFlowSimulator1.ipynb
https://github.com/Divyanshu-ISM/Oil-and-Gas-
data-analysis
Thank You.