You are on page 1of 36

JABATAN KEJURUTERAAN MEKANIK

Department of Mechanical Engineering

LAPORAN KERTAS KERJA


Assignment Report

Sesi & Sem 2020/2021 Semester 2


Session & Sem

Kod & Nama Kursus KIG2007 Computer Programming


Course Code & Name

Tajuk Ujikaji Pipe Analysis Simulator


Title of Experiment

Kumpulan Halal Dim Sum


Group

Nama & No. Kad Matrix 1. Adriana Izzati binti Helmi Zam Halik (KIG190007,
Name & Matrix Number 17204525/1)
2. Ahmad Fadlan Syahmi bin Ahmad Faiz (KIG190014,
17204702/1)
3. Goh Yi Chung (KIG190044, 17206734/1)
4. Khoo Hau Zhe (KIG190512, 17206582/1)
5. Nurul Iman binti Nur Elahi (KIG190137, 17204009/1)

Nama Pensyarah Dr. Mohd Nashrul Bin Mohd Zubir


Lecturer’s Name

Tarikh Hantar 23 / 6 / 2021


Submission Date

1
1 Abstract

This project simulates the piping analysis of fluid dynamics, allowing the user to input parameters such
as the geometry of pipe, the density of the fluid, number of bends involved in the pipe system, etc., to
obtain output variables such as Reynold's number, and entry length, head loss etc. The inputs are
arranged as arrays, and the subsequent calculations are done as arrays. This program involves 17
equations for the calculation process, and each equation is organised using functions for a clearer
understanding. Then, it is tested with ten sets of inputs to obtain its respective outputs. Different types
of variables ranging from the dimension of shape to the type of bend used were requested for the user
to input, with 10 different cases, in order to produce the desired outcomes such as minor loss, head loss,
head required and many more. In addition, to evaluate our calculations accurately using coding, excel
calculations were also done to compare between those desired outputs. In this case, the highest
percentage error obtained comparing between coding and excel calculations is 0.000121% for case 8.
This value is so small and can be neglected, thus bringing us to the conclusion that our coding
calculations are precise and accurate. However, there are some discrepancies and limitations that our
coding faced and further be discussed in the result and discussion part.

2 Objectives

1. To create a fluid flow pipe analysis program using Programming Language C++.
2. To determine all the parameters required for fluid flow pipe analysis problems.

3 Theoretical Background

3.1 List of Inputs

1. Shape of pipe - circular, square or rectangular


2. Geometry of circular pipe – diameter, D
3. Geometry of square and rectangular pipes – height, a and width, b
4. Density of fluid, 𝜌
5. Velocity of fluid, V
6. Dynamic viscosity of fluid, 𝜇
7. Type of material used
8. Number of bends used
9. Type of bends used
10. Orientation of bends – vertical or horizontal

3.2 List of Equations

After determining the shape of pipe by the user, the hydraulic diameter, Dh is determined to calculate
the Reynold’s number.
Circular pipe:
𝜋𝐷 2
4( 4 )
𝐷ℎ,𝑐𝑖𝑟𝑐𝑢𝑙𝑎𝑟 =
𝜋𝐷

2
=𝐷
4𝑎 2
Square duct: 𝐷ℎ,𝑠𝑞𝑢𝑎𝑟𝑒 =
4𝑎
=𝑎
Rectangular duct:
4𝑎𝑏
𝐷ℎ,𝑟𝑒𝑐𝑡𝑎𝑛𝑔𝑢𝑙𝑎𝑟 =
2(𝑎 + 𝑏)
2𝑎𝑏
=
𝑎+𝑏

where
D = diameter of circular pipe (m)
a = height (m)
b = width (m)

Reynold’s number, Re describes the flow behavior, whether the flow is laminar, transitional or
turbulent. Reynold’s number is the ratio of inertial forces to viscous forces of a fluid. Generally, fluids
with Reynold’s number lower than 2300 is considered laminar, while Reynold’s number of more than
10000 is considered turbulent flow. The values in between 2300 and 10000 are considered transitional
flow, where the fluid fluctuates from laminar and turbulent flow behavior. To calculate Reynold’s
number,
𝜌𝑉𝐷ℎ
𝑅𝑒 =
𝜇
where,
Dh = hydraulic diameter of pipe (m)
V = average velocity of fluid flow (m/s)
𝜇 = dynamic viscosity (kg/ms)
Re = Reynold’s number
𝜌 = density of fluid (kg/m3)

The entry lengths of fluid flow, Lh of laminar and turbulent flows are determined by

𝐿ℎ,𝑙𝑎𝑚𝑖𝑛𝑎𝑟 ≅ 0.05𝑅𝑒𝐷

𝐿ℎ,𝑡𝑢𝑟𝑏𝑢𝑙𝑒𝑛𝑡 ≅ 1.359𝑅𝑒 0.25 𝐷

After determining the flow characteristic, for laminar flow, the friction factor, f of circular pipe is
determined by

64
𝑓=
𝑅𝑒

while for turbulent flow, the Haaland Equation is used to calculate the friction factor.

𝜀 1.11
1 6.9
= −1.8 𝑙𝑜𝑔 [( 𝐷 ) + ]
√𝑓 3.7 𝑅𝑒

3
where,
𝜀 = surface roughness of pipe

However, friction factors for fully developed laminar flow in pipes of various cross-sections are
determined by the table in Fluid Mechanics, chapter 8, table 8-1.

To calculate the head loss, by substituting the Darcy friction factor and Reynold's Number, we will get
the Darcy-Weisbach equation. This equation calculates the major head losses, hL,major .

𝑓𝐿𝑉 2
ℎ𝐿,𝑚𝑎𝑗𝑜𝑟 =
2𝑔𝐷

where,
L = length of the pipe (m)
g = gravitational acceleration (m/s2)

Whereas for the minor losses, hL,minor, they are calculated using the loss coefficient, KL by the equation
below. The minor losses include the frictional losses through 90° pipe bends.

𝑉2
ℎ𝐿,𝑚𝑖𝑛𝑜𝑟 = ∑ (𝐾𝐿 )
2𝑔

Therefore, the total head losses across the pipe is the summation of major and minor head losses.

ℎ𝐿𝑡𝑜𝑡𝑎𝑙 = ℎ𝐿,𝑚𝑎𝑗𝑜𝑟 + ℎ𝐿,𝑚𝑖𝑛𝑜𝑟


𝐿 𝑉2
= [𝑓 ( ) + ∑ 𝐾𝐿 ]
𝐷 2𝑔

Besides head loss, the required operating pressure also depends on factors such as the velocity of the
fluid, the pressure of the fluid, the elevation differences. The Bernoulli’s Equation is essentially the
conservation of energy but rearranged. The equation can be written as,

𝑃1 𝑎1 𝑉1 2 𝑃2 𝛼2 𝑉2 2
+ + 𝑧1 + ℎ𝑝𝑢𝑚𝑝 = + + 𝑧2 + ℎ𝐿,𝑡𝑜𝑡𝑎𝑙
𝜌𝑔 2𝑔 𝜌𝑔 2𝑔

The assumptions made to apply Bernoulli’s equation are,


- Flow is steady.
- There is no friction.
- The fluid is incompressible and have constant density.

Based on Bernoulli’s equation, the head required for the pipe flow if the flow section does not involve
any pump or turbine is

𝑃2 − 𝑃1 𝑉2 2 − 𝑉1 2
ℎ𝑟𝑒𝑞𝑢𝑖𝑟𝑒𝑑 = + + (𝑧2 −𝑧1 ) + ℎ𝐿,𝑡𝑜𝑡𝑎𝑙
𝜌𝑔 2𝑔

4
From this equation, if the cross-sectional area's flow section is constant, the average flow velocity is
constant (𝑉1 = 𝑉2 ). Therefore, we obtain

ℎ𝑟𝑒𝑞𝑢𝑖𝑟𝑒𝑑 = (𝑧2 −𝑧1 ) + ℎ𝐿,𝑡𝑜𝑡𝑎𝑙


where
𝑧1 = initial height (m)
𝑧2 = final height (m)

