/
ex-gwf-radial.py
2007 lines (1769 loc) · 60 KB
/
ex-gwf-radial.py
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
# ## Radial Groundwater Flow Model
#
# This example, ex-gwf-radial, shows how the MODFLOW 6 DISU Package
# can be used to simulate an axisymmetric radial model.
#
# The example corresponds to the first example described in:
# Bedekar, V., Scantlebury, L., and Panday, S. (2019).
# Axisymmetric Modeling Using MODFLOW-USG.Groundwater, 57(5), 772-777.
#
# And the numerical result is compared against the analytical solution
# presented in Equation 17 of
# Neuman, S. P. (1974). Effect of partial penetration on flow in
# unconfined aquifers considering delayed gravity response.
# Water resources research, 10(2), 303-312
# ### Initial setup
#
# Import dependencies, define the example name and workspace, and read settings from environment variables.
# +
import os
import pathlib as pl
from math import sqrt
import flopy
import git
import matplotlib.pyplot as plt
import numpy as np
from flopy.plot.styles import styles
from matplotlib.patches import Circle
from modflow_devtools.misc import get_env, timed
# Solve definite integral using Fortran library QUADPACK
from scipy.integrate import quad
# Find a root of a function using Brent's method within a bracketed range
from scipy.optimize import brentq
# Zero Order Bessel Function
from scipy.special import j0, jn_zeros
# Example name and workspace paths. If this example is running
# in the git repository, use the folder structure described in
# the README. Otherwise just use the current working directory.
sim_name = "ex-gwf-rad-disu"
try:
root = pl.Path(git.Repo(".", search_parent_directories=True).working_dir)
except:
root = None
workspace = root / "examples" if root else pl.Path.cwd()
figs_path = root / "figures" if root else pl.Path.cwd()
# Settings from environment variables
write = get_env("WRITE", True)
run = get_env("RUN", True)
plot = get_env("PLOT", True)
plot_show = get_env("PLOT_SHOW", True)
plot_save = get_env("PLOT_SAVE", True)
# -
# Define some utilities for creating the grid and solving the radial solution
# +
# Radial unconfined drawdown solution from Neuman 1974
pi = 3.141592653589793
sin = np.sin
cos = np.cos
sinh = np.sinh
cosh = np.cosh
exp = np.exp
def get_disu_radial_kwargs(
nlay,
nradial,
radius_outer,
surface_elevation,
layer_thickness,
get_vertex=False,
):
"""
Simple utility for creating radial unstructured elements
with the disu package.
Input assumes that each layer contains the same radial band,
but their thickness can be different.
Parameters
----------
nlay: number of layers (int)
nradial: number of radial bands to construct (int)
radius_outer: Outer radius of each radial band (array-like float with nradial length)
surface_elevation: Top elevation of layer 1 as either a float or nradial array-like float values.
If given as float, then value is replicated for each radial band.
layer_thickness: Thickness of each layer as either a float or nlay array-like float values.
If given as float, then value is replicated for each layer.
"""
pi = 3.141592653589793
def get_nn(lay, rad):
return nradial * lay + rad
def get_rad_array(var, rep):
try:
dim = len(var)
except:
dim, var = 1, [var]
if dim != 1 and dim != rep:
raise IndexError(
f"get_rad_array(var): var must be a scalar or have len(var)=={rep}"
)
if dim == 1:
return np.full(rep, var[0], dtype=np.float64)
else:
return np.array(var, dtype=np.float64)
nodes = nlay * nradial
surf = get_rad_array(surface_elevation, nradial)
thick = get_rad_array(layer_thickness, nlay)
iac = np.zeros(nodes, dtype=int)
ja = []
ihc = []
cl12 = []
hwva = []
area = np.zeros(nodes, dtype=float)
top = np.zeros(nodes, dtype=float)
bot = np.zeros(nodes, dtype=float)
for lay in range(nlay):
st = nradial * lay
sp = nradial * (lay + 1)
top[st:sp] = surf - thick[:lay].sum()
bot[st:sp] = surf - thick[: lay + 1].sum()
for lay in range(nlay):
for rad in range(nradial):
# diagonal/self
n = get_nn(lay, rad)
ja.append(n)
iac[n] += 1
if rad > 0:
area[n] = pi * (radius_outer[rad] ** 2 - radius_outer[rad - 1] ** 2)
else:
area[n] = pi * radius_outer[rad] ** 2
ihc.append(n + 1)
cl12.append(n + 1)
hwva.append(n + 1)
# up
if lay > 0:
ja.append(n - nradial)
iac[n] += 1
ihc.append(0)
cl12.append(0.5 * (top[n] - bot[n]))
hwva.append(area[n])
# to center
if rad > 0:
ja.append(n - 1)
iac[n] += 1
ihc.append(1)
cl12.append(0.5 * (radius_outer[rad] - radius_outer[rad - 1]))
hwva.append(2.0 * pi * radius_outer[rad - 1])
# to outer
if rad < nradial - 1:
ja.append(n + 1)
iac[n] += 1
ihc.append(1)
hwva.append(2.0 * pi * radius_outer[rad])
if rad > 0:
cl12.append(0.5 * (radius_outer[rad] - radius_outer[rad - 1]))
else:
cl12.append(radius_outer[rad])
# bottom
if lay < nlay - 1:
ja.append(n + nradial)
iac[n] += 1
ihc.append(0)
cl12.append(0.5 * (top[n] - bot[n]))
hwva.append(area[n])
# Build rectangular equivalent of radial coordinates (unwrap radial bands)
if get_vertex:
perimeter_outer = np.fromiter(
(2.0 * pi * rad for rad in radius_outer),
dtype=float,
count=nradial,
)
xc = 0.5 * radius_outer[0]
yc = 0.5 * perimeter_outer[-1]
# all cells have same y-axis cell center; yc is costant
#
# cell2d: [icell2d, xc, yc, ncvert, icvert]; first node: cell2d = [[0, xc, yc, [2, 1, 0]]]
cell2d = []
for lay in range(nlay):
n = get_nn(lay, 0)
cell2d.append([n, xc, yc, 3, 2, 1, 0])
#
xv = radius_outer[0]
# half perimeter is equal to the y shift for vertices
sh = 0.5 * perimeter_outer[0]
vertices = [
[0, 0.0, yc],
[1, xv, yc - sh],
[2, xv, yc + sh],
] # vertices: [iv, xv, yv]
iv = 3
for r in range(1, nradial):
# radius_outer[r-1] + 0.5*(radius_outer[r] - radius_outer[r-1])
xc = 0.5 * (radius_outer[r - 1] + radius_outer[r])
for lay in range(nlay):
n = get_nn(lay, r)
# cell2d: [icell2d, xc, yc, ncvert, icvert]
cell2d.append([n, xc, yc, 4, iv - 2, iv - 1, iv + 1, iv])
xv = radius_outer[r]
# half perimeter is equal to the y shift for vertices
sh = 0.5 * perimeter_outer[r]
vertices.append([iv, xv, yc - sh]) # vertices: [iv, xv, yv]
iv += 1
vertices.append([iv, xv, yc + sh]) # vertices: [iv, xv, yv]
iv += 1
cell2d.sort(key=lambda row: row[0]) # sort by node number
ja = np.array(ja, dtype=np.int32)
nja = ja.shape[0]
hwva = np.array(hwva, dtype=np.float64)
kw = {}
kw["nodes"] = nodes
kw["nja"] = nja
kw["nvert"] = None
kw["top"] = top
kw["bot"] = bot
kw["area"] = area
kw["iac"] = iac
kw["ja"] = ja
kw["ihc"] = ihc
kw["cl12"] = cl12
kw["hwva"] = hwva
if get_vertex:
kw["nvert"] = len(vertices) # = 2*nradial + 1
kw["vertices"] = vertices
kw["cell2d"] = cell2d
kw["angldegx"] = np.zeros(nja, dtype=float)
else:
kw["nvert"] = 0
return kw
def _find_hyperbolic_max_value():
seterr = np.seterr()
np.seterr(all="ignore")
inf = np.inf
x = 10.0
delt = 1.0
for i in range(1000000):
x += delt
try:
if inf == sinh(x):
break
except:
break
np.seterr(**seterr)
return x - delt
_hyperbolic_max_value = _find_hyperbolic_max_value()
def _find_hyperbolic_equivalent_value():
x = 10.0
delt = 0.0001
for i in range(1000000):
x += delt
if x > _hyperbolic_max_value:
break
try:
if sinh(x) == cosh(x):
return x
except:
break
return x - delt
_hyperbolic_equivalence = _find_hyperbolic_equivalent_value()
class RadialUnconfinedDrawdown:
"""
Solves the drawdown that occurs from pumping from partial penetration
in an unconfined, radial aquifer. Uses the method described in:
Neuman, S. P. (1974). Effect of partial penetration on flow in
unconfined aquifers considering delayed gravity response.
Water resources research, 10(2), 303-312.
"""
hyperbolic_max_value = _hyperbolic_max_value
hyperbolic_equivalence = _hyperbolic_equivalence
bottom: float
Kr: float
Kz: float
Ss: float
Sy: float
well_top: float
well_bot: float
saturated_thickness: float
_sigma: float
_beta: float
def __init__(
self,
bottom_elevation,
hydraulic_conductivity_radial=None,
hydraulic_conductivity_vertical=None,
specific_storage=None,
specific_yield=None,
well_screen_elevation_top=None,
well_screen_elevation_bottom=None,
water_table_elevation=None,
saturated_thickness=None,
):
"""
Initialize unconfined, radial groundwater model to solve drawdown
at an observation location in response to pumping at the center of
the model (that is, the well extracts water at radius = 0).
Parameters
----------
rad : int
radial band number (0 to nradial-1)
bottom_elevation : float
Elevation of the impermeable base of the model ($L$)
hydraulic_conductivity_radial : float
Radial direction hydraulic conductivity of model ($L/T$)
hydraulic_conductivity_vertical : float
Vertical (z) direction hydraulic conductivity of model ($L/T$)
specific_storage : float
Specific storage of aquifer ($1/T$)
specific_yield : float
Specific yield of aquifer ($-$)
well_screen_elevation_top : float
Pumping well's top screen elevation ($L$)
well_screen_elevation_bottom : float
Pumping well's bottom screen elevation ($L$)
water_table_elevation : float
Initial water table elevation. Note, saturated_thickness (b) is
calculated as $water_table_elevation - bottom_elevation$ ($L$)
saturated_thickness : float
Specify the initial saturated thickness of the unconfined aquifer.
Value is used to calculate the water_table_elevation. If
water_table_elevation is defined, then saturated_thickness input
is ignored and set to
$water_table_elevation - bottom_elevation$ ($L$)
"""
self.bottom = float(bottom_elevation)
self.Kr = self._float_or_none(hydraulic_conductivity_radial)
self.Kz = self._float_or_none(hydraulic_conductivity_vertical)
self.Ss = self._float_or_none(specific_storage)
self.Sy = self._float_or_none(specific_yield)
self.well_top = self._float_or_none(well_screen_elevation_top)
self.well_bot = self._float_or_none(well_screen_elevation_bottom)
if water_table_elevation is not None and saturated_thickness is not None:
raise RuntimeError(
"RadialUnconfinedDrawdown() must specify only "
+ "water_table_elevation or saturated_thickness, but not "
+ "both at the same time."
)
if water_table_elevation is not None:
self.saturated_thickness = float(water_table_elevation) - self.bottom
elif saturated_thickness is not None:
self.saturated_thickness = float(saturated_thickness)
else:
self.saturated_thickness = None
def _prop_check(self):
error = []
if self.Kr is None:
error.append("hydraulic_conductivity_radial")
if self.Kz is None:
error.append("hydraulic_conductivity_vertical")
if self.Ss is None:
error.append("specific_storage")
if self.Sy is None:
error.append("specific_yield")
if self.well_top is None:
error.append("well_screen_elevation_top")
if self.well_bot is None:
error.append("well_screen_elevation_bottom")
if error:
raise RuntimeError(
"RadialUnconfinedDrawdown: Attempted to solve radial "
+ "groundwater model\nwith the following input not specified\n"
+ "\n".join(error)
)
if self.well_top <= self.well_bot:
raise RuntimeError(
"RadialUnconfinedDrawdown: "
+ "well_screen_elevation_top <= well_screen_elevation_bottom\n"
+ f"That is: {self.well_top} <= "
+ f"{self.well_bot}"
)
def drawdown(
self,
pump,
time,
radius,
observation_elevation,
observation_elevation_bot=None,
sumrtol=1.0e-6,
u_n_rtol=1.0e-5,
epsabs=1.49e-8,
bessel_loop_limit=5,
quad_limit=128,
show_progress=False,
ty_time=False,
ts_time=False,
as_head=False,
):
"""
Solves the radial model's drawdown for a given pumping rate and
time at a given observation point
(radius, observation_elevation) or observation well screen interval
(radius, observation_elevation:observation_elevation_bot).
This solves drawdown by integrating equation 17 from
Neuman, S. P. (1974). Effect of partial penetration on flow in
unconfined aquifers considering delayed gravity response.
Water resources research, 10(2), 303-312
Parameters
----------
pump : float
Pumping rate of well at center of radial model ($L^3/T$)
Positive values are the water extraction rate.
Negative or zero values indicate no pumping and result returns
the dimensionless drawdown instead of regular drawdown.
time : float or Sequence[float]
Time that observation is made
radius : float
Radius of the observation location (distance from well, $L$)
observation_elevation : float
Either the location of the observation point, or the top elevation
of the observation well screen ($L$)
observation_elevation_bot : float
If specified, then represents the bottom elevation of the
observation well screen. If not specified (or set to None), then
observation location is treated as a single point, located at
radius and observation_elevation ($L$)
sumrtol : float
Solution involves integration of $y$ variable from 0 to ∞ from
Equation 17 in:
Neuman, S. P. (1974). Effect of partial penetration on flow in
unconfined aquifers considering delayed gravity response.
Water resources research, 10(2), 303-312.
The integration is broken into subsections that are spaced around
bessel function roots. The integration is complete when a
three sequential subsection solutions are less than
sumrtol times the largest subsection.
That is, the last included subsection contributes a
relatively small value compared to the largest of the sum.
u_n_rtol : float
Terminates the solution of the infinite series:
$\\sum_{n=1}^{\\infty} u_n(y)$
when
$u_n(y) < u_n(0) * u_n_rtol$
epsabs : float or int
scipy.integrate.quad absolute error tolerance.
Passed directly to that function's `epsabs` kwarg.
bessel_loop_limit : int
the integral is solved along each bessel function root.
The first 1024 roots are precalculated and automatically increased
if more are required. The upper limit for calculated roots is
1024 * 2 ^ bessel_loop_limit
If this limit is reached, then a warning is raised.
quad_limit : int
scipy.integrate.quad upper bound on the number of
subintervals used in the adaptive algorithm.
Passed directly to that function's `limit` kwarg.
show_progress : bool
if True, then progress is printed to the command prompt in the form:
ty_time : bool
if True, then `time` kwarg is dimensionless time with
respect to Specific Yield
ts_time : bool
if True, then `time` kwarg is dimensionless time with
respect to Specific Storage.
as_head : bool
If true, then drawdown result is converted to
head using the model bottom and initial saturated thickness.
If pump > 0, then as_head is ignored.
Returns
-------
result : float or list[float]
If time is float, then result is float.
If time is Sequence[float], then result is list[float].
If pump > 0, then result is the drawdown that occurs
from pump at time and radius at observation point
observation_elevation or from the observation well
screen interval observation_elevation to
observation_elevation_top ($L$).
If pump <= 0, then result is converted to
dimensionless drawdown ($-$)
"""
if not hasattr(time, "strip") and hasattr(time, "__iter__"):
return self.drawdown_times(
pump,
time,
radius,
observation_elevation,
observation_elevation_bot,
sumrtol,
u_n_rtol,
epsabs,
bessel_loop_limit,
quad_limit,
show_progress,
ty_time,
ts_time,
as_head,
)
return self.drawdown_times(
pump,
[time],
radius,
observation_elevation,
observation_elevation_bot,
sumrtol,
u_n_rtol,
epsabs,
bessel_loop_limit,
quad_limit,
show_progress,
ty_time,
ts_time,
as_head,
)[0]
def drawdown_times(
self,
pump,
times,
radius,
observation_elevation,
observation_elevation_bot=None,
sumrtol=1.0e-6,
u_n_rtol=1.0e-5,
epsabs=1.49e-8,
bessel_loop_limit=5,
quad_limit=128,
show_progress=False,
ty_time=False,
ts_time=False,
as_head=False,
):
# Same as self.drawdown, but times is a list[float] of
# observation times and returns a list[float] drawdowns.
if bessel_loop_limit < 1:
bessel_loop_limit = 1
bessel_roots0 = 1024
bessel_roots = bessel_roots0
bessel_root_limit_reached = []
self._prop_check()
if ty_time and ts_time:
raise RuntimeError(
"RadialUnconfinedDrawdown.drawdown_times "
+ "cannot set both ty_time and ts_time to True."
)
r = radius
b = self.saturated_thickness
sigma = self.Ss * b / self.Sy
beta = (r / b) * (r / b) * (self.Kz / self.Kr)
sqrt_beta = sqrt(beta)
if np.isnan(pump) or pump <= 0.0:
# Return dimensionless drawdown
coef = 1.0
else:
coef = pump / (4.0 * pi * b * self.Kr)
# dimensionless well screen top
dd = (self.saturated_thickness + self.bottom - self.well_top) / b
# dimensionless well screen bottom
ld = (self.saturated_thickness + self.bottom - self.well_bot) / b
# Solution must be in dimensionless time with respect to Ss;
# ts = kr*b*t/(Ss*b*r^2)
if ty_time:
ts_list = self.ty2ts(times)
elif ts_time:
ts_list = times
else:
ts_list = self.time2ts(times, r)
# distance above bottom to observation point or obs screen bottom
zt = observation_elevation - self.bottom
if observation_elevation_bot is None:
# Single Point Observation
zd = zt / b # dimensionless elevation of observation point
neuman1974_integral = self.neuman1974_integral1
obs_arg = (zd,)
else:
# distance above bottom to observation screen top
zb = observation_elevation_bot - self.bottom
# dimensionless elevation of observation screen interval
ztd, zbd = zt / b, zb / b
# dz = 1 / (zt - zb) -> implied in the
# modified u0 and uN functions
neuman1974_integral = self.neuman1974_integral2
obs_arg = (zbd, ztd)
s = [] # drawdown, one to one match with times
nstp = len(ts_list)
for stp, ts in enumerate(ts_list):
if show_progress:
print(
f"Solving {stp+1:4d} of {nstp}; " + f"time = {self.ts2time(ts, r)}",
end="",
)
args = (sigma, beta, sqrt_beta, ld, dd, ts, *obs_arg, u_n_rtol)
sol = 0.0
y0, y1 = 0.0, 0.0
mxdelt = 0.0
j0_roots = jn_zeros(0, bessel_roots) / sqrt_beta
jr0 = 0
jr1 = j0_roots.size
converged = 0
bessel_loop_count = 0
while converged < 3 and bessel_loop_count <= bessel_loop_limit:
if bessel_loop_count > 0:
bessel_roots *= 2
j0_roots = jn_zeros(0, bessel_roots) / sqrt_beta
jr0, jr1 = jr1, j0_roots.size
j0_roots_iter = np.nditer(j0_roots[jr0:jr1])
bessel_loop_count += 1
# Iterate over two roots to get full cycle
for j0_root in j0_roots_iter:
# First root
y0, y1 = y1, j0_root
delt1 = quad(
neuman1974_integral,
y0,
y1,
args,
epsabs=epsabs,
limit=quad_limit,
)[0]
#
# Second root
y0, y1 = y1, next(j0_roots_iter)
delt2 = quad(
neuman1974_integral,
y0,
y1,
args,
epsabs=epsabs,
limit=quad_limit,
)[0]
if np.isnan(delt1) or np.isnan(delt2):
break
sol += delt1 + delt2
adelt = abs(delt1 + delt2)
if adelt > mxdelt:
mxdelt = adelt
elif adelt < mxdelt * sumrtol:
converged += 1 # increment the convergence counter
# Converged if three sequential solutions (adelt)
# are less than mxdelt*sumrtol
if converged >= 3:
break
else:
converged = 0 # reset convergence counter
if sol < 0.0:
s.append(0.0)
else:
s.append(coef * sol)
if converged < 3:
bessel_root_limit_reached.append(stp)
if show_progress:
if converged < 3:
print(f"\ts = {s[-1]}\tbessel_loop_limit reached")
else:
print(f"\ts = {s[-1]}")
if pump > 0.0 and as_head:
initial_head = self.bottom + self.saturated_thickness
return [initial_head - drawdown for drawdown in s]
if len(bessel_root_limit_reached) > 0:
import warnings
root = j0_roots[-1]
bad_times = "\n".join([str(times[it]) for it in bessel_root_limit_reached])
warnings.warn(
"\n\nRadialUnconfinedDrawdown.drawdown_times failed to "
+ f"meet convergence sumrtol = {sumrtol}"
+ "\nwithin the precalculated Bessel root solutions "
+ "(convergence is evaluated at every second Bessel root).\n\n"
+ "The number of Bessel roots are automatically increased "
+ "up to:\n"
+ f" {bessel_roots0} * 2^bessel_loop_limit\nwhere:\n"
+ " bessel_loop_limit = {bessel_loop_limit}\n"
+ f"resulting in {1024*2**bessel_loop_limit} roots evaluated, "
+ "with the last root being {root}\n"
+ f"(That is, the Neuman integral was solved form 0 to {root})"
+ "\n\n"
+ "You can either ignore this warning\n"
+ "or to remove it attempt to increase bessel_loop_limit\n"
+ "or increase sumrtol (reducing accuracy).\n\nThe following "
+ "times are what triggered this warning:\n"
+ bad_times
+ "\n"
)
return s
@staticmethod
def neuman1974_integral1(y, alpha, beta, sqrt_beta, ld, dd, ts, zd, uN_tol=1.0e-6):
"""
Solves equation 17 from
Neuman, S. P. (1974). Effect of partial penetration on flow in
unconfined aquifers considering delayed gravity response.
Water resources research, 10(2), 303-312.
"""
if y == 0.0 or ts == 0.0:
return 0.0
u0 = RadialUnconfinedDrawdown.u_0(alpha, beta, zd, ld, dd, ts, y)
if np.isnan(u0):
u0 = 0.0
uN_func = RadialUnconfinedDrawdown.u_n
mxdelt = 0.0
uN = 0.0
for n in range(1, 25001):
delt = uN_func(alpha, beta, zd, ld, dd, ts, y, n)
if np.isnan(delt):
break
uN += delt
adelt = abs(delt)
if adelt > mxdelt:
mxdelt = adelt
elif adelt < mxdelt * uN_tol:
break
return 4.0 * y * j0(y * sqrt_beta) * (u0 + uN)
@staticmethod
def gamma0(g, y, s):
"""
Gamma0 root function from equation 18 in:
Neuman, S. P. (1974). Effect of partial penetration on flow in
unconfined aquifers considering delayed gravity response.
Water resources research, 10(2), 303-312.
=> Solution must be constrained by g^2 < y^2
To honor the constraint solution returns the absolute value
of the solution.
"""
if g >= _hyperbolic_equivalence:
# sinh ≈ cosh for large g
return s * g - (y * y - g * g)
return s * g * sinh(g) - (y * y - g * g) * cosh(g)
@staticmethod
def gammaN(g, y, s):
"""
GammaN root function from equation 19 in:
Neuman, S. P. (1974). Effect of partial penetration on flow in
unconfined aquifers considering delayed gravity response.
Water resources research, 10(2), 303-312.
=> Solution must be constrained by (2n-1)(π/2)< g < nπ
"""
return s * g * sin(g) + (y * y + g * g) * cos(g)
@staticmethod
def u_0(alpha, beta, z, l, d, ts, y):
gamma0 = RadialUnconfinedDrawdown.gamma0
a, b = 0.9 * y, y
try:
a, b = RadialUnconfinedDrawdown._get_bracket(gamma0, a, b, (y, alpha))
except RuntimeError:
a, b = RadialUnconfinedDrawdown._get_bracket(
gamma0, 0.0, b, (y, alpha), 1000
)
g = brentq(gamma0, a, b, args=(y, alpha), maxiter=500, xtol=1.0e-16)
# Check for cosh/sinh overflow
if g > _hyperbolic_max_value:
return 0.0
y2 = y * y
g2 = g * g
num1 = 1 - exp(-ts * beta * (y2 - g2))
num2 = cosh(g * z)
num3 = sinh(g * (1 - d)) - sinh(g * (1 - l))
den1 = y2 + (1 + alpha) * g2 - ((y2 - g2) ** 2) / alpha
den2 = cosh(g)
den3 = (l - d) * sinh(g)
# num1*num2*num3 / (den1*den2*den3)
return (num1 / den1) * (num2 / den2) * (num3 / den3)
@staticmethod
def u_n(alpha, beta, z, l, d, ts, y, n):
gammaN = RadialUnconfinedDrawdown.gammaN
a, b = (2 * n - 1) * (pi / 2.0), n * pi
try:
a, b = RadialUnconfinedDrawdown._get_bracket(gammaN, a, b, (y, alpha))
except RuntimeError:
a, b = RadialUnconfinedDrawdown._get_bracket(gammaN, a, b, (y, alpha), 1000)
g = brentq(gammaN, a, b, args=(y, alpha), maxiter=500, xtol=1.0e-16)
y2 = y * y
g2 = g * g
num1 = 1 - exp(-ts * beta * (y2 + g2))
num2 = cos(g * z)
num3 = sin(g * (1 - d)) - sin(g * (1 - l))
den1 = y2 - (1 + alpha) * g2 - ((y2 + g2) ** 2) / alpha
den2 = cos(g)
den3 = (l - d) * sin(g)
return num1 * num2 * num3 / (den1 * den2 * den3)
@staticmethod
def neuman1974_integral2(
y, alpha, beta, sqrt_beta, ld, dd, ts, z1, z2, uN_tol=1.0e-10
):
"""
Solves equation 20 from
Neuman, S. P. (1974). Effect of partial penetration on flow in
unconfined aquifers considering delayed gravity response.
Water resources research, 10(2), 303-312.
"""
if y == 0.0 or ts == 0.0:
return 0.0
u0 = RadialUnconfinedDrawdown.u_0_z1z2(alpha, beta, z1, z2, ld, dd, ts, y)
uN_func = RadialUnconfinedDrawdown.u_n_z1z2
mxdelt = 0.0
uN = 0.0
for n in range(1, 10001):
delt = uN_func(alpha, beta, z1, z2, ld, dd, ts, y, n)
uN += delt
adelt = abs(delt)
if adelt > mxdelt:
mxdelt = adelt
elif adelt < mxdelt * uN_tol:
break
return 4.0 * y * j0(y * sqrt_beta) * (u0 + uN)
@staticmethod
def u_0_z1z2(alpha, beta, z1, z2, l, d, ts, y):
gamma0 = RadialUnconfinedDrawdown.gamma0
a, b = 0.9 * y, y
try:
a, b = RadialUnconfinedDrawdown._get_bracket(gamma0, a, b, (y, alpha))
except RuntimeError:
a, b = RadialUnconfinedDrawdown._get_bracket(
gamma0, 0.0, b, (y, alpha), 1000
)
g = brentq(gamma0, a, b, args=(y, alpha), maxiter=500, xtol=1.0e-16)
# Check for cosh/sinh overflow
if g > _hyperbolic_max_value:
return 0.0
y2 = y * y
g2 = g * g
num1 = 1 - exp(-ts * beta * (y2 - g2))
num2 = sinh(g * z2) - sinh(g * z1)
num3 = sinh(g * (1 - d)) - sinh(g * (1 - l))
den1 = (y2 + (1 + alpha) * g2 - ((y2 - g2) ** 2) / alpha) * (z2 - z1) * g
den2 = cosh(g)
den3 = (l - d) * sinh(g)
# num1*num2*num3 / (den1*den2*den3)
return (num1 / den1) * (num2 / den2) * (num3 / den3)
@staticmethod
def u_n_z1z2(alpha, beta, z1, z2, l, d, ts, y, n):
gammaN = RadialUnconfinedDrawdown.gammaN
a, b = (2 * n - 1) * (pi / 2.0), n * pi
try:
a, b = RadialUnconfinedDrawdown._get_bracket(gammaN, a, b, (y, alpha))
except RuntimeError:
a, b = RadialUnconfinedDrawdown._get_bracket(gammaN, a, b, (y, alpha), 1000)
g = brentq(gammaN, a, b, args=(y, alpha), maxiter=500, xtol=1.0e-16)
y2 = y * y
g2 = g * g
num1 = 1 - exp(-ts * beta * (y2 + g2))
num2 = sin(g * z2) - sin(g * z1)
num3 = sin(g * (1 - d)) - sin(g * (1 - l))
den1 = y2 - (1 + alpha) * g2 - ((y2 + g2) ** 2) / alpha
den2 = cos(g) * (z2 - z1) * g
den3 = (l - d) * sin(g)
return num1 * num2 * num3 / (den1 * den2 * den3)
def time2ty(self, time, radius):
# dimensionless time with respect to Sy
if hasattr(time, "__iter__"):
# can iterate to get multiple times
return [
self.Kr * self.saturated_thickness * t / (self.Sy * radius * radius)
for t in time
]
return self.Kr * self.saturated_thickness * time / (self.Sy * radius * radius)
def time2ts(self, time, radius):
# dimensionless time with respect to Ss
if hasattr(time, "__iter__"):
# can iterate to get multiple times
return [self.Kr * t / (self.Ss * radius * radius) for t in time]
return self.Kr * time / (self.Ss * radius * radius)
def ty2time(self, ty, radius):
# dimensionless time with respect to Sy
if hasattr(ty, "__iter__"):
# can iterate to get multiple times
return [
t * self.Sy * radius * radius / (self.Kr * self.saturated_thickness)
for t in ty
]
return ty * self.Sy * radius * radius / (self.Kr * self.saturated_thickness)
def ts2time(self, ts, radius): # dimensionless time with respect to Ss
if hasattr(ts, "__iter__"): # can iterate to get multiple times
return [t * self.Ss * radius * radius / self.Kr for t in ts]
return ts * self.Ss * radius * radius / self.Kr
def ty2ts(self, ty):
if hasattr(ty, "__iter__"):
# can iterate to get multiple times
return [t * self.Sy / (self.Ss * self.saturated_thickness) for t in ty]
return ty * self.Sy / (self.Ss * self.saturated_thickness)
def drawdown2unitless(self, s, pump):
# dimensionless drawdown
return 4 * pi * self.Kr * self.saturated_thickness * s / pump
def unitless2drawdown(self, s, pump):
# drawdown
return pump * s / (4 * pi * self.Kr * self.saturated_thickness)
@staticmethod
def _float_or_none(val):
if val is not None:
return float(val)
return None
@staticmethod
def _get_bracket(func, a, b, arg=(), internal_search_split=100):
"""
Given initial range [a, b], search within the range for
root finding brackets.
That is, return [a, b] that results in f(a) * f(b) < 0.
"""
if a > b:
a, b = b, a
f1 = func(a, *arg)