Skip to content

Commit fe06b22

Browse files
Parse EndUseOptions from string in enum method
1 parent 9662c37 commit fe06b22

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

src/geophires_x/OptionList.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,32 @@ class EndUseOptions(str, Enum):
1212
COGENERATION_PARALLEL_EXTRA_HEAT = "Cogeneration Parallel Cycle, Heat sales considered as extra income" # 51
1313
COGENERATION_PARALLEL_EXTRA_ELECTRICITY = "Cogeneration Parallel Cycle, Electricity sales considered as extra income" # 52
1414

15+
@staticmethod
16+
def get_end_use_option_from_input_string(input_string:str):
17+
"""
18+
:rtype: EndUseOptions
19+
"""
20+
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}')
40+
1541

1642
class PlantType(str, Enum):
1743
SUB_CRITICAL_ORC = "Subcritical ORC" # 1

src/geophires_x/SurfacePlant.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -519,23 +519,10 @@ def read_parameters(self, model:Model) -> None:
519519

520520
# handle special cases
521521
if ParameterToModify.Name == 'End-Use Option':
522-
if ParameterReadIn.sValue == str(1):
523-
ParameterToModify.value = EndUseOptions.ELECTRICITY
524-
elif ParameterReadIn.sValue == str(2):
525-
ParameterToModify.value = EndUseOptions.HEAT
522+
end_use_option = EndUseOptions.get_end_use_option_from_input_string(ParameterReadIn.sValue)
523+
ParameterToModify.value = end_use_option
524+
if end_use_option == EndUseOptions.HEAT:
526525
self.plant_type.value = PlantType.INDUSTRIAL
527-
elif ParameterReadIn.sValue == str(31):
528-
ParameterToModify.value = EndUseOptions.COGENERATION_TOPPING_EXTRA_HEAT
529-
elif ParameterReadIn.sValue == str(32):
530-
ParameterToModify.value = EndUseOptions.COGENERATION_TOPPING_EXTRA_ELECTRICITY
531-
elif ParameterReadIn.sValue == str(41):
532-
ParameterToModify.value = EndUseOptions.COGENERATION_BOTTOMING_EXTRA_HEAT
533-
elif ParameterReadIn.sValue == str(42):
534-
ParameterToModify.value = EndUseOptions.COGENERATION_BOTTOMING_EXTRA_ELECTRICITY
535-
elif ParameterReadIn.sValue == str(51):
536-
ParameterToModify.value = EndUseOptions.COGENERATION_PARALLEL_EXTRA_HEAT
537-
elif ParameterReadIn.sValue == str(52):
538-
ParameterToModify.value = EndUseOptions.COGENERATION_PARALLEL_EXTRA_ELECTRICITY
539526

540527
elif ParameterToModify.Name == 'Power Plant Type':
541528
if ParameterReadIn.sValue == str(1):

src/geophires_x/SurfacePlantAGS.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,8 @@ def read_parameters(self, model: Model) -> None:
298298

299299
# handle special cases
300300
if ParameterToModify.Name == "End-Use Option":
301-
if ParameterReadIn.sValue == '1':
302-
ParameterToModify.value = EndUseOptions.ELECTRICITY
303-
elif ParameterReadIn.sValue == '2':
304-
ParameterToModify.value = EndUseOptions.HEAT
301+
ParameterToModify.value = EndUseOptions.get_end_use_option_from_input_string(ParameterReadIn.sValue)
302+
305303
else:
306304
model.logger.info("No parameters read because no content provided")
307305

0 commit comments

Comments
 (0)