With reference to an article on the IAACBlog (now removed), I replied to the author request: “I was forced to use the workbench environment because i was unable to achieve the same contact results with Ansys classical version, ultimately ending the potential to have a fully automated program. I am still working on this, If anyone can help me out to provide a source of documentation for Ansys workbench that would be greatly appreciated” some months ago, but my comment is not published yet (why?). For this reason, today I reply directly on my blog.
First of all, we have to transform a NURBS surface in a MESH object in this way:
‘The number of elements in U and V direction
elemsNumU = 10
elemsNumV = 10
nodesNumU = elemsNumU + 1
nodesNumV = elemsNumV + 1
ReDim Nodes(nodesNumU * nodesNumV – 1)
Dim domU, domV, stepSizeU, stepSizeV
Rhino.AddLayer “Mesh”,RGB(255, 0, 0), 0
Rhino.CurrentLayer(“Mesh”)
‘Get the domain of the surface
domU = Rhino.SurfaceDomain(surface(i), 0)
domV = Rhino.SurfaceDomain(surface(i), 1)
‘If Not IsArray(domU) Or Not IsArray(domV) Then Exit Sub
stepSizeU = (domU(1) – domU(0)) / elemsNumU
stepSizeV = (domV(1) – domV(0)) / elemsNumV
For j = 0 To elemsNumV
‘Set the y coordinate
coord(1) = domV(0) + stepSizeV * j
For k = 0 To elemsNumU
‘Set the x coordinate
coord(0) = domU(0) + stepSizeU * k
‘Generates the z coordinate and stores the points in the A array
nodes(nodesNumU*j+k) = Rhino.EvaluateSurface(surface(i), coord)
Next
Next
ReDim topology(elemsNumU * elemsNumV – 1)
For j=0 To elemsNumV-1
For k=0 To elemsNumU-1
topology(elemsNumU*j+k) = Array((elemsNumU+1)*(j+0)+(k+0), (elemsNumU+1)*(j+0)+(k+1), (elemsNumU+1)*(j+1)+(k+1), (elemsNumU+1)*(j+1)+(k+0))
Next
Next
Rhino.AddMesh nodes, topology
Secondly, we have to translate our Rhino-MESH into a valid input file for Ansys:
‘The input file for the FEM analysis
Dim fsObject, fp, node
outPath = “c:RhinoTempInputAnsys.txt”
Set fsObject = CreateObject(“Scripting.FileSystemObject”)
Set fp = fsObject.CreateTextFile(outPath, True)
fp.Writeline “/PREP7”
fp.Writeline “!* …Static analysis”
fp.Writeline “ANTYPE,STATIC”
fp.Writeline “ET,1,SHELL63,,1”
fp.Writeline “R,1,0.3 !* …Shell thickness”
fp.Writeline “MP,EX,1,3E+7” ‘Units: m and KN
fp.Writeline “MP,NUXY,1,0.15”
fp.Writeline “!* …”
fp.Writeline “TYPE,1”
fp.Writeline “MAT,1”
fp.Writeline “REAL,1”
‘Mesh nodes
fp.Writeline “!*”
fp.Writeline “!* …Nodes”
For j = 0 To nodesNumV – 1
For k = 0 To nodesNumU – 1
node = nodes(nodesNumU*j+k)
fp.Writeline “N,” & nodesNumU*j+k+1 & “,” & node(0) & “,” & node(1) & “,” & node(2)
Next
Next
‘Shell elements (only geometry)
fp.Writeline “!*”
fp.Writeline “!* …Shell elements”
For j=0 To elemsNumV-1
For k=1 To elemsNumU
‘Ansys Shell 63 elements
nodes(nodesNumU*j+k) = Array((nodesNumU)*(j+0)+(k+0), (nodesNumU)*(j+0)+(k+1), (nodesNumU)*(j+1)+(k+1), (nodesNumU)*(j+1)+(k+0))
fp.Writeline “E,” & nodes(nodesNumU*j+k)(0) & “,” & nodes(nodesNumU*j+k)(1) & “,” & nodes(nodesNumU*j+k)(2) & “,” & nodes(nodesNumU*j+k)(3)
Next
Next
fp.Writeline “!* …”
fp.Writeline “FINISH”
fp.Writeline “/SOLU”
fp.Writeline “!* …Constrains”
‘Single Node constrain
fp.Writeline “D,” & CStr(1) & “,UX” ‘— 1 is the number of the node to constrain
fp.Writeline “D,” & CStr(1) & “,UY”
fp.Writeline “D,” & CStr(1) & “,UZ”
‘External constrains
For m = 0 To elemsNumU
fp.Writeline “D,” & CStr(m+1) & “,UX”
fp.Writeline “D,” & CStr(m+1) & “,UY”
fp.Writeline “D,” & CStr(m+1) & “,UZ”
Next
For m = 0 To nodesNumV-2
fp.Writeline “D,” & CStr(m*nodesNumU)+1 & “,UX”
fp.Writeline “D,” & CStr(m*nodesNumU)+1 & “,UY”
fp.Writeline “D,” & CStr(m*nodesNumU)+1 & “,UZ”
Next
fp.Writeline “!* …Forces”
‘Nodal forces
For k=0 To (nodesNumU * nodesNumV -1)
fp.Writeline “F, ” & (k+1) & “, FZ, 1”
Next
‘Gravity ACEL and MPDATA, DENS
fp.Writeline “MPTEMP,,,,,,,,”
fp.Writeline “MPTEMP,1,0 “
fp.Writeline “MPDATA,DENS,1,,25”
fp.Writeline “ACEL,0,0,-1,”
fp.Writeline “SOLVE”
fp.Writeline “!* …Postprocessor”
fp.Writeline “/POST1”
‘fp.Writeline “PRNSOL, U, X”
‘fp.Writeline “PRNSOL, U, Y”
fp.Writeline “PRNSOL, U, Z” ‘Z direction displacements
fp.Writeline “FINISH”
fp.close
Finally, we have to launch the analysis and to read the results (e.g. the maximum displacement). It is better to separate this operation in a private function to recall:
Dim applicPath, applic, maxDisplacement
Dim fileExe, fileInput, fileOutput
fileExe = “C:ProgrammiAnsys Incv100ANSYSbinintelansys100.exe” ‘Programs for ENG WIN versions
fileInput = “c:RhinoTempInputAnsys.txt”
fileOutput = “c:RhinoTempOutputAnsys.txt”
applicPath = fileExe & ” -b -i ” & fileInput & ” -o ” & fileOutput
Set applic = CreateObject(“WScript.Shell”)
applic.exec(applicPath)
Dim datiOut, out, rigaDati, risultDati, fileOutput, fileCompleto, counter
out = False
counter = 1
Set datiOut = CreateObject(“Scripting.FileSystemObject”)
‘— File exists?
Do Until out = True
out = datiOut.FileExists(fileOutput)
Rhino.sleep 1000
Counter = counter + 1
Loop
Rhino.Print “Now the output file exists”
Rhino.sleep 1000
Set out = datiOut.OpenTextFile(fileOutput, 1)
risultDati = 0
‘— Max displ value exists?
contatore = 1
fileCompleto = 0
Do Until fileCompleto = 1
While Not Out.AtEndOfStream
rigaDati = Out.readLine
If rigaDati = ” | ANSYS RUN COMPLETED |” Then
Rhino.Print “Analysis complete!”
fileCompleto = 1
End If
Wend
Rhino.sleep 1000
counter = counter + 1
If contatore = 600 Then
risultDati = 100
Rhino.Print “Error”
Exit Do
End If
Loop
‘— Read Max displacement
Set out = datiOut.OpenTextFile(fileOutput, 1)
Do While Not out.AtEndOfStream
rigaDati = out.readLine
If Left(RigaDati, 12) = ” *** ERROR *” Then
risultDati = 100
Exit Do
ElseIf Left(RigaDati, 12) = ” MAXIMUM ABS” Then
out.SkipLine ‘1
rigaDati = out.readLine
risultDati = Mid(rigaDati, 9, 12)
Exit Do
End If
Loop
‘RESULT
maxDisplacement = risultDati
Out.Close
‘Delete the output file
‘Out = DatiOut.DeleteFile(fileOutput, True)
That’s an automatic procedure to evaluate the structural performance of a Rhino MESH object with the ANSYS FEM solver.
Reference: Pugnale A., Sassone M., Morphogenesis and Structural Optimization of Shell Structures with the Aid of a Genetic Algorithm, in “Journal of the International Association for Shell and Spatial Structures”, Vol. 48, n. 155, Dicembre 2007.