## Chapter 2: How to Invoke User Subroutines

To explain how user subroutines are invoked in Autodyn we will look at a specific example. Most user subroutines require a specification of user for a particular input specification. However, some user subroutines are always called as discussed in Timing of Calls to User Subroutines.

In the following example, a sample user subroutine (supplied with the ANSYS install) is used to demonstrate how to create a user subroutine project, compile a user subroutine into a custom Autodyn executable, launch the custom-compiled Autodyn executable, and finally run a model which invokes the user subroutine.

## Tantalum Bar Example

Start Autodyn on your computer and from the main menu load cycle zero of the problem user_strength_example_0.ad (found in the folder \ANSYS Inc\v182\aisol\Samples\AUTODYN).

Use the options on the Plots menu to see the material locations and boundary conditions for the problem. You will see that the problem consists of a tantalum cylinder impacting a rigid wall:

Now select the Materials menu, and Review the material data for TANTALUM. You will notice that a Von Mises yield model has been specified for this material. This model allows you to define a constant yield stress.

Suppose that instead of keeping it constant (Von Mises), you want to make the yield stress a function of the effective plastic strain.

First click Modify. In the resulting dialog, expand the Strength section and inspect the available options for yield models. The option Piecewise exists, which could be used to describe such a relationship. However, in the interests of illustrating user subroutines, a user subroutine displaying the same behavior as the piecewise strength model will be used in the ensuing sections. Therefore you will supply your own custom yield model. To enable the use of the strength model user subroutine, change the selected yield option from Von Mises to User Strength #1:

You can now input the variables Shear Modulus (SC(1)), and SC(2) through SC(11), to be used in the MD_STR_USER_1 module. Note that these predefined parameters are only present for demonstration and can be tailored in terms of number of parameters, names, and units. It is also possible to add your own option list and parameters from many of the existing standard Autodyn strength models.

The use of the input parameters allows you to code and link your user subroutine once, and then change variable input values through Autodyn input. The user specifies the usage of these parameters in the MD_STR_USER_1 module.

For the moment, enter a Shear Modulus of 0.692 as before with the Von Mises model, so that you can close and save the data for the Tantalum material.

Save the model and press Run. The error dialog displayed below will be shown because no user subroutine has been written and compiled for User Strength #1. This will be done in the following steps.

1. Save the model, then navigate to the Options menu and select Create User-Subroutine Project. You will be prompted to choose a directory in which the user subroutine project will be created. After the user subroutine project is created, navigate to the directory where it resides. You will see a folder called Autodyn user_subroutines.

2. A user-subroutine for this example has already been created, and is located in the install directory in the folder \v170\aisol\Samples\AUTODYN. Copy the file MDSTR_USER_1.tut to MDSTR_USER_1.f90 in the fsrc directory in the Autodyn user subroutines folder created in Step 1, selecting Yes if asked whether to overwrite the existing file.

3. Navigate back to the Autodyn user_subroutines folder. Here you will find a solution file called ad_usrsub.sln. On Windows, launch this file in Visual Studio (or another IDE) and build the solution (for Linux see Linking your own User Subroutines on Linux Platforms). This will build both an Autodyn executable and a slave executable (for parallel processing) which have the custom user subroutine built in. Launch the resulting compiled master executable (ad_usrsub.exe).

4. Open the file user_strength_example_0 that was saved in Step 1. First head back to the materials menu and select Modify. You will see that the parameters have changed in the strength section (see image below). These parameters can be modified to change the material properties.

5. Press Run, and the problem will solve. The effects of changing the strength model from the user subroutine can be tested by changing the parameters and observed within Autodyn.

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