Furthermore, to obtain volumetric flow rate, the cross-sectional area of pipe, A (m2) is first determined.
Circular pipe:
𝜋𝐷 2
𝐴=
4

Square and rectangular ducts:


𝐴=𝑎×𝑏

After determining the area, the volumetric flow rate, Qv (m3) is

𝑉
𝑄𝑣 =
𝑡
=𝐴×𝑉

3.3 List of Outputs

1. Hydraulic diameter, Dh
2. Area, A
3. Reynold’s number, Re
4. Entry length, Lh
5. Flow rate, Qv
6. Surface roughness, 𝜀
7. Friction factor, f
8. Length of pipe, L
9. Elevation of pipe, z
10. Minor loss, hL,minor
11. Major loss, hL,major
12. Total head loss, hL,total
13. Total head required, hrequired

4 Methodology

4.1 Coding approach

Many strategies are used to create a program that can solve a pipe problem with many equations to write
the codes. The codes' breakdowns are explained in words, and a flowchart is provided for reference as
follows. The lines specified are based on Halal Dim Sum KIG2007.cpp file attached.

4.1.1 Headers

5
From line 1-5, 5 different standard library headers are included, which are <iostream>, <cmath>,
<iomanip>, <stdlib.h>, <fstream>. <iostream> is used to declare functions for standard input or
output [cin, cout]. <cmath> is used to perform mathematical functions [pow(), log()]. <iomanip>
contains helper functions to control the format of input and output [setw]. <stdlib.h> is used for general
purposes functions [system()]. Lastly, <fstream> enables us to read and write from files [ofstream].

To describe more on <fstream>, it provides the class ofstream to write into files. To write into a text
file, ofstream myfile (line 325) is constructed with parameters of "halaldimsum.txt" and ios::ate
where "halaldimsum.txt", the name of the file, will be created. ios::ate is the mode where the file is
opened. ios::ate overrides the current information in the file every time the program is run instead of
continuing the information. For example, if the user inserted the wrong value and exited the application
and then rerun it, the incorrect value output will be removed automatically. If the file is opened
successfully, then the program executes the following codes in the main function. If the file cannot be
opened, the program will print the output to inform the user that it is unable to open the file, and the
program will not be executed.

4.1.2 Declaration and Initialization

From lines 318-323, all the variables and arrays in the main function are declared. Since there are many
inputs based on certain pipe flow conditions, the array is utilized to store the large data sets under the
same variable name.

Besides main() function, the codes are arranged and divided into eight void functions and four float
functions. Function serves as a collection of statements or a set of statements that perform the task
together. The program is more organized and clearer to understand, even if it involves many equations
with these functions.

4.1.3 Input of Program

The C++ program executes the coding in the main function first (line 316). For the case where the file
is opened successfully (refer 4.1.1) (line 326), a do … while loop (line 328-350) is executed where the
user will first enter the input for the geometry of the pipe (0 for circular pipe and 1 for square or
rectangular ducts). The geometry is stored in the variable called decide_geometry. Next, the if …else
statement is used to decide which functions between circular and square or rectangular ducts are to be
called. For circular tube, the circular tube function (line 10-23) is called. And for square/rectangular
duct, the duct function (line 25-42) is called.

For circular tube function, the parameters are float diameter, float radius and float arr_tube[]. If this
function is called, the user needs to enter the diameter of the circular tube. From this, the radius and
area are determined. The hydraulic diameter, area and radius are all assigned to three different arrays
(arr_tube [1], arr_tube [2] and arr_tube [3]).

For duct function, the parameters are float height, float width and float arr_tube[]. If this function is
called, the user needs to enter the height and width of the square/rectangular duct. From this, the area
is then determined. The hydraulic diameter, area, width and height are all assigned to four different
arrays (arr_tube [1], arr_tube [2], arr_tube [3], arr_tube[4]).

6
Back to the main function, another do … while loop is executed (line 342-250) for the user to input the
values for fluid density, velocity and dynamic viscosity. If the user enters a velocity which is negative,
then the loop will run over again until the user enters a positive velocity.

After that, the Reynolds number, Re function (line 44-49) is called with the parameters of float d, float
v, float Dh, float dv and float arr_reynolds which correspond to arguments of density, velocity,
hydraulic diameter, dynamic viscosity and array of Reynolds number.

Next, the user is required to input the material of the pipe used, each represented by a character such as
glass - g, plastic - p etc. Then, the input is stored in the variable decide_material. With this information,
the roughness function (lines 51-84) is called. In this function, the switch … case statement is used to
determine the roughness, e of the pipe material. If the user does not enter the input based on the given
options, a message will be printed to ask the user to enter again under default. The program continues
by asking the user whether there is any bend available (0 for yes and 1 for no).
If there is no bend available, the bend_no function (line 164-175) with the parameter of float arr_bend[]
is called. In this function, the float length_total (total length of pipe), float height_total (height
difference of pipe) and float k_total (loss coefficients) are initialized and set to 0. Then, the user needs
to enter the length of the pipe. Since there is no bend, therefore the height_total and k_total are kept as
0. Then, the length_total, height_total and k_total are assigned to arr_bend [1], arr_bend [2] and
arr_bend [3] respectively.

If bend(s) are present, the bend_yes function (line 177-292) is called. Besides initializing the variables
like in the bend_no function, boolean a and b = true are used to check for wrong bend type and wrong
bend orientation, respectively. The function first asks the user to input the length of pipe before the first
bend, then asks for the total number of bends. The total number of bends is stored in bendsize variable.
Then, a for loop (line 193-291) is executed to loop for every possible bends. The user is required to
enter the characters w, x, y and z which correspond to the 4 given type of bends. The bend_answer is
the counter which enables the for loop to loop until it reaches the number of bends inserted by the user.
Then, for the number of bends inserted, the user will enter the input the bend type for each bend by
using the switch … case statement inside a do … while statement (line 202-235). For each bend, the
k_total (loss coefficient) will add up based on the bend type. Same as before, if the user does not enter
the bend type based on the given options, a message will be printed to ask the user to enter again under
default. Then, the user has to enter the length of pipe after the first bend along with its orientation
(vertical or horizontal) until it reaches the inserted total number of bends. Next, another do …while
statement and switch … case statement (line 245-284) is used to determine the orientation of each bend.
For vertical bend, the user needs to input whether the bend is going downwards - d or upwards - u.
Then, the input is stored in the v_direction [bend_answer] array. Inside this do … while statement, if
… else statement (line 260-268) is used to sum up the height_total (height difference) based on the
vertical bends. For horizontal bends, only the length_total (total length of pipes) is summed up.

After completing the bends, the main function proceeds with determining the Reynolds number of the
pipe flow by using if … else statement (line 372-388). The laminar flow (Re<=2300) is further divided
into circular and non-circular geometry because their equations are different.

For circular tube with laminar flow, laminar_c function (line 86-96) is called with parameters of float
Re (Reynolds number), float d (density) and float arr_flow (array). In this function, the friction factor,
f and entry length are both calculated and stored in arr_flow [0] and arr_flow [1].

7
For non-circular tube with laminar flow, the laminar_notc (line 98-137) is called with parameters of
float R (Re), float (density), float w (width), float h (height) and float arr_flow (array). First, the ratio
of width/height, x is determined and if … else statement is used. For each x, a different equation is used
to determine the friction factor, f.

For turbulent flow (Re>2300), the non_laminar function (line 139-155) is called. This function is much
simpler because it only involves one equation despite the geometry of the pipe. Similarly, friction factor
and entry length are also calculated.

Next, the head_loss function (line 294-305) is called to calculate the head loss of the pipe system. It
involves parameters of float k (total loss coefficient), float f (friction factor), float l (total length), float
d (density), float v (velocity) and float arr_head [ ] (array for minor, major and total head losses).

There are two functions left before proceeding to the outputs: flowrate (line 157-162) and bernoulli
(line 307-314) functions. Flowrate function has the parameter of float v (velocity) and float a (area)
and in this function, flowrate, Q is calculated. For the bernoulli function with parameters of float z (
total height difference) and float h1 (total head loss), total head required, h_required is calculated.

4.1.4 Output of Program

After the user has inserted all the inputs required, system(“cls”) is executed to clear the screen of the
user’s inputs on the console. Then, all the outputs are displayed along with their units in the console
and saved in the "halaldimsum.txt" text file.

The do … while loop of the main function enables the user to re-execute or terminate the program after
completing the case once (0 - continue with another case and 1 - exit the program).

At the end, the file is closed using myfile.close().

8
4.2 Flowchart

Figure 1: Flowchart of the program

9
5 Results and Discussions

Below are the cases, containing all the parameters required, that we used to describe 10 different fluid
flow through pipes to test the program and the results are subsequently compared to results obtained
through manual calculations.

5.1 Inputs
Table 1: Tabulated Inputs for Case 1 until 10.
Geometry (𝑚) Density Velocit
Dynamic Type of Length of
of y of
Case Shape Viscosity, Material Pipe Before
Fluid, Fluid, 𝑘𝑔
Diameter Height Width 𝑘𝑔 𝑚 𝜇 (𝑚.𝑠) Used Bend, 𝐿 (𝑚)
𝜌 ( 3) 𝑣 ( )
𝑚 𝑠
1 Circular 1.00 None None 1.184 1.00 0.00001849 Glass 1.0
2 Circular 2.00 None None 1.184 2.00 0.00001849 Plastic 2.0
3 Circular 3.00 None None 1.225 3.00 0.00001802 Cast Iron 3.0
Galvanized
4 Circular 0.04 None None 997.000 0.04 0.00089100 4.5
Iron
5 Rectangular None 1.000 2.00 1.184 1.00 0.00001849 Glass 1.0
6 Rectangular None 0.015 0.04 1.225 0.80 0.00001802 Cast Iron 1.2
Galvanized
7 Rectangular None 0.200 1.40 997.000 0.20 0.00089100 3.0
Iron
8 Square None 0.010 0.01 1.184 2.00 0.00001849 Plastic 1.0
9 Square None 0.500 0.50 1.225 1.00 0.00001802 Cast Iron 2.0
Galvanized
10 Square None 1.000 1.00 997.000 0.80 0.00089100 3.0
Iron

Table 2: Bend 1 Characteristics.


Bend 1
Case
Type Coefficient of pipe, 𝐾𝐿 Length After Bend, 𝐿 (𝑚) Orientation
1 None 0.0 0.0 None
2 90° Smooth Bend (Flanged) 0.3 1.0 Horizontal
3 90° Smooth Bend (Flanged) 0.3 1.0 Horizontal
4 90° Miter Bend (Without Vanes) 1.1 2.0 Horizontal
5 90° Smooth Bend (Flanged) 0.3 1.0 Vertical (Upwards)
6 90° Miter Bend (Without Vanes) 1.1 2.1 Vertical (Upwards)
7 90° Smooth Bend (Flanged) 0.3 1.0 Vertical (Upwards)
8 90° Miter Bend (Without Vanes) 1.1 1.5 Horizontal
9 90° Smooth Bend (Flanged) 0.3 1.0 Vertical (Downwards)
10 90° Smooth Bend (Flanged) 0.3 1.0 Vertical (Upwards)

Table 3: Bend 2 Characteristics.


Bend 2
Case
Type Coefficient of pipe, 𝐾𝐿 Length After Bend, 𝐿 (𝑚) Orientation
1 None 0.0 0.0 None
2 None 0.0 0.0 None
3 90° Smooth Bend (Threaded) 0.9 1.0 Vertical (Upwards)
4 90° Miter Bend (With Vanes) 0.2 4.0 Vertical (Upwards)
5 None 0.0 0.0 None
6 90° Miter Bend (With Vanes) 0.2 1.6 Horizontal
7 90° Miter Bend (Without Vanes) 1.1 2.0 Vertical (Upwards)
8 None 0.0 0.0 None
9 90° Smooth Bend (Threaded) 0.9 1.2 Horizontal
10 90° Miter Bend (With Vanes) 0.2 2.0 Horizontal

10
Table 4: Bend 3 Characteristics.
Bend 3
Case
Type Coefficient of pipe, 𝐾𝐿 Length After Bend, 𝐿 (𝑚) Orientation
1 None 0.0 0.0 None
2 None 0.0 0.0 None
3 None 0.0 0.0 None
4 90° Smooth Bend (Threaded) 0.9 3.0 Horizontal
5 None 0.0 0.0 None
6 None 0.0 0.0 None
7 90° Miter Bend (With Vanes) 0.2 1.5 Horizontal
8 None 0.0 0.0 None
9 None 0.0 0.0 None
10 90° Miter Bend (Without Vanes) 1.1 1.0 Vertical (Downwards)

The graphical representations of all the 10 inputs can be referred to Section 6.4 of the appendix.

5.2 Outputs

5.2.1 Calculation Using Excel

Table 5: Tabulated Output Calculations using Excel.


Hydraulic Reynold's Entry Flow Surface Length Elevation
Area, Rate, Friction
Diameter, Number, Length, Roughne of Pipe, of Pipe,
Case 𝐴 (𝑚2 ) 𝑚3 Factor, 𝑓
𝐷ℎ (𝑚) 𝑅𝑒 𝐿ℎ (𝑚) 𝑄 ( ) ss, 𝜀 (𝑚) 𝐿(𝑚) 𝑧 (𝑚)
𝑠
1 1.0000 0.78540 64034.613 21.61838 0.78540 0.00000 0.019606801 1.0 0.0
2 2.0000 3.14159 256138.453 61.14601 6.28320 0.00000 0.014780657 3.0 0.0
3 3.0000 7.06858 611820.200 114.02410 21.20575 0.00026 0.013782608 5.0 1.0
4 0.0400 0.00126 1790.348 3.58070 5.03E-05 0.00015 0.035747242 13.5 4.0
5 1.3333 2.00000 85379.484 30.97395 2.00000 0.00000 0.018427935 2.0 1.0
6 0.0218 0.0006 1186.560 1.29443 0.00048 0.00026 0.057611901 4.9 2.1
7 0.3500 0.28000 78327.722 7.95731 0.05600 0.00015 0.020467101 7.5 3.0
8 0.0100 0.00010 1280.692 0.64035 0.00020 0.00000 0.044444713 2.5 0.0
9 0.5000 0.25000 33990.011 9.22629 0.25000 0.00026 0.023923784 4.2 -1.0
10 1.0000 1.00000 895173.962 41.80193 0.80000 0.00015 0.014109529 7.0 0.0

11
Table 6: Tabulated Output Calculations using Excel.
Total Total Head
Minor Loss, Major Loss, Total Head Loss,
Coefficient of Required,
Case ℎ𝐿,𝑚𝑖𝑛𝑜𝑟 (𝑚) ℎ𝐿,𝑚𝑎𝑗𝑜𝑟 (𝑚) ℎ𝐿,𝑡𝑜𝑡𝑎𝑙 (𝑚)
Pipe, 𝐾𝐿 ℎ𝐿,𝑟𝑒𝑞𝑢𝑖𝑟𝑒𝑑 (𝑚)
1 0.0 0.0000000 0.00100 0.0009993 0.000999
2 0.3 0.0611621 0.00452 0.0656822 0.065682
3 1.2 0.5504587 0.01054 0.5609959 1.560996
4 2.2 0.0001794 0.00098 0.0011633 4.001163
5 0.3 0.0152905 0.00141 0.0166994 1.016699
6 1.3 0.0424057 0.42206 0.4644623 2.564462
7 1.6 0.0032620 0.00089 0.0041561 3.004156
8 1.1 0.2242610 2.26528 2.4895368 2.489537
9 1.2 0.0611621 0.01024 0.0714047 -0.928600
10 1.6 0.0521916 0.00322 0.0554134 0.055413

4.2.2 Calculations Using Coding

Table 7: Tabulated Output Calculations using Coding.


