?? 平板熱傳導.frm
字號:
VERSION 5.00
Begin VB.Form Formpanel
Caption = "平板熱傳導"
ClientHeight = 8070
ClientLeft = 60
ClientTop = 345
ClientWidth = 10755
LinkTopic = "Form1"
ScaleHeight = 8070
ScaleWidth = 10755
StartUpPosition = 3 '窗口缺省
Begin VB.PictureBox Picture1
Height = 5295
Left = 120
ScaleHeight = 5235
ScaleWidth = 7155
TabIndex = 15
Top = 480
Width = 7215
End
Begin VB.Frame Frame1
Caption = "參數選擇"
Height = 2895
Left = 7920
TabIndex = 0
Top = 240
Width = 2535
Begin VB.ComboBox Combta
Height = 300
ItemData = "平板熱傳導.frx":0000
Left = 1080
List = "平板熱傳導.frx":0016
TabIndex = 18
Top = 2280
Width = 1095
End
Begin VB.ComboBox Combody
Height = 300
ItemData = "平板熱傳導.frx":0043
Left = 1080
List = "平板熱傳導.frx":0053
TabIndex = 13
Top = 1320
Width = 1095
End
Begin VB.ComboBox Combodt
Height = 300
ItemData = "平板熱傳導.frx":0071
Left = 1080
List = "平板熱傳導.frx":0081
TabIndex = 4
Top = 360
Width = 1095
End
Begin VB.ComboBox Combodx
Height = 300
ItemData = "平板熱傳導.frx":009F
Left = 1080
List = "平板熱傳導.frx":00AF
TabIndex = 3
Top = 840
Width = 1095
End
Begin VB.ComboBox Combotime
Height = 300
ItemData = "平板熱傳導.frx":00CD
Left = 1080
List = "平板熱傳導.frx":00EC
TabIndex = 2
Top = 1800
Width = 1095
End
Begin VB.Label Label6
AutoSize = -1 'True
Caption = "熱傳導系數"
Height = 180
Left = 0
TabIndex = 17
Top = 2400
Width = 900
End
Begin VB.Label Label5
Alignment = 2 'Center
AutoSize = -1 'True
Caption = "Y軸步長"
Height = 180
Left = 240
TabIndex = 14
Top = 1320
Width = 645
End
Begin VB.Label Label2
Alignment = 2 'Center
AutoSize = -1 'True
Caption = "時間步長"
Height = 180
Left = 120
TabIndex = 7
Top = 360
Width = 855
End
Begin VB.Label Label3
Alignment = 2 'Center
AutoSize = -1 'True
Caption = "x軸步長"
Height = 180
Left = 240
TabIndex = 6
Top = 840
Width = 645
End
Begin VB.Label Label4
Alignment = 2 'Center
AutoSize = -1 'True
Caption = "時間"
Height = 180
Left = 480
TabIndex = 5
Top = 1800
Width = 375
End
End
Begin VB.Frame Frame2
Height = 2895
Left = 7920
TabIndex = 1
Top = 3000
Width = 2535
Begin VB.CommandButton Command1
Caption = "清屏"
Height = 495
Left = 240
TabIndex = 16
Top = 1200
Width = 1815
End
Begin VB.CommandButton cmdend
Caption = "結束"
Height = 495
Left = 240
TabIndex = 9
Top = 2040
Width = 1815
End
Begin VB.CommandButton cmdok
Caption = "(ADI)計算數值解并繪圖"
Height = 495
Left = 240
TabIndex = 8
Top = 360
Width = 1815
End
End
Begin VB.Frame Frame3
Height = 1455
Left = 4920
TabIndex = 10
Top = 6000
Width = 5655
Begin VB.TextBox TxtResult
Height = 375
Left = 1920
TabIndex = 11
Top = 600
Width = 3615
End
Begin VB.Label Label1
Alignment = 2 'Center
AutoSize = -1 'True
Caption = "結果已保存至"
Height = 180
Left = 540
TabIndex = 12
Top = 720
Width = 1095
End
End
End
Attribute VB_Name = "Formpanel"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Sub TRIDAG(A(), B(), C(), R(), U(), N) '追趕法子程序,求解矩陣
ReDim GAM(N) '根據傳值過來的數組的大小來確定GAM的大小
If B(1) = 0# Then Exit Sub
BET = B(1)
U(1) = R(1) / BET
For j = 2 To N
GAM(j) = C(j - 1) / BET
BET = B(j) - A(j) * GAM(j)
If BET = 0# Then Exit Sub
U(j) = (R(j) - A(j) * U(j - 1)) / BET
Next j
For j = N - 1 To 1 Step -1
U(j) = U(j) - GAM(j + 1) * U(j + 1)
Next j
End Sub
Private Sub cmdend_Click()
Formpanel.Hide
Form2.Show
End Sub
Private Sub spotplot(zz(), xw, yw, dx, dy)
Dim sx1, sx2, sy1, sy2 As Integer
Dim sx, sy As Double
Dim x, y, cx, cy As Single
Dim xx, yy, s As Single
Dim i, j, nx, ny As Integer
Dim sxx, syy As Single
Const pi = 3.14159
Picture1.Scale (0, 0)-(640, 480)
s = pi / 16
nx = Fix(xw / dx)
ny = Fix(yw / dy)
sx1 = 140: sx2 = 600
sy1 = 360: sy2 = 100
cx = (sx2 - sx1) / xw / 2
cy = (sy1 - sy2) / yw / 2
sxx = sx1 + 1 * cy * Cos(s)
syy = sy1 - 1 * cy * Sin(s)
Picture1.Line (sx1, sy1)-(sx2, sy1)
Picture1.CurrentX = sx2: Picture1.CurrentY = sy1 + 0.5: Picture1.Print "X"
Picture1.CurrentX = sx1 + 1 * cx: Picture1.CurrentY = sy1 + 0.5: Picture1.Print 1
Picture1.Line (sx1 + 1 * cx, sy1)-(sx1 + 1 * cx, sy1 - 8)
Picture1.Line (sx1, sy1)-(sxx, syy)
Picture1.CurrentX = sxx: Picture1.CurrentY = syy: Picture1.Print 1
Picture1.CurrentX = sxx - 50: Picture1.CurrentY = syy - 20: Picture1.Print "Y"
Picture1.Line (sx1, sy1)-(sx1, sy1 - 150)
Picture1.CurrentX = sx1 - 50: Picture1.CurrentY = sy1 - 100: Picture1.Print 100
Picture1.CurrentX = sx1: Picture1.CurrentY = sy1 - 150: Picture1.Print "T"
Picture1.Line (sx1, sy1 - 100)-(sx1 + 8, sy1 - 100)
colorcode = 15 * Rnd
For j = 0 To ny
For i = 0 To nx
x = i * dx
xx = x * cx + sx1
y = j * dy
yy = sy1 - y * cy * Sin(s)
sx = xx + y * cy * Cos(s)
sy = yy - zz(i, j)
'sy = sy
Picture1.PSet (sx, sy), QBColor(colorcode)
Next i
Next j
End Sub
'計算數值解主程序
Private Sub cmdok_Click()
'Const alpha = 0.0147214
Dim total_x, total_y, total_t, dx, dy, dt
'total_x是矩形邊界x方向的長
'total_y是矩形邊界y方向得長
'total_t是時間
'dx,dy和dt分別是x軸方向的步長、y軸方向得步長和時間步長
'alpha是熱擴散系數
Dim boundary, alpha As Single '定義邊界值變量
Dim i As Integer, j, k As Integer, nx As Integer, ny As Integer, nt As Integer
Dim A(), B(), C(), R(), U()
Dim point(), m As Double
Dim judge As Integer
'定義矩形邊界的長和寬
total_y = 1
total_x = 1
total_t = Val(Combotime.List(Combotime.ListIndex))
alpha = Val(Combta.Text)
'確定各方的步長
dx = Val(Combodx.List(Combodx.ListIndex))
dy = Val(Combody.List(Combody.ListIndex))
dt = Val(Combodt.List(Combodt.ListIndex))
If Combodx.ListIndex = -1 Or Combodt.ListIndex = -1 Or Combotime.ListIndex = -1 Or Combody.ListIndex = -1 Then
i = MsgBox("未輸入參數", vbExclamation Or vbOKCancel Or vbDefaultButton1, _
"參數輸入") '若用戶未填入參數提示用戶
Exit Sub
End If
'計算各方向的步長的點數
nx = CInt(total_x / dx)
ny = CInt(total_y / dy)
nt = CInt(total_t / dt)
'給邊界變量賦值
boundary = 100
'根據點數定義數組大小
ReDim point(nx, ny)
'給point數組賦初始時刻的值
For i = 0 To nx
For j = 0 To ny
point(i, j) = 0
Next j
Next i
m = 0.5 * dt * alpha
' If m / dx ^ 2 > 0.5 Or m / dy ^ 2 > 0.5 Then
'i = MsgBox("不收斂", vbExclamation Or vbOKCancel Or vbDefaultButton1, _
'"重新輸入")
'Exit Sub
'End If
'創建文件保存數據
Open App.Path + "\計算結果.txt" For Output As #1
judge = 0
For k = 0 To nt - 1
If judge = 0 Then
'以下為對x是隱格式,y是顯格式,計算前半時刻的溫度值
For j = 1 To ny - 1
'重新定義追趕矩陣的大小
ReDim A(1 To nx - 1), B(1 To nx - 1), C(1 To nx - 1), R(1 To nx - 1), U(1 To nx - 1)
'給矩陣賦值
R(1) = point(1, j) + (m / (dx ^ 2)) * boundary + (m / (dy ^ 2)) * (point(1, j + 1) - 2 * point(1, j) + point(1, j - 1))
R(nx - 1) = point(nx - 1, j) + (m / (dx ^ 2)) * boundary + (m / (dy ^ 2)) * (point(nx - 1, j + 1) - 2 * point(nx - 1, j) + point(nx - 1, j - 1))
For i = 2 To nx - 2
R(i) = point(i, j) + (m / dy ^ 2) * (point(i, j + 1) - 2 * point(i, j) + point(i, j - 1))
Next i
For i = 2 To nx - 1
A(i) = -m / (dx ^ 2)
Next i
For i = 1 To nx - 1
B(i) = 1 + (2 * m) / (dx ^ 2)
Next i
For i = 1 To nx - 2
C(i) = -m / (dx ^ 2)
Next i
Call TRIDAG(A(), B(), C(), R(), U(), (nx - 1))
'將計算的結果賦給point數組
For i = 1 To nx - 1
point(i, j) = U(i)
Next i
Next j
If k = 0 Then
For i = 0 To nx
point(i, 0) = 100: point(i, ny) = 100
Next i
For j = 0 To ny
point(0, j) = 100: point(nx, j) = 100
Next j
End If
'以下是對y是隱格式,對x是顯格式,計算后半時刻的溫度值
For i = 1 To nx - 1
ReDim A(1 To ny - 1), B(1 To ny - 1), C(1 To ny - 1), R(1 To ny - 1), U(1 To ny - 1)
'給矩陣向量賦值
R(1) = point(i, 1) + (m / (dy ^ 2)) * boundary + (m / (dx ^ 2)) * (point(i + 1, 1) - 2 * point(i, 1) + point(i - 1, 1))
R(ny - 1) = point(i, ny - 1) + (m / (dy ^ 2)) * boundary + (m / (dx ^ 2)) * (point(i + 1, ny - 1) - 2 * point(i, ny - 1) + point(i - 1, ny - 1))
For j = 2 To ny - 2
R(j) = point(i, j) + (m / (dx ^ 2)) * (point(i + 1, j) - 2 * point(i, j) + point(i - 1, j))
Next j
For j = 2 To ny - 1
A(j) = -(m / (dy ^ 2))
Next j
For j = 1 To ny - 1
B(j) = 1 + 2 * (m / (dy ^ 2))
Next j
For j = 1 To ny - 2
C(j) = -(m / (dy ^ 2))
Next j
Call TRIDAG(A(), B(), C(), R(), U(), (ny - 1))
'將計算的結果賦給point數組
For j = 1 To ny - 1
point(i, j) = U(j)
Next j
Next i
judge = 1
Else '交換計算次序
'以下是對y是隱格式,對x是顯格式,計算前半時刻的溫度值
For i = 1 To nx - 1
ReDim A(1 To ny - 1), B(1 To ny - 1), C(1 To ny - 1), R(1 To ny - 1), U(1 To ny - 1)
'給矩陣的向量賦值
R(1) = point(i, 1) + (m / (dy ^ 2)) * boundary + (m / (dx ^ 2)) * (point(i + 1, 1) - 2 * point(i, 1) + point(i - 1, 1))
R(ny - 1) = point(i, ny - 1) + (m / (dy ^ 2)) * boundary + (m / (dx ^ 2)) * (point(i + 1, ny - 1) - 2 * point(i, ny - 1) + point(i - 1, ny - 1))
For j = 2 To ny - 2
R(j) = point(i, j) + (m / (dx ^ 2)) * (point(i + 1, j) - 2 * point(i, j) + point(i - 1, j))
Next j
For j = 2 To ny - 1
A(j) = -(m / (dy ^ 2))
Next j
For j = 1 To ny - 1
B(j) = 1 + 2 * (m / (dy ^ 2))
Next j
For j = 1 To ny - 2
C(j) = -(m / (dy ^ 2))
Next j
Call TRIDAG(A(), B(), C(), R(), U(), (ny - 1))
'將計算的結果賦給point數組
For j = 1 To ny - 1
point(i, j) = U(j)
Next j
Next i
'以下為對x是隱格式,y是顯格式,計算后半時刻的溫度值
For j = 1 To ny - 1
'重新定義追趕矩陣的大小
ReDim A(1 To nx - 1), B(1 To nx - 1), C(1 To nx - 1), R(1 To nx - 1), U(1 To nx - 1)
'給追趕矩陣的右端向量R賦值
R(1) = point(1, j) + (m / (dx ^ 2)) * boundary + (m / (dy ^ 2)) * (point(1, j + 1) - 2 * point(1, j) + point(1, j - 1))
R(nx - 1) = point(nx - 1, j) + (m / (dx ^ 2)) * boundary + (m / (dy ^ 2)) * (point(nx - 1, j + 1) - 2 * point(nx - 1, j) + point(nx - 1, j - 1))
For i = 2 To nx - 2
R(i) = point(i, j) + (m / dy ^ 2) * (point(i, j + 1) - 2 * point(i, j) + point(i, j - 1))
Next i
For i = 2 To nx - 1
A(i) = -m / (dx ^ 2)
Next i
For i = 1 To nx - 1
B(i) = 1 + (2 * m) / (dx ^ 2)
Next i
For i = 1 To nx - 2
C(i) = -m / (dx ^ 2)
Next i
Call TRIDAG(A(), B(), C(), R(), U(), (nx - 1))
'將計算的結果賦給point數組
For i = 1 To nx - 1
point(i, j) = U(i)
Next i
Next j
judge = 0
End If
Next k
Call spotplot(point(), total_x, total_y, dx, dy)
For i = 1 To nx - 1
For j = 0 To ny
Print #1, Format$(point(i, j), "##0.#0"); " "; '將結果保存至文件中
Next j
Print #1, " "
Next i
Close #1 '關閉文件
TxtResult.Text = App.Path + "\計算結果.txt" '顯示文件保存路徑
End Sub
Private Sub Command1_Click()
Picture1.Cls
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -