Pipe Flow  Open Channel Flow

12172016, 08:09 PM
(This post was last modified: 01082017 03:20 AM by Gene222.)
Post: #1




Pipe Flow  Open Channel Flow
This program calculates either the depth or flow rate for open channel flow in circular pipes using Manning’s Equation in English or Metric units. The depth is calculated by a trial and error process.
When using the program, the input screen asks for values of UNITS, DIAM, D, S, N, and Q. To solve for the depth of flow, enter a 0 for D; or to solve for Q, enter a 0 for Q. UNITS, 0 for English units or 1 for Metric units. DIAM, diameter in inch or millimeters D, depth in inch or millimeters S, slope in decimal form, such as 0.005 N, Manning n value Q, flow rate in ft^3/s or m^3/s After all the values have been entered, press the “OK” screen tab located at the lower right of the screen. The results are printed on the terminal screen. EDIT This program is only accurate to 3 or 31/2 digits. This program is a conversion of an old FORTRAN program that was printed in Schaum’s Solved Problems in Fluid Mechanics & Hydraulics, 1989. When I saw this program many years ago, I could never figure out how this program worked. So, I wrote this program just to see what made the FORTRAN program tick and to learn more on programming the HP Prime. The FORTRAN program used punch cards, so it was probably written in the 1960s or 70s. A copy of the FORTRAN program is attached at the end. The rest of what follows is a discussion on how the program works. Manning Equation The program uses Manning equation for a circular pipe and solves the flow depth by a trial and error process. Manning Equation, Q = (k/n)*A*R^(2/3)*SQRT(S), was simplified by moving the constants and known variables to the left side of the equation and the unknown variables to the right side of the equation. Q*n /(k*SQRT(S)) = A*R^(2/3), or Q*n/k/SQRT(S) = A*R^(2/3) Substituting in A/WP = R gives Q*n/k/SQRT(S) = A * (A/WP)^(2/3), or Q*n/k/SQRT(S) = A^(5/3) / WP^(2/3) The constants and known variables are lump together in a single variable called AWP, where AWP = Q*n/k/SQRT(S). This leaves Manning’s Equation in the form of: AWP = A^(5/3) / WP^(2/3) To solve the above equation for depth by a trial and error process, Manning equation was rearranged to equal zero. A^(5/3) / WP^(2/3) – AWP = 0 A depth is assumed and plugged into above the equation. When a depth is found that satisfies the equation, meaning the left side of the equation equals zero, the correct depth is found. The program assumes an initial DEPTH = 0.001 in feet or meters, and calculates the A and WP using a subroutine. A and WP is plugged into the above equation and stored in TRY1, in other words, TRY1 = A^(5/3) / WP^(2/3) – AWP. Using a FOR loop, the DEPTH is incremented to 0.002. A and WP are calculated for D=0.002, and plugged into the above equation. The results are stored in TRY2. To determine if a solution to the modified Manning equation is found, TRY1 (results from the previous iteration) is multiplied by TRY2 (results for the current iteration). When Try1*TRY2 is less than zero, the solution for the DEPTH is found. This works because when the DEPTH is incremented from 0.001 and upwards, the TRY1 and TRY2 values are positive. When DEPTH is incremented just past the solution for DEPTH, TRY1 is positive, and TRY2 is negative. If you were to continue with the iterations, TRY1 and TRY2 would both be negative. Area and Wetted Perimeter Formulas The subroutine AREAWP() calculates the flow area and wetted perimeter given the diameter, radius, depth. There are different formulas for (1) a pipe less than half full and (2) a pipe more than half full. The formulas were difficult to figure out from the FORTRAN program. They were based on pipe diagrams shown below. The area and wetted perimeter formulas and how they were derived are attached at the end as a PDF file. These formulas are in radians, and would require the calculator to be set to radian mode. When the calculator was in degree mode, the ACOS function returns an angle in degrees, giving you the wrong answer. In early versions of the HP Prime calculator, I think you could program the calculator to switch to radian mode at the beginning of the program. Then perform the calculations in radian mode, and then switch back to degree mode at the end of the program, but you cannot do this for the current version. EDIT  It is possible to program the calculator to switch to radian mode. See the 5th post below. The formulas were rewritten so that the subroutine will work if the calculator is in degree or radian mode. This required two sets of formulas for calculating the area and wetted perimeter. One set is used when the calculator is in radian mode, the other set is used when the calculator is in degree mode. By using two sets of formulas, the user does not need to manually to switch the calculator to radian mode before running the program. English and Metric Units Manning equation can be solved for English or SI units simply by changing the k coefficient and using the appropriate units. So, the same variables and equations are used whether you have Metric units or English units. However, the depth and pipe diameters are in inches or millimeters. After the depth and diameter are entered in by the user, the depth and diameter variables are converted to feet or meters. All subsequent calculations are calculated in feet or meters. When the depth or Q value is solved by the program, the depth and diameter variables are converted back to inches or millimeters. The results of the program are printed out, where the depth and diameter are printed out in inches or millimeters. The FORTRAN program did not quite do this. It calculated the area in square inches or square millimeters and the wetted perimeter in inches or millimeters. This was too confusing, so, I changed the program to calculate the area and wetted perimeter in units of feet or meters. Global variables and use of the subroutine UNITS, DIAM and DEPTH were defined as global variables. If the program is run a second time, the previous values of UNITS, DIAM, and DEPTH will be retained by the calculator and be shown on the input screen. This is intentional, because it is sometimes convenient. Variables N, S, and Q are already predefined by the calculator, and do not need to be declared. They function like global variables. So, when the program is run a seconded time, the previous values will be shown in the input screen. All of the local variables were defined with the local statement placed above and outside the main program. By doing so, the local variables can be access by both the main program and subroutine. This eliminates the need to define which variables need to be passed from the main program to the subroutine, and which variables need to be returned from the subroutine to the main program. Problems with the program The FORTRAN program used a lot of GO TO statements. The HP Prime does not have GO TO statements. So, the GO TO statements were replaced with IF, IF/ELSE, and FOR loop statements. I could not figure out how to print out an error message if the flow rate exceeds the capacity of the pipe for open channel flow as was done in the FORTRAN program, because there was no GO TO statement in the HP Prime. The HP Prime program will stop and a give a “PIPE Error: Invalid input” error message when solving for depth where the flow rate exceeds the capacity of the pipe. EDIT  See the 3rd post below for solution to print an error message. If the depth of flow (depth/dia) is above about 0.82, there are two solutions for the given Q. When solving for the depth, the trial and error process starts at a depth of 0.001 and increases the depth by 0.001 until it finds a solution for the depth. So, this program will only find the first solution for the depth. Check Problems The program does not give the exact answers, but it is pretty close. EDIT The problems below have the exact answers, so you can see how accurate the program is. English Units, depth less than half full UNITS = 0 Pipe Diameter (DIAM) = 24 in DEPTH = 5.6 in (y/D = 0.23333) Slope S = 0.005 Manning N = 0.012 Flowrate Q = 2.0690 cfs Flow Area (AREA) = 0.5571 ft^2 Wetted Perimeter WP = 2.0165 ft Velocity V = 3.7141 ft/s Metric Units, depth less than half full UNITS = 1 Pipe Diameter (DIAM) = 500 mm DEPTH = 125 mm (y/D = 0.25) Slope S = 0.01 Manning N = 0.013 Flowrate Q = 0.0517 m^3/s Flow Area (AREA) = 0.0384 m^2 Wetted Perimeter WP = 0.5236 m Velocity V = 1.3474 m/s English Units, depth more than half full UNITS = 0 Pipe Diameter (DIAM) = 24 in DEPTH = 18 in (y/D = 0.75) Slope S = 0.003 Manning N = 0.014 Flowrate Q = 10.4908 cfs Flow Area (AREA) = 2.5274 ft^2 Wetted Perimeter WP = 4.1887 ft Velocity V = 4.1509 ft/s Metric Units, depth more than half full UNITS = 1 Pipe Diameter (DIAM) = 500 mm DEPTH = 375 mm (y/D = 0.75) Slope S= 0.009 Manning N = 0.013 Flowrate Q = 0.3267 m^3/s Flow Area (AREA) = 0.1580 m^2 Wetted Perimeter WP = 1.0472 m Velocity V = 2.0679 m/s Metric Units, Pipe with pressure flow UNITS = 1 Pipe Diameter (DIAM) = 500 mm DEPTH = not applicable Slope S= 0.009 Manning N = 0.013 Flowrate Q = 2 m^3/s Solving for depth gives the following error PIPE Error: Invalid input 