Hydraulic Reynold's Entry Flow Surface Length Elevation
Area, Rate, Friction
Diameter, Number, Length, Roughne of Pipe, of Pipe,
Case 𝐴 (𝑚2 ) 𝑚3 Factor, 𝑓
𝐷ℎ (𝑚) 𝑅𝑒 𝐿ℎ (𝑚) 𝑄 ( ) ss, 𝜀 (𝑚) 𝐿(𝑚) 𝑧 (𝑚)
𝑠
1 1.00000 0.78550 64034.60 21.61840 0.78550 0.00000 0.0196068 1.0 0.0
2 2.00000 3.14200 256138.00 61.14600 6.28400 0.00000 0.0147807 3.0 0.0
3 3.00000 7.06858 611820.20 114.02410 21.20575 0.00026 0.0137826 5.0 1.0
4 0.04000 0.00126 1790.35 3.58070 5.03E-5 0.00015 0.0357472 13.5 4.0
5 1.33333 2.00000 85379.50 30.97390 2.00000 0.00000 0.0184279 2.0 1.0
6 0.0218 0.00060 1186.56 1.2944295 0.00048 0.00026 0.0576119 4.9 2.1
7 0.35000 0.28000 78327.70 7.95731 0.05600 0.00015 0.0204671 7.5 3.0
8 0.01000 0.00010 1280.69 0.64035 0.00020 0.00000 0.0444447 2.5 0.0
9 0.50000 0.25000 33990.01 9.22629 0.25000 0.00026 0.0239238 4.2 -1.0
10 1.00000 1.00000 895174.00 41.80190 0.80000 0.00015 0.0141095 7.0 0.0

Table 8: Tabulated Output Calculations using Coding.


Total Total Head
Minor Loss, Major Loss, Total Head Loss,
Coefficient of Required,
Case ℎ𝐿,𝑚𝑖𝑛𝑜𝑟 (𝑚) ℎ𝐿,𝑚𝑎𝑗𝑜𝑟 (𝑚) ℎ𝐿,𝑡𝑜𝑡𝑎𝑙 (𝑚)
Pipe, 𝐾𝐿 ℎ𝐿,𝑟𝑒𝑞𝑢𝑖𝑟𝑒𝑑 (𝑚)
1 0.0 0.0000000 0.00100 0.0009993 0.000999
2 0.3 0.0611621 0.00452 0.0656822 0.065682
3 1.2 0.5504587 0.01054 0.5609959 1.560996
4 2.2 0.0001794 0.00098 0.0011633 4.001163
5 0.3 0.0152905 0.00141 0.0166994 1.016700
6 1.3 0.0424057 0.42206 0.4644623 2.564462
7 1.6 0.0032620 0.00089 0.0041561 3.004156
8 1.1 0.2242610 2.26528 2.4895400 2.489540
9 1.2 0.0611621 0.01024 0.0714047 -0.928600
10 1.6 0.0521916 0.00322 0.0554134 0.055413

12
5.3 Calculations

5.3.1 Total Head Required, ℎ𝐿,𝑟𝑒𝑞𝑢𝑖𝑟𝑒𝑑 (𝑚) Percentage Error

𝐸𝑥𝑐𝑒𝑙 𝐶𝑎𝑙𝑐𝑢𝑙𝑎𝑡𝑖𝑜𝑛𝑠 − 𝐶𝑜𝑑𝑖𝑛𝑔 𝐶𝑎𝑙𝑐𝑢𝑙𝑎𝑡𝑖𝑜𝑛𝑠


𝑃𝑒𝑟𝑐𝑒𝑛𝑡𝑎𝑔𝑒 𝐸𝑟𝑟𝑜𝑟 = | | × 100%
𝐸𝑥𝑐𝑒𝑙 𝐶𝑎𝑙𝑐𝑢𝑙𝑎𝑡𝑖𝑜𝑛𝑠

Case 1:

0.000999 − 0.000999
𝑃𝑒𝑟𝑐𝑒𝑛𝑡𝑎𝑔𝑒 𝐸𝑟𝑟𝑜𝑟 = | | × 100% = 0.000000%
0.000999

Case 2:

0.065682 − 0.065682
𝑃𝑒𝑟𝑐𝑒𝑛𝑡𝑎𝑔𝑒 𝐸𝑟𝑟𝑜𝑟 = | | × 100% = 0 %
0.065682

Case 3:

1.560996 − 1.560996
𝑃𝑒𝑟𝑐𝑒𝑛𝑡𝑎𝑔𝑒 𝐸𝑟𝑟𝑜𝑟 = | | × 100% = 0 %
1.560996

Case 4:

4.001163 − 4.001163
𝑃𝑒𝑟𝑐𝑒𝑛𝑡𝑎𝑔𝑒 𝐸𝑟𝑟𝑜𝑟 = | | × 100% = 0 %
4.001163

Case 5:

1.016699 − 1.016700
𝑃𝑒𝑟𝑐𝑒𝑛𝑡𝑎𝑔𝑒 𝐸𝑟𝑟𝑜𝑟 = | | × 100% = 0.000098 %
1.016699

Case 6:

2.564462 − 2.564462
𝑃𝑒𝑟𝑐𝑒𝑛𝑡𝑎𝑔𝑒 𝐸𝑟𝑟𝑜𝑟 = | | × 100% = 0 %
2.564462

Case 7:

3.004156 − 3.004156
𝑃𝑒𝑟𝑐𝑒𝑛𝑡𝑎𝑔𝑒 𝐸𝑟𝑟𝑜𝑟 = | | × 100% = 0 %
3.004156

Case 8:

2.489537 − 2.489540
𝑃𝑒𝑟𝑐𝑒𝑛𝑡𝑎𝑔𝑒 𝐸𝑟𝑟𝑜𝑟 = | | × 100% = 0.000121%
2.489537

Case 9:

−0.928600 − (−0.928600)
𝑃𝑒𝑟𝑐𝑒𝑛𝑡𝑎𝑔𝑒 𝐸𝑟𝑟𝑜𝑟 = | | × 100% = 0 %
−0.928600

13
Case 10:

0.055413 − 0.055413
𝑃𝑒𝑟𝑐𝑒𝑛𝑡𝑎𝑔𝑒 𝐸𝑟𝑟𝑜𝑟 = | | × 100% = 0 %
0.055413

Table 9: Comparison of Total Head Required between Excel and Coding


Excel Total Head Coding Total Head
Case Required, ℎ𝐿,𝑅𝑒𝑞𝑢𝑖𝑟𝑒𝑑 (𝑚) Required, ℎ𝐿,𝑅𝑒𝑞𝑢𝑖𝑟𝑒𝑑 (𝑚) Percentage Error (%)
1 0.000999 0.000999 0.000000
2 0.065682 0.065682 0.000000
3 1.561128 1.561130 0.000000
4 4.001163 4.001163 0.000000
5 1.016699 1.016700 0.000098
6 2.612945 2.612950 0.000000
7 3.004156 3.004156 0.000000
8 2.489537 2.489540 0.000121
9 -0.928600 -0.928600 0.000000
10 0.055413 0.055413 0.000000

5.3.2 Case 10 Output Calculations

2(𝐻𝑒𝑖𝑔ℎ𝑡 × 𝑊𝑖𝑑𝑡ℎ)
1. 𝐻𝑦𝑑𝑟𝑎𝑢𝑙𝑖𝑐 𝐷𝑖𝑎𝑚𝑒𝑡𝑒𝑟 (𝑅𝑒𝑐𝑡𝑎𝑛𝑔𝑢𝑙𝑎𝑟 𝐷𝑢𝑐𝑡), 𝐷ℎ =
𝐻𝑒𝑖𝑔ℎ𝑡 + 𝑊𝑖𝑑𝑡ℎ

2(1𝑚 × 1𝑚)
𝐻𝑦𝑑𝑟𝑎𝑢𝑙𝑖𝑐 𝐷𝑖𝑎𝑚𝑒𝑡𝑒𝑟 (𝑅𝑒𝑐𝑡𝑎𝑛𝑔𝑢𝑙𝑎𝑟 𝐷𝑢𝑐𝑡), 𝐷ℎ = = 1𝑚
1𝑚 + 1𝑚

