Skip to content

Commit b0f1ad0

Browse files
committedFeb 26, 2025·
Fix issue 332
1 parent e89f22d commit b0f1ad0

File tree

4 files changed

+154
-2
lines changed

4 files changed

+154
-2
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1111

1212
- Added support for DHW profiles in optimisation (issue #272).
1313
- Added Prandtl number to FluidData class (issue #326).
14+
- Pressure drop calculation for horizontal pipe and total system (issue #332).
1415

1516
## Changed
1617

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import copy
2+
3+
import numpy as np
4+
import pygfunction as gt
5+
6+
from GHEtool import *
7+
from GHEtool.VariableClasses.PipeData import _PipeData
8+
from math import pi
9+
10+
11+
def calculate_pressure_drop_horizontal(fluid_data: FluidData, r_in: float, length: float, minor_losses: float) -> float:
12+
"""
13+
This function calculates the pressure drop in the horizontal pipe.
14+
15+
Parameters
16+
----------
17+
fluid_data : FluidData
18+
Fluid data
19+
r_in : float
20+
Inner pipe diameter [m]
21+
length : float
22+
Length of the pipe [m]
23+
minor_losses : float
24+
Coefficient for minor losses [-]
25+
26+
Returns
27+
-------
28+
Pressure drop : float
29+
Pressure drop [kPa]
30+
"""
31+
# Darcy fluid factor
32+
fd = gt.pipes.fluid_friction_factor_circular_pipe(
33+
fluid_data.mfr,
34+
r_in,
35+
fluid_data.mu,
36+
fluid_data.rho,
37+
1e-6)
38+
A = pi * r_in ** 2
39+
V = (fluid_data.vfr / 1000) / A
40+
41+
return ((fd * length / (2 * r_in) + minor_losses) * fluid_data.rho * V ** 2 / 2) / 1000
42+
43+
44+
def calculate_total_pressure_drop(pipe_data: _PipeData, fluid_data: FluidData, borehole_length: float,
45+
r_in: float, distance: float, minor_losses: float) -> float:
46+
"""
47+
This function calculates the total pressure drop of your system, assuming every borehole is brought individually
48+
to the main collector.
49+
50+
Parameters
51+
----------
52+
pipe_data : PipeData
53+
Pipe data
54+
fluid_data : FluidData
55+
Fluid data
56+
borehole_length : float
57+
Borehole length [m]
58+
r_in : float
59+
Inner pipe diameter [m]
60+
distance : float
61+
distance from the borehole to the collector [m]
62+
minor_losses : float
63+
Coefficient for minor losses [-]
64+
65+
Returns
66+
-------
67+
Pressure drop : float
68+
Pressure drop [kPa]
69+
"""
70+
71+
return pipe_data.pressure_drop(fluid_data, borehole_length) + \
72+
calculate_pressure_drop_horizontal(fluid_data, r_in, distance * 2, minor_losses)
73+
74+
75+
def create_pressure_drop_curve(pipe_data: _PipeData, fluid_data: FluidData, borehole_length: float,
76+
r_in: float, distance: float, minor_losses: float, range: float = 2,
77+
datapoints: int = 30) -> tuple:
78+
"""
79+
This function calculates the pressure drop for different flow rates.
80+
81+
Parameters
82+
----------
83+
pipe_data : PipeData
84+
Pipe data
85+
fluid_data : FluidData
86+
Fluid data
87+
borehole_length : float
88+
Borehole length [m]
89+
r_in : float
90+
Inner pipe diameter [m]
91+
distance : float
92+
distance from the borehole to the collector [m]
93+
minor_losses : float
94+
Coefficient for minor losses [-]
95+
range : float
96+
Multiplier of the flow rate for the range of the data.
97+
datapoints : int
98+
Number of datapoints.
99+
100+
Returns
101+
-------
102+
pressure drop, flow rates : np.ndarray, np.ndarray
103+
Array with the pressure drops [kPa], Array with the flow rates per borehole [l/s]
104+
"""
105+
106+
flow_rates = np.linspace(0, range * fluid_data.vfr, datapoints)
107+
pressure_drops = np.zeros(flow_rates.shape)
108+
109+
new_fluid = copy.copy(fluid_data)
110+
111+
for i, val in enumerate(flow_rates):
112+
new_fluid.vfr = val
113+
pressure_drops[i] = calculate_total_pressure_drop(pipe_data, new_fluid, borehole_length, r_in, distance,
114+
minor_losses)
115+
116+
return np.nan_to_num(pressure_drops), flow_rates

‎GHEtool/VariableClasses/PipeData/MultipleUTube.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import numpy as np
44
import pygfunction as gt
55
import matplotlib.pyplot as plt
6-
from math import pi
76

7+
from math import pi
88
from GHEtool.VariableClasses.PipeData._PipeData import _PipeData
99
from GHEtool.VariableClasses.FluidData import FluidData
1010

@@ -163,7 +163,7 @@ def pressure_drop(self, fluid_data: FluidData, borehole_length: float) -> float:
163163

164164
# add 0.2 for the local losses
165165
# (source: https://www.engineeringtoolbox.com/minor-loss-coefficients-pipes-d_626.html)
166-
return ((fd * (borehole_length * 2) / (2 * self.r_in) + 0.2) * fluid_data.rho * V ** 2 / 2) / 1000
166+
return ((fd * (borehole_length * 2) / (2 * self.r_in) + 0.0) * fluid_data.rho * V ** 2 / 2) / 1000
167167

168168
def draw_borehole_internal(self, r_b: float) -> None:
169169
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import numpy as np
2+
3+
from GHEtool import *
4+
from GHEtool.Methods.pressure_drop_calculation import calculate_pressure_drop_horizontal, calculate_total_pressure_drop, \
5+
create_pressure_drop_curve
6+
7+
8+
def test_horizontal():
9+
fluid_data = FluidData(0.2, 0.568, 998, 4180, 1e-3)
10+
11+
assert np.isclose(calculate_pressure_drop_horizontal(fluid_data, 0.02 - 0.0037 / 2, 15, 0), 0.26307939880441045)
12+
assert np.isclose(calculate_pressure_drop_horizontal(fluid_data, 0.02 - 0.0037 / 2, 15, 2), 0.3005010707434382)
13+
14+
15+
def test_total_pressure_drop():
16+
single_u = SingleUTube(1.5, 0.013, 0.016, 0.4, 0.035)
17+
double_u = DoubleUTube(1.5, 0.013, 0.016, 0.4, 0.035)
18+
fluid_data = FluidData(0.3, 0.568, 998, 4180, 1e-3)
19+
20+
assert np.isclose(calculate_total_pressure_drop(single_u, fluid_data, 100, 0.02 - 0.0037 / 2, 10, 2),
21+
35.307092460895696)
22+
assert np.isclose(calculate_total_pressure_drop(double_u, fluid_data, 100, 0.02 - 0.0037 / 2, 10, 2),
23+
11.139813565855187)
24+
25+
26+
def test_range_pressure_drop():
27+
single_u = SingleUTube(1.5, 0.013, 0.016, 0.4, 0.035)
28+
fluid_data = FluidData(0.2, 0.568, 998, 4180, 1e-3)
29+
30+
pressure, _ = create_pressure_drop_curve(single_u, fluid_data, 100, 0.02 - 0.0037 / 2, 10, 2)
31+
assert np.allclose(pressure, np.array(
32+
[0, 0.25311388, 0.50658373, 0.76040955, 1.90081784, 2.79351152, 3.81007873, 4.95814128, 6.23317941,
33+
7.63146176, 9.14983034, 10.78556091, 12.53626754, 14.39983464, 16.37436709, 18.45815002, 20.64962988,
34+
22.94737642, 25.3500745, 27.85650679, 30.46554156, 33.1761225, 35.98726063, 38.89802652, 41.90754461,
35+
45.0149878, 48.21957292, 51.52055679, 54.9172327, 58.40892744]))

0 commit comments

Comments
 (0)
Please sign in to comment.