12182016, 06:17 PM
(This post was last modified: 12182016 06:24 PM by Dieter.)
Post: #2




RE: Pipe Flow  Open Channel Flow
(12172016 08:09 PM)Gene222 Wrote: There are different formulas for (1) a pipe less than half full and (2) a pipe more than half full. Actually only one single formula is required as the arccos function may return angles greater or less than 90° (resp. pi/2). ;) So there is no need to distinguish two separate cases. I happened to write a Manning program for the HP35s this summer. It uses one common formula for relative less or greater than the drain radius. The results are the same as the ones you posted. Setting up a good and effective iterative method to solve for the angle resp. depth is not too hard. With a good first guess you can get five digit accuracy in merely two iterations, or about 10 digits in three. If you do not want to simply use the calculator's builtin solver, that is. ;) You may also consider cases where two different solutions exist (approx. 0,82 < relative depth < 1). (12172016 08:09 PM)Gene222 Wrote: The formulas were difficult to figure out from the FORTRAN program. They were based on pipe diagrams shown below. If you are looking for formulas you may google "Partially Full Pipe Flow Calculations" to find a PDF by Harlan H. Bengtson which should provide you with most of the relevant math. Yes, this paper also distinguishes two different cases for less/more than half full pipes. ;) Dieter 

01072017, 01:11 AM
Post: #3




