mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 15:55:37 +00:00
244 lines
8.0 KiB
C++
244 lines
8.0 KiB
C++
/*************************************************************************************
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
Source file: extras/Hadrons/Modules/MScalarSUN/TwoPoint.hpp
|
|
|
|
Copyright (C) 2015-2018
|
|
|
|
Author: Antonin Portelli <antonin.portelli@me.com>
|
|
|
|
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 */
|
|
#ifndef Hadrons_MScalarSUN_TwoPoint_hpp_
|
|
#define Hadrons_MScalarSUN_TwoPoint_hpp_
|
|
|
|
#include <Grid/Hadrons/Global.hpp>
|
|
#include <Grid/Hadrons/Module.hpp>
|
|
#include <Grid/Hadrons/ModuleFactory.hpp>
|
|
#include <Grid/Hadrons/Modules/MScalarSUN/Utils.hpp>
|
|
|
|
BEGIN_HADRONS_NAMESPACE
|
|
|
|
/******************************************************************************
|
|
* 2-pt functions for a given set of operators *
|
|
******************************************************************************/
|
|
BEGIN_MODULE_NAMESPACE(MScalarSUN)
|
|
|
|
class TwoPointPar: Serializable
|
|
{
|
|
public:
|
|
typedef std::pair<std::string, std::string> OpPair;
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(TwoPointPar,
|
|
std::vector<OpPair>, op,
|
|
std::vector<std::string>, mom,
|
|
std::string, output);
|
|
};
|
|
|
|
template <typename SImpl>
|
|
class TTwoPoint: public Module<TwoPointPar>
|
|
{
|
|
public:
|
|
typedef typename SImpl::Field Field;
|
|
typedef typename SImpl::ComplexField ComplexField;
|
|
typedef std::vector<TComplex> SlicedOp;
|
|
|
|
class Result: Serializable
|
|
{
|
|
public:
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
|
|
std::string, sink,
|
|
std::string, source,
|
|
std::vector<int>, mom,
|
|
std::vector<Complex>, data);
|
|
};
|
|
public:
|
|
// constructor
|
|
TTwoPoint(const std::string name);
|
|
// destructor
|
|
virtual ~TTwoPoint(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);
|
|
private:
|
|
// make 2-pt function
|
|
template <class SinkSite, class SourceSite>
|
|
std::vector<Complex> makeTwoPoint(const std::vector<SinkSite> &sink,
|
|
const std::vector<SourceSite> &source);
|
|
private:
|
|
std::vector<std::vector<int>> mom_;
|
|
};
|
|
|
|
MODULE_REGISTER_TMP(TwoPointSU2, TTwoPoint<ScalarNxNAdjImplR<2>>, MScalarSUN);
|
|
MODULE_REGISTER_TMP(TwoPointSU3, TTwoPoint<ScalarNxNAdjImplR<3>>, MScalarSUN);
|
|
MODULE_REGISTER_TMP(TwoPointSU4, TTwoPoint<ScalarNxNAdjImplR<4>>, MScalarSUN);
|
|
MODULE_REGISTER_TMP(TwoPointSU5, TTwoPoint<ScalarNxNAdjImplR<5>>, MScalarSUN);
|
|
MODULE_REGISTER_TMP(TwoPointSU6, TTwoPoint<ScalarNxNAdjImplR<6>>, MScalarSUN);
|
|
|
|
/******************************************************************************
|
|
* TTwoPoint implementation *
|
|
******************************************************************************/
|
|
// constructor /////////////////////////////////////////////////////////////////
|
|
template <typename SImpl>
|
|
TTwoPoint<SImpl>::TTwoPoint(const std::string name)
|
|
: Module<TwoPointPar>(name)
|
|
{}
|
|
|
|
// dependencies/products ///////////////////////////////////////////////////////
|
|
template <typename SImpl>
|
|
std::vector<std::string> TTwoPoint<SImpl>::getInput(void)
|
|
{
|
|
std::vector<std::string> in;
|
|
std::set<std::string> ops;
|
|
|
|
for (auto &p: par().op)
|
|
{
|
|
ops.insert(p.first);
|
|
ops.insert(p.second);
|
|
}
|
|
for (auto &o: ops)
|
|
{
|
|
in.push_back(o);
|
|
}
|
|
|
|
return in;
|
|
}
|
|
|
|
template <typename SImpl>
|
|
std::vector<std::string> TTwoPoint<SImpl>::getOutput(void)
|
|
{
|
|
std::vector<std::string> out = {};
|
|
|
|
return out;
|
|
}
|
|
|
|
// setup ///////////////////////////////////////////////////////////////////////
|
|
template <typename SImpl>
|
|
void TTwoPoint<SImpl>::setup(void)
|
|
{
|
|
const unsigned int nd = env().getDim().size();
|
|
|
|
mom_.resize(par().mom.size());
|
|
for (unsigned int i = 0; i < mom_.size(); ++i)
|
|
{
|
|
mom_[i] = strToVec<int>(par().mom[i]);
|
|
if (mom_[i].size() != nd - 1)
|
|
{
|
|
HADRONS_ERROR(Size, "momentum number of components different from "
|
|
+ std::to_string(nd-1));
|
|
}
|
|
}
|
|
envTmpLat(ComplexField, "ftBuf");
|
|
}
|
|
|
|
// execution ///////////////////////////////////////////////////////////////////
|
|
template <typename SImpl>
|
|
void TTwoPoint<SImpl>::execute(void)
|
|
{
|
|
LOG(Message) << "Computing 2-point functions" << std::endl;
|
|
for (auto &p: par().op)
|
|
{
|
|
LOG(Message) << " <" << p.first << " " << p.second << ">" << std::endl;
|
|
}
|
|
|
|
const unsigned int nd = env().getDim().size();
|
|
const unsigned int nt = env().getDim().back();
|
|
const unsigned int nop = par().op.size();
|
|
const unsigned int nmom = mom_.size();
|
|
std::vector<int> dMask(nd, 1);
|
|
std::set<std::string> ops;
|
|
std::vector<Result> result;
|
|
std::map<std::string, std::vector<SlicedOp>> slicedOp;
|
|
FFT fft(env().getGrid());
|
|
|
|
envGetTmp(ComplexField, ftBuf);
|
|
dMask[nd - 1] = 0;
|
|
for (auto &p: par().op)
|
|
{
|
|
ops.insert(p.first);
|
|
ops.insert(p.second);
|
|
}
|
|
for (auto &o: ops)
|
|
{
|
|
auto &op = envGet(ComplexField, o);
|
|
|
|
slicedOp[o].resize(nmom);
|
|
LOG(Message) << "Operator '" << o << "' FFT" << std::endl;
|
|
fft.FFT_dim_mask(ftBuf, op, dMask, FFT::backward);
|
|
for (unsigned int m = 0; m < nmom; ++m)
|
|
{
|
|
auto qt = mom_[m];
|
|
|
|
qt.resize(nd);
|
|
slicedOp[o][m].resize(nt);
|
|
for (unsigned int t = 0; t < nt; ++t)
|
|
{
|
|
qt[nd - 1] = t;
|
|
peekSite(slicedOp[o][m][t], ftBuf, qt);
|
|
}
|
|
}
|
|
}
|
|
LOG(Message) << "Making contractions" << std::endl;
|
|
for (unsigned int m = 0; m < nmom; ++m)
|
|
for (auto &p: par().op)
|
|
{
|
|
Result r;
|
|
|
|
r.sink = p.first;
|
|
r.source = p.second;
|
|
r.mom = mom_[m];
|
|
r.data = makeTwoPoint(slicedOp[p.first][m], slicedOp[p.second][m]);
|
|
result.push_back(r);
|
|
}
|
|
saveResult(par().output, "twopt", result);
|
|
}
|
|
|
|
// make 2-pt function //////////////////////////////////////////////////////////
|
|
template <class SImpl>
|
|
template <class SinkSite, class SourceSite>
|
|
std::vector<Complex> TTwoPoint<SImpl>::makeTwoPoint(
|
|
const std::vector<SinkSite> &sink,
|
|
const std::vector<SourceSite> &source)
|
|
{
|
|
assert(sink.size() == source.size());
|
|
|
|
unsigned int nt = sink.size();
|
|
std::vector<Complex> res(nt, 0.);
|
|
|
|
for (unsigned int dt = 0; dt < nt; ++dt)
|
|
{
|
|
for (unsigned int t = 0; t < nt; ++t)
|
|
{
|
|
res[dt] += TensorRemove(trace(sink[(t+dt)%nt]*adj(source[t])));
|
|
}
|
|
res[dt] *= 1./static_cast<double>(nt);
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
END_MODULE_NAMESPACE
|
|
|
|
END_HADRONS_NAMESPACE
|
|
|
|
#endif // Hadrons_MScalarSUN_TwoPoint_hpp_
|