blob: 51f85e033ee809f1e64ae3f1a9f1465044302290 [file] [log] [blame]
Brian Silverman7c33ab22018-08-04 17:14:51 -07001/*
2 [auto_generated]
3 libs/numeric/odeint/examples/bind_member_functions.hpp
4
5 [begin_description]
6 tba.
7 [end_description]
8
9 Copyright 2012 Karsten Ahnert
10 Copyright 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#include <iostream>
18
19#include <boost/numeric/odeint.hpp>
20
21namespace odeint = boost::numeric::odeint;
22
23typedef boost::array< double , 3 > state_type;
24
25//[ ode_wrapper
26template< class Obj , class Mem >
27class ode_wrapper
28{
29 Obj m_obj;
30 Mem m_mem;
31
32public:
33
34 ode_wrapper( Obj obj , Mem mem ) : m_obj( obj ) , m_mem( mem ) { }
35
36 template< class State , class Deriv , class Time >
37 void operator()( const State &x , Deriv &dxdt , Time t )
38 {
39 (m_obj.*m_mem)( x , dxdt , t );
40 }
41};
42
43template< class Obj , class Mem >
44ode_wrapper< Obj , Mem > make_ode_wrapper( Obj obj , Mem mem )
45{
46 return ode_wrapper< Obj , Mem >( obj , mem );
47}
48//]
49
50
51template< class Obj , class Mem >
52class observer_wrapper
53{
54 Obj m_obj;
55 Mem m_mem;
56
57public:
58
59 observer_wrapper( Obj obj , Mem mem ) : m_obj( obj ) , m_mem( mem ) { }
60
61 template< class State , class Time >
62 void operator()( const State &x , Time t )
63 {
64 (m_obj.*m_mem)( x , t );
65 }
66};
67
68template< class Obj , class Mem >
69observer_wrapper< Obj , Mem > make_observer_wrapper( Obj obj , Mem mem )
70{
71 return observer_wrapper< Obj , Mem >( obj , mem );
72}
73
74
75
76//[ bind_member_function
77struct lorenz
78{
79 void ode( const state_type &x , state_type &dxdt , double t ) const
80 {
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];
84 }
85};
86
87int main( int argc , char *argv[] )
88{
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 );
93 return 0;
94}
95//]
96
97
98/*
99struct lorenz
100{
101 void ode( const state_type &x , state_type &dxdt , double t ) const
102 {
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];
106 }
107
108 void obs( const state_type &x , double t ) const
109 {
110 std::cout << t << " " << x[0] << " " << x[1] << " " << x[2] << "\n";
111 }
112};
113
114int main( int argc , char *argv[] )
115{
116 using namespace boost::numeric::odeint;
117
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 ) );
123
124 return 0;
125}
126*/