Você está na página 1de 61

Autodyn User Subroutines

15.0 Release

Advanced Training Course


2013 ANSYS, Inc.

August 5, 2013

Release 15.0

Course Content

User Subroutines Development Environment

Installed files
Microsoft .NET development environment
Provided user subroutines
Creating user executable
Debugging user executable

Running user executables in Workbench

Writing User Subroutines

Template Files
Formal Parameters
AUTODYN Modules
Utility Functions / Subroutines
Hands-on Example #1
AUTODYN Grid Variables
Hands-on Example #2 and #3
Material Modeling Modules
Hands-on Example #4
Using the Debugger
Workshop

2013 ANSYS, Inc.

August 5, 2013

Release 15.0

User Subroutines Development Environment


User subroutines are created, edited, linked, debugged and executed
using the Microsoft .NET development environment
Required Software:

Intel Visual Fortran Composer XE 2011


Microsoft Visual Studio C++ .NET 2010
User executables can subsequently be run in Through Workbench

2013 ANSYS, Inc.

August 5, 2013

Release 15.0

User Subroutines Development Environment


Standard Workbench installation:

The files required for creating and using AUTODYN User Subroutines are

automatically installed in (default installation)


C:\Program Files\ANSYS Inc\v150\AISOL\Autodyn\Winx64 for 64-bit OS
C:\Program Files\ANSYS Inc\v150\AISOL\Autodyn\Intel for 32-bit OS
The user subroutine environment uses details from the installation
directory
A user subroutine project directory structure can be created from within
the AUTODYN user interface
This can be placed anywhere in your directory structure
You can have as many projects as you want!
However, user subroutine projects are specific to an installed version.
If you install an update of AUTODYN / Workbench, you will need to
update your user subroutine projects
Create a new subroutine project with the new AUTODYN version
Merge your code changes into this new project structure

2013 ANSYS, Inc.

August 5, 2013

Release 15.0

User Subroutines
Development Environment

2013 ANSYS, Inc.

August 5, 2013

Release 15.0

User Subroutines Development Environment


Installed Files

..\AUTODYN user_subroutines
\fsrc
\2d\usrsub2.f90
\3d\usrsub3.f90
\materials\mdeos_user_1.f90
mdstr_user_1.f90
mdfai_user_1.f90
mdero_user_1.f90
\ad_usrsub.sln
\ad_usrsub.vfproj
\ad_usrsub_slave.vfproj

2013 ANSYS, Inc.

August 5, 2013

AUTODYN-2D user subroutines


AUTODYN-3D user subroutines
User equation of state model
User strength model
User failure model
User erosion model
Intel/.NET Solution files
Intel/.NET Fortran project files

Release 15.0

User Subroutines Development Environment

AUTODYN Solution Files

A single solution file is provided: ad_usrsub.sln

Double click on this file to open the project in the Microsoft .NET
development environment

2013 ANSYS, Inc.

August 5, 2013

Release 15.0

User Subroutines Development Environment

Choose
Debug or Release

2013 ANSYS, Inc.

August 5, 2013

Choose
x64 or win32

Release 15.0

User Subroutines Development Environment


Two Projects

ad_usrsub

creates primary executable


ad_usrsub_slave
creates slave executable for parallel processing

Modularized material model routines

mdeos_user_1.f90
mdero_user_1.f90
mdfai_user_1.f90
mdstr_user_1.f90

All other user subroutines are contained in

usrsub2.f90
usrsub33.f90

2013 ANSYS, Inc.

August 5, 2013

Release 15.0

User Subroutines Development Environment


Material Modeling User Subroutines
MDEOS_USER_1

Modularized custom equation of state (Previously EXEOS)

MDSTR_USER_1

Modularized custom yield and/or shear model (Previously EXYLD)

MDFAI_USER_1

Modularized custom failure criteria (Previously EXFAIL / EXFAILS)

MDERO_USER_1

Modularized custom erosion criteria (Previously EXEROD)

EXBULK

Custom bulk modulus for a linear EOS

EXCOMP

Custom porous compaction curve, P- equation of state

EXCRCK

Custom tensile crack softening rate

EXDAM

Custom damage parameter

EXPLRN

Custom plastic flow return algorithm

EXSHR

Custom shear modulus

EXSTIF

Custom stiffness matrix, orthotropic-elastic with failure

EXTAB

Custom tabulated saturation curve for two-phase EOS

2013 ANSYS, Inc.

August 5, 2013

10

Release 15.0

User Subroutines Development Environment


Other User Subroutines
EXACC

Apply user defined acceleration to a Lagrangian node

EXALE

Custom ALE (Arbitrary Lagrange Euler) grid motions

EXEDIT

Custom edits

EXFLOW

Custom Euler flow boundary

EXLOAD

Loading additional, non-standard data from "SAVE" files

EXPOR

Custom variable polygon porosity

EXSAVE

Saving additional, non-standard data to "SAVE" files

EXSIE

Custom energy deposition

EXSTR

Custom stress boundary condition

EXVAL

Custom initial conditions

