Python: Calculate the uniform flow depth of a rectangular cross section using the Brent method

In the unequal flow calculation program (normal flow calculation) introduced earlier, it is necessary to specify the water level at the downstream end association, and the equal flow depth is used for it. In other words, it is necessary to know the uniform flow depth. For the time being, you will be solving nonlinear equations, but I think the good thing about Python is that you can do such calculations quickly.

The basic formula for calculating the uniform flow depth of a rectangular cross section is as follows.

\begin{gather}
Q=A\cdot v \\
v=\cfrac{1}{n}\cdot R^{2/3}\cdot i^{1/2} \\
R=\cfrac{b\cdot h}{b+2\cdot h}
\end{gather}
$ Q $ (known) flow rate Mr
$ n $ (Known) Manning Roughness Length
$ i $ (Known) Canal floor gradient
$ h $ (unknown) constant flow depth

The following equation, which is a transformation of the above equation into the form $ f = 0 $, is solved for $ h $.

\begin{equation}
f=Q-\cfrac{b\cdot h}{n}\cdot \left(\cfrac{b\cdot h}{b+2\cdot h}\right)^{2/3}\cdot i^{1/2}=0
\end{equation}

In this program, it is solved using scipy.optimize.brentq. The initial value of the solution given to the Brent method is given as `` `h1 = 0, h2 = 10```.

The calculation of the critical water depth $ h_c $ is a bonus.

The program is as shown below.

# normal depth and critical depth of rectangular cross section
import numpy as np
from scipy import optimize


def cal_hc(q,b):
    # critical depth
    g=9.8
    hc=(q**2/g/b**2)**(1/3)
    return hc


def func(h,q,b,n,i):
    f=q-b*h/n*(b*h/(b+2*h))**(2/3)*i**(1/2)    
    return f    


def main():
    q=42.0  # discharge
    b=4.0   # channel width
    n=0.014 # Manning's roughness coefficient
    i=0.001 # invert gradient
    
    h1=0.0
    h2=10.0
    hh=optimize.brentq(func,h1,h2,args=(q,b,n,i))

    print('hn=',hh) # normal depth
    
    hc=cal_hc(q,b)
    print('hc=',hc) # critical depth
    
#==============
# Execution
#==============
if __name__ == '__main__': main()

The calculation result is as follows.

hn= 3.866645305835682
hc= 2.2407023732785825

That's all. Thank you.

Recommended Posts

Python: Calculate the uniform flow depth of a rectangular cross section using the Brent method
Cut a part of the string using a Python slice
A simple Python implementation of the k-nearest neighbor method (k-NN)
Reuse the behavior of the @property method by using a descriptor [16/100]
A function that measures the processing time of a method in python
Calculate the shortest route of a graph with Dijkstra's algorithm and Python
Calculate the probability of being a squid coin with Bayes' theorem [python]
Hit a method of a class instance with the Python Bottle Web API
[python] [meta] Is the type of python a type?
The story of blackjack A processing (python)
Let Python measure the average score of a page using the PageSpeed Insights API
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
I made a script to record the active window using win32gui of Python
How to calculate the volatility of a brand
Get the caller of a function in Python
Calculate the total number of combinations with python
Make a copy of the list in Python
Calculate the probability of outliers on a boxplot
[Python] A rough understanding of the logging module
Output in the form of a python array
Try using the collections module (ChainMap) of python3
A discussion of the strengths and weaknesses of Python
Approximate a Bezier curve through a specified point using the least squares method in Python
Calculation of the shortest path using the Monte Carlo method
[Python] A program that counts the number of valleys
Calculate volume from the two-dimensional structure of a compound
[Python] Calculate the average value of the pixel value RGB of the object
Destroy the intermediate expression of the sweep method with Python
Determine the threshold using the P tile method in python
A python implementation of the Bayesian linear regression class
Calculate the regression coefficient of simple regression analysis with python
Explanation of the concept of regression analysis using Python Part 1
Steps to calculate the likelihood of a normal distribution
[Python] Summary of table creation method using DataFrame (pandas)
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 2 ~
[Python] Mask the image into a circle using Pillow
Tasks at the start of a new python project
Explanation of the concept of regression analysis using Python Extra 1
Study from the beginning of Python Hour8: Using packages
A reminder about the implementation of recommendations in Python
I tried using Python (3) instead of a scientific calculator
[Python] A program that compares the positions of kangaroos.
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 3 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 4 ~
Calculate the product of matrices with a character expression?
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 5 ~
A little bit from Python using the Jenkins API
Python Note: The mystery of assigning a variable to a variable