/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./lib/qcd/action/fermion/WilsonFermion5D.cc Copyright (C) 2015 Author: Azusa Yamaguchi Author: Peter Boyle Author: Peter Boyle Author: Peter Boyle Author: paboyle Author: Guido Cossu Author: Andrew Lawson Author: Vera Guelpers 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 */ #include #include #include NAMESPACE_BEGIN(Grid); // 5d lattice for DWF. template WilsonFermion5D::WilsonFermion5D(GaugeField &_Umu, GridCartesian &FiveDimGrid, GridRedBlackCartesian &FiveDimRedBlackGrid, GridCartesian &FourDimGrid, GridRedBlackCartesian &FourDimRedBlackGrid, RealD _M5,const ImplParams &p) : Kernels(p), _FiveDimGrid (&FiveDimGrid), _FiveDimRedBlackGrid(&FiveDimRedBlackGrid), _FourDimGrid (&FourDimGrid), _FourDimRedBlackGrid(&FourDimRedBlackGrid), Stencil (_FiveDimGrid,npoint,Even,directions,displacements,p), StencilEven(_FiveDimRedBlackGrid,npoint,Even,directions,displacements,p), // source is Even StencilOdd (_FiveDimRedBlackGrid,npoint,Odd ,directions,displacements,p), // source is Odd M5(_M5), Umu(_FourDimGrid), UmuEven(_FourDimRedBlackGrid), UmuOdd (_FourDimRedBlackGrid), Lebesgue(_FourDimGrid), LebesgueEvenOdd(_FourDimRedBlackGrid), _tmp(&FiveDimRedBlackGrid), Dirichlet(0) { Stencil.lo = &Lebesgue; StencilEven.lo = &LebesgueEvenOdd; StencilOdd.lo = &LebesgueEvenOdd; // some assertions assert(FiveDimGrid._ndimension==5); assert(FourDimGrid._ndimension==4); assert(FourDimRedBlackGrid._ndimension==4); assert(FiveDimRedBlackGrid._ndimension==5); assert(FiveDimRedBlackGrid._checker_dim==1); // Don't checker the s direction // extent of fifth dim and not spread out Ls=FiveDimGrid._fdimensions[0]; assert(FiveDimRedBlackGrid._fdimensions[0]==Ls); assert(FiveDimGrid._processors[0] ==1); assert(FiveDimRedBlackGrid._processors[0] ==1); // Other dimensions must match the decomposition of the four-D fields for(int d=0;d<4;d++){ assert(FiveDimGrid._processors[d+1] ==FourDimGrid._processors[d]); assert(FiveDimRedBlackGrid._processors[d+1] ==FourDimGrid._processors[d]); assert(FourDimRedBlackGrid._processors[d] ==FourDimGrid._processors[d]); assert(FiveDimGrid._fdimensions[d+1] ==FourDimGrid._fdimensions[d]); assert(FiveDimRedBlackGrid._fdimensions[d+1]==FourDimGrid._fdimensions[d]); assert(FourDimRedBlackGrid._fdimensions[d] ==FourDimGrid._fdimensions[d]); assert(FiveDimGrid._simd_layout[d+1] ==FourDimGrid._simd_layout[d]); assert(FiveDimRedBlackGrid._simd_layout[d+1]==FourDimGrid._simd_layout[d]); assert(FourDimRedBlackGrid._simd_layout[d] ==FourDimGrid._simd_layout[d]); } if ( p.dirichlet.size() == Nd+1) { Coordinate block = p.dirichlet; if ( block[0] || block[1] || block[2] || block[3] || block[4] ){ Dirichlet = 1; std::cout << GridLogMessage << " WilsonFermion: non-trivial Dirichlet condition "<< block << std::endl; std::cout << GridLogMessage << " WilsonFermion: partial Dirichlet "<< p.partialDirichlet << std::endl; Block = block; } } else { Coordinate block(Nd+1,0); Block = block; } if (Impl::LsVectorised) { int nsimd = Simd::Nsimd(); // Dimension zero of the five-d is the Ls direction assert(FiveDimGrid._simd_layout[0] ==nsimd); assert(FiveDimRedBlackGrid._simd_layout[0]==nsimd); for(int d=0;d<4;d++){ assert(FourDimGrid._simd_layout[d]==1); assert(FourDimRedBlackGrid._simd_layout[d]==1); assert(FiveDimRedBlackGrid._simd_layout[d+1]==1); } } else { // Dimension zero of the five-d is the Ls direction assert(FiveDimRedBlackGrid._simd_layout[0]==1); assert(FiveDimGrid._simd_layout[0] ==1); } // Allocate the required comms buffer ImportGauge(_Umu); // Build lists of exterior only nodes int LLs = FiveDimGrid._rdimensions[0]; int vol4; vol4=FourDimGrid.oSites(); Stencil.BuildSurfaceList(LLs,vol4); vol4=FourDimRedBlackGrid.oSites(); StencilEven.BuildSurfaceList(LLs,vol4); StencilOdd.BuildSurfaceList(LLs,vol4); } template void WilsonFermion5D::ImportGauge(const GaugeField &_Umu) { GaugeField HUmu(_Umu.Grid()); HUmu = _Umu*(-0.5); if ( Dirichlet ) { if ( this->Params.partialDirichlet ) { std::cout << GridLogMessage << " partialDirichlet BCs " <LocalDimensions()[d]; if (GaugeBlock) assert( (GaugeBlock%ldim)==0); } if (!this->Params.partialDirichlet) { std::cout << GridLogMessage << " Dirichlet filtering gauge field BCs block " < Filter(GaugeBlock); Filter.applyFilter(HUmu); } else { std::cout << GridLogMessage << " Dirichlet "<< Dirichlet << " NOT filtered gauge field" < void WilsonFermion5D::DhopDir(const FermionField &in, FermionField &out,int dir5,int disp) { int dir = dir5-1; // Maps to the ordering above in "directions" that is passed to stencil // we drop off the innermost fifth dimension // assert( (disp==1)||(disp==-1) ); // assert( (dir>=0)&&(dir<4) ); //must do x,y,z or t; int skip = (disp==1) ? 0 : 1; int dirdisp = dir+skip*4; int gamma = dir+(1-skip)*4; Compressor compressor(DaggerNo); Stencil.HaloExchange(in,compressor); uint64_t Nsite = Umu.Grid()->oSites(); Kernels::DhopDirKernel(Stencil,Umu,Stencil.CommBuf(),Ls,Nsite,in,out,dirdisp,gamma); }; template void WilsonFermion5D::DhopDirAll(const FermionField &in, std::vector &out) { Compressor compressor(DaggerNo); Stencil.HaloExchange(in,compressor); uint64_t Nsite = Umu.Grid()->oSites(); Kernels::DhopDirAll(Stencil,Umu,Stencil.CommBuf(),Ls,Nsite,in,out); }; template void WilsonFermion5D::DerivInternal(StencilImpl & st, DoubledGaugeField & U, GaugeField &mat, const FermionField &A, const FermionField &B, int dag) { assert((dag==DaggerNo) ||(dag==DaggerYes)); conformable(st.Grid(),A.Grid()); conformable(st.Grid(),B.Grid()); Compressor compressor(dag); FermionField Btilde(B.Grid()); FermionField Atilde(B.Grid()); st.HaloExchange(B,compressor); Atilde=A; int LLs = B.Grid()->_rdimensions[0]; for (int mu = 0; mu < Nd; mu++) { //////////////////////////////////////////////////////////////////////// // Flip gamma if dag //////////////////////////////////////////////////////////////////////// int gamma = mu; if (!dag) gamma += Nd; //////////////////////// // Call the single hop //////////////////////// int Usites = U.Grid()->oSites(); Kernels::DhopDirKernel(st, U, st.CommBuf(), Ls, Usites, B, Btilde, mu,gamma); //////////////////////////// // spin trace outer product //////////////////////////// Impl::InsertForce5D(mat, Btilde, Atilde, mu); } } template void WilsonFermion5D::DhopDeriv(GaugeField &mat, const FermionField &A, const FermionField &B, int dag) { conformable(A.Grid(),FermionGrid()); conformable(A.Grid(),B.Grid()); //conformable(GaugeGrid(),mat.Grid());// this is not general! leaving as a comment mat.Checkerboard() = A.Checkerboard(); // mat.checkerboard = A.checkerboard; DerivInternal(Stencil,Umu,mat,A,B,dag); } template void WilsonFermion5D::DhopDerivEO(GaugeField &mat, const FermionField &A, const FermionField &B, int dag) { conformable(A.Grid(),FermionRedBlackGrid()); conformable(A.Grid(),B.Grid()); assert(B.Checkerboard()==Odd); assert(A.Checkerboard()==Even); mat.Checkerboard() = Even; DerivInternal(StencilOdd,UmuEven,mat,A,B,dag); } template void WilsonFermion5D::DhopDerivOE(GaugeField &mat, const FermionField &A, const FermionField &B, int dag) { conformable(A.Grid(),FermionRedBlackGrid()); conformable(A.Grid(),B.Grid()); assert(B.Checkerboard()==Even); assert(A.Checkerboard()==Odd); mat.Checkerboard() = Odd; DerivInternal(StencilEven,UmuOdd,mat,A,B,dag); } template void WilsonFermion5D::DhopInternal(StencilImpl & st, LebesgueOrder &lo, DoubledGaugeField & U, const FermionField &in, FermionField &out,int dag) { if ( WilsonKernelsStatic::Comms == WilsonKernelsStatic::CommsAndCompute ) DhopInternalOverlappedComms(st,lo,U,in,out,dag); else DhopInternalSerialComms(st,lo,U,in,out,dag); } template void WilsonFermion5D::DhopInternalOverlappedComms(StencilImpl & st, LebesgueOrder &lo, DoubledGaugeField & U, const FermionField &in, FermionField &out,int dag) { GRID_TRACE("DhopInternalOverlappedComms"); Compressor compressor(dag); int LLs = in.Grid()->_rdimensions[0]; int len = U.Grid()->oSites(); ///////////////////////////// // Start comms // Gather intranode and extra node differentiated?? ///////////////////////////// { GRID_TRACE("Gather"); st.HaloExchangeOptGather(in,compressor); // Put the barrier in the routine } std::vector > requests; auto id=traceStart("Communicate overlapped"); st.CommunicateBegin(requests); ///////////////////////////// // Overlap with comms ///////////////////////////// { GRID_TRACE("MergeSHM"); st.CommsMergeSHM(compressor);// Could do this inside parallel region overlapped with comms } ///////////////////////////// // do the compute interior ///////////////////////////// int Opt = WilsonKernelsStatic::Opt; // Why pass this. Kernels should know if (dag == DaggerYes) { GRID_TRACE("DhopDagInterior"); Kernels::DhopDagKernel(Opt,st,U,st.CommBuf(),LLs,U.oSites(),in,out,1,0); } else { GRID_TRACE("DhopInterior"); Kernels::DhopKernel (Opt,st,U,st.CommBuf(),LLs,U.oSites(),in,out,1,0); } ///////////////////////////// // Complete comms ///////////////////////////// st.CommunicateComplete(requests); traceStop(id); ///////////////////////////// // do the compute exterior ///////////////////////////// { GRID_TRACE("Merge"); st.CommsMerge(compressor); } if (dag == DaggerYes) { GRID_TRACE("DhopDagExterior"); Kernels::DhopDagKernel(Opt,st,U,st.CommBuf(),LLs,U.oSites(),in,out,0,1); } else { GRID_TRACE("DhopExterior"); Kernels::DhopKernel (Opt,st,U,st.CommBuf(),LLs,U.oSites(),in,out,0,1); } } template void WilsonFermion5D::DhopInternalSerialComms(StencilImpl & st, LebesgueOrder &lo, DoubledGaugeField & U, const FermionField &in, FermionField &out,int dag) { GRID_TRACE("DhopInternalSerialComms"); Compressor compressor(dag); int LLs = in.Grid()->_rdimensions[0]; { GRID_TRACE("HaloExchange"); st.HaloExchangeOpt(in,compressor); } int Opt = WilsonKernelsStatic::Opt; if (dag == DaggerYes) { GRID_TRACE("DhopDag"); Kernels::DhopDagKernel(Opt,st,U,st.CommBuf(),LLs,U.oSites(),in,out); } else { GRID_TRACE("Dhop"); Kernels::DhopKernel(Opt,st,U,st.CommBuf(),LLs,U.oSites(),in,out); } } template void WilsonFermion5D::DhopOE(const FermionField &in, FermionField &out,int dag) { conformable(in.Grid(),FermionRedBlackGrid()); // verifies half grid conformable(in.Grid(),out.Grid()); // drops the cb check assert(in.Checkerboard()==Even); out.Checkerboard() = Odd; DhopInternal(StencilEven,LebesgueEvenOdd,UmuOdd,in,out,dag); } template void WilsonFermion5D::DhopEO(const FermionField &in, FermionField &out,int dag) { conformable(in.Grid(),FermionRedBlackGrid()); // verifies half grid conformable(in.Grid(),out.Grid()); // drops the cb check assert(in.Checkerboard()==Odd); out.Checkerboard() = Even; DhopInternal(StencilOdd,LebesgueEvenOdd,UmuEven,in,out,dag); } template void WilsonFermion5D::Dhop(const FermionField &in, FermionField &out,int dag) { conformable(in.Grid(),FermionGrid()); // verifies full grid conformable(in.Grid(),out.Grid()); out.Checkerboard() = in.Checkerboard(); DhopInternal(Stencil,Lebesgue,Umu,in,out,dag); } template void WilsonFermion5D::DW(const FermionField &in, FermionField &out,int dag) { out.Checkerboard()=in.Checkerboard(); Dhop(in,out,dag); // -0.5 is included axpy(out,4.0-M5,in,out); } template void WilsonFermion5D::MomentumSpacePropagatorHt_5d(FermionField &out,const FermionField &in, RealD mass,std::vector twist) { // what type LatticeComplex GridBase *_grid = _FourDimGrid; GridBase *_5dgrid = _FiveDimGrid; conformable(_5dgrid,out.Grid()); FermionField PRsource(_5dgrid); FermionField PLsource(_5dgrid); FermionField buf1_4d(_grid); FermionField buf2_4d(_grid); FermionField GR(_5dgrid); FermionField GL(_5dgrid); FermionField bufL_4d(_grid); FermionField bufR_4d(_grid); unsigned int Ls = in.Grid()->_rdimensions[0]; typedef typename FermionField::vector_type vector_type; typedef typename FermionField::scalar_type ScalComplex; typedef iSinglet Tcomplex; typedef Lattice > LatComplex; Gamma::Algebra Gmu [] = { Gamma::Algebra::GammaX, Gamma::Algebra::GammaY, Gamma::Algebra::GammaZ, Gamma::Algebra::GammaT }; Gamma g5(Gamma::Algebra::Gamma5); Coordinate latt_size = _grid->_fdimensions; LatComplex sk(_grid); sk = Zero(); LatComplex sk2(_grid); sk2= Zero(); LatComplex W(_grid); W= Zero(); LatComplex one (_grid); one = ScalComplex(1.0,0.0); LatComplex cosha(_grid); LatComplex kmu(_grid); LatComplex Wea(_grid); LatComplex Wema(_grid); LatComplex ea(_grid); LatComplex ema(_grid); LatComplex eaLs(_grid); LatComplex emaLs(_grid); LatComplex ea2Ls(_grid); LatComplex ema2Ls(_grid); LatComplex sinha(_grid); LatComplex sinhaLs(_grid); LatComplex coshaLs(_grid); LatComplex A(_grid); LatComplex F(_grid); LatComplex App(_grid); LatComplex Amm(_grid); LatComplex Bpp(_grid); LatComplex Bmm(_grid); LatComplex ABpm(_grid); //Apm=Amp=Bpm=Bmp LatComplex signW(_grid); ScalComplex ci(0.0,1.0); for(int mu=0;mu alpha //////////////////////////////////////////// cosha = (one + W*W + sk) / (abs(W)*2.0); ea = (cosha + sqrt(cosha*cosha-one)); ema= (cosha - sqrt(cosha*cosha-one)); eaLs = pow(ea,Ls); emaLs= pow(ema,Ls); ea2Ls = pow(ea,2.0*Ls); ema2Ls= pow(ema,2.0*Ls); Wea= abs(W) * ea; Wema= abs(W) * ema; // a=log(ea); sinha = 0.5*(ea - ema); sinhaLs = 0.5*(eaLs-emaLs); coshaLs = 0.5*(eaLs+emaLs); A = one / (abs(W) * sinha * 2.0) * one / (sinhaLs * 2.0); F = eaLs * (one - Wea + (Wema - one) * mass*mass); F = F + emaLs * (Wema - one + (one - Wea) * mass*mass); F = F - abs(W) * sinha * 4.0 * mass; Bpp = (A/F) * (ema2Ls - one) * (one - Wema) * (one - mass*mass * one); Bmm = (A/F) * (one - ea2Ls) * (one - Wea) * (one - mass*mass * one); App = (A/F) * (ema2Ls - one) * ema * (ema - abs(W)) * (one - mass*mass * one); Amm = (A/F) * (one - ea2Ls) * ea * (ea - abs(W)) * (one - mass*mass * one); ABpm = (A/F) * abs(W) * sinha * 2.0 * (one + mass * coshaLs * 2.0 + mass*mass * one); //P+ source, P- source PRsource = (in + g5 * in) * 0.5; PLsource = (in - g5 * in) * 0.5; //calculate GR, GL for(unsigned int ss=1;ss<=Ls;ss++) { bufR_4d = Zero(); bufL_4d = Zero(); for(unsigned int tt=1;tt<=Ls;tt++) { //possible sign if W<0 if((ss+tt)%2==1) signW = abs(W)/W; else signW = one; unsigned int f = (ss > tt) ? ss-tt : tt-ss; //f = abs(ss-tt) //GR buf1_4d = Zero(); ExtractSlice(buf1_4d, PRsource, (tt-1), 0); //G(s,t) bufR_4d = bufR_4d + A * eaLs * pow(ema,f) * signW * buf1_4d + A * emaLs * pow(ea,f) * signW * buf1_4d; //A++*exp(a(s+t)) bufR_4d = bufR_4d + App * pow(ea,ss) * pow(ea,tt) * signW * buf1_4d ; //A+-*exp(a(s-t)) bufR_4d = bufR_4d + ABpm * pow(ea,ss) * pow(ema,tt) * signW * buf1_4d ; //A-+*exp(a(-s+t)) bufR_4d = bufR_4d + ABpm * pow(ema,ss) * pow(ea,tt) * signW * buf1_4d ; //A--*exp(a(-s-t)) bufR_4d = bufR_4d + Amm * pow(ema,ss) * pow(ema,tt) * signW * buf1_4d ; //GL buf2_4d = Zero(); ExtractSlice(buf2_4d, PLsource, (tt-1), 0); //G(s,t) bufL_4d = bufL_4d + A * eaLs * pow(ema,f) * signW * buf2_4d + A * emaLs * pow(ea,f) * signW * buf2_4d; //B++*exp(a(s+t)) bufL_4d = bufL_4d + Bpp * pow(ea,ss) * pow(ea,tt) * signW * buf2_4d ; //B+-*exp(a(s-t)) bufL_4d = bufL_4d + ABpm * pow(ea,ss) * pow(ema,tt) * signW * buf2_4d ; //B-+*exp(a(-s+t)) bufL_4d = bufL_4d + ABpm * pow(ema,ss) * pow(ea,tt) * signW * buf2_4d ; //B--*exp(a(-s-t)) bufL_4d = bufL_4d + Bmm * pow(ema,ss) * pow(ema,tt) * signW * buf2_4d ; } InsertSlice(bufR_4d, GR, (ss-1), 0); InsertSlice(bufL_4d, GL, (ss-1), 0); } //calculate propagator for(unsigned int ss=1;ss<=Ls;ss++) { bufR_4d = Zero(); bufL_4d = Zero(); //(i*gamma_mu*sin(p_mu) - W)*(GL*P- source) buf1_4d = Zero(); ExtractSlice(buf1_4d, GL, (ss-1), 0); buf2_4d = Zero(); for(int mu=0;mu void WilsonFermion5D::MomentumSpacePropagatorHt(FermionField &out,const FermionField &in, RealD mass,std::vector twist) { // what type LatticeComplex GridBase *_grid = _FourDimGrid; conformable(_grid,out.Grid()); typedef typename FermionField::vector_type vector_type; typedef typename FermionField::scalar_type ScalComplex; typedef iSinglet Tcomplex; typedef Lattice > LatComplex; Gamma::Algebra Gmu [] = { Gamma::Algebra::GammaX, Gamma::Algebra::GammaY, Gamma::Algebra::GammaZ, Gamma::Algebra::GammaT }; Coordinate latt_size = _grid->_fdimensions; FermionField num (_grid); num = Zero(); LatComplex sk(_grid); sk = Zero(); LatComplex sk2(_grid); sk2= Zero(); LatComplex W(_grid); W= Zero(); LatComplex a(_grid); a= Zero(); LatComplex one (_grid); one = ScalComplex(1.0,0.0); LatComplex denom(_grid); denom= Zero(); LatComplex cosha(_grid); LatComplex kmu(_grid); LatComplex Wea(_grid); LatComplex Wema(_grid); ScalComplex ci(0.0,1.0); for(int mu=0;mu exp(+/- alpha) //////////////////////////////////////////// cosha = (one + W*W + sk) / (abs(W)*2.0); Wea = abs(W)*(cosha + sqrt(cosha*cosha-one)); Wema= abs(W)*(cosha - sqrt(cosha*cosha-one)); num = num + ( one - Wema ) * mass * in; denom= ( Wea - one ) + mass*mass * (one - Wema); out = num/denom; } template void WilsonFermion5D::MomentumSpacePropagatorHw(FermionField &out,const FermionField &in,RealD mass,std::vector twist) { Gamma::Algebra Gmu [] = { Gamma::Algebra::GammaX, Gamma::Algebra::GammaY, Gamma::Algebra::GammaZ, Gamma::Algebra::GammaT }; GridBase *_grid = _FourDimGrid; conformable(_grid,out.Grid()); typedef typename FermionField::vector_type vector_type; typedef typename FermionField::scalar_type ScalComplex; typedef Lattice > LatComplex; Coordinate latt_size = _grid->_fdimensions; LatComplex sk(_grid); sk = Zero(); LatComplex sk2(_grid); sk2= Zero(); LatComplex w_k(_grid); w_k= Zero(); LatComplex b_k(_grid); b_k= Zero(); LatComplex one (_grid); one = ScalComplex(1.0,0.0); FermionField num (_grid); num = Zero(); LatComplex denom(_grid); denom= Zero(); LatComplex kmu(_grid); ScalComplex ci(0.0,1.0); for(int mu=0;mu qSiteVec(Nsimd); \ extract(qSite, qSiteVec); \ for (int i = 0; i < Nsimd / 2; ++i) \ { \ typename SitePropagator::scalar_object tmp = qSiteVec[i]; \ qSiteVec[i] = qSiteVec[Nsimd - i - 1]; \ qSiteVec[Nsimd - i - 1] = tmp; \ } \ merge(qSiteRev, qSiteVec); \ } ******************************************************************************/ NAMESPACE_END(Grid);