flexiblesusy is hosted by Hepforge, IPPP Durham
FlexibleSUSY
composite_root_finder.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 COMPOSITE_ROOT_FINDER_H
20#define COMPOSITE_ROOT_FINDER_H
21
22#include "root_finder.hpp"
23#include <cstddef>
24#include <vector>
25#include <Eigen/Core>
26
27namespace flexiblesusy {
28
33template<std::size_t N>
35public:
36 using Vec_t = Eigen::Matrix<double, N, 1>;
37 using Fun_t = std::function<Vec_t(const Vec_t&)>;
38
40 Vec_t get_solution() const { return point; }
42 void set_precision(double p) { precision = p; }
44 void set_max_iterations(std::size_t n) { max_it = n; }
46 void reset();
48 void solve(const Fun_t&, const Vec_t&);
49
50private:
51 Vec_t point{Vec_t::Zero()};
52 double precision{1e-3};
53 std::size_t max_it{100};
54};
55
56template<std::size_t N>
61
62template<std::size_t N>
63void Composite_root_finder<N>::solve(const Fun_t& fun, const Vec_t& v0)
64{
65 std::vector<Root_finder<N>> rfs = {
66 Root_finder<N>(fun, max_it, precision, Root_finder<N>::GSLHybridS),
67 Root_finder<N>(fun, max_it, precision, Root_finder<N>::GSLHybrid),
68 Root_finder<N>(fun, max_it, precision, Root_finder<N>::GSLBroyden)
69 };
70
71 auto err = !GSL_SUCCESS;
72
73 for (auto& rf: rfs) {
74 err = rf.solve(v0);
75
76 if (err == GSL_SUCCESS) {
77 point = rf.get_solution();
78 break;
79 }
80 }
81
82 if (err != GSL_SUCCESS)
83 throw NoConvergenceError(max_it);
84}
85
86} // namespace flexiblesusy
87
88#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
std::function< Vec_t(const Vec_t &)> Fun_t
void set_precision(double p)
set precision goal
void solve(const Fun_t &, const Vec_t &)
solves the boundary value problem with initial guess
No convergence while solving the RGEs.
Definition error.hpp:57
Function root finder.
virtual int solve(const Eigen::VectorXd &) override