2. 𝐴𝑟𝑒𝑎, 𝐴 (𝑚2 ) = 𝐻𝑒𝑖𝑔ℎ𝑡 × 𝑊𝑖𝑑𝑡ℎ = 1𝑚 × 1𝑚 = 1𝑚2

𝑘𝑔 𝑚
𝜌𝑣𝐷 (997 3 ) (0.8 𝑠 ) (1𝑚)
ℎ 𝑚
3. 𝑅𝑒𝑦𝑛𝑜𝑙𝑑′ 𝑠 𝑁𝑢𝑚𝑏𝑒𝑟, 𝑅𝑒 = = = 895173.9618 (𝑇𝑢𝑟𝑏𝑢𝑙𝑒𝑛𝑡)
𝜇 𝑘𝑔
0.000891 𝑚. 𝑠

1 1
4. 𝐸𝑛𝑡𝑟𝑦 𝐿𝑒𝑛𝑔𝑡ℎ, 𝐿ℎ,𝑡𝑢𝑟𝑏𝑢𝑙𝑒𝑛𝑡 = 1.359𝑅𝑒 4 𝐷ℎ = 1.359(895173.9618)4 (1.0𝑚) = 41.8019284𝑚

𝑚3 𝑚 𝑚3
5. 𝐹𝑙𝑜𝑤 𝑅𝑎𝑡𝑒, 𝑄 ( ) = 𝑣𝑎𝑣𝑔 𝐴𝑐 = (0.8 ) (1𝑚2 ) = 0.8
𝑠 𝑠 𝑠

6. 𝑆𝑢𝑟𝑓𝑎𝑐𝑒 𝑅𝑜𝑢𝑔ℎ𝑛𝑒𝑠𝑠, 𝜀 (𝑚) = 𝑅𝑜𝑢𝑔ℎ𝑛𝑒𝑠𝑠 (𝐺𝑎𝑙𝑣𝑎𝑛𝑖𝑧𝑒𝑑 𝐼𝑟𝑜𝑛) = 0.00015𝑚

𝜀 1.11
1 6.9 𝐷
7. 𝐹𝑟𝑖𝑐𝑡𝑖𝑜𝑛 𝐹𝑎𝑐𝑡𝑜𝑟, 𝑓𝑡𝑢𝑟𝑏𝑢𝑙𝑒𝑛𝑡 = = −1.8 𝑙𝑜𝑔 𝑙𝑜𝑔 [ +( ℎ) ]
√𝑓 𝑅𝑒 3.7

14
0.00015𝑚 1.11
1 6.9 1𝑚
= −1.8 𝑙𝑜𝑔 𝑙𝑜𝑔 [ +( ) ] = 0.014109528
√𝑓 895173.9618 3.7

8. 𝑇𝑜𝑡𝑎𝑙 𝐿𝑒𝑛𝑔𝑡ℎ 𝑜𝑓 𝑃𝑖𝑝𝑒, 𝐿 (𝑚) = 𝐿𝑒𝑛𝑔𝑡ℎ 𝑜𝑓 𝑃𝑖𝑝𝑒 𝑏𝑒𝑓𝑜𝑟𝑒 𝐵𝑒𝑛𝑑 +

∑ 𝐿𝑒𝑛𝑔𝑡ℎ 𝑜𝑓 𝑃𝑖𝑝𝑒 𝑎𝑓𝑡𝑒𝑟 𝐵𝑒𝑛𝑑 1

𝑇𝑜𝑡𝑎𝑙 𝐿𝑒𝑛𝑔𝑡ℎ 𝑜𝑓 𝑃𝑖𝑝𝑒, 𝐿 (𝑚) = 3𝑚 + 1𝑚 + 2𝑚 + 1𝑚 = 7𝑚

9. 𝑇𝑜𝑡𝑎𝑙 𝐸𝑙𝑒𝑣𝑎𝑡𝑖𝑜𝑛 𝑜𝑓 𝑃𝑖𝑝𝑒, 𝐿 (𝑚) = ∑ 𝐿𝑒𝑛𝑔𝑡ℎ 𝑜𝑓 𝑃𝑖𝑝𝑒 𝑎𝑓𝑡𝑒𝑟 𝐵𝑒𝑛𝑑 (𝑉𝑒𝑟𝑡𝑖𝑐𝑎𝑙 𝑈𝑝𝑤𝑎𝑟𝑑𝑠) −

∑ 𝐿𝑒𝑛𝑔𝑡ℎ 𝑜𝑓 𝑃𝑖𝑝𝑒 𝑎𝑓𝑡𝑒𝑟 𝐵𝑒𝑛𝑑 (𝑉𝑒𝑟𝑡𝑖𝑐𝑎𝑙 𝐷𝑜𝑤𝑛𝑤𝑎𝑟𝑑𝑠)

𝑇𝑜𝑡𝑎𝑙 𝐸𝑙𝑒𝑣𝑎𝑡𝑖𝑜𝑛 𝑜𝑓 𝑃𝑖𝑝𝑒, 𝑧 (𝑚) = 1𝑚 − 1𝑚 = 0𝑚

10. 𝑇𝑜𝑡𝑎𝑙 𝐿𝑜𝑠𝑠 𝐶𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡 𝑜𝑓 𝑃𝑖𝑝𝑒, 𝐾𝐿 = ∑ 𝐿𝑜𝑠𝑠 𝐶𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡 𝑜𝑓 𝐵𝑒𝑛𝑑, 𝐾𝐿

𝑇𝑜𝑡𝑎𝑙 𝐿𝑜𝑠𝑠 𝐶𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡 𝑜𝑓 𝑃𝑖𝑝𝑒, 𝐾𝐿 = 0.3 + 0.2 + 1.1 = 1.6

𝑚 2
𝑣2 (0.8 𝑠 )
11. 𝑀𝑖𝑛𝑜𝑟 𝐿𝑜𝑠𝑠, ℎ𝐿,𝑀𝑖𝑛𝑜𝑟 (𝑚) = ∑ 𝐾𝐿 = (1.6) ( 𝑚 ) = 0.052191641𝑚
2𝑔 2 (9.81 2 )
𝑠

𝐿 𝑣2
12. 𝑀𝑎𝑗𝑜𝑟 𝐿𝑜𝑠𝑠, ℎ𝐿,𝑀𝑎𝑗𝑜𝑟 (𝑚) = ∑ 𝑓
𝐷ℎ 2𝑔

𝑚 2
7𝑚 (0.8 𝑠 )
𝑀𝑎𝑗𝑜𝑟 𝐿𝑜𝑠𝑠, ℎ𝐿,𝑀𝑎𝑗𝑜𝑟 (𝑚) = (0.014109528) ( ) ( ) = 3.221747474 × 10−3 𝑚
1𝑚 2 (9.81 𝑚 )
𝑠2

13. 𝑇𝑜𝑡𝑎𝑙 𝐻𝑒𝑎𝑑 𝐿𝑜𝑠𝑠, ℎ𝐿,𝑇𝑜𝑡𝑎𝑙 (𝑚) = 𝑀𝑎𝑗𝑜𝑟 𝐿𝑜𝑠𝑠, ℎ𝐿,𝑀𝑎𝑗𝑜𝑟 (𝑚) + 𝑀𝑖𝑛𝑜𝑟 𝐿𝑜𝑠𝑠, ℎ𝐿,𝑀𝑖𝑛𝑜𝑟 (𝑚)

𝑇𝑜𝑡𝑎𝑙 𝐻𝑒𝑎𝑑 𝐿𝑜𝑠𝑠, ℎ𝐿,𝑇𝑜𝑡𝑎𝑙 (𝑚) = 0.052191641𝑚 + 3.221747474 × 10−3 𝑚 = 0.055418157𝑚

15
14. 𝑇𝑜𝑡𝑎𝑙 𝐻𝑒𝑎𝑑 𝑅𝑒𝑞𝑢𝑖𝑟𝑒𝑑, ℎ𝐿,𝑟𝑒𝑞𝑢𝑖𝑟𝑒𝑑 (𝑚)

