Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimal discretization of segments along boreholes #153

Open
MassimoCimmino opened this issue Oct 20, 2021 · 7 comments · May be fixed by #245
Open

Optimal discretization of segments along boreholes #153

MassimoCimmino opened this issue Oct 20, 2021 · 7 comments · May be fixed by #245
Milestone

Comments

@MassimoCimmino
Copy link
Owner

MassimoCimmino commented Oct 20, 2021

#136 showed that the optimal segment_ratios that minimizes the error on the g-function is dependent on the number of segments (and potentially on the bore field configuration).

This issue is to find optimal parameters (end_length_ratio) for the borehole discretization. A solution would be to generate a table that gives the optimal parameter for each value of nSegments up to reasonable max value (e.g. nSegments=128). This could be accessed by setting end_length_ratio='optimal' as an input to utilities.segment_ratios().

MassimoCimmino added a commit that referenced this issue Nov 1, 2021
PR #136 introduces a `segment_lengths` parameter to the `gFunction`
class, supported by the addition of the attribute to the `Borehole`,
`_BasePipe`, and `Network` classes. This parameter enables a non-
uniform discretization of segments along the lengths of the boreholes
for calculations (including g-functions).

  - All g-function solvers are updated to support the feature. The
    identification of similarities had to be adjusted to verify that
	pairs of boreholes share the same discretization before applying
	thermal response factors to multiple pairs.
  - To conserve calculation speed in the evaluation of g-functions
    using equal segments or identical discretization along boreholes,
	`_equal_segment_ratios` and `_uniform_segment_ratios` boolean
	attributes are added to the `gFunction`class.
  - The ratio `1 / (2 * H_2)` is moved out of the integrand functions
    of the finite line source solution. `H_2` is now a vector and slows
	down the calculations if considered in `quad` and `quad_vec`.
  - A `segment_ratios()` function is added to the `utilities` module to
    facilitate the discretization of boreholes. Default parameters have
	been set to achieve acceptable accuracy. Issue #153 will determine
	optimal parameters for borehole discretization.
  - Tests are extended to cover the new features.

Co-authored-by: Massimo Cimmino <[email protected]>
Co-authored-by: Jack Cook <[email protected]>
This was referenced Nov 8, 2021
@MassimoCimmino
Copy link
Owner Author

MassimoCimmino commented Nov 14, 2021

It seems the optimal discretization is dependent on the boundary condition and on the borehole spacing. Here is some initial results for large rectangular fields using the 'equivalent' solver and nSegments=8. The reference g-function is calculated using a uniform discretization of nSegments=64.

Figure_1

@MassimoCimmino

This comment was marked as outdated.

@jo-isiordia
Copy link

jo-isiordia commented Nov 21, 2022

@MassimoCimmino, continuing with your analysis, the optimal discretization is dependent on the number of segments, as well as the borehole’s configuration, including the borehole’s length, spacing, and the number of boreholes within the field. An initial evaluation of the error on the g-function, with a discretization using the current 2% end-length ratio is shown in the following figure, where the maximum relative error is presented on the vertical axis and the field characteristics, which in this case is the non-dimensional coefficient B/H, are on the horizontal axis, whereas the number of boreholes in the field is color-mapped.
Non-optimized g-function error - 8 segments
Based on these initial results, an “optimal” end-length ratio (ELR) depending on the number of segments that allows the minimization of the maximum relative error found on 11,440 different rectangular field configurations is proposed, considering a BC-UBWT (boundary condition of equal wall temperature throughout the length and for each borehole) using the “equivalent” solver, varying the borefield’s characteristics as follows.

  • Length of borehole (H) from 50 m. to 300 m. with a step of 10 m.
  • Bore to bore spacing (B) from 3 m. to 10 m. with a step of 2 m.
  • Number of boreholes from 2 by 1 to 20 by 20 in a rectangular array.
  • Time from 100 h to 1,000 years with 25 non-uniform steps using time_geometric from the pygfunction utilities module.

