]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | [auto_generated] | |
3 | boost/numeric/odeint/integrate/detail/integrate_const.hpp | |
4 | ||
5 | [begin_description] | |
6 | integrate const implementation | |
7 | [end_description] | |
8 | ||
9 | Copyright 2009-2012 Karsten Ahnert | |
10 | Copyright 2009-2012 Mario Mulansky | |
11 | ||
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) | |
15 | */ | |
16 | ||
17 | #ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_CONST_HPP_INCLUDED | |
18 | #define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_CONST_HPP_INCLUDED | |
19 | ||
20 | #include <boost/range/algorithm/for_each.hpp> | |
21 | ||
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> | |
29 | ||
30 | namespace boost { | |
31 | namespace numeric { | |
32 | namespace odeint { | |
33 | namespace detail { | |
34 | ||
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 | |
41 | ); | |
42 | ||
43 | ||
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 | |
49 | ) | |
50 | { | |
51 | size_t obs_calls = 0; | |
52 | ||
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 ) ); | |
57 | ||
58 | // step integration steps gives step+1 observer calls | |
59 | return obs_calls-1; | |
60 | } | |
61 | ||
62 | ||
63 | ||
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 | |
69 | ) | |
70 | { | |
71 | typename odeint::unwrap_reference< Observer >::type &obs = observer; | |
72 | ||
73 | Time time = start_time; | |
74 | const Time time_step = dt; | |
75 | int step = 0; | |
76 | ||
77 | while( less_eq_with_sign( static_cast<Time>(time+time_step) , end_time , dt ) ) | |
78 | { | |
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 | |
84 | ++step; | |
85 | time = start_time + static_cast< typename unit_value_type<Time>::type >(step) * time_step; | |
86 | } | |
87 | obs( start_state , time ); | |
88 | ||
89 | return step; | |
90 | } | |
91 | ||
92 | ||
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 | |
98 | ) | |
99 | { | |
100 | size_t obs_calls = 0; | |
101 | ||
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 ) ); | |
105 | return obs_calls-1; | |
106 | } | |
107 | ||
108 | ||
109 | } } } } | |
110 | ||
111 | #endif |