Upload
davidvaca9
View
40
Download
3
Embed Size (px)
Citation preview
Uso de VBA para simular una perturbación aleatoria en un Tanque Agitado
A B C D E1 Parámetros del Tanque2 Magnitud Símbol
oValor Unidad
3 Diámetro D = 5 [m]4 Altura del Tanque H = 2 [m]5 Altura Inicial Fluido ho = 0 [m]67 Parámetros de la Tubería8 Magnitud Símbol
oValor Unidad
9 Contante de Válvula Kv = 15 [m3/h*atm1/2]
10
Fracción de Apertura f = 1
11
Caída de Presión Total
deltap = 6,8046 [atm]
1213
Parámetro de Integración
14
Magnitud Símbolo
Valor Unidad
15
Tiempo de Simulación
Tmax = 10 [h]
T deltat = 1,00E-03 [h]
1718
Parámetro de los Flujos
19
Magnitud Símbolo
Valor Unidad
20
Flujo Inicial de Entrada
Q = 50 [m3/h]
0 2 4 6 8 10 12
-0.5
0
0.5
1
1.5
2
2.5
Nivel del Líquido en el Tiempo
Tiempo [hr]
Niv
el d
el Lí
quid
o [m
]
0 2 4 6 8 10 120
10
20
30
40
50
60
70
Nivel del Líquido en el Tiempo
Caudal de Entrada [m3/h]
Caudal de Salida [m3/h]
Tiempo [hr]
Niv
el d
el Lí
quid
o [m
]
Código Fuente
Dim D, H, ho, Kv, f, Tmax, deltat, deltap, Q As Single
Sub Tanque()
'Parámetros del Tanque
D = Worksheets("Hoja1").Cells(3, 4)
H = Worksheets("Hoja1").Cells(4, 4)
ho = Worksheets("Hoja1").Cells(5, 4)
'Parámetros de la Tubería
Kv = Worksheets("Hoja1").Cells(9, 4)
f = Worksheets("Hoja1").Cells(10, 4)
deltap = Worksheets("Hoja1").Cells(11, 4)
'Parámetros de Integración
Tmax = Worksheets("Hoja1").Cells(15, 4)
deltat = Worksheets("Hoja1").Cells(16, 4)
'Parámetros de los Flujos
Q = Worksheets("Hoja1").Cells(20, 4)
Call integration(D, H, ho, Kv, f, deltap, Tmax, deltat, Q)
End Sub
Sub integration(D, H, ho, Kv, f, deltap, Tmax, deltat, Q)
K = 1 / 4 * 3.14159 * D * D
Qf = Kv * f * Sqr(deltap)
ht = ho
fila = 3
Worksheets("Hoja2").Cells(1, 1) = "tiempo"
Worksheets("Hoja2").Cells(2, 1) = "[hr]"
Worksheets("Hoja2").Cells(1, 2) = "Nivel del Líquido"
Worksheets("Hoja2").Cells(2, 2) = "[m]"
Worksheets("Hoja2").Cells(1, 3) = "Caudal de Entrada"
Worksheets("Hoja2").Cells(2, 3) = "[m3/h]"
Worksheets("Hoja2").Cells(1, 4) = "Caudal de Salida"
Worksheets("Hoja2").Cells(2, 4) = "[m3/h]"
For t = 0 To Tmax Step deltat
'Ecuación del Balance de Masa
deltah = (Qo - Qf) / K * deltat
ht = ht + deltah
If ht < H Then
If t < 1 / 5 * Tmax Then
Qo = Q
Worksheets("Hoja2").Cells(fila, 1) = t
Worksheets("Hoja2").Cells(fila, 2) = ht
Worksheets("Hoja2").Cells(fila, 3) = Qo
Worksheets("Hoja2").Cells(fila, 4) = Qf
fila = fila + 1
ElseIf t >= 1 / 5 * Tmax Then
Qo = (60 - 50) * Rnd + 50
Worksheets("Hoja2").Cells(fila, 1) = t
Worksheets("Hoja2").Cells(fila, 2) = ht
Worksheets("Hoja2").Cells(fila, 3) = Qo
Worksheets("Hoja2").Cells(fila, 4) = Qf
fila = fila + 1
End If
ElseIf ht >= H Then
ht = H
Qo = (60 - 50) * Rnd + 50
Worksheets("Hoja2").Cells(fila, 1) = t
Worksheets("Hoja2").Cells(fila, 2) = ht
Worksheets("Hoja2").Cells(fila, 3) = Qo
Worksheets("Hoja2").Cells(fila, 4) = Qf
fila = fila + 1
End If
Next t
Worksheets("Hoja2").Cells(fila, 1) = t
Worksheets("Hoja2").Cells(fila, 2) = ht
Worksheets("Hoja2").Cells(fila, 3) = Qo
Worksheets("Hoja2").Cells(fila, 4) = Qf
End Sub