Sunteți pe pagina 1din 39

ANSYS® Customization and

Automation with APDL


Presented By
Computer 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

z Introduction
— What is APDL?
— What can you do with APDL?
— Features of APDL
— Advantages and Disadvantages of APDL
z APDL Basics
B i
z Parametric Modeling
z Importing/Exporting data in/out of ANSYS
z C t
Customized
i d menus andd toolbars
t lb
z Storing macros
z Encrypting macros
z M
Macro example
l
z Consulting examples:
— Pin insertion macro
— Stent automation macro

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 2
Associates, Inc.
Introduction: What is APDL?

z APDL = ANSYS Parametric Design Language


— APDL is a scripting
p g language
g g used to automate and customize tasks in ANSYS
— 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
z 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
z Features of APDL
— Macros, if-then-else branching, do-loops, and scalar, vector, and matrix
operations.
— Macros are APDL routines
— Virtually all ANSYS commands can be used in APDL
Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 3
Associates, Inc.
Introduction: APDL Examples

z Automation
— Create ggeometry y with a new set of dimensions ((Parametric Modeling)
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
p for the selected
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

z Customization
— Create simple input and output menus (*ASK, *MSG, Multipro)
— Create customized toolbar items to perform common tasks

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 4
Associates, Inc.
Introduction: Advantages of APDL

z Price: No extra cost: Included with all ANSYS products


z 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 picks
picks.
— Interpreted (not compiled) so effects of modifications are immediately
realizable.
z G d Documentation:
Good D t ti
— APDL Programmer’s Guide
— ANSYS Commands Reference
— CAEA S
Seminar:
i “ANSYS C
Customization
i i and dP
Programming
i (APDL)”
z Other:
— Specially
p y compiled
p version of ANSYS is not required
q

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 5
Associates, Inc.
Introduction: Disadvantages of APDL

z Limited Customization:
— Only simple input and message menus can be generated
generated.
z Speed:
— Can be slow for complex operations on large models. User subroutines are
generally much faster
faster.

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 6
Associates, Inc.
Introduction: APDL Basics

z 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 command
d
— (example: *STAT,A1)

— Deleting scalar parameters:


• parameter =
• OR *SET,parameter

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 7
Associates, Inc.
Introduction: APDL Basics

z Scalar Parameters cont…


— Forced p
parameter substitution:
• Enclose the parameter name in % signs for substitution in
character expressions

E
Example:
l Run
R multiple
lti l iinputt fil
files and
d solve
l th
them iin order
d
job=‘fname’
*DO,I,1,5
/input %job%%I% inp
/input,%job%%I%,inp ! input = ‘fname1
fname1.inp
inp’, ‘fname2
fname2.inp
inp’, …
/solu
solve
finish
*ENDDO

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 8
Associates, Inc.
Introduction: APDL Basics

z 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

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 9
Associates, Inc.
Introduction: APDL Basics

z Scalar Functions
— 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),
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
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
pi = acos(-1)
F, i, FY, fmax*SIN(2*pi*time/tmax)
Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 10
Associates, Inc.
Introduction: APDL Basics

z Array Functions
— 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.
• *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
position
ii 2,5
2 5 off the
h array XVAL
K,4,XVAL(2,5),0.,0.
Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 11
Associates, Inc.
Introduction: APDL Basics

z *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

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 12
Associates, Inc.
Introduction: APDL Basics

z *DO loops
— Same functionalityy as *DO loops
p in FORTRAN
— *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
*ENDDO
ENDDO
*ENDDO

z *DOWHILE loops
— *DOWHILE, parameter
— Loops repeatedl
repeatedly thro
through
gh the ne
nextt *ENDDO command as long as parameter is
true (greater than zero)
Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 13
Associates, Inc.
Introduction: APDL Basics

z Getting information from the database


— *GET
GET commands and functions:
• Can retrieve almost any scalar information needed from the database:

S
Sample
l off information
i f ti you can retrieve
t i with
ith the
th *GET command:
d
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
material
t i l property
t value
l att a specified
ifi d temperature
t t
time step size in solution
Help, *GET to get a full list of retrievable data

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 14
Associates, Inc.
Introduction: APDL Basics

z Getting information from the database


— *VGET
VGET functions:
• Can read a large amount of database information into vectors:

Sample of information you can retrieve with the *VGET


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
VGET to get a full list of retrievable data

