3 boost/numeric/odeint/integrate/detail/integrate_const.hpp
6 integrate const 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_CONST_HPP_INCLUDED
18 #define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_CONST_HPP_INCLUDED
20 #include <boost/range/algorithm/for_each.hpp>
22 #include <boost/numeric/odeint/util/unwrap_reference.hpp>
23 #include <boost/numeric/odeint/stepper/stepper_categories.hpp>
24 #include <boost/numeric/odeint/util/unit_helper.hpp>
25 #include <boost/numeric/odeint/iterator/const_step_time_iterator.hpp>
26 #include <boost/numeric/odeint/iterator/integrate/detail/integrate_adaptive.hpp>
27 #include <boost/numeric/odeint/iterator/integrate/detail/functors.hpp>
28 #include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
35 // forward declaration
36 template< class Stepper , class System , class State , class Time , class Observer >
37 size_t integrate_adaptive(
38 Stepper stepper , System system , State &start_state ,
39 Time &start_time , Time end_time , Time &dt ,
40 Observer observer , controlled_stepper_tag
44 template< class Stepper , class System , class State , class Time , class Observer >
45 size_t integrate_const(
46 Stepper stepper , System system , State &start_state ,
47 Time start_time , Time end_time , Time dt ,
48 Observer observer , stepper_tag
53 boost::for_each( make_const_step_time_range( stepper , system , start_state ,
54 start_time , end_time , dt ) ,
55 // should we use traits<Stepper>::state_type here instead of State? NO!
56 obs_caller< Observer >( obs_calls , observer ) );
58 // step integration steps gives step+1 observer calls
64 template< class Stepper , class System , class State , class Time , class Observer >
65 size_t integrate_const(
66 Stepper stepper , System system , State &start_state ,
67 Time start_time , Time end_time , Time dt ,
68 Observer observer , controlled_stepper_tag
71 typename odeint::unwrap_reference< Observer >::type &obs = observer;
73 Time time = start_time;
74 const Time time_step = dt;
77 while( less_eq_with_sign( static_cast<Time>(time+time_step) , end_time , dt ) )
79 obs( start_state , time );
80 detail::integrate_adaptive( stepper , system , start_state , time , time+time_step , dt ,
81 null_observer() , controlled_stepper_tag() );
82 // direct computation of the time avoids error propagation happening when using time += dt
83 // we need clumsy type analysis to get boost units working here
85 time = start_time + static_cast< typename unit_value_type<Time>::type >(step) * time_step;
87 obs( start_state , time );
93 template< class Stepper , class System , class State , class Time , class Observer >
94 size_t integrate_const(
95 Stepper stepper , System system , State &start_state ,
96 Time start_time , Time end_time , Time dt ,
97 Observer observer , dense_output_stepper_tag
100 size_t obs_calls = 0;
102 boost::for_each( make_const_step_time_range( stepper , system , start_state ,
103 start_time , end_time , dt ) ,
104 obs_caller< Observer >( obs_calls , observer ) );