Untitled
unknown
plain_text
2 years ago
6.3 kB
5
Indexable
Function FDOUB(X As Single, Y As Single, xo As Single, yo As Single, KAPPA As Single) ' Functions for the Stream function due to elementary flows. ' This is based on equation 6.96 on page 308 in the fluids pdf ' This REAL function returns the stream function at X,Y due to a ' Doublet of strength KAPPA located at XO,YO. Dim Pie As Single ' Assign the value of pi to the variable Pie Pie = Application.Pi() ' Calculate the stream function due to a doublet using the given formula FDOUB = -KAPPA * (1# / (2# * Pie)) * (Y - yo) / ((X - xo) ^ 2 + (Y - yo) ^ 2) End Function Function Fpsands(X As Single, Y As Single, x0 As Single, y0 As Single, hat As Single) As Single ' Functions for the Stream function due to elementary flows. ' This REAL function returns the stream function at x,y due to a ' source or a sink of strength hat located at x0,y0 ' This is based on equation 6.83 on page 303 in the fluids pdf Dim Pie As Single, A As Single, B As Single Pie = Application.Pi() B = X - x0 A = Y - y0 If Y > 0 Then ' The Atan2 function gives the correct answer if the y value is greater than zero, ' that is, first and second quadrants. Fpsands = (hat / (2# * Pie)) * (Application.Atan2(B, A)) Else ' This equation corrects the atan2 problem when y is less than zero, ' that is the third and fourth quadrants Fpsands = (hat / (2# * Pie)) * ((2# * Pie) + (Application.Atan2(B, A))) End If End Function Function fvortex(X As Single, Y As Single, x0 As Single, y0 As Single, gamma As Single) As Single ' Functions for the Stream function due to elementary flows. ' This is based on equation 6.91 on page 306 in the fluids pdf. ' This REAL function returns the stream function at x,y due to a ' vortex of strength gamma located at x0,y0 Dim Pie As Single, lan As Single Pie = Application.Pi() fvortex = (gamma / (2# * Pie)) * Application.Ln((((X - x0) ^ 2) + _ ((Y - y0) ^ 2)) ^ 0.5) End Function Function UniformFlowStreamFunction(X As Single, Y As Single, U As Single, alpha As Single) As Single ' Function for the stream function of uniform flow ' ? = U * (y * Cos(a) - x * Cos(a)) UniformFlowStreamFunction = U * (Y * Cos(alpha) - X * Cos(alpha)) End Function Function SumOfResults(X As Single, Y As Single, x01 As Single, y01 As Single, KAPPA As Single, x02 As Single, y02 As Single, hat As Single, x03 As Single, y03 As Single, gamma As Single, U As Single, alpha As Single) Dim result1 As Single Dim result2 As Single Dim result3 As Single Dim result4 As Single ' Call each function and store their results result1 = FDOUB(X, Y, x01, y01, KAPPA) result2 = Fpsands(X, Y, x02, y02, hat) result3 = fvortex(X, Y, x03, y03, gamma) result4 = UniformFlowStreamFunction(X, Y, U, alpha) ' Add the results together SumOfResults = result1 + result2 + result3 + result4 End Function Sub CalculateStreamFunction4() ' Specify the coordinates and parameters Dim X As Single Dim Y As Single Dim U As Single Dim alpha As Single ' Assign values to the coordinates and parameters X = Range("D13").Value Y = Range("E12").Value U = Range("D6").Value alpha = Range("D7").Value ' Calculate the stream function using the UniformFlowStreamFunction and store it Dim result1 As Single result4 = UniformFlowStreamFunction(X, Y, U, alpha) End Sub Function SumOfResults(X As Variant, Y As Variant, x01 As Single, y01 As Single, KAPPA As Single, _ x02 As Single, y02 As Single, hat As Single, x03 As Single, _ y03 As Single, gamma As Single, U As Single, alpha As Single) As Double Dim result1 As Single Dim result2 As Single Dim result3 As Single Dim result4 As Single ' Call each function for each value in X and Y arrays Dim i As Long For i = LBound(X, 1) To UBound(X, 1) result1 = result1 + FDOUB(X(i, 1), Y(i, 1), x01, y01, KAPPA) result2 = result2 + Fpsands(X(i, 1), Y(i, 1), x02, y02, hat) result3 = result3 + fvortex(X(i, 1), Y(i, 1), x03, y03, gamma) result4 = result4 + UniformFlowStreamFunction(X(i, 1), Y(i, 1), U, alpha) Next i ' Sum up the results SumOfResults = result1 + result2 + result3 + result4 'Function SumOfResults(X As Single, Y As Single, x01 As Single, y01 As Single, KAPPA As Single, x02 As Single, y02 As Single, hat As Single, x03 As Single, _ 'y03 As Single, gamma As Single, U As Single, alpha As Single) 'Dim result1 As Single 'Dim result2 As Single 'Dim result3 As Single 'Dim result4 As Single ' Call each function and store their results 'result1 = FDOUB(X, Y, x01, y01, KAPPA) 'result2 = Fpsands(X, Y, x02, y02, hat) 'result3 = fvortex(X, Y, x03, y03, gamma) 'result4 = UniformFlowStreamFunction(X, Y, U, alpha) ' Add the results together 'SumOfResults = result1 + result2 + result3 + result4 'End Function End Function Sub CalculateAndPlaceResult() 'Variables for FDOUB Dim X as Single Dim Y as Single Dim x01 As Single Dim y01 As Single Dim KAPPA As Single 'Variables for Fpsands Dim x02 As Single Dim y02 As Single Dim hat As Single 'Variables for fvortex Dim x03 As Single Dim y03 As Single Dim gamma As Single 'Variables for UniformFlowStreamFunction Dim U As Single Dim alpha As Single 'Assign Values to each variable X = Range("D13:D38").Value Y = Range("E12:O12").Value 'FDOUB x01 = Range("J7").Value y01 = Range("J8").Value KAPPA = Range("J6").Value 'Fpsands x02 = Range("F7").Value y02 = Range("F8").Value hat = Range("F6").Value 'fvortex x03 = Range("L7").Value y03 = Range("L8").Value gamma = Range("L6").Value 'UniformFlowStreamFunction U = Range("D6").Value alpha = Range("D7").Value For I = X To 1 Step -1 For J = Y To 1 Step -1 Cells(J+12,I+4).value = SumOfResults(I, J, x01, y01, KAPPA, x02, y02, hat, x03, y03, gamma, U, alpha) End Sub
Editor is loading...
Leave a Comment