Skip to content

Commit a38fc4f

Browse files
test_gringarten_stehfest_precision
1 parent 73e9ce2 commit a38fc4f

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/geophires_x/MPFReservoir.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22

3-
import mpmath
3+
from mpmath import mp
44
import numpy as np
55
from mpmath import *
66
import geophires_x.Model as Model
@@ -108,22 +108,22 @@ def Calculate(self, model: Model):
108108
# calculate non-dimensional temperature array
109109
Twnd = []
110110
try:
111-
stash_dps = mpmath.dps
111+
stash_dps = mp.dps
112112
if self.gringarten_stehfest_precision.Provided:
113-
mpmath.dps = self.gringarten_stehfest_precision.value
113+
mp.dps = self.gringarten_stehfest_precision.value
114114

115115
for t in range(1, len(model.reserv.timevector.value)):
116116
Twnd = Twnd + [float(invertlaplace(fp, td[t], method='stehfest'))]
117117
except Exception as e_:
118-
mpmath.dps = stash_dps
118+
mp.dps = stash_dps
119119

120120
msg = (f'Error: GEOPHIRES could not execute numerical inverse laplace calculation for reservoir model 1 '
121121
f'({self.gringarten_stehfest_precision.Name} = {mpmath.dps}). '
122122
'Simulation will abort.')
123123
print(msg)
124124
raise RuntimeError(msg) from e_
125125

126-
mpmath.dps = stash_dps
126+
mp.dps = stash_dps
127127

128128
Twnd = np.asarray(Twnd)
129129

tests/geophires_x_tests/test_reservoir.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
from geophires_x_client import GeophiresInputParameters
1313
from geophires_x_client import GeophiresXClient
1414
from geophires_x_client import GeophiresXResult
15+
from geophires_x_client import ImmutableGeophiresInputParameters
1516
from tests.base_test_case import BaseTestCase
1617

1718

1819
class ReservoirTestCase(BaseTestCase):
20+
1921
def test_lithostatic_pressure(self):
2022
p = static_pressure_MPa(2700, 3000)
2123
self.assertEqual(79.433865, p)
@@ -32,6 +34,30 @@ def test_reservoir_lithostatic_pressure(self):
3234
self.assertAlmostEqual(79.433865, p.magnitude, places=3)
3335
self.assertEqual('megapascal', p.units)
3436

37+
def test_gringarten_stehfest_precision(self):
38+
def _get_result(gringarten_stehfest_precision: int) -> GeophiresXResult:
39+
return GeophiresXClient(enable_caching=False).get_geophires_result(
40+
ImmutableGeophiresInputParameters(
41+
from_file_path=self._get_test_file_path('generic-egs-case.txt'),
42+
params={'Gringarten-Stehfest Precision': gringarten_stehfest_precision},
43+
)
44+
)
45+
46+
_ = _get_result(15) # warm up any caching
47+
result_15 = _get_result(15)
48+
result_8 = _get_result(8)
49+
50+
def calc_time(r: GeophiresXResult) -> float:
51+
return r.result['Simulation Metadata']['Calculation Time']['value']
52+
53+
calc_time_15_sec = calc_time(result_15)
54+
calc_time_8_sec = calc_time(result_8)
55+
56+
msg = f'calc_time_15_sec={calc_time_15_sec}, calc_time_8_sec={calc_time_8_sec}'
57+
print(f'[DEBUG] {msg}')
58+
59+
self.assertLess(calc_time_8_sec, calc_time_15_sec)
60+
3561
# noinspection PyMethodMayBeStatic
3662
def _new_model(self, input_file=None) -> Model:
3763
stash_cwd = Path.cwd()

0 commit comments

Comments
 (0)