TNO Intern

Commit 49f7c2c7 authored by Hen Brett's avatar Hen Brett 🐔
Browse files

Simplifying code adjusting tests

parent d3103ce9
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
from pythermogis.workflow.utc.flow import calculate_volumetric_flow
from workflow.utc.doublet_utils import calc_lifetime


def calculate_cooling_temperature(
+2 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ from pythermogis.workflow.utc.doublet_utils import calculate_injection_temp_with
from pythermogis.workflow.utc.pressure import calculate_max_pressure, optimize_pressure
from pythermogis.workflow.utc.cooling_temp import calculate_cooling_temperature
from pythermogis.workflow.utc.well_distance import optimize_well_distance, \
    optimize_well_distance2
    optimize_well_distance
from utils.timer import print_time

EUR_PER_CT_PER_KWH = 0.36
@@ -103,7 +103,7 @@ def calculate_doublet_performance(props: UTCConfiguration, input: DoubletInput,
    timer = print_time(timer, "cooling temperature: ", verbose=verbose)

    if props.optim_well_dist:
        well_distance = optimize_well_distance2(
        well_distance = optimize_well_distance(
            props,
            input,
            drawdown_pressure,
+5 −5
Original line number Diff line number Diff line
@@ -53,24 +53,24 @@ def calculate_volumetric_flow(
    else:
        heat_exchanger_efficiency = props.heat_exchanger_efficiency

    heat_power_per_doublet = max(
        1e-6, d1d_results.geothermal_powers * heat_exchanger_efficiency
    )
    heat_power_produced = np.clip(
        np.array(d1d_results.heat_power_produced) * heat_exchanger_efficiency,
        1e-6,
        None,
    )

    # Calculate cop
    heat_power_per_doublet = max(
        1e-6, d1d_results.geothermal_powers * heat_exchanger_efficiency
    )
    power_consumption = (
        (heat_power_per_doublet / heat_exchanger_efficiency) / d1d_results.cop
    ) + (heat_power_per_doublet * props.heat_exchanger_parasitic)

    if props.use_orc:
        heat_power_per_doublet -= power_consumption

    cop = heat_power_per_doublet / power_consumption

    # Calculate heat pump performance
    if props.use_heat_pump:
        hp_results = calculate_heat_pump_performance(
            props,
+20 −4
Original line number Diff line number Diff line
import numpy as np
from scipy.optimize import brentq, brenth
from scipy.optimize import brenth

from pythermogis.workflow.utc.doublet_utils import calc_lifetime
from pythermogis.workflow.utc.flow import calculate_volumetric_flow


def optimize_well_distance(
def optimize_well_distance_original(
    props,
    input,
    drawdown_pressure: float,
    injection_temp: float,
) -> float:
    """
    The original well distance optimization algorithm. This is kept for testing purposes
    but has been replaced with the scipy implementation of the brenth algorithm which
    does the same thing more accurately.

    Parameters
    ----------
    props
    input
    drawdown_pressure
    injection_temp

    Returns
    -------

    """

    dist_min = props.optim_dist_well_dist_min
    dist_max = props.optim_dist_well_dist_max
    well_distance = np.mean([dist_min, dist_max])
@@ -18,7 +35,6 @@ def optimize_well_distance(
    for iter_count in range(1000):
        if abs(dist_max - dist_min) <= 10.0:
            return well_distance
        print(iter_count)
        well_distance = np.mean([dist_min, dist_max])

        # --- Compute flow for this distance ---
@@ -87,7 +103,7 @@ def f1(
    ) - props.optim_dist_lifetime


def optimize_well_distance2(
def optimize_well_distance(
    props,
    input,
    drawdown_pressure: float,
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ def test_calculate_doublet_performance_precise():


    # Assert
    rtol = 0.002 # accurate to 0.2%
    rtol = 0.005 # accurate to 0.5%
    assert np.isclose(result.flow, 227.2757568359375, rtol=rtol)
    assert np.isclose(result.pres, 60, rtol=rtol)
    assert np.isclose(result.utc, 6.616096470753937, rtol=rtol)
Loading