From d335d14f1129bd70c8573ee3dfbe9af1ad3edd3f Mon Sep 17 00:00:00 2001 From: Massimo Cimmino Date: Mon, 24 Jan 2022 13:43:39 -0500 Subject: [PATCH 1/2] Change integral bounds --- pygfunction/heat_transfer.py | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/pygfunction/heat_transfer.py b/pygfunction/heat_transfer.py index 2eead48a..14aada3a 100644 --- a/pygfunction/heat_transfer.py +++ b/pygfunction/heat_transfer.py @@ -136,9 +136,14 @@ def finite_line_source( reaSource=reaSource, imgSource=imgSource, N=N) else: if not approximation: - h = np.stack( - [0.5 / H2 * quad(f, 1.0 / np.sqrt(4.0*alpha*t), np.inf)[0] for t in time], - axis=-1) + # Lower bound of integration + a = 1.0 / np.sqrt(4.0*alpha*time) + # Upper bound of integration + b = np.concatenate(([np.inf], a[:-1])) + h = np.cumsum(np.stack( + [0.5 / H2 * quad(f, a_i, b_i)[0] + for t, a_i, b_i in zip(time, a, b)], + axis=-1), axis=-1) else: h = finite_line_source_approximation( time, alpha, dis, H1, D1, H2, D2, @@ -396,10 +401,14 @@ def finite_line_source_vectorized( a = 1.0 / np.sqrt(4.0*alpha*time) h = 0.5 / H2 * quad_vec(f, a, np.inf)[0] else: - h = np.stack( - [0.5 / H2 * quad_vec(f, 1.0 / np.sqrt(4.0*alpha*t), np.inf)[0] - for t in time], - axis=-1) + # Lower bound of integration + a = 1.0 / np.sqrt(4.0*alpha*time) + # Upper bound of integration + b = np.concatenate(([np.inf], a[:-1])) + h = np.cumsum(np.stack( + [0.5 / H2 * quad_vec(f, a_i, b_i)[0] + for t, a_i, b_i in zip(time, a, b)], + axis=-1), axis=-1) else: h = finite_line_source_approximation( time, alpha, dis, H1, D1, H2, D2, reaSource=reaSource, @@ -506,10 +515,14 @@ def finite_line_source_equivalent_boreholes_vectorized( a = 1.0 / np.sqrt(4.0*alpha*time) h = 0.5 / (N2*H2) * quad_vec(f, a, np.inf)[0] else: - h = np.stack( - [0.5 / (N2*H2) * quad_vec(f, 1.0 / np.sqrt(4.0*alpha*t), np.inf)[0] - for t in time], - axis=-1) + # Lower bound of integration + a = 1.0 / np.sqrt(4.0*alpha*time) + # Upper bound of integration + b = np.concatenate(([np.inf], a[:-1])) + h = np.cumsum(np.stack( + [0.5 / (N2*H2) * quad_vec(f, a_i, b_i)[0] + for t, a_i, b_i in zip(time, a, b)], + axis=-1), axis=-1) return h From 1402a01f853976c617aa3b14b365b2bdef0054ef Mon Sep 17 00:00:00 2001 From: Massimo Cimmino Date: Mon, 24 Jan 2022 13:43:47 -0500 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72ed73a4..4da0c751 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * [Issue 152](https://github.com/MassimoCimmino/pygfunction/issues/152) - Vectorized `coefficients_temperature` and `_general_solution` in `pipe` objects to accept depths `z` as an array. This speeds up calculations for `get_temperature` and `get_borehole_heat_extraction_rate` class methods. * [Issue 183](https://github.com/MassimoCimmino/pygfunction/issues/183) - Vectorized `pipes.multipole()` and `pipes._Fmk()` to decrease the calculation time of `pipes.thermal_resistances()`. A `memoization` technique is implemented to reduce computation time for repeated function calls to further speed-up the initialization of `Pipe` and `Network` objects. * [Issue 198](https://github.com/MassimoCimmino/pygfunction/issues/198) - Refactored the `'detailed'` solver to evaluate same-borehole thermal response factors in a single call to `finite_line_source_vectorized()`. This speeds up calculations of *g*-functions using the `'detailed'` solver. +* [Issue 199](https://github.com/MassimoCimmino/pygfunction/issues/199) - Changed the integral bounds to avoid repeated evaluation of integrals over semi-infinite intervals. This speeds up calculations of *g*-functions using all solvers and the evaluation of the finite line source solution with `time` as an array. ### Other changes