blob: 2c716ca118c3b55ffb2364d2367bd58c607b99dc [file] [log] [blame]
Brian Silverman7c33ab22018-08-04 17:14:51 -07001/*
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
20typedef std::list< double > state_type;
21
22namespace boost { namespace numeric { namespace odeint {
23
24template< >
25struct is_resizeable< state_type >
26{ // declare resizeability
27 typedef boost::true_type type;
28 const static bool value = type::value;
29};
30
31template< >
32struct same_size_impl< state_type , state_type >
33{ // define how to check size
34 static bool same_size( const state_type &v1 ,
35 const state_type &v2 )
36 {
37 return v1.size() == v2.size();
38 }
39};
40
41template< >
42struct resize_impl< state_type , state_type >
43{ // define how to resize
44 static void resize( state_type &v1 ,
45 const state_type &v2 )
46 {
47 v1.resize( v2.size() );
48 }
49};
50
51} } }
52//]
53
54void 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
68using namespace boost::numeric::odeint;
69
70int 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}