Skip to content

Commit 0df1296

Browse files
authored
Merge pull request #357 from wouterpeere/Hydratech
Hydratech
2 parents 6f1e842 + 4169e62 commit 0df1296

File tree

6 files changed

+86
-17
lines changed

6 files changed

+86
-17
lines changed

GHEtool/VariableClasses/FluidData/CommercialFluids/CoolflowNTP.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __init__(self, volume_ratio: float):
9898
[np.nan, np.nan, np.nan, np.nan, 171.56, 261.75, 275.05], # -30°C
9999
[np.nan, np.nan, np.nan, np.nan, np.nan, 415.79, 391.37], # -35°C
100100
[np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, 552.34], # -40°C
101-
]) * 10e-6 * self._rho_array # convert from kinematic viscosity in mm²/s to dynamic viscosity in Pa.s
101+
]) * 1e-6 * self._rho_array # convert from kinematic viscosity in mm²/s to dynamic viscosity in Pa.s
102102

103103
self._cp_array = np.array([
104104
[4.05, 3.97, 3.91, 3.85, 3.79, 3.72, 3.60], # 80°C
@@ -130,3 +130,6 @@ def __init__(self, volume_ratio: float):
130130

131131
if self.check_volume_ratio(volume_ratio):
132132
self._volume_ratio = volume_ratio
133+
134+
# update nan values
135+
self._fill_nan_values_vertically()

GHEtool/VariableClasses/FluidData/CommercialFluids/ThermoxDTX.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55

66
import numpy as np
7-
87
from GHEtool.VariableClasses.FluidData.CommercialFluids._CommercialFluids import _CommercialFluids
98

109

@@ -17,6 +16,7 @@ def __init__(self, volume_ratio: float):
1716
self._volume_ratio_array = np.array([22, 28, 33, 38, 42, 46, 50, 52, 54.3]) / 100
1817

1918
self._freezing_array = np.array([-10, -15, -20, -25, -30, -35, -40, -45, -50])
19+
2020
self._k_f_array = np.array([
2121
[0.544, 0.508, 0.480, 0.452, 0.431, 0.412, 0.394, 0.386, 0.374], # 80°C
2222
[0.541, 0.506, 0.478, 0.451, 0.432, 0.413, 0.396, 0.387, 0.376], # 75°C
@@ -103,7 +103,7 @@ def __init__(self, volume_ratio: float):
103103
[np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, 247.80, 395.42, 401.36], # -40°C
104104
[np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, 627.39, 762.70], # -45°C
105105
[np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, 1433.75], # -50°C
106-
]) * 10e-6 * self._rho_array # convert from kinematic viscosity in mm²/s to dynamic viscosity in Pa.s
106+
]) * 1e-6 * self._rho_array # convert from kinematic viscosity in mm²/s to dynamic viscosity in Pa.s
107107
self._cp_array = np.array([
108108
[3.97, 3.89, 3.82, 3.75, 3.68, 3.62, 3.56, 3.53, 3.49], # 80°C
109109
[3.97, 3.88, 3.81, 3.73, 3.67, 3.60, 3.55, 3.52, 3.47], # 75°C
@@ -136,3 +136,6 @@ def __init__(self, volume_ratio: float):
136136

137137
if self.check_volume_ratio(volume_ratio):
138138
self._volume_ratio = volume_ratio
139+
140+
# update nan values
141+
self._fill_nan_values_vertically()

GHEtool/VariableClasses/FluidData/CommercialFluids/_CommercialFluids.py

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import numpy as np
6+
import pandas as pd
67
import scipy as sc
78

89

@@ -45,20 +46,49 @@ def check_volume_ratio(self, volume_ratio: float) -> bool:
4546

4647
def freeze_point(self, volume_ratio: float) -> float:
4748
if self.check_volume_ratio(volume_ratio):
48-
return np.interp(volume_ratio, self._volume_ratio_array, self._freezing_array)
49+
return float(np.interp(volume_ratio, self._volume_ratio_array, self._freezing_array))
4950

5051
def conductivity(self, temp: float, volume_ratio: float = None):
51-
return sc.interpolate.interpn((self._temperatures, self._volume_ratio_array), self._k_f_array,
52-
(temp, self._volume_ratio if volume_ratio is None else volume_ratio))
52+
temp = sc.interpolate.interpn((self._temperatures, self._volume_ratio_array), self._k_f_array,
53+
(temp, self._volume_ratio if volume_ratio is None else volume_ratio),
54+
bounds_error=False)
55+
if len(temp) == 1:
56+
return float(temp)
57+
return temp
5358

5459
def viscosity(self, temp: float, volume_ratio: float = None):
55-
return sc.interpolate.interpn((self._temperatures, self._volume_ratio_array), self._mu_array,
56-
(temp, self._volume_ratio if volume_ratio is None else volume_ratio))
60+
temp = sc.interpolate.interpn((self._temperatures, self._volume_ratio_array), self._mu_array,
61+
(temp, self._volume_ratio if volume_ratio is None else volume_ratio),
62+
bounds_error=False)
63+
if len(temp) == 1:
64+
return float(temp)
65+
return temp
5766

5867
def density(self, temp: float, volume_ratio: float = None):
59-
return sc.interpolate.interpn((self._temperatures, self._volume_ratio_array), self._rho_array,
60-
(temp, self._volume_ratio if volume_ratio is None else volume_ratio))
68+
temp = sc.interpolate.interpn((self._temperatures, self._volume_ratio_array), self._rho_array,
69+
(temp, self._volume_ratio if volume_ratio is None else volume_ratio),
70+
bounds_error=False)
71+
if len(temp) == 1:
72+
return float(temp)
73+
return temp
6174

6275
def specific_heat(self, temp: float, volume_ratio: float = None):
63-
return sc.interpolate.interpn((self._temperatures, self._volume_ratio_array), self._cp_array,
64-
(temp, self._volume_ratio if volume_ratio is None else volume_ratio))
76+
temp = sc.interpolate.interpn((self._temperatures, self._volume_ratio_array), self._cp_array,
77+
(temp, self._volume_ratio if volume_ratio is None else volume_ratio),
78+
bounds_error=False)
79+
if len(temp) == 1:
80+
return float(temp)
81+
return temp
82+
83+
def _fill_nan_values_vertically(self) -> None:
84+
"""
85+
Fill NaN values in a 2D array by interpolating vertically (column-wise).
86+
87+
Returns
88+
-------
89+
None
90+
"""
91+
self._k_f_array = pd.DataFrame(self._k_f_array).interpolate(axis=0, limit_direction='both').to_numpy()
92+
self._rho_array = pd.DataFrame(self._rho_array).interpolate(axis=0, limit_direction='both').to_numpy()
93+
self._mu_array = pd.DataFrame(self._mu_array).interpolate(axis=0, limit_direction='both').to_numpy()
94+
self._cp_array = pd.DataFrame(self._cp_array).interpolate(axis=0, limit_direction='both').to_numpy()

GHEtool/test/unit-tests/test_borehole.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ def test_calculate_Rb():
9898
np.isclose(borehole.calculate_Rb(100, 1, 0.075, 3), 0.09483159131195469)
9999
assert np.isclose(borehole.calculate_Rb(100, 1, 0.075, 3, temperature=20), 0.13807578911314267)
100100

101+
borehole.fluid_data = TemperatureDependentFluidData('Thermox DTX', 25)
102+
with pytest.raises(TypeError):
103+
np.isclose(borehole.calculate_Rb(100, 1, 0.075, 3), 0.09483159131195469)
104+
assert np.isclose(borehole.calculate_Rb(100, 1, 0.075, 3, temperature=20), 0.13513271096418708)
105+
101106

102107
def test_Rb():
103108
borehole = Borehole()
@@ -250,3 +255,13 @@ def test_saved_data_reynolds():
250255
"[W/(m·K)]': 0.4, 'epsilon [mm]': 0.001}",
251256
'r_b': 0.075}
252257
assert np.allclose(resistance1, borehole.calculate_Rb(100, 1, 0.075, 3, temperature=np.array([0, 1, 2, 5])))
258+
259+
260+
def test_saved_data_reynolds_commercial():
261+
borehole = Borehole()
262+
borehole.pipe_data = MultipleUTube(1, 0.015, 0.02, 0.4, 0.05, 2)
263+
borehole.fluid_data = TemperatureDependentFluidData('Thermox DTX', 25)
264+
borehole.flow_data = ConstantFlowRate(vfr=0.3)
265+
266+
assert np.allclose([0.12849791, 0.12843995, 0.1283812, 0.12820668],
267+
borehole.calculate_Rb(100, 1, 0.075, 3, temperature=np.array([0, 1, 2, 5])))

GHEtool/test/unit-tests/test_fluiddata.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,34 @@ def test_stability_convert_percentages():
228228
assert np.isclose(5, fluid._convert_to_vol_percentage(fluid._convert_to_mass_percentage(5)))
229229

230230

231+
def test_temperature_dependent_fluid_data_neg_temperatures():
232+
fluid = TemperatureDependentFluidData('MPG', 25)
233+
assert np.isclose(fluid.k_f(-20), 0.44057954246124154)
234+
fluid = TemperatureDependentFluidData('Thermox DTX', 25)
235+
assert np.isclose(fluid.k_f(-25), 0.4851181912179882)
236+
237+
231238
def test_commercial_fluids_data():
232239
fluid = ThermoxDTX(0.28)
233240
assert np.isclose(fluid.freeze_point(0.28), -15)
234241
assert np.isclose(fluid.conductivity(10), 0.475)
235242
assert np.isclose(fluid.conductivity(5), 0.473)
236243
assert np.isclose(fluid.density(10), 1046)
237244
assert np.isclose(fluid.specific_heat(10), 3780)
238-
assert np.isclose(fluid.viscosity(10), 3.28 * fluid.density(10) * 10e-6)
245+
assert np.isclose(fluid.viscosity(10), 3.28 * fluid.density(10) * 1e-6)
246+
247+
assert np.allclose(fluid.conductivity([10, 12]), [0.475, 0.4758])
248+
assert np.allclose(fluid.density([10, 12]), [1046, 1045.6])
249+
assert np.allclose(fluid.specific_heat([10, 12]), [3780, 3780.])
250+
assert np.allclose(fluid.viscosity([10, 12]), [0.00343088, 0.003216388])
239251

240252
fluid = TemperatureDependentFluidData('Thermox DTX', 28, mass_percentage=False)
241253
assert np.isclose(fluid.freezing_point, -15)
242254
assert np.isclose(fluid.k_f(10), 0.475)
243255
assert np.isclose(fluid.k_f(5), 0.473)
244256
assert np.isclose(fluid.rho(10), 1046)
245257
assert np.isclose(fluid.cp(10), 3780)
246-
assert np.isclose(fluid.mu(10), 3.28 * fluid.rho(10) * 10e-6)
258+
assert np.isclose(fluid.mu(10), 3.28 * fluid.rho(10) * 1e-6)
247259

248260
assert (np.isclose(fluid.rho(100), fluid.rho(80)))
249261

@@ -253,15 +265,21 @@ def test_commercial_fluids_data():
253265
assert np.isclose(fluid.conductivity(5), 0.443)
254266
assert np.isclose(fluid.density(10), 1037)
255267
assert np.isclose(fluid.specific_heat(10), 3820)
256-
assert np.isclose(fluid.viscosity(10), 5.46 * fluid.density(10) * 10e-6)
268+
assert np.isclose(fluid.viscosity(10), 5.46 * fluid.density(10) * 1e-6)
257269

258270
fluid = TemperatureDependentFluidData('Coolflow NTP', 33, mass_percentage=False)
259271
assert np.isclose(fluid.freezing_point, -15)
260272
assert np.isclose(fluid.k_f(10), 0.444)
261273
assert np.isclose(fluid.k_f(5), 0.443)
262274
assert np.isclose(fluid.rho(10), 1037)
263275
assert np.isclose(fluid.cp(10), 3820)
264-
assert np.isclose(fluid.mu(10), 5.46 * fluid.rho(10) * 10e-6)
276+
assert np.isclose(fluid.mu(10), 5.46 * fluid.rho(10) * 1e-6)
277+
278+
# test bounds error
279+
assert np.isclose(fluid.k_f(-100), 0.435)
280+
assert np.isclose(fluid.mu(-100), 0.02204968)
281+
assert np.isclose(fluid.rho(-100), 1046.0)
282+
assert np.isclose(fluid.cp(-100), 3770.0)
265283

266284
with pytest.raises(ValueError):
267285
fluid = ThermoxDTX(100)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = GHEtool
3-
version = 2.3.3.dev3
3+
version = 2.3.3.dev4
44
author = Wouter Peere
55
author_email = wouter@ghetool.eu
66
description = Python package for borefield sizing

0 commit comments

Comments
 (0)