Robotran C Documentation
dopri5.h
Go to the documentation of this file.
1 
13 /* DOPRI5
14  ------
15 
16 
17 This code computes the numerical solution of a system of first order ordinary
18 differential equations y'=f(x,y). It uses an explicit Runge-Kutta method of
19 order (4)5 due to Dormand & Prince with step size control and dense output.
20 
21 Authors : E. Hairer & G. Wanner
22  Universite de Geneve, dept. de Mathematiques
23  CH-1211 GENEVE 4, SWITZERLAND
24  E-mail : HAIRER@DIVSUN.UNIGE.CH, WANNER@DIVSUN.UNIGE.CH
25 
26 The code is described in : E. Hairer, S.P. Norsett and G. Wanner, Solving
27 ordinary differential equations I, nonstiff problems, 2nd edition,
28 Springer Series in Computational Mathematics, Springer-Verlag (1993).
29 
30 Version of April 28, 1994.
31 
32 Remarks about the C version : this version allocates memory by itself, the
33 iwork array (among the initial FORTRAN parameters) has been splitted into
34 independant initial parameters, the statistical variables and last step size
35 and x have been encapsulated in the module and are now accessible through
36 dedicated functions, the variable names have been kept to maintain a kind
37 of reading compatibility between the C and FORTRAN codes; adaptation made by
38 J.Colinge (COLINGE@DIVSUN.UNIGE.CH).
39 
40 
41 
42 INPUT PARAMETERS
43 ----------------
44 
45 n Dimension of the system (n < UINT_MAX).
46 
47 fcn A pointer the the function definig the differential equation, this
48  function must have the following prototype
49 
50  void fcn (unsigned n, long nr, double x, double *y, double *f, MbsData *s, MbsDirdyn *dd) -> modif: nr, s and dd added
51 
52  where the array f will be filled with the function result.
53 
54 x Initial x value.
55 
56 *y Initial y values (double y[n]).
57 
58 xend Final x value (xend-x may be positive or negative).
59 
60 *rtoler Relative and absolute error tolerances. They can be both scalars or
61 *atoler vectors of length n (in the scalar case pass the addresses of
62  variables where you have placed the tolerance values).
63 
64 itoler Switch for atoler and rtoler :
65  itoler=0 : both atoler and rtoler are scalars, the code keeps
66  roughly the local error of y[i] below
67  rtoler*abs(y[i])+atoler.
68  itoler=1 : both rtoler and atoler are vectors, the code keeps
69  the local error of y[i] below
70  rtoler[i]*abs(y[i])+atoler[i].
71 
72 solout A pointer to the output function called during integration.
73  If iout >= 1, it is called after every successful step. If iout = 0,
74  pass a pointer equal to NULL. solout must have the following
75  prototype
76 
77  solout (long nr, double xold, double x, double* y, unsigned n, int* irtrn, MbsData* s, MbsDirdyn* dd) -> modif: s and dd added
78 
79  where y is the solution the at nr-th grid point x, xold is the
80  previous grid point and irtrn serves to interrupt the integration
81  (if set to a negative value).
82 
83  Continuous output : during the calls to solout, a continuous solution
84  for the interval (xold,x) is available through the function
85 
86  contd5(i,s)
87 
88  which provides an approximation to the i-th component of the solution
89  at the point s (s must lie in the interval (xold,x)).
90 
91 iout Switch for calling solout :
92  iout=0 : no call,
93  iout=1 : solout only used for output,
94  iout=2 : dense output is performed in solout (in this case nrdens
95  must be greater than 0).
96 
97 fileout A pointer to the stream used for messages, if you do not want any
98  message, just pass NULL.
99 
100 icont An array containing the indexes of components for which dense
101  output is required. If no dense output is required, pass NULL.
102 
103 licont The number of cells in icont.
104 
105 
106 Sophisticated setting of parameters
107 -----------------------------------
108 
109  Several parameters have a default value (if set to 0) but, to better
110  adapt the code to your problem, you can specify particular initial
111  values.
112 
113 uround The rounding unit, default 2.3E-16 (this default value can be
114  replaced in the code by DBL_EPSILON providing float.h defines it
115  in your system).
116 
117 safe Safety factor in the step size prediction, default 0.9.
118 
119 fac1 Parameters for step size selection; the new step size is chosen
120 fac2 subject to the restriction fac1 <= hnew/hold <= fac2.
121  Default values are fac1=0.2 and fac2=10.0.
122 
123 beta The "beta" for stabilized step size control (see section IV.2 of our
124  book). Larger values for beta ( <= 0.1 ) make the step size control
125  more stable. dopri5 needs a larger beta than Higham & Hall. Negative
126  initial value provoke beta=0; default beta=0.04.
127 
128 hmax Maximal step size, default xend-x.
129 
130 h Initial step size, default is a guess computed by the function hinit.
131 
132 nmax Maximal number of allowed steps, default 100000.
133 
134 meth Switch for the choice of the method coefficients; at the moment the
135  only possibility and default value are 1.
136 
137 nstiff Test for stiffness is activated when the current step number is a
138  multiple of nstiff. A negative value means no test and the default
139  is 1000.
140 
141 nrdens Number of components for which dense outpout is required, default 0.
142  For 0 < nrdens < n, the components have to be specified in icont[0],
143  icont[1], ... icont[nrdens-1]. Note that if nrdens=0 or nrdens=n, no
144  icont is needed, pass NULL.
145 
146 
147 Memory requirements
148 -------------------
149 
150  The function dopri5 allocates dynamically 8*n doubles for the method
151  stages, 5*nrdens doubles for the interpolation if dense output is
152  performed and n unsigned if 0 < nrdens < n.
153 
154 
155 
156 OUTPUT PARAMETERS
157 -----------------
158 
159 y numerical solution at x=xRead() (see below).
160 
161 dopri5 returns the following values
162 
163  1 : computation successful,
164  2 : computation successful interrupted by solout,
165  -1 : input is not consistent,
166  -2 : larger nmax is needed,
167  -3 : step size becomes too small,
168  -4 : the problem is probably stff (interrupted).
169 
170 
171 Several functions provide access to different values :
172 
173 xRead x value for which the solution has been computed (x=xend after
174  successful return).
175 
176 hRead Predicted step size of the last accepted step (useful for a
177  subsequent call to dopri5).
178 
179 nstepRead Number of used steps.
180 naccptRead Number of accepted steps.
181 nrejctRead Number of rejected steps.
182 nfcnRead Number of function calls.
183 
184 
185 */
186 
187 #ifndef _DOPRI5_H_INCLUDED
188 #define _DOPRI5_H_INCLUDED
189 
190 #include <stdio.h>
191 #include <limits.h>
192 
193 // modif: add mbs_data and mbs_dirdyn_struct headers
194 #include "mbs_data.h"
195 #include "mbs_dirdyn_struct.h"
196 
197 // modif: long nr, MbsData *s, MbsDirdyn *dd added
198 typedef int(*FcnEqDiff)(unsigned n, long nr, double x, double *y, double *f, MbsData *s, MbsDirdyn *dd);
199 
200 // modif, MbsData *s, MbsDirdyn *dd, int init_flag added
201 typedef int(*SolTrait)(long nr, double xold, double x, double* y, unsigned n, int* irtrn, int init_flag, MbsData *s, MbsDirdyn *dd);
202 
204 extern int dopri5
205 (unsigned n, /* dimension of the system <= UINT_MAX-1*/
206  FcnEqDiff fcn, /* function computing the value of f(x,y) */
207  double x, /* initial x-value */
208  double* y, /* initial values for y */
209  double xend, /* final x-value (xend-x may be positive or negative) */
210  double* rtoler, /* relative error tolerance */
211  double* atoler, /* absolute error tolerance */
212  int itoler, /* switch for rtoler and atoler */
213  SolTrait solout, /* function providing the numerical solution during integration */
214  int iout, /* switch for calling solout */
215  double uround, /* rounding unit */
216  double safe, /* safety factor */
217  double fac1, /* parameters for step size selection */
218  double fac2,
219  double beta, /* for stabilized step size control */
220  double hmax, /* maximal step size */
221  double h, /* initial step size */
222  long nmax, /* maximal number of allowed steps */
223  int meth, /* switch for the choice of the coefficients */
224  long nstiff, /* test for stiffness */
225  unsigned nrdens, /* number of components for which dense outpout is required */
226  unsigned* icont, /* indexes of components for which dense output is required, >= nrdens */
227  unsigned licont, /* declared length of icon */
228  double **dopri5_alloc_tab, /* modif: tabular of allocated vectors */
229  MbsData *s, /* modif: Robotran main fields */
230  MbsDirdyn *dd, /* modif: direct dynamics */
231  double *last_h /* modif: last step used */
232  ); // modif: MbsData *s, MbsDirdyn *dd added
233 
234 extern double contd5
235 (unsigned ii, /* index of desired component */
236  double x /* approximation at x */
237  );
238 
239 extern long nfcnRead(void); /* encapsulation of statistical data */
240 extern long nstepRead(void);
241 extern long naccptRead(void);
242 extern long nrejctRead(void);
243 extern double hRead(void);
244 extern double xRead(void);
245 
246 #endif
k6
double * k6
Definition: dopri5.c:32
mbs_dirdyn.h
max_d
static double max_d(double a, double b)
Definition: dopri5.c:91
MbsData::tsim
double tsim
The time value.
Definition: mbs_data.h:208
MbsDirdyn::y
double * y
Pointer to the state vector, this is a dvec_0 of size nState.
Definition: mbs_dirdyn_struct.h:153
mbs_data.h
mbs_dirdyn_struct.h
MbsDirdyn::yd
double * yd
Pointers to the derivative vector (dvec_0) of size nState.
Definition: mbs_dirdyn_struct.h:160
rcont5
static double * rcont5
Definition: dopri5.c:33
min_d
static double min_d(double a, double b)
Definition: dopri5.c:84
nrejct
static long nrejct
Definition: dopri5.c:29
k3
double * k3
Definition: dopri5.c:32
mbs_fct_dirdyn
int mbs_fct_dirdyn(double tsim, double y[], double dydt[], MbsData *s, MbsDirdyn *dd)
direct dynamics derivative computation
Definition: mbs_dirdyn.c:1067
last_hnew
static double last_hnew
Definition: dopri5.c:30
k1
double * k1
Definition: dopri5.c:32
SolTrait
int(* SolTrait)(long nr, double xold, double x, double *y, unsigned n, int *irtrn, int init_flag, MbsData *s, MbsDirdyn *dd)
Definition: dopri5.h:201
_MBS_ERR_MOD_SPEC_15
#define _MBS_ERR_MOD_SPEC_15
Generic error number Module specific errors range from -11 to -19 please read the error message a...
Definition: mbs_errors_names.h:186
naccptRead
long naccptRead(void)
Definition: dopri5.c:49
dopri5.h
This header defines function for dopri5 in C. based on an external source (see below)
k4
double * k4
Definition: dopri5.c:32
nrejctRead
long nrejctRead(void)
Definition: dopri5.c:56
nstep
static long nstep
Definition: dopri5.c:29
dopcor
static int dopcor(unsigned n, FcnEqDiff fcn, double x, double *y, double xend, double hmax, double h, double *rtoler, double *atoler, int itoler, SolTrait solout, int iout, long nmax, double uround, int meth, long nstiff, double safe, double beta, double fac1, double fac2, unsigned *icont, MbsData *s, MbsDirdyn *dd)
Definition: dopri5.c:178
MbsDirdyn::tsim
double tsim
current simulation time
Definition: mbs_dirdyn_struct.h:149
xout
static double xout
Definition: dopri5.c:30
mbs_msg
void mbs_msg(char *msg,...)
Send a message.
Definition: mbs_message.c:76
rcont1
static double * rcont1
Definition: dopri5.c:33
nfcn
static long nfcn
Definition: dopri5.c:29
yy1
double * yy1
Definition: dopri5.c:32
nstepRead
long nstepRead(void)
Definition: dopri5.c:42
contd5
double contd5(unsigned ii, double x)
Definition: dopri5.c:732
xold
static double xold
Definition: dopri5.c:30
nstepRead
long nstepRead(void)
Definition: dopri5.c:42
rcont2
static double * rcont2
Definition: dopri5.c:33
FcnEqDiff
int(* FcnEqDiff)(unsigned n, long nr, double x, double *y, double *f, MbsData *s, MbsDirdyn *dd)
Definition: dopri5.h:198
xRead
double xRead(void)
Definition: dopri5.c:70
hRead
double hRead(void)
Definition: dopri5.c:63
naccptRead
long naccptRead(void)
Definition: dopri5.c:49
hout
static double hout
Definition: dopri5.c:30
dopri5
int dopri5(unsigned n, FcnEqDiff fcn, double x, double *y, double xend, double *rtoler, double *atoler, int itoler, SolTrait solout, int iout, double uround, double safe, double fac1, double fac2, double beta, double hmax, double h, long nmax, int meth, long nstiff, unsigned nrdens, unsigned *icont, unsigned licont, double **dopri5_alloc_tab, MbsData *s, MbsDirdyn *dd, double *last_h)
See the source file for more informations.
Definition: dopri5.c:530
mbs_message.h
nfcnRead
long nfcnRead(void)
Definition: dopri5.c:35
MbsData
Definition: mbs_data.h:149
contd5
double contd5(unsigned ii, double x)
Definition: dopri5.c:732
nrds
static unsigned nrds
Definition: dopri5.c:31
n_fcn
static long n_fcn
Definition: dopri5.c:29
nrejctRead
long nrejctRead(void)
Definition: dopri5.c:56
rcont4
static double * rcont4
Definition: dopri5.c:33
dopri5
int dopri5(unsigned n, FcnEqDiff fcn, double x, double *y, double xend, double *rtoler, double *atoler, int itoler, SolTrait solout, int iout, double uround, double safe, double fac1, double fac2, double beta, double hmax, double h, long nmax, int meth, long nstiff, unsigned nrdens, unsigned *icont, unsigned licont, double **dopri5_alloc_tab, MbsData *s, MbsDirdyn *dd, double *last_h)
See the source file for more informations.
Definition: dopri5.c:530
k2
double * k2
Definition: dopri5.c:32
hRead
double hRead(void)
Definition: dopri5.c:63
xRead
double xRead(void)
Definition: dopri5.c:70
sign
static double sign(double a, double b)
Definition: dopri5.c:77
MbsDirdynOptions::verbose
int verbose
1 to get print indications related to time adaptive integrator, 0 otherwise, default = 1
Definition: mbs_dirdyn_struct.h:110
nfcnRead
long nfcnRead(void)
Definition: dopri5.c:35
MbsDirdyn
General structure of the direct dynamic module.
Definition: mbs_dirdyn_struct.h:144
k5
double * k5
Definition: dopri5.c:32
ysti
double * ysti
Definition: dopri5.c:32
indir
static unsigned * indir
Definition: dopri5.c:31
MbsDirdyn::options
MbsDirdynOptions * options
structure defining the option of a direct dynamic
Definition: mbs_dirdyn_struct.h:146
MbsDirdynOptions::flag_stop_stiff
int flag_stop_stiff
1 to stop integration if it become stiff, 0 (default value) otherwise, default = 0
Definition: mbs_dirdyn_struct.h:111
naccpt
static long naccpt
Definition: dopri5.c:29
hinit
static double hinit(unsigned n, FcnEqDiff fcn, double x, double *y, double posneg, double *f0, double *f1, double *yy1, int iord, double hmax, double *atoler, double *rtoler, int itoler, MbsData *s, MbsDirdyn *dd)
Definition: dopri5.c:99
mbs_warning_msg
void mbs_warning_msg(char *msg,...)
Send a warning message.
Definition: mbs_message.c:89
rcont3
static double * rcont3
Definition: dopri5.c:33
mbs_errors_names.h