Skip to content

Commit

Permalink
HIP RA refactor WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolm-dsider committed Jan 4, 2024
1 parent ea5c67d commit 3fb5b63
Show file tree
Hide file tree
Showing 56 changed files with 2,640 additions and 1,611 deletions.
4 changes: 2 additions & 2 deletions src/geophires_x/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file tells git what files to ignore (e.g., you won't see them as
# This file tells git what files to ignore (reservoir_enthalpy.g., you won't see them as
# untracked with "git status"). Add anything to it that can be cleared
# without any worry (e.g., by "git clean -Xdf"), because it can be
# without any worry (reservoir_enthalpy.g., by "git clean -Xdf"), because it can be
# regenerated. Lines beginning with # are comments. You can also ignore
# files on a per-repository basis by modifying the core.excludesfile
# configuration option (see "git help config"). If you need to make git
Expand Down
8 changes: 4 additions & 4 deletions src/geophires_x/AGSEconomics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import numpy as np
import geophires_x.Model as Model
import geophires_x.Economics as Economics
from .Parameter import floatParameter
from .Units import *
from .OptionList import WorkingFluid, EndUseOptions, EconomicModel
from geophires_x.Parameter import floatParameter
from geophires_x.Units import *
from geophires_x.OptionList import WorkingFluid, EndUseOptions, EconomicModel


class AGSEconomics(Economics.Economics):
Expand Down Expand Up @@ -113,7 +113,7 @@ def read_parameters(self, model: Model) -> None:

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

model.logger.info("complete " + str(__class__) + ": " + sys._getframe().f_code.co_name)

Expand Down
22 changes: 11 additions & 11 deletions src/geophires_x/AGSOutputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def PrintOutputs(self, model: Model):
# Deal with converting Units back to PreferredUnits, if required.
# before we write the outputs, we go thru all the parameters for all of the objects and set the values
# back to the units that the user entered the data in
# We do this because the value may be displayed in the output, and we want the user to recognize their value,
# reservoir_producible_electricity do this because the value may be displayed in the output, and we want the user to recognize their value,
# not some converted value
for obj in [model.reserv, model.wellbores, model.surfaceplant, model.economics]:
for key in obj.ParameterDict:
Expand All @@ -40,7 +40,7 @@ def PrintOutputs(self, model: Model):
ConvertUnitsBack(param, model)

# now we need to loop thru all thw output parameters to update their units to whatever units the user has specified.
# i.e., they may have specified that all LENGTH results must be in feet, so we need to convert
# i.reservoir_enthalpy., they may have specified that all LENGTH results must be in feet, so we need to convert
# those from whatever LENGTH unit they are to feet.
# same for all the other classes of units (TEMPERATURE, DENSITY, etc).

Expand All @@ -61,7 +61,7 @@ def PrintOutputs(self, model: Model):
f = scipy.interpolate.interp1d(np.arange(0, len(model.wellbores.PumpingPower.value)),
model.wellbores.PumpingPower.value, fill_value="extrapolate")
model.wellbores.PumpingPower.value = f(np.arange(0, len(model.wellbores.ProducedTemperature.value), 1.0))
if model.surfaceplant.enduseoption.value != EndUseOptions.HEAT:
if model.surfaceplant.enduse_option.value != EndUseOptions.HEAT:
if len(model.wellbores.PumpingPower.value) != len(model.wellbores.ProducedTemperature.value):
f = scipy.interpolate.interp1d(np.arange(0, len(model.wellbores.PumpingPower.value)),
model.wellbores.PumpingPower.value, fill_value="extrapolate")
Expand Down Expand Up @@ -155,14 +155,14 @@ def PrintOutputs(self, model: Model):
f.write(' ******************************\n')
f.write(' * POWER GENERATION PROFILE *\n')
f.write(' ******************************\n')
if model.surfaceplant.enduseoption.value == EndUseOptions.ELECTRICITY: # only electricity
if model.surfaceplant.enduse_option.value == EndUseOptions.ELECTRICITY: # only electricity
f.write(
' YEAR THERMAL GEOFLUID PUMP NET FIRST LAW\n')
f.write(
' DRAWDOWN TEMPERATURE POWER POWER EFFICIENCY\n')
f.write(
" (" + model.wellbores.ProducedTemperature.CurrentUnits.value + ") (" + model.wellbores.PumpingPower.CurrentUnits.value + ") (" + model.surfaceplant.NetElectricityProduced.CurrentUnits.value + ") (%)\n")
for i in range(0, model.surfaceplant.plantlifetime.value):
for i in range(0, model.surfaceplant.plant_lifetime.value):
f.write(
' {0:2.0f} {1:8.4f} {2:8.2f} {3:8.4f} {4:8.4f} {5:8.4f}'.format(
i + 1,
Expand All @@ -172,11 +172,11 @@ def PrintOutputs(self, model: Model):
model.wellbores.PumpingPower.value[i],
model.surfaceplant.NetElectricityProduced.value[i],
model.surfaceplant.FirstLawEfficiency.value[i] * 100) + NL)
elif model.surfaceplant.enduseoption.value == EndUseOptions.HEAT: # only direct-use
elif model.surfaceplant.enduse_option.value == EndUseOptions.HEAT: # only direct-use
f.write(' YEAR THERMAL GEOFLUID PUMP NET\n')
f.write(' DRAWDOWN TEMPERATURE POWER HEAT\n')
f.write(' (deg C) (MW) (MW)\n')
for i in range(0, model.surfaceplant.plantlifetime.value - 1):
for i in range(0, model.surfaceplant.plant_lifetime.value - 1):
f.write(
' {0:2.0f} {1:8.4f} {2:8.2f} {3:8.4f} {4:8.4f}'.format(
i,
Expand All @@ -193,29 +193,29 @@ def PrintOutputs(self, model: Model):
' * HEAT AND/OR ELECTRICITY EXTRACTION AND GENERATION PROFILE *\n')
f.write(
' ***************************************************************\n')
if model.surfaceplant.enduseoption.value == EndUseOptions.ELECTRICITY: # only electricity
if model.surfaceplant.enduse_option.value == EndUseOptions.ELECTRICITY: # only electricity
f.write(
' YEAR ELECTRICITY HEAT RESERVOIR PERCENTAGE OF\n')
f.write(
' PROVIDED EXTRACTED HEAT CONTENT TOTAL HEAT MINED\n')
f.write(
' (GWh/year) (GWh/year) (10^15 J) (%)\n')
for i in range(0, model.surfaceplant.plantlifetime.value):
for i in range(0, model.surfaceplant.plant_lifetime.value):
f.write(
' {0:2.0f} {1:8.1f} {2:8.1f} {3:8.2f} {4:8.2f}'.format(
i + 1,
model.surfaceplant.NetkWhProduced.value[i] / 1E6,
model.surfaceplant.HeatkWhExtracted.value[i] / 1E6,
model.surfaceplant.RemainingReservoirHeatContent.value[i],
(model.reserv.InitialReservoirHeatContent.value - model.surfaceplant.RemainingReservoirHeatContent.value[i]) * 100 / model.reserv.InitialReservoirHeatContent.value) + NL)
elif model.surfaceplant.enduseoption.value == EndUseOptions.HEAT: # only direct-use
elif model.surfaceplant.enduse_option.value == EndUseOptions.HEAT: # only direct-use
f.write(
' YEAR HEAT HEAT RESERVOIR CUM PERCENTAGE OF\n')
f.write(
' PROVIDED EXTRACTED HEAT CONTENT TOTAL HEAT MINED\n')
f.write(
' (GWh/year) (GWh/year) (10^15 J) (%)\n')
for i in range(0, model.surfaceplant.plantlifetime.value - 1):
for i in range(0, model.surfaceplant.plant_lifetime.value - 1):
f.write(
' {0:2.0f} {1:8.1f} {2:8.1f} {3:8.2f} {4:8.2f}'.format(
i + 1,
Expand Down
36 changes: 16 additions & 20 deletions src/geophires_x/AGSSurfacePlant.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import sys
import os
import numpy as np
import geophires_x.Model as Model
from geophires_x.WellBores import *
from .Parameter import floatParameter, OutputParameter
from .Units import *
from .OptionList import WorkingFluid, EndUseOptions
from geophires_x.Parameter import floatParameter, OutputParameter
from geophires_x.Units import *
from geophires_x.OptionList import WorkingFluid, EndUseOptions
from geophires_x.SurfacePlant import SurfacePlant as SurfacePlant

# code from Koenraad
Expand Down Expand Up @@ -322,16 +318,16 @@ def read_parameters(self, model: Model) -> None:
model.logger.info("No parameters read because no content provided")

# inputs we already have - needs to be set at ReadParameter time so values set at the latest possible time
self.End_use = model.surfaceplant.enduseoption.value # same units are GEOPHIRES
self.Pump_efficiency = model.surfaceplant.pumpeff.value # same units are GEOPHIRES
self.Lifetime = int(model.surfaceplant.plantlifetime.value) # same units are GEOPHIRES
self.T0 = model.surfaceplant.Tenv.value + 273.15 # convert Celsius to Kelvin
self.End_use = model.surfaceplant.enduse_option.value # same units are GEOPHIRES
self.Pump_efficiency = model.surfaceplant.pump_efficiency.value # same units are GEOPHIRES
self.Lifetime = int(model.surfaceplant.plant_lifetime.value) # same units are GEOPHIRES
self.T0 = model.surfaceplant.ambient_temperature.value + 273.15 # convert Celsius to Kelvin
self.Discount_rate = model.economics.discountrate.value # same units are GEOPHIRES

# initialize some arrays
self.HeatkWhProduced.value = [0.0] * model.surfaceplant.plantlifetime.value # initialize the array
self.HeatkWhExtracted.value = [0.0] * model.surfaceplant.plantlifetime.value # initialize the array
self.PumpingkWh.value = [0.0] * model.surfaceplant.plantlifetime.value # initialize the array
self.HeatkWhProduced.value = [0.0] * model.surfaceplant.plant_lifetime.value # initialize the array
self.HeatkWhExtracted.value = [0.0] * model.surfaceplant.plant_lifetime.value # initialize the array
self.PumpingkWh.value = [0.0] * model.surfaceplant.plant_lifetime.value # initialize the array

model.logger.info("complete " + str(__class__) + ": " + sys._getframe().f_code.co_name)

Expand Down Expand Up @@ -758,26 +754,26 @@ def Calculate(self, model: Model) -> None:
self.HeatExtracted.value = self.HeatExtracted.value / 1000.0
# useful direct-use heat provided to application [MWth]
self.HeatProduced.value = self.HeatExtracted.value * self.enduseefficiencyfactor.value
for i in range(0, self.plantlifetime.value):
for i in range(0, self.plant_lifetime.value):
self.HeatkWhExtracted.value[i] = np.trapz(self.HeatExtracted.value[
(i * model.economics.timestepsperyear.value):((
i + 1) * model.economics.timestepsperyear.value) + 1],
dx=1. / model.economics.timestepsperyear.value * 365. * 24.) * 1000. * self.utilfactor.value
dx=1. / model.economics.timestepsperyear.value * 365. * 24.) * 1000. * self.utilization_factor.value
self.PumpingkWh.value[i] = np.trapz(model.wellbores.PumpingPower.value[
(i * model.economics.timestepsperyear.value):((
i + 1) * model.economics.timestepsperyear.value) + 1],
dx=1. / model.economics.timestepsperyear.value * 365. * 24.) * 1000. * self.utilfactor.value
dx=1. / model.economics.timestepsperyear.value * 365. * 24.) * 1000. * self.utilization_factor.value

self.RemainingReservoirHeatContent.value = model.reserv.InitialReservoirHeatContent.value - np.cumsum(
self.HeatkWhExtracted.value) * 3600 * 1E3 / 1E15

if self.End_use != EndUseOptions.ELECTRICITY:
self.HeatkWhProduced.value = np.zeros(self.plantlifetime.value)
for i in range(0, self.plantlifetime.value):
self.HeatkWhProduced.value = np.zeros(self.plant_lifetime.value)
for i in range(0, self.plant_lifetime.value):
self.HeatkWhProduced.value[i] = np.trapz(self.HeatProduced.value[
(0 + i * model.economics.timestepsperyear.value):((
i + 1) * model.economics.timestepsperyear.value) + 1],
dx=1. / model.economics.timestepsperyear.value * 365. * 24.) * 1000. * self.utilfactor.value
dx=1. / model.economics.timestepsperyear.value * 365. * 24.) * 1000. * self.utilization_factor.value
else:
# copy some arrays so we have a GEOPHIRES equivalent
self.TotalkWhProduced.value = self.Annual_electricity_production.copy()
Expand Down
Loading

0 comments on commit 3fb5b63

Please sign in to comment.