Grid 0.7.0
GaugeConfiguration.h
Go to the documentation of this file.
1
6#pragma once
7
9
10
11//trivial class for no smearing
12template< class Impl >
13class NoSmearing : public ConfigurationBase<typename Impl::Field>
14{
15public:
17
18 Field* ThinLinks;
19
21
22 virtual void set_Field(Field& U) { ThinLinks = &U; }
23
24 virtual void smeared_force(Field&) {}
25
26 virtual Field& get_SmearedU() { return *ThinLinks; }
27
28 virtual Field &get_U(bool smeared = false)
29 {
30 return *ThinLinks;
31 }
32};
33
45template <class Gimpl>
46class SmearedConfiguration : public ConfigurationBase<typename Gimpl::Field>
47{
48public:
50
51protected:
52 const unsigned int smearingLevels;
54 std::vector<GaugeField> SmearedSet;
55public:
56 GaugeField* ThinLinks; /* Pointer to the thin links configuration */ // move to base???
57protected:
58
59 // Member functions
60 //====================================================================
61
62 // Overridden in masked version
63 virtual void fill_smearedSet(GaugeField &U)
64 {
65 ThinLinks = &U; // attach the smearing routine to the field U
66
67 // check the pointer is not null
68 if (ThinLinks == NULL)
69 std::cout << GridLogError
70 << "[SmearedConfiguration] Error in ThinLinks pointer\n";
71
72 if (smearingLevels > 0)
73 {
74 std::cout << GridLogDebug
75 << "[SmearedConfiguration] Filling SmearedSet\n";
76 GaugeField previous_u(ThinLinks->Grid());
77
78 previous_u = *ThinLinks;
79 for (int smearLvl = 0; smearLvl < smearingLevels; ++smearLvl)
80 {
81 StoutSmearing->smear(SmearedSet[smearLvl], previous_u);
82 previous_u = SmearedSet[smearLvl];
83
84 // For debug purposes
85 RealD impl_plaq = WilsonLoops<Gimpl>::avgPlaquette(previous_u);
86 std::cout << GridLogDebug
87 << "[SmearedConfiguration] Plaq: " << impl_plaq << std::endl;
88 }
89 }
90 }
91
92 //overridden in masked verson
93 virtual GaugeField AnalyticSmearedForce(const GaugeField& SigmaKPrime,
94 const GaugeField& GaugeK) const
95 {
96 GridBase* grid = GaugeK.Grid();
97 GaugeField C(grid), SigmaK(grid), iLambda(grid);
98 GaugeLinkField iLambda_mu(grid);
99 GaugeLinkField iQ(grid), e_iQ(grid);
100 GaugeLinkField SigmaKPrime_mu(grid);
101 GaugeLinkField GaugeKmu(grid), Cmu(grid);
102
103 StoutSmearing->BaseSmear(C, GaugeK);
104 SigmaK = Zero();
105 iLambda = Zero();
106
107 for (int mu = 0; mu < Nd; mu++)
108 {
109 Cmu = peekLorentz(C, mu);
110 GaugeKmu = peekLorentz(GaugeK, mu);
111 SigmaKPrime_mu = peekLorentz(SigmaKPrime, mu);
112 iQ = Ta(Cmu * adj(GaugeKmu));
113 set_iLambda(iLambda_mu, e_iQ, iQ, SigmaKPrime_mu, GaugeKmu);
114 pokeLorentz(SigmaK, SigmaKPrime_mu * e_iQ + adj(Cmu) * iLambda_mu, mu);
115 pokeLorentz(iLambda, iLambda_mu, mu);
116 }
117 StoutSmearing->derivative(SigmaK, iLambda,
118 GaugeK); // derivative of SmearBase
119 return SigmaK;
120 }
121
123 const GaugeField &get_smeared_conf(int Level) const
124 {
125 return SmearedSet[Level];
126 }
127
128 //====================================================================
129 void set_iLambda(GaugeLinkField& iLambda, GaugeLinkField& e_iQ,
130 const GaugeLinkField& iQ, const GaugeLinkField& Sigmap,
131 const GaugeLinkField& GaugeK) const
132 {
133 GridBase* grid = iQ.Grid();
134 GaugeLinkField iQ2(grid), iQ3(grid), B1(grid), B2(grid), USigmap(grid);
135 GaugeLinkField unity(grid);
136 unity = 1.0;
137
138 LatticeComplex u(grid), w(grid);
139 LatticeComplex f0(grid), f1(grid), f2(grid);
140 LatticeComplex xi0(grid), xi1(grid), tmp(grid);
141 LatticeComplex u2(grid), w2(grid), cosw(grid);
142 LatticeComplex emiu(grid), e2iu(grid), qt(grid), fden(grid);
143 LatticeComplex r01(grid), r11(grid), r21(grid), r02(grid), r12(grid);
144 LatticeComplex r22(grid), tr1(grid), tr2(grid);
145 LatticeComplex b10(grid), b11(grid), b12(grid), b20(grid), b21(grid),
146 b22(grid);
147 LatticeComplex LatticeUnitComplex(grid);
148
149 LatticeUnitComplex = 1.0;
150
151 // Exponential
152 iQ2 = iQ * iQ;
153 iQ3 = iQ * iQ2;
154 StoutSmearing->set_uw(u, w, iQ2, iQ3);
155 StoutSmearing->set_fj(f0, f1, f2, u, w);
156 e_iQ = f0 * unity + timesMinusI(f1) * iQ - f2 * iQ2;
157
158 // Getting B1, B2, Gamma and Lambda
159 // simplify this part, reduntant calculations in set_fj
160 xi0 = StoutSmearing->func_xi0(w);
161 xi1 = StoutSmearing->func_xi1(w);
162 u2 = u * u;
163 w2 = w * w;
164 cosw = cos(w);
165
166 emiu = cos(u) - timesI(sin(u));
167 e2iu = cos(2.0 * u) + timesI(sin(2.0 * u));
168
169 r01 = (2.0 * u + timesI(2.0 * (u2 - w2))) * e2iu +
170 emiu * ((16.0 * u * cosw + 2.0 * u * (3.0 * u2 + w2) * xi0) +
171 timesI(-8.0 * u2 * cosw + 2.0 * (9.0 * u2 + w2) * xi0));
172
173 r11 = (2.0 * LatticeUnitComplex + timesI(4.0 * u)) * e2iu +
174 emiu * ((-2.0 * cosw + (3.0 * u2 - w2) * xi0) +
175 timesI((2.0 * u * cosw + 6.0 * u * xi0)));
176
177 r21 =
178 2.0 * timesI(e2iu) + emiu * (-3.0 * u * xi0 + timesI(cosw - 3.0 * xi0));
179
180 r02 = -2.0 * e2iu +
181 emiu * (-8.0 * u2 * xi0 +
182 timesI(2.0 * u * (cosw + xi0 + 3.0 * u2 * xi1)));
183
184 r12 = emiu * (2.0 * u * xi0 + timesI(-cosw - xi0 + 3.0 * u2 * xi1));
185
186 r22 = emiu * (xi0 - timesI(3.0 * u * xi1));
187
188 fden = LatticeUnitComplex / (2.0 * (9.0 * u2 - w2) * (9.0 * u2 - w2));
189
190 b10 = 2.0 * u * r01 + (3.0 * u2 - w2) * r02 - (30.0 * u2 + 2.0 * w2) * f0;
191 b11 = 2.0 * u * r11 + (3.0 * u2 - w2) * r12 - (30.0 * u2 + 2.0 * w2) * f1;
192 b12 = 2.0 * u * r21 + (3.0 * u2 - w2) * r22 - (30.0 * u2 + 2.0 * w2) * f2;
193
194 b20 = r01 - (3.0 * u) * r02 - (24.0 * u) * f0;
195 b21 = r11 - (3.0 * u) * r12 - (24.0 * u) * f1;
196 b22 = r21 - (3.0 * u) * r22 - (24.0 * u) * f2;
197
198 b10 *= fden;
199 b11 *= fden;
200 b12 *= fden;
201 b20 *= fden;
202 b21 *= fden;
203 b22 *= fden;
204
205 B1 = b10 * unity + timesMinusI(b11) * iQ - b12 * iQ2;
206 B2 = b20 * unity + timesMinusI(b21) * iQ - b22 * iQ2;
207 USigmap = GaugeK * Sigmap;
208
209 tr1 = trace(USigmap * B1);
210 tr2 = trace(USigmap * B2);
211
212 GaugeLinkField QUS = iQ * USigmap;
213 GaugeLinkField USQ = USigmap * iQ;
214
215 GaugeLinkField iGamma = tr1 * iQ - timesI(tr2) * iQ2 +
216 timesI(f1) * USigmap + f2 * QUS + f2 * USQ;
217
218 iLambda = Ta(iGamma);
219 }
220
221 //====================================================================
222public:
223
224 /* Standard constructor */
225 SmearedConfiguration(GridCartesian* UGrid, unsigned int Nsmear,
226 Smear_Stout<Gimpl>& Stout)
227 : smearingLevels(Nsmear), StoutSmearing(&Stout), ThinLinks(NULL)
228 {
229 for (unsigned int i = 0; i < smearingLevels; ++i)
230 SmearedSet.push_back(*(new GaugeField(UGrid)));
231 }
232
236
237 // attach the smeared routines to the thin links U and fill the smeared set
238 virtual void set_Field(GaugeField &U)
239 {
240 double start = usecond();
242 double end = usecond();
243 double time = (end - start)/ 1e3;
244 std::cout << GridLogMessage << "Smearing in " << time << " ms" << std::endl;
245 }
246
247 //====================================================================
248 virtual void smeared_force(GaugeField &SigmaTilde)
249 {
250 if (smearingLevels > 0)
251 {
252 double start = usecond();
253 GaugeField force = SigmaTilde; // actually = U*SigmaTilde
254 GaugeLinkField tmp_mu(SigmaTilde.Grid());
255
256 for (int mu = 0; mu < Nd; mu++)
257 {
258 // to get just SigmaTilde
259 tmp_mu = adj(peekLorentz(SmearedSet[smearingLevels - 1], mu)) * peekLorentz(force, mu);
260 pokeLorentz(force, tmp_mu, mu);
261 }
262
263 for (int ismr = smearingLevels - 1; ismr > 0; --ismr)
264 force = AnalyticSmearedForce(force, get_smeared_conf(ismr - 1));
265
266 force = AnalyticSmearedForce(force, *ThinLinks);
267
268 for (int mu = 0; mu < Nd; mu++)
269 {
270 tmp_mu = peekLorentz(*ThinLinks, mu) * peekLorentz(force, mu);
271 pokeLorentz(SigmaTilde, tmp_mu, mu);
272 }
273 double end = usecond();
274 double time = (end - start)/ 1e3;
275 std::cout << GridLogMessage << " GaugeConfiguration: Smeared Force chain rule took " << time << " ms" << std::endl;
276 } // if smearingLevels = 0 do nothing
277 SigmaTilde=Gimpl::projectForce(SigmaTilde); // Ta
278
279 }
280 //====================================================================
281
282 virtual GaugeField& get_SmearedU() { return SmearedSet[smearingLevels - 1]; }
283
284 virtual GaugeField &get_U(bool smeared = false)
285 {
286 // get the config, thin links by default
287 if (smeared)
288 {
289 if (smearingLevels)
290 {
291 RealD impl_plaq =
293 std::cout << GridLogDebug << "getting Usmr Plaq: " << impl_plaq
294 << std::endl;
295 return get_SmearedU();
296 }
297 else
298 {
300 std::cout << GridLogDebug << "getting Thin Plaq: " << impl_plaq
301 << std::endl;
302 return *ThinLinks;
303 }
304 }
305 else
306 {
308 std::cout << GridLogDebug << "getting Thin Plaq: " << impl_plaq
309 << std::endl;
310 return *ThinLinks;
311 }
312 }
313};
314
316
accelerator_inline void timesMinusI(Grid_simd2< S, V > &ret, const Grid_simd2< S, V > &in)
accelerator_inline void timesI(Grid_simd2< S, V > &ret, const Grid_simd2< S, V > &in)
accelerator_inline Grid_simd2< S, V > trace(const Grid_simd2< S, V > &arg)
accelerator_inline Grid_simd< S, V > cos(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > sin(const Grid_simd< S, V > &r)
Lattice< vobj > adj(const Lattice< vobj > &lhs)
GridLogger GridLogError(1, "Error", GridLogColours, "RED")
GridLogger GridLogDebug(1, "Debug", GridLogColours, "PURPLE")
GridLogger GridLogMessage(1, "Message", GridLogColours, "NORMAL")
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
void pokeLorentz(Lattice< vobj > &lhs, const Lattice< decltype(peekIndex< LorentzIndex >(vobj(), 0))> &rhs, int i)
Definition QCD.h:487
static constexpr int Nd
Definition QCD.h:52
Lattice< vTComplex > LatticeComplex
Definition QCD.h:359
auto peekLorentz(const vobj &rhs, int i) -> decltype(PeekIndex< LorentzIndex >(rhs, 0))
Definition QCD.h:446
double RealD
Definition Simd.h:61
accelerator_inline iScalar< vtype > Ta(const iScalar< vtype > &r)
Definition Tensor_Ta.h:45
double usecond(void)
Definition Timer.h:50
static INTERNAL_PRECISION U
Definition Zolotarev.cc:230
INHERIT_FIELD_TYPES(Impl)
virtual Field & get_U(bool smeared=false)
virtual Field & get_SmearedU()
virtual void set_Field(Field &U)
virtual void smeared_force(Field &)
Stout smearing of link variable.
const unsigned int smearingLevels
virtual void set_Field(GaugeField &U)
virtual GaugeField AnalyticSmearedForce(const GaugeField &SigmaKPrime, const GaugeField &GaugeK) const
const GaugeField & get_smeared_conf(int Level) const
Returns smeared configuration at level 'Level'.
virtual GaugeField & get_U(bool smeared=false)
Smear_Stout< Gimpl > * StoutSmearing
SmearedConfiguration(GridCartesian *UGrid, unsigned int Nsmear, Smear_Stout< Gimpl > &Stout)
virtual void smeared_force(GaugeField &SigmaTilde)
void set_iLambda(GaugeLinkField &iLambda, GaugeLinkField &e_iQ, const GaugeLinkField &iQ, const GaugeLinkField &Sigmap, const GaugeLinkField &GaugeK) const
virtual GaugeField & get_SmearedU()
std::vector< GaugeField > SmearedSet
virtual void fill_smearedSet(GaugeField &U)
static RealD avgPlaquette(const GaugeLorentz &Umu)
Definition Simd.h:194