PYTHON SCRIPTS FOR ABAQUS LEARN BY EXAMPLE
Gautam Puri
This document is the Table of Contents for the book. A preview version of the book is available as a separate download from the book website. Book website: www.abaquspython.com
Contents 1.
A Taste of Scripting 1.1 1.2 1.3 1.4 1.5
2.
Running a Script 2.1 2.2 2.3
2.4
2.5 2.6
3.
Introduction Using a script to define materials To script or not to script.. Running a complete analysis through a script Conclusion
Introduction How Python fits in Running a script within Abaqus/CAE 2.3.1 Running a script in GUI to execute a single or multiple tasks 2.3.2 Running a script in GUI to execute an entire simulation Running a script from the command line 2.4.1 Run the script from the command line without the GUI 2.4.2 Run the script from the command line with the GUI Running a script from the command line interface (CLI) Conclusion
Python 101 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8
Introduction Statements Variables and assignment statements Lists Dictionaries Tuples Classes, Objects and Instances What’s next?
1 1 1 8 8 32 33 33 33 34 35 35 35 37 38 39 40 41 41 41 41 44 46 49 51 59
ii Contents
4.
The Basics of Scripting – Cantilever Beam Example 4.1 4.2 4.3
4.4
5.
Python 102 5.1
5.2
6.
Introduction A basic script Breaking down the script 4.3.1 Initialization (import required modules) 4.3.2 Create the model 4.3.3 Create the part 4.3.4 Define the materials 4.3.5 Create solid sections and make section assignments 4.3.6 Create an assembly 4.3.7 Create steps 4.3.8 Create and define field output requests 4.3.9 Create and define history output requests 4.3.10 Apply loads 4.3.11 Apply constraints/boundary conditions 4.3.12 Mesh 4.3.13 Create and run the job 4.3.14 Post processing What’s Next?
Introduction 5.1.1 If… elif … else statements 5.1.2 For loops 5.1.3 range() function 5.1.4 While-loops 5.1.5 break and continue statements What’s Next?
Replay files, Macros and IDEs 6.1 6.2 6.3 6.4
Introduction Replay Files Example - Compare replay with a well written script Macros
60 60 60 64 65 67 68 71 72 74 75 76 77 78 81 83 88 89 90 92 92 92 94 95 97 97 99 100 100 100 101 106
Contents iii 6.5
6.6
7.
Static Analysis of a Loaded Truss 7.1 7.2 7.3 7.4
7.5
8.
IDEs and Text Editors 6.5.1 IDLE 6.5.2 Notepad ++ 6.5.3 Abaqus PDE 6.5.4 Other options What’s Next?
Introduction Procedure in GUI Python Script Examining the Script 7.4.1 Initialization (import required modules) 7.4.2 Create the model 7.4.3 Create the part 7.4.4 Define the materials 7.4.5 Create sections and make section assignments 7.4.6 Create an assembly 7.4.7 Create steps 7.4.8 Create and define field output requests 7.4.9 Create and define history output requests 7.4.10 Apply loads 7.4.11 Apply boundary conditions 7.4.12 Mesh 7.4.13 Create and run the job 7.4.14 Post processing – setting the viewport 7.4.15 Plot the deformed state and modify common options 7.4.16 Plot the field outputs Summary
Explicit Analysis of a Dynamically Loaded Truss 8.1 8.2 8.3
Introduction Procedure in GUI Python Script
109 109 109 110 113 114 117 117 118 124 129 129 130 130 131 132 134 135 135 135 136 137 139 141 141 142 143 145 146 146 147 154
iv Contents
8.4
9.
8.3.1 Part, material, section and assembly blocks 8.3.2 Creating sets 8.3.3 Creating steps 8.3.4 Create and define history output requests 8.3.5 Apply loads 8.3.6 Boundary conditions, mesh, running the job and initial post processing 8.3.7 XY plots of displacement Summary
Analysis of a Frame of I-Beams 9.1 9.2 9.3 9.4
9.5
Introduction Procedure in GUI Python Script Examining the Script 9.4.1 Initialization (import required modules) 9.4.2 Create the model 9.4.3 Create the part 9.4.4 Define the materials 9.4.5 Create profiles 9.4.6 Create sections and make section assignments 9.4.7 Assign section orientations 9.4.8 Create an assembly 9.4.9 Create connectors using wire features 9.4.10 Use constraint equations for two nodes 9.4.11 Create steps 9.4.12 Create and define field output requests 9.4.13 Create and define history output requests 9.4.14 Apply loads 9.4.15 Apply boundary conditions 9.4.16 Mesh 9.4.17 Create and run the job Summary
160 161 162 163 164 164 165 170 171 171 174 188 199 199 199 199 206 206 207 210 210 211 216 218 218 218 218 220 222 222 223
Contents v
10.
Bending of a Planar Shell (Plate) 10.1 10.2 10.3 10.4
10.5
11.
Introduction Procedure in GUI Python Script Examining the Script 10.4.1 Initialization (import required modules) 10.4.2 Create the model 10.4.3 Create the part 10.4.4 Define the materials 10.4.5 Create solid sections and make section assignments 10.4.6 Create an assembly 10.4.7 Create steps 10.4.8 Create and define field output requests 10.4.9 Create and define history output requests 10.4.10 Apply boundary conditions 10.4.11 Partition part to create vertices 10.4.12 Apply loads 10.4.13 Mesh 10.4.14 Create and run the job 10.4.15 Display deformed state with contours 10.4.16 Write Field Output Report Summary
Heat Transfer Analysis 11.1 11.2 11.3 11.4
224 224 226 233 239 239 239 239 240 240 242 242 243 243 244 245 248 248 250 250 251 252 253
Introduction 253 Procedure in GUI 255 Python Script 261 Examining the Script 266 11.4.1 Initialization, creation of the model, part, materials, sections and assembly 266 11.4.2 Create a datum plane and partition the part 266 11.4.3 Create steps 268 11.4.4 Apply constraints/boundary conditions 268 11.4.5 Apply loads 269
vi Contents
11.5
12.
Contact Analysis (Contact Pairs Method) 12.1 12.2 12.3 12.4
12.5 12.6
13.
11.4.6 Create interactions 11.4.7 Mesh 11.4.8 Create and run the job 11.4.9 Post Processing Summary
Introduction Procedure in GUI Python Script Examining the Script 12.4.1 Initialization (import required modules) 12.4.2 Create the model 12.4.3 Create the part 12.4.4 Define the materials 12.4.5 Create solid sections and make section assignments 12.4.6 Create an assembly 12.4.7 Create steps 12.4.8 Create and define field output requests 12.4.9 Create and define history output requests 12.4.10 Apply boundary conditions 12.4.11 Apply loads 12.4.12 Create Surfaces 12.4.13 Create Interaction Properties 12.4.14 Create Interactions 12.4.15 Mesh 12.4.16 Create and run the job 12.4.17 Post Processing - Display deformed state Summary What’s Next?
Optimization – Determine the Maximum Plate Bending Loads 13.1 13.2
Introduction Methodology
270 273 275 275 278 279 279 281 291 300 300 300 301 302 303 304 309 310 310 310 312 312 313 314 316 317 318 318 318 319 319 319
Contents vii 13.3 13.4
13.5
14.
Python Script 321 Examining the Script 329 13.4.1 Model, Part, Material, Section, Assembly, Step, Field Output Request, Boundary Condition, Partition and Mesh creation. 329 13.4.2 Initialization 329 13.4.3 Modify and run the analysis at each iteration 330 13.4.4 Print a table of the results 338 13.4.5 Read the report file to determine where the maximum stress was exceeded 341 13.4.6 Light up elements in the viewport where max stress is exceeded 345 13.4.7 Print messages to the message area 347 Summary 348
Parameterization, Prompt Boxes and XY Plots 14.1 14.2 14.3 14.4
14.5
Introduction Methodology Python Script Examining the Script 14.4.1 Accept inputs 14.4.2 Create the model 14.4.3 Create part 14.4.4 Create a section 14.4.5 Create sets 14.4.6 Request and use load magnitude 14.4.7 Boundary conditions 14.4.8 Initial post processing 14.4.9 Combined XY plot 14.4.10 Chart Options 14.4.11 Axis Options 14.4.12 Title Options 14.4.13 Chart Legend Options 14.4.14 XY Curve Options 14.4.15 Print the plot to an image Summary
349 349 350 351 363 363 366 366 367 368 368 369 370 371 371 373 375 376 377 378 379
viii Contents
15.
Optimization of a Parameterized Sandwich Structure 15.1 15.2 15.3 15.4
15.5
16.
Introduction Procedure in GUI Python Script Examining the Script 15.4.1 Accept inputs 15.4.2 Variable initialization and preliminary calculations 15.4.3 Create the model 15.4.4 Create the parts, material, section and assembly 15.4.5 Identify faces and sets 15.4.6 Assemble parts 15.4.7 Create steps, boundary conditions and loads 15.4.8 Surfaces and Tie constraints 15.4.9 Mesh and Run Job 15.4.10 XY Reports 15.4.11 Read from report 15.4.12 Write to output file Summary
Explore an Output Database 16.1 16.2 16.3 16.4 16.5
380 380 382 392 405 405 407 408 408 409 410 411 412 413 413 415 416 417 418
Introduction 418 Methodology 419 Before we begin – Odb Object Model 420 How to run the script 423 Python Script 423 16.5.1 Initialization 429 16.5.2 Mathematical operations on field data 429 16.5.3 Access information about part, nodes, elements, stresses, displacements 433 16.5.4 Display history output information for static truss analysis 441 16.5.5 Display history output information for dynamic explicit truss analysis 444 16.5.6 Extract material and section definitions 447 16.5.7 Extract material and section definitions 449
Contents ix 16.6 16.7 16.8
17.
Combine Frames of two Output Databases and Create an Animation 17.1 17.2 17.3 17.4 17.5 17.6 17.7 17.8
17.9
18.
Introduction Methodology Procedure in GUI How to run the script Python Script to simulate plastic plate bending Python Script to simulate elastic springback Python Script to combine the output databases Examining the Script 17.8.1 Class Definition. 17.8.2 Read data from output databases 17.8.3 Create a new output database 17.8.4 Create the animation using the new output database Summary
Monitor an Analysis Job and Send an Email when Complete 18.1 18.2 18.3 18.4
18.5
19.
Object Model Interrogation More object model interrogation techniques Summary
Introduction Methodology Python Script Examining the Script 18.4.1 Job submission and message callback 18.4.2 Define the callback function 18.4.3 Define a function to handle post processing 18.4.4 Define the email function Summary
A Really Simple GUI (RSG) for the Sandwich Structure Study 19.1 19.2
Introduction Methodology
450 454 457 459 459 460 460 467 467 475 486 492 492 493 500 507 509 510 510 510 511 516 517 519 520 520 524 527 527 527
x Contents 19.3 19.4 19.5 19.6
19.7
20.
Create a Custom GUI Application Template 20.1 20.2 20.3 20.4 20.5 20.6
20.7
21.
Getting Started with RSG Create an RSG for Sandwich Structure Analysis Python Script to respond to the GUI dialog inputs Examining the Script 19.6.1 Function definition 19.6.2 Material variable assignments 19.6.3 Create the materials 19.6.4 Create the sections 19.6.5 To write (or not write) XY report and print displacement Summary
Introduction What is the Abaqus GUI Toolkit Components of a GUI Application GUI and Kernel Processes Methodology Python Script 20.6.1 Application Startup Script 20.6.2 Main Window 20.6.3 Modified Canvas Toolset (modified ‘Viewport’ menu) 20.6.4 Custom Persistant toolset 20.6.5 Adding some functionality with a ‘main’ program 20.6.6 Custom Module 20.6.7 Form Mode 20.6.8 Modal Dialog box 20.6.9 Modeless Dialog box Summary
Custom GUI Application for Beam Frame Analysis 21.1 21.2 21.3 21.4
Introduction Layout Managers and Widgets Transitions and Process Updates Exploring the scripts
528 535 552 566 566 566 567 568 569 569 570 570 571 571 573 575 576 576 579 587 593 602 607 615 619 623 625 626 626 630 631 631
Contents xi
21.5
22.
21.4.1 Beam Application Kernel Script 21.4.2 Beam Application Startup Script 21.4.3 Beam Application Main Window 21.4.4 Custom Persistant toolset 21.4.5 Custom Beam Module 21.4.6 Step 1 Dialog Form and Dialog Box 21.4.7 Step 2 Dialog Form and Dialog Box 21.4.8 Step 3 Procedure and Dialog Box 21.4.9 Step 4 Form and Dialog Box Summary
Plug-ins 22.1 22.2 22.3
22.4
631 655 656 657 666 671 688 701 709 716 717
Introduction Methodology Learn by Example 22.3.1 Kernel Plug-in Example 22.3.2 GUI Plug-in Example Summary
717 717 718 718 720 724