Skip to content

Commit 77c1957

Browse files
Merge branch 'enum-numerical-vals'
2 parents 6b1b1b2 + aa19e55 commit 77c1957

File tree

8 files changed

+80
-47
lines changed

8 files changed

+80
-47
lines changed

src/geophires_x/AGSOutputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def PrintOutputs(self, model: Model):
6161
f = scipy.interpolate.interp1d(np.arange(0, len(model.wellbores.PumpingPower.value)),
6262
model.wellbores.PumpingPower.value, fill_value="extrapolate")
6363
model.wellbores.PumpingPower.value = f(np.arange(0, len(model.wellbores.ProducedTemperature.value), 1.0))
64-
if model.surfaceplant.enduse_option.value != EndUseOptions.HEAT:
64+
if model.surfaceplant.enduse_option.value is not EndUseOptions.HEAT:
6565
if len(model.wellbores.PumpingPower.value) != len(model.wellbores.ProducedTemperature.value):
6666
f = scipy.interpolate.interp1d(np.arange(0, len(model.wellbores.PumpingPower.value)),
6767
model.wellbores.PumpingPower.value, fill_value="extrapolate")

src/geophires_x/EconomicsAddOns.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,10 @@ def Calculate(self, model: Model) -> None:
279279
# so we need to update them here so when they get used in the final economic calculation (below),
280280
# the new values reflect the addition of the AddOns
281281
for i in range(0, model.surfaceplant.plant_lifetime.value):
282-
if model.surfaceplant.enduse_option.value != EndUseOptions.HEAT: # all these end-use options have an electricity generation component
282+
if model.surfaceplant.enduse_option.value is not EndUseOptions.HEAT: # all these end-use options have an electricity generation component
283283
model.surfaceplant.TotalkWhProduced.value[i] = model.surfaceplant.TotalkWhProduced.value[i] + self.AddOnElecGainedTotalPerYear.value
284284
model.surfaceplant.NetkWhProduced.value[i] = model.surfaceplant.NetkWhProduced.value[i] + self.AddOnElecGainedTotalPerYear.value
285-
if model.surfaceplant.enduse_option.value != EndUseOptions.ELECTRICITY:
285+
if model.surfaceplant.enduse_option.value is not EndUseOptions.ELECTRICITY:
286286
model.surfaceplant.HeatkWhProduced.value[i] = model.surfaceplant.HeatkWhProduced.value[i] + self.AddOnHeatGainedTotalPerYear.value
287287
else:
288288
# all the end-use option of direct-use only components have a heat generation component

src/geophires_x/EconomicsS_DAC_GT.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,13 +654,13 @@ def Calculate(self, model: Model) -> None:
654654
# some (all) of it to do the capture, so when they get used in the final economic calculation (below),
655655
# the new values reflect the impact of S-DAC-GT
656656
for i in range(0, model.surfaceplant.plant_lifetime.value):
657-
if model.surfaceplant.enduse_option.value != EndUseOptions.HEAT:
657+
if model.surfaceplant.enduse_option.value is not EndUseOptions.HEAT:
658658
# all these end-use options have an electricity generation component
659659
model.surfaceplant.TotalkWhProduced.value[i] = model.surfaceplant.TotalkWhProduced.value[i] - (
660660
self.CarbonExtractedAnnually.value[i] * self.elec.value)
661661
model.surfaceplant.NetkWhProduced.value[i] = model.surfaceplant.NetkWhProduced.value[i] - (
662662
self.CarbonExtractedAnnually.value[i] * self.elec.value)
663-
if model.surfaceplant.enduse_option.value != EndUseOptions.ELECTRICITY:
663+
if model.surfaceplant.enduse_option.value is not EndUseOptions.ELECTRICITY:
664664
model.surfaceplant.HeatkWhProduced.value[i] = model.surfaceplant.HeatkWhProduced.value[i] - (
665665
self.CarbonExtractedAnnually.value[i] * self.therm.value)
666666
else:

src/geophires_x/OptionList.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,37 @@
33

44