Note: *VGET
VGET is much faster than looping with *DO
DO

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 15
Associates, Inc.
Introduction: APDL Basics

z 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
z Up to 19 arguments can be passed to a macro
Example: Macro to create a block with a hole:
File: mkblk.mac
mkblk mac
Sample Call to the macro: mkblk, 2., 3., 2.,1.4
/prep7
g g g
block,,arg1,,arg2,,arg3 ! ((block,,2,,3,,2))
sphere,arg4 ! (sphere,1.4)
vsbv,1,2
finish

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 16
Associates, Inc.
Parametric Modeling

z Parametric models can be generated to rapidly determine the effect of


a design
g modification
— Recommended procedure:
• Create a first pass at a model using parameters for design variables
• Copy the jobname
jobname.log
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 changes

Example: Parametric Plate Model


length = 20
width = 5
thick = 0.25
/prep7
rect,0,length,0,width
r,1,thick

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 17
Associates, Inc.
Importing/Exporting Data in/out of ANSYS

z Allows data exchange between ANSYS and other codes


— Import
p data into ANSYS from an external file using
g *VREAD,, *TREAD
— 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
vread,aa(1,1),read2,txt,,KJI,1,jdim,idim
aa(1 1) read2 txt KJI 1 jdim idim
(2f4.0)
File: ‘read2.txt’
11 12
21 22
31 32
41 42
51 52

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 18
Associates, Inc.
Customized Menus and Toolbars

z Allows for simple customized messages and input menus


— *ASK
ASK command: Pop up a simple input menu
Example: *ask, jtitle, ’job title’

— *MSG command: Pop up a simple message


Example: *msg, ui, ’inner’, 25, 1.2, 148
Radius ( %C) = %I, Thick = %G, Length = %G

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 19
Associates, Inc.
Customized Menus and Toolbars – cont…

z You can create a multiple-prompt menu using the *MULTIPRO Utility


— This can include a limited amount of text and input
p fields

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 20
Associates, Inc.
Customized Menus and Toolbars – cont…

z 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 1
rect,0,w1,0,1
rect,0,w2,0,5
aadd,all

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 21
Associates, Inc.
Storing macros

z Macros can be stored in a “macro” directory and accessed with either


_
the ANSYS_MACROLIB environment variable or the /PSEARCH
command.
z Macro files are searched in the following order:
1 ANSYS ‘docu’
1. 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
defined: Utility M
Menu > M
Macro > M
Macro SSearch hP
Path)
th)
4. Local working directory

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 22
Associates, Inc.
Encrypting macros

z Macros can be encrypted and run with an encryption password


— 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


Encrypted Macro EPTCREATE.MAC
/ENCRYPT,pass99,eptcreate,mac
/DECRYPT,PASSWORD
/nopr
01 dvg0
01_dvg0
/PREP7
02%WIaIl
rect,0,w1,0,1
03y\!maY%i:#Vp
rect,0,w2,0,5
04i#\KU)b?}Zkp


esize,.25
0CT9FPdX1/?
amesh,all
0DYHLl@
/gopr
/DECRYPT
/ENCRYPT

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 23
Associates, Inc.
Sample Macro

z 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)

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 24
Associates, Inc.
Sample Macro cont …

! Usage: sxyz,X,Y,Z,’comp’
pdef,S%arg4%,s,%arg4%,avg
! where: X= x coord. (undef. geom.)
!
! Y y coord.
Y= d
! Get the result from the first point on the path
! Z= z coord.
*get,ar21,path,,item,s%arg4%,pathpt,1
! comp= stress component
!
! (‘x’,’y’,’z’,’1’,etc. Use ‘eqv’ as default)
! Print the result
/nopr
*msg
msg,ui,arg4,arg1,arg2,arg3,ar21
ui arg4 arg1 arg2 arg3 ar21
*get,ar20,active,,rout
The averaged stress S%C at X= %g, Y= %g, Z= %g &
! If user is in /POST1 proceed
%/ is %g
*if,ar20,eq,31,then
!
! Turn off warning messages
! Turn warning messages back on
/uis,msgpop,3
/uis msgpop 2
/uis,msgpop,2
!
!
! Set up the path
*else
path,path1,2,,
!
! Define two path points
! Print warning message if user is not in /post1
ppath,1,,arg1,arg2,arg3
pp , ,, g , g , g
*msg ui
*msg,ui
ppath,2,,arg1+.0001,arg2+.0001,arg3
*** You need to be in /POST1 to run SXYZ ***
!
*endif
! Map the result onto the path
/gopr
*get,artype,parm,arg4,type
,a type,eq,0,t e
*if,artype,eq,0,then
arg4= ‘eqv’
*endif

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 25
Associates, Inc.
APDL Example 1: Pin insertion macro

