From 799596ae018c1916d1532debbab57791304e1cf5 Mon Sep 17 00:00:00 2001 From: bretth Date: Tue, 9 Dec 2025 08:58:47 +0100 Subject: [PATCH 1/5] Adding an extra performance test --- src/pythermogis/workflow/utc/doubletcalc.py | 2 +- tests/utc/test_doubletcalc.py | 38 ++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/pythermogis/workflow/utc/doubletcalc.py b/src/pythermogis/workflow/utc/doubletcalc.py index 6e7c9b9..f52b39b 100644 --- a/src/pythermogis/workflow/utc/doubletcalc.py +++ b/src/pythermogis/workflow/utc/doubletcalc.py @@ -96,7 +96,7 @@ def doubletcalc( well_distance=well_distance, cooling_fraction=0.1, yearly_operating_hours=props.load_hours, - pressure_balance_tolerance=1e-1, + pressure_balance_tolerance=1e-2, viscosity_mode=props.viscosity_mode, heat_exchanger_exit_temperature=injection_temp, ) diff --git a/tests/utc/test_doubletcalc.py b/tests/utc/test_doubletcalc.py index 1f0f7a4..13191e4 100644 --- a/tests/utc/test_doubletcalc.py +++ b/tests/utc/test_doubletcalc.py @@ -2,6 +2,10 @@ from pythermogis.workflow.utc.utc_properties import UTCConfiguration from pythermogis.workflow.utc.doublet import DoubletInput from pythermogis.workflow.utc.doubletcalc import doubletcalc import numpy as np +import timeit + +from utils.timer import print_time + def test_doubletcalc(): props = UTCConfiguration() @@ -24,4 +28,36 @@ def test_doubletcalc(): assert np.isclose(results.flowrate, 18.631507399806665, rtol=0.01) assert np.isclose(results.pump_power_required, 5.175418689587975, rtol=0.01) assert np.isclose(results.production_temp, 41.36211427733413, rtol=0.01) - assert np.isclose(results.heat_power_produced[0], 0.027926914290870505, rtol=0.01) \ No newline at end of file + assert np.isclose(results.heat_power_produced[0], 0.027926914290870505, rtol=0.01) + + +def test_doubletcalc_performance(): + props = UTCConfiguration(segment_length=1) + + input_data = DoubletInput( + unknown_input_value=-999.0, + thickness=100.0, + transmissivity=17500.0, + transmissivity_with_ntg=17500.0, + ntg=1.0, + depth=2000, + porosity=0.0, + temperature=50.0, + ) + + nsims = 1000 + # one iteration to warm up the JIT compiled functions + doubletcalc(props, input_data, 600000, 1550, 40) + start = timeit.default_timer() + for _ in range(nsims): + results = doubletcalc(props, input_data, 600000, 1550, 40) + time_elapsed = timeit.default_timer() - start + print(f"{(nsims/time_elapsed):.1f} sims/s") + + rtol=0.25 + assert np.isclose(results.geothermal_powers, 0.027926914290870505, rtol=rtol) + assert np.isclose(results.cop, 5.396068601571214, rtol=rtol) + assert np.isclose(results.flowrate, 18.631507399806665, rtol=rtol) + assert np.isclose(results.pump_power_required, 5.175418689587975, rtol=rtol) + assert np.isclose(results.production_temp, 41.36211427733413, rtol=rtol) + assert np.isclose(results.heat_power_produced[0], 0.027926914290870505, rtol=rtol) \ No newline at end of file -- GitLab From 3d885b8f647e5bd52ae0f474ae0a3f9c66623832 Mon Sep 17 00:00:00 2001 From: bretth Date: Tue, 9 Dec 2025 09:08:47 +0100 Subject: [PATCH 2/5] Adding extra performance tests to compare more directly with the Java code --- tests/utc/test_doublet.py | 2 +- tests/utc/test_doubletcalc.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utc/test_doublet.py b/tests/utc/test_doublet.py index 785a5f4..55eb074 100644 --- a/tests/utc/test_doublet.py +++ b/tests/utc/test_doublet.py @@ -73,7 +73,7 @@ def test_calculate_doublet_performance_approximate(): result = calculate_doublet_performance(props, input_data) start = timeit.default_timer() - n_sims = 500 + n_sims = 1000 for _ in range(n_sims): result = calculate_doublet_performance(props, input_data) time_elapsed = timeit.default_timer() - start diff --git a/tests/utc/test_doubletcalc.py b/tests/utc/test_doubletcalc.py index 13191e4..24154d2 100644 --- a/tests/utc/test_doubletcalc.py +++ b/tests/utc/test_doubletcalc.py @@ -45,7 +45,7 @@ def test_doubletcalc_performance(): temperature=50.0, ) - nsims = 1000 + nsims = 10000 # one iteration to warm up the JIT compiled functions doubletcalc(props, input_data, 600000, 1550, 40) start = timeit.default_timer() -- GitLab From a1077b00f9a339d74592fc8e2f225049db09f4f7 Mon Sep 17 00:00:00 2001 From: bretth Date: Tue, 9 Dec 2025 09:12:49 +0100 Subject: [PATCH 3/5] Adding extra performance tests to compare more directly with the Java code --- src/pythermogis/workflow/utc/doubletcalc.py | 11 +++++++---- tests/utc/test_doublet.py | 2 +- tests/utc/test_doubletcalc.py | 14 ++++++++------ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/pythermogis/workflow/utc/doubletcalc.py b/src/pythermogis/workflow/utc/doubletcalc.py index f52b39b..e57ad1b 100644 --- a/src/pythermogis/workflow/utc/doubletcalc.py +++ b/src/pythermogis/workflow/utc/doubletcalc.py @@ -1,10 +1,13 @@ import math from dataclasses import dataclass -from pythermogis.workflow.utc.utc_properties import UTCConfiguration + +from numba import njit from pydoubletcalc import Aquifer, Doublet, Well, WellPipeSegment -from pythermogis.workflow.utc.water import get_salinity + from pythermogis.workflow.utc.rock import get_geothermal_gradient -from numba import njit +from pythermogis.workflow.utc.utc_properties import UTCConfiguration +from pythermogis.workflow.utc.water import get_salinity + INCH_SI = 0.0254 @dataclass @@ -96,7 +99,7 @@ def doubletcalc( well_distance=well_distance, cooling_fraction=0.1, yearly_operating_hours=props.load_hours, - pressure_balance_tolerance=1e-2, + pressure_balance_tolerance=1e-1, viscosity_mode=props.viscosity_mode, heat_exchanger_exit_temperature=injection_temp, ) diff --git a/tests/utc/test_doublet.py b/tests/utc/test_doublet.py index 55eb074..483a512 100644 --- a/tests/utc/test_doublet.py +++ b/tests/utc/test_doublet.py @@ -48,6 +48,7 @@ def test_calculate_doublet_performance_precise(): assert np.isclose(result.var_opex, -7.510325908660889, rtol=rtol) assert np.isclose(result.fixed_opex, -11.227973937988281, rtol=rtol) +@pytest.skip("This is for timing performance and comparing to the Java code, not needed to run on the pipeline") def test_calculate_doublet_performance_approximate(): # Arrange: instantiate default UTCConfiguration props = UTCConfiguration( @@ -81,7 +82,6 @@ def test_calculate_doublet_performance_approximate(): print(f"{n_sims} simulations took: {time_elapsed:.1f} seconds\n" f"{n_sims/time_elapsed:.1f} simulations per second") - # Assert rtol = 0.01 # accurate to 1% assert np.isclose(result.flow, 227.2757568359375, rtol=rtol) diff --git a/tests/utc/test_doubletcalc.py b/tests/utc/test_doubletcalc.py index 24154d2..9a45bbe 100644 --- a/tests/utc/test_doubletcalc.py +++ b/tests/utc/test_doubletcalc.py @@ -1,10 +1,11 @@ -from pythermogis.workflow.utc.utc_properties import UTCConfiguration -from pythermogis.workflow.utc.doublet import DoubletInput -from pythermogis.workflow.utc.doubletcalc import doubletcalc -import numpy as np import timeit -from utils.timer import print_time +import numpy as np +import pytest + +from pythermogis.workflow.utc.doublet import DoubletInput +from pythermogis.workflow.utc.doubletcalc import doubletcalc +from pythermogis.workflow.utc.utc_properties import UTCConfiguration def test_doubletcalc(): @@ -30,7 +31,7 @@ def test_doubletcalc(): assert np.isclose(results.production_temp, 41.36211427733413, rtol=0.01) assert np.isclose(results.heat_power_produced[0], 0.027926914290870505, rtol=0.01) - +@pytest.skip("This is for timing performance and comparing to the Java code, not needed to run on the pipeline") def test_doubletcalc_performance(): props = UTCConfiguration(segment_length=1) @@ -48,6 +49,7 @@ def test_doubletcalc_performance(): nsims = 10000 # one iteration to warm up the JIT compiled functions doubletcalc(props, input_data, 600000, 1550, 40) + start = timeit.default_timer() for _ in range(nsims): results = doubletcalc(props, input_data, 600000, 1550, 40) -- GitLab From 6685b4f2e20ea3287d43196358a76258f97f4167 Mon Sep 17 00:00:00 2001 From: bretth Date: Tue, 9 Dec 2025 09:22:05 +0100 Subject: [PATCH 4/5] Adding extra performance tests to compare more directly with the Java code --- tests/utc/test_doublet.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/utc/test_doublet.py b/tests/utc/test_doublet.py index 483a512..b48f67a 100644 --- a/tests/utc/test_doublet.py +++ b/tests/utc/test_doublet.py @@ -2,6 +2,8 @@ import timeit import numpy as np +import pytest + from pythermogis.workflow.utc.doublet import DoubletInput, calculate_doublet_performance from pythermogis.workflow.utc.utc_properties import UTCConfiguration @@ -48,7 +50,6 @@ def test_calculate_doublet_performance_precise(): assert np.isclose(result.var_opex, -7.510325908660889, rtol=rtol) assert np.isclose(result.fixed_opex, -11.227973937988281, rtol=rtol) -@pytest.skip("This is for timing performance and comparing to the Java code, not needed to run on the pipeline") def test_calculate_doublet_performance_approximate(): # Arrange: instantiate default UTCConfiguration props = UTCConfiguration( -- GitLab From 44c2a5e44b3839c0837024129ea39851746613fb Mon Sep 17 00:00:00 2001 From: bretth Date: Tue, 9 Dec 2025 09:26:11 +0100 Subject: [PATCH 5/5] Ensuring all the tests pass --- tests/utc/test_doublet.py | 1 - tests/utc/test_doubletcalc.py | 1 - 2 files changed, 2 deletions(-) diff --git a/tests/utc/test_doublet.py b/tests/utc/test_doublet.py index b48f67a..eb053e6 100644 --- a/tests/utc/test_doublet.py +++ b/tests/utc/test_doublet.py @@ -2,7 +2,6 @@ import timeit import numpy as np -import pytest from pythermogis.workflow.utc.doublet import DoubletInput, calculate_doublet_performance from pythermogis.workflow.utc.utc_properties import UTCConfiguration diff --git a/tests/utc/test_doubletcalc.py b/tests/utc/test_doubletcalc.py index 9a45bbe..e49d5d1 100644 --- a/tests/utc/test_doubletcalc.py +++ b/tests/utc/test_doubletcalc.py @@ -31,7 +31,6 @@ def test_doubletcalc(): assert np.isclose(results.production_temp, 41.36211427733413, rtol=0.01) assert np.isclose(results.heat_power_produced[0], 0.027926914290870505, rtol=0.01) -@pytest.skip("This is for timing performance and comparing to the Java code, not needed to run on the pipeline") def test_doubletcalc_performance(): props = UTCConfiguration(segment_length=1) -- GitLab