generation_functions.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. libs/numeric/odeint/examples/stochastic_euler.hpp
  3. Copyright 2012 Karsten Ahnert
  4. Copyright 2012-2013 Mario Mulansky
  5. Copyright 2013 Pascal Germroth
  6. Stochastic euler stepper example and Ornstein-Uhlenbeck process
  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 <boost/array.hpp>
  12. #include <boost/numeric/odeint.hpp>
  13. typedef boost::array< double , 1 > state_type;
  14. using namespace boost::numeric::odeint;
  15. //[ generation_functions_own_steppers
  16. class custom_stepper
  17. {
  18. public:
  19. typedef double value_type;
  20. // ...
  21. };
  22. class custom_controller
  23. {
  24. // ...
  25. };
  26. class custom_dense_output
  27. {
  28. // ...
  29. };
  30. //]
  31. //[ generation_functions_get_controller
  32. namespace boost { namespace numeric { namespace odeint {
  33. template<>
  34. struct get_controller< custom_stepper >
  35. {
  36. typedef custom_controller type;
  37. };
  38. } } }
  39. //]
  40. //[ generation_functions_controller_factory
  41. namespace boost { namespace numeric { namespace odeint {
  42. template<>
  43. struct controller_factory< custom_stepper , custom_controller >
  44. {
  45. custom_controller operator()( double abs_tol , double rel_tol , const custom_stepper & ) const
  46. {
  47. return custom_controller();
  48. }
  49. custom_controller operator()( double abs_tol , double rel_tol , double max_dt ,
  50. const custom_stepper & ) const
  51. {
  52. // version with maximal allowed step size max_dt
  53. return custom_controller();
  54. }
  55. };
  56. } } }
  57. //]
  58. int main( int argc , char **argv )
  59. {
  60. {
  61. typedef runge_kutta_dopri5< state_type > stepper_type;
  62. /*
  63. //[ generation_functions_syntax_auto
  64. auto stepper1 = make_controlled( 1.0e-6 , 1.0e-6 , stepper_type() );
  65. // or with max step size limit:
  66. // auto stepper1 = make_controlled( 1.0e-6 , 1.0e-6 , 0.01, stepper_type() );
  67. auto stepper2 = make_dense_output( 1.0e-6 , 1.0e-6 , stepper_type() );
  68. //]
  69. */
  70. //[ generation_functions_syntax_result_of
  71. boost::numeric::odeint::result_of::make_controlled< stepper_type >::type stepper3 = make_controlled( 1.0e-6 , 1.0e-6 , stepper_type() );
  72. (void)stepper3;
  73. boost::numeric::odeint::result_of::make_dense_output< stepper_type >::type stepper4 = make_dense_output( 1.0e-6 , 1.0e-6 , stepper_type() );
  74. (void)stepper4;
  75. //]
  76. }
  77. {
  78. /*
  79. //[ generation_functions_example_custom_controller
  80. auto stepper5 = make_controlled( 1.0e-6 , 1.0e-6 , custom_stepper() );
  81. //]
  82. */
  83. boost::numeric::odeint::result_of::make_controlled< custom_stepper >::type stepper5 = make_controlled( 1.0e-6 , 1.0e-6 , custom_stepper() );
  84. (void)stepper5;
  85. }
  86. return 0;
  87. }