Skip to content

Commit 308f66a

Browse files
authored
Merge pull request #405 from wouterpeere/issue403-get_rb-is-slow-for-variable-fluid-properties
Issue403 get rb is slow for variable fluid properties
2 parents f22b8f9 + 01b9071 commit 308f66a

File tree

9 files changed

+370
-18
lines changed

9 files changed

+370
-18
lines changed

GHEtool/Borefield.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from scipy.signal import convolve
1717

1818
from GHEtool.VariableClasses import FluidData, Borehole, GroundConstantTemperature, ResultsMonthly, ResultsHourly, \
19-
TemperatureDependentFluidData
19+
TemperatureDependentFluidData, SCOP, SEER
2020
from GHEtool.VariableClasses import CustomGFunction, load_custom_gfunction, GFunction, CalculationSetup, Cluster, \
2121
EERCombined
2222
from GHEtool.VariableClasses.LoadData import *
@@ -1545,9 +1545,9 @@ def _size_based_on_temperature_profile(self, quadrant: int, hourly: bool = False
15451545
self.H = self.H * .5 + H_prev * 0.5
15461546
limit = self.Tf_min if quadrant in (3, 4, 20) else self.Tf_max
15471547
if hourly:
1548-
self._calculate_temperature_profile(self.H, hourly=True, fluid_temperature=limit)
1548+
self._calculate_temperature_profile(self.H, hourly=True, sizing=True)
15491549
else:
1550-
self._calculate_temperature_profile(self.H, hourly=False, fluid_temperature=limit)
1550+
self._calculate_temperature_profile(self.H, hourly=False, sizing=True)
15511551
H_prev = self.H
15521552
if not deep_sizing:
15531553
if quadrant == 1:
@@ -1740,8 +1740,7 @@ def _delete_calculated_temperatures(self) -> None:
17401740
self.results = ResultsMonthly()
17411741
self.load.reset_results(self.Tf_min, self.Tf_max)
17421742

1743-
def _calculate_temperature_profile(self, H: float = None, hourly: bool = False,
1744-
fluid_temperature: float = None) -> None:
1743+
def _calculate_temperature_profile(self, H: float = None, hourly: bool = False, sizing: bool = False) -> None:
17451744
"""
17461745
This function calculates the evolution in the fluid temperature and borehole wall temperature.
17471746
@@ -1751,8 +1750,8 @@ def _calculate_temperature_profile(self, H: float = None, hourly: bool = False,
17511750
Borehole length at which the temperatures should be evaluated [m]. If None, then the current length is taken.
17521751
hourly : bool
17531752
True if the temperature evolution should be calculated on an hourly basis.
1754-
fluid_temperature : float
1755-
During sizing, this differs from None so the specific temperature is taken.
1753+
sizing : bool
1754+
True if this method is called during sizing.
17561755
17571756
Returns
17581757
-------
@@ -1769,13 +1768,26 @@ def calculate_temperatures(H, hourly=hourly, results_temperature=ResultsMonthly(
17691768

17701769
results = None
17711770

1772-
def get_rb(temperature):
1773-
if fluid_temperature is not None and Borefield.USE_SPEED_UP_IN_SIZING:
1774-
return self.borehole.get_Rb(H, self.D, self.r_b, self.ground_data.k_s(depth, self.D), depth,
1775-
temperature=fluid_temperature)
1771+
def get_rb(temperature, limit=None):
1772+
variable_efficiency = isinstance(self.load, _LoadDataBuilding) and not (
1773+
isinstance(self.load.cop, SCOP) and isinstance(self.load.cop_dhw, SCOP) and isinstance(
1774+
self.load.eer, SEER))
1775+
if self.USE_SPEED_UP_IN_SIZING and sizing and not variable_efficiency:
1776+
# use only extreme temperatures when sizing
1777+
if limit is not None:
1778+
if len(temperature) == 0:
1779+
return self.borehole.get_Rb(H, self.D, self.r_b, self.ground_data.k_s(depth, self.D), depth,
1780+
temperature=self.Tf_min)
1781+
elif limit == self.Tf_max:
1782+
return self.borehole.get_Rb(H, self.D, self.r_b, self.ground_data.k_s(depth, self.D), depth,
1783+
temperature=max(temperature))
1784+
else:
1785+
return self.borehole.get_Rb(H, self.D, self.r_b, self.ground_data.k_s(depth, self.D), depth,
1786+
temperature=min(temperature))
17761787
if len(temperature) == 0:
17771788
return self.borehole.get_Rb(H, self.D, self.r_b, self.ground_data.k_s(depth, self.D), depth,
17781789
temperature=self.Tf_min)
1790+
17791791
return self.borehole.get_Rb(H, self.D, self.r_b, self.ground_data.k_s(depth, self.D), depth,
17801792
temperature=temperature)
17811793

@@ -1806,22 +1818,24 @@ def get_rb(temperature):
18061818
# now the Tf will be calculated based on
18071819
# Tf = Tb + Q * R_b
18081820
results_month_injection = Tb + self.load.monthly_baseload_injection_power_simulation_period * 1000 * (
1809-
get_rb(results_temperature.monthly_injection) / self.number_of_boreholes / H)
1821+
get_rb(results_temperature.monthly_injection, self.Tf_max) / self.number_of_boreholes / H)
18101822
results_month_extraction = Tb - self.load.monthly_baseload_extraction_power_simulation_period * 1000 * (
1811-
get_rb(results_temperature.monthly_extraction) / self.number_of_boreholes / H)
1823+
get_rb(results_temperature.monthly_extraction, self.Tf_min) / self.number_of_boreholes / H)
18121824

18131825
# extra summation if the g-function value for the peak is included
18141826
results_peak_injection = (
18151827
Tb
18161828
+ (self.load.monthly_peak_injection_simulation_period
1817-
* (g_value_peak_injection / k_s / 2 / pi + get_rb(results_temperature.peak_injection))
1829+
* (g_value_peak_injection / k_s / 2 / pi + get_rb(results_temperature.peak_injection,
1830+
self.Tf_max))
18181831
- self.load.monthly_baseload_injection_power_simulation_period * g_value_peak_injection / k_s / 2 / pi)
18191832
* 1000 / self.number_of_boreholes / H
18201833
)
18211834
results_peak_extraction = (
18221835
Tb +
18231836
(- self.load.monthly_peak_extraction_simulation_period
1824-
* (g_value_peak_extraction / k_s / 2 / pi + get_rb(results_temperature.peak_extraction))
1837+
* (g_value_peak_extraction / k_s / 2 / pi + get_rb(results_temperature.peak_extraction,
1838+
self.Tf_min))
18251839
+ self.load.monthly_baseload_extraction_power_simulation_period * g_value_peak_extraction / k_s / 2 / pi)
18261840
* 1000 / self.number_of_boreholes / H
18271841
)
@@ -1859,10 +1873,14 @@ def get_rb(temperature):
18591873
# now the Tf will be calculated based on
18601874
# Tf = Tb + Q * R_b
18611875
temperature_result = Tb + hourly_load * 1000 * (
1862-
get_rb(results_temperature.peak_injection) / self.number_of_boreholes / H)
1876+
get_rb(results_temperature.peak_injection, self.Tf_max) / self.number_of_boreholes / H)
18631877

18641878
# reset other variables
18651879
results = ResultsHourly(borehole_wall_temp=Tb, temperature_fluid=temperature_result)
1880+
if sizing:
1881+
# do the same for extraction
1882+
results._Tf_extraction = Tb + hourly_load * 1000 * (
1883+
get_rb(results_temperature.peak_extraction, self.Tf_min) / self.number_of_boreholes / H)
18661884

18671885
return results
18681886

0 commit comments

Comments
 (0)