elliptic_functions.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * elliptic_functions.cpp
  3. *
  4. * Copyright 2011-2013 Mario Mulansky
  5. * Copyright 2011-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 <fstream>
  13. #include <cmath>
  14. #include <boost/array.hpp>
  15. #include <boost/numeric/odeint/config.hpp>
  16. #include <boost/numeric/odeint.hpp>
  17. #include <boost/numeric/odeint/stepper/bulirsch_stoer.hpp>
  18. #include <boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp>
  19. using namespace std;
  20. using namespace boost::numeric::odeint;
  21. typedef boost::array< double , 3 > state_type;
  22. /*
  23. * x1' = x2*x3
  24. * x2' = -x1*x3
  25. * x3' = -m*x1*x2
  26. */
  27. void rhs( const state_type &x , state_type &dxdt , const double t )
  28. {
  29. static const double m = 0.51;
  30. dxdt[0] = x[1]*x[2];
  31. dxdt[1] = -x[0]*x[2];
  32. dxdt[2] = -m*x[0]*x[1];
  33. }
  34. ofstream out;
  35. void write_out( const state_type &x , const double t )
  36. {
  37. out << t << '\t' << x[0] << '\t' << x[1] << '\t' << x[2] << endl;
  38. }
  39. int main()
  40. {
  41. bulirsch_stoer_dense_out< state_type > stepper( 1E-9 , 1E-9 , 1.0 , 0.0 );
  42. state_type x1 = {{ 0.0 , 1.0 , 1.0 }};
  43. double t = 0.0;
  44. double dt = 0.01;
  45. out.open( "elliptic1.dat" );
  46. out.precision(16);
  47. integrate_const( stepper , rhs , x1 , t , 100.0 , dt , write_out );
  48. out.close();
  49. state_type x2 = {{ 0.0 , 1.0 , 1.0 }};
  50. out.open( "elliptic2.dat" );
  51. out.precision(16);
  52. integrate_adaptive( stepper , rhs , x2 , t , 100.0 , dt , write_out );
  53. out.close();
  54. typedef runge_kutta_dopri5< state_type > dopri5_type;
  55. typedef controlled_runge_kutta< dopri5_type > controlled_dopri5_type;
  56. typedef dense_output_runge_kutta< controlled_dopri5_type > dense_output_dopri5_type;
  57. dense_output_dopri5_type dopri5 = make_dense_output( 1E-9 , 1E-9 , dopri5_type() );
  58. //dense_output_dopri5_type dopri5( controlled_dopri5_type( default_error_checker< double >( 1E-9 , 0.0 , 0.0 , 0.0 ) ) );
  59. state_type x3 = {{ 0.0 , 1.0 , 1.0 }};
  60. out.open( "elliptic3.dat" );
  61. out.precision(16);
  62. integrate_adaptive( dopri5 , rhs , x3 , t , 100.0 , dt , write_out );
  63. out.close();
  64. }