|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r69999 - in sandbox/odeint/branches/karsten: . boost/numeric/odeint/integrate boost/numeric/odeint/integrate/detail boost/numeric/odeint/stepper libs/numeric/odeint/regression_test
From: karsten.ahnert_at_[hidden]
Date: 2011-03-15 04:45:45
Author: karsten
Date: 2011-03-15 04:45:41 EDT (Tue, 15 Mar 2011)
New Revision: 69999
URL: http://svn.boost.org/trac/boost/changeset/69999
Log:
integrate functions
Text files modified:
sandbox/odeint/branches/karsten/TODO | 6 ++
sandbox/odeint/branches/karsten/boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp | 50 +++++++++++++++++---
sandbox/odeint/branches/karsten/boost/numeric/odeint/integrate/detail/integrate_const.hpp | 81 ++++++++++++++++++++++++----------
sandbox/odeint/branches/karsten/boost/numeric/odeint/integrate/integrate.hpp | 93 ++++++++++++++++++++++-----------------
sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/controlled_error_stepper.hpp | 7 ++
sandbox/odeint/branches/karsten/libs/numeric/odeint/regression_test/integrate_functions.cpp | 27 +++++++++++
6 files changed, 187 insertions(+), 77 deletions(-)
Modified: sandbox/odeint/branches/karsten/TODO
==============================================================================
--- sandbox/odeint/branches/karsten/TODO (original)
+++ sandbox/odeint/branches/karsten/TODO 2011-03-15 04:45:41 EDT (Tue, 15 Mar 2011)
@@ -9,9 +9,13 @@
* test explicit stepper with ranges
* split check_concepts into check_stepper_concept, check_error_stepper_concept, check_controlled_stepper_concept
* include test/thrust in jam system, use system from
+* integrate functions
+ * check forwarding problem
+ * check where exactly the observer will be called (before, after each step?)
+* Factory functions for steppers, controlled_steppers, error_checker und dense_output_stepper
+* rename error_checker_standard to default_error_checker
* implicit euler, include dfdt
* same interface for implicit_euler and rosenbrock4
-* integrate functions
DIFFICULT * finishing change of controlled_stepper to units
* check if rosenbrock controller and controlled_stepper can both be used with the explicit steppers
OK * move error_checker into controlled_stepper
Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp 2011-03-15 04:45:41 EDT (Tue, 15 Mar 2011)
@@ -13,8 +13,14 @@
namespace odeint {
namespace detail {
+
+
template< class Stepper , class System , class State , class Time , class Observer >
-size_t integrate_adaptive( Stepper stepper , System system , State &start_state , Time start_time , const Time &end_time , Time dt , Observer &observer , stepper_tag )
+size_t integrate_adaptive(
+ Stepper stepper , System system , State &start_state ,
+ Time &start_time , const Time &end_time , Time &dt ,
+ Observer &observer , stepper_tag
+ )
{
size_t count = 0;
while( start_time < end_time )
@@ -27,20 +33,46 @@
return count;
}
-template< class Stepper , class System , class State , class Time , class Observer >
-size_t integrate_adaptive( Stepper stepper , System system , State &start_state , const Time &start_time , const Time &end_time , const Time &dt , Observer &observer , error_stepper_tag )
-{
- return 0;
-}
+
+
template< class Stepper , class System , class State , class Time , class Observer >
-size_t integrate_adaptive( Stepper stepper , System system , State &start_state , const Time &start_time , const Time &end_time , const Time &dt , Observer observer , controlled_stepper_tag )
+size_t integrate_adaptive(
+ Stepper stepper , System system , State &start_state ,
+ Time &start_time , const Time &end_time , Time &dt ,
+ Observer observer , controlled_stepper_tag
+ )
{
- return 0;
+ size_t num_of_steps = 0;
+ while( start_time < end_time )
+ {
+ observer( start_time , start_state );
+ if( ( start_time + dt ) > end_time )
+ {
+ dt = end_time - start_time;
+ }
+
+ size_t trials = 0;
+ controlled_step_result res = success_step_size_unchanged;
+ do
+ {
+ res = stepper.try_step( system , start_state , start_time , dt );
+ ++trials;
+ }
+ while( ( res == step_size_decreased ) && ( trials < 1000 ) );
+ ++num_of_steps;
+ }
+ observer( start_time , start_state );
+ return num_of_steps;
}
+
+
template< class Stepper , class System , class State , class Time , class Observer >
-size_t integrate_adaptive( Stepper stepper , System system , State &start_state , const Time &start_time , const Time &end_time , const Time &dt , Observer observer , dense_output_stepper_tag )
+size_t integrate_adaptive(
+ Stepper stepper , System system , State &start_state ,
+ const Time &start_time , const Time &end_time , const Time &dt ,
+ Observer observer , dense_output_stepper_tag )
{
return 0;
}
Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/integrate/detail/integrate_const.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/integrate/detail/integrate_const.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/integrate/detail/integrate_const.hpp 2011-03-15 04:45:41 EDT (Tue, 15 Mar 2011)
@@ -8,6 +8,9 @@
#ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_CONST_HPP_
#define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_CONST_HPP_
+
+#include <boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp>
+
#include <iostream>
using namespace std;
@@ -17,8 +20,14 @@
namespace odeint {
namespace detail {
+
+
template< class Stepper , class System , class State , class Time , class Observer >
-size_t integrate_const( Stepper stepper , System system , State &start_state , Time start_time , const Time &end_time , const Time &dt , Observer &observer , stepper_tag )
+size_t integrate_const(
+ Stepper stepper , System system , State &start_state ,
+ Time start_time , Time end_time , Time dt ,
+ Observer &observer , stepper_tag
+ )
{
while( start_time < end_time )
{
@@ -30,41 +39,65 @@
return 0;
}
+
+
template< class Stepper , class System , class State , class Time , class Observer >
-size_t integrate_const( Stepper stepper , System system , State &start_state , Time start_time , const Time &end_time , const Time &dt , Observer observer , controlled_stepper_tag )
+size_t integrate_const(
+ Stepper stepper , System system , State &start_state ,
+ Time &start_time , const Time &end_time , Time &dt ,
+ Observer observer , controlled_stepper_tag
+ )
{
- clog << "huhu" << endl;
+ size_t count = 0;
Time time_step = dt;
while( start_time < end_time )
{
observer( start_time , start_state );
- Time next_time = start_time + dt;
- while( start_time < next_time )
- {
- if( ( start_time + time_step ) > next_time )
- {
- time_step = next_time - start_time;
- }
- size_t trials = 0;
-
- // the following loop can maybe be taken from another integrate functions
- controlled_step_result res = success_step_size_unchanged;
- do
- {
- stepper.try_step( system , start_state , start_time , time_step );
- ++trials;
- }
- while( ( res == step_size_decreased ) || ( trials < 1000 ) );
- }
+ Time next_time = start_time + time_step;
+ if( next_time > end_time ) next_time = end_time;
+ detail::integrate_adaptive(
+ stepper , system , start_state , start_time , next_time , dt ,
+ do_nothing_observer() , controlled_stepper_tag() );
+ ++count;
}
observer( start_time , start_state );
-
- return 0;
+ return count;
}
+
+
template< class Stepper , class System , class State , class Time , class Observer >
-size_t integrate_const( Stepper stepper , System system , State &start_state , const Time &start_time , const Time &end_time , const Time &dt , Observer observer , dense_output_stepper_tag )
+size_t integrate_const(
+ Stepper stepper , System system , State &start_state ,
+ Time start_time , Time end_time , Time dt ,
+ Observer observer , dense_output_stepper_tag )
{
+ clog << "dense output" << endl;
+ stepper.initialize( start_state , start_time , dt );
+
+ size_t count = 0;
+ size_t count2 = 0;
+ while( start_time < end_time )
+ {
+ while( ( start_time < stepper.current_time() ) && ( start_time < end_time ) )
+ {
+ stepper.calc_state( start_time , start_state );
+ observer( start_time , start_state );
+ start_time += dt;
+ ++count;
+ }
+
+ // we have not reached the end, do another real step
+ if( start_time < end_time )
+ {
+ stepper.do_step( system );
+ ++count2;
+ }
+ }
+ clog << count2 << endl;
+ return count;
+
+
observer( start_time , start_state );
return 0;
}
Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/integrate/integrate.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/integrate/integrate.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/integrate/integrate.hpp 2011-03-15 04:45:41 EDT (Tue, 15 Mar 2011)
@@ -1,6 +1,16 @@
/*
* integrate_const.hpp
*
+ *
+ * Overview:
+ *
+ * size_t integrate( stepper , system , start_state , start_time , end_time , dt , observer );
+ *
+ * Time integrate_n_steps( stepper , system , start_state , start_time , dt , num_of_steps , observer );
+ *
+ * size_t integrate_adaptive( stepper , system , start_state , start_time , end_time , start_dt , observer );
+ *
+ *
* Created on: Jan 31, 2011
* Author: karsten
*/
@@ -20,17 +30,6 @@
namespace odeint {
-/*
-
-Overview:
-
-size_t integrate( stepper , system , start_state , start_time , end_time , dt , observer );
-
-Time integrate_n_steps( stepper , system , start_state , start_time , dt , num_of_steps , observer );
-
-size_t integrate_adaptive( stepper , system , start_state , start_time , end_time , start_dt , observer );
-
-*/
@@ -39,65 +38,77 @@
* Integrates with constant time step dt.
*/
template< class Stepper , class System , class State , class Time , class Observer >
-size_t integrate( Stepper stepper , System system , State &start_state , const Time &start_time , const Time &end_time , const Time &dt , Observer observer )
+size_t integrate(
+ Stepper stepper , System system , State &start_state ,
+ Time start_time , Time end_time , Time dt ,
+ Observer observer
+ )
{
// we want to get as fast as possible to the end
if( boost::is_same< do_nothing_observer , Observer >::value )
{
- return detail::integrate_adaptive( stepper , system , start_state , start_time , end_time , dt , observer , typename Stepper::stepper_category() );
+ return detail::integrate_adaptive(
+ stepper , system , start_state ,
+ start_time , end_time , dt ,
+ observer , typename Stepper::stepper_category() );
}
else
{
- return detail::integrate_const( stepper , system , start_state , start_time , end_time , dt , observer , typename Stepper::stepper_category() );
+ return detail::integrate_const(
+ stepper , system , start_state ,
+ start_time , end_time , dt ,
+ observer , typename Stepper::stepper_category() );
}
}
+
+
+
+/*
+ * Integrates n steps
+ */
template< class Stepper , class System , class State , class Time , class Observer >
-Time integrate_n_steps( Stepper stepper , System system , State &start_state , const Time &start_time , const Time &dt , size_t num_of_steps , Observer observer )
+Time integrate_n_steps(
+ Stepper stepper , System system , State &start_state ,
+ Time start_time , Time dt , size_t num_of_steps ,
+ Observer observer )
{
Time end_time = dt * num_of_steps;
// we want to get as fast as possible to the end
if( boost::is_same< do_nothing_observer , Observer >::type::value )
{
- detail::integrate_adaptive( stepper , system , start_state , start_time , end_time , dt , observer , typename Stepper::stepper_category() );
+ detail::integrate_adaptive(
+ stepper , system , start_state ,
+ start_time , end_time , dt ,
+ observer , typename Stepper::stepper_category() );
}
else
{
- detail::integrate_const( stepper , system , start_state , start_time , end_time , dt , observer , typename Stepper::stepper_category() );
+ detail::integrate_const(
+ stepper , system , start_state ,
+ start_time , end_time , dt ,
+ observer , typename Stepper::stepper_category() );
}
return end_time;
}
-template< class Stepper , class System , class State , class Time , class Observer >
-size_t integrate_adaptive( Stepper stepper , System system , State &start_state , const Time &start_time , const Time &end_time , const Time &dt , Observer observer )
-{
- return detail::integrate_adaptive( stepper , system , start_state , start_time , end_time , dt , observer , typename Stepper::stepper_category() );
-}
-
-
-
-/*
- * Old integrate functions
- */
-
-// Constant integrator
-//size_t integrate_const( stepper , system , state , start_time , end_time , dt , observer );
-//size_t integrate_const( stepper , system , state , start_time , end_time , dt );
-//time_type integrate_const_steps( stepper , system , state , start_time , dt , num_of_steps , observer );
-//time_type integrate_const_steps( stepper , system , state , start_time , dt , num_of_steps );
-//
-//// Adaptive integrators
-//size_t integrate_adaptive( stepper, system , state , start_time , end_time , dt , observer );
-//size_t integrate_adaptive( stepper, system , state , start_time , end_time , dt );
-//size_t integrate( stepper , system , state , start_time , end_end , dt , time_inserter , state_inserter );
-//size_t integrate( system , state,start_time , end_time , time_inserter , state_inserter , dt = 1E-4 , eps_abs = 1E-6 , eps_rel = 1E-7 , a_x = 1.0 , a_dxdt = 1.0 );
-
+template< class Stepper , class System , class State , class Time , class Observer >
+size_t integrate_adaptive(
+ Stepper stepper , System system , State &start_state ,
+ Time start_time , Time end_time , Time dt ,
+ Observer observer )
+{
+ return detail::integrate_adaptive(
+ stepper , system , start_state ,
+ start_time , end_time , dt ,
+ observer , typename Stepper::stepper_category() );
+}
Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/controlled_error_stepper.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/controlled_error_stepper.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/controlled_error_stepper.hpp 2011-03-15 04:45:41 EDT (Tue, 15 Mar 2011)
@@ -55,7 +55,12 @@
typedef Operations operations_type;
- error_checker_standard( void ) : m_eps_abs( 1E-6 ) , m_eps_rel( 1E-6 ) , m_a_x( 1.0 ) , m_a_dxdt( 1.0 )
+ error_checker_standard(
+ value_type eps_abs = static_cast< value_type >( 1.0e-6 ) ,
+ value_type eps_rel = static_cast< value_type >( 1.0e-6 ) ,
+ value_type a_x = static_cast< value_type >( 1.0 ) ,
+ value_type a_dxdt = static_cast< value_type >( 1.0 ) )
+ : m_eps_abs( eps_abs ) , m_eps_rel( eps_rel ) , m_a_x( a_x ) , m_a_dxdt( a_dxdt )
{}
Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/regression_test/integrate_functions.cpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/regression_test/integrate_functions.cpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/regression_test/integrate_functions.cpp 2011-03-15 04:45:41 EDT (Tue, 15 Mar 2011)
@@ -126,7 +126,32 @@
// integrate_n_steps( explicit_euler< state_type >() , lorenz() , x1 , 0.0 , 0.1 , 100 , cout << _1 << "\n" );
// integrate_adaptive( explicit_euler< state_type >() , lorenz() , x1 , 0.0 , 10.0 , 0.1 , cout << _1 << "\n" );
- integrate( controlled_error_stepper< explicit_error_rk54_ck< state_type > >() , lorenz() , x1 , 0.0 , 10.0 , 0.01 , tmp_func() );
+
+
+
+ // works
+// size_t num_of_steps = integrate(
+// controlled_error_stepper< explicit_error_rk54_ck< state_type > >() ,
+// lorenz() , x1 , 0.0 , 50.0 , 0.1 , tmp_func() );
+// clog << num_of_steps << endl;
+
+ // works
+// num_of_steps = integrate_adaptive(
+// controlled_error_stepper< explicit_error_rk54_ck< state_type > >() ,
+// lorenz() , x1 , 0.0 , 50.0 , 0.1 , tmp_func() );
+// clog << num_of_steps << endl;
+
+
+ // seems to work, check
+ typedef explicit_error_dopri5< state_type > dopri5_type;
+ typedef controlled_error_stepper< dopri5_type > controlled_error_stepper_type;
+ typedef dense_output_controlled_explicit_fsal< controlled_error_stepper_type > stepper_type;
+
+ controlled_error_stepper_type controlled_stepper(
+ dopri5_type() , error_checker_standard< double >( 1.0e-1 , 0.1 ) );
+ size_t num_of_steps = integrate(
+ stepper_type( controlled_stepper ) , lorenz() , x1 , 0.0 , 50.0 , 0.001 , tmp_func() );
+ clog << num_of_steps << endl;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk