4.8.3.89. HAVSIN

Table 4.223 Function Name

Language type

Subroutine

FORTRAN

call rd_havsin(x, x0, h0, x1, h1, order, value, errflg) or havsin(x, x0, h0, x1, h1, order, value, errflg)

C/C++

rd_havsin(x, x0, h0, x1, h1, order, &value, &errflg) or havsin(x, x0, h0, x1, h1, order, &value, &errflg)

Table 4.224 Parameter information

Variable Name

Size

Description

x

double

The input variable for the defined HAVSIN.

x0

double

The starting point for the HAVSIN function.

h0

double

The initial value for the input variable (within the range of x≤x0).

x1

double

The ending point for the HAVSIN function.

h1

double

The initial value for the input variable (within the range of x≥x1).

order

int

  1. order = 0

    \(Value=\left\{ \begin{array}{*{35}{l}} {{h}_{0}} & (x\le {{x}_{0}}) \\ \frac{({{h}_{0}}+{{h}_{1}})}{2}+\frac{({{h}_{1}}-{{h}_{0}})}{2}\times \sin \left( \pi \frac{(x-{{x}_{0}})}{({{x}_{1}}-{{x}_{0}})}-\frac{\pi }{2} \right) & \left( {{x}_{0}}\le x\le {{x}_{1}} \right) \\ {{h}_{1}} & (x\ge {{x}_{1}}) \\ \end{array} \right.\)

  2. order = 1

    \(Value=\left\{ \begin{array}{*{35}{l}} 0 & (x\le {{x}_{0}}) \\ \frac{({{h}_{1}}-{{h}_{0}})}{2}\times \frac{\pi }{(x-{{x}_{0}})}\times \cos \left( \pi \frac{(x-{{x}_{0}})}{({{x}_{1}}-{{x}_{0}})}-\frac{\pi }{2} \right) & \left( {{x}_{0}}\le x\le {{x}_{1}} \right) \\ 0 & (x\ge {{x}_{1}}) \\ \end{array} \right.\)

  3. order = 2

    \(Value=\left\{ \begin{array}{*{35}{l}} 0 & (x\le {{x}_{0}}) \\ -\frac{({{h}_{1}}-{{h}_{0}})}{2}\times {{\left( \frac{\pi }{(x-{{x}_{0}})} \right)}^{2}}\times \sin \left( \pi \frac{(x-{{x}_{0}})}{({{x}_{1}}-{{x}_{0}})}-\frac{\pi }{2} \right) & \left( {{x}_{0}}\le x\le {{x}_{1}} \right) \\ 0 & (x\ge {{x}_{1}}) \\ \end{array} \right.\)

value

double

error

logical/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.94 Fortran code for HAVSIN
 C---- SUB. DIFFERENTIAL
       SUBROUTINE DIFFERENTIAL_USUB
     &          (TIME,UPAR,NPAR,JFLAG,IFLAG,RESULT)
 C---- TO EXPORT * SUBROUTINE
       !DEC$ ATTRIBUTES DLLEXPORT,C::DIFFERENTIAL_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     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]

 C---- USER STATEMENT
       DOUBLE PRECISION VALUE, VELO, STIME
       INTEGER IORD
       LOGICAL ERRFLG

       STIME = 1.0D0
       VELO = 74.0D0
       IF ( JFLAG ) THEN
         IORD = 1
       ELSE
         IORD = 0
       ENDIF
       CALL RD_HAVSIN(TIME,0.0D0,0.0D0,STIME,VELO,IORD,VALUE,ERRFLG)

       RESULT = VALUE

       RETURN
       END
Listing 4.95 C/C++ code for HAVSIN
 #include "stdafx.h"
 #include "DllFunc.h"

 HAVSIN_API void __cdecl differential_usub
   (double time, double upar[], int npar, int jflag, int iflag, double* result)
 {
   using namespace rd_syscall;
   // Parameter Information
   //   time: Simulation time of RD/Solver
   //   upar: Parameters defined by user
   //   npar: Number of user parameters
   //   jflag: When RD/Solver evaluates a Jacobian, the flag is true.
   //   iflag: When RD/Solver initializes arrays, the flag is true.
   //   result: Returned value

   // User statement
   double value, velo, stime;
   int iord, errflg;

   stime = 1.0;
   velo = 74.0;
   if (jflag) {
       iord = 1;
   }
   else {
       iord = 0;
   }
   rd_havsin(time,0.0,0.0,stime,velo,iord,&value,&errflg);
   *result = value;

 }