Grid 0.7.0
Integrator_algorithm.h
Go to the documentation of this file.
1/*************************************************************************************
2
3Grid physics library, www.github.com/paboyle/Grid
4
5Source file: ./lib/qcd/hmc/integrators/Integrator_algorithm.h
6
7Copyright (C) 2015
8
9Author: Peter Boyle <paboyle@ph.ed.ac.uk>
10Author: neo <cossu@post.kek.jp>
11
12This program is free software; you can redistribute it and/or modify
13it under the terms of the GNU General Public License as published by
14the Free Software Foundation; either version 2 of the License, or
15(at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License along
23with this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25
26See the full license in the file "LICENSE" in the top level distribution
27directory
28*************************************************************************************/
29/* END LEGAL */
30//--------------------------------------------------------------------
31
32
37//--------------------------------------------------------------------
38
39#ifndef INTEGRATOR_ALG_INCLUDED
40#define INTEGRATOR_ALG_INCLUDED
41
43
44/* PAB:
45 *
46 * Recursive leapfrog; explanation of nested stepping
47 *
48 * Nested 1:4; units in dt for top level integrator
49 *
50 * CHROMA IroIro
51 * 0 1 0
52 * P 1/2 P 1/2
53 * P 1/16 P1/16
54 * U 1/8 U1/8
55 * P 1/8 P1/8
56 * U 1/8 U1/8
57 * P 1/8 P1/8
58 * U 1/8 U1/8
59 * P 1/8 P1/8
60 * U 1/8 U1/8
61 * P 1/16 P1/8
62 * P 1 P 1
63 * P 1/16 * skipped --- avoids revaluating force
64 * U 1/8 U1/8
65 * P 1/8 P1/8
66 * U 1/8 U1/8
67 * P 1/8 P1/8
68 * U 1/8 U1/8
69 * P 1/8 P1/8
70 * U 1/8 U1/8
71 * P 1/16 P1/8
72 * P 1 P 1
73 * P 1/16 * skipped
74 * U 1/8 U1/8
75 * P 1/8 P1/8
76 * U 1/8 U1/8
77 * P 1/8 P1/8
78 * U 1/8 U1/8
79 * P 1/8 P1/8
80 * U 1/8 U1/8
81 * P 1/16 * skipped
82 * P 1 P 1
83 * P 1/16 P1/8
84 * U 1/8 U1/8
85 * P 1/8 P1/8
86 * U 1/8 U1/8
87 * P 1/8 P1/8
88 * U 1/8 U1/8
89 * P 1/8 P1/8
90 * U 1/8 U1/8
91 * P 1/16 P1/16
92 * P 1/2 P 1/2
93 */
94
95template <class FieldImplementation_, class SmearingPolicy, class RepresentationPolicy = Representations<FundamentalRepresentation> >
96class LeapFrog : public Integrator<FieldImplementation_, SmearingPolicy, RepresentationPolicy>
97{
98public:
99 typedef FieldImplementation_ FieldImplementation;
102
103 std::string integrator_name(){return "LeapFrog";}
104
106 : Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(grid, Par, Aset, Sm){};
107
108 void step(Field& U, int level, int _first, int _last) {
109 int fl = this->as.size() - 1;
110 // level : current level
111 // fl : final level
112 // eps : current step size
113
114 // Get current level step size
115 RealD eps = this->Params.trajL/this->Params.MDsteps;
116 for (int l = 0; l <= level; ++l) eps /= this->as[l].multiplier;
117
118 int multiplier = this->as[level].multiplier;
119 for (int e = 0; e < multiplier; ++e) {
120 int first_step = _first && (e == 0);
121 int last_step = _last && (e == multiplier - 1);
122
123 if (first_step) { // initial half step
124 this->update_P(U, level, eps / 2.0);
125 }
126
127 if (level == fl) { // lowest level
128 this->update_U(U, eps);
129 } else { // recursive function call
130 this->step(U, level + 1, first_step, last_step);
131 }
132
133 int mm = last_step ? 1 : 2;
134 this->update_P(U, level, mm * eps / 2.0);
135 }
136 }
137};
138
139template <class FieldImplementation_, class SmearingPolicy, class RepresentationPolicy = Representations<FundamentalRepresentation> >
140class MinimumNorm2 : public Integrator<FieldImplementation_, SmearingPolicy, RepresentationPolicy>
141{
142private:
143 const RealD lambda = 0.1931833275037836;
144
145public:
146 typedef FieldImplementation_ FieldImplementation;
148
150 : Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(grid, Par, Aset, Sm){};
151
152 std::string integrator_name(){return "MininumNorm2";}
153
154 void step(Field& U, int level, int _first, int _last) {
155 // level : current level
156 // fl : final level
157 // eps : current step size
158
159 int fl = this->as.size() - 1;
160
161 RealD eps = this->Params.trajL/this->Params.MDsteps * 2.0;
162 for (int l = 0; l <= level; ++l) eps /= 2.0 * this->as[l].multiplier;
163
164 // Nesting: 2xupdate_U of size eps/2
165 // Next level is eps/2/multiplier
166
167 int multiplier = this->as[level].multiplier;
168 for (int e = 0; e < multiplier; ++e) { // steps per step
169
170 int first_step = _first && (e == 0);
171 int last_step = _last && (e == multiplier - 1);
172
173 if (first_step) { // initial half step
174 this->update_P(U, level, lambda * eps);
175 }
176
177 if (level == fl) { // lowest level
178 this->update_U(U, 0.5 * eps);
179 } else { // recursive function call
180 this->step(U, level + 1, first_step, 0);
181 }
182
183 this->update_P(U, level, (1.0 - 2.0 * lambda) * eps);
184
185 if (level == fl) { // lowest level
186 this->update_U(U, 0.5 * eps);
187 } else { // recursive function call
188 this->step(U, level + 1, 0, last_step);
189 }
190
191 int mm = (last_step) ? 1 : 2;
192 this->update_P(U, level, lambda * eps * mm);
193 }
194 }
195};
196
197template <class FieldImplementation_, class SmearingPolicy, class RepresentationPolicy = Representations<FundamentalRepresentation> >
198class ForceGradient : public Integrator<FieldImplementation_, SmearingPolicy, RepresentationPolicy>
199{
200private:
201 const RealD lambda = 1.0 / 6.0;
202 const RealD chi = 1.0 / 72.0;
203 const RealD xi = 0.0;
204 const RealD theta = 0.0;
205
206public:
207 typedef FieldImplementation_ FieldImplementation;
209
210 // Looks like dH scales as dt^4. tested wilson/wilson 2 level.
213 SmearingPolicy& Sm)
214 : Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(
215 grid, Par, Aset, Sm){};
216
217 std::string integrator_name(){return "ForceGradient";}
218
219 void FG_update_P(Field& U, int level, double fg_dt, double ep) {
220 Field Ufg(U.Grid());
221 Field Pfg(U.Grid());
222 Ufg = U;
223 Pfg = Zero();
224 std::cout << GridLogIntegrator << "FG update " << fg_dt << " " << ep << std::endl;
225 // prepare_fg; no prediction/result cache for now
226 // could relax CG stopping conditions for the
227 // derivatives in the small step since the force gets multiplied by
228 // a tiny dt^2 term relative to main force.
229 //
230 // Presently 4 force evals, and should have 3, so 1.33x too expensive.
231 // could reduce this with sloppy CG to perhaps 1.15x too expensive
232 // even without prediction.
233 this->update_P(Pfg, Ufg, level, fg_dt);
234 Pfg = Pfg*(1.0/fg_dt);
235 this->update_U(Pfg, Ufg, fg_dt);
236 this->update_P(Ufg, level, ep);
237 }
238
239 void step(Field& U, int level, int _first, int _last) {
240 RealD eps = this->Params.trajL/this->Params.MDsteps * 2.0;
241 for (int l = 0; l <= level; ++l) eps /= 2.0 * this->as[l].multiplier;
242
243 RealD Chi = chi * eps * eps * eps;
244
245 int fl = this->as.size() - 1;
246
247 int multiplier = this->as[level].multiplier;
248
249 for (int e = 0; e < multiplier; ++e) { // steps per step
250
251 int first_step = _first && (e == 0);
252 int last_step = _last && (e == multiplier - 1);
253
254 if (first_step) { // initial half step
255 this->update_P(U, level, lambda * eps);
256 }
257
258 if (level == fl) { // lowest level
259 this->update_U(U, 0.5 * eps);
260 } else { // recursive function call
261 this->step(U, level + 1, first_step, 0);
262 }
263
264 this->FG_update_P(U, level, 2 * Chi / ((1.0 - 2.0 * lambda) * eps), (1.0 - 2.0 * lambda) * eps);
265
266 if (level == fl) { // lowest level
267 this->update_U(U, 0.5 * eps);
268 } else { // recursive function call
269 this->step(U, level + 1, 0, last_step);
270 }
271
272 int mm = (last_step) ? 1 : 2;
273 this->update_P(U, level, lambda * eps * mm);
274 }
275 }
276};
277
279
280#endif // INTEGRATOR_INCLUDED
std::vector< ActionLevel< GaugeField, R > > ActionSet
Definition ActionSet.h:108
GridLogger GridLogIntegrator(1, "Integrator", GridLogColours, "BLUE")
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
double RealD
Definition Simd.h:61
static INTERNAL_PRECISION U
Definition Zolotarev.cc:230
void step(Field &U, int level, int _first, int _last)
INHERIT_FIELD_TYPES(FieldImplementation)
FieldImplementation_ FieldImplementation
std::string integrator_name()
void FG_update_P(Field &U, int level, double fg_dt, double ep)
ForceGradient(GridBase *grid, IntegratorParameters Par, ActionSet< Field, RepresentationPolicy > &Aset, SmearingPolicy &Sm)
const ActionSet< Field, RepresentationPolicy > as
Definition Integrator.h:88
Integrator(GridBase *grid, IntegratorParameters Par, ActionSet< Field, RepresentationPolicy > &Aset, SmearingPolicy &Sm)
Definition Integrator.h:221
void update_U(Field &U, double ep)
Definition Integrator.h:193
void update_P(Field &U, int level, double ep)
Definition Integrator.h:98
std::string integrator_name()
FieldImplementation_ FieldImplementation
INHERIT_FIELD_TYPES(FieldImplementation)
LeapFrog(GridBase *grid, IntegratorParameters Par, ActionSet< Field, RepresentationPolicy > &Aset, SmearingPolicy &Sm)
void step(Field &U, int level, int _first, int _last)
LeapFrog< FieldImplementation, SmearingPolicy, RepresentationPolicy > Algorithm
FieldImplementation_ FieldImplementation
std::string integrator_name()
MinimumNorm2(GridBase *grid, IntegratorParameters Par, ActionSet< Field, RepresentationPolicy > &Aset, SmearingPolicy &Sm)
INHERIT_FIELD_TYPES(FieldImplementation)
void step(Field &U, int level, int _first, int _last)
Definition Simd.h:194