1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-14 01:35:36 +00:00
Grid/tests/sp2n/Test_project_on_Sp.cc

241 lines
7.7 KiB
C++
Raw Normal View History

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 02:39:36 +01:00
bool has_correct_group_block_structure(const T& 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 << GridLogMessage << std::endl;
const int nsp = Nc / 2;
Complex i(0., 1.);
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);
2023-05-02 15:44:34 +01:00
}
2023-05-03 02:39:36 +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-05-02 15:44:34 +01:00
}
2023-05-03 02:39:36 +01:00
}
return true;
2023-05-02 15:44:34 +01:00
};
template <typename T>
bool is_element_of_sp2n_group(const T& U) {
2023-05-03 02:39:36 +01:00
LatticeColourMatrixD aux(U.Grid());
LatticeColourMatrixD identity(U.Grid());
identity = 1.0;
LatticeColourMatrixD Omega(U.Grid());
Sp<Nc>::Omega(Omega);
std::cout << GridLogMessage << "Check matrix is non-zero " << std::endl;
assert(norm2(U) > 1e-8);
2023-05-03 02:39:36 +01:00
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);
aux = Omega - (U * Omega * transpose(U));
std::cout << GridLogMessage << "Omega - U Omega transpose(U) = " << norm2(aux)
<< std::endl;
assert(norm2(aux) < 1e-8);
std::cout << GridLogMessage
<< "|Det| = " << norm2(Determinant(U)) / U.Grid()->gSites()
<< std::endl;
assert(norm2(Determinant(U)) / U.Grid()->gSites() - 1 < 1e-8);
2023-05-03 02:39:36 +01:00
2023-05-03 01:51:46 +01:00
return has_correct_group_block_structure(U);
2023-05-02 15:44:34 +01:00
}
2023-05-03 02:39:36 +01:00
template <typename T>
2023-05-02 15:44:34 +01:00
void test_group_projections(T U) {
2023-05-03 02:39:36 +01:00
RealD Delta = 666.;
LatticeColourMatrixD identity(U.Grid());
identity = 1.0;
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;
U = U + Delta * identity;
U = ProjectOnSpGroup(U);
assert(is_element_of_sp2n_group(U));
name = "ProjectOnGeneralGroup";
2023-05-03 02:39:36 +01:00
std::cout << GridLogMessage << "Testing " << name << std::endl;
std::cout << GridLogMessage << "Apply to deformed matrix" << std::endl;
U = U + Delta * identity;
U = Sp<Nc>::ProjectOnGeneralGroup(U);
2023-05-03 02:39:36 +01:00
assert(is_element_of_sp2n_group(U));
name = "ProjectOnSpecialGroup";
2023-05-03 02:39:36 +01:00
std::cout << GridLogMessage << "Testing " << name << std::endl;
std::cout << GridLogMessage << "Apply to deformed matrix" << std::endl;
U = U + Delta * identity;
Sp<Nc>::ProjectOnSpecialGroup(U);
2023-05-03 02:39:36 +01:00
assert(is_element_of_sp2n_group(U));
2023-07-03 18:00:32 +01:00
name = "ProjectSpn";
std::cout << GridLogMessage << "Testing " << name << std::endl;
std::cout << GridLogMessage << "Apply to deformed matrix" << std::endl;
U = U + Delta * identity;
ProjectSpn(U);
assert(is_element_of_sp2n_group(U));
2023-05-02 15:44:34 +01:00
}
2023-05-03 02:39:36 +01:00
template <typename T>
2023-05-03 02:32:42 +01:00
bool has_correct_algebra_block_structure(const T& U) {
// this only checks for the anti-hermitian part of the algebra
2023-05-03 02:39:36 +01:00
const int nsp = Nc / 2;
Complex i(0., 1.);
2023-05-03 02:32:42 +01:00
std::cout << GridLogMessage << "Checking the structure is " << std::endl;
2023-05-03 16:15:12 +01:00
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<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);
}
2023-05-03 16:15:12 +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-05-03 16:15:12 +01:00
}
2023-05-03 02:39:36 +01:00
return true;
2023-05-03 02:32:42 +01:00
}
2023-05-03 02:39:36 +01:00
template <typename T>
bool is_element_of_sp2n_algebra(const T& U) {
2023-05-03 02:39:36 +01:00
LatticeColourMatrixD aux(U.Grid());
LatticeColourMatrixD identity(U.Grid());
identity = 1.0;
LatticeColourMatrixD Omega(U.Grid());
Sp<Nc>::Omega(Omega);
std::cout << GridLogMessage << "Check matrix is non-zero " << std::endl;
assert(norm2(U) > 1e-8);
2023-05-03 02:39:36 +01:00
aux = U - adj(U);
std::cout << GridLogMessage << "T - Tda = " << norm2(aux)
<< " (not supposed to vanish)" << std::endl;
2023-05-03 02:39:36 +01:00
aux = U + adj(U);
std::cout << GridLogMessage << "T + Tda = " << norm2(aux)
<< " (supposed to vanish)" << std::endl;
assert(norm2(aux) - 1 < 1e-8);
2023-05-03 02:39:36 +01:00
std::cout << GridLogMessage << "Check that Omega T Omega + conj(T) = 0 "
2023-05-03 02:39:36 +01:00
<< std::endl;
aux = Omega * U * Omega + conjugate(U);
2023-05-03 02:39:36 +01:00
assert(norm2(aux) < 1e-8);
return has_correct_algebra_block_structure(U);
2023-05-03 02:32:42 +01:00
}
2023-05-03 02:39:36 +01:00
template <typename T>
2023-05-03 02:32:42 +01:00
void test_algebra_projections(T U) {
2023-05-03 02:39:36 +01:00
RealD Delta = 666.;
LatticeColourMatrixD tmp(U.Grid());
LatticeColourMatrixD identity(U.Grid());
identity = 1.0;
std::cout << GridLogMessage << "# # # #" << std::endl;
std::cout << GridLogMessage << "Algebra" << std::endl;
std::cout << GridLogMessage << "# # # #" << std::endl;
std::cout << GridLogMessage << std::endl;
std::string name = "SpTa";
std::cout << GridLogMessage << "Testing " << name << std::endl;
std::cout << GridLogMessage << "Apply to deformed matrix" << std::endl;
U = U + Delta * identity;
U = SpTa(U);
assert(is_element_of_sp2n_algebra(U));
name = "TaProj";
std::cout << GridLogMessage << "Testing " << name << std::endl;
std::cout << GridLogMessage << "Apply to deformed matrix" << std::endl;
U = U + Delta * identity;
Sp<Nc>::taProj(U, tmp);
U = tmp;
assert(is_element_of_sp2n_algebra(U));
}
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();
GridCartesian Grid(latt_size, simd_layout, mpi_layout);
LatticeGaugeField Umu(&Grid);
LatticeColourMatrixD U(&Grid);
// Will test resimplectification-related functionalities (from
// ProjectOnGeneralGroup, ProjectOnSpGroup, ProjectOnSpecialGroup) and projection on the
// algebra (from SpTa)
// ProjectOnGeneralGroup, ProjectOnSpGroup project on the non-special group allowi for complex determinants of module 1
// ProjectOnSpecialGroup projects on the full gauge group providing a determinant equals to 1
2023-05-03 02:39:36 +01:00
std::vector<int> pseeds({1, 2, 3, 4, 5});
GridParallelRNG pRNG(&Grid);
pRNG.SeedFixedIntegers(pseeds);
SU<Nc>::HotConfiguration(pRNG, Umu);
U = PeekIndex<LorentzIndex>(Umu, 0);
test_group_projections(U);
U = PeekIndex<LorentzIndex>(Umu, 1);
test_algebra_projections(U);
2021-10-12 09:06:15 +01:00
2023-05-03 02:39:36 +01:00
Grid_finalize();
2021-10-12 09:06:15 +01:00
}