]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/numeric/odeint/stepper/rosenbrock4_dense_output.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / numeric / odeint / stepper / rosenbrock4_dense_output.hpp
1 /*
2 [auto_generated]
3 boost/numeric/odeint/stepper/rosenbrock4_dense_output.hpp
4
5 [begin_description]
6 Dense output for Rosenbrock 4.
7 [end_description]
8
9 Copyright 2011-2012 Karsten Ahnert
10 Copyright 2011-2015 Mario Mulansky
11 Copyright 2012 Christoph Koke
12
13 Distributed under the Boost Software License, Version 1.0.
14 (See accompanying file LICENSE_1_0.txt or
15 copy at http://www.boost.org/LICENSE_1_0.txt)
16 */
17
18
19 #ifndef BOOST_NUMERIC_ODEINT_STEPPER_ROSENBROCK4_DENSE_OUTPUT_HPP_INCLUDED
20 #define BOOST_NUMERIC_ODEINT_STEPPER_ROSENBROCK4_DENSE_OUTPUT_HPP_INCLUDED
21
22
23 #include <utility>
24
25 #include <boost/numeric/odeint/util/bind.hpp>
26
27 #include <boost/numeric/odeint/stepper/rosenbrock4_controller.hpp>
28 #include <boost/numeric/odeint/util/is_resizeable.hpp>
29
30 #include <boost/numeric/odeint/integrate/max_step_checker.hpp>
31
32
33 namespace boost {
34 namespace numeric {
35 namespace odeint {
36
37 template< class ControlledStepper >
38 class rosenbrock4_dense_output
39 {
40
41 public:
42
43 typedef ControlledStepper controlled_stepper_type;
44 typedef typename unwrap_reference< controlled_stepper_type >::type unwrapped_controlled_stepper_type;
45 typedef typename unwrapped_controlled_stepper_type::stepper_type stepper_type;
46 typedef typename stepper_type::value_type value_type;
47 typedef typename stepper_type::state_type state_type;
48 typedef typename stepper_type::wrapped_state_type wrapped_state_type;
49 typedef typename stepper_type::time_type time_type;
50 typedef typename stepper_type::deriv_type deriv_type;
51 typedef typename stepper_type::wrapped_deriv_type wrapped_deriv_type;
52 typedef typename stepper_type::resizer_type resizer_type;
53 typedef dense_output_stepper_tag stepper_category;
54
55 typedef rosenbrock4_dense_output< ControlledStepper > dense_output_stepper_type;
56
57 rosenbrock4_dense_output( const controlled_stepper_type &stepper = controlled_stepper_type() )
58 : m_stepper( stepper ) ,
59 m_x1() , m_x2() ,
60 m_current_state_x1( true ) ,
61 m_t() , m_t_old() , m_dt()
62 {
63 }
64
65
66
67 template< class StateType >
68 void initialize( const StateType &x0 , time_type t0 , time_type dt0 )
69 {
70 m_resizer.adjust_size( x0 , detail::bind( &dense_output_stepper_type::template resize_impl< StateType > , detail::ref( *this ) , detail::_1 ) );
71 get_current_state() = x0;
72 m_t = t0;
73 m_dt = dt0;
74 }
75
76 template< class System >
77 std::pair< time_type , time_type > do_step( System system )
78 {
79 unwrapped_controlled_stepper_type &stepper = m_stepper;
80 failed_step_checker fail_checker; // to throw a runtime_error if step size adjustment fails
81 controlled_step_result res = fail;
82 m_t_old = m_t;
83 do
84 {
85 res = stepper.try_step( system , get_current_state() , m_t , get_old_state() , m_dt );
86 fail_checker(); // check for overflow of failed steps
87 }
88 while( res == fail );
89 stepper.stepper().prepare_dense_output();
90 this->toggle_current_state();
91 return std::make_pair( m_t_old , m_t );
92 }
93
94
95 /*
96 * The two overloads are needed in order to solve the forwarding problem.
97 */
98 template< class StateOut >
99 void calc_state( time_type t , StateOut &x )
100 {
101 unwrapped_controlled_stepper_type &stepper = m_stepper;
102 stepper.stepper().calc_state( t , x , get_old_state() , m_t_old , get_current_state() , m_t );
103 }
104
105 template< class StateOut >
106 void calc_state( time_type t , const StateOut &x )
107 {
108 unwrapped_controlled_stepper_type &stepper = m_stepper;
109 stepper.stepper().calc_state( t , x , get_old_state() , m_t_old , get_current_state() , m_t );
110 }
111
112
113 template< class StateType >
114 void adjust_size( const StateType &x )
115 {
116 unwrapped_controlled_stepper_type &stepper = m_stepper;
117 stepper.adjust_size( x );
118 resize_impl( x );
119 }
120
121
122
123
124 const state_type& current_state( void ) const
125 {
126 return get_current_state();
127 }
128
129 time_type current_time( void ) const
130 {
131 return m_t;
132 }
133
134 const state_type& previous_state( void ) const
135 {
136 return get_old_state();
137 }
138
139 time_type previous_time( void ) const
140 {
141 return m_t_old;
142 }
143
144 time_type current_time_step( void ) const
145 {
146 return m_dt;
147 }
148
149
150
151
152 private:
153
154 state_type& get_current_state( void )
155 {
156 return m_current_state_x1 ? m_x1.m_v : m_x2.m_v ;
157 }
158
159 const state_type& get_current_state( void ) const
160 {
161 return m_current_state_x1 ? m_x1.m_v : m_x2.m_v ;
162 }
163
164 state_type& get_old_state( void )
165 {
166 return m_current_state_x1 ? m_x2.m_v : m_x1.m_v ;
167 }
168
169 const state_type& get_old_state( void ) const
170 {
171 return m_current_state_x1 ? m_x2.m_v : m_x1.m_v ;
172 }
173
174 void toggle_current_state( void )
175 {
176 m_current_state_x1 = ! m_current_state_x1;
177 }
178
179
180 template< class StateIn >
181 bool resize_impl( const StateIn &x )
182 {
183 bool resized = false;
184 resized |= adjust_size_by_resizeability( m_x1 , x , typename is_resizeable<state_type>::type() );
185 resized |= adjust_size_by_resizeability( m_x2 , x , typename is_resizeable<state_type>::type() );
186 return resized;
187 }
188
189
190 controlled_stepper_type m_stepper;
191 resizer_type m_resizer;
192 wrapped_state_type m_x1 , m_x2;
193 bool m_current_state_x1;
194 time_type m_t , m_t_old , m_dt;
195 };
196
197
198
199 } // namespace odeint
200 } // namespace numeric
201 } // namespace boost
202
203
204 #endif // BOOST_NUMERIC_ODEINT_STEPPER_ROSENBROCK4_DENSE_OUTPUT_HPP_INCLUDED