]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/odeint/examples/bind_member_functions.cpp
3 libs/numeric/odeint/examples/bind_member_functions.hpp
9 Copyright 2012 Karsten Ahnert
10 Copyright 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)
19 #include <boost/numeric/odeint.hpp>
21 namespace odeint
= boost::numeric::odeint
;
23 typedef boost::array
< double , 3 > state_type
;
26 template< class Obj
, class Mem
>
34 ode_wrapper( Obj obj
, Mem mem
) : m_obj( obj
) , m_mem( mem
) { }
36 template< class State
, class Deriv
, class Time
>
37 void operator()( const State
&x
, Deriv
&dxdt
, Time t
)
39 (m_obj
.*m_mem
)( x
, dxdt
, t
);
43 template< class Obj
, class Mem
>
44 ode_wrapper
< Obj
, Mem
> make_ode_wrapper( Obj obj
, Mem mem
)
46 return ode_wrapper
< Obj
, Mem
>( obj
, mem
);
51 template< class Obj
, class Mem
>
52 class observer_wrapper
59 observer_wrapper( Obj obj
, Mem mem
) : m_obj( obj
) , m_mem( mem
) { }
61 template< class State
, class Time
>
62 void operator()( const State
&x
, Time t
)
64 (m_obj
.*m_mem
)( x
, t
);
68 template< class Obj
, class Mem
>
69 observer_wrapper
< Obj
, Mem
> make_observer_wrapper( Obj obj
, Mem mem
)
71 return observer_wrapper
< Obj
, Mem
>( obj
, mem
);
76 //[ bind_member_function
79 void ode( const state_type
&x
, state_type
&dxdt
, double t
) const
81 dxdt
[0] = 10.0 * ( x
[1] - x
[0] );
82 dxdt
[1] = 28.0 * x
[0] - x
[1] - x
[0] * x
[2];
83 dxdt
[2] = -8.0 / 3.0 * x
[2] + x
[0] * x
[1];
87 int main( int argc
, char *argv
[] )
89 using namespace boost::numeric::odeint
;
90 state_type x
= {{ 10.0 , 10.0 , 10.0 }};
91 integrate_const( runge_kutta4
< state_type
>() , make_ode_wrapper( lorenz() , &lorenz::ode
) ,
92 x
, 0.0 , 10.0 , 0.01 );
101 void ode( const state_type &x , state_type &dxdt , double t ) const
103 dxdt[0] = 10.0 * ( x[1] - x[0] );
104 dxdt[1] = 28.0 * x[0] - x[1] - x[0] * x[2];
105 dxdt[2] = -8.0 / 3.0 * x[2] + x[0] * x[1];
108 void obs( const state_type &x , double t ) const
110 std::cout << t << " " << x[0] << " " << x[1] << " " << x[2] << "\n";
114 int main( int argc , char *argv[] )
116 using namespace boost::numeric::odeint;
118 state_type x = {{ 10.0 , 10.0 , 10.0 }};
119 integrate_const( runge_kutta4< state_type >() ,
120 make_ode_wrapper( lorenz() , &lorenz::ode ) ,
121 x , 0.0 , 10.0 , 0.01 ,
122 make_observer_wrapper( lorenz() , &lorenz::obs ) );