2019-01-18 13:14:28 +00:00
|
|
|
#ifndef Hadrons_MDistil_DistilVectors_hpp_
|
|
|
|
#define Hadrons_MDistil_DistilVectors_hpp_
|
|
|
|
|
|
|
|
#include <Hadrons/Global.hpp>
|
|
|
|
#include <Hadrons/Module.hpp>
|
|
|
|
#include <Hadrons/ModuleFactory.hpp>
|
2019-01-21 16:04:18 +00:00
|
|
|
#include <Hadrons/Solver.hpp>
|
|
|
|
#include <Hadrons/EigenPack.hpp>
|
|
|
|
#include <Hadrons/A2AVectors.hpp>
|
|
|
|
#include <Hadrons/DilutedNoise.hpp>
|
2019-01-18 13:14:28 +00:00
|
|
|
|
|
|
|
BEGIN_HADRONS_NAMESPACE
|
2019-01-21 16:04:18 +00:00
|
|
|
/*
|
|
|
|
template<typename LatticeObj>
|
|
|
|
class Perambulator : Serializable{
|
|
|
|
// TODO: The next line makes friends across all combinations
|
|
|
|
// (not much of a problem given all public anyway ...)
|
|
|
|
// FYI, the bug here was that I forgot that the friend is templated
|
|
|
|
template<typename T> friend std::ostream & operator<<(std::ostream &os, const Perambulator<T>& p);
|
|
|
|
protected:
|
|
|
|
public:
|
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS( Perambulator,
|
|
|
|
std::string, ID, // Allows owner to specialise
|
|
|
|
std::string, Provenance, // For info only
|
|
|
|
std::vector<int>, dimensions,
|
|
|
|
std::vector<LatticeObj>, perambulator,
|
|
|
|
// Following items are redundant, but useful
|
|
|
|
int, nd, // Number of dimensions
|
|
|
|
size_t, NumElements); // Number of elements
|
|
|
|
protected:
|
|
|
|
// Constructor common code
|
|
|
|
inline void ConstructCommon(const int * Dimensions) {
|
|
|
|
assert(nd > 0);
|
|
|
|
dimensions.resize(nd);
|
|
|
|
NumElements = 1;
|
|
|
|
for(int i = 0 ; i < nd ; i++) {
|
|
|
|
assert(Dimensions[i] > 0);
|
|
|
|
NumElements *= (size_t) Dimensions[i];
|
|
|
|
dimensions[i] = Dimensions[i];
|
|
|
|
}
|
|
|
|
//const LatticeObj perambulatorDefault;
|
|
|
|
perambulator.resize(NumElements);//,perambulatorDefault);
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
// Constructor with dimensions passed as std::vector<int>
|
|
|
|
inline Perambulator(const std::vector<int> & Dimensions)
|
|
|
|
: nd {(int) Dimensions.size()} {
|
|
|
|
ConstructCommon( &Dimensions[0] ); }
|
|
|
|
|
|
|
|
// Constructor with dimensions passed as std::vector<int>
|
|
|
|
inline Perambulator(const std::vector<int> & Dimensions, const std::string sID)
|
|
|
|
: nd {(int) Dimensions.size()}, ID(sID) {
|
|
|
|
ConstructCommon( &Dimensions[0] ); }
|
|
|
|
|
|
|
|
// Constructor with dimensions passed as std::vector<int>
|
|
|
|
inline Perambulator(const std::vector<int> & Dimensions, const std::string sID, const std::string sProvenance)
|
|
|
|
: nd {(int) Dimensions.size()}, ID(sID), Provenance(sProvenance) {
|
|
|
|
ConstructCommon( &Dimensions[0] ); }
|
|
|
|
|
|
|
|
// Constructor with dimensions passed as individual parameters
|
|
|
|
// FYI: The caller is free to ignore the names and use the indices however they see fit
|
|
|
|
inline Perambulator(int NumNoise, int NumEvec=1, int NumTime=1, int NumSpin=1, int I_k=1, int I_t=1, int I_s=1) {
|
|
|
|
int Dimensions[]={NumNoise,NumEvec,NumTime,NumSpin,I_k,I_t,I_s};
|
|
|
|
nd = sizeof(Dimensions)/sizeof(Dimensions[0]);
|
|
|
|
while( nd > 1 && Dimensions[nd-1] == 1 )
|
|
|
|
nd--;
|
|
|
|
ConstructCommon( Dimensions );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline LatticeObj & operator()(size_t count, const int * Coord) {
|
|
|
|
assert( count == nd );
|
|
|
|
assert( Coord );
|
|
|
|
size_t idx = 0;
|
|
|
|
// C memory order (???)
|
|
|
|
for( int d = 0 ; d < nd ; d++ ) {
|
|
|
|
assert( Coord[d] < dimensions[d] );
|
|
|
|
idx *= (size_t) dimensions[d];
|
|
|
|
idx += (size_t) Coord[d];
|
|
|
|
}
|
|
|
|
return perambulator[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline LatticeObj & operator()(const std::vector<int> Coord) {
|
|
|
|
return operator()(Coord.size(), &Coord[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline LatticeObj & operator()(int idxNoise, int idxEvec=0, int idxTime=0, int idxSpin=0, int I_k=0, int I_t=0, int I_s=0) {
|
|
|
|
int MyIndex[]={idxNoise,idxEvec,idxTime,idxSpin,I_k,I_t,I_s};
|
|
|
|
int i = sizeof(MyIndex)/sizeof(MyIndex[0]);
|
|
|
|
assert( i >= nd );
|
|
|
|
while( i > nd )
|
|
|
|
assert(MyIndex[--i] == 0);
|
|
|
|
return operator()(i, MyIndex);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
*/
|
2019-01-18 13:14:28 +00:00
|
|
|
|
2019-01-18 13:23:03 +00:00
|
|
|
/******************************************************************************
|
2019-01-18 15:58:10 +00:00
|
|
|
* Class to generate Distillation $\varrho$ and $\varphi$ vectors *
|
|
|
|
******************************************************************************/
|
2019-01-18 13:23:03 +00:00
|
|
|
/*
|
2019-01-18 15:58:10 +00:00
|
|
|
template <typename FImpl>
|
|
|
|
class DistilVectorsFromPerambulator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FERM_TYPE_ALIASES(FImpl,);
|
|
|
|
SOLVER_TYPE_ALIASES(FImpl,);
|
|
|
|
public:
|
|
|
|
DistilVectorsFromPerambulator(FMat &action);
|
|
|
|
virtual ~DistilVectorsFromPerambulator(void) = default;
|
|
|
|
void makeRho(FermionField &rhoOut,
|
|
|
|
const FermionField &evec, const Complex &noises);
|
|
|
|
void makePhi(FermionField &phiOut,
|
|
|
|
const FermionField &evec, const SpinVector &Perambulators);
|
|
|
|
private:
|
|
|
|
GridBase *fGrid_, *frbGrid_, *gGrid_;
|
|
|
|
bool is5d_;
|
|
|
|
FermionField src_o_, sol_e_, sol_o_, tmp_, tmp5_;
|
|
|
|
};
|
|
|
|
|
|
|
|
*/
|
2019-01-18 13:23:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
2019-01-18 16:38:13 +00:00
|
|
|
* DistilVectorsFromPerambulator template implementation *
|
2019-01-18 15:58:10 +00:00
|
|
|
******************************************************************************/
|
|
|
|
|
2019-01-21 16:04:18 +00:00
|
|
|
/*
|
2019-01-18 15:58:10 +00:00
|
|
|
template <typename FImpl>
|
2019-01-18 16:38:13 +00:00
|
|
|
DistilVectorsFromPerambulator<FImpl>::DistilVectorsFromPerambulator(FMat &action)
|
2019-01-18 15:58:10 +00:00
|
|
|
: action_(action)
|
|
|
|
, fGrid_(action_.FermionGrid())
|
|
|
|
, frbGrid_(action_.FermionRedBlackGrid())
|
|
|
|
, gGrid_(action_.GaugeGrid())
|
|
|
|
, src_o_(frbGrid_)
|
|
|
|
, sol_e_(frbGrid_)
|
|
|
|
, sol_o_(frbGrid_)
|
|
|
|
, tmp_(frbGrid_)
|
|
|
|
, tmp5_(fGrid_)
|
|
|
|
, op_(action_)
|
|
|
|
{}
|
|
|
|
|
|
|
|
template <typename FImpl>
|
2019-01-18 16:38:13 +00:00
|
|
|
void DistilVectorsFromPerambulator<FImpl>::makeRho(FermionField &rhoOut, const FermionField &evec, const Complex &noises)
|
2019-01-18 15:58:10 +00:00
|
|
|
{
|
2019-01-21 16:04:18 +00:00
|
|
|
// INPUT:::::::::
|
|
|
|
Grid::Hadrons::EigenPack<LatticeColourVector> eig4d;
|
|
|
|
std::vector<std::vector<std::vector<SpinVector> > > noises;
|
|
|
|
|
|
|
|
// OUTPUT::::::::
|
|
|
|
std::vector <LatticeSpinColourVector> sources_tsrc;
|
|
|
|
{
|
|
|
|
LatticeSpinColourVector vecModel(grid4d);
|
|
|
|
sources_tsrc.resize(nnoise*LI*Ns*Nt_inv,vecModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-18 15:58:10 +00:00
|
|
|
|
2019-01-21 16:04:18 +00:00
|
|
|
|
|
|
|
// TEMPORARY:::::::::
|
2019-01-18 15:58:10 +00:00
|
|
|
LatticeSpinColourVector tmp2(grid4d);
|
|
|
|
LatticeSpinColourVector tmp3d(grid3d);
|
|
|
|
LatticeColourVector tmp3d_nospin(grid3d);
|
|
|
|
LatticeColourVector tmp_nospin(grid4d);
|
|
|
|
LatticeColourVector evec3d(grid3d);
|
|
|
|
|
2019-01-18 16:38:13 +00:00
|
|
|
int vecindex;
|
2019-01-18 13:23:03 +00:00
|
|
|
for (int inoise = 0; inoise < nnoise; inoise++) {
|
|
|
|
for (int dk = 0; dk < LI; dk++) {
|
|
|
|
for (int dt = 0; dt < Nt_inv; dt++) {
|
|
|
|
if(full_tdil) dt=tsrc; //TODO: this works for now, as longs as tsrc=0, but will crash otherwise!
|
|
|
|
for (int ds = 0; ds < Ns; ds++) {
|
|
|
|
vecindex = inoise + nnoise * dk + nnoise * LI * ds + nnoise *LI * Ns*dt;
|
|
|
|
sources_tsrc[vecindex] = zero;
|
|
|
|
tmp3d_nospin = zero;
|
|
|
|
for (int it = dt; it < Nt; it += TI){
|
|
|
|
if( it >= Ntfirst && it < Ntfirst + Ntlocal ) {
|
|
|
|
for (int ik = dk; ik < nvec; ik += LI){
|
|
|
|
for (int is = ds; is < Ns; is += Ns){ //at the moment, full spin dilution is enforced
|
2019-01-18 15:58:10 +00:00
|
|
|
ExtractSliceLocal(evec3d,eig4d.evec[ik],0,it,3);
|
|
|
|
tmp3d_nospin = evec3d * noises[inoise][it][ik]()(is)(); //noises do not have to be a spin vector
|
2019-01-18 13:23:03 +00:00
|
|
|
tmp3d=zero;
|
|
|
|
pokeSpin(tmp3d,tmp3d_nospin,is);
|
|
|
|
tmp2=zero;
|
|
|
|
#ifdef USE_LOCAL_SLICES
|
|
|
|
InsertSliceLocal(tmp3d,tmp2,0,it-Ntfirst,Grid::QCD::Tdir);
|
|
|
|
#else
|
|
|
|
InsertSlice(tmp3d,tmp2,it,Grid::QCD::Tdir);
|
|
|
|
#endif
|
|
|
|
sources_tsrc[vecindex] += tmp2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-18 16:38:13 +00:00
|
|
|
template <typename FImpl>
|
|
|
|
void DistilVectorsFromPerambulator<FImpl>::makePhi(FermionField &rhoOut, const FermionField &evec, const SpinVector &perambulator)
|
|
|
|
{
|
|
|
|
|
2019-01-21 16:04:18 +00:00
|
|
|
// INPUT:::::::::
|
|
|
|
Perambulator<SpinVector> perambulator;
|
|
|
|
Grid::Hadrons::EigenPack<LatticeColourVector> eig4d;
|
|
|
|
|
|
|
|
// OUTPUT::::::::
|
|
|
|
std::vector <LatticeSpinColourVector> sinks_tsrc;
|
|
|
|
{
|
|
|
|
LatticeSpinColourVector vecModel(grid4d);
|
|
|
|
sinks_tsrc.resize(nnoise*LI*Ns*Nt_inv,vecModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TEMPORARY:::::::::
|
2019-01-18 16:38:13 +00:00
|
|
|
LatticeSpinColourVector tmp2(grid4d);
|
|
|
|
LatticeSpinColourVector tmp3d(grid3d);
|
|
|
|
LatticeColourVector tmp3d_nospin(grid3d);
|
|
|
|
LatticeColourVector tmp_nospin(grid4d);
|
|
|
|
LatticeColourVector evec3d(grid3d);
|
|
|
|
|
|
|
|
int vecindex;
|
|
|
|
for (int inoise = 0; inoise < nnoise; inoise++) {
|
|
|
|
for (int dk = 0; dk < LI; dk++) {
|
|
|
|
for (int dt = 0; dt < Nt_inv; dt++) {
|
|
|
|
for (int ds = 0; ds < Ns; ds++) {
|
|
|
|
vecindex = inoise + nnoise * dk + nnoise * LI * ds + nnoise *LI * Ns*dt;
|
|
|
|
sinks_tsrc[vecindex] = zero;
|
|
|
|
for (int t = Ntfirst; t < Ntfirst + Ntlocal; t++) {
|
|
|
|
sink_tslice=zero;
|
|
|
|
for (int ivec = 0; ivec < nvec; ivec++) {
|
|
|
|
ExtractSliceLocal(evec3d,eig4d.evec[ivec],0,t,3);
|
|
|
|
sink_tslice += evec3d * perambulator(t, ivec, dk, inoise,dt,ds);
|
|
|
|
}
|
|
|
|
#ifdef USE_LOCAL_SLICES
|
|
|
|
InsertSliceLocal(sink_tslice,sinks_tsrc[vecindex],0,t-Ntfirst,Grid::QCD::Tdir);
|
|
|
|
#else
|
|
|
|
InsertSlice(sink_tslice,sinks_tsrc[vecindex],t,Grid::QCD::Tdir);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-18 13:23:03 +00:00
|
|
|
|
2019-01-21 16:04:18 +00:00
|
|
|
*/
|
2019-01-18 13:23:03 +00:00
|
|
|
|
|
|
|
|
2019-01-18 13:14:28 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* DistilVectors *
|
|
|
|
******************************************************************************/
|
|
|
|
BEGIN_MODULE_NAMESPACE(MDistil)
|
|
|
|
|
|
|
|
class DistilVectorsPar: Serializable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(DistilVectorsPar,
|
2019-01-21 16:04:18 +00:00
|
|
|
std::string, noise,
|
|
|
|
std::string, perambulator,
|
|
|
|
std::string, eigenPack,
|
|
|
|
bool, multiFile);
|
2019-01-18 13:14:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename FImpl>
|
|
|
|
class TDistilVectors: public Module<DistilVectorsPar>
|
|
|
|
{
|
2019-01-21 16:04:18 +00:00
|
|
|
public:
|
|
|
|
FERM_TYPE_ALIASES(FImpl,);
|
2019-01-18 13:14:28 +00:00
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
TDistilVectors(const std::string name);
|
|
|
|
// destructor
|
|
|
|
virtual ~TDistilVectors(void) {};
|
|
|
|
// dependency relation
|
|
|
|
virtual std::vector<std::string> getInput(void);
|
|
|
|
virtual std::vector<std::string> getOutput(void);
|
|
|
|
// setup
|
|
|
|
virtual void setup(void);
|
|
|
|
// execution
|
|
|
|
virtual void execute(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_REGISTER_TMP(DistilVectors, TDistilVectors<FIMPL>, MDistil);
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* TDistilVectors implementation *
|
|
|
|
******************************************************************************/
|
|
|
|
// constructor /////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
TDistilVectors<FImpl>::TDistilVectors(const std::string name)
|
|
|
|
: Module<DistilVectorsPar>(name)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// dependencies/products ///////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
std::vector<std::string> TDistilVectors<FImpl>::getInput(void)
|
|
|
|
{
|
|
|
|
std::vector<std::string> in;
|
2019-01-21 16:04:18 +00:00
|
|
|
|
|
|
|
in.push_back(par().noise);
|
|
|
|
in.push_back(par().perambulator);
|
|
|
|
in.push_back(par().eigenPack);
|
|
|
|
|
2019-01-18 13:14:28 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FImpl>
|
|
|
|
std::vector<std::string> TDistilVectors<FImpl>::getOutput(void)
|
|
|
|
{
|
2019-01-21 16:04:18 +00:00
|
|
|
std::vector<std::string> out = {getName() + "_rho", getName() + "_phi"};
|
2019-01-18 13:14:28 +00:00
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup ///////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
void TDistilVectors<FImpl>::setup(void)
|
|
|
|
{
|
2019-01-21 16:04:18 +00:00
|
|
|
auto &noise = envGet(std::vector<std::vector<std::vector<SpinVector>>>, par().noise);
|
|
|
|
|
|
|
|
envCreate(std::vector<FermionField>, getName() + "_rho", 1,
|
|
|
|
noise.size(), envGetGrid(FermionField));
|
|
|
|
envCreate(std::vector<FermionField>, getName() + "_phi", 1,
|
|
|
|
noise.size(), envGetGrid(FermionField));
|
|
|
|
|
|
|
|
|
|
|
|
envTmp(LatticeSpinColourVector, "tmp2",1,LatticeSpinColourVector(env().getGrid()));
|
|
|
|
envTmp(LatticeColourVector, "tmp_nospin",1,LatticeColourVector(env().getGrid()));
|
|
|
|
//GridCartesian * const grid3d;
|
|
|
|
//ExtractSlice(grid3d,env().getGrid(),0,3);
|
|
|
|
//envTmp(LatticeSpinColourVector, "tmp3d",1,LatticeSpinColourVector(grid3d));
|
|
|
|
/*LatticeSpinColourVector tmp3d(grid3d);
|
|
|
|
LatticeColourVector tmp3d_nospin(grid3d);
|
|
|
|
LatticeColourVector evec3d(grid3d);
|
|
|
|
*/
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// execution ///////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
void TDistilVectors<FImpl>::execute(void)
|
|
|
|
{
|
2019-01-21 16:04:18 +00:00
|
|
|
|
|
|
|
auto &noise = envGet(std::vector<std::vector<std::vector<SpinVector>>>, par().noise);
|
|
|
|
auto &perambulator = envGet(std::vector<SpinVector>, par().perambulator);
|
|
|
|
//auto &perambulator = envGet(Perambulator<SpinVector>, par().noise);
|
|
|
|
auto &epack = envGet(Grid::Hadrons::EigenPack<LatticeColourVector>, par().eigenPack);
|
|
|
|
auto &rho = envGet(std::vector<FermionField>, getName() + "_rho");
|
|
|
|
auto &phi = envGet(std::vector<FermionField>, getName() + "_phi");
|
|
|
|
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
END_MODULE_NAMESPACE
|
|
|
|
|
|
|
|
END_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
#endif // Hadrons_MDistil_DistilVectors_hpp_
|