flexiblesusy is hosted by Hepforge, IPPP Durham
FlexibleSUSY
lattice_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 lattice_solver_hpp
20#define lattice_solver_hpp
21
22
23#include <functional>
24#include <iostream>
25#include <algorithm>
26#include <vector>
27#include <unordered_set>
28#include <cstddef>
29#include <cstdlib>
30#include <cassert>
31#include <boost/thread/thread.hpp>
32#include <boost/thread/barrier.hpp>
33#include "mathdefs.hpp"
34
35#include "rg_flow.hpp"
36#include "error.hpp"
37#include "lattice_model.hpp"
38
39namespace flexiblesusy {
40
41#if 1
42template <class T> class Constraint;
43template <class T> class Matching;
44template <class T> class Convergence_tester;
45template <class T> class Initial_guesser;
46#endif
47
48class Lattice;
49class Lattice_constraint;
50// class SingleSiteConstraint;
51// class InterTheoryConstraint;
52using SingleSiteConstraint = Constraint<Lattice>;
53using InterTheoryConstraint = Matching<Lattice>;
54
55class Two_scale_running_precision;
56
57
58using RVec = std::vector<Real>;
59
60
61template<class T>
63public:
64 band_matrix(size_t N, size_t KL, size_t KU, size_t LD) :
65 n(N), kl(KL), ku(KU), ld(LD) {
66 assert(ld >= kl+ku+1);
67 AB = new T[ld*n];
68 }
69 ~band_matrix() { delete[] AB; }
70 T *pointer() { return AB; }
71 void clear() { for (size_t i = 0; i < ld*n; i++) AB[i] = 0; }
72 T& operator()(size_t i, size_t j) {
73 assert(i < n && j < n && i+ku >= j && i <= j+kl);
74 size_t idx = kl+ku+i-j + ld*j;
75 assert(idx < ld*n);
76 return AB[idx];
77 }
78
79private:
80 size_t n, kl, ku, ld;
81 T *AB;
82};
83
84
85template<>
86class RGFlow<Lattice> {
87public:
88 enum Inner_status { JUMPED=-2, ENDLESS=-1, CONVERGED=0 };
89
90 class MemoryError : public Error {
91 public:
92 MemoryError(const std::string& message_) : Error(message_) {}
93 virtual ~MemoryError() = default;
94 };
95
96 class SetupError : public Error {
97 public:
98 SetupError(const std::string& message_) : Error(message_) {}
99 virtual ~SetupError() = default;
100 };
101
102 class NonInvertibleMatrixError : public Error {
103 public:
104 NonInvertibleMatrixError(const std::string& message_) :
105 Error(message_) {}
106 virtual ~NonInvertibleMatrixError() = default;
107 };
108
109 class DivergenceError : public Error {
110 public:
111 DivergenceError(const std::string& message_) : Error(message_) {}
112 virtual ~DivergenceError() = default;
113 };
114
115 class NoConvergenceError : public Error {
116 public:
117 NoConvergenceError(size_t number_of_iterations_)
118 : Error("RGFlow<Lattice>: no convergence")
119 , number_of_iterations(number_of_iterations_) {}
120 virtual ~NoConvergenceError() = default;
121 std::string what_detailed() const override {
122 std::stringstream message;
123 message << "RGFlow<Lattice>::NoConvergenceError: no convergence"
124 << " after " << number_of_iterations << " iterations";
125 return message.str();
126 }
127 private:
129 };
130
132 public:
134 : Error("non-perturbative RG running")
135 , model(model_)
136 , scale(scale_)
137 {}
138 virtual ~NonPerturbativeRunningError() = default;
139 std::string what_detailed() const override;
140 private:
142 double scale;
143 };
144
145 struct EFT {
146 EFT(Lattice_model *model, RGFlow *flow) :
147 w(model), units(w->width, 1), f(flow)
148 {}
150 RVec units; // x normalizations
151 // std::vector<ptrdiff_t> r_offset;
153 size_t height;
154 size_t T;
155 size_t offset; // location within y_
156 };
157
158 union EqRow {
159 EqRow *next; // next free element
160 struct {
161 size_t T, m; // first site
162 size_t n; // number of occupied sites
163 size_t realRow; // row within A_
164 } rowSpec;
165 };
166
167 // RGFlow(std::vector<EFT *> efts, std::vector<Constraint *> constraints,
168 // Real scale0, int verbose, std::ostream *lout);
169 RGFlow();
170 ~RGFlow();
171
175 const std::vector<SingleSiteConstraint*>& constraints);
179 InterTheoryConstraint *m = nullptr,
180 const std::vector<SingleSiteConstraint*>& constraints = std::vector<SingleSiteConstraint*>());
185 const std::vector<SingleSiteConstraint*>& upward_constraints,
186 const std::vector<SingleSiteConstraint*>& downward_constraints);
192 const std::vector<SingleSiteConstraint*>& upward_constraints,
193 const std::vector<SingleSiteConstraint*>& downward_constraints);
195 void reset();
197 void set_convergence_tester(Convergence_tester<Lattice>*);
200 void set_running_precision(Two_scale_running_precision*);
201 void set_initial_guesser(Initial_guesser<Lattice>*);
202
203 void enable_hybrid() { hybrid = true; }
204 void disable_multithreading() { multithreading = false; };
205 void solve();
206 friend std::ostream& operator<<(std::ostream &out, const RGFlow& flow);
207
208 struct EFTspec : public EFT {
209 EFTspec(Lattice_model *model,
210 const std::vector<SingleSiteConstraint*>& cs,
212 RGFlow *flow);
213
214 // Lattice_model *model;
215 std::vector<SingleSiteConstraint*> constraints;
217 };
218 std::vector<EFTspec> efts;
222 Real a; // continuation parameter btw 0 & 1
224 size_t max_iter;
226 bool hybrid;
227 Real scl0; // t == log(mu/scl0)
228 RVec y_; // entire RG flow
230 RVec z; // RHS of linear equations
231 std::vector<EqRow> row_pool;
233 int N, KL, KU, LDA; // for lapack
234 std::vector<int> IPIV; // ditto
235 int verb;
236 // std::ostream *log;
237 size_t site_offset(size_t T, size_t m) const {
238 assert(m < efts[T].height);
239 return efts[T].offset + m*efts[T].w->width;
240 }
241 Real& A(size_t r, size_t T, size_t m, size_t i)
242 { return (*A_)(r, site_offset(T,m) + i); }
243 Real& y(size_t T, size_t m, size_t i) { return y_[site_offset(T,m) + i]; }
244 Real y(size_t T, size_t m, size_t i) const
245 { return y_[site_offset(T,m) + i]; }
246 Real u(size_t T, size_t i) const { return efts[T].units[i]; }
247 Real x(size_t T, size_t m, size_t i) const { return y(T,m,i) * u(T,i); }
248 std::vector<Lattice_constraint*> constraints;
249 std::vector<size_t> teqidx;
250 std::vector<size_t> rgeidx;
251 std::unordered_set<Lattice_constraint*> elementary_constraints;
253 // as of v1.52 boost::thread gives valgrind the impression that
254 // 8 bytes are not freed at exit
255 // see http://www.cplusplus.com/forum/unices/83480/
256 boost::thread_group *threads;
257 boost::barrier *threads_begin, *threads_end;
259 void set_units();
260 void apply_constraints();
261 void apply_constraints_thread(Lattice_constraint *c);
262 void create_threads();
263 void join_threads();
264 Real maxdiff(const RVec& y0, const RVec& y1);
265 void init_lattice();
266 void increase_a();
267 void increase_density();
268 void rk_stage();
269 Inner_status iterate();
270 std::vector<std::vector<size_t>> refine_lattice();
271 void enable_Runge_Kutta();
272 void disable_Runge_Kutta();
273 void resample(const std::vector<std::vector<size_t>>& site_maps);
274 EqRow *ralloc(size_t T, size_t m, size_t span);
275 void rfree(EqRow *r);
276 void init_free_row_list();
277 void sort_rows();
278};
279
280} // namespace flexiblesusy
281
282#endif // lattice_solver_hpp
No convergence while solving the RGEs.
Definition: error.hpp:57
Non-perturbative RG running.
Definition: error.hpp:142
MemoryError(const std::string &message_)
NonPerturbativeRunningError(Lattice_model *model_, double scale_)
SetupError(const std::string &message_)
void add_model(Lattice_model *, InterTheoryConstraint *m=nullptr, const std::vector< SingleSiteConstraint * > &constraints=std::vector< SingleSiteConstraint * >())
std::vector< Lattice_constraint * > constraints
std::unordered_set< Lattice_constraint * > elementary_constraints
Real y(size_t T, size_t m, size_t i) const
friend std::ostream & operator<<(std::ostream &out, const RGFlow &flow)
Initial_guesser< Lattice > * init_profile
void add_model(Lattice_model *model, const std::vector< SingleSiteConstraint * > &constraints)
Real & y(size_t T, size_t m, size_t i)
Real x(size_t T, size_t m, size_t i) const
Real & A(size_t r, size_t T, size_t m, size_t i)
void add_model(Lattice_model *, const std::vector< SingleSiteConstraint * > &upward_constraints, const std::vector< SingleSiteConstraint * > &downward_constraints)
void add_model(Lattice_model *, InterTheoryConstraint *m, const std::vector< SingleSiteConstraint * > &upward_constraints, const std::vector< SingleSiteConstraint * > &downward_constraints)
Real u(size_t T, size_t i) const
size_t site_offset(size_t T, size_t m) const
Spectrum generator was not setup correctly.
Definition: error.hpp:46
T & operator()(size_t i, size_t j)
band_matrix(size_t N, size_t KL, size_t KU, size_t LD)
std::complex< double > f(double tau) noexcept
double Real
Definition: mathdefs.hpp:12
Constraint< Lattice > SingleSiteConstraint
std::vector< Real > RVec
Matching< Lattice > InterTheoryConstraint
EFT(Lattice_model *model, RGFlow *flow)
std::vector< SingleSiteConstraint * > constraints