blob: dc295c4738fca60aca3f0d8e957113de671c405f [file] [log] [blame]
Brian Silverman7c33ab22018-08-04 17:14:51 -07001/*
2 [auto_generated]
3 libs/numeric/odeint/test/rosenbrock4.cpp
4
5 [begin_description]
6 This file tests the Rosenbrock 4 stepper and its controller and dense output stepper.
7 [end_description]
8
9 Copyright 2009-2012 Karsten Ahnert
10 Copyright 2009-2012 Mario Mulansky
11
12 Distributed under the Boost Software License, Version 1.0.
13 (See accompanying file LICENSE_1_0.txt or
14 copy at http://www.boost.org/LICENSE_1_0.txt)
15 */
16
17// disable checked iterator warning for msvc
18#include <boost/config.hpp>
19#ifdef BOOST_MSVC
20 #pragma warning(disable:4996)
21#endif
22
23#define BOOST_TEST_MODULE odeint_rosenbrock4
24
25#include <utility>
26#include <iostream>
27
28#include <boost/test/unit_test.hpp>
29#include <boost/multiprecision/cpp_dec_float.hpp>
30
31#include <boost/numeric/odeint/stepper/rosenbrock4.hpp>
32#include <boost/numeric/odeint/stepper/rosenbrock4_controller.hpp>
33#include <boost/numeric/odeint/stepper/rosenbrock4_dense_output.hpp>
34
35#include <boost/numeric/ublas/vector.hpp>
36#include <boost/numeric/ublas/matrix.hpp>
37
38using namespace boost::unit_test;
39using namespace boost::numeric::odeint;
40
41typedef boost::multiprecision::cpp_dec_float_50 value_type;
42typedef boost::numeric::ublas::vector< value_type > state_type;
43typedef boost::numeric::ublas::matrix< value_type > matrix_type;
44
45
46struct sys
47{
48 void operator()( const state_type &x , state_type &dxdt , const value_type &t ) const
49 {
50 dxdt( 0 ) = x( 0 ) + 2 * x( 1 );
51 dxdt( 1 ) = x( 1 );
52 }
53};
54
55struct jacobi
56{
57 void operator()( const state_type &x , matrix_type &jacobi , const value_type &t , state_type &dfdt ) const
58 {
59 jacobi( 0 , 0 ) = 1;
60 jacobi( 0 , 1 ) = 2;
61 jacobi( 1 , 0 ) = 0;
62 jacobi( 1 , 1 ) = 1;
63 dfdt( 0 ) = 0.0;
64 dfdt( 1 ) = 0.0;
65 }
66};
67
68BOOST_AUTO_TEST_SUITE( rosenbrock4_test )
69
70BOOST_AUTO_TEST_CASE( test_rosenbrock4_stepper )
71{
72 typedef rosenbrock4< value_type > stepper_type;
73 stepper_type stepper;
74
75 typedef stepper_type::state_type state_type;
76 typedef stepper_type::value_type stepper_value_type;
77 typedef stepper_type::deriv_type deriv_type;
78 typedef stepper_type::time_type time_type;
79
80 state_type x( 2 ) , xerr( 2 );
81 x(0) = 0.0; x(1) = 1.0;
82
83 stepper.do_step( std::make_pair( sys() , jacobi() ) , x ,
84 static_cast<value_type>(0.0) , static_cast<value_type>(0.1) , xerr );
85
86 stepper.do_step( std::make_pair( sys() , jacobi() ) , x ,
87 static_cast<value_type>(0.0) , static_cast<value_type>(0.1) );
88
89// using std::abs;
90// value_type eps = 1E-12;
91//
92// // compare with analytic solution of above system
93// BOOST_CHECK_SMALL( abs( x(0) - 20.0/81.0 ) , eps );
94// BOOST_CHECK_SMALL( abs( x(1) - 10.0/9.0 ) , eps );
95
96}
97
98BOOST_AUTO_TEST_CASE( test_rosenbrock4_controller )
99{
100 typedef rosenbrock4_controller< rosenbrock4< value_type > > stepper_type;
101 stepper_type stepper;
102
103 typedef stepper_type::state_type state_type;
104 typedef stepper_type::value_type stepper_value_type;
105 typedef stepper_type::deriv_type deriv_type;
106 typedef stepper_type::time_type time_type;
107
108 state_type x( 2 );
109 x( 0 ) = 0.0 ; x(1) = 1.0;
110
111 value_type t = 0.0 , dt = 0.01;
112 stepper.try_step( std::make_pair( sys() , jacobi() ) , x , t , dt );
113}
114
115BOOST_AUTO_TEST_CASE( test_rosenbrock4_dense_output )
116{
117 typedef rosenbrock4_dense_output< rosenbrock4_controller< rosenbrock4< value_type > > > stepper_type;
118 typedef rosenbrock4_controller< rosenbrock4< value_type > > controlled_stepper_type;
119 controlled_stepper_type c_stepper;
120 stepper_type stepper( c_stepper );
121
122 typedef stepper_type::state_type state_type;
123 typedef stepper_type::value_type stepper_value_type;
124 typedef stepper_type::deriv_type deriv_type;
125 typedef stepper_type::time_type time_type;
126 state_type x( 2 );
127 x( 0 ) = 0.0 ; x(1) = 1.0;
128 stepper.initialize( x , 0.0 , 0.1 );
129 std::pair< value_type , value_type > tr = stepper.do_step( std::make_pair( sys() , jacobi() ) );
130 stepper.calc_state( 0.5 * ( tr.first + tr.second ) , x );
131}
132
133BOOST_AUTO_TEST_CASE( test_rosenbrock4_copy_dense_output )
134{
135 typedef rosenbrock4_controller< rosenbrock4< value_type > > controlled_stepper_type;
136 typedef rosenbrock4_dense_output< controlled_stepper_type > stepper_type;
137
138 controlled_stepper_type c_stepper;
139 stepper_type stepper( c_stepper );
140 stepper_type stepper2( stepper );
141}
142
143BOOST_AUTO_TEST_SUITE_END()