flexiblesusy is hosted by Hepforge, IPPP Durham
FlexibleSUSY
shooting_solver.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
19#ifndef SHOOTING_SOLVER_H
20#define SHOOTING_SOLVER_H
21
23#include "logger.hpp"
24#include "model.hpp"
27#include <cstddef>
28#include <vector>
29#include <Eigen/Core>
30
31namespace flexiblesusy {
32
37template<std::size_t N>
39public:
40 using Vec_t = Eigen::Matrix<double, N, 1>;
41 using Fun_t = std::function<Vec_t(const Vec_t&)>;
42 using Pre_t = std::function<Vec_t()>;
43 using Set_t = std::function<void(const Vec_t&)>;
44
50 void add(const Pre_t& p) { predictor = p; }
52 void add(const Set_t& s) { setter = s; }
54 Vec_t get_solution() const { return solution; }
56 void set_precision(double p) { precision = p; }
58 void set_max_iterations(std::size_t n) { max_it = n; }
60 void reset();
62 void solve(const Vec_t&);
63
64private:
65 struct Slider {
66 public:
67 virtual ~Slider() {}
68 virtual void clear_problems() {}
69 virtual double get_scale() = 0;
70 virtual void slide() {}
71 };
72
73 struct Constraint_slider : public Slider {
74 public:
77 virtual ~Constraint_slider() = default;
78 virtual void clear_problems() override { model->clear_problems(); }
79 virtual double get_scale() override { return constraint->get_scale(); }
80 virtual void slide() override {
81 const auto Q = get_scale();
82 VERBOSE_MSG("> \trunning " << model->name() << " to scale " << Q << " GeV");
83 model->run_to(Q);
84 VERBOSE_MSG("> \tapplying " << constraint->name());
86 }
87 private:
90 };
91
92 struct Matching_slider : public Slider {
93 public:
95 : m1(m1_), m2(m2_), matching(mc) {}
96 virtual ~Matching_slider() = default;
97 virtual void clear_problems() override {
100 }
101 virtual double get_scale() override { return matching->get_scale(); }
102 virtual void slide() override {
103 const auto Q = get_scale();
104 VERBOSE_MSG("> \trunning " << m1->name() << " to scale " << Q << " GeV");
105 m1->run_to(Q);
106 VERBOSE_MSG("> \trunning " << m2->name() << " to scale " << Q << " GeV");
107 m2->run_to(Q);
108 VERBOSE_MSG("> \tmatching " << m1->name() << " -> " << m2->name());
109 matching->match();
110 }
111 private:
114 };
115
116 std::vector<std::shared_ptr<Slider> > sliders{};
117 Vec_t solution{Vec_t::Zero()};
118 double precision{1e-3};
119 std::size_t max_it{100};
120 Pre_t predictor{nullptr};
121 Set_t setter{nullptr};
122};
123
130template<std::size_t N>
132{
133 if (!c) throw SetupError("constraint pointer is NULL");
134 if (!m) throw SetupError("model pointer is NULL");
135 sliders.push_back(std::make_shared<Constraint_slider>(m, c));
136}
137
147template<std::size_t N>
149{
150 if (!mc) throw SetupError("matching condition pointer is NULL");
151 if (!m1) throw SetupError("model pointer 1 is NULL");
152 if (!m2) throw SetupError("model pointer 2 is NULL");
153 mc->set_models(m1, m2);
154 sliders.push_back(std::make_shared<Matching_slider>(m1, m2, mc));
155}
156
160template<std::size_t N>
162{
163 sliders.clear();
164 solution = Vec_t::Zero();
165 precision = 1e-3;
166 max_it = 100;
167 predictor = nullptr;
168 setter = nullptr;
169}
170
181template<std::size_t N>
183{
184 if (!predictor)
185 throw SetupError("No predictor set!");
186 if (!setter)
187 throw SetupError("No setter set!");
188
189 Fun_t fun = [&] (const Vec_t& v) {
190 setter(v);
191 for (auto& s: sliders) {
192 s->slide();
193 }
194 return predictor();
195 };
196
198 crs.set_precision(precision);
199 crs.set_max_iterations(max_it);
200 crs.solve(fun, v0);
201
202 solution = crs.get_solution();
203}
204
205} // namespace flexiblesusy
206
207#endif
Encapsulates several root finders.
Vec_t get_solution() const
returns solution
void set_max_iterations(std::size_t n)
set maximum number of iterations
void set_precision(double p)
set precision goal
void solve(const Fun_t &, const Vec_t &)
solves the boundary value problem with initial guess
virtual void clear_problems()=0
virtual std::string name() const =0
virtual void run_to(double, double eps=-1.0)=0
Spectrum generator was not setup correctly.
Definition error.hpp:46
Solves the IVP using the shooting method.
Pre_t predictor
calculates prediction
void add(const Set_t &s)
add parameter setter
std::function< Vec_t(const Vec_t &)> Fun_t
void add(Single_scale_constraint *, Model *)
add constraint
std::function< Vec_t()> Pre_t
std::function< void(const Vec_t &)> Set_t
std::size_t max_it
maximum number of iterations
std::vector< std::shared_ptr< Slider > > sliders
sliders to be run
Eigen::Matrix< double, N, 1 > Vec_t
void set_max_iterations(std::size_t n)
set maximum number of iterations
double precision
running precision
Vec_t get_solution() const
returns solution
void reset()
clear all internal data
void add(const Pre_t &p)
add predictor
void solve(const Vec_t &)
solves the boundary value problem with initial guess
void set_precision(double p)
set precision goal
virtual double get_scale() const =0
get scale where to apply
virtual void apply()=0
apply constraint
virtual std::string name() const
name of constraint
virtual double get_scale() const =0
#define VERBOSE_MSG(msg)
Definition logger.hpp:57
const double mc
Definition consts.hpp:104
Constraint_slider(Model *m, Single_scale_constraint *c)
Matching_slider(Model *m1_, Model *m2_, Single_scale_matching *mc)