This method is not recommended in general but it gives an introduction to methods with automatic step control that are described in section Long-time integration.
In order to integrate a system of ODEs one has to
- define an instance of class DMap or LDMap (see Maps and their derivatives ) that describes the vector field, like
DMap pendulum(
"time:t;par:omega;var:x,dx;fun:dx,sin(omega*t)-sin(x);");
pendulum.setParameter("omega",1.);
This class is used to represent a map .
Definition: Map.h:125
- define an instance of ODE solver (class DOdeSolver or LDOdeSolver)
double timeStep = 0.125;
solver.setStep(timeStep);
int order
Definition: tayltst.cpp:31
capd::dynsys::BasicOdeSolver< capd::DMap > DOdeSolver
Definition: typedefs.h:26
- Attention
- An instance of DOdeSolver can be use to integrate many initial conditions. It is strongly not recommended to create an instance of DOdeSolver for each IVP we want to solve.
- specify the initial condition
u[0] = 1.;
u[1] = 2.;
double t = 4;
- and then integrate
After the above call
- , where is local flow induced by our (nonautonomous) ODE
- value of
t
is updated to t = t+timeStep
Repeating the last line like
for(int i=0;i<numberOfSteps;++i){
u = solver(t,u);
cout << "t=" << t << ", u=" << u << endl;
}
one can obtain selected points on the trajectory of the point u
.
- Note
- if the system is autonomous one can skip argument
t
and write
- Note
- Step control is built-in the solver and is turned on by default. In order to obtain a point on the trajectory after user specified time we must turn off step control. This can be achieved by call to
solver.setStep(timeStep);
The above approach does not profit from the automatic step control strategies. There are three additional functions solver.turnOffStepControl();
solver.turnOnStepControl();
solver.onOffStepControl(booleanArgument);
that manage step control. See Error tolerance and step control for more details on step control strategies and parameters.
Complete example (from examples/odes/DSolverExample.cpp):
#include <cstdio>
DMap pendulum(
"time:t;par:omega;var:x,dx;fun:dx,sin(omega*t)-sin(x);");
pendulum.setParameter("omega",1.);
solver.setStep(0.125);
u[0] = 1.;
u[1] = 2.;
double t = 4;
do{
u = solver(t,u);
printf("t=%6f, x=%6f, dx=%6f\n",t,u[0],u[1]);
}while(t<5);
return 0;
}
int main(int argc, char *argv[])
Definition: argdemo.cpp:81
Definition: ApplicationDesc.h:23