void operator()( void ) { Stepper stepper; const int o = stepper.order()+1; //order of the error is order of approximation + 1 const state_type x0 = {{ 0.0 , 1.0 }}; state_type x1; const double t = 0.0; /* do a first step with dt=0.1 to get an estimate on the prefactor of the error dx = f * dt^(order+1) */ double dt = 0.5; stepper.do_step( osc() , x0 , t , x1 , dt ); const double f = 2.0 * std::abs( sin(dt) - x1[0] ) / std::pow( dt , o ); // upper bound std::cout << o << " , " << f << std::endl; /* as long as we have errors above machine precision */ while( f*std::pow( dt , o ) > 1E-16 ) { // reset stepper which require resetting (fsal steppers) resetter< typename Stepper::stepper_category >::reset( stepper ); stepper.do_step( osc() , x0 , t , x1 , dt ); std::cout << "Testing dt=" << dt << std::endl; BOOST_CHECK_LT( std::abs( sin(dt) - x1[0] ) , f*std::pow( dt , o ) ); dt *= 0.5; } }
void operator()( void ) { Stepper stepper; const int o = stepper.order()+1; //order of the error is order of approximation + 1 const state_type q0 = {{ 0.0 }}; const state_type p0 = {{ 1.0 }}; state_type q1,p1; std::pair< state_type , state_type >x1( q1 , p1 ); const double t = 0.0; /* do a first step with dt=0.1 to get an estimate on the prefactor of the error dx = f * dt^(order+1) */ double dt = 0.5; stepper.do_step( osc() , std::make_pair( q0 , p0 ) , t , x1 , dt ); const double f = 2.0 * std::abs( sin(dt) - x1.first[0] ) / std::pow( dt , o ); std::cout << o << " , " << f << std::endl; /* as long as we have errors above machine precision */ while( f*std::pow( dt , o ) > 1E-16 ) { stepper.do_step( osc() , std::make_pair( q0 , p0 ) , t , x1 , dt ); std::cout << "Testing dt=" << dt << std::endl; BOOST_CHECK_SMALL( std::abs( sin(dt) - x1.first[0] ) , f*std::pow( dt , o ) ); dt *= 0.5; } }
void operator()( void ) { double t = 0; const double dt = 0.1; state_type x = 0; Stepper stepper; InitStepper init_stepper; stepper.initialize( init_stepper, rhs, x, t, dt ); // ab-stepper needs order-1 init steps: t and x should be (order-1)*dt BOOST_CHECK_CLOSE( t , (stepper.order()-1)*dt , 1E-16 ); BOOST_CHECK_CLOSE( x, ( stepper.order() - 1 ) * dt, 2E-14 ); }
void operator()( void ) { Stepper stepper; initializing_stepper init_stepper; const int o = stepper.order()+1; //order of the error is order of approximation + 1 const state_type x0 = {{ 0.0 , 1.0 }}; state_type x1 = x0; double t = 0.0; double dt = 0.2; // initialization, does a number of steps already to fill internal buffer, t is increased // we use the rk78 as initializing stepper stepper.initialize( boost::ref(init_stepper) , osc() , x1 , t , dt ); double A = std::sqrt( x1[0]*x1[0] + x1[1]*x1[1] ); double phi = std::asin(x1[0]/A) - t; // do a number of steps to fill the buffer with results from adams bashforth for( size_t n=0 ; n < stepper.steps ; ++n ) { stepper.do_step( osc() , x1 , t , dt ); t += dt; } // now we do the actual step stepper.do_step( osc() , x1 , t , dt ); // only examine the error of the adams-bashforth step, not the initialization const double f = 2.0 * std::abs( A*sin(t+dt+phi) - x1[0] ) / std::pow( dt , o ); // upper bound std::cout << o << " , " << f << std::endl; /* as long as we have errors above machine precision */ while( f*std::pow( dt , o ) > 1E-16 ) { x1 = x0; t = 0.0; stepper.initialize( boost::ref(init_stepper) , osc() , x1 , t , dt ); A = std::sqrt( x1[0]*x1[0] + x1[1]*x1[1] ); phi = std::asin(x1[0]/A) - t; // now we do the actual step stepper.do_step( osc() , x1 , t , dt ); // only examine the error of the adams-bashforth step, not the initialization std::cout << "Testing dt=" << dt << " , " << std::abs( A*sin(t+dt+phi) - x1[0] ) << std::endl; BOOST_CHECK_LT( std::abs( A*sin(t+dt+phi) - x1[0] ) , f*std::pow( dt , o ) ); dt *= 0.5; } }