5.8. Reviewing Example Macros

Following are two example macros. The example macro below, called offset.mac, offsets selected nodes in the PREP7 preprocessor. This macro is for demonstration purposes only because the NGEN command provides a more convenient method.

!   Macro to offset selected nodes in PREP7
!   The below file is saved as:  offset.mac (must be lowercase)
!   Usage:  offset,dx,dy,dz

/nop            ! suppress printout for this macro

*get,nnode,node,,num,max   ! get number of nodes

*dim,x,,nnode       ! set up arrays for node locations
*dim,y,,nnode
*dim,z,,nnode

*dim,sel,,nnode     ! set up array for select vector

*vget,x(1),node,1,loc,x   ! get coordinates
*vget,y(1),node,1,loc,y
*vget,z(1),node,1,loc,z

*vget,sel(1),node,1,nsel  ! get selected set

*voper,x(1),x(1),add,arg1 ! offset locations
*voper,y(1),y(1),add,arg2
*voper,z(1),z(1),add,arg3

! *do,i,1,nnode           ! store new positions
!  *if,sel(i),gt,0,then   ! this form takes 98 sec for 100,000 nodes
!    n,i,x(i),y(i),z(i)
!  *endif
! *enddo

*vmask,sel(1)         ! takes 3 seconds for 100,000 nodes
n,(1:NNODE),x(1:NNODE),y(1:NNODE),z(1:NNODE)

x(1) =       ! delete parameters (cleanup)
y(1) = 
z(1) = 
sel(1) =
i=
nnode=

/go          ! resume printout

The following example macro, called bilinear.mac, evaluates two bilinear materials. This is a useful macro that can be run after solving a static analysis. Material 1 is the tension properties, and Material 2 is the compression properties. ARG1 is the number of iterations (default is 2).

/nop
_niter = arg1                      ! set number of iterations
*if,_niter,lt,2,then
   _Niter = 2
*endif
*do,iter,1,_niter                  ! loop on number of iterations
/post1
set,1,1
*get,ar11,elem,,num,maxd           ! Get number of elements
*dim,_s1,,ar11                     ! array for element s1
*dim,_s3,,ar11                     ! array for element s3
etable,sigmax,s,1                  ! s1 is in element table sigmax
etable,sigmin,s,3                  ! s3 is in element table sigmin
*vget,_s1(1),elem,1,etab,sigmax    ! get element maximum stress in s1
*vget,_s3(1),elem,1,etab,sigmin    ! get element minimum stress in s3
*dim,_mask,,ar11                   ! array for mask vector
*voper,_mask(1),_s1(1),lt,0        ! true if max. stress < 0
*vcum,1                            ! accumulate compression elements
*vabs,0,1                          ! absolute value of s3
*voper,_mask(1),_s3(1),gt,_s1(1)   ! true if abs(minstr) > maxstr
finish

/prep7                             ! go to prep7 for element material mods
mat,1                              ! set all materials to tension properties
emod,all

*vput,_mask(1),elem,1,esel         ! select compression elements
mat,2                              ! change selected elements to compression
emod,all

call                               ! select all elements
finish

_s1(1)=                            ! clean up all vectors (set to zero)
_s3(1)=
_mask(1)=

/solve                             ! rerun the analysis
solve
finish

*enddo                             ! end of iterations

_niter=                            ! clean up iteration counters 
_iter=
/gop

Release 18.2 - © ANSYS, Inc. All rights reserved.