Skip to content

Commit

Permalink
Merge branch 'NREL:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolm-dsider authored Jul 3, 2024
2 parents 72013e4 + 21bc007 commit b6f63f9
Show file tree
Hide file tree
Showing 34 changed files with 841 additions and 404 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 3.4.38
current_version = 3.4.42
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion .cookiecutterrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ default_context:
sphinx_doctest: "no"
sphinx_theme: "sphinx-py3doc-enhanced-theme"
test_matrix_separate_coverage: "no"
version: 3.4.38
version: 3.4.42
version_manager: "bump2version"
website: "https://github.com/NREL"
year_from: "2023"
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ Free software: `MIT license <LICENSE>`__
:alt: Supported implementations
:target: https://pypi.org/project/geophires-x

.. |commits-since| image:: https://img.shields.io/github/commits-since/softwareengineerprogrammer/GEOPHIRES-X/v3.4.38.svg
.. |commits-since| image:: https://img.shields.io/github/commits-since/softwareengineerprogrammer/GEOPHIRES-X/v3.4.42.svg
:alt: Commits since latest release
:target: https://github.com/softwareengineerprogrammer/GEOPHIRES-X/compare/v3.4.38...main
:target: https://github.com/softwareengineerprogrammer/GEOPHIRES-X/compare/v3.4.42...main

.. |docs| image:: https://readthedocs.org/projects/GEOPHIRES-X/badge/?style=flat
:target: https://nrel.github.io/GEOPHIRES-X
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
year = '2024'
author = 'NREL'
copyright = f'{year}, {author}'
version = release = '3.4.38'
version = release = '3.4.42'

pygments_style = 'trac'
templates_path = ['./templates']
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def read(*names, **kwargs):

