Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifications to RiverFlowDynamics #1

Merged
Merged
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
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"<a href=\"http://landlab.github.io\"><img style=\"float: left\" src=\"../../landlab_header.png\"></a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 2D Surface Water Flow component\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<small>For more Landlab tutorials, click here: <a href=\"https://landlab.readthedocs.io/en/latest/user_guide/tutorials.html\">https://landlab.readthedocs.io/en/latest/user_guide/tutorials.html</a></small>\n",
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -66,7 +49,7 @@
"\n",
"A semi-implicit, semi-Lagrangian, finite volume numerical approximation represents the depth averaged, 2D shallow-water equations described before. The water surface elevation, $\\eta$, is defined at the center of each computational volume (nodes). Water depth, $H$, and velocity components, $U$ and $V$, are defined at the midpoint of volume faces (links). The finite volume structure provides a control volume representation that is inherently mass conservative.\n",
"\n",
"The combination of a semi-implciit water surface elevation solution and a semi-Lagrangian representation of advection provides the advantages of a stable solution and of time steps that exceed the CFL criterion. In the semi-implicit process, $\\eta$ in the momentum equations, and the velocity divergence in the continuity equation, are trated implicitly. The advective terms in the momentum equations, are discretized explicitly. See the cited literature for more details.\n",
"The combination of a semi-implciit water surface elevation solution and a semi-Lagrangian representation of advection provides the advantages of a stable solution and of time steps that exceed the CFL criterion. In the semi-implicit process, $\\eta$ in the momentum equations, and the velocity divergence in the continuity equation, are treated implicitly. The advective terms in the momentum equations, are discretized explicitly. See the cited literature for more details.\n",
"\n",
"### The component\n",
"\n",
Expand All @@ -82,11 +65,11 @@
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from IPython.display import clear_output\n",
"from tqdm import trange\n",
"\n",
"from landlab import RasterModelGrid\n",
"from landlab.components import river_flow_dynamics\n",
"from landlab.io import read_esri_ascii\n",
"from landlab.plot.imshow import imshow_grid"
"from landlab.io import esri_ascii"
]
},
{
Expand Down Expand Up @@ -129,8 +112,8 @@
"outputs": [],
"source": [
"# Basic parameters\n",
"n = 0.012 # Manning's roughness coefficient, [s/m^(1/3)]\n",
"S0 = 0.01 # Channel slope [m/m]\n",
"mannings_n = 0.012 # Manning's roughness coefficient, [s/m^(1/3)]\n",
"channel_slope = 0.01 # Channel slope [m/m]\n",
"\n",
"# Simulation parameters\n",
"n_timesteps = 100 # Number of timesteps\n",
Expand Down Expand Up @@ -172,8 +155,9 @@
"outputs": [],
"source": [
"# The grid represents a basic rectangular channel with slope equal to 0.01 m/m\n",
"te = grid.add_zeros(\"topographic__elevation\", at=\"node\")\n",
"te += 1.0 - S0 * grid.x_of_node\n",
"te = grid.add_field(\n",
" \"topographic__elevation\", 1.0 - channel_slope * grid.x_of_node, at=\"node\"\n",
")\n",
"te[grid.y_of_node > 1.5] = 2.5\n",
"te[grid.y_of_node < 0.5] = 2.5"
]
Expand All @@ -192,7 +176,7 @@
"outputs": [],
"source": [
"# Showing the topography\n",
"imshow_grid(grid, \"topographic__elevation\")"
"grid.imshow(\"topographic__elevation\")"
]
},
{
Expand All @@ -215,8 +199,7 @@
"vel = grid.add_zeros(\"surface_water__velocity\", at=\"link\")\n",
"\n",
"# Calculating the initial water surface elevation from water depth and topographic elevation\n",
"wse = grid.add_zeros(\"surface_water__elevation\", at=\"node\")\n",
"wse += h + te"
"wse = grid.add_field(\"surface_water__elevation\", te, at=\"node\")"
]
},
{
Expand Down Expand Up @@ -284,7 +267,7 @@
"rfd = river_flow_dynamics(\n",
" grid,\n",
" dt=dt,\n",
" mannings_n=n,\n",
" mannings_n=mannings_n,\n",
" fixed_entry_nodes=fixed_entry_nodes,\n",
" fixed_entry_links=fixed_entry_links,\n",
" entry_nodes_h_values=entry_nodes_h_values,\n",
Expand All @@ -305,31 +288,18 @@
"metadata": {},
"outputs": [],
"source": [
"# The simulation may take a long time to run,\n",
"# so we added a progress report\n",
"progress0 = 0\n",
"# Set the animation frequency to n_timesteps if you\n",
"# don't want to plot the water depth\n",
"# display_animation_freq = n_timesteps\n",
"display_animation_freq = 5\n",
"\n",
"# Set displayAnimation to True if you want to see how\n",
"# the water moves throughout the channel\n",
"displayAnimation = True\n",
"displayAnimationFreq = 5\n",
"disp = 0\n",
"\n",
"for timestep in range(n_timesteps):\n",
"grid.imshow(\"surface_water__depth\", output=True)\n",
"for timestep in trange(n_timesteps):\n",
" rfd.run_one_step()\n",
"\n",
" progress = int(((timestep + 1) / n_timesteps) * 100)\n",
" if progress > progress0 + 1:\n",
" print(\"\\r\" + f\"Progress: [{progress}%]\", end=\"\")\n",
" progress0 = progress\n",
"\n",
" if disp >= displayAnimationFreq:\n",
" if timestep % display_animation_freq == 0:\n",
" clear_output(wait=True) # This will clear the previous image\n",
" imshow_grid(grid, \"surface_water__depth\")\n",
" plt.show()\n",
" disp = -1\n",
"\n",
" disp += 1"
" grid.imshow(\"surface_water__depth\", output=True)"
]
},
{
Expand All @@ -345,7 +315,7 @@
"metadata": {},
"outputs": [],
"source": [
"imshow_grid(grid, \"surface_water__depth\")"
"grid.imshow(\"surface_water__depth\")"
]
},
{
Expand All @@ -361,7 +331,7 @@
"metadata": {},
"outputs": [],
"source": [
"imshow_grid(grid, \"surface_water__elevation\")"
"grid.imshow(\"surface_water__elevation\")"
]
},
{
Expand All @@ -382,7 +352,9 @@
"source": [
"# Getting the grid and some parameters\n",
"asc_file = \"DEM-kootenai_37x50_1x1.asc\"\n",
"(grid, teDEM) = read_esri_ascii(asc_file, grid=None, reshape=False, name=None, halo=0)"
"with open(asc_file) as fp:\n",
" grid = esri_ascii.load(fp, name=\"topographic__elevation\")\n",
"te = grid.at_node[\"topographic__elevation\"]"
]
},
{
Expand All @@ -399,31 +371,13 @@
"outputs": [],
"source": [
"# Basic parameters\n",
"n = 0.012 # Manning's roughness coefficient, [s/m^(1/3)]\n",
"mannings_n = 0.012 # Manning's roughness coefficient, [s/m^(1/3)]\n",
"\n",
"# Simulation parameters\n",
"n_timesteps = 75 # Number of timesteps\n",
"dt = 1.0 # Timestep duration, [s]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Since the topography is provided by the DEM, we just need to assign it to our `\"topographic__elevation\"` field. It also provides the number of nodes and grid spacing, because they are inherent properties of the DEM."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# The grid represents a basic rectangular channel with slope equal to 0.01 m/m\n",
"te = grid.add_zeros(\"topographic__elevation\", at=\"node\")\n",
"te += teDEM"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -438,7 +392,7 @@
"outputs": [],
"source": [
"# Showing the topography\n",
"imshow_grid(grid, \"topographic__elevation\")"
"grid.imshow(\"topographic__elevation\")"
]
},
{
Expand All @@ -461,8 +415,7 @@
"vel = grid.add_zeros(\"surface_water__velocity\", at=\"link\")\n",
"\n",
"# Calculating the initial water surface elevation from water depth and topographic elevation\n",
"wse = grid.add_zeros(\"surface_water__elevation\", at=\"node\")\n",
"wse += h + te"
"wse = grid.add_field(\"surface_water__elevation\", te, at=\"node\")"
]
},
{
Expand Down Expand Up @@ -607,7 +560,7 @@
"rfd = river_flow_dynamics(\n",
" grid,\n",
" dt=dt,\n",
" mannings_n=n,\n",
" mannings_n=mannings_n,\n",
" fixed_entry_nodes=fixed_entry_nodes,\n",
" fixed_entry_links=fixed_entry_links,\n",
" entry_nodes_h_values=entry_nodes_h_values,\n",
Expand All @@ -628,31 +581,18 @@
"metadata": {},
"outputs": [],
"source": [
"# The simulation may take a long time to run,\n",
"# so we added a progress report\n",
"progress0 = 0\n",
"\n",
"# Set displayAnimation to True if you want to see how\n",
"# the water moves throughout the channel\n",
"displayAnimation = True\n",
"displayAnimationFreq = 5\n",
"disp = 0\n",
"# Set the animation frequency to n_timesteps if you\n",
"# don't want to plot the water depth\n",
"# display_animation_freq = n_timesteps\n",
"display_animation_freq = 5\n",
"\n",
"for timestep in range(n_timesteps):\n",
"grid.imshow(\"surface_water__depth\", output=True)\n",
"for timestep in trange(n_timesteps):\n",
" rfd.run_one_step()\n",
"\n",
" progress = int(((timestep + 1) / n_timesteps) * 100)\n",
" if progress > progress0 + 1:\n",
" print(\"\\r\" + f\"Progress: [{progress}%]\", end=\"\")\n",
" progress0 = progress\n",
"\n",
" if disp >= displayAnimationFreq:\n",
" if timestep % display_animation_freq == 0:\n",
" clear_output(wait=True) # This will clear the previous image\n",
" imshow_grid(grid, \"surface_water__depth\")\n",
" plt.show()\n",
" disp = -1\n",
"\n",
" disp += 1"
" grid.imshow(\"surface_water__depth\", output=True)"
]
},
{
Expand All @@ -668,7 +608,7 @@
"metadata": {},
"outputs": [],
"source": [
"imshow_grid(grid, \"surface_water__depth\")"
"grid.imshow(\"surface_water__depth\")"
]
},
{
Expand Down Expand Up @@ -708,9 +648,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.12.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Loading
Loading