2 * van_der_pol_stiff.cpp
4 * Created on: Dec 12, 2011
6 * Copyright 2012 Karsten Ahnert
7 * Copyright 2012-2013 Rajeev Singh
8 * Copyright 2012-2013 Mario Mulansky
10 * Distributed under the Boost Software License, Version 1.0.
11 * (See accompanying file LICENSE_1_0.txt or
12 * copy at http://www.boost.org/LICENSE_1_0.txt)
19 #include <boost/numeric/odeint.hpp>
21 #include <boost/phoenix/core.hpp>
22 #include <boost/phoenix/operator.hpp>
25 using namespace boost::numeric::odeint;
26 namespace phoenix = boost::phoenix;
28 const double mu = 1000.0;
31 typedef boost::numeric::ublas::vector< double > vector_type;
32 typedef boost::numeric::ublas::matrix< double > matrix_type;
36 void operator()( const vector_type &x , vector_type &dxdt , double t )
39 dxdt[1] = -x[0] - mu * x[1] * (x[0]*x[0]-1.0);
43 struct vdp_stiff_jacobi
45 void operator()( const vector_type &x , matrix_type &J , const double &t , vector_type &dfdt )
49 J(1, 0) = -1.0 - 2.0*mu * x[0] * x[1];
50 J(1, 1) = -mu * ( x[0] * x[0] - 1.0);
58 int main( int argc , char **argv )
60 //[ integrate_stiff_system
62 /* initialize random seed: */
66 for (int i=0; i<2; i++)
67 x[i] = 1.0; //(1.0 * rand()) / RAND_MAX;
69 size_t num_of_steps = integrate_const( make_dense_output< rosenbrock4< double > >( 1.0e-6 , 1.0e-6 ) ,
70 make_pair( vdp_stiff() , vdp_stiff_jacobi() ) ,
71 x , 0.0 , 1000.0 , 1.0
72 , cout << phoenix::arg_names::arg2 << " " << phoenix::arg_names::arg1[0] << " " << phoenix::arg_names::arg1[1] << "\n"
75 clog << num_of_steps << endl;
79 //[ integrate_stiff_system_alternative
83 for (int i=0; i<2; i++)
84 x2[i] = 1.0; //(1.0 * rand()) / RAND_MAX;
86 //size_t num_of_steps2 = integrate_const( make_dense_output< runge_kutta_dopri5< vector_type > >( 1.0e-6 , 1.0e-6 ) ,
87 // vdp_stiff() , x2 , 0.0 , 1000.0 , 1.0
88 // , cout << phoenix::arg_names::arg2 << " " << phoenix::arg_names::arg1[0] << " " << phoenix::arg_names::arg1[1] << "\n"
91 //clog << num_of_steps2 << endl;