diff --git a/Grid/tensors/Tensor_Ta.h b/Grid/tensors/Tensor_Ta.h index 15120ffd..cc21378e 100644 --- a/Grid/tensors/Tensor_Ta.h +++ b/Grid/tensors/Tensor_Ta.h @@ -212,58 +212,52 @@ accelerator_inline iMatrix ProjectOnSpGroup(const iMatrix &arg iMatrix ret(arg); vtype nrm; vtype inner; - vtype tmp; for(int c1=0;c1 - prn += conjugate(ret._internal[c1][c])*ret._internal[b+N/2][c]; // - } + for(int c=0; c + prn += conjugate(ret._internal[c1][c])*ret._internal[b+N/2][c]; // + } - for(int c=0; c U_b + U_{b+N} ) - } + for(int c=0; c U_b + U_{b+N} ) } + } - zeroit(inner); - for(int c2=0;c2gSites(); + const int nsp = Nc / 2; + LatticeColourMatrixD Omega(Uin.Grid()); + Sp::Omega(Omega); + LatticeColourMatrixD aux(Uin.Grid()); + LatticeColourMatrixD identity(Uin.Grid()); + Complex i(0., 1.); + identity = 1; + + std::cout << GridLogMessage << "Check matrix is non-zero " << std::endl; + assert(norm2(Uin) > 1e-8); + aux = Uin*adj(Uin) - identity; + std::cout << GridLogMessage << "U adjU - 1 = " << norm2(aux)/vol << std::endl; + assert(norm2(aux) < 1e-8); + aux = Omega - (Uin * Omega * transpose(Uin)); + std::cout << GridLogMessage << "Omega - U Omega transpose(U) = " << norm2(aux)/vol << std::endl; + assert(norm2(aux) < 1e-8); + //Sp::OmegaInvariance(Uin) + std::cout << GridLogMessage << "Checking the structure is " << std::endl; + std::cout << GridLogMessage << "U = ( W X ) " << std::endl; + std::cout << GridLogMessage << " ( -X^* W^* ) " << std::endl; + for (int c1 = 0; c1 < nsp; c1++) //check on W + { + for (int c2 = 0; c2 < nsp; c2++) + { + auto W = PeekIndex(Uin,c1,c2); + auto Wstar = PeekIndex(Uin,c1+nsp,c2+nsp); + auto Ww = conjugate( Wstar ); + auto amizero = sum(W - Ww); + auto amizeroo = TensorRemove(amizero); + assert( amizeroo.real() < 10e-6 ); + amizeroo *= i; + assert( amizeroo.real() < 10e-6 ); + } + } + for (int c1 = 0; c1 < nsp ; c1++) + { + for (int c2 = 0; c2 < nsp; c2++) + { + auto X = PeekIndex(Uin,c1,c2+nsp); + auto minusXstar = PeekIndex(Uin,c1+nsp,c2); + auto minusXx = conjugate(minusXstar); + auto amizero = sum (X + minusXx); + auto amizeroo = TensorRemove(amizero); + assert( amizeroo.real() < 10e-6 ); + amizeroo *= i; + assert( amizeroo.real() < 10e-6 ); + } + } + std::cout << GridLogMessage << "|Det| = " << norm2( Determinant(Uin) ) / vol << std::endl; + assert( norm2( Determinant(Uin) ) / vol - 1 < 1e-8); + return 0; +} + +int SpAntiHermitianAlgebraQuiz (const LatticeColourMatrixD Uin) +{ + double vol = Uin.Grid()->gSites(); + const int nsp = Nc / 2; + LatticeColourMatrixD Omega(Uin.Grid()); + Sp::Omega(Omega); + LatticeColourMatrixD aux(Uin.Grid()); + LatticeColourMatrixD identity(Uin.Grid()); + Complex i(0., 1.); + identity = 1; + + std::cout << GridLogMessage << "Check matrix is non-zero " << std::endl; + assert(norm2(Uin) > 1e-8); + aux = Uin - adj(Uin); + std::cout << GridLogMessage << "SpTa ::: T - Tda = " << norm2(aux)/vol << std::endl; + aux = Uin + adj(Uin); + std::cout << GridLogMessage << "SpTa ::: T + Tda = " << norm2(aux)/vol << std::endl; + assert( norm2(aux) - 1 < 1e-8); + std::cout << GridLogMessage << "Check that Omega T Omega + conj(T) = 0 " << std::endl; + aux = Omega*Uin*Omega + conjugate(Uin); + assert( norm2(aux) < 1e-8); + std::cout << GridLogMessage << "Checking the structure is " << std::endl; + std::cout << GridLogMessage << "U = ( W X ) " << std::endl; + std::cout << GridLogMessage << " ( -X^* W^* ) " << std::endl; + for (int c1 = 0; c1 < nsp; c1++) //check on W + { + for (int c2 = 0; c2 < nsp; c2++) + { + auto W = PeekIndex(Uin,c1,c2); + auto Wstar = PeekIndex(Uin,c1+nsp,c2+nsp); + auto Ww = conjugate( Wstar ); + auto amizero = sum(W - Ww); + auto amizeroo = TensorRemove(amizero); + assert( amizeroo.real() < 10e-6 ); + amizeroo *= i; + assert( amizeroo.real() < 10e-6 ); + } + } + for (int c1 = 0; c1 < nsp ; c1++) + { + for (int c2 = 0; c2 < nsp; c2++) + { + auto X = PeekIndex(Uin,c1,c2+nsp); + auto minusXstar = PeekIndex(Uin,c1+nsp,c2); + auto minusXx = conjugate(minusXstar); + auto amizero = sum (X + minusXx); + auto amizeroo = TensorRemove(amizero); + assert( amizeroo.real() < 10e-6 ); + amizeroo *= i; + assert( amizeroo.real() < 10e-6 ); + } + } + return 0; +} + int main (int argc, char **argv) { Grid_init(&argc,&argv); - Coordinate latt_size = GridDefaultLatt(); Coordinate simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd()); Coordinate mpi_layout = GridDefaultMpi(); @@ -14,27 +124,18 @@ int main (int argc, char **argv) GridCartesian Grid(latt_size,simd_layout,mpi_layout); GridRedBlackCartesian RBGrid(&Grid); - LatticeGaugeField Umu(&Grid); LatticeColourMatrixD U(&Grid); - LatticeColourMatrixD Up(&Grid); LatticeColourMatrixD aux(&Grid); LatticeColourMatrixD identity(&Grid); - - // Will test resimplectification-related functionalities (from ProjectOnGaugeGroup, ProjectOnSpGroup, ProjectGn) and projection on the algebra (from ProjectSp2nAlgebra) - // we work with matrices with positive determinant so detU = 1 even if in principle ProjectOnGaugeGroup and ProjectOnSpGroup allow for detU=-1 - // so the checks will be the same for the three functions - // NB only ProjectGn is the proper simplectification function - - - const int nsp = Nc / 2; - + LatticeColourMatrixD Omega(&Grid); + Sp::Omega(Omega); + identity = 1.0; - RealD epsilon = 0.01; - RealD Delta = 666.; + RealD epsilon = 0.1; Complex i(0., 1.); - RealD u = 0.; double vol = Umu.Grid()->gSites(); + const int nsp = Nc / 2; std::vector pseeds({1,2,3,4,5}); GridParallelRNG pRNG(&Grid); pRNG.SeedFixedIntegers(pseeds); @@ -42,236 +143,76 @@ int main (int argc, char **argv) SU::HotConfiguration(pRNG,Umu); U = PeekIndex(Umu,0); - aux = U*adj(U) - identity; std::cout << GridLogMessage << "Starting with random SUn matrix " << std::endl; - std::cout << GridLogMessage << "Unitary check " << std::endl; + aux = U*adj(U) - identity; std::cout < 1e-8 ); } - Sp::OmegaInvariance(U); - std::cout <::OmegaInvariance(U); // no assertion here, but the next check will kill us if we are not simplectic - - // checks on elements - - std::cout << GridLogMessage << "Checking the structure is " << std::endl; - std::cout << GridLogMessage << "U = ( W X ) " << std::endl; - std::cout << GridLogMessage << " ( -X^* W^* ) " << std::endl; - std::cout <(U,c1,c2); - auto Wstar = PeekIndex(U,c1+nsp,c2+nsp); - auto Ww = conjugate( Wstar ); - auto amizero = sum(W - Ww); - auto amizeroo = TensorRemove(amizero); - assert( amizeroo.real() < 10e-6 ); - amizeroo *= i; - assert( amizeroo.real() < 10e-6 ); - } - - } - - for (int c1 = 0; c1 < nsp ; c1++) - { - for (int c2 = 0; c2 < nsp; c2++) - { - auto X = PeekIndex(U,c1,c2+nsp); - auto minusXstar = PeekIndex(U,c1+nsp,c2); - auto minusXx = conjugate(minusXstar); - auto amizero = sum (X + minusXx); - auto amizeroo = TensorRemove(amizero); - assert( amizeroo.real() < 10e-6 ); - amizeroo *= i; - assert( amizeroo.real() < 10e-6 ); - } - } + std::cout << GridLogMessage << "Run checks:" << std::endl; + SpGroupQuiz(U); + det = sum( Determinant(U) ); + std::cout << GridLogMessage << "Re(Det) after ProjectOnSpGroup (nothing to assert) = " << real(det) / vol << std::endl; + det = det*i; + std::cout << GridLogMessage << "Im(Det) after ProjectOnSpGroup (nothing to assert) = " << real(det) / vol << std::endl; + // ProjectOnGaugeGroup SU::HotConfiguration(pRNG,Umu); //refresh - U = PeekIndex(Umu,1); - + U = PeekIndex(Umu,0); std::cout << GridLogMessage << "Testing ProjectOnGaugeGroup" << std::endl; - U = U + Delta*identity; + U = U + epsilon*identity - i*identity; std::cout << GridLogMessage << "Apply ProjectOnGaugeGroup to deformed matrix" << std::endl; Sp::ProjectOnGaugeGroup(U); - aux = U*adj(U) - identity; - std::cout << GridLogMessage << "U adjU - 1 = " << norm2(aux) << std::endl; - assert( norm2(aux) < 1e-8); - Sp::OmegaInvariance(U); - - std::cout << GridLogMessage << "Checking the structure is " << std::endl; - std::cout << GridLogMessage << "U = ( W X ) " << std::endl; - std::cout << GridLogMessage << " ( -X^* W^* ) " << std::endl; - - for (int c1 = 0; c1 < nsp; c1++) //check on W - { - for (int c2 = 0; c2 < nsp; c2++) - { - auto W = PeekIndex(U,c1,c2); - auto Wstar = PeekIndex(U,c1+nsp,c2+nsp); - auto Ww = conjugate( Wstar ); - auto amizero = sum(W - Ww); - auto amizeroo = TensorRemove(amizero); - assert( amizeroo.real() < 10e-6 ); - amizeroo *= i; - assert( amizeroo.real() < 10e-6 ); - } - - } - - for (int c1 = 0; c1 < nsp ; c1++) - { - for (int c2 = 0; c2 < nsp; c2++) - { - auto X = PeekIndex(U,c1,c2+nsp); - auto minusXstar = PeekIndex(U,c1+nsp,c2); - auto minusXx = conjugate(minusXstar); - auto amizero = sum (X + minusXx); - auto amizeroo = TensorRemove(amizero); - assert( amizeroo.real() < 10e-6 ); - amizeroo *= i; - assert( amizeroo.real() < 10e-6 ); - } - } + std::cout << GridLogMessage <<"Run checks:" << std::endl; + SpGroupQuiz(U); + det = sum( Determinant(U) ); + std::cout << GridLogMessage << "Re(Det) after ProjectOnGaugeGroup (nothing to assert) = " << real(det) / vol << std::endl; + det = det*i; + std::cout << GridLogMessage << "Im(Det) after ProjectOnGaugeGroup (nothing to assert) = " << real(det) / vol << std::endl; + // ProjectGn + SU::HotConfiguration(pRNG,Umu); //refresh + U = PeekIndex(Umu,0); std::cout << GridLogMessage << "Testing ProjectGn" << std::endl; - U = U + Delta*identity; + U = U + epsilon*identity - i*identity; std::cout << GridLogMessage << "Apply ProjectGn to deformed matrix" << std::endl; Sp::ProjectGn(U); - aux = U*adj(U) - identity; - std::cout << GridLogMessage << "U adjU - 1 = " << norm2(aux) << std::endl; - assert( norm2(aux) < 1e-8); - std::cout << GridLogMessage << "Det after ProjectGn = " << norm2( Determinant(U) ) / vol << std::endl; - assert( norm2(aux) - 1 < 1e-8); - Sp::OmegaInvariance(U); - - std::cout << GridLogMessage << "Checking the structure is " << std::endl; - std::cout << GridLogMessage << "U = ( W X ) " << std::endl; - std::cout << GridLogMessage << " ( -X^* W^* ) " << std::endl; - std::cout <(U,c1,c2); - auto Wstar = PeekIndex(U,c1+nsp,c2+nsp); - auto Ww = conjugate( Wstar ); - auto amizero = sum(W - Ww); - auto amizeroo = TensorRemove(amizero); - assert( amizeroo.real() < 10e-6 ); - amizeroo *= i; - assert( amizeroo.real() < 10e-6 ); - } - - } - - for (int c1 = 0; c1 < nsp ; c1++) - { - for (int c2 = 0; c2 < nsp; c2++) - { - auto X = PeekIndex(U,c1,c2+nsp); - auto minusXstar = PeekIndex(U,c1+nsp,c2); - auto minusXx = conjugate(minusXstar); - auto amizero = sum (X + minusXx); - auto amizeroo = TensorRemove(amizero); - assert( amizeroo.real() < 10e-6 ); - amizeroo *= i; - assert( amizeroo.real() < 10e-6 ); - } - } - std::cout <(Umu,0); + std::cout << GridLogMessage << "Testing SpTa" << std::endl; + U = U + epsilon*identity - i*identity; std::cout << GridLogMessage << "Apply SpTa to deformed matrix" << std::endl; U = SpTa(U); - - aux = U - adj(U); - std::cout << GridLogMessage << "SpTa ::: T - Tda = " << norm2(aux) << std::endl; - aux = U + adj(U); - std::cout << GridLogMessage << "SpTa ::: T + Tda = " << norm2(aux) << std::endl; - assert( norm2(aux) - 1 < 1e-8); - - std::cout << GridLogMessage << "Check that Omega T Omega + conj(T) = 0 " << std::endl; - - LatticeColourMatrixD Omega(&Grid); - Sp::Omega(Omega); - aux = Omega*U*Omega + conjugate(U); - assert( norm2(aux) < 1e-8); - - - std::cout << GridLogMessage << "Checking the structure is " << std::endl; - std::cout << GridLogMessage << "U = ( W X ) " << std::endl; - std::cout << GridLogMessage << " ( -X^* W^* ) " << std::endl; - std::cout <(U,c1,c2); - auto Wstar = PeekIndex(U,c1+nsp,c2+nsp); - auto Ww = conjugate( Wstar ); - auto amizero = sum(W - Ww); - auto amizeroo = TensorRemove(amizero); - assert( amizeroo.real() < 10e-6 ); - amizeroo *= i; - assert( amizeroo.real() < 10e-6 ); - } - - } - - for (int c1 = 0; c1 < nsp ; c1++) - { - for (int c2 = 0; c2 < nsp; c2++) - { - auto X = PeekIndex(U,c1,c2+nsp); - auto minusXstar = PeekIndex(U,c1+nsp,c2); - auto minusXx = conjugate(minusXstar); - auto amizero = sum (X + minusXx); - auto amizeroo = TensorRemove(amizero); - assert( amizeroo.real() < 10e-6 ); - amizeroo *= i; - assert( amizeroo.real() < 10e-6 ); - } - } + std::cout << GridLogMessage << "Run checks:" << std::endl; + SpAntiHermitianAlgebraQuiz(U); Grid_finalize();