mbsim  4.0.0
MBSim Kernel
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
boost_odeint_integrator_predef.h
1 /* Copyright (C) 2017 Markus Friedrich
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  */
17 
18 #include "boost_odeint_integrator.h"
19 
20 // runge_kutta_dopri5<Vec>
21 #include <boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp>
22 #include <boost/numeric/odeint/stepper/dense_output_runge_kutta.hpp>
23 
24 // bulirsch_stoer<Vec>
25 #include <boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp>
26 
27 // euler<Vec>
28 #include <boost/numeric/odeint/stepper/euler.hpp>
29 
30 // rosenbrock4<double>
31 #include <boost/numeric/odeint/stepper/rosenbrock4_dense_output.hpp>
32 
33 namespace MBSim {
34 
35  namespace BoostOdeintHelper {
36 
37  // Definition of concepts of DOS. (see header file BoostOdeintDOS)
38 
39 
40 
41  // runge_kutta_dopri5<Vec>
42 
43  // type definitions
44  typedef boost::numeric::odeint::runge_kutta_dopri5<fmatvec::Vec> RKDOPRI5Stepper;
45  typedef boost::numeric::odeint::default_error_checker<double, boost::numeric::odeint::range_algebra,
46  boost::numeric::odeint::default_operations> RKDOPRI5Checker;
47  class RKDOPRI5Adjuster : public boost::numeric::odeint::default_step_adjuster<double, double> {
48  public:
49  RKDOPRI5Adjuster(double dtMax) : boost::numeric::odeint::default_step_adjuster<double, double>(dtMax) {}
50 #if BOOST_VERSION >= 107100
51  void setDtMax(double dtMax) { m_max_dt = dtMax; }
52 #endif
53  };
54 #if BOOST_VERSION >= 107100
55  typedef boost::numeric::odeint::controlled_runge_kutta<RKDOPRI5Stepper, RKDOPRI5Checker,
56  boost::reference_wrapper<RKDOPRI5Adjuster>> ControlledRK;
57 #else
58  typedef boost::numeric::odeint::controlled_runge_kutta<RKDOPRI5Stepper, RKDOPRI5Checker,
59  RKDOPRI5Adjuster> ControlledRK;
60 #endif
61  typedef boost::numeric::odeint::dense_output_runge_kutta<ControlledRK> DOSRK;
62 
63  // DOS concept for the boost odeint runge_kutta_dopri5<Vec> stepper
64  class RKDOPRI5 : public DOSRK {
65  public:
67  typedef typename ControlledRK::stepper_category UnderlayingStepperCategory;
68  RKDOPRI5(double aTol, double rTol, double dtMax) :
69 #if BOOST_VERSION >= 107100
70  DOSRK(ControlledRK(RKDOPRI5Checker(aTol, rTol), boost::ref(rkdopri5Adjuster), RKDOPRI5Stepper())), rkdopri5Adjuster(dtMax) {}
71 #else
72  DOSRK(ControlledRK(RKDOPRI5Checker(aTol, rTol), RKDOPRI5Adjuster(dtMax), RKDOPRI5Stepper())) {}
73 #endif
74 #if BOOST_VERSION >= 107100
75  void setDtMax(double dtMax) { rkdopri5Adjuster.setDtMax(dtMax); }
76  private:
77  RKDOPRI5Adjuster rkdopri5Adjuster;
78 #endif
79  };
80 
81 
82 
83  // bulirsch_stoer<Vec>
84 
85  // type definitions
86  typedef boost::numeric::odeint::bulirsch_stoer_dense_out<fmatvec::Vec> DOSBS;
87 
88  // DOS concept for the boost odeint bulirsch_stoer_dense_out<Vec> stepper.
89  class BulirschStoer : public DOSBS {
90  public:
92  typedef boost::numeric::odeint::controlled_stepper_tag UnderlayingStepperCategory;
93  BulirschStoer(double aTol, double rTol, double dtMax) : DOSBS(aTol, rTol, 1.0, 1.0, dtMax) {}
94 #if BOOST_VERSION >= 107100
95  void setDtMax(double dtMax) { m_max_dt = dtMax; }
96 #endif
97  };
98 
99 
100 
101  // euler<Vec>
102 
103  // type definitions
104  typedef boost::numeric::odeint::euler<fmatvec::Vec> EulerStepper;
105  typedef boost::numeric::odeint::dense_output_runge_kutta<EulerStepper> DOSEuler;
106 
107  // DOS concept for the boost odeint euler<Vec> stepper
108  class Euler : public DOSEuler {
109  public:
111  typedef typename EulerStepper::stepper_category UnderlayingStepperCategory;
112  Euler(double aTol, double rTol, double dtMax) : DOSEuler() {}
113 #if BOOST_VERSION >= 107100
114  void setDtMax(double) {}
115 #endif
116  };
117 
118 
119 
120  // rosenbrock4<double>
121 
122  // type definitions
123  typedef boost::numeric::odeint::rosenbrock4<double> RB4;
124  class ControlledRB4 : public boost::numeric::odeint::rosenbrock4_controller<RB4> {
125  public:
126  ControlledRB4(double aTol, double rTol, double dtMax) : boost::numeric::odeint::rosenbrock4_controller<RB4>(aTol, rTol, dtMax) {}
127 #if BOOST_VERSION >= 107100
128  void setDtMax(double dtMax) { m_max_dt = dtMax; }
129 #endif
130  };
131 #if BOOST_VERSION >= 107100
132  typedef boost::numeric::odeint::rosenbrock4_dense_output<boost::reference_wrapper<ControlledRB4>> DOSRB4;
133 #else
134  typedef boost::numeric::odeint::rosenbrock4_dense_output<ControlledRB4> DOSRB4;
135 #endif
136 
137  // DOS concept for the boost odeint rosenbrock4<double> stepper
138  class Rosenbrock4 : public DOSRB4 {
139  public:
141  typedef typename ControlledRB4::stepper_category UnderlayingStepperCategory;
142 #if BOOST_VERSION >= 107100
143  Rosenbrock4(double aTol, double rTol, double dtMax) : DOSRB4(boost::ref(controlledRB4)), controlledRB4(aTol, rTol, dtMax) {}
144 #else
145  Rosenbrock4(double aTol, double rTol, double dtMax) : DOSRB4(ControlledRB4(aTol, rTol, dtMax)) {}
146 #endif
147 #if BOOST_VERSION >= 107100
148  void setDtMax(double dtMax) { controlledRB4.setDtMax(dtMax); }
149  private:
150  ControlledRB4 controlledRB4;
151 #endif
152  };
153 
154  }
155 
156  // explicit integrators
160  // implicit integrators
162 
163 }
Definition: boost_odeint_integrator_predef.h:108
Definition: boost_odeint_integrator_predef.h:138
Definition: boost_odeint_integrator.h:69
Definition: boost_odeint_integrator_predef.h:64
Definition: boost_odeint_integrator_predef.h:124
Definition: boost_odeint_integrator.h:67
Definition: boost_odeint_integrator.h:103
Definition: boost_odeint_integrator_predef.h:89
Definition: boost_odeint_integrator_predef.h:47