From c5465d0570dc53d47f1f049407fb066c407c6246 Mon Sep 17 00:00:00 2001 From: wouterpeere Date: Mon, 20 Jan 2025 11:11:33 +0100 Subject: [PATCH] First implementation of the tilt property --- GHEtool/Borefield.py | 10 +++++++--- GHEtool/VariableClasses/CustomGFunction.py | 7 ++++--- GHEtool/test/unit-tests/test_main_class.py | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/GHEtool/Borefield.py b/GHEtool/Borefield.py index 10cff41b..37dbb92d 100644 --- a/GHEtool/Borefield.py +++ b/GHEtool/Borefield.py @@ -4,6 +4,7 @@ from __future__ import annotations import copy +import math import warnings from math import pi from typing import Tuple, Union @@ -133,6 +134,7 @@ def __init__( self.Tf_min: float = 0.0 # minimum temperature of the fluid # initiale borehole + self.avg_tilt: float = 0. self.borehole = Borehole() # initiate different sizing @@ -204,7 +206,7 @@ def depth(self) -> float: def calculate_depth(self, borehole_length: float, buried_depth: float) -> float: """ - This function calculates the depth of the borehole. + This function calculates the depth of the borehole given the average tilt of the borefield. Parameters ---------- @@ -218,8 +220,9 @@ def calculate_depth(self, borehole_length: float, buried_depth: float) -> float: float Depth of the borehole [m] """ - # TODO take into account tilt - return borehole_length + buried_depth + if np.isclose(self.avg_tilt, 0): + return borehole_length + buried_depth + return np.average([bor.H * math.cos(bor.tilt) for bor in self.borefield]) + buried_depth @property def H(self) -> float: @@ -458,6 +461,7 @@ def borefield(self, borefield: list[gt.boreholes.Borehole] = None) -> None: self.D = np.average([bor.D for bor in borefield]) self.r_b = np.average([bor.r_b for bor in borefield]) self._H = np.average([bor.H for bor in borefield]) + self.avg_tilt = np.average([bor.tilt for bor in borefield]) self.gfunction_calculation_object.remove_previous_data() unequal_length = np.any([bor.H != borefield[0].H for bor in borefield]) if unequal_length: diff --git a/GHEtool/VariableClasses/CustomGFunction.py b/GHEtool/VariableClasses/CustomGFunction.py index dfafd2c3..cb7076c7 100644 --- a/GHEtool/VariableClasses/CustomGFunction.py +++ b/GHEtool/VariableClasses/CustomGFunction.py @@ -2,6 +2,7 @@ This file contains both the CustomGFunction class and all the relevant information w.r.t. custom gfunctions. """ import copy +import math import pickle import warnings from typing import List, Union @@ -225,10 +226,10 @@ def create_custom_dataset(self, borefield: List[gt.boreholes.Borehole], alpha: U # calculate borehole buried depth D = np.average([bor.D for bor in borefield]) - # TODO correct for tilt + tilt = np.average([bor.tilt for bor in borefield]) + depth = borehole_length * math.cos(tilt) + D gfunc_uniform_T = gt.gfunction.gFunction(borefield, - alpha if isinstance(alpha, float) else alpha(borehole_length + D, - D), + alpha if isinstance(alpha, float) else alpha(depth, D), self.time_array, options=self.options, method=self.options["method"]) diff --git a/GHEtool/test/unit-tests/test_main_class.py b/GHEtool/test/unit-tests/test_main_class.py index 993f8386..b239dcf3 100644 --- a/GHEtool/test/unit-tests/test_main_class.py +++ b/GHEtool/test/unit-tests/test_main_class.py @@ -1,5 +1,6 @@ # noinspection PyPackageRequirements import copy +import math import matplotlib.pyplot as plt import numpy as np @@ -70,6 +71,7 @@ def test_nb_of_boreholes(): borefield.set_ground_parameters(data_ground_flux) assert borefield.number_of_boreholes == 120 borefield.set_borefield(gt.boreholes.rectangle_field(5, 5, 6, 6, 110, 0.1, 0.07)) + assert np.isclose(borefield.avg_tilt, 0) assert np.isclose(borefield.H, 110) assert np.isclose(borefield.r_b, 0.07) assert np.isclose(borefield.D, 0.1) @@ -78,11 +80,13 @@ def test_nb_of_boreholes(): assert np.any(borefield.gfunction_calculation_object.borehole_length_array) borefield.borefield = gt.boreholes.rectangle_field(6, 5, 6, 6, 100, 1, 0.075) assert not np.any(borefield.gfunction_calculation_object.borehole_length_array) + assert np.isclose(borefield.avg_tilt, 0) assert np.isclose(borefield.H, 100) assert np.isclose(borefield.r_b, 0.075) assert np.isclose(borefield.D, 1) borefield.gfunction(5000, 110) assert np.any(borefield.gfunction_calculation_object.borehole_length_array) + assert np.isclose(borefield.avg_tilt, 0) assert borefield.number_of_boreholes == 30 borefield.borefield = None assert not np.any(borefield.gfunction_calculation_object.borehole_length_array) @@ -91,6 +95,7 @@ def test_nb_of_boreholes(): borefield.borefield = gt.boreholes.rectangle_field(6, 5, 6, 6, 100, 1, 0.075) borefield.gfunction(5000, 110) assert np.any(borefield.gfunction_calculation_object.borehole_length_array) + assert np.isclose(borefield.avg_tilt, 0) borefield.set_borefield(None) assert not np.any(borefield.gfunction_calculation_object.borehole_length_array) assert borefield.number_of_boreholes == 0 @@ -105,6 +110,17 @@ def test_set_borefield(): assert borefield.H == 125 +def test_tilt(): + borefield = Borefield() + borefield.set_borefield([ + gt.boreholes.Borehole(100, 4, 0.075, 0, 0), + gt.boreholes.Borehole(150, 4, 0.075, 10, 0, tilt=math.pi / 9) + ]) + assert borefield.H == 125 + assert np.isclose(borefield.avg_tilt, math.pi / 18) + assert np.isclose(borefield.depth, 4 + (100 + 150 * math.cos(math.pi / 9)) / 2) + + def test_gfunction_with_irregular_borehole_depth(): borefield = Borefield() borefield.ground_data = ground_data_constant