Grid 0.7.0
Tensor_Ta.h
Go to the documentation of this file.
1/*************************************************************************************
2
3 Grid physics library, www.github.com/paboyle/Grid
4
5 Source file: ./lib/tensors/Tensor_Ta.h
6
7 Copyright (C) 2015
8
9Author: Peter Boyle <paboyle@ph.ed.ac.uk>
10Author: neo <cossu@post.kek.jp>
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 GRID_MATH_TA_H
30#define GRID_MATH_TA_H
31
32
34
36// Ta function for scalar, vector, matrix
38/*
39 accelerator_inline ComplexF Ta( const ComplexF &arg){ return arg;}
40 accelerator_inline ComplexD Ta( const ComplexD &arg){ return arg;}
41 accelerator_inline RealF Ta( const RealF &arg){ return arg;}
42 accelerator_inline RealD Ta( const RealD &arg){ return arg;}
43*/
44
45template<class vtype> accelerator_inline iScalar<vtype> Ta(const iScalar<vtype>&r)
46{
48 ret._internal = Ta(r._internal);
49 return ret;
50}
51template<class vtype,int N> accelerator_inline iVector<vtype,N> Ta(const iVector<vtype,N>&r)
52{
54 for(int i=0;i<N;i++){
55 ret._internal[i] = Ta(r._internal[i]);
56 }
57 return ret;
58}
59template<class vtype,int N> accelerator_inline iMatrix<vtype,N> Ta(const iMatrix<vtype,N> &arg)
60{
62
63 double factor = (1.0/(double)N);
64 ret= (arg - adj(arg))*0.5;
65 ret=ret - (trace(ret)*factor);
66 return ret;
67}
68
70{
72 ret._internal = SpTa(r._internal);
73 return ret;
74}
75template<class vtype,int N> accelerator_inline iVector<vtype,N> SpTa(const iVector<vtype,N>&r)
76{
78 for(int i=0;i<N;i++){
79 ret._internal[i] = SpTa(r._internal[i]);
80 }
81 return ret;
82}
83template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
85{
86 // Generalises Ta to Sp2n
87 // Applies the following projections
88 // P_{antihermitian} P_{antihermitian-Sp-algebra} P_{traceless}
89 // where the ordering matters
90 // P_{traceless} subtracts the trace
91 // P_{antihermitian-Sp-algebra} provides the block structure of the algebra based on U = exp(T) i.e. anti-hermitian generators
92 // P_{antihermitian} does in-adj(in) / 2
93 iMatrix<vtype,N> ret(arg);
94 double factor = (1.0/(double)N);
95 vtype nrm;
96 nrm = 0.5;
97
98 ret = arg - (trace(arg)*factor);
99
100 for(int c1=0;c1<N/2;c1++)
101 {
102 for(int c2=0;c2<N/2;c2++)
103 {
104 ret._internal[c1][c2] = nrm*(conjugate(ret._internal[c1+N/2][c2+N/2]) + ret._internal[c1][c2]); // new[up-left] = old[up-left]+old*[down-right]
105 ret._internal[c1][c2+N/2] = nrm*(ret._internal[c1][c2+N/2] - conjugate(ret._internal[c1+N/2][c2])); // new[up-right] = old[up-right]-old*[down-left]
106 }
107 for(int c2=N/2;c2<N;c2++)
108 {
109 ret._internal[c1+N/2][c2-N/2] = -conjugate(ret._internal[c1][c2]); // reconstructs lower blocks
110 ret._internal[c1+N/2][c2] = conjugate(ret._internal[c1][c2-N/2]); // from upper blocks
111 }
112 }
113
114 ret = (ret - adj(ret))*0.5;
115
116 return ret;
117}
118
120// ProjectOnGroup function for scalar, vector, matrix
121// Projects on orthogonal, unitary group
123
125{
126 iScalar<vtype> ret;
128 return ret;
129}
131{
133 for(int i=0;i<N;i++){
134 ret._internal[i] = ProjectOnGroup(r._internal[i]);
135 }
136 return ret;
137}
138template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
140{
141 typedef typename iMatrix<vtype,N>::scalar_type scalar;
142 // need a check for the group type?
143 iMatrix<vtype,N> ret(arg);
144 vtype nrm;
145 vtype inner;
146 scalar one(1.0);
147 for(int c1=0;c1<N;c1++){
148
149 // Normalises row c1
150 zeroit(inner);
151 for(int c2=0;c2<N;c2++)
152 inner += innerProduct(ret._internal[c1][c2],ret._internal[c1][c2]);
153
154 nrm = sqrt(inner);
155 nrm = one/nrm;
156 for(int c2=0;c2<N;c2++)
157 ret._internal[c1][c2]*= nrm;
158
159 // Remove c1 from rows c1+1...N-1
160 for (int b=c1+1; b<N; ++b){
161 decltype(ret._internal[b][b]*ret._internal[b][b]) pr;
162 zeroit(pr);
163 for(int c=0; c<N; ++c)
164 pr += conjugate(ret._internal[c1][c])*ret._internal[b][c];
165
166 for(int c=0; c<N; ++c){
167 ret._internal[b][c] -= pr * ret._internal[c1][c];
168 }
169 }
170 }
171
172 // Normalise last row
173 {
174 int c1 = N-1;
175 zeroit(inner);
176 for(int c2=0;c2<N;c2++)
177 inner += innerProduct(ret._internal[c1][c2],ret._internal[c1][c2]);
178
179 nrm = sqrt(inner);
180 nrm = one/nrm;
181 for(int c2=0;c2<N;c2++)
182 ret._internal[c1][c2]*= nrm;
183 }
184 // assuming the determinant is ok
185 return ret;
186}
187
188// re-do for sp2n
189
190// Ta cannot be defined here for Sp2n because I need the generators from the Sp class
191// It is defined in gauge impl types
192
194{
195 iScalar<vtype> ret;
197 return ret;
198}
200{
202 for(int i=0;i<N;i++){
203 ret._internal[i] = ProjectOnSpGroup(r._internal[i]);
204 }
205 return ret;
206}
207
208
209// int N is 2n in Sp(2n)
210template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
212{
213 // need a check for the group type?
214 iMatrix<vtype,N> ret(arg);
215 vtype nrm;
216 vtype inner;
217
218 for(int c1=0;c1<N/2;c1++)
219 {
220
221 for (int b=0; b<c1; b++) // remove the b-rows from U_c1
222 {
223 decltype(ret._internal[b][b]*ret._internal[b][b]) pr;
224 decltype(ret._internal[b][b]*ret._internal[b][b]) prn;
225 zeroit(pr);
226 zeroit(prn);
227
228 for(int c=0; c<N; c++)
229 {
230 pr += conjugate(ret._internal[c1][c])*ret._internal[b][c]; // <U_c1 | U_b >
231 prn += conjugate(ret._internal[c1][c])*ret._internal[b+N/2][c]; // <U_c1 | U_{b+N} >
232 }
233
234
235 for(int c=0; c<N; c++)
236 {
237 ret._internal[c1][c] -= (conjugate(pr) * ret._internal[b][c] + conjugate(prn) * ret._internal[b+N/2][c] ); // U_c1 -= ( <U_c1 | U_b > U_b + <U_c1 | U_{b+N} > U_{b+N} )
238 }
239 }
240
241 zeroit(inner);
242 for(int c2=0;c2<N;c2++)
243 {
244 inner += innerProduct(ret._internal[c1][c2],ret._internal[c1][c2]);
245 }
246
247 nrm = sqrt(inner);
248 nrm = 1.0/nrm;
249 for(int c2=0;c2<N;c2++)
250 {
251 ret._internal[c1][c2]*= nrm;
252 }
253
254 for(int c2=0;c2<N/2;c2++)
255 {
256 ret._internal[c1+N/2][c2+N/2] = conjugate(ret._internal[c1][c2]); // down right in the new matrix = (up-left)* of the old matrix
257 }
258
259 for(int c2=N/2;c2<N;c2++)
260 {
261 ret._internal[c1+N/2][c2-N/2] = -conjugate(ret._internal[c1][c2]);; // down left in the new matrix = -(up-right)* of the old
262 }
263 }
264 return ret;
265}
266
268
269#endif
#define accelerator_inline
#define one
Definition BGQQPX.h:108
accelerator_inline void zeroit(Grid_simd2< S, V > &z)
accelerator_inline Grid_simd2< S, V > trace(const Grid_simd2< S, V > &arg)
accelerator_inline Grid_simd< S, V > sqrt(const Grid_simd< S, V > &r)
Lattice< vobj > conjugate(const Lattice< vobj > &lhs)
Lattice< vobj > adj(const Lattice< vobj > &lhs)
ComplexD innerProduct(const Lattice< vobj > &left, const Lattice< vobj > &right)
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
accelerator_inline iScalar< vtype > ProjectOnSpGroup(const iScalar< vtype > &r)
Definition Tensor_Ta.h:193
accelerator_inline iScalar< vtype > SpTa(const iScalar< vtype > &r)
Definition Tensor_Ta.h:69
accelerator_inline iScalar< vtype > ProjectOnGroup(const iScalar< vtype > &r)
Definition Tensor_Ta.h:124
accelerator_inline iScalar< vtype > Ta(const iScalar< vtype > &r)
Definition Tensor_Ta.h:45
vtype _internal[N][N]
vtype _internal
vtype _internal[N]