55
class EndUseOptions(str, Enum):
6-
ELECTRICITY = "Electricity" # 1
7-
HEAT = "Direct-Use Heat" # 2
8-
COGENERATION_TOPPING_EXTRA_HEAT = "Cogeneration Topping Cycle, Heat sales considered as extra income" # 31
9-
COGENERATION_TOPPING_EXTRA_ELECTRICITY = "Cogeneration Topping Cycle, Electricity sales considered as extra income" # 32
10-
COGENERATION_BOTTOMING_EXTRA_HEAT = "Cogeneration Bottoming Cycle, Heat sales considered as extra income" # 41
11-
COGENERATION_BOTTOMING_EXTRA_ELECTRICITY = "Cogeneration Bottoming Cycle, Electricity sales considered as extra income" # 42
12-
COGENERATION_PARALLEL_EXTRA_HEAT = "Cogeneration Parallel Cycle, Heat sales considered as extra income" # 51
13-
COGENERATION_PARALLEL_EXTRA_ELECTRICITY = "Cogeneration Parallel Cycle, Electricity sales considered as extra income" # 52
6+
ELECTRICITY = 1, "Electricity"
7+
HEAT = 2, "Direct-Use Heat"
8+
COGENERATION_TOPPING_EXTRA_HEAT = 31, "Cogeneration Topping Cycle, Heat sales considered as extra income"
9+
COGENERATION_TOPPING_EXTRA_ELECTRICITY = 32, "Cogeneration Topping Cycle, Electricity sales considered as extra income"
10+
COGENERATION_BOTTOMING_EXTRA_HEAT = 41, "Cogeneration Bottoming Cycle, Heat sales considered as extra income"
11+
COGENERATION_BOTTOMING_EXTRA_ELECTRICITY = 42, "Cogeneration Bottoming Cycle, Electricity sales considered as extra income"
12+
COGENERATION_PARALLEL_EXTRA_HEAT = 51, "Cogeneration Parallel Cycle, Heat sales considered as extra income"
13+
COGENERATION_PARALLEL_EXTRA_ELECTRICITY = 52, "Cogeneration Parallel Cycle, Electricity sales considered as extra income"
14+
15+
def __new__(cls, *args, **kwds):
16+
obj = str.__new__(cls)
17+
obj._value_ = args[1]
18+
return obj
19+
20+
def __init__(self, numerical_input_value: int, _: str):
21+
self._numerical_input_value = numerical_input_value
22+
23+
def __eq__(self, other):
24+
return str(self) == str(other)
1425

1526
@staticmethod
1627
def get_end_use_option_from_input_string(input_string:str):
1728
"""
1829
:rtype: EndUseOptions
1930
"""
2031

21-
if input_string == str(1):
22-
return EndUseOptions.ELECTRICITY
23-
elif input_string == str(2):
24-
return EndUseOptions.HEAT
25-
self.plant_type.value = PlantType.INDUSTRIAL
26-
elif input_string == str(31):
27-
return EndUseOptions.COGENERATION_TOPPING_EXTRA_HEAT
28-
elif input_string == str(32):
29-
return EndUseOptions.COGENERATION_TOPPING_EXTRA_ELECTRICITY
30-
elif input_string == str(41):
31-
return EndUseOptions.COGENERATION_BOTTOMING_EXTRA_HEAT
32-
elif input_string == str(42):
33-
return EndUseOptions.COGENERATION_BOTTOMING_EXTRA_ELECTRICITY
34-
elif input_string == str(51):
35-
return EndUseOptions.COGENERATION_PARALLEL_EXTRA_HEAT
36-
elif input_string == str(52):
37-
return EndUseOptions.COGENERATION_PARALLEL_EXTRA_ELECTRICITY
38-
39-
raise ValueError(f'Unknown End-Use Option value: {input_string}')
32+
for option in EndUseOptions:
33+
if input_string == str(option._numerical_input_value):
34+
return option
35+
36+
raise ValueError(f'Unknown End-Use Option input value: {input_string}')
4037

4138

4239
class PlantType(str, Enum):
@@ -99,22 +96,26 @@ class WellDrillingCostCorrelation(str, Enum):
9996
VERTICAL_LARGE_IDEAL = 16, "vertical open-hole, large diameter, ideal", -0.00240, 752.93946, 524337.65380
10097
DEVIATED_LARGE_IDEAL = 17, "deviated liner, large diameter, ideal", 0.00376, 762.52696, 765103.07690
10198

99+
def calculate_cost_MUSD(self, meters) -> float:
100+
return (self._c2 * meters ** 2 + self._c1 * meters + self._c0) * 1E-6
102101

103102
def __new__(cls, *args, **kwds):
104103
obj = str.__new__(cls)
105104
obj._value_ = args[1]
106105
return obj
107106

108-
def __init__(self, idx: int, _: str, c2:float, c1:float, c0:float):
107+
def __init__(self, numerical_input_value: int, _: str, c2: float, c1: float, c0: float):
109108
self._c2 = c2
110109
self._c1 = c1
111110
self._c0 = c0
112111

112+
def __eq__(self, other):
113+
return str(self) == str(other)
114+
113115
def calculate_cost_MUSD(self, meters) -> float:
114116
return (self._c2 * meters ** 2 + self._c1 * meters + self._c0) * 1E-6
115117

116118

117-
118119
class FractureShape(str, Enum):
119120
CIRCULAR_AREA = "Circular fracture with known area"
120121
CIRCULAR_DIAMETER = "Circular fracture with known diameter"

src/geophires_x/Outputs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ def PrintOutputs(self, model: Model):
795795
summary.append(OutputTableItem('Average Net Electricity Production', '{0:10.2f}'.format(
796796
np.average(model.surfaceplant.NetElectricityProduced.value)),
797797
model.surfaceplant.NetElectricityProduced.CurrentUnits.value))
798-
if model.surfaceplant.enduse_option.value != EndUseOptions.ELECTRICITY: # there is a direct-use component
798+
if model.surfaceplant.enduse_option.value is not EndUseOptions.ELECTRICITY: # there is a direct-use component
799799
summary.append(OutputTableItem('Average Direct-Use Heat Production',
800800
'{0:10.2f}'.format(np.average(model.surfaceplant.HeatProduced.value)),
801801
model.surfaceplant.HeatProduced.CurrentUnits.value))
@@ -1567,7 +1567,7 @@ def PrintOutputs(self, model: Model):
15671567
f.write(' Surface Application: ' + str(model.surfaceplant.plant_type.value.value) + NL)
15681568
if model.surfaceplant.enduse_option.value in [EndUseOptions.ELECTRICITY, EndUseOptions.COGENERATION_TOPPING_EXTRA_HEAT, EndUseOptions.COGENERATION_TOPPING_EXTRA_ELECTRICITY, EndUseOptions.COGENERATION_BOTTOMING_EXTRA_ELECTRICITY, EndUseOptions.COGENERATION_BOTTOMING_EXTRA_HEAT, EndUseOptions.COGENERATION_PARALLEL_EXTRA_HEAT, EndUseOptions.COGENERATION_PARALLEL_EXTRA_ELECTRICITY]: # there is an electricity component
15691569
f.write(f' Average Net Electricity Production: {np.average(model.surfaceplant.NetElectricityProduced.value):10.2f} ' + model.surfaceplant.NetElectricityProduced.CurrentUnits.value + NL)
1570-
if model.surfaceplant.enduse_option.value != EndUseOptions.ELECTRICITY: # there is a direct-use component
1570+
if model.surfaceplant.enduse_option.value is not EndUseOptions.ELECTRICITY: # there is a direct-use component
15711571
f.write(f' Average Direct-Use Heat Production: {np.average(model.surfaceplant.HeatProduced.value):10.2f} '+ model.surfaceplant.HeatProduced.CurrentUnits.value + NL)
15721572
if model.surfaceplant.plant_type.value == PlantType.DISTRICT_HEATING:
15731573
f.write(f' Annual District Heating Demand: {np.average(model.surfaceplant.annual_heating_demand.value):10.2f} ' + model.surfaceplant.annual_heating_demand.CurrentUnits.value + NL)

