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

Material Balance & Havlena Odeh Python Code DeepSeek

The document contains Python functions to calculate cumulative oil production (Np) for two scenarios: constant compressibility and solution gas drive. It also includes a method for estimating initial oil in place (N) using the Havlena-Odeh technique, which involves computing underground withdrawal and total expansion over time. Example usage is provided for both calculation methods and the Havlena-Odeh estimation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Material Balance & Havlena Odeh Python Code DeepSeek

The document contains Python functions to calculate cumulative oil production (Np) for two scenarios: constant compressibility and solution gas drive. It also includes a method for estimating initial oil in place (N) using the Havlena-Odeh technique, which involves computing underground withdrawal and total expansion over time. Example usage is provided for both calculation methods and the Havlena-Odeh estimation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Def constant_compressibility_Np(pi, p, N, Ct, Bo, Boi):

“””

Calculate cumulative oil produced (Np) for the constant compressibility case (oil above
bubble-point pressure).

Parameters:

Pi (float): Initial reservoir pressure (psi)

P (float): Current reservoir pressure (psi)

N (float): Initial oil in place (STB)

Ct (float): Total compressibility (1/psi)

Bo (float): Oil formation volume factor at current pressure (RB/STB)


Boi (float): Initial oil formation volume factor (RB/STB)

Returns:

Float: Cumulative oil produced (STB)

“””

Delta_p = pi – p

Np = (delta_p * N * Ct * Boi) / Bo

Return Np

Def solution_gas_drive_Np(N, Bo, Bg, Bw, Rsi, Rs, Rp, m, Boi, Bgi, c_w, c_f, S_wi, pi, p, We,
Wp):

“””

Calculate cumulative oil produced (Np) for the solution gas drive case.

Parameters:

N (float): Initial oil in place (STB)

Bo (float): Oil formation volume factor at current pressure (RB/STB)

Bg (float): Gas formation volume factor (RB/SCF)

Bw (float): Water formation volume factor (RB/STB)

Rsi (float): Initial solution gas-oil ratio (SCF/STB)

Rs (float): Current solution gas-oil ratio (SCF/STB)

Rp (float): Cumulative produced gas-oil ratio (SCF/STB)

M (float): Ratio of initial gas cap volume to oil zone volume

Boi (float): Initial oil formation volume factor (RB/STB)

Bgi (float): Initial gas formation volume factor (RB/SCF)


C_w (float): Water compressibility (1/psi)

C_f (float): Formation (rock) compressibility (1/psi)

S_wi (float): Initial water saturation

Pi (float): Initial reservoir pressure (psi)

P (float): Current reservoir pressure (psi)

We (float): Cumulative water influx (RB)

Wp (float): Cumulative water produced (STB)

Returns:

Float: Cumulative oil produced (STB)

“””

# Calculate individual expansion terms

Oil_expansion = N * ((Bo – Boi) + (Rsi – Rs) * Bg)

Gas_cap_expansion = m * N * Boi * (Bg / Bgi – 1)

Water_pore_compression = (1 + m) * N * Boi * (c_w * S_wi + c_f) / (1 – S_wi) * (pi – p)

Water_influx = We * Bw

# Total right-hand side of the equation

Total_right = oil_expansion + gas_cap_expansion + water_pore_compression +


water_influx

# Subtract water produced and calculate denominator

Numerator = total_right – Wp * Bw

Denominator = Bo + (Rp – Rs) * Bg

If denominator == 0:
Raise ValueError(“Denominator is zero. Check input values for Bo, Rp, Rs, and Bg.”)

Np = numerator / denominator

Return Np

# Example Usage

If __name__ == “__main__”:

# Example for constant compressibility case

