|
| 1 | +import copy |
| 2 | + |
| 3 | +import numpy as np |
| 4 | +import pygfunction as gt |
| 5 | + |
| 6 | +from GHEtool.VariableClasses.PipeData._PipeData import _PipeData |
| 7 | +from GHEtool.VariableClasses.FluidData._FluidData import _FluidData |
| 8 | +from GHEtool.VariableClasses.FlowData.ConstantFlowRate import ConstantFlowRate |
| 9 | +from GHEtool.VariableClasses.FlowData._FlowData import _FlowData |
| 10 | +from math import pi |
| 11 | + |
| 12 | + |
| 13 | +class PressureDrop: |
| 14 | + |
| 15 | + def __init__(self, pipe_data: _PipeData, fluid_data: _FluidData, flow_data: _FlowData, minor_losses_borehole: float, |
| 16 | + borehole_length: float, r_in_lateral: float, distance_lateral: float, minor_losses_lateral: float, |
| 17 | + r_in_main: float, distance_main: float, minor_losses_main: float, |
| 18 | + nb_of_boreholes: int, series_factor: int, tichelmann_factor: int, **kwargs): |
| 19 | + """ |
| 20 | +
|
| 21 | + Parameters |
| 22 | + ---------- |
| 23 | + pipe_data : Pipe data |
| 24 | + Pipe data class |
| 25 | + fluid_data : Fluid data |
| 26 | + Fluid data class |
| 27 | + flow_data : Flow data |
| 28 | + Flow data class |
| 29 | + minor_losses_borehole : float |
| 30 | + Minor losses in the borehole (e.g. connections to the horizontal pipe) [-] |
| 31 | + borehole_length : float |
| 32 | + Length of the borehole [m] |
| 33 | + r_in_lateral : float |
| 34 | + Inner radius of the lateral connection between the borehole and the manifold [m] |
| 35 | + distance_lateral : float |
| 36 | + Distance between the borehole to the manifold [m] |
| 37 | + minor_losses_lateral : float |
| 38 | + Minor losses in the lateral connection between the borehole and the manifold (e.g. the connection |
| 39 | + to the manifold) [-] |
| 40 | + r_in_main : float |
| 41 | + Inner radius of the main header between the manifold and the plant room [m] |
| 42 | + distance_main : float |
| 43 | + Distance between the manifold and the plant room [m] |
| 44 | + minor_losses_main : float |
| 45 | + Minor losses in the main header [-] |
| 46 | + nb_of_boreholes : int |
| 47 | + Number of boreholes in the borefield [-] |
| 48 | + series_factor : int |
| 49 | + Number of boreholes in series [-] |
| 50 | + tichelmann_factor : int |
| 51 | + Number of boreholes in Tichelmann [-] |
| 52 | + """ |
| 53 | + self.pipe_data = pipe_data |
| 54 | + self.fluid_data = fluid_data |
| 55 | + self.flow_data = flow_data |
| 56 | + self.borehole_length = borehole_length |
| 57 | + self.minor_losses_borehole = minor_losses_borehole |
| 58 | + self.r_in_lateral = r_in_lateral |
| 59 | + self.distance_lateral = distance_lateral |
| 60 | + self.minor_losses_lateral = minor_losses_lateral |
| 61 | + self.r_in_main = r_in_main |
| 62 | + self.distance_main = distance_main |
| 63 | + self.minor_losses_main = minor_losses_main |
| 64 | + self.nb_of_boreholes = nb_of_boreholes |
| 65 | + self.series_factor = series_factor |
| 66 | + self.tichelmann_factor = tichelmann_factor |
| 67 | + |
| 68 | + def calculate_pressure_drop_borehole(self, **kwargs) -> float: |
| 69 | + """ |
| 70 | + This function calculates the pressure drop inside the borehole. |
| 71 | +
|
| 72 | + Returns |
| 73 | + ------- |
| 74 | + Pressure drop in kPa |
| 75 | + """ |
| 76 | + return self.pipe_data.pressure_drop(self.fluid_data, self.flow_data, self.borehole_length, **kwargs) |
| 77 | + |
| 78 | + def calculate_pressure_drop_lateral(self, **kwargs) -> float: |
| 79 | + """ |
| 80 | + This function calculates the pressure drop in the lateral pipes, i.e. the pipes between the borehole and |
| 81 | + the manifold. |
| 82 | +
|
| 83 | + Returns |
| 84 | + ------- |
| 85 | + Pressure drop in kPa |
| 86 | + """ |
| 87 | + |
| 88 | + # Darcy fluid factor |
| 89 | + fd = gt.pipes.fluid_friction_factor_circular_pipe( |
| 90 | + self.flow_data.mfr(fluid_data=self.fluid_data, **kwargs) * self.series_factor * self.tichelmann_factor, |
| 91 | + self.r_in_lateral, |
| 92 | + self.fluid_data.mu(**kwargs), |
| 93 | + self.fluid_data.rho(**kwargs), |
| 94 | + 1e-6) |
| 95 | + A = pi * self.r_in_lateral ** 2 |
| 96 | + V = (self.flow_data.vfr(fluid_data=self.fluid_data, |
| 97 | + **kwargs) / 1000) / A * self.series_factor * self.tichelmann_factor |
| 98 | + |
| 99 | + # distance_later * 2 for back and forth |
| 100 | + return ((fd * self.distance_lateral * 2 / ( |
| 101 | + 2 * self.r_in_lateral) + self.minor_losses_lateral) * self.fluid_data.rho( |
| 102 | + **kwargs) * V ** 2 / 2) / 1000 |
| 103 | + |
| 104 | + def calculate_pressure_drop_main(self, **kwargs) -> float: |
| 105 | + """ |
| 106 | + This function calculates the pressure drop in the main header, i.e. between the manifold and the plant room. |
| 107 | +
|
| 108 | + Returns |
| 109 | + ------- |
| 110 | + Pressure drop in kPa |
| 111 | + """ |
| 112 | + # Darcy fluid factor |
| 113 | + fd = gt.pipes.fluid_friction_factor_circular_pipe( |
| 114 | + self.flow_data.mfr(fluid_data=self.fluid_data, **kwargs) * self.nb_of_boreholes / self.series_factor, |
| 115 | + self.r_in_main, |
| 116 | + self.fluid_data.mu(**kwargs), |
| 117 | + self.fluid_data.rho(**kwargs), |
| 118 | + 1e-6) |
| 119 | + A = pi * self.r_in_main ** 2 |
| 120 | + V = (self.flow_data.vfr(fluid_data=self.fluid_data, |
| 121 | + **kwargs) / 1000) / A * self.nb_of_boreholes / self.series_factor |
| 122 | + |
| 123 | + # distance_later * 2 for back and forth |
| 124 | + return ((fd * self.distance_main * 2 / ( |
| 125 | + 2 * self.r_in_main) + self.minor_losses_main) * self.fluid_data.rho( |
| 126 | + **kwargs) * V ** 2 / 2) / 1000 |
| 127 | + |
| 128 | + def calculate_total_pressure_drop(self, **kwargs) -> float: |
| 129 | + """ |
| 130 | + This function calculates the total pressure drop of the borefield. |
| 131 | +
|
| 132 | + Returns |
| 133 | + ------- |
| 134 | + Pressure drop in kPa |
| 135 | + """ |
| 136 | + return self.calculate_pressure_drop_borehole(**kwargs) + \ |
| 137 | + self.calculate_pressure_drop_lateral(**kwargs) + \ |
| 138 | + self.calculate_pressure_drop_main(**kwargs) |
| 139 | + |
| 140 | + def create_pressure_drop_curve(self, range: float = 2, datapoints: int = 30, **kwargs): |
| 141 | + """ |
| 142 | + This function calculates the total pressure drop for different flow rates. |
| 143 | +
|
| 144 | + Parameters |
| 145 | + ---------- |
| 146 | + range : float |
| 147 | + Multiplier of the flow rate for the range of the data. |
| 148 | + datapoints : int |
| 149 | + Number of datapoints. |
| 150 | +
|
| 151 | + Returns |
| 152 | + ------- |
| 153 | + pressure drop in the borehole, pressure drop in the lateral pipes, pressure drop in the main header, flow rates : np.ndarray, np.ndarray, np.ndarray, np.ndarray |
| 154 | + Array with the pressure drops in the borehole [kPa], Array with the pressure drops in the lateral pipe [kPa], Array with the pressure drops in the main header [kPa], Array with the flow rates per borehole [l/s] |
| 155 | + """ |
| 156 | + # backup |
| 157 | + flow_backup = copy.copy(self.flow_data) |
| 158 | + |
| 159 | + flow_rates = np.linspace(0, range * self.flow_data.vfr(fluid_data=self.fluid_data, **kwargs), datapoints) |
| 160 | + pressure_drops_pipe = np.zeros(flow_rates.shape) |
| 161 | + pressure_drops_lateral = np.zeros(flow_rates.shape) |
| 162 | + pressure_drops_main = np.zeros(flow_rates.shape) |
| 163 | + |
| 164 | + for i, val in enumerate(flow_rates): |
| 165 | + self.flow_data = ConstantFlowRate(vfr=val) |
| 166 | + pressure_drops_pipe[i] = self.calculate_pressure_drop_borehole(**kwargs) |
| 167 | + pressure_drops_lateral[i] = self.calculate_pressure_drop_lateral(**kwargs) |
| 168 | + pressure_drops_main[i] = self.calculate_pressure_drop_main(**kwargs) |
| 169 | + |
| 170 | + # reset backup |
| 171 | + self.flow_data = flow_backup |
| 172 | + return np.nan_to_num(pressure_drops_pipe), np.nan_to_num(pressure_drops_lateral), \ |
| 173 | + np.nan_to_num(pressure_drops_main), flow_rates |
0 commit comments