Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ECMM171P Programming for Engineers

Assignment 1 - Friction Factors

As a fluid flows through a pipe, it encounters resistance according to several factors, including the diameter and wall roughness of the pipe, the velocity and viscosity of the fluid, and whether the fluid is in a laminar or turbulent state. However, the relationship between these variables is typically complex and nonlinear, meaning that we require computational techniques to predict pressure losses a requirement in a range of engineering design scenarios.

The purpose of this assignment is to create a predictive engineering tool to calculate the so- called friction factor of a pipe flow, thereby providing an estimate of pressure loss per unit length.

1    Theory

Consider a circular pipe of diameter D and length L, through which a fluid of density ρ is flowing at a mean flow velocity U . The pressure loss ∆p per unit length is given by the Darcy- Weisbach equation

p          ρU2

L           2D ,

where the dimensionless quantity fD  is referred to as the Darcy friction factor.  The precise value of the friction factor, however, is difficult to determine analytically for turbulent flows. Its calculation depends on:

❼ The Reynolds number

ρUD

Re =

where µ is the dynamic viscosity of the fluid. Re dictates whether the fluid is in a turbulent or laminar state: if Re < 2040 the flow can be assumed to be laminar, or if Re ≥ 2040 we assume it is turbulent.

❼ For turbulent flows, the pipe’s relative roughness, ϵr  = ϵ/D, where ϵ is the pipe’s effective

roughness height.

1.1    Calculating fD

If the flow is laminar, then the relationship for the friction factor is straightforward and can be derived from the Poiseuille (laminar) flow profile, giving,

fD  =

On the other hand, if the flow is turbulent, the relationship is more complex. In this case, fD can only be found by solving the nonlinear Colebrook- White equation

 = −2log10  (  + ) .

Clearly, this relationship cannot be solved analytically. However, by rearranging this equation, we can see that it can instead be turned into a root-finding problem; i.e. find fD  such that the function C(fD ) = 0, where

C(fD ) =  + 2log10  (  + ) .

This is where your program will come into play! Your task is to write a Newton-Rapshon solver that will solve this root finding problem.

2    Your Tasks

1. Write two functions called colebrook and colebrook deriv that evaluate C(fD ) and the derivative of C(fD ) with respect to fD , respectively. These functions should include:

Inputs:    the friction factor fD , the Reynolds number Re, and the relative roughness e/D . Outputs:    the value of C(fd ) and of the derivative of C(fD ) respectively.

2. In order to find the root of a function f(x) using the Newton-Raphson algorithm, we first require the function’s derivative f\ (x) and an initial starting point x0 , then we can approximate roots of the function by applying the iterative relationship

f(xn )

f\ (xn ) ,

which after enough iterations usually gives a good approximation to a root of f .

In this task, you should write a function called newton, which will perform Newton- Rapshon using your colebrook and colebrook deriv functions to solve for a root of the C(fD ) function.

In the Newton-Raphson algorithm you should check at each step whether the sequence is your desired tolerance.  You should also include a variable controlling the maximum number of iterations in case the algorithm does not converge.


has converged to a limit, this can be done by calculating |xn  xn 1 | < tol, where tol


Your newton function should include:

Inputs:  initial value, tolerance, max iterations

Outputs:  the root, number of iterations the algorithm run.

 

10- 1

10-2

Moody chart for laminar/turbulent pipe flow

103                        104                        105                        106                         107                        108                        109

Reynolds number: Re

Figure 1: Moody diagram for a range of relative pipe roughness factors.

NOTE: Depending on how you solve the problem your newton function will likely require some extra parameters which may be needed by the colebrook function. You are free to adjust the inputs to your newton function based on your approach, however you should describe in your comments what those parameters are.

3. Finally, write a script called moody which calls the Newton-Raphson function to find the friction coefficients and plots a Moody diagram similar to the one shown in Figure 1. Moody diagrams visualise the friction factor for laminar and turbulent regimes across a range of different pipe roughness factors and Reynolds numbers, on a log-log scale. Typically a specific value of ϵ/D is compared against a range of reference values.  In particular, your Moody diagram should show:

❼ the laminar friction factor for 500 ≤ Re ≤ 2500;

❼ the turbulent friction factors given by the Colebrook equation for 2 × 103  ≤ Re ≤ 108 for the reference values of ϵ/D = 0 (i.e. a smooth pipe), 10 6 , 10 5 , 10 4 , 10 3  and 10 2 .

❼ the laminar-turbulent transition point at Re = 2040.

❼ an optional list of points, shown as markers on the graph, that are read by your script.

Your script should read a text file (found on ELE) which will contain values of:  Pipe diameter D, Fluid velocity U in m·s 1, Dynamic viscosity µ in Pa·s, Fluid density kg ·m3 , and Pipe roughness ϵ in mm, and then highlight in the Moody diagram the locations where they correspond.  Finally it should output in a new text file called pressure loss .txt the friction factor and the pressure loss per unit length (∆p/L) for the given parameters.

Your program should produce a Matlab figure, but also export it into a .png format. Please format the figure in a similar way as in the example shown in Figure 1 including labels, and markers for the desired points (as provided by the text file).

NOTE: In order to check that your programs are working correctly, you can use the following parameters and compare the friction factor with your program outputs:

Pipe  diameter  [m]:  1

Fluid  velocity  [m/s]:  1

Fluid  density  [kg/mˆ3]:  1000

Fluid  viscosity  [Pa  s]:  0 .0010518

Pipe  roughness  [mm]:  3

Reynolds  number  is:  9 .5075e+05

Calculated  friction  factor:  2 .6273e-02

3    Marking scheme

Your submission will be assessed on the following criteria:

❼ Fully working implementation of the colebrook and colebrook deriv functions. [10%]

❼ Fully working implementation of the newton method.                                    [30%]

❼ Fully working implementation of the moody script which calls the functions.  [30%]

❼ Correct implementation of the text input/output in your script and correctly for-

matted graph.                                                                                               [15%]

❼ Discretionary marks for good programming technique, structure, testing and com-

menting.                                                                                                       [15%]

Details regarding the specific criteria that are used in the above can be found in the module handbook on ELE. You should attempt all of the above routines; incomplete solutions will be given partial credit.  Note that these routines will all be marked independently, and you can still receive full credit for complete solutions even if the preceding parts are not fully implemented.

4    Submission

You should compress all your Matlab files and your Moody diagram in a single .zip file, and submit using BART.