Assignment 5 – Find Depth of Flow in an Open Channel

Outcome

Use NumPy library functions and the Newton-Raphson iterative method to solve a nonlinear equation numerically

Note: This assignment must be submitted in Colab (Jupyter format). You can cut/paste code and report from other tools into Colab or do the entire assignment directly in Colab. Colab has a share notebook link that you can copy and paste as your submission.

https://colab.research.google.com/

Assignment

The Mannings Equation finds the Flow Q (cubic feet per second or cfs) in an open channel. The equation is

Q = 1.49/n * A * R^2/3 * S^1/2

Where

Q = Flowrate in cfs
A = Cross Sectional Area of Flow (square feet)
R = Hydraulic Radius (A/ Wetted Perimeter)
S = Downward Slope of the Channel (fraction)

The Wetted Perimeter and the Cross-Section of Flow are both dependent on the channel's geometry. For this assignment, we will use a Trapezoidal Channel.

If you work out the Flow Area, you will find it is

A = b*y + y*(z*y) = by + z*y^2

The Wetted Perimeter is a little trickier, but a little geometry will show it to be

W = b + 2y(1 + z^2)^1/2

where b = base width (ft); z = Side slope (horizontal to vertical = 1); y = depth.

Putting it all together gives a Hydraulic Radius of

R = (b*y + z*y^2)/(b + 2y*(1+z^2))^1/2

All this goes into the Mannings Equation

Q = 1.49/n * (b*y + z*y^2) * ((b*y + z*y^2)/(b + 2y(1+z^2))^1/2)^2/3 * S^1/2

Luckily, I will give you the code for this equation in Python. You are free to use this code. Note that you will be solving for y (depth) by reformulating this equation as a root-finding problem and applying an iterative technique.

import numpy as np

def TrapezoidalQ(n, b, y, z, s):
   # n is Manning's n - table at
   # https://www.engineeringtoolbox.com/mannings-roughness-d_799.html
   # b = Bottom width of channel (ft)
   # y = Depth of channel (ft)
   # z = Side slope of channel (horizontal)
   # s = Directional slope of channel - direction of flow
   A = b*y + z*y*y
   W = b + 2*y*np.sqrt(1 + z*z)
   R = A/W
   Q = 1.49/n * A * np.power(R, 2.0/3.0) * np.sqrt(s)
   return Q

As an engineer, you are designing a warning system that must trigger when the flow is 50 cfs, but your measuring system measures depth. What will be the depth at which you trigger the alarm?

Values to Use:

Manning's n for "Earth Channel – Clean" (you need to look this up - you can use https://www.engineeringtoolbox.com/mannings-roughness-d_799.html )
b = 3 foot bottom
z = 2 Horiz : 1 Vert Side Slope
s = 1 foot drop for every 100 feet

(hint: A depth of 1 foot will give you Q = 25.1 cfs)

Write the program code and create a document that demonstrates you can use NumPy and the Newton-Raphson method to solve this problem.

You should write a function called CalculateDepth(Q_target, n, b, z, s). Inputs should be the target flowrate (Q_target), Manning's roughness coefficient (n), Bottom Width (b), Side Slope (z), and Longitudinal Slope (s). Your function must use the Newton-Raphson method — either by implementing it manually or by calling the appropriate NumPy/SciPy library function — to converge on a solution with 0.001 foot accuracy.

A key part of this assignment is investigating which Python library function is best suited for this type of root-finding problem. Before writing your final solution, you should research and compare at least two available options (for example, scipy.optimize.newton, scipy.optimize.brentq, or a manually coded Newton-Raphson loop using NumPy). In your report, explain why you selected the method you chose.

The Newton-Raphson method requires you to reformulate the problem as finding the root of a function f(y) = 0. To apply Newton-Raphson, you will also need the derivative f'(y) with respect to depth y. You may derive this analytically or use NumPy's numerical differentiation capabilities. Your code should demonstrate the iterative steps converging toward the solution.

You should also include a plot of Flow (Q) vs. Depth using NumPy arrays and Matplotlib, with the solution point clearly labeled on the plot.

Report

The methodology of your report must describe the Newton-Raphson method and explain how you reformulated the Manning's Equation problem as a root-finding problem. You must compare at least two Python library approaches and justify your final selection. You must also report the depth for the specified flow rate. A plot of flow rate (Q) vs. depth with the solution labeled on the plot is required in the report.

Report Format (Details at Submission Guidelines (Engineering Reports) )
Cover - Name/Date/Class/Assignment #
Problem Statement - Copy/Paste and then modify to state problem
Methodology - The approach to the problem — describe the Newton-Raphson method, how f(y) was defined, how the derivative was obtained, and which library function was selected and why
Results - Be sure to answer the problem asked in the problem statement; include the Q vs. depth plot with solution labeled
Conclusion - This can be short; include any observations about convergence behavior or library selection
Appendices - Code or any additional information here