Grid 0.7.0
GaugeFix.h
Go to the documentation of this file.
1/*************************************************************************************
2
3 grid` physics library, www.github.com/paboyle/Grid
4
5 Copyright (C) 2015
6
7Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
8Author: Peter Boyle <paboyle@ph.ed.ac.uk>
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License along
21 with this program; if not, write to the Free Software Foundation, Inc.,
22 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
24 See the full license in the file "LICENSE" in the top level distribution directory
25*************************************************************************************/
26/* END LEGAL */
27//#include <Grid/Grid.h>
28
29#ifndef GRID_QCD_GAUGE_FIX_H
30#define GRID_QCD_GAUGE_FIX_H
31
33
34
35template <class Gimpl>
36class FourierAcceleratedGaugeFixer : public Gimpl {
37public:
39
40 typedef typename Gimpl::GaugeLinkField GaugeMat;
41 typedef typename Gimpl::GaugeField GaugeLorentz;
42
43 //A_\mu(x) = -i Ta(U_\mu(x) ) where Ta(U) = 1/2( U - U^dag ) - 1/2N tr(U - U^dag) is the traceless antihermitian part. This is an O(A^3) approximation to the logarithm of U
45 Complex cmi(0.0,-1.0);
46 A = Ta(U) * cmi;
47 }
48
49 //The derivative of the Lie algebra field
50 static void DmuAmu(const std::vector<GaugeMat> &U, GaugeMat &dmuAmu,int orthog) {
51 GridBase* grid = U[0].Grid();
52 GaugeMat Ax(grid);
53 GaugeMat Axm1(grid);
54 GaugeMat Utmp(grid);
55
56 dmuAmu=Zero();
57 for(int mu=0;mu<Nd;mu++){
58 if ( mu != orthog ) {
59 //Rather than define functionality to work out how the BCs apply to A_\mu we simply use the BC-aware Cshift to the gauge links and compute A_\mu(x) and A_\mu(x-1) separately
60 //Ax = A_\mu(x)
62
63 //Axm1 = A_\mu(x_\mu-1)
64 Utmp = Gimpl::CshiftLink(U[mu], mu, -1);
66
67 //Derivative
68 dmuAmu = dmuAmu + Ax - Axm1;
69 }
70 }
71 }
72
73 //Fix the gauge field Umu
74 //0 < alpha < 1 is related to the step size, cf https://arxiv.org/pdf/1405.5812.pdf
75 static void SteepestDescentGaugeFix(GaugeLorentz &Umu,Real alpha,int maxiter,Real Omega_tol, Real Phi_tol,bool Fourier=false,int orthog=-1,bool err_on_no_converge=true) {
76 GridBase *grid = Umu.Grid();
77 GaugeMat xform(grid);
78 SteepestDescentGaugeFix(Umu,xform,alpha,maxiter,Omega_tol,Phi_tol,Fourier,orthog,err_on_no_converge);
79 }
80 static void SteepestDescentGaugeFix(GaugeLorentz &Umu,GaugeMat &xform,Real alpha,int maxiter,Real Omega_tol, Real Phi_tol,bool Fourier=false,int orthog=-1,bool err_on_no_converge=true) {
81 //Fix the gauge field Umu and also return the gauge transformation from the original gauge field, xform
82
83 GridBase *grid = Umu.Grid();
84
86 Real org_link_trace=WilsonLoops<Gimpl>::linkTrace(Umu);
87 Real old_trace = org_link_trace;
88 Real trG;
89
90 xform=1.0;
91
92 std::vector<GaugeMat> U(Nd,grid);
93 GaugeMat dmuAmu(grid);
94
95 {
97 Real link_trace=WilsonLoops<Gimpl>::linkTrace(Umu);
98 if( (orthog>=0) && (orthog<Nd) ){
99 std::cout << GridLogMessage << " Gauge fixing to Coulomb gauge time="<<orthog<< " plaq= "<<plaq<<" link trace = "<<link_trace<< std::endl;
100 } else {
101 std::cout << GridLogMessage << " Gauge fixing to Landau gauge plaq= "<<plaq<<" link trace = "<<link_trace<< std::endl;
102 }
103 }
104 for(int i=0;i<maxiter;i++){
105
106 for(int mu=0;mu<Nd;mu++) U[mu]= PeekIndex<LorentzIndex>(Umu,mu);
107
108 if ( Fourier==false ) {
109 trG = SteepestDescentStep(U,xform,alpha,dmuAmu,orthog);
110 } else {
111 trG = FourierAccelSteepestDescentStep(U,xform,alpha,dmuAmu,orthog);
112 }
113
114 // std::cout << GridLogMessage << "trG "<< trG<< std::endl;
115 // std::cout << GridLogMessage << "xform "<< norm2(xform)<< std::endl;
116 // std::cout << GridLogMessage << "dmuAmu "<< norm2(dmuAmu)<< std::endl;
117
118 for(int mu=0;mu<Nd;mu++) PokeIndex<LorentzIndex>(Umu,U[mu],mu);
119 // Monitor progress and convergence test
120 // infrequently to minimise cost overhead
121 if ( i %20 == 0 ) {
123 Real link_trace=WilsonLoops<Gimpl>::linkTrace(Umu);
124
125 if (Fourier)
126 std::cout << GridLogMessage << "Fourier Iteration "<<i<< " plaq= "<<plaq<< " dmuAmu " << norm2(dmuAmu)<< std::endl;
127 else
128 std::cout << GridLogMessage << " Iteration "<<i<< " plaq= "<<plaq<< " dmuAmu " << norm2(dmuAmu)<< std::endl;
129
130 Real Phi = 1.0 - old_trace / link_trace ;
131 Real Omega= 1.0 - trG;
132
133 std::cout << GridLogMessage << " Iteration "<<i<< " Phi= "<<Phi<< " Omega= " << Omega<< " trG " << trG <<std::endl;
134 if ( (Omega < Omega_tol) && ( ::fabs(Phi) < Phi_tol) ) {
135 std::cout << GridLogMessage << "Converged ! "<<std::endl;
136 return;
137 }
138
139 old_trace = link_trace;
140
141 }
142 }
143 std::cout << GridLogError << "Gauge fixing did not converge in " << maxiter << " iterations." << std::endl;
144 if (err_on_no_converge)
145 assert(0 && "Gauge fixing did not converge within the specified number of iterations");
146 };
147 static Real SteepestDescentStep(std::vector<GaugeMat> &U,GaugeMat &xform, Real alpha, GaugeMat & dmuAmu,int orthog) {
148 GridBase *grid = U[0].Grid();
149
150 GaugeMat g(grid);
151 ExpiAlphaDmuAmu(U,g,alpha,dmuAmu,orthog);
152
153 Real vol = grid->gSites();
154 Real trG = TensorRemove(sum(trace(g))).real()/vol/Nc;
155
156 xform = g*xform ;
158
159 return trG;
160 }
161
162 static Real FourierAccelSteepestDescentStep(std::vector<GaugeMat> &U,GaugeMat &xform, Real alpha, GaugeMat & dmuAmu,int orthog) {
163
164 GridBase *grid = U[0].Grid();
165
166 Real vol = grid->gSites();
167
168 FFT theFFT((GridCartesian *)grid);
169
170 LatticeComplex Fp(grid);
171 LatticeComplex psq(grid); psq=Zero();
172 LatticeComplex pmu(grid);
173 LatticeComplex one(grid); one = Complex(1.0,0.0);
174
175 GaugeMat g(grid);
176 GaugeMat dmuAmu_p(grid);
177 DmuAmu(U,dmuAmu,orthog);
178
179 std::vector<int> mask(Nd,1);
180 for(int mu=0;mu<Nd;mu++) if (mu==orthog) mask[mu]=0;
181 theFFT.FFT_dim_mask(dmuAmu_p,dmuAmu,mask,FFT::forward);
182
184 // Work out Fp = psq_max/ psq...
185 // Avoid singularities in Fp
187 Coordinate latt_size = grid->GlobalDimensions();
188 Coordinate coor(grid->_ndimension,0);
189 for(int mu=0;mu<Nd;mu++) {
190 if ( mu != orthog ) {
191 Real TwoPiL = M_PI * 2.0/ latt_size[mu];
192 LatticeCoordinate(pmu,mu);
193 pmu = TwoPiL * pmu ;
194 psq = psq + 4.0*sin(pmu*0.5)*sin(pmu*0.5);
195 }
196 }
197
198 Complex psqMax(16.0);
199 Fp = psqMax*one/psq;
200
201 pokeSite(TComplex(16.0),Fp,coor);
202 if( (orthog>=0) && (orthog<Nd) ){
203 for(int t=0;t<grid->GlobalDimensions()[orthog];t++){
204 coor[orthog]=t;
205 pokeSite(TComplex(16.0),Fp,coor);
206 }
207 }
208
209 dmuAmu_p = dmuAmu_p * Fp;
210
211 theFFT.FFT_dim_mask(dmuAmu,dmuAmu_p,mask,FFT::backward);
212
213 GaugeMat ciadmam(grid);
214 Complex cialpha(0.0,-alpha);
215 ciadmam = dmuAmu*cialpha;
216 SU<Nc>::taExp(ciadmam,g);
217
218 Real trG = TensorRemove(sum(trace(g))).real()/vol/Nc;
219
220 xform = g*xform ;
222
223 return trG;
224 }
225
226 static void ExpiAlphaDmuAmu(const std::vector<GaugeMat> &U,GaugeMat &g, Real alpha, GaugeMat &dmuAmu,int orthog) {
227 GridBase *grid = g.Grid();
228 Complex cialpha(0.0,-alpha);
229 GaugeMat ciadmam(grid);
230 DmuAmu(U,dmuAmu,orthog);
231 ciadmam = dmuAmu*cialpha;
232 SU<Nc>::taExp(ciadmam,g);
233 }
234};
235
237
238#endif
#define one
Definition BGQQPX.h:108
AcceleratorVector< int, MaxDims > Coordinate
Definition Coordinate.h:95
accelerator_inline Grid_simd2< S, V > trace(const Grid_simd2< S, V > &arg)
accelerator_inline Grid_simd< S, V > sin(const Grid_simd< S, V > &r)
void LatticeCoordinate(Lattice< iobj > &l, int mu)
void pokeSite(const sobj &s, Lattice< vobj > &l, const Coordinate &site)
vobj::scalar_object sum(const vobj *arg, Integer osites)
RealD norm2(const Lattice< vobj > &arg)
GridLogger GridLogError(1, "Error", GridLogColours, "RED")
GridLogger GridLogMessage(1, "Message", GridLogColours, "NORMAL")
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
static constexpr int Nd
Definition QCD.h:52
static constexpr int Nc
Definition QCD.h:50
Lattice< vTComplex > LatticeComplex
Definition QCD.h:359
iSinglet< Complex > TComplex
Definition QCD.h:273
RealF Real
Definition Simd.h:65
std::complex< Real > Complex
Definition Simd.h:80
static void Omega(LatticeColourMatrixD &in)
Definition Sp2n.impl.h:286
accelerator_inline iScalar< vtype > Ta(const iScalar< vtype > &r)
Definition Tensor_Ta.h:45
accelerator_inline std::enable_if<!isGridTensor< T >::value, T >::type TensorRemove(T arg)
static INTERNAL_PRECISION U
Definition Zolotarev.cc:230
#define M_PI
Definition Zolotarev.cc:41
Definition FFT.h:105
static const int backward
Definition FFT.h:123
void FFT_dim_mask(Lattice< vobj > &result, const Lattice< vobj > &source, Coordinate mask, int sign)
Definition FFT.h:147
static const int forward
Definition FFT.h:122
Gimpl::GaugeLinkField GaugeMat
Definition GaugeFix.h:40
static Real FourierAccelSteepestDescentStep(std::vector< GaugeMat > &U, GaugeMat &xform, Real alpha, GaugeMat &dmuAmu, int orthog)
Definition GaugeFix.h:162
static void GaugeLinkToLieAlgebraField(const GaugeMat &U, GaugeMat &A)
Definition GaugeFix.h:44
static void DmuAmu(const std::vector< GaugeMat > &U, GaugeMat &dmuAmu, int orthog)
Definition GaugeFix.h:50
static Real SteepestDescentStep(std::vector< GaugeMat > &U, GaugeMat &xform, Real alpha, GaugeMat &dmuAmu, int orthog)
Definition GaugeFix.h:147
static void ExpiAlphaDmuAmu(const std::vector< GaugeMat > &U, GaugeMat &g, Real alpha, GaugeMat &dmuAmu, int orthog)
Definition GaugeFix.h:226
static void SteepestDescentGaugeFix(GaugeLorentz &Umu, Real alpha, int maxiter, Real Omega_tol, Real Phi_tol, bool Fourier=false, int orthog=-1, bool err_on_no_converge=true)
Definition GaugeFix.h:75
static void SteepestDescentGaugeFix(GaugeLorentz &Umu, GaugeMat &xform, Real alpha, int maxiter, Real Omega_tol, Real Phi_tol, bool Fourier=false, int orthog=-1, bool err_on_no_converge=true)
Definition GaugeFix.h:80
Gimpl::GaugeField GaugeLorentz
Definition GaugeFix.h:41
static void taExp(const LatticeMatrixType &x, LatticeMatrixType &ex)
Definition GaugeGroup.h:387
static void GaugeTransform(typename Gimpl::GaugeField &Umu, typename Gimpl::GaugeLinkField &g)
Definition GaugeGroup.h:555
const Coordinate & GlobalDimensions(void)
int64_t gSites(void) const
static RealD avgPlaquette(const GaugeLorentz &Umu)
static RealD linkTrace(const GaugeLorentz &Umu)
Definition Simd.h:194