Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
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/integrate/detail/integrate_n_steps.hpp> | |
26 #include <boost/numeric/odeint/util/bind.hpp> | |
27 #include <boost/numeric/odeint/util/unwrap_reference.hpp> | |
28 #include <boost/numeric/odeint/util/copy.hpp> | |
29 | |
30 #include <boost/numeric/odeint/util/detail/less_with_sign.hpp> | |
31 | |
32 | |
33 #include <iostream> | |
34 | |
35 namespace boost { | |
36 namespace numeric { | |
37 namespace odeint { | |
38 namespace detail { | |
39 | |
40 // forward declaration | |
41 template< class Stepper , class System , class State , class Time , class Observer> | |
42 Time integrate_n_steps( | |
43 Stepper stepper , System system , State &start_state , | |
44 Time start_time , Time dt , size_t num_of_steps , | |
45 Observer observer , stepper_tag ); | |
46 | |
47 /* | |
48 * integrate_adaptive for simple stepper is basically an integrate_const + some last step | |
49 */ | |
50 template< class Stepper , class System , class State , class Time , class Observer > | |
51 size_t integrate_adaptive( | |
52 Stepper stepper , System system , State &start_state , | |
53 Time start_time , Time end_time , Time dt , | |
54 Observer observer , stepper_tag | |
55 ) | |
56 { | |
57 size_t steps = static_cast< size_t >( (end_time-start_time)/dt ); | |
58 Time end = detail::integrate_n_steps( stepper , system , start_state , start_time , | |
59 dt , steps , observer , stepper_tag() ); | |
60 if( less_with_sign( end , end_time , dt ) ) | |
61 { //make a last step to end exactly at end_time | |
62 stepper.do_step( system , start_state , end , end_time - end ); | |
63 steps++; | |
64 typename odeint::unwrap_reference< Observer >::type &obs = observer; | |
65 obs( start_state , end_time ); | |
66 } | |
67 return steps; | |
68 } | |
69 | |
70 | |
71 /* | |
72 * classical integrate adaptive | |
73 */ | |
74 template< class Stepper , class System , class State , class Time , class Observer > | |
75 size_t integrate_adaptive( | |
76 Stepper stepper , System system , State &start_state , | |
77 Time &start_time , Time end_time , Time &dt , | |
78 Observer observer , controlled_stepper_tag | |
79 ) | |
80 { | |
81 typename odeint::unwrap_reference< Observer >::type &obs = observer; | |
82 | |
83 const size_t max_attempts = 1000; | |
84 const char *error_string = "Integrate adaptive : Maximal number of iterations reached. A step size could not be found."; | |
85 size_t count = 0; | |
86 while( less_with_sign( start_time , end_time , dt ) ) | |
87 { | |
88 obs( start_state , start_time ); | |
89 if( less_with_sign( end_time , start_time + dt , dt ) ) | |
90 { | |
91 dt = end_time - start_time; | |
92 } | |
93 | |
94 size_t trials = 0; | |
95 controlled_step_result res = success; | |
96 do | |
97 { | |
98 res = stepper.try_step( system , start_state , start_time , dt ); | |
99 ++trials; | |
100 } | |
101 while( ( res == fail ) && ( trials < max_attempts ) ); | |
102 if( trials == max_attempts ) throw std::overflow_error( error_string ); | |
103 | |
104 ++count; | |
105 } | |
106 obs( start_state , start_time ); | |
107 return count; | |
108 } | |
109 | |
110 | |
111 /* | |
112 * integrate adaptive for dense output steppers | |
113 * | |
114 * step size control is used if the stepper supports it | |
115 */ | |
116 template< class Stepper , class System , class State , class Time , class Observer > | |
117 size_t integrate_adaptive( | |
118 Stepper stepper , System system , State &start_state , | |
119 Time start_time , Time end_time , Time dt , | |
120 Observer observer , dense_output_stepper_tag ) | |
121 { | |
122 typename odeint::unwrap_reference< Observer >::type &obs = observer; | |
123 | |
124 size_t count = 0; | |
125 stepper.initialize( start_state , start_time , dt ); | |
126 | |
127 while( less_with_sign( stepper.current_time() , end_time , stepper.current_time_step() ) ) | |
128 { | |
129 while( less_eq_with_sign( stepper.current_time() + stepper.current_time_step() , | |
130 end_time , | |
131 stepper.current_time_step() ) ) | |
132 { //make sure we don't go beyond the end_time | |
133 obs( stepper.current_state() , stepper.current_time() ); | |
134 stepper.do_step( system ); | |
135 ++count; | |
136 } | |
137 stepper.initialize( stepper.current_state() , stepper.current_time() , end_time - stepper.current_time() ); | |
138 } | |
139 obs( stepper.current_state() , stepper.current_time() ); | |
140 // overwrite start_state with the final point | |
141 boost::numeric::odeint::copy( stepper.current_state() , start_state ); | |
142 return count; | |
143 } | |
144 | |
145 | |
146 | |
147 | |
148 } // namespace detail | |
149 } // namespace odeint | |
150 } // namespace numeric | |
151 } // namespace boost | |
152 | |
153 | |
154 #endif // BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED |