mirror of
https://github.com/boostorg/odeint.git
synced 2026-02-21 15:22:08 +00:00
bulirsch stoer with dense output can now be used - tested on nontrivial example (elliptic functions), everything looks fine.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <cmath>
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/config.hpp>
|
||||
|
||||
@@ -50,36 +51,39 @@ void write_out( const state_type &x , const double t )
|
||||
|
||||
int main()
|
||||
{
|
||||
bulirsch_stoer_dense_out< state_type > stepper( 1E-10 , 0.0 , 0.0 , 0.0 );
|
||||
bulirsch_stoer_dense_out< state_type > stepper( 1E-8 , 0.0 , 0.0 , 0.0 );
|
||||
|
||||
state_type x = {{ 0.0 }};
|
||||
state_type x = {{ 2.0 / sqrt(3.0) }};
|
||||
|
||||
//double t = M_PI/6.0;
|
||||
double t = 0.0;
|
||||
double t = M_PI/6.0;
|
||||
//double t = 0.0;
|
||||
double dt = 0.01;
|
||||
//double t_end = M_PI/2.0 - 0.1;
|
||||
double t_end = 100.0;
|
||||
double t_end = M_PI/2.0 - 0.1;
|
||||
//double t_end = 100.0;
|
||||
|
||||
out.open( "bs.dat" );
|
||||
integrate_const( stepper , rhs2 , x , t , t_end , dt , write_out );
|
||||
out.precision(16);
|
||||
integrate_const( stepper , rhs , x , t , t_end , dt , write_out );
|
||||
out.close();
|
||||
|
||||
x[0] = 0.0;
|
||||
x[0] = 2.0 / sqrt(3.0);
|
||||
|
||||
out.open( "bs2.dat" );
|
||||
integrate_adaptive( stepper , rhs2 , x , t , t_end , dt , write_out );
|
||||
out.precision(16);
|
||||
integrate_adaptive( stepper , rhs , x , t , t_end , dt , write_out );
|
||||
out.close();
|
||||
|
||||
typedef runge_kutta_dopri5< state_type > dopri5_type;
|
||||
typedef controlled_error_stepper< dopri5_type > controlled_dopri5_type;
|
||||
typedef dense_output_controlled_explicit_fsal< controlled_dopri5_type > dense_output_dopri5_type;
|
||||
|
||||
dense_output_dopri5_type dopri5( controlled_dopri5_type( dopri5_type() , default_error_checker< double >( 1E-10 , 0.0 , 0.0 , 0.0 ) ) );
|
||||
dense_output_dopri5_type dopri5( controlled_dopri5_type( dopri5_type() , default_error_checker< double >( 1E-2 , 0.0 , 0.0 , 0.0 ) ) );
|
||||
|
||||
x[0] = 0.0;
|
||||
x[0] = 2.0 / sqrt(3.0);
|
||||
|
||||
out.open( "bs3.dat" );
|
||||
integrate_adaptive( dopri5 , rhs2 , x , t , t_end , dt , write_out );
|
||||
out.precision(16);
|
||||
integrate_adaptive( dopri5 , rhs , x , t , t_end , dt , write_out );
|
||||
out.close();
|
||||
|
||||
}
|
||||
|
||||
19
libs/numeric/odeint/examples/elliptic.py
Normal file
19
libs/numeric/odeint/examples/elliptic.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from pylab import *
|
||||
from scipy import special
|
||||
|
||||
data1 = loadtxt("elliptic1.dat")
|
||||
data2 = loadtxt("elliptic2.dat")
|
||||
data3 = loadtxt("elliptic3.dat")
|
||||
|
||||
sn1,cn1,dn1,phi1 = special.ellipj( data1[:,0] , 0.51 )
|
||||
sn2,cn2,dn2,phi2 = special.ellipj( data2[:,0] , 0.51 )
|
||||
sn3,cn3,dn3,phi3 = special.ellipj( data3[:,0] , 0.51 )
|
||||
|
||||
semilogy( data1[:,0] , abs(data1[:,1]-sn1) )
|
||||
semilogy( data2[:,0] , abs(data2[:,1]-sn2) , 'ro' )
|
||||
semilogy( data3[:,0] , abs(data3[:,1]-sn3) , '--' )
|
||||
|
||||
show()
|
||||
|
||||
|
||||
|
||||
@@ -27,14 +27,16 @@ typedef boost::array< double , 3 > state_type;
|
||||
/*
|
||||
* x1' = x2*x3
|
||||
* x2' = -x1*x3
|
||||
* x3' = -0.51*x1*x2
|
||||
* x3' = -m*x1*x2
|
||||
*/
|
||||
|
||||
void rhs( const state_type &x , state_type &dxdt , const double t )
|
||||
{
|
||||
static const double m = 0.51;
|
||||
|
||||
dxdt[0] = x[1]*x[2];
|
||||
dxdt[1] = -x[0]*x[2];
|
||||
dxdt[2] = -0.51*x[0]*x[1];
|
||||
dxdt[2] = -m*x[0]*x[1];
|
||||
}
|
||||
|
||||
ofstream out;
|
||||
@@ -46,32 +48,35 @@ void write_out( const state_type &x , const double t )
|
||||
|
||||
int main()
|
||||
{
|
||||
bulirsch_stoer_dense_out< state_type > stepper( 1E-10 , 1E-10 , 1.0 , 0.0 );
|
||||
bulirsch_stoer_dense_out< state_type > stepper( 1E-9 , 1E-9 , 1.0 , 0.0 );
|
||||
|
||||
state_type x1 = {{ 0.0 , 1.0 , 1.0 }};
|
||||
|
||||
double t = 0.0;
|
||||
double dt = 0.1;
|
||||
double dt = 0.01;
|
||||
|
||||
out.open( "elliptic1.dat" );
|
||||
integrate_const( stepper , rhs , x1 , t , 10.0 , dt , write_out );
|
||||
out.precision(16);
|
||||
integrate_const( stepper , rhs , x1 , t , 100.0 , dt , write_out );
|
||||
out.close();
|
||||
|
||||
state_type x2 = {{ 0.0 , 1.0 , 1.0 }};
|
||||
|
||||
out.open( "elliptic2.dat" );
|
||||
integrate_adaptive( stepper , rhs , x2 , t , 10.0 , dt , write_out );
|
||||
out.precision(16);
|
||||
integrate_adaptive( stepper , rhs , x2 , t , 100.0 , dt , write_out );
|
||||
out.close();
|
||||
|
||||
typedef runge_kutta_dopri5< state_type > dopri5_type;
|
||||
typedef controlled_error_stepper< dopri5_type > controlled_dopri5_type;
|
||||
typedef dense_output_controlled_explicit_fsal< controlled_dopri5_type > dense_output_dopri5_type;
|
||||
|
||||
dense_output_dopri5_type dopri5( controlled_dopri5_type( dopri5_type() , default_error_checker< double >( 1E-10 , 0.0 , 0.0 , 0.0 ) ) );
|
||||
dense_output_dopri5_type dopri5( controlled_dopri5_type( dopri5_type() , default_error_checker< double >( 1E-9 , 0.0 , 0.0 , 0.0 ) ) );
|
||||
|
||||
state_type x3 = {{ 0.0 , 1.0 , 1.0 }};
|
||||
|
||||
out.open( "elliptic3.dat" );
|
||||
integrate_adaptive( dopri5 , rhs , x3 , t , 10.0 , dt , write_out );
|
||||
out.precision(16);
|
||||
integrate_adaptive( dopri5 , rhs , x3 , t , 100.0 , dt , write_out );
|
||||
out.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user