4.8.2.4. MATRIX_FORCE

This subroutine defines a user - defined matrix force.

Table 4.20 Function Name

Language type

Subroutine

FORTRAN

matrix_force (TIME ,UPAR,NPAR,DISP,VELO,JFLAG,IFLAG,RESULT,JDISP,JVELO)

C/C++

matrix_force (double time, double upar[], int npar, double disp[6], double velo[6], int jflag, int iflag, double result[6], double jdisp[36], double jvelo[36])

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

disp

double[6]

Displacement vector between two force markers with respect to the base marker

velo

double[6]

Velocity vector between two force markers with respect to the base marker.

jflag

int

When RecurDyn/Solver evaluates 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[6]

Returned value and one-dimensional variable.

jdisp

double[36]

Force Jacobian of displacement and this is thirty-six dimensional arrays.

jvelo

double[36]

Force Jacobian of velocity and this is thirty-six dimensional arrays

Example

../_images/image319.gif

Figure 4.108 Beam model using a Matrix 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.7 Fortran code for Matrix Force
 C---- SUB. MATRIX_FORCE
       SUBROUTINE MATRIX_FORCE
     &          (TIME,UPAR,NPAR,DISP,VELO,JFLAG,IFLAG,
     &           RESULT,JDISP,JVELO)
 C---- TO EXPORT * SUBROUTINE
       !DEC$ ATTRIBUTES DLLEXPORT,C::MATRIX_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     DISP   : Displacement vector between two force markers w.r.t. base marker. (Input)
 C     VELO   : Velocity vector between two force markers w.r.t. base marker. (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 matrix force vector. (Output, Size : 6)
 C     JDISP  : Returned force Jacobian of displacement. (Output, Size : 36)
 C     JVELO  : Returned force Jacobian of velocity. (Output, Size : 36)

       DOUBLE PRECISION TIME, UPAR(*), DISP(*), VELO(*)
       INTEGER NPAR
       LOGICAL JFLAG, IFLAG
       DOUBLE PRECISION RESULT[REFERENCE](6)
       DOUBLE PRECISION JDISP[REFERENCE](36), JVELO[REFERENCE](36)

 C---- USER STATEMENT
       DOUBLE PRECISION TK, TC, RK, RC
       INTEGER I

       TK = UPAR(1)
       TC = UPAR(2)
       RK = UPAR(3)
       RC = UPAR(4)

       IF ( JFLAG ) THEN
         DO I = 1, 36
           JDISP(I) = 0.0D0
           JVELO(I) = 0.0D0
         ENDDO

         JDISP(1) = -TK
         JDISP(8) = -TK
         JDISP(15) = -TK
         JDISP(22) = -RK
         JDISP(29) = -RK
         JDISP(36) = -RK
         JVELO(1) = -TC
         JVELO(8) = -TC
         JVELO(15) = -TC
         JVELO(22) = -RC
         JVELO(29) = -RC
         JVELO(36) = -RC
       ENDIF

       RESULT(1) = - TK * DISP(1) - TC * VELO(1)
       RESULT(2) = - TK * DISP(2) - TC * VELO(2)
       RESULT(3) = - TK * DISP(3) - TC * VELO(3)
       RESULT(4) = - RK * DISP(4) - RC * VELO(4)
       RESULT(5) = - RK * DISP(5) - RC * VELO(5)
       RESULT(6) = - RK * DISP(6) - RC * VELO(6)

       RETURN
       END
Listing 4.8 C/C++ code for Matrix Force
 #include "stdafx.h"
 #include "DllFunc.h"

 MatrixForce_API void __cdecl matrix_force
   (double time, double upar[], int npar, double disp[6], double velo[6],
   int jflag, int iflag, double result[6], double jdisp[36], double jvelo[36])
 {
   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)
   //   disp   : Displacement vector between two force markers w.r.t. base marker. (Input)
   //   velo   : Velocity vector between two force markers w.r.t. base marker. (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 matrix force vector. (Output, Size : 6)
   //   jdisp  : Returned force Jacobian of displacement. (Output, Size : 36)
   //   jvelo  : Returned force Jacobian of velocity. (Output, Size : 36)

   // User Statement
   double tk, tc, rk, rc;
   int i;

   tk = upar[0];
   tc = upar[1];
   rk = upar[2];
   rc = upar[3];

   if ( jflag ) {
     for(i=0;i<36;i++){
       jdisp[i] = 0.0;
       jvelo[i] = 0.0;
     }

     jdisp[0] = -tk;
     jdisp[7] = -tk;
     jdisp[14] = -tk;
     jdisp[21] = -rk;
     jdisp[28] = -rk;
     jdisp[35] = -rk;
     jvelo[0] = -tc;
     jvelo[7] = -tc;
     jvelo[14] = -tc;
     jvelo[21] = -rc;
     jvelo[28] = -rc;
     jvelo[35] = -rc;
   }

   result[0] = - tk * disp[0] - tc * velo[0];
   result[1] = - tk * disp[1] - tc * velo[1];
   result[2] = - tk * disp[2] - tc * velo[2];
   result[3] = - rk * disp[3] - rc * velo[3];
   result[4] = - rk * disp[4] - rc * velo[4];
   result[5] = - rk * disp[5] - rc * velo[5];
 }