From 3f0f92cda6cdc213e5bb39f981774d96e505cc8e Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 6 Aug 2018 12:11:52 +0100 Subject: [PATCH] Hadrons: first cleaning/integration of A2A/meson fields --- extras/Hadrons/AllToAllVectors.hpp | 10 ++ extras/Hadrons/DilutedNoise.hpp | 2 - .../Modules/MContraction/A2AMesonField.hpp | 29 ++-- .../MNoise/TimeDilutedSpinColorDiagonal.cc | 1 + .../MNoise/TimeDilutedSpinColorDiagonal.hpp | 1 + extras/Hadrons/Modules/MSolver/A2AVectors.cc | 4 +- extras/Hadrons/Modules/MSolver/A2AVectors.hpp | 155 +++++++----------- 7 files changed, 89 insertions(+), 113 deletions(-) diff --git a/extras/Hadrons/AllToAllVectors.hpp b/extras/Hadrons/AllToAllVectors.hpp index 7d9aa62e..b21b6862 100644 --- a/extras/Hadrons/AllToAllVectors.hpp +++ b/extras/Hadrons/AllToAllVectors.hpp @@ -51,6 +51,16 @@ class A2AModesSchurDiagTwo v_high_4d.resize(size_4d, grid_4d); } + int get_Nh(void) const + { + return Nh; + } + + int get_Nl(void) const + { + return Nl; + } + void high_modes(Field &source_5d, Field &w_source_5d, Field &source_4d, int i) { int i5d; diff --git a/extras/Hadrons/DilutedNoise.hpp b/extras/Hadrons/DilutedNoise.hpp index 304b210d..a284d46b 100644 --- a/extras/Hadrons/DilutedNoise.hpp +++ b/extras/Hadrons/DilutedNoise.hpp @@ -142,7 +142,6 @@ void TimeDilutedSpinColorDiagonalNoise::generateNoise(GridParallelRNG &rn LatticeCoordinate(tLat, nd - 1); bernoulli(rng, eta); eta = (2.*eta - shift)*(1./::sqrt(2.)); - std::cout << eta << std::endl; for (unsigned int t = 0; t < nt_; ++t) { etaCut = where((tLat == t), eta, 0.*eta); @@ -154,7 +153,6 @@ void TimeDilutedSpinColorDiagonalNoise::generateNoise(GridParallelRNG &rn { noise[i] = zero; pokeColour(noise[i], etas, c); - std::cout << noise[i] << std::endl; i++; } } diff --git a/extras/Hadrons/Modules/MContraction/A2AMesonField.hpp b/extras/Hadrons/Modules/MContraction/A2AMesonField.hpp index df203e6f..9a09c0b6 100644 --- a/extras/Hadrons/Modules/MContraction/A2AMesonField.hpp +++ b/extras/Hadrons/Modules/MContraction/A2AMesonField.hpp @@ -24,8 +24,6 @@ class A2AMesonFieldPar : Serializable int, cacheBlock, int, schurBlock, int, Nmom, - int, N, - int, Nl, std::string, A2A, std::string, output); }; @@ -82,9 +80,7 @@ TA2AMesonField::TA2AMesonField(const std::string name) template std::vector TA2AMesonField::getInput(void) { - std::vector in = {par().A2A + "_class"}; - in.push_back(par().A2A + "_w_high_4d"); - in.push_back(par().A2A + "_v_high_4d"); + std::vector in = {par().A2A}; return in; } @@ -102,18 +98,17 @@ std::vector TA2AMesonField::getOutput(void) template void TA2AMesonField::setup(void) { - auto &a2a = envGet(A2ABase, par().A2A + "_class"); - int nt = env().getDim(Tp); - int Nl = par().Nl; - int N = par().N; - int Ls_ = env().getObjectLs(par().A2A + "_class"); + auto &a2a = envGet(A2ABase, par().A2A); + int Ls = env().getObjectLs(par().A2A); // Four D fields - envTmp(std::vector, "w", 1, par().schurBlock, FermionField(env().getGrid(1))); - envTmp(std::vector, "v", 1, par().schurBlock, FermionField(env().getGrid(1))); + envTmp(std::vector, "w", 1, par().schurBlock, + FermionField(env().getGrid())); + envTmp(std::vector, "v", 1, par().schurBlock, + FermionField(env().getGrid())); // 5D tmp - envTmpLat(FermionField, "tmp_5d", Ls_); + envTmpLat(FermionField, "tmp_5d", Ls); } @@ -305,7 +300,7 @@ void TA2AMesonField::execute(void) { LOG(Message) << "Computing A2A meson field" << std::endl; - auto &a2a = envGet(A2ABase, par().A2A + "_class"); + auto &a2a = envGet(A2ABase, par().A2A); // 2+6+4+4 = 16 gammas // Ordering defined here @@ -335,8 +330,9 @@ void TA2AMesonField::execute(void) int nx = env().getDim(Xp); int ny = env().getDim(Yp); int nz = env().getDim(Zp); - int N = par().N; - int Nl = par().Nl; + int Nl = a2a.get_Nl(); + int N = Nl + a2a.get_Nh(); + int ngamma = gammas.size(); int schurBlock = par().schurBlock; @@ -407,7 +403,6 @@ void TA2AMesonField::execute(void) int N_iii = MIN(N_ii-ii,cacheBlock); int N_jjj = MIN(N_jj-jj,cacheBlock); - Eigen::Tensor mesonFieldBlocked(nmom,ngamma,nt,N_iii,N_jjj); t_contr-=usecond(); diff --git a/extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc b/extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc index e02c359a..472a0b4d 100644 --- a/extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc +++ b/extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc @@ -5,3 +5,4 @@ using namespace Hadrons; using namespace MNoise; template class Grid::Hadrons::MNoise::TTimeDilutedSpinColorDiagonal; +template class Grid::Hadrons::MNoise::TTimeDilutedSpinColorDiagonal; diff --git a/extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp b/extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp index 1f6e89f9..7e2a471f 100644 --- a/extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp +++ b/extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp @@ -31,6 +31,7 @@ public: }; MODULE_REGISTER_TMP(TimeDilutedSpinColorDiagonal, TTimeDilutedSpinColorDiagonal, MNoise); +MODULE_REGISTER_TMP(ZTimeDilutedSpinColorDiagonal, TTimeDilutedSpinColorDiagonal, MNoise); /****************************************************************************** * TTimeDilutedSpinColorDiagonal implementation * diff --git a/extras/Hadrons/Modules/MSolver/A2AVectors.cc b/extras/Hadrons/Modules/MSolver/A2AVectors.cc index f72f405d..477d0b72 100644 --- a/extras/Hadrons/Modules/MSolver/A2AVectors.cc +++ b/extras/Hadrons/Modules/MSolver/A2AVectors.cc @@ -4,5 +4,5 @@ using namespace Grid; using namespace Hadrons; using namespace MSolver; -template class Grid::Hadrons::MSolver::TA2AVectors; -template class Grid::Hadrons::MSolver::TA2AVectors; +template class Grid::Hadrons::MSolver::TA2AVectors>; +template class Grid::Hadrons::MSolver::TA2AVectors>; diff --git a/extras/Hadrons/Modules/MSolver/A2AVectors.hpp b/extras/Hadrons/Modules/MSolver/A2AVectors.hpp index d7e4cfe4..20fa7c2e 100644 --- a/extras/Hadrons/Modules/MSolver/A2AVectors.hpp +++ b/extras/Hadrons/Modules/MSolver/A2AVectors.hpp @@ -7,6 +7,7 @@ #include #include #include +#include BEGIN_HADRONS_NAMESPACE @@ -21,26 +22,20 @@ public: GRID_SERIALIZABLE_CLASS_MEMBERS(A2AVectorsPar, bool, return_5d, int, Nl, - int, N, - std::vector, sources, + std::string, noise, std::string, action, std::string, eigenPack, std::string, solver); }; -template +template class TA2AVectors : public Module { - public: +public: FERM_TYPE_ALIASES(FImpl,); SOLVER_TYPE_ALIASES(FImpl,); - - typedef FermionEigenPack EPack; - typedef CoarseFermionEigenPack CoarseEPack; - - typedef A2AModesSchurDiagTwo A2ABase; - - public: + typedef A2AModesSchurDiagTwo A2ABase; +public: // constructor TA2AVectors(const std::string name); // destructor @@ -53,46 +48,37 @@ class TA2AVectors : public Module virtual void setup(void); // execution virtual void execute(void); - - private: - unsigned int Ls_; - std::string className_; }; -MODULE_REGISTER_TMP(A2AVectors, ARG(TA2AVectors), MSolver); -MODULE_REGISTER_TMP(ZA2AVectors, ARG(TA2AVectors), MSolver); +MODULE_REGISTER_TMP(A2AVectors, + ARG(TA2AVectors>), MSolver); +MODULE_REGISTER_TMP(ZA2AVectors, + ARG(TA2AVectors>), MSolver); /****************************************************************************** * TA2AVectors implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -template -TA2AVectors::TA2AVectors(const std::string name) +template +TA2AVectors::TA2AVectors(const std::string name) : Module(name) -, className_ (name + "_class") {} // dependencies/products /////////////////////////////////////////////////////// -template -std::vector TA2AVectors::getInput(void) +template +std::vector TA2AVectors::getInput(void) { int Nl = par().Nl; std::string sub_string = ""; if (Nl > 0) sub_string = "_subtract"; - std::vector in = {par().solver + sub_string}; - int n = par().sources.size(); - - for (unsigned int t = 0; t < n; t += 1) - { - in.push_back(par().sources[t]); - } + std::vector in = {par().solver + sub_string, par().noise}; return in; } -template -std::vector TA2AVectors::getReference(void) +template +std::vector TA2AVectors::getReference(void) { std::vector ref = {par().action}; @@ -104,22 +90,21 @@ std::vector TA2AVectors::getReference(void) return ref; } -template -std::vector TA2AVectors::getOutput(void) +template +std::vector TA2AVectors::getOutput(void) { - std::vector out = {getName(), className_}; + std::vector out = {getName()}; return out; } // setup /////////////////////////////////////////////////////////////////////// -template -void TA2AVectors::setup(void) +template +void TA2AVectors::setup(void) { - int N = par().N; int Nl = par().Nl; - int Nh = N - Nl; - bool return_5d = par().return_5d; + bool return_5d = par().return_5d; + auto &noise = envGet(DilutedNoise, par().noise); int Ls; std::string sub_string = ""; @@ -139,94 +124,80 @@ void TA2AVectors::setup(void) if (Nl > 0) { // Low modes - auto &epack = envGet(EPack, par().eigenPack); + auto &epack = envGet(Pack, par().eigenPack); LOG(Message) << "Creating a2a vectors " << getName() << " using eigenpack '" << par().eigenPack << "' (" << epack.evec.size() << " modes)" << - " and " << Nh << " high modes." << std::endl; + " and " << noise.size() << " high modes." << std::endl; evec = &epack.evec; eval = &epack.eval; } else { LOG(Message) << "Creating a2a vectors " << getName() << - " using " << Nh << " high modes only." << std::endl; + " using " << noise.size() << " high modes only." << std::endl; } - envCreate(A2ABase, className_, Ls, - evec, eval, - action, - solver, - Nl, Nh, - return_5d); + envCreate(A2ABase, getName(), Ls, evec, eval, action, solver, Nl, noise.size(), + return_5d); } // execution /////////////////////////////////////////////////////////////////// -template -void TA2AVectors::execute(void) +template +void TA2AVectors::execute(void) { auto &action = envGet(FMat, par().action); + auto &noise = envGet(DilutedNoise, par().noise); - int Nt = env().getDim(Tp); - int Nc = FImpl::Dimension; - int Ls_; + int Ls; int Nl = par().Nl; std::string sub_string = ""; if (Nl > 0) sub_string = "_subtract"; - Ls_ = env().getObjectLs(par().solver + sub_string); + Ls = env().getObjectLs(par().solver + sub_string); - auto &a2areturn = envGet(A2ABase, className_); + auto &a2areturn = envGet(A2ABase, getName()); // High modes - auto sources = par().sources; - int Nsrc = par().sources.size(); - envGetTmp(FermionField, ferm_src); envGetTmp(FermionField, unphys_ferm); envGetTmp(FermionField, tmp); - - int N_count = 0; - for (unsigned int s = 0; s < Ns; ++s) - for (unsigned int c = 0; c < Nc; ++c) - for (unsigned int T = 0; T < Nsrc; T++) + for (unsigned int i = 0; i < noise.size(); i++) + { + LOG(Message) << "A2A src for noise vector " << i << std::endl; + // source conversion for 4D sources + if (!env().isObject5d(par().noise)) { - auto &prop_src = envGet(PropagatorField, sources[T]); - LOG(Message) << "A2A src for s = " << s << " , c = " << c << ", T = " << T << std::endl; - // source conversion for 4D sources - if (!env().isObject5d(sources[T])) + if (Ls == 1) { - if (Ls_ == 1) - { - PropToFerm(ferm_src, prop_src, s, c); - tmp = ferm_src; - } - else - { - PropToFerm(tmp, prop_src, s, c); - action.ImportPhysicalFermionSource(tmp, ferm_src); - action.ImportUnphysicalFermion(tmp, unphys_ferm); - } + ferm_src = noise[i]; + tmp = ferm_src; } - // source conversion for 5D sources else { - if (Ls_ != env().getObjectLs(sources[T])) - { - HADRONS_ERROR(Size, "Ls mismatch between quark action and source"); - } - else - { - PropToFerm(ferm_src, prop_src, s, c); - action.ExportPhysicalFermionSolution(ferm_src, tmp); - unphys_ferm = ferm_src; - } + tmp = noise[i]; + action.ImportPhysicalFermionSource(noise[i], ferm_src); + action.ImportUnphysicalFermion(noise[i], unphys_ferm); } - LOG(Message) << "a2areturn.high_modes Ncount = " << N_count << std::endl; - a2areturn.high_modes(ferm_src, unphys_ferm, tmp, N_count); - N_count++; } + // source conversion for 5D sources + else + { + if (Ls != env().getObjectLs(par().noise)) + { + HADRONS_ERROR(Size, "Ls mismatch between quark action and source"); + } + else + { + ferm_src = noise[i]; + action.ExportPhysicalFermionSolution(ferm_src, tmp); + unphys_ferm = ferm_src; + } + } + LOG(Message) << "solveHighMode i = " << i << std::endl; + a2areturn.high_modes(ferm_src, unphys_ferm, tmp, i); + } } END_MODULE_NAMESPACE