Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
619 changes: 619 additions & 0 deletions docs/transient/05benchmarks/well_near_leaky_fault.ipynb

Large diffs are not rendered by default.

165 changes: 141 additions & 24 deletions docs/transient/05benchmarks/well_near_leaky_river.ipynb

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ classifiers = [
"Topic :: Scientific/Engineering :: Hydrology",
]
requires-python = ">=3.11"
dependencies = ["numpy", "scipy", "numba", "matplotlib", "pandas", "tqdm"]
dependencies = [
"numpy",
"scipy",
"numba",
"matplotlib",
"pandas",
"tqdm",
"ruff>=0.16.9",
]

[project.urls]
homepage = "https://github.com/timflow-org/timflow"
Expand Down
117 changes: 101 additions & 16 deletions timflow/bessel/besselnumba.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,45 @@ def bessells(x, y, z1, z2, lab, order, d1in, d2in):
######## Bessel line-sink discharge vector functions


# #@numba.njit(nogil=True, cache=True)
# def bessells_int_ho_qxqy_old(x, y, z1, z2, lab, order, d1, d2):
# """Docs.

# To come here
# """
# nt = 20 # number of terms in series is nt + 1
# bigz = (2 * complex(x, y) - (z1 + z2)) / (z2 - z1)
# bigx = bigz.real
# bigy = bigz.imag
# L = np.abs(z2 - z1)
# ang = np.arctan2(lab.imag, lab.real)
# angz = np.arctan2((z2 - z1).imag, (z2 - z1).real)
# biglab = 2 * lab / L
# biga = np.abs(biglab)

# exprange = np.exp(-complex(0, 2) * ang * nrange)
# ahat = a * exprange
# bhat = (b - a * complex(0, 2) * ang) * exprange

# atil = 2 * nrange[1:] * ahat[1:]
# btil = 2 * nrange[1:] * bhat[1:] + 2 * ahat[1:]

# omega = Fp(x, y, z1, z2, biga, order + 1, d1, d2, atil, btil, nt - 1)
# omegalap = lapld_int_ho_d1d2(x, y, z1, z2, order, d1, d2)
# term1 = 1 / (2 * np.pi * biga**2) * bigx * omega[:-1]
# term2 = -1 / (2 * np.pi * biga**2) * omega[1:]
# term3 = 2 * ahat[0] * omegalap.imag
# qx = term1 + term2 + term3
# term1 = 1 / (2 * np.pi * biga**2) * bigy * omega[:-1]
# term3 = 2 * ahat[0] * omegalap.real
# qy = term1 + term3

# qxqy = np.zeros(2 * order + 2, dtype=np.complex128)
# qxqy[: order + 1] = qx * np.cos(angz) - qy * np.sin(angz)
# qxqy[order + 1 :] = qx * np.sin(angz) + qy * np.cos(angz)
# return qxqy


@numba.njit(nogil=True, cache=True)
def bessells_int_ho_qxqy(x, y, z1, z2, lab, order, d1, d2):
"""Docs.
Expand All @@ -1001,13 +1040,14 @@ def bessells_int_ho_qxqy(x, y, z1, z2, lab, order, d1, d2):

omega = Fp(x, y, z1, z2, biga, order + 1, d1, d2, atil, btil, nt - 1)
omegalap = lapld_int_ho_d1d2(x, y, z1, z2, order, d1, d2)
term1 = 1 / (2 * np.pi * biga**2) * bigx * omega[:-1]
term2 = -1 / (2 * np.pi * biga**2) * omega[1:]
term3 = 2 * ahat[0] * omegalap.imag
qx = term1 + term2 + term3
term1 = 1 / (2 * np.pi * biga**2) * bigy * omega[:-1]
term3 = 2 * ahat[0] * omegalap.real
qy = term1 + term3
term1 = bigx / (biga**2) * omega[:-1]
term2 = -1 / (biga**2) * omega[1:]
term3 = 4 * np.pi * ahat[0] * omegalap.imag
# Note: qx and qy are already scaled by L / 2
qx = 1 / (2 * np.pi) * (term1 + term2 + term3)
term1 = bigy / (biga**2) * omega[:-1]
term3 = 4 * np.pi * ahat[0] * omegalap.real
qy = 1 / (2 * np.pi) * (term1 + term3)

qxqy = np.zeros(2 * order + 2, dtype=np.complex128)
qxqy[: order + 1] = qx * np.cos(angz) - qy * np.sin(angz)
Expand Down Expand Up @@ -1343,6 +1383,48 @@ def besselld(x, y, z1, z2, lab, order, d1in, d2in):


######## Bessel line-doublet discharge vector functions
# @numba.njit(nogil=True, cache=True)
# def besselld_int_ho_qxqy_old(x, y, z1, z2, lab, order, d1, d2):
# """Docs.

# To come here
# """
# nt = 20 # number of terms in series is nt + 1
# bigz = (2 * complex(x, y) - (z1 + z2)) / (z2 - z1)
# bigx = bigz.real
# bigy = bigz.imag
# L = np.abs(z2 - z1)
# ang = np.arctan2(lab.imag, lab.real)
# angz = np.arctan2((z2 - z1).imag, (z2 - z1).real)
# biglab = 2 * lab / L
# biga = np.abs(biglab)

# exprange = np.exp(-complex(0, 2) * ang * nrange)
# ahat = a1 * exprange
# bhat = (b1 - a1 * complex(0, 2) * ang) * exprange

# atil = 2 * nrange[1:] * ahat[1:]
# btil = 2 * nrange[1:] * bhat[1:] + 2 * ahat[1:]

# omega_pot = Fp(x, y, z1, z2, biga, order, d1, d2, ahat, bhat, nt)
# omega = Fp(x, y, z1, z2, biga, order + 1, d1, d2, atil, btil, nt - 1)
# omegalap = lapld_int_ho_d1d2(x, y, z1, z2, order, d1, d2)
# wlap = lapld_int_ho_wdis_d1d2(x, y, z1, z2, order, d1, d2)

# term1 = bigx / (2 * np.pi * biga**2) * omega[:-1]
# term2 = -1 / (2 * np.pi * biga**2) * omega[1:]
# term3 = 2 * ahat[0] * omegalap.imag
# qx = -2 * bigy / (L * biglab**2) * (term1 + term2 + term3) # + wlap.real

# term1 = 1 / (2.0 * np.pi * biglab**2) * 2 / L * omega_pot
# term2 = bigy / (2 * np.pi * biga**2) * omega[:-1]
# term3 = 2 * ahat[0] * omegalap.real
# qy = -term1 - 2 * bigy / (L * biglab**2) * (term2 + term3) # - wlap.imag

# qxqy = np.zeros(2 * order + 2, dtype=np.complex128)
# qxqy[: order + 1] = qx * np.cos(angz) - qy * np.sin(angz) + wlap.real
# qxqy[order + 1 :] = qx * np.sin(angz) + qy * np.cos(angz) - wlap.imag
# return qxqy


@numba.njit(nogil=True, cache=True)
Expand Down Expand Up @@ -1373,15 +1455,18 @@ def besselld_int_ho_qxqy(x, y, z1, z2, lab, order, d1, d2):
omegalap = lapld_int_ho_d1d2(x, y, z1, z2, order, d1, d2)
wlap = lapld_int_ho_wdis_d1d2(x, y, z1, z2, order, d1, d2)

term1 = bigx / (2 * np.pi * biga**2) * omega[:-1]
term2 = -1 / (2 * np.pi * biga**2) * omega[1:]
term3 = 2 * ahat[0] * omegalap.imag
qx = -2 * bigy / (L * biglab**2) * (term1 + term2 + term3) # + wlap.real

term1 = 1 / (2.0 * np.pi * biglab**2) * 2 / L * omega_pot
term2 = bigy / (2 * np.pi * biga**2) * omega[:-1]
term3 = 2 * ahat[0] * omegalap.real
qy = -term1 - 2 * bigy / (L * biglab**2) * (term2 + term3) # - wlap.imag
term1 = bigx / (biga**2) * omega[:-1]
term2 = -1 / (biga**2) * omega[1:]
term3 = 4 * np.pi * ahat[0] * omegalap.imag
qx = (
-(2 / L) * bigy / (2 * np.pi * biglab**2) * (term1 + term2 + term3)
) # + wlap.real

term1 = omega_pot
term2 = bigy / (biga**2) * omega[:-1]
term3 = 4 * np.pi * ahat[0] * omegalap.real
qy = 1 / (2.0 * np.pi * biglab**2) * (term1 + bigy * (term2 + term3)) # - wlap.imag
qy = -(2 / L) * qy # properly scaled

qxqy = np.zeros(2 * order + 2, dtype=np.complex128)
qxqy[: order + 1] = qx * np.cos(angz) - qy * np.sin(angz) + wlap.real
Expand Down
41 changes: 41 additions & 0 deletions timflow/transient/equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,47 @@
import numpy as np


class HeadEquationNew:
def equation(self):
"""Matrix rows for head-specified conditions.

Really written as constant potential element.
Works for nunknowns = 1
Returns matrix part nunknowns,neq,npval, complex.

Returns rhs part nunknowns,nvbc,npval, complex
Phi_out - c*T*q_s = Phi_in
Well: q_s = Q / (2*pi*r_w*H)
LineSink: q_s = sigma / H = Q / (L*H)
"""
mat = np.empty((self.nunknowns, self.model.neq, self.model.npval), dtype=complex)
# rhs needs be initialized zero
rhs = np.zeros(
(self.nunknowns, self.model.ngvbc, self.model.npval), dtype=complex
)
for icp in range(self.ncp):
ieq = 0
for e in self.model.elementlist:
if e.nunknowns > 0:
mat[icp, ieq : ieq + e.nunknowns, :] = e.potinflayers(
self.xc[icp], self.yc[icp], self.layers
)
if e == self:
for jparam in range(self.ncp):
mat[icp, ieq + jparam, :] -= (
self.resfacp[0] * e.strengthinflayers[icp, jparam]
)
ieq += e.nunknowns
for i in range(self.model.ngbc):
rhs[icp, i, :] -= self.model.gbclist[i].unitpotentiallayers(
self.xc[icp], self.yc[icp], self.layers
)
if self.type == "v":
iself = self.model.vbclist.index(self)
rhs[icp, self.model.ngbc + iself, :] = self.pc[icp] / self.model.p
return mat, rhs


class HeadEquation:
def equation(self):
"""Matrix rows for head-specified conditions.
Expand Down
17 changes: 3 additions & 14 deletions timflow/transient/linedoublet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import numpy as np

from timflow.bessel import besselnumba
from timflow.steady.controlpoints import controlpoints
from timflow.transient.element import Element
from timflow.transient.equation import LeakyWallEquation

Expand Down Expand Up @@ -80,20 +81,8 @@ def initialize(self):
self.cosout = np.cos(self.thetanormOut) * np.ones(self.ncp)
self.sinout = np.sin(self.thetanormOut) * np.ones(self.ncp)
#
thetacp = np.arange(np.pi, 0, -np.pi / self.ncp) - 0.5 * np.pi / self.ncp
Zcp = np.zeros(self.ncp, dtype=complex)
Zcp.real = np.cos(thetacp)
# control point just on positive site (this is handy later on)
Zcp.imag = 1e-6
zcp = Zcp * (self.z2 - self.z1) / 2 + 0.5 * (self.z1 + self.z2)
self.xc = zcp.real
self.yc = zcp.imag
# control point just on negative side
# (this is needed for building the system of equations)
Zcp.imag = -1e-6
zcp = Zcp * (self.z2 - self.z1) / 2 + 0.5 * (self.z1 + self.z2)
self.xcneg = zcp.real
self.ycneg = zcp.imag # control points just on negative side
self.xc, self.yc = controlpoints(self.ncp, self.z1, self.z2, eps=1e-6)
self.xcneg, self.ycneg = controlpoints(self.ncp, self.z1, self.z2, eps=-1e-6)
#
self.aq = self.model.aq.find_aquifer_data(self.xc[0], self.yc[0])
self.setbc()
Expand Down
35 changes: 19 additions & 16 deletions timflow/transient/linesink.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
import numpy as np

from timflow.bessel import besselnumba
from timflow.steady.controlpoints import controlpoints, strengthinf_controlpoints
from timflow.transient.element import Element
from timflow.transient.equation import (
HeadEquation,
HeadEquationNores,
HeadEquationNew,
MscreenDitchEquation,
MscreenEquation,
)
Expand Down Expand Up @@ -140,7 +141,10 @@ def potinf(self, x, y, aq=None):
return rv.reshape((self.nparam, aq.naq, self.model.npval))

def disvecinf(self, x, y, aq=None):
"""Can be called with only one x,y value."""
"""Can be called with only one x,y value.

