Skip to content

Commit 5d0cd69

Browse files
Merge pull request NREL#304 from softwareengineerprogrammer/main
Synchronize discount rate and fixed internal rate automatically
2 parents c976107 + 6281bd8 commit 5d0cd69

17 files changed

+97
-26
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 3.6.2
2+
current_version = 3.6.3
33
commit = True
44
tag = True
55

.cookiecutterrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ default_context:
5454
sphinx_doctest: "no"
5555
sphinx_theme: "sphinx-py3doc-enhanced-theme"
5656
test_matrix_separate_coverage: "no"
57-
version: 3.6.2
57+
version: 3.6.3
5858
version_manager: "bump2version"
5959
website: "https://github.com/NREL"
6060
year_from: "2023"

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ Free software: `MIT license <LICENSE>`__
5151
:alt: Supported implementations
5252
:target: https://pypi.org/project/geophires-x
5353

54-
.. |commits-since| image:: https://img.shields.io/github/commits-since/softwareengineerprogrammer/GEOPHIRES-X/v3.6.2.svg
54+
.. |commits-since| image:: https://img.shields.io/github/commits-since/softwareengineerprogrammer/GEOPHIRES-X/v3.6.3.svg
5555
:alt: Commits since latest release
56-
:target: https://github.com/softwareengineerprogrammer/GEOPHIRES-X/compare/v3.6.2...main
56+
:target: https://github.com/softwareengineerprogrammer/GEOPHIRES-X/compare/v3.6.3...main
5757

5858
.. |docs| image:: https://readthedocs.org/projects/GEOPHIRES-X/badge/?style=flat
5959
:target: https://nrel.github.io/GEOPHIRES-X

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
year = '2024'
1919
author = 'NREL'
2020
copyright = f'{year}, {author}'
21-
version = release = '3.6.2'
21+
version = release = '3.6.3'
2222

2323
pygments_style = 'trac'
2424
templates_path = ['./templates']

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def read(*names, **kwargs):
1313

