Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Useful implementation of Colebrook-White equation solver
- Function Colebrook2(Rr As Double, Re As Double) As Double
- Dim f_min As Double, f_max As Double, f As Double
- Dim g_lower As Double, g_middle As Double
- Dim n As Integer
- f_min = (2.51 / Re) ^ 2 * (1 - Rr / 3.7) ^ (-2)
- f_max = ((2.51 / Re + Log(10) / 2) / (1 - Rr / 3.7)) ^ 2
- n = 0
- Do
- n = n + 1
- f = (f_min + f_max) / 2
- g_middle = -2 / Log(10) * Log(Rr / 3.7 + 2.51 / Re * f ^ (-1 / 2)) - f ^ (-1 / 2)
- g_lower = -2 / Log(10) * Log(Rr / 3.7 + 2.51 / Re * f_min ^ (-1 / 2)) - f_min ^ (-1 / 2)
- If (g_middle = 0 Or (f_max - f_min) / 2 < 0.000001) Then
- Exit Do
- Else
- If (g_middle * g_lower > 0) Then
- f_min = f
- Else
- f_max = f
- End If
- End If
- Colebrook2 = f
- If (n > 100) Then
- Colebrook2 = CVErr(xlErrNA)
- Exit Do
- End If
- Loop
- End Function
Advertisement
Add Comment
Please, Sign In to add comment