Grid 0.7.0
Lattice_trace.h
Go to the documentation of this file.
1/*************************************************************************************
2
3 Grid physics library, www.github.com/paboyle/Grid
4
5 Source file: ./lib/lattice/Lattice_trace.h
6
7 Copyright (C) 2015
8
9Author: Peter Boyle <paboyle@ph.ed.ac.uk>
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License along
22 with this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25 See the full license in the file "LICENSE" in the top level distribution directory
26*************************************************************************************/
27/* END LEGAL */
28#ifndef GRID_LATTICE_TRACE_H
29#define GRID_LATTICE_TRACE_H
30
32// Tracing, transposing, peeking, poking
34
36
38// Trace
40/*
41template<class vobj>
42inline auto trace(const Lattice<vobj> &lhs) -> Lattice<decltype(trace(vobj()))>
43{
44 Lattice<decltype(trace(vobj()))> ret(lhs.Grid());
45 autoView(ret_v , ret, AcceleratorWrite);
46 autoView(lhs_v , lhs, AcceleratorRead);
47 accelerator_for( ss, lhs_v.size(), vobj::Nsimd(), {
48 coalescedWrite(ret_v[ss], trace(lhs_v(ss)));
49 });
50 return ret;
51};
52*/
53
55// Trace Index level dependent operation
57template<int Index,class vobj>
59{
60 Lattice<decltype(traceIndex<Index>(vobj()))> ret(lhs.Grid());
61 autoView( ret_v , ret, AcceleratorWrite);
62 autoView( lhs_v , lhs, AcceleratorRead);
63 accelerator_for( ss, lhs_v.size(), vobj::Nsimd(), {
64 coalescedWrite(ret_v[ss], traceIndex<Index>(lhs_v(ss)));
65 });
66 return ret;
67};
68
69template<int N, class Vec>
71{
72 GridBase *grid=Umu.Grid();
73 auto lvol = grid->lSites();
75 typedef typename Vec::scalar_type scalar;
76 autoView(Umu_v,Umu,CpuRead);
77 autoView(ret_v,ret,CpuWrite);
78 thread_for(site,lvol,{
79 Eigen::MatrixXcd EigenU = Eigen::MatrixXcd::Zero(N,N);
80 Coordinate lcoor;
81 grid->LocalIndexToLocalCoor(site, lcoor);
83 peekLocalSite(Us, Umu_v, lcoor);
84 for(int i=0;i<N;i++){
85 for(int j=0;j<N;j++){
86 scalar tmp= Us()()(i,j);
87 ComplexD ztmp(real(tmp),imag(tmp));
88 EigenU(i,j)=ztmp;
89 }}
90 ComplexD detD = EigenU.determinant();
91 typename Vec::scalar_type det(detD.real(),detD.imag());
92 pokeLocalSite(det,ret_v,lcoor);
93 });
94 return ret;
95}
96
97template<int N>
99{
100 GridBase *grid=Umu.Grid();
101 auto lvol = grid->lSites();
103
104 autoView(Umu_v,Umu,CpuRead);
105 autoView(ret_v,ret,CpuWrite);
106 thread_for(site,lvol,{
107 Eigen::MatrixXcd EigenU = Eigen::MatrixXcd::Zero(N,N);
108 Coordinate lcoor;
109 grid->LocalIndexToLocalCoor(site, lcoor);
112 peekLocalSite(Us, Umu_v, lcoor);
113 for(int i=0;i<N;i++){
114 for(int j=0;j<N;j++){
115 EigenU(i,j) = Us()()(i,j);
116 }}
117 Eigen::MatrixXcd EigenUinv = EigenU.inverse();
118 for(int i=0;i<N;i++){
119 for(int j=0;j<N;j++){
120 Ui()()(i,j) = EigenUinv(i,j);
121 }}
122 pokeLocalSite(Ui,ret_v,lcoor);
123 });
124 return ret;
125}
126
127
129#endif
130
#define accelerator_for(iterator, num, nsimd,...)
AcceleratorVector< int, MaxDims > Coordinate
Definition Coordinate.h:95
void peekLocalSite(sobj &s, const LatticeView< vobj > &l, Coordinate &site)
void pokeLocalSite(const sobj &s, LatticeView< vobj > &l, Coordinate &site)
Lattice< vobj > real(const Lattice< vobj > &lhs)
Lattice< vobj > imag(const Lattice< vobj > &lhs)
Lattice< iScalar< iScalar< iScalar< Vec > > > > Determinant(const Lattice< iScalar< iScalar< iMatrix< Vec, N > > > > &Umu)
Lattice< iScalar< iScalar< iMatrix< vComplexD, N > > > > Inverse(const Lattice< iScalar< iScalar< iMatrix< vComplexD, N > > > > &Umu)
auto TraceIndex(const Lattice< vobj > &lhs) -> Lattice< decltype(traceIndex< Index >(vobj()))>
#define autoView(l_v, l, mode)
@ AcceleratorRead
@ CpuRead
@ AcceleratorWrite
@ CpuWrite
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
std::complex< RealD > ComplexD
Definition Simd.h:79
#define thread_for(i, num,...)
Definition Threads.h:60
void LocalIndexToLocalCoor(int lidx, Coordinate &lcoor)
int lSites(void) const