Medusa  1.1
Coordinate Free Mehless Method implementation
RKExplicit.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_INTEGRATORS_RKEXPLICIT_HPP_
2 #define MEDUSA_BITS_INTEGRATORS_RKEXPLICIT_HPP_
3 
9 #include "RKExplicit_fwd.hpp"
10 
11 namespace mm {
12 namespace integrators {
13 namespace Explicit {
14 
15 template <class scalar_t>
17  Eigen::Matrix<scalar_t, 4, 1> alpha;
18  alpha << 0, 0.5, 0.5, 1.0;
19  Eigen::Matrix<scalar_t, 4, 4> beta;
20  beta << 0.0, 0.0, 0.0, 0.0,
21  0.5, 0.0, 0.0, 0.0,
22  0.0, 0.5, 0.0, 0.0,
23  0.0, 0.0, 1.0, 0.0;
24  Eigen::Matrix<scalar_t, 4, 1> gamma;
25  gamma << 1. / 6., 2. / 6., 2. / 6., 1. / 6.;
26  return {alpha, beta, gamma};
27 }
28 
29 template <class scalar_t>
31  Eigen::Matrix<scalar_t, 4, 1> alpha;
32  alpha << 0, 1. / 3., 2. / 3., 1.0;
33  Eigen::Matrix<scalar_t, 4, 4> beta;
34  beta << 0.0, 0.0, 0.0, 0.0,
35  1. / 3., 0.0, 0.0, 0.0,
36  -1. / 3., 1.0, 0.0, 0.0,
37  1.0, -1.0, 1.0, 0.0;
38  Eigen::Matrix<scalar_t, 4, 1> gamma;
39  gamma << 1. / 8., 3. / 8., 3. / 8., 1. / 8.;
40  return {alpha, beta, gamma};
41 }
42 
43 template <class scalar_t>
45  Eigen::Matrix<scalar_t, 1, 1> alpha;
46  alpha << 0.0;
47  Eigen::Matrix<scalar_t, 1, 1> beta;
48  beta << 0.0;
49  Eigen::Matrix<scalar_t, 1, 1> gamma;
50  gamma << 1.0;
51  return {alpha, beta, gamma};
52 }
53 
54 template <class scalar_t>
56  Eigen::Matrix<scalar_t, 2, 1> alpha;
57  alpha << 0.0, 0.5;
58  Eigen::Matrix<scalar_t, 2, 2> beta;
59  beta << 0.0, 0.0, 0.5, 0.0;
60  Eigen::Matrix<scalar_t, 2, 1> gamma;
61  gamma << 0.0, 1.0;
62  return {alpha, beta, gamma};
63 }
64 
65 template <class scalar_t>
67  Eigen::Matrix<scalar_t, 3, 1> alpha;
68  alpha << 0, 0.5, 1.0;
69  Eigen::Matrix<scalar_t, 3, 3> beta;
70  beta << 0.0, 0.0, 0.0,
71  0.5, 0.0, 0.0,
72  -1.0, 2.0, 0.0;
73  Eigen::Matrix<scalar_t, 3, 1> gamma;
74  gamma << 1. / 6., 2. / 3., 1. / 6.;
75  return {alpha, beta, gamma};
76 }
77 
78 template <class scalar_t>
80  Eigen::Matrix<scalar_t, 6, 1> alpha;
81  alpha << 0, 1. / 4., 3. / 8., 12. / 13., 1., 1. / 2.;
82  Eigen::Matrix<scalar_t, 6, 6> beta;
83  beta << 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
84  1. / 4., 0.0, 0.0, 0.0, 0.0, 0.0,
85  3. / 32., 9. / 32., 0.0, 0.0, 0.0, 0.0,
86  1932. / 2197, -7200. / 2197., 7296. / 2197., 0.0, 0.0, 0.0,
87  439. / 216., -8., 3680. / 513., -845. / 4104., 0.0, 0.0,
88  -8. / 27., 2., -3544. / 2565., 1859. / 4104., -11. / 40., 0.0;
89  Eigen::Matrix<scalar_t, 6, 1> gamma;
90  gamma << 16. / 135., 0.0, 6656. / 12825., 28561. / 56430., -9. / 50., 2. / 55.;
91  return {alpha, beta, gamma};
92 }
93 
95 namespace of_order_internal {
96 
97 template <int order, class scalar_t>
99  static_assert(order > 0, "Order must be positive.");
100  static_assert(order < 5, "Methods of higher orders do not correspond with the number of "
101  "stages, you must call them manually. If you got this error "
102  "calling AB5() method, supply e.g. Fehlberg5 as the first "
103  "parameter and its type as the template parameter.");
104  throw; // to avoid warnings
105 }
106 
108 template <class scalar_t>
109 struct _of_order_impl<1, scalar_t> {
110  static RKExplicit<scalar_t, 1> of_order() { return Euler(); }
111 };
112 
114 template <class scalar_t>
115 struct _of_order_impl<2, scalar_t> {
116  static RKExplicit<scalar_t, 2> of_order() { return Midpoint(); }
117 };
118 
120 template <class scalar_t>
121 struct _of_order_impl<3, scalar_t> {
122  static RKExplicit<scalar_t, 3> of_order() { return RK3(); }
123 };
124 
126 template <class scalar_t>
127 struct _of_order_impl<4, scalar_t> {
128  static RKExplicit<scalar_t, 4> of_order() { return RK4(); }
129 };
130 
131 } // namespace of_order_internal
133 
134 } // namespace Explicit
135 } // namespace integrators
136 } // namespace mm
137 
138 #endif // MEDUSA_BITS_INTEGRATORS_RKEXPLICIT_HPP_
RKExplicit_fwd.hpp
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
mm::integrators::Explicit::Midpoint
RKExplicit< scalar_t, 2 > Midpoint()
Explicit midpoint rule, 2nd order.
Definition: RKExplicit.hpp:55
scalar_t
Scalar scalar_t
Type of the elements, alias of Scalar.
Definition: MatrixBaseAddons.hpp:16
mm::RKExplicit
Class representing an explicit Runge-Kutta method.
Definition: RKExplicit_fwd.hpp:32
mm::integrators::Explicit::RK3
RKExplicit< scalar_t, 3 > RK3()
Kutta's third order method.
Definition: RKExplicit.hpp:66
mm::integrators::Explicit::of_order
static RKExplicit< scalar_t, order > of_order()
Returns Runge Kutta explicit method of requested order with given floating point type.
Definition: RKExplicit_fwd.hpp:293
mm::integrators::ExplicitMultistep::of_order
static AdamsBashforth< scalar_t, order > of_order()
Returns Adams-Bashforth explicit method of requested order with given floating point type.
Definition: AdamsBashforth_fwd.hpp:296
mm::integrators::Explicit::RK38
RKExplicit< scalar_t, 4 > RK38()
3/8 rule 4th order method
Definition: RKExplicit.hpp:30
mm::integrators::Explicit::RK4
RKExplicit< scalar_t, 4 > RK4()
Standard RK4 4th order method.
Definition: RKExplicit.hpp:16
mm::integrators::Explicit::Fehlberg5
RKExplicit< scalar_t, 6 > Fehlberg5()
Fifth order method appearing in Fehlberg's method.
Definition: RKExplicit.hpp:79
mm::integrators::Explicit::Euler
RKExplicit< scalar_t, 1 > Euler()
Explicit Euler's method, 1st order.
Definition: RKExplicit.hpp:44