Material Balance & Havlena Odeh Python Code DeepSeek
Material Balance & Havlena Odeh Python Code DeepSeek
“””
Calculate cumulative oil produced (Np) for the constant compressibility case (oil above
bubble-point pressure).
Parameters:
Returns:
“””
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:
Returns:
“””
Water_influx = We * Bw
Numerator = total_right – Wp * Bw
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__”:
Np_const = constant_compressibility_Np(
Np_sol = solution_gas_drive_Np(
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:
Returns:
“””
# Expansion terms
Efw = (1 + m) * Boi * (c_w * S_wi + c_f) / (1 – S_wi) * (pi – p) # Formation water and pore
compaction
Return F, E_total
“””
Parameters:
“””
E = np.array(E_total_list).reshape(-1, 1)
F = np.array(F_list)
N, _, _, _ = np.linalg.lstsq(E, F, rcond=None)
Return N[0]
# Example Usage
If __name__ == “__main__”:
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,
},
{ # 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,
},
{ # 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,
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