4.8.2.7. MOTION

This subroutine defines a user - defined motion. This subroutine can be used for translational joint, rotational joint, cylindrical joint and PTCV.

Table 4.26 Function Name

Language type

Subroutine

FORTRAN

motion_usub (TIME,UPAR,NPAR,IORD,IFLAG,RESULT)

C/C++

motion_usub (double time, double upar[], int npar, int iord, int iflag, double *result)

Table 4.27 Parameter information

Variable Name

Size

Description

time

double

Current simulation time of RecurDyn/Solver.

upar

double[30]

Parameters defined by the user. The maximum size of array is 30.

npar

int

Number of user parameters.

iord

int

Integrator order.

iflag

int

When RecurDyn/Solver makes its initial call to this routine, the flag is true. Otherwise, the flag is false.

result

double

Returned value and one-dimensional variable.

Example

../_images/image322.gif

Figure 4.111 Example Model using Motion User Subroutine

Note

If the user wants to run this model using a user subroutine, the user can refer it in the directory (<install dir>\Help\usub\**).

Motion User Subroutine can only be used as displacement.

Listing 4.13 Fortran code for Motion
 C---- SUB. MOTION_USUB
       SUBROUTINE MOTION_USUB
     &          (TIME,UPAR,NPAR,IORD,IFLAG,RESULT)
 C---- TO EXPORT * SUBROUTINE
       !DEC$ ATTRIBUTES DLLEXPORT,C::MOTION_USUB

 C---- INCLUDE SYSTEM CALL
       INCLUDE 'SYSCAL.F'

 C---- DEFINE VARIABLES
 C     Parameter Information
 C     TIME   : Simulation time of RD/Solver. (Input)
 C     UPAR   : Parameters defined by user. (Input)
 C     NPAR   : Number of user parameters. (Input)
 C     IORD   : Integrator order. (Input)
 C     IFLAG  : When RD/Solver initializes arrays, the flag is true. (Input)
 C     RESULT : Returned value. (Output)

       DOUBLE PRECISION TIME, UPAR(*)
       INTEGER NPAR, IORD
       LOGICAL IFLAG
       DOUBLE PRECISION RESULT[REFERENCE]

 C---- USER STATEMENT
       DOUBLE PRECISION SHIFT, OMEGA
       DOUBLE PRECISION VALUE
       DOUBLE PRECISION COEF(3)
       LOGICAL ERRFLG

       SHIFT = UPAR(1)
       OMEGA = UPAR(2)
       COEF(1) = UPAR(3)
       COEF(2) = UPAR(4)
       COEF(3) = UPAR(5)

       CALL RD_FORCOS(TIME, SHIFT, OMEGA, COEF, 3, IORD, VALUE, ERRFLG)

       RESULT = VALUE

       RETURN
       END
Listing 4.14 C/C++ code for Motion
 #include "stdafx.h"
 #include "DllFunc.h"

 Motion_API void __cdecl motion_usub
   (double time, double upar[], int npar, int iord, int iflag, double* result)
 {
   using namespace rd_syscall;
   // Parameter Information
   //   time    :  Simulation time of RD/Solver. (Input)
   //   upar    :  Parameters defined by user. (Input)
   //   npar    :  Number of user parameters. (Input)
   //   iord    :  Integrator order. (Input)
   //   iflag   :  When RD/Solver initializes arrays, the flag is true. (Input)
   //   result  :  Returned value. (Output)

   // User Statement
   // Local Variable Definition
   double shift, omega;
   double value;
   double coef[3];
   int errflg;

   // Assign Impact Parameter
   shift=upar[0];
   omega=upar[1];
   coef[0]=upar[2];
   coef[1]=upar[3];
   coef[2]=upar[4];

   // Call the RD_FORCOS to collect Information for Calculation
   rd_forcos(time, shift, omega, coef, 3, iord, &value, &errflg);

   // Return the value
   *result=value;
 }