PC Board Pin Insertion Macro


z Goal: Optimize pin insertion forces

Solderless pin illustration from


www.zierick.com

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 26
Associates, Inc.
Input Parameters

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 27
Associates, Inc.
Geometric Variations

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 28
Associates, Inc.
Pin Model Generation

Pin Model Generation

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 29
Associates, Inc.
Insertion Force Optimization

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 30
Associates, Inc.
APDL Example 2: Stent automation macro

Stent Automated
Analysis
y System
y

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 31
Associates, Inc.
What is a Stent ?

z A balloon expanded stent is a small, latticed, metal scaffold that is


introduced into y
your blood vessel on a balloon catheter.
z The doctor maneuvers the catheter into the blocked artery and inflates the
balloon.
z Inflation causes the stent to expand and press against the vessel wall.
z Once the balloon has been deflated and withdrawn, the stent stays in
place permanently, holding the blood vessel open and improving blood
flow.

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 32
Associates, Inc.
Stent Finite Element Analysis

z 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) width
soptp(1,4) = 'axial c-to-c length'
soptp(1,5) = 'cir. c-to-c length'
!
rro = .00897
width = .00378
lst = .03577
03577
lcirc = .01479

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 33
Associates, Inc.
Stent Finite Element Analysis

z Sample parameters, including the option for the analysis to email


results back to the user!

nrep = 6 ! no. of circum. repeating sections


arep = 0.25 ! no. of repeating sections modeled
isymm = 2 ! 1=no symmetry, 2=symmetry
twall = 0.0055 ! wall thickness (inch)
crpid = 0. ! crimped inner diameter of stent (mm)
desid = 3.0 g expanded
! design p inner diameter of stent ((mm))
cdivs = 6 ! line divisions on circum .boundary lines
ldivs = 4 ! line divisions on long. boundary lines
issiz = 6 ! smart sizing parameter
gsfac = 1.
1 ! global element sizing factor
numsub = 30 ! starting number of substeps in each LS
ores = 5 ! frequency of writing results
mailit = 1 ! e-mail results files: 0=no, 1=yes

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 34
Associates, Inc.
Automated Geometry Generation

z 3-D ANSYS model developed through extrusion and coordinate


transformation automatically in APDL.
APDL

2D Geometry From Cylindrical 3D Mesh with


Parametric
a a et c Model
ode target
g surface

Flat 3D Mesh

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 35
Associates, Inc.
3-D Stent Expansion

3D Expansion Analysis Results


Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 36
Associates, Inc.
Automated Postprocessing

! Animation Generation & Automated Postprocessing


!
i2dan = 1 ! 0=no 2d animation, 1=create 2d animation
i3dan = 0 ! 0=no 3d animation, 1=create 3d animation
!
p=1
flstep ! first load stepp to animate
llstep = 3 ! last load step to animate
mrep = 1 ! no. of rows of stent to animate
nskip = 1 ! results step increment to animate
smin = 0. ! min. plastic strain on contour
smax = 0.35 ! max. plastic strain on contour
contfact = 1.0 ! contour multiplication factor
cdist = 0.75 ! contour viewing distance
forl = 1 ! 0=fit to initial state,
state 1=fit to final state
ilgd = 1 ! 0=legend off, 1=legend on
iball = 1 ! 0=balloon off, 1=balloon on
ijpg = 3 ! 0=none, 1=geom jpeg, 2=final jpeg, 3=both
idb3 = 0 !00=no dbdb, 1=geom
1 db
db, 2=final
2 fi l db,
db 3=both
3 b th

Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 37
Associates, Inc.
Results for a Simple Stent Geometry

Deployed Device
Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 38
Associates, Inc.
Copyright© 2002
Computer Aided Engineering Computer Aided Engineering Associates, Inc. 39
Associates, Inc.

S-ar putea să vă placă și