Untitled
unknown
plain_text
10 months ago
4.0 kB
3
Indexable
Never
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 Integer, Y As Integer, 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 ' Sum up the results SumOfResults = FDOUB(X(i, 1), Y(i, 1), x01, y01, KAPPA) + Fpsands(X(i, 1), Y(i, 1), x02, y02, hat) + fvortex(X(i, 1), Y(i, 1), x03, y03, gamma) + UniformFlowStreamFunction(X(i, 1), Y(i, 1), U, alpha) End Function Sub CalculateAndPlaceResult() 'Variables for FDOUB Dim X as Integer Dim Y as Integer 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 Y = Range("D13:D38").Count 'Rows X = Range("E12:O12").Count 'Col '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 = 0 To X For J = 0 To Y Cells(J+13,I+5).Value = SumOfResults(Cells(12,15 - I).Value,Cells(13+J, 4).Value, x01, y01, KAPPA, x02, y02, hat, x03, y03, gamma, U, alpha) Next J Next I End Sub
Leave a Comment