= 𝑇𝑜𝑡𝑎𝑙 𝐸𝑙𝑒𝑣𝑎𝑡𝑖𝑜𝑛 𝑜𝑓 𝑃𝑖𝑝𝑒, 𝑧 (𝑚) + 𝑇𝑜𝑡𝑎𝑙 𝐻𝑒𝑎𝑑 𝐿𝑜𝑠𝑠, ℎ𝐿,𝑇𝑜𝑡𝑎𝑙

𝑇𝑜𝑡𝑎𝑙 𝐻𝑒𝑎𝑑 𝑅𝑒𝑞𝑢𝑖𝑟𝑒𝑑, ℎ𝐿,𝑟𝑒𝑞𝑢𝑖𝑟𝑒𝑑 (𝑚) = 0.055418157𝑚 + 0𝑚 = 0.055418157𝑚

5.4 Discussion

5.4.1 Input

A general program was created to solve general-based topic on Internal Flow using Programming
Language, particularly C++. In this case, main coding was typed in a software called Dev C++ to
calculate all the parameters needed in designing a pump with bends. Apart from that, calculations using
Excel also were used to compare the value to get the exact value.

As shown in table 1, different variables were used in each case which were used for input parameters
in Excel calculations and Coding. Ten cases were provided with four cases for circular pipe, three for
rectangular and another three for square duct. The diameter is constant throughout the circular pipe;
meanwhile, height and width value must be determined if rectangular and square duct were used. Other
𝑘𝑔
than that, we used two types of fluids, saturated water and air, with different densities of 997.0 for
𝑚3
𝑘𝑔 𝑘𝑔
water, 1.184 3 and 1.225 3 for air.
𝑚 𝑚

Furthermore, fluid velocity was initially increased from 1ms to 3ms for cases 1 to 3, and we set a fluid
𝑚
velocity 0.04 𝑠 to test for laminar flow. o test for laminar flow. The same trend with case 4 to 10 used
a higher value of velocity and then decreased them to produce laminar flow. Besides, dynamic viscosity
value was obtained along with the density of fluid by referring to table A-9 and A-3 as below:

Figure 2: Properties of Air Table A-9

16
Figure 3: Properties of Saturated Water Table A-3

𝑘𝑔 𝑘𝑔 𝑘𝑔
The densities of air are 1.184 and 1.225 , the dynamic viscosities are 1.849 × 10−5 and
𝑚3 𝑚3 𝑚.𝑠
𝑘𝑔 𝑘𝑔
1.802 × 10−5 𝑚.𝑠, respectively. On the other hand, for saturated water, the density used is 997.0 𝑚3 and
𝑘𝑔
0.891 × 10−3 for dynamic viscosity. Moreover, the type of material for the pipe provided was glass
𝑚.𝑠
and plastics with 0 surface roughness, and cast iron, ε=0.00026m and galvanized iron, ε=0.00015m.
Therefore, we used a variety of materials to test different scenarios. Then, the length of pipe before
bending was specified for every case as illustrated in table 5 and 7.

As for the bend, we only limit our findings to 3 bends to prevent a long table and calculations, but our
program can execute the number of bends as desired by the users. There are four types of bends used in
this program which are 90° smooth bend (flanged and threaded), 90° miter bend (with and without
vanes). In our investigation, the effect of different types of bends were examined in each case where
different types of bends provide different value of loss coefficient, 𝐾𝐿 , to be more precise, 90° smooth
bend (flanged) gives a value of loss coefficient, 𝐾𝐿 of 0.3, , 90° smooth bend (threaded) is 0.9, 90° miter
bend (with vanes) is 0.2, and , 90° miter bend (without wanes) is 1.1.

Next, the length of pipe after each bend is required to be input by the user with an orientation of
horizontal, vertical (upwards) and vertical (downwards). To clear the confusion on the orientation of
the pipe, this program is meant to be in 3D mode, where the horizontal axis is on x plane, and the
vertical part is on the y-axis. For instance, when a user inputs a bend, but the pipe orientation is
horizontal, the pipe goes to the z-axis instead of y-axis. However, when the user inputs a bend and the
pipe is orientated vertically, the pipe goes onto the y-axis direction, either positive (upwards) or negative
(downwards).

5.4.2 Output

The first output calculated was the hydraulic diameter which highly depends on the diameter for circular
shape and the height and width of the geometry for rectangular and square duct. Moving on to the area,
the area calculated is the cross-sectional area of the pipe itself by using the standard area formula of a
circle, rectangle, and square. In addition, Reynold's number is a function of density, velocity, hydraulic
diameter, and dynamic viscosity. We found out that as the velocity, density, and hydraulic diameter
increased. At the same time, dynamic viscosity decreased, the magnitude of Reynold's number
significantly higher, which proves the directly proportional relationship between Re and density,
velocity, and hydraulic diameter subsequently vice versa with dynamic viscosity. Apart from that, Re

17
with a value less than 2300 is considered laminar meanwhile, above 2300 is turbulent. This was to
simplify the calculations as transitional flow is hard to evaluate. In table 5-8, the row with a blue
highlight indicates laminar flow.

Additionally, entry length, Lh is the distance from the entry pipe to a point which the flow reaches
within about 2% of the fully developed flow. Based on table …., It can be shown that laminar flow has
a lower value of entry length when comparing with the turbulent flow, which proved both equations:

1
𝐸𝑛𝑡𝑟𝑦 𝐿𝑒𝑛𝑔𝑡ℎ, 𝐿ℎ,𝑡𝑢𝑟𝑏𝑢𝑙𝑒𝑛𝑡 = 1.359𝑅𝑒 4 𝐷ℎ

𝐸𝑛𝑡𝑟𝑦 𝐿𝑒𝑛𝑔𝑡ℎ, 𝐿ℎ,𝑙𝑎𝑚𝑖𝑛𝑎𝑟 = 0.005𝑅𝑒𝐷ℎ

Flow rate, 𝑄 is a measure of volume of fluid flow through a cross-sectional area over time. By referring
to table 5 and 7, as we can see, the flow rate has a larger value in turbulent flow due to its larger velocity.
As we used, 𝑄 = 𝑣𝐴𝑠 equation, it's proven that flow rate increases with velocity and area. Furthermore,
surface roughness determined is based on the type of material used for pipe, such as glass, plastic, cast
iron, and galvanized iron. They have their unique value of surface roughness. The friction factor is a
description of friction losses in pipe flow and open channel flow. In this case, the friction factor for
laminar flow solely relies on Reynold's number and pipe geometry, whether it is circular, rectangular,
and square. Changes in geometry have different formulas to determine the friction factor. Meanwhile,
for turbulent flow, the friction factor is related to Reynold's number and the ratio of surface roughness
and hydraulic diameter, where the more the surface roughness, the more the friction losses in a pipe.

Total length of pipe is simply the addition of pipe length from the beginning to the end, and elevation
of pipe is the height difference between the elevations of fluid in and the fluid out. Moreover, the total
loss coefficient of pipe is the total loss coefficient contributed by bends, where more bends are attached,
more total loss coefficient value. Since the minor loss is somehow associated with total loss coefficient
caused by bends, and magnitude of fluid velocity, this minor loss value will increase as the number of
bends and velocity of fluid increases.

On the other hand, major loss is correlated with the friction factor, length of the pipe, and fluid velocity.
When the roughness of the pipe is larger with a longer tube (length), the major loss is higher because
of the bigger resistance that needs to be overcome by the fluid. Total head loss is directly the sum of
minor and major loss in pipe, mainly supplied by the surface roughness, Reynold's number, length of
pipe, diameter of pipe, and the number of bends. Finally, the total head required is the measure of total
head loss plus the pipe elevation. As we can see in table 6 and 8, there is a negative value of head
required which tells us that this pipe does not need the support of pump because the flow of fluid can
be directed by itself without the help of pump.

5.4.3 Comparison between Excel and Coding

