Rectangular Channel Analysis with Python
How to analyze flow over rectangular channels using Manning's Equation
July 10, 2024
Reading Time: 3 minutes
Open channel analysis is one of the widely-used discipline in civil and hydraulics engineering for the analysis of both drainage and irrigation channels.
In this post, we will see how to analyze flow elements of a rectangular open channel using python
and the library channelflowlib
.
channelflowlib
channelflowlib
is a python module for open channel flow analysis for hydraulics engineering. This is the library that we are going to use in this post.
Requirements
The following are the requirements in order to follow along.
- Code editor (VS Code or any)
- Python interpreter
- Knowledge of using a terminal/command prompt
Python should be installed in the computer in order for use to start using the library.
In order to navigate directories, install dependencies and running the program.
Creating the Project
In order to create the project, let's select a directory and create a new directory for our project. In mine, I will call it sample-rect
short for "sample rectangular".
md sample-rect
mkdir sample-project
Then now create a new file, you can name it anything but I'll call mine main.py
.
Next, let's create a virtual environment (optional) to store our dependencies in our project as project-wide and not globally.
virtualenv venv
Then to activate the virtual environment
venv\Scripts\activate
source ./venv/bin/activate
Installation of channelflowlib
Now to install the library that we are going to use
pip install channelflowlib
Sample Problem
Suppose we have a sample problem with the given data:
Given | Value |
---|---|
Discharge | 1.0 |
Bed Slope | 0.001 |
Base Width | 1.0 |
Manning's n | 0.015 |
In this case, our unknown is the water depth.
Analysis
Now in our code for the analysis of the problem:
In our main.py
from channelflowlib.openchannellib import Rectangular
# Initialize the object
rect = Rectangular(unknown='water_depth')
rect.discharge = 1.0
rect.channel_slope = 0.001
rect.channel_base = 1.0
rect.roughness = 0.015
rect.analyze()
# Display result
print(f"Water depth = {rect.water_depth}")
This would output
Water depth = 0.989
Breakdown
On line 1, we imported the library, specifically the Rectangular
class.
Then on line 4, we initialized a rectangular channel object by specifying the unknown, in our problem, the unknown is 'water_depth'. You can set the unknown to be 'discharge', 'water_depth', 'channel_slope', and 'channel_base'.
Then line 6 - 9 sets the known properties of the channel. Any finally, on line 11, we call the analyze
method to perform channel analysis.
Summary
You can now access other flow elements such as average velocity, wetted perimeter, cross sectional area of water, etc.
That's it for our tutorial today. I hope you can use this.