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_
|
|
|
|
|
|
|
|
#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-22 17:59:55 +00:00
|
|
|
|
|
|
|
// These are members of Distillation
|
2019-04-26 07:24:56 +01:00
|
|
|
#include <Hadrons/Distil.hpp>
|
2019-01-18 13:14:28 +00:00
|
|
|
|
|
|
|
BEGIN_HADRONS_NAMESPACE
|
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
|
|
|
******************************************************************************/
|
|
|
|
BEGIN_MODULE_NAMESPACE(MDistil)
|
|
|
|
|
|
|
|
class DistilVectorsPar: Serializable
|
|
|
|
{
|
|
|
|
public:
|
2019-04-29 18:40:38 +01:00
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(DistilVectorsPar,
|
|
|
|
std::string, noise,
|
|
|
|
std::string, perambulator,
|
|
|
|
std::string, lapevec,
|
|
|
|
std::string, source,
|
|
|
|
std::string, sink,
|
|
|
|
int, tsrc,
|
2019-04-30 23:53:57 +01:00
|
|
|
std::string, nvec,
|
|
|
|
std::string, TI)
|
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-04-29 18:40:38 +01:00
|
|
|
FERM_TYPE_ALIASES(FImpl,);
|
|
|
|
// 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);
|
2019-03-20 14:41:36 +00:00
|
|
|
protected:
|
2019-04-29 18:40:38 +01:00
|
|
|
// These variables are created in setup() and freed in Cleanup()
|
|
|
|
GridCartesian * grid3d; // Owned by me, so I must delete it
|
|
|
|
GridCartesian * grid4d; // Owned by environment (so I won't delete it)
|
|
|
|
virtual void Cleanup(void);
|
|
|
|
public:
|
|
|
|
// These variables contain parameters
|
|
|
|
std::string PerambulatorName;
|
|
|
|
std::string NoiseVectorName;
|
|
|
|
std::string LapEvecName;
|
|
|
|
bool bMakeSource;
|
|
|
|
bool bMakeSink;
|
|
|
|
std::string SourceName;
|
|
|
|
std::string SinkName;
|
2019-01-18 13:14:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_REGISTER_TMP(DistilVectors, TDistilVectors<FIMPL>, MDistil);
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* TDistilVectors implementation *
|
|
|
|
******************************************************************************/
|
|
|
|
// constructor /////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
TDistilVectors<FImpl>::TDistilVectors(const std::string name)
|
2019-03-20 14:41:36 +00:00
|
|
|
: grid3d{nullptr}, grid4d{nullptr}, Module<DistilVectorsPar>(name)
|
2019-01-18 13:14:28 +00:00
|
|
|
{}
|
2019-03-20 14:41:36 +00:00
|
|
|
// destructor
|
|
|
|
template <typename FImpl>
|
|
|
|
TDistilVectors<FImpl>::~TDistilVectors(void)
|
|
|
|
{
|
|
|
|
Cleanup();
|
|
|
|
};
|
2019-01-18 13:14:28 +00:00
|
|
|
|
|
|
|
// dependencies/products ///////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
std::vector<std::string> TDistilVectors<FImpl>::getInput(void)
|
|
|
|
{
|
2019-04-29 18:40:38 +01:00
|
|
|
PerambulatorName = par().perambulator;
|
|
|
|
if( PerambulatorName.size() == 0 ) {
|
|
|
|
PerambulatorName = getName();
|
|
|
|
PerambulatorName.append( "_peramb" );
|
|
|
|
}
|
|
|
|
NoiseVectorName = par().noise;
|
|
|
|
if( NoiseVectorName.size() == 0 ) {
|
|
|
|
NoiseVectorName = PerambulatorName;
|
|
|
|
NoiseVectorName.append( "_noise" );
|
|
|
|
}
|
|
|
|
LapEvecName = par().lapevec;
|
|
|
|
if( LapEvecName.size() == 0 ) {
|
|
|
|
LapEvecName = PerambulatorName;
|
|
|
|
LapEvecName.append( "_lapevec" );
|
|
|
|
}
|
|
|
|
return { PerambulatorName, NoiseVectorName, LapEvecName };
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FImpl>
|
|
|
|
std::vector<std::string> TDistilVectors<FImpl>::getOutput(void)
|
|
|
|
{
|
2019-04-29 18:40:38 +01:00
|
|
|
SourceName = par().source;
|
|
|
|
SinkName = par().sink;
|
|
|
|
bMakeSource = ( SourceName.size() > 0 );
|
|
|
|
bMakeSink = ( SinkName.size() > 0 );
|
|
|
|
if( !bMakeSource && !bMakeSink ) {
|
|
|
|
SourceName = getName();
|
|
|
|
SinkName = SourceName;
|
|
|
|
SourceName.append( "_rho" );
|
|
|
|
SinkName.append( "_phi" );
|
|
|
|
bMakeSource = true;
|
|
|
|
bMakeSink = true;
|
|
|
|
}
|
|
|
|
std::vector<std::string> out;
|
|
|
|
if( bMakeSource )
|
|
|
|
out.push_back( SourceName );
|
|
|
|
if( bMakeSink )
|
|
|
|
out.push_back( SinkName );
|
|
|
|
return out;
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// setup ///////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
void TDistilVectors<FImpl>::setup(void)
|
|
|
|
{
|
2019-04-29 18:40:38 +01:00
|
|
|
Cleanup();
|
2019-04-30 14:41:48 +01:00
|
|
|
auto &noise = envGet(NoiseTensor, NoiseVectorName);
|
2019-05-01 13:04:51 +01:00
|
|
|
auto &perambulator = envGet(PerambTensor, PerambulatorName);
|
2019-01-30 18:03:34 +00:00
|
|
|
|
2019-04-29 18:40:38 +01:00
|
|
|
// We expect the perambulator to have been created with these indices
|
2019-05-01 18:11:37 +01:00
|
|
|
assert( perambulator.ValidateIndexNames( PerambIndexNames.size(), &PerambIndexNames[0] ) && "Perambulator index names bad" );
|
2019-04-29 18:40:38 +01:00
|
|
|
|
2019-04-30 23:53:57 +01:00
|
|
|
const int Nt{ env().getDim(Tdir) };
|
2019-05-01 13:04:51 +01:00
|
|
|
assert( Nt == static_cast<int>( perambulator.tensor.dimension(0) ) && "PerambTensor time dimensionality bad" );
|
2019-04-30 23:53:57 +01:00
|
|
|
const int TI{ Hadrons::MDistil::DistilParameters::ParameterDefault( par().TI, Nt, true) };
|
|
|
|
const int LI{ static_cast<int>( perambulator.tensor.dimension(2) ) };
|
|
|
|
const int SI{ static_cast<int>( perambulator.tensor.dimension(5) ) };
|
|
|
|
const int Nt_inv{ static_cast<int>( perambulator.tensor.dimension(4) ) };
|
|
|
|
const int nnoise{ static_cast<int>( perambulator.tensor.dimension(3) ) };
|
|
|
|
assert( nnoise >= static_cast<int>( noise.dimension(0) ) && "Not enough noise vectors for perambulator" );
|
|
|
|
// Nvec defaults to what's in the perambulator unless overriden
|
|
|
|
const int nvec_per{ static_cast<int>( perambulator.tensor.dimension(1) ) };
|
|
|
|
const int nvec{Hadrons::MDistil::DistilParameters::ParameterDefault(par().nvec, nvec_per, true) };
|
|
|
|
assert( nvec <= nvec_per && "Not enough distillation sub-space vectors" );
|
2019-01-30 18:03:34 +00:00
|
|
|
|
2019-04-29 18:40:38 +01:00
|
|
|
if( bMakeSource )
|
|
|
|
envCreate(std::vector<FermionField>, SourceName, 1, nnoise*LI*SI*Nt_inv, envGetGrid(FermionField));
|
|
|
|
if( bMakeSink )
|
|
|
|
envCreate(std::vector<FermionField>, SinkName, 1, nnoise*LI*SI*Nt_inv, envGetGrid(FermionField));
|
2019-01-22 13:27:51 +00:00
|
|
|
|
2019-03-27 12:00:36 +00:00
|
|
|
grid4d = env().getGrid();
|
2019-01-22 13:27:51 +00:00
|
|
|
std::vector<int> latt_size = GridDefaultLatt();
|
|
|
|
std::vector<int> simd_layout = GridDefaultSimd(Nd, vComplex::Nsimd());
|
|
|
|
std::vector<int> mpi_layout = GridDefaultMpi();
|
|
|
|
std::vector<int> 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-03-20 14:41:36 +00:00
|
|
|
grid3d = MakeLowerDimGrid(grid4d);
|
2019-04-29 18:40:38 +01:00
|
|
|
|
|
|
|
|
2019-01-22 13:27:51 +00:00
|
|
|
envTmp(LatticeSpinColourVector, "tmp2",1,LatticeSpinColourVector(grid4d));
|
2019-04-29 18:40:38 +01:00
|
|
|
//envTmp(LatticeColourVector, "tmp_nospin",1,LatticeColourVector(grid4d));
|
2019-01-22 13:27:51 +00:00
|
|
|
envTmp(LatticeSpinColourVector, "tmp3d",1,LatticeSpinColourVector(grid3d));
|
|
|
|
envTmp(LatticeColourVector, "tmp3d_nospin",1,LatticeColourVector(grid3d));
|
|
|
|
envTmp(LatticeSpinColourVector, "sink_tslice",1,LatticeSpinColourVector(grid3d));
|
|
|
|
envTmp(LatticeColourVector, "evec3d",1,LatticeColourVector(grid3d));
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
2019-03-20 14:41:36 +00:00
|
|
|
// clean up any temporaries created by setup (that aren't stored in the environment)
|
|
|
|
template <typename FImpl>
|
|
|
|
void TDistilVectors<FImpl>::Cleanup(void)
|
|
|
|
{
|
|
|
|
if( grid3d != nullptr ) {
|
|
|
|
delete grid3d;
|
|
|
|
grid3d = nullptr;
|
|
|
|
}
|
|
|
|
grid4d = nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-18 13:14:28 +00:00
|
|
|
// execution ///////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
void TDistilVectors<FImpl>::execute(void)
|
|
|
|
{
|
2019-04-30 14:41:48 +01:00
|
|
|
auto &noise = envGet(NoiseTensor, NoiseVectorName);
|
2019-05-01 13:04:51 +01:00
|
|
|
auto &perambulator = envGet(PerambTensor, PerambulatorName);
|
2019-04-29 18:40:38 +01:00
|
|
|
auto &epack = envGet(Grid::Hadrons::EigenPack<LatticeColourVector>, LapEvecName);
|
|
|
|
|
2019-01-21 16:45:31 +00:00
|
|
|
envGetTmp(LatticeSpinColourVector, tmp2);
|
2019-01-22 13:27:51 +00:00
|
|
|
envGetTmp(LatticeSpinColourVector, tmp3d);
|
2019-04-30 23:53:57 +01:00
|
|
|
envGetTmp(LatticeColourVector, tmp3d_nospin);
|
2019-01-22 13:27:51 +00:00
|
|
|
envGetTmp(LatticeSpinColourVector, sink_tslice);
|
2019-04-30 23:53:57 +01:00
|
|
|
envGetTmp(LatticeColourVector, evec3d);
|
|
|
|
|
|
|
|
const int Ntlocal{ grid4d->LocalDimensions()[3] };
|
|
|
|
const int Ntfirst{ grid4d->LocalStarts()[3] };
|
|
|
|
|
|
|
|
const int Ns{ Grid::QCD::Ns };
|
|
|
|
const int Nt{ env().getDim(Tdir) };
|
|
|
|
const int TI{ Hadrons::MDistil::DistilParameters::ParameterDefault( par().TI, Nt, false ) };
|
|
|
|
const int LI{ static_cast<int>( perambulator.tensor.dimension(2) ) };
|
|
|
|
const int SI{ static_cast<int>( perambulator.tensor.dimension(5) ) };
|
|
|
|
const int Nt_inv{ static_cast<int>( perambulator.tensor.dimension(4) ) };
|
|
|
|
const int nnoise{ static_cast<int>( perambulator.tensor.dimension(3) ) };
|
|
|
|
// Nvec defaults to what's in the perambulator unless overriden
|
|
|
|
const int nvec{Hadrons::MDistil::DistilParameters::ParameterDefault(par().nvec, static_cast<int>( perambulator.tensor.dimension(1) ), false)};
|
|
|
|
const int tsrc{ par().tsrc };
|
|
|
|
const bool full_tdil{ TI==Nt };
|
|
|
|
|
2019-01-21 16:45:31 +00:00
|
|
|
int vecindex;
|
2019-01-31 11:35:05 +00:00
|
|
|
int t_inv;
|
2019-04-29 18:40:38 +01:00
|
|
|
if( bMakeSource ) {
|
|
|
|
auto &rho = envGet(std::vector<FermionField>, SourceName);
|
2019-04-30 14:41:48 +01:00
|
|
|
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 < SI; ds++ ) {
|
2019-04-29 18:40:38 +01:00
|
|
|
vecindex = inoise + nnoise * dk + nnoise * LI * ds + nnoise *LI * SI*dt;
|
|
|
|
rho[vecindex] = zero;
|
|
|
|
tmp3d_nospin = zero;
|
|
|
|
for (int it = dt; it < Nt; it += TI){
|
|
|
|
if (full_tdil) t_inv = tsrc; else t_inv = it;
|
|
|
|
if( t_inv >= Ntfirst && t_inv < Ntfirst + Ntlocal ) {
|
|
|
|
for (int ik = dk; ik < nvec; ik += LI){
|
|
|
|
for (int is = ds; is < Ns; is += SI){
|
2019-05-06 10:35:42 +01:00
|
|
|
ExtractSliceLocal(evec3d,epack.evec[ik],0,t_inv-Ntfirst,Grid::QCD::Tdir);
|
2019-04-30 14:41:48 +01:00
|
|
|
//tmp3d_nospin = evec3d * noise[inoise + nnoise*(t_inv + Nt*(ik+nvec*is))];
|
|
|
|
tmp3d_nospin = evec3d * noise(inoise, t_inv, ik, is);
|
2019-04-29 18:40:38 +01:00
|
|
|
tmp3d=zero;
|
|
|
|
pokeSpin(tmp3d,tmp3d_nospin,is);
|
|
|
|
tmp2=zero;
|
|
|
|
InsertSliceLocal(tmp3d,tmp2,0,t_inv-Ntfirst,Grid::QCD::Tdir);
|
|
|
|
rho[vecindex] += tmp2;
|
|
|
|
}
|
2019-03-05 12:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 18:40:38 +01:00
|
|
|
if( bMakeSink ) {
|
|
|
|
auto &phi = envGet(std::vector<FermionField>, SinkName);
|
2019-04-30 14:41:48 +01:00
|
|
|
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 < SI; ds++ ) {
|
2019-04-29 18:40:38 +01:00
|
|
|
vecindex = inoise + nnoise * dk + nnoise * LI * ds + nnoise *LI * SI*dt;
|
|
|
|
phi[vecindex] = zero;
|
|
|
|
for (int t = Ntfirst; t < Ntfirst + Ntlocal; t++) {
|
|
|
|
sink_tslice=zero;
|
|
|
|
for (int ivec = 0; ivec < nvec; ivec++) {
|
2019-05-06 10:35:42 +01:00
|
|
|
ExtractSliceLocal(evec3d,epack.evec[ivec],0,t-Ntfirst,Grid::QCD::Tdir);
|
2019-04-29 18:40:38 +01:00
|
|
|
sink_tslice += evec3d * perambulator(t, ivec, dk, inoise,dt,ds);
|
|
|
|
}
|
|
|
|
InsertSliceLocal(sink_tslice,phi[vecindex],0,t-Ntfirst,Grid::QCD::Tdir);
|
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_
|