Excel and coding calculations were used in this program to determine the difference between them.
Total head required is the parameter that we are interested to compare. As shown in calculations part,
each case total head required for Excel and Coding calculations are differentiate by calculating the
𝐸𝑥𝑐𝑒𝑙 𝐶𝑎𝑙𝑐𝑢𝑙𝑎𝑡𝑖𝑜𝑛𝑠−𝐶𝑜𝑑𝑖𝑛𝑔 𝐶𝑎𝑙𝑐𝑢𝑙𝑎𝑡𝑖𝑜𝑛𝑠
percentage error with a formula of 𝑃𝑒𝑟𝑐𝑒𝑛𝑡𝑎𝑔𝑒 𝐸𝑟𝑟𝑜𝑟 = | 𝐸𝑥𝑐𝑒𝑙 𝐶𝑎𝑙𝑐𝑢𝑙𝑎𝑡𝑖𝑜𝑛𝑠
|. In this
case, excel calculations were treated as the actual value and the coding calculations were assumed to be
the experimental value. The tabulated data of percentage error from case 1 to 10 were recorded in table

18
9, with highest possible percentage error registered at 0.000121% from case 8, where most cases
assumed to be negligible since the value is too small, the lowest percentage error obtained is 0%, which
indicates that our calculations for coding are undoubtedly accurate.

However, the small percentage error might be due to some discrepancies that occurred during the
program execution. Firstly, human error, when one accidentally key in the value to coding and excel,
even if it was a small value, it will affect the whole calculations. Hence, carelessness should be avoided
in this case as well; one should check properly every case whether the input value was synced between
coding and excel. Besides that, our coding uses float as our type of variable. Therefore, there may be
differences in the round-off value between excel and coding calculations. For instance, in case 8, the
excel value 2.489537 was not rounded off; meanwhile coding value rounded off to 2.489540. Therefore,
we must set a suitable type of variable based on the desired value to appear as the same value that we
want.

5.4.4 Limitations

In creating a program, limitations are always there as sometimes the program was designed to suit some
specified condition or cannot cater to high precision calculations. First and foremost, the output for
transitional flow (2300 < 𝑅𝑒 < 10000) is not accurate as we only consider two conditions which are
laminar and turbulent flow with a value of (𝑅𝑒 < 2300) and (𝑅𝑒 > 2300), respectively. This condition
was chosen because there are no specified steps in solving the laminar flow problem in our syllabus.
Secondly, in our program, the pipe diameter is always fixed at the beginning until the end tip, which
users are unable to input variable diameters of pipe being connected.

Furthermore, the pipe orientation will always start off as a horizontal pipe. The user cannot choose to
insert vertical direction of pipe at the initial part of the program. Finally, the pipe cannot be bend to
180° from vertical (upwards) to vertical (downwards) orientation. For example, if the user input pipe
orientation of vertical (upwards) for bend 1, logically, it needs a 180° bend if the user input a vertical
(downwards) pipe orientation for bend 2.

It should also be noted that in our programming, the horizontal pipes are not specified if they are to
extend in the x or z-axis. This is because our program is mainly used to calculate the head losses and
head required for the fluid to be pumped through the pipe.

Besides that, our program also lacks some significant options such as the options for T-fittings and non
90° bends as mentioned above.

5.4.5 Recommendations
- The scope covered for fluid flow through pipe can be widened to encompass more scenarios and be
more robust to cover more problems.
- The options for pipe fittings should be expanded for other non-90° bends, etc.
- The shape of pipe and configuration can be displayed to help confirm the user that their pipe is of the
right proportions and help visualization.

19
6 Conclusion

In a nutshell, a program is created using programming language C++ to determine all the parameters
required for fluid flow pipe analysis with different input variables. The results were then compared with
manual calculations done in Microsoft Excel. In this case, total head required for all cases are compared
and the highest percentage error obtained is 0.000121%. Therefore, we can conclude that our results are
accurate since the percentage error is small and can be neglected. However, there are a few limitations
faced by our program which has been further discussed in the discussion part.

7 References

Çengel, Yunus A. Fluid mechanics : fundamentals and applications, McGraw-Hill series.

8 Appendix

8.1 Code
#include <iostream>
#include <cmath>
#include <iomanip>
#include <stdlib.h>
#include <fstream>
#define g 9.81

using namespace std;

void circular_tube(float diameter, float radius, float arr_tube[]) //call function for circular
tube
{
float diameter_h, area; // hydraulic diameter - diameter_h

cout<<"\nEnter the diameter (m): ";


cin>>diameter;
diameter_h=diameter;
radius=diameter/2;
area=3.142*radius*radius;

arr_tube[0] = diameter_h;
arr_tube[1] = area;
arr_tube[2] = radius;
}

void duct(float height, float width, float arr_tube []) //call function for square/rectangular
tube
{
float diameter_h, area; // hydraulic diameter - diameter_h

cout<<"\nHeight (m): ";


cin>>height;

20
cout<<"Width (m): ";
cin>>width;

diameter_h=((2*height*width)/(height+width));
area=width*height;

arr_tube[0] = diameter_h;
arr_tube[1] = area;
arr_tube[2] = width;
arr_tube[3] = height;
}

void Re(float d, float v, float Dh, float dv, float arr_reynolds []) // d = density, v =
velocity, diameter_h = hydraulic diameter, dv = dynamic viscosity
{
float Re;
Re=(d*v*Dh)/dv;
arr_reynolds [0] = Re;
}

float roughness (char decision, float e)


{
cout<<"\nMaterial of the pipe used\ng - glass\np - plastic\nc - cast iron\ni - galvanized
iron\n";
cout<<"\nMaterial:";
cin>>decision;

switch (decision)
{
case 'g':
case 'G':
case 'p':
case 'P':
e = 0;
break;

case'c':
case'C':
e = 0.00026;
break;

case 'i':
case'I':
e = 0.00015;
break;

default:
cout<< "\nError!\nPlease enter correct material based on the given options\n\n";
cout<< "Enter a valid material: ";

21
roughness(decision, e); //to call if wrong input
break;
}
cout<<endl;

return e;
}

void laminar_c (float Re, float d, float arr_flow [])


{
float f, entry_length;

f=64/Re;
entry_length = 0.05*Re*d;

arr_flow [0] = f;
arr_flow [1] = entry_length;

void laminar_notc ( float R, float d, float w, float h, float arr_flow []) // R- Re, w- width,
h- height
{
float f, entry_length;
double x;

x = round(w/h);

if (x == 1)
{
f= 56.92/R;
}
else if (x == 2)
{
f= 62.20/R;
}
else if (x == 3)
{
f= 68.36/R;
}
else if (x == 4)
{
f= 72.92/R;
}
else if (x == 5 || x == 6)
{
f= 78.80/R;
}
else if (x == 7 || x == 8)
{

22
f= 82.32/R;
}
else if (x >= 9)
{
f= 96.00/R;
}
entry_length = 0.05*R*d;

arr_flow [0] = f;
arr_flow [1] = entry_length;
}

float nonlaminar (float r, float d, float R, float arr_flow []) // r- roughness, d- diameter,
R- Re
{
float f, entry_length;
float base1, base2, exp1, ans1, ans2;

base1 = (r/d)/3.7;
exp1 = 1.11;
ans1 = pow (base1, exp1);
ans2 = log(ans1 + (6.9/R))/log(10);
base2 = 1/(-1.8*ans2);
f = pow(base2, 2);

entry_length = 1.359*pow(R,0.25)*d;

arr_flow [0] = f;
arr_flow [1] = entry_length;
}

float flowrate(float v, float a)


{
float Q;
Q = v*a;
return Q;
}

void bend_no ( float arr_bend []) //call function if there are no available bend(s)
{
float length_total = 0;
float height_total = 0, k_total = 0;

cout<<"\nLength of pipe (in m): ";


cin>>length_total;

arr_bend [0] = length_total;


arr_bend [1] = height_total;
arr_bend [2] = k_total;
}

23
void bend_yes ( float arr_bend []) //call function if there are available bend(s)
{
int bendsize;
char bend_or [bendsize], bend_type [bendsize], v_direction [bendsize];
float length_after [bendsize];

float length_total = 0, height_total = 0, k_total = 0;

bool a = true; //to check for wrong bend type


bool b = true; //to check for wrong bend orientation

cout<<"\nLength of the pipe before the first bend (in m): ";
cin>>length_total;
cout<<"Total number of bends: ";
cin>>bendsize;

for(int bend_answer = 0; bend_answer < bendsize; bend_answer++) // loop for every


possible bends
{
cout<<"\nTypes of bends available:\n";
cout<<"w - 90 degrees smooth bend (flanged)\n";
cout<<"x - 90 degrees smooth bend (threaded)\n";
cout<<"y - 90 degrees miter bend (without vanes)\n";
cout<<"z - 90 degrees miter bend (with vanes)\n\n";
cout<<"Please enter the type of bends for bend "<< bend_answer +1<<":";

do
{
a = true;
cin>>bend_type[bend_answer];

switch (bend_type [bend_answer])


{
case 'w':
case 'W':
k_total = k_total + 0.3;
break;

case 'x':
case 'X':
k_total = k_total + 0.9;
break;

case 'y':
case 'Y':
k_total = k_total + 1.1;
break;

case 'z':

24
case 'Z':
k_total = k_total + 0.2;
break;

default:
a = false;
cout<< "\nError!\nPlease enter the bend type based on the given options.\n\n";
cout<< "Please enter the correct bend type:";
break;
}
}while (a==false);

cout<<"Length of pipe after bend "<<bend_answer +1<<"(in m): ";


cin>> length_after[bend_answer];

cout<<"Orientation of bend:\n";
cout<< "v - Vertical\n";
cout<< "h - Horizontal\n\n";
cout<<"Please enter the orientation for bend: "<<bend_answer +1<<":";

do
{
b = true;
cin>> bend_or[bend_answer];

switch (bend_or [bend_answer])


{
case 'v':
case 'V':
cout<<"Is the vertical going upward or downward?:\n";
cout<< "u - upward\n";
cout<< "d - downward\n\n";
cout<< "Please enter the direction of the bend: ";
cin>>v_direction[bend_answer];

if (v_direction[bend_answer] == 'u')
{
height_total = height_total + length_after[bend_answer];
}

else if (v_direction[bend_answer] == 'd')


{
height_total = height_total - length_after[bend_answer];
}

length_total = length_total + length_after[bend_answer];


break;

case 'h':
case 'H':

25
length_total = length_total + length_after[bend_answer];
break;

default:
b = false;
cout<< "\nError!\nPlease enter correct orientation of the bend.\n\n";
cout<< "Please enter the correct bend orientation:";
break;
}
}while (b==false);

//length_total = length_total + length;

arr_bend [0] = length_total;


arr_bend [1] = height_total;
arr_bend [2] = k_total;
}
}

void head_loss(float k, float f, float l, float d, float v, float arr_head[])


{
float hl_major, hl_minor, hl_total;

hl_minor = (k*v*v)/(2*g);
hl_major = (f*l*v*v)/(2*g*d);
hl_total = hl_minor + hl_major;

arr_head [0] = hl_minor;


arr_head [1] = hl_major;
arr_head [2] = hl_total;
}

float bernoulli(float z, float hl)


{
float h_required, answer;

h_required = z+hl;

return h_required;
}

int main ()
{
float arr_tube [4], arr_bend [3], arr_head [3], arr_flow [2], arr_reynolds [2];
char decide_material;
float diameter, radius, width, height;
float density, velocity, d_viscosity, friction_f, pressure1, pressure2, velocity2;
float e;
int decide_bend, decide_geometry, decide_program;

26
ofstream myfile ("halaldimsum.txt", ios::ate);
if (myfile.is_open())
{
do {
cout<<"Enter the geometry of the pipe\nCircular - 0"<<setw(40)<<"Square/Rectangular
- 1\n";
cin>>decide_geometry;

if (decide_geometry == 0)
{
circular_tube(diameter, radius, arr_tube);
}

else if (decide_geometry == 1)
{
duct(height, width, arr_tube);
}

do
{
cout<<"Density of fluid (kg/m^3): ";
cin>>density;
cout<<"Velocity of fluid (m/s): ";
cin>>velocity;
cout<<"Dynamic viscosity (kg m-1 s-1): ";
cin>>d_viscosity;
}while (velocity<0);

Re(density, velocity, arr_tube[0], d_viscosity, arr_reynolds);

roughness (decide_material, e);

cout<<"\nAre there any bends available?\nYes - 0"<<setw(20)<<"No - 1\n";


cin>>decide_bend;

if (decide_bend == 1)
{
bend_no( arr_bend);
}

else if (decide_bend == 0)
{
bend_yes( arr_bend);
}

if (arr_reynolds [0] <= 2300)


{
if (decide_geometry == 0)
{
laminar_c (arr_reynolds [0],arr_tube [0], arr_flow);

27
}

else if (decide_geometry == 1)
{
laminar_notc (arr_reynolds [0], arr_tube[0], arr_tube [2], arr_tube [3], arr_flow)
;
}
}

else if (2301 <= arr_reynolds[0])


{
nonlaminar (roughness(decide_material,
e), arr_tube [0], arr_reynolds [0], arr_flow);
}

head_loss(arr_bend [2], arr_flow [0], arr_bend[0], arr_tube[0], velocity, arr_head);

system("cls");
//Everything that will appear as output
cout<<"Hydraulic diameter: "<<arr_tube[0]<<" m"
<<"\nArea: "<<arr_tube [1]<<" m^2"
<<"\nReynold's number: "<<arr_reynolds [0]
<<"\nEntry length: "<<arr_flow [1]<<" m"
<<"\nFlow rate: "<<flowrate(velocity, arr_tube [1])
<<"\nSurface roughness: "<<roughness(decide_material, e)
<<"\nFriction factor: "<<arr_flow [0]
<<"\nTotal length of the pipe: "<<arr_bend[0]<<" m"
<<"\nTotal height elevation of the pipe: "<<arr_bend[1]<<" m"
<<"\nTotal coefficient loss of pipe: "<<arr_bend[2]
<<"\nMinor loss: "<<arr_head [0]<<" m"
<<"\nMajor loss: "<<arr_head [1]<<" m"
<<"\nTotal head loss: "<<arr_head [2]<<" m"
<<"\nTotal head required: "<<bernoulli(arr_bend[1], arr_head[2])<<" m";

myfile <<"Hydraulic diameter: "<<arr_tube[0]<<" m"


<<"\nArea: "<<arr_tube [1]<<" m^2"
<<"\nReynold's number: "<<arr_reynolds [0]
<<"\nEntry length: "<<arr_flow [1]<<" m"
<<"\nFlow rate: "<<flowrate(velocity, arr_tube [1])
<<"\nSurface roughness: "<<roughness(decide_material, e)
<<"\nFriction factor: "<<arr_flow [0]
<<"\nTotal length of the pipe: "<<arr_bend[0]<<" m"
<<"\nTotal height elevation of the pipe: "<<arr_bend[1]<<" m"
<<"\nTotal coefficient loss of pipe: "<<arr_bend[2]
<<"\nMinor loss: "<<arr_head [0]<<" m"
<<"\nMajor loss: "<<arr_head [1]<<" m"
<<"\nTotal head loss: "<<arr_head [2]<<" m"
<<"\nTotal head required: "<<bernoulli(arr_bend[1], arr_head[2])<<" m";

28
cout<<"\n\nWould you like to continue with another case?\n0 - Continue with another
case\n1 - Exit the program\n";
cin>>decide_program;
system("cls");
} while (decide_program != 1);

myfile.close();
}
else cout << "Unable to open file";
return 0;
}

8.2 Input

29
30
8.3 Output

31
8.4 Graphical representations of pipes of 10 inputs

Figure 4: Pipe in Case 1

Figure 5: Pipe in Case 2

32
Figure 6: Pipe in Case 3

Figure 7: Pipe in Case 4

33
Figure 8: Pipe in Case 5

Figure 9: Pipe in Case 6

34
Figure 10: Pipe in Case 7

Figure 11: Pipe in Case 8

35
Figure 12: Pipe in Case 9

Figure 13: Pipe in Case 10

36

You might also like