Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c51df7e
Draft of coupling class
mdbartos Mar 27, 2024
04057af
Re-create tests
mdbartos May 31, 2024
3771ba6
Separate numba functions for coverage tests
mdbartos May 31, 2024
832c0b9
Simplify geometry function inputs
mdbartos Jun 1, 2024
d457ebe
Merge branch 'master' into organization
mdbartos Jun 1, 2024
dacd658
Fix merge conflict
mdbartos Jun 2, 2024
73006f4
Refactoring of geometry and state space representation
mdbartos Aug 9, 2024
d05739a
Add callback functionality
Aug 15, 2024
dba305d
Ensure storage areas are not negative
mdbartos Jan 21, 2025
a2ea123
Ensure storage areas are never negative (include constant)
mdbartos Jan 21, 2025
dab8841
Fix Darcy-Weisbach friction formulation for low-flow conditions
mdbartos Feb 7, 2025
b4bcf22
Fix tabular volume calculation
mdbartos Feb 28, 2025
7afbe0d
Fix error in boundary friction slope
mdbartos Jul 6, 2025
7af88fe
Add diagnostics
mdbartos Jul 6, 2025
04b94a9
Default to old convergence behavior
mdbartos Jul 7, 2025
65bdfdb
Add more diagnostic tooling; work on min depth constraint
mdbartos Jul 9, 2025
6793902
Add boundary velocities
mdbartos Jul 14, 2025
e438f5a
Refactor matrix creation
mdbartos Jul 15, 2025
c5ea106
Add computation of momentum at boundaries
mdbartos Jul 15, 2025
ec9f4f5
Downstream boundary problem fixed
mdbartos Jul 15, 2025
3851406
More stable
mdbartos Jul 19, 2025
5efbf7b
Add quotient rule formulation of SVE
mdbartos Jul 29, 2025
4e78c84
Add velocity limiter
mdbartos Aug 15, 2025
d999c28
Change direction of recurrence based on Froude condition
mdbartos Aug 15, 2025
645d2a9
Add functions to volume tracker; enforce minimum depth
mdbartos Aug 15, 2025
f3f9430
Implement flux limiter in Newton-Raphson iterations
mdbartos Aug 15, 2025
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
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[run]
omit = pipedream_solver/nsuperlink.py,pipedream_solver/ninfiltration.py,pipedream_solver/nquality.py,pipedream_solver/ngeometry.py,pipedream_solver/nutils.py
omit = pipedream_solver/geometry.py, pipedream_solver/infiltration.py, pipedream_solver/_nsuperlink.py, pipedream_solver/_ninfiltration.py
121 changes: 121 additions & 0 deletions pipedream_solver/_ninfiltration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import numpy as np
from numba import njit
from pipedream_solver.nutils import newton_raphson, bounded_newton_raphson, numba_any

@njit
def run_green_ampt_newton(F_2, x0, F_1, dt, Ks, theta_d, psi_f, ia, max_iter=50,
atol=1.48e-8, rtol=0.0, bounded=True):
"""
Use Newton-Raphson iteration to find cumulative infiltration at next time step (F_2).

Inputs:
-------
F_2 : np.ndarray (float)
Cumulative infiltration at next time step (meters).
x0 : np.ndarray (float)
Initial guess for cumulative infiltration (meters)
F_1 : np.ndarray (float)
Cumulative infiltration at previous time step (meters)
dt : np.ndarray (float)
Time step (seconds)
Ks : np.ndarray (float)
Saturated hydraulic conductivity (m/s)
theta_d : np.ndarray (float)
Soil moisture deficit (-)
psi_f : np.ndarray (float)
Matric potential of the wetting front (m)
ia : np.ndarray (float)
Available rainfall depth (meters)
max_iter : int
Maximum number of Newton-Raphson iterations
atol : float
Allowable (absolute) error of the zero value
rtol : float
Allowable (relative) error of the zero value
bounded : bool
If True, use bounded Newton-Raphson iteration
"""
n = F_2.size
for i in range(n):
x_0_i = x0[i]
F_1_i = F_1[i]
dt_i = dt[i]
nargs = np.zeros(5)
nargs[0] = F_1_i
nargs[1] = dt_i
nargs[2] = Ks[i]
nargs[3] = theta_d[i]
nargs[4] = psi_f[i]
if bounded:
min_F = 0
max_F = F_1_i + ia[i] * dt_i
F_est = bounded_newton_raphson(numba_integrated_green_ampt,
numba_derivative_green_ampt,
x_0_i, min_F, max_F,
nargs, max_iter=max_iter,
atol=atol, rtol=rtol)
else:
F_est = newton_raphson(numba_integrated_green_ampt,
numba_derivative_green_ampt,
x_0_i, nargs, max_iter=max_iter,
atol=atol, rtol=rtol)
F_2[i] = F_est
return F_2

@njit
def numba_integrated_green_ampt(F_2, args):
"""
Solve integrated form of Green Ampt equation for cumulative infiltration.

Inputs:
-------
F_2: np.ndarray (float)
Cumulative infiltration at current timestep (m)
F_1: np.ndarray (float)
Cumulative infiltration at next timestep (m)
dt: float
Time step (seconds)
Ks: np.ndarray (float)
Saturated hydraulic conductivity (m/s)
theta_d: np.ndarray (float)
Soil moisture deficit
psi_s: np.ndarray (float)
Soil suction head (m)
"""
F_1 = args[0]
dt = args[1]
Ks = args[2]
theta_d = args[3]
psi_s = args[4]
C = Ks * dt + F_1 - psi_s * theta_d * np.log(F_1 + np.abs(psi_s) * theta_d)
zero = C + psi_s * theta_d * np.log(F_2 + np.abs(psi_s) * theta_d) - F_2
return zero

@njit
def numba_derivative_green_ampt(F_2, args):
"""
Derivative of Green Ampt equation for cumulative infiltration.

Inputs:
-------
F_2: np.ndarray (float)
Cumulative infiltration at current timestep (m)
F_1: np.ndarray (float)
Cumulative infiltration at next timestep (m)
dt: float
Time step (seconds)
Ks: np.ndarray (float)
Saturated hydraulic conductivity (m/s)
theta_d: np.ndarray (float)
Soil moisture deficit
psi_s: np.ndarray (float)
Soil suction head (m)
"""
F_1 = args[0]
dt = args[1]
Ks = args[2]
theta_d = args[3]
psi_s = args[4]
zero = (psi_s * theta_d / (psi_s * theta_d + F_2)) - 1
return zero

Loading