Returns array of naparam, naq, npval
"""
if aq is None:
aq = self.model.aq.find_aquifer_data(x, y)
rvx = np.zeros(
Expand Down Expand Up @@ -433,7 +437,7 @@ def potinf(self, x, y, aq=None):
return rv

def disvecinf(self, x, y, aq=None):
"""Returns array (nunknowns,Nperiods)."""
"""Returns array (nparam, naq, npval)."""
if aq is None:
aq = self.model.aq.find_aquifer_data(x, y)
rvx = np.zeros((self.nparam, aq.naq, self.model.npval), dtype=complex)
Expand Down Expand Up @@ -909,21 +913,12 @@ def initialize(self):
self.z1 = self.x1 + 1j * self.y1
self.z2 = self.x2 + 1j * self.y2
self.L = np.abs(self.z1 - self.z2)
#
thetacp = np.arange(np.pi, 0, -np.pi / self.ncp) - 0.5 * np.pi / self.ncp
Zcp = np.zeros(self.ncp, dtype=complex)
Zcp.real = np.cos(thetacp)
# control point just on positive site (this is handy later on)
Zcp.imag = 1e-6
zcp = Zcp * (self.z2 - self.z1) / 2 + 0.5 * (self.z1 + self.z2)
self.xc = zcp.real
self.yc = zcp.imag
self.xc, self.yc = controlpoints(self.ncp, self.z1, self.z2, eps=1e-6)
#
self.aq = self.model.aq.find_aquifer_data(self.xc[0], self.yc[0])
self.setbc()
coef = self.aq.coef[self.layers, :]
self.setflowcoef()
# shape of term (self.nlayers, self.aq.naq, self.model.npval)
self.term = self.flowcoef * coef
self.term2 = self.term.reshape(
self.nlayers, self.aq.naq, self.model.nint, self.model.npint
Expand All @@ -936,6 +931,11 @@ def initialize(self):
self.dischargeinflayers = np.sum(
self.dischargeinf * self.aq.eigvec[self.layers, :, :], 1
)
# tested for 1 layer
fac = self.flowcoef * coef
self.strengthinflayers = np.sum(fac * self.aq.eigvec[self.layers, :, :], 1)
strengthinf = strengthinf_controlpoints(self.ncp, self.nlayers)
self.strengthinflayers = strengthinf[:, :, None] * self.strengthinflayers
if self.wh == "H":
self.wh = self.aq.Haq[self.layers]
elif self.wh == "2H":
Expand Down Expand Up @@ -1082,7 +1082,8 @@ def __init__(
)


class RiverHo(LineSinkHoBase, HeadEquationNores):
class RiverHo(LineSinkHoBase, HeadEquationNew):
# class RiverHo(LineSinkHoBase, HeadEquationNores):
"""River of which the head varies through time.

May be screened in multiple layers but all with the same head
Expand All @@ -1096,6 +1097,8 @@ def __init__(
x2=1,
y2=0,
tsandh=[(0.0, 1.0)],
res=0.0,
wh="H",
order=0,
layers=0,
label=None,
Expand All @@ -1114,8 +1117,8 @@ def __init__(
x2=x2,
y2=y2,
tsandbc=tsandh,
res=0.0,
wh="H",
res=res,
wh=wh,
order=order,
layers=layers,
type=etype,
Expand Down
Loading
Loading