Brian Silverman | 7c33ab2 | 2018-08-04 17:14:51 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * van_der_pol_stiff.cpp |
| 3 | * |
| 4 | * Created on: Dec 12, 2011 |
| 5 | * |
| 6 | * Copyright 2012 Karsten Ahnert |
| 7 | * Copyright 2012-2013 Rajeev Singh |
| 8 | * Copyright 2012-2013 Mario Mulansky |
| 9 | * |
| 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) |
| 13 | */ |
| 14 | |
| 15 | #include <iostream> |
| 16 | #include <fstream> |
| 17 | #include <utility> |
| 18 | |
| 19 | #include <boost/numeric/odeint.hpp> |
| 20 | |
| 21 | #include <boost/phoenix/core.hpp> |
| 22 | #include <boost/phoenix/operator.hpp> |
| 23 | |
| 24 | using namespace std; |
| 25 | using namespace boost::numeric::odeint; |
| 26 | namespace phoenix = boost::phoenix; |
| 27 | |
| 28 | const double mu = 1000.0; |
| 29 | |
| 30 | |
| 31 | typedef boost::numeric::ublas::vector< double > vector_type; |
| 32 | typedef boost::numeric::ublas::matrix< double > matrix_type; |
| 33 | |
| 34 | struct vdp_stiff |
| 35 | { |
| 36 | void operator()( const vector_type &x , vector_type &dxdt , double t ) |
| 37 | { |
| 38 | dxdt[0] = x[1]; |
| 39 | dxdt[1] = -x[0] - mu * x[1] * (x[0]*x[0]-1.0); |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | struct vdp_stiff_jacobi |
| 44 | { |
| 45 | void operator()( const vector_type &x , matrix_type &J , const double &t , vector_type &dfdt ) |
| 46 | { |
| 47 | J(0, 0) = 0.0; |
| 48 | J(0, 1) = 1.0; |
| 49 | J(1, 0) = -1.0 - 2.0*mu * x[0] * x[1]; |
| 50 | J(1, 1) = -mu * ( x[0] * x[0] - 1.0); |
| 51 | |
| 52 | dfdt[0] = 0.0; |
| 53 | dfdt[1] = 0.0; |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | |
| 58 | int main( int argc , char **argv ) |
| 59 | { |
| 60 | //[ integrate_stiff_system |
| 61 | vector_type x( 2 ); |
| 62 | /* initialize random seed: */ |
| 63 | srand ( time(NULL) ); |
| 64 | |
| 65 | // initial conditions |
| 66 | for (int i=0; i<2; i++) |
| 67 | x[i] = 1.0; //(1.0 * rand()) / RAND_MAX; |
| 68 | |
| 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" |
| 73 | ); |
| 74 | //] |
| 75 | clog << num_of_steps << endl; |
| 76 | |
| 77 | |
| 78 | |
| 79 | //[ integrate_stiff_system_alternative |
| 80 | |
| 81 | vector_type x2( 2 ); |
| 82 | // initial conditions |
| 83 | for (int i=0; i<2; i++) |
| 84 | x2[i] = 1.0; //(1.0 * rand()) / RAND_MAX; |
| 85 | |
| 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" |
| 89 | // ); |
| 90 | //] |
| 91 | //clog << num_of_steps2 << endl; |
| 92 | |
| 93 | |
| 94 | return 0; |
| 95 | } |