EXVEL

Custom velocity boundary condition

EXZONE

Custom nodal coordinates

2013 ANSYS, Inc.

August 5, 2013

11

Release 15.0

User Subroutines Development Environment


Creating User Executables

Select Platform/Optimisation

Debug lets you debug the source code in user subroutines


Build Toolbar
Press Build Solution
to create executable

Executables are produced


in the root of your
user subroutine project
directory

ad_usersub.exe

Primary executable
ad_usrsub_slave.exe
Slave executable for parallel
processing

2013 ANSYS, Inc.

August 5, 2013

12

Release 15.0

User Subroutines Development Environment


Debugging is performed within the development environment
In the development environment

Select Debug for the solution configuration


Build the executable
Select Start Without

Debugging from the


Debug pull-down window
to start Autodyn User
Executable in regular mode
Select Start Debugging
from the Debug pull-down
window to start Autodyn
User Executable in debug
mode

2013 ANSYS, Inc.

August 5, 2013

13

Release 15.0

Running User Executables


in Workbench

RMC on setup and


choose Select user
executable

Select the primary


executable from your
user subroutine
directory

2013 ANSYS, Inc.

August 5, 2013

14

Release 15.0

User Subroutines: Linux Environment


Required software for compiling user-subroutines:

Intel Fortran Compiler 11.1 for Linux


User subroutines can be created and edited using a text editor (i.e. vi
text editor)
These subroutines can be found in:

/ansys_inc/v150/autodyn/usrsub/<platform>
The platform directory is either:

linia32 (32bit Linux)


linia64 (64bit Itanium II Linux)
linop64 (64bit AMD 64 Linux)
linem64t (64bit Intel EM64T Linux)

2013 ANSYS, Inc.

August 5, 2013

15

Release 15.0

User Subroutines: Linux Environment


We recommend that the user-subroutine directory and its subdirectories be copied to your home directory to avoid conflict
Steps for compiling user-subroutines:

Define the path for HP-MPI directory in autolnk, OR, set environment

variable MPI_ROOT to point to the path of HP-MPI directory


Type ./autolnk within the user-subroutine directory

The HP-MPI directory is installed in:

/ansys_inc/v150/autodyn/hpmpi/<platform>

2013 ANSYS, Inc.

August 5, 2013

16

Release 15.0

User Subroutines: Linux Environment


Steps for executing customized AUTODYN:

Set environment variable CUSTOMIZED_AUTODYN to point to the path of


customized AUTODYN executable

For parallel processing, path in parallel.cfg file should also point to the
path of customized AUTODYN executable

Run standard AUTODYN script (i.e. AUTODYN_EXE)


To return to standard AUTODYN executable:

Unset environment variable CUSTOMIZED_AUTODYN

2013 ANSYS, Inc.

August 5, 2013

17

Release 15.0

Writing User Subroutines


Common techniques and tools

Using formal parameters passed to and from the user subroutine


Using global variables in AUTODYN modules (e.g. time, material data,

cycle number, etc.)


Using Part grid variables (e.g. pressure, density, velocity, etc.)
Calling AUTODYN utility functions / subroutines
Messaging from a user subroutine
Terminating execution from a user subroutine

2013 ANSYS, Inc.

August 5, 2013

18

Release 15.0

Open the User Subroutine Source File

Double click it
to open the file

2013 ANSYS, Inc.

August 5, 2013

19

Release 15.0

Writing User Subroutines


Dummy Subroutines
SUBROUTINE EXSTR (NAMSTR,RBC,I1,J1,I2,J2,X1,Y1,X2,Y2,PRES)
USE kindef
USE bnddef
USE ijknow
USE cycvar
USE wrapup

! OUTPUT PARAMETERS

Formal Parameters

IMPLICIT NONE

PRESSURE TO BE APPLIED TO CELL FACE

! THE FOLLOWING MODULES CONTAIN INFORMATION WHICH MAY BE


! USEFUL FOR COMPUTING THE BOUNDARY PRESSURE :-

Data modules

! MODULE 'IJKNOW'

INTEGER (INT4) :: I1, I2, J1, J2


REAL (REAL8) :: PRES, X1, X2, Y1,
REAL (REAL8), DIMENSION(5) :: RBC
CHARACTER (LEN=10) :: NAMSTR

Y2

Subroutine description

! ************************************************************************
! THIS IS A USER SUPPLIED SUBROUTINE WHICH COMPUTES A BOUNDARY
! PRESSURE FOR A CELL FACE. THE FACE OF THE CELL MUST EITHER BE
! ON A GRID BOUNDARY (I=1,I=IMAX,J=1,J=JMAX) OR MUST BE ADJACENT
! TO AN UNUSED CELL. EXSTR IS CALLED ONCE PER CYCLE FOR EACH CELL
! FACE ASSIGNED THE USER STRESS CONDITION THROUGH INPUT. EXSTR IS
! USED IF THE BOUNDARY PRESSURE CANNOT BE DEFINED USING ONE OF THE
! STANDARD FUNCTIONS PROVIDED BY AUTODYN.

