Skip to content

Commit

Permalink
Merge pull request #5 from softwareengineerprogrammer/main
Browse files Browse the repository at this point in the history
Improve state of unit tests
  • Loading branch information
softwareengineerprogrammer authored Oct 4, 2023
2 parents 55f3052 + 9e29bd3 commit 88177cc
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
fail-fast: true
matrix:
include:
- name: 'check'
Expand Down
31 changes: 19 additions & 12 deletions src/geophires_x/AGSOutputs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import datetime
import time
import sys
import traceback

from .Parameter import ConvertUnitsBack, ConvertOutputUnits
from .OptionList import EndUseOptions, EconomicModel
from .Units import *
Expand Down Expand Up @@ -42,18 +44,22 @@ def PrintOutputs(self, model: Model):
if model.wellbores.IsAGS: # do a classical output display
import scipy
# Need to do some interpolating to get the arrays to be the right size for output
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")
model.wellbores.PumpingPower.value = f(np.arange(0, len(model.wellbores.ProducedTemperature.value), 1.0))
if len(model.surfaceplant.NetElectricityProduced.value) != len(model.wellbores.ProducedTemperature.value):
f = scipy.interpolate.interp1d(np.arange(0, len(model.surfaceplant.NetElectricityProduced.value)),
model.surfaceplant.NetElectricityProduced.value, fill_value="extrapolate")
model.surfaceplant.NetElectricityProduced.value = f(np.arange(0, len(model.wellbores.ProducedTemperature.value), 1.0))
if len(model.surfaceplant.FirstLawEfficiency.value) != len(model.wellbores.ProducedTemperature.value):
f = scipy.interpolate.interp1d(np.arange(0, len(model.surfaceplant.FirstLawEfficiency.value)),
model.surfaceplant.FirstLawEfficiency.value, fill_value="extrapolate")
model.surfaceplant.FirstLawEfficiency.value = f(np.arange(0, len(model.wellbores.ProducedTemperature.value), 1.0))

# FIXME TODO - determine if ignore errstate is appropriate here. Without ignore, GitHub Actions unit
# tests fail in a way that appears to be specific to their runners (processor architecture, maybe)
with np.errstate(all='ignore'):
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")
model.wellbores.PumpingPower.value = f(np.arange(0, len(model.wellbores.ProducedTemperature.value), 1.0))
if len(model.surfaceplant.NetElectricityProduced.value) != len(model.wellbores.ProducedTemperature.value):
f = scipy.interpolate.interp1d(np.arange(0, len(model.surfaceplant.NetElectricityProduced.value)),
model.surfaceplant.NetElectricityProduced.value, fill_value="extrapolate")
model.surfaceplant.NetElectricityProduced.value = f(np.arange(0, len(model.wellbores.ProducedTemperature.value), 1.0))
if len(model.surfaceplant.FirstLawEfficiency.value) != len(model.wellbores.ProducedTemperature.value):
f = scipy.interpolate.interp1d(np.arange(0, len(model.surfaceplant.FirstLawEfficiency.value)),
model.surfaceplant.FirstLawEfficiency.value, fill_value="extrapolate")
model.surfaceplant.FirstLawEfficiency.value = f(np.arange(0, len(model.wellbores.ProducedTemperature.value), 1.0))

if not model.economics.econmodel.value == EconomicModel.CLGS:
super().PrintOutputs(model)
Expand Down Expand Up @@ -214,6 +220,7 @@ def PrintOutputs(self, model: Model):
model.logger.critical(str(ex))
model.logger.critical(
"Error: GEOPHIRES Failed to write the output file. Exiting....Line %i" % tb.tb_lineno)
traceback.print_exc()
sys.exit()

model.logger.info("Complete " + str(__class__) + ": " + sys._getframe().f_code.co_name)
25 changes: 20 additions & 5 deletions src/geophires_x/AGSWellBores.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,23 @@


class data:
def __init__(self, fname, case, fluid):
_cache = {}

@staticmethod
def _get_cache_key(fname, case, fluid):
return f'{fname}/{case},{fluid}'

@staticmethod
def get(fname, case, fluid):
cache_key = data._get_cache_key(fname,case,fluid)
if cache_key in data._cache:
return data._cache[cache_key]
else:
d = data(fname,case,fluid)
data._cache[cache_key] = d
return d

def __init__(self, fname, case, fluid):
self.fluid = fluid
self.case = case

Expand Down Expand Up @@ -595,9 +610,9 @@ def initialize(self, model: Model) -> None:

if self.Fluid.value == WorkingFluid.WATER:
if self.Configuration.value == Configuration.ULOOP:
self.u_H2O = data(self.filename, Configuration.ULOOP.value, "H2O")
self.u_H2O = data.get(self.filename, Configuration.ULOOP.value, "H2O")
elif self.Configuration.value == Configuration.COAXIAL:
self.u_H2O = data(self.filename, Configuration.COAXIAL.value, "H2O")
self.u_H2O = data.get(self.filename, Configuration.COAXIAL.value, "H2O")
self.timearray = self.u_H2O.time
self.FlowRateVector = self.u_H2O.mdot # length of 26
self.HorizontalLengthVector = self.u_H2O.L2 # length of 20
Expand All @@ -609,9 +624,9 @@ def initialize(self, model: Model) -> None:
self.Fluid_name = 'Water'
elif self.Fluid.value == WorkingFluid.SCO2:
if self.Configuration.value == Configuration.ULOOP:
self.u_sCO2 = data(self.filename, Configuration.ULOOP.value, "sCO2")
self.u_sCO2 = data.get(self.filename, Configuration.ULOOP.value, "sCO2")
elif self.Configuration.value == Configuration.COAXIAL:
self.u_sCO2 = data(self.filename, Configuration.COAXIAL.value, "sCO2")
self.u_sCO2 = data.get(self.filename, Configuration.COAXIAL.value, "sCO2")
self.timearray = self.u_sCO2.time
self.FlowRateVector = self.u_sCO2.mdot # length of 26
self.HorizontalLengthVector = self.u_sCO2.L2 # length of 20
Expand Down

0 comments on commit 88177cc

Please sign in to comment.