C/C++ example for translational force user subroutine

 

#include "stdafx.h"

#include "DllFunc.h"

#include <math.h>

 

TranslationalForce_API void __cdecl translational_force(double time, double upar[], int npar, int jflag, int iflag, double result[3])

{

           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

           // Local Varialbe Definition

           int minus[3];

           double value[3];

 

           // Assign Impact Parameters

           minus[0] = (int) upar[0];

           minus[1] = (int) upar[1];

           minus[2] = (int) upar[2];

 

           for (int i = 0; i < 3; i++)

           {

                     if (i == 0)

                     {

                                value[i] = 8;

                     }

                     else if (i == 1)

                     {

                                value[i] = 24*time;

                     }

                     else

                     {

                                value[i] = 48*pow(time, 2);

                     }

 

                     if (minus[i] != 0)

                     {

                                value[i] = -value[i];

                     }

           }

 

           // Assign the Returned Value

           result[0] = value[0];

           result[1] = value[1];

           result[2] = value[2];

}