from scipy.special import exp1
import numpy as np
import matplotlib.pyplot as plt

"""
Explanation: Section 6.4.3
Theis wells introduction
Theis considered the transient flow due to a well with a constant extraction since $t=0$ placed in a uniform confined aquifer of infinite extent.
The solution may be opbtained by straighforward Lapace transformation and looking up de result from the Laplace inversions table. It reads
$$ s(r, t) = \frac Q {4 \pi kD} W(u),\,\,\,\, u = \frac {r^2 S} {4 kD t}$$
where W(..) is the so-called Theis well function, which is actually equal to the mathematical exponential integral
$$ W(z) = \mathtt{exp1}(z) = \intop _z ^\infty \frac {e^{-y}} {y} dy $$
The exponential integral lives in scipy special as the function $\mathtt{exp1}(z)$
After importing this function from the module scipy.special we can use exp1(u)
End of explanation
"""


u = np.logspace(-6, 1, 71)

plt.title('Theis type curve $W(u)$ vs $1/u$')
plt.xlabel('1/u')
plt.ylabel('W(u), exp1(u)')
plt.xscale('log')
plt.yscale('log')
plt.grid()
plt.plot(1/u, exp1(u))
plt.show()

"""
Explanation: The firs thing to note is that the dradown depends on the combination of parameter contained in $u$. Any combination of parameters yieling the same $u$ will have the same drawdown, even though these sitautions may intuitively seem wide apart.
All possible outcomes are, therefore, represented by the exp1, which depends on a single parameter, $u$. The curve is called a type curve. However, we generally plot exp1$(u)$ versus $1/u$ instead of $u$. The reason os that 1/u is proportional to time, which makes the type curve more intuitiv as it is then a picture of drawdown versus (scaled) time.
End of explanation
"""


plt.title('Theis type curve $W(u)$ vs $u$')
plt.xlabel('u')
plt.ylabel('W(u), exp1(u)')
plt.xscale('log')
plt.yscale('log')
plt.grid()
plt.plot(u, exp1(u))
plt.show()

"""
Explanation: The plot of W(u) vs u is simply not intuitive
End of explanation
"""


plt.title('Theis type curve $W(u)$ vs $1/u$')
plt.xlabel('1/u')
plt.ylabel('W(u), exp1(u)')
plt.xscale('log')
plt.yscale('linear')
plt.grid()
plt.plot(1/u, exp1(u))
plt.show()

"""
Explanation: Before computers became ubiquitous
Before computes became ubiquitous (all around), one had to compute $u = \frac {r^2 S} {4 kD t} and then look up $W(u)$ in a table or read it from the type curve. Clearly this was much more work than using a modern computer and a package that has the exponential integral on board.
A linear y scale, shows clearly that the drawdown increases forever
As the water from a well in an infinite aquifer without any head boundaries can only come from storage, the drawdown must increase indefinitely. This is clearly shown on the curve below. The dradown after some time starts to increase and then becomes a straigt line on logarithmic time scale. This means that the rate at which the drawdown increases slows down continuously, but it never becomes zero. In fact the is taken from storage farther and farther away from the well.
End of explanation
"""


