-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathgfunction.py
More file actions
1768 lines (1633 loc) · 75.8 KB
/
gfunction.py
File metadata and controls
1768 lines (1633 loc) · 75.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
import warnings
from time import perf_counter
import numpy as np
from scipy.interpolate import interp1d as interp1d
from .borefield import Borefield
from .boreholes import Borehole, find_duplicates
from .networks import Network
from .solvers import (
Detailed,
Equivalent,
Similarities
)
from .utilities import (
segment_ratios,
_initialize_figure,
_format_axes
)
class gFunction(object):
"""
Class for the calculation and visualization of the g-functions of
geothermal bore fields.
This class superimposes the finite line source (FLS) solution to
estimate the g-function of a geothermal bore field. Each borehole is
modeled as a series of finite line source segments, as proposed in
[#gFunction-CimBer2014]_. Different boundary conditions and solution
methods are implemented.
Attributes
----------
boreholes_or_network : list of Borehole objects or Network object
List of boreholes included in the bore field, or network of boreholes
and pipes.
alpha : float
Soil thermal diffusivity (in m2/s).
time : float or array, optional
Values of time (in seconds) for which the g-function is evaluated. The
g-function is only evaluated at initialization if a value is provided.
Default is None.
method : str, optional
Method for the evaluation of the g-function. Should be one of
- 'similarities' :
The accelerated method of Cimmino (2018)
[#gFunction-Cimmin2018]_, using similarities in the bore field
to decrease the number of evaluations of the FLS solution.
- 'detailed' :
The classical superposition of the FLS solution. The FLS
solution is evaluated for all pairs of segments in the bore
field.
- 'equivalent' :
The equivalent borehole method of Prieto and Cimmino (2021)
[#gFunction-PriCim2021]_. Boreholes are assembled into groups
of boreholes that share similar borehole wall temperatures and
heat extraction rates. Each group is represented by an
equivalent borehole and the group-to-group thermal interactions
are calculated by the FLS solution. This is an approximation of
the 'similarities' method.
Default is 'equivalent'.
boundary_condition : str, optional
Boundary condition for the evaluation of the g-function. Should be one
of
- 'UHTR' :
**Uniform heat transfer rate**. This corresponds to boundary
condition *BC-I* as defined by Cimmino and Bernier (2014)
[#gFunction-CimBer2014]_.
- 'UBWT' :
**Uniform borehole wall temperature**. This corresponds to
boundary condition *BC-III* as defined by Cimmino and Bernier
(2014) [#gFunction-CimBer2014]_.
- 'MIFT' :
**Mixed inlet fluid temperatures**. This boundary condition was
introduced by Cimmino (2015) [#gFunction-Cimmin2015]_ for
parallel-connected boreholes and extended to mixed
configurations by Cimmino (2019) [#gFunction-Cimmin2019]_.
If not given, chosen to be 'UBWT' if a list of boreholes is provided
or 'MIFT' if a Network object is provided.
m_flow_borehole : (nInlets,) array or (nMassFlow, nInlets,) array, optional
Fluid mass flow rate into each circuit of the network. If a
(nMassFlow, nInlets,) array is supplied, the
(nMassFlow, nMassFlow,) variable mass flow rate g-functions
will be evaluated using the method of Cimmino (2024)
[#gFunction-Cimmin2024]_. Only required for the 'MIFT' boundary
condition. Only one of 'm_flow_borehole' and 'm_flow_network' can be
provided.
Default is None.
m_flow_network : float or (nMassFlow,) array, optional
Fluid mass flow rate into the network of boreholes. If an array
is supplied, the (nMassFlow, nMassFlow,) variable mass flow
rate g-functions will be evaluated using the method of Cimmino
(2024) [#gFunction-Cimmin2024]_. Only required for the 'MIFT' boundary
condition. Only one of 'm_flow_borehole' and 'm_flow_network' can be
provided.
Default is None.
cp_f : float, optional
Fluid specific isobaric heat capacity (in J/kg.degC). Only required
for the 'MIFT' boundary condition.
Default is None.
options : dict, optional
A dictionary of solver options. All methods accept the following
generic options:
nSegments : int or list, optional
Number of line segments used per borehole, or list of number of
line segments used for each borehole.
Default is 8.
segment_ratios : array, list of arrays, or callable, optional
Ratio of the borehole length represented by each segment. The
sum of ratios must be equal to 1. The shape of the array is of
(nSegments,) or list of (nSegments[i],). If
segment_ratios==None, segments of equal lengths are considered.
If a callable is provided, it must return an array of size
(nSegments,) when provided with nSegments (of type int) as an
argument, or an array of size (nSegments[i],) when provided
with an element of nSegments (of type list).
Default is :func:`utilities.segment_ratios`.
approximate_FLS : bool, optional
Set to true to use the approximation of the FLS solution of
Cimmino (2021) [#gFunction-Cimmin2021]_. This approximation
does not require the numerical evaluation of any integral. When
using the 'equivalent' solver, the approximation is only
applied to the thermal response at the borehole radius. Thermal
interaction between boreholes is evaluated using the FLS
solution.
Default is False.
nFLS : int, optional
Number of terms in the approximation of the FLS solution. This
parameter is unused if `approximate_FLS` is set to False.
Default is 10. Maximum is 25.
mQuad : int, optional
Number of Gauss-Legendre sample points for the integral over
:math:`u` in the inclined FLS solution.
Default is 11.
linear_threshold : float, optional
Threshold time (in seconds) under which the g-function is
linearized. The g-function value is then interpolated between 0
and its value at the threshold. If linear_threshold==None, the
g-function is linearized for times
`t < r_b**2 / (25 * self.alpha)`.
Default is None.
disp : bool, optional
Set to true to print progression messages.
Default is False.
profiles : bool, optional
Set to true to keep in memory the temperatures and heat
extraction rates.
Default is False.
kind : str, optional
Interpolation method used for segment-to-segment thermal
response factors. See documentation for
scipy.interpolate.interp1d.
Default is 'linear'.
dtype : numpy dtype, optional
numpy data type used for matrices and vectors. Should be one of
numpy.single or numpy.double.
Default is numpy.double.
The 'similarities' solver accepts the following method-specific
options:
disTol : float, optional
Relative tolerance on radial distance. Two distances
(d1, d2) between two pairs of boreholes are considered equal if
the difference between the two distances (abs(d1-d2)) is below
tolerance.
Default is 0.01.
tol : float, optional
Relative tolerance on length and depth. Two lengths H1, H2
(or depths D1, D2) are considered equal if
abs(H1 - H2)/H2 < tol.
Default is 1.0e-6.
The 'equivalent' solver accepts the following method-specific
options:
disTol : float, optional
Relative tolerance on radial distance. Two distances
(d1, d2) between two pairs of boreholes are considered equal if
the difference between the two distances (abs(d1-d2)) is below
tolerance.
Default is 0.01.
tol : float, optional
Relative tolerance on length and depth. Two lengths H1, H2
(or depths D1, D2) are considered equal if
abs(H1 - H2)/H2 < tol.
Default is 1.0e-6.
kClusters : int, optional
Increment on the minimum number of equivalent boreholes
determined by cutting the dendrogram of the bore field given
by the hierarchical agglomerative clustering method. Increasing
the value of this parameter increases the accuracy of the
method.
Default is 1.
Notes
-----
- The 'equivalent' solver does not support the 'MIFT' boundary condition
when boreholes are connected in series.
- The 'equivalent' solver does not support inclined boreholes.
- The g-function is linearized for times `t < r_b**2 / (25 * self.alpha)`.
The g-function value is then interpolated between 0 and its value at the
threshold.
- If the 'MIFT' boundary condition is used, only one of the
'm_flow_borehole' or 'm_flow_network' can be supplied.
References
----------
.. [#gFunction-CimBer2014] Cimmino, M., & Bernier, M. (2014). A
semi-analytical method to generate g-functions for geothermal bore
fields. International Journal of Heat and Mass Transfer, 70, 641-650.
.. [#gFunction-Cimmin2015] Cimmino, M. (2015). The effects of borehole
thermal resistances and fluid flow rate on the g-functions of geothermal
bore fields. International Journal of Heat and Mass Transfer, 91,
1119-1127.
.. [#gFunction-Cimmin2018] Cimmino, M. (2018). Fast calculation of the
g-functions of geothermal borehole fields using similarities in the
evaluation of the finite line source solution. Journal of Building
Performance Simulation, 11 (6), 655-668.
.. [#gFunction-Cimmin2019] Cimmino, M. (2019). Semi-analytical method for
g-function calculation of bore fields with series- and
parallel-connected boreholes. Science and Technology for the Built
Environment, 25 (8), 1007-1022.
.. [#gFunction-PriCim2021] Prieto, C., & Cimmino, M.
(2021). Thermal interactions in large irregular fields of geothermal
boreholes: the method of equivalent borehole. Journal of Building
Performance Simulation, 14 (4), 446-460.
.. [#gFunction-Cimmin2021] Cimmino, M. (2021). An approximation of the
finite line source solution to model thermal interactions between
geothermal boreholes. International Communications in Heat and Mass
Transfer, 127, 105496.
.. [#gFunction-Cimmin2024] Cimmino, M. (2024). g-Functions for fields of
series- and parallel-connected boreholes with variable fluid mass flow
rate and reversible flow direction. Renewable Energy, 228, 120661.
"""
def __init__(self, boreholes_or_network, alpha, time=None,
method='equivalent', boundary_condition=None,
m_flow_borehole=None, m_flow_network=None,
cp_f=None, options={}):
self.alpha = alpha
self.time = time
self.method = method
self.boundary_condition = boundary_condition
self.m_flow_borehole = m_flow_borehole
self.m_flow_network = m_flow_network
self.cp_f = cp_f
self.options = options
# Format inputs and assign default values where needed
self._format_inputs(boreholes_or_network)
# Check the validity of inputs
self._check_inputs()
# Load the chosen solver
if self.method.lower()=='similarities':
self.solver = Similarities(
self.boreholes, self.network, self.time,
self.boundary_condition, self.m_flow_borehole,
self.m_flow_network, self.cp_f, **self.options)
elif self.method.lower()=='detailed':
self.solver = Detailed(
self.boreholes, self.network, self.time,
self.boundary_condition, self.m_flow_borehole,
self.m_flow_network, self.cp_f, **self.options)
elif self.method.lower()=='equivalent':
self.solver = Equivalent(
self.boreholes, self.network, self.time,
self.boundary_condition, self.m_flow_borehole,
self.m_flow_network, self.cp_f, **self.options)
else:
raise ValueError(f"'{method}' is not a valid method.")
# If a time vector is provided, evaluate the g-function
if self.time is not None:
self.gFunc = self.evaluate_g_function(self.time)
def evaluate_g_function(self, time):
"""
Evaluate the g-function.
Parameters
----------
time : float or array
Values of time (in seconds) for which the g-function is evaluated.
Returns
-------
gFunction : float or array
Values of the g-function
"""
time = np.maximum(np.atleast_1d(time), 0.)
assert len(time) == 1 or np.all(time[:-1] <= time[1:]), \
"Time values must be provided in increasing order."
# Save time values
self.time = time
if self.solver.disp:
print(60*'-')
print(f"Calculating g-function for boundary condition : "
f"'{self.boundary_condition}'".center(60))
print(60*'-')
# Initialize chrono
tic = perf_counter()
# Evaluate g-function
self.gFunc = self.solver.solve(time, self.alpha)
toc = perf_counter()
if self.solver.disp:
print(f'Total time for g-function evaluation: '
f'{toc - tic:.3f} sec')
print(60*'-')
return self.gFunc
def visualize_g_function(self, which=None):
"""
Plot the g-function of the borefield.
Parameters
----------
which : list of tuple, optional
Tuples (i, j) of the variable mass flow rate g-functions to plot.
If None, all g-functions are plotted.
Default is None.
Returns
-------
fig : figure
Figure object (matplotlib).
"""
from ._mpl import plt
# Configure figure and axes
fig = _initialize_figure()
ax = fig.add_subplot(111)
ax.set_xlabel(r'ln$(t/t_s)$')
ax.set_ylabel(r'$g$-function')
_format_axes(ax)
# Borefield characteristic time
ts = np.mean([b.H for b in self.boreholes])**2/(9.*self.alpha)
# Dimensionless time (log)
lntts = np.log(self.time/ts)
# Draw g-function
if self.solver.nMassFlow == 0:
ax.plot(lntts, self.gFunc)
elif which is None:
for j in range(self.solver.nMassFlow):
for i in range(self.solver.nMassFlow):
ax.plot(
lntts,
self.gFunc[i,j,:],
label=f'$g_{{{i}{j}}}$')
plt.legend()
else:
if which is None:
which = [
(i, j) for j in range(self.solver.nMassFlow)
for i in range(self.solver.nMassFlow)]
for (i, j) in which:
ax.plot(
lntts,
self.gFunc[i,j,:],
label=f'$g_{{{i}{j}}}$')
plt.legend()
# Adjust figure to window
plt.tight_layout()
return fig
def visualize_heat_extraction_rates(
self, iBoreholes=None, showTilt=True, which=None):
"""
Plot the time-variation of the average heat extraction rates.
Parameters
----------
iBoreholes : list of int
Borehole indices to plot heat extraction rates.
If iBoreholes is None, heat extraction rates are plotted for all
boreholes.
Default is None.
showTilt : bool
Set to True to show borehole inclination.
Default is True
which : list of int, optional
Indices i of the diagonal variable mass flow rate g-functions for
which to plot heat extraction rates.
If None, all diagonal g-functions are plotted.
Default is None.
Returns
-------
fig : figure
Figure object (matplotlib).
"""
from ._mpl import plt
# If iBoreholes is None, then plot all boreholes
if iBoreholes is None:
iBoreholes = range(len(self.solver.boreholes))
# Import heat extraction rates
Q_t = self._heat_extraction_rates(iBoreholes)
# Borefield characteristic time
ts = np.mean([b.H for b in self.solver.boreholes])**2/(9.*self.alpha)
# Dimensionless time (log)
lntts = np.log(self.time/ts)
if self.solver.nMassFlow == 0:
# Configure figure and axes
fig = _initialize_figure()
ax1 = fig.add_subplot(121)
ax1.set_xlabel(r'$x$ [m]')
ax1.set_ylabel(r'$y$ [m]')
ax1.axis('equal')
_format_axes(ax1)
ax2 = fig.add_subplot(122)
ax2.set_xlabel(r'ln$(t/t_s)$')
ax2.set_ylabel(r'$\bar{Q}_b$')
_format_axes(ax2)
# Plot curves for requested boreholes
for i, borehole in enumerate(self.solver.boreholes):
if i in iBoreholes:
# Draw heat extraction rate
line = ax2.plot(lntts, Q_t[iBoreholes.index(i)])
color = line[-1]._color
# Draw colored marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H*np.sin(borehole.tilt)*np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H*np.sin(borehole.tilt)*np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color=color)
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color=color)
else:
# Draw black marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H*np.sin(borehole.tilt)*np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H*np.sin(borehole.tilt)*np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color='k')
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color='k')
# Adjust figure to window
plt.tight_layout()
else:
m_flow = self.solver.m_flow
if which is None:
which = [n for n in range(self.solver.nMassFlow)]
for n in which:
# Configure figure and axes
fig = _initialize_figure()
fig.suptitle(
f'Heat extraction rates for m_flow={m_flow[n]} kg/s')
ax1 = fig.add_subplot(121)
ax1.set_xlabel(r'$x$ [m]')
ax1.set_ylabel(r'$y$ [m]')
ax1.axis('equal')
_format_axes(ax1)
ax2 = fig.add_subplot(122)
ax2.set_xlabel(r'ln$(t/t_s)$')
ax2.set_ylabel(r'$\bar{Q}_b$')
_format_axes(ax2)
# Plot curves for requested boreholes
for i, borehole in enumerate(self.solver.boreholes):
if i in iBoreholes:
# Draw heat extraction rate
line = ax2.plot(lntts, Q_t[iBoreholes.index(i)][n])
color = line[-1]._color
# Draw colored marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H*np.sin(borehole.tilt)*np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H*np.sin(borehole.tilt)*np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color=color)
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color=color)
else:
# Draw black marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H*np.sin(borehole.tilt)*np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H*np.sin(borehole.tilt)*np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color='k')
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color='k')
# Adjust figure to window
plt.tight_layout()
return fig
def visualize_heat_extraction_rate_profiles(
self, time=None, iBoreholes=None, showTilt=True, which=None):
"""
Plot the heat extraction rate profiles at chosen time.
Parameters
----------
time : float
Values of time (in seconds) to plot heat extraction rate profiles.
If time is None, heat extraction rates are plotted at the last
time step.
Default is None.
iBoreholes : list of int
Borehole indices to plot heat extraction rate profiles.
If iBoreholes is None, heat extraction rates are plotted for all
boreholes.
Default is None.
showTilt : bool
Set to True to show borehole inclination.
Default is True
which : list of int, optional
Indices i of the diagonal variable mass flow rate g-functions for
which to plot heat extraction rates.
If None, all diagonal g-functions are plotted.
Default is None.
Returns
-------
fig : figure
Figure object (matplotlib).
"""
from ._mpl import plt
# If iBoreholes is None, then plot all boreholes
if iBoreholes is None:
iBoreholes = range(len(self.solver.boreholes))
# Import heat extraction rate profiles
z, Q_b = self._heat_extraction_rate_profiles(time, iBoreholes)
if self.solver.nMassFlow == 0:
# Configure figure and axes
fig = _initialize_figure()
ax1 = fig.add_subplot(121)
ax1.set_xlabel(r'$x$ [m]')
ax1.set_ylabel(r'$y$ [m]')
ax1.axis('equal')
_format_axes(ax1)
ax2 = fig.add_subplot(122)
ax2.set_xlabel(r'$Q_b$')
ax2.set_ylabel(r'$z$ [m]')
ax2.invert_yaxis()
_format_axes(ax2)
# Plot curves for requested boreholes
for i, borehole in enumerate(self.solver.boreholes):
if i in iBoreholes:
# Draw heat extraction rate profile
line = ax2.plot(
Q_b[iBoreholes.index(i)], z[iBoreholes.index(i)])
color = line[-1]._color
# Draw colored marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H*np.sin(borehole.tilt)*np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H*np.sin(borehole.tilt)*np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color=color)
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color=color)
else:
# Draw black marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H*np.sin(borehole.tilt)*np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H*np.sin(borehole.tilt)*np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color='k')
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color='k')
# Adjust figure to window
plt.tight_layout()
else:
m_flow = self.solver.m_flow
if which is None:
which = [n for n in range(self.solver.nMassFlow)]
for n in which:
# Configure figure and axes
fig = _initialize_figure()
fig.suptitle(
f'Heat extraction rate profiles for m_flow={m_flow[n]} kg/s')
ax1 = fig.add_subplot(121)
ax1.set_xlabel(r'$x$ [m]')
ax1.set_ylabel(r'$y$ [m]')
ax1.axis('equal')
_format_axes(ax1)
ax2 = fig.add_subplot(122)
ax2.set_xlabel(r'$Q_b$')
ax2.set_ylabel(r'$z$ [m]')
ax2.invert_yaxis()
_format_axes(ax2)
# Plot curves for requested boreholes
for i, borehole in enumerate(self.solver.boreholes):
if i in iBoreholes:
# Draw heat extraction rate profile
line = ax2.plot(
Q_b[iBoreholes.index(i)][n],
z[iBoreholes.index(i)])
color = line[-1]._color
# Draw colored marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H*np.sin(borehole.tilt)*np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H*np.sin(borehole.tilt)*np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color=color)
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color=color)
else:
# Draw black marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H*np.sin(borehole.tilt)*np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H*np.sin(borehole.tilt)*np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color='k')
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color='k')
# Adjust figure to window
plt.tight_layout()
return fig
def visualize_temperatures(
self, iBoreholes=None, showTilt=True, which=None):
"""
Plot the time-variation of the average borehole wall temperatures.
Parameters
----------
iBoreholes : list of int
Borehole indices to plot temperatures.
If iBoreholes is None, temperatures are plotted for all boreholes.
Default is None.
showTilt : bool
Set to True to show borehole inclination.
Default is True
which : list of int, optional
Indices i of the diagonal variable mass flow rate g-functions for
which to plot borehole wall temperatures.
If None, all diagonal g-functions are plotted.
Default is None.
Returns
-------
fig : figure
Figure object (matplotlib).
"""
from ._mpl import plt
# If iBoreholes is None, then plot all boreholes
if iBoreholes is None:
iBoreholes = range(len(self.solver.boreholes))
# Import temperatures
T_b = self._temperatures(iBoreholes)
# Borefield characteristic time
ts = np.mean([b.H for b in self.solver.boreholes])**2/(9.*self.alpha)
# Dimensionless time (log)
lntts = np.log(self.time/ts)
if self.solver.nMassFlow == 0:
# Configure figure and axes
fig = _initialize_figure()
ax1 = fig.add_subplot(121)
ax1.set_xlabel(r'$x$ [m]')
ax1.set_ylabel(r'$y$ [m]')
ax1.axis('equal')
_format_axes(ax1)
ax2 = fig.add_subplot(122)
ax2.set_xlabel(r'ln$(t/t_s)$')
ax2.set_ylabel(r'$\bar{T}_b$')
_format_axes(ax2)
# Plot curves for requested boreholes
for i, borehole in enumerate(self.solver.boreholes):
if i in iBoreholes:
# Draw borehole wall temperature
line = ax2.plot(lntts, T_b[iBoreholes.index(i)])
color = line[-1]._color
# Draw colored marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H*np.sin(borehole.tilt)*np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H*np.sin(borehole.tilt)*np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color=color)
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color=color)
else:
# Draw black marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H*np.sin(borehole.tilt)*np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H*np.sin(borehole.tilt)*np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color='k')
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color='k')
# Adjust figure to window
plt.tight_layout()
else:
m_flow = self.solver.m_flow
if which is None:
which = [n for n in range(self.solver.nMassFlow)]
for n in which:
# Configure figure and axes
fig = _initialize_figure()
fig.suptitle(
f'Borehole wall temperatures for m_flow={m_flow[n]} kg/s')
ax1 = fig.add_subplot(121)
ax1.set_xlabel(r'$x$ [m]')
ax1.set_ylabel(r'$y$ [m]')
ax1.axis('equal')
_format_axes(ax1)
ax2 = fig.add_subplot(122)
ax2.set_xlabel(r'ln$(t/t_s)$')
ax2.set_ylabel(r'$\bar{T}_b$')
_format_axes(ax2)
# Plot curves for requested boreholes
for i, borehole in enumerate(self.solver.boreholes):
if i in iBoreholes:
# Draw borehole wall temperature
line = ax2.plot(lntts, T_b[iBoreholes.index(i)][n])
color = line[-1]._color
# Draw colored marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H*np.sin(borehole.tilt)*np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H*np.sin(borehole.tilt)*np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color=color)
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color=color)
else:
# Draw black marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H*np.sin(borehole.tilt)*np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H*np.sin(borehole.tilt)*np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color='k')
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color='k')
# Adjust figure to window
plt.tight_layout()
return fig
def visualize_temperature_profiles(
self, time=None, iBoreholes=None, showTilt=True, which=None):
"""
Plot the borehole wall temperature profiles at chosen time.
Parameters
----------
time : float
Values of time (in seconds) to plot temperature profiles.
If time is None, temperatures are plotted at the last time step.
Default is None.
iBoreholes : list of int
Borehole indices to plot temperature profiles.
If iBoreholes is None, temperatures are plotted for all boreholes.
Default is None.
showTilt : bool
Set to True to show borehole inclination.
Default is True
which : list of int, optional
Indices i of the diagonal variable mass flow rate g-functions for
which to plot borehole wall temperatures.
If None, all diagonal g-functions are plotted.
Default is None.
Returns
-------
fig : figure
Figure object (matplotlib).
"""
from ._mpl import plt
# If iBoreholes is None, then plot all boreholes
if iBoreholes is None:
iBoreholes = range(len(self.boreholes))
# Import temperature profiles
z, T_b = self._temperature_profiles(time, iBoreholes)
if self.solver.nMassFlow == 0:
# Configure figure and axes
fig = _initialize_figure()
ax1 = fig.add_subplot(121)
ax1.set_xlabel(r'$x$ [m]')
ax1.set_ylabel(r'$y$ [m]')
ax1.axis('equal')
_format_axes(ax1)
ax2 = fig.add_subplot(122)
ax2.set_xlabel(r'$T_b$')
ax2.set_ylabel(r'$z$ [m]')
ax2.invert_yaxis()
_format_axes(ax2)
# Plot curves for requested boreholes
for i, borehole in enumerate(self.solver.boreholes):
if i in iBoreholes:
# Draw borehole wall temperature profile
line = ax2.plot(
T_b[iBoreholes.index(i)],
z[iBoreholes.index(i)])
color = line[-1]._color
# Draw colored marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H * np.sin(borehole.tilt) * np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H * np.sin(borehole.tilt) * np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color=color)
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color=color)
else:
# Draw black marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H * np.sin(borehole.tilt) * np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H * np.sin(borehole.tilt) * np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color='k')
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color='k')
plt.tight_layout()
else:
m_flow = self.solver.m_flow
if which is None:
which = [n for n in range(self.solver.nMassFlow)]
for n in which:
# Configure figure and axes
fig = _initialize_figure()
fig.suptitle(
f'Borehole wall temperature profiles for m_flow={m_flow[n]} kg/s')
ax1 = fig.add_subplot(121)
ax1.set_xlabel(r'$x$ [m]')
ax1.set_ylabel(r'$y$ [m]')
ax1.axis('equal')
_format_axes(ax1)
ax2 = fig.add_subplot(122)
ax2.set_xlabel(r'$T_b$')
ax2.set_ylabel(r'$z$ [m]')
ax2.invert_yaxis()
_format_axes(ax2)
# Plot curves for requested boreholes
for i, borehole in enumerate(self.solver.boreholes):
if i in iBoreholes:
# Draw borehole wall temperature profile
line = ax2.plot(
T_b[iBoreholes.index(i)][n],
z[iBoreholes.index(i)])
color = line[-1]._color
# Draw colored marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H * np.sin(borehole.tilt) * np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H * np.sin(borehole.tilt) * np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color=color)
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color=color)
else:
# Draw black marker for borehole position
if showTilt:
ax1.plot(
[borehole.x, borehole.x + borehole.H * np.sin(borehole.tilt) * np.cos(borehole.orientation)],
[borehole.y, borehole.y + borehole.H * np.sin(borehole.tilt) * np.sin(borehole.orientation)],
linestyle='--',
marker='None',
color='k')
ax1.plot(borehole.x,
borehole.y,
linestyle='None',
marker='o',
color='k')
plt.tight_layout()
return fig
def _heat_extraction_rates(self, iBoreholes):
"""
Extract and format heat extraction rates for plotting.
Parameters
----------
iBoreholes : list of int
Borehole indices to extract heat extraction rates.
Returns
-------
Q_t : list of array
Heat extraction rates (dimensionless).
"""
# Initialize list
Q_t = []
for i in iBoreholes:
if self.boundary_condition == 'UHTR':
# For the UHTR boundary condition, the heat extraction rate is
# constant. A vector of length len(self.solver.time) is
# required for the time-dependent figure.
Q_t.append(self.solver.Q_b*np.ones(len(self.solver.time)))
else:
# For other boundary conditions, evaluate the average
# heat extraction rate.
i0 = self.solver._i0Segments[i]
i1 = self.solver._i1Segments[i]
segment_ratios = self.solver.segment_ratios[i]
if self.solver.nMassFlow == 0:
Q_t.append(
np.sum(