0% found this document useful (0 votes)
752 views

Reservoir Simulation With Python (Notes - Math - Code)

The document discusses reservoir simulation using Python. It covers topics like introducing reservoir simulation, the workflow, theoretical aspects like the diffusivity equation, numerical methods like finite difference, and solving examples of the heat and pressure diffusivity equations from scratch in Python. It also discusses understanding the workflow of commercial simulators and history matching. The key steps involve initializing properties, setting boundary and initial conditions, discretizing the equations, and solving the numerical system to model pressure change over space and time.

Uploaded by

Mustafa Naithel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
752 views

Reservoir Simulation With Python (Notes - Math - Code)

The document discusses reservoir simulation using Python. It covers topics like introducing reservoir simulation, the workflow, theoretical aspects like the diffusivity equation, numerical methods like finite difference, and solving examples of the heat and pressure diffusivity equations from scratch in Python. It also discusses understanding the workflow of commercial simulators and history matching. The key steps involve initializing properties, setting boundary and initial conditions, discretizing the equations, and solving the numerical system to model pressure change over space and time.

Uploaded by

Mustafa Naithel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Reservoir Simulation with

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.

• Inputs as in Rock-Fluid Properties.


• Conditions as in Initial / Inner BC / Outer BC
Adding Inputs
and Conditions. • Well Models if applicable.

• Solution Modes – Implicit | Explicit | Crank-Nicholson


Solution
4.2 Elaboration on Steps- Finite Difference
Methods (Space – Time Discretization).
k
→ = Note : −
c
→  = 5.615
2P 2P 2P P →  = 0.001127
→ + + = (1 /  )
x 2
y 2
z 2
t
P
→  P = (1 /  )
2

t
   kA P  V   
→  x + q ' =  
x  B x   t  B 
 P  B
2
 c P
→ 2 +  q ' + =
x  kAx   k t
• Discretized in space version-

Pi +1 − 2 Pi + Pi −1  B  c P
→ +  q '  =
x  kAx   k t
2

• Discretized in time version- Depending on this we can choose


if we want to go explicit or implicit.

Pi+t1+1 − 2 Pit +1 + Pi−t1+1  B  c Pi t +1 − Pi t


• Implicit- → +  q'  =
x  kAx   k t
2

P t
• Explicit- → i+1 − 2 P t
+ P t
 B  c P t +1
− P t
i i −1
+  q '  =
 kAx   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

• The Implicit-Methodology is unconditionally stable, no matter


how long the time step you pick.
• By time step we mean delta t.
• However, in this, we have to solve N simultaneous equations.
• Hence it is computationally involving.
4.3 Solved Example to explain the
workflow.
• Given – 1D Flow | unsteady state | Single Phase. Homogeneous Property
distribution. phi = 0.30 | Kx = 178 mD | Viscocity = 1 cp |B = 1 rb/STB | c =5E-6
psi .
• Given – Blocks at exteremes have No Flow Boundaries. Blocks in well 2 and 6
produce 2000 STB/day. P(initial) = 4000 psia.
• Solve using Implicit (Backward diff. In time).

Pi+t 1+1 − 2 Pit +1 + Pi−t1+1  B  c Pi t +1 − Pi t


→ +  q '  =
x 2  kAx   k t
 B 
→  q '   6.23 *10 −7 q '
 kAx 
c Pi t +1 − Pi t
→  0.0213 * ( Pi t +1 − Pi t )
 k t
• Initial Condition – Pi = 4000 (all blocks)
• By Symmetry –
P1 = P7 | P2 = P6 | P3 = P5
• Blocks 2 and 6 have wells with q’ = -2000
STB/d and hence they’ll have the flow term.
• Rest all won’t.
• We only have to solve for half of the system,
based on symmetry.
 P1t  4000
 t  
P 4000
→  2t  =  ..........Initial − Condition
 P3  4000
 t  
 P4   4000 

− 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

• Solver used: py-pde.

❑ It helps solving the various PDEs using a block-centered


Finite Difference Method.
❑ Step 1: Build a Grid – UnitGrid/CartesianGrid/PolarGrid
etc.
❑ Step 2: Define/Initialize a scalar field for that grid. Define
Initial State and Boundary Conditions. The scalar fields in
our case can be P/Saturation/Porosity or anything that
varies as f(space,time).
❑ Call and execute a solver based on the type of PDE used.
❑ Store the results into a variable. Plot it. Make a movie of
it to see dynamic results of simulation.
Example Code with outputs-

>> grid = UnitGrid([20,20])


>> grid.plot()
>>eq = DiffusionPDE(diffusivity=0.1)
>>state_i = ScalarField(grid=grid , data = P)
>>state_i.plot(title='Initial Pressure condition', colorbar=True )
>>result = eq.solve(state_i , t_range= 10 , dt = 0.0001)
>>result.plot(title='Pressure COndition after t = 10' , colorbar=True)
7. Understanding the workflow of a commercial Simulator

• Memory Allocation and Property specification(Rock-Types, No. Of wells etc.)


RUNSPEC

• 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

• Different Compartments/HFUs of the Reservoir.


REGIONS

SOLUTION-
• Define Equilllibrium states. Fluid contacts etc.
STATES

• Shows results – 2D Plots / 3D simulations etc.


SUMMARY

• Any time dependent/change-history/well-completion etc. Must be entered here.


SCHEDULE
8. History Matching
The main purpose of reservoir simulation is to predict the rate of
hydrocarbon recovery for different methods of field operation.
However, the answer is only as good as the input data. The accuracy of the
simulator can be improved by history matching.
The first step in a history match is to calculate reservoir performance using
the best data available.
The results are compared with the field recorded histories of the wells. If the
agreement is not satisfactory, such data as permeability, relative permeability,
and porosity are varied from one computer run to another until a match is
achieved.
The simulator is then used to predict performance for alternative plans of
operating the reservoir.
In general, the longer the matched history period, the more reliable the
predicted performance will be.
It is important that the engineer periodically monitors the predicted vs the
actual performance and to update his physical picture of the reservoir.
• Key Points-
1. A perfect/unique match is never obtained. It is either fair or poor.
2. The changes in parameters are well within pre-described limits because
we cannot classify the input schemes use-less.
3. Multiple Realizations are there. This is called Stochastic approach.

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

3. Computational Python using SymPy – A good technique to reduce human computations.


Code - https://github.com/Divyanshu-ISM/Oil-and-Gas-data-analysis/blob/master/Computational_Python_SymPy.ipynb

4. Inter-polation and Calculus with Python - https://github.com/Divyanshu-ISM/Oil-and-


Gas-data-analysis/blob/master/Calculus_with_Python1.ipynb
GitHub Repository

https://github.com/Divyanshu-ISM/Oil-and-Gas-
data-analysis

Thank You.

You might also like