odeint_rk4_array.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * odeint_rk4_array
  3. *
  4. * Copyright 2011 Mario Mulansky
  5. * Copyright 2012 Karsten Ahnert
  6. *
  7. * Distributed under the Boost Software License, Version 1.0.
  8. * (See accompanying file LICENSE_1_0.txt or
  9. * copy at http://www.boost.org/LICENSE_1_0.txt)
  10. */
  11. #include <iostream>
  12. #include <boost/timer.hpp>
  13. #include <boost/array.hpp>
  14. #include <boost/numeric/odeint/stepper/runge_kutta4_classic.hpp>
  15. #include <boost/numeric/odeint/stepper/runge_kutta4.hpp>
  16. #include <boost/numeric/odeint/algebra/array_algebra.hpp>
  17. #include "lorenz.hpp"
  18. typedef boost::timer timer_type;
  19. typedef boost::array< double , 3 > state_type;
  20. using namespace boost::numeric::odeint;
  21. //typedef boost::numeric::odeint::runge_kutta4_classic< state_type > rk4_odeint_type;
  22. // use the never resizer explicitely for optimal performance with gcc,
  23. // for the intel compiler this doesnt matter and the above definition
  24. // gives the same performance
  25. typedef runge_kutta4_classic< state_type , double , state_type , double ,
  26. array_algebra, default_operations, never_resizer > rk4_odeint_type;
  27. const int loops = 21;
  28. const int num_of_steps = 20000000;
  29. const double dt = 1E-10;
  30. int main()
  31. {
  32. double min_time = 1E6; // something big
  33. rk4_odeint_type stepper;
  34. std::clog.precision(16);
  35. std::cout.precision(16);
  36. for( int n=0; n<loops; n++ )
  37. {
  38. state_type x = {{ 8.5, 3.1, 1.2 }};
  39. double t = 0.0;
  40. timer_type timer;
  41. for( size_t i = 0 ; i < num_of_steps ; ++i )
  42. {
  43. stepper.do_step( lorenz(), x, t, dt );
  44. t += dt;
  45. }
  46. min_time = std::min( timer.elapsed() , min_time );
  47. std::clog << timer.elapsed() << '\t' << x[0] << std::endl;
  48. }
  49. std::cout << "Minimal Runtime: " << min_time << std::endl;
  50. }