MACROS IMPLEMENTADOS ------------------------------------------------------------------------------------------------------------- ECUACIÓN DE COLEBROOK PARA FACTOR DE FRICCIÓN ------------------------------------------------------------------------------------------------------------- Function Ff(Re As Single, eD As Single) As Single 'ff es el factor de fricción, Re es el número de Reynolds y eD es e/D la rugosidad relativa Dim A As Single, B As Single, Err As Single B = 0.1 Err = 1 A = -2 * Log(eD / 3.7 + 2.51 / Re / (B ^ 0.5)) / Log(10) Ff = 1 / A ^ 2 Do Until Err < 0.000001 B = Ff A = -2 * Log(eD / 3.71 + 2.51 / Re / (B ^ 0.5)) / Log(10) Ff = 1 / A ^ 2 Err = Abs(B - Ff) Loop End Function ------------------------------------------------------------------------------------------------------------- RESISTENCIA EN UN DUCTO ------------------------------------------------------------------------------------------------------------- Function RDucto(ro As Single, f As Single, L As Single, Per As Single, A As Single) As Single Dim K As Double Dim df As Double ' Calcular K K = f * ro / 2 ' Calcular df df = ro / 0.075 ' Calcular R RDucto = K * L * (Per / A ^ 3) * df End Function ------------------------------------------------------------------------------------------------------------- RESISTENCIA EN UN ACCESORIO ------------------------------------------------------------------------------------------------------------- Function RAccesorio(ro As Single, k As Single, A As Single) As Single ' Calcular RAccesorio RAccesorio = k * ro / (2 * A ^ 2) End Function ------------------------------------------------------------------------------------------------------------- DELTA Q PARA MÉTODO HARDY CROSS ------------------------------------------------------------------------------------------------------------- Function DeltaFlujo(Qa As Range, R As Range, pf As Double, Sf As Double) As Double Dim i As Integer Dim sum1 As Double, sum2 As Double, Qai As Double sum1 = 0 sum2 = 0 ' Realizar la suma para los valores de DeltaQ For i = 1 To Qa.Cells.Count Qai = Qa.Cells(i, 1).Value sum1 = sum1 + R.Cells(i, 1).Value * Abs(Qai) * Qai - pf sum2 = sum2 + 2 * R.Cells(i, 1).Value * Abs(Qai) + Sf Next i ' Calcular DeltaQ DeltaFlujo = -sum1 / sum2 End Function ------------------------------------------------------------------------------------------------------------- ITERACIONES ------------------------------------------------------------------------------------------------------------- Sub IteracionSistemaI() Dim i As Integer Dim ValorC15 As Double Dim ValorC21 As Double Dim ValorC27 As Double Dim ValorC33 As Double Dim ValorC39 As Double ' límite de iteraciones Const MaxIteraciones As Integer = 1000 ' Hoja Dim NombreHoja As String NombreHoja = "MALLAS" Dim Hoja As Worksheet Set Hoja = ThisWorkbook.Sheets(NombreHoja) ' Iniciar iteraciones For i = 1 To MaxIteraciones ' Copiar valores de E10:E38 (Q corregido) a D10:D38 (Q anterior) Hoja.Range("D10:D38").Value = Hoja.Range("E10:E38").Value ' Obtener el valor absoluto de DeltaQ ValorC15 = Abs(Hoja.Range("C15").Value) ValorC21 = Abs(Hoja.Range("C21").Value) ValorC27 = Abs(Hoja.Range("C27").Value) ValorC33 = Abs(Hoja.Range("C33").Value) ValorC39 = Abs(Hoja.Range("C39").Value) ' Verificar si |DeltaQ|<= 0,00001 If ValorC15 <= 0.00001 And ValorC21 <= 0.00001 And ValorC27 <= 0.00001 And ValorC33 <= 0.00001 And ValorC39 <= 0.00001 Then MsgBox "Iteración finalizada en la iteración " & i Exit Sub End If ' Si no se cumple la condición, continuar con la próxima iteración Next i ' Mensaje si se alcanza el límite máximo de iteraciones MsgBox "Se alcanzó el límite máximo de iteraciones (" & MaxIteraciones & " iteraciones)." End Sub