1414
setup(
1515
name='geophires-x',
16-
version='3.6.2',
16+
version='3.6.3',
1717
license='MIT',
1818
description='GEOPHIRES is a free and open-source geothermal techno-economic simulator.',
1919
long_description='{}\n{}'.format(

src/geophires_x/Economics.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import math
2+
import os
23
import sys
34
import numpy as np
45
import numpy_financial as npf
@@ -845,7 +846,7 @@ def __init__(self, model: Model):
845846
Min=0.0,
846847
Max=1.0,
847848
UnitType=Units.PERCENT,
848-
PreferredUnits=PercentUnit.PERCENT,
849+
PreferredUnits=PercentUnit.TENTH,
849850
CurrentUnits=PercentUnit.TENTH,
850851
ErrMessage=f'assume default discount rate ({discount_rate_default_val})',
851852
ToolTipText="Discount rate used in the Standard Levelized Cost Model"
@@ -1711,6 +1712,12 @@ def __init__(self, model: Model):
17111712
PreferredUnits=MassUnit.LB,
17121713
CurrentUnits=MassUnit.LB
17131714
)
1715+
self.interest_rate = self.OutputParameterDict[self.interest_rate.Name] = OutputParameter(
1716+
Name='Interest Rate',
1717+
UnitType=Units.PERCENT,
1718+
PreferredUnits=PercentUnit.PERCENT,
1719+
CurrentUnits=PercentUnit.PERCENT
1720+
)
17141721
self.TotalRevenue = self.OutputParameterDict[self.TotalRevenue.Name] = OutputParameter(
17151722
Name="Annual Revenue from Project",
17161723
UnitType=Units.CURRENCYFREQUENCY,
@@ -2147,15 +2154,43 @@ def read_parameters(self, model: Model) -> None:
21472154
if key.startswith("AddOn"):
21482155
self.DoAddOnCalculations.value = True
21492156
break
2157+
21502158
for key in model.InputParameters.keys():
21512159
if key.startswith("S-DAC-GT"):
21522160
self.DoSDACGTCalculations.value = True
21532161
break
21542162

21552163
coerce_int_params_to_enum_values(self.ParameterDict)
2164+
self.sync_interest_rate(model)
21562165

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

2168+
def sync_interest_rate(self, model):
2169+
def discount_rate_display() -> str:
2170+
return str(self.discountrate.quantity()).replace(' dimensionless', '')
2171+
2172+
if self.discountrate.Provided ^ self.FixedInternalRate.Provided:
2173+
if self.discountrate.Provided:
2174+
self.FixedInternalRate.value = self.discountrate.quantity().to(
2175+
convertible_unit(self.FixedInternalRate.CurrentUnits)).magnitude
2176+
model.logger.info(f'Set {self.FixedInternalRate.Name} to {self.FixedInternalRate.quantity()} '
2177+
f'because {self.discountrate.Name} was provided ({discount_rate_display()})')
2178+
else:
2179+
self.discountrate.value = self.FixedInternalRate.quantity().to(
2180+
convertible_unit(self.discountrate.CurrentUnits)).magnitude
2181+
model.logger.info(
2182+
f'Set {self.discountrate.Name} to {discount_rate_display()} because '
2183+
f'{self.FixedInternalRate.Name} was provided ({self.FixedInternalRate.quantity()})')
2184+
2185+
if self.discountrate.Provided and self.FixedInternalRate.Provided \
2186+
and self.discountrate.quantity().to(convertible_unit(self.FixedInternalRate.CurrentUnits)).magnitude \
2187+
!= self.FixedInternalRate.value:
2188+
model.logger.warning(f'{self.discountrate.Name} and {self.FixedInternalRate.Name} provided with different '
2189+
f'values ({discount_rate_display()}; {self.FixedInternalRate.quantity()}). '
2190+
f'It is recommended to only provide one of these values.')
2191+
2192+
self.interest_rate.value = self.discountrate.quantity().to(convertible_unit(self.interest_rate.CurrentUnits)).magnitude
2193+
21592194
def Calculate(self, model: Model) -> None:
21602195
"""
21612196
The Calculate function is where all the calculations are done.

src/geophires_x/Outputs.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
PlantType
2424
from geophires_x.GeoPHIRESUtils import UpgradeSymbologyOfUnits, render_default, InsertImagesIntoHTML
2525
from geophires_x.Parameter import Parameter
26+
from geophires_x.Units import convertible_unit, Units, PercentUnit
2627

2728
NL = '\n'
2829
validFilenameChars = "-_.() %s%s" % (string.ascii_letters, string.digits)
@@ -1637,10 +1638,7 @@ def PrintOutputs(self, model: Model):
16371638
f.write(f' Fixed Charge Rate (FCR): {model.economics.FCR.value*100.0:10.2f} ' + model.economics.FCR.CurrentUnits.value + NL)
16381639
elif model.economics.econmodel.value == EconomicModel.STANDARDIZED_LEVELIZED_COST:
16391640
f.write(' Economic Model = ' + model.economics.econmodel.value.value + NL)
1640-
1641-
# FIXME discountrate should not be multiplied by 100 here -
1642-
# it appears to be incorrectly claiming its units are percent when the actual value is in tenths.
1643-
f.write(f' Interest Rate: {model.economics.discountrate.value*100.0:10.2f} {model.economics.discountrate.CurrentUnits.value}\n')
1641+
f.write(f' {model.economics.interest_rate.Name}: {model.economics.interest_rate.value:10.2f} {model.economics.interest_rate.CurrentUnits.value}\n')
16441642

16451643
elif model.economics.econmodel.value == EconomicModel.BICYCLE:
16461644
f.write(' Economic Model = ' + model.economics.econmodel.value.value + NL)

src/geophires_x/SUTRAEconomics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ def read_parameters(self, model: Model) -> None:
330330
else:
331331
model.logger.info('No parameters read because no content provided')
332332

333+
self.sync_interest_rate(model)
334+
333335
model.logger.info(f'Complete {__class__!s}: {sys._getframe().f_code.co_name}')
334336

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

src/geophires_x/SUTRAOutputs.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@ def PrintOutputs(self, model: Model):
8585
f.write(f" Fixed Charge Rate (FCR): {model.economics.FCR.value*100.0:10.2f} " + model.economics.FCR.CurrentUnits.value + NL)
8686
elif model.economics.econmodel.value == EconomicModel.STANDARDIZED_LEVELIZED_COST:
8787
f.write(" Economic Model = " + model.economics.econmodel.value.value + NL)
88-
89-
# FIXME discountrate should not be multiplied by 100 here -
90-
# it appears to be incorrectly claiming its units are percent when the actual value is in tenths.
91-
f.write(f" Interest Rate: {model.economics.discountrate.value*100.0:10.2f} {model.economics.discountrate.CurrentUnits.value}\n")
88+
f.write(f' {model.economics.interest_rate.Name}: {model.economics.interest_rate.value:10.2f} {model.economics.interest_rate.CurrentUnits.value}\n')
9289

9390
elif model.economics.econmodel.value == EconomicModel.BICYCLE:
9491
f.write(" Economic Model = " + model.economics.econmodel.value.value + NL)

src/geophires_x/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '3.6.2'
1+
__version__ = '3.6.3'

0 commit comments

Comments
 (0)