Moody Chart Calculator Design
The Moody chart is based on the solutions to the Colebrook equation; this calculator uses Newton's method for finding zeros to solve the Colebrook equation.
Colebrook equation |
Newton's method |
How this calculator was made and how you can implement your own will be explained here. First, the simpler results from the Moody chart that do not require Newton's method will be covered. This includes the case of laminar flow, which occurs when the Reynolds Number (Re) is less than about 2300; the friction factor (f) can easily be calculated by dividing 64 by the Reynolds Number. This can be derived by applying the assumption of laminar flow in a circular pipe to the Navier-Stokes equations. It is worth noting that the friction factor for laminar flow does not depend on the relative roughness (ε/D) of a pipe.
Friction factor for laminar flow |
Transition flow occurs when the Reynolds Numbers is between about 2300 and 4000. Flows at this rate often oscillate between laminar and turbulent because of the sudden increase in friction factor that is associated with turbulent flow. This makes accurate predictions of transition flow friction factors impossible without testing.
Fully rough flow is when increasing the Reynolds number of a turbulent flow no longer affects the friction factor. Unlike laminar flow, the friction factor of fully rough flow depends only on the relative roughness of a pipe. In this case the friction factor can be expressed explicitly as a function of relative roughness using the von Kármán equation. For convenience, a variable x will be defined as the inverse square root of the friction factor, and this will be used for the remainder of this explanation.
|
von Kármán equation for fully rough flow |
For a pipe with an inner diameter that is smooth (i.e. the relative roughness is zero) the Prandtl equation may used. Newton's method for finding zeros is used to solve this equation. To accomplish this the right hand side (RHS) of the Prandtl equation is moved to the left hand side (LHS) leaving the RHS at zero. The LHS will be defined as the equation y(x) to be used for Newton's method. The derivative of y(x) must also be evaluated for Newton's method; this will be y'(x). Another definition for convenience is made to simplify the math; the variable B will be defined as 2.51 divided by the Reynolds number.
Prandtl equation
|
Form of Prandtl equation for Newton's method |
For all turbulent flow in rough or smooth pipes the Colebrook equation can be used. To get the Colebrook equation into a form that can be solved using Newton's method the same procedure implemented on the Prandtl equation is used. Again a variable, in this case A, is added to to simplify the math.
Colebrook equation
|
Form of Colebrook equation for Newton's method |
Whether the Prandtl equation or Colebrook equation are being solved, Newton's method requires an initial guess (x0) to hone in on the actual solution. In 1983 S. E. Haaland developed an explict relationship to make good approximations of the solutions to the Colebrook equation. This will be used as the initial guess. This guess is then plugged into Newton's method and iterated recursively N times (usually two or three times) to converge upon the solution. The solution is then converted back into a friction factor based on the relationship made in the beginning.
S. H. Haaland relationship
|
Newton's method
|
This how the Moody chart calculator above evaluates friction factors. The following pseudocode is based on the code used for the calculator:
function moody(Re (Reynolds Number), rel_e (Relative roughness (e/D)), n (iterations (optional))) begin if Re = 0 (no flow) then return "infinity" if Re <=2300 (Laminar Flow condition) then return 64/Re; if Re < 4000 (Transition Flow, this cannot be accurately calculated) then return "transition flow" (Turbulent Flow conditions) var x (x = f^(-1/2)) if Re = Infinity (fully rough flow) then begin if rel_e = 0 then return 0 else x=-2.0*log10(rel_e/3.7) (Von Karman equation) return 1/(x^2) (f = 1/x^2) end equation y (y = 0, this is used in Newton's method to find x), y' (y'= dy/dx) var A (A = (e/D)/3.7), B (B = 2.51/Re ) B = 2.51/Re if rel_e = 0 (smooth pipe flow) then begin A = 0 y(x) = "x+2*log10(B*x)" (y = Prandtl equation = 0) y'(x) = "1+2/(x*ln10)" end else if rel_e > 0 (typical turbulent pipe flow) then begin A = rel_e/3.7 y(x) = "x+2*log10(A+B*x)" (y = Colebrook equation =0) y'(x) = "1+2*(B/ln10)/(A+B*x)" end if n is undefined then n = 3 (default # of iterations for Newton's Method) x = -1.8*log10((6.9/Re)+A^1.11) (S.E. Haaland equation (initial guess)) for var i from 1 to n (Newton's Method) x = x-y(x)/y'(x) return 1/(x^2) (f = 1/x^2) end |
It is important to recognize the code above requires the ability to evaluate a string as an equation. This is not convenient to do in most programming languages. Also for real world situations (i.e. 0<Re<∞ and 0≤ε/D<1) the friction factor only needs to be evaluated from the laminar flow relationship or Colebrook equation. I only added these other cases for completeness, but the pseudocode above can be simplified to the pseudocode below for simple accurate real world calculations.
function moody(Re (Reynolds Number), rel_e (Relative roughness (e/D)), n (iterations (optional))) begin if Re <=2300 (Laminar Flow) then return 64/Re; if Re < 4000 (Transition Flow, this cannot be accurately calculated) then return "transition flow" (Turbulent Flow) var x (x = f^(-1/2)), y (y = 0, this is used in Newton's method to find x), y' (y'= dy/dx), A (A = (e/D)/3.7), B (B = 2.51/Re ) A = rel_e/3.7 B = 2.51/Re if n is undefined then n = 3 (default # of iterations for Newton's Method) x = -1.8*log10((6.9/Re)+A^1.11) (S.E. Haaland equation (initial guess)) for var i from 1 to n (Newton's Method) begin y = x+2*log10(A+B*x) (y = Colebrook equation =0) y' = 1+2*(B/ln10)/(A+B*x) x = x - y/y' end return 1/(x^2) (f = 1/x^2) end |
This code is simple enough to be implemented in a program, script, spreadsheet, or graphing calculator.
If you have any questions, comments, or concerns I can be contacted at [email protected].