from scipy.optimize import root def manningC(d, args): Q, w,h,sSlopeL,sSlopeR,nMann,lSlope = args #left side slope can be different from right side slope area = ((((d*sSlopeL)+(d*sSlopeR)+w)+w)/2)*d # wet perimeter wPer = w+(d*(sSlopeL*sSlopeL+1)**0.5)+(d*(sSlopeR*sSlopeR+1)**0.5) #Hydraulic Radius hR = area/ wPer # following formula must be zero # manipulation of Manning's formula mannR = (Q*nMann/lSlope**0.5)-(area*hR**(2.0/3.0)) return mannR ###### MAIN CODE # the following are input data to our open channel manning calculation # flow, width, height, left side slope, right side slope, # Manning coefficient, longitudinal slope args0 = [2.5,2,.5,1.0,1.0,.015,.005] initD = .00001 # initial water depth value # then we call the root scipy function to the manningC sol =root(manningC,initD, args=(args0,)) # print the root found print(sol.x)
Python programming, with examples in hydraulic engineering and in hydrology.
Showing posts with label manning's formula. Show all posts
Showing posts with label manning's formula. Show all posts
Wednesday, May 2, 2018
Solve Manning's Equation with Python Scipy library
Wednesday, July 19, 2017
Solving Manning's equation for channels with Python
Manning's equation is a very common formula used in hydraulic engineering. It is an empirical formula that estimates the average velocity of open channel flow, based on a roughness coefficient.

The problem of solving Manning's formula is that it is an implicit formula - the water depth variable (independent variable) is inside R (Hydraulic Radius) and A (flow area) - becoming dificult to isolate the independent variable.
A common approach for solving this equation is to use numerical methods, as the Newton-Raphson method.
In this case, we try different water depths until the function
- a manipulation of the original manning formula, became equal to zero.
An implementation for the resolution of the above, for open channels and using the Newton-Raphson approximation, is shown below.
If you found this code of this explanation useful, please let me know.
def manningC(lam, args): Q,base,alt,talE,talD,nMann,decl = args area = ((((lam*talE)+(lam*talD)+base)+base)/2)*lam perM = base+(lam*(talE*talE+1)**0.5)+(lam*(talD*talD+1)**0.5) raio = area/ perM mannR = (Q*nMann/decl**0.5)-(area*raio**(2.0/3.0)) return mannR def solve(f, x0, h, args): lastX = x0 nextX = lastX + 10* h # "different than lastX so loop starts OK while (abs(lastX - nextX) > h): # this is how you terminate the loop - note use of abs() newY = f(nextX,args) # just for debug... see what happens # print out progress... again just debug print lastX," -> f(", nextX, ") = ", newY lastX = nextX nextX = lastX - newY / derivative(f, lastX, h, args) # update estimate using N-R return nextX def derivative(f, x, h, args): return (f(x+h,args) - f(x-h,args)) / (2.0*h) if __name__=='__main__': # arguments in this case are - flow, bottom width, height, # Left side slope, rigth side slope, manning, longitudinal slope args0 = [2.5,1,.5,1.0,1.0,.015,.005] initD = .01 # call the solver with a precision of 0.001 xFound = solve(manningC, initD, 0.001, args0) print 'Solution Found - Water depth = %.3f' %xFound
Friday, July 29, 2016
Solving Manning's equation with Python
Manning's equation is a very common formula used in hydraulic engineering. It is an empirical formula that estimates the average velocity of open channel flow, based on a roughness coefficient.

The problem of solving Manning's formula is that it is an implicit formula, for the water depth variable, that defines the R (Hydraulic Radius).
A common approach for solving this equation is using numerical methods, as the Newton-Raphson method. An implementation for the resolution of the Manning Formula for pipes, by the Newton-Raphson approximation, is shown below.

The problem of solving Manning's formula is that it is an implicit formula, for the water depth variable, that defines the R (Hydraulic Radius).
A common approach for solving this equation is using numerical methods, as the Newton-Raphson method. An implementation for the resolution of the Manning Formula for pipes, by the Newton-Raphson approximation, is shown below.
def manningTub(depth, args): Q = args[0] diamMM = args[1] nMann = args[2] slope = args[3] diamM = diamMM / 1000.0 angle = 2*acos(1-2*depth/diamM) area = diamM*diamM/8.0*(angle-sin(angle)) radius = diamM/4*(1-sin(angle)/angle) mannR = (Q*nMann/slope**0.5)-(area*radius**(2.0/3.0)) return mannR def solve(f, x0, h, args): lastX = x0 nextX = lastX + 10* h # "different than lastX so loop starts OK while (abs(lastX - nextX) > h): # this is how you terminate the loop - note use of abs() newY = f(nextX,args) # just for debug... see what happens print "f(", nextX, ") = ", newY # print out progress... again just debug lastX = nextX nextX = lastX - newY / derivative(f, lastX, h, args) # update estimate using N-R return nextX def derivative(f, x, h, args): return (f(x+h,args) - f(x-h,args)) / (2.0*h) # might want to return a small non-zero if ==0 #### EXAMPLE CALL xFound = solve(manningTub, initDepth, 0.001, [flowRate,diam,nMann,enSlope]) # call the solver
Subscribe to:
Posts (Atom)