Modelling Pipe Flow Using Python
Modelling Pipe Flow Using Python
ABSTRACT
In every wake of life, the flow of fluids through pipes is encountered. The major problem encountered while analysing pipe flow problems is obtaining friction factor.
Though Moody's diagram helps evaluate the friction factor, the obtained solution is error-prone due to errors in reading the graph. So, to remove the mistakes using
hand calculations and improper use of diagram, an attempt has been made in this research article to automate the process of pipe flow modelling. The Colebrook-White
equation has been iteratively solved to obtain the friction factor. The modelling is done using Python as it is easy to use and has a vast library backup. The robustness of
the developed program has been demonstrated by plotting Moody's diagram using the code. Three different pipe flow problems through a single pipeline are solved
using the developed program, and the obtained results are precisely equal to those shown in the literature.
KEYWORDS: Pipe flow; Friction factor; Python Programming; Moody's diagram; Reynolds number.
Nomenclature: This means that stress is responsible for the pressure drop in the pipe. Now, if the
A Cross-sectional area of pipe (m2) above expression is replaced in the skin friction coefficient (cf), then it is also
cf Fanning's friction factor called the Fannings friction factor [7], as shown in Eq (2).
d Pipe diameter (m)
Dh Hydraulic diameter (m)
L Pipe length (m) ............................................................................... (2)
Q Volume flow rate (m3/s)
Re Reynolds number
v Average flow velocity Where v is the average flow velocity (v=Q/A), Darcy defined his friction factor
f Darcy's Friction factor as four times that of Fanning’s viz [8].
ρ Fluid density (kg/m3)
Δp Pressure drop (Pa) ................................................................................. (3)
ϵ Wall roughness (m)
Therefore, the pressure drops (Δp) across a pipe length L in a fluid of density ρ
1. INTRODUCTION:
and velocity v is given by:
Understanding the fluid flow regime is of utmost importance from the engineer-
ing point of view when a fluid flows. Reynold's number (Re) [1], which is the
.................................................................................. (4)
ratio of inertia to viscous force, talks about the flow regime, i.e., whether it is lami-
nar or turbulent [2]. For Pipe flow, if the Re is less than 2000, it is called laminar,
whereas when it is more than 4000, it is called turbulent flow [3]. Laminar flow is And the power to be supplied to the fluid (of flow rate Q) to overcome is pressure
where laminas of fluid glide smoothly one over the other. In contrast, the turbu- drop is given by:
lent flow is the one intermingling of fluid laminas. In other words, turbulent flow
can be said to be where the flow becomes an irregular function of time [4]. And as ................................................................................ (5)
the flow velocities in turbulent flows become periodic with respect to the time,
we cannot have a steady flow. On the other hand, these fluctuations are random, If the flow is laminar, one can quickly get the relation between friction factor f
so a statistical description is possible. The variation may be brought down by the and Re, as shown in Eq. (6).
law of probability so that an average velocity is defined [5].
Usually, all flows in nature are turbulent, so laminar flow occurs with minimal ................................................................................................(6)
velocities, which are not usually encountered in practical applications. So the
most vital thin in turbulent flow is that the fluid friction viz. layer to layer and
between fluid and sold friction gets enhanced [6]. Which means it offers more But when the flow becomes turbulent, friction between the fluid and solid wall
resistance for the given type of fluid. This means for a given flow rate through a and within the fluid enhances due to mixing in the turbulent zone. So due to a rise
duct, the pressure drop across a length of a duct is much more than that of a lami- in flow resistance, the pressure drop gets enhanced. But there is not a single equa-
nar flow. For a fluid flow in a pipe (Figure 1), the wall shear stress (τw) can be eval- tion by which one can fit the pressure drop and flow rate relation or f-Re relations
uated as [7]: through the entire range of turbulent flow regimes. So, to handle such situations,
experiments come in. People like Stanton [9], Nikuradse [9,10], etc., have
worked on developing such expressions, and finally, Moody documented them
.................................................................................. (1) in the form of a diagram which is famously known as Moody's diagram [11].
They have observed that in turbulent flow, the f is not the only function of Re but
wall roughness as well. But reading this diagram requires a great deal of interpo-
lation, which can result in an error. So, to help the researchers working in the field
of pipe flow, some sort of computations is required, which will save time and
make the error of the computation free.
.................................................... (7)
Where Dh is the hydraulic diameter which gets reduced to the pipe diameter d for
the circular pipe. Eq. (7) is an implicit equation which cannot be directly solved
for the f. So, an iterative procedure can be adapted to solve for f. The steps to solve
the Eq. (7) implicitly are as follows:
iii. Solve Eq. (8) for new f (say fn) by using fg as:
...................................................... (9)
v. Update the fg by obtained value fn as a new guess for the next iteration.
First, Re is checked; if it is less than 2000 then Eq. (6) is used to evaluate the f,
whereas the Colebrook equation is solved for other values. Moreover, one can
also observe that in the equation, relative roughness is used, which is the ratio of
wall roughness to that of pipe diameter (ϵ/d ). Therefore, to use this function, one Figure 2: Friction factor vs Re for different values of relative
has to supply the wall roughness, pipe diameter, Re, and guess value for friction roughness.
factor as shown in the below-mentioned code snippet.
4. CLASSES OF PROBLEMS TYPICALLY ENCOUNTERED IN A
FLUID FLOW IN A SINGLE PIPELINE:
When flow through a single pipeline happens then, three distinct types of prob-
lems usually are arisen, which are listed below:
I. The pipe diameter, pipe length, and flow rates are given, and one has to find
ii. Head loss over a pipe length for a pipe of known diameter is given; the target
is to find the flow rate and power required.
iii. The flow rate and the head loss over a given pipe length are known the pipe
diameter has to be evaluated.
The first class of problem is explicit, and one can quickly solve the pressure drop
and power using Eq. (4) and (5). However, the second and third types of prob-
lems cannot be solved explicitly as velocity and friction factors are unknown in
the second, and diameter, and friction factors are unknown in the third class. So,
these problems can only be solved by iteration procedure. To solve these prob-
lems with the help of Python, following apart for the function to evaluate friction
factor, the following more functions are created to ease up the problem solving:
Now let us demonstrate how these problems can be solved using the above
python functions.
i. Determine the frictional head loss and pumping power required when water
flows through a 300 m long steel pipe of 150 mm diameter at a flow rate of
0.05 m3/s. The kinematic viscosity of water and the wall roughness of the
pipe are ν = 1.14×10-6 mm and ϵ = 0.15 mm [23].
Python Solution:
The program output is: Q = 0.0126 m3/s.
iii. Determine the size of a pipe (ϵ=0.15 mm) needed to transmit water
(ν=1.14×10-6 m2/s) to a distance of 180 m at 0.85 m3/s with a loss of head of 9
m [23].
Python solution:
ii. Oil of kinematic viscosity of 10-5 m2/s flows at a steady state through a pipe of
diameter 100 mm and of surface roughness of 0.25 mm. For a pipe length of
120 m, the friction head loss is 5 m. What is the flow rate of oil through the
pipe [23].
It has been observed that the results obtained by the computer programs are the
same as those obtained in the literature [23].
REFERENCES:
I. N. Rott, Note on the History of the Reynolds Number, Annu. Rev. Fluid Mech. 22
(1990) 1–12. doi:10.1146/annurev.fl.22.010190.000245.
II. M.T. Schobeiri, Basic Physics of Laminar-Turbulent Transition, in: Turbomach.
Flow Phys. Dyn. Perform., Springer Berlin Heidelberg, Berlin, Heidelberg, 2012:
pp. 515–544. doi:10.1007/978-3-642-24675-3_19.
III. G. Biswas, V. Eswaran, Turbulent flows: fundamentals, experiments and modeling,
CRC Press, 2002.
IV. A. Cioncolini, L. Santini, An experimental investigation regarding the laminar to tur-
bulent flow transition in helically coiled pipes, Exp. Therm. Fluid Sci. 30 (2006)
367–380. doi:https://doi.org/10.1016/j.expthermflusci.2005.08.005.
V. Y. Zhou, Turbulence theories and statistical closure approaches, Phys. Rep. 935
(2021) 1–117. doi:https://doi.org/10.1016/j.physrep.2021.07.001.
VI. E.A. Al-Khdheeawi, D.S. Mahdi, Apparent viscosity prediction of water-based
muds using empirical correlation and an artificial neural network, Energies. 12
(2019) 1–10. doi:10.3390/en12163067.
VII. B. Guerrero, M.F. Lambert, R.C. Chin, Extreme wall shear stress events in turbulent
pipe flows: spatial characteristics of coherent motions, J. Fluid Mech. 904 (2020)
A18. doi:10.1017/jfm.2020.689.
VIII. H.A. Milukow, A.D. Binns, J. Adamowski, H. Bonakdari, B. Gharabaghi, Estima-
tion of the Darcy–Weisbach friction factor for ungauged streams using Gene
Expression Programming and Extreme Learning Machines, J. Hydrol. 568 (2019)
311–321. doi:https://doi.org/10.1016/j.jhydrol.2018.10.073.
IX. J. Nikuradse, Regularity of turbulent flow in smooth pipes, 1949.
X. J. Nikuradse, others, Laws of flow in rough pipes, (1950).
XI. M. LaViolette, On the History, Science, and Technology Included in the Moody Dia-
gram, J. Fluids Eng. 139 (2017). doi:10.1115/1.4035116.
XII. P. Dumka, S. Sharma, H. Gautam, D.R. Mishra, Finite Volume Modelling of an
Axisymmetric Cylindrical Fin using Python, Res. Appl. Therm. Eng. 4 (2021) 1–11.
XIII. Y.C. Huei, Benefits and introduction to python programming for freshmore students
using inexpensive robots, in: Proc. IEEE Int. Conf. Teaching, Assess. Learn. Eng.
Learn. Futur. Now, TALE 2014, 2015: pp. 12–17. doi:10.1109/TALE.2014.
7062611.
XIV. G. Moruzzi, Python Basics and the Interactive Mode, in: Essent. Python Phys.,
Springer International Publishing, Cham, 2020: pp. 1–39. doi:10.1007/978-3-030-
45027-4_1.
XV. P. Dumka, A. Singh, G.P. Singh, D.R. Mishra, Kinematics of Fluid : A Python
Approach, Int. J. Res. Anal. Rev. 9 (2022) 131–135.
XVI. M. Cywiak, D. Cywiak, SymPy, in: Multi-Platform Graph. Program. with Kivy
Basic Anal. Program. 2D, 3D, Stereosc. Des., Apress, Berkeley, CA, 2021: pp.
173–190. doi:10.1007/978-1-4842-7113-1_11.
XVII. A. Meurer, C.P. Smith, M. Paprocki, O. Čertík, S.B. Kirpichev, M. Rocklin, Am.T.
Kumar, S. Ivanov, J.K. Moore, S. Singh, T. Rathnayake, S. Vig, B.E. Granger, R.P.
Muller, F. Bonazzi, H. Gupta, S. Vats, F. Johansson, F. Pedregosa, M.J. Curry, A.R.
Terrel, Š. Roučka, A. Saboo, I. Fernando, S. Kulal, R. Cimrman, A. Scopatz, SymPy:
Symbolic computing in python, PeerJ Comput. Sci. 2017 (2017) 1–27.
doi:10.7717/peerj-cs.103.
XVIII. R. Johansson, Numerical python: Scientific computing and data science applica-
tions with numpy, SciPy and matplotlib, Second edition, Apress, Berkeley, CA,
2018. doi:10.1007/978-1-4842-4246-9.
XIX. P.S. Pawar, D.R. Mishra, P. Dumka, M. Pradesh, Obtaining Exact Solutions of
Visco- Incompressible Parallel Flows Using Python, Int. J. Eng. Appl. Sci. Technol.
6 (2022) 213–217.
XX. P. Dumka, P.S. Pawar, A. Sauda, G. Shukla, D.R. Mishra, Application of He’s
homotopy and perturbation method to solve heat transfer equations: A python
approach, Adv. Eng. Softw. 170 (2022) 103160. doi:10.1016/j.advengsoft.
2022.103160.
XXI. E. Bisong, Matplotlib and Seaborn, in: Build. Mach. Learn. Deep Learn. Model.
Google Cloud Platf., Apress, Berkeley, CA, 2019: pp. 151–165. doi:10.1007/978-1-
4842-4470-8_12.
XXII. D.I.H. Barr, C. White, A.A. Smith, T.E. Stanton, Application of Similitude Theory to
Correlation of Uniform Flow Data., Proc. Inst. Civ. Eng. 37 (1967) 487–509.
XXIII. G. Biswas, S.K. Som, Introduction to Fluid Mechanics and Fluid Machines, Tata
McGraw-Hill Education, 2003.