RE: Pipe Flow  Open Channel Flow
The original program was revised to print out an error message if the flow rate exceeds the capacity of the pipe for open channel flow as was done in the original FORTRAN program.
I had previously stated that I could not figure out how to print an error statement because there was no GOTO statement in the HP Prime. This problem was discussed in the following post. http://www.hpmuseum.org/forum/thread7203.html The solution was to use an IF statement with a BREAK(2) statement. The “2” in the BREAK statement means two breaks. The first break exits the FOR loop, and the second break exits the outer IF statement, such that the program “jumps” to the end of the main program, if I understood the referenced post correctly. The program ends, and the print terminal with the error message is shown. 

01072017, 07:52 PM
Post: #4




RE: Pipe Flow  Open Channel Flow
GoTo trivializes the logic of a code (lazy minds). I hope they never incorporate GoTo into HPprime. The TI68k calculators have GoTo and I've never used them.
http://www.hpcalc.org 20 years online 

01082017, 03:15 AM
(This post was last modified: 01082017 04:54 PM by Gene222.)
Post: #5




RE: Pipe Flow  Open Channel Flow
In the first post, I stated that you could not program the calculator to switch to radian mode at the beginning of the program, perform the calculations in radian mode, and switch back to degree mode at the end of the program. This is not true. I think the problem was that I had App angle setting mode set to degrees. See the following post.
http://www.hpmuseum.org/forum/thread4154.html The attached program demonstrates that the program can switch the calculator to radian mode so that the area and wetted perimeter can be calculated using the radian formulas. The angle setting mode in Home and App views can be programed to change the calculator's HAngle and AAngle system variables. If HAngle = 0, then the angle mode in Home view is in radians. If HAngle = 1, then the angle mode in Home view is in degrees. If AAngle = 0, then the angle mode in App view is the same as is defined in Home view. If AAngle = 1, then the angle mode in both App view and Home view are in radians, regardless of the HAngle setting. If AAngle = 2, then the angle mode in both App view and Home view are in degrees, regardless of the HAngle setting. At the beginning of program, the user angle mode settings were saved in variables HAngleSetting and AAngleSettings with the following statements. HAngleSetting:=HAngle; AAngleSetting:=AAngle; Further, the calculator’s angle mode was changed to radians with the following statements. AAngle:=0; HAngle:=0; At the end of the program, the previous user angle settings were restored with the following statements. HAngle:=HAngleSetting; AAngle:=AAngleSetting; This worked fine, except when the program printed out an error message that the flow rate exceeds the capacity of the pipe for open channel flow. When this happened, the previous user angle settings were not restored. The program execution seemed to stop after the error message was printed. I don’t know why this happened. I am just a beginner still learning to program the calculator. So, the statements to restore the previous user angle setting were also placed just before the printing of the error statement. 

01102017, 05:47 PM
Post: #6




RE: Pipe Flow  Open Channel Flow
The documentation for BREAK(n) says that it is used to break out of loops (or nested loops). So with there being only a single FOR loop, why are you using BREAK(2)?
Graph 3D  QPI  SolveSys 

01102017, 11:27 PM
Post: #7




RE: Pipe Flow  Open Channel Flow
The reason I used a BREAK(2) was because I wanted the program to print an error message and show the message on the terminal screen, when the flow rate exceeds the capacity of the pipe for open channel flow. If I used a single BREAK, the program execution exited the FOR loop, but continued with the code below the FOR loop. I wanted to skip the rest of the code block in the IF Q>0.00001 statement, so right or wrong, I used a BREAK(2).
The following problem would trigger an error message where the flow rate exceeds the capacity of the pipe. The trigger is when the when DEPTH1 in the loop reaches DIAM. UNITS = 1 Pipe Diameter (DIAM) = 500 mm DEPTH = 0 (Thus solve for depth) Slope S= 0.009 Manning N = 0.013 Flowrate Q = 2 m^3/s Now that I think about, the second break in the BREAK(2) statement might be exiting the BEGIN/END code of the main program. That would explain why angle mode was not being restored to the original values. 

01122017, 07:30 PM
Post: #8




RE: Pipe Flow  Open Channel Flow
(01102017 11:27 PM)Gene222 Wrote: The reason I used a BREAK(2) was because I wanted the program to print an error message and show the message on the terminal screen, when the flow rate exceeds the capacity of the pipe for open channel flow. If I used a single BREAK, the program execution exited the FOR loop, but continued with the code below the FOR loop. I wanted to skip the rest of the code block in the IF Q>0.00001 statement, so right or wrong, I used a BREAK(2). If the BREAK(2) is exiting the main program because it breaks out of loops, and not IF's, you could add an extra loop so that the restore executes Code:
Stephen Lewkowicz (G1CMZ) 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)