Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
robotran
mbsysc
Commits
f08db471
Commit
f08db471
authored
Sep 02, 2015
by
Nicolas Van der Noot
Browse files
convert identation
parent
27a6f3a6
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
MBsysC/mbs_common/mbs_numerics/dopri5.c
View file @
f08db471
This diff is collapsed.
Click to expand it.
MBsysC/mbs_common/mbs_numerics/dopri5.h
View file @
f08db471
/* DOPRI5
------
------
This code computes the numerical solution of a system of first order ordinary
...
...
@@ -7,9 +7,9 @@ differential equations y'=f(x,y). It uses an explicit Runge-Kutta method of
order (4)5 due to Dormand & Prince with step size control and dense output.
Authors : E. Hairer & G. Wanner
Universite de Geneve, dept. de Mathematiques
CH-1211 GENEVE 4, SWITZERLAND
E-mail : HAIRER@DIVSUN.UNIGE.CH, WANNER@DIVSUN.UNIGE.CH
Universite de Geneve, dept. de Mathematiques
CH-1211 GENEVE 4, SWITZERLAND
E-mail : HAIRER@DIVSUN.UNIGE.CH, WANNER@DIVSUN.UNIGE.CH
The code is described in : E. Hairer, S.P. Norsett and G. Wanner, Solving
ordinary differential equations I, nonstiff problems, 2nd edition,
...
...
@@ -33,11 +33,11 @@ INPUT PARAMETERS
n Dimension of the system (n < UINT_MAX).
fcn A pointer the the function definig the differential equation, this
function must have the following prototype
function must have the following prototype
void fcn (unsigned n, double x, double *y, double *f)
void fcn (unsigned n, double x, double *y, double *f)
where the array f will be filled with the function result.
where the array f will be filled with the function result.
x Initial x value.
...
...
@@ -47,46 +47,46 @@ xend Final x value (xend-x may be positive or negative).
*rtoler Relative and absolute error tolerances. They can be both scalars or
*atoler vectors of length n (in the scalar case pass the addresses of
variables where you have placed the tolerance values).
variables where you have placed the tolerance values).
itoler Switch for atoler and rtoler :
itoler=0 : both atoler and rtoler are scalars, the code keeps
roughly the local error of y[i] below
rtoler*abs(y[i])+atoler.
itoler=1 : both rtoler and atoler are vectors, the code keeps
the local error of y[i] below
rtoler[i]*abs(y[i])+atoler[i].
itoler=0 : both atoler and rtoler are scalars, the code keeps
roughly the local error of y[i] below
rtoler*abs(y[i])+atoler.
itoler=1 : both rtoler and atoler are vectors, the code keeps
the local error of y[i] below
rtoler[i]*abs(y[i])+atoler[i].
solout A pointer to the output function called during integration.
If iout >= 1, it is called after every successful step. If iout = 0,
pass a pointer equal to NULL. solout must must have the following
prototype
If iout >= 1, it is called after every successful step. If iout = 0,
pass a pointer equal to NULL. solout must must have the following
prototype
solout (long nr, double xold, double x, double* y, unsigned n, int* irtrn)
solout (long nr, double xold, double x, double* y, unsigned n, int* irtrn)
where y is the solution the at nr-th grid point x, xold is the
previous grid point and irtrn serves to interrupt the integration
(if set to a negative value).
where y is the solution the at nr-th grid point x, xold is the
previous grid point and irtrn serves to interrupt the integration
(if set to a negative value).
Continuous output : during the calls to solout, a continuous solution
for the interval (xold,x) is available through the function
Continuous output : during the calls to solout, a continuous solution
for the interval (xold,x) is available through the function
contd5(i,s)
contd5(i,s)
which provides an approximation to the i-th component of the solution
at the point s (s must lie in the interval (xold,x)).
which provides an approximation to the i-th component of the solution
at the point s (s must lie in the interval (xold,x)).
iout Switch for calling solout :
iout=0 : no call,
iout=1 : solout only used for output,
iout=2 : dense output is performed in solout (in this case nrdens
must be greater than 0).
iout=0 : no call,
iout=1 : solout only used for output,
iout=2 : dense output is performed in solout (in this case nrdens
must be greater than 0).
fileout A pointer to the stream used for messages, if you do not want any
message, just pass NULL.
message, just pass NULL.
icont An array containing the indexes of components for which dense
output is required. If no dense output is required, pass NULL.
output is required. If no dense output is required, pass NULL.
licont The number of cells in icont.
...
...
@@ -94,24 +94,24 @@ licont The number of cells in icont.
Sophisticated setting of parameters
-----------------------------------
Several parameters have a default value (if set to 0) but, to better
adapt the code to your problem, you can specify particular initial
values.
Several parameters have a default value (if set to 0) but, to better
adapt the code to your problem, you can specify particular initial
values.
uround The rounding unit, default 2.3E-16 (this default value can be
replaced in the code by DBL_EPSILON providing float.h defines it
in your system).
replaced in the code by DBL_EPSILON providing float.h defines it
in your system).
safe Safety factor in the step size prediction, default 0.9.
fac1 Parameters for step size selection; the new step size is chosen
fac2 subject to the restriction fac1 <= hnew/hold <= fac2.
Default values are fac1=0.2 and fac2=10.0.
Default values are fac1=0.2 and fac2=10.0.
beta The "beta" for stabilized step size control (see section IV.2 of our
book). Larger values for beta ( <= 0.1 ) make the step size control
more stable. dopri5 needs a larger beta than Higham & Hall. Negative
initial value provoke beta=0; default beta=0.04.
book). Larger values for beta ( <= 0.1 ) make the step size control
more stable. dopri5 needs a larger beta than Higham & Hall. Negative
initial value provoke beta=0; default beta=0.04.
hmax Maximal step size, default xend-x.
...
...
@@ -120,24 +120,24 @@ h Initial step size, default is a guess computed by the function hinit.
nmax Maximal number of allowed steps, default 100000.
meth Switch for the choice of the method coefficients; at the moment the
only possibility and default value are 1.
only possibility and default value are 1.
nstiff Test for stiffness is activated when the current step number is a
multiple of nstiff. A negative value means no test and the default
is 1000.
multiple of nstiff. A negative value means no test and the default
is 1000.
nrdens Number of components for which dense outpout is required, default 0.
For 0 < nrdens < n, the components have to be specified in icont[0],
icont[1], ... icont[nrdens-1]. Note that if nrdens=0 or nrdens=n, no
icont is needed, pass NULL.
For 0 < nrdens < n, the components have to be specified in icont[0],
icont[1], ... icont[nrdens-1]. Note that if nrdens=0 or nrdens=n, no
icont is needed, pass NULL.
Memory requirements
-------------------
The function dopri5 allocates dynamically 8*n doubles for the method
stages, 5*nrdens doubles for the interpolation if dense output is
performed and n unsigned if 0 < nrdens < n.
The function dopri5 allocates dynamically 8*n doubles for the method
stages, 5*nrdens doubles for the interpolation if dense output is
performed and n unsigned if 0 < nrdens < n.
...
...
@@ -148,21 +148,21 @@ y numerical solution at x=xRead() (see below).
dopri5 returns the following values
1 : computation successful,
2 : computation successful interrupted by solout,
-1 : input is not consistent,
-2 : larger nmax is needed,
-3 : step size becomes too small,
-4 : the problem is probably stff (interrupted).
1 : computation successful,
2 : computation successful interrupted by solout,
-1 : input is not consistent,
-2 : larger nmax is needed,
-3 : step size becomes too small,
-4 : the problem is probably stff (interrupted).
Several functions provide access to different values :
xRead x value for which the solution has been computed (x=xend after
successful return).
successful return).
hRead Predicted step size of the last accepted step (useful for a
subsequent call to dopri5).
subsequent call to dopri5).
nstepRead Number of used steps.
naccptRead Number of accepted steps.
...
...
@@ -181,36 +181,36 @@ typedef void (*SolTrait)(long nr, double xold, double x, double* y, unsigned n,
extern
int
dopri5
(
unsigned
n
,
/* dimension of the system <= UINT_MAX-1*/
FcnEqDiff
fcn
,
/* function computing the value of f(x,y) */
double
x
,
/* initial x-value */
double
*
y
,
/* initial values for y */
double
xend
,
/* final x-value (xend-x may be positive or negative) */
double
*
rtoler
,
/* relative error tolerance */
double
*
atoler
,
/* absolute error tolerance */
int
itoler
,
/* switch for rtoler and atoler */
SolTrait
solout
,
/* function providing the numerical solution during integration */
int
iout
,
/* switch for calling solout */
FILE
*
fileout
,
/* messages stream */
double
uround
,
/* rounding unit */
double
safe
,
/* safety factor */
double
fac1
,
/* parameters for step size selection */
double
fac2
,
double
beta
,
/* for stabilized step size control */
double
hmax
,
/* maximal step size */
double
h
,
/* initial step size */
long
nmax
,
/* maximal number of allowed steps */
int
meth
,
/* switch for the choice of the coefficients */
long
nstiff
,
/* test for stiffness */
unsigned
nrdens
,
/* number of components for which dense outpout is required */
unsigned
*
icont
,
/* indexes of components for which dense output is required, >= nrdens */
unsigned
licont
/* declared length of icon */
);
(
unsigned
n
,
/* dimension of the system <= UINT_MAX-1*/
FcnEqDiff
fcn
,
/* function computing the value of f(x,y) */
double
x
,
/* initial x-value */
double
*
y
,
/* initial values for y */
double
xend
,
/* final x-value (xend-x may be positive or negative) */
double
*
rtoler
,
/* relative error tolerance */
double
*
atoler
,
/* absolute error tolerance */
int
itoler
,
/* switch for rtoler and atoler */
SolTrait
solout
,
/* function providing the numerical solution during integration */
int
iout
,
/* switch for calling solout */
FILE
*
fileout
,
/* messages stream */
double
uround
,
/* rounding unit */
double
safe
,
/* safety factor */
double
fac1
,
/* parameters for step size selection */
double
fac2
,
double
beta
,
/* for stabilized step size control */
double
hmax
,
/* maximal step size */
double
h
,
/* initial step size */
long
nmax
,
/* maximal number of allowed steps */
int
meth
,
/* switch for the choice of the coefficients */
long
nstiff
,
/* test for stiffness */
unsigned
nrdens
,
/* number of components for which dense outpout is required */
unsigned
*
icont
,
/* indexes of components for which dense output is required, >= nrdens */
unsigned
licont
/* declared length of icon */
);
extern
double
contd5
(
unsigned
ii
,
/* index of desired component */
double
x
/* approximation at x */
);
(
unsigned
ii
,
/* index of desired component */
double
x
/* approximation at x */
);
extern
long
nfcnRead
(
void
);
/* encapsulation of statistical data */
extern
long
nstepRead
(
void
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment