3 libs/numeric/odeint/test/implicit_euler.cpp
6 This file tests the implicit Euler stepper.
9 Copyright 2010-2011 Mario Mulansky
10 Copyright 2010-2012 Karsten Ahnert
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)
18 // disable checked iterator warning for msvc
19 #include <boost/config.hpp>
21 #pragma warning(disable:4996)
24 #define BOOST_TEST_MODULE odeint_implicit_euler
26 #include <boost/test/unit_test.hpp>
31 #include <boost/numeric/odeint/stepper/implicit_euler.hpp>
32 //#include <boost/numeric/odeint/util/ublas_resize.hpp>
34 #include <boost/numeric/ublas/vector.hpp>
35 #include <boost/numeric/ublas/matrix.hpp>
37 using namespace boost::unit_test;
38 using namespace boost::numeric::odeint;
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;
44 /* use functors, because functions don't work with msvc 10, I guess this is a bug */
47 void operator()( const state_type &x , state_type &dxdt , const value_type t ) const
49 dxdt( 0 ) = x( 0 ) + 2 * x( 1 );
56 void operator()( const state_type &x , matrix_type &jacobi , const value_type t ) const
65 BOOST_AUTO_TEST_SUITE( implicit_euler_test )
67 BOOST_AUTO_TEST_CASE( test_euler )
69 implicit_euler< value_type > stepper;
71 x(0) = 0.0; x(1) = 1.0;
73 value_type eps = 1E-12;
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 );
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 );
86 BOOST_AUTO_TEST_SUITE_END()