2019-04-26 07:24:56 +01:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
2019-04-26 08:23:15 +01:00
|
|
|
Source file: Hadrons/Modules/MDistil/Perambulator.hpp
|
2019-04-26 07:24:56 +01:00
|
|
|
|
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-04-26 08:23:15 +01:00
|
|
|
#ifndef Hadrons_MDistil_Perambulator_hpp_
|
|
|
|
#define Hadrons_MDistil_Perambulator_hpp_
|
2019-01-18 13:14:28 +00:00
|
|
|
|
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 15:06:45 +00:00
|
|
|
|
2019-01-18 13:14:28 +00:00
|
|
|
/******************************************************************************
|
2019-04-26 08:23:15 +01:00
|
|
|
* Perambulator *
|
2019-01-18 13:14:28 +00:00
|
|
|
******************************************************************************/
|
|
|
|
BEGIN_MODULE_NAMESPACE(MDistil)
|
2019-01-31 12:24:32 +00:00
|
|
|
|
2019-04-26 08:23:15 +01:00
|
|
|
class PerambulatorPar: Serializable
|
2019-01-18 13:14:28 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-04-26 08:23:15 +01:00
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(PerambulatorPar,
|
2019-04-30 23:53:57 +01:00
|
|
|
std::string, lapevec,
|
|
|
|
std::string, solver,
|
2019-04-18 17:47:09 +01:00
|
|
|
std::string, noise,
|
2019-03-13 12:09:12 +00:00
|
|
|
std::string, PerambFileName, //stem!!!
|
2019-01-31 12:24:32 +00:00
|
|
|
int, nvec,
|
2019-04-30 23:53:57 +01:00
|
|
|
DistilParameters, Distil);
|
2019-01-18 13:14:28 +00:00
|
|
|
};
|
|
|
|
|
2019-02-01 13:23:42 +00:00
|
|
|
template <typename FImpl>
|
2019-04-26 08:23:15 +01:00
|
|
|
class TPerambulator: public Module<PerambulatorPar>
|
2019-01-18 13:14:28 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-04-30 23:53:57 +01:00
|
|
|
FERM_TYPE_ALIASES(FImpl,);
|
|
|
|
SOLVER_TYPE_ALIASES(FImpl,);
|
|
|
|
// constructor
|
|
|
|
TPerambulator(const std::string name);
|
|
|
|
// destructor
|
|
|
|
virtual ~TPerambulator(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-01-30 21:16:09 +00:00
|
|
|
protected:
|
2019-04-30 23:53:57 +01:00
|
|
|
virtual void Cleanup(void);
|
2019-01-30 21:16:09 +00:00
|
|
|
protected:
|
2019-04-30 23:53:57 +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)
|
|
|
|
// Other members
|
|
|
|
unsigned int Ls_;
|
|
|
|
std::string sLapEvecName;
|
|
|
|
std::string sNoiseName;
|
2019-01-18 13:14:28 +00:00
|
|
|
};
|
|
|
|
|
2019-04-26 08:23:15 +01:00
|
|
|
// Can't name the module Perambulator, because that's what we've called the object
|
|
|
|
MODULE_REGISTER_TMP(Peramb, TPerambulator<FIMPL>, MDistil);
|
2019-01-18 13:14:28 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
2019-04-26 08:23:15 +01:00
|
|
|
* TPerambulator implementation *
|
2019-01-18 13:14:28 +00:00
|
|
|
******************************************************************************/
|
|
|
|
// constructor /////////////////////////////////////////////////////////////////
|
2019-02-01 13:23:42 +00:00
|
|
|
template <typename FImpl>
|
2019-04-26 08:23:15 +01:00
|
|
|
TPerambulator<FImpl>::TPerambulator(const std::string name)
|
|
|
|
: grid3d{nullptr}, grid4d{nullptr}, Module<PerambulatorPar>(name)
|
2019-01-18 13:14:28 +00:00
|
|
|
{}
|
|
|
|
|
2019-01-30 21:16:09 +00:00
|
|
|
// destructor
|
2019-02-01 13:23:42 +00:00
|
|
|
template <typename FImpl>
|
2019-04-26 08:23:15 +01:00
|
|
|
TPerambulator<FImpl>::~TPerambulator(void)
|
2019-01-30 21:16:09 +00:00
|
|
|
{
|
|
|
|
Cleanup();
|
|
|
|
};
|
|
|
|
|
2019-01-18 13:14:28 +00:00
|
|
|
// dependencies/products ///////////////////////////////////////////////////////
|
2019-02-01 13:23:42 +00:00
|
|
|
template <typename FImpl>
|
2019-04-26 08:23:15 +01:00
|
|
|
std::vector<std::string> TPerambulator<FImpl>::getInput(void)
|
2019-01-18 13:14:28 +00:00
|
|
|
{
|
2019-04-30 23:53:57 +01:00
|
|
|
sLapEvecName = par().lapevec;
|
|
|
|
sNoiseName = par().noise;
|
|
|
|
if( sNoiseName.length() == 0 )
|
|
|
|
sNoiseName = getName() + "_noise";
|
|
|
|
return {sLapEvecName, par().solver, sNoiseName };
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
2019-02-01 13:23:42 +00:00
|
|
|
template <typename FImpl>
|
2019-04-26 08:23:15 +01:00
|
|
|
std::vector<std::string> TPerambulator<FImpl>::getOutput(void)
|
2019-01-18 13:14:28 +00:00
|
|
|
{
|
2019-04-30 23:53:57 +01:00
|
|
|
return {getName(), getName() + "_unsmeared_sink"};
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// setup ///////////////////////////////////////////////////////////////////////
|
2019-02-01 13:23:42 +00:00
|
|
|
template <typename FImpl>
|
2019-04-26 08:23:15 +01:00
|
|
|
void TPerambulator<FImpl>::setup(void)
|
2019-01-18 13:14:28 +00:00
|
|
|
{
|
2019-04-30 14:41:48 +01:00
|
|
|
Cleanup();
|
|
|
|
grid4d = env().getGrid();
|
|
|
|
grid3d = MakeLowerDimGrid(grid4d);
|
2019-04-30 23:53:57 +01:00
|
|
|
DISTIL_PARAMETERS_DEFINE( true );
|
2019-04-30 14:41:48 +01:00
|
|
|
|
2019-04-30 23:53:57 +01:00
|
|
|
envCreate(Perambulator, getName(), 1, PerambIndexNames,Nt,nvec,LI,nnoise,Nt_inv,SI);
|
2019-04-30 14:41:48 +01:00
|
|
|
envCreate(std::vector<FermionField>, getName() + "_unsmeared_sink", 1,
|
2019-02-01 13:23:42 +00:00
|
|
|
nnoise*LI*Ns*Nt_inv, envGetGrid(FermionField));
|
2019-04-30 14:41:48 +01:00
|
|
|
|
|
|
|
envTmpLat(LatticeSpinColourVector, "dist_source");
|
|
|
|
envTmpLat(LatticeSpinColourVector, "tmp2");
|
|
|
|
envTmpLat(LatticeSpinColourVector, "result");
|
|
|
|
envTmpLat(LatticeColourVector, "result_nospin");
|
|
|
|
envTmp(LatticeSpinColourVector, "tmp3d",1,LatticeSpinColourVector(grid3d));
|
|
|
|
envTmp(LatticeColourVector, "tmp3d_nospin",1,LatticeColourVector(grid3d));
|
|
|
|
envTmp(LatticeColourVector, "result_3d",1,LatticeColourVector(grid3d));
|
|
|
|
envTmp(LatticeColourVector, "evec3d",1,LatticeColourVector(grid3d));
|
|
|
|
|
|
|
|
Ls_ = env().getObjectLs(par().solver);
|
|
|
|
envTmpLat(FermionField, "v4dtmp");
|
|
|
|
envTmpLat(FermionField, "v5dtmp", Ls_);
|
|
|
|
envTmpLat(FermionField, "v5dtmp_sol", Ls_);
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 21:16:09 +00:00
|
|
|
// clean up any temporaries created by setup (that aren't stored in the environment)
|
2019-02-01 13:23:42 +00:00
|
|
|
template <typename FImpl>
|
2019-04-26 08:23:15 +01:00
|
|
|
void TPerambulator<FImpl>::Cleanup(void)
|
2019-01-30 21:16:09 +00:00
|
|
|
{
|
|
|
|
if( grid3d != nullptr ) {
|
|
|
|
delete grid3d;
|
|
|
|
grid3d = nullptr;
|
|
|
|
}
|
|
|
|
grid4d = nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-18 13:14:28 +00:00
|
|
|
// execution ///////////////////////////////////////////////////////////////////
|
2019-02-01 13:23:42 +00:00
|
|
|
template <typename FImpl>
|
2019-04-26 08:23:15 +01:00
|
|
|
void TPerambulator<FImpl>::execute(void)
|
2019-01-18 13:14:28 +00:00
|
|
|
{
|
2019-04-30 23:53:57 +01:00
|
|
|
DISTIL_PARAMETERS_DEFINE( false );
|
2019-04-30 14:41:48 +01:00
|
|
|
|
2019-03-08 16:28:21 +00:00
|
|
|
auto &solver=envGet(Solver, par().solver);
|
|
|
|
auto &mat = solver.getFMat();
|
|
|
|
envGetTmp(FermionField, v4dtmp);
|
|
|
|
envGetTmp(FermionField, v5dtmp);
|
|
|
|
envGetTmp(FermionField, v5dtmp_sol);
|
|
|
|
|
2019-04-30 23:53:57 +01:00
|
|
|
auto &noise = envGet(NoiseTensor, sNoiseName);
|
|
|
|
auto &perambulator = envGet(Perambulator, getName());
|
|
|
|
auto &epack = envGet(LapEvecs, sLapEvecName);
|
2019-04-19 13:54:25 +01:00
|
|
|
auto &unsmeared_sink = envGet(std::vector<FermionField>, getName() + "_unsmeared_sink");
|
2019-01-22 15:52:26 +00:00
|
|
|
|
2019-02-04 12:06:32 +00:00
|
|
|
|
|
|
|
// Load perambulator if it exists on disk instead of creating it
|
2019-03-13 13:15:12 +00:00
|
|
|
// Not sure this is how we want it - rather specify an input flag 'read'
|
|
|
|
// and assert that the file is there.
|
2019-02-04 12:06:32 +00:00
|
|
|
|
2019-01-22 15:52:26 +00:00
|
|
|
envGetTmp(LatticeSpinColourVector, dist_source);
|
|
|
|
envGetTmp(LatticeSpinColourVector, tmp2);
|
|
|
|
envGetTmp(LatticeSpinColourVector, result);
|
|
|
|
envGetTmp(LatticeColourVector, result_nospin);
|
|
|
|
envGetTmp(LatticeSpinColourVector, tmp3d);
|
|
|
|
envGetTmp(LatticeColourVector, tmp3d_nospin);
|
|
|
|
envGetTmp(LatticeColourVector, result_3d);
|
|
|
|
envGetTmp(LatticeColourVector, evec3d);
|
|
|
|
|
2019-01-31 12:24:32 +00:00
|
|
|
const int Ntlocal{grid4d->LocalDimensions()[3]};
|
|
|
|
const int Ntfirst{grid4d->LocalStarts()[3]};
|
2019-01-23 13:58:20 +00:00
|
|
|
|
2019-01-31 12:24:32 +00:00
|
|
|
{
|
2019-03-13 12:09:12 +00:00
|
|
|
|
2019-01-31 11:35:05 +00:00
|
|
|
int t_inv;
|
2019-01-18 17:47:41 +00:00
|
|
|
for (int inoise = 0; inoise < nnoise; inoise++) {
|
|
|
|
for (int dk = 0; dk < LI; dk++) {
|
|
|
|
for (int dt = 0; dt < Nt_inv; dt++) {
|
2019-03-22 13:30:11 +00:00
|
|
|
for (int ds = 0; ds < SI; ds++) {
|
2019-01-18 17:47:41 +00:00
|
|
|
std::cout << "LapH source vector from noise " << inoise << " and dilution component (d_k,d_t,d_alpha) : (" << dk << ","<< dt << "," << ds << ")" << std::endl;
|
|
|
|
dist_source = zero;
|
|
|
|
tmp3d_nospin = zero;
|
|
|
|
evec3d = zero;
|
|
|
|
for (int it = dt; it < Nt; it += TI){
|
2019-01-31 11:35:05 +00:00
|
|
|
if (full_tdil) t_inv = tsrc; else t_inv = it;
|
|
|
|
if( t_inv >= Ntfirst && t_inv < Ntfirst + Ntlocal ) {
|
2019-01-18 17:47:41 +00:00
|
|
|
for (int ik = dk; ik < nvec; ik += LI){
|
2019-03-22 13:30:11 +00:00
|
|
|
for (int is = ds; is < Ns; is += SI){
|
2019-01-31 11:35:05 +00:00
|
|
|
ExtractSliceLocal(evec3d,epack.evec[ik],0,t_inv,3);
|
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-01-18 17:47:41 +00:00
|
|
|
tmp3d=zero;
|
|
|
|
pokeSpin(tmp3d,tmp3d_nospin,is);
|
|
|
|
tmp2=zero;
|
2019-01-31 11:35:05 +00:00
|
|
|
InsertSliceLocal(tmp3d,tmp2,0,t_inv-Ntfirst,Grid::QCD::Tdir);
|
2019-01-18 17:47:41 +00:00
|
|
|
dist_source += tmp2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result=zero;
|
2019-03-08 16:28:21 +00:00
|
|
|
v4dtmp = dist_source;
|
|
|
|
if (Ls_ == 1){
|
|
|
|
solver(result, v4dtmp);
|
|
|
|
} else {
|
|
|
|
mat.ImportPhysicalFermionSource(v4dtmp, v5dtmp);
|
|
|
|
solver(v5dtmp_sol, v5dtmp);
|
|
|
|
mat.ExportPhysicalFermionSolution(v5dtmp_sol, v4dtmp);
|
|
|
|
result = v4dtmp;
|
|
|
|
}
|
2019-02-01 13:23:42 +00:00
|
|
|
if ((1)) // comment out if unsmeared sink is too large???
|
|
|
|
unsmeared_sink[inoise+nnoise*(dk+LI*(dt+Nt_inv*ds))] = result;
|
2019-01-18 17:47:41 +00:00
|
|
|
for (int is = 0; is < Ns; is++) {
|
|
|
|
result_nospin = peekSpin(result,is);
|
|
|
|
for (int t = Ntfirst; t < Ntfirst + Ntlocal; t++) {
|
|
|
|
ExtractSliceLocal(result_3d,result_nospin,0,t-Ntfirst,Grid::QCD::Tdir);
|
|
|
|
for (int ivec = 0; ivec < nvec; ivec++) {
|
2019-01-22 15:52:26 +00:00
|
|
|
ExtractSliceLocal(evec3d,epack.evec[ivec],0,t,3);
|
2019-03-25 22:56:01 +00:00
|
|
|
pokeSpin(perambulator(t, ivec, dk, inoise,dt,ds),static_cast<Complex>(innerProduct(evec3d, result_3d)),is);
|
2019-01-18 17:47:41 +00:00
|
|
|
}
|
2019-04-28 23:24:57 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-18 17:47:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-31 12:24:32 +00:00
|
|
|
}
|
2019-04-28 23:24:57 +01:00
|
|
|
std::cout << "perambulator done" << std::endl;
|
|
|
|
perambulator.SliceShare( grid3d, grid4d );
|
|
|
|
|
|
|
|
if(grid4d->IsBoss()) {
|
|
|
|
std::string sPerambName{par().PerambFileName};
|
|
|
|
if( sPerambName.length() == 0 )
|
|
|
|
sPerambName = getName();
|
|
|
|
sPerambName.append( "." );
|
|
|
|
sPerambName.append( std::to_string(vm().getTrajectory()));
|
2019-04-28 17:53:42 +01:00
|
|
|
//perambulator.WriteBinary(sPerambName);
|
2019-04-28 20:23:44 +01:00
|
|
|
perambulator.write(sPerambName.c_str());
|
2019-04-28 17:53:42 +01:00
|
|
|
}
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
END_MODULE_NAMESPACE
|
|
|
|
|
|
|
|
END_HADRONS_NAMESPACE
|
|
|
|
|
2019-04-26 08:23:15 +01:00
|
|
|
#endif // Hadrons_MDistil_Perambulator_hpp_
|