Skip to content

Commit 0aef412

Browse files
Unit test for MC HIP-RA-X NREL#180
1 parent bc3959d commit 0aef412

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

src/geophires_monte_carlo/MC_GeoPHIRES3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def Write_HTML_Output(
9696
for index, row in df.iterrows():
9797
data = row.values[0 : len(outputs)]
9898

99-
# have to deal with the special case where thr last column is actually
99+
# have to deal with the special case where the last column is actually
100100
# a compound string with multiple columns in it that looks like this:
101101
# ' (Gradient 1:47.219846973456924;Reservoir Temperature:264.7789623351493;...)'
102102
str_to_parse = str(row.values[len(outputs)]).strip().replace('(', '').replace(')', '')
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Reservoir Temperature, 250.0
2+
Rejection Temperature, 60.0
3+
Reservoir Porosity, 10.0
4+
Reservoir Area, 55.0
5+
Reservoir Thickness, 0.25
6+
Reservoir Life Cycle, 25
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
INPUT, Formation Porosity, uniform, 9.0, 28.0
2+
INPUT, Reservoir Area, uniform, 50.0, 120.0
3+
INPUT, Reservoir Thickness, uniform, 0.122, 0.299
4+
INPUT, Reservoir Temperature, uniform, 130, 170
5+
INPUT, Rejection Temperature, uniform, 20, 33
6+
OUTPUT, Producible Heat (reservoir)
7+
OUTPUT, Producible Electricity (reservoir)
8+
ITERATIONS, 10

tests/geophires_monte_carlo_tests/test_geophires_monte_carlo.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,37 @@ def test_hip_ra_monte_carlo(self):
138138
self.assertLess(json_result['Producible Electricity']['median'], 1000)
139139
self.assertGreater(json_result['Producible Electricity']['median'], 20)
140140

141+
def test_hip_ra_x_monte_carlo(self):
142+
client = GeophiresMonteCarloClient()
143+
144+
result: MonteCarloResult = client.get_monte_carlo_result(
145+
MonteCarloRequest(
146+
SimulationProgram.HIP_RA_X,
147+
self._get_arg_file_path('HIP-RA-X_example1.txt'),
148+
self._get_arg_file_path('MC_HIP-RA-X_Settings_file.txt'),
149+
self._get_arg_file_path('MC_HIP-RA-X_Result.txt'),
150+
)
151+
)
152+
self.assertIsNotNone(result)
153+
self.assertIsNotNone(result.output_file_path)
154+
155+
with open(result.output_file_path) as f:
156+
result_content = '\n'.join(f.readlines())
157+
self.assertIn('Electricity', result_content)
158+
159+
with open(result.json_output_file_path) as f:
160+
json_result = json.loads(f.read())
161+
self.assertIn('Producible Electricity (reservoir)', json_result)
162+
163+
# Note: it is possible, though unlikely, for the test to incorrectly fail (i.e. a false negative)
164+
# if the random values generated happen to give valid results that are outside this range.
165+
# If you experience intermittent test failures from the below lines (that are unrelated to HIP-RA code
166+
# changes), then it probably means the expected range or settings file need to be adjusted to 'guarantee'
167+
# the results can be confidently asserted. (Such as in
168+
# https://github.com/NREL/GEOPHIRES-X/pull/178/commits/ec4db42fca5a90715ceb5143e18315d5f3d782b7)
169+
self.assertLess(json_result['Producible Electricity (reservoir)']['median'], 1000)
170+
self.assertGreater(json_result['Producible Electricity (reservoir)']['median'], 20)
171+
141172
def _get_arg_file_path(self, arg_file):
142173
test_dir: Path = Path(os.path.abspath(__file__)).parent
143174
return Path(test_dir, arg_file).absolute()

0 commit comments

Comments
 (0)