BubbleProfiler  0.3.0
by Peter Athron, Csaba Balazs, Michael Bardsley, Andrew Fowlie, Dylan Harries & Graham White
integration_policy.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of BubbleProfiler.
3  *
4  * BubbleProfiler is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * BubbleProfiler is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with BubbleProfiler. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef BUBBLEPROFILER_INTEGRATION_POLICY_HPP_INCLUDED
19 #define BUBBLEPROFILER_INTEGRATION_POLICY_HPP_INCLUDED
20 
21 #include "eigen_state_utils.hpp"
22 
23 #include <boost/numeric/odeint.hpp>
24 
25 namespace BubbleProfiler {
26 
27 template <class Parameter,
28  class State,
29  class Stepper = boost::numeric::odeint::runge_kutta4<
30  State,
31  Parameter,
32  State,
33  Parameter,
36 protected:
37  ~Fixed_step_size_integrator() = default;
38 
39  template <class System, class Observer>
40  int integrate_system(System system, State& state,
41  Parameter from, Parameter to, Parameter step_size,
42  Observer observer) const;
43 };
44 
45 template <class Parameter, class State, class Stepper>
46 template <class System, class Observer>
48  System system, State& state, Parameter from, Parameter to,
49  Parameter step_size, Observer observer) const
50 {
51  Stepper stepper;
52  return boost::numeric::odeint::integrate_adaptive(
53  stepper, system, state, from, to, step_size, observer);
54 }
55 
56 template <class Parameter, class State, class Stepper>
58 public:
59  void set_absolute_error(Parameter err) { abs_err = err; }
60  void set_relative_error(Parameter err) { rel_err = err; }
61 
62 protected:
64 
65  template <class System, class Observer>
66  int integrate_system(System system, State& state,
67  Parameter from, Parameter to, Parameter step_size,
68  Observer observer) const;
69 
70 private:
71  Parameter abs_err{1.e-6};
72  Parameter rel_err{1.e-6};
73 };
74 
75 template <class Parameter, class State, class Stepper>
76 template <class System, class Observer>
78  System system, State& state, Parameter from, Parameter to,
79  Parameter step_size, Observer observer) const
80 {
81  auto stepper = boost::numeric::odeint::make_controlled(abs_err, rel_err,
82  Stepper());
83 
84  return boost::numeric::odeint::integrate_adaptive(
85  stepper, system, state, from, to, step_size, observer);
86 }
87 
88 } // namespace BubbleProfiler
89 
90 #endif
int integrate_system(System system, State &state, Parameter from, Parameter to, Parameter step_size, Observer observer) const
int integrate_system(System system, State &state, Parameter from, Parameter to, Parameter step_size, Observer observer) const