Grid 0.7.0
Photon.h
Go to the documentation of this file.
1/*************************************************************************************
2
3 Grid physics library, www.github.com/paboyle/Grid
4
5 Source file: ./lib/qcd/action/gauge/Photon.h
6
7Copyright (C) 2015-2018
8
9 Author: Peter Boyle <paboyle@ph.ed.ac.uk>
10 Author: Antonin Portelli <antonin.portelli@me.com>
11 Author: James Harrison <J.Harrison@soton.ac.uk>
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License along
24 with this program; if not, write to the Free Software Foundation, Inc.,
25 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26
27 See the full license in the file "LICENSE" in the top level distribution directory
28 *************************************************************************************/
29/* END LEGAL */
30#pragma once
31
33
34 template <class S>
36 {
37 public:
38 typedef S Simd;
39 typedef typename Simd::scalar_type Scalar;
40
41 template <typename vtype>
43 template <typename vtype>
45
49
53 };
54
56
57 template <class GImpl>
58 class Photon
59 {
60 public:
62 typedef typename SiteGaugeLink::scalar_object ScalarSite;
63 typedef typename ScalarSite::scalar_type ScalarComplex;
64 GRID_SERIALIZABLE_ENUM(Gauge, undef, feynman, 1, coulomb, 2, landau, 3);
65 GRID_SERIALIZABLE_ENUM(ZmScheme, undef, qedL, 1, qedTL, 2);
66 public:
67 Photon(GridBase *grid, Gauge gauge, ZmScheme zmScheme, std::vector<Real> improvement);
68 Photon(GridBase *grid, Gauge gauge, ZmScheme zmScheme);
69 virtual ~Photon(void) = default;
70 void FreePropagator(const GaugeField &in, GaugeField &out);
71 void MomentumSpacePropagator(const GaugeField &in, GaugeField &out);
72 void StochasticWeight(GaugeLinkField &weight);
73 void StochasticField(GaugeField &out, GridParallelRNG &rng);
74 void StochasticField(GaugeField &out, GridParallelRNG &rng,
75 const GaugeLinkField &weight);
76 void UnitField(GaugeField &out);
77 private:
79 void makeKHat(std::vector<GaugeLinkField> &khat);
80 void makeInvKHatSquared(GaugeLinkField &out);
81 void zmSub(GaugeLinkField &out);
82 void transverseProjectSpatial(GaugeField &out);
83 void gaugeTransform(GaugeField &out);
84 private:
86 Gauge gauge_;
87 ZmScheme zmScheme_;
88 std::vector<Real> improvement_;
89 };
90
92
93 template<class GImpl>
94 Photon<GImpl>::Photon(GridBase *grid, Gauge gauge, ZmScheme zmScheme,
95 std::vector<Real> improvements)
96 : grid_(grid), gauge_(gauge), zmScheme_(zmScheme), improvement_(improvements)
97 {}
98
99 template<class GImpl>
100 Photon<GImpl>::Photon(GridBase *grid, Gauge gauge, ZmScheme zmScheme)
101 : Photon(grid, gauge, zmScheme, std::vector<Real>())
102 {}
103
104 template<class GImpl>
105 void Photon<GImpl>::FreePropagator(const GaugeField &in, GaugeField &out)
106 {
107 FFT theFFT(dynamic_cast<GridCartesian *>(grid_));
108 GaugeField in_k(grid_);
109 GaugeField prop_k(grid_);
110
111 theFFT.FFT_all_dim(in_k, in, FFT::forward);
112 MomentumSpacePropagator(prop_k, in_k);
113 theFFT.FFT_all_dim(out, prop_k, FFT::backward);
114 }
115
116 template<class GImpl>
118 {
119 LatticeInteger coor(grid_);
120 auto l = grid_->FullDimensions();
121
122 spNrm = Zero();
123 for(int mu = 0; mu < grid_->Nd() - 1; mu++)
124 {
125 LatticeCoordinate(coor, mu);
126 coor = where(coor < Integer(l[mu]/2), coor, coor - Integer(l[mu]));
127 spNrm = spNrm + coor*coor;
128 }
129 }
130
131 template<class GImpl>
132 void Photon<GImpl>::makeKHat(std::vector<GaugeLinkField> &khat)
133 {
134 const unsigned int nd = grid_->Nd();
135 auto l = grid_->FullDimensions();
136 Complex ci(0., 1.);
137
138 khat.resize(nd, grid_);
139 for (unsigned int mu = 0; mu < nd; ++mu)
140 {
141 Real piL = M_PI/l[mu];
142
143 LatticeCoordinate(khat[mu], mu);
144 khat[mu] = exp(piL*ci*khat[mu])*2.*sin(piL*khat[mu]);
145 }
146 }
147
148 template<class GImpl>
149 void Photon<GImpl>::makeInvKHatSquared(GaugeLinkField &out)
150 {
151 std::vector<GaugeLinkField> khat;
152 GaugeLinkField lone(grid_);
153 const unsigned int nd = grid_->Nd();
154 Coordinate zm(nd, 0);
155 ScalarSite one = ScalarComplex(1., 0.), z = ScalarComplex(0., 0.);
156
157 out = Zero();
158 makeKHat(khat);
159 for(int mu = 0; mu < nd; mu++)
160 {
161 out = out + khat[mu]*conjugate(khat[mu]);
162 }
163 lone = ScalarComplex(1., 0.);
164 pokeSite(one, out, zm);
165 out = lone/out;
166 pokeSite(z, out, zm);
167 }
168
169 template<class GImpl>
170 void Photon<GImpl>::zmSub(GaugeLinkField &out)
171 {
172 switch (zmScheme_)
173 {
174 case ZmScheme::qedTL:
175 {
176 Coordinate zm(grid_->Nd(), 0);
177 ScalarSite z = ScalarComplex(0., 0.);
178
179 pokeSite(z, out, zm);
180 break;
181 }
182 case ZmScheme::qedL:
183 {
184 LatticeInteger spNrm(grid_);
185
186 makeSpatialNorm(spNrm);
187 out = where(spNrm == Integer(0), 0.*out, out);
188 for(int i = 0; i < improvement_.size(); i++)
189 {
190 Real f = sqrt(improvement_[i] + 1);
191 out = where(spNrm == Integer(i + 1), f*out, out);
192 }
193 break;
194 }
195 default:
196 assert(0);
197 break;
198 }
199 }
200
201 template<class GImpl>
203 {
204 const unsigned int nd = grid_->Nd();
205 GaugeLinkField invKHat(grid_), cst(grid_), spdiv(grid_);
206 LatticeInteger spNrm(grid_);
207 std::vector<GaugeLinkField> khat, a(nd, grid_), aProj(nd, grid_);
208
209 invKHat = Zero();
210 makeSpatialNorm(spNrm);
211 makeKHat(khat);
212 for (unsigned int mu = 0; mu < nd; ++mu)
213 {
214 a[mu] = peekLorentz(out, mu);
215 if (mu < nd - 1)
216 {
217 invKHat += khat[mu]*conjugate(khat[mu]);
218 }
219 }
220 cst = ScalarComplex(1., 0.);
221 invKHat = where(spNrm == Integer(0), cst, invKHat);
222 invKHat = cst/invKHat;
223 cst = Zero();
224 invKHat = where(spNrm == Integer(0), cst, invKHat);
225 spdiv = Zero();
226 for (unsigned int nu = 0; nu < nd - 1; ++nu)
227 {
228 spdiv += conjugate(khat[nu])*a[nu];
229 }
230 spdiv *= invKHat;
231 for (unsigned int mu = 0; mu < nd; ++mu)
232 {
233 aProj[mu] = a[mu] - khat[mu]*spdiv;
234 pokeLorentz(out, aProj[mu], mu);
235 }
236 }
237
238 template<class GImpl>
239 void Photon<GImpl>::gaugeTransform(GaugeField &out)
240 {
241 switch (gauge_)
242 {
243 case Gauge::feynman:
244 break;
245 case Gauge::coulomb:
247 break;
248 case Gauge::landau:
249 assert(0);
250 break;
251 default:
252 assert(0);
253 break;
254 }
255 }
256
257 template<class GImpl>
258 void Photon<GImpl>::MomentumSpacePropagator(const GaugeField &in,
259 GaugeField &out)
260 {
261 LatticeComplex momProp(grid_);
262
263 makeInvKHatSquared(momProp);
264 zmSub(momProp);
265
266 out = in*momProp;
267 }
268
269 template<class GImpl>
270 void Photon<GImpl>::StochasticWeight(GaugeLinkField &weight)
271 {
272 const unsigned int nd = grid_->Nd();
273 auto l = grid_->FullDimensions();
274 Integer vol = 1;
275
276 for(unsigned int mu = 0; mu < nd; mu++)
277 {
278 vol = vol*l[mu];
279 }
280 makeInvKHatSquared(weight);
281 weight = sqrt(vol)*sqrt(weight);
282 zmSub(weight);
283 }
284
285 template<class GImpl>
287 {
288 GaugeLinkField weight(grid_);
289
290 StochasticWeight(weight);
291 StochasticField(out, rng, weight);
292 }
293
294 template<class GImpl>
296 const GaugeLinkField &weight)
297 {
298 const unsigned int nd = grid_->Nd();
299 GaugeLinkField r(grid_);
300 GaugeField aTilde(grid_);
301 FFT fft(dynamic_cast<GridCartesian *>(grid_));
302
303 for(unsigned int mu = 0; mu < nd; mu++)
304 {
305 gaussian(rng, r);
306 r = weight*r;
307 pokeLorentz(aTilde, r, mu);
308 }
309 gaugeTransform(aTilde);
310 fft.FFT_all_dim(out, aTilde, FFT::backward);
311 out = real(out);
312 }
313
314 template<class GImpl>
315 void Photon<GImpl>::UnitField(GaugeField &out)
316 {
317 const unsigned int nd = grid_->Nd();
318 GaugeLinkField r(grid_);
319
320 r = ScalarComplex(1., 0.);
321 for(unsigned int mu = 0; mu < nd; mu++)
322 {
323 pokeLorentz(out, r, mu);
324 }
325 out = real(out);
326 }
327
329
#define one
Definition BGQQPX.h:108
AcceleratorVector< int, MaxDims > Coordinate
Definition Coordinate.h:95
accelerator_inline Grid_simd< S, V > sin(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > exp(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > sqrt(const Grid_simd< S, V > &r)
void LatticeCoordinate(Lattice< iobj > &l, int mu)
void pokeSite(const sobj &s, Lattice< vobj > &l, const Coordinate &site)
Lattice< vobj > real(const Lattice< vobj > &lhs)
Lattice< vobj > conjugate(const Lattice< vobj > &lhs)
void gaussian(GridParallelRNG &rng, Lattice< vobj > &l)
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
Photon< QedGImplR > PhotonR
Definition Photon.h:91
QedGImpl< vComplex > QedGImplR
Definition Photon.h:55
void pokeLorentz(Lattice< vobj > &lhs, const Lattice< decltype(peekIndex< LorentzIndex >(vobj(), 0))> &rhs, int i)
Definition QCD.h:487
Lattice< vTInteger > LatticeInteger
Definition QCD.h:364
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
uint32_t Integer
Definition Simd.h:58
RealF Real
Definition Simd.h:65
std::complex< Real > Complex
Definition Simd.h:80
#define M_PI
Definition Zolotarev.cc:41
Definition FFT.h:105
static const int backward
Definition FFT.h:123
static const int forward
Definition FFT.h:122
void FFT_all_dim(Lattice< vobj > &result, const Lattice< vobj > &source, int sign)
Definition FFT.h:162
void UnitField(GaugeField &out)
Definition Photon.h:315
void zmSub(GaugeLinkField &out)
Definition Photon.h:170
void FreePropagator(const GaugeField &in, GaugeField &out)
Definition Photon.h:105
void makeKHat(std::vector< GaugeLinkField > &khat)
Definition Photon.h:132
void StochasticWeight(GaugeLinkField &weight)
Definition Photon.h:270
void gaugeTransform(GaugeField &out)
Definition Photon.h:239
void StochasticField(GaugeField &out, GridParallelRNG &rng, const GaugeLinkField &weight)
Definition Photon.h:295
void MomentumSpacePropagator(const GaugeField &in, GaugeField &out)
Definition Photon.h:258
void StochasticField(GaugeField &out, GridParallelRNG &rng)
Definition Photon.h:286
void makeInvKHatSquared(GaugeLinkField &out)
Definition Photon.h:149
SiteGaugeLink::scalar_object ScalarSite
Definition Photon.h:62
virtual ~Photon(void)=default
Photon(GridBase *grid, Gauge gauge, ZmScheme zmScheme)
Definition Photon.h:100
std::vector< Real > improvement_
Definition Photon.h:88
GRID_SERIALIZABLE_ENUM(ZmScheme, undef, qedL, 1, qedTL, 2)
GridBase * grid_
Definition Photon.h:85
ScalarSite::scalar_type ScalarComplex
Definition Photon.h:63
INHERIT_GIMPL_TYPES(GImpl)
void transverseProjectSpatial(GaugeField &out)
Definition Photon.h:202
ZmScheme zmScheme_
Definition Photon.h:87
GRID_SERIALIZABLE_ENUM(Gauge, undef, feynman, 1, coulomb, 2, landau, 3)
void makeSpatialNorm(LatticeInteger &spNrm)
Definition Photon.h:117
Photon(GridBase *grid, Gauge gauge, ZmScheme zmScheme, std::vector< Real > improvement)
Definition Photon.h:94
SiteLink SiteComplex
Definition Photon.h:48
Lattice< SiteField > Field
Definition Photon.h:51
Lattice< SiteLink > LinkField
Definition Photon.h:50
iVector< iScalar< iScalar< vtype > >, Nd > iImplGaugeField
Definition Photon.h:44
S Simd
Definition Photon.h:38
iImplGaugeField< Simd > SiteField
Definition Photon.h:47
iImplGaugeLink< Simd > SiteLink
Definition Photon.h:46
iScalar< iScalar< iScalar< vtype > > > iImplGaugeLink
Definition Photon.h:42
Simd::scalar_type Scalar
Definition Photon.h:39
LinkField ComplexField
Definition Photon.h:52
Definition Simd.h:194