Skip to content

Commit 7b9619b

Browse files
Support combining input file and params object in GeophiresInputParameters
1 parent f043ca5 commit 7b9619b

File tree

5 files changed

+197
-11
lines changed

5 files changed

+197
-11
lines changed

src/geophires_x_client/geophires_input_parameters.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,31 @@ class PowerPlantType(Enum):
3434

3535

3636
class GeophiresInputParameters:
37+
3738
def __init__(self, params: Optional[MappingProxyType] = None, from_file_path: Optional[Path] = None):
38-
assert (params is None) ^ (from_file_path is None), 'Only one of params or from_file_path may be provided'
39+
"""
40+
Note that params will override any duplicate entries in from_file_path
41+
"""
42+
43+
assert (params is not None) or (from_file_path is not None), 'One of params or from_file_path must be provided'
44+
45+
if from_file_path is not None:
46+
self._id = hash(from_file_path)
47+
self._file_path = from_file_path
3948

4049
if params is not None:
4150
self._params = dict(params)
51+
52+
if self._file_path is None:
4253
self._id = abs(hash(frozenset(self._params.items())))
54+
self._file_path = Path(tempfile.gettempdir(), f'geophires-input-params_{self._id}.txt')
55+
56+
if params is not None:
4357
# TODO validate params - i.e. that all names are accepted by simulation, values don't exceed max allowed,
4458
# etc.
4559

46-
tmp_file_path = Path(tempfile.gettempdir(), f'geophires-input-params_{self._id}.txt')
47-
f = Path.open(tmp_file_path, 'w')
48-
49-
f.writelines([','.join([str(p) for p in param_item]) + '\n' for param_item in self._params.items()])
50-
f.close()
51-
self._file_path = tmp_file_path
52-
53-
if from_file_path is not None:
54-
self._file_path = from_file_path
55-
self._id = hash(from_file_path)
60+
with open(self._file_path, 'a', encoding='UTF-8') as f:
61+
f.writelines([', '.join([str(p) for p in param_item]) + '\n' for param_item in self._params.items()])
5662

5763
def as_file_path(self):
5864
return self._file_path

tests/geophires_x_client_tests/__init__.py

Whitespace-only changes.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
GEOPHIRES v2.0 Input File
2+
Created on 2018-06-11
3+
Last modified on 2024-02-28
4+
Geothermal Electricity Problem using a Multiple Parallel Fractures Model
5+
6+
Example 1 Description: This problem considers an EGS reservoir at 3km depth.
7+
Ramey's model is applied to simulate production wellbore heat losses. The heat
8+
is used in for electricity application with a reinjection temperature of 50deg.C.
9+
10+
11+
***Subsurface technical parameters***
12+
*************************************
13+
Reservoir Model,1, ---Multiple Fractures reservoir model
14+
Reservoir Depth,3, ---[km]
15+
Number of Segments,1, ---[-]
16+
Gradient 1,50, ---[deg.C/km]
17+
Maximum Temperature,400, ---[deg.C]
18+
Number of Production Wells,2, ---[-]
19+
Number of Injection Wells,2, ---[-]
20+
Production Well Diameter,7, ---[inch]
21+
Injection Well Diameter,7, ---[inch]
22+
Ramey Production Wellbore Model,1, ---0 if disabled 1 if enabled
23+
Production Wellbore Temperature Drop,.5, ---[deg.C]
24+
Injection Wellbore Temperature Gain,0, ---[deg.C]
25+
Production Flow Rate per Well,55, ---[kg/s]
26+
Fracture Shape,3, ---[-] Should be 1 2 3 or 4. See manual for details
27+
Fracture Height,900, ---[m]
28+
Reservoir Volume Option,3, ---[-] Should be 1 2 3 or 4. See manual for details
29+
Number of Fractures,20, ---[-]
30+
Reservoir Volume,1000000000, ---[m^3]
31+
Water Loss Fraction,.02, ---[-]
32+
Productivity Index,5, ---[kg/s/bar]
33+
Injectivity Index,5, ---[kg/s/bar]
34+
Injection Temperature,50, ---[deg.C]
35+
Maximum Drawdown,1, ---[-] no redrilling considered
36+
Reservoir Heat Capacity,1000, ---[J/kg/K]
37+
Reservoir Density,2700, ---[kg/m^3]
38+
Reservoir Thermal Conductivity,2.7, ---[W/m/K]
39+
40+
***SURFACE TECHNICAL PARAMETERS***
41+
**********************************
42+
End-Use Option,1, ---[-] Electricity
43+
Power Plant Type,2, ---[-] Supercritical ORC
44+
Circulation Pump Efficiency,.8, ---[-] between .1 and 1
45+
Utilization Factor,.9, ---[-] between .1 and 1
46+
Surface Temperature,20, ---[deg.C]
47+
Ambient Temperature,20, ---[deg.C]
48+
49+
***FINANCIAL PARAMETERS***
50+
**************************
51+
Plant Lifetime,30, ---[years]
52+
Economic Model,1, ---[-] Fixed Charge Rate Model
53+
Fixed Charge Rate,.05, ---[-] between 0 and 1
54+
Inflation Rate During Construction,0, ---[-]
55+
56+
***CAPITAL AND O&M COST PARAMETERS***
57+
*************************************
58+
Well Drilling and Completion Capital Cost Adjustment Factor,1, ---[-] Use built-in correlations
59+
Well Drilling Cost Correlation,1, ---[-] Use built-in correlations
60+
Reservoir Stimulation Capital Cost Adjustment Factor,1, ---[-] Use built-in correlations
61+
Surface Plant Capital Cost Adjustment Factor,1, ---[-] Use built-in correlations
62+
Field Gathering System Capital Cost Adjustment Factor,1, ---[-] Use built-in correlations
63+
Exploration Capital Cost Adjustment Factor,1, ---[-] Use built-in correlations
64+
Wellfield O&M Cost Adjustment Factor,1, ---[-] Use built-in correlations
65+
Surface Plant O&M Cost Adjustment Factor,1, ---[-] Use built-in correlations
66+
Water Cost Adjustment Factor,1, ---[-] Use built-in correlations
67+
68+
69+
***Simulation Parameters***
70+
***************************
71+
72+
Print Output to Console,1, ---[-] Should be 0 (don't print results) or 1 (print results)
73+
Time steps per year,6, ---[1/year]
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
GEOPHIRES v2.0 Input File
2+
Created on 2018-06-11
3+
Last modified on 2018-06-11
4+
Geothermal Direct-Use Example Problem using a Linear Heat Sweep Model.
5+
6+
Example 2 Description: This problem considers an EGS reservoir at 3km depth.
7+
Ramey's model is applied to simulate production wellbore heat losses. The heat
8+
is used in direct-use heat application with reinjection temperature of 70deg.C
9+
10+
***Subsurface Technical Parameters***
11+
*************************************
12+
13+
Reservoir Model,2, ---Linear Heat Sweep Model
14+
Reservoir Depth,3, ---[km]
15+
Number of Segments,1, ---[-]
16+
Gradient 1,55, ---[deg.C/km]
17+
Number of Production Wells,2, ---[-]
18+
Number of Injection Wells,2, ---[-]
19+
Production Well Diameter,8, ---[inch]
20+
Injection Well Diameter,8, ---[inch]
21+
Ramey Production Wellbore Model,1, ---Should be 0 (disable) or 1(enable)
22+
Injection Wellbore Temperature Gain,0, ---[deg.C]
23+
Production Flow Rate per Well,30, ---[kg/s]
24+
Fracture Shape,2, ---Should be 1 2 3 or 4. See manual for option details
25+
Fracture Height,300, ---[m]
26+
Reservoir Volume Option,2, ---Should be 1 2 3 or 4. See manual for option details
27+
Fracture Separation,60, ---[m]
28+
Reservoir Impedance,0.2, ---[GPa*s/m3]
29+
Injection Temperature,70, ---[deg.C]
30+
Maximum Drawdown,.3, ---Should be between 0 and 1 depending on redrilling
31+
Reservoir Heat Capacity,975, ---[J/kg/K]
32+
Reservoir Density,3000, ---[kg/m3]
33+
Reservoir Thermal Conductivity,3.2, ---[W/m/K]
34+
Reservoir Porosity,.1, ---[-]
35+
36+
***Surface Technical Parameters***
37+
**********************************
38+
End-Use Option,2, ---Direct Use Heat
39+
Circulation Pump Efficiency,.8, ---[-]
40+
Utilization Factor,.9, ---[-]
41+
End-Use Efficiency Factor,.9, ---[-]
42+
Surface Temperature,15, ---[deg.C]
43+
44+
***Financial Parameters***
45+
**************************
46+
47+
Plant Lifetime,25, ---[years]
48+
Economic Model,2, ---Standard Levelized Cost Model
49+
Discount Rate,.05, ---[-]
50+
Inflation Rate During Construction,0, ---[-]
51+
52+
***Capital and O&M Cost Parameters***
53+
*************************************
54+
55+
Well Drilling and Completion Capital Cost Adjustment Factor,1, ---[M$/well] Use built-in correlations
56+
Well Drilling Cost Correlation,1, ---[-]
57+
Reservoir Stimulation Capital Cost Adjustment Factor,1, ---[-] Use built-in correlations
58+
Surface Plant Capital Cost Adjustment Factor,1, ---[-] Use built-in correlations
59+
Field Gathering System Capital Cost Adjustment Factor,1, ---[-] Use built-in correlations
60+
Exploration Capital Cost Adjustment Factor,1, ---[-] Use built-in correlations
61+
Wellfield O&M Cost Adjustment Factor,1, ---[-] Use built in correlations
62+
Surface Plant O&M Cost Adjustment Factor,1, ---[-] Use built-in correlations
63+
Water Cost Adjustment Factor,1, ---[-] Use built-in correlations
64+
Electricity Rate,.05, ---[$/kWh]
65+
66+
***Simulation Parameters***
67+
***************************
68+
Print Output to Console,1, ---should be either 0 (do not show) or 1 (show)
69+
Time steps per year,3, ---[-]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import tempfile
2+
import uuid
3+
from pathlib import Path
4+
5+
from base_test_case import BaseTestCase
6+
from geophires_x_client import GeophiresInputParameters
7+
8+
9+
class GeophiresInputParametersTestCase(BaseTestCase):
10+
11+
def test_id(self):
12+
input_1 = GeophiresInputParameters(from_file_path=self._get_test_file_path('example1.txt'))
13+
input_2 = GeophiresInputParameters(from_file_path=self._get_test_file_path('example2.txt'))
14+
self.assertIsNot(input_1._id, input_2._id)
15+
16+
def test_init_with_input_file(self):
17+
file_path = self._get_test_file_path('example1.txt')
18+
input_params = GeophiresInputParameters(from_file_path=file_path)
19+
self.assertEqual(file_path, input_params.as_file_path())
20+
21+
def test_init_with_params(self):
22+
dummy_input_path = Path(tempfile.gettempdir(), f'geophires-dummy-input-params_{uuid.uuid4()!s}.txt')
23+
with open(dummy_input_path, 'w', encoding='UTF-8') as f:
24+
f.write('Foo, Bar\nBaz, Qux\n')
25+
26+
input_from_file = GeophiresInputParameters(from_file_path=dummy_input_path)
27+
input_from_params = GeophiresInputParameters(params={'Foo': 'Bar', 'Baz': 'Qux'})
28+
self.assertFileContentsEqual(input_from_file.as_file_path(), input_from_params.as_file_path())
29+
30+
def test_init_with_input_file_and_parameters(self):
31+
dummy_input_path = Path(tempfile.gettempdir(), f'geophires-dummy-input-params_{uuid.uuid4()!s}.txt')
32+
with open(dummy_input_path, 'w', encoding='UTF-8') as f:
33+
f.write('Foo, Bar\nBaz, Qux\n')
34+
35+
input_params = GeophiresInputParameters(from_file_path=dummy_input_path, params={'Baz': 'Quux', 'Quuz': 2})
36+
37+
with open(input_params.as_file_path(), encoding='UTF-8') as f:
38+
self.assertEqual('Foo, Bar\nBaz, Qux\nBaz, Quux\nQuuz, 2\n', f.read())

0 commit comments

Comments
 (0)