Skip to content

Commit 381f796

Browse files
Merge pull request #37 from softwareengineerprogrammer/combine-discount-rate-and-fixed-internal-rate
Set fixed internal rate default value to same as discount rate
2 parents c1927fb + 04f9feb commit 381f796

25 files changed

+157
-146
lines changed

src/geophires_x/AGSEconomics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def read_parameters(self, model: Model) -> None:
110110
# including the ones that are specific to this class
111111

112112
# inputs we already have - needs to be set at ReadParameter time so values set at the latest possible time
113-
self.Discount_rate = model.economics.discountrate.value # same units are GEOPHIRES
114-
self.Electricity_rate = model.surfaceplant.electricity_cost_to_buy.value # same units are GEOPHIRES
113+
self.Discount_rate = model.economics.discountrate.value # same units as GEOPHIRES
114+
self.Electricity_rate = model.surfaceplant.electricity_cost_to_buy.value # same units as GEOPHIRES
115115

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

src/geophires_x/AGSOutputs.py

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
import geophires_x
77

8-
from .Parameter import ConvertUnitsBack, ConvertOutputUnits
9-
from .OptionList import EndUseOptions, EconomicModel
10-
from .Units import *
8+
from geophires_x.OptionList import EndUseOptions, EconomicModel
9+
1110
import geophires_x.Model as Model
1211
import geophires_x.Outputs as Outputs
1312
import numpy as np
1413

14+
from geophires_x.Units import TemperatureUnit
15+
1516
NL = "\n"
1617

1718

@@ -28,27 +29,8 @@ def PrintOutputs(self, model: Model):
2829
:return: None
2930
"""
3031
model.logger.info(f'Init {str(__class__)}: {sys._getframe().f_code.co_name}')
31-
# Deal with converting Units back to PreferredUnits, if required.
32-
# before we write the outputs, we go thru all the parameters for all of the objects and set the values
33-
# back to the units that the user entered the data in
34-
# We do this because the value may be displayed in the output, and we want the user to recognize their value,
35-
# not some converted value
36-
for obj in [model.reserv, model.wellbores, model.surfaceplant, model.economics]:
37-
for key in obj.ParameterDict:
38-
param = obj.ParameterDict[key]
39-
if not param.UnitsMatch:
40-
ConvertUnitsBack(param, model)
41-
42-
# now we need to loop thru all the output parameters to update their units to whatever units the user has specified.
43-
# i.e., they may have specified that all LENGTH results must be in feet, so we need to convert
44-
# those from whatever LENGTH unit they are to feet.
45-
# same for all the other classes of units (TEMPERATURE, DENSITY, etc).
46-
47-
for obj in [model.reserv, model.wellbores, model.surfaceplant, model.economics]:
48-
for key in obj.OutputParameterDict:
49-
if key in self.ParameterDict:
50-
if self.ParameterDict[key] != obj.OutputParameterDict[key].CurrentUnits:
51-
ConvertOutputUnits(obj.OutputParameterDict[key], self.ParameterDict[key], model)
32+
33+
self._convert_units(model)
5234

5335
# ---------------------------------------
5436
# write results to output file and screen

src/geophires_x/Economics.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -837,15 +837,17 @@ def __init__(self, model: Model):
837837
ErrMessage="assume default fixed charge rate (0.1)",
838838
ToolTipText="Fixed charge rate (FCR) used in the Fixed Charge Rate Model"
839839
)
840+
841+
discount_rate_default_val = 0.0625
840842
self.discountrate = self.ParameterDict[self.discountrate.Name] = floatParameter(
841843
"Discount Rate",
842-
DefaultValue=0.07,
844+
DefaultValue=discount_rate_default_val,
843845
Min=0.0,
844846
Max=1.0,
845847
UnitType=Units.PERCENT,
846-
PreferredUnits=PercentUnit.TENTH,
848+
PreferredUnits=PercentUnit.PERCENT,
847849
CurrentUnits=PercentUnit.TENTH,
848-
ErrMessage="assume default discount rate (0.07)",
850+
ErrMessage=f'assume default discount rate ({discount_rate_default_val})',
849851
ToolTipText="Discount rate used in the Standard Levelized Cost Model"
850852
)
851853
self.FIB = self.ParameterDict[self.FIB.Name] = floatParameter(
@@ -1379,15 +1381,18 @@ def __init__(self, model: Model):
13791381
PreferredUnits=CurrencyUnit.MDOLLARS,
13801382
CurrentUnits=CurrencyUnit.MDOLLARS
13811383
)
1384+
1385+
fir_default_unit = PercentUnit.PERCENT
1386+
fir_default_val = self.discountrate.quantity().to(convertible_unit(fir_default_unit)).magnitude
13821387
self.FixedInternalRate = self.ParameterDict[self.FixedInternalRate.Name] = floatParameter(
13831388
"Fixed Internal Rate",
1384-
DefaultValue=6.25,
1389+
DefaultValue=fir_default_val,
13851390
Min=0.0,
13861391
Max=100.0,
13871392
UnitType=Units.PERCENT,
13881393
PreferredUnits=PercentUnit.PERCENT,
1389-
CurrentUnits=PercentUnit.PERCENT,
1390-
ErrMessage="assume default for fixed internal rate (6.25%)",
1394+
CurrentUnits=fir_default_unit,
1395+
ErrMessage=f'assume default for fixed internal rate ({fir_default_val}%)',
13911396
ToolTipText="Fixed Internal Rate (used in NPV calculation)"
13921397
)
13931398
self.CAPEX_heat_electricity_plant_ratio = self.ParameterDict[self.CAPEX_heat_electricity_plant_ratio.Name] = floatParameter(
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
USD = [currency]
22
cents = USD / 100
3+
KUSD = USD * 1000
4+
MMBTU = BTU * 1_000_000

src/geophires_x/GeoPHIRESUtils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import CoolProp.CoolProp as CP
1919

2020
from geophires_x.Parameter import ParameterEntry, Parameter
21-
from geophires_x.Units import get_unit_registry
21+
from geophires_x.Units import get_unit_registry, convertible_unit
2222

2323
_logger = logging.getLogger('root') # TODO use __name__ instead of root
2424

@@ -224,7 +224,7 @@ def quantity(value: float, unit: str) -> PlainQuantity:
224224
:rtype: pint.registry.Quantity - note type annotation uses PlainQuantity due to issues with python 3.8 failing
225225
to import the Quantity TypeAlias
226226
"""
227-
return _ureg.Quantity(value, unit)
227+
return _ureg.Quantity(value, convertible_unit(unit))
228228

229229

230230
@lru_cache

src/geophires_x/Outputs.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -744,15 +744,7 @@ def read_parameters(self, model: Model, default_output_path: Path = None) -> Non
744744

745745
model.logger.info(f'Complete {__class__!s}: {__name__}')
746746

747-
def PrintOutputs(self, model: Model):
748-
"""
749-
PrintOutputs writes the standard outputs to the output file.
750-
:param model: The container class of the application, giving access to everything else, including the logger
751-
:type model: :class:`~geophires_x.Model.Model`
752-
:return: None
753-
"""
754-
model.logger.info(f'Init {str(__class__)}: {sys._getframe().f_code.co_name}')
755-
747+
def _convert_units(self, model: Model):
756748
# Deal with converting Units back to PreferredUnits, if required.
757749
# before we write the outputs, we go thru all the parameters for all of the objects and set the values back
758750
# to the units that the user entered the data in
@@ -779,6 +771,17 @@ def PrintOutputs(self, model: Model):
779771
elif not output_param.UnitsMatch:
780772
obj.OutputParameterDict[key] = output_param.with_preferred_units()
781773

774+
def PrintOutputs(self, model: Model):
775+
"""
776+
PrintOutputs writes the standard outputs to the output file.
777+
:param model: The container class of the application, giving access to everything else, including the logger
778+
:type model: :class:`~geophires_x.Model.Model`
779+
:return: None
780+
"""
781+
model.logger.info(f'Init {str(__class__)}: {sys._getframe().f_code.co_name}')
782+
783+
self._convert_units(model)
784+
782785
#data structures and assignments for HTML and Improved Text Output formats
783786
simulation_metadata = []
784787
summary = []
@@ -1634,7 +1637,11 @@ def PrintOutputs(self, model: Model):
16341637
f.write(f' Fixed Charge Rate (FCR): {model.economics.FCR.value*100.0:10.2f} ' + model.economics.FCR.CurrentUnits.value + NL)
16351638
elif model.economics.econmodel.value == EconomicModel.STANDARDIZED_LEVELIZED_COST:
16361639
f.write(' Economic Model = ' + model.economics.econmodel.value.value + NL)
1637-
f.write(f' Interest Rate: {model.economics.discountrate.value*100.0:10.2f} ' + model.economics.discountrate.CurrentUnits.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')
1644+
16381645
elif model.economics.econmodel.value == EconomicModel.BICYCLE:
16391646
f.write(' Economic Model = ' + model.economics.econmodel.value.value + NL)
16401647
f.write(f' Accrued financing during construction: {model.economics.inflrateconstruction.value*100:10.2f} ' + model.economics.inflrateconstruction.CurrentUnits.value + NL)

src/geophires_x/OutputsAddOns.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def PrintOutputs(self, model) -> tuple:
2020
"""
2121
model.logger.info(f'Init {str(__class__)}: {__name__}')
2222

23+
self._convert_units(model)
24+
2325
# now do AddOn output, which will append to the original output
2426
# write results to output file and screen
2527
try:

src/geophires_x/OutputsCCUS.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ def PrintOutputs(self, model):
1616
:type model: :class:`~geophires_x.Model.Model`
1717
:return: Nothing
1818
"""
19-
model.logger.info("Init " + str(__class__) + ": " + sys._getframe().f_code.co_name)
19+
model.logger.info(f'Init {__class__!s}: sys._getframe().f_code.co_name')
20+
21+
self._convert_units(model)
2022

2123
if np.sum(model.ccuseconomics.CCUSRevenue.value) == 0:
2224
return # don't bother if we have nothing to report.

src/geophires_x/OutputsS_DAC_GT.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def PrintOutputs(self, model) -> tuple:
1818
"""
1919
model.logger.info(f'Init {str(__class__)}: {__name__}')
2020

21+
self._convert_units(model)
22+
2123
# now do S_DAC_GT output, which will append to the original output
2224
# write results to output file and screen
2325
try:

src/geophires_x/Parameter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def UnitsMatch(self) -> str:
7676

7777
def with_preferred_units(self) -> Any: # Any is a proxy for Self
7878
ret: OutputParameter = dataclasses.replace(self)
79-
ret.value = ret.quantity().to(ret.PreferredUnits).magnitude
79+
ret.value = ret.quantity().to(convertible_unit(ret.PreferredUnits)).magnitude
8080
ret.CurrentUnits = ret.PreferredUnits
8181
return ret
8282

@@ -609,7 +609,7 @@ def ConvertUnitsBack(ParamToModify: Parameter, model):
609609
model.logger.info(f'Init {str(__name__)}: {sys._getframe().f_code.co_name} for {ParamToModify.Name}')
610610

611611
try:
612-
ParamToModify.value = _ureg.Quantity(ParamToModify.value, ParamToModify.CurrentUnits.value).to(ParamToModify.PreferredUnits.value).magnitude
612+
ParamToModify.value = _ureg.Quantity(ParamToModify.value, convertible_unit(ParamToModify.CurrentUnits)).to(convertible_unit(ParamToModify.PreferredUnits)).magnitude
613613
ParamToModify.CurrentUnits = ParamToModify.PreferredUnits
614614
except AttributeError as ae:
615615
# TODO refactor to check for/convert currency instead of relying on try/except once currency conversion is
@@ -848,7 +848,7 @@ def ConvertOutputUnits(oparam: OutputParameter, newUnit: Units, model):
848848
"""
849849

850850
try:
851-
oparam.value = _ureg.Quantity(oparam.value, oparam.CurrentUnits.value).to(newUnit.value).magnitude
851+
oparam.value = _ureg.Quantity(oparam.value, oparam.CurrentUnits.value).to(convertible_unit(newUnit.value)).magnitude
852852
oparam.CurrentUnits = newUnit
853853
return
854854
except AttributeError as ae:

0 commit comments

Comments
 (0)