4.8.3.8. FORSIN

Table 4.61 Function Name

Language type

Subroutine

FORTRAN

call rd_forsin(x, x0, w, upar, npar, order, value, errflg) or forsin(x, x0, w, upar, npar, order, value, errflg)

C/C++

rd_forsin(x, x0, w, upar, npar, order, &value, &errflg) or forsin(x, x0, w, upar, npar, order, &value, &errflg)

Table 4.62 Parameter information

Variable Name

Size

Description

x

double

The input variable for the defined Fourier sine series.

x0

double

The x-direction offset for the variable (x) in the Fourier sine series.

w

double

The base frequency for the Fourier sine series (in radians).

upar

double*

Argument list array. This array have to contain coefficient for the Fourier sine series.

npar

int

Number of arguments in the argument list array.

order

int

The order can be 3 values. (order = 0, 1 or 2.)

value

double

  1. order = 0

    \(Value=c_0+\sum\limits_{j=1}^{npar}{c_j}\times \sin (j\times \omega \times (x-x_0))\)

    where,

    \(c_j\) is coefficient for Fourier sine series.

    \(c_j\) is same as \(upar(j)\).

  2. order = 1

    \(Value=\sum\limits_{j=1}^{npar}{\left( (j\times \omega )\times {{c}_{j}}\times \cos (j\times \omega \times (x-{{x}_{0}})) \right)}\)

  3. order = 2

    \(Value=-\sum\limits_{j=1}^{npar}{\left( {{(j\times \omega )}^{2}}\times {{c}_{j}}\times \sin (j\times \omega \times (x-{{x}_{0}})) \right)}\)

errflg

int

Error flag. If the result of this argument is zero, there’s no error

Listing 4.46 Fortran code for FORSIN
 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 CORF(3)
       LOGICAL ERRFLG

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

       CALL RD_FORSIN(TIME,SHIFT,OMEGA,COEF,3,IORD,VALUE,ERRFLG)
       RESULT = VALUE

       RETURN
       END
Listing 4.47 C/C++ code for FORSIN
 #include "stdafx.h"
 #include "DllFunc.h"

 FORSIN_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_FORSIN to collect Information for Calculation
   rd_forsin(time,shift,omega,coef,3,iord,&value,&errflg);

   //return the value
   *result = value;

 }