ديناميک سيالات محاسباتی

نمونه ای از پروژه های انجام شده برای درس دینامیک سیالات محاسباتی برای مهندسان


Create Matrix :

Dim A(100, 100) As Double

Dim B(100, 100) As Double

Dim C(100, 100) As Double

Dim m As Integer

Dim N As Integer

Dim l As Integer

Private Sub Command1_Click()

m = Text1.Text

N = Text2.Text

l = Text3.Text

'first matrix

MSFlexGrid1.Rows = m + 1

MSFlexGrid1.Cols = N + 1

MSFlexGrid1.Col = 1

MSFlexGrid1.Row = 1

MSFlexGrid1.Col = 0

MSFlexGrid1.Row = 0

For i = 1 To m

 MSFlexGrid1.Col = 0

 MSFlexGrid1.Row = i

 MSFlexGrid1.Text = i

 For j = 1 To N

 MSFlexGrid1.Row = 0

 MSFlexGrid1.Col = j

 MSFlexGrid1.Text = j

 MSFlexGrid1.Row = i

 MSFlexGrid1.Col = j

 MSFlexGrid1.Text = Int(Rnd() * 10)

 'MSFlexGrid1.Text = InputBox("A(" + Str(i) + "," + Str(j) + ")", "First Matrix", 4)

 A(i, j) = Val(MSFlexGrid1.Text)

 Next j

Next i

MSFlexGrid2.Rows = N + 1

MSFlexGrid2.Cols = l + 1

MSFlexGrid2.Col = 0

MSFlexGrid2.Row = 0

For i = 1 To N

 MSFlexGrid2.Col = 0

 MSFlexGrid2.Row = i

 MSFlexGrid2.Text = i

 For j = 1 To l

 MSFlexGrid2.Row = 0

 MSFlexGrid2.Col = j

 MSFlexGrid2.Text = j

 MSFlexGrid2.Row = i

 MSFlexGrid2.Col = j

 MSFlexGrid2.Text = Int(Rnd() * 10)

 'MSFlexGrid2.Text = InputBox("B(" + Str(i) + "," + Str(j) + ")", "Second Matrix", 2)

 B(i, j) = Val(MSFlexGrid2.Text)

 Next j

Next i

MSFlexGrid3.Rows = m + 1

MSFlexGrid3.Cols = l + 1

MSFlexGrid3.Col = 0

MSFlexGrid3.Row = 0

For i = 1 To m

 MSFlexGrid3.Col = 0

 MSFlexGrid3.Row = i

 MSFlexGrid3.Text = i

 For j = 1 To l

 For k = 1 To N

 MSFlexGrid3.Row = 0

 MSFlexGrid3.Col = j

 MSFlexGrid3.Text = j

 MSFlexGrid3.Row = i

 MSFlexGrid3.Col = j

 C(i, j) = A(i, k) * B(k, j) + C(i, j)

  MSFlexGrid3.Text = Str(C(i, j))

 Next k

 Next j

 Next i

End Sub

Private Sub Command2_Click()

Unload Me

start.Show

End Sub

Private Sub Form_Load()

Trans start.hwnd, 100

End Sub





Newton


Dim x As Double

Dim Y As Double

Dim Epsilon As Double

Dim df_dx As Double

Dim N As Integer

Private Sub Command1_Click()

fx = fx_text.Text

x = startpoint_text.Text

Epsilon = residual_text.Text

N = 0

Temp = Replace(fx, "x", x)

fx0 = ScriptControl1.Eval(Temp)

Do Until (Abs(fx0 - fy) < Epsilon)

 Y = x

 Temp = Replace(fx, "x", Y)

 fy = ScriptControl1.Eval(Temp)

 

 Temp = Replace(fx, "x", x + 0.001)

 fdx = ScriptControl1.Eval(Temp)

 df_dx = (fdx - fx0) / 0.001

 

 x = x - fx0 / df_dx

 Temp = Replace(fx, "x", x)

 fx0 = ScriptControl1.Eval(Temp)

 

 N = N + 1

Loop

answer_text.Text = x

n_text.Text = N

End Sub

Private Sub Command2_Click()

Unload Me

start.Show

End Sub

Private Sub Form_Load()

Trans start.hwnd, 100

End Sub





Expilicit


Dim Lenght, INI_time, CFL, Alpha, Temp0, Temp(1000), Temp2(1000), Delta_x, Delta_Time, INT_Temp As Double

Dim N, Imax As Integer

Dim exportfile, ch

Private Sub Command1_Click()

CFL = txt_cfl.Text

 If txt_cfl.Text = Empty Then

 ms = MsgBox("You Should Enter A Value For CFL(CFL<0.5)", vbOKOnly, "Expilicit")

 Exit Sub

 End If

 If CFL > 0.5 Then

 C = MsgBox("You Should Enter A CFL Under 0.5(CFL<0.5)", vbOKOnly, "Expilicit")

 txt_cfl.Text = Empty

 Exit Sub

 End If

 answer.Text = Empty

 Lenght = Txt_Lenght.Text

 INI_time = txt_INI_Time.Text

directory", , "CFD_3")

 Alpha = txt_Alpha.Text

 Imax = txt_Imax.Text

 Delta_x = Lenght / (Imax - 1)

 Temp(1) = txt_INI_temp.Text

 Delta_Time = (CFL * (Delta_x) ^ 2) / Alpha

 N = INI_time / Delta_Time

 Temp2(1) = txt_Temp

 Temp(1) = txt_Temp

 exportfile = "answer_Expilicit.dat"

 Open exportfile For Output As 1

 Print #1, "X Position" + Space(15) + "Temperature"

 For k = 2 To Imax

 Temp(k) = txt_INI_temp

 Next k

 For i = 1 To N

 For j = 2 To Imax - 1

 Temp2(j) = Temp(j) + CFL * (Temp(j + 1) - 2 * Temp(j) +  Temp(j - 1))

/ 0 نظر / 12 بازدید