rock-physics-open 0.2.3__py3-none-any.whl → 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of rock-physics-open might be problematic. Click here for more details.

Files changed (42) hide show
  1. rock_physics_open/equinor_utilities/gen_utilities/dict_to_float.py +6 -1
  2. rock_physics_open/equinor_utilities/gen_utilities/dim_check_vector.py +35 -5
  3. rock_physics_open/equinor_utilities/gen_utilities/filter_input.py +11 -6
  4. rock_physics_open/equinor_utilities/gen_utilities/filter_output.py +29 -19
  5. rock_physics_open/equinor_utilities/machine_learning_utilities/__init__.py +18 -5
  6. rock_physics_open/equinor_utilities/machine_learning_utilities/base_pressure_model.py +172 -0
  7. rock_physics_open/equinor_utilities/machine_learning_utilities/exponential_model.py +100 -86
  8. rock_physics_open/equinor_utilities/machine_learning_utilities/friable_pressure_models.py +230 -0
  9. rock_physics_open/equinor_utilities/machine_learning_utilities/import_ml_models.py +23 -4
  10. rock_physics_open/equinor_utilities/machine_learning_utilities/patchy_cement_pressure_models.py +280 -0
  11. rock_physics_open/equinor_utilities/machine_learning_utilities/polynomial_model.py +128 -0
  12. rock_physics_open/equinor_utilities/machine_learning_utilities/sigmoidal_model.py +204 -155
  13. rock_physics_open/equinor_utilities/optimisation_utilities/__init__.py +19 -0
  14. rock_physics_open/equinor_utilities/snapshot_test_utilities/compare_snapshots.py +1 -2
  15. rock_physics_open/fluid_models/brine_model/brine_properties.py +70 -35
  16. rock_physics_open/fluid_models/gas_model/gas_properties.py +79 -37
  17. rock_physics_open/fluid_models/oil_model/dead_oil_density.py +21 -16
  18. rock_physics_open/fluid_models/oil_model/dead_oil_velocity.py +9 -7
  19. rock_physics_open/fluid_models/oil_model/live_oil_density.py +16 -13
  20. rock_physics_open/fluid_models/oil_model/live_oil_velocity.py +3 -3
  21. rock_physics_open/fluid_models/oil_model/oil_properties.py +59 -29
  22. rock_physics_open/sandstone_models/__init__.py +2 -0
  23. rock_physics_open/sandstone_models/constant_cement_optimisation.py +4 -1
  24. rock_physics_open/sandstone_models/friable_optimisation.py +4 -1
  25. rock_physics_open/sandstone_models/patchy_cement_model.py +89 -6
  26. rock_physics_open/sandstone_models/patchy_cement_optimisation.py +4 -1
  27. rock_physics_open/t_matrix_models/__init__.py +0 -10
  28. rock_physics_open/t_matrix_models/carbonate_pressure_substitution.py +1 -1
  29. rock_physics_open/t_matrix_models/curvefit_t_matrix_exp.py +1 -2
  30. rock_physics_open/t_matrix_models/t_matrix_opt_fluid_sub_exp.py +3 -3
  31. rock_physics_open/t_matrix_models/t_matrix_opt_fluid_sub_petec.py +5 -1
  32. rock_physics_open/t_matrix_models/t_matrix_opt_forward_model_exp.py +5 -1
  33. rock_physics_open/t_matrix_models/t_matrix_opt_forward_model_min.py +4 -1
  34. rock_physics_open/t_matrix_models/t_matrix_parameter_optimisation_exp.py +5 -1
  35. rock_physics_open/t_matrix_models/t_matrix_parameter_optimisation_min.py +4 -1
  36. rock_physics_open/version.py +2 -2
  37. {rock_physics_open-0.2.3.dist-info → rock_physics_open-0.3.0.dist-info}/METADATA +4 -8
  38. {rock_physics_open-0.2.3.dist-info → rock_physics_open-0.3.0.dist-info}/RECORD +42 -37
  39. /rock_physics_open/{t_matrix_models → equinor_utilities/optimisation_utilities}/opt_subst_utilities.py +0 -0
  40. {rock_physics_open-0.2.3.dist-info → rock_physics_open-0.3.0.dist-info}/WHEEL +0 -0
  41. {rock_physics_open-0.2.3.dist-info → rock_physics_open-0.3.0.dist-info}/licenses/LICENSE +0 -0
  42. {rock_physics_open-0.2.3.dist-info → rock_physics_open-0.3.0.dist-info}/top_level.txt +0 -0
