Skip to content

Commit

Permalink
Merge pull request #333 from wouterpeere/issue332-add-u-bend-in-press…
Browse files Browse the repository at this point in the history
…ure-drop

Issue332 add u bend in pressure drop
  • Loading branch information
wouterpeere authored Feb 26, 2025
2 parents dc2fc2a + c607ad8 commit b58cdd2
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

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

## Changed

- Added U-bend to the pressure drop calculation of the pipe (issue #332).

## [2.3.1] - 2025-01-23

Expand Down
116 changes: 116 additions & 0 deletions GHEtool/Methods/pressure_drop_calculation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import copy

import numpy as np
import pygfunction as gt

from GHEtool import *
from GHEtool.VariableClasses.PipeData import _PipeData
from math import pi


def calculate_pressure_drop_horizontal(fluid_data: FluidData, r_in: float, length: float, minor_losses: float) -> float:
"""
This function calculates the pressure drop in the horizontal pipe.
Parameters
----------
fluid_data : FluidData
Fluid data
r_in : float
Inner pipe diameter [m]
length : float
Length of the pipe [m]
minor_losses : float
Coefficient for minor losses [-]
Returns
-------
Pressure drop : float
Pressure drop [kPa]
"""
# Darcy fluid factor
fd = gt.pipes.fluid_friction_factor_circular_pipe(
fluid_data.mfr,
r_in,
fluid_data.mu,
fluid_data.rho,
1e-6)
A = pi * r_in ** 2
V = (fluid_data.vfr / 1000) / A

return ((fd * length / (2 * r_in) + minor_losses) * fluid_data.rho * V ** 2 / 2) / 1000


def calculate_total_pressure_drop(pipe_data: _PipeData, fluid_data: FluidData, borehole_length: float,
r_in: float, distance: float, minor_losses: float) -> float:
"""
This function calculates the total pressure drop of your system, assuming every borehole is brought individually
to the main collector.
Parameters
----------
pipe_data : PipeData
Pipe data
fluid_data : FluidData
Fluid data
borehole_length : float
Borehole length [m]
r_in : float
Inner pipe diameter [m]
distance : float
distance from the borehole to the collector [m]
minor_losses : float
Coefficient for minor losses [-]
Returns
-------
Pressure drop : float
Pressure drop [kPa]
"""

return pipe_data.pressure_drop(fluid_data, borehole_length) + \
calculate_pressure_drop_horizontal(fluid_data, r_in, distance * 2, minor_losses)


def create_pressure_drop_curve(pipe_data: _PipeData, fluid_data: FluidData, borehole_length: float,
r_in: float, distance: float, minor_losses: float, range: float = 2,
datapoints: int = 30) -> tuple:
"""
This function calculates the pressure drop for different flow rates.
Parameters
----------
pipe_data : PipeData
Pipe data
fluid_data : FluidData
Fluid data
borehole_length : float
Borehole length [m]
r_in : float
Inner pipe diameter [m]
distance : float
distance from the borehole to the collector [m]
minor_losses : float
Coefficient for minor losses [-]
range : float
Multiplier of the flow rate for the range of the data.
datapoints : int
Number of datapoints.
Returns
-------
pressure drop, flow rates : np.ndarray, np.ndarray
Array with the pressure drops [kPa], Array with the flow rates per borehole [l/s]
"""

flow_rates = np.linspace(0, range * fluid_data.vfr, datapoints)
pressure_drops = np.zeros(flow_rates.shape)

new_fluid = copy.copy(fluid_data)

for i, val in enumerate(flow_rates):
new_fluid.vfr = val
pressure_drops[i] = calculate_total_pressure_drop(pipe_data, new_fluid, borehole_length, r_in, distance,
minor_losses)

return np.nan_to_num(pressure_drops), flow_rates
11 changes: 7 additions & 4 deletions GHEtool/VariableClasses/PipeData/CoaxialPipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def Re(self, fluid_data: FluidData) -> float:
# Reynolds number
return fluid_data.rho * V * D_h / fluid_data.mu

def pressure_drop(self, fluid_data: FluidData, borehole_depth: float) -> float:
def pressure_drop(self, fluid_data: FluidData, borehole_length: float) -> float:
"""
Calculates the pressure drop across the entire borehole.
It assumed that the U-tubes are all connected in parallel.
Expand All @@ -149,8 +149,8 @@ def pressure_drop(self, fluid_data: FluidData, borehole_depth: float) -> float:
----------
fluid_data: FluidData
Fluid data
borehole_depth : float
Borehole depth [m]
borehole_length : float
Borehole length [m]
Returns
-------
Expand All @@ -167,7 +167,10 @@ def pressure_drop(self, fluid_data: FluidData, borehole_depth: float) -> float:
# Darcy-Wiesbach friction factor
fd = gt.pipes.fluid_friction_factor_circular_pipe(
fluid_data.mfr, r_h, fluid_data.mu, fluid_data.rho, self.epsilon)
return (fd * (borehole_depth * 2) / (2 * r_h) * fluid_data.rho * V ** 2 / 2) / 1000

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

def draw_borehole_internal(self, r_b: float) -> None:
"""
Expand Down
12 changes: 7 additions & 5 deletions GHEtool/VariableClasses/PipeData/MultipleUTube.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import numpy as np
import pygfunction as gt
import matplotlib.pyplot as plt
from math import pi

from math import pi
from GHEtool.VariableClasses.PipeData._PipeData import _PipeData
from GHEtool.VariableClasses.FluidData import FluidData

Expand Down Expand Up @@ -133,7 +133,7 @@ def Re(self, fluid_data: FluidData) -> float:
(pi * self.r_in ** 2)
return fluid_data.rho * u * self.r_in * 2 / fluid_data.mu

def pressure_drop(self, fluid_data: FluidData, borehole_depth: float) -> float:
def pressure_drop(self, fluid_data: FluidData, borehole_length: float) -> float:
"""
Calculates the pressure drop across the entire borehole.
It assumed that the U-tubes are all connected in parallel.
Expand All @@ -142,8 +142,8 @@ def pressure_drop(self, fluid_data: FluidData, borehole_depth: float) -> float:
----------
fluid_data: FluidData
Fluid data
borehole_depth : float
Borehole depth [m]
borehole_length : float
Borehole length [m]
Returns
-------
Expand All @@ -161,7 +161,9 @@ def pressure_drop(self, fluid_data: FluidData, borehole_depth: float) -> float:
A = pi * self.r_in ** 2
V = (fluid_data.vfr / 1000) / A / self.number_of_pipes

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

def draw_borehole_internal(self, r_b: float) -> None:
"""
Expand Down
6 changes: 3 additions & 3 deletions GHEtool/VariableClasses/PipeData/_PipeData.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def Re(self, fluid_data: FluidData) -> float:
"""

@abc.abstractmethod
def pressure_drop(self, fluid_data: FluidData, borehole_depth: float) -> float:
def pressure_drop(self, fluid_data: FluidData, borehole_length: float) -> float:
"""
Calculates the pressure drop across the entire borehole.
It assumed that the U-tubes are all connected in parallel.
Expand All @@ -90,8 +90,8 @@ def pressure_drop(self, fluid_data: FluidData, borehole_depth: float) -> float:
----------
fluid_data: FluidData
Fluid data
borehole_depth : float
Borehole depth [m]
borehole_length : float
Borehole length [m]
Returns
-------
Expand Down
6 changes: 3 additions & 3 deletions GHEtool/test/unit-tests/test_pipedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ def test_pressure_drop():
fluid_data = FluidData(0.3, 0.568, 998, 4180, 1e-3)
single = MultipleUTube(1, 0.02, 0.02, 0.4, 0.05, 1)
double = MultipleUTube(1, 0.013, 0.016, 0.4, 0.05, 2)
assert np.isclose(single.pressure_drop(fluid_data, 100), 4.4688388696204555)
assert np.isclose(double.pressure_drop(fluid_data, 100), 10.339838859988387)
assert np.isclose(single.pressure_drop(fluid_data, 100), 4.474549607676448)
assert np.isclose(double.pressure_drop(fluid_data, 100), 10.347836812519452)
coaxial = CoaxialPipe(r_in_in, r_in_out, r_out_in, r_out_out, k_p, k_g, is_inner_inlet=True)
assert np.isclose(coaxial.pressure_drop(fluid_data, 100), 0.16366613552554135)
assert np.isclose(coaxial.pressure_drop(fluid_data, 100), 0.1639237572210245)


def test_repr_():
Expand Down
35 changes: 35 additions & 0 deletions GHEtool/test/unit-tests/test_pressure_drop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import numpy as np

from GHEtool import *
from GHEtool.Methods.pressure_drop_calculation import calculate_pressure_drop_horizontal, calculate_total_pressure_drop, \
create_pressure_drop_curve


def test_horizontal():
fluid_data = FluidData(0.2, 0.568, 998, 4180, 1e-3)

assert np.isclose(calculate_pressure_drop_horizontal(fluid_data, 0.02 - 0.0037 / 2, 15, 0), 0.26307939880441045)
assert np.isclose(calculate_pressure_drop_horizontal(fluid_data, 0.02 - 0.0037 / 2, 15, 2), 0.3005010707434382)


def test_total_pressure_drop():
single_u = SingleUTube(1.5, 0.013, 0.016, 0.4, 0.035)
double_u = DoubleUTube(1.5, 0.013, 0.016, 0.4, 0.035)
fluid_data = FluidData(0.3, 0.568, 998, 4180, 1e-3)

assert np.isclose(calculate_total_pressure_drop(single_u, fluid_data, 100, 0.02 - 0.0037 / 2, 10, 2),
35.307092460895696)
assert np.isclose(calculate_total_pressure_drop(double_u, fluid_data, 100, 0.02 - 0.0037 / 2, 10, 2),
11.139813565855187)


def test_range_pressure_drop():
single_u = SingleUTube(1.5, 0.013, 0.016, 0.4, 0.035)
fluid_data = FluidData(0.2, 0.568, 998, 4180, 1e-3)

pressure, _ = create_pressure_drop_curve(single_u, fluid_data, 100, 0.02 - 0.0037 / 2, 10, 2)
assert np.allclose(pressure, np.array(
[0., 0.2531815, 0.50685423, 0.76101819, 1.90189987, 2.7952022, 3.8125133, 4.961455, 6.23750754, 7.63693955,
9.15659304, 10.79374378, 12.54600583, 14.41126361, 16.38762198, 18.4733661, 20.6669424, 22.96692063,
25.37198565, 27.88092014, 30.49259237, 33.20594602, 36.01999211, 38.93380122, 41.94649778, 45.05725469,
48.26528879, 51.56985689, 54.97025229, 58.46580177]))
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = GHEtool
version = 2.3.1
version = 2.3.2dev0
author = Wouter Peere
author_email = [email protected]
description = Python package for borefield sizing
Expand Down

0 comments on commit b58cdd2

Please sign in to comment.