Np_const = constant_compressibility_Np(

Pi=5000, p=4500, N=1e6, Ct=1e-5, Bo=1.2, Boi=1.25

Print(f”Constant Compressibility Case: Np = {Np_const:.2f} STB”)

# Example for solution gas drive case

Np_sol = solution_gas_drive_Np(

N=1e6, Bo=1.2, Bg=0.002, Bw=1.0,

Rsi=600, Rs=500, Rp=700, m=0.5,

Boi=1.25, Bgi=0.0018, c_w=3e-6, c_f=4e-6,

S_wi=0.2, pi=5000, p=4500, We=1e5, Wp=1e4

Print(f”Solution Gas Drive Case: Np = {Np_sol:.2f} STB”)


HAVLENA-ODEH N CALCULATION

To estimate the initial oil in place (N) using the Havlena-Odeh method, we compute the
underground withdrawal (F) and total expansion (E_total) for multiple time steps, then
perform a linear regression.
Below is the Python code:

Import numpy as np

Def compute_havlena_odeh_terms(Np, Bo, Bg, Bw, Rp, Rs, Rsi, Wp, m, Boi, Bgi, c_w, c_f,
S_wi, pi, p, We=0):

“””

Compute F (underground withdrawal) and E_total (total expansion) for a single time step.

Parameters:

Np (float): Cumulative oil produced (STB)

Bo (float): Oil FVF at current pressure (RB/STB)

Bg (float): Gas FVF (RB/SCF)

Bw (float): Water FVF (RB/STB)

Rp (float): Cumulative produced GOR (SCF/STB)

Rs (float): Current solution GOR (SCF/STB)

Rsi (float): Initial solution GOR (SCF/STB)

Wp (float): Cumulative water produced (STB)

M (float): Gas cap ratio

Boi (float): Initial oil FVF (RB/STB)

Bgi (float): Initial gas FVF (RB/SCF)

C_w (float): Water compressibility (1/psi)

C_f (float): Rock compressibility (1/psi)

S_wi (float): Initial water saturation

Pi (float): Initial pressure (psi)

P (float): Current pressure (psi)


We (float): Water influx (RB) – optional

Returns:

Tuple: (F, E_total)

“””

# Underground withdrawal (F)

F = Np * (Bo + (Rp – Rs) * Bg) + Wp * Bw – We * Bw

# Expansion terms

Eo = (Bo – Boi) + (Rsi – Rs) * Bg # Oil and dissolved gas expansion

Eg = Boi * (Bg / Bgi – 1) # Gas cap expansion

Efw = (1 + m) * Boi * (c_w * S_wi + c_f) / (1 – S_wi) * (pi – p) # Formation water and pore
compaction

E_total = Eo + m * Eg + Efw # Total expansion

Return F, E_total

Def estimate_N_havlena_odeh(F_list, E_total_list):

“””

Estimate N (initial oil in place) using linear regression: F = N * E_total.

Parameters:

F_list (list): List of F values for each time step

E_total_list (list): List of E_total values for each time step


Returns:

Float: Estimated N (STB)

“””

# Reshape data for numpy

E = np.array(E_total_list).reshape(-1, 1)

F = np.array(F_list)

# Perform linear regression (without intercept)

N, _, _, _ = np.linalg.lstsq(E, F, rcond=None)

Return N[0]

# Example Usage

If __name__ == “__main__”:

# Example data for three time steps (hypothetical values)

Time_steps = [

{ # Time step 1

‘Np’: 10000, ‘Bo’: 1.2, ‘Bg’: 0.002, ‘Bw’: 1.0, ‘Rp’: 700,

‘Rs’: 500, ‘Rsi’: 600, ‘Wp’: 1000, ‘m’: 0.5, ‘Boi’: 1.25,

‘Bgi’: 0.0018, ‘c_w’: 3e-6, ‘c_f’: 4e-6, ‘S_wi’: 0.2,

‘pi’: 5000, ‘p’: 4800, ‘We’: 5000

},

{ # Time step 2

‘Np’: 20000, ‘Bo’: 1.15, ‘Bg’: 0.0025, ‘Bw’: 1.0, ‘Rp’: 750,

‘Rs’: 450, ‘Rsi’: 600, ‘Wp’: 2000, ‘m’: 0.5, ‘Boi’: 1.25,
‘Bgi’: 0.0018, ‘c_w’: 3e-6, ‘c_f’: 4e-6, ‘S_wi’: 0.2,

‘pi’: 5000, ‘p’: 4600, ‘We’: 10000

},

{ # Time step 3

‘Np’: 30000, ‘Bo’: 1.1, ‘Bg’: 0.003, ‘Bw’: 1.0, ‘Rp’: 800,

‘Rs’: 400, ‘Rsi’: 600, ‘Wp’: 3000, ‘m’: 0.5, ‘Boi’: 1.25,

‘Bgi’: 0.0018, ‘c_w’: 3e-6, ‘c_f’: 4e-6, ‘S_wi’: 0.2,

‘pi’: 5000, ‘p’: 4400, ‘We’: 15000

# Compute F and E_total for each time step

F_values = []

E_total_values = []

For ts in time_steps:

F, E_total = compute_havlena_odeh_terms(**ts)

F_values.append(F)

E_total_values.append(E_total)

# Estimate N

N_estimated = estimate_N_havlena_odeh(F_values, E_total_values)

Print(f”Estimated Initial Oil in Place (N): {N_estimated:,.0f} STB”)

You might also like