1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/*
[auto_generated]
libs/numeric/odeint/examples/bind_member_functions.hpp
[begin_description]
tba.
[end_description]
Copyright 2012 Karsten Ahnert
Copyright 2012 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#include <iostream>
#include <boost/numeric/odeint.hpp>
namespace odeint = boost::numeric::odeint;
typedef boost::array< double , 3 > state_type;
//[ ode_wrapper
template< class Obj , class Mem >
class ode_wrapper
{
Obj m_obj;
Mem m_mem;
public:
ode_wrapper( Obj obj , Mem mem ) : m_obj( obj ) , m_mem( mem ) { }
template< class State , class Deriv , class Time >
void operator()( const State &x , Deriv &dxdt , Time t )
{
(m_obj.*m_mem)( x , dxdt , t );
}
};
template< class Obj , class Mem >
ode_wrapper< Obj , Mem > make_ode_wrapper( Obj obj , Mem mem )
{
return ode_wrapper< Obj , Mem >( obj , mem );
}
//]
template< class Obj , class Mem >
class observer_wrapper
{
Obj m_obj;
Mem m_mem;
public:
observer_wrapper( Obj obj , Mem mem ) : m_obj( obj ) , m_mem( mem ) { }
template< class State , class Time >
void operator()( const State &x , Time t )
{
(m_obj.*m_mem)( x , t );
}
};
template< class Obj , class Mem >
observer_wrapper< Obj , Mem > make_observer_wrapper( Obj obj , Mem mem )
{
return observer_wrapper< Obj , Mem >( obj , mem );
}
//[ bind_member_function
struct lorenz
{
void ode( const state_type &x , state_type &dxdt , double t ) const
{
dxdt[0] = 10.0 * ( x[1] - x[0] );
dxdt[1] = 28.0 * x[0] - x[1] - x[0] * x[2];
dxdt[2] = -8.0 / 3.0 * x[2] + x[0] * x[1];
}
};
int main( int argc , char *argv[] )
{
using namespace boost::numeric::odeint;
state_type x = {{ 10.0 , 10.0 , 10.0 }};
integrate_const( runge_kutta4< state_type >() , make_ode_wrapper( lorenz() , &lorenz::ode ) ,
x , 0.0 , 10.0 , 0.01 );
return 0;
}
//]
/*
struct lorenz
{
void ode( const state_type &x , state_type &dxdt , double t ) const
{
dxdt[0] = 10.0 * ( x[1] - x[0] );
dxdt[1] = 28.0 * x[0] - x[1] - x[0] * x[2];
dxdt[2] = -8.0 / 3.0 * x[2] + x[0] * x[1];
}
void obs( const state_type &x , double t ) const
{
std::cout << t << " " << x[0] << " " << x[1] << " " << x[2] << "\n";
}
};
int main( int argc , char *argv[] )
{
using namespace boost::numeric::odeint;
state_type x = {{ 10.0 , 10.0 , 10.0 }};
integrate_const( runge_kutta4< state_type >() ,
make_ode_wrapper( lorenz() , &lorenz::ode ) ,
x , 0.0 , 10.0 , 0.01 ,
make_observer_wrapper( lorenz() , &lorenz::obs ) );
return 0;
}
*/
|