1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00:00

Vectors now too and right multiple of matrix with gamma

This commit is contained in:
Peter Boyle 2015-04-24 19:08:29 +01:00
parent f2ac20e7ab
commit 71d5927a66
3 changed files with 156 additions and 21 deletions

View File

@ -4,18 +4,21 @@ AM_CXXFLAGS = -I$(top_srcdir)/
extra_sources=
if BUILD_COMMS_MPI
extra_sources+=communicator/Grid_communicator_mpi.cc
extra_sources+=stencil/Grid_stencil_common.cc
endif
if BUILD_COMMS_NONE
extra_sources+=communicator/Grid_communicator_fake.cc
extra_sources+=stencil/Grid_stencil_common.cc
endif
#
# Libraries
#
lib_LIBRARIES = libGrid.a
libGrid_a_SOURCES = Grid_init.cc $(extra_sources)
libGrid_a_SOURCES =\
Grid_init.cc\
stencil/Grid_stencil_common.cc\
qcd/Grid_qcd_dirac.cc\
$(extra_sources)
#
# Include files
@ -32,7 +35,6 @@ include_HEADERS =\
Grid_math.h\
Grid_simd.h\
Grid_stencil.h\
Grid_summation.h\
Grid_where.h
nobase_include_HEADERS=\
@ -68,7 +70,8 @@ nobase_include_HEADERS=\
math/Grid_math_trace.h\
math/Grid_math_traits.h\
math/Grid_math_transpose.h\
qcd/Grid_QCD.h\
qcd/Grid_qcd.h\
qcd/Grid_qcd_dirac.h\
simd/Grid_vComplexD.h\
simd/Grid_vComplexF.h\
simd/Grid_vInteger.h\

View File

@ -44,12 +44,14 @@ namespace QCD {
// MinusSigmaYT,
// MinusSigmaZT
};
static GammaMatrix GammaMatrices[];
static const char *GammaMatrixNames[];
Gamma (GammaMatrix g) { _g=g; }
GammaMatrix _g;
};
@ -94,13 +96,13 @@ namespace QCD {
}
};
template<class vtype> inline void multGammaX(iVector<vtype,Ns> &ret, iVector<vtype,Ns> &rhs){
template<class vtype> inline void multGammaX(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
ret._internal[0] = timesI(rhs._internal[3]);
ret._internal[1] = timesI(rhs._internal[2]);
ret._internal[2] = timesMinusI(rhs._internal[1]);
ret._internal[3] = timesMinusI(rhs._internal[0]);
};
template<class vtype> inline void multMinusGammaX(iVector<vtype,Ns> &ret, iVector<vtype,Ns> &rhs){
template<class vtype> inline void multMinusGammaX(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
ret(0) = timesMinusI(rhs(3));
ret(1) = timesMinusI(rhs(2));
ret(2) = timesI(rhs(1));
@ -146,13 +148,13 @@ namespace QCD {
ret(3,i) = rhs(0,i);
}
};
template<class vtype> inline void multGammaY(iVector<vtype,Ns> &ret, iVector<vtype,Ns> &rhs){
template<class vtype> inline void multGammaY(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
ret(0) = -rhs(3);
ret(1) = rhs(2);
ret(2) = rhs(1);
ret(3) = -rhs(0);
};
template<class vtype> inline void multMinusGammaY(iVector<vtype,Ns> &ret, iVector<vtype,Ns> &rhs){
template<class vtype> inline void multMinusGammaY(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
ret(0) = rhs(3);
ret(1) = -rhs(2);
ret(2) = -rhs(1);
@ -196,13 +198,13 @@ namespace QCD {
ret(3,i) = timesMinusI(rhs(1,i));
}
};
template<class vtype> inline void multGammaZ(iVector<vtype,Ns> &ret, iVector<vtype,Ns> &rhs){
template<class vtype> inline void multGammaZ(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
ret(0) = timesI(rhs(2));
ret(1) =timesMinusI(rhs(3));
ret(2) =timesMinusI(rhs(0));
ret(3) = timesI(rhs(1));
};
template<class vtype> inline void multMinusGammaZ(iVector<vtype,Ns> &ret, iVector<vtype,Ns> &rhs){
template<class vtype> inline void multMinusGammaZ(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
ret(0) = timesMinusI(rhs(2));
ret(1) = timesI(rhs(3));
ret(2) = timesI(rhs(0));
@ -246,13 +248,13 @@ namespace QCD {
ret(3,i) =-rhs(1,i);
}
};
template<class vtype> inline void multGammaT(iVector<vtype,Ns> &ret, iVector<vtype,Ns> &rhs){
template<class vtype> inline void multGammaT(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
ret(0) = rhs(2);
ret(1) = rhs(3);
ret(2) = rhs(0);
ret(3) = rhs(1);
};
template<class vtype> inline void multMinusGammaT(iVector<vtype,Ns> &ret, iVector<vtype,Ns> &rhs){
template<class vtype> inline void multMinusGammaT(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
ret(0) =-rhs(2);
ret(1) =-rhs(3);
ret(2) =-rhs(0);
@ -298,13 +300,13 @@ namespace QCD {
}
};
template<class vtype> inline void multGamma5(iVector<vtype,Ns> &ret, iVector<vtype,Ns> &rhs){
template<class vtype> inline void multGamma5(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
ret(0) = rhs(0);
ret(1) = rhs(1);
ret(2) =-rhs(2);
ret(3) =-rhs(3);
};
template<class vtype> inline void multMinusGamma5(iVector<vtype,Ns> &ret, iVector<vtype,Ns> &rhs){
template<class vtype> inline void multMinusGamma5(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
ret(0) =-rhs(0);
ret(1) =-rhs(1);
ret(2) = rhs(2);
@ -313,6 +315,10 @@ namespace QCD {
#ifdef GRID_WARN_SUBOPTIMAL
#warning "Optimisation alert switch over to multGammaX early "
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////
// Operator * : first case this is not a spin index, so recurse
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -323,10 +329,8 @@ namespace QCD {
// note that doing so from the lattice operator will avoid copy back and case switch overhead, as
// was done for the tensor math operator to remove operator * notation early
//
#ifdef GRID_WARN_SUBOPTIMAL
#warning "Optimisation alert switch over to multGammaX early "
#endif
//left multiply
template<class vtype> inline auto operator * ( const Gamma &G,const iScalar<vtype> &arg) ->
typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,SpinIndex>::notvalue,iScalar<vtype> >::type
@ -349,6 +353,32 @@ namespace QCD {
ret._internal=G*arg._internal;
return ret;
}
//right multiply
template<class vtype> inline auto operator * (const iScalar<vtype> &arg, const Gamma &G) ->
typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,SpinIndex>::notvalue,iScalar<vtype> >::type
{
iScalar<vtype> ret;
ret._internal=arg._internal*G;
return ret;
}
template<class vtype,int N> inline auto operator * (const iVector<vtype,N> &arg, const Gamma &G) ->
typename std::enable_if<matchGridTensorIndex<iVector<vtype,N>,SpinIndex>::notvalue,iVector<vtype,N> >::type
{
iVector<vtype,N> ret;
ret._internal=arg._internal*G;
return ret;
}
template<class vtype,int N> inline auto operator * (const iMatrix<vtype,N> &arg, const Gamma &G) ->
typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,SpinIndex>::notvalue,iMatrix<vtype,N> >::type
{
iMatrix<vtype,N> ret;
ret._internal=arg._internal*G;
return ret;
}
////////////////////////////////////////////////////////
// When we hit the spin index this matches and we stop
////////////////////////////////////////////////////////
@ -399,6 +429,104 @@ namespace QCD {
}
return ret;
}
// Could have used type trait for Matrix/vector and then an enable if to share code
template<class vtype> inline auto operator * ( const Gamma &G,const iVector<vtype,Ns> &arg) ->
typename std::enable_if<matchGridTensorIndex<iVector<vtype,Ns>,SpinIndex>::value,iVector<vtype,Ns> >::type
{
iVector<vtype,Ns> ret;
switch (G._g) {
case Gamma::Identity:
ret = arg;
break;
case Gamma::MinusIdentity:
ret = -arg;
break;
case Gamma::GammaX:
multGammaX(ret,arg);
break;
case Gamma::MinusGammaX:
multMinusGammaX(ret,arg);
break;
case Gamma::GammaY:
multGammaY(ret,arg);
break;
case Gamma::MinusGammaY:
multMinusGammaY(ret,arg);
break;
case Gamma::GammaZ:
multGammaZ(ret,arg);
break;
case Gamma::MinusGammaZ:
multMinusGammaZ(ret,arg);
break;
case Gamma::GammaT:
multGammaT(ret,arg);
break;
case Gamma::MinusGammaT:
multMinusGammaT(ret,arg);
break;
case Gamma::Gamma5:
multGamma5(ret,arg);
break;
case Gamma::MinusGamma5:
multMinusGamma5(ret,arg);
break;
default:
assert(0);
break;
}
return ret;
}
template<class vtype> inline auto operator * (const iMatrix<vtype,Ns> &arg, const Gamma &G) ->
typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,Ns>,SpinIndex>::value,iMatrix<vtype,Ns> >::type
{
iMatrix<vtype,Ns> ret;
switch (G._g) {
case Gamma::Identity:
ret = arg;
break;
case Gamma::MinusIdentity:
ret = -arg;
break;
case Gamma::GammaX:
rmultGammaX(ret,arg);
break;
case Gamma::MinusGammaX:
rmultMinusGammaX(ret,arg);
break;
case Gamma::GammaY:
rmultGammaY(ret,arg);
break;
case Gamma::MinusGammaY:
rmultMinusGammaY(ret,arg);
break;
case Gamma::GammaZ:
rmultGammaZ(ret,arg);
break;
case Gamma::MinusGammaZ:
rmultMinusGammaZ(ret,arg);
break;
case Gamma::GammaT:
rmultGammaT(ret,arg);
break;
case Gamma::MinusGammaT:
rmultMinusGammaT(ret,arg);
break;
case Gamma::Gamma5:
rmultGamma5(ret,arg);
break;
case Gamma::MinusGamma5:
rmultMinusGamma5(ret,arg);
break;
default:
assert(0);
break;
}
return ret;
}
/* Output from test
./Grid_gamma
Identity((1,0),(0,0),(0,0),(0,0))

View File

@ -23,6 +23,9 @@ int main (int argc, char ** argv)
SpinMatrix rr=zero;
SpinMatrix result;
SpinVector lv=zero;
SpinVector rv=zero;
for(int a=0;a<Ns;a++){
ident()(a,a) = 1.0;
}
@ -56,8 +59,9 @@ int main (int argc, char ** argv)
"-Gamma5 ",
" "
};
// result == ll*Gamma(g[0])*rr;
// result == ll*Gamma(g[0]);
result =ll*Gamma(g[0])*rr;
result =ll*Gamma(g[0]);
rv = Gamma(g[0])*lv;
for(int mu=0;mu<12;mu++){