blob: ca71f660016ab3a1405e46967c47014be4b7f7cd [file] [log] [blame]
Brian Silverman7c33ab22018-08-04 17:14:51 -07001/*
2 * rosenbrock4.cpp
3 *
4 * Copyright 2010-2012 Mario Mulansky
5 * Copyright 2011-2012 Karsten Ahnert
6 * Copyright 2012 Andreas Angelopoulos
7 *
8 * Distributed under the Boost Software License, Version 1.0.
9 * (See accompanying file LICENSE_1_0.txt or
10 * copy at http://www.boost.org/LICENSE_1_0.txt)
11 */
12
13#include <iostream>
14#include <fstream>
15#include <utility>
16
17#include <boost/numeric/odeint.hpp>
18
19#include <boost/phoenix/core.hpp>
20
21#include <boost/phoenix/core.hpp>
22#include <boost/phoenix/operator.hpp>
23
24using namespace std;
25using namespace boost::numeric::odeint;
26namespace phoenix = boost::phoenix;
27
28
29
30//[ stiff_system_definition
31typedef boost::numeric::ublas::vector< double > vector_type;
32typedef boost::numeric::ublas::matrix< double > matrix_type;
33
34struct stiff_system
35{
36 void operator()( const vector_type &x , vector_type &dxdt , double /* t */ )
37 {
38 dxdt[ 0 ] = -101.0 * x[ 0 ] - 100.0 * x[ 1 ];
39 dxdt[ 1 ] = x[ 0 ];
40 }
41};
42
43struct stiff_system_jacobi
44{
45 void operator()( const vector_type & /* x */ , matrix_type &J , const double & /* t */ , vector_type &dfdt )
46 {
47 J( 0 , 0 ) = -101.0;
48 J( 0 , 1 ) = -100.0;
49 J( 1 , 0 ) = 1.0;
50 J( 1 , 1 ) = 0.0;
51 dfdt[0] = 0.0;
52 dfdt[1] = 0.0;
53 }
54};
55//]
56
57
58
59/*
60//[ stiff_system_alternative_definition
61typedef boost::numeric::ublas::vector< double > vector_type;
62typedef boost::numeric::ublas::matrix< double > matrix_type;
63
64struct stiff_system
65{
66 template< class State >
67 void operator()( const State &x , State &dxdt , double t )
68 {
69 ...
70 }
71};
72
73struct stiff_system_jacobi
74{
75 template< class State , class Matrix >
76 void operator()( const State &x , Matrix &J , const double &t , State &dfdt )
77 {
78 ...
79 }
80};
81//]
82 */
83
84
85
86int main( int argc , char **argv )
87{
88// typedef rosenbrock4< double > stepper_type;
89// typedef rosenbrock4_controller< stepper_type > controlled_stepper_type;
90// typedef rosenbrock4_dense_output< controlled_stepper_type > dense_output_type;
91 //[ integrate_stiff_system
92 vector_type x( 2 , 1.0 );
93
94 size_t num_of_steps = integrate_const( make_dense_output< rosenbrock4< double > >( 1.0e-6 , 1.0e-6 ) ,
95 make_pair( stiff_system() , stiff_system_jacobi() ) ,
96 x , 0.0 , 50.0 , 0.01 ,
97 cout << phoenix::arg_names::arg2 << " " << phoenix::arg_names::arg1[0] << "\n" );
98 //]
99 clog << num_of_steps << endl;
100
101
102
103// typedef runge_kutta_dopri5< vector_type > dopri5_type;
104// typedef controlled_runge_kutta< dopri5_type > controlled_dopri5_type;
105// typedef dense_output_runge_kutta< controlled_dopri5_type > dense_output_dopri5_type;
106 //[ integrate_stiff_system_alternative
107
108 vector_type x2( 2 , 1.0 );
109
110 size_t num_of_steps2 = integrate_const( make_dense_output< runge_kutta_dopri5< vector_type > >( 1.0e-6 , 1.0e-6 ) ,
111 stiff_system() , x2 , 0.0 , 50.0 , 0.01 ,
112 cout << phoenix::arg_names::arg2 << " " << phoenix::arg_names::arg1[0] << "\n" );
113 //]
114 clog << num_of_steps2 << endl;
115
116
117 return 0;
118}