1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
| Imports System.Runtime.InteropServices
Public Class Form1
Dim abaqus_exec As String = ""
Dim path As String = ""
Dim DriveMap As String = "z:"
Dim objNet, objFSO As Object
Dim data_path As String = "\\sv0117\data\abaqus"
Dim i As Integer = 0
Dim job_folder As String
Dim proc As New System.Diagnostics.Process()
Dim loginform As New LoginForm1()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
label_user.Text = "USER : " & System.Environment.UserDomainName & "\" & System.Environment.UserName
Label_os.Text = "OS : " & System.Environment.OSVersion.VersionString
label_computer.Text = "COMPUTER : " & System.Environment.MachineName.ToString
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_input.Click
TextBox1.Text = ""
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName = "" Then
Exit Sub
End If
If Not (New System.IO.FileInfo(OpenFileDialog1.FileName).Extension) = ".inp" Then
Output("reset")
Output("Only .inp files are supported as input file")
TextBox1.Text = ""
Exit Sub
End If
TextBox1.Text = OpenFileDialog1.FileName
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_submit.Click
If check_user_input() = False Then
Exit Sub
Else
Output("reset")
define_abaqus()
UAC()
map()
create_job_folder()
move_file_to_server()
submit_job()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_cancel.Click
End
End Sub
Sub Output(ByVal output_string)
If output_string = "reset" Then
output_console.Text = ""
Exit Sub
End If
output_console.Text = output_console.Text & "# " & output_string & vbCrLf
End Sub
Function check_user_input()
If (FileIO.FileSystem.FileExists(TextBox1.Text) And ComboBox_version.Items.Contains(ComboBox_version.Text) And ComboBox_cores.Items.Contains(ComboBox_cores.Text)) Then
Return True
Exit Function
Else
Output("reset")
If Not FileIO.FileSystem.FileExists(TextBox1.Text) Then
If TextBox1.Text = "" Then
Output("You must specify an input file")
Else
Output("File does not exist : " & TextBox1.Text)
End If
End If
If Not ComboBox_version.Items.Contains(ComboBox_version.Text) Then
If ComboBox_version.Text = "" Then
Output("You must specify an ABAQUS version")
Else : Output("Specified version not suported : " & ComboBox_version.Text)
End If
End If
If Not ComboBox_cores.Items.Contains(ComboBox_cores.Text) Then
If ComboBox_cores.Text = "" Then
Output("You must specify a number of core")
Else
Output("Specified cores number not supported : " & ComboBox_cores.Text)
End If
End If
End If
Return False
End Function
Sub define_abaqus()
'==================================================================================================
'Defining the abaqus exec depending on version.
'==================================================================================================
Select Case System.Environment.OSVersion.Version.Build.ToString
Case "3790"
Output("x64 OS detected, will use x64 ABAQUS version")
abaqus_exec = "\" & ComboBox_version.Text & "\exec\abq" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1)) & ".exe"
path = "\\sv0117\Abaqus"
Case "2600"
Output("x32 OS detected, will use x32 ABAQUS version")
abaqus_exec = "\" & ComboBox_version.Text & "\exec\abq" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1)) & ".exe"
path = "\\sv0117\Abaqus_x32"
Case Else
Output("Unknow OS bit code (" & System.Environment.OSVersion.Version.Build.ToString & "), will assume 32 bit version")
abaqus_exec = "\" & ComboBox_version.Text & "\exec\abq" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1)) & ".exe"
path = "\\sv0117\Abaqus_x32"
End Select
End Sub
Sub UAC()
'==================================================================================================
'user access control
'==================================================================================================
If Not IO.File.Exists(path & abaqus_exec) Then
Output("server access failed ...")
Output("The most common reason is because you're not allowed to use the compute cluster.")
Output("Contact XXXXXX to request access to the compute cluster.")
Exit Sub
Else
Output("Abaqus " & ComboBox_version.Text & " detected and operationnal")
End If
End Sub
Sub map()
'==================================================================================================
'Mapping drive z: for ABAQUS
'==================================================================================================
objFSO = CreateObject("Scripting.FileSystemObject")
objNet = CreateObject("Wscript.Network")
If IO.File.Exists(DriveMap & "\" & abaqus_exec) Then
Output("mapping on " & DriveMap & "already correct")
ElseIf objFSO.DriveExists(DriveMap) Then
Output(DriveMap & " map not mounted for ABAQUS use, will unmap and remap. If operation fails, remove " & DriveMap & " map manually.")
objNet.RemoveNetworkDrive(DriveMap, True, True)
objNet.MapNetworkDrive(DriveMap, path, True)
Else
Output("mapping z:")
objNet.MapNetworkDrive(DriveMap, path, True)
End If
'==================================================================================================
'Mapping drive y: for data transfert
'==================================================================================================
If IO.Directory.Exists(data_path & "\" & Environment.UserName) Then
Output("found ... user directory on headnode")
If objFSO.DriveExists("y:") Then objNet.RemoveNetworkDrive("y:", True, True)
Output("mapping y:")
objNet.MapNetworkDrive("y:", data_path & "\" & Environment.UserName, True)
Else
Output("user directory on headnode not found, will create")
IO.Directory.CreateDirectory(data_path & "\" & Environment.UserName)
If objFSO.DriveExists("y:") Then objNet.RemoveNetworkDrive("y:", True, True)
Output("mapping y:")
objNet.MapNetworkDrive("y:", data_path & "\" & Environment.UserName, True)
End If
End Sub
Sub create_job_folder()
'==================================================================================================
'creating job folder
'==================================================================================================
If IO.Directory.Exists("y:\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name) & "_" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1))) Then
Do Until Not (IO.Directory.Exists("y:\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name) & "_" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1)) & "_" & i))
i = i + 1
Loop
IO.Directory.CreateDirectory("y:\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name) & "_" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1)) & "_" & i)
job_folder = "y:\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name) & "_" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1)) & "_" & i
Output("creating job folder " & job_folder)
Else
IO.Directory.CreateDirectory("y:\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name) & "_" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1)))
job_folder = "y:\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name) & "_" & (Mid(ComboBox_version.Text, 1, 1)) & (Mid(ComboBox_version.Text, 3, 1)) & (Mid(ComboBox_version.Text, 5, 1))
Output("creating job folder " & job_folder)
End If
i = 0
End Sub
Sub move_file_to_server()
'==================================================================================================
'moving file to server
'==================================================================================================
Output("moving " & TextBox1.Text)
Output("to " & job_folder & "\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name))
IO.File.Copy(TextBox1.Text, job_folder & "\" & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name))
End Sub
Sub submit_job()
'==================================================================================================
'submiting job
'==================================================================================================
Output("================================STARTING ABAQUS================================")
proc.StartInfo.UseShellExecute = False
proc.StartInfo.RedirectStandardOutput = True
proc.StartInfo.WorkingDirectory = job_folder
proc.StartInfo.FileName = path & abaqus_exec
proc.StartInfo.Arguments = " -j " & (New System.IO.FileInfo(OpenFileDialog1.FileName).Name) & " -cpus " & ComboBox_cores.Text
proc.Start()
Dim out_lines As String = ""
While Not proc.StandardOutput.EndOfStream
out_lines = proc.StandardOutput.ReadLine.ToString
Output(out_lines)
If Not IsNothing(out_lines) Then
If Not InStr(out_lines, "Enter the password for") = 0 Then
LoginForm1.ShowDialog()
sendkey(LoginForm1.PasswordTextBox.Text)
sendkey("{Enter}")
sendkey("y")
sendkey("{Enter}")
End If
End If
End While
proc.WaitForExit()
proc.Close()
TextBox1.Text = ""
End Sub
Sub sendkey(ByVal my_key)
proc.WaitForInputIdle(2000)
System.Windows.Forms.SendKeys.SendWait("""" & my_key & """")
End Sub
End Class |
Partager