-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.py
More file actions
152 lines (119 loc) · 3.82 KB
/
utils.py
File metadata and controls
152 lines (119 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
""" Useful functions for reservoir simulation tasks """
import numpy
def linear_mobility(s, mu_w, mu_o, s_wir, s_oir, deriv=False):
""" Linear mobility model
Parameters
----------
s : ndarray, shape (ny, nx) | (ny*nx,)
Saturation
mu_w : float
Viscosity of water
mu_o : float
Viscosity of oil
s_wir : float
Irreducible water saturation
s_oir : float
Irreducible oil saturation
deriv : bool
If True, also return derivatives
Returns
-------
if deriv=False,
lamb_w, lamb_o : (2x) ndarray, shape (ny, nx) | (ny*nx,)
lamb_w : water mobility
lamb_o : oil mobility
if deriv=True,
lamb_w, lamb_o, dlamb_w, dlamb_o : (4x) ndarray, shape (ny, nx) | (ny*nx,)
lamb_w : water mobility
lamb_o : oil mobility
dlamb_w : derivative of water mobility
dlamb_o : derivative of oil mobility
"""
mu_w, mu_o, s_wir, s_oir = float(mu_w), float(mu_o), float(s_wir), float(s_oir)
_s = (s-s_wir)/(1.0-s_wir-s_oir)
lamb_w = _s/mu_w
lamb_o = (1.0-_s)/mu_o
if deriv:
dlamb_w = 1.0/(mu_w*(1.0-s_wir-s_oir))
dlamb_o = -1.0/(mu_o*(1.0-s_wir-s_oir))
return lamb_w, lamb_o, dlamb_w, dlamb_o
return lamb_w, lamb_o
def quadratic_mobility(s, mu_w, mu_o, s_wir, s_oir, deriv=False):
""" Quadratic mobility model
Parameters
----------
s : ndarray, shape (ny, nx) | (ny*nx,)
Saturation
mu_w : float
Viscosity of water
mu_o : float
Viscosity of oil
s_wir : float
Irreducible water saturation
s_oir : float
Irreducible oil saturation
deriv : bool
If True, also return derivatives
Returns
-------
if deriv=False,
lamb_w, lamb_o : (2x) ndarray, shape (ny, nx) | (ny*nx,)
lamb_w : water mobility
lamb_o : oil mobility
if deriv=True,
lamb_w, lamb_o, dlamb_w, dlamb_o : (4x) ndarray, shape (ny, nx) | (ny*nx,)
lamb_w : water mobility
lamb_o : oil mobility
dlamb_w : derivative of water mobility
dlamb_o : derivative of oil mobility
"""
mu_w, mu_o, s_wir, s_oir = float(mu_w), float(mu_o), float(s_wir), float(s_oir)
_s = (s-s_wir)/(1.0-s_wir-s_oir)
lamb_w = _s**2/mu_w
lamb_o = (1.0-_s)**2/mu_o
if deriv:
dlamb_w = 2.0*_s/(mu_w*(1.0-s_wir-s_oir))
dlamb_o = -2.0*(1.0-_s)/(mu_o*(1.0-s_wir-s_oir))
return lamb_w, lamb_o, dlamb_w, dlamb_o
return lamb_w, lamb_o
def f_fn(s, mobi_fn):
""" Water fractional flow
Parameters
----------
s : ndarray, shape (ny, nx) | (ny*nx,)
Saturation
mobi_fn : callable
Mobility function lamb_w, lamb_o = mobi_fn(s) where:
lamb_w : water mobility
lamb_o : oil mobility
"""
lamb_w, lamb_o = mobi_fn(s)
return lamb_w / (lamb_w + lamb_o)
def df_fn(s, mobi_fn):
""" Derivative (element-wise) of water fractional flow
Parameters
----------
s : ndarray, shape (ny, nx) | (ny*nx,)
Saturation
mobi_fn : callable
Mobility function lamb_w, lamb_o, dlamb_w, dlamb_o = mobi_fn(s, deriv=True) where:
lamb_w : water mobility
lamb_o : oil mobility
dlamb_w : derivative of water mobility
dlamb_o : derivative of oil mobility
"""
lamb_w, lamb_o, dlamb_w, dlamb_o = mobi_fn(s, deriv=True)
return dlamb_w / (lamb_w + lamb_o) - lamb_w * (dlamb_w + dlamb_o) / (lamb_w + lamb_o)**2
def lamb_fn(s, mobi_fn):
""" Total mobility
Parameters
----------
s : ndarray, shape (ny, nx) | (ny*nx,)
Saturation
mobi_fn : callable
Mobility function lamb_w, lamb_o = mobi_fn(s) where:
lamb_w : water mobility
lamb_o : oil mobility
"""
lamb_w, lamb_o = mobi_fn(s)
return lamb_w + lamb_o