4.8.3.100. STEP

Table 4.245 Function Name

Language type

Subroutine

FORTRAN

call rd_step(x, x0, h0, x1, h1, order, value, errflg) or step(x, x0, h0, x1, h1, order, value, errflg)

C/C++

rd_step(x, x0, h0, x1, h1, order, &value, &errflg) or step(x, x0, h0, x1, h1, order, &value, &errflg)

Table 4.246 Parameter information

Variable Name

Size

Description

x

double

Specify the independent variable.

x0

double

The x value at which the STEP function begins.

h0

double

Initial value of the STEP function.

x1

double

The x value at which the STEP function ends

h1

double

Final value at which the STEP function

order

int

  1. order = 0

    \(value=\left\{ \begin{array}{*{35}{l}} {{h}_{0}} & x\le {{x}_{0}} \\ {{h}_{0}}+({{h}_{1}}-{{h}_{0}}){{\left( \frac{(x-{{x}_{0}})}{({{x}_{1}}-{{x}_{0}})} \right)}^{2}}\left( 3-2\frac{(x-{{x}_{0}})}{({{x}_{1}}-{{x}_{0}})} \right) & {{x}_{0}}\le x\le {{x}_{1}} \\ {{h}_{1}} & x\ge {{x}_{1}} \\ \end{array} \right.\)

  2. order = 1

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

  3. order = 2

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

value

double

errflg

logical

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

Listing 4.110 Fortran code for STEP
 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_STEP(TIME,0.0D0,0.0D0,STIME,VELO,IORD,VALUE,ERRFLG)

       RESULT = VALUE

       RETURN
       END
Listing 4.111 C/C++ code for STEP
 #include "stdafx.h"
 #include "DllFunc.h"

 STEP_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. (Input)
   //   upar   : Parameters defined by user. (Input)
   //   npar   : Number of user parameters. (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 value. (Output)

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

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

 }