Vous êtes sur la page 1sur 40

ANSYS

C t
Customization
i ti
and
d
Automation with
APDL

2002 CAE Associates

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

Introduction

z
z
z
z
z
z
z
z

What is APDL?
What can you do with APDL?
Features of APDL
Advantages and Disadvantages of APDL

APDL Basics
B i
Parametric Modeling
Importing/Exporting data in/out of ANSYS
C t
Customized
i d menus and
d toolbars
t lb
Storing macros
Encrypting macros
M
Macro
example
l
Consulting examples:

Pin insertion macro


Stent automation macro

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

Introduction: What is APDL?

APDL = ANSYS Parametric Design Language

What can you do with APDL?

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
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
Virtually all ANSYS commands can be used in APDL

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

Introduction: APDL Examples

Automation

Create g
geometry
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

Customization

Create simple input and output menus (*ASK, *MSG, Multipro)


Create customized toolbar items to perform common tasks

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

Introduction: Advantages of APDL

Price: No extra cost: Included with all ANSYS products

Rapid Learning Curve:

G d Documentation:
Good
D
t ti

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.
APDL Programmers Guide
ANSYS Commands Reference
CAEA S
Seminar:
i
ANSYS C
Customization
i i and
dP
Programming
i (APDL)

Other:

Specially
p
y compiled
p
version of ANSYS is not required
q

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

Introduction: Disadvantages of APDL

Limited Customization:

Only simple input and message menus can be generated


generated.

Speed:

Can be slow for complex operations on large models. User subroutines are
generally much faster
faster.

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

Introduction: APDL Basics

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
Associates, Inc.

Computer Aided Engineering Associates, Inc.

Introduction: APDL Basics

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
Associates, Inc.

Computer Aided Engineering Associates, Inc.

Introduction: APDL Basics

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
Associates, Inc.

Computer Aided Engineering Associates, Inc.

Introduction: APDL Basics

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
Associates, Inc.

Computer Aided Engineering Associates, Inc.

10

Introduction: APDL Basics

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
Associates, Inc.

Computer Aided Engineering Associates, Inc.

11

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

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

12

Introduction: APDL Basics

*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

*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
Associates, Inc.

Computer Aided Engineering Associates, Inc.

13

Introduction: APDL Basics

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
Associates, Inc.

Computer Aided Engineering Associates, Inc.

14

Introduction: APDL Basics

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
Associates, Inc.

Computer Aided Engineering Associates, Inc.

15

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.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
Associates, Inc.

Computer Aided Engineering Associates, Inc.

16

Parametric Modeling

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
Associates, Inc.

Computer Aided Engineering Associates, Inc.

17

Importing/Exporting Data in/out of ANSYS

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
Associates, Inc.

Computer Aided Engineering Associates, Inc.

18

Customized Menus and Toolbars

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:

Copyright 2002
Computer Aided Engineering
Associates, Inc.

*msg, ui, inner, 25, 1.2, 148


Radius ( %C) = %I, Thick = %G, Length = %G

Computer Aided Engineering Associates, Inc.

19

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


p fields

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

20

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

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

21

Storing macros

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


_
environment variable or the /PSEARCH
the ANSYS_MACROLIB
command.

Macro files are searched in the following order:


1 ANSYS docu
1.
docu directory
2. ANSYS_MACROLIB environment variable (if defined)
3. Users home directory or the directory specified with the /PSEARCH command (if
d fi d Utilit
defined:
Utility M
Menu > M
Macro > M
Macro S
Search
hP
Path)
th)
4. Local working directory

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

22

Encrypting macros

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


/ENCRYPT,pass99,eptcreate,mac
/nopr
/PREP7
rect,0,w1,0,1
rect,0,w2,0,5

esize,.25
amesh,all
/gopr
/ENCRYPT
Copyright 2002
Computer Aided Engineering
Associates, Inc.

Encrypted Macro EPTCREATE.MAC


/DECRYPT,PASSWORD
01 dvg0
01_dvg0
02%WIaIl
03y\!maY%i:#Vp
04i#\KU)b?}Zkp

0CT9FPdX1/?
0DYHLl@
/DECRYPT

Computer Aided Engineering Associates, Inc.

23

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)

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

24

Sample Macro cont

! Usage: sxyz,X,Y,Z,comp
! where: X= x coord. (undef. geom.)
!
Y y coord.
Y=
d
!
Z= z coord.
!
comp= stress component
! (x,y,z,1,etc. Use eqv as default)
/nopr
*get,ar20,active,,rout
! If user is in /POST1 proceed
*if,ar20,eq,31,then
! Turn off warning messages
/uis,msgpop,3
!
! Set up the path
path,path1,2,,
! Define two path points
ppath,1,,arg1,arg2,arg3
pp
, ,, g , g , g
ppath,2,,arg1+.0001,arg2+.0001,arg3
!
! Map the result onto the path
*get,artype,parm,arg4,type
,a type,eq,0,t e
*if,artype,eq,0,then
arg4= eqv
*endif
Copyright 2002
Computer Aided Engineering
Associates, Inc.

pdef,S%arg4%,s,%arg4%,avg
!
! Get the result from the first point on the path
*get,ar21,path,,item,s%arg4%,pathpt,1
!
! Print the result
*msg
msg,ui,arg4,arg1,arg2,arg3,ar21
ui arg4 arg1 arg2 arg3 ar21
The averaged stress S%C at X= %g, Y= %g, Z= %g &
%/ is %g
!
! Turn warning messages back on
/uis msgpop 2
/uis,msgpop,2
!
*else
!
! Print warning message if user is not in /post1
*msg ui
*msg,ui
*** You need to be in /POST1 to run SXYZ ***
*endif
/gopr

Computer Aided Engineering Associates, Inc.

25

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
Associates, Inc.

Computer Aided Engineering Associates, Inc.

26

Input Parameters

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

27

Geometric Variations

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

28

Pin Model Generation

Pin Model Generation

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

29

Insertion Force Optimization

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

30

APDL Example 2: Stent automation macro

Stent Automated
Analysis
y
System
y

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

31

What is a Stent ?

z
z
z
z

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


introduced into y
your blood vessel on a balloon catheter.
The doctor maneuvers the catheter into the blocked artery and inflates the
balloon.
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.

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

32

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)
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
Associates, Inc.

Computer Aided Engineering Associates, Inc.

33

Stent Finite Element Analysis

Sample parameters, including the option for the analysis to email


results back to the user!
nrep = 6
arep = 0.25
isymm = 2
twall = 0.0055
crpid = 0.
desid = 3.0
cdivs = 6
ldivs = 4
issiz = 6
gsfac = 1.
1
numsub = 30
ores = 5
mailit = 1

Copyright 2002
Computer Aided Engineering
Associates, Inc.

! no. of circum. repeating sections


! no. of repeating sections modeled
! 1=no symmetry, 2=symmetry
! wall thickness (inch)
! crimped inner diameter of stent (mm)
g expanded
p
inner diameter of stent ((mm))
! design
! line divisions on circum .boundary lines
! line divisions on long. boundary lines
! smart sizing parameter
! global element sizing factor
! starting number of substeps in each LS
! frequency of writing results
! e-mail results files: 0=no, 1=yes

Computer Aided Engineering Associates, Inc.

34

Automated Geometry Generation

3-D ANSYS model developed through extrusion and coordinate


transformation automatically in APDL.
APDL
Cylindrical 3D Mesh with
target
g surface

2D Geometry From
Parametric
a a et c Model
ode

Flat 3D Mesh

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

35

3-D Stent Expansion

3D Expansion Analysis Results


Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

36

Automated Postprocessing

! Animation Generation & Automated Postprocessing


!
i2dan = 1
i3dan = 0
!
p=1
flstep
llstep = 3
mrep = 1
nskip = 1
smin = 0.
smax = 0.35
contfact = 1.0
cdist = 0.75
forl = 1
ilgd = 1
iball = 1
ijpg = 3
idb3 = 0

Copyright 2002
Computer Aided Engineering
Associates, Inc.

! 0=no 2d animation, 1=create 2d animation


! 0=no 3d animation, 1=create 3d animation
! first load step
p to animate
! last load step to animate
! no. of rows of stent to animate
! results step increment to animate
! min. plastic strain on contour
! max. plastic strain on contour
! contour multiplication factor
! contour viewing distance
! 0=fit to initial state,
state 1=fit to final state
! 0=legend off, 1=legend on
! 0=balloon off, 1=balloon on
! 0=none, 1=geom jpeg, 2=final jpeg, 3=both
!0
0=no db
db, 1=geom
1
db
db, 2=final
2 fi l db,
db 3=both
3 b th

Computer Aided Engineering Associates, Inc.

37

Results for a Simple Stent Geometry

Deployed Device
Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

38

Copyright 2002
Computer Aided Engineering
Associates, Inc.

Computer Aided Engineering Associates, Inc.

39