/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./lib/qcd/QCD.h Copyright (C) 2015 Author: Azusa Yamaguchi Author: Peter Boyle Author: Peter Boyle Author: neo Author: paboyle This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ #pragma once NAMESPACE_BEGIN(Grid); static constexpr int Xdir = 0; static constexpr int Ydir = 1; static constexpr int Zdir = 2; static constexpr int Tdir = 3; static constexpr int Xp = 0; static constexpr int Yp = 1; static constexpr int Zp = 2; static constexpr int Tp = 3; static constexpr int Xm = 4; static constexpr int Ym = 5; static constexpr int Zm = 6; static constexpr int Tm = 7; static constexpr int Nc=Config_Nc; static constexpr int Ns=4; static constexpr int Nd=4; static constexpr int Nhs=2; // half spinor static constexpr int Nds=8; // double stored gauge field static constexpr int Ngp=2; // gparity index range ////////////////////////////////////////////////////////////////////////////// // QCD iMatrix types // Index conventions: Lorentz x Spin x Colour // note: static constexpr int or constexpr will work for type deductions // with the intel compiler (up to version 17) ////////////////////////////////////////////////////////////////////////////// #define ColourIndex (2) #define SpinIndex (1) #define LorentzIndex (0) #define GparityFlavourIndex (0) // Also should make these a named enum type static constexpr int DaggerNo=0; static constexpr int DaggerYes=1; static constexpr int InverseNo=0; static constexpr int InverseYes=1; // Useful traits is this a spin index //typename std::enable_if,SpinorIndex>::value,iVector >::type *SFINAE; const int SpinorIndex = 2; template struct isSpinor { static constexpr bool value = (SpinorIndex==T::TensorLevel); }; template using IfSpinor = Invoke::value,int> > ; template using IfNotSpinor = Invoke::value,int> > ; const int CoarseIndex = 4; template struct isCoarsened { static constexpr bool value = (CoarseIndex<=T::TensorLevel); }; template using IfCoarsened = Invoke::value,int> > ; template using IfNotCoarsened = Invoke::value,int> > ; const int GparityFlavourTensorIndex = 3; //TensorLevel counts from the bottom! // ChrisK very keen to add extra space for Gparity doubling. // // Also add domain wall index, in a way where Wilson operator // naturally distributes across the 5th dimensions. // // That probably makes for GridRedBlack4dCartesian grid. // s,sp,c,spc,lc template using iSinglet = iScalar > >; template using iSpinMatrix = iScalar, Ns> >; template using iColourMatrix = iScalar > > ; template using iSpinColourMatrix = iScalar, Ns> >; template using iLorentzColourMatrix = iVector >, Nd > ; template using iLorentzComplex = iVector >, Nd > ; template using iDoubleStoredColourMatrix = iVector >, Nds > ; template using iSpinVector = iScalar, Ns> >; template using iColourVector = iScalar > >; template using iSpinColourVector = iScalar, Ns> >; template using iHalfSpinVector = iScalar, Nhs> >; template using iHalfSpinColourVector = iScalar, Nhs> >; template using iSpinColourSpinColourMatrix = iScalar, Ns>, Nc>, Ns> >; template using iGparityFlavourVector = iVector >, Ngp>; template using iGparitySpinColourVector = iVector, Ns>, Ngp >; template using iGparityHalfSpinColourVector = iVector, Nhs>, Ngp >; template using iGparityFlavourMatrix = iMatrix >, Ngp>; // Spin matrix typedef iSpinMatrix SpinMatrix; typedef iSpinMatrix SpinMatrixF; typedef iSpinMatrix SpinMatrixD; typedef iSpinMatrix vSpinMatrix; typedef iSpinMatrix vSpinMatrixF; typedef iSpinMatrix vSpinMatrixD; typedef iSpinMatrix vSpinMatrixD2; // Colour Matrix typedef iColourMatrix ColourMatrix; typedef iColourMatrix ColourMatrixF; typedef iColourMatrix ColourMatrixD; typedef iColourMatrix vColourMatrix; typedef iColourMatrix vColourMatrixF; typedef iColourMatrix vColourMatrixD; typedef iColourMatrix vColourMatrixD2; // SpinColour matrix typedef iSpinColourMatrix SpinColourMatrix; typedef iSpinColourMatrix SpinColourMatrixF; typedef iSpinColourMatrix SpinColourMatrixD; typedef iSpinColourMatrix vSpinColourMatrix; typedef iSpinColourMatrix vSpinColourMatrixF; typedef iSpinColourMatrix vSpinColourMatrixD; typedef iSpinColourMatrix vSpinColourMatrixD2; // SpinColourSpinColour matrix typedef iSpinColourSpinColourMatrix SpinColourSpinColourMatrix; typedef iSpinColourSpinColourMatrix SpinColourSpinColourMatrixF; typedef iSpinColourSpinColourMatrix SpinColourSpinColourMatrixD; typedef iSpinColourSpinColourMatrix vSpinColourSpinColourMatrix; typedef iSpinColourSpinColourMatrix vSpinColourSpinColourMatrixF; typedef iSpinColourSpinColourMatrix vSpinColourSpinColourMatrixD; typedef iSpinColourSpinColourMatrix vSpinColourSpinColourMatrixD2; // SpinColourSpinColour matrix typedef iSpinColourSpinColourMatrix SpinColourSpinColourMatrix; typedef iSpinColourSpinColourMatrix SpinColourSpinColourMatrixF; typedef iSpinColourSpinColourMatrix SpinColourSpinColourMatrixD; typedef iSpinColourSpinColourMatrix vSpinColourSpinColourMatrix; typedef iSpinColourSpinColourMatrix vSpinColourSpinColourMatrixF; typedef iSpinColourSpinColourMatrix vSpinColourSpinColourMatrixD; typedef iSpinColourSpinColourMatrix vSpinColourSpinColourMatrixD2; // LorentzColour typedef iLorentzColourMatrix LorentzColourMatrix; typedef iLorentzColourMatrix LorentzColourMatrixF; typedef iLorentzColourMatrix LorentzColourMatrixD; typedef iLorentzColourMatrix vLorentzColourMatrix; typedef iLorentzColourMatrix vLorentzColourMatrixF; typedef iLorentzColourMatrix vLorentzColourMatrixD; typedef iLorentzColourMatrix vLorentzColourMatrixD2; // LorentzComplex typedef iLorentzComplex LorentzComplex; typedef iLorentzComplex LorentzComplexF; typedef iLorentzComplex LorentzComplexD; typedef iLorentzComplex vLorentzComplex; typedef iLorentzComplex vLorentzComplexF; typedef iLorentzComplex vLorentzComplexD; // DoubleStored gauge field typedef iDoubleStoredColourMatrix DoubleStoredColourMatrix; typedef iDoubleStoredColourMatrix DoubleStoredColourMatrixF; typedef iDoubleStoredColourMatrix DoubleStoredColourMatrixD; typedef iDoubleStoredColourMatrix vDoubleStoredColourMatrix; typedef iDoubleStoredColourMatrix vDoubleStoredColourMatrixF; typedef iDoubleStoredColourMatrix vDoubleStoredColourMatrixD; typedef iDoubleStoredColourMatrix vDoubleStoredColourMatrixD2; //G-parity flavour matrix typedef iGparityFlavourMatrix GparityFlavourMatrix; typedef iGparityFlavourMatrix GparityFlavourMatrixF; typedef iGparityFlavourMatrix GparityFlavourMatrixD; typedef iGparityFlavourMatrix vGparityFlavourMatrix; typedef iGparityFlavourMatrix vGparityFlavourMatrixF; typedef iGparityFlavourMatrix vGparityFlavourMatrixD; typedef iGparityFlavourMatrix vGparityFlavourMatrixD2; // Spin vector typedef iSpinVector SpinVector; typedef iSpinVector SpinVectorF; typedef iSpinVector SpinVectorD; typedef iSpinVector vSpinVector; typedef iSpinVector vSpinVectorF; typedef iSpinVector vSpinVectorD; typedef iSpinVector vSpinVectorD2; // Colour vector typedef iColourVector ColourVector; typedef iColourVector ColourVectorF; typedef iColourVector ColourVectorD; typedef iColourVector vColourVector; typedef iColourVector vColourVectorF; typedef iColourVector vColourVectorD; typedef iColourVector vColourVectorD2; // SpinColourVector typedef iSpinColourVector SpinColourVector; typedef iSpinColourVector SpinColourVectorF; typedef iSpinColourVector SpinColourVectorD; typedef iSpinColourVector vSpinColourVector; typedef iSpinColourVector vSpinColourVectorF; typedef iSpinColourVector vSpinColourVectorD; typedef iSpinColourVector vSpinColourVectorD2; // HalfSpin vector typedef iHalfSpinVector HalfSpinVector; typedef iHalfSpinVector HalfSpinVectorF; typedef iHalfSpinVector HalfSpinVectorD; typedef iHalfSpinVector vHalfSpinVector; typedef iHalfSpinVector vHalfSpinVectorF; typedef iHalfSpinVector vHalfSpinVectorD; typedef iHalfSpinVector vHalfSpinVectorD2; // HalfSpinColour vector typedef iHalfSpinColourVector HalfSpinColourVector; typedef iHalfSpinColourVector HalfSpinColourVectorF; typedef iHalfSpinColourVector HalfSpinColourVectorD; typedef iHalfSpinColourVector vHalfSpinColourVector; typedef iHalfSpinColourVector vHalfSpinColourVectorF; typedef iHalfSpinColourVector vHalfSpinColourVectorD; typedef iHalfSpinColourVector vHalfSpinColourVectorD2; //G-parity flavour vector typedef iGparityFlavourVector GparityFlavourVector; typedef iGparityFlavourVector GparityFlavourVectorF; typedef iGparityFlavourVector GparityFlavourVectorD; typedef iGparityFlavourVector vGparityFlavourVector; typedef iGparityFlavourVector vGparityFlavourVectorF; typedef iGparityFlavourVector vGparityFlavourVectorD; typedef iGparityFlavourVector vGparityFlavourVectorD2; // singlets typedef iSinglet TComplex; // FIXME This is painful. Tensor singlet complex type. typedef iSinglet TComplexF; // FIXME This is painful. Tensor singlet complex type. typedef iSinglet TComplexD; // FIXME This is painful. Tensor singlet complex type. typedef iSinglet vTComplex ; // what if we don't know the tensor structure typedef iSinglet vTComplexF; // what if we don't know the tensor structure typedef iSinglet vTComplexD; // what if we don't know the tensor structure typedef iSinglet vTComplexD2; // what if we don't know the tensor structure typedef iSinglet TReal; // Shouldn't need these; can I make it work without? typedef iSinglet TRealF; // Shouldn't need these; can I make it work without? typedef iSinglet TRealD; // Shouldn't need these; can I make it work without? typedef iSinglet vTReal; typedef iSinglet vTRealF; typedef iSinglet vTRealD; typedef iSinglet vTInteger; typedef iSinglet TInteger; // Lattices of these typedef Lattice LatticeColourMatrix; typedef Lattice LatticeColourMatrixF; typedef Lattice LatticeColourMatrixD; typedef Lattice LatticeColourMatrixD2; typedef Lattice LatticeSpinMatrix; typedef Lattice LatticeSpinMatrixF; typedef Lattice LatticeSpinMatrixD; typedef Lattice LatticeSpinMatrixD2; typedef Lattice LatticeSpinColourMatrix; typedef Lattice LatticeSpinColourMatrixF; typedef Lattice LatticeSpinColourMatrixD; typedef Lattice LatticeSpinColourMatrixD2; typedef Lattice LatticeSpinColourSpinColourMatrix; typedef Lattice LatticeSpinColourSpinColourMatrixF; typedef Lattice LatticeSpinColourSpinColourMatrixD; typedef Lattice LatticeSpinColourSpinColourMatrixD2; typedef Lattice LatticeLorentzColourMatrix; typedef Lattice LatticeLorentzColourMatrixF; typedef Lattice LatticeLorentzColourMatrixD; typedef Lattice LatticeLorentzColourMatrixD2; typedef Lattice LatticeLorentzComplex; typedef Lattice LatticeLorentzComplexF; typedef Lattice LatticeLorentzComplexD; // DoubleStored gauge field typedef Lattice LatticeDoubleStoredColourMatrix; typedef Lattice LatticeDoubleStoredColourMatrixF; typedef Lattice LatticeDoubleStoredColourMatrixD; typedef Lattice LatticeDoubleStoredColourMatrixD2; typedef Lattice LatticeSpinVector; typedef Lattice LatticeSpinVectorF; typedef Lattice LatticeSpinVectorD; typedef Lattice LatticeSpinVectorD2; typedef Lattice LatticeColourVector; typedef Lattice LatticeColourVectorF; typedef Lattice LatticeColourVectorD; typedef Lattice LatticeColourVectorD2; typedef Lattice LatticeSpinColourVector; typedef Lattice LatticeSpinColourVectorF; typedef Lattice LatticeSpinColourVectorD; typedef Lattice LatticeSpinColourVectorD2; typedef Lattice LatticeHalfSpinVector; typedef Lattice LatticeHalfSpinVectorF; typedef Lattice LatticeHalfSpinVectorD; typedef Lattice LatticeHalfSpinVectorD2; typedef Lattice LatticeHalfSpinColourVector; typedef Lattice LatticeHalfSpinColourVectorF; typedef Lattice LatticeHalfSpinColourVectorD; typedef Lattice LatticeHalfSpinColourVectorD2; typedef Lattice LatticeReal; typedef Lattice LatticeRealF; typedef Lattice LatticeRealD; typedef Lattice LatticeComplex; typedef Lattice LatticeComplexF; typedef Lattice LatticeComplexD; typedef Lattice LatticeComplexD2; typedef Lattice LatticeInteger; // Predicates for "where" /////////////////////////////////////////// // Physical names for things /////////////////////////////////////////// typedef LatticeHalfSpinColourVector LatticeHalfFermion; typedef LatticeHalfSpinColourVectorF LatticeHalfFermionF; typedef LatticeHalfSpinColourVectorD LatticeHalfFermionD; typedef LatticeHalfSpinColourVectorD2 LatticeHalfFermionD2; typedef LatticeSpinColourVector LatticeFermion; typedef LatticeSpinColourVectorF LatticeFermionF; typedef LatticeSpinColourVectorD LatticeFermionD; typedef LatticeSpinColourVectorD2 LatticeFermionD2; typedef LatticeSpinColourMatrix LatticePropagator; typedef LatticeSpinColourMatrixF LatticePropagatorF; typedef LatticeSpinColourMatrixD LatticePropagatorD; typedef LatticeSpinColourMatrixD2 LatticePropagatorD2; typedef LatticeLorentzColourMatrix LatticeGaugeField; typedef LatticeLorentzColourMatrixF LatticeGaugeFieldF; typedef LatticeLorentzColourMatrixD LatticeGaugeFieldD; typedef LatticeLorentzColourMatrixD2 LatticeGaugeFieldD2; typedef LatticeDoubleStoredColourMatrix LatticeDoubledGaugeField; typedef LatticeDoubleStoredColourMatrixF LatticeDoubledGaugeFieldF; typedef LatticeDoubleStoredColourMatrixD LatticeDoubledGaugeFieldD; typedef LatticeDoubleStoredColourMatrixD2 LatticeDoubledGaugeFieldD2; template using LorentzScalar = Lattice >; typedef Lattice LatticeStaggeredFermion; typedef Lattice LatticeStaggeredFermionF; typedef Lattice LatticeStaggeredFermionD; typedef Lattice LatticeStaggeredFermionD2; typedef Lattice LatticeStaggeredPropagator; typedef Lattice LatticeStaggeredPropagatorF; typedef Lattice LatticeStaggeredPropagatorD; typedef Lattice LatticeStaggeredPropagatorD2; ////////////////////////////////////////////////////////////////////////////// // Peek and Poke named after physics attributes ////////////////////////////////////////////////////////////////////////////// //spin template auto peekSpin(const vobj &rhs,int i) -> decltype(PeekIndex(rhs,0)) { return PeekIndex(rhs,i); } template auto peekSpin(const vobj &rhs,int i,int j) -> decltype(PeekIndex(rhs,0,0)) { return PeekIndex(rhs,i,j); } template auto peekSpin(const Lattice &rhs,int i) -> decltype(PeekIndex(rhs,0)) { return PeekIndex(rhs,i); } template auto peekSpin(const Lattice &rhs,int i,int j) -> decltype(PeekIndex(rhs,0,0)) { return PeekIndex(rhs,i,j); } //colour template auto peekColour(const vobj &rhs,int i) -> decltype(PeekIndex(rhs,0)) { return PeekIndex(rhs,i); } template auto peekColour(const vobj &rhs,int i,int j) -> decltype(PeekIndex(rhs,0,0)) { return PeekIndex(rhs,i,j); } template auto peekColour(const Lattice &rhs,int i) -> decltype(PeekIndex(rhs,0)) { return PeekIndex(rhs,i); } template auto peekColour(const Lattice &rhs,int i,int j) -> decltype(PeekIndex(rhs,0,0)) { return PeekIndex(rhs,i,j); } //lorentz template auto peekLorentz(const vobj &rhs,int i) -> decltype(PeekIndex(rhs,0)) { return PeekIndex(rhs,i); } template auto peekLorentz(const Lattice &rhs,int i) -> decltype(PeekIndex(rhs,0)) { return PeekIndex(rhs,i); } ////////////////////////////////////////////// // Poke lattice ////////////////////////////////////////////// template void pokeColour(Lattice &lhs, const Lattice(vobj(),0))> & rhs, int i) { PokeIndex(lhs,rhs,i); } template void pokeColour(Lattice &lhs, const Lattice(vobj(),0,0))> & rhs, int i,int j) { PokeIndex(lhs,rhs,i,j); } template void pokeSpin(Lattice &lhs, const Lattice(vobj(),0))> & rhs, int i) { PokeIndex(lhs,rhs,i); } template void pokeSpin(Lattice &lhs, const Lattice(vobj(),0,0))> & rhs, int i,int j) { PokeIndex(lhs,rhs,i,j); } template void pokeLorentz(Lattice &lhs, const Lattice(vobj(),0))> & rhs, int i) { PokeIndex(lhs,rhs,i); } ////////////////////////////////////////////// // Poke scalars ////////////////////////////////////////////// template void pokeSpin(vobj &lhs,const decltype(peekIndex(lhs,0)) & rhs,int i) { pokeIndex(lhs,rhs,i); } template void pokeSpin(vobj &lhs,const decltype(peekIndex(lhs,0,0)) & rhs,int i,int j) { pokeIndex(lhs,rhs,i,j); } template void pokeColour(vobj &lhs,const decltype(peekIndex(lhs,0)) & rhs,int i) { pokeIndex(lhs,rhs,i); } template void pokeColour(vobj &lhs,const decltype(peekIndex(lhs,0,0)) & rhs,int i,int j) { pokeIndex(lhs,rhs,i,j); } template void pokeLorentz(vobj &lhs,const decltype(peekIndex(lhs,0)) & rhs,int i) { pokeIndex(lhs,rhs,i); } ////////////////////////////////////////////// // Fermion <-> propagator assignements ////////////////////////////////////////////// //template #define FAST_FERM_TO_PROP template void FermToProp(typename Fimpl::PropagatorField &p, const typename Fimpl::FermionField &f, const int s, const int c) { #ifdef FAST_FERM_TO_PROP autoView(p_v,p,CpuWrite); autoView(f_v,f,CpuRead); thread_for(idx,p_v.oSites(),{ for(int ss = 0; ss < Ns; ++ss) { for(int cc = 0; cc < Fimpl::Dimension; ++cc) { p_v[idx]()(ss,s)(cc,c) = f_v[idx]()(ss)(cc); // Propagator sink index is LEFT, suitable for left mult by gauge link (e.g.) }} }); #else for(int j = 0; j < Ns; ++j) { auto pjs = peekSpin(p, j, s); auto fj = peekSpin(f, j); for(int i = 0; i < Fimpl::Dimension; ++i) { pokeColour(pjs, peekColour(fj, i), i, c); } pokeSpin(p, pjs, j, s); } #endif } //template template void PropToFerm(typename Fimpl::FermionField &f, const typename Fimpl::PropagatorField &p, const int s, const int c) { #ifdef FAST_FERM_TO_PROP autoView(p_v,p,CpuRead); autoView(f_v,f,CpuWrite); thread_for(idx,p_v.oSites(),{ for(int ss = 0; ss < Ns; ++ss) { for(int cc = 0; cc < Fimpl::Dimension; ++cc) { f_v[idx]()(ss)(cc) = p_v[idx]()(ss,s)(cc,c); // LEFT index is copied across for s,c right index }} }); #else for(int j = 0; j < Ns; ++j) { auto pjs = peekSpin(p, j, s); auto fj = peekSpin(f, j); for(int i = 0; i < Fimpl::Dimension; ++i) { pokeColour(fj, peekColour(pjs, i, c), i); } pokeSpin(f, fj, j); } #endif } ////////////////////////////////////////////// // transpose array and scalar ////////////////////////////////////////////// template inline Lattice transposeSpin(const Lattice &lhs){ return transposeIndex(lhs); } template inline Lattice transposeColour(const Lattice &lhs){ return transposeIndex(lhs); } template inline vobj transposeSpin(const vobj &lhs){ return transposeIndex(lhs); } template inline vobj transposeColour(const vobj &lhs){ return transposeIndex(lhs); } ////////////////////////////////////////// // Trace lattice and non-lattice ////////////////////////////////////////// template inline auto traceSpin(const Lattice &lhs) -> Lattice(vobj()))> { return traceIndex(lhs); } template inline auto traceColour(const Lattice &lhs) -> Lattice(vobj()))> { return traceIndex(lhs); } template inline auto traceSpin(const vobj &lhs) -> Lattice(lhs))> { return traceIndex(lhs); } template inline auto traceColour(const vobj &lhs) -> Lattice(lhs))> { return traceIndex(lhs); } ////////////////////////////////////////// // Current types ////////////////////////////////////////// GRID_SERIALIZABLE_ENUM(Current, undef, Vector, 0, Axial, 1, Tadpole, 2); NAMESPACE_END(Grid);