VERSION 5.00 Begin VB.Form Form1 BorderStyle = 1 'Fixed Single Caption = "Hall Effect Simulation" ClientHeight = 6630 ClientLeft = 45 ClientTop = 330 ClientWidth = 10395 LinkTopic = "Form1" MaxButton = 0 'False ScaleHeight = 6630 ScaleWidth = 10395 StartUpPosition = 3 'Windows Default Begin VB.HScrollBar HScroll2 Height = 255 LargeChange = 100 Left = 8040 Max = 20000 TabIndex = 19 Top = 6240 Value = 10000 Width = 2055 End Begin VB.HScrollBar HScroll1 Height = 255 LargeChange = 100 Left = 8040 Max = 30000 TabIndex = 18 Top = 5520 Value = 10000 Width = 2055 End Begin VB.CommandButton Command1 Caption = "Reset" Height = 255 Left = 4560 TabIndex = 14 Top = 5400 Width = 855 End Begin VB.CheckBox Check3 Caption = "Pause Simulation" Height = 255 Left = 5760 TabIndex = 13 Top = 5880 Value = 1 'Checked Width = 1935 End Begin VB.CheckBox Check2 Caption = "Show B field" Height = 255 Left = 5760 TabIndex = 12 Top = 5520 Width = 1455 End Begin VB.PictureBox Pic1 Appearance = 0 'Flat BackColor = &H80000005& ForeColor = &H80000008& Height = 4530 Left = 120 ScaleHeight = 4500 ScaleWidth = 4500 TabIndex = 9 Top = 120 Width = 4530 End Begin VB.ComboBox DeltaTime Height = 315 Left = 2520 Style = 2 'Dropdown List TabIndex = 7 Top = 6120 Width = 1575 End Begin VB.ComboBox DeltaSpace Height = 315 Left = 2520 Style = 2 'Dropdown List TabIndex = 5 Top = 5760 Width = 1815 End Begin VB.CheckBox Check1 Caption = "Grid Lines" Height = 255 Left = 5760 TabIndex = 4 Top = 5160 Value = 1 'Checked Width = 1455 End Begin VB.ComboBox WaveType Height = 315 Left = 1680 Style = 2 'Dropdown List TabIndex = 3 Top = 5400 Visible = 0 'False Width = 2775 End Begin VB.PictureBox Pic2 Appearance = 0 'Flat BackColor = &H80000005& ForeColor = &H80000008& Height = 4530 Left = 4800 ScaleHeight = 4500 ScaleWidth = 4500 TabIndex = 0 Top = 120 Width = 4530 End Begin VB.Timer Timer1 Interval = 100 Left = 8880 Top = 4800 End Begin VB.Label Label10 Caption = "Applied Magnetic Field" Height = 255 Left = 8040 TabIndex = 21 Top = 6000 Width = 2175 End Begin VB.Label Label9 Caption = "Applied Voltage" Height = 255 Left = 8040 TabIndex = 20 Top = 5280 Width = 2175 End Begin VB.Label Label8 Alignment = 2 'Center BackColor = &H000000FF& Caption = "Neg. charge" ForeColor = &H00FFFFFF& Height = 255 Left = 3360 TabIndex = 17 Top = 4920 Width = 1095 End Begin VB.Label Label7 Alignment = 2 'Center BackColor = &H00FF0000& Caption = "Pos. charge" ForeColor = &H00FFFFFF& Height = 255 Left = 3360 TabIndex = 16 Top = 4680 Width = 1095 End Begin VB.Label Label6 Caption = "Initial Configuration" Height = 255 Left = 120 TabIndex = 15 Top = 5400 Visible = 0 'False Width = 1455 End Begin VB.Label Label5 Caption = "DT" Height = 255 Left = 2040 TabIndex = 11 Top = 6120 Width = 375 End Begin VB.Label Label4 Caption = "DS" Height = 255 Left = 2040 TabIndex = 10 Top = 5760 Width = 375 End Begin VB.Label Label3 Caption = "1800 nm" Height = 255 Left = 9600 TabIndex = 8 Top = 2160 Width = 735 End Begin VB.Line Line1 X1 = 9480 X2 = 9480 Y1 = 120 Y2 = 4680 End Begin VB.Label TimeLabel Caption = "Iteration:" Height = 255 Left = 5760 TabIndex = 6 Top = 6240 Width = 2175 End Begin VB.Label Label2 Caption = "Current Magnitude" Height = 255 Left = 5280 TabIndex = 2 Top = 4800 Width = 3015 End Begin VB.Label Label1 Caption = "E-Field is along the X-axis" BeginProperty Font Name = "Microsoft Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 360 TabIndex = 1 Top = 4800 Width = 2655 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False '*** Hall Effect Simulation - Dan Piehl *** ' 'This program is designed to simulate the Hall Effect 'using a 3-dimensional array for the electric and magnetic components 'of each cell in the simulation space. ' Option Explicit Option Base 1 Option Compare Text Const Max = 50 'Largest array subscript value Dim LimitX As Integer 'Upper bound on X subscript Dim LimitY As Integer 'Upper bound on Y subscript Dim LimitZ As Integer 'Upper bound on Z subscript Dim Center As Integer 'Center of simulation space Const PI = 3.14159265358979 'Approximate Pi value Dim TimeCounter As Long 'Iteration counter Dim TimeClock As Double 'Elapsed time accumulator Dim Refraction As Boolean 'Refraction indicator Dim JX(0 To Max, 0 To Max, 0 To Max) As Double 'E vector field Dim Charge(0 To Max, 0 To Max, 0 To Max) As Double Dim JY(0 To Max, 0 To Max, 0 To Max) As Double Dim BX(0 To Max, 0 To Max, 0 To Max) As Double 'B vector field Dim BY(0 To Max, 0 To Max, 0 To Max) As Double Dim BZ(0 To Max, 0 To Max, 0 To Max) As Double Dim DeltaCharge(0 To Max, 0 To Max, 0 To Max) As Double '*** Initialize the Simulation *** ' Private Sub InitializeSimulation(Structure As Integer) Dim X As Integer 'Index along X-axis Dim Y As Integer 'Index along Y-axis Dim Z As Integer 'Index along Z-axis '--- Reset time and field arrays --- TimeCounter = 0 'Reset time to zero TimeClock = 0 For X = 0 To LimitX 'Loop through every cell For Y = 0 To LimitY For Z = 0 To LimitZ Charge(X, Y, Z) = 0 JX(X, Y, Z) = 0 JY(X, Y, Z) = 0 BZ(X, Y, Z) = 0 Next Next Next End Sub '*** Plot the Lattice on the VB Form *** ' Private Sub ShowLattice() Dim V As Double Dim X As Integer Dim Y As Integer Dim SX As Single Dim SY As Single Dim PX As Single Dim PY As Single Dim C As Long Dim GridLines As Boolean Dim ShowBField As Boolean SX = Pic1.ScaleWidth / (LimitX + 1) 'Compute X & Y scale factor SY = Pic1.ScaleWidth / (LimitY + 1) GridLines = (Check1.Value = 1) 'Get gridline setting ShowBField = (Check2.Value = 1) 'Get B-field setting For X = 0 To LimitX For Y = 0 To LimitY PX = X * SX 'Determine X,Y screen location PY = (LimitY - Y) * SY '--- Draw E-field cells --- V = 240 * Charge(X, Y, LimitZ \ 2) / 8000 If V < 0 Then If V < -255 Then V = -255 C = RGB(-V, 0, 0) 'Show negative E in red Else If V > 255 Then V = 255 C = RGB(0, 0, V) 'Show positive E in blue End If Pic1.Line (PX, PY)-(PX + SX, PY + SY), C, BF If GridLines Then Pic1.Line (PX, PY)-(PX + SX, PY + SY), RGB(64, 64, 64), B ElseIf Abs(Y - 0.4 * LimitY) < 0.5 Then Pic1.Line (PX, PY + SY)-(PX + SX, PY + SY), RGB(64, 64, 64), B End If If ShowBField Then 'V = BZ(X, Y, LimitZ \ 2) V = HScroll2.Value - 10000 If V > 2000 Then 'Show positive B-field V = 256 * V / 10000 If V > 255 Then V = 255 Pic1.Line (PX + SX \ 2, PY + SY \ 2)-(PX + SX \ 2 + 15, PY + SY \ 2 + 15), RGB(0, V, 0), BF ElseIf V < -2000 Then 'Show negative B-field V = 256 * -V / 10000 Pic1.Line (PX + SX \ 2 - 30, PY + SY \ 2 - 30)-(PX + SX \ 2 + 45, PY + SY \ 2 + 45), RGB(0, V, 0) Pic1.Line (PX + SX \ 2 + 30, PY + SY \ 2 - 30)-(PX + SX \ 2 - 45, PY + SY \ 2 + 45), RGB(0, V, 0) End If End If '--- Draw S cells --- V = JX(X, Y, LimitZ \ 2) * JX(X, Y, LimitZ \ 2) _ + JY(X, Y, LimitZ \ 2) * JY(X, Y, LimitZ \ 2) V = 255 * V / (50000) If V < 0 Then V = 0 If V > 255 Then V = 255 C = RGB(V, V, V) Pic2.Line (PX, PY)-(PX + SX, PY + SY), C, BF If GridLines Then Pic2.Line (PX, PY)-(PX + SX, PY + SY), RGB(64, 64, 64), B End If Next Next End Sub '*** Handle transition from one state to the next *** Private Sub Transition() Dim X As Integer 'X,Y,Z subscript counter Dim Y As Integer Dim Z As Integer Dim X1 As Integer 'X,Y,Z neighbor subscripts Dim X2 As Integer Dim Y1 As Integer Dim Y2 As Integer Dim Z1 As Integer Dim Z2 As Integer Dim D As Double 'Change in numerical value Dim TC As Double 'Time-based constant (related to delta-t) Dim K As Double 'Conductivity constant Dim V As Double Dim B As Double On Error Resume Next 'Skip errors when floating-point limit is reached '--- Perform time-based calculations for each iteration --- D = DeltaTime.ListIndex + 1 TC = (1 + LimitX) / (2 * D * 100) TimeCounter = TimeCounter + 1 TimeClock = TimeClock + 60 / D TimeLabel = "Iteration: " & TimeCounter & " (" & TimeClock & " as)" '--- Apply a Voltage --- For Y = 0 To LimitY For Z = 0 To LimitZ V = V + Charge(0, Y, Z) V = V - Charge(LimitX, Y, Z) Next Next V = 0.5 * (HScroll1.Value - V / (LimitY + 1) / (LimitZ + 1)) B = HScroll2.Value - 10000 K = 1 / 6 'Conductivity constant '--- Determine current --- For X = 0 To LimitX X1 = X - 1: If X1 < 0 Then X1 = LimitX X2 = X + 1: If X2 > LimitX Then X2 = 0 For Y = 0 To LimitY Y1 = Y - 1: If Y1 < 0 Then Y1 = LimitY Y2 = Y + 1: If Y2 > LimitY Then Y2 = 0 For Z = 0 To LimitZ Z1 = Z - 1: If Z1 < 0 Then Z1 = LimitZ Z2 = Z + 1: If Z2 > LimitZ Then Z2 = 0 JX(X, Y, Z) = K * (Charge(X2, Y, Z) - Charge(X1, Y, Z)) JY(X, Y, Z) = K * (Charge(X, Y2, Z) - Charge(X, Y1, Z)) If Y = 0 Or Y = LimitY Then ' JX(X, Y, Z) = 0 JY(X, Y, Z) = 0 End If Next Next Next '--- Determine changes needed based on neighboring cells --- For X = 0 To LimitX X1 = X - 1: If X1 < 0 Then X1 = LimitX X2 = X + 1: If X2 > LimitX Then X2 = 0 For Y = 0 To LimitY Y1 = Y - 1: If Y1 < 0 Then Y1 = LimitY Y2 = Y + 1: If Y2 > LimitY Then Y2 = 0 For Z = 0 To LimitZ Z1 = Z - 1: If Z1 < 0 Then Z1 = LimitZ Z2 = Z + 1: If Z2 > LimitZ Then Z2 = 0 D = (Charge(X1, Y, Z) + Charge(X2, Y, Z) _ + Charge(X, Y1, Z) + Charge(X, Y2, Z) _ + Charge(X, Y, Z1) + Charge(X, Y, Z2) _ - 6 * Charge(X, Y, Z)) * K ' D = D + B * (JX(X, Y2, Z) - JX(X, Y1, Z)) _ ' + B * (JY(X2, Y, Z) - JY(X1, Y, Z)) If X = 0 Then D = D + V If X = LimitX Then D = D - V DeltaCharge(X, Y, Z) = D Next Next Next '--- Apply magnetic component For X = 0 To LimitX X1 = X - 1: If X1 < 0 Then X1 = LimitX X2 = X + 1: If X2 > LimitX Then X2 = 0 For Y = 0 To LimitY - 1 Y1 = Y - 1: If Y1 < 0 Then Y1 = LimitY Y2 = Y + 1: If Y2 > LimitY Then Y2 = 0 For Z = 0 To LimitZ Z1 = Z - 1: If Z1 < 0 Then Z1 = LimitZ Z2 = Z + 1: If Z2 > LimitZ Then Z2 = 0 D = B / 10000 * (JX(X, Y, Z) + JX(X, Y2, Z)) / 2 DeltaCharge(X, Y, Z) = DeltaCharge(X, Y, Z) - D DeltaCharge(X, Y2, Z) = DeltaCharge(X, Y2, Z) + D D = B / 10000 * (JY(X, Y, Z) + JY(X2, Y, Z)) / 2 DeltaCharge(X, Y, Z) = DeltaCharge(X, Y, Z) + D DeltaCharge(X2, Y, Z) = DeltaCharge(X2, Y, Z) - D Next Next Next '--- Apply changes to E & B vectors --- For X = 0 To LimitX For Y = 0 To LimitY For Z = 0 To LimitZ Charge(X, Y, Z) = (Charge(X, Y, Z) + DeltaCharge(X, Y, Z)) Next Next Next End Sub '*** Event Procedure to Reset Simulation *** ' Private Sub Command1_Click() WaveType_Click End Sub '*** List item selection *** ' Private Sub WaveType_Click() Dim I As Integer I = WaveType.ListIndex 'Determine simulation structure If I < 0 Then Exit Sub 'If none selected, don't continue InitializeSimulation I 'Initialize the simulation End Sub '*** Change to spatial granularity *** ' Private Sub DeltaSpace_Click() Dim I As Integer I = 10 * (DeltaSpace.ListIndex + 1) 'Determine matrix size (10,20,30,40,50) LimitX = I - 1 'Set limits on X,Y,Z subscripts LimitY = I - 1 LimitZ = 0 Center = I \ 2 'Calculate simulation center WaveType_Click 'Reset the simulation End Sub '*** Start-up Procedure *** ' Private Sub Form_Load() '--- Fill the drop-down lists with appropriate values --- With DeltaSpace .AddItem "180 nm (10 X 10)" .AddItem "90 nm (20 X 20)" .AddItem "60 nm (30 X 30)" .AddItem "45 nm (40 X 40)" .AddItem "36 nm (50 X 50)" End With With DeltaTime .AddItem "60 as" .AddItem "30 as" .AddItem "20 as" .AddItem "15 as" .AddItem "12 as" .AddItem "10 as" End With '--- Set the initial drop-down list values --- DeltaTime.ListIndex = 5 DeltaSpace.ListIndex = 1 'WaveType.ListIndex = 0 End Sub '*** Run Timed Events *** ' Private Sub Timer1_Timer() If Check3.Value = 0 Then 'If simulation is not paused... Transition 'perform transition to next point in time End If ShowLattice 'Refresh the display End Sub