@@ -1,188 +1,237 @@
1
+ from __future__ import annotations
2
+
1
3
  import pickle
2
- from io import BufferedIOBase
3
- from typing import Union
4
+ from typing import Any
4
5
 
5
6
  import numpy as np
6
7
 
8
+ from .base_pressure_model import BasePressureModel
9
+
10
+
11
+ class SigmoidalPressureModel(BasePressureModel):
12
+ """
13
+ Sigmoidal pressure sensitivity model for velocity prediction.
14
+
15
+ Uses nested sigmoid functions: velocity amplitude varies with porosity,
16
+ and velocity varies sigmoidally with effective pressure using the amplitude.
17
+
18
+ Input format (n,3): [porosity, p_eff_in_situ, p_eff_depleted]
19
+
20
+ The model applies two sigmoid transformations:
21
+ 1. Porosity -> velocity amplitude using phi_model parameters
22
+ 2. Effective pressure -> velocity using p_eff_model parameters and amplitude
23
+ """
7
24
 
8
- class Sigmoid:
9
25
  def __init__(
10
26
  self,
11
- amplitude: float = None,
12
- median_point: float = None,
13
- x_scaling: float = None,
14
- bias: float = None,
15
- description="",
27
+ phi_amplitude: float,
28
+ phi_median_point: float,
29
+ phi_x_scaling: float,
30
+ phi_bias: float,
31
+ p_eff_median_point: float,
32
+ p_eff_x_scaling: float,
33
+ p_eff_bias: float,
34
+ model_max_pressure: float | None = None,
35
+ description: str = "",
16
36
  ):
17
- self._amplitude = amplitude
18
- self._median_point = median_point
19
- self._x_scaling = x_scaling
20
- self._bias = bias
21
- self._description = description
22
-
23
- def todict(self):
24
- return {
25
- "amplitude": self._amplitude,
26
- "median_point": self._median_point,
27
- "x_scaling": self._x_scaling,
28
- "bias": self._bias,
29
- "description": self._description,
30
- }
37
+ """
38
+ Initialize sigmoidal pressure model.
39
+
40
+ Parameters
41
+ ----------
42
+ phi_amplitude : float
43
+ Amplitude parameter for porosity sigmoid [m/s].
44
+ phi_median_point : float
45
+ Median point for porosity sigmoid [fraction].
46
+ phi_x_scaling : float
47
+ X-scaling parameter for porosity sigmoid [unitless].
48
+ phi_bias : float
49
+ Bias parameter for porosity sigmoid [m/s].
50
+ p_eff_median_point : float
51
+ Median point for pressure sigmoid [Pa].
52
+ p_eff_x_scaling : float
53
+ X-scaling parameter for pressure sigmoid [1/Pa].
54
+ p_eff_bias : float
55
+ Bias parameter for pressure sigmoid [m/s].
56
+ model_max_pressure : float | None
57
+ Maximum pressure for predict_max method [Pa].
58
+ description : str
59
+ Model description.
60
+ """
61
+ super().__init__(model_max_pressure, description)
62
+ # Porosity model parameters
63
+ self._phi_amplitude = phi_amplitude
64
+ self._phi_median_point = phi_median_point
65
+ self._phi_x_scaling = phi_x_scaling
66
+ self._phi_bias = phi_bias
67
+ # Pressure model parameters
68
+ self._p_eff_median_point = p_eff_median_point
69
+ self._p_eff_x_scaling = p_eff_x_scaling
70
+ self._p_eff_bias = p_eff_bias
31
71
 
32
72
  @property
33
- def amplitude(self):
34
- return self._amplitude
73
+ def phi_amplitude(self) -> float:
74
+ """Porosity sigmoid amplitude."""
75
+ return self._phi_amplitude
35
76
 
36
77
  @property
37
- def median_point(self):
38
- return self._median_point
78
+ def phi_median_point(self) -> float:
79
+ """Porosity sigmoid median point."""
80
+ return self._phi_median_point
39
81
 
40
82
  @property
41
- def x_scaling(self):
42
- return self._x_scaling
83
+ def phi_x_scaling(self) -> float:
84
+ """Porosity sigmoid x-scaling."""
85
+ return self._phi_x_scaling
43
86
 
44
87
  @property
45
- def bias(self):
46
- return self._bias
88
+ def phi_bias(self) -> float:
89
+ """Porosity sigmoid bias."""
90
+ return self._phi_bias
47
91
 
48
92
  @property
49
- def description(self):
50
- return self._description
51
-
52
- def predict(self, x):
53
- if isinstance(x, list):
54
- x = np.array(x)
55
- if not self._valid():
56
- return None
57
- return (
58
- self._amplitude / (1 + np.exp(-self._x_scaling * (x - self._median_point)))
59
- + self._bias
60
- )
61
-
62
- def predict_amp(self, x, amp):
63
- if isinstance(x, list):
64
- x = np.array(x)
65
- if isinstance(amp, list):
66
- amp = np.array(amp)
67
- if not self._valid(variant="amp"):
68
- return None
69
- return (
70
- amp / (1 + np.exp(-self._x_scaling * (x - self._median_point))) + self._bias
71
- )
72
-
73
- @classmethod
74
- def save(cls, file):
75
- with open(file, "wb") as f_out:
76
- pickle.dump(cls, f_out)
77
-
78
- @classmethod
79
- def load(cls, file):
80
- with open(file, "rb") as f_in:
81
- return pickle.load(f_in)
82
-
83
- def _valid(self, variant=None):
84
- if variant is None and self.amplitude is None:
85
- raise ValueError('object field "variant" is not set')
86
- if self.median_point is None:
87
- raise ValueError('object field "median_point" is not set')
88
- if self.x_scaling is None:
89
- raise ValueError('object field "x_scaling" is not set')
90
- if self.bias is None:
91
- raise ValueError('object field "bias" is not set')
92
- return True
93
-
94
-
95
- class CarbonateSigmoidalPressure:
96
- def __init__(
97
- self,
98
- phi_model: Union[dict, Sigmoid] = None,
99
- p_eff_model: Union[dict, Sigmoid] = None,
100
- ):
101
- if isinstance(phi_model, Sigmoid):
102
- self._phi_model = phi_model
103
- elif isinstance(phi_model, dict):
104
- self._phi_model = Sigmoid(**phi_model)
105
- else:
106
- self._phi_model = None
107
- if isinstance(p_eff_model, Sigmoid):
108
- self._p_eff_model = p_eff_model
109
- elif isinstance(p_eff_model, dict):
110
- self._p_eff_model = Sigmoid(**p_eff_model)
111
- else:
112
- self._p_eff_model = None
93
+ def p_eff_median_point(self) -> float:
94
+ """Pressure sigmoid median point."""
95
+ return self._p_eff_median_point
113
96
 
114
97
  @property
115
- def phi_model(self):
116
- return self._phi_model
117
-
118
- @phi_model.setter
119
- def phi_model(self, phi_mod):
120
- if isinstance(phi_mod, Sigmoid):
121
- self._phi_model = phi_mod
122
- else:
123
- raise ValueError(
124
- f"{type(self)}: expected input Sigmoid object, received {type(phi_mod)}"
125
- )
98
+ def p_eff_x_scaling(self) -> float:
99
+ """Pressure sigmoid x-scaling."""
100
+ return self._p_eff_x_scaling
126
101
 
127
102
  @property
128
- def p_eff_model(self):
129
- return self._p_eff_model
130
-
131
- @p_eff_model.setter
132
- def p_eff_model(self, p_eff_mod):
133
- if isinstance(p_eff_mod, Sigmoid):
134
- self._p_eff_model = p_eff_mod
135
- else:
103
+ def p_eff_bias(self) -> float:
104
+ """Pressure sigmoid bias."""
105
+ return self._p_eff_bias
106
+
107
+ def validate_input(self, inp_arr: np.ndarray) -> np.ndarray:
108
+ """
109
+ Validate input for sigmoidal model.
110
+
111
+ Parameters
112
+ ----------
113
+ inp_arr : np.ndarray
114
+ Input array to validate.
115
+
116
+ Returns
117
+ -------
118
+ np.ndarray
119
+ Validated input array.
120
+
121
+ Raises
122
+ ------
123
+ ValueError
124
+ If input format is invalid.
125
+ """
126
+ if not isinstance(inp_arr, np.ndarray):
127
+ raise ValueError("Input must be numpy ndarray.")
128
+ if inp_arr.ndim != 2 or inp_arr.shape[1] != 3:
136
129
  raise ValueError(
137
- f"{type(self)}: expected input Sigmoid object, received {type(p_eff_mod)}"
130
+ "Input must be (n,3): [porosity, p_eff_in_situ, p_eff_depleted]"
138
131
  )
