From 5364d580c9fac0fb86e3adbda5623e80a7a2559c Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Tue, 13 May 2025 18:42:44 -0400 Subject: [PATCH] Output chirality, eigenvector density files and python source lego plot --- tests/lanczos/Test_dwf_G5R5.cc | 81 +++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 7 deletions(-) diff --git a/tests/lanczos/Test_dwf_G5R5.cc b/tests/lanczos/Test_dwf_G5R5.cc index 0fd1bc35..fb3a95c3 100644 --- a/tests/lanczos/Test_dwf_G5R5.cc +++ b/tests/lanczos/Test_dwf_G5R5.cc @@ -31,12 +31,23 @@ directory using namespace std; using namespace Grid; - ; //typedef WilsonFermionD FermionOp; typedef DomainWallFermionD FermionOp; typedef typename DomainWallFermionD::FermionField FermionField; +template void writeFile(T& in, std::string const fname){ +#ifdef HAVE_LIME + // Ref: https://github.com/paboyle/Grid/blob/feature/scidac-wp1/tests/debug/Test_general_coarse_hdcg_phys48.cc#L111 + std::cout << Grid::GridLogMessage << "Writes to: " << fname << std::endl; + Grid::emptyUserRecord record; + Grid::ScidacWriter WR(in.Grid()->IsBoss()); + WR.open(fname); + WR.writeScidacFieldRecord(in,record,0); + WR.close(); +#endif + // What is the appropriate way to throw error? +} RealD AllZero(RealD x) { return 0.; } @@ -121,7 +132,7 @@ int main(int argc, char** argv) { int Ls=16; RealD M5=1.8; - RealD mass = -1.0; + RealD mass = 0.01; mass=LanParams.mass; Ls=LanParams.Ls; @@ -159,10 +170,10 @@ int main(int argc, char** argv) { U[mu] = PeekIndex(Umu, mu); } */ - - int Nstop = 10; int Nk = 20; + int Nstop = Nk; int Np = 80; + Nstop=LanParams.Nstop; Nk=LanParams.Nk; Np=LanParams.Np; @@ -201,8 +212,12 @@ int main(int argc, char** argv) { int Nconv; IRL.calc(eval, evec, src, Nconv); - std::cout << mass <<" : " << eval << std::endl; - + std::cout << mass <<" : " << eval << std::endl; + std::cout << " #evecs " << evec.size() << std::endl; + std::cout << " Nconv " << Nconv << std::endl; + std::cout << " Nm " << Nm << std::endl; + if ( Nconv > evec.size() ) Nconv = evec.size(); + #if 0 Gamma g5(Gamma::Algebra::Gamma5) ; ComplexD dot; @@ -232,6 +247,7 @@ int main(int argc, char** argv) { vector finalevec(Nconv, FGrid); vector eMe(Nconv), eMMe(Nconv); for(int i = 0; i < Nconv; i++){ + cout << "calculate the matrix element["<: " << endl; @@ -326,13 +342,27 @@ int main(int argc, char** argv) { axpby_ssp(G5evec[i], -1., finalevec[i], 0., G5evec[i], j, j); } } + for(int i = 0; i < Nconv; i++){ chiral_matrix_real[i].resize(Nconv); chiral_matrix[i].resize(Nconv); + + std::string evfile("./evec_density"); + evfile = evfile+"_"+std::to_string(i); + auto evdensity = localInnerProduct(finalevec[i],finalevec[i] ); + writeFile(evdensity,evfile); + for(int j = 0; j < Nconv; j++){ chiral_matrix[i][j] = innerProduct(finalevec[i], G5evec[j]); + std::cout <<" chiral_matrix_real signed "< 0.8 ) { + auto g5density = localInnerProduct(finalevec[i], G5evec[j]); + std::string chfile("./chiral_density_"); + chfile = chfile +std::to_string(i)+"_"+std::to_string(j); + writeFile(g5density,chfile); + } } } for(int i = 0; i < Nconv; i++){ @@ -341,6 +371,43 @@ int main(int argc, char** argv) { } } - + FILE *fp = fopen("lego-plot.py","w"); assert(fp!=NULL); +#define PYTHON_LINE(A) fprintf(fp,A"\n"); + PYTHON_LINE("import matplotlib.pyplot as plt"); + PYTHON_LINE("import numpy as np"); + PYTHON_LINE(""); + PYTHON_LINE("fig = plt.figure()"); + PYTHON_LINE("ax = fig.add_subplot(projection='3d')"); + PYTHON_LINE(""); + PYTHON_LINE("x, y = np.random.rand(2, 100) * 4"); + PYTHON_LINE("hist, xedges, yedges = np.histogram2d(x, y, bins=10, range=[[0, 9], [0, 9]])"); + PYTHON_LINE(""); + PYTHON_LINE("# Construct arrays for the anchor positions of the 16 bars"); + PYTHON_LINE("xpos, ypos = np.meshgrid(xedges[:-1] + 0.25, yedges[:-1] + 0.25, indexing=\"ij\")"); + PYTHON_LINE("xpos = xpos.ravel()"); + PYTHON_LINE("ypos = ypos.ravel()"); + PYTHON_LINE("zpos = 0"); + PYTHON_LINE(""); + PYTHON_LINE("# Construct arrays with the dimensions for the 16 bars."); + PYTHON_LINE("dx = dy = 0.5 * np.ones_like(zpos)"); + PYTHON_LINE("dz = np.array(["); + for(int i = 0; i < Nconv; i++){ + fprintf(fp,"\t[ "); + for(int j = 0; j < Nconv; j++){ + fprintf(fp,"%lf ",chiral_matrix_real[i][j]); + if(j