Skip to content

Commit

Permalink
Output total carbon emissions in kilotons for example_SHR-2
Browse files Browse the repository at this point in the history
  • Loading branch information
softwareengineerprogrammer committed Jun 27, 2024
1 parent e3d3da1 commit b7a6d86
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/geophires_x/Outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,8 @@ def PrintOutputs(self, model: Model):

if model.economics.DoCarbonCalculations.value:
summary.append(OutputTableItem('Total Avoided Carbon Emissions', '{0:10.2f}'.format(
model.economics.CarbonThatWouldHaveBeenProducedTotal.quantity().to('tonne').magnitude), 'tonne'))
model.economics.CarbonThatWouldHaveBeenProducedTotal.value),
model.economics.CarbonThatWouldHaveBeenProducedTotal.CurrentUnits.value))

if model.economics.econmodel.value == EconomicModel.FCR:
economic_parameters.append(OutputTableItem('Economic Model', model.economics.econmodel.value.value))
Expand Down Expand Up @@ -1605,7 +1606,8 @@ def PrintOutputs(self, model: Model):
f.write(f' Segment {str(i):s} Thickness: {model.reserv.layerthickness.value[i-1]:10.0f} ' + model.reserv.layerthickness.CurrentUnits.value + NL)
f.write(f' Segment {str(i+1):s} Geothermal gradient: {model.reserv.gradient.value[i]:10.4g} ' + model.reserv.gradient.CurrentUnits.value + NL)
if model.economics.DoCarbonCalculations.value:
f.write(f' Total Avoided Carbon Emissions: {model.economics.CarbonThatWouldHaveBeenProducedTotal.quantity().to("tonne").magnitude:10.2f} tonne' + NL)
f.write(f' Total Avoided Carbon Emissions: {model.economics.CarbonThatWouldHaveBeenProducedTotal.value:10.2f} '
f'{model.economics.CarbonThatWouldHaveBeenProducedTotal.CurrentUnits.value}\n')

f.write(NL)
f.write(NL)
Expand Down
10 changes: 10 additions & 0 deletions src/geophires_x/Parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,16 @@ def ConvertOutputUnits(oparam: OutputParameter, newUnit: Units, model):
:type model: :class:`~geophires_x.Model.Model`
:return: None
"""

try:
oparam.value = _ureg.Quantity(oparam.value, oparam.CurrentUnits.value).to(newUnit.value).magnitude
oparam.CurrentUnits = newUnit
return
except AttributeError as ae:
# TODO refactor to check for/convert currency instead of relying on try/except once currency conversion is
# re-enabled - https://github.com/NREL/GEOPHIRES-X/issues/236?title=Currency+conversions+disabled
model.logger.warning(f'Failed to convert units with pint, falling back to legacy conversion code ({ae})')

if isinstance(oparam.value, str):
return # strings have no units
elif isinstance(oparam.value, bool):
Expand Down
1 change: 1 addition & 0 deletions src/geophires_x/Units.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ class MassUnit(str, Enum):
KILOGRAM = "kilogram"
TONNE = "tonne"
TON = "ton"
KILOTON = "kiloton"
LB = "pound"
OZ = "ounce"

Expand Down
9 changes: 5 additions & 4 deletions tests/examples/example_SHR-2.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

Simulation Metadata
----------------------
GEOPHIRES Version: 3.4.34
Simulation Date: 2024-06-19
Simulation Time: 07:44
Calculation Time: 0.593 sec
GEOPHIRES Version: 3.4.41
Simulation Date: 2024-06-27
Simulation Time: 12:21
Calculation Time: 0.602 sec

***SUMMARY OF RESULTS***

Expand All @@ -19,6 +19,7 @@ Simulation Metadata
Flowrate per production well: 55.0 kg/sec
Well depth (or total length, if not vertical): 7.5 kilometer
Geothermal gradient: 50 degC/km
Total Avoided Carbon Emissions: 3403.38 kiloton


***ECONOMIC PARAMETERS***
Expand Down
2 changes: 2 additions & 0 deletions tests/examples/example_SHR-2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ Electricity Escalation Rate Per Year, 0.012
Annual License Etc, 0
Flat License Etc, 0
Tax Relief Per Year, 2.212
Do Carbon Price Calculations, true
Units:Total Saved Carbon Production, kiloton,

0 comments on commit b7a6d86

Please sign in to comment.