Skip to content

Commit 3385832

Browse files
Merge remote-tracking branch 'origin/main'
2 parents 23920bd + 5af5bbd commit 3385832

File tree

3 files changed

+66
-15
lines changed

3 files changed

+66
-15
lines changed

src/geophires_x/AGSWellBores.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -716,28 +716,24 @@ def verify(self, model: Model) -> int:
716716
errors = []
717717

718718
def on_invalid_parameter_value(err_msg):
719-
errors.append(err_msg)
720-
print(err_msg)
721-
model.logger.fatal(err_msg)
719+
s = f'Error: CLGS model database imposes additional range restrictions: {err_msg}. Simulation terminated.'
720+
errors.append(s)
721+
print(s)
722+
model.logger.fatal(s)
722723
self.error = 1
723724

724725
if self.Nonvertical_length.value < 1000 or self.Nonvertical_length.value > 20000:
725-
on_invalid_parameter_value(
726-
'Error: CLGS model database imposes additional range restrictions: Nonvertical length must be '
727-
'between 1,000 and 20,000 m. Simulation terminated.'
728-
)
726+
on_invalid_parameter_value('Nonvertical length must be between 1,000 and 20,000 m')
729727

730728
if self.Tinj.value < 30.0 or self.Tinj.value > 60.0:
731-
on_invalid_parameter_value(
732-
'Error: CLGS model database imposes additional range restrictions: Injection temperature '
733-
'must be between 30 and 60 C. Simulation terminated.'
734-
)
729+
on_invalid_parameter_value('Injection temperature must be between 30 and 60 C')
735730

736731
if self.krock < 1.5 or self.krock > 4.5:
737-
on_invalid_parameter_value(
738-
'Error: CLGS model database imposes additional range restrictions: '
739-
'Rock thermal conductivity must be between 1.5 and 4.5 W/m/K. Simulation terminated.'
740-
)
732+
on_invalid_parameter_value('Rock thermal conductivity must be between 1.5 and 4.5 W/m/K')
733+
734+
if model.reserv.gradient.value[0] < 0.03 or model.reserv.gradient.value[0] > 0.07:
735+
on_invalid_parameter_value(f'{model.reserv.gradient1.Name} must be between '
736+
f'30 and 70 {TemperatureGradientUnit.DEGREESCPERKM.value}')
741737

742738
model.logger.info(f'complete {str(__class__)}: {sys._getframe().f_code.co_name}')
743739

@@ -816,6 +812,12 @@ def Calculate(self, model: Model) -> None:
816812
"""
817813
model.logger.info(f'Init {__class__!s}: {sys._getframe().f_code.co_name}')
818814

815+
if model.reserv.Trock.value > model.reserv.Tmax.value:
816+
s = f'{model.reserv.Trock.Name} ({model.reserv.Trock.value}) exceeds ' \
817+
f'{model.reserv.Tmax.Name} ({model.reserv.Tmax.value})'
818+
model.logger.critical(s)
819+
raise ValueError(s)
820+
819821
self.Tini = model.reserv.Trock.value # initialize the temperature to be the initial temperature of the reservoir
820822
if self.Tini > 375.0 or self.numnonverticalsections.value > 1:
821823
# must be a multilateral setup or too hot for CLGS, so must try to use wanju code.

src/geophires_x/SurfacePlant.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ def electricity_heat_production(self, enduse_option: EndUseOptions, availability
152152

153153
# next do the electricity produced - the same for all, except enduse=5, where it is recalculated
154154
ElectricityProduced = availability * etau * nprod * prodwellflowrate
155+
if ElectricityProduced.max() < 0:
156+
# TODO: make message more informative (possibly by hinting that maximum temperature may be too high)
157+
raise RuntimeError('Electricity production calculated as negative.')
155158

156159
if enduse_option == EndUseOptions.ELECTRICITY:
157160
# pure electricity

tests/test_geophires_x.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,3 +867,49 @@ def test_heat_pump_lcoh_bicycle(self):
867867

868868
lcoh = result.result['SUMMARY OF RESULTS']['Direct-Use heat breakeven price (LCOH)']['value']
869869
self.assertTrue(10 < lcoh < 20) # Sanity-check that value is non-zero and broadly within the expected range.
870+
871+
def test_ags_temperature_limitations(self):
872+
client = GeophiresXClient()
873+
874+
with self.assertRaises(RuntimeError) as e:
875+
params = GeophiresInputParameters(
876+
{
877+
'Is AGS': True,
878+
'Well Geometry Configuration': 1,
879+
'Injection Temperature': 60,
880+
'Gradient 1': 60,
881+
'Reservoir Depth': 8,
882+
'Cylindrical Reservoir Input Depth': 8,
883+
'Economic Model': 3,
884+
}
885+
)
886+
client.get_geophires_result(params)
887+
self.assertIn(' exceeds ', str(e.exception))
888+
889+
with self.assertRaises(RuntimeError) as e:
890+
params = GeophiresInputParameters(
891+
{
892+
'Is AGS': True,
893+
'Closed-loop Configuration': 2,
894+
'Gradient 1': 25,
895+
'Reservoir Depth': 3,
896+
'Injection Temperature': 60,
897+
'Economic Model': 4,
898+
}
899+
)
900+
client.get_geophires_result(params)
901+
self.assertIn('failed to validate CLGS input value', str(e.exception))
902+
903+
def test_negative_electricity_production_raises_error(self):
904+
client = GeophiresXClient()
905+
with self.assertRaises(RuntimeError) as e:
906+
params = GeophiresInputParameters(
907+
{
908+
'Reservoir Depth': 5,
909+
'Gradient 1': 112,
910+
'Power Plant Type': 2,
911+
'Maximum Temperature': 600,
912+
}
913+
)
914+
client.get_geophires_result(params)
915+
self.assertIn('Electricity production calculated as negative', str(e.exception))

0 commit comments

Comments
 (0)