2 * Copyright 2011-2012 Mario Mulansky
3 * Copyright 2012-2013 Karsten Ahnert
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)
9 * Example for self defined vector type.
14 #include <boost/numeric/odeint.hpp>
17 template< size_t MAX_N
>
20 typedef std::vector
< double > vector
;
23 typedef vector::iterator iterator
;
24 typedef vector::const_iterator const_iterator
;
27 my_vector( const size_t N
)
39 // ... [ implement container interface ]
41 const double & operator[]( const size_t n
) const
44 double & operator[]( const size_t n
)
48 { return m_v
.begin(); }
50 const_iterator
begin() const
51 { return m_v
.begin(); }
56 const_iterator
end() const
60 { return m_v
.size(); }
62 void resize( const size_t n
)
66 std::vector
< double > m_v
;
70 //[my_vector_resizeable
71 // define my_vector as resizeable
73 namespace boost
{ namespace numeric
{ namespace odeint
{
76 struct is_resizeable
< my_vector
<N
> >
78 typedef boost::true_type type
;
79 static const bool value
= type::value
;
86 typedef my_vector
<3> state_type
;
88 void lorenz( const state_type
&x
, state_type
&dxdt
, const double t
)
90 const double sigma( 10.0 );
91 const double R( 28.0 );
92 const double b( 8.0 / 3.0 );
94 dxdt
[0] = sigma
* ( x
[1] - x
[0] );
95 dxdt
[1] = R
* x
[0] - x
[1] - x
[0] * x
[2];
96 dxdt
[2] = -b
* x
[2] + x
[0] * x
[1];
99 using namespace boost::numeric::odeint
;
104 x
[0] = 5.0 ; x
[1] = 10.0 ; x
[2] = 10.0;
106 // make sure resizing is ON
107 BOOST_STATIC_ASSERT( is_resizeable
<state_type
>::value
== true );
109 // my_vector works with range_algebra as it implements
110 // the required parts of a container interface
111 // no further work is required
113 integrate_const( runge_kutta4
< state_type
>() , lorenz
, x
, 0.0 , 10.0 , 0.1 );