• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * stuart_landau.cpp
3  *
4  * This example demonstrates how one can use odeint can be used with state types consisting of complex variables.
5  *
6  * Copyright 2011-2012 Karsten Ahnert
7  * Copyright 2011-2013 Mario Mulansky
8  * Distributed under the Boost Software License, Version 1.0. (See
9  * accompanying file LICENSE_1_0.txt or copy at
10  * http://www.boost.org/LICENSE_1_0.txt)
11  */
12 
13 #include <iostream>
14 #include <complex>
15 #include <boost/array.hpp>
16 
17 #include <boost/numeric/odeint.hpp>
18 
19 using namespace std;
20 using namespace boost::numeric::odeint;
21 
22 //[ stuart_landau_system_function
23 typedef complex< double > state_type;
24 
25 struct stuart_landau
26 {
27     double m_eta;
28     double m_alpha;
29 
stuart_landaustuart_landau30     stuart_landau( double eta = 1.0 , double alpha = 1.0 )
31     : m_eta( eta ) , m_alpha( alpha ) { }
32 
operator ()stuart_landau33     void operator()( const state_type &x , state_type &dxdt , double t ) const
34     {
35         const complex< double > I( 0.0 , 1.0 );
36         dxdt = ( 1.0 + m_eta * I ) * x - ( 1.0 + m_alpha * I ) * norm( x ) * x;
37     }
38 };
39 //]
40 
41 
42 /*
43 //[ stuart_landau_system_function_alternative
44 double eta = 1.0;
45 double alpha = 1.0;
46 
47 void stuart_landau( const state_type &x , state_type &dxdt , double t )
48 {
49     const complex< double > I( 0.0 , 1.0 );
50     dxdt = ( 1.0 + m_eta * I ) * x - ( 1.0 + m_alpha * I ) * norm( x ) * x;
51 }
52 //]
53 */
54 
55 
56 struct streaming_observer
57 {
58     std::ostream& m_out;
59 
streaming_observerstreaming_observer60     streaming_observer( std::ostream &out ) : m_out( out ) { }
61 
62     template< class State >
operator ()streaming_observer63     void operator()( const State &x , double t ) const
64     {
65         m_out << t;
66         m_out << "\t" << x.real() << "\t" << x.imag() ;
67         m_out << "\n";
68     }
69 };
70 
71 
72 
73 
main(int argc,char ** argv)74 int main( int argc , char **argv )
75 {
76     //[ stuart_landau_integration
77     state_type x = complex< double >( 1.0 , 0.0 );
78 
79     const double dt = 0.1;
80 
81     typedef runge_kutta4< state_type > stepper_type;
82 
83     integrate_const( stepper_type() , stuart_landau( 2.0 , 1.0 ) , x , 0.0 , 10.0 , dt , streaming_observer( cout ) );
84     //]
85 
86     return 0;
87 }
88