pipedream

🚰 Interactive hydrodynamic solver for pipe and channel networks

View the Project on GitHub mdbartos/pipedream

Overview

    â€¢ Governing equations
    â€¢ Model structure

Examples

    â€¢ Flow on hillslope
    â€¢ Simulation context manager
    â€¢ Contaminant transport on hillslope
    â€¢ Uncoupled overland flow
    â€¢ Coupled overland flow
    â€¢ Simple dynamic control example
    â€¢ Adaptive step size control
    â€¢ Validation with real-world network
    â€¢ Kalman filtering with holdout analysis

Reference

    â€¢ Hydraulic solver API reference
    â€¢ Infiltration solver API reference
    â€¢ Water quality solver API reference
    â€¢ Model inputs
    â€¢ Hydraulic geometry reference

Fully coupled infiltration and runoff routing

Import modules

import numpy as np
import pandas as pd
from pipedream_solver.hydrology import GreenAmpt
from pipedream_solver.hydraulics import SuperLink
from pipedream_solver.simulation import Simulation

import matplotlib.pyplot as plt
import seaborn as sns

Load model data

input_path = '../data/hillslope'
superjunctions = pd.read_csv(f'{input_path}/hillslope_superjunctions.csv')
superlinks = pd.read_csv(f'{input_path}/hillslope_superlinks.csv')
soil_params = pd.read_csv(f'{input_path}/hillslope_soil_params.csv')

Inspect soil parameters

soil_params.head()
psi_f Ks theta_s theta_i A_s
0 0.020529 0.000011 0.37 0.15 108.695652
1 0.020529 0.000011 0.37 0.15 217.391304
2 0.020529 0.000011 0.37 0.15 217.391304
3 0.020529 0.000011 0.37 0.15 217.391304
4 0.020529 0.000011 0.37 0.15 217.391304

Instantiate hydraulic/infiltration models

internal_links = 24
superlink = SuperLink(superlinks, superjunctions, internal_links=internal_links)
greenampt = GreenAmpt(soil_params)

Specify precipitation inputs

# Specify precipitation on each soil element in (m/s)
i_0 = 50 / 1000 / 3600 * np.ones(superlink.NIk)
i_1 = np.zeros(superlink.NIk)
# Create dict to collect infiltration data
f = {}

# Set initial timestep
dt = 15

# Spin up model
superlink.spinup(n_steps=200)

# Create simulation context manager
with Simulation(superlink, t_start=0, t_end=(18 * 3600)) as simulation:
    # While simulation time has not expired...
    while simulation.t <= simulation.t_end:
        greenampt.d = superlink.h_Ik
        if simulation.t < (12 * 3600):
            greenampt.step(dt=dt, i=i_0)
        else:
            greenampt.step(dt=dt, i=i_1)
        Q_Ik = greenampt.Q
        # Step hydraulic model forward in time
        simulation.step(dt=dt, Q_Ik=Q_Ik)
        # Record internal depth and flow states
        simulation.record_state()
        f[simulation.t] = greenampt.f.copy()
        # Print progress bar
        simulation.print_progress()
[==================================================] 100.0% [4.33 s]

Visualize hydraulic modeling results

sns.set_palette('cool')
_ = simulation.model.plot_profile([0, 1], width=100)

png

sns.set_palette('rainbow_r', internal_links + 1)
simulation.states.h_Ik.plot(legend=False)

plt.title('Internal junction depths')
plt.ylabel('Depth (m)')
plt.xlabel('Time (s)')

png

sns.set_palette('rainbow_r', internal_links)
simulation.states.Q_ik.plot(legend=False)

plt.title('Internal link flows')
plt.ylabel('Flow (cms)')
plt.xlabel('Time (s)')

png

f = pd.DataFrame.from_dict(f, orient='index')

f.plot(legend=False)
plt.title('Infiltration in channel segments')
plt.xlabel('Time (s)')
plt.ylabel('Infiltration rate (m/s)')

png