139
-
140
- def predict(self, inp_arr: np.ndarray) -> np.ndarray:
141
- # Don't save any of the intermediate calculations, only return the difference between the effective pressure
142
- # cases. The method name is set to be the same as for other machine learning models
143
- self._validate_input(inp_arr)
144
- velocity_amp = self._phi_model.predict(inp_arr[:, 0].flatten())
145
- velocity_init = self._p_eff_model.predict_amp(
146
- inp_arr[:, 1].flatten(), velocity_amp
132
+ return inp_arr
133
+
134
+ def _sigmoid_phi(self, phi: np.ndarray) -> np.ndarray:
135
+ """
136
+ Calculate velocity amplitude from porosity using sigmoid function.
137
+
138
+ Parameters
139
+ ----------
140
+ phi : np.ndarray
141
+ Porosity values [fraction].
142
+
143
+ Returns
144
+ -------
145
+ np.ndarray
146
+ Velocity amplitude values [m/s].
147
+ """
148
+ return (
149
+ self._phi_amplitude
150
+ / (1 + np.exp(-self._phi_x_scaling * (phi - self._phi_median_point)))
151
+ + self._phi_bias
147
152
  )
148
- velocity_depl = self._p_eff_model.predict_amp(
149
- inp_arr[:, 2].flatten(), velocity_amp
153
+
154
+ def _sigmoid_p_eff(self, p_eff: np.ndarray, amplitude: np.ndarray) -> np.ndarray:
155
+ """
156
+ Calculate velocity from effective pressure using sigmoid function with amplitude.
157
+
158
+ Parameters
159
+ ----------
160
+ p_eff : np.ndarray
161
+ Effective pressure values [Pa].
162
+ amplitude : np.ndarray
163
+ Velocity amplitude values [m/s].
164
+
165
+ Returns
166
+ -------
167
+ np.ndarray
168
+ Velocity values [m/s].
169
+ """
170
+ return (
171
+ amplitude
172
+ / (1 + np.exp(-self._p_eff_x_scaling * (p_eff - self._p_eff_median_point)))
173
+ + self._p_eff_bias
150
174
  )
151
- return velocity_depl - velocity_init
152
175
 
153
176
  def predict_abs(self, inp_arr: np.ndarray, case: str = "in_situ") -> np.ndarray:
154
- # Method for access to absolute results, not just the difference
155
- self._validate_input(inp_arr)
156
- velocity_amp = self._phi_model.predict(inp_arr[:, 0].flatten())
157
- if case == "in_situ":
158
- return self._p_eff_model.predict_amp(inp_arr[:, 1].flatten(), velocity_amp)
159
- return self._p_eff_model.predict_amp(inp_arr[:, 2].flatten(), velocity_amp)
160
-
161
- def _validate_input(self, input_array):
162
- if not isinstance(input_array, np.ndarray):
163
- raise ValueError(
164
- f"{type(input_array)}: should be numpy array with shape n x 3"
165
- )
166
- if not ((input_array.ndim == 2) and (input_array.shape[1] == 3)):
167
- raise ValueError(
168
- f'{type(self)}: Input array should be of shape n x 3, with columns in sequence "PHIT", '
169
- f'"P_EFF_in_situ" and "P_EFF_depleted"'
170
- )
171
-
172
- def todict(self):
177
+ """
178
+ Calculate absolute velocity for specified pressure case.
179
+
180
+ Parameters
181
+ ----------
182
+ inp_arr : np.ndarray
183
+ Validated input array (n,3).
184
+ case : str
185
+ Pressure case: "in_situ" or "depleted".
186
+
187
+ Returns
188
+ -------
189
+ np.ndarray
190
+ Velocity values [m/s].
191
+ """
192
+ arr = self.validate_input(inp_arr)
193
+
194
+ phi = arr[:, 0]
195
+ p_in_situ = arr[:, 1]
196
+ p_depleted = arr[:, 2]
197
+
198
+ # Calculate velocity amplitude from porosity
199
+ velocity_amplitude = self._sigmoid_phi(phi)
200
+
201
+ # Select pressure based on case
202
+ p_eff = p_in_situ if case == "in_situ" else p_depleted
203
+
204
+ # Calculate velocity from effective pressure and amplitude
205
+ return self._sigmoid_p_eff(p_eff, velocity_amplitude)
206
+
207
+ def todict(self) -> dict[str, Any]:
208
+ """Convert model to dictionary."""
173
209
  return {
174
- "phi_model": self._phi_model.todict(),
175
- "p_eff_model": self._p_eff_model.todict(),
210
+ "phi_amplitude": self._phi_amplitude,
211
+ "phi_median_point": self._phi_median_point,
212
+ "phi_x_scaling": self._phi_x_scaling,
213
+ "phi_bias": self._phi_bias,
214
+ "p_eff_median_point": self._p_eff_median_point,
215
+ "p_eff_x_scaling": self._p_eff_x_scaling,
216
+ "p_eff_bias": self._p_eff_bias,
217
+ "model_max_pressure": self._model_max_pressure,
218
+ "description": self._description,
176
219
  }
177
220
 
178
- def save(self, file: Union[str, BufferedIOBase]):
179
- with open(file, "wb") as f_out:
180
- pickle.dump(self.todict(), f_out)
181
-
182
221
  @classmethod
183
- def load(cls, file: Union[str, BufferedIOBase]):
222
+ def load(cls, file: str | bytes) -> "SigmoidalPressureModel":
223
+ """Load sigmoidal model from pickle file."""
184
224
  with open(file, "rb") as f_in:
185
- load_dict = pickle.load(f_in)
186
- return cls(
187
- phi_model=load_dict["phi_model"], p_eff_model=load_dict["p_eff_model"]
188
- )
225
+ d = pickle.load(f_in)
226
+
227
+ return cls(
228
+ phi_amplitude=d["phi_amplitude"],
229
+ phi_median_point=d["phi_median_point"],
230
+ phi_x_scaling=d["phi_x_scaling"],
231
+ phi_bias=d["phi_bias"],
232
+ p_eff_median_point=d["p_eff_median_point"],
233
+ p_eff_x_scaling=d["p_eff_x_scaling"],
234
+ p_eff_bias=d["p_eff_bias"],
235
+ model_max_pressure=d["model_max_pressure"],
236
+ description=d["description"],
237
+ )
@@ -0,0 +1,19 @@
1
+ from .opt_subst_utilities import (
2
+ gen_mod_routine,
3
+ gen_opt_routine,
4
+ gen_sub_routine,
5
+ load_opt_params,
6
+ opt_param_info,
7
+ opt_param_to_ascii,
8
+ save_opt_params,
9
+ )
10
+
11
+ __all__ = [
12
+ "gen_mod_routine",
13
+ "gen_sub_routine",
14
+ "gen_opt_routine",
15
+ "opt_param_to_ascii",
16
+ "opt_param_info",
17
+ "save_opt_params",
18
+ "load_opt_params",
19
+ ]
@@ -1,7 +1,6 @@
1
1
  import inspect
2
2
  import math
3
3
  import re
4
- from typing import Union
5
4
  from warnings import warn
6
5
 
7
6
  import numpy as np
@@ -13,7 +12,7 @@ from .snapshots import get_snapshot_name
13
12
 
14
13
 
15
14
  def compare_snapshots(
16
- test_results: Union[np.ndarray, tuple, DataFrame],
15
+ test_results: np.ndarray | tuple | DataFrame,
17
16
  saved_results: tuple,
18
17
  name_arr=None,
19
18
  display_results: bool = False,
@@ -14,16 +14,16 @@ def brine_properties(
14
14
  p_cacl: np.ndarray | float | None = None,
15
15
  ) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
16
16
  """
17
- :param salinity: Salinity of solution as ppm of NaCl.
18
- :param pressure: Pressure (Pa) of oil
19
- :param temperature: Temperature (Celsius) of oil.
17
+ :param salinity: Salinity of solution as [ppm] of NaCl.
18
+ :param pressure: Pressure [Pa]
19
+ :param temperature: Temperature [°C]
20
20
  :param p_nacl: NaCl percentage, for future use
21
21
  :param p_kcl: KCl percentage, for future use
22
22
  :param p_cacl: CaCl percentage, for future use
23
- :return: vel_b [m/s], den_b [kg/m^3], k_b [Pa]
23
+ :return: Brine velocity vel_b [m/s], brine density den_b [kg/m^3], brine bulk modulus k_b [Pa]
24
24
  """
25
- vel_b = brine_primary_velocity(temperature, pressure * 1e-6, salinity * 1e-6)
26
- den_b = brine_density(temperature, pressure * 1e-6, salinity * 1e-6) * 1000
25
+ vel_b = brine_primary_velocity(temperature, pressure, salinity)
26
+ den_b = brine_density(temperature, pressure, salinity)
27
27
  k_b = vel_b**2 * den_b
28
28
  return vel_b, den_b, k_b
29
29
 
@@ -35,19 +35,27 @@ def brine_density(
35
35
  ) -> np.ndarray | float:
36
36
  """
37
37
  density of sodium chloride solutions, equation 27 in Batzle & Wang [1].
38
- :param salinity: Salinity of solution as weight fraction (ppm/1000000) of
39
- sodium chloride.
40
- :param pressure: Pressure (MPa) of oil
41
- :param temperature: Temperature (Celsius) of oil.
42
- :return: density of solution in g/cc.
38
+ :param salinity: Salinity of solution in ppm
39
+ :param pressure: Pressure [Pa]
40
+ :param temperature: Temperature [°C]
41
+ :return: density of solution in [kg/m^3].
43
42
  """
43
+ # Change unit of pressure to MPa
44
+ pressure_mpa = pressure / 1.0e6
45
+ # Change unit of salinity to fraction
46
+ salinity_frac = salinity / 1.0e6
47
+
44
48
  coefficients = [
45
49
  [[0.668, 3e-4], [8e-5, -13e-6], [3e-6, 0.0]],
46
50
  [[0.44, -24e-4], [-33e-4, 47e-6], [0.0, 0.0]],
47
51
  ]
48
- return water_density(temperature, pressure) + salinity * polyval3d(
49
- salinity, temperature, pressure, coefficients
52
+ water_den = water_density(temperature, pressure)
53
+ brine_correction = (
54
+ salinity_frac
55
+ * polyval3d(salinity_frac, temperature, pressure_mpa, coefficients)
56
+ * 1000.0
50
57
  )
58
+ return water_den + brine_correction
51
59
 
52
60
 
53
61
  def brine_primary_velocity(
@@ -58,12 +66,16 @@ def brine_primary_velocity(
58
66
  """
59
67
  Primary wave velocity of sodium chloride solutions, equation 29 in Batzle & Wang [1]
60
68
 
61
- :param salinity: Salinity of solution as weight fraction (ppm/1000000) of
62
- sodium chloride.
63
- :param pressure: Pressure (MPa) of oil
64
- :param temperature: Temperature (Celsius) of oil.
69
+ :param salinity: Salinity of solution as [ppm] of sodium chloride
70
+ :param pressure: Pressure [Pa]
71
+ :param temperature: Temperature [°C]
65
72
  :return: velocity of solution in m/s.
66
73
  """
74
+ # Change unit for salinity from ppm to fraction
75
+ salinity_frac = salinity / 1.0e6
76
+ # Change the unit for pressure from Pa to MPa
77
+ pressure_mpa = pressure / 1.0e6
78
+
67
79
  coefficients = np.zeros((3, 4, 3))
68
80
  coefficients[0, 0, 0] = 1170
69
81
  coefficients[0, 1, 0] = -9.6
@@ -77,8 +89,8 @@ def brine_primary_velocity(
77
89
  coefficients[1, 0, 2] = 0.16
78
90
  coefficients[2, 0, 0] = -820
79
91
 
80
- return water_primary_velocity(temperature, pressure) + salinity * polyval3d(
81
- sqrt(salinity), temperature, pressure, coefficients
92
+ return water_primary_velocity(temperature, pressure) + salinity_frac * polyval3d(
93
+ sqrt(salinity_frac), temperature, pressure_mpa, coefficients
82
94
  )
83
95
 
84
96
 
@@ -88,17 +100,20 @@ def water_density(
88
100
  ) -> np.ndarray | float:
89
101
  """
90
102
  Density of water,, equation 27a in Batzle & Wang [1].
91
- :param pressure: Pressure (MPa) of oil
92
- :param temperature: Temperature (Celsius) of oil.
93
- :return: Density of water in g/cc.
103
+ :param pressure: Pressure [Pa]
104
+ :param temperature: Temperature [°C]
105
+ :return: Density of water in [kg/m^3].
94
106
  """
107
+ # Change unit of pressure from Pa to MPa
108
+ pressure_mpa = pressure / 1.0e6
109
+
95
110
  coefficients = [
96
111
  [1.0, 489e-6, -333e-9],
97
112
  [-8e-5, -2e-6, -2e-09],
98
113
  [-33e-7, 16e-9, 0.0],
99
114
  [1.75e-9, -13e-12, 0.0],
100
115
  ]
101
- return polyval2d(temperature, pressure, coefficients)
116
+ return polyval2d(temperature, pressure_mpa, coefficients) * 1000.0
102
117
 
103
118
 
104
119
  def water_primary_velocity(
@@ -107,11 +122,14 @@ def water_primary_velocity(
107
122
  ) -> np.ndarray | float:
108
123
  """
109
124
  Primary wave velocity of water, table 1 and equation 28 in Batzle & Wang [1].
110
- :param pressure: Pressure (MPa) of oil
111
- :param temperature: Temperature (Celsius) of oil.
125
+ :param pressure: Pressure [Pa]
126
+ :param temperature: Temperature [°C]
112
127
  :return: primary wave velocity of water in m/s.
113
128
  """
114
- if np.any(pressure > 100):
129
+ # Change unit of pressure from Pa to MPa
130
+ pressure_mpa = pressure / 1.0e6
131
+
132
+ if np.any(pressure_mpa > 100):
115
133
  warnings.warn(
116
134
  "Calculations for water velocity is not precise for\n"
117
135
  + "pressure outside [0,100]MPa"
@@ -125,19 +143,36 @@ def water_primary_velocity(
125
143
  [1.487e-4, -6.503e-7, -1.455e-8, 1.327e-10],
126
144
  [-2.197e-7, 7.987e-10, 5.23e-11, -4.614e-13],
127
145
  ]
128
- return polyval2d(temperature, pressure, coefficients)
146
+ return polyval2d(temperature, pressure_mpa, coefficients)
129
147
 
130
148
 
131
149
  def water(
132
150
  temperature: np.ndarray | float, pressure: np.ndarray | float
133
151
  ) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
134
152
  """
135
- :param pressure: Pressure (Pa) of oil
136
- :param temperature: Temperature (Celsius) of oil.
137
- :return: water_density [kg/m^3], water_velocity [m/s], water_bulk_modulus [Pa]
153
+ :param pressure: Pressure [Pa]
154
+ :param temperature: Temperature [°C]
155
+ :return: water_velocity [m/s], water_density [kg/m^3], water_bulk_modulus [Pa]
138
156
  """
139
- pressure_mpa = pressure * 1.0e-6
140
- water_den = water_density(temperature, pressure_mpa)
141
- water_vel = water_primary_velocity(temperature, pressure_mpa)
142
- water_k = water_vel**2 * water_den * 1000.0
143
- return water_den, water_vel, water_k
157
+ water_den = water_density(temperature, pressure)
158
+ water_vel = water_primary_velocity(temperature, pressure)
159
+ water_k = water_vel**2 * water_den
160
+ return water_vel, water_den, water_k
161
+
162
+
163
+ def brine_viscosity(
164
+ temperature: np.ndarray | float,
165
+ salinity: np.ndarray | float,
166
+ ) -> np.ndarray | float:
167
+ """
168
+ Brine viscosity according to Batzle & Wang [1].
169
+
170
+ Based on equation 32.
171
+ """
172
+ salinity_frac = salinity / 1.0e6
173
+ return (
174
+ 0.1
175
+ + 0.333 * salinity_frac
176
+ + (1.65 + 91.9 * salinity_frac**3)
177
+ * np.exp(-(0.42 * (salinity_frac**0.8 - 0.17) ** 2 + 0.045) * temperature**0.8)
178
+ )