47.1.6. User Subroutines

47.1.6.1. Preparing and Compiling

To prepare a user subroutine

The source code for the user subroutines is very similar between Windows and Linux. The example axial force routine below shows the modifications for using the user subroutines for Linux. The included file is set to be SYSCAL_LN.H for C++ routines and is set to SYSCAL_LN.F for Fortran subroutines. There are also changes to the subroutine declaration statement, as shown in the example code.

//#include "stdafx.h"
//#include "DllFunc.h"
#include "SYSCAL_LN.H"
//C_API void __cdecl axial_force extern "C" void axial_force
(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
   // Local Variable Definition

   int mkid[3], errflg, akispl_id;
   int usp3,usp4;
   double usp2;
   double disp, value[3];

   // Assign Impact Parameters
   mkid[0] = (int) upar[0];
   mkid[1] = (int) upar[1];
   mkid[2] = (int) upar[2];
   akispl_id = (int) upar[3];

   usp3 = 3;
   usp2 = 0.0;
   usp4 = 0;

   // Call the Auxiliary subroutines for Calculation
   // The argument of the function must be changed to Pointer.

   sysfnc("DX", mkid, &usp3, &disp, &errflg);
   rd_akispl(&disp, &usp2, &akispl_id, &usp4, value, &errflg);

   // Assign the Returned Value
   *result = value[0];
}

USUB Example

  • USUB : <Linux Solver Install Dir>\USUB\

  • SYSCAL_LN File : <Linux Solver Install Dir>\USUB\

To compile a user subroutine

A Makefile can be created with the following text:

#ifort -fPIC -shared -o axial_force.so axial_force.for
#gfortran -fPIC -shared -o axial_force.so axial_force.for
#g++ -fPIC -shared -o axial_force.so DllFunc_LN.cpp
g++ -fPIC -shared -o axial_force.so DllFunc_LN.cpp

One of the compile command lines in the Makefile should be uncommented, according to the language of the user subroutine and according to the compiler that is available. Note that:

  • If you use a g++, make sure that the files DllFunc_LN.cpp and SYSCAL_LN.H are located in the local directory with the Makefile.

  • If you use a Fortran, make sure that the files axial_force.for and SYSCAL_LN.F are located in the local directory with the Makefile.

You need to execute the make command (with your Makefile) in order to compile your file.

47.1.6.2. Using

After compiling, you can get a *.so file. Your model uses the *.so file to access the user subroutine. Before running the RecurDyn/Solver:

  • Make sure that the *.so file is located in the same working directory as the RMD file.

  • Checking that the user subroutine name (and path) in the RMD file matches the name and location of the *.so file.

You do not prepare to execute the RecurDyn/Solver with the custom user subroutine.