From 9ae9245de705636146ccdbdf52f12e7093ddf412 Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Mon, 8 Nov 2021 14:56:26 -0600 Subject: [PATCH 1/8] make todo list for segment ratios --- pygfunction/utilities.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pygfunction/utilities.py b/pygfunction/utilities.py index 9084159d..ad888fa7 100644 --- a/pygfunction/utilities.py +++ b/pygfunction/utilities.py @@ -39,6 +39,8 @@ def segment_ratios(nSegments, end_length_ratio=0.02): extraction boreholes. PhD Thesis. University of Lund, Department of Mathematical Physics. Lund, Sweden. """ + # TODO: End length ratio of 0 < alpha < 0.5 should apply to all cases + # TODO: allow nSegments==2 and nSegments==1, but warn user for override about end_length_ratio def is_even(n): "Returns True if n is even." return not(n & 0x1) From 2e63e8e0b1abffc824301c4da4fb3a323a001d84 Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Mon, 8 Nov 2021 15:00:54 -0600 Subject: [PATCH 2/8] allow nSegments>=1 --- pygfunction/utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygfunction/utilities.py b/pygfunction/utilities.py index ad888fa7..2c036199 100644 --- a/pygfunction/utilities.py +++ b/pygfunction/utilities.py @@ -44,7 +44,7 @@ def segment_ratios(nSegments, end_length_ratio=0.02): def is_even(n): "Returns True if n is even." return not(n & 0x1) - assert nSegments >= 3 and isinstance(nSegments, int), \ + assert nSegments >= 1 and isinstance(nSegments, int), \ "The number of segments `nSegments` should be greater or equal " \ "to 3 and of type int." assert end_length_ratio > 0. and isinstance(end_length_ratio, (float, np.floating)), \ From 2ee8cb6a327be3a402c19de262ae23abf5d1b937 Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Mon, 8 Nov 2021 15:05:11 -0600 Subject: [PATCH 3/8] update warning about 0 < alpha < 0.5 --- pygfunction/utilities.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pygfunction/utilities.py b/pygfunction/utilities.py index 2c036199..546aaf78 100644 --- a/pygfunction/utilities.py +++ b/pygfunction/utilities.py @@ -47,16 +47,14 @@ def is_even(n): assert nSegments >= 1 and isinstance(nSegments, int), \ "The number of segments `nSegments` should be greater or equal " \ "to 3 and of type int." - assert end_length_ratio > 0. and isinstance(end_length_ratio, (float, np.floating)), \ + assert 0. < end_length_ratio < 0.5 and \ + isinstance(end_length_ratio, (float, np.floating)), \ "The end-length-ratio `end_length_ratio` should be greater than " \ - "0. and of type float." + "0, less than 0.5 (0 < end_length_ratio < 0.5) and of type float." # If nSegments == 3, then the middle segment is simply the remainder of the # length if nSegments == 3: - assert end_length_ratio < 0.5, \ - "For nSegments == 3, the end-length-ratio `end_length_ratio` " \ - "should be less than 0.5." segment_ratios = np.array( [end_length_ratio, 1 - 2 * end_length_ratio, From 39dd80c052670a8868d4f41ff738e3fe58ed4383 Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Mon, 8 Nov 2021 15:09:35 -0600 Subject: [PATCH 4/8] allow nSegments of 1 and 2 --- pygfunction/utilities.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pygfunction/utilities.py b/pygfunction/utilities.py index 546aaf78..d8d5c223 100644 --- a/pygfunction/utilities.py +++ b/pygfunction/utilities.py @@ -39,8 +39,6 @@ def segment_ratios(nSegments, end_length_ratio=0.02): extraction boreholes. PhD Thesis. University of Lund, Department of Mathematical Physics. Lund, Sweden. """ - # TODO: End length ratio of 0 < alpha < 0.5 should apply to all cases - # TODO: allow nSegments==2 and nSegments==1, but warn user for override about end_length_ratio def is_even(n): "Returns True if n is even." return not(n & 0x1) @@ -52,14 +50,26 @@ def is_even(n): "The end-length-ratio `end_length_ratio` should be greater than " \ "0, less than 0.5 (0 < end_length_ratio < 0.5) and of type float." + if nSegments == 1: + warnings.warn('nSegments = 1 has been provided. The ' + '`end_length_ratio` will be over-ridden. One segment ' + 'ratio of 1.0 will be returned.') + return np.array([1.0]) + elif nSegments == 2: + warnings.warn('nSegments = 2 ahs been provided. The ' + '`end_length_ratio` will be over-ridden. Two segment ' + 'ratios of [0.5, 0.5] will be returned.') + return np.array([0.5, 0.5]) # If nSegments == 3, then the middle segment is simply the remainder of the # length - if nSegments == 3: + elif nSegments == 3: segment_ratios = np.array( [end_length_ratio, 1 - 2 * end_length_ratio, end_length_ratio]) return segment_ratios + else: + pass # If end_length_ratio == 1 / nSegments, then the discretization is # uniform From 367991b097bd1714ada45aef4d3545383e9123ef Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Mon, 8 Nov 2021 15:12:48 -0600 Subject: [PATCH 5/8] update warning message for nSegments==1 --- pygfunction/utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygfunction/utilities.py b/pygfunction/utilities.py index d8d5c223..ba70e932 100644 --- a/pygfunction/utilities.py +++ b/pygfunction/utilities.py @@ -53,7 +53,7 @@ def is_even(n): if nSegments == 1: warnings.warn('nSegments = 1 has been provided. The ' '`end_length_ratio` will be over-ridden. One segment ' - 'ratio of 1.0 will be returned.') + 'ratio of [1.0] will be returned.') return np.array([1.0]) elif nSegments == 2: warnings.warn('nSegments = 2 ahs been provided. The ' From 32d8422b431889e4db17686870d31499909a791a Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Mon, 8 Nov 2021 15:21:32 -0600 Subject: [PATCH 6/8] document #159 in changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b332fd43..654a2859 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ * [Issue 99](https://github.com/MassimoCimmino/pygfunction/issues/99) - Fixed an issue where `MultipleUTube._continuity_condition()` and `MultipleUTube._general_solution()` returned complex valued coefficient matrices. * [Issue 130](https://github.com/MassimoCimmino/pygfunction/issues/130) - Fix incorrect initialization of variables `_mix_out` and `_mixing_m_flow` in `Network`. * [Issue 155](https://github.com/MassimoCimmino/pygfunction/issues/155) - Fix incorrect initialization of variables in `Network` and `_BasePipe`. Stored variables are now initialized as `numpy.nan` instead of `numpy.empty`. +* [Issue 159](https://github.com/MassimoCimmino/pygfunction/issues/159) - Fix `segment_ratios` function in the `utilities` module to always expect 0 < `end_length_ratio` < 0.5, and allows for `nSegments=1` or `nSegments=2`. If 1<=`nSegments`<3 then the user is warned that the `end_length_ratio` parameter is being over-ridden. ## Version 2.0.0 (2021-05-22) From 3ecf95b86288634b2da901b8b8667e6d11f21c17 Mon Sep 17 00:00:00 2001 From: Massimo Cimmino Date: Tue, 9 Nov 2021 10:36:45 -0500 Subject: [PATCH 7/8] Review PR #136 - Corrected typos. - Removed warning for nSegments=1, since segment_ratios = [1.] is the only valid value in this case. - Added some comments. - Clarified the warning for factor < 1 to better inform the user on how to resolve the issue. --- pygfunction/utilities.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pygfunction/utilities.py b/pygfunction/utilities.py index ba70e932..96edf24f 100644 --- a/pygfunction/utilities.py +++ b/pygfunction/utilities.py @@ -44,19 +44,18 @@ def is_even(n): return not(n & 0x1) assert nSegments >= 1 and isinstance(nSegments, int), \ "The number of segments `nSegments` should be greater or equal " \ - "to 3 and of type int." + "to 1 and of type int." assert 0. < end_length_ratio < 0.5 and \ isinstance(end_length_ratio, (float, np.floating)), \ "The end-length-ratio `end_length_ratio` should be greater than " \ "0, less than 0.5 (0 < end_length_ratio < 0.5) and of type float." + # If nSegments == 1, the only segment covers the entire length if nSegments == 1: - warnings.warn('nSegments = 1 has been provided. The ' - '`end_length_ratio` will be over-ridden. One segment ' - 'ratio of [1.0] will be returned.') return np.array([1.0]) + # If nSegments == 2, split the borehole in two even segments elif nSegments == 2: - warnings.warn('nSegments = 2 ahs been provided. The ' + warnings.warn('nSegments = 2 has been provided. The ' '`end_length_ratio` will be over-ridden. Two segment ' 'ratios of [0.5, 0.5] will be returned.') return np.array([0.5, 0.5]) @@ -144,7 +143,7 @@ def is_even(n): 'A decreasing segment ratios discretization was found by ' 'utilities.segment_ratios(). Better accuracy is expected for ' 'increasing segment ratios. Consider decreasing the ' - 'end-length-ratio.') + 'end-length-ratio such that end_length_ratio < 1 / nSegments.') return segment_ratios From 2eda93874d61702f6a967605620500d925a1761e Mon Sep 17 00:00:00 2001 From: Massimo Cimmino Date: Tue, 9 Nov 2021 10:41:27 -0500 Subject: [PATCH 8/8] Allow end_length_ratio = 0.5 for nSegments = 2 --- pygfunction/utilities.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pygfunction/utilities.py b/pygfunction/utilities.py index 96edf24f..4b77a157 100644 --- a/pygfunction/utilities.py +++ b/pygfunction/utilities.py @@ -45,7 +45,7 @@ def is_even(n): assert nSegments >= 1 and isinstance(nSegments, int), \ "The number of segments `nSegments` should be greater or equal " \ "to 1 and of type int." - assert 0. < end_length_ratio < 0.5 and \ + assert nSegments <= 2 or 0. < end_length_ratio < 0.5 and \ isinstance(end_length_ratio, (float, np.floating)), \ "The end-length-ratio `end_length_ratio` should be greater than " \ "0, less than 0.5 (0 < end_length_ratio < 0.5) and of type float." @@ -55,9 +55,10 @@ def is_even(n): return np.array([1.0]) # If nSegments == 2, split the borehole in two even segments elif nSegments == 2: - warnings.warn('nSegments = 2 has been provided. The ' - '`end_length_ratio` will be over-ridden. Two segment ' - 'ratios of [0.5, 0.5] will be returned.') + if not np.abs(end_length_ratio - 0.5) < 1e-6: + warnings.warn('nSegments = 2 has been provided. The ' + '`end_length_ratio` will be over-ridden. Two ' + 'segment ratios of [0.5, 0.5] will be returned.') return np.array([0.5, 0.5]) # If nSegments == 3, then the middle segment is simply the remainder of the # length