Skip to content

Commit 2be710b

Browse files
Parameterize TOUGH2 executable path NREL#291
1 parent 73d4be3 commit 2be710b

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed

src/geophires_x/TOUGH2Reservoir.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import sys
2-
import os
32
import numpy as np
43
from .Parameter import floatParameter, strParameter
54
from .Units import *
65
import geophires_x.Model as Model
7-
from .Reservoir import Reservoir
6+
from geophires_x.Reservoir import Reservoir
87

98

109
class TOUGH2Reservoir(Reservoir):
1110
"""
1211
This class models the TOUGH2 Reservoir.
1312
"""
14-
def __init__(self, model:Model):
13+
def __init__(self, model: Model):
1514
"""
1615
The __init__ function is called automatically when a class is instantiated.
1716
It initializes the attributes of an object, and sets default values for certain arguments that can be overridden
@@ -33,6 +32,11 @@ def __init__(self, model:Model):
3332
# or used for Output
3433
# This also includes all Parameters that are calculated and then published using the Printouts function.
3534
# specific to this stype of reservoir
35+
self.tough2_executable_path = self.ParameterDict[self.tough2_executable_path.Name] = strParameter(
36+
"TOUGH2 Executable Path",
37+
DefaultValue='xt2_eos1.exe',
38+
UnitType=Units.NONE,
39+
)
3640
self.tough2modelfilename = self.ParameterDict[self.tough2modelfilename.Name] = strParameter(
3741
"TOUGH2 Model/File Name",
3842
value='Doublet',
@@ -126,7 +130,7 @@ def Calculate(self, model:Model):
126130

127131
# GEOPHIRES assumes TOUGH2 executable and input file are in same directory as GEOPHIRESv3.py
128132
# create tough2 input file
129-
path_to_exe = str('xt2_eos1.exe')
133+
path_to_exe = str(self.tough2_executable_path.value)
130134
if not os.path.exists(os.path.join(os.getcwd(), path_to_exe)):
131135
model.logger.critical('TOUGH2 executable file does not exist in current working directory. \
132136
GEOPHIRES will abort simulation.')
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from pathlib import Path
2+
3+
from tests.base_test_case import BaseTestCase
4+
5+
# Ruff disabled because imports are order-dependent
6+
# ruff: noqa: I001
7+
from geophires_x.Model import Model
8+
from geophires_x.Parameter import ParameterEntry
9+
10+
11+
# ruff: noqa: I001
12+
from geophires_x.TOUGH2Reservoir import TOUGH2Reservoir
13+
from geophires_x.OptionList import ReservoirModel
14+
from geophires_x_client import GeophiresInputParameters
15+
16+
import sys
17+
import os
18+
19+
20+
class Tough2ReservoirTestCase(BaseTestCase):
21+
def _new_model_with_tough2_reservoir(self, input_file=None) -> Model:
22+
stash_cwd = Path.cwd()
23+
stash_sys_argv = sys.argv
24+
25+
sys.argv = ['']
26+
27+
if input_file is not None:
28+
sys.argv.append(input_file)
29+
30+
m = Model(enable_geophires_logging_config=False)
31+
m.InputParameters['Reservoir Model'] = ParameterEntry(
32+
Name='Reservoir Model', sValue=str(ReservoirModel.TOUGH2_SIMULATOR.int_value)
33+
)
34+
m.reserv = TOUGH2Reservoir(m)
35+
36+
if input_file is not None:
37+
m.read_parameters()
38+
39+
sys.argv = stash_sys_argv
40+
os.chdir(stash_cwd)
41+
42+
return m
43+
44+
def test_read_inputs(self):
45+
base_params = GeophiresInputParameters(
46+
from_file_path=self._get_test_file_path('../examples/example1.txt'),
47+
params={
48+
'Reservoir Model': ReservoirModel.TOUGH2_SIMULATOR.int_value,
49+
},
50+
)
51+
model = self._new_model_with_tough2_reservoir(input_file=base_params.as_file_path())
52+
self.assertEqual(model.reserv.tough2_executable_path.value, 'xt2_eos1.exe')
53+
54+
params_custom_exe = GeophiresInputParameters(
55+
from_file_path=self._get_test_file_path('../examples/example1.txt'),
56+
params={
57+
'Reservoir Model': ReservoirModel.TOUGH2_SIMULATOR.int_value,
58+
'TOUGH2 Executable Path': 'C:\\Users\\my-geophires-project\\tough3-eos1.exe',
59+
},
60+
)
61+
model = self._new_model_with_tough2_reservoir(input_file=params_custom_exe.as_file_path())
62+
reservoir: TOUGH2Reservoir = model.reserv
63+
self.assertEqual(reservoir.tough2_executable_path.value, 'C:\\Users\\my-geophires-project\\tough3-eos1.exe')

0 commit comments

Comments
 (0)