import numpy as np
import matplotlib.pyplot as plt
from boreflow import BCArray, Geometry, Simulation, Flux, Limiter, TimeIntegration
Example of the BoreFlow package
Example calculation of a predefined flow on a horizontal surface and a steep slope.
# 1) Create geometry
= np.array([0, 2, 11]) # X-coordinate x[i]
x = np.array([3, 3, 0]) # Elevation z[i] at x[i]
z = np.array([0.0175, 0.0175]) # Manning roughness (n) between x[i] and x[i+1]
n = Geometry(x, z, n)
geometry
# Plot the geometry
plt.figure()="black", label="Geometry")
plt.plot(x, z, color0]], [z[0]], "o", color="red", label="Inflow")
plt.plot([x[-1]], [z[-1]], "o", color="blue", label="Free outflow")
plt.plot([x[
plt.legend()"x-coordinate [m]")
plt.xlabel("z-coordinate [m]")
plt.ylabel("equal")
plt.axis( plt.show()
# 2) Create boundary conditions
= np.array([0, 1, 4])
t = np.array([0.5, 0.8, 0])
h = np.array([1.0, 2.0, 0])
u = BCArray(t, h, u)
bc
# 3) Initialize simulation settings
= Simulation(t_end=10.0, cfl=0.2, max_dt=0.01, nx=110)
sim
# 4) Run the simulation
= sim.run(geometry, bc, Limiter.minmod, Flux.HLL, TimeIntegration.EF) results
Simulating: 0%| | 0.00/10.00 sSimulating: 6%|▌ | 0.55/10.00 sSimulating: 11%|█ | 1.10/10.00 sSimulating: 15%|█▍ | 1.49/10.00 sSimulating: 18%|█▊ | 1.78/10.00 sSimulating: 20%|██ | 2.01/10.00 sSimulating: 22%|██▏ | 2.19/10.00 sSimulating: 23%|██▎ | 2.33/10.00 sSimulating: 25%|██▍ | 2.45/10.00 sSimulating: 26%|██▌ | 2.56/10.00 sSimulating: 27%|██▋ | 2.65/10.00 sSimulating: 27%|██▋ | 2.74/10.00 sSimulating: 28%|██▊ | 2.82/10.00 sSimulating: 29%|██▉ | 2.89/10.00 sSimulating: 30%|██▉ | 2.96/10.00 sSimulating: 30%|███ | 3.03/10.00 sSimulating: 31%|███ | 3.10/10.00 sSimulating: 32%|███▏ | 3.17/10.00 sSimulating: 32%|███▏ | 3.24/10.00 sSimulating: 33%|███▎ | 3.31/10.00 sSimulating: 34%|███▍ | 3.38/10.00 sSimulating: 35%|███▍ | 3.45/10.00 sSimulating: 35%|███▌ | 3.52/10.00 sSimulating: 36%|███▌ | 3.59/10.00 sSimulating: 37%|███▋ | 3.66/10.00 sSimulating: 37%|███▋ | 3.73/10.00 sSimulating: 38%|███▊ | 3.81/10.00 sSimulating: 39%|███▉ | 3.88/10.00 sSimulating: 40%|███▉ | 3.95/10.00 sSimulating: 40%|████ | 4.03/10.00 sSimulating: 41%|████ | 4.11/10.00 sSimulating: 42%|████▏ | 4.18/10.00 sSimulating: 43%|████▎ | 4.26/10.00 sSimulating: 43%|████▎ | 4.34/10.00 sSimulating: 44%|████▍ | 4.42/10.00 sSimulating: 45%|████▌ | 4.50/10.00 sSimulating: 46%|████▌ | 4.58/10.00 sSimulating: 47%|████▋ | 4.67/10.00 sSimulating: 48%|████▊ | 4.75/10.00 sSimulating: 48%|████▊ | 4.84/10.00 sSimulating: 49%|████▉ | 4.93/10.00 sSimulating: 50%|█████ | 5.02/10.00 sSimulating: 51%|█████ | 5.11/10.00 sSimulating: 52%|█████▏ | 5.21/10.00 sSimulating: 53%|█████▎ | 5.30/10.00 sSimulating: 54%|█████▍ | 5.40/10.00 sSimulating: 55%|█████▌ | 5.51/10.00 sSimulating: 56%|█████▌ | 5.61/10.00 sSimulating: 57%|█████▋ | 5.72/10.00 sSimulating: 58%|█████▊ | 5.84/10.00 sSimulating: 60%|█████▉ | 5.95/10.00 sSimulating: 61%|██████ | 6.08/10.00 sSimulating: 62%|██████▏ | 6.20/10.00 sSimulating: 63%|██████▎ | 6.34/10.00 sSimulating: 65%|██████▍ | 6.48/10.00 sSimulating: 66%|██████▋ | 6.63/10.00 sSimulating: 68%|██████▊ | 6.78/10.00 sSimulating: 69%|██████▉ | 6.94/10.00 sSimulating: 71%|███████ | 7.11/10.00 sSimulating: 73%|███████▎ | 7.29/10.00 sSimulating: 75%|███████▍ | 7.48/10.00 sSimulating: 77%|███████▋ | 7.68/10.00 sSimulating: 79%|███████▉ | 7.88/10.00 sSimulating: 81%|████████ | 8.11/10.00 sSimulating: 83%|████████▎ | 8.34/10.00 sSimulating: 86%|████████▌ | 8.58/10.00 sSimulating: 88%|████████▊ | 8.83/10.00 sSimulating: 91%|█████████ | 9.08/10.00 sSimulating: 93%|█████████▎| 9.33/10.00 sSimulating: 96%|█████████▌| 9.58/10.00 sSimulating: 98%|█████████▊| 9.83/10.00 sSimulating: 100%|██████████| 10.00/10.00 s
Simulation done in 8.20 sec
# Plot peak flow velocity and peak flow thickness
= plt.subplots(1, 3, figsize=[8, 3.5])
fig, (ax0, ax1, ax2)
# Mark the transition between the horizontal surface and the sloped surface (x = 2m / s = 2m)
2.0, color="grey", ls=":") for ax in [ax0, ax1, ax2]]
[ax.axvline(
# Get and plot peak flow characteristics
= results.get_peak_flow()
h, u, q ="black")
ax0.plot(results.s, h, color="black")
ax1.plot(results.s, u, color="black")
ax2.plot(results.s, q, color
# Plot layout
"Distance along geometry (s-coordinate) [m]") for ax in [ax0, ax1, ax2]]
[ax.set_xlabel("Peak flow thickness [m]")
ax0.set_ylabel("Peak depth-avg flow velocity [m/s]")
ax1.set_ylabel("Peak flow discharge [m2/s]")
ax2.set_ylabel(0, np.max(results.s)) for ax in [ax0, ax1, ax2]]
[ax.set_xlim(0, None) for ax in [ax0, ax1, ax2]]
[ax.set_ylim("Peak Flow Characteristics along Geometry")
fig.suptitle(
fig.tight_layout() plt.show()
# Plot
= plt.subplots(1, 2, figsize=[8, 4])
fig, (ax0, ax1)
# Get and plot the flow at s=5m
= results.get_st(s=5.0)
res_t, res_h, res_u ="black")
ax0.plot(res_t, res_h, color="black")
ax1.plot(res_t, res_u, color
# Plot layout
"Time [s]") for ax in [ax0, ax1]]
[ax.set_xlabel("Flow thickness [m]")
ax0.set_ylabel("Depth-avg flow velocity [m/s]")
ax1.set_ylabel(0, np.max(res_t)) for ax in [ax0, ax1]]
[ax.set_xlim(0, None) for ax in [ax0, ax1]]
[ax.set_ylim("Temporal Evolution of Flow at s = 5m")
fig.suptitle(
fig.tight_layout() plt.show()