2018-06-28 16:17:26 +01:00
|
|
|
#ifndef Hadrons_MContraction_MesonFieldGamma_hpp_
|
|
|
|
#define Hadrons_MContraction_MesonFieldGamma_hpp_
|
2018-06-22 12:28:41 +01:00
|
|
|
|
|
|
|
#include <Grid/Hadrons/Global.hpp>
|
|
|
|
#include <Grid/Hadrons/Module.hpp>
|
|
|
|
#include <Grid/Hadrons/ModuleFactory.hpp>
|
|
|
|
#include <Grid/Hadrons/AllToAllVectors.hpp>
|
2018-07-19 15:56:52 +01:00
|
|
|
#include <Grid/Hadrons/AllToAllReduction.hpp>
|
|
|
|
#include <Grid/Grid_Eigen_Dense.h>
|
|
|
|
#include <fstream>
|
2018-06-22 12:28:41 +01:00
|
|
|
|
|
|
|
BEGIN_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
/******************************************************************************
|
2018-06-28 16:17:26 +01:00
|
|
|
* MesonFieldGamma *
|
2018-06-22 12:28:41 +01:00
|
|
|
******************************************************************************/
|
|
|
|
BEGIN_MODULE_NAMESPACE(MContraction)
|
|
|
|
|
2018-06-25 12:20:46 +01:00
|
|
|
class MesonFieldPar : Serializable
|
2018-06-22 12:28:41 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-06-25 12:20:46 +01:00
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(MesonFieldPar,
|
2018-06-22 12:28:41 +01:00
|
|
|
int, Nl,
|
|
|
|
int, N,
|
2018-07-19 15:56:52 +01:00
|
|
|
int, Nblock,
|
2018-06-22 12:28:41 +01:00
|
|
|
std::string, A2A1,
|
|
|
|
std::string, A2A2,
|
2018-06-28 16:17:26 +01:00
|
|
|
std::string, gammas,
|
2018-06-22 12:28:41 +01:00
|
|
|
std::string, output);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename FImpl>
|
2018-06-28 16:17:26 +01:00
|
|
|
class TMesonFieldGamma : public Module<MesonFieldPar>
|
2018-06-22 12:28:41 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
FERM_TYPE_ALIASES(FImpl, );
|
2018-06-28 16:17:26 +01:00
|
|
|
SOLVER_TYPE_ALIASES(FImpl, );
|
2018-06-22 12:28:41 +01:00
|
|
|
|
2018-06-28 16:17:26 +01:00
|
|
|
typedef A2AModesSchurDiagTwo<typename FImpl::FermionField, FMat, Solver> A2ABase;
|
2018-06-22 12:28:41 +01:00
|
|
|
|
|
|
|
class Result : Serializable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
|
2018-06-28 16:17:26 +01:00
|
|
|
Gamma::Algebra, gamma,
|
2018-07-16 16:19:59 +01:00
|
|
|
std::vector<std::vector<std::vector<ComplexD>>>, MesonField);
|
2018-06-22 12:28:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
// constructor
|
2018-06-28 16:17:26 +01:00
|
|
|
TMesonFieldGamma(const std::string name);
|
2018-06-22 12:28:41 +01:00
|
|
|
// destructor
|
2018-06-28 16:17:26 +01:00
|
|
|
virtual ~TMesonFieldGamma(void){};
|
2018-06-22 12:28:41 +01:00
|
|
|
// dependency relation
|
|
|
|
virtual std::vector<std::string> getInput(void);
|
|
|
|
virtual std::vector<std::string> getOutput(void);
|
2018-06-28 16:17:26 +01:00
|
|
|
virtual void parseGammaString(std::vector<Gamma::Algebra> &gammaList);
|
2018-07-19 15:56:52 +01:00
|
|
|
virtual void vectorOfWs(std::vector<FermionField> &w, int i, int Nblock, FermionField &tmpw_5d, std::vector<FermionField> &vec_w);
|
|
|
|
virtual void vectorOfVs(std::vector<FermionField> &v, int j, int Nblock, FermionField &tmpv_5d, std::vector<FermionField> &vec_v);
|
|
|
|
virtual void gammaMult(std::vector<FermionField> &v, Gamma gamma);
|
2018-06-22 12:28:41 +01:00
|
|
|
// setup
|
|
|
|
virtual void setup(void);
|
|
|
|
// execution
|
|
|
|
virtual void execute(void);
|
|
|
|
};
|
|
|
|
|
2018-06-28 16:17:26 +01:00
|
|
|
MODULE_REGISTER(MesonFieldGamma, ARG(TMesonFieldGamma<FIMPL>), MContraction);
|
2018-07-03 14:04:53 +01:00
|
|
|
MODULE_REGISTER(ZMesonFieldGamma, ARG(TMesonFieldGamma<ZFIMPL>), MContraction);
|
2018-06-22 12:28:41 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
2018-06-28 16:17:26 +01:00
|
|
|
* TMesonFieldGamma implementation *
|
2018-06-22 12:28:41 +01:00
|
|
|
******************************************************************************/
|
|
|
|
// constructor /////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
2018-06-28 16:17:26 +01:00
|
|
|
TMesonFieldGamma<FImpl>::TMesonFieldGamma(const std::string name)
|
2018-06-25 12:20:46 +01:00
|
|
|
: Module<MesonFieldPar>(name)
|
2018-06-22 12:28:41 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// dependencies/products ///////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
2018-06-28 16:17:26 +01:00
|
|
|
std::vector<std::string> TMesonFieldGamma<FImpl>::getInput(void)
|
2018-06-22 12:28:41 +01:00
|
|
|
{
|
2018-06-28 16:17:26 +01:00
|
|
|
std::vector<std::string> in = {par().A2A1 + "_class", par().A2A2 + "_class"};
|
2018-07-22 14:40:31 +01:00
|
|
|
in.push_back(par().A2A1 + "_w_high_4d");
|
|
|
|
in.push_back(par().A2A2 + "_v_high_4d");
|
2018-06-22 12:28:41 +01:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FImpl>
|
2018-06-28 16:17:26 +01:00
|
|
|
std::vector<std::string> TMesonFieldGamma<FImpl>::getOutput(void)
|
2018-06-22 12:28:41 +01:00
|
|
|
{
|
|
|
|
std::vector<std::string> out = {};
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2018-06-28 16:17:26 +01:00
|
|
|
template <typename FImpl>
|
|
|
|
void TMesonFieldGamma<FImpl>::parseGammaString(std::vector<Gamma::Algebra> &gammaList)
|
|
|
|
{
|
|
|
|
gammaList.clear();
|
|
|
|
// Determine gamma matrices to insert at source/sink.
|
|
|
|
if (par().gammas.compare("all") == 0)
|
|
|
|
{
|
|
|
|
// Do all contractions.
|
|
|
|
for (unsigned int i = 1; i < Gamma::nGamma; i += 2)
|
|
|
|
{
|
|
|
|
gammaList.push_back(((Gamma::Algebra)i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Parse individual contractions from input string.
|
|
|
|
gammaList = strToVec<Gamma::Algebra>(par().gammas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-19 15:56:52 +01:00
|
|
|
template <typename FImpl>
|
|
|
|
void TMesonFieldGamma<FImpl>::vectorOfWs(std::vector<FermionField> &w, int i, int Nblock, FermionField &tmpw_5d, std::vector<FermionField> &vec_w)
|
|
|
|
{
|
|
|
|
for (unsigned int ni = 0; ni < Nblock; ni++)
|
|
|
|
{
|
|
|
|
vec_w[ni] = w[i + ni];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FImpl>
|
|
|
|
void TMesonFieldGamma<FImpl>::vectorOfVs(std::vector<FermionField> &v, int j, int Nblock, FermionField &tmpv_5d, std::vector<FermionField> &vec_v)
|
|
|
|
{
|
|
|
|
for (unsigned int nj = 0; nj < Nblock; nj++)
|
|
|
|
{
|
|
|
|
vec_v[nj] = v[j+nj];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FImpl>
|
|
|
|
void TMesonFieldGamma<FImpl>::gammaMult(std::vector<FermionField> &v, Gamma gamma)
|
|
|
|
{
|
|
|
|
int Nblock = v.size();
|
|
|
|
for (unsigned int nj = 0; nj < Nblock; nj++)
|
|
|
|
{
|
|
|
|
v[nj] = gamma * v[nj];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 12:28:41 +01:00
|
|
|
// setup ///////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
2018-06-28 16:17:26 +01:00
|
|
|
void TMesonFieldGamma<FImpl>::setup(void)
|
2018-06-22 12:28:41 +01:00
|
|
|
{
|
|
|
|
int nt = env().getDim(Tp);
|
|
|
|
int N = par().N;
|
2018-07-19 15:56:52 +01:00
|
|
|
int Nblock = par().Nblock;
|
2018-06-22 12:28:41 +01:00
|
|
|
|
2018-06-28 16:17:26 +01:00
|
|
|
int Ls_ = env().getObjectLs(par().A2A1 + "_class");
|
2018-06-22 12:28:41 +01:00
|
|
|
|
|
|
|
envTmpLat(FermionField, "tmpv_5d", Ls_);
|
|
|
|
envTmpLat(FermionField, "tmpw_5d", Ls_);
|
2018-07-19 15:56:52 +01:00
|
|
|
|
|
|
|
envTmp(std::vector<FermionField>, "w", 1, N, FermionField(env().getGrid(1)));
|
|
|
|
envTmp(std::vector<FermionField>, "v", 1, N, FermionField(env().getGrid(1)));
|
|
|
|
|
|
|
|
envTmp(Eigen::MatrixXcd, "MF", 1, Eigen::MatrixXcd::Zero(nt, N * N));
|
|
|
|
|
|
|
|
envTmp(std::vector<FermionField>, "w_block", 1, Nblock, FermionField(env().getGrid(1)));
|
|
|
|
envTmp(std::vector<FermionField>, "v_block", 1, Nblock, FermionField(env().getGrid(1)));
|
2018-06-22 12:28:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// execution ///////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
2018-06-28 16:17:26 +01:00
|
|
|
void TMesonFieldGamma<FImpl>::execute(void)
|
2018-06-22 12:28:41 +01:00
|
|
|
{
|
2018-06-28 16:17:26 +01:00
|
|
|
LOG(Message) << "Computing A2A meson field for gamma = " << par().gammas << ", taking w from " << par().A2A1 << " and v from " << par().A2A2 << std::endl;
|
2018-06-22 12:28:41 +01:00
|
|
|
|
|
|
|
int N = par().N;
|
2018-06-25 12:20:46 +01:00
|
|
|
int nt = env().getDim(Tp);
|
2018-07-19 15:56:52 +01:00
|
|
|
int Nblock = par().Nblock;
|
2018-06-28 16:17:26 +01:00
|
|
|
|
|
|
|
std::vector<Result> result;
|
|
|
|
std::vector<Gamma::Algebra> gammaResultList;
|
|
|
|
std::vector<Gamma> gammaList;
|
|
|
|
|
|
|
|
parseGammaString(gammaResultList);
|
|
|
|
result.resize(gammaResultList.size());
|
|
|
|
|
|
|
|
Gamma g5(Gamma::Algebra::Gamma5);
|
|
|
|
gammaList.resize(gammaResultList.size(), g5);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < result.size(); ++i)
|
|
|
|
{
|
|
|
|
result[i].gamma = gammaResultList[i];
|
|
|
|
result[i].MesonField.resize(N, std::vector<std::vector<ComplexD>>(N, std::vector<ComplexD>(nt)));
|
|
|
|
|
|
|
|
Gamma gamma(gammaResultList[i]);
|
|
|
|
gammaList[i] = gamma;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &a2a1 = envGet(A2ABase, par().A2A1 + "_class");
|
|
|
|
auto &a2a2 = envGet(A2ABase, par().A2A2 + "_class");
|
2018-06-22 12:28:41 +01:00
|
|
|
|
|
|
|
envGetTmp(FermionField, tmpv_5d);
|
|
|
|
envGetTmp(FermionField, tmpw_5d);
|
|
|
|
|
2018-07-19 15:56:52 +01:00
|
|
|
envGetTmp(std::vector<FermionField>, v);
|
|
|
|
envGetTmp(std::vector<FermionField>, w);
|
|
|
|
LOG(Message) << "Finding v and w vectors for N = " << N << std::endl;
|
|
|
|
for (int i = 0; i < N; i++)
|
2018-06-22 12:28:41 +01:00
|
|
|
{
|
2018-07-19 15:56:52 +01:00
|
|
|
a2a2.return_v(i, tmpv_5d, v[i]);
|
|
|
|
a2a1.return_w(i, tmpw_5d, w[i]);
|
|
|
|
}
|
|
|
|
LOG(Message) << "Found v and w vectors for N = " << N << std::endl;
|
|
|
|
|
|
|
|
std::vector<std::vector<ComplexD>> MesonField_ij;
|
|
|
|
LOG(Message) << "Before blocked MFs, Nblock = " << Nblock << std::endl;
|
|
|
|
envGetTmp(std::vector<FermionField>, v_block);
|
|
|
|
envGetTmp(std::vector<FermionField>, w_block);
|
|
|
|
MesonField_ij.resize(Nblock * Nblock, std::vector<ComplexD>(nt));
|
|
|
|
|
|
|
|
envGetTmp(Eigen::MatrixXcd, MF);
|
|
|
|
|
|
|
|
LOG(Message) << "Before blocked MFs, Nblock = " << Nblock << std::endl;
|
|
|
|
for (unsigned int i = 0; i < N; i += Nblock)
|
|
|
|
{
|
|
|
|
vectorOfWs(w, i, Nblock, tmpw_5d, w_block);
|
|
|
|
for (unsigned int j = 0; j < N; j += Nblock)
|
2018-06-22 12:28:41 +01:00
|
|
|
{
|
2018-07-19 15:56:52 +01:00
|
|
|
vectorOfVs(v, j, Nblock, tmpv_5d, v_block);
|
2018-06-28 16:17:26 +01:00
|
|
|
for (unsigned int k = 0; k < result.size(); k++)
|
|
|
|
{
|
2018-07-19 15:56:52 +01:00
|
|
|
gammaMult(v_block, gammaList[k]);
|
|
|
|
sliceInnerProductMesonField(MesonField_ij, w_block, v_block, Tp);
|
|
|
|
for (unsigned int nj = 0; nj < Nblock; nj++)
|
|
|
|
{
|
|
|
|
for (unsigned int ni = 0; ni < Nblock; ni++)
|
|
|
|
{
|
|
|
|
MF.col((i + ni) + (j + nj) * N) = Eigen::VectorXcd::Map(&MesonField_ij[nj * Nblock + ni][0], MesonField_ij[nj * Nblock + ni].size());
|
|
|
|
}
|
|
|
|
}
|
2018-06-28 16:17:26 +01:00
|
|
|
}
|
2018-06-22 12:28:41 +01:00
|
|
|
}
|
|
|
|
if (i % 10 == 0)
|
|
|
|
{
|
|
|
|
LOG(Message) << "MF for i = " << i << " of " << N << std::endl;
|
|
|
|
}
|
|
|
|
}
|
2018-07-19 15:56:52 +01:00
|
|
|
LOG(Message) << "Before Global sum, Nblock = " << Nblock << std::endl;
|
|
|
|
v_block[0]._grid->GlobalSumVector(MF.data(), MF.size());
|
|
|
|
LOG(Message) << "After Global sum, Nblock = " << Nblock << std::endl;
|
|
|
|
for (unsigned int i = 0; i < N; i++)
|
|
|
|
{
|
|
|
|
for (unsigned int j = 0; j < N; j++)
|
|
|
|
{
|
|
|
|
for (unsigned int k = 0; k < result.size(); k++)
|
|
|
|
{
|
|
|
|
for (unsigned int t = 0; t < nt; t++)
|
|
|
|
{
|
|
|
|
result[k].MesonField[i][j][t] = MF.col(i + N * j)[t];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-22 12:28:41 +01:00
|
|
|
saveResult(par().output, "meson", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
END_MODULE_NAMESPACE
|
|
|
|
|
|
|
|
END_HADRONS_NAMESPACE
|
|
|
|
|
2018-06-28 16:17:26 +01:00
|
|
|
#endif // Hadrons_MContraction_MesonFieldGm_hpp_
|