1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-09-20 01:05:38 +01:00

Cleanup and prepare for pull request

This commit is contained in:
Guido Cossu 2017-10-24 13:21:17 +01:00
parent cbda4f66e0
commit ec8cd11c1f
4 changed files with 258 additions and 307 deletions

View File

@ -39,29 +39,33 @@ namespace QCD
template <class Impl>
RealD WilsonCloverFermion<Impl>::M(const FermionField &in, FermionField &out)
{
FermionField temp(out._grid);
// Wilson term
out.checkerboard = in.checkerboard;
this->Dhop(in, out, DaggerNo);
// Clover term
// apply the sigma and Fmunu
FermionField temp(out._grid);
Mooee(in, temp);
out += temp;
return axpy_norm(out, 4 + this->mass, in, out);
return norm2(out);
}
template <class Impl>
RealD WilsonCloverFermion<Impl>::Mdag(const FermionField &in, FermionField &out)
{
FermionField temp(out._grid);
// Wilson term
out.checkerboard = in.checkerboard;
this->Dhop(in, out, DaggerYes);
// Clover term
// apply the sigma and Fmunu
FermionField temp(out._grid);
MooeeDag(in, temp);
out += temp;
return axpy_norm(out, 4 + this->mass, in, out);
return norm2(out);
}
template <class Impl>
@ -87,7 +91,7 @@ void WilsonCloverFermion<Impl>::ImportGauge(const GaugeField &_Umu)
CloverTerm += fillCloverYT(Ey);
CloverTerm += fillCloverZT(Ez);
CloverTerm *= (0.5) * csw;
CloverTerm += (4.0 + this->mass);
int lvol = _Umu._grid->lSites();
int DimRep = Impl::Dimension;
@ -98,7 +102,6 @@ void WilsonCloverFermion<Impl>::ImportGauge(const GaugeField &_Umu)
std::vector<int> lcoor;
typename SiteCloverType::scalar_object Qx = zero, Qxinv = zero;
for (int site = 0; site < lvol; site++)
{
grid->LocalIndexToLocalCoor(site, lcoor);
@ -125,24 +128,18 @@ void WilsonCloverFermion<Impl>::ImportGauge(const GaugeField &_Umu)
pokeLocalSite(Qxinv, CloverTermInv, lcoor);
}
// Separate the even and odd parts.
// Separate the even and odd parts
pickCheckerboard(Even, CloverTermEven, CloverTerm);
pickCheckerboard(Odd, CloverTermOdd, CloverTerm);
pickCheckerboard(Even, CloverTermDagEven, adj(CloverTerm));
pickCheckerboard(Odd, CloverTermDagOdd, adj(CloverTerm));
pickCheckerboard(Even, CloverTermInvEven, CloverTermInv);
pickCheckerboard(Odd, CloverTermInvOdd, CloverTermInv);
pickCheckerboard(Even, CloverTermInvDagEven, adj(CloverTermInv));
pickCheckerboard(Odd, CloverTermInvDagOdd, adj(CloverTermInv));
}
template <class Impl>
@ -177,81 +174,46 @@ void WilsonCloverFermion<Impl>::MooeeInternal(const FermionField &in, FermionFie
CloverFieldType *Clover;
assert(in.checkerboard == Odd || in.checkerboard == Even);
if (dag){
if (in._grid->_isCheckerBoarded){
if (in.checkerboard == Odd){
// std::cout << "Calling clover term adj Odd" << std::endl;
if (dag)
{
if (in._grid->_isCheckerBoarded)
{
if (in.checkerboard == Odd)
{
Clover = (inv) ? &CloverTermInvDagOdd : &CloverTermDagOdd;
/* test
int DimRep = Impl::Dimension;
Eigen::MatrixXcd A = Eigen::MatrixXcd::Zero(Ns * DimRep, Ns * DimRep);
std::vector<int> lcoor;
typename SiteCloverType::scalar_object Qx2 = zero;
GridBase *grid = in._grid;
int site = 0 ;
grid->LocalIndexToLocalCoor(site, lcoor);
peekLocalSite(Qx2, *Clover, lcoor);
for (int j = 0; j < Ns; j++)
for (int k = 0; k < Ns; k++)
for (int a = 0; a < DimRep; a++)
for (int b = 0; b < DimRep; b++)
A(a + j * DimRep, b + k * DimRep) = Qx2()(j, k)(a, b);
std::cout << "adj Odd =" << site << "\n" << A << std::endl;
end test */
} else {
// std::cout << "Calling clover term adj Even" << std::endl;
}
else
{
Clover = (inv) ? &CloverTermInvDagEven : &CloverTermDagEven;
/* test
int DimRep = Impl::Dimension;
Eigen::MatrixXcd A = Eigen::MatrixXcd::Zero(Ns * DimRep, Ns * DimRep);
std::vector<int> lcoor;
typename SiteCloverType::scalar_object Qx2 = zero;
GridBase *grid = in._grid;
int site = 0 ;
grid->LocalIndexToLocalCoor(site, lcoor);
peekLocalSite(Qx2, *Clover, lcoor);
for (int j = 0; j < Ns; j++)
for (int k = 0; k < Ns; k++)
for (int a = 0; a < DimRep; a++)
for (int b = 0; b < DimRep; b++)
A(a + j * DimRep, b + k * DimRep) = Qx2()(j, k)(a, b);
std::cout << "adj Odd =" << site << "\n" << A << std::endl;
end test */
}
// std::cout << GridLogMessage << "*Clover.checkerboard " << (*Clover).checkerboard << std::endl;
out = *Clover * in;
} else {
Clover = (inv) ? &CloverTermInv : &CloverTerm;
//out = adj(*Clover) * in;
out = adj(CloverTerm) * in;
}
else
{
Clover = (inv) ? &CloverTermInv : &CloverTerm;
out = adj(*Clover) * in;
}
}
else
{
if (in._grid->_isCheckerBoarded)
{
} else {
if (in._grid->_isCheckerBoarded){
if (in.checkerboard == Odd){
if (in.checkerboard == Odd)
{
// std::cout << "Calling clover term Odd" << std::endl;
Clover = (inv) ? &CloverTermInvOdd : &CloverTermOdd;
} else {
}
else
{
// std::cout << "Calling clover term Even" << std::endl;
Clover = (inv) ? &CloverTermInvEven : &CloverTermEven;
}
out = *Clover * in;
// std::cout << GridLogMessage << "*Clover.checkerboard " << (*Clover).checkerboard << std::endl;
} else {
}
else
{
Clover = (inv) ? &CloverTermInv : &CloverTerm;
out = *Clover * in;
}
@ -264,7 +226,6 @@ template <class Impl>
void WilsonCloverFermion<Impl>::MDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag)
{
GaugeField tmp(mat._grid);
conformable(U._grid, V._grid);
@ -299,10 +260,17 @@ std::vector<GaugeLinkField> C1p(Nd,grid), C2p(Nd,grid), C3p(Nd,grid), C4p(Nd,gri
std::vector<GaugeLinkField> C1m(Nd, grid), C2m(Nd, grid), C3m(Nd, grid), C4m(Nd, grid);
std::vector<GaugeLinkField> U(Nd, mat._grid);
for (int mu = 0; mu < Nd; mu++) {
for (int mu = 0; mu < Nd; mu++)
{
U[mu] = PeekIndex<LorentzIndex>(mat, mu);
C1p[mu]=zero; C2p[mu]=zero; C3p[mu]=zero; C4p[mu]=zero;
C1m[mu]=zero; C2m[mu]=zero; C3m[mu]=zero; C4m[mu]=zero;
C1p[mu] = zero;
C2p[mu] = zero;
C3p[mu] = zero;
C4p[mu] = zero;
C1m[mu] = zero;
C2m[mu] = zero;
C3m[mu] = zero;
C4m[mu] = zero;
}
/*
@ -316,11 +284,15 @@ for (int mu = 0; mu < Nd; mu++) {
}
*/
for (int i=0;i<4;i++){ //spin
for(int j=0;j<4;j++){ //spin
for (int i = 0; i < 4; i++)
{ //spin
for (int j = 0; j < 4; j++)
{ //spin
for (int mu=0;mu<4;mu++){ //color
for (int nu=0;nu<4;nu++){ //color
for (int mu = 0; mu < 4; mu++)
{ //color
for (int nu = 0; nu < 4; nu++)
{ //color
// insertion in upper staple
tmp = Lambda * U[nu];
@ -349,15 +321,10 @@ for (int mu=0;mu<4;mu++){ //color
C4m[mu] += Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu) * tmp;
}
}
}
}
//Still implementing. Have to be tested, and understood how to project EO
}
// Derivative parts

View File

@ -26,6 +26,7 @@
See the full license in the file "LICENSE" in the top level distribution directory
*************************************************************************************/
/* END LEGAL */
#ifndef GRID_QCD_WILSON_CLOVER_FERMION_H
#define GRID_QCD_WILSON_CLOVER_FERMION_H
@ -42,9 +43,11 @@ class WilsonCloverFermion : public WilsonFermion<Impl>
public:
// Types definitions
INHERIT_IMPL_TYPES(Impl);
template <typename vtype> using iImplClover = iScalar<iMatrix<iMatrix<vtype, Impl::Dimension>, Ns> >;
template <typename vtype>
using iImplClover = iScalar<iMatrix<iMatrix<vtype, Impl::Dimension>, Ns>>;
typedef iImplClover<Simd> SiteCloverType;
typedef Lattice<SiteCloverType> CloverFieldType;
public:
typedef WilsonFermion<Impl> WilsonBase;
@ -64,13 +67,15 @@ public:
CloverTermOdd(&Hgrid),
CloverTermInvEven(&Hgrid),
CloverTermInvOdd(&Hgrid),
CloverTermDagEven(&Hgrid), //test
CloverTermDagOdd(&Hgrid), //test
CloverTermInvDagEven(&Hgrid), //test
CloverTermInvDagOdd(&Hgrid) //test
CloverTermDagEven(&Hgrid),
CloverTermDagOdd(&Hgrid),
CloverTermInvDagEven(&Hgrid),
CloverTermInvDagOdd(&Hgrid)
{
csw = _csw;
assert(Nd == 4); // require 4 dimensions
if (csw == 0) std::cout << GridLogWarning << "Initializing WilsonCloverFermion with csw = 0" << std::endl;
}
virtual RealD M(const FermionField &in, FermionField &out);
@ -92,11 +97,11 @@ private:
// here fixing the 4 dimensions, make it more general?
RealD csw; // Clover coefficient
CloverFieldType CloverTerm=zero, CloverTermInv=zero; // Clover term
CloverFieldType CloverTermEven=zero, CloverTermOdd=zero; // Clover term EO
CloverFieldType CloverTermInvEven=zero, CloverTermInvOdd=zero; // Clover term Inv EO
CloverFieldType CloverTermDagEven=zero, CloverTermDagOdd=zero; // Clover term Dag EO
CloverFieldType CloverTermInvDagEven=zero, CloverTermInvDagOdd=zero; // Clover term Inv Dag EO
CloverFieldType CloverTerm, CloverTermInv; // Clover term
CloverFieldType CloverTermEven, CloverTermOdd; // Clover term EO
CloverFieldType CloverTermInvEven, CloverTermInvOdd; // Clover term Inv EO
CloverFieldType CloverTermDagEven, CloverTermDagOdd; // Clover term Dag EO
CloverFieldType CloverTermInvDagEven, CloverTermInvDagOdd; // Clover term Inv Dag EO
// eventually these two can be compressed into 6x6 blocks instead of the 12x12
// using the DeGrand-Rossi basis for the gamma matrices
@ -196,7 +201,6 @@ private:
return T;
}
};
}
}

View File

@ -237,7 +237,7 @@ int main (int argc, char ** argv)
setCheckerboard(src,src_o);
//Gauge Transformation
////////////////////// Gauge Transformation
std::vector<int> seeds2({5,6,7,8});
GridParallelRNG pRNG2(&Grid); pRNG2.SeedFixedIntegers(seeds2);
LatticeColourMatrix Omega(&Grid);
@ -251,7 +251,7 @@ int main (int argc, char ** argv)
U_prime_mu=Omega*U[mu]*adj(ShiftedOmega);
pokeLorentz(U_prime,U_prime_mu,mu);
}
/////////////////
WilsonCloverFermionR Dwc_prime(U_prime,Grid,RBGrid,mass,csw,params);
Dwc_prime.ImportGauge(U_prime);
@ -298,7 +298,7 @@ int main (int argc, char ** argv)
std::cout<<GridLogMessage<<"=========================================================="<<std::endl;
chi=zero; phi=zero; err=zero;
WilsonCloverFermionR Dwc_csw0(Umu,Grid,RBGrid,mass,0.0,params); // <-- csw=0
WilsonCloverFermionR Dwc_csw0(Umu,Grid,RBGrid,mass,0.0,params); // <-- Notice: csw=0
Dwc_csw0.ImportGauge(Umu);
pickCheckerboard(Even,phi_e,phi);
@ -318,9 +318,7 @@ int main (int argc, char ** argv)
setCheckerboard(src,src_e);
setCheckerboard(src,src_o);
FermionField::scalar_type scal(4.0 + mass);
err = chi - (phi + scal*src) ; // subtraction of the mass term (not present in Mooee Clover!)
err = chi - phi;
std::cout<<GridLogMessage << "norm diff "<< norm2(err)<< std::endl;
Grid_finalize();

View File

@ -27,28 +27,23 @@
/* END LEGAL */
#include <Grid/Grid.h>
#include <chroma.h>
#include <actions/ferm/invert/syssolver_linop_cg_array.h>
#include <actions/ferm/invert/syssolver_linop_aggregate.h>
// Mass
double mq = 0.0;
double mq = 0.01;
// Define Wilson Types
typedef Grid::QCD::WilsonImplR::FermionField FermionField;
typedef Grid::QCD::LatticeGaugeField GaugeField;
#include <chroma.h>
#include <actions/ferm/invert/syssolver_linop_cg_array.h>
#include <actions/ferm/invert/syssolver_linop_aggregate.h>
enum ChromaAction
{
Wilson, // Wilson
WilsonClover // CloverFermions
};
void make_gauge(GaugeField &lat, FermionField &src);
void calc_grid(ChromaAction CA, GaugeField &lat, FermionField &src, FermionField &res, int dag);
void calc_chroma(ChromaAction CA, GaugeField &lat, FermionField &src, FermionField &res, int dag);
namespace Chroma
{
@ -286,91 +281,6 @@ public:
};
} // namespace Chroma
int main(int argc, char **argv)
{
/********************************************************
* Setup QDP
*********************************************************/
Chroma::initialize(&argc, &argv);
Chroma::WilsonTypeFermActs4DEnv::registerAll();
/********************************************************
* Setup Grid
*********************************************************/
Grid::Grid_init(&argc, &argv);
Grid::GridCartesian *UGrid = Grid::QCD::SpaceTimeGrid::makeFourDimGrid(Grid::GridDefaultLatt(),
Grid::GridDefaultSimd(Grid::QCD::Nd, Grid::vComplex::Nsimd()),
Grid::GridDefaultMpi());
std::vector<int> gd = UGrid->GlobalDimensions();
QDP::multi1d<int> nrow(QDP::Nd);
for (int mu = 0; mu < 4; mu++)
nrow[mu] = gd[mu];
QDP::Layout::setLattSize(nrow);
QDP::Layout::create();
GaugeField Ug(UGrid);
FermionField src(UGrid);
FermionField res_chroma(UGrid);
FermionField res_grid(UGrid);
FermionField only_wilson(UGrid);
FermionField difference(UGrid);
std::vector<ChromaAction> ActionList({Wilson, WilsonClover});
std::vector<std::string> ActionName({"Wilson", "WilsonClover"});
{
for (int i = 0; i < ActionList.size(); i++)
{
std::cout << "*****************************" << std::endl;
std::cout << "Action " << ActionName[i] << std::endl;
std::cout << "*****************************" << std::endl;
make_gauge(Ug, src); // fills the gauge field and the fermion field with random numbers
for (int dag = 0; dag < 2; dag++)
{
{
std::cout << "Dag = " << dag << std::endl;
calc_chroma(ActionList[i], Ug, src, res_chroma, dag);
// Remove the normalisation of Chroma Gauge links ????????
std::cout << "Norm of Chroma " << ActionName[i] << " multiply " << Grid::norm2(res_chroma) << std::endl;
calc_grid(ActionList[i], Ug, src, res_grid, dag);
std::cout << "Norm of gauge " << Grid::norm2(Ug) << std::endl;
std::cout << "Norm of Grid " << ActionName[i] << " multiply " << Grid::norm2(res_grid) << std::endl;
difference = res_chroma - res_grid;
std::cout << "Norm of difference " << Grid::norm2(difference) << std::endl;
// Isolate Clover term
/*
calc_grid(Wilson, Ug, src, only_wilson, dag); // Wilson term
res_grid -= only_wilson;
res_chroma -= only_wilson;
std::cout << "Chroma:" << res_chroma << std::endl;
std::cout << "Grid :" << res_grid << std::endl;
difference = (res_grid-res_chroma);
std::cout << "Difference :" << difference << std::endl;
*/
}
}
std::cout << "Finished test " << std::endl;
Chroma::finalize();
}
}
}
void calc_chroma(ChromaAction action, GaugeField &lat, FermionField &src, FermionField &res, int dag)
{
QDP::multi1d<QDP::LatticeColorMatrix> u(4);
@ -467,7 +377,6 @@ void make_gauge(GaugeField &Umu, FermionField &src)
}
}
*/
}
void calc_grid(ChromaAction action, Grid::QCD::LatticeGaugeField &Umu, Grid::QCD::LatticeFermion &src, Grid::QCD::LatticeFermion &res, int dag)
@ -512,3 +421,76 @@ void calc_grid(ChromaAction action, Grid::QCD::LatticeGaugeField &Umu, Grid::QCD
assert(0);
}
int main(int argc, char **argv)
{
/********************************************************
* Setup QDP
*********************************************************/
Chroma::initialize(&argc, &argv);
Chroma::WilsonTypeFermActs4DEnv::registerAll();
/********************************************************
* Setup Grid
*********************************************************/
Grid::Grid_init(&argc, &argv);
Grid::GridCartesian *UGrid = Grid::QCD::SpaceTimeGrid::makeFourDimGrid(Grid::GridDefaultLatt(),
Grid::GridDefaultSimd(Grid::QCD::Nd, Grid::vComplex::Nsimd()),
Grid::GridDefaultMpi());
std::vector<int> gd = UGrid->GlobalDimensions();
QDP::multi1d<int> nrow(QDP::Nd);
for (int mu = 0; mu < 4; mu++)
nrow[mu] = gd[mu];
QDP::Layout::setLattSize(nrow);
QDP::Layout::create();
GaugeField Ug(UGrid);
FermionField src(UGrid);
FermionField res_chroma(UGrid);
FermionField res_grid(UGrid);
FermionField only_wilson(UGrid);
FermionField difference(UGrid);
std::vector<ChromaAction> ActionList({Wilson, WilsonClover});
std::vector<std::string> ActionName({"Wilson", "WilsonClover"});
{
for (int i = 0; i < ActionList.size(); i++)
{
std::cout << "*****************************" << std::endl;
std::cout << "Action " << ActionName[i] << std::endl;
std::cout << "*****************************" << std::endl;
make_gauge(Ug, src); // fills the gauge field and the fermion field with random numbers
for (int dag = 0; dag < 2; dag++)
{
{
std::cout << "Dag = " << dag << std::endl;
calc_chroma(ActionList[i], Ug, src, res_chroma, dag);
// Remove the normalisation of Chroma Gauge links ????????
std::cout << "Norm of Chroma " << ActionName[i] << " multiply " << Grid::norm2(res_chroma) << std::endl;
calc_grid(ActionList[i], Ug, src, res_grid, dag);
std::cout << "Norm of gauge " << Grid::norm2(Ug) << std::endl;
std::cout << "Norm of Grid " << ActionName[i] << " multiply " << Grid::norm2(res_grid) << std::endl;
difference = res_chroma - res_grid;
std::cout << "Norm of difference " << Grid::norm2(difference) << std::endl;
}
}
std::cout << "Finished test " << std::endl;
Chroma::finalize();
}
}
}