regression_189.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. [begin_description]
  3. Test case for issue 189:
  4. Controlled Rosenbrock stepper fails to increase step size
  5. [end_description]
  6. Copyright 2016 Karsten Ahnert
  7. Copyright 2016 Mario Mulansky
  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. #define BOOST_TEST_MODULE odeint_regression_189
  13. #include <boost/numeric/odeint.hpp>
  14. #include <boost/test/unit_test.hpp>
  15. #include <boost/phoenix/core.hpp>
  16. #include <boost/phoenix/operator.hpp>
  17. using namespace boost::numeric::odeint;
  18. namespace phoenix = boost::phoenix;
  19. typedef boost::numeric::ublas::vector< double > vector_type;
  20. typedef boost::numeric::ublas::matrix< double > matrix_type;
  21. struct stiff_system
  22. {
  23. void operator()( const vector_type &x , vector_type &dxdt , double /* t */ )
  24. {
  25. dxdt[ 0 ] = -101.0 * x[ 0 ] - 100.0 * x[ 1 ];
  26. dxdt[ 1 ] = x[ 0 ];
  27. }
  28. };
  29. struct stiff_system_jacobi
  30. {
  31. void operator()( const vector_type & /* x */ , matrix_type &J , const double & /* t */ , vector_type &dfdt )
  32. {
  33. J( 0 , 0 ) = -101.0;
  34. J( 0 , 1 ) = -100.0;
  35. J( 1 , 0 ) = 1.0;
  36. J( 1 , 1 ) = 0.0;
  37. dfdt[0] = 0.0;
  38. dfdt[1] = 0.0;
  39. }
  40. };
  41. BOOST_AUTO_TEST_CASE( regression_189 )
  42. {
  43. vector_type x( 2 , 1.0 );
  44. size_t num_of_steps = integrate_const( make_dense_output< rosenbrock4< double > >( 1.0e-6 , 1.0e-6 ) ,
  45. std::make_pair( stiff_system() , stiff_system_jacobi() ) ,
  46. x , 0.0 , 50.0 , 0.01 ,
  47. std::cout << phoenix::arg_names::arg2 << " " << phoenix::arg_names::arg1[0] << "\n" );
  48. // regression: number of steps should be 74
  49. size_t num_of_steps_expected = 74;
  50. BOOST_CHECK_EQUAL( num_of_steps , num_of_steps_expected );
  51. vector_type x2( 2 , 1.0 );
  52. size_t num_of_steps2 = integrate_const( make_dense_output< runge_kutta_dopri5< vector_type > >( 1.0e-6 , 1.0e-6 ) ,
  53. stiff_system() , x2 , 0.0 , 50.0 , 0.01 ,
  54. std::cout << phoenix::arg_names::arg2 << " " << phoenix::arg_names::arg1[0] << "\n" );
  55. num_of_steps_expected = 1531;
  56. BOOST_CHECK_EQUAL( num_of_steps2 , num_of_steps_expected );
  57. }