1 /*
2 [auto_generated]
3 libs/numeric/odeint/test/implicit_euler.cpp
4
5 [begin_description]
6 This file tests the implicit Euler stepper.
7 [end_description]
8
9 Copyright 2010-2011 Mario Mulansky
10 Copyright 2010-2012 Karsten Ahnert
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
18 // disable checked iterator warning for msvc
19 #include <boost/config.hpp>
20 #ifdef BOOST_MSVC
21 #pragma warning(disable:4996)
22 #endif
23
24 #define BOOST_TEST_MODULE odeint_implicit_euler
25
26 #include <boost/test/unit_test.hpp>
27
28 #include <utility>
29 #include <iostream>
30
31 #include <boost/numeric/odeint/stepper/implicit_euler.hpp>
32 //#include <boost/numeric/odeint/util/ublas_resize.hpp>
33
34 #include <boost/numeric/ublas/vector.hpp>
35 #include <boost/numeric/ublas/matrix.hpp>
36
37 using namespace boost::unit_test;
38 using namespace boost::numeric::odeint;
39
40 typedef double value_type;
41 typedef boost::numeric::ublas::vector< value_type > state_type;
42 typedef boost::numeric::ublas::matrix< value_type > matrix_type;
43
44 /* use functors, because functions don't work with msvc 10, I guess this is a bug */
45 struct sys
46 {
operator ()sys47 void operator()( const state_type &x , state_type &dxdt , const value_type t ) const
48 {
49 dxdt( 0 ) = x( 0 ) + 2 * x( 1 );
50 dxdt( 1 ) = x( 1 );
51 }
52 };
53
54 struct jacobi
55 {
operator ()jacobi56 void operator()( const state_type &x , matrix_type &jacobi , const value_type t ) const
57 {
58 jacobi( 0 , 0 ) = 1;
59 jacobi( 0 , 1 ) = 2;
60 jacobi( 1 , 0 ) = 0;
61 jacobi( 1 , 1 ) = 1;
62 }
63 };
64
65 BOOST_AUTO_TEST_SUITE( implicit_euler_test )
66
BOOST_AUTO_TEST_CASE(test_euler)67 BOOST_AUTO_TEST_CASE( test_euler )
68 {
69 implicit_euler< value_type > stepper;
70 state_type x( 2 );
71 x(0) = 0.0; x(1) = 1.0;
72
73 value_type eps = 1E-12;
74
75 /* make_pair doesn't work with function pointers on msvc 10 */
76 stepper.do_step( std::make_pair( sys() , jacobi() ) , x , 0.0 , 0.1 );
77
78 using std::abs;
79
80 // compare with analytic solution of above system
81 BOOST_CHECK_MESSAGE( abs( x(0) - 20.0/81.0 ) < eps , x(0) - 20.0/81.0 );
82 BOOST_CHECK_MESSAGE( abs( x(1) - 10.0/9.0 ) < eps , x(0) - 10.0/9.0 );
83
84 }
85
86 BOOST_AUTO_TEST_SUITE_END()
87