src/geophires_x/SurfacePlant.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def annual_electricity_pumping_power(self, plant_lifetime: int, enduse_option: E
193193
dx=1. / timestepsperyear * 365. * 24.) * 1000. * utilization_factor
194194
NetkWhProduced[i] = np.trapz(NetElectricityProduced[(0 + i * timestepsperyear):((i + 1) * timestepsperyear) + 1],
195195
dx=1. / timestepsperyear * 365. * 24.) * 1000. * utilization_factor
196-
if enduse_option != EndUseOptions.ELECTRICITY:
196+
if enduse_option is not EndUseOptions.ELECTRICITY:
197197
# all those end-use options have a direct-use component
198198
HeatkWhProduced = np.zeros(plant_lifetime)
199199
for i in range(0, plant_lifetime):
@@ -236,15 +236,15 @@ def __init__(self, model: Model):
236236
AllowableRange=[1, 2, 31, 32, 41, 42, 51, 52],
237237
UnitType=Units.NONE,
238238
ErrMessage="assume default end-use option (1: electricity only)",
239-
ToolTipText="""Select the end-use application of the geofluid heat:
240-
1: Electricity;
241-
2: Direct-Use Heat;
242-
31: Cogeneration Topping Cycle, Heat sales considered as extra income;
243-
32: Cogeneration Topping Cycle, Electricity sales considered as extra income;
244-
41: Cogeneration Bottoming Cycle, Heat sales considered as extra income;
245-
42: Cogeneration Bottoming Cycle, Electricity sales considered as extra income;
246-
51: Cogeneration Parallel Cycle, Heat sales considered as extra income;
247-
52: Cogeneration Parallel Cycle, Electricity sales considered as extra income"""
239+
ToolTipText="Select the end-use application of the geofluid heat: " +
240+
"1: Electricity; " +
241+
"2: Direct-Use Heat; " +
242+
"31: Cogeneration Topping Cycle, Heat sales considered as extra income; " +
243+
"32: Cogeneration Topping Cycle, Electricity sales considered as extra income; " +
244+
"41: Cogeneration Bottoming Cycle, Heat sales considered as extra income; " +
245+
"42: Cogeneration Bottoming Cycle, Electricity sales considered as extra income; " +
246+
"51: Cogeneration Parallel Cycle, Heat sales considered as extra income; " +
247+
"52: Cogeneration Parallel Cycle, Electricity sales considered as extra income"
248248
)
249249
self.plant_type = self.ParameterDict[self.plant_type.Name] = intParameter(
250250
"Power Plant Type",

src/geophires_x/SurfacePlantAGS.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ def Calculate(self, model: Model) -> None:
751751
self.RemainingReservoirHeatContent.value = model.reserv.InitialReservoirHeatContent.value - np.cumsum(
752752
self.HeatkWhExtracted.value) * 3600 * 1E3 / 1E15
753753

754-
if self.End_use != EndUseOptions.ELECTRICITY:
754+
if self.End_use is not EndUseOptions.ELECTRICITY:
755755
self.HeatkWhProduced.value = np.zeros(self.plant_lifetime.value)
756756
for i in range(0, self.plant_lifetime.value):
757757
self.HeatkWhProduced.value[i] = np.trapz(self.HeatProduced.value[
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from base_test_case import BaseTestCase
2+
from geophires_x.OptionList import EndUseOptions
3+
from geophires_x.OptionList import PlantType
4+
from geophires_x.OptionList import WellDrillingCostCorrelation
5+
6+
7+
class EndUseOptionsTestCase(BaseTestCase):
8+
def test_get_end_use_option_from_input_string(self):
9+
self.assertEqual(EndUseOptions.get_end_use_option_from_input_string('1'), EndUseOptions.ELECTRICITY)
10+
11+
with self.assertRaises(ValueError):
12+
EndUseOptions.get_end_use_option_from_input_string('2034982309')
13+
14+
def test_equality(self):
15+
self.assertFalse(EndUseOptions.HEAT == EndUseOptions.ELECTRICITY)
16+
self.assertTrue(EndUseOptions.HEAT == EndUseOptions.HEAT)
17+
self.assertFalse(EndUseOptions.HEAT is None)
18+
self.assertTrue(EndUseOptions.HEAT is EndUseOptions.HEAT)
19+
# self.assertTrue(EndUseOptions.HEAT == 'HEAT')
20+
# self.assertFalse(EndUseOptions.HEAT == 'Electricity')
21+
22+
23+
class WellDrillingCostCorrelationTestCase(BaseTestCase):
24+
def test_equality(self):
25+
self.assertFalse(WellDrillingCostCorrelation.VERTICAL_SMALL == WellDrillingCostCorrelation.DEVIATED_SMALL)
26+
self.assertTrue(WellDrillingCostCorrelation.VERTICAL_SMALL == WellDrillingCostCorrelation.VERTICAL_SMALL)
27+
28+
29+
class PlantTypeTestCase(BaseTestCase):
30+
def test_equality(self):
31+
self.assertFalse(PlantType.SUB_CRITICAL_ORC == PlantType.SUPER_CRITICAL_ORC)
32+
self.assertTrue(WellDrillingCostCorrelation.VERTICAL_SMALL == WellDrillingCostCorrelation.VERTICAL_SMALL)

0 commit comments

Comments
 (0)