Rhinoceros and Ansys
- 6 November 2008
- By Alberto Pugnale
- In Blogs, Engineering, Parametric Design, Research, Scripting/Tooling, Teaching and learning
- 6 Comments
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.
6 Comments
Leave a Reply Cancel Reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Categories
- Alberto Pugnale (9)
- Architects, Engineers, Artists (9)
- Blogs (1)
- Books (3)
- Digital Fabrication (2)
- Engineering (23)
- Evolutionary techniques (17)
- Form-finding (17)
- History of construction (4)
- Mathematics, Geometry and Topology (3)
- News (7)
- Parametric Design (27)
- Publications/Conferences (12)
- Reciprocity (4)
- Research (21)
- Researchers, Academics (4)
- Scripting/Tooling (23)
- Teaching and learning (19)
Hello,
First of all, thank you so much for posting this process. It has been extremely useful. I was trying to use the script that you’ve posted here and i am trying to find a way to visualise the data in the outputansys.txt file in rhino/ansys but cant seem to access the results. Please advice
First of all, you have to verify that the results exist. I have posted a script that creates a mesh with quadrilateral elements. They suffer warping effects and the FEM analysis could fail sometimes, if the surface has an accentuated curvature or if the mesh grid is too large. You could try to modify the test surface or the mesh elements in U and V direction. Otherwise, you can triangulate the mesh adding a diagonal line (and creating triangular shell63 elements).
I believe you have set correctly the FEM analysis before running the script, with constrains, etc…
Regards,
Alberto
Its funny i was looking for other ansys information and i found this. I am the author of that post on the iaac blog. Im not sure exacly what you are trying to do based on the posts i am seeing here but if you have any questions email me at thorsoej@gmail.com. In the end i used the workbench environment and exported the excel data then used a rhinoscript to optimize my forms based on the excel data and large multidimentional arrays.
Erik
In this way you have an automatic procedure that is able to generate FEM models for structural analysis in Ansys and to read the results in Rhino. It was written to work inside a genetic algorithm but it could be used in any iterative process. With reference to your code, this is a suggestion to avoid any user interference with the procedure.
I have not understood the second part of your work, with a second code to structurally optimize your shapes.
Regards,
Alberto
Thank you very much for your response. In this way do you get an output of a text file with all of the stresses or displacement for the nodes? Do you run the fortran code as a ansys batch? Did u do this in a project of your own? If so i would like to see the results. I can send you a copy of my final boards to show you what i ment by “structurally optimize my shapes”.
Thanks
Erik
In the posted code you can find the correct syntax to run Ansys in Batch mode. (C:ProgramsAnsys Incv100ANSYSbinintelansys100.exe –B –I c:RhinoTempInputAnsys.txt –O c:RhinoTempOutputAnsys.txt). In this way, I can use the Ansys FEM solver automatically. I need also a Subroutine to generate the input file (a code to translate a geometry into a text file) and a Function to read the output file (in my case with z-displacements and to convert it in a performance value) if I want to insert this procedure inside an evolutionary (or simply iterative) algorithm. That’s what I have done in my first year of my PhD course with my tutor Prof. Mario Sassone. All the results and the application to a crematorium designed by Toyo Ito are published in the Journal cited above in this post. We can send each other our results by e-mail.
Alberto