MNOW - CURRENT SUBGRID NUMBER

! MODULE 'CYCVAR'
!
!
!

Useful Variables
contained in data
modules

NCYCLE - CURRENT CYCLE NUMBER


TIME - CURRENT TIME
DLTH - TIME STEP FOR CURRENT CYCLE

! ************************************************************************
! TEMPORARY ERROR MESSAGE - REPLACE WITH YOUR OWN CODE
CALL USR_MESSAG ('$User subroutine EXSTR missing$')
NSWRAP = 9

! INPUT PARAMETERS
! NAMSTR BOUNDARY CONDITION NAME (DEFINED BY USER DURING INPUT)
! RBC(1-5) INPUT PARAMETERS FOR BOUNDARY CONDITION
! I1,J1
!
! I2,J2

PRES

Definition of
Output
Parameters

RETURN

Default error message

END SUBROUTINE EXSTR

(replace it with
required coding)

)
) CELL FACE RUNS FROM (I1,J1) TO (I2,J2)
)

! X1,Y1

COORDINATES OF (I1,J1)

! X2,Y2

COORDINATES OF (I2,J2)

2013 ANSYS, Inc.

Definition of input
parameters
August 5, 2013

20

Release 15.0

Writing User Subroutines


Formal Parameters

Most user subroutines have formal parameters.


Comments at the head of a User Subroutine define each parameter
Input parameter, output parameter, or both.
Simple User Subroutines compute the output parameter(s) from the
input parameter(s).
If a user subroutine requires other variables that are not formal
parameters they must obtain it in some other manner.

Data Modules
Function calls
Input parameters Output parameter

SUBROUTINE EXSTR (NAMSTR,RBC,I1,J1,I2,J2,X1,Y1,X2,Y2,PRES)

2013 ANSYS, Inc.

August 5, 2013

21

Release 15.0

Writing User Subroutines


User Input Parameters
Parameters input by the user are passed through to a user
subroutine as an array in the formal parameter list. e.g:
SUBROUTINE EXVEL (NAMVEL,RBC,K,XB,YB,UXT,UYT)
USE kindef
USE bnddef
USE ijknow
USE wrapup
IMPLICIT NONE
INTEGER (INT4) ::
K
REAL (REAL8) :: UXT, UYT, XB,
REAL (REAL8), DIMENSION(5) :: RBC
CHARACTER (LEN=10) :: NAMVEL
.
param1 = RBC(1)
param2 = RBC(2)

2013 ANSYS, Inc.

August 5, 2013

22

YB

Release 15.0

Writing User Subroutines


AUTODYN Data Modules
Global data not available as formal parameters can usually be
obtained directly from AUTODYN data modules: *.mod .
All modules described in Appendix A, User Subroutines Tutorial
To use a particular module in a User Subroutine insert the statement:
USE xxxxxx
where xxxxxx is the name of the appropriate module.

Dummy subroutines have USE statements already defined for


modules containing the most often required global data
Comments indicate which variables are likely to be useful.
Be extremely careful if you choose to modify module variables.
These variables are used by other routines and assigning bad
values to them can cause AUTODYN to crash!

2013 ANSYS, Inc.

August 5, 2013

23

Release 15.0

Writing User Subroutines


Timing of calls to User Subroutines

Type

Timing of calls

Depending upon the user subroutine,

the routine may be called once per


problem (e.g. EXLOAD), once per
specified cycle (e.g. EXEDIT), or many
times for each cycle and each element /
cell
Calling sequence of user subroutines are
classified according to type
Chapter 3, Table 2 lists the calling
sequence type for all User Subroutines

2013 ANSYS, Inc.

August 5, 2013

24

Called once, each time a Load or Save is


requested

Called at each user specified cycle

Called for user specified material, each cell,


each cycle

Called for particular boundary conditions,


each cell on boundary, each cycle

Called for each cell, each cycle

Called for each fill (initialization) region,


during problem set-up

Called for each EXZONE menu selection:


Part/Zoning/Import

Release 15.0

Writing User Subroutines


Displaying a Message to the User

Usage:

CALL USR_MESSAG ('message to be displayed')


CALL USR_MESSAG (TEXT)

Purpose:

Displays a message in the message panel

Call subroutine USR_MESSAG


displays message in message
panel
continues automatically

Call subroutine USR_ERROR


displays message in a pop-up
error window
requires user OK to continue

2013 ANSYS, Inc.

August 5, 2013

25

Usage:

CALL USR_ERROR (title,'message to be displayed')


CALL USR_ERROR (TITLE,TEXT)

Purpose:

Displays a message in an error window


e.g.
CALL
USR_ERROR(Warning
!,Inconsistent
parameters)

Release 15.0

Writing User Subroutines


Asking the User a Question

Call subroutine GETYON


Usage:

CALL GETYON (YON, 'Question');

Purpose:

Presents a question in the message area and awaits a yes/no answer.


"YON" is the answer ("Y" or "N", no other input is accepted). Maximum text
length is 80 characters.

