ANSYS Motion 2019 R3 User Subroutine Tutorial PDF
ANSYS Motion 2019 R3 User Subroutine Tutorial PDF
ANSYS Motion 2019 R3 User Subroutine Tutorial PDF
ANSYS
User Subroutine
Tutorial
ANSYS, Inc.
User Subroutine Tutorial ANSYS, Inc.
Contents
2. Creating a Project............................................................................................................................ 3
2.1. Running the Microsoft Visual Studio 2010 ............................................................................. 3
2.2. Creating a new project ............................................................................................................ 3
-1-
User Subroutine Tutorial ANSYS, Inc.
1. Getting Started
Followings are prerequisite knowledge how to use User Subroutine. It recommend to use Microsoft
Visual Studio 2010 Express Edition, or greater for using Visual C++ language.
Followings are prerequisite knowledge how to use ANSYS Motion/User Subroutine
For more information as above prerequisite knowledge, please refer to the ANSYS
Motion/Preprocessor Manual and Tutorial, ANSYS Motion/Postprocessor Manual and Tutorial,
ANSYS Motion/User Subroutine Manual.
-2-
User Subroutine Tutorial ANSYS, Inc.
2. Creating a Project
Explaining how to create *.dll file for user subroutine. This tutorial is explained by Microsoft
Visual Studio Express Edition 2010. This tutorial was written on 32 bit platform basis. To follow
along with this tutorial, you will need to build with 64 bit platform.
Select Win32 Win32 Console Application Key in 'Contact' in the Name box and
location is 'C:\User_Subroutine' Click OK.(Uncheck create directory for solution).
-3-
User Subroutine Tutorial ANSYS, Inc.
-4-
User Subroutine Tutorial ANSYS, Inc.
Select DLL Check Empty project Click Finish. The new project for User subroutine is
created.
-5-
User Subroutine Tutorial ANSYS, Inc.
When user is compiling by 32-bit, bring the lib file in 32-bit solver. When user is compiling by
64-bit, bring the lib file in 64-bit solver. Copy and paste the dfslv.lib file to project folder.
Lib file is located as follows, (ANSYS Motion install path\Motion\Solver\Windowns\lib)
Click right button of a mouse at the name of the project and select Properties.
-6-
User Subroutine Tutorial ANSYS, Inc.
-7-
User Subroutine Tutorial ANSYS, Inc.
Click Macros
-8-
User Subroutine Tutorial ANSYS, Inc.
Key in $(ProjectDir) in the Additional Library Directories box after confirming setting by All
Configurations.
Click Input and key in dfslv.lib at the Additional Dependencies box. And click OK.
-9-
User Subroutine Tutorial ANSYS, Inc.
4.1. Copy defusub.h file and paste the file in the project folder
- 10 -
User Subroutine Tutorial ANSYS, Inc.
Check contents after double click of the added defusub.h in solution explorer.
- 11 -
User Subroutine Tutorial ANSYS, Inc.
Click mouse right button of project. Select Add select New Item.
- 12 -
User Subroutine Tutorial ANSYS, Inc.
The following code calculated the displacement and velocity by using sysary function after
get Markers, Contact Stiffness, Damping Coefficient and Contact order at upar[]. Then,
calculate a force.
#include "defusub.h"
#include <stdio.h>
#pragma warning(disable : 4996)
#ifdef _MANAGED
#pragma managed(push, off)
#endif
- 13 -
User Subroutine Tutorial ANSYS, Inc.
//input data
mkid[0] = (int)upar[0];
mkid[1] = (int)upar[1];
mkid[2] = (int)upar[2];
k = (double)upar[3];
c = (double)upar[4];
n = (double)upar[5];
radius = (double)upar[6];
nvalue = 6;
//contact force
if (disp[2] < radius)
{
delta[2] = -(disp[2]-radius);
delta_dot[2] = -vel[2];
force[2] = (k*pow(delta[2],n))+(c*delta_dot[2]);
}
else
{
for(i=0; i<6 ; i++)
{
force[i] = 0;
}
}
//return value
for(i=0; i<6 ; i++)
{
value[i] = force[i];
}
}
- 14 -
User Subroutine Tutorial ANSYS, Inc.
- 15 -
User Subroutine Tutorial ANSYS, Inc.
Click the Build at top menu Click Rebuild Solution Bulid the project
Check the type of solution and move to Release folder of low rank. Confirm the created
Contact.dll file.
- 16 -
User Subroutine Tutorial ANSYS, Inc.
Run ANSYS Motion Menu Create New Model Select Standard EMBD Model and
key in the name. Click OK.
- 17 -
User Subroutine Tutorial ANSYS, Inc.
- 18 -
User Subroutine Tutorial ANSYS, Inc.
Create Vector Force . Base Body is ground and Action Body is the sphere body (BD_01) .
Action Marker is a base marker of BD_01/CM and Base Marker is the marker of
Ground/MK_01.
When create Vector Force, refer to table and picture as following.
VECTOR_01
Base Body Ground
Action Body BD_01
Base Position MK_01
Action Position BD_01/CM
.
< Creating Vector Force >
- 19 -
User Subroutine Tutorial ANSYS, Inc.
- 20 -
User Subroutine Tutorial ANSYS, Inc.
7.2. Analysis
<Run button>
<Executed Simulation>
- 21 -
User Subroutine Tutorial ANSYS, Inc.
<Simulation Result>.
- 22 -