Ansys, Inc. provides a set of user subroutines named user01
through user10 for defining custom commands:
To define a custom command:
Insert the code for the functions you want to perform into subroutine
user01(oruser02, etc.).Link the subroutine into the program.
Issue the command /UCMD to define a name for a custom command that calls and executes your subroutine. Use the command format shown below:
/UCMD,Cmd,SRNUM
-
Cmd The name for your new command. It can contain any number of characters, but only the first four are significant. The name you specify can not conflict with the name of any command or the names of any other commands or macros.
-
SRNUM The number of the subroutine your command should call; that is, a value between 01 and 10. For example, suppose that you create and link in a user subroutine for a parabolic distribution of pressure, and you name that subroutine
user01. Issuing the command shown below creates a new command, PARB, that when issued calls your parabolic pressure distribution subroutine:
/UCMD,PARB,1
To make these "custom command" subroutines available in all your sessions, include the /UCMD commands in your start-up file (START.ANS).
You also can use /UCMD to remove a custom command. To do so, simply use a blank value
for Cmd, as shown below:
/UCMD,,1
This command removes the PARB command. To list all user-defined command names, issue the command /UCMD,STAT.
*deck,user01 USERDISTRIB
function user01()
c *** primary function: user routine number 01
c *** Copyright ANSYS. All Rights Reserved.
c *** ansys, inc.
c *** Notice - This file contains ANSYS Confidential information ***
c /*******************************************************************\
c | this is a user routine that may be used by users to include their |
c | special coding. accesss to this routine is by the command usr1. |
c | usr1 may be changed by the user using the command /ucmd. the |
c | user may then use this routine to call his/her special routines. |
c | ansys routines to access information in the ansys database may be |
c | found in the "ansys programmer's manual", available from ansys,inc|
c | see user02 for a simple example usage. |
C | routines user03 to user10 are also available. |
C \*******************************************************************/
c input arguments: none
c output arguments:
c user01 (int,sc,out) - result code (should be zero)
c (which is ignored for now)
c **************************************************************
c Functions for accessing data on the command line
c integer function intinfun(iField) - gets an integer from field iField
c double precision function dpinfun(iField) - gets double precision
c character*4 ch4infun(iField) - gets (upper case) 4 characters
c character*8 ch8infun(iField) - gets (mixed case) 8 characters
c character*32 ch32infun(iField) - gets (mixed case) 32 characters
c **************************************************************
c
#include "impcom.inc"
#include "ansysdef.inc"
external wrinqr
integer wrinqr
integer user01, iott
iott = wrinqr(2)
c ***** USER'S CODE IS INSERTED HERE *****
write (iott,2000)
2000 format (//' ***** CALL TO ANSYS,INC DUMMY USER01 *****'//)
c ***** do not return this result code in a real user routine
user01 = -654321
c ***** instead return a zero *****
c user01 = 0
return
end
*deck,user02 USERDISTRIB
function user02()
c *** primary function: user routine number 02
c --- This demonstration offsets selected nodes with the command:
c usr2,dx,dy,dz
c *** Copyright ANSYS. All Rights Reserved.
c *** ansys, inc.
c *** Notice - This file contains ANSYS Confidential information ***
c /*******************************************************************\
c | see user01 for additional information on user routines |
c \*******************************************************************/
c input arguments: none
c output arguments:
c user02 (int,sc,out) - result code (should be zero)
c (which is ignored for now)
c **************************************************************
c Functions for accessing data on the command line
c integer function intinfun(iField) - gets an integer from field iField
c double precision function dpinfun(iField) - gets double precision
c character*4 ch4infun(iField) - gets (upper case) 4 characters
c character*8 ch8infun(iField) - gets (mixed case) 8 characters
c character*32 ch32infun(iField) - gets (mixed case) 32 characters
c **************************************************************
c
#include "impcom.inc"
#include "ansysdef.inc"
external wrinqr,ndnext,ndgxyz,ndpxyz,erhandler, dpinfun
integer wrinqr,ndnext,ndgxyz
double precision dpinfun
integer user02, iott, i ,ksel
double precision xyz(3), offset(3)
c ***** get the desired offsets from the command line *****
offset(1) = dpinfun(2)
offset(2) = dpinfun(3)
offset(3) = dpinfun(4)
i = 0
10 i = ndnext(i)
if (i .gt. 0) then
ksel = ndgxyz (i,xyz(1))
if (ksel .eq. 1) then
xyz(1) = xyz(1) + offset(1)
xyz(2) = xyz(2) + offset(2)
xyz(3) = xyz(3) + offset(3)
call ndpxyz (i,xyz(1))
endif
goto 10
endif
c ***** write to output file *****
iott = wrinqr(WR_OUTPUT)
write (iott,2000)
2000 format (/' NODE OFFSET COMPLETE '/)
c ***** write to GUI window *****
call erhandler ('user02',3000,
x 2,'NODE OFFSET COMPLETE',0.0d0,' ')
c ***** required return value *****
user02 = 0
return
end
*deck,user03 USERDISTRIB
function user03()
c *** primary function: user routine number 03. Gives example of
c ANSYS Memory usage
c *** Copyright ANSYS. All Rights Reserved.
c *** ansys, inc.
c *** Notice - This file contains ANSYS Confidential information ***
c /*******************************************************************\
c | see user01 for additional information on user routines |
c \*******************************************************************/
c input arguments: none
c output arguments:
c user03 (int,sc,out) - result code (should be zero)
c (which is ignored for now)
c **************************************************************
c Functions for accessing data on the command line
c integer function intinfun(iField) - gets an integer from field iField
c double precision function dpinfun(iField) - gets double precision
c character*4 ch4infun(iField) - gets (upper case) 4 characters
c character*8 ch8infun(iField) - gets (mixed case) 8 characters
c character*32 ch32infun(iField) - gets (mixed case) 32 characters
c **************************************************************
#include "impcom.inc"
#include "ansysdef.inc"
external wrinqr, ndinqr, ndgxyz, ndnext, fAnsMemAlloc,
x fAnsMemFree,erhandler, parreturn, parstatus
integer wrinqr, ndinqr, ndgxyz, ndnext
PTRFTN fAnsMemAlloc
integer user03, iott, i, ksel, numnp, node, istat
double precision xyz(3), xmean, ymean, zmean, stdxyz(3),
x sodx, sody, sodz
c pointers:
pointer (pdXnodeL,Xnode)
pointer (pdYnodeL,Ynode)
pointer (pdZnodeL,Znode)
double precision Xnode(*), Ynode(*), Znode(*)
c *** Get nodal xyz locations and calculate standard deviation of
c *** x coordinates, y coordinates, & z coordinates
c *** get number of currently selected nodes
numnp = ndinqr(0,DB_NUMSELECTED)
istat = 1
if (numnp .le. 0) go to 999
c *** allocate memory for x, y, & z coordinates of nodes
pdXnodeL = fAnsMemAlloc(numnp,MEM_DOUBLE,'XCoords ')
pdYnodeL = fAnsMemAlloc(numnp,MEM_DOUBLE,'YCoords ')
pdZnodeL = fAnsMemAlloc(numnp,MEM_DOUBLE,'ZCoords ')
c *** loop through all selected nodes
i = 1
node = 0
xmean = 0.0d0
ymean = 0.0d0
zmean = 0.0d0
10 node = ndnext(node)
if (node .gt. 0) then
c *** get xyz coordinates
ksel = ndgxyz(node,xyz(1))
c *** store this node's xyz coordinates
Xnode(i) = xyz(1)
Ynode(i) = xyz(2)
Znode(i) = xyz(3)
c *** while we're looping, accumulate sums to calculate means
xmean = xmean + xyz(1)
ymean = ymean + xyz(2)
zmean = zmean + xyz(3)
c *** increment index
i = i + 1
c *** loop back up for next selected node
goto 10
endif
c *** node = 0, at the end of node list
c *** calculate mean of xyz coordinates
xmean = xmean / numnp
ymean = ymean / numnp
zmean = zmean / numnp
c *** calculate standard deviation for xyz coordinates
sodx = 0
sody = 0
sodz = 0
do i = 1, numnp
sodx = sodx + (Xnode(i) - xmean)**2
sody = sody + (Ynode(i) - ymean)**2
sodz = sodz + (Znode(i) - zmean)**2
enddo
stdxyz(1) = sqrt(sodx / (numnp-1))
stdxyz(2) = sqrt(sody / (numnp-1))
stdxyz(3) = sqrt(sodz / (numnp-1))
c ***** write to output file *****
iott = wrinqr(WR_OUTPUT)
write (iott,2000) xmean,ymean,zmean,
x stdxyz(1),stdxyz(2),stdxyz(3)
2000 format (/' MEAN FOR X COORDINATES:',G12.5/
x ' MEAN FOR Y COORDINATES:',G12.5/
x ' MEAN FOR Z COORDINATES:',G12.5/
x ' STD FOR X COORDINATES:',G12.5/
x ' STD FOR Y COORDINATES:',G12.5/
x ' STD FOR Z COORDINATES:',G12.5)
c ***** write to GUI window *****
call erhandler ('user03',5000,2,
x 'STD FOR X COORDINATES: %G %/
x STD FOR Y COORDINATES: %G %/
x STD FOR Z COORDINATES: %G',stdxyz(1),' ')
c ***** set _STATUS to 0 for success *****
istat = 0
c *** release dynamically allocated memory
call fAnsMemFree (pdZnodeL)
call fAnsMemFree (pdYnodeL)
call fAnsMemFree (pdXnodeL)
c ***** required return value *****
999 user03 = 0
c ***** set _RETURN to number of nodes processed *****
call parreturn (dble(numnp))
c ***** set _STATUS for success (0) or no nodes (1) *****
call parstatus (istat)
return
end
*deck,user04 USERDISTRIB
function user04()
c *** primary function: user routine number 04; demonstrates gettting a
c list of nodes attached to a keypoint, line, or area
c *** Copyright ANSYS. All Rights Reserved.
c *** ansys, inc.
c *** Notice - This file contains ANSYS Confidential information ***
c /*******************************************************************\
c | see user01 for additional information on user routines |
c \*******************************************************************/
c input arguments: none
c output arguments:
c user04 (int,sc,out) - result code (should be zero)
c (which is ignored for now)
c **************************************************************
c Functions for accessing data on the command line
c integer function intinfun(iField) - gets an integer from field iField
c double precision function dpinfun(iField) - gets double precision
c character*4 ch4infun(iField) - gets (upper case) 4 characters
c character*8 ch8infun(iField) - gets (mixed case) 8 characters
c character*32 ch32infun(iField) - gets (mixed case) 32 characters
c **************************************************************
c
#include "impcom.inc"
#include "ansysdef.inc"
external ndkpnt
external wrinqr, ndline, ndarea, intinfun
integer wrinqr, ndline, ndarea, intinfun
external ch4infun
character*4 ch4infun
integer user04, iott, listk(20),listl(20),lista(20), listin(1),
x i, num,ktype, nkpnts, nlines, nareas
character*4 type, lab2
iott = wrinqr (WR_OUTPUT)
c --- setup with: /UCMD,GNSME,4
c !gnsme,group,num,type
c ! group = kp, ln, or ar
c ! num = entity number of kp, ln, or ar
c ! type = interior, or all
c ---- see input deck dv-5805s
lab2 = ch4infun(2)
write (iott,2010) lab2
2010 format(/' group name (type of entity) = ',a4)
num = intinfun(3)
write (iott,2020) num
2020 format (' entity number =',i4)
listin(1) = num
if (lab2 .ne. 'KP ' ) then
type = ch4infun(4)
if (type .eq. 'INTE') then
write (iott,2030)
2030 format (' interior nodes only ')
ktype = 0
elseif (type .eq. 'ALL ') then
write (iott,2040)
2040 format (' all (interior and edge/end) nodes ')
ktype = 1
else
write (iott,2050)
2050 format ('Only INTE or ALL are acceptable in last field',
x ' on user-written gnsme command')
endif
endif
if (lab2 .eq. 'KP ' ) then
nkpnts = 0
call ndkpnt (1,listin(1),nkpnts,listk(1))
write (iott,2110) nkpnts
2110 format (' number of nodes on keypoint = ',i4)
write (iott,2115) (listk(i),i=1,nkpnts)
2115 format (' node on keypoint = ',i4)
elseif (lab2 .eq. 'LN ' ) then
nlines = ndline (num,ktype,listl(1))
write (iott,2120) nlines
2120 format (' number of nodes on line = ',i4)
write (iott,2125) (listl(i),i=1,nlines)
2125 format (' list of nodes on line'/(3x,i4))
elseif (lab2 .eq. 'AR ' ) then
nareas = ndarea (num,ktype,lista(1))
write (iott,2130) nareas
2130 format (' number of nodes on area = ',i4)
write (iott,2135) (lista(i),i=1,nareas)
2135 format (' list of nodes on area'/(3x,i4))
else
write (iott,2150)
2150 format (' Only KP, LN, or AR are acceptable on user-written ',
x 'gnsme command')
endif
user04 = 0
return
end