Grid 0.7.0
CovariantCshift.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/utils/CovariantCshift.h
6
7 Copyright (C) 2015
8
9Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
10Author: paboyle <paboyle@ph.ed.ac.uk>
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License along
23 with this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25
26 See the full license in the file "LICENSE" in the top level distribution directory
27*************************************************************************************/
28/* END LEGAL */
29#ifndef QCD_UTILS_COVARIANT_CSHIFT_H
30#define QCD_UTILS_COVARIANT_CSHIFT_H
31
33
35// Low performance implementation of CovariantCshift API
37// Make these members of an Impl class for BC's.
38
39namespace PeriodicBC {
40 //Out(x) = Link(x)*field(x+mu)
41 template<class covariant,class gauge> Lattice<covariant> CovShiftForward(const Lattice<gauge> &Link,
42 int mu,
43 const Lattice<covariant> &field)
44 {
45 return Link*Cshift(field,mu,1);// moves towards negative mu
46 }
47 //Out(x) = Link^dag(x-mu)*field(x-mu)
48 template<class covariant,class gauge> Lattice<covariant> CovShiftBackward(const Lattice<gauge> &Link,
49 int mu,
50 const Lattice<covariant> &field)
51 {
52 Lattice<covariant> tmp(field.Grid());
53 tmp = adj(Link)*field;
54 return Cshift(tmp,mu,-1);// moves towards positive mu
55 }
56 //Out(x) = Link^dag(x-mu)
57 template<class gauge> Lattice<gauge>
59 {
60 return Cshift(adj(Link), mu, -1);
61 }
62 //Out(x) = Link(x)
63 template<class gauge> Lattice<gauge>
65 {
66 return Link;
67 }
68 //Link(x) = Link(x+mu)
69 template<class gauge> Lattice<gauge>
70 ShiftStaple(const Lattice<gauge> &Link, int mu)
71 {
72 return Cshift(Link, mu, 1);
73 }
74
75 template<class gauge,class Expr,typename std::enable_if<is_lattice_expr<Expr>::value,void>::type * = nullptr>
77 int mu,
78 const Expr &expr) -> decltype(closure(expr))
79 {
80 auto arg = closure(expr);
81 return CovShiftForward(Link,mu,arg);
82 }
83 template<class gauge,class Expr,typename std::enable_if<is_lattice_expr<Expr>::value,void>::type * = nullptr>
85 int mu,
86 const Expr &expr) -> decltype(closure(expr))
87 {
88 auto arg = closure(expr);
89 return CovShiftBackward(Link,mu,arg);
90 }
91
92 //Boundary-aware C-shift of gauge links / gauge transformation matrices
93 template<class gauge> Lattice<gauge>
94 CshiftLink(const Lattice<gauge> &Link, int mu, int shift)
95 {
96 return Cshift(Link, mu, shift);
97 }
98
99}
100
101
102namespace ConjugateBC {
103
104 // Must give right answers across boundary
105 // <----
106 // --
107 // | |
108 // xxxxxxxxxxxxxxxxxxxx
109 // | |
110 //
111 // Stap= Cshift(GImpl::CovShiftForward(U[nu],nu,
112 // GImpl::CovShiftForward(U[nu],nu,
113 // GImpl::CovShiftBackward(U[mu],mu,
114 // GImpl::CovShiftBackward(U[nu],nu,
115 // GImpl::CovShiftIdentityBackward(U[nu],nu,-1))))) , mu, 1);
116 //
117 // U U^* U^* U^T U^adj = U (U U U^dag U^T )^*
118 // = U (U U U^dag)^* ( U^T )^*
119 //
120 // So covariant shift rule: Conjugate inward shifted plane when crossing boundary applies.
121 //
122 // This Conjugate should be applied to BOTH the link and the covariant field on backward shift
123 // boundary wrap.
124 //
125 // | |
126 // xxxxxxxxxxxxxxxxx
127 // | | <---- this link is Conjugated, and the path leading into it. Segment crossing in and out is double Conjugated.
128 // --
129 // ------->
130 template<class covariant,class gauge> Lattice<covariant> CovShiftForward(const Lattice<gauge> &Link,
131 int mu,
132 const Lattice<covariant> &field)
133 {
134 GridBase * grid = Link.Grid();
135
136 int Lmu = grid->GlobalDimensions()[mu]-1;
137
138 conformable(field,Link);
139
140 Lattice<iScalar<vInteger> > coor(grid); LatticeCoordinate(coor,mu);
141
142 Lattice<covariant> field_bc = Cshift(field,mu,1);// moves towards negative mu;
143
144 field_bc = where(coor==Lmu,conjugate(field_bc),field_bc);
145 // std::cout<<"Gparity::CovCshiftForward mu="<<mu<<std::endl;
146 return Link*field_bc;
147 }
148
149 template<class covariant,class gauge> Lattice<covariant> CovShiftBackward(const Lattice<gauge> &Link,
150 int mu,
151 const Lattice<covariant> &field)
152 {
153 GridBase * grid = field.Grid();
154
155 int Lmu = grid->GlobalDimensions()[mu]-1;
156
157 conformable(field,Link);
158
159 Lattice<iScalar<vInteger> > coor(grid); LatticeCoordinate(coor,mu);
160
161 Lattice<covariant> tmp(grid);
162
163 tmp = adj(Link)*field;
164 tmp = where(coor==Lmu,conjugate(tmp),tmp);
165 // std::cout<<"Gparity::CovCshiftBackward mu="<<mu<<std::endl;
166 return Cshift(tmp,mu,-1);// moves towards positive mu
167 }
168
169 //Out(x) = U^dag_\mu(x-mu) | x_\mu != 0
170 // = U^T_\mu(L-1) | x_\mu == 0
171 template<class gauge> Lattice<gauge>
173 GridBase *grid = Link.Grid();
174 int Lmu = grid->GlobalDimensions()[mu] - 1;
175
176 Lattice<iScalar<vInteger>> coor(grid);
177 LatticeCoordinate(coor, mu);
178
179 Lattice<gauge> tmp(grid);
180 tmp = adj(Link);
181 tmp = where(coor == Lmu, conjugate(tmp), tmp);
182 return Cshift(tmp, mu, -1); // moves towards positive mu
183 }
184 template<class gauge> Lattice<gauge>
186 return Link;
187 }
188
189 //Out(x) = S_\mu(x+\hat\mu) | x_\mu != L-1
190 // = S*_\mu(0) | x_\mu == L-1
191 //Note: While this is used for Staples it is also applicable for shifting gauge links or gauge transformation matrices
192 template<class gauge> Lattice<gauge>
193 ShiftStaple(const Lattice<gauge> &Link, int mu)
194 {
195 GridBase *grid = Link.Grid();
196 int Lmu = grid->GlobalDimensions()[mu] - 1;
197
198 Lattice<iScalar<vInteger>> coor(grid);
199 LatticeCoordinate(coor, mu);
200
201 Lattice<gauge> tmp(grid);
202 tmp = Cshift(Link, mu, 1);
203 tmp = where(coor == Lmu, conjugate(tmp), tmp);
204 return tmp;
205 }
206
207 template<class gauge,class Expr,typename std::enable_if<is_lattice_expr<Expr>::value,void>::type * = nullptr>
209 int mu,
210 const Expr &expr) -> decltype(closure(expr))
211 {
212 auto arg = closure(expr);
213 return CovShiftForward(Link,mu,arg);
214 }
215 template<class gauge,class Expr,typename std::enable_if<is_lattice_expr<Expr>::value,void>::type * = nullptr>
217 int mu,
218 const Expr &expr) -> decltype(closure(expr))
219 {
220 auto arg = closure(expr);
221 return CovShiftBackward(Link,mu,arg);
222 }
223
224 //Boundary-aware C-shift of gauge links / gauge transformation matrices
225 //shift = 1
226 //Out(x) = U_\mu(x+\hat\mu) | x_\mu != L-1
227 // = U*_\mu(0) | x_\mu == L-1
228 //shift = -1
229 //Out(x) = U_\mu(x-mu) | x_\mu != 0
230 // = U*_\mu(L-1) | x_\mu == 0
231 //shift = 2
232 //Out(x) = U_\mu(x+2\hat\mu) | x_\mu < L-2
233 // = U*_\mu(1) | x_\mu == L-1
234 // = U*_\mu(0) | x_\mu == L-2
235 //shift = -2
236 //Out(x) = U_\mu(x-2mu) | x_\mu > 1
237 // = U*_\mu(L-2) | x_\mu == 0
238 // = U*_\mu(L-1) | x_\mu == 1
239 //etc
240 template<class gauge> Lattice<gauge>
241 CshiftLink(const Lattice<gauge> &Link, int mu, int shift)
242 {
243 GridBase *grid = Link.Grid();
244 int Lmu = grid->GlobalDimensions()[mu];
245 assert(abs(shift) < Lmu && "Invalid shift value");
246
247 Lattice<iScalar<vInteger>> coor(grid);
248 LatticeCoordinate(coor, mu);
249
250 Lattice<gauge> tmp(grid);
251 if(shift > 0){
252 tmp = Cshift(Link, mu, shift);
253 tmp = where(coor >= Lmu-shift, conjugate(tmp), tmp);
254 return tmp;
255 }else if(shift < 0){
256 tmp = Link;
257 tmp = where(coor >= Lmu+shift, conjugate(tmp), tmp);
258 return Cshift(tmp, mu, shift);
259 }
260
261 //shift == 0
262 return Link;
263 }
264
265}
266
267
269#endif
auto Cshift(const Expression &expr, int dim, int shift) -> decltype(closure(expr))
Definition Cshift.h:55
accelerator_inline Grid_simd< S, V > abs(const Grid_simd< S, V > &r)
auto closure(const LatticeUnaryExpression< Op, T1 > &expr) -> Lattice< typename std::remove_const< decltype(expr.op.func(vecEval(0, expr.arg1)))>::type >
Definition Lattice_ET.h:492
void conformable(const Lattice< obj1 > &lhs, const Lattice< obj2 > &rhs)
void LatticeCoordinate(Lattice< iobj > &l, int mu)
Lattice< vobj > conjugate(const Lattice< vobj > &lhs)
Lattice< vobj > adj(const Lattice< vobj > &lhs)
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
const Coordinate & GlobalDimensions(void)
GridBase * Grid(void) const
Lattice< gauge > CovShiftIdentityBackward(const Lattice< gauge > &Link, int mu)
Lattice< gauge > CshiftLink(const Lattice< gauge > &Link, int mu, int shift)
Lattice< covariant > CovShiftForward(const Lattice< gauge > &Link, int mu, const Lattice< covariant > &field)
Lattice< gauge > ShiftStaple(const Lattice< gauge > &Link, int mu)
Lattice< covariant > CovShiftBackward(const Lattice< gauge > &Link, int mu, const Lattice< covariant > &field)
Lattice< gauge > CovShiftIdentityForward(const Lattice< gauge > &Link, int mu)
Lattice< gauge > CovShiftIdentityForward(const Lattice< gauge > &Link, int mu)
Lattice< covariant > CovShiftForward(const Lattice< gauge > &Link, int mu, const Lattice< covariant > &field)
Lattice< gauge > ShiftStaple(const Lattice< gauge > &Link, int mu)
Lattice< gauge > CovShiftIdentityBackward(const Lattice< gauge > &Link, int mu)
Lattice< covariant > CovShiftBackward(const Lattice< gauge > &Link, int mu, const Lattice< covariant > &field)
Lattice< gauge > CshiftLink(const Lattice< gauge > &Link, int mu, int shift)