1 /*
2 Copyright 2011-2012 Mario Mulansky
3 Copyright 2012-2013 Karsten Ahnert
4
5 Distributed under the Boost Software License, Version 1.0.
6 (See accompanying file LICENSE_1_0.txt or
7 copy at http://www.boost.org/LICENSE_1_0.txt)
8 */
9
10
11 /* example showing how odeint can be used with std::list */
12
13 #include <iostream>
14 #include <cmath>
15 #include <list>
16
17 #include <boost/numeric/odeint.hpp>
18
19 //[ list_bindings
20 typedef std::list< double > state_type;
21
22 namespace boost { namespace numeric { namespace odeint {
23
24 template< >
25 struct is_resizeable< state_type >
26 { // declare resizeability
27 typedef boost::true_type type;
28 const static bool value = type::value;
29 };
30
31 template< >
32 struct same_size_impl< state_type , state_type >
33 { // define how to check size
same_sizeboost::numeric::odeint::same_size_impl34 static bool same_size( const state_type &v1 ,
35 const state_type &v2 )
36 {
37 return v1.size() == v2.size();
38 }
39 };
40
41 template< >
42 struct resize_impl< state_type , state_type >
43 { // define how to resize
resizeboost::numeric::odeint::resize_impl44 static void resize( state_type &v1 ,
45 const state_type &v2 )
46 {
47 v1.resize( v2.size() );
48 }
49 };
50
51 } } }
52 //]
53
lattice(const state_type & x,state_type & dxdt,const double)54 void lattice( const state_type &x , state_type &dxdt , const double /* t */ )
55 {
56 state_type::const_iterator x_begin = x.begin();
57 state_type::const_iterator x_end = x.end();
58 state_type::iterator dxdt_begin = dxdt.begin();
59
60 x_end--; // stop one before last
61 while( x_begin != x_end )
62 {
63 *(dxdt_begin++) = std::sin( *(x_begin) - *(x_begin++) );
64 }
65 *dxdt_begin = sin( *x_begin - *(x.begin()) ); // periodic boundary
66 }
67
68 using namespace boost::numeric::odeint;
69
main()70 int main()
71 {
72 const int N = 32;
73 state_type x;
74 for( int i=0 ; i<N ; ++i )
75 x.push_back( 1.0*i/N );
76
77 integrate_const( runge_kutta4< state_type >() , lattice , x , 0.0 , 10.0 , 0.1 );
78 }
79