3 boost/numeric/odeint/integrate/detail/integrate_n_steps.hpp
6 integrate steps implementation
9 Copyright 2009-2012 Karsten Ahnert
10 Copyright 2009-2012 Mario Mulansky
12 Distributed under the Boost Software License, Version 1.0.
13 (See accompanying file LICENSE_1_0.txt or
14 copy at http://www.boost.org/LICENSE_1_0.txt)
17 #ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_N_STEPS_HPP_INCLUDED
18 #define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_N_STEPS_HPP_INCLUDED
20 #include <boost/numeric/odeint/util/unwrap_reference.hpp>
21 #include <boost/numeric/odeint/stepper/stepper_categories.hpp>
22 #include <boost/numeric/odeint/iterator/integrate/detail/integrate_adaptive.hpp>
23 #include <boost/numeric/odeint/iterator/integrate/detail/functors.hpp>
24 #include <boost/numeric/odeint/iterator/n_step_time_iterator.hpp>
25 #include <boost/numeric/odeint/util/unit_helper.hpp>
27 #include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
34 // forward declaration
35 template< class Stepper , class System , class State , class Time , class Observer >
36 size_t integrate_adaptive(
37 Stepper stepper , System system , State &start_state ,
38 Time &start_time , Time end_time , Time &dt ,
39 Observer observer , controlled_stepper_tag
44 template< class Stepper , class System , class State , class Time , class Observer>
45 Time integrate_n_steps(
46 Stepper stepper , System system , State &start_state ,
47 Time start_time , Time dt , size_t num_of_steps ,
48 Observer observer , stepper_tag )
50 // ToDo: is there a better way to extract the final time?
51 Time t = start_time; // Assignment is only here to avoid warnings.
52 boost::for_each( make_n_step_time_range( stepper , system , start_state ,
53 start_time , dt , num_of_steps ) ,
54 obs_caller_time< Observer , Time >( t , observer ) );
59 /* controlled version */
60 template< class Stepper , class System , class State , class Time , class Observer>
61 Time integrate_n_steps(
62 Stepper stepper , System system , State &start_state ,
63 Time start_time , Time dt , size_t num_of_steps ,
64 Observer observer , controlled_stepper_tag )
66 typename odeint::unwrap_reference< Observer >::type &obs = observer;
68 Time time = start_time;
71 for( size_t step = 0; step < num_of_steps ; ++step )
73 obs( start_state , time );
74 detail::integrate_adaptive( stepper , system , start_state , time , static_cast<Time>(time+time_step) , dt ,
75 null_observer() , controlled_stepper_tag() );
76 // direct computation of the time avoids error propagation happening when using time += dt
77 // we need clumsy type analysis to get boost units working here
78 time = start_time + static_cast< typename unit_value_type<Time>::type >(step+1) * time_step;
80 obs( start_state , time );
86 /* dense output version */
87 template< class Stepper , class System , class State , class Time , class Observer>
88 Time integrate_n_steps(
89 Stepper stepper , System system , State &start_state ,
90 Time start_time , Time dt , size_t num_of_steps ,
91 Observer observer , dense_output_stepper_tag )
93 // ToDo: is there a better way to extract the final time?
94 Time t = start_time; // Assignment is only here to avoid warnings.
95 boost::for_each( make_n_step_time_range( stepper , system , start_state ,
96 start_time , dt , num_of_steps ) ,
97 obs_caller_time< Observer , Time >( t , observer ) );
107 #endif /* BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_N_STEPS_HPP_INCLUDED */