TNO Intern

Commit d3103ce9 authored by Hen Brett's avatar Hen Brett 🐔
Browse files

Simplifying code

parent 3ab160d8
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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_distance(
        well_distance = optimize_well_distance2(
            props,
            input,
            drawdown_pressure,
+28 −32
Original line number Diff line number Diff line
@@ -31,49 +31,41 @@ def calculate_volumetric_flow(
):
    for step in [0, 1e5, -1e5, 2e5, -2e5, 3e5, -3e5]:
        d1d_results = doubletcalc(
            props, input_data, original_pressure + step, well_distance, injection_temp
            props,
            input_data,
            original_pressure + step,
            well_distance,
            injection_temp
        )
        if d1d_results is not None:
            break

    # if varying pressure didnt work return None
    # if no valid output results return None
    if d1d_results is None:
        return None

    geothermal_powers = d1d_results.geothermal_powers
    cop = d1d_results.cop
    flowrate = d1d_results.flowrate
    pump_power_required = d1d_results.pump_power_required
    production_temp = d1d_results.production_temp
    heat_power_produced = np.array(d1d_results.heat_power_produced)

    if props.use_orc:
        he2 = get_orc_efficiency(
            production_temp,
        heat_exchanger_efficiency = get_orc_efficiency(
            d1d_results.production_temp,
            props.heat_exchanger_basetemp,
            props.heat_exchanger_efficiency,
        )
    else:
        he2 = props.heat_exchanger_efficiency

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

    ignore_subsurface = (
        props.well_cost_scaling
        + props.well_cost_const
        + props.well_cost_z
        + props.well_cost_z2
    ) < 1e-3
        heat_exchanger_efficiency = props.heat_exchanger_efficiency

    if ignore_subsurface:
        cop = 1e4
        pump_power_required = 0.0

    power_consumption = ((heat_power_per_doublet / he2) / cop) + (
        heat_power_per_doublet * props.heat_exchanger_parasitic
    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,
    )

    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

@@ -81,7 +73,11 @@ def calculate_volumetric_flow(

    if props.use_heat_pump:
        hp_results = calculate_heat_pump_performance(
            props, input_data, production_temp, injection_temp, flowrate
            props,
            input_data,
            d1d_results.production_temp,
            injection_temp,
            d1d_results.flowrate,
        )
        hp_cop = hp_results.hp_cop
        hp_added_power = hp_results.hp_added_power
@@ -97,8 +93,8 @@ def calculate_volumetric_flow(
        hp_elec_consumption,
        heat_power_per_doublet,
        cop,
        flowrate,
        pump_power_required,
        production_temp,
        d1d_results.flowrate,
        d1d_results.pump_power_required,
        d1d_results.production_temp,
        heat_power_produced,
    )
 No newline at end of file
+2 −6
Original line number Diff line number Diff line
import numpy as np
from scipy.optimize import minimize_scalar
from scipy.optimize import brentq, brenth

from pythermogis.workflow.utc.doublet_utils import calc_lifetime
@@ -17,10 +16,9 @@ def optimize_well_distance(
    well_distance = np.mean([dist_min, dist_max])

    for iter_count in range(1000):
        print(iter_count)
        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 ---
@@ -64,7 +62,6 @@ def optimize_well_distance(
def f1(
    well_distance, props, input, drawdown_pressure: float, injection_temp: float
) -> float:
    print("calling f1")
    # --- Compute flow for this distance ---
    results = calculate_volumetric_flow(
        props=props,
@@ -96,10 +93,9 @@ def optimize_well_distance2(
    drawdown_pressure: float,
    injection_temp: float,
) -> float:

    # find the well distance between the min and max which comes closest to the optimal
    # doublet lifetime, as defined in props.
    well_distance = brentq(
    well_distance = brenth(
        f1,
        props.optim_dist_well_dist_min,
        props.optim_dist_well_dist_max,
+2 −2
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ def test_calculate_doublet_performance_precise():


    # Assert
    rtol = 0.005 # accurate to 0.2%
    rtol = 0.002 # accurate to 0.2%
    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)
@@ -81,7 +81,7 @@ def test_calculate_doublet_performance_approximate():


    # Assert
    rtol = 0.005 # accurate to 0.5%
    rtol = 0.01 # accurate to 1%
    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)
+1 −2
Original line number Diff line number Diff line
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

def test_doubletcalc():
@@ -11,7 +10,7 @@ def test_doubletcalc():
        unknown_input_value=-999.0,
        thickness=100.0,
        transmissivity=17500.0,
        transmissivity_with_ntg=0.0,
        transmissivity_with_ntg=17500.0,
        ntg=1.0,
        depth=2000,
        porosity=0.0,
Loading