8.6.4. Common Parameters in a User Subroutine

The function and its parameters must first be defined to write the User Subroutine. As shown in the figure below and table, the function type must be defined as a void function with several options.

Figure 8.49: Function type in a User Subroutine

ContentDescription
extern "C" DLLEXPORTThe function type and options for exporting. The DLLEXPORT keyword means __declspec(dllexport) void __cdecl which is defined in the header file of defusub.h.
get_dispThe function name of User Subroutine. This name is not fixed for each user subroutine and can be freely defined. This name must be set in the 9th step as shown as shown in Figure 8.43: User Subroutine sub-entity window.

Figure 8.50: Common parameters in a User Subroutine

Common parameters in a User Subroutine

Every Motion User Subroutine has common input parameters as shown in the table below. Additionally, several user subroutines such as contact, matrix force and concentrated load have special parameters which will be introduced in each corresponding section.

Figure 8.51: Common parameters for a User Subroutine

ParameterTypeDescription
slvidVoid *The pointer of the user subroutine in Motion solver. This pointer is used when calling Intrinsic Functions in a User Subroutine. This pointer must not be changed in the subroutine.
timeConstant Double PrecisionSimulation time, which is not changed in the subroutine.
upar []Double Precision Array

User parameters, which are defined the 6th step as shown in Figure 8.43: User Subroutine sub-entity window. The values in the array can be changed in the subroutine. Also, if the value is the ID of an entity, it must be cast to the integer variable type. For example,

DF_INT marker_id;

marker_id = (DF_INT) upar[0];

nparConstant IntegerThe number of user parameters, which is not changed in the subroutine.
jflagConstant IntegerThe Jacobian flag, which is not changed in the subroutine. When the Motion solver evaluates the Jacobian matrix, this flag is set to one. Otherwise, this flag is zero.
sflagConstant IntegerThe solution flag, which is not changed in the subroutine. When the Motion solver initializes the user subroutine, this flag is set to one. In this case, every intrinsic function which uses the ID of an entity must be called. When the Motion solver completes a successful iteration at each time step, this flag is set to two. If you want to report intermediate values, you can utilize this option.
value [] or valueDouble Precision Array or Double Precision

The return values, which must be initialized with zero in the subroutine. If the number of the return value is one, this must be defined as a double precision refereence as follows.

DF_DOUBLE &value