diff --git a/tests/core/Test_gamma.cc b/tests/core/Test_gamma.cc index a853f216..38a43a11 100644 --- a/tests/core/Test_gamma.cc +++ b/tests/core/Test_gamma.cc @@ -1,223 +1,236 @@ - /************************************************************************************* +/************************************************************************************* - Grid physics library, www.github.com/paboyle/Grid +Grid physics library, www.github.com/paboyle/Grid - Source file: ./tests/Test_gamma.cc +Source file: ./tests/Test_gamma.cc - Copyright (C) 2015 +Copyright (C) 2015-2017 Author: Azusa Yamaguchi Author: Peter Boyle +Author: Antonin Portelli - 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 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. +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. +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 - *************************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #include using namespace std; using namespace Grid; -using namespace Grid::QCD; +using namespace QCD; -//template class is_pod< iScalar > -//{ -// -//}; +static constexpr double tolerance = 1.0e-6; +static std::array testAlgebra; -int main (int argc, char ** argv) +void print(const SpinMatrix &g) +{ + for(int i = 0; i < Ns; i++) + { + std::cout << GridLogMessage << "("; + for(int j=0;j testg; + SpinMatrix testg5; + const Complex I(0., 1.), mI(0., -1.); + + testg[0] = zero; + testg[0]()(0, 3) = I; + testg[0]()(1, 2) = I; + testg[0]()(2, 1) = mI; + testg[0]()(3, 0) = mI; + std::cout << GridLogMessage << "test GammaX= " << std::endl; + print(testg[0]); + testg[1] = zero; + testg[1]()(0, 3) = -1.; + testg[1]()(1, 2) = 1.; + testg[1]()(2, 1) = 1.; + testg[1]()(3, 0) = -1.; + std::cout << GridLogMessage << "test GammaY= " << std::endl; + print(testg[1]); + testg[2] = zero; + testg[2]()(0, 2) = I; + testg[2]()(1, 3) = mI; + testg[2]()(2, 0) = mI; + testg[2]()(3, 1) = I; + std::cout << GridLogMessage << "test GammaZ= " << std::endl; + print(testg[2]); + testg[3] = zero; + testg[3]()(0, 2) = 1.; + testg[3]()(1, 3) = 1.; + testg[3]()(2, 0) = 1.; + testg[3]()(3, 1) = 1.; + std::cout << GridLogMessage << "test GammaT= " << std::endl; + print(testg[3]); + testg5 = testg[0]*testg[1]*testg[2]*testg[3]; + +#define DEFINE_TEST_G(g, exp)\ +testAlgebra[Gamma::Algebra::g] = exp;\ +testAlgebra[Gamma::Algebra::Minus##g] = -exp;\ + + DEFINE_TEST_G(Identity , 1.); + DEFINE_TEST_G(Gamma5 , testg5); + DEFINE_TEST_G(GammaX , testg[0]); + DEFINE_TEST_G(GammaY , testg[1]); + DEFINE_TEST_G(GammaZ , testg[2]); + DEFINE_TEST_G(GammaT , testg[3]); + DEFINE_TEST_G(GammaXGamma5, testg[0]*testg5); + DEFINE_TEST_G(GammaYGamma5, testg[1]*testg5); + DEFINE_TEST_G(GammaZGamma5, testg[2]*testg5); + DEFINE_TEST_G(GammaTGamma5, testg[3]*testg5); + DEFINE_TEST_G(SigmaXY , .5*(testg[0]*testg[1] - testg[1]*testg[0])); + DEFINE_TEST_G(SigmaXZ , .5*(testg[0]*testg[2] - testg[2]*testg[0])); + DEFINE_TEST_G(SigmaXT , .5*(testg[0]*testg[3] - testg[3]*testg[0])); + DEFINE_TEST_G(SigmaYZ , .5*(testg[1]*testg[2] - testg[2]*testg[1])); + DEFINE_TEST_G(SigmaYT , .5*(testg[1]*testg[3] - testg[3]*testg[1])); + DEFINE_TEST_G(SigmaZT , .5*(testg[2]*testg[3] - testg[3]*testg[2])); + +#undef DEFINE_TEST_G +} + +template +void test(const Expr &a, const Expr &b) +{ + if (norm2(a - b) < tolerance) + { + std::cout << "[OK] "; + } + else + { + std::cout << "[fail]" << std::endl; + std::cout << GridLogError << "a= " << a << std::endl; + std::cout << GridLogError << "is different (tolerance= " << tolerance << ") from " << std::endl; + std::cout << GridLogError << "b= " << b << std::endl; + exit(EXIT_FAILURE); + } +} + +void checkMat(const Gamma::Algebra a, GridSerialRNG &rng) +{ + SpinVector v; + SpinMatrix m, &testg = testAlgebra[a]; + Gamma g(a); + bool pass = true; + + random(rng, v); + random(rng, m); + + std::cout << GridLogMessage << "Checking " << Gamma::name[a] << ": "; + std::cout << "vecmul "; + test(g*v, testg*v); + std::cout << "matlmul "; + test(g*m, testg*m); + std::cout << "matrmul "; + test(m*g, m*testg); + std::cout << std::endl; +} + +void checkProd(const Gamma::Algebra a, const Gamma::Algebra b) +{ + SpinMatrix gm, testg = testAlgebra[a]*testAlgebra[b]; + Gamma ga(a), gb(b), g = ga*gb; + bool pass = true; + + std::cout << GridLogMessage << "Checking " << Gamma::name[a] << " * " + << Gamma::name[b] << ": "; + gm = 1.0; + gm = g*gm; + test(gm, testg); + std::cout << "(= " << Gamma::name[g.g] << ")" << std::endl; +} + +void checkProject(GridSerialRNG &rng) +{ + SpinVector rv, recon, full; + HalfSpinVector hsp, hsm; + + random(rng, rv); + +#define CHECK_PROJ(dir, gamma)\ +std::cout << GridLogMessage << "Checking " << #dir << " projector: ";\ +spProj##dir(hsm,rv);\ +spRecon##dir(recon,hsm);\ +test(recon, rv + Gamma(Gamma::Algebra::gamma)*rv);\ +std::cout << std::endl; + + CHECK_PROJ(Xp, GammaX); + CHECK_PROJ(Yp, GammaY); + CHECK_PROJ(Zp, GammaZ); + CHECK_PROJ(Tp, GammaT); + CHECK_PROJ(5p, Gamma5); + CHECK_PROJ(Xm, MinusGammaX); + CHECK_PROJ(Ym, MinusGammaY); + CHECK_PROJ(Zm, MinusGammaZ); + CHECK_PROJ(Tm, MinusGammaT); + CHECK_PROJ(5m, MinusGamma5); + +#undef CHECK_PROJ +} + +int main(int argc, char *argv[]) { Grid_init(&argc,&argv); - + std::vector latt_size = GridDefaultLatt(); std::vector simd_layout = GridDefaultSimd(4,vComplex::Nsimd()); std::vector mpi_layout = GridDefaultMpi(); - - GridCartesian Grid(latt_size,simd_layout,mpi_layout); - - GridParallelRNG pRNG(&Grid); - pRNG.SeedRandomDevice(); - - GridSerialRNG sRNG; + + GridCartesian Grid(latt_size,simd_layout,mpi_layout); + GridSerialRNG sRNG; + sRNG.SeedRandomDevice(); - - SpinMatrix ident; ident=zero; - SpinMatrix rnd ; random(sRNG,rnd); - - SpinMatrix ll; ll=zero; - SpinMatrix rr; rr=zero; - SpinMatrix result; - - SpinVector lv; random(sRNG,lv); - SpinVector rv; random(sRNG,rv); - - // std::cout<::value << std::endl; - // std::cout<::value << std::endl; - // std::cout<::value << std::endl; - // std::cout<::value << std::endl; - // std::cout<::value << std::endl; - // std::cout< " << std::is_pod >::value << std::endl; - // std::cout< " << std::is_pod >::value << std::endl; - // std::cout< " << std::is_pod >::value << std::endl; - // std::cout< " << std::is_pod >::value << std::endl; - // std::cout< " << std::is_pod >::value << std::endl; - // std::cout< " << std::is_pod >::value << std::endl; - // std::cout< " < >::value << std::endl; - // std::cout< "< >::value << std::endl; - - for(int a=0;a