TNO Intern

Commit 60f69559 authored by Florian Knappers's avatar Florian Knappers
Browse files

Merge branch...

Merge branch '90-add-a-performance-test-to-be-able-to-compare-directly-to-the-java-code-2' into 'python-rewrite-of-java-code'

Resolve "Add a performance test to be able to compare directly to the Java code"

See merge request !109
parents 1c19ca30 44c2a5e4
Loading
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
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
+2 −2
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ import timeit

import numpy as np


from pythermogis.workflow.utc.doublet import DoubletInput, calculate_doublet_performance
from pythermogis.workflow.utc.utc_properties import UTCConfiguration

@@ -73,7 +74,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
@@ -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)
+40 −3
Original line number Diff line number Diff line
from pythermogis.workflow.utc.utc_properties import UTCConfiguration
import timeit

import numpy as np
import pytest

from pythermogis.workflow.utc.doublet import DoubletInput
from pythermogis.workflow.utc.doubletcalc import doubletcalc
import numpy as np
from pythermogis.workflow.utc.utc_properties import UTCConfiguration


def test_doubletcalc():
    props = UTCConfiguration()
@@ -25,3 +30,35 @@ def test_doubletcalc():
    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)

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 = 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)
    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