Example:

CHARACTER*1 YON
CALL GETYON (YON, 'Stop run - are you sure?')
IF (YON=='Y') STOP

2013 ANSYS, Inc.

August 5, 2013

26

CALL GETYON (YON, TEXT)

Release 15.0

Writing User Subroutines


Ways to terminate execution if an error is detected in a User
Subroutine
Put a STOP statement in the user subroutine
Immediately terminates the program and returns to the operating system
May loose information contained in output buffers

Call subroutine ADQUIT


This will return you to the operating system in an orderly manner
Usage:

CALL ADQUIT ('Message to be displayed')


CALL ADQUIT(TEXT)

Purpose:

Terminates AUTODYN EXECUTION immediately.

Example:

CALL ADQUIT ('Error #1 in routine EXEOS')

To stop executing a problem without quitting AUTODYN, set the


wrapup switch NSWRAP (in module WRAPUP) equal to 99
AUTODYN stops execution at the end of the current cycle and returns to the
main menu
The message Problem terminated by user subroutine is displayed
Calculations will continue to the end of the current cycle, so set return
parameters to reasonable values so that they can be used without
consequence, if necessary
2013 ANSYS, Inc.

August 5, 2013

27

Release 15.0

Writing User Subroutines


Hands-on Example #1
Write a user subroutine, EXVEL, to apply a sinusoidal X-velocity
boundary condition with amplitude A m/s and frequency T ms
Ux = A sin t, where = 2/T
Use input parameters #1 and #2 to read values for T and A
Compile and link the user subroutine
Run the executable and load the file usersub_example_1.ad
Define the boundary condition with T = 1.0E-4 and A = 100.0
Apply the boundary condition to I=1.
Run the calculation to the wrapup cycle
View X-velocity vs time at the 5 gauge locations

2013 ANSYS, Inc.

August 5, 2013

28

Release 15.0

Writing User Subroutines


Two formats for dynamic data are used in AUTODYN to store mesh
(node and element) data
Structured (IJK based)

Used for structured Lagrange, Euler, ALE, Shell and Beam meshes (grids)
Data can be accessed directly in the dynamically allocated grid arrays
(fastest)
Functions can optionally be used to assist retrieval and storage of grid
data
Must be used to access data in multi-material Euler cells

Unstructured solvers

Used for unstructured Lagrange, Shell and Beam meshes


No direct access
Functions available to assist access (retrieve / store) node and element
data

2013 ANSYS, Inc.

August 5, 2013

29

Release 15.0

Writing User Subroutines


Accessing Data in Structured Meshes
Current Part number is stored in NSUB (module SUBDEF)
Current Part name is stored in NAMSUB(NSUB) (module SUBDEF)
To change the current Part by number:
NSUB = nsub_new
CALL GETSUB

To change the current Part by name:


USE SUBDEF
DO NS = 1, NUMSUB
IF (NAMSUB(NS) /= New Part name) CYCLE
NSUB = NS
EXIT
END DO
CALL GETSUB
2013 ANSYS, Inc.

August 5, 2013

30

Release 15.0

Writing User Subroutines


FUNCTION IJKSET (3D only)

Usage: IJK = IJKSET3 (I,J,K)


Purpose: Gets the IJK index of node/zone (I,J,K) relative to the current Part
FUNCTION IJSET (2D only)

Usage: IJ = IJSET (I,J)


Purpose: Gets the IJ index of node/zone (I,J) relative to the current Part
FUNCTION IJKSETS (3D only)

Usage: IJKS = IJKSETS3 (I,J,K,N)


Purpose: Gets the IJK index of node/zone (I,J,K) relative to any Part, where
N is the Part number (in order of definition, starting with 1).

FUNCTION IJSETS (2D only)

Usage: IJS = IJSETS (N,I,J)


Purpose: Gets the IJK index of node/zone (I,J) relative to any Part, where N
is the Part number (in order of definition, starting with 1).
2013 ANSYS, Inc.

August 5, 2013

31

Release 15.0

Writing User Subroutines


SUBROUTINE IJANDK (inverse of IJKSET) (3D only)

Usage: CALL IJANDK3 (IJKIN,I,J,K) ; IJKIN is input, I,J, and K are output
Purpose: Gets the I,J, and K indices for IJK relative to the current Part
SUBROUTINE IANDJ (inverse of IJSET) (2D only)

Usage: CALL IANDJ (IJIN,I,J) ; IJIN is input, I and J are output


Purpose: Gets the I and J indices for IJ relative to the current Part
SUBROUTINE IJANDKS (inverse of IJKSETS) (3D only)

Usage: CALL IJANDKS3 (IJKSIN,I,J,K) ; IJKSIN is input, I,J, and K are output
Purpose: Gets the I,J, and K indices for IJK relative to any Part
SUBROUTINE IANDJS (inverse of IJSETS) (2D only)

Usage: CALL IANDJS (IJSIN,I,J,M,IJKL);IJSIN is input, I,J,M and IJKL are


output
Purpose: Gets the I and J indices for IJK relative to the any Part. Also
output is the Part number M and the local IJK for that Part.
2013 ANSYS, Inc.

August 5, 2013

32

Release 15.0

Writing User Subroutines


Direct access of AUTODYN Part variables

2D (node & cell/element), 3D (node)

Variable = var(IJ), e.g. pressure = PN(IJ)


3D (cell/element)
variable = MTSUB(IJK)%V(Nvar)
or
ML => MTSUB(IJK)%V(1:NUMMLV)
variable = ML(Nvar),
e.g. pressure = ML(NPN)
See Appendix B for a full list of variables (var)

2013 ANSYS, Inc.

August 5, 2013

33

Release 15.0

Writing User Subroutines


Indirect access to AUTODYN Part variables
FUNCTION GV
Usage: GV (NV,IJ) / GV3(NV,IJK)
Purpose: Gets the value of Part variable NV for the node/element IJK
relative to current Part

FUNCTION GVS
Usage: GVS (NV,IJS) / GVS3(NV,IJKS)
Purpose: Gets the value of Part variable NV for the node/element IJS
/ IJKS relative to any Part

SUBROUTINE PUTGVS
Usage: CALL PUTGVS (NV,IJS,VALUE) / CALL PUTGVS3 (NV,IJKS,VALUE) ;
all values are input
Purpose: Puts (stores) the VALUE of Part variable NV for the
node/element IJS / IJKS in the dynamic storage arrays.

Module mdgrid / mdgrid3 lists values for NV


2013 ANSYS, Inc.

August 5, 2013

34

Release 15.0

Writing User Subroutines


Indirect access to AUTODYN Part variables

FUNCTION GETV3 (3D only)


Usage: GETV3 (NV,IJK,MODE)
Purpose: This is a general function that gets the variable NV for zone IJK
for the current Part. Depending on the value of MODE the following
actions are taken:
MODE=0 : gets zonal variable NV (calls GV3)
MODE>0 : gets multi-material variable NV for MAT=MODE
MODE<0 : gets volume weighted average over all materials for multimaterial variable NV.

2013 ANSYS, Inc.

August 5, 2013

35

Release 15.0

Writing User Subroutines


Accessing Euler Multi-material Data
CALL GETMLT (IJ,0) or CALL GETMLT3 (IJK,0)

Note: Material names are stored in


MATERIALS(matno)%NAME
Store the updated Euler
Multi-material Data
CALL PUTMLT (IJ,0) or

CALL PUTMLT3 (IJK,0)


2013 ANSYS, Inc.

August 5, 2013

Multi-material variable

Internal array

Material volume fraction

CVF(1,matno)

Material mass

CMS(1,matno)

Material compression

CMU(1,matno)

Material internal energy

CEN(1,matno)

Material temperature

CTP(1,matno)

Material alpha

CAL(1,matno)

Material burn fraction

CBF(1,matno)*

Material damage

CDM(1,matno)*

Material plastic strain

CPS(1,matno)*

AUTODYN-3D only

36

Release 15.0

Writing User Subroutines


Accessing Multi-material Data for Face Operations (2 cells)
CALL GETMLT (IJ1,IJ2) [2,1]

IJ1

IJ1

IJ2

IJ2

CVF(1,M) CVF(2,M)

0.25

0.15

0.0

0.0

CVF(1,M) CVF(2,M)

0.4

0.0

0.25

0.15

0.0

0.0

0.0

0.5

0.4

0.0

0.0

0.5

CALL PUTMLT (IJ1,IJ2) [2,3]


2013 ANSYS, Inc.

August 5, 2013

37

Release 15.0

Writing User Subroutines


Accessing Data in Unstructured Meshes

Node and element variables must be accessed and stored using the
following function calls
CALL GET_ELEM_VAR (index_elem, index_layer)
CALL GET_NODE_VAR (index_node, index_layer)
CALL PUT_ELEM_VAR (index_elem, index_layer)
CALL PUT_NODE_VAR (index_node, index_layer)
where
index_elem is the internal index for an element
index_node is the internal index for a node
index_layer is the layer (integration point) number for each
element/node

2013 ANSYS, Inc.

August 5, 2013

38

Release 15.0

Writing User Subroutines


Accessing Data in Unstructured Meshes
To access node and element variables:
USE mdvar_all
RVL(index_var) contains all real variables for the element/node
IVL(index_var) contains all integer variables for the
element/node
Example:
CALL GET_ELEM_VAR(index_elem,index_layer)
PRESSURE = RVL(IVR_PRESSURE)
..
..
RVL(IVR_PRESSURE) = PRESSURE
CALL PUT_ELEM_VAR(index_elem,index_layer)

Values of index_var for all variable are listed in Appendix B

2013 ANSYS, Inc.

August 5, 2013

39

Release 15.0

Writing User Subroutines


Accessing Data in Unstructured Meshes

Retrieving and updating unstructured element or node data requires the

global index_elem or index_node as input


For material modeling user subroutines, the index of the current element
will be available via
USE mdstring
Index_elem = ELEM_NOW
For other user subroutines, the index can be obtained by
Direct access through user element numbers
Access to all elements in a Part
Access to all elements in a Component
Access to all elements in a Group

2013 ANSYS, Inc.

August 5, 2013

40

Release 15.0

Writing User Subroutines


Accessing Data in Unstructured Meshes

To obtain the Part number for a known Part name:


USE mdpart
INTEGER(INT4) :: NPART, NPART_WANTED
NPART_WANTED = 0
DO NPART = 1, NUM_PARTS
IF (PARTS(NPART)%P%NAME/=Part name) CYCLE
NPART_WANTED = NPART
END DO
! ERROR, PART NOT FOUND
IF (NPART_WANTED= = 0) CALL USR_ERROR (ERROR !, PART NOT
FOUND)

2013 ANSYS, Inc.

August 5, 2013

41

Release 15.0

Writing User Subroutines


Accessing Data in Unstructured Meshes

Direct access through user element numbers


User element numbers can be viewed in plots
USE mdstring
IMPLICIT NONE
INTEGER(INT4) :: NEL_USER, NEL, N
NEL = 0
DO N = 1, NUM_ENTITY_ENTRIES(TYPE_ELEM)
IF (ENTITY_TYPES(TYPE_ELEM)%ID(N)==NEL_USER) THEN
NEL = N
EXIT
END IF
END DO
2013 ANSYS, Inc.

August 5, 2013

42

Release 15.0

Writing User Subroutines


Access to all elements in an unstructured Mesh
USE mdpart
USE mdvar_all
USE mdsolv
IMPLICIT NONE
INTEGER(INT4) :: NPART, N, NEL, NINST
! LOOP OVER ALL UNSTRUCTURED PARTS
DO NPART = 1, NUM_PARTS
PART => PARTS(NPART)%P
IF (PART%ELEM_CLASS/=ICLASS_VOLUME) CYCLE ! SKIP NON-SOLID ELEMENTS
! LOOP OVER ELEMENTS IN PART
DO N = 1, PART%NUMELM
NEL = PART%ELEMENT_LIST(N) ! OBTAIN GLOBAL INTERNAL INDEX OF ELEMENT
! COPY ELEMENT VARIABLES INTO LOCAL VARIABLE VECTOR
NINST = 0
CALL GET_ELEM_VAL(NEL,NINST)
! CALCULATE IMPEDANCE AND PLACE IT IN VAR01
RVL(IVR_VAR01) = RVL(IVR_DENSITY)*RVL(IVR_SOUNDSPEED)
! COPY UPDATED LOCAL ELEMENT DATA BACK TO MAIN STORAGE
CALL PUT_ELEM_VAL(NEL,NINST)
END DO
END DO
2013 ANSYS, Inc.

August 5, 2013

43

Release 15.0

Writing User Subroutines


Hands-on Example #2

User-defined Variables for Structured Meshes


Write a user subroutine, EXEDIT, to define two user variables (VAR01,

VAR02) to:
store the maximum pressure over time for each element / cell
store the impedance (c) of the material with the largest volume
fraction in each element / cell
Use the user executable for a 2D blast analysis

2013 ANSYS, Inc.

August 5, 2013

44

Release 15.0

Writing User Subroutines


Hands-on Example #3

User-defined Variables for Unstructured Meshes


Write a user subroutine, EXEDIT3, to define two user variables (VAR01,

VAR02) to:
store the maximum von-Mises stress over time for each element
store the time at which this maximum stress occurs in each element
Use the user executable for a 3D Taylor test analysis

2013 ANSYS, Inc.

August 5, 2013

45

Release 15.0

Writing Material Modeling Routines


Modularized Material Modeling Routines let you:

Build an input GUI


Check the consistency of input parameters
Map input parameters to solver parameters
Write the solver equations
MDEOS_USER_1

Equation of state

MDSTR_USER_1

Strength (Yield and/or Shear) Model

MDFAI_USER_1

Failure criteria

MDERO_USER_1

Erosion criteria

2013 ANSYS, Inc.

August 5, 2013

46

Release 15.0

Writing Material Modeling Routines


Example Layout : Strength Model
Module STR_USER_1
(Declare scalar and array variables used in the model here)
INIT_STR_USER_1
(Define input parameters and create a menu to read them in)
SET_STR_USER_1
(Copy input parameters to solver scalar/array variables)
CHECK_STR_USER_1
(Check that input parameters are valid)
SOLVE_STR_USER_1
(Strength model solver)

2013 ANSYS, Inc.

August 5, 2013

47

Release 15.0

Writing Material Modeling Routines


Example : Strength Model

monotonic increasing

2013 ANSYS, Inc.

August 5, 2013

48

Release 15.0

Writing Material Modeling Routines


Module STR_USER_1
Purpose: Define scalar / array variables used by the solver

Example
MODULE STR_USER_1
USE kindef
IMPLICIT NONE
SAVE
! SPECIFY COMMON VARIABLES TO BE ACCESSED BY ROUTINES BELOW
HERE
! INTEGER(INT4) ::
! REAL(REAL8) ::
REAL (REAL8), DIMENSION(3) :: EP, YS
END MODULE STR_USER_1

2013 ANSYS, Inc.

August 5, 2013

49

Release 15.0

Writing Material Modeling Routines


Subroutine INIT_STR_USER_1

Purpose: Initialization / Set up input menus


Example
Default coding

Custom coding

SUBROUTINE INIT_STR_USER_1(IFACT)
.
.
EQ%NAME = 'User Strength #1'
EQ%NPAR = 11 ! NUMBER OF REAL INPUT PARAMETERS
! FOR EACH REAL INPUT PARAMETER, ASSIGN DATA
! ('name ' L, T,M,H, val, min,max,default,0,required)
EQ%PAR(1)=PRMT (1,'Shear Modulus',-1,-2,1,0,ZERO,ZERO,BIG,ZERO ,0,1)
EQ%PAR(2)=PRMT (2,'SC(2)'
,-1,-2,1,0,ZERO,ZERO,BIG,ZERO ,0,0)
EQ%PAR(3)=PRMT (3,'SC(3)'
,-1,-2,1,0,ZERO,ZERO,BIG,ZERO ,0,0)
EQ%PAR(4)=PRMT (4,'SC(4)'
,-1,-2,1,0,ZERO,ZERO,BIG,ZERO ,0,0)
EQ%PAR(5)=PRMT (5,'SC(5)'
,-1,-2,1,0,ZERO,ZERO,BIG,ZERO ,0,0)
EQ%PAR(6)=PRMT (6,'SC(6)'
,-1,-2,1,0,ZERO,ZERO,BIG,ZERO ,0,0)
EQ%PAR(7)=PRMT (7,'SC(7)'
,-1,-2,1,0,ZERO,ZERO,BIG,ZERO ,0,0)
EQ%PAR(8)=PRMT (8,'SC(8)'
,-1,-2,1,0,ZERO,ZERO,BIG,ZERO ,0,0)
EQ%PAR(9)=PRMT (9,'SC(9)'
,-1,-2,1,0,ZERO,ZERO,BIG,ZERO ,0,0)
EQ%PAR(10)=PRMT(10,'SC(10)'
,-1,-2,1,0,ZERO,ZERO,BIG,ZERO ,0,0)
EQ%PAR(11)=PRMT(11,'SC(11)'
,-1,-2,1,0,ZERO,ZERO,BIG,ZERO ,0,0)
.
.

2013 ANSYS, Inc.

August 5, 2013

SUBROUTINE INIT_STR_USER_1 (IFACT)


.
.
EQ%NAME = User Hardening'
EQ%NPAR = 7 ! NUMBER OF REAL INPUT PARAMETERS
! FOR EACH REAL INPUT PARAMETER, ASSIGN DATA
! ('name ' L, T,M,H, val, min,max,default,0,required)
EQ%PAR(1)=PRMT (1,'Shear Modulus',-1,-2,1,0,ZERO,ZERO,BIG,ZERO ,0,1)
EQ%PAR(2)=PRMT (2,'EPS #1'
, 0, 0,0,0,ZERO,ZERO,BIG,ZERO ,0,0)
EQ%PAR(3)=PRMT (3,'EPS #2'
, 0, 0,0,0,ZERO,ZERO,BIG,ZERO ,0,0)
EQ%PAR(4)=PRMT (4,'EPS #3'
, 0, 0,0,0,ZERO,ZERO,BIG,ZERO ,0,0)
EQ%PAR(5)=PRMT (5,'YIELD #1' ,-1,-2,1,0,ZERO,ZERO,BIG,ZERO ,0,0)
EQ%PAR(6)=PRMT (6,'YIELD #2' ,-1,-2,1,0,ZERO,ZERO,BIG,ZERO ,0,0)
EQ%PAR(7)=PRMT (7,'YIELD #3' ,-1,-2,1,0,ZERO,ZERO,BIG,ZERO ,0,0)
....
....

50

Release 15.0

Writing Material Modeling Routines


Subroutine SET_STR_USER_1

Purpose: Copy input parameters to solver scalar/array variables


Example
Default coding

Custom coding

SUBROUTINE SET_STR_USER_1
USE material
USE str_user_1
IMPLICIT NONE
! *****************************************************
! THIS SUBROUTINE ASSIGNS SHORTCUTS
! FOR DIRECT USE IN THE SOLVER
! *****************************************************
SHRMDZ = EQ%PAR(1)%VAL
SC(1) = EQ%PAR(1)%VAL
SC(2) = EQ%PAR(2)%VAL
SC(3) = EQ%PAR(3)%VAL
SC(4) = EQ%PAR(4)%VAL
SC(5) = EQ%PAR(5)%VAL
SC(6) = EQ%PAR(6)%VAL
SC(7) = EQ%PAR(7)%VAL
SC(8) = EQ%PAR(8)%VAL
SC(9) = EQ%PAR(9)%VAL
SC(10) = EQ%PAR(10)%VAL
SC(11) = EQ%PAR(11)%VAL
RETURN
END SUBROUTINE SET_STR_USER_1

2013 ANSYS, Inc.

August 5, 2013

SUBROUTINE SET_STR_USER_1
USE material
USE str_user_1
IMPLICIT NONE
! *****************************************************
! THIS SUBROUTINE ASSIGNS SHORTCUTS
! FOR DIRECT USE IN THE SOLVER
! *****************************************************
SHRMDZ = EQ%PAR(1)%VAL
EP(1) = EQ%PAR(2)%VAL
EP(2) = EQ%PAR(3)%VAL
EP(3) = EQ%PAR(4)%VAL
YS(1) = EQ%PAR(5)%VAL
YS(2) = EQ%PAR(6)%VAL
YS(3) = EQ%PAR(7)%VAL
RETURN
END SUBROUTINE SET_STR_USER_1

51

Release 15.0

Writing Material Modeling Routines


Subroutine CHECK_STR_USER_1
Purpose: Check that input parameters are valid

Example
SUBROUTINE CHECK_STR_USER_1
USE material
USE str_user_1
IMPLICIT NONE
INTEGER (INT4) :: IERROR
! ************************************************************************
! THIS SUBROUTINE CHECKS EOS INPUT DATA
! ************************************************************************
! PLACE USER CHECKS HERE
! CHECK THAT EPS IS MONOTONICALLY INCREASING
IERROR = 0
IF (EP(1)>EP(2).OR.EP(1)>EP(3)) IERROR = 1
IF (EP(2)>EP(3)) IERROR = 1
IF (IERROR==1) THEN
CALL USR_ERROR (' ERROR !','USER STRENGTH MODEL. Plastic strain must be monotonically
increasing.')
END IF
RETURN
END SUBROUTINE CHECK_STR_USER_1

2013 ANSYS, Inc.

August 5, 2013

52

Release 15.0

Writing Material Modeling Routines


Subroutine SOLVE_STR_USER_1_2D/3D
Purpose: Solver routine for Strength Model

Example
SUBROUTINE SOLVE_STR_USER_1_2D
(PRES,TT1,TT2,TT3,XMUT,EPST,EPSD,TEMPT,DAMAGE,YIELDT,IFAIL)
.
! SUBROUTINE CALLED BY ALL STRENGTH MODELS SO SKIP OUT, BY DEFAULT
IF (NSTR/=IMF_STR_USER_1) GO TO 900
! THIS ROUTINE IS ONLY WRITTEN FOR TANTALUM.
! CHECK THAT NO OTHER MATERIAL TRIES TO USE THIS ROUTINE.
IF (MTL%NAME(1:8)/='TANTALUM') THEN
CALL USR_MESSAG ('USER STRENGTH MODEL called for invalid material')
NSWRAP = 99
YIELDT = ZERO
GO TO 900
END IF

2013 ANSYS, Inc.

August 5, 2013

53

Release 15.0

Writing Material Modeling Routines

! SET CURRENT YIELD STRESS


! PLASTIC STRAIN LESS THAN EP(1)
IF (EPST<=EP(1)) THEN
YIELDT = YS(1)
! PLASTIC STRAIN GREATER THAN EP(3)
ELSE IF (EPST>=EP(3)) THEN
YIELDT = YS(3)
! INTERPOLATE YIELD STRESS FROM YP VS. EP CURVE
ELSE
DO I = 2,3
IF (EPST<=EP(I)) THEN
IM = I-1
YIELDT = YS(IM) + (YS(I)-YS(IM))*(EPST-EP(IM))/(EP(I)-EP(IM))
END IF
END DO
END IF

900 RETURN
END SUBROUTINE SOLVE_STR_USER_1_2D

2013 ANSYS, Inc.

August 5, 2013

54

Release 15.0

Writing Material Modeling Routines


Hands-on Example #4

Write a user failure model, to


Compute damage as a integral function of pressure
Reduce the hydrodynamic failure strength linearly as damage increases
Activate crack softening when failure occurs

2013 ANSYS, Inc.

August 5, 2013

55

Release 15.0

Using The Debugger

Insert breakpoints so that AUTODYN will


pause at these inserted breakpoints

2013 ANSYS, Inc.

August 5, 2013

56

Release 15.0

Using The Debugger


Start the debugger

2013 ANSYS, Inc.

August 5, 2013

57

Release 15.0

Using The Debugger

Subroutine is not protected from invalid


operations (i.e. divisor is zero)

2013 ANSYS, Inc.

August 5, 2013

58

Release 15.0

Using The Debugger

Insert the following lines to


protect from invalid operations
(i.e. divisor is zero)

2013 ANSYS, Inc.

August 5, 2013

59

Release 15.0

Using The Debugger

Subroutine is now protected


from invalid operations (i.e.
divisor is zero)

2013 ANSYS, Inc.

August 5, 2013

60

Release 15.0

User Subroutines

Workshop

2013 ANSYS, Inc.

August 5, 2013

61

Release 15.0

Você também pode gostar