2019-04-26 07:24:56 +01:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
|
|
|
Source file: Hadrons/Modules/MDistil/DistilVectors.hpp
|
|
|
|
|
2019-04-26 07:39:05 +01:00
|
|
|
Copyright (C) 2019
|
2019-04-26 07:24:56 +01:00
|
|
|
|
|
|
|
Author: Felix Erben <ferben@ed.ac.uk>
|
|
|
|
Author: Michael Marshall <Michael.Marshall@ed.ac.uk>
|
|
|
|
|
|
|
|
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
|
|
|
|
*************************************************************************************/
|
|
|
|
/* END LEGAL */
|
|
|
|
|
2019-01-18 13:14:28 +00:00
|
|
|
#ifndef Hadrons_MDistil_DistilVectors_hpp_
|
|
|
|
#define Hadrons_MDistil_DistilVectors_hpp_
|
|
|
|
|
2019-11-12 17:31:42 +00:00
|
|
|
#include <Hadrons/Modules/MDistil/Distil.hpp>
|
2019-01-18 13:14:28 +00:00
|
|
|
|
|
|
|
BEGIN_HADRONS_NAMESPACE
|
2019-11-02 14:58:32 +00:00
|
|
|
BEGIN_MODULE_NAMESPACE(MDistil)
|
2019-01-22 13:27:51 +00:00
|
|
|
|
2019-01-18 13:14:28 +00:00
|
|
|
/******************************************************************************
|
2019-04-29 18:40:38 +01:00
|
|
|
* DistilVectors *
|
|
|
|
* (Create rho and/or phi vectors) *
|
2019-01-18 13:14:28 +00:00
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class DistilVectorsPar: Serializable
|
|
|
|
{
|
|
|
|
public:
|
2019-11-02 16:15:48 +00:00
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(DistilVectorsPar,
|
|
|
|
std::string, noise,
|
|
|
|
std::string, perambulator,
|
|
|
|
std::string, lapevec,
|
2019-11-11 17:29:55 +00:00
|
|
|
std::string, rho,
|
|
|
|
std::string, phi,
|
2019-11-12 21:53:09 +00:00
|
|
|
std::string, DistilParams);
|
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:
|
2019-11-02 16:15:48 +00:00
|
|
|
FERM_TYPE_ALIASES(FImpl,);
|
|
|
|
// constructor
|
|
|
|
TDistilVectors(const std::string name);
|
|
|
|
// destructor
|
2019-11-12 23:18:37 +00:00
|
|
|
virtual ~TDistilVectors(void) {};
|
2019-11-02 16:15:48 +00:00
|
|
|
// 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);
|
2019-03-20 14:41:36 +00:00
|
|
|
protected:
|
2019-11-12 21:53:09 +00:00
|
|
|
std::unique_ptr<GridCartesian> grid3d; // Owned by me, so I must delete it
|
2019-04-29 18:40:38 +01:00
|
|
|
public:
|
2019-11-02 16:15:48 +00:00
|
|
|
// These variables contain parameters
|
2019-11-11 17:29:55 +00:00
|
|
|
std::string RhoName;
|
|
|
|
std::string PhiName;
|
2019-01-18 13:14:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_REGISTER_TMP(DistilVectors, TDistilVectors<FIMPL>, MDistil);
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* TDistilVectors implementation *
|
|
|
|
******************************************************************************/
|
|
|
|
// constructor /////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
2019-11-12 21:53:09 +00:00
|
|
|
TDistilVectors<FImpl>::TDistilVectors(const std::string name) : Module<DistilVectorsPar>(name) {}
|
2019-01-18 13:14:28 +00:00
|
|
|
|
|
|
|
// dependencies/products ///////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
std::vector<std::string> TDistilVectors<FImpl>::getInput(void)
|
|
|
|
{
|
2019-11-12 21:53:09 +00:00
|
|
|
return {par().noise,par().perambulator,par().lapevec,par().DistilParams};
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FImpl>
|
|
|
|
std::vector<std::string> TDistilVectors<FImpl>::getOutput(void)
|
|
|
|
{
|
2019-11-12 21:53:09 +00:00
|
|
|
RhoName = par().rho;
|
|
|
|
PhiName = par().phi;
|
|
|
|
if (RhoName.empty() && PhiName.empty())
|
2019-11-02 16:15:48 +00:00
|
|
|
{
|
2019-11-13 12:16:56 +00:00
|
|
|
HADRONS_ERROR(Argument,"No output specified");
|
2019-11-02 16:15:48 +00:00
|
|
|
}
|
|
|
|
std::vector<std::string> out;
|
2019-11-12 21:53:09 +00:00
|
|
|
if (!RhoName.empty())
|
2019-11-11 17:29:55 +00:00
|
|
|
out.push_back(RhoName);
|
2019-11-12 21:53:09 +00:00
|
|
|
if (!PhiName.empty())
|
2019-11-11 17:29:55 +00:00
|
|
|
out.push_back(PhiName);
|
2019-11-02 16:15:48 +00:00
|
|
|
return out;
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// setup ///////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
void TDistilVectors<FImpl>::setup(void)
|
|
|
|
{
|
2019-11-02 16:15:48 +00:00
|
|
|
// We expect the perambulator to have been created with these indices
|
2019-11-12 21:53:09 +00:00
|
|
|
auto &perambulator = envGet(PerambTensor, par().perambulator);
|
|
|
|
if (!perambulator.ValidateIndexNames())
|
|
|
|
HADRONS_ERROR(Range,"Perambulator index names bad");
|
|
|
|
|
|
|
|
const DistilParameters &dp{envGet(DistilParameters, par().DistilParams)};
|
|
|
|
const int Nt{env().getDim(Tdir)};
|
|
|
|
const bool full_tdil{ dp.TI == Nt };
|
|
|
|
const int Nt_inv{ full_tdil ? 1 : dp.TI };
|
2019-11-02 16:15:48 +00:00
|
|
|
|
2019-11-12 21:53:09 +00:00
|
|
|
if (!RhoName.empty())
|
|
|
|
envCreate(std::vector<FermionField>, RhoName, 1, dp.nnoise*dp.LI*dp.SI*Nt_inv, envGetGrid(FermionField));
|
|
|
|
if (!PhiName.empty())
|
|
|
|
envCreate(std::vector<FermionField>, PhiName, 1, dp.nnoise*dp.LI*dp.SI*Nt_inv, envGetGrid(FermionField));
|
2019-11-02 16:15:48 +00:00
|
|
|
|
|
|
|
Coordinate latt_size = GridDefaultLatt();
|
|
|
|
Coordinate mpi_layout = GridDefaultMpi();
|
|
|
|
Coordinate simd_layout_3 = GridDefaultSimd(Nd-1, vComplex::Nsimd());
|
|
|
|
latt_size[Nd-1] = 1;
|
|
|
|
simd_layout_3.push_back( 1 );
|
|
|
|
mpi_layout[Nd-1] = 1;
|
2019-11-12 21:53:09 +00:00
|
|
|
GridCartesian * const grid4d{env().getGrid()};
|
|
|
|
grid3d.reset(MakeLowerDimGrid(grid4d));
|
2019-11-02 16:15:48 +00:00
|
|
|
|
2019-11-11 17:29:55 +00:00
|
|
|
envTmp(LatticeSpinColourVector, "source4d",1,LatticeSpinColourVector(grid4d));
|
2019-11-12 21:53:09 +00:00
|
|
|
envTmp(LatticeSpinColourVector, "source3d",1,LatticeSpinColourVector(grid3d.get()));
|
|
|
|
envTmp(LatticeColourVector, "source3d_nospin",1,LatticeColourVector(grid3d.get()));
|
|
|
|
envTmp(LatticeSpinColourVector, "sink3d",1,LatticeSpinColourVector(grid3d.get()));
|
|
|
|
envTmp(LatticeColourVector, "evec3d",1,LatticeColourVector(grid3d.get()));
|
2019-03-20 14:41:36 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 13:14:28 +00:00
|
|
|
// execution ///////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
void TDistilVectors<FImpl>::execute(void)
|
|
|
|
{
|
2019-11-12 21:53:09 +00:00
|
|
|
auto &noise = envGet(NoiseTensor, par().noise);
|
|
|
|
auto &perambulator = envGet(PerambTensor, par().perambulator);
|
|
|
|
auto &epack = envGet(Grid::Hadrons::EigenPack<LatticeColourVector>, par().lapevec);
|
2019-11-13 11:21:08 +00:00
|
|
|
const DistilParameters &dp{envGet(DistilParameters, par().DistilParams)};
|
2019-11-02 16:15:48 +00:00
|
|
|
|
2019-11-11 17:29:55 +00:00
|
|
|
envGetTmp(LatticeSpinColourVector, source4d);
|
|
|
|
envGetTmp(LatticeSpinColourVector, source3d);
|
|
|
|
envGetTmp(LatticeColourVector, source3d_nospin);
|
|
|
|
envGetTmp(LatticeSpinColourVector, sink3d);
|
2019-11-02 16:15:48 +00:00
|
|
|
envGetTmp(LatticeColourVector, evec3d);
|
|
|
|
|
2019-11-12 21:53:09 +00:00
|
|
|
GridCartesian * const grid4d{env().getGrid()};
|
2019-11-02 16:15:48 +00:00
|
|
|
const int Ntlocal{ grid4d->LocalDimensions()[3] };
|
|
|
|
const int Ntfirst{ grid4d->LocalStarts()[3] };
|
|
|
|
|
2019-11-11 17:29:55 +00:00
|
|
|
const int Nt{env().getDim(Tdir)};
|
2019-11-13 14:52:06 +00:00
|
|
|
const bool full_tdil{ dp.TI == Nt };
|
|
|
|
const int Nt_inv{ full_tdil ? 1 : dp.TI };
|
2019-11-02 16:15:48 +00:00
|
|
|
|
|
|
|
int vecindex;
|
|
|
|
int t_inv;
|
2019-11-12 21:53:09 +00:00
|
|
|
if (!RhoName.empty())
|
2019-11-02 16:15:48 +00:00
|
|
|
{
|
2019-11-11 17:29:55 +00:00
|
|
|
auto &rho = envGet(std::vector<FermionField>, RhoName);
|
2019-11-13 14:52:06 +00:00
|
|
|
for (int inoise = 0; inoise < dp.nnoise; inoise++)
|
|
|
|
{
|
|
|
|
for (int dk = 0; dk < dp.LI; dk++)
|
|
|
|
{
|
|
|
|
for (int dt = 0; dt < Nt_inv; dt++)
|
|
|
|
{
|
|
|
|
for (int ds = 0; ds < dp.SI; ds++)
|
|
|
|
{
|
2019-11-13 16:34:09 +00:00
|
|
|
vecindex = inoise + dp.nnoise * (dk + dp.LI * (ds + dp.SI * dt));
|
2019-11-02 16:15:48 +00:00
|
|
|
rho[vecindex] = 0;
|
2019-11-13 14:52:06 +00:00
|
|
|
for (int it = dt; it < Nt; it += dp.TI)
|
|
|
|
{
|
|
|
|
const int t_inv{full_tdil ? dp.tsrc : it};
|
|
|
|
if (t_inv >= Ntfirst && t_inv < Ntfirst + Ntlocal)
|
|
|
|
{
|
|
|
|
for (int ik = dk; ik < dp.nvec; ik += dp.LI)
|
|
|
|
{
|
|
|
|
for (int is = ds; is < Ns; is += dp.SI)
|
|
|
|
{
|
2019-11-02 16:15:48 +00:00
|
|
|
ExtractSliceLocal(evec3d,epack.evec[ik],0,t_inv-Ntfirst,Tdir);
|
2019-11-11 17:29:55 +00:00
|
|
|
source3d_nospin = evec3d * noise.tensor(inoise, t_inv, ik, is);
|
|
|
|
source3d=0;
|
|
|
|
pokeSpin(source3d,source3d_nospin,is);
|
|
|
|
source4d=0;
|
|
|
|
InsertSliceLocal(source3d,source4d,0,t_inv-Ntfirst,Tdir);
|
|
|
|
rho[vecindex] += source4d;
|
2019-11-02 16:15:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-05 12:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-13 14:52:06 +00:00
|
|
|
if (!PhiName.empty())
|
|
|
|
{
|
2019-11-11 17:29:55 +00:00
|
|
|
auto &phi = envGet(std::vector<FermionField>, PhiName);
|
2019-11-13 14:52:06 +00:00
|
|
|
for (int inoise = 0; inoise < dp.nnoise; inoise++)
|
|
|
|
{
|
|
|
|
for (int dk = 0; dk < dp.LI; dk++)
|
|
|
|
{
|
|
|
|
for (int dt = 0; dt < Nt_inv; dt++)
|
|
|
|
{
|
|
|
|
for (int ds = 0; ds < dp.SI; ds++)
|
|
|
|
{
|
2019-11-13 16:34:09 +00:00
|
|
|
vecindex = inoise + dp.nnoise * (dk + dp.LI * (ds + dp.SI * dt));
|
2019-11-02 16:15:48 +00:00
|
|
|
phi[vecindex] = 0;
|
2019-11-13 14:52:06 +00:00
|
|
|
for (int t = Ntfirst; t < Ntfirst + Ntlocal; t++)
|
|
|
|
{
|
2019-11-11 17:29:55 +00:00
|
|
|
sink3d=0;
|
2019-11-13 14:52:06 +00:00
|
|
|
for (int ivec = 0; ivec < dp.nvec; ivec++)
|
|
|
|
{
|
2019-11-02 16:15:48 +00:00
|
|
|
ExtractSliceLocal(evec3d,epack.evec[ivec],0,t-Ntfirst,Tdir);
|
2019-11-11 17:29:55 +00:00
|
|
|
sink3d += evec3d * perambulator.tensor(t, ivec, dk, inoise,dt,ds);
|
2019-11-02 16:15:48 +00:00
|
|
|
}
|
2019-11-11 17:29:55 +00:00
|
|
|
InsertSliceLocal(sink3d,phi[vecindex],0,t-Ntfirst,Tdir);
|
2019-11-02 16:15:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-22 13:27:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
END_MODULE_NAMESPACE
|
|
|
|
END_HADRONS_NAMESPACE
|
|
|
|
#endif // Hadrons_MDistil_DistilVectors_hpp_
|