4.8.3.1. AKISPL

Table 4.47 Function Name

Language type

Subroutine

FORTRAN

call rd_akispl(xval, zval, identity, order, array, errflg) or call akispl(xval, zval, identity, order, array, errflg)

C/C++

rd_akispl(xval, zval, identity, order, &array[0], &errflg) or akispl(xval, zval, identity, order, &array[0], &errflg)

Table 4.48 Parameter information

Variable Name

Size

Description

xval

double

An input variable for the AKISPL function.

  • Generally, this variable is time or a function that returns a real number.

zval

double

An input variable for the AKISPL function.

  • The second variable is necessary for three dimensional spline functions.

  • This variable must be a function that returns a real number. Otherwise, 0 is applied.

\(\begin{aligned} & \begin{matrix} \left\{ \begin{matrix} {{y}_{1}}=f(x,{{z}_{1}}) \\ {{y}_{2}}=f(x,{{z}_{2}}) \\ \end{matrix} \right., & {{z}_{1}}<z<{{z}_{2}} \\ \end{matrix} \\ & y={{y}_{1}}+\frac{(z-{{z}_{1}})({{y}_{2}}-{{y}_{1}})}{{{z}_{2}}-{{z}_{1}}} \\ \end{aligned}\)

identity

int

The identity of Spline.

order

int

The interpolation method for the functions (return the value if 0,

return calculation for 1st order differential equation if 1, and return calculation for 2nd order differential equation if 2)

  1. order = 0

    \(array=f(x,spline\_data)\)

  2. order = 1

    \(array=\frac{d}{dx}\left( f(x,spline\_data) \right)\)

  3. order = 2

    \(array=\frac{{d}^{2}}{d{x}^{2}}\left( f(x,spline\_data) \right)\)

array

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.34 Fortran code for AKISPL
 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
       double precision result_order(1)
       double precision result_order0(1)
       double precision result_order1(1)
       double precision result_order2(1)
       integer splineID
       integer iorder
       integer iflagRest
       logical ERRFLG
       integer errorID

 C---- Assign Parameter
       splineID = int(UPAR(1))
       iorder = int(UPAR(2))
       iflagTest = int(UPAR(3))

 C---- Call RD_AKISPL to get the result of spline
       if (iflagTest) then
         call RD_AKISPL(time,0,splineID,0,result_order0(1),ERRFLG)
         errorID = 1000
         call ERRMES(ERRFLG,'Error : order 0',errorID,'AKISPL')

         call RD_AKISPL(time,0,splineID,1,result_order1(1),ERRFLG)
         errorID = 1001
         call ERRMES(ERRFLG,'Error : order 1',errorID,'AKISPL')

         call RD_AKISPL(time,0,splineID,2,result_order2(1),ERRFLG)
         errorID = 1002
         call ERRMES(ERRFLG,'Error : order 2',errorID,'AKISPL')

 C------- Assign the returned value to User Subroutine
         if (iorder .eq. 0) then
             RESULT = result_order0(1)
         else if (iorder .eq. 1) then
             RESULT = result_order1(1)
         else if (ioerder .eq. 2) then
             RESULT = result_order2(1)
         endif
       else
         call RD_AKISPL(time,0,splineID,iorder,result_order(1),ERRFLG)
         errorID = 2000
         call ERRMES(ERRFLG,'Error : order',errorID,'AKISPL')

 C------- Assign the returned value to User Subroutine
         RESULT = result_order(1)
       endif

       RETURN
       END
Listing 4.35 C/C++ code for AKISPL
 #include "stdafx.h"
 #include "DllFunc.h"

 Akispl_C_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 result_order0 = 0.0;
   double result_order1 = 0.0;
   double result_order2 = 0.0;
   int splineID;
   int iorder = 0;
   int iflagTest = 0;
   int ERRFLG = 0;
   int errorID = 0;

   // Assign Parameters
   splineID = (int)upar[0];
   iorder = (int)upar[1];
   iflagTest = (int)upar[2];

   // Call RD_AKISPL to collect information for calculations
   if (iflagTest)
   {
       rd_akispl(time,0,splineID,0,&result_order0,&ERRFLG);
       errorID = 1000;
       errmes(ERRFLG,"Error : order 0",errorID,"AKISPL");

       rd_akispl(time,0,splineID,1,&result_order1,&ERRFLG);
       errorID = 1001;
       errmes(ERRFLG,"Error : order 1",errorID,"AKISPL");

       rd_akispl(time,0,splineID,2,&result_order2,&ERRFLG);
       errorID = 1002;
       errmes(ERRFLG,"Error : order 2",errorID,"AKISPL");

       // Assign the returned value to User Subroutine
       if (iorder == 0)
       {
         *result = result_order0;
       }
       else if (iorder == 1)
       {
         *result = result_order1;
       }
       else if (iorder ==2)
       {
         *result = result_order2;
       }
   }
   else
   {
       // Assign the returned value to User Subroutine
       rd_akispl(time,0,splineID,iorder,result,&ERRFLG);
       errorID = 2000;
       errmes(ERRFLG,"Error : order",errorID,"AKISPL");
   }

 }