blob: 6baa5f22d59550671958f58a832527ae3eac3305 [file] [log] [blame]
Brian Silverman7c33ab22018-08-04 17:14:51 -07001/*
2 libs/numeric/odeint/examples/stochastic_euler.hpp
3
4 Copyright 2012 Karsten Ahnert
5 Copyright 2012-2013 Mario Mulansky
6 Copyright 2013 Pascal Germroth
7
8 Stochastic euler stepper example and Ornstein-Uhlenbeck process
9
10 Distributed under the Boost Software License, Version 1.0.
11(See accompanying file LICENSE_1_0.txt or
12 copy at http://www.boost.org/LICENSE_1_0.txt)
13 */
14
15#include <boost/array.hpp>
16
17#include <boost/numeric/odeint.hpp>
18
19typedef boost::array< double , 1 > state_type;
20
21using namespace boost::numeric::odeint;
22
23
24//[ generation_functions_own_steppers
25class custom_stepper
26{
27public:
28
29 typedef double value_type;
30 // ...
31};
32
33class custom_controller
34{
35 // ...
36};
37
38class custom_dense_output
39{
40 // ...
41};
42//]
43
44
45//[ generation_functions_get_controller
46namespace boost { namespace numeric { namespace odeint {
47
48template<>
49struct get_controller< custom_stepper >
50{
51 typedef custom_controller type;
52};
53
54} } }
55//]
56
57//[ generation_functions_controller_factory
58namespace boost { namespace numeric { namespace odeint {
59
60template<>
61struct controller_factory< custom_stepper , custom_controller >
62{
63 custom_controller operator()( double abs_tol , double rel_tol , const custom_stepper & ) const
64 {
65 return custom_controller();
66 }
67
68 custom_controller operator()( double abs_tol , double rel_tol , double max_dt ,
69 const custom_stepper & ) const
70 {
71 // version with maximal allowed step size max_dt
72 return custom_controller();
73 }
74};
75
76} } }
77//]
78
79int main( int argc , char **argv )
80{
81 {
82 typedef runge_kutta_dopri5< state_type > stepper_type;
83
84 /*
85 //[ generation_functions_syntax_auto
86 auto stepper1 = make_controlled( 1.0e-6 , 1.0e-6 , stepper_type() );
87 // or with max step size limit:
88 // auto stepper1 = make_controlled( 1.0e-6 , 1.0e-6 , 0.01, stepper_type() );
89
90 auto stepper2 = make_dense_output( 1.0e-6 , 1.0e-6 , stepper_type() );
91 //]
92 */
93
94 //[ generation_functions_syntax_result_of
95 boost::numeric::odeint::result_of::make_controlled< stepper_type >::type stepper3 = make_controlled( 1.0e-6 , 1.0e-6 , stepper_type() );
96 (void)stepper3;
97 boost::numeric::odeint::result_of::make_dense_output< stepper_type >::type stepper4 = make_dense_output( 1.0e-6 , 1.0e-6 , stepper_type() );
98 (void)stepper4;
99 //]
100 }
101
102 {
103 /*
104 //[ generation_functions_example_custom_controller
105 auto stepper5 = make_controlled( 1.0e-6 , 1.0e-6 , custom_stepper() );
106 //]
107 */
108
109 boost::numeric::odeint::result_of::make_controlled< custom_stepper >::type stepper5 = make_controlled( 1.0e-6 , 1.0e-6 , custom_stepper() );
110 (void)stepper5;
111 }
112 return 0;
113}