flexiblesusy is hosted by Hepforge, IPPP Durham
FlexibleSUSY
basic_rk_integrator.hpp
Go to the documentation of this file.
1// ====================================================================
2// This file is part of FlexibleSUSY.
3//
4// FlexibleSUSY is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published
6// by the Free Software Foundation, either version 3 of the License,
7// or (at your option) any later version.
8//
9// FlexibleSUSY is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with FlexibleSUSY. If not, see
16// <http://www.gnu.org/licenses/>.
17// ====================================================================
18
24#ifndef BASIC_RK_INTEGRATOR_H
25#define BASIC_RK_INTEGRATOR_H
26
27#include <functional>
28
29#include "rk.hpp"
30
31namespace flexiblesusy {
32
33namespace runge_kutta {
34
42template <typename StateType, typename Derivs>
44public:
46 double step(StateType&, const StateType&, double&, double,
47 double, const StateType&, Derivs, int&) const;
48private:
50 void runge_kutta_step(const StateType&, const StateType&, double,
51 double, StateType&, StateType&, Derivs) const;
52};
53
67template <typename StateType, typename Derivs>
69 const StateType& y, const StateType& dydx, double x,
70 double h, StateType& yout, StateType& yerr, Derivs derivs) const
71{
72 rungeKuttaStep(y, dydx, x, h, yout, yerr, derivs);
73}
74
92template <typename StateType, typename Derivs>
94 StateType& y, const StateType& dydx, double& x, double htry,
95 double eps, const StateType& yscal, Derivs derivs,
96 int& max_step_dir) const
97{
98 return odeStepper(y, dydx, x, htry, eps, yscal, derivs, max_step_dir);
99}
100
109template <typename StateType,
110 typename Derivs
111 = std::function<StateType(double, const StateType&)>,
112 typename Stepper = Basic_rk_stepper<StateType,Derivs> >
114public:
116 void operator()(double start, double end, StateType& ystart,
117 Derivs derivs, double tolerance) const;
118
121 void set_max_steps(int s) { max_steps = s; }
122
125 int get_max_steps() const { return max_steps; }
126
127private:
128 int max_steps{400};
129 Stepper stepper{};
130};
131
144template <typename StateType, typename Derivs, typename Stepper>
146 double start, double end, StateType& ystart, Derivs derivs,
147 double tolerance) const
148{
149 const double guess = (start - end) * 0.1; // first step size
150 const double hmin = (start - end) * tolerance * 1.0e-5;
151 const auto rkqs = [this] (
152 StateType& y, const StateType& dydx, double& x, double htry,
153 double eps, const StateType& yscal, Derivs derivs,
154 int& max_step_dir) -> double {
155 return this->stepper.step(y, dydx, x, htry, eps,
156 yscal, derivs, max_step_dir);
157 };
158
159 integrateOdes(ystart, start, end, tolerance, guess, hmin,
160 derivs, rkqs, max_steps);
161}
162
163} // namespace runge_kutta
164
165} // namespace flexiblesusy
166
167#endif
Class for integrating a system of first order ODEs.
int get_max_steps() const
Returns the maximum number of allowed steps in the integration.
void operator()(double start, double end, StateType &ystart, Derivs derivs, double tolerance) const
Integrates the system over an interval.
void set_max_steps(int s)
Sets the maximum number of allowed steps in the integration.
Stepper stepper
Stepper to provide a Runge-Kutta step.
int max_steps
Maximum number of steps in integration.
Class to carry out a 5th order Runge-Kutta step.
void runge_kutta_step(const StateType &, const StateType &, double, double, StateType &, StateType &, Derivs) const
Carries out a single 5th order Runge-Kutta step.
double step(StateType &, const StateType &, double &, double, double, const StateType &, Derivs, int &) const
Carries out a variable step-size Runge-Kutta step.
void integrateOdes(ArrayType &ystart, double from, double to, double eps, double h1, double hmin, Derivs derivs, Stepper rkqs=runge_kutta::odeStepper< ArrayType, Derivs >, int max_steps=400)
Organises integration of 1st order system of ODEs.
Definition: rk.hpp:158
double odeStepper(ArrayType &y, const ArrayType &dydx, double &x, double htry, double eps, const ArrayType &yscal, Derivs derivs, int &max_step_dir)
organises the variable step-size for Runge-Kutta evolution
Definition: rk.hpp:107
void rungeKuttaStep(const ArrayType &y, const ArrayType &dydx, double x, double h, ArrayType &yout, ArrayType &yerr, Derivs derivs)
Definition: rk.hpp:52
double * end(GSL_vector &v)
iterator to end of GSL_vector
Definition: gsl_vector.cpp:254
Integration of ODEs by Runge-Kutta.