5
5
import numpy as np
6
6
from matplotlib import pyplot as plt
7
7
import geophires_x .Model as Model
8
- from geophires_x .Parameter import ConvertUnitsBack , ConvertOutputUnits , LookupUnits
8
+ from geophires_x .Economics import Economics
9
+ from geophires_x .Parameter import ConvertUnitsBack , ConvertOutputUnits , LookupUnits , OutputParameter
9
10
from geophires_x .OptionList import EndUseOptions , EconomicModel , ReservoirModel , FractureShape , ReservoirVolume , \
10
11
PlantType
11
12
@@ -87,17 +88,21 @@ def PrintOutputs(self, model: Model):
87
88
param = obj .ParameterDict [key ]
88
89
if not param .UnitsMatch : ConvertUnitsBack (param , model )
89
90
90
- # now we need to loop through all thw output parameters to update their units to
91
+ # now we need to loop through all the output parameters to update their units to
91
92
# whatever units the user has specified.
92
93
# i.e., they may have specified that all LENGTH results must be in feet, so we need to convert those
93
94
# from whatever LENGTH unit they are to feet.
94
95
# same for all the other classes of units (TEMPERATURE, DENSITY, etc).
95
96
96
97
for obj in [model .reserv , model .wellbores , model .surfaceplant , model .economics ]:
97
98
for key in obj .OutputParameterDict :
99
+ output_param :OutputParameter = obj .OutputParameterDict [key ]
98
100
if key in self .ParameterDict :
99
- if self .ParameterDict [key ] != obj .OutputParameterDict [key ].CurrentUnits :
100
- ConvertOutputUnits (obj .OutputParameterDict [key ], self .ParameterDict [key ], model )
101
+ if self .ParameterDict [key ].PreferredUnits != output_param .CurrentUnits :
102
+ ConvertOutputUnits (output_param , self .ParameterDict [key ].PreferredUnits , model )
103
+ elif not output_param .UnitsMatch :
104
+ obj .OutputParameterDict [key ] = output_param .with_preferred_units ()
105
+
101
106
102
107
# write results to output file and screen
103
108
@@ -110,7 +115,7 @@ def PrintOutputs(self, model: Model):
110
115
f .write ("Simulation Metadata\n " )
111
116
f .write ("----------------------\n " )
112
117
f .write (f' GEOPHIRES Version: { geophires_x .__version__ } \n ' )
113
- f .write (" GEOPHIRES Build Date: 2022-06-30 \n " )
118
+ f .write (" GEOPHIRES Build Date: 2024-03-05 \n " ) # FIXME TODO https://github.com/NREL/GEOPHIRES-X/issues/139
114
119
f .write (" Simulation Date: " + datetime .datetime .now ().strftime ("%Y-%m-%d\n " ))
115
120
f .write (" Simulation Time: " + datetime .datetime .now ().strftime ("%H:%M\n " ))
116
121
f .write (" Calculation Time: " + "{0:10.3f}" .format ((time .time ()- model .tic )) + " sec\n " )
@@ -185,7 +190,7 @@ def PrintOutputs(self, model: Model):
185
190
payback_period_val = model .economics .ProjectPaybackPeriod .value
186
191
project_payback_period_display = f'{ payback_period_val :10.2f} { model .economics .ProjectPaybackPeriod .PreferredUnits .value } ' \
187
192
if payback_period_val > 0.0 else 'N/A'
188
- f .write (f' Project Payback Period: { project_payback_period_display } \n ' )
193
+ f .write (f' Project Payback Period: { project_payback_period_display } \n ' )
189
194
190
195
if model .surfaceplant .enduse_option .value in [EndUseOptions .COGENERATION_TOPPING_EXTRA_HEAT ,
191
196
EndUseOptions .COGENERATION_BOTTOMING_EXTRA_HEAT ,
@@ -621,48 +626,58 @@ def PrintOutputs(self, model: Model):
621
626
"Year Electricity | Heat | Cooling | Carbon | Project" + NL )
622
627
f .write (
623
628
"Since Price Ann. Rev. Cumm. Rev. | Price Ann. Rev. Cumm. Rev. | Price Ann. Rev. Cumm. Rev. | Price Ann. Rev. Cumm. Rev. | OPEX Net Rev. Net Cashflow" + NL )
624
- econ = model .economics
629
+ econ :Economics = model .economics
630
+
631
+ def o (output_param : OutputParameter ):
632
+ # TODO generalize this and/or FIXME make it unnecessary
633
+ if output_param .Name in econ .OutputParameterDict :
634
+ return econ .OutputParameterDict [output_param .Name ]
635
+ else :
636
+ return o
637
+
625
638
f .write ("Start ("
626
- + econ .ElecPrice . PreferredUnits .value +
627
- ")(" + econ .ElecRevenue . PreferredUnits .value +
628
- ") (" + econ .ElecCummRevenue . PreferredUnits .value +
629
- ") |(" + econ .HeatPrice . PreferredUnits .value +
630
- ") (" + econ .HeatRevenue . PreferredUnits .value +
631
- ") (" + econ .HeatCummRevenue . PreferredUnits .value +
632
- ") |(" + econ .CoolingPrice . PreferredUnits .value +
633
- ") (" + econ .CoolingRevenue . PreferredUnits .value +
634
- ") (" + econ .CoolingCummRevenue . PreferredUnits .value +
635
- ") |(" + econ .CarbonPrice . PreferredUnits .value +
636
- ") (" + econ .CarbonRevenue . PreferredUnits .value +
637
- ") (" + econ .CarbonCummCashFlow . PreferredUnits .value +
638
- ") |(" + econ .Coam . PreferredUnits .value +
639
- ") (" + econ .TotalRevenue . PreferredUnits .value +
640
- ") (" + econ .TotalCummRevenue . PreferredUnits .value + ")\n " )
639
+ + o ( econ .ElecPrice ). CurrentUnits .value +
640
+ ")(" + o ( econ .ElecRevenue ). CurrentUnits .value +
641
+ ") (" + o ( econ .ElecCummRevenue ). CurrentUnits .value +
642
+ ") |(" + o ( econ .HeatPrice ). CurrentUnits .value +
643
+ ") (" + o ( econ .HeatRevenue ). CurrentUnits .value +
644
+ ") (" + o ( econ .HeatCummRevenue ). CurrentUnits .value +
645
+ ") |(" + o ( econ .CoolingPrice ). CurrentUnits .value +
646
+ ") (" + o ( econ .CoolingRevenue ). CurrentUnits .value +
647
+ ") (" + o ( econ .CoolingCummRevenue ). CurrentUnits .value +
648
+ ") |(" + o ( econ .CarbonPrice ). CurrentUnits .value +
649
+ ") (" + o ( econ .CarbonRevenue ). CurrentUnits .value +
650
+ ") (" + o ( econ .CarbonCummCashFlow ). CurrentUnits .value +
651
+ ") |(" + o ( econ .Coam ). CurrentUnits .value +
652
+ ") (" + o ( econ .TotalRevenue ). CurrentUnits .value +
653
+ ") (" + o ( econ .TotalCummRevenue ). CurrentUnits .value + ")\n " )
641
654
f .write (
642
655
"________________________________________________________________________________________________________________________________________________________________________________________" + NL )
643
656
# running years...
644
657
for ii in range (0 , (
645
658
model .surfaceplant .construction_years .value + model .surfaceplant .plant_lifetime .value - 1 ), 1 ):
659
+
646
660
if ii < model .surfaceplant .construction_years .value :
647
661
OPEX = 0.0 # zero out the OPEX during construction years
648
662
else :
649
- OPEX = econ .Coam .value
663
+ OPEX = o ( econ .Coam ) .value
650
664
f .write (
651
- f"{ ii + 1 :3.0f} { econ .ElecPrice .value [ii ]:5.2f} { econ .ElecRevenue .value [ii ]:5.2f} { econ .ElecCummRevenue .value [ii ]:5.2f} | { econ .HeatPrice .value [ii ]:5.2f} { econ .HeatRevenue .value [ii ]:5.2f} { econ .HeatCummRevenue .value [ii ]:5.2f} | { econ .CoolingPrice .value [ii ]:5.2f} { econ .CoolingRevenue .value [ii ]:5.2f} { econ .CoolingCummRevenue .value [ii ]:5.2f} | { econ .CarbonPrice .value [ii ]:5.2f} { econ .CarbonRevenue .value [ii ]:5.2f} { econ .CarbonCummCashFlow .value [ii ]:5.2f} | { OPEX :5.2f} { econ .TotalRevenue .value [ii ]:5.2f} { econ .TotalCummRevenue .value [ii ]:5.2f} \n " )
665
+ f"{ ii + 1 :3.0f} { o ( econ .ElecPrice ) .value [ii ]:5.2f} { o ( econ .ElecRevenue ) .value [ii ]:5.2f} { o ( econ .ElecCummRevenue ) .value [ii ]:5.2f} | { o ( econ .HeatPrice ) .value [ii ]:5.2f} { o ( econ .HeatRevenue ) .value [ii ]:5.2f} { o ( econ .HeatCummRevenue ) .value [ii ]:5.2f} | { o ( econ .CoolingPrice ) .value [ii ]:5.2f} { o ( econ .CoolingRevenue ) .value [ii ]:5.2f} { o ( econ .CoolingCummRevenue ) .value [ii ]:5.2f} | { o ( econ .CarbonPrice ) .value [ii ]:5.2f} { o ( econ .CarbonRevenue ) .value [ii ]:5.2f} { o ( econ .CarbonCummCashFlow ) .value [ii ]:5.2f} | { OPEX :5.2f} { o ( econ .TotalRevenue ) .value [ii ]:5.2f} { o ( econ .TotalCummRevenue ) .value [ii ]:5.2f} \n " )
652
666
f .write (NL )
653
667
654
668
if model .economics .DoAddOnCalculations .value : model .addoutputs .PrintOutputs (model )
655
669
if model .economics .DoSDACGTCalculations .value : model .sdacgtoutputs .PrintOutputs (model )
656
670
657
671
except BaseException as ex :
658
672
tb = sys .exc_info ()[2 ]
659
- print (str (ex ))
660
- print ("Error: GEOPHIRES Failed to write the output file. Exiting....Line %i" % tb .tb_lineno )
673
+ msg = "Error: GEOPHIRES Failed to write the output file. Exiting....Line %i" % tb .tb_lineno
674
+ print (str (ex ))
675
+ print (msg )
661
676
model .logger .critical (str (ex ))
662
- model .logger .critical ("Error: GEOPHIRES Failed to write the output file. Exiting....Line %i" % tb . tb_lineno )
663
- sys . exit ()
677
+ model .logger .critical (msg )
678
+ raise RuntimeError ( msg ) from ex
664
679
665
- model .logger .info (" Complete " + str ( __class__ ) + ": " + sys ._getframe ().f_code .co_name )
680
+ model .logger .info (f' Complete { __class__ !s } : { sys ._getframe ().f_code .co_name } ' )
666
681
667
682
def MakeDistrictHeatingPlot (self , model : Model ):
668
683
"""
0 commit comments