Skip to content

Commit 58c3dab

Browse files
Merge pull request #29 from softwareengineerprogrammer/enum-values-in-schema-2
Enum values in schema
2 parents df7febe + 52fd836 commit 58c3dab

16 files changed

+700
-276
lines changed

src/geophires_x/AGSEconomics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def Calculate(self, model: Model) -> None:
183183
"""
184184
model.logger.info(f'Init {__class__!s}: {sys._getframe().f_code.co_name}')
185185

186-
if self.econmodel.value != EconomicModel.CLGS: # do a classical econ calculation
186+
if self.econmodel.value is not EconomicModel.CLGS: # do a classical econ calculation
187187
super().Calculate(model)
188188
else:
189189
# use the CLGS-Style economic calculations

src/geophires_x/AGSOutputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def PrintOutputs(self, model: Model):
7272
model.surfaceplant.NetElectricityProduced.value, fill_value="extrapolate")
7373
model.surfaceplant.NetElectricityProduced.value = f(np.arange(0, len(model.wellbores.ProducedTemperature.value), 1.0))
7474

75-
if not model.economics.econmodel.value == EconomicModel.CLGS:
75+
if model.economics.econmodel.value is not EconomicModel.CLGS:
7676
super().PrintOutputs(model)
7777
else:
7878
with open(self.output_file, 'w', encoding='UTF-8') as f:

src/geophires_x/Economics.py

Lines changed: 14 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import numpy_financial as npf
66
import geophires_x.Model as Model
77
from geophires_x.OptionList import Configuration, WellDrillingCostCorrelation, EconomicModel, EndUseOptions, PlantType
8-
from geophires_x.Parameter import intParameter, floatParameter, OutputParameter, ReadParameter, boolParameter
8+
from geophires_x.Parameter import intParameter, floatParameter, OutputParameter, ReadParameter, boolParameter, \
9+
coerce_int_params_to_enum_values
910
from geophires_x.Units import *
1011

1112

@@ -608,12 +609,13 @@ def __init__(self, model: Model):
608609
# This is the default.
609610
self.econmodel = self.ParameterDict[self.econmodel.Name] = intParameter(
610611
"Economic Model",
611-
DefaultValue=EconomicModel.STANDARDIZED_LEVELIZED_COST,
612+
DefaultValue=EconomicModel.STANDARDIZED_LEVELIZED_COST.int_value,
612613
AllowableRange=[1, 2, 3, 4],
614+
ValuesEnum=EconomicModel,
613615
Required=True,
614616
ErrMessage="assume default economic model (2)",
615617
ToolTipText="Specify the economic model to calculate the levelized cost of energy." +
616-
" 1: Fixed Charge Rate Model, 2: Standard Levelized Cost Model, 3: BICYCLE Levelized Cost Model, 4: CLGS"
618+
'; '.join([f'{it.int_value}: {it.value}' for it in EconomicModel])
617619
)
618620
self.ccstimfixed = self.ParameterDict[self.ccstimfixed.Name] = floatParameter(
619621
"Reservoir Stimulation Capital Cost",
@@ -989,12 +991,13 @@ def __init__(self, model: Model):
989991
)
990992
self.wellcorrelation = self.ParameterDict[self.wellcorrelation.Name] = intParameter(
991993
"Well Drilling Cost Correlation",
992-
DefaultValue=WellDrillingCostCorrelation.VERTICAL_LARGE_INT1,
994+
DefaultValue=WellDrillingCostCorrelation.VERTICAL_LARGE_INT1.int_value,
993995
AllowableRange=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
996+
ValuesEnum=WellDrillingCostCorrelation,
994997
UnitType=Units.NONE,
995998
ErrMessage="assume default well drilling cost correlation (10)",
996999
ToolTipText="Select the built-in well drilling and completion cost correlation: " +
997-
'; '.join([f'{it.numerical_input_value}: {it.value}' for it in WellDrillingCostCorrelation])
1000+
'; '.join([f'{it.int_value}: {it.value}' for it in WellDrillingCostCorrelation])
9981001
)
9991002

10001003
self.DoAddOnCalculations = self.ParameterDict[self.DoAddOnCalculations.Name] = boolParameter(
@@ -1851,53 +1854,11 @@ def read_parameters(self, model: Model) -> None:
18511854

18521855
# handle special cases
18531856
if ParameterToModify.Name == "Economic Model":
1854-
if ParameterReadIn.sValue == '1':
1855-
self.econmodel.value = EconomicModel.FCR
1856-
elif ParameterReadIn.sValue == '2':
1857-
# use standard LCOE/LCOH calculation as found on wikipedia (requires an interest rate).
1858-
self.econmodel.value = EconomicModel.STANDARDIZED_LEVELIZED_COST
1859-
elif ParameterReadIn.sValue == '3':
1860-
# use Bicycle LCOE/LCOH model (requires several financial input parameters)
1861-
self.econmodel.value = EconomicModel.BICYCLE
1862-
else:
1863-
self.econmodel.value = EconomicModel.CLGS # CLGS
1857+
self.econmodel.value = EconomicModel.from_input_string(ParameterReadIn.sValue)
1858+
18641859
elif ParameterToModify.Name == "Well Drilling Cost Correlation":
1865-
if ParameterReadIn.sValue == '1':
1866-
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_SMALL
1867-
elif ParameterReadIn.sValue == '2':
1868-
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_SMALL
1869-
elif ParameterReadIn.sValue == '3':
1870-
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_LARGE
1871-
elif ParameterReadIn.sValue == '4':
1872-
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_LARGE
1873-
elif ParameterReadIn.sValue == '5':
1874-
ParameterToModify.value = WellDrillingCostCorrelation.SIMPLE
1875-
elif ParameterReadIn.sValue == '6':
1876-
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_SMALL_INT1
1877-
elif ParameterReadIn.sValue == '7':
1878-
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_SMALL_INT2
1879-
elif ParameterReadIn.sValue == '8':
1880-
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_SMALL_INT1
1881-
elif ParameterReadIn.sValue == '9':
1882-
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_SMALL_INT2
1883-
elif ParameterReadIn.sValue == '10':
1884-
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_LARGE_INT1
1885-
elif ParameterReadIn.sValue == '11':
1886-
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_LARGE_INT2
1887-
elif ParameterReadIn.sValue == '12':
1888-
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_LARGE_INT1
1889-
elif ParameterReadIn.sValue == '13':
1890-
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_LARGE_INT2
1891-
elif ParameterReadIn.sValue == '14':
1892-
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_SMALL_IDEAL
1893-
elif ParameterReadIn.sValue == '15':
1894-
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_SMALL_IDEAL
1895-
elif ParameterReadIn.sValue == '16':
1896-
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_LARGE_IDEAL
1897-
elif ParameterReadIn.sValue == '17':
1898-
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_LARGE_IDEAL
1899-
else:
1900-
ParameterToModify.value = WellDrillingCostCorrelation.SIMPLE # Assuming 'SIMPLE' is still a valid option
1860+
ParameterToModify.value = WellDrillingCostCorrelation.from_input_string(ParameterReadIn.sValue)
1861+
19011862
elif ParameterToModify.Name == "Reservoir Stimulation Capital Cost Adjustment Factor":
19021863
if self.ccstimfixed.Valid and ParameterToModify.Valid:
19031864
print("Warning: Provided reservoir stimulation cost adjustment factor not considered" +
@@ -2222,6 +2183,8 @@ def read_parameters(self, model: Model) -> None:
22222183
self.DoSDACGTCalculations.value = True
22232184
break
22242185

2186+
coerce_int_params_to_enum_values(self.ParameterDict)
2187+
22252188
model.logger.info(f'complete {__class__!s}: {sys._getframe().f_code.co_name}')
22262189

22272190
def Calculate(self, model: Model) -> None:

src/geophires_x/GeoPHIRESUtils.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from __future__ import annotations
22

33
import logging
4-
import os
54
import sys
5+
from enum import Enum
66
from os.path import exists
77
import dataclasses
88
import json
99
import numbers
1010
from functools import lru_cache
11-
from typing import Optional
11+
from typing import Optional, Any
1212

1313
import scipy
1414
from pint.facets.plain import PlainQuantity
@@ -577,6 +577,22 @@ class _EnhancedJSONEncoder(json.JSONEncoder):
577577
def default(self, o):
578578
if dataclasses.is_dataclass(o):
579579
return dataclasses.asdict(o)
580+
581+
if issubclass(o, Enum):
582+
def get_entry(member) -> dict[str, Any]:
583+
d = {
584+
'name': member.name,
585+
'value': member.value
586+
}
587+
588+
if hasattr(member, 'int_value'):
589+
d['int_value'] = member.int_value
590+
591+
return d
592+
593+
ret = [get_entry(member) for member in o]
594+
return ret
595+
580596
return super().default(o)
581597

582598

@@ -603,3 +619,4 @@ def static_pressure_MPa(rho_kg_per_m3: float, depth_m: float) -> float:
603619
pressure_mpa = quantity(pressure_Pa, 'Pa').to('MPa').magnitude
604620

605621
return pressure_mpa
622+

0 commit comments

Comments
 (0)