setup(
name='geophires-x',
version='3.4.38',
version='3.4.42',
license='MIT',
description='GEOPHIRES is a free and open-source geothermal techno-economic simulator.',
long_description='{}\n{}'.format(
Expand Down
2 changes: 1 addition & 1 deletion src/geophires_x/AGSEconomics.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def Calculate(self, model: Model) -> None:
"""
model.logger.info(f'Init {__class__!s}: {sys._getframe().f_code.co_name}')

if self.econmodel.value != EconomicModel.CLGS: # do a classical econ calculation
if self.econmodel.value is not EconomicModel.CLGS: # do a classical econ calculation
super().Calculate(model)
else:
# use the CLGS-Style economic calculations
Expand Down
2 changes: 1 addition & 1 deletion src/geophires_x/AGSOutputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def PrintOutputs(self, model: Model):
model.surfaceplant.NetElectricityProduced.value, fill_value="extrapolate")
model.surfaceplant.NetElectricityProduced.value = f(np.arange(0, len(model.wellbores.ProducedTemperature.value), 1.0))

if not model.economics.econmodel.value == EconomicModel.CLGS:
if model.economics.econmodel.value is not EconomicModel.CLGS:
super().PrintOutputs(model)
else:
with open(self.output_file, 'w', encoding='UTF-8') as f:
Expand Down
70 changes: 17 additions & 53 deletions src/geophires_x/Economics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import numpy_financial as npf
import geophires_x.Model as Model
from geophires_x.OptionList import Configuration, WellDrillingCostCorrelation, EconomicModel, EndUseOptions, PlantType
from geophires_x.Parameter import intParameter, floatParameter, OutputParameter, ReadParameter, boolParameter
from geophires_x.Parameter import intParameter, floatParameter, OutputParameter, ReadParameter, boolParameter, \
coerce_int_params_to_enum_values
from geophires_x.Units import *


Expand Down Expand Up @@ -608,12 +609,13 @@ def __init__(self, model: Model):
# This is the default.
self.econmodel = self.ParameterDict[self.econmodel.Name] = intParameter(
"Economic Model",
DefaultValue=EconomicModel.STANDARDIZED_LEVELIZED_COST,
DefaultValue=EconomicModel.STANDARDIZED_LEVELIZED_COST.int_value,
AllowableRange=[1, 2, 3, 4],
ValuesEnum=EconomicModel,
Required=True,
ErrMessage="assume default economic model (2)",
ToolTipText="Specify the economic model to calculate the levelized cost of energy." +
" 1: Fixed Charge Rate Model, 2: Standard Levelized Cost Model, 3: BICYCLE Levelized Cost Model, 4: CLGS"
'; '.join([f'{it.int_value}: {it.value}' for it in EconomicModel])
)
self.ccstimfixed = self.ParameterDict[self.ccstimfixed.Name] = floatParameter(
"Reservoir Stimulation Capital Cost",
Expand Down Expand Up @@ -989,12 +991,13 @@ def __init__(self, model: Model):
)
self.wellcorrelation = self.ParameterDict[self.wellcorrelation.Name] = intParameter(
"Well Drilling Cost Correlation",
DefaultValue=WellDrillingCostCorrelation.VERTICAL_LARGE_INT1,
DefaultValue=WellDrillingCostCorrelation.VERTICAL_LARGE_INT1.int_value,
AllowableRange=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
ValuesEnum=WellDrillingCostCorrelation,
UnitType=Units.NONE,
ErrMessage="assume default well drilling cost correlation (10)",
ToolTipText="Select the built-in well drilling and completion cost correlation: " +
'; '.join([f'{it.numerical_input_value}: {it.value}' for it in WellDrillingCostCorrelation])
'; '.join([f'{it.int_value}: {it.value}' for it in WellDrillingCostCorrelation])
)

self.DoAddOnCalculations = self.ParameterDict[self.DoAddOnCalculations.Name] = boolParameter(
Expand Down Expand Up @@ -1370,8 +1373,9 @@ def __init__(self, model: Model):
UnitType=Units.CO2PRODUCTION,
PreferredUnits=CO2ProductionUnit.LBSPERKWH,
CurrentUnits=CO2ProductionUnit.LBSPERKWH,
ErrMessage="assume the default value CO2 production for burning natural gas (0.407855 lbs/kWh)", #LBSPERKWH https://www.epa.gov/energy/greenhouse-gases-equivalencies-calculator-calculations-and-references
ToolTipText="CO2 intensity of buring natural gas (how much CO2 is produced per kWh of heat produced (0.407855 lbs/kWh))"
ErrMessage="assume the default value CO2 production for burning natural gas (0.070324961 lbs/kWh)",
ToolTipText="CO2 intensity of burning natural gas (how much CO2 is produced per kWh of heat produced "
"(0.070324961 lbs/kWh; https://www.epa.gov/energy/greenhouse-gases-equivalencies-calculator-calculations-and-references))"
)

self.AnnualLicenseEtc = self.ParameterDict[self.AnnualLicenseEtc.Name] = floatParameter(
Expand Down Expand Up @@ -1906,53 +1910,11 @@ def read_parameters(self, model: Model) -> None:

# handle special cases
if ParameterToModify.Name == "Economic Model":
if ParameterReadIn.sValue == '1':
self.econmodel.value = EconomicModel.FCR
elif ParameterReadIn.sValue == '2':
# use standard LCOE/LCOH calculation as found on wikipedia (requires an interest rate).
self.econmodel.value = EconomicModel.STANDARDIZED_LEVELIZED_COST
elif ParameterReadIn.sValue == '3':
# use Bicycle LCOE/LCOH model (requires several financial input parameters)
self.econmodel.value = EconomicModel.BICYCLE
else:
self.econmodel.value = EconomicModel.CLGS # CLGS
self.econmodel.value = EconomicModel.from_input_string(ParameterReadIn.sValue)

elif ParameterToModify.Name == "Well Drilling Cost Correlation":
if ParameterReadIn.sValue == '1':
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_SMALL
elif ParameterReadIn.sValue == '2':
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_SMALL
elif ParameterReadIn.sValue == '3':
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_LARGE
elif ParameterReadIn.sValue == '4':
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_LARGE
elif ParameterReadIn.sValue == '5':
ParameterToModify.value = WellDrillingCostCorrelation.SIMPLE
elif ParameterReadIn.sValue == '6':
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_SMALL_INT1
elif ParameterReadIn.sValue == '7':
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_SMALL_INT2
elif ParameterReadIn.sValue == '8':
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_SMALL_INT1
elif ParameterReadIn.sValue == '9':
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_SMALL_INT2
elif ParameterReadIn.sValue == '10':
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_LARGE_INT1
elif ParameterReadIn.sValue == '11':
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_LARGE_INT2
elif ParameterReadIn.sValue == '12':
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_LARGE_INT1
elif ParameterReadIn.sValue == '13':
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_LARGE_INT2
elif ParameterReadIn.sValue == '14':
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_SMALL_IDEAL
elif ParameterReadIn.sValue == '15':
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_SMALL_IDEAL
elif ParameterReadIn.sValue == '16':
ParameterToModify.value = WellDrillingCostCorrelation.VERTICAL_LARGE_IDEAL
elif ParameterReadIn.sValue == '17':
ParameterToModify.value = WellDrillingCostCorrelation.DEVIATED_LARGE_IDEAL
else:
ParameterToModify.value = WellDrillingCostCorrelation.SIMPLE # Assuming 'SIMPLE' is still a valid option
ParameterToModify.value = WellDrillingCostCorrelation.from_input_string(ParameterReadIn.sValue)

elif ParameterToModify.Name == "Reservoir Stimulation Capital Cost Adjustment Factor":
if self.ccstimfixed.Valid and ParameterToModify.Valid:
print("Warning: Provided reservoir stimulation cost adjustment factor not considered" +
Expand Down Expand Up @@ -2277,6 +2239,8 @@ def read_parameters(self, model: Model) -> None:
self.DoSDACGTCalculations.value = True
break

coerce_int_params_to_enum_values(self.ParameterDict)

model.logger.info(f'complete {__class__!s}: {sys._getframe().f_code.co_name}')

def Calculate(self, model: Model) -> None:
Expand Down
21 changes: 19 additions & 2 deletions src/geophires_x/GeoPHIRESUtils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import annotations

import logging
import os
import sys
from enum import Enum
from os.path import exists
import dataclasses
import json
import numbers
from functools import lru_cache
from typing import Optional
from typing import Optional, Any

import scipy
from pint.facets.plain import PlainQuantity
Expand Down Expand Up @@ -577,6 +577,22 @@ class _EnhancedJSONEncoder(json.JSONEncoder):
def default(self, o):
if dataclasses.is_dataclass(o):
return dataclasses.asdict(o)

if issubclass(o, Enum):
def get_entry(member) -> dict[str, Any]:
d = {
'name': member.name,
'value': member.value
}

if hasattr(member, 'int_value'):
d['int_value'] = member.int_value

return d

ret = [get_entry(member) for member in o]
return ret

return super().default(o)


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

return pressure_mpa

Loading

0 comments on commit b6f63f9

Please sign in to comment.