Skip to content

Commit 972ec07

Browse files
authored
Merge pull request #346 from wouterpeere/issue345-bring-up-to-date-with-pygfunction-v230
Issue345 bring up to date with pygfunction v230
2 parents 31d42fe + 075d73e commit 972ec07

26 files changed

+209
-169
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2020

2121
- Added U-bend to the pressure drop calculation of the pipe (issue #332).
2222
- Remove optimise_load_power and optimise_load_energy from Borefield object (issue #332).
23+
- Changed back-end to be compatible with pygfunction 2.3.0 (issue #345).
2324

2425
## Fixed
2526

GHEtool/Borefield.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __init__(
4848
peak_injection: ArrayLike = None,
4949
baseload_extraction: ArrayLike = None,
5050
baseload_injection: ArrayLike = None,
51-
borefield: list[gt.boreholes.Borehole] = None,
51+
borefield: gt.borefield.Borefield = None,
5252
custom_gfunction: CustomGFunction = None,
5353
load: _LoadData = None,
5454
**kwargs
@@ -187,7 +187,7 @@ def number_of_boreholes(self) -> int:
187187
int
188188
Number of boreholes
189189
"""
190-
return len(self.borefield) if self.borefield is not None else 0
190+
return self.borefield.nBoreholes if self.borefield is not None else 0
191191

192192
@property
193193
def depth(self) -> float:
@@ -217,7 +217,7 @@ def calculate_depth(self, borehole_length: float, buried_depth: float) -> float:
217217
float
218218
Depth of the borehole [m]
219219
"""
220-
if np.isclose(self.avg_tilt, 0):
220+
if self.borefield is None or np.all(self.borefield.tilt == 0):
221221
return borehole_length + buried_depth
222222
return np.average([bor.H * math.cos(bor.tilt) for bor in self.borefield]) + buried_depth
223223

@@ -248,20 +248,19 @@ def H(self, H: float) -> None:
248248
None
249249
"""
250250
self._H = H
251-
for bor in self._borefield:
252-
bor.H = H
251+
self._borefield.H = np.full(self.number_of_boreholes, H)
253252

254253
# the boreholes are equal in length
255254
self.gfunction_calculation_object.store_previous_values = \
256255
self.gfunction_calculation_object._store_previous_values_backup
257256

258-
def set_borefield(self, borefield: list[gt.boreholes.Borehole] = None) -> None:
257+
def set_borefield(self, borefield: gt.borefield.Borefield = None) -> None:
259258
"""
260259
This function set the borefield object. When None is given, the borefield will be deleted.
261260
262261
Parameters
263262
----------
264-
borefield : List[pygfunction.boreholes.Borehole]
263+
borefield : pygfunction.borefield.Borefield
265264
Borefield created with the pygfunction package
266265
267266
Returns
@@ -298,7 +297,7 @@ def create_rectangular_borefield(self, N_1: int, N_2: int, B_1: float, B_2: floa
298297
-------
299298
pygfunction borefield object
300299
"""
301-
borefield = gt.boreholes.rectangle_field(N_1, N_2, B_1, B_2, H, D, r_b)
300+
borefield = gt.borefield.Borefield.rectangle_field(N_1, N_2, B_1, B_2, H, D, r_b)
302301
self.set_borefield(borefield)
303302

304303
return borefield
@@ -326,7 +325,7 @@ def create_circular_borefield(self, N: int, R: float, H: float, D: float = 1, r_
326325
-------
327326
pygfunction borefield object
328327
"""
329-
borefield = gt.boreholes.circle_field(N, R, H, D, r_b)
328+
borefield = gt.borefield.Borefield.circle_field(N, R, H, D, r_b)
330329
self.set_borefield(borefield)
331330
return borefield
332331

@@ -358,7 +357,7 @@ def create_U_shaped_borefield(self, N_1: int, N_2: int, B_1: float, B_2: float,
358357
-------
359358
pygfunction borefield object
360359
"""
361-
borefield = gt.boreholes.U_shaped_field(N_1, N_2, B_1, B_2, H, D, r_b)
360+
borefield = gt.borefield.Borefield.U_shaped_field(N_1, N_2, B_1, B_2, H, D, r_b)
362361
self.set_borefield(borefield)
363362
return borefield
364363

@@ -390,7 +389,7 @@ def create_L_shaped_borefield(self, N_1: int, N_2: int, B_1: float, B_2: float,
390389
-------
391390
pygfunction borefield object
392391
"""
393-
borefield = gt.boreholes.L_shaped_field(N_1, N_2, B_1, B_2, H, D, r_b)
392+
borefield = gt.borefield.Borefield.L_shaped_field(N_1, N_2, B_1, B_2, H, D, r_b)
394393
self.set_borefield(borefield)
395394
return borefield
396395

@@ -422,7 +421,7 @@ def create_box_shaped_borefield(self, N_1: int, N_2: int, B_1: float, B_2: float
422421
-------
423422
pygfunction borefield object
424423
"""
425-
borefield = gt.boreholes.box_shaped_field(N_1, N_2, B_1, B_2, H, D, r_b)
424+
borefield = gt.borefield.Borefield.box_shaped_field(N_1, N_2, B_1, B_2, H, D, r_b)
426425
self.set_borefield(borefield)
427426
return borefield
428427

@@ -438,13 +437,13 @@ def borefield(self):
438437
return self._borefield
439438

440439
@borefield.setter
441-
def borefield(self, borefield: list[gt.boreholes.Borehole] = None) -> None:
440+
def borefield(self, borefield: gt.borefield.Borefield = None) -> None:
442441
"""
443442
This function sets the borefield configuration. When no input is given, the borefield variable will be deleted.
444443
445444
Parameters
446445
----------
447-
borefield : List[pygfunction.boreholes.Borehole]
446+
borefield : pygfunction.borefield.Borefield
448447
Borefield created with the pygfunction package
449448
450449
Returns
@@ -455,14 +454,14 @@ def borefield(self, borefield: list[gt.boreholes.Borehole] = None) -> None:
455454
del self.borefield
456455
return
457456
self._borefield = borefield
458-
self.D = np.average([bor.D for bor in borefield])
459-
self.r_b = np.average([bor.r_b for bor in borefield])
460-
self._H = np.average([bor.H for bor in borefield])
461-
self.avg_tilt = np.average([bor.tilt for bor in borefield])
462-
if not np.isclose(self.avg_tilt, 0):
457+
self.D = np.average(borefield.D)
458+
self.r_b = np.average(borefield.r_b)
459+
self._H = np.average(borefield.H)
460+
self.avg_tilt = np.average(borefield.tilt)
461+
if not np.all(borefield.tilt == 0):
463462
self.gfunction_calculation_object.options['method'] = 'similarities'
464463
self.gfunction_calculation_object.remove_previous_data()
465-
unequal_length = np.any([bor.H != borefield[0].H for bor in borefield])
464+
unequal_length = not np.all(borefield.H == self.H)
466465
if unequal_length:
467466
self.gfunction_calculation_object._store_previous_values = not unequal_length
468467
else:
@@ -1860,9 +1859,7 @@ def create_custom_dataset(self, time_array: ArrayLike = None, borehole_length_ar
18601859
When no borefield or ground data is set
18611860
"""
18621861

1863-
try:
1864-
self.borefield[0]
1865-
except TypeError:
1862+
if self.borefield is None:
18661863
raise ValueError("No borefield is set for which the gfunctions should be calculated")
18671864
try:
18681865
self.ground_data.alpha(depth=100)

GHEtool/Examples/custom_borefield_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def custom_borefield_configuration():
5353
borefield.set_min_avg_fluid_temperature(0) # minimum temperature
5454

5555
# create custom borefield based on pygfunction
56-
custom_field = gt.boreholes.L_shaped_field(N_1=4, N_2=5, B_1=5., B_2=5., H=100., D=4, r_b=0.05)
56+
custom_field = gt.borefield.Borefield.L_shaped_field(N_1=4, N_2=5, B_1=5., B_2=5., H=100., D=4, r_b=0.05)
5757

5858
# set the custom borefield (so the number of boreholes is correct)
5959
borefield.set_borefield(custom_field)

GHEtool/Examples/effect_of_borehole_configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def effect_borefield_configuration():
1212
# GroundData for an initial field of 11 x 11
1313
data = GroundConstantTemperature(3, 10)
14-
borefield_gt = gt.boreholes.rectangle_field(11, 11, 6, 6, 110, 1, 0.075)
14+
borefield_gt = gt.borefield.Borefield.rectangle_field(11, 11, 6, 6, 110, 1, 0.075)
1515

1616
# Monthly loading values
1717
peak_cooling = np.array([0., 0, 34., 69., 133., 187., 213., 240., 160., 37., 0., 0.]) # Peak cooling in kW
@@ -52,7 +52,7 @@ def effect_borefield_configuration():
5252

5353
# borefield of 6x20
5454
data = GroundConstantTemperature(3, 10)
55-
borefield_gt = gt.boreholes.rectangle_field(6, 20, 6, 6, 110, 1, 0.075)
55+
borefield_gt = gt.borefield.Borefield.rectangle_field(6, 20, 6, 6, 110, 1, 0.075)
5656

5757
# set ground parameters to borefield
5858
borefield.set_borefield(borefield_gt)

GHEtool/Examples/find_optimal_borefield.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,31 @@
6161

6262
@cache
6363
def line(x, y):
64-
temp = gt.boreholes.rectangle_field(x, y, max(B_max, width / x), max(B_max, length / y), 100, 0.7, 0.07)
64+
temp = gt.borefield.Borefield.rectangle_field(x, y, max(B_max, width / x), max(B_max, length / y), 100, 0.7, 0.07)
6565
return len(temp), temp
6666

6767

6868
@cache
6969
def L(x, y):
70-
temp = gt.boreholes.L_shaped_field(x, y, max(B_max, width / x), max(B_max, length / y), 100, 0.7, 0.07)
70+
temp = gt.borefield.Borefield.L_shaped_field(x, y, max(B_max, width / x), max(B_max, length / y), 100, 0.7, 0.07)
7171
return len(temp), temp
7272

7373

7474
@cache
7575
def U(x, y):
76-
temp = gt.boreholes.U_shaped_field(x, y, max(B_max, width / x), max(B_max, length / y), 100, 0.7, 0.07)
76+
temp = gt.borefield.Borefield.U_shaped_field(x, y, max(B_max, width / x), max(B_max, length / y), 100, 0.7, 0.07)
7777
return len(temp), temp
7878

7979

8080
@cache
8181
def box(x, y):
82-
temp = gt.boreholes.box_shaped_field(x, y, max(B_max, width / x), max(B_max, length / y), 100, 0.7, 0.07)
82+
temp = gt.borefield.Borefield.box_shaped_field(x, y, max(B_max, width / x), max(B_max, length / y), 100, 0.7, 0.07)
8383
return len(temp), temp
8484

8585

8686
@cache
8787
def rectangle(x, y):
88-
temp = gt.boreholes.rectangle_field(x, y, max(B_max, width / x), max(B_max, length / y), 100, 0.7, 0.07)
88+
temp = gt.borefield.Borefield.rectangle_field(x, y, max(B_max, width / x), max(B_max, length / y), 100, 0.7, 0.07)
8989
return len(temp), temp
9090

9191

GHEtool/Examples/import_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# initiate ground data
1010
data = GroundConstantTemperature(3, 10, 2.4 * 10 ** 6)
11-
borefield_gt = gt.boreholes.rectangle_field(10, 12, 6, 6, 110, 1, 0.075)
11+
borefield_gt = gt.borefield.Borefield.rectangle_field(10, 12, 6, 6, 110, 1, 0.075)
1212

1313
# initiate borefield
1414
borefield = Borefield()

GHEtool/Examples/sizing_with_Rb_calculation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def sizing_with_Rb():
4242
fluid_data = FluidData(0.2, 0.568, 998, 4180, 1e-3)
4343
pipe_data = DoubleUTube(1, 0.015, 0.02, 0.4, 0.05)
4444

45-
borefield_gt = gt.boreholes.rectangle_field(10, 12, 6, 6, 100, 1, 0.075)
45+
borefield_gt = gt.borefield.Borefield.rectangle_field(10, 12, 6, 6, 100, 1, 0.075)
4646

4747
# Monthly loading values
4848
peak_cooling = np.array([0., 0, 34., 69., 133., 187., 213., 240., 160., 37., 0., 0.]) # Peak cooling in kW
@@ -128,8 +128,8 @@ def sizing_with_Rb():
128128

129129
# Do the same thing but with another constant Rb* value based on a borehole length of 185m.
130130

131-
borefield_gt = gt.boreholes.rectangle_field(10, 12, 6, 6, 185, 1,
132-
0.075) # borefield with an accurate guess of 185m for the borehole length
131+
borefield_gt = gt.borefield.Borefield.rectangle_field(10, 12, 6, 6, 185, 1,
132+
0.075) # borefield with an accurate guess of 185m for the borehole length
133133
borefield.set_borefield(borefield_gt)
134134

135135
# size with a constant Rb* value

GHEtool/Examples/sizing_with_building_load_hourly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# initiate ground data
1414
data = GroundFluxTemperature(2.1, 10, flux=0.07)
15-
borefield_gt = gt.boreholes.rectangle_field(10, 12, 6, 6, 110, 1, 0.075)
15+
borefield_gt = gt.borefield.Borefield.rectangle_field(10, 12, 6, 6, 110, 1, 0.075)
1616

1717
cop = COP(np.array(
1818
[4.42, 5.21, 6.04, 7.52, 9.5, 3.99, 4.58, 5.21, 6.02, 6.83, 3.86, 4.39, 4.97,

GHEtool/Examples/tilted_borefield.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ def tilted():
2424
)
2525

2626
# define borefield
27-
borefield_tilted = [gt.boreholes.Borehole(150, 0.75, 0.07, -3, 0, math.pi / 7, orientation=math.pi),
28-
gt.boreholes.Borehole(150, 0.75, 0.07, 3, 0, math.pi / 7, orientation=0)]
29-
borefield_without_tilt = [gt.boreholes.Borehole(150, 0.75, 0.07, -3, 0),
30-
gt.boreholes.Borehole(150, 0.75, 0.07, 3, 0)]
27+
borefield_tilted = gt.borefield.Borefield.from_boreholes(
28+
[gt.boreholes.Borehole(150, 0.75, 0.07, -3, 0, math.pi / 7, orientation=math.pi),
29+
gt.boreholes.Borehole(150, 0.75, 0.07, 3, 0, math.pi / 7, orientation=0)])
30+
borefield_without_tilt = gt.borefield.Borefield.from_boreholes([gt.boreholes.Borehole(150, 0.75, 0.07, -3, 0),
31+
gt.boreholes.Borehole(150, 0.75, 0.07, 3, 0)])
3132

3233
# initiate GHEtool object with tilted borefield
3334
borefield = Borefield(borefield=borefield_tilted, load=load_data)

GHEtool/Validation/cases.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
# relevant borefield data for the calculations
1515
data = GroundConstantTemperature(3.5, # conductivity of the soil (W/mK)
16-
10) # Ground temperature at infinity (degrees C)
16+
10) # Ground temperature at infinity (degrees C)
1717

18-
borefield_gt = gt.boreholes.rectangle_field(10, 12, 6.5, 6.5, 100, 4, 0.075)
18+
borefield_gt = gt.borefield.Borefield.rectangle_field(10, 12, 6.5, 6.5, 100, 4, 0.075)
1919

2020

2121
def load_case(number):
@@ -24,7 +24,8 @@ def load_case(number):
2424
if number == 1:
2525
# case 1
2626
# limited in the first year by cooling
27-
monthly_load_heating_percentage = np.array([0.155, 0.148, 0.125, .099, .064, 0., 0., 0., 0.061, 0.087, 0.117, 0.144])
27+
monthly_load_heating_percentage = np.array(
28+
[0.155, 0.148, 0.125, .099, .064, 0., 0., 0., 0.061, 0.087, 0.117, 0.144])
2829
monthly_load_cooling_percentage = np.array([0.025, 0.05, 0.05, .05, .075, .1, .2, .2, .1, .075, .05, .025])
2930
monthly_load_heating = monthly_load_heating_percentage * 300 * 10 ** 3 # kWh
3031
monthly_load_cooling = monthly_load_cooling_percentage * 150 * 10 ** 3 # kWh
@@ -34,7 +35,8 @@ def load_case(number):
3435
elif number == 2:
3536
# case 2
3637
# limited in the last year by cooling
37-
monthly_load_heating_percentage = np.array([0.155, 0.148, 0.125, .099, .064, 0., 0., 0., 0.061, 0.087, .117, 0.144])
38+
monthly_load_heating_percentage = np.array(
39+
[0.155, 0.148, 0.125, .099, .064, 0., 0., 0., 0.061, 0.087, .117, 0.144])
3840
monthly_load_cooling_percentage = np.array([0.025, 0.05, 0.05, .05, .075, .1, .2, .2, .1, .075, .05, .025])
3941
monthly_load_heating = monthly_load_heating_percentage * 160 * 10 ** 3 # kWh
4042
monthly_load_cooling = monthly_load_cooling_percentage * 240 * 10 ** 3 # kWh
@@ -44,7 +46,8 @@ def load_case(number):
4446
elif number == 3:
4547
# case 3
4648
# limited in the first year by heating
47-
monthly_load_heating_percentage = np.array([0.155, 0.148, 0.125, .099, .064, 0., 0., 0., 0.061, 0.087, .117, 0.144])
49+
monthly_load_heating_percentage = np.array(
50+
[0.155, 0.148, 0.125, .099, .064, 0., 0., 0., 0.061, 0.087, .117, 0.144])
4851
monthly_load_cooling_percentage = np.array([0.025, 0.05, 0.05, .05, .075, .1, .2, .2, .1, .075, .05, .025])
4952
monthly_load_heating = monthly_load_heating_percentage * 160 * 10 ** 3 # kWh
5053
monthly_load_cooling = monthly_load_cooling_percentage * 240 * 10 ** 3 # kWh
@@ -54,7 +57,8 @@ def load_case(number):
5457
else:
5558
# case 4
5659
# limited in the last year by heating
57-
monthly_load_heating_percentage = np.array([0.155, 0.148, 0.125, .099, .064, 0., 0., 0., 0.061, 0.087, 0.117, 0.144])
60+
monthly_load_heating_percentage = np.array(
61+
[0.155, 0.148, 0.125, .099, .064, 0., 0., 0., 0.061, 0.087, 0.117, 0.144])
5862
monthly_load_cooling_percentage = np.array([0.025, 0.05, 0.05, .05, .075, .1, .2, .2, .1, .075, .05, .025])
5963
monthly_load_heating = monthly_load_heating_percentage * 300 * 10 ** 3 # kWh
6064
monthly_load_cooling = monthly_load_cooling_percentage * 150 * 10 ** 3 # kWh
@@ -65,7 +69,6 @@ def load_case(number):
6569

6670

6771
def check_cases():
68-
6972
"""
7073
This function checks whether the borefield sizing gives the correct (i.e. validated) results for the 4 cases.
7174
If not, an assertion error is raised.
@@ -87,14 +90,14 @@ def check_cases():
8790
borefield.set_min_avg_fluid_temperature(0) # minimum temperature
8891

8992
borefield.size(100, L2_sizing=True)
90-
print(f'correct answer L2: {correct_answers_L2[i-1]}; calculated answer L2: {round(borefield.H,2)}; error: '
93+
print(f'correct answer L2: {correct_answers_L2[i - 1]}; calculated answer L2: {round(borefield.H, 2)}; error: '
9194
f'{round(abs(1 - borefield.H / correct_answers_L2[i - 1]) * 100, 4)} %')
92-
assert np.isclose(borefield.H, correct_answers_L2[i-1], rtol=0.001)
95+
assert np.isclose(borefield.H, correct_answers_L2[i - 1], rtol=0.001)
9396

9497
borefield.size(100, L3_sizing=True)
9598
print(f'correct answer L3: {correct_answers_L3[i - 1]}; calculated answer L3: {round(borefield.H, 2)}; error: '
9699
f'{round(abs(1 - borefield.H / correct_answers_L3[i - 1]) * 100, 4)} %')
97-
assert np.isclose(borefield.H, correct_answers_L3[i-1], rtol=0.001)
100+
assert np.isclose(borefield.H, correct_answers_L3[i - 1], rtol=0.001)
98101

99102

100103
def check_custom_datafile():
@@ -107,7 +110,7 @@ def check_custom_datafile():
107110

108111
correct_answers = (56.75, 117.23, 66.94, 91.32)
109112

110-
custom_field = gt.boreholes.rectangle_field(N_1=12, N_2=10, B_1=6.5, B_2=6.5, H=110., D=4, r_b=0.075)
113+
custom_field = gt.borefield.Borefield.rectangle_field(N_1=12, N_2=10, B_1=6.5, B_2=6.5, H=110., D=4, r_b=0.075)
111114

112115
for i in (1, 2, 3, 4):
113116
borefield = Borefield(load=MonthlyGeothermalLoadAbsolute(*load_case(i)))
@@ -121,11 +124,11 @@ def check_custom_datafile():
121124
borefield.set_min_avg_fluid_temperature(0) # minimum temperature
122125

123126
borefield.size(100, L3_sizing=True)
124-
print(f'correct answer: {correct_answers[i-1]}; calculated '
125-
f'answer: {round(borefield.H,2)}; error: '
126-
f'{round(abs(1-borefield.H/correct_answers[i - 1])*100,4)} %')
127+
print(f'correct answer: {correct_answers[i - 1]}; calculated '
128+
f'answer: {round(borefield.H, 2)}; error: '
129+
f'{round(abs(1 - borefield.H / correct_answers[i - 1]) * 100, 4)} %')
127130

128131

129-
if __name__ == "__main__": # pragma: no cover
132+
if __name__ == "__main__": # pragma: no cover
130133
check_cases() # check different cases
131134
check_custom_datafile() # check if the custom datafile is correct

0 commit comments

Comments
 (0)