Other constant parameters are the buried depth = 4 m., the borehole radius = 0.075 m., and the ground’s thermal diffusivity = 1e-6 m2/s.
Two optimization problems have been solved by using the scipy.optimize package, one to find an “optimal” end-length ratio that is able to minimize the maximum value of the whole set of relative errors of the 11,440 configurations (“Proposed ELR”) and another one to find an optimal end-length ratio for every specific borefield configuration (“Optimized ELR”) only to compare how far from the “best case scenario” the results are, when using a single end-length ratio for all borefield configurations.
The objective function related to the "proposed ELR" could be represented as:
image
Where g_i (t) is the calculated g-function for the i-th configuration at the time t.
g_(ref,i) (t) is the reference g-function for the i-th configuration at the time t.
C is the total number of borehole’s configurations being analyzed.
The following figures show the results of the second optimization problem, finding an Optimal end-length ratio for each configuration. At the left hand side there is a similar graph as the first one in this comment, comparing the maximum relative error found per each borefield configuration, and to the right hand side, the figure shows the different end-length ratio of each configuration.
Optimal ELR g-function error and optimal ELR - 8 segments
The following figure shows, in the vertical axis, the maximum relative error found on g-functions for borefields with an 8 segment discretization against the non-dimensional B/H coefficient in the horizontal axis, using three different end-length ratios.

  1. The current constant 2% end-length ratio, in red.
  2. The optimized end-length ratio for each borefield configuration, which has been calculated for each one of the 11,440 configurations, in purple.
  3. The proposed end-length ratio (0.93% for the 8 segments discretization), a single value that should minimize the overall maximum relative error for all the configurations being studied, in blue.

image
The points on the figure represent the maximum relative error found for all the configurations for each B/H value (spacing between boreholes divided by length of the boreholes), which is one of the non-dimensional coefficients used to calculate the g-functions, whereas the curves are the trend-lines that better represents the behavior of these points.
Something that is important to notice, even though it is not depicted in the previous figure, is that the maximum relative error was found at the maximum time value used to evaluate the g-functions (t_max = 1,000 years) for every configuration, and usually for fields containing the greatest number of boreholes.
It can be noticed that there are some regions where the “non-optimized ELR” performs better than the “proposed ELR”, using the latter allows the user to make sure that the relative error will not be greater than 1.6%, at least for the range of borefield configurations being studied, instead of the 4% related to small B/H values, which translates to small bore to bore spacing and long boreholes.
The reference g-function has been calculated for 43,471 borefield configurations, but with a non-uniform discretization of 8 segments using segment_ratios from the pygfunction utilities module, and then dividing 6 times each segment, resulting in 48 segments.
The following figure shows the RMSE (root-mean-square error) of the g-functions evaluated over the 25-time steps, using the proposed end-length ratio of 0.93%, for a reduced amount of borefield configurations, that represent the initial set of 11,440 borefields.
image
The varying characteristics of the borefields used to calculate the RMSE are:

  • Length of borehole (H): 50 m., 200 m., and 300 m.
  • Bore to bore spacing (B): 3 m., 6 m., and 10 m.
  • Number of boreholes along the horizontal axis of the rectangular array: 2, 10 and 20.
  • Number of boreholes along the vertical axis of the rectangular array: 1, 10 and 20.
  • Time from 100 h to 1,000 years with 25 non-uniform steps using time_geometric from the pygfunction utilities module.

All the possible combinations of the previous characteristics result in a total of 54 borehole configurations depicting the overall behavior of the 11,440 initial configurations.
It can be seen from the results, that the maximum RMSE is below 2 units (same units as the g-functions) for the configurations with many boreholes and small B/H values. The RMSE was calculated as follows.
image
Where T is the number of time steps.
t_0 is the initial time step (100 h) to evaluate the g-functions.
t_{max} is the maximum time (1,000 years) to evaluate the g-functions.
The normalized RMSE has also been calculated, as shown in the following figure.
image
Like previous results, the NRMSE is around 1.5% with a maximum of 1.9% as per the configuration of 400 boreholes, H = 300 m., and B = 10 m.
Finally, the same process has been performed for borehole’s discretization ranging from 3 to 20 segments. The results are presented in the following figure.
image
The results show that if the number of segments increases, the proposed end-length ratio decreases as well as the maximum relative error found. Besides, in the case of 3 segments, the maximum relative error is 12.8% which represents the maximum punctual error (worst case scenario). However, the NRMSE is 1.9%, which means that the overall calculated g-functions’ deviation from the reference is less than 2%. After the discretization of 5 segments, the maximum relative error drops to 4.4%, which is already low, even though the NRMSE is still 1.9%.
After 10 segments, the maximum relative error is already under 1%, so even if the discretization is more refined, this will not translate into better g-function approximations.
For the last 4 discretization cases, the proposed end-length ratio is around 0.1%, which is the proposed value for a borefield discretization with more than 20 segments.
The proposed end-length ratios that have been calculated performing the optimization of the objective function for different number of segments, are summarized in the following table.

