4.8.2.11. ROTATIONAL_FORCE

This subroutine defines a user - defined rotational force vector.

Table 4.33 Function Name

Language type

Subroutine

FORTRAN

rotational_force (time,upar,npar,jflag,iflag,result)

C/C++

rotational_force (double time, double upar[], int npar, int jflag, int iflag, double result[3])

Table 4.34 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.

jflag

int

When RecurDyn/Solver evaluates the Jacobian, the flag is true. Otherwise, the flag is false.

iflag

int

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

result

double[3]

Returned force vector and three-dimensional variable.

Example

../_images/image327.gif

Figure 4.115 Example Model using Rotational Force 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\**).

Listing 4.21 Fortran code for Rotational Force
 C---- SUB. ROTATIONAL_FORCE
       SUBROUTINE ROTATIONAL_FORCE
     &          (TIME,UPAR,NPAR,JFLAG,IFLAG,RESULT)
 C---- TO EXPORT * SUBROUTINE
       !DEC$ ATTRIBUTES DLLEXPORT,C::ROTATIONAL_FORCE

 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     JFLAG  : When RD/Solver evaluates a Jacobian, the flag is true. (Input)
 C     IFLAG  : When RD/Solver initializes arrays, the flag is true. (Input)
 C     RESULT : Returned value. (Output)

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

 C---- USER STATEMENT
 C---- LOCAL VARIABLE DEFINITIONS
       INTEGER I
       INTEGER MINUS(3)
 DOUBLE PRECISION PI
       DOUBLE PRECISION VALUE(3)

 C---- ASSIGN IMPACT PARAMETERS
 PI = DACOS(-1.0d0)
       MINUS(1) = UPAR(1)
       MINUS(2) = UPAR(2)
       MINUS(3) = UPAR(3)

 DO I=1, 3
 IF(MINUS(I) .NE. 0) THEN
 VALUE(I) = -(((4*PI)**2)/3)**0.5;
 ELSE
 VALUE(I) = (((4*PI)**2)/3)**0.5;
 ENDIF
 ENDDO

 C---- ASSIGN THE RETURNED VALUE
       RESULT(1) = VALUE(1)
 RESULT(2) = VALUE(2)
 RESULT(3) = VALUE(3)

       RETURN
       END
Listing 4.22 C/C++ code for Rotational Force
 #include "stdafx.h"
 #include "DllFunc.h"
 #define _USE_MATH_DEFINES // for C
 #include <math.h>

 TranslationalForce_API void __cdecl translational_force(double time, double upar[], int npar, int jflag, int iflag, double result[3])
 {
   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)
   //   jflag   : When RD/Solver evaluates a Jacobian, the flag is true. (Input)
   //   iflag   : When RD/Solver initializes arrays, the flag is true. (Input)
   //   result  : Returned value. (Output)

   // User Statement
   // Local Variable Definition
   int minus[3];
   double value[3];

   // Assign Impact Parameters
   minus[0] = (int) upar[0];
   minus[1] = (int) upar[1];
   minus[2] = (int) upar[2];

   for (int i = 0; i < 3; i++)
   {
     if (minus[i] != 0)
     {
       value[i] = -pow((pow(4*M_PI, 2))/3, 0.5);
     }
     else
     {
       value[i] = pow((pow(4*M_PI, 2))/3, 0.5);
     }
   }

   // Assign the Returned Value
   result[0] = value[0];
   result[1] = value[1];
   result[2] = value[2];
 }