Skip to content

Commit 9aba846

Browse files
Add Gringarten-Stehfest Precision parameter to MPFReservoir
1 parent ad5fc2e commit 9aba846

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

src/geophires_x/MPFReservoir.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import sys
2+
3+
import mpmath
24
import numpy as np
35
from mpmath import *
46
import geophires_x.Model as Model
7+
from .Parameter import intParameter
58
from .Reservoir import Reservoir
9+
from .Units import Units
610

711

812
class MPFReservoir(Reservoir):
@@ -12,6 +16,7 @@ class MPFReservoir(Reservoir):
1216
It also has its own methods and attributes that are unique to this class.
1317
"""
1418

19+
# noinspection PyUnresolvedReferences,PyProtectedMember
1520
def __init__(self, model: Model):
1621
"""
1722
The __init__ function is called automatically when a class is instantiated.
@@ -31,15 +36,30 @@ def __init__(self, model: Model):
3136
:type model: :class:`~geophires_x.Model.Model`
3237
:return: None
3338
"""
34-
model.logger.info("Init " + str(__class__) + ": " + sys._getframe().f_code.co_name)
39+
model.logger.info(f'Init {str(__class__)}: {sys._getframe().f_code.co_name}')
40+
3541
super().__init__(model) # initialize the parent parameters and variables
3642
sclass = str(__class__).replace("<class \'", "")
3743
self.MyClass = sclass.replace("\'>", "")
38-
model.logger.info("Complete " + str(__class__) + ": " + sys._getframe().f_code.co_name)
44+
45+
max_allowed_precision = 15
46+
self.gringarten_stehfest_precision = self.ParameterDict[self.gringarten_stehfest_precision.Name] = intParameter(
47+
'Gringarten-Stehfest Precision',
48+
DefaultValue=15,
49+
AllowableRange=list(range(8, max_allowed_precision + 1)),
50+
UnitType=Units.NONE,
51+
Required=False,
52+
ToolTipText='Sets the numerical precision (decimal places) for the Stehfest '
53+
'algorithm used for the inverse Laplace transform.'
54+
)
55+
56+
57+
model.logger.info(f'Complete {str(__class__)}: {sys._getframe().f_code.co_name}')
3958

4059
def __str__(self):
4160
return "MPFReservoir"
4261

62+
# noinspection PyUnresolvedReferences,PyProtectedMember
4363
def read_parameters(self, model: Model) -> None:
4464
"""
4565
The read_parameters function reads in the parameters from a dictionary created by reading the user-provided file
@@ -51,15 +71,16 @@ def read_parameters(self, model: Model) -> None:
5171
:type model: :class:`~geophires_x.Model.Model`
5272
:return: None
5373
"""
54-
model.logger.info("Init " + str(__class__) + ": " + sys._getframe().f_code.co_name)
74+
model.logger.info(f'Init {str(__class__)}: {sys._getframe().f_code.co_name}')
5575
# if we call super, we don't need to deal with setting the parameters here,
5676
# just deal with the special cases for the variables in this class
5777
# because the call to the super.readparameters will set all the variables,
5878
# including the ones that are specific to this class
5979
super().read_parameters(model) # read the parameters for the parent.
6080

61-
model.logger.info("Complete " + str(__class__) + ": " + sys._getframe().f_code.co_name)
81+
model.logger.info(f'Complete {str(__class__)}: {sys._getframe().f_code.co_name}')
6282

83+
# noinspection SpellCheckingInspection,PyUnresolvedReferences,PyProtectedMember
6384
def Calculate(self, model: Model):
6485
"""
6586
The Calculate function calculates the values of all the parameters that are calculated by this object.
@@ -87,13 +108,22 @@ def Calculate(self, model: Model):
87108
# calculate non-dimensional temperature array
88109
Twnd = []
89110
try:
111+
stash_dps = mpmath.dps
112+
if self.gringarten_stehfest_precision.Provided:
113+
mpmath.dps = self.gringarten_stehfest_precision.value
114+
90115
for t in range(1, len(model.reserv.timevector.value)):
91116
Twnd = Twnd + [float(invertlaplace(fp, td[t], method='stehfest'))]
92-
except:
93-
msg = ('Error: GEOPHIRES could not execute numerical inverse laplace calculation for reservoir model 1. '
117+
except Exception as e_:
118+
mpmath.dps = stash_dps
119+
120+
msg = (f'Error: GEOPHIRES could not execute numerical inverse laplace calculation for reservoir model 1 '
121+
f'({self.gringarten_stehfest_precision.Name} = {mpmath.dps}). '
94122
'Simulation will abort.')
95123
print(msg)
96-
raise RuntimeError(msg)
124+
raise RuntimeError(msg) from e_
125+
126+
mpmath.dps = stash_dps
97127

98128
Twnd = np.asarray(Twnd)
99129

src/geophires_x_schema_generator/geophires-request.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,15 @@
412412
"minimum": 0,
413413
"maximum": 0.2
414414
},
415+
"Gringarten-Stehfest Precision": {
416+
"description": "Sets the numerical precision (decimal places) for the Stehfest algorithm used for the inverse Laplace transform.",
417+
"type": "integer",
418+
"units": null,
419+
"category": "Reservoir",
420+
"default": 15,
421+
"minimum": 8,
422+
"maximum": 15
423+
},
415424
"Cylindrical Reservoir Input Depth": {
416425
"description": "Depth of the inflow end of a cylindrical reservoir",
417426
"type": "number",

0 commit comments

Comments
 (0)