2
0
mirror of https://github.com/boostorg/odeint.git synced 2026-02-16 01:32:09 +00:00

* interface changes for the fsal steppers

* some test routines for dense output steppers and controlled steppers
This commit is contained in:
karsten
2010-11-02 14:39:28 +00:00
parent 0cf7ab86e5
commit 34575ca069
7 changed files with 300 additions and 138 deletions

View File

@@ -6,18 +6,10 @@
import testing ;
#project
# : requirements
# <include>../../../..
# <include>$(BOOST_ROOT)
# <define>BOOST_ALL_NO_LIB=1
# : build-dir .
# ;
project
: requirements
<define>BOOST_ALL_NO_LIB=1
<library>/boost/test//boost_unit_test_framework
<include>../../../..
<include>$(BOOST_ROOT)
;
@@ -31,9 +23,14 @@ unit-test basic_test
check_dense_output_explicit_euler.cpp
check_dense_output_dopri5.cpp
:
: <link>static
: <library>/boost/test//boost_unit_test_framework
<link>static
;
exe controlled_stepper_evolution
: controlled_stepper_evolution.cpp
;
exe dense_output_stepper_evolution
: dense_output_stepper_evolution.cpp
;

View File

@@ -0,0 +1,77 @@
/*
* controlled_stepper_evolution.cpp
*
* Created on: Nov 2, 2010
* Author: karsten
*/
#include <string>
#include <fstream>
#include <iostream>
#include <tr1/array>
#include <boost/numeric/odeint.hpp>
#define tab "\t"
using namespace std;
using namespace boost::numeric::odeint;
typedef std::tr1::array< double , 2 > state_type;
ostream& operator<<( ostream &out , const state_type &x )
{
out << x[0] << tab << x[1];
return out;
}
void sys( const state_type &x , state_type &dxdt , double t )
{
dxdt[0] = x[1];
dxdt[1] = -x[0];
}
state_type sys_solution( double t , const state_type &x0 )
{
state_type sol = {{ 0.0 , 0.0 }};
sol[0] = x0[0] * cos( t ) + x0[1] * sin( t );
sol[1] = -x0[0] * sin( t ) + x0[1] * cos( t );
return sol;
}
template< class Stepper >
void evolution( Stepper &stepper , double t_end , const state_type &x0 , const string &filename )
{
ofstream fout( filename.c_str() );
state_type x = x0;
double t = 0.0 , dt = 0.01;
while( t < t_end )
{
state_type orig = sys_solution( t , x0 );
state_type diff = {{ orig[0] - x[0] , orig[1] - x[1] }};
double diff_abs = sqrt( diff[0] * diff[0] + diff[1] * diff[1] );
fout << t << tab << orig << tab << x << tab << diff << tab << diff_abs << endl;
stepper.try_step( sys , x , t , dt );
}
}
int main( int argc , char **argv )
{
typedef explicit_error_rk54_ck< state_type > rk54_type;
typedef explicit_error_dopri5< state_type > dopri5_type;
rk54_type rk54;
dopri5_type dopri5;
controlled_error_stepper< rk54_type > rk54_controlled( rk54 );
controlled_error_stepper< dopri5_type > dopri5_controlled( dopri5 );
state_type x0 = {{ 1.25 , 0.43 }};
evolution( rk54_controlled , 100.0 , x0 , "rk54.dat" );
evolution( dopri5_controlled , 100.0 , x0 , "dopri5.dat" );
return 0;
}

View File

@@ -0,0 +1,92 @@
/*
* dense_output_stepper_evolution.cpp
*
* Created on: Nov 2, 2010
* Author: karsten
*/
#include <string>
#include <fstream>
#include <iostream>
#include <tr1/array>
#include <boost/numeric/odeint.hpp>
#define tab "\t"
using namespace std;
using namespace boost::numeric::odeint;
typedef std::tr1::array< double , 2 > state_type;
ostream& operator<<( ostream &out , const state_type &x )
{
out << x[0] << tab << x[1];
return out;
}
void sys( const state_type &x , state_type &dxdt , double t )
{
dxdt[0] = x[1];
dxdt[1] = -x[0];
}
state_type sys_solution( double t , const state_type &x0 )
{
state_type sol = {{ 0.0 , 0.0 }};
sol[0] = x0[0] * cos( t ) + x0[1] * sin( t );
sol[1] = -x0[0] * sin( t ) + x0[1] * cos( t );
return sol;
}
template< class Stepper >
void evolution( Stepper &stepper , double t_end , const state_type &x0 , const string &stepper_filename , const string &state_filename )
{
ofstream state_out( state_filename.c_str() );
ofstream stepper_out( stepper_filename.c_str() );
stepper.initialize( x0 , 0.0 , 0.01 );
state_type x = x0;
double t = 0.0;
double dt = 0.001;
while( t < t_end )
{
if( t < stepper.current_time() )
{
stepper.calc_state( t , x );
state_type orig = sys_solution( t , x0 );
state_type diff = {{ orig[0] - x[0] , orig[1] - x[1] }};
double diff_abs = sqrt( diff[0] * diff[0] + diff[1] * diff[1] );
state_out << t << tab << x << tab << orig << tab << diff << diff_abs << endl;
}
else
{
stepper.do_step( sys );
stepper_out << stepper.current_time() << "\t" << stepper.current_state() << std::endl;
continue;
}
t += dt;
}
}
int main( int argc , char **argv )
{
typedef explicit_error_dopri5< state_type > dopri5_type;
typedef controlled_error_stepper< dopri5_type > controlled_dopri5_type;
dopri5_type dopri5;
controlled_dopri5_type controlled_dopri5( dopri5 );
dense_output_explicit_euler< state_type > dense_euler;
dense_output_dopri5< controlled_dopri5_type > dense_dopri5( controlled_dopri5 );
state_type x0 = {{ 1.25 , 0.43 }};
evolution( dense_euler , 100.0 , x0 , "dense_euler_stepper.dat" , "dense_euler_state.dat" );
evolution( dense_dopri5 , 100.0 , x0 , "dense_dopri5_stepper.dat" , "dense_dopri5_state.dat" );
}