ansys® customization and automation with apdl
TRANSCRIPT
ANSYS® Customization and Automation with APDL
Presented ByComputer Aided Engineering
Associates, Inc.
Copyright © 2002 Computer Aided Engineering Associates, Inc. All rights reserved. Use, reproduction, distribution, etc. without the express written consent of Computer Aided Engineering Associates, Inc. is prohibited.
Presentation Topics
Introduction— What is APDL?— What can you do with APDL?— Features of APDL— Advantages and Disadvantages of APDL
APDL B iAPDL BasicsParametric ModelingImporting/Exporting data in/out of ANSYSC t i d d t lbCustomized menus and toolbarsStoring macrosEncrypting macrosM lMacro exampleConsulting examples:
— Pin insertion macroStent automation macro
Computer Aided Engineering Associates, Inc. 2Computer Aided Engineering Associates, Inc. 2Copyright© 2002Computer Aided Engineering Associates, Inc.
— Stent automation macro
Introduction: What is APDL?
APDL = ANSYS Parametric Design Language— APDL is a scripting language used to automate and customize tasks in ANSYSp g g g— APDL combines ANSYS commands with FORTRAN-like functions— APDL is used to do many of the operations done by user-subroutines in other
FE codes
What can you do with APDL?— Create parametric models to quickly evaluate design changes— Create macros to automate complex or often-repeated tasks— Import and export data to external files— Perform scalar, vector, and matrix operations— Create simple customized menus and toolbar items
Features of APDL— Macros, if-then-else branching, do-loops, and scalar, vector, and matrix
operations.Macros are APDL routines
Computer Aided Engineering Associates, Inc. 3Computer Aided Engineering Associates, Inc. 3Copyright© 2002Computer Aided Engineering Associates, Inc.
— Macros are APDL routines— Virtually all ANSYS commands can be used in APDL
Introduction: APDL Examples
Automation— Create geometry with a new set of dimensions (Parametric Modeling)g y ( g)— Calculate the volume of all selected elements— Convert structural temperatures to heat transfer temperatures— Write all of the max. and min. stress/strain components for the selected p
element set to a file— Calculate the maximum difference in stress over a range of load steps— Move the selected nodes and elements by offset values— Import shell elements, nodes, and thickness values from an external file— Create component sets from node or element lists in an external file
Customization— Create simple input and output menus (*ASK, *MSG, Multipro)— Create customized toolbar items to perform common tasks
Computer Aided Engineering Associates, Inc. 4Computer Aided Engineering Associates, Inc. 4Copyright© 2002Computer Aided Engineering Associates, Inc.
— Create customized toolbar items to perform common tasks
Introduction: Advantages of APDL
Price: No extra cost: Included with all ANSYS products
Rapid Learning Curve:Rapid Learning Curve:— Rapid learning curve, primarily devoted to learning ANSYS commands.— Can use the jobname.log file to get the ANSYS command equivalent to your
menu picksmenu picks.— Interpreted (not compiled) so effects of modifications are immediately
realizable.
G d D t tiGood Documentation:— APDL Programmer’s Guide— ANSYS Commands Reference
CAEA S i “ANSYS C i i d P i (APDL)”— CAEA Seminar: “ANSYS Customization and Programming (APDL)”
Other:— Specially compiled version of ANSYS is not required
Computer Aided Engineering Associates, Inc. 5Computer Aided Engineering Associates, Inc. 5Copyright© 2002Computer Aided Engineering Associates, Inc.
p y p q
Introduction: Disadvantages of APDL
Limited Customization: — Only simple input and message menus can be generatedOnly simple input and message menus can be generated.
Speed: — Can be slow for complex operations on large models. User subroutines are
generally much fastergenerally much faster.
Computer Aided Engineering Associates, Inc. 6Computer Aided Engineering Associates, Inc. 6Copyright© 2002Computer Aided Engineering Associates, Inc.
Introduction: APDL Basics
Scalar Parameters — Defining scalar parameters:— Defining scalar parameters:
• parameter = value— (example 1: A1 = 12.98)— (example 2: B1 = ‘Turbine Blade Analysis’)
• OR *SET,parameter,value— (example: *SET,A1,12.98)
— Listing scalar parameters:*STAT d• *STAT command
— (example: *STAT,A1)
— Deleting scalar parameters:• parameter =• parameter =• OR *SET,parameter
Computer Aided Engineering Associates, Inc. 7Computer Aided Engineering Associates, Inc. 7Copyright© 2002Computer Aided Engineering Associates, Inc.
Introduction: APDL Basics
Scalar Parameters cont… — Forced parameter substitution:p
• Enclose the parameter name in % signs for substitution in character expressions
E l R lti l i t fil d l th i dExample: Run multiple input files and solve them in order
job=‘fname’
*DO,I,1,5
/input %job%%I% inp ! input = ‘fname1 inp’ ‘fname2 inp’ /input,%job%%I%,inp ! input = fname1.inp , fname2.inp , …
/solu
solve
finishfinish
*ENDDO
Computer Aided Engineering Associates, Inc. 8Computer Aided Engineering Associates, Inc. 8Copyright© 2002Computer Aided Engineering Associates, Inc.
Introduction: APDL Basics
Array Parameters — Defining array parameters:— Defining array parameters:
• *DIM command— (example 1: *DIM,A1,array,10,2,1)— (example 2: *DIM,B1,character,6,2)
• OR Parameters > Array Parameters > Define/Edit
— Listing array parameters:• *STAT command
— (example: *STAT,A1)
— Deleting array parameters:• parameter =• OR *SET,parameter
Computer Aided Engineering Associates, Inc. 9Computer Aided Engineering Associates, Inc. 9Copyright© 2002Computer Aided Engineering Associates, Inc.
Introduction: APDL Basics
Scalar Functions — Many standard programming functions are available:— Many standard programming functions are available:
• A = 4*2, B = 16/4, C = A – B, D = A+B, E = A**B
• SIN(x), COS(x), TAN(x), ASIN(x), ACOS(x), ATAN(x), ATAN2(y,x)
• SINH(x) COSH(x) TANH(x)• SINH(x), COSH(x), TANH(x)
• SQRT(x), ABS(x), SIGN(x,y)
• NINT(x), MOD(x,y)
• EXP(x), LOG(x), LOG10(x)
• RAND(x,y), GDIS(x,y)
• LWCASE(cparm), UPCASE(cparm), VALCHR(cparm)
• CHRVAL(parm) (where cparm is a character parameter)
Help on *SET will list all of the functionsHelp on SET will list all of the functions
— These functions can be inserted into any numeric field of a command• Example: Apply a sinusoidal force to node i
Computer Aided Engineering Associates, Inc. 10Computer Aided Engineering Associates, Inc. 10Copyright© 2002Computer Aided Engineering Associates, Inc.
pi = acos(-1)
F, i, FY, fmax*SIN(2*pi*time/tmax)
Introduction: APDL Basics
Array Functions — Many Array and Matrix operations are available:— Many Array and Matrix operations are available:
Examples
• *VFUN – performs a function on one array parameter
• copy to another array, square root of each entry, etc.copy to another array, square root of each entry, etc.
• *VOPER – operates on two array parameters
• add, multiply, divide, etc. entries in two arrays
• *VSCFUN – determine the properties of an array parameter
• max., mean, standard deviation, etc. of all entries
• *MOPER – performs matrix operations on two arrays
• matrix multiplication, sorting, etc.
— Array values can be inserted into any field of a command• Example: Define keypoint #4 with an x coordinate equal to the value in
i i 2 5 f h XVAL
Computer Aided Engineering Associates, Inc. 11Computer Aided Engineering Associates, Inc. 11Copyright© 2002Computer Aided Engineering Associates, Inc.
position 2,5 of the array XVALK,4,XVAL(2,5),0.,0.
Introduction: APDL Basics
*IF statements — Same functionality as IF statements in FORTRAN— *IF, *ENDIF,*ELSEIF, and *ELSE commands can be used to perform logical branching
operations— Syntax: *IF, VAL1, Oper1, VAL2, AND / OR, VAL3, Oper2, VAL4, THEN
Computer Aided Engineering Associates, Inc. 12Computer Aided Engineering Associates, Inc. 12Copyright© 2002Computer Aided Engineering Associates, Inc.
Introduction: APDL Basics
*DO loops — Same functionality as *DO loops in FORTRANy p— *DO, parameter, ival, fval, inc
Sample Format:
*DO, i, 1, 7, 2
*DO, j, 1, 20
n, (i-1)*20 +j, 0.1*j, i-1
*ENDDOENDDO
*ENDDO
*DOWHILE loops — *DOWHILE, parameter
Loops repeatedl thro gh the ne t *ENDDO command as long as parameter is
Computer Aided Engineering Associates, Inc. 13Computer Aided Engineering Associates, Inc. 13Copyright© 2002Computer Aided Engineering Associates, Inc.
— Loops repeatedly through the next *ENDDO command as long as parameter is true (greater than zero)
Introduction: APDL Basics
Getting information from the database — *GET commands and functions:— GET commands and functions:
• Can retrieve almost any scalar information needed from the database:
S l f i f ti t i ith th *GET dSample of information you can retrieve with the *GET command:
UX, UY, UZ structural displacement at node N
SX, SY, SZ stresses at node N
maximum node number in the selected set
coordinates of a keypoint
stress at a node
jobname and title
t i l t l t ifi d t tmaterial property value at a specified temperature
time step size in solution
Help, *GET to get a full list of retrievable data
Computer Aided Engineering Associates, Inc. 14Computer Aided Engineering Associates, Inc. 14Copyright© 2002Computer Aided Engineering Associates, Inc.
Introduction: APDL Basics
Getting information from the database — *VGET functions:— VGET functions:
• Can read a large amount of database information into vectors:
Sample of information you can retrieve with the *VGET command:Sample of information you can retrieve with the VGET command:
X, Y, Z coordinates of all selected nodes
UX, UY, UZ displacements of all selected nodes
SX, SY, SZ stresses of all selected nodes
Keypoint numbers on all of the selected lines
Surface areas of all of the selected areas
Help, *VGET to get a full list of retrievable dataHelp, VGET to get a full list of retrievable data
Note: *VGET is much faster than looping with *DO
Computer Aided Engineering Associates, Inc. 15Computer Aided Engineering Associates, Inc. 15Copyright© 2002Computer Aided Engineering Associates, Inc.
Note: VGET is much faster than looping with DO
Introduction: APDL Basics
Executing Macros and Input Files— File > Read input from (input file name)— Command Line: /input,filename,ext— Utility Menu > Macro > Execute Macro— Use a macro command format: filename.mac
Up to 19 arguments can be passed to a macro
Example: Macro to create a block with a hole:
File: mkblk macFile: mkblk.mac
Sample Call to the macro: mkblk, 2., 3., 2.,1.4
/prep7
block,,arg1,,arg2,,arg3 ! (block,,2,,3,,2)g g g ( )
sphere,arg4 ! (sphere,1.4)
vsbv,1,2
finish
Computer Aided Engineering Associates, Inc. 16Computer Aided Engineering Associates, Inc. 16Copyright© 2002Computer Aided Engineering Associates, Inc.
Parametric Modeling
Parametric models can be generated to rapidly determine the effect of a design modification g
— Recommended procedure:• Create a first pass at a model using parameters for design variables
• Copy the jobname log file to another file name to be used as your parametric input• Copy the jobname.log file to another file name to be used as your parametric input file.
• Modify the design parameters in the input file
• Read the input file into ANSYS to solve the new analysis with the design changesRead the input file into ANSYS to solve the new analysis with the design changes
Example: Parametric Plate Model
length = 20
width = 5width 5
thick = 0.25
/prep7
rect,0,length,0,width
Computer Aided Engineering Associates, Inc. 17Computer Aided Engineering Associates, Inc. 17Copyright© 2002Computer Aided Engineering Associates, Inc.
r,1,thick
…
Importing/Exporting Data in/out of ANSYS
Allows data exchange between ANSYS and other codes — Import data into ANSYS from an external file using *VREAD, *TREAD p g ,
— Export data to an external file from ANSYS using *VWRITE, *MWRITE
Example: Importing data with *VREAD
idim = 5
jdim = 2
*dim,aa,,idim,jdim
*vread aa(1 1) read2 txt KJI 1 jdim idimvread,aa(1,1),read2,txt,,KJI,1,jdim,idim
(2f4.0)
File: ‘read2.txt’11 1221 2231 3241 4251 52
Computer Aided Engineering Associates, Inc. 18Computer Aided Engineering Associates, Inc. 18Copyright© 2002Computer Aided Engineering Associates, Inc.
51 52
Customized Menus and Toolbars
Allows for simple customized messages and input menus— *ASK command: Pop up a simple input menu— ASK command: Pop up a simple input menu
Example: *ask, jtitle, ’job title’
— *MSG command: Pop up a simple messageExample: *msg, ui, ’inner’, 25, 1.2, 148
Radius ( %C) = %I, Thick = %G, Length = %G
Computer Aided Engineering Associates, Inc. 19Computer Aided Engineering Associates, Inc. 19Copyright© 2002Computer Aided Engineering Associates, Inc.
Customized Menus and Toolbars – cont…
You can create a multiple-prompt menu using the *MULTIPRO Utility— This can include a limited amount of text and input fieldsp
Computer Aided Engineering Associates, Inc. 20Computer Aided Engineering Associates, Inc. 20Copyright© 2002Computer Aided Engineering Associates, Inc.
Customized Menus and Toolbars – cont…
Toolbar items can be used to execute macros or commonly used commands
*ABBR, MKPART, ptcreate
PTCREATE.MAC: Macro to create and mesh a bracket
w1 = 3
w2 = 1
/prep7
rect 0 w1 0 1rect,0,w1,0,1
rect,0,w2,0,5
aadd,all
…
Computer Aided Engineering Associates, Inc. 21Computer Aided Engineering Associates, Inc. 21Copyright© 2002Computer Aided Engineering Associates, Inc.
Storing macros
Macros can be stored in a “macro” directory and accessed with either the ANSYS_MACROLIB environment variable or the /PSEARCH _command.Macro files are searched in the following order:1 ANSYS ‘docu’ directory1. ANSYS docu directory
2. ANSYS_MACROLIB environment variable (if defined)
3. User’s home directory or the directory specified with the /PSEARCH command (if d fi d Utilit M > M > M S h P th)defined: Utility Menu > Macro > Macro Search Path)
4. Local working directory
Computer Aided Engineering Associates, Inc. 22Computer Aided Engineering Associates, Inc. 22Copyright© 2002Computer Aided Engineering Associates, Inc.
Encrypting macros
Macros can be encrypted and run with an encryption password— Use the /ENCRYPT command to assign the password and the encrypted macro— Use the /ENCRYPT command to assign the password and the encrypted macro
name
— Use the /DECRYPT command to enter the password and run the macro
Example: Encrypt Macro PTCREATE.MAC
/ENCRYPT,pass99,eptcreate,mac
/nopr
Encrypted Macro EPTCREATE.MAC
/DECRYPT,PASSWORD
01 dvg0/PREP7
rect,0,w1,0,1
rect,0,w2,0,5
01_dvg0
02%WIaIl
03y\!maY%i:#Vp
04i#\KU)b?}Zkp…
esize,.25
amesh,all
/gopr
…
0CT9FPdX1/?
0DYHLl@
/DECRYPT
Computer Aided Engineering Associates, Inc. 23Computer Aided Engineering Associates, Inc. 23Copyright© 2002Computer Aided Engineering Associates, Inc.
/ENCRYPT/DECRYPT
Sample Macro
Macro SXYZ.mac: Calculates any stress component at any coordinate in the model
Macro Call: SXYZ, 0.19, 0.14, 0 , ‘x’
(Calculate the SX Stress at X = 0.19, Y = 0.14, and Z = 0 using averaged nodal stresses)stresses)
Computer Aided Engineering Associates, Inc. 24Computer Aided Engineering Associates, Inc. 24Copyright© 2002Computer Aided Engineering Associates, Inc.
Sample Macro cont …
! Usage: sxyz,X,Y,Z,’comp’! where: X= x coord. (undef. geom.)! Y d
pdef,S%arg4%,s,%arg4%,avg!
! Y= y coord.! Z= z coord.! comp= stress component! (‘x’,’y’,’z’,’1’,etc. Use ‘eqv’ as default) /nopr
! Get the result from the first point on the path*get,ar21,path,,item,s%arg4%,pathpt,1!! Print the result
*msg ui arg4 arg1 arg2 arg3 ar21*get,ar20,active,,rout! If user is in /POST1 proceed*if,ar20,eq,31,then! Turn off warning messages/uis,msgpop,3
msg,ui,arg4,arg1,arg2,arg3,ar21The averaged stress S%C at X= %g, Y= %g, Z= %g &%/ is %g
!! Turn warning messages back on/uis msgpop 2
!! Set up the pathpath,path1,2,,! Define two path pointsppath,1,,arg1,arg2,arg3
/uis,msgpop,2!*else!! Print warning message if user is not in /post1
*msg uipp , ,, g , g , gppath,2,,arg1+.0001,arg2+.0001,arg3!! Map the result onto the path*get,artype,parm,arg4,type*if,artype,eq,0,then
*msg,ui*** You need to be in /POST1 to run SXYZ ***
*endif/gopr
Computer Aided Engineering Associates, Inc. 25Computer Aided Engineering Associates, Inc. 25Copyright© 2002Computer Aided Engineering Associates, Inc.
,a type,eq,0,t earg4= ‘eqv’
*endif
APDL Example 1: Pin insertion macroAPDL Example 1: Pin insertion macro
PC Board Pin Insertion MacroPC Board Pin Insertion MacroGoal: Optimize pin insertion forcesGoal: Optimize pin insertion forces
Solderless pin illustration from
www.zierick.com
Computer Aided Engineering Associates, Inc. 26Computer Aided Engineering Associates, Inc. 26Copyright© 2002Computer Aided Engineering Associates, Inc.
Input ParametersInput Parameters
Computer Aided Engineering Associates, Inc. 27Computer Aided Engineering Associates, Inc. 27Copyright© 2002Computer Aided Engineering Associates, Inc.
Geometric VariationsGeometric Variations
Computer Aided Engineering Associates, Inc. 28Computer Aided Engineering Associates, Inc. 28Copyright© 2002Computer Aided Engineering Associates, Inc.
Pin Model GenerationPin Model Generation
Pin Model Generation
Computer Aided Engineering Associates, Inc. 29Computer Aided Engineering Associates, Inc. 29Copyright© 2002Computer Aided Engineering Associates, Inc.
Insertion Force OptimizationInsertion Force Optimization
Computer Aided Engineering Associates, Inc. 30Computer Aided Engineering Associates, Inc. 30Copyright© 2002Computer Aided Engineering Associates, Inc.
APDL Example 2: Stent automation macroAPDL Example 2: Stent automation macro
Stent Automated Stent Automated Analysis SystemAnalysis Systemy yy y
Computer Aided Engineering Associates, Inc. 31Computer Aided Engineering Associates, Inc. 31Copyright© 2002Computer Aided Engineering Associates, Inc.
What is a Stent ?
A balloon expanded stent is a small, latticed, metal scaffold that is introduced into your blood vessel on a balloon catheter. yThe doctor maneuvers the catheter into the blocked artery and inflates the balloon.Inflation causes the stent to expand and press against the vessel wall.Inflation causes the stent to expand and press against the vessel wall. Once the balloon has been deflated and withdrawn, the stent stays in place permanently, holding the blood vessel open and improving blood flow.flow.
Computer Aided Engineering Associates, Inc. 32Computer Aided Engineering Associates, Inc. 32Copyright© 2002Computer Aided Engineering Associates, Inc.
Stent Finite Element Analysis
FEA starting point could be a 2-D CAD drawing or model parameters.
Example Parameters:soptp(1,1) = 'outer bend radius'soptp(1 3) = ‘width’soptp(1,3) = widthsoptp(1,4) = 'axial c-to-c length'soptp(1,5) = 'cir. c-to-c length'!!rro = .00897width = .00378lst = 03577lst = .03577lcirc = .01479
Computer Aided Engineering Associates, Inc. 33Computer Aided Engineering Associates, Inc. 33Copyright© 2002Computer Aided Engineering Associates, Inc.
Stent Finite Element Analysis
Sample parameters, including the option for the analysis to email results back to the user!results back to the user!
nrep = 6 ! no. of circum. repeating sectionsarep = 0.25 ! no. of repeating sections modeledisymm = 2 ! 1=no symmetry, 2=symmetrytwall = 0.0055 ! wall thickness (inch)crpid = 0. ! crimped inner diameter of stent (mm)desid = 3.0 ! design expanded inner diameter of stent (mm)g p ( )cdivs = 6 ! line divisions on circum .boundary linesldivs = 4 ! line divisions on long. boundary linesissiz = 6 ! smart sizing parametergsfac = 1 ! global element sizing factorgsfac = 1. ! global element sizing factornumsub = 30 ! starting number of substeps in each LSores = 5 ! frequency of writing resultsmailit = 1 ! e-mail results files: 0=no, 1=yes
Computer Aided Engineering Associates, Inc. 34Computer Aided Engineering Associates, Inc. 34Copyright© 2002Computer Aided Engineering Associates, Inc.
Automated Geometry Generation
3-D ANSYS model developed through extrusion and coordinate transformation automatically in APDL
2D Geometry From Parametric Model
Cylindrical 3D Mesh with target surface
transformation automatically in APDL.
a a et c ode
Flat 3D Mesh
g
Flat 3D Mesh
Computer Aided Engineering Associates, Inc. 35Computer Aided Engineering Associates, Inc. 35Copyright© 2002Computer Aided Engineering Associates, Inc.
3-D Stent Expansion
Computer Aided Engineering Associates, Inc. 36Computer Aided Engineering Associates, Inc. 36Copyright© 2002Computer Aided Engineering Associates, Inc.
3D Expansion Analysis Results
Automated Postprocessing
! Animation Generation & Automated Postprocessing!i2dan = 1 ! 0=no 2d animation, 1=create 2d animationi3dan = 0 ! 0=no 3d animation, 1=create 3d animation!flstep = 1 ! first load step to animatep pllstep = 3 ! last load step to animatemrep = 1 ! no. of rows of stent to animatenskip = 1 ! results step increment to animatesmin = 0. ! min. plastic strain on contoursmin 0. ! min. plastic strain on contoursmax = 0.35 ! max. plastic strain on contourcontfact = 1.0 ! contour multiplication factorcdist = 0.75 ! contour viewing distanceforl = 1 ! 0=fit to initial state 1=fit to final stateforl = 1 ! 0=fit to initial state, 1=fit to final stateilgd = 1 ! 0=legend off, 1=legend oniball = 1 ! 0=balloon off, 1=balloon onijpg = 3 ! 0=none, 1=geom jpeg, 2=final jpeg, 3=bothidb3 0 ! 0 db 1 db 2 fi l db 3 b th
Computer Aided Engineering Associates, Inc. 37Computer Aided Engineering Associates, Inc. 37Copyright© 2002Computer Aided Engineering Associates, Inc.
idb3 = 0 ! 0=no db, 1=geom db, 2=final db, 3=both
Results for a Simple Stent Geometry
Deployed Device
Computer Aided Engineering Associates, Inc. 38Computer Aided Engineering Associates, Inc. 38Copyright© 2002Computer Aided Engineering Associates, Inc.
Deployed Device