0% found this document useful (0 votes)
6 views2 pages

VBA Code for Settling Velocity Calculation

The document contains a VBA macro for calculating the settling velocity of particles in a fluid. It reads input parameters such as particle density, fluid density, and diameters, computes coefficients K1 and K2, and iteratively calculates the settling velocity until a specified tolerance is met. The results, including Reynolds number and drag coefficient, are output to an Excel sheet and a message box displays the final settling velocity and the number of iterations taken.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

VBA Code for Settling Velocity Calculation

The document contains a VBA macro for calculating the settling velocity of particles in a fluid. It reads input parameters such as particle density, fluid density, and diameters, computes coefficients K1 and K2, and iteratively calculates the settling velocity until a specified tolerance is met. The results, including Reynolds number and drag coefficient, are output to an Excel sheet and a message box displays the final settling velocity and the number of iterations taken.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Sub ComputeSettlingVelocitySR()

Dim i As Integer
Dim V_old As Double, V_new As Double, Re As Double, Cd As Double
Dim K1 As Double, K2 As Double, phi As Double
Dim rho_p As Double, rho_f As Double, g As Double
Dim dv As Double, dn As Double, D As Double
Dim tol As Double, error_val As Double
Dim Re_mod As Double

' Read inputs


rho_p = Range("B3").Value ' Particle density
rho_f = Range("B4").Value ' Fluid density
phi = Range("B5").Value ' Sphericity
dn = Range("B6").Value ' Nominal diameter
dv = Range("B7").Value ' Volume-equivalent diameter
D = Range("B8").Value ' Pipe/characteristic length
g = Range("B9").Value ' Gravitational acceleration
V_old = Range("B10").Value ' Initial velocity guess

' Compute K1 and K2


K1 = 1 / ((phi) ^ 0.5)
K2 = (10 ^ (1.8148 * (-Log(phi) / Log(10)) ^ 0.5743)) / phi ' (10 ^ (1.8148 *
(-Log(10) * (phi)) ^ 0.5743)) / (phi) '

' Write K1 and K2 to cells B12 and B13


Range("A12").Value = "K1"
Range("B12").Value = K1
Range("A13").Value = "K2"
Range("B13").Value = K2

' Initialize loop


tol = 0.00001
i = 1

' Clear previous iteration table


Range("A21:F100").ClearContents
Range("A20:F20").Value = Array("Iteration", "V_s (m/s)", "Re", "Re'", "C_d",
"Error")

Do
' Compute Reynolds number
Re = rho_f * V_old * dn / 0.001 ' mu = 0.001 Pa·s
Re_mod = Re * K1 * K2

' Drag coefficient


Cd = ((24 / Re_mod) * (1 + 0.1118 * Re_mod ^ 0.6567) + 0.4305 / (1 + 3305 /
Re_mod))

' Settling velocity


V_new = Sqr((4 * g * dn * (rho_p - rho_f)) / (3 * rho_f * Cd))

' Error
error_val = Abs(V_new - V_old)

' Output to table


With Range("A" & i + 20)
.Offset(0, 0).Value = i
.Offset(0, 1).Value = V_new
.Offset(0, 2).Value = Re
.Offset(0, 3).Value = Re_mod
.Offset(0, 4).Value = Cd
If i > 1 Then
.Offset(0, 5).Value = error_val
End If
End With

V_old = V_new
i = i + 1
Loop While error_val > tol And i <= 100

' Output final velocity to B14


Range("A14").Value = "Final V_s"
Range("B14").Value = V_new

MsgBox "Settling velocity converged to " & Round(V_new, 5) & " m/s in " & i - 1
& " iterations.", vbInformation
End Sub

You might also like