From 25e9be50b541290d85c38936ceee84b31bd76b75 Mon Sep 17 00:00:00 2001 From: Felix Erben Date: Fri, 2 Jul 2021 15:51:19 +0100 Subject: [PATCH 1/4] created test file --- tests/Test_meson_field.cc | 91 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/Test_meson_field.cc diff --git a/tests/Test_meson_field.cc b/tests/Test_meson_field.cc new file mode 100644 index 00000000..b108ee57 --- /dev/null +++ b/tests/Test_meson_field.cc @@ -0,0 +1,91 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: tests/core/Test_meson_field.cc + +Copyright (C) 2015-2018 + +Author: Felix Erben + +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. + +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 +*************************************************************************************/ + +#include +#include + +using namespace Grid; + +typedef typename DomainWallFermionR::ComplexField ComplexField; +typedef typename DomainWallFermionR::FermionField FermionField; + +int main(int argc, char *argv[]) +{ + // initialization + Grid_init(&argc, &argv); + std::cout << GridLogMessage << "Grid initialized" << std::endl; + + Coordinate latt_size = GridDefaultLatt(); + Coordinate simd_layout = GridDefaultSimd(4, vComplex::Nsimd()); + Coordinate mpi_layout = GridDefaultMpi(); + GridCartesian grid(latt_size,simd_layout,mpi_layout); + + // MesonField lhs and rhs vectors + int mfDim = 10; + std::vector phi(mfDim,&grid); + std::vector rho(mfDim,&grid); + // Gamma matrices used in the contraction + Gamma::Algebra Gmu [] = { + Gamma::Algebra::GammaX, + Gamma::Algebra::GammaY, + Gamma::Algebra::GammaZ, + Gamma::Algebra::GammaT + }; + + // momentum phases e^{ipx} + std::vector> momenta = { + {0.,0.,0.}, + {1.,0.,0.}, + {1.,1.,0.}, + {1.,1.,1.}, + {2.,0.,0.} + }; + std::vector phases(momenta.size(),&grid); + ComplexField coor(&grid); + Complex Ci(0.0,1.0); + for (unsigned int j = 0; j < momenta.size(); ++j) + { + phases[j] = Zero(); + for(unsigned int mu = 0; mu < momenta[j].size(); mu++) + { + LatticeCoordinate(coor, mu); + phases[j] = phases[j] + momenta[j][mu]/GridDefaultLatt()[mu]*coor; + } + phases[j] = exp((Real)(2*M_PI)*Ci*phases[j]); + } + + Eigen::Tensor mf;//(momenta.size(),12,GridDefaultLatt()[3],10,10); + + //execute meson field routine + //A2Autils::MesonField(mf,phi,phi,Gmu,phases,3); + + // epilogue + std::cout << GridLogMessage << "Grid is finalizing now" << std::endl; + Grid_finalize(); + + return EXIT_SUCCESS; +} From 67c3c16fe5762d8dce988ad39d8a391457de5fa9 Mon Sep 17 00:00:00 2001 From: Felix Erben Date: Mon, 5 Jul 2021 14:41:52 +0100 Subject: [PATCH 2/4] working test --- tests/Test_meson_field.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/Test_meson_field.cc b/tests/Test_meson_field.cc index b108ee57..97d3106e 100644 --- a/tests/Test_meson_field.cc +++ b/tests/Test_meson_field.cc @@ -45,11 +45,18 @@ int main(int argc, char *argv[]) GridCartesian grid(latt_size,simd_layout,mpi_layout); // MesonField lhs and rhs vectors - int mfDim = 10; + int mfDim = 3; std::vector phi(mfDim,&grid); std::vector rho(mfDim,&grid); + std::vector seeds({1,2,3,4}); + GridParallelRNG pRNG(&grid); + pRNG.SeedFixedIntegers(seeds); + for (unsigned int i = 0; i < mfDim; ++i){ + random(pRNG,phi[i]); + random(pRNG,rho[i]); //ideally only nonzero on t=0 + } // Gamma matrices used in the contraction - Gamma::Algebra Gmu [] = { + std::vector Gmu = { Gamma::Algebra::GammaX, Gamma::Algebra::GammaY, Gamma::Algebra::GammaZ, @@ -78,10 +85,12 @@ int main(int argc, char *argv[]) phases[j] = exp((Real)(2*M_PI)*Ci*phases[j]); } - Eigen::Tensor mf;//(momenta.size(),12,GridDefaultLatt()[3],10,10); + Eigen::Tensor mf(momenta.size(),Gmu.size(),GridDefaultLatt()[3],mfDim,mfDim); //execute meson field routine - //A2Autils::MesonField(mf,phi,phi,Gmu,phases,3); + A2Autils::MesonField(mf,&phi[0],&phi[0],Gmu,phases,3); + + std::cout << mf << std::endl; // epilogue std::cout << GridLogMessage << "Grid is finalizing now" << std::endl; From fcc4374d7b5fbc6f9933df037b15aa35f15ceffe Mon Sep 17 00:00:00 2001 From: Felix Erben Date: Mon, 5 Jul 2021 14:52:00 +0100 Subject: [PATCH 3/4] i/o done --- tests/Test_meson_field.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/Test_meson_field.cc b/tests/Test_meson_field.cc index 97d3106e..61b5b8be 100644 --- a/tests/Test_meson_field.cc +++ b/tests/Test_meson_field.cc @@ -92,6 +92,21 @@ int main(int argc, char *argv[]) std::cout << mf << std::endl; + std::string FileName = "Meson_Fields"; +#ifdef HAVE_HDF5 + using Default_Reader = Grid::Hdf5Reader; + using Default_Writer = Grid::Hdf5Writer; + FileName.append(".h5"); +#else + using Default_Reader = Grid::BinaryReader; + using Default_Writer = Grid::BinaryWriter; + FileName.append(".bin"); +#endif + + + Default_Writer w(FileName); + write(w,"phi_phi",mf); + // epilogue std::cout << GridLogMessage << "Grid is finalizing now" << std::endl; Grid_finalize(); From d75a66a3e6321fd85497222b1b396fb90bb63480 Mon Sep 17 00:00:00 2001 From: Felix Erben Date: Tue, 6 Jul 2021 11:42:36 +0100 Subject: [PATCH 4/4] test done --- tests/Test_meson_field.cc | 73 ++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/tests/Test_meson_field.cc b/tests/Test_meson_field.cc index 61b5b8be..25d908d7 100644 --- a/tests/Test_meson_field.cc +++ b/tests/Test_meson_field.cc @@ -30,6 +30,9 @@ See the full license in the file "LICENSE" in the top level distribution directo using namespace Grid; +const int TSRC = 0; //timeslice where rho is nonzero +const int VDIM = 5; //length of each vector + typedef typename DomainWallFermionR::ComplexField ComplexField; typedef typename DomainWallFermionR::FermionField FermionField; @@ -38,23 +41,31 @@ int main(int argc, char *argv[]) // initialization Grid_init(&argc, &argv); std::cout << GridLogMessage << "Grid initialized" << std::endl; - + + // Lattice and rng setup Coordinate latt_size = GridDefaultLatt(); Coordinate simd_layout = GridDefaultSimd(4, vComplex::Nsimd()); Coordinate mpi_layout = GridDefaultMpi(); GridCartesian grid(latt_size,simd_layout,mpi_layout); - - // MesonField lhs and rhs vectors - int mfDim = 3; - std::vector phi(mfDim,&grid); - std::vector rho(mfDim,&grid); + int Nt = GridDefaultLatt()[Tp]; + Lattice> t(&grid); + LatticeCoordinate(t, Tp); std::vector seeds({1,2,3,4}); GridParallelRNG pRNG(&grid); pRNG.SeedFixedIntegers(seeds); - for (unsigned int i = 0; i < mfDim; ++i){ + + // MesonField lhs and rhs vectors + std::vector phi(VDIM,&grid); + std::vector rho(VDIM,&grid); + FermionField rho_tmp(&grid); + std::cout << GridLogMessage << "Initialising random meson fields" << std::endl; + for (unsigned int i = 0; i < VDIM; ++i){ random(pRNG,phi[i]); - random(pRNG,rho[i]); //ideally only nonzero on t=0 + random(pRNG,rho_tmp); //ideally only nonzero on t=0 + rho[i] = where((t==TSRC), rho_tmp, 0.*rho_tmp); //ideally only nonzero on t=0 } + std::cout << GridLogMessage << "Meson fields initialised, rho non-zero only for t = " << TSRC << std::endl; + // Gamma matrices used in the contraction std::vector Gmu = { Gamma::Algebra::GammaX, @@ -71,6 +82,10 @@ int main(int argc, char *argv[]) {1.,1.,1.}, {2.,0.,0.} }; + + std::cout << GridLogMessage << "Meson fields will be created for " << Gmu.size() << " Gamma matrices and " << momenta.size() << " momenta." << std::endl; + + std::cout << GridLogMessage << "Computing complex phases" << std::endl; std::vector phases(momenta.size(),&grid); ComplexField coor(&grid); Complex Ci(0.0,1.0); @@ -84,28 +99,46 @@ int main(int argc, char *argv[]) } phases[j] = exp((Real)(2*M_PI)*Ci*phases[j]); } + std::cout << GridLogMessage << "Computing complex phases done." << std::endl; - Eigen::Tensor mf(momenta.size(),Gmu.size(),GridDefaultLatt()[3],mfDim,mfDim); + Eigen::Tensor Mpp(momenta.size(),Gmu.size(),Nt,VDIM,VDIM); + Eigen::Tensor Mpr(momenta.size(),Gmu.size(),Nt,VDIM,VDIM); + Eigen::Tensor Mrr(momenta.size(),Gmu.size(),Nt,VDIM,VDIM); + + // timer + double start,stop; //execute meson field routine - A2Autils::MesonField(mf,&phi[0],&phi[0],Gmu,phases,3); - - std::cout << mf << std::endl; + start = usecond(); + A2Autils::MesonField(Mpp,&phi[0],&phi[0],Gmu,phases,Tp); + stop = usecond(); + std::cout << GridLogMessage << "M(phi,phi) created, execution time " << stop-start << " us" << std::endl; + start = usecond(); + /* Ideally, for this meson field we could pass TSRC (even better a list of timeslices) + * to the routine so that all the compnents which are predictably equal to zero are not computed. */ + A2Autils::MesonField(Mpr,&phi[0],&rho[0],Gmu,phases,Tp); + stop = usecond(); + std::cout << GridLogMessage << "M(phi,rho) created, execution time " << stop-start << " us" << std::endl; + start = usecond(); + A2Autils::MesonField(Mrr,&rho[0],&rho[0],Gmu,phases,Tp); + stop = usecond(); + std::cout << GridLogMessage << "M(rho,rho) created, execution time " << stop-start << " us" << std::endl; std::string FileName = "Meson_Fields"; #ifdef HAVE_HDF5 - using Default_Reader = Grid::Hdf5Reader; - using Default_Writer = Grid::Hdf5Writer; - FileName.append(".h5"); + using Default_Reader = Grid::Hdf5Reader; + using Default_Writer = Grid::Hdf5Writer; + FileName.append(".h5"); #else - using Default_Reader = Grid::BinaryReader; - using Default_Writer = Grid::BinaryWriter; - FileName.append(".bin"); + using Default_Reader = Grid::BinaryReader; + using Default_Writer = Grid::BinaryWriter; + FileName.append(".bin"); #endif - Default_Writer w(FileName); - write(w,"phi_phi",mf); + write(w,"phi_phi",Mpp); + write(w,"phi_rho",Mpr); + write(w,"rho_rho",Mrr); // epilogue std::cout << GridLogMessage << "Grid is finalizing now" << std::endl;