4.8.3.3. CHEBY

Table 4.51 Function Name

Language type

Subroutine

FORTRAN

call rd_cheby(x, x0, upar, npar, order, value, errflg) or cheby(x, x0, upar, npar, order, value, errflg)

C/C++

rd_cheby (x, x0, upar, npar, order, &value, &errflg) or cheby (x, x0, upar, npar, order, &value, &errflg)

Table 4.52 Parameter information

Variable Name

Size

Description

x

double

The input variable for the Chebyshev equation.

x0

double

The x-direction offset for the variable (X) in the Chebyshev polynomial

upar

double*

Argument list array. This array contains the coefficient values for Chebyshev polynomial.

npar

int

Number of arguments in the argument list array.

order

int

Return the value if 0, return calculation for 1st order differential equation if 1, and return calculation for 2nd order differential equation if 2.

If oder = 0,

\(value=\sum\limits_{j=0}^{npar}{upar(j)}\cdot {{T}_{j}}(x-x_0), 0\le j\le npar\)

where,

\({{T}_{j}}(x-x_0)=2\cdot (x-x_0)\cdot {{T}_{j-1}}(x-x_0)-{{T}_{j-2}}(x-x_0)\)

\({{T}_{0}}(x-x_0)=1, {{T}_{1}}(x-x_0))=x-x_0\)

value

double

errflg

int

If an error is encountered in invoking Predefined subroutine, this variable becomes true. This variable must be declared as a logical variable

Listing 4.38 Fortran code for CHEBY
 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
 C---- Local Variable Definition
 INTEGER i
       DOUBLE PRICISION value, mkid(5)
       INTEGER errflg

 C---- Assign Impact Parameter
       do i=1,5
         mkid(i) = UPAR(i)
       enddo

 C---- Call RD_CUBSPL to get the result of spline
 call RD_CHEBY(time,0.5,mkid(1),5,0,value, errflg)

 C------- Assign the returned value to User Subroutine
       RESULT = value

       RETURN
       END
Listing 4.39 C/C++ code for CHEBY
 #include "stdafx.h"
 #include "DllFunc.h"

 CHEBY_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
   double value,mkid[5];
   int errflg, i;

   // Assign Impact Parameters
   for(i=0;i<5;i++){
       mkid[i] = upar[i];
   }

   // call rd_cheby to collect information for calculations
   rd_cheby(time,0.5,mkid,5,0,&value,&errflg);

   // Assign the returned value to user subroutine
   *result = array;
 }