]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | [auto_generated] | |
3 | boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp | |
4 | ||
5 | [begin_description] | |
6 | Default Integrate adaptive implementation. | |
7 | [end_description] | |
8 | ||
9 | Copyright 2009-2011 Karsten Ahnert | |
10 | Copyright 2009-2011 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 | ||
18 | #ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED | |
19 | #define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED | |
20 | ||
21 | #include <stdexcept> | |
22 | ||
23 | #include <boost/numeric/odeint/stepper/stepper_categories.hpp> | |
24 | #include <boost/numeric/odeint/stepper/controlled_step_result.hpp> | |
25 | #include <boost/numeric/odeint/iterator/integrate/detail/integrate_const.hpp> | |
26 | #include <boost/numeric/odeint/iterator/adaptive_time_iterator.hpp> | |
27 | #include <boost/numeric/odeint/iterator/integrate/detail/functors.hpp> | |
28 | #include <boost/numeric/odeint/util/bind.hpp> | |
29 | #include <boost/numeric/odeint/util/unwrap_reference.hpp> | |
30 | #include <boost/numeric/odeint/util/copy.hpp> | |
31 | ||
32 | #include <boost/numeric/odeint/util/detail/less_with_sign.hpp> | |
33 | ||
34 | namespace boost { | |
35 | namespace numeric { | |
36 | namespace odeint { | |
37 | namespace detail { | |
38 | ||
39 | // forward declaration | |
40 | template< class Stepper , class System , class State , class Time , class Observer> | |
41 | size_t integrate_const( | |
42 | Stepper stepper , System system , State &start_state , | |
43 | Time start_time , Time end_time , Time dt , | |
44 | Observer observer , stepper_tag ); | |
45 | ||
46 | /* | |
47 | * integrate_adaptive for simple stepper is basically an integrate_const + some last step | |
48 | */ | |
49 | template< class Stepper , class System , class State , class Time , class Observer > | |
50 | size_t integrate_adaptive( | |
51 | Stepper stepper , System system , State &start_state , | |
52 | Time start_time , Time end_time , Time dt , | |
53 | Observer observer , stepper_tag | |
54 | ) | |
55 | { | |
56 | size_t steps = detail::integrate_const( stepper , system , start_state , start_time , | |
57 | end_time , dt , observer , stepper_tag() ); | |
58 | typename odeint::unwrap_reference< Observer >::type &obs = observer; | |
59 | typename odeint::unwrap_reference< Stepper >::type &st = stepper; | |
60 | ||
61 | Time end = start_time + dt*steps; | |
62 | if( less_with_sign( end , end_time , dt ) ) | |
63 | { //make a last step to end exactly at end_time | |
64 | st.do_step( system , start_state , end , end_time - end ); | |
65 | steps++; | |
66 | obs( start_state , end_time ); | |
67 | } | |
68 | return steps; | |
69 | } | |
70 | ||
71 | ||
72 | /* | |
73 | * classical integrate adaptive | |
74 | */ | |
75 | template< class Stepper , class System , class State , class Time , class Observer > | |
76 | size_t integrate_adaptive( | |
77 | Stepper stepper , System system , State &start_state , | |
78 | Time &start_time , Time end_time , Time &dt , | |
79 | Observer observer , controlled_stepper_tag | |
80 | ) | |
81 | { | |
82 | size_t obs_calls = 0; | |
83 | ||
84 | boost::for_each( make_adaptive_time_range( stepper , system , start_state , | |
85 | start_time , end_time , dt ) , | |
86 | obs_caller< Observer >( obs_calls , observer ) ); | |
87 | ||
88 | return obs_calls-1; | |
89 | } | |
90 | ||
91 | ||
92 | /* | |
93 | * integrate adaptive for dense output steppers | |
94 | * | |
95 | * step size control is used if the stepper supports it | |
96 | */ | |
97 | template< class Stepper , class System , class State , class Time , class Observer > | |
98 | size_t integrate_adaptive( | |
99 | Stepper stepper , System system , State &start_state , | |
100 | Time start_time , Time end_time , Time dt , | |
101 | Observer observer , dense_output_stepper_tag ) | |
102 | { | |
103 | size_t obs_calls = 0; | |
104 | ||
105 | boost::for_each( make_adaptive_time_range( stepper , system , start_state , | |
106 | start_time , end_time , dt ) , | |
107 | obs_caller< Observer >( obs_calls , observer ) ); | |
108 | ||
109 | return obs_calls-1; | |
110 | } | |
111 | ||
112 | ||
113 | ||
114 | ||
115 | } // namespace detail | |
116 | } // namespace odeint | |
117 | } // namespace numeric | |
118 | } // namespace boost | |
119 | ||
120 | ||
121 | #endif // BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED |