2021-10-12 09:06:15 +01:00
# include <Grid/Grid.h>
using namespace Grid ;
2023-05-02 15:44:34 +01:00
template < typename T >
2023-05-03 01:51:46 +01:00
bool has_correct_group_block_structure ( const T & U ) {
2023-05-02 15:44:34 +01:00
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 < < GridLogMessage < < std : : endl ;
2023-05-03 01:51:46 +01:00
const int nsp = Nc / 2 ;
Complex i ( 0. , 1. ) ;
2023-05-02 15:44:34 +01:00
for ( int c1 = 0 ; c1 < nsp ; c1 + + ) //check on W
{
for ( int c2 = 0 ; c2 < nsp ; c2 + + )
{
auto W = PeekIndex < ColourIndex > ( U , c1 , c2 ) ;
auto Wstar = PeekIndex < ColourIndex > ( 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 < ColourIndex > ( U , c1 , c2 + nsp ) ;
auto minusXstar = PeekIndex < ColourIndex > ( 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 ) ;
}
}
return true ;
} ;
template < typename T >
2023-05-03 01:51:46 +01:00
bool is_element_of_sp2n_group ( T U ) { // does explicitly take a copy in order to not spoil the matrix for further use
2023-05-02 15:44:34 +01:00
LatticeColourMatrixD aux ( U . Grid ( ) ) ;
LatticeColourMatrixD identity ( U . Grid ( ) ) ;
identity = 1.0 ;
std : : cout < < GridLogMessage < < " Unitary check " < < std : : endl ;
aux = U * adj ( U ) - identity ;
std : : cout < < GridLogMessage < < " U adjU - 1 = " < < norm2 ( aux ) < < std : : endl ;
assert ( norm2 ( aux ) < 1e-8 ) ;
std : : cout < < GridLogMessage < < " Checking Omega invariance " < < std : : endl ;
Sp < Nc > : : OmegaInvariance ( U ) ; // no assertion here, but the next check will kill us if we are not simplectic
2023-05-03 01:51:46 +01:00
return has_correct_group_block_structure ( U ) ;
2023-05-02 15:44:34 +01:00
}
template < typename T >
void test_group_projections ( T U ) {
RealD Delta = 666. ;
LatticeColourMatrixD identity ( U . Grid ( ) ) ;
identity = 1.0 ;
std : : cout < < GridLogMessage < < std : : endl ;
std : : cout < < GridLogMessage < < " # # # # " < < std : : endl ;
std : : cout < < GridLogMessage < < " Group " < < std : : endl ;
std : : cout < < GridLogMessage < < " # # # # " < < std : : endl ;
std : : cout < < GridLogMessage < < std : : endl ;
std : : string name = " ProjectOnSpGroup " ;
std : : cout < < GridLogMessage < < " Testing " < < name < < std : : endl ;
std : : cout < < GridLogMessage < < " Apply to deformed matrix " < < std : : endl ;
2023-05-03 01:51:46 +01:00
U = U + Delta * identity ;
2023-05-02 15:44:34 +01:00
U = ProjectOnSpGroup ( U ) ;
2023-05-03 01:51:46 +01:00
assert ( is_element_of_sp2n_group ( U ) ) ;
2023-05-02 15:44:34 +01:00
name = " ProjectOnGaugeGroup " ;
std : : cout < < GridLogMessage < < " Testing " < < name < < std : : endl ;
std : : cout < < GridLogMessage < < " Apply to deformed matrix " < < std : : endl ;
U = U + Delta * identity ;
Sp < Nc > : : ProjectOnGaugeGroup ( U ) ;
2023-05-03 01:51:46 +01:00
assert ( is_element_of_sp2n_group ( U ) ) ;
2023-05-02 15:44:34 +01:00
name = " ProjectGn " ;
std : : cout < < GridLogMessage < < " Testing " < < name < < std : : endl ;
std : : cout < < GridLogMessage < < " Apply to deformed matrix " < < std : : endl ;
U = U + Delta * identity ;
Sp < Nc > : : ProjectGn ( U ) ;
2023-05-03 01:51:46 +01:00
assert ( is_element_of_sp2n_group ( U ) ) ;
2023-05-02 15:44:34 +01:00
}
2021-10-12 09:06:15 +01:00
int main ( int argc , char * * argv )
{
2021-10-13 15:07:23 +01:00
Grid_init ( & argc , & argv ) ;
2021-10-12 09:06:15 +01:00
Coordinate latt_size = GridDefaultLatt ( ) ;
Coordinate simd_layout = GridDefaultSimd ( Nd , vComplex : : Nsimd ( ) ) ;
Coordinate mpi_layout = GridDefaultMpi ( ) ;
GridCartesian Grid ( latt_size , simd_layout , mpi_layout ) ;
LatticeGaugeField Umu ( & Grid ) ;
LatticeColourMatrixD U ( & Grid ) ;
2023-04-04 17:48:13 +01:00
LatticeColourMatrixD Up ( & Grid ) ;
2021-10-12 12:12:16 +01:00
LatticeColourMatrixD aux ( & Grid ) ;
LatticeColourMatrixD identity ( & Grid ) ;
2023-04-03 16:31:19 +01:00
// 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
2022-11-30 14:27:19 +00:00
const int nsp = Nc / 2 ;
2021-10-13 15:07:23 +01:00
2021-10-12 12:12:16 +01:00
identity = 1.0 ;
RealD epsilon = 0.01 ;
2023-04-06 12:08:17 +01:00
RealD Delta = 666. ;
2021-10-12 12:12:16 +01:00
Complex i ( 0. , 1. ) ;
RealD u = 0. ;
double vol = Umu . Grid ( ) - > gSites ( ) ;
2021-10-12 09:06:15 +01:00
std : : vector < int > pseeds ( { 1 , 2 , 3 , 4 , 5 } ) ;
GridParallelRNG pRNG ( & Grid ) ; pRNG . SeedFixedIntegers ( pseeds ) ;
SU < Nc > : : HotConfiguration ( pRNG , Umu ) ;
2023-04-03 16:31:19 +01:00
U = PeekIndex < LorentzIndex > ( Umu , 0 ) ;
2021-10-12 12:12:16 +01:00
aux = U * adj ( U ) - identity ;
2021-10-13 15:07:23 +01:00
std : : cout < < GridLogMessage < < " Starting with random SUn matrix " < < std : : endl ;
std : : cout < < GridLogMessage < < " Unitary check " < < std : : endl ;
2021-10-12 12:12:16 +01:00
std : : cout < < GridLogMessage < < " U adjU - 1 = " < < norm2 ( aux ) < < std : : endl ;
2021-10-13 15:07:23 +01:00
assert ( norm2 ( aux ) < 1e-8 ) ;
2021-10-12 12:12:16 +01:00
std : : cout < < GridLogMessage < < std : : endl ;
2021-10-13 15:07:23 +01:00
if ( Nc ! = 2 )
{
2021-10-22 10:44:54 +01:00
std : : cout < < GridLogMessage < < " This matrix should not leave Omega invariant, expect a warning " < < std : : endl ;
2021-10-13 15:07:23 +01:00
}
2022-11-23 19:40:28 +00:00
Sp < Nc > : : OmegaInvariance ( U ) ;
2021-10-12 12:12:16 +01:00
std : : cout < < GridLogMessage < < std : : endl ;
2021-10-12 09:06:15 +01:00
2021-10-12 12:12:16 +01:00
U = U + epsilon * identity ;
aux = U * adj ( U ) - identity ;
2021-10-12 09:06:15 +01:00
2021-10-13 15:07:23 +01:00
std : : cout < < GridLogMessage < < " Unitary matrix deformed " < < std : : endl ;
2021-10-12 12:12:16 +01:00
std : : cout < < GridLogMessage < < " now U adjU - 1 = " < < norm2 ( aux ) < < std : : endl ;
2023-04-03 16:31:19 +01:00
2023-05-02 15:44:34 +01:00
test_group_projections ( U ) ;
2023-04-03 16:31:19 +01:00
2023-04-04 17:48:13 +01:00
std : : cout < < GridLogMessage < < std : : endl ;
std : : cout < < GridLogMessage < < " # # # # " < < std : : endl ;
std : : cout < < GridLogMessage < < " Algebra " < < std : : endl ;
std : : cout < < GridLogMessage < < " # # # # " < < std : : endl ;
std : : cout < < GridLogMessage < < std : : endl ;
std : : cout < < GridLogMessage < < " Testing SpTa " < < std : : endl ;
2021-10-12 12:12:16 +01:00
2023-04-03 16:31:19 +01:00
U = PeekIndex < LorentzIndex > ( Umu , 1 ) ;
2023-04-06 12:08:17 +01:00
U = U + Delta * identity ;
2023-04-03 16:31:19 +01:00
std : : cout < < GridLogMessage < < " Matrix deformed " < < std : : endl ;
2023-04-04 17:48:13 +01:00
std : : cout < < GridLogMessage < < " Apply SpTa to deformed matrix " < < std : : endl ;
U = SpTa ( U ) ;
2023-04-03 16:31:19 +01:00
2023-04-04 17:48:13 +01:00
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 ;
2023-04-03 16:31:19 +01:00
2023-04-04 17:48:13 +01:00
std : : cout < < GridLogMessage < < " Check that Omega U Omega = conj(U) " < < std : : endl ;
LatticeColourMatrixD Omega ( & Grid ) ;
2023-04-03 16:31:19 +01:00
Sp < Nc > : : Omega ( Omega ) ;
aux = Omega * U * Omega - conjugate ( U ) ;
std : : cout < < GridLogMessage < < " Omega U Omega - conj(U) = " < < norm2 ( aux ) < < std : : endl ;
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 < < GridLogMessage < < std : : endl ;
for ( int c1 = 0 ; c1 < nsp ; c1 + + ) //check on W
2021-10-12 12:12:16 +01:00
{
2023-04-03 16:31:19 +01:00
for ( int c2 = 0 ; c2 < nsp ; c2 + + )
{
auto W = PeekIndex < ColourIndex > ( U , c1 , c2 ) ;
auto Wstar = PeekIndex < ColourIndex > ( 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 ) ;
}
}
2021-10-12 12:12:16 +01:00
2023-04-03 16:31:19 +01:00
for ( int c1 = 0 ; c1 < nsp ; c1 + + )
{
for ( int c2 = 0 ; c2 < nsp ; c2 + + )
{
auto X = PeekIndex < ColourIndex > ( U , c1 , c2 + nsp ) ;
auto minusXstar = PeekIndex < ColourIndex > ( 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 ) ;
}
}
2023-04-04 17:48:13 +01:00
//test Ta
/*
U = U + 666. * identity ;
Up = Ta ( U ) ;
aux = Up - adj ( Up ) ;
std : : cout < < GridLogMessage < < " TA !!! T - Tda = " < < norm2 ( aux ) < < std : : endl ;
aux = Up + adj ( Up ) ;
std : : cout < < GridLogMessage < < " TA !!! T + Tda = " < < norm2 ( aux ) < < std : : endl ; */
// test taProj
std : : cout < < GridLogMessage < < " Testing taProj " < < std : : endl ;
2023-04-06 12:08:17 +01:00
U = U + Delta * identity ;
2023-04-04 17:48:13 +01:00
std : : cout < < GridLogMessage < < " Matrix deformed " < < std : : endl ;
std : : cout < < GridLogMessage < < " Apply taProj to deformed matrix " < < std : : endl ;
Sp < Nc > : : taProj ( U , Up ) ;
aux = Up - adj ( Up ) ;
std : : cout < < GridLogMessage < < " taProj ::: T - Tda = " < < norm2 ( aux ) < < std : : endl ;
aux = Up + adj ( Up ) ;
std : : cout < < GridLogMessage < < " taProj ::: T + Tda = " < < norm2 ( aux ) < < std : : endl ;
std : : cout < < GridLogMessage < < " Check that Omega U Omega = conj(U) " < < std : : endl ;
Sp < Nc > : : Omega ( Omega ) ;
aux = Omega * Up * Omega - conjugate ( Up ) ;
std : : cout < < GridLogMessage < < " Omega U Omega - conj(U) = " < < norm2 ( aux ) < < std : : endl ;
assert ( norm2 ( aux ) < 1e-8 ) ;
// before it was
aux = Omega * U * Omega - conjugate ( U ) ;
std : : cout < < GridLogMessage < < " before taProj Omega U Omega - conj(U) = " < < norm2 ( aux ) < < std : : endl ;
U = Up ;
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 < < GridLogMessage < < std : : endl ;
for ( int c1 = 0 ; c1 < nsp ; c1 + + ) //check on W
{
for ( int c2 = 0 ; c2 < nsp ; c2 + + )
{
auto W = PeekIndex < ColourIndex > ( U , c1 , c2 ) ;
auto Wstar = PeekIndex < ColourIndex > ( 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 < ColourIndex > ( U , c1 , c2 + nsp ) ;
auto minusXstar = PeekIndex < ColourIndex > ( 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 ) ;
}
}
2023-04-06 12:08:17 +01:00
2021-10-12 09:06:15 +01:00
Grid_finalize ( ) ;
}