Skip to content

Commit c549c39

Browse files
Convert units in all Outputs classes
1 parent 14bc59d commit c549c39

File tree

8 files changed

+42
-43
lines changed

8 files changed

+42
-43
lines changed

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
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/Outputs.py

Lines changed: 12 additions & 9 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 = []

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/SUTRAOutputs.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import sys
44

55
import geophires_x
6-
import numpy as np
76
import geophires_x.Model as Model
87
from geophires_x.Outputs import Outputs
9-
from .OptionList import EconomicModel
8+
from geophires_x.OptionList import EconomicModel
9+
10+
import numpy as np
1011

1112
NL="\n"
1213

@@ -47,6 +48,7 @@ def PrintOutputs(self, model: Model):
4748
"""
4849
model.logger.info(f'Init {str(__class__)}: {sys._getframe().f_code.co_name}')
4950

51+
self._convert_units(model)
5052

5153
# write results to output file and screen
5254
try:
@@ -83,7 +85,11 @@ def PrintOutputs(self, model: Model):
8385
f.write(f" Fixed Charge Rate (FCR): {model.economics.FCR.value*100.0:10.2f} " + model.economics.FCR.CurrentUnits.value + NL)
8486
elif model.economics.econmodel.value == EconomicModel.STANDARDIZED_LEVELIZED_COST:
8587
f.write(" Economic Model = " + model.economics.econmodel.value.value + NL)
86-
f.write(f" Interest Rate: {model.economics.discountrate.value*100.0:10.2f} " + model.economics.discountrate.CurrentUnits.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")
92+
8793
elif model.economics.econmodel.value == EconomicModel.BICYCLE:
8894
f.write(" Economic Model = " + model.economics.econmodel.value.value + NL)
8995
f.write(f" Accrued financing during construction: {model.economics.inflrateconstruction.value*100:10.2f} " + model.economics.inflrateconstruction.PreferredUnits.value + NL)

tests/examples/SUTRAExample1.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Simulation Metadata
66
----------------------
77
GEOPHIRES Version: 3.6.0
88
Simulation Date: 2024-10-10
9-
Simulation Time: 11:54
10-
Calculation Time: 0.510 sec
9+
Simulation Time: 12:23
10+
Calculation Time: 0.515 sec
1111

1212
***SUMMARY OF RESULTS***
1313

@@ -17,7 +17,7 @@ Simulation Metadata
1717
Number of Production Wells: 1
1818
Number of Injection Wells: 1
1919
Lifetime Average Well Flow Rate: 16.2 kg/sec
20-
Well depth: 600.0 meter
20+
Well depth: 0.6 kilometer
2121

2222

2323
***ECONOMIC PARAMETERS***
@@ -31,11 +31,11 @@ Simulation Metadata
3131

3232
Number of Production Wells: 1
3333
Number of Injection Wells: 1
34-
Well Depth: 600.0 meter
34+
Well Depth: 0.6 kilometer
3535
Pump efficiency: 0.8
3636
Lifetime Average Well Flow Rate: 16.2 kg/sec
37-
Injection well casing ID: 0.198 meter
38-
Production well casing ID: 0.198 meter
37+
Injection well casing ID: 7.800 in
38+
Production well casing ID: 7.800 in
3939

4040

4141
***RESERVOIR SIMULATION RESULTS***

0 commit comments

Comments
 (0)