<style> </style>
Number of segments Single value end-length ratio [%] g-function maximum relative error [%]
3 4.9815088 12.76180118
4 3.6552159 9.198007236
5 2.1154286 4.425303902
6 1.7554335 3.387627878
7 1.07976099 1.918855204
8 0.933328725 1.573007695
9 0.56647504 1.126958382
10 0.543812273 0.926026377
11 0.420806777 0.698536353
12 0.38677094 0.589718204
13 0.321749616 0.461556782
14 0.273372555 0.390246517
15 0.26220223 0.310080598
16 0.2073062 0.261352627
17 0.12950481 0.202410441
18 0.102573158 0.159855556
19 0.094044551 0.112241572
20 0.113892859 0.087696581

@MassimoCimmino
Copy link
Owner Author

@jo-isiordia This looks great! The reduction of the error seems significant.

A few things :

  • For the use of the 0.1 % end-length-ratio for nSegments > 20, could we quantify the errors? I'dlike to know when (or if) the error reaches 0.01 %.
  • How is the optimal discretization sensitive to the buried depth (D)? Are the results as good for, e.g., D = 2 m and D = 8 m?
  • Are the optimal end-length-ratio dependent on the reference discretization? More precisely, would a end-length-ratio of 0.933 % for 8 segments and refined 6 times lead to the same optimal end-length-ratio of 0.933 % for 8 segments?

@jo-isiordia
Copy link

@MassimoCimmino Following up with your comments.

  1. I have extended the analysis to reach 40 segments.

image

The figure shows a tendency of the proposed ELR to stay around 0.2% over 20 segments and the maximum relative error continues to decrease, reaching 0.01% at 32 segments. The whole set of results are shown in the table below.

<style> </style>
Number of segments Single value end-length ratio [-] g-function maximum relative error [%]
3 0.049815 12.7618
4 0.036552 9.198007
5 0.021154 4.425304
6 0.017554 3.387628
7 0.010798 1.918855
8 0.009333 1.573008
9 0.005665 1.126958
10 0.005438 0.926026
11 0.004208 0.698536
12 0.003868 0.589718
13 0.003217 0.461557
14 0.002734 0.390247
15 0.002622 0.310081
16 0.002073 0.261353
17 0.001295 0.20241
18 0.001026 0.159856
19 0.00094 0.112242
20 0.001139 0.087697
21 0.001309 0.069054
22 0.001425 0.056228
23 0.001525 0.04618
24 0.001602 0.038229
25 0.001667 0.031994
26 0.00172 0.026678
27 0.001765 0.022475
28 0.001803 0.018768
29 0.001835 0.015818
30 0.001863 0.013136
31 0.001888 0.01105
32 0.001911 0.009198
33 0.001931 0.007703
34 0.001949 0.006313
35 0.001965 0.005187
36 0.001979 0.004103
37 0.001991 0.003216
38 0.002002 0.002384
39 0.002011 0.002327
40 0.00202 0.002935
  1. The “proposed ELR” is recalculated for the same bore fields configurations but with different buried depths (2 and 8 m. besides the original one of 4m.). It seems like the results of the proposed ELR change depending on the buried depth, notoriously for bore holes with a small number of segments, as shown in the following figure, depicting the three buried depth scenarios: 2 m. in purple, 4 m. in light blue, and 8 m. in red.

image

The variations of the proposed ELR between the configurations with the smallest and the largest buried depths (red and purple dots in the figure) are 1.5, 0.2 and 0.02 percentage points for the 3, 8, and 12 segments scenarios (highlighted in red), respectively. However, the maximum relative error of the g-functions is considerably higher for smaller depths and lower for larger depths, as shown below, even using the previously “proposed ELR” values adapted for each scenario.

image

The variations of the maximum relative error of the g-functions between the configurations with the smallest and the largest buried depths (red and purple dots in the figure) are 10.9, 0.96 and 0.3 percentage points for the 3, 8, and 12 segments scenarios (highlighted in red), respectively. This error variations continue to decrease for larger number of segments, but for lower number of segments this could lead to higher relative errors than expected in the initial analysis (without considering the impact of the buried depth).

  1. Lastly, the “proposed ELR” do not seem to be affected by those changes on the initial ELR used to generate the reference g-functions. When solving the optimization problem using a reference with a discretization of 8 segments, refined 6 times and a constant ELR of 0.933%, the results are the same as previously shown.

@j-c-cook
Copy link
Contributor

j-c-cook commented Jan 7, 2023

image

It can be noticed that there are some regions where the “non-optimized ELR” performs better than the “proposed ELR”, using the latter allows the user to make sure that the relative error will not be greater than 1.6%, at least for the range of borefield configurations being studied, instead of the 4% related to small B/H values, which translates to small bore to bore spacing and long boreholes.

@jo-isiordia Thank you for your contribution. I currently have a line of questioning regarding one of your plots.

Is it true that the optimal end length ratio (ELR) is out performed by the non-optimized ELR of 2% in the B/H range of about 0.55 to 0.15? Does the curve fit create a misleading representation? If not, how then did the optimization (minimization) of the objective function result in lower accuracy? Is it possible that the algorithm found a local minima, rather than a global? Why wouldn't the "optimal" ELR be 2% in that region if it truly performs better?

@jo-isiordia
Copy link

jo-isiordia commented Jan 7, 2023

@j-c-cook I appreciate your comments, and I believe this confusion is, in part, due to the nomenclature I used for the (3) different end-length ratio scenarios as well as the trend lines on the figures.

As you just mentioned, in the range of 0.055<B/H<0.15 the Non-optimized ELR seems to outperform the other two ELR resulting from two different minimization processes, but in reality it is only the trend line generated based on the actual values (the blurred points behind the curves) that originates this misunderstanding.

I added a table down below with some B/H values corresponding to the previously mentioned range (0.055<B/H<0.15) for small and large bore fields considering an 8-segment discretization, comparing the three ELR scenarios and their corresponding relative error of the g-function for better clarity.

As you can see in the table below, the "Optimized ELR" results in the best results (lowest relative error), i.e. the closest g-functions to the reference. On the other hand, referencing my previous comment, the "Proposed ELR" does not always perform better than the "Non-optimized ELR", since they are both a constant value for each discretization case and the only difference is that with the Proposed ELR the maximum relative error found on the whole set of configurations being analyzed is minimized, which means that it performs better than the original ELR of 2% for most bore field configurations, but not all of them.

Just to clarify a bit more, the Proposed ELR is less accurate than the Optimized ELR but the disadvantage of using the latter is that it depends on the bore field's layout and characteristics such as the borehole's length, bore to bore spacing, etc. and it takes time (between 1 and 15 minutes) to calculate, compared to the Proposed ELR that only depends on the number of segments of the discretization and the outcome is most of the time better than the Non-optimized ELR results.
I hope to have answered all your questions and that everything is clearer now, but do not hesitate to ask further questions.

<style> </style>
B/H Non opt ELR error [%] Optimized ELR error [%] Proposed ELR error [%]
0.05 0.270 0.182 0.210
0.05 0.479 0.456 0.468
0.05 1.153 0.837 0.851
0.05 0.222 0.180 0.184
0.05 0.487 0.481 0.524
0.05 1.401 1.151 1.152
0.05 0.200 0.173 0.173
0.05 0.494 0.493 0.559
0.05 1.553 1.347 1.364
0.05 0.183 0.163 0.163
0.05 0.497 0.496 0.582
0.05 1.672 1.513 1.562
0.06 0.2948 0.1827 0.2264
0.06 0.4824 0.4607 0.4705
0.06 1.0807 0.8379 0.8514
0.07 0.2213 0.1856 0.1881
0.07 0.4761 0.4760 0.5477
0.07 1.3417 1.2674 1.3003
0.1 0.2950 0.1984 0.2326
0.1 0.4737 0.4693 0.4982
0.1 1.1017 1.0504 1.0680
0.1 0.2525 0.1982 0.2084
0.1 0.4596 0.4595 0.5182
0.1 1.1939 1.1764 1.2525
0.1 0.2199 0.1890 0.1905
0.1 0.4487 0.4471 0.5368
0.1 1.2792 1.2775 1.4441
0.125 0.2377 0.1967 0.2014
0.125 0.4324 0.4316 0.5039
0.125 1.2026 1.1990 1.4647
0.14 0.294 0.204 0.234
0.14 0.450 0.448 0.479
0.14 1.105 1.105 1.281

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants