2019-05-23 16:38:13 +01:00
|
|
|
#ifndef Hadrons_MSource_Gauss_hpp_
|
|
|
|
#define Hadrons_MSource_Gauss_hpp_
|
|
|
|
|
|
|
|
#include <Hadrons/Global.hpp>
|
|
|
|
#include <Hadrons/Module.hpp>
|
|
|
|
#include <Hadrons/ModuleFactory.hpp>
|
|
|
|
|
|
|
|
BEGIN_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Gauss *
|
2019-05-23 17:33:32 +01:00
|
|
|
* result[n] = 1/(sqrt(2*pi)*width)^dim *
|
2019-05-28 17:26:55 +01:00
|
|
|
* * exp(-|n-position|^2/(2*width^2)) *
|
2019-06-01 23:56:14 +01:00
|
|
|
* * exp(i*2*pi/L*mom*n) *
|
2019-05-23 16:38:13 +01:00
|
|
|
* where: *
|
|
|
|
* n=(n[0],n[1],...,n[dim-1]) (lattice coordinate) *
|
|
|
|
* dim=Nd-1 *
|
|
|
|
******************************************************************************/
|
|
|
|
BEGIN_MODULE_NAMESPACE(MSource)
|
|
|
|
|
|
|
|
class GaussPar: Serializable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(GaussPar,
|
|
|
|
std::string, position,
|
2019-06-01 23:56:14 +01:00
|
|
|
std::string, mom,
|
2019-06-02 12:36:57 +01:00
|
|
|
Integer, tA,
|
|
|
|
Integer, tB,
|
2019-05-23 16:38:13 +01:00
|
|
|
double, width);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename FImpl>
|
|
|
|
class TGauss: public Module<GaussPar>
|
|
|
|
{
|
2019-05-29 16:25:45 +01:00
|
|
|
BASIC_TYPE_ALIASES(FImpl,);
|
2019-05-23 16:38:13 +01:00
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
TGauss(const std::string name);
|
|
|
|
// destructor
|
|
|
|
virtual ~TGauss(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:
|
|
|
|
std::vector<int> position_;
|
2019-06-01 23:56:14 +01:00
|
|
|
std::vector<int> mom_;
|
2019-05-23 16:38:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_REGISTER_TMP(Gauss, TGauss<FIMPL>, MSource);
|
2019-06-01 23:56:14 +01:00
|
|
|
MODULE_REGISTER_TMP(ScalarGauss, TGauss<ScalarImplCR>, MSource);
|
2019-05-23 16:38:13 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* TGauss implementation *
|
|
|
|
******************************************************************************/
|
|
|
|
// constructor /////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
TGauss<FImpl>::TGauss(const std::string name)
|
|
|
|
: Module<GaussPar>(name)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// dependencies/products ///////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
std::vector<std::string> TGauss<FImpl>::getInput(void)
|
|
|
|
{
|
|
|
|
std::vector<std::string> in;
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FImpl>
|
|
|
|
std::vector<std::string> TGauss<FImpl>::getOutput(void)
|
|
|
|
{
|
|
|
|
std::vector<std::string> out = {getName()};
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup ///////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
void TGauss<FImpl>::setup(void)
|
|
|
|
{
|
2019-06-01 23:56:14 +01:00
|
|
|
auto parse_vector = [](const std::string &vec, int dim,
|
|
|
|
const std::string &desc)
|
|
|
|
{
|
|
|
|
std::vector<int> res = strToVec<int>(vec);
|
|
|
|
if(res.size() != dim) {
|
|
|
|
HADRONS_ERROR(Size, desc + " has "
|
|
|
|
+ std::to_string(res.size()) + " instead of "
|
|
|
|
+ std::to_string(dim) + " components");
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
position_ = parse_vector(par().position, env().getNd()-1, "position");
|
|
|
|
mom_ = parse_vector(par().mom, env().getNd(), "momentum");
|
|
|
|
|
|
|
|
envCreateLat(PropagatorField, getName());
|
2019-05-29 16:25:45 +01:00
|
|
|
envTmpLat(ComplexField, "component");
|
2019-06-01 23:56:14 +01:00
|
|
|
envTmpLat(ComplexField, "ScalarRho");
|
|
|
|
envTmp(LatticeInteger, "compHelper", 1, envGetGrid(ComplexField));
|
2019-05-23 16:38:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// execution ///////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
void TGauss<FImpl>::execute(void)
|
|
|
|
{
|
2019-06-01 23:56:14 +01:00
|
|
|
auto &rho = envGet(PropagatorField, getName());
|
2019-05-29 16:25:45 +01:00
|
|
|
envGetTmp(ComplexField, component);
|
2019-06-01 23:56:14 +01:00
|
|
|
envGetTmp(ComplexField, ScalarRho);
|
|
|
|
envGetTmp(LatticeInteger, compHelper);
|
2019-05-23 16:38:13 +01:00
|
|
|
const int dim=env().getNd()-1;
|
2019-06-01 23:56:14 +01:00
|
|
|
const Real fact=-0.5/std::pow(par().width,2);
|
2019-05-24 20:16:09 +01:00
|
|
|
const Complex i(0.0, 1.0);
|
2019-08-12 14:57:11 +01:00
|
|
|
const Real Pi(M_PI);
|
2019-06-01 23:56:14 +01:00
|
|
|
const SitePropagator idMat=[](){ SitePropagator s; s=1.; return s; }();
|
2019-05-23 16:38:13 +01:00
|
|
|
|
2019-08-15 01:43:00 +01:00
|
|
|
ScalarRho=Zero();
|
2019-05-23 16:38:13 +01:00
|
|
|
for(int mu=0; mu<dim; mu++) {
|
2019-05-23 17:33:32 +01:00
|
|
|
assert(env().getDim(mu)%2==0);
|
2019-06-01 23:56:14 +01:00
|
|
|
assert(position_[mu]>=0 && position_[mu]<env().getDim(mu));
|
|
|
|
|
|
|
|
const int Lmu=env().getDim(mu);
|
|
|
|
const int LmuHalf=Lmu/2;
|
|
|
|
const int posMu=position_[mu];
|
|
|
|
|
|
|
|
LatticeCoordinate(component, mu);
|
|
|
|
LatticeCoordinate(compHelper, mu);
|
|
|
|
|
|
|
|
//spatial dimensions of momentum phase
|
2019-08-12 14:57:11 +01:00
|
|
|
ScalarRho+=(i*(mom_[mu]*2*Pi/Lmu))*component;
|
2019-06-01 23:56:14 +01:00
|
|
|
|
|
|
|
//Gauss distribution
|
|
|
|
component-=Complex(posMu);
|
2019-06-02 12:36:57 +01:00
|
|
|
if(posMu<LmuHalf)
|
2019-06-01 23:56:14 +01:00
|
|
|
{
|
2019-06-02 12:36:57 +01:00
|
|
|
component=where((compHelper>Integer(posMu+LmuHalf)),
|
2019-06-01 23:56:14 +01:00
|
|
|
component-Complex(Lmu),
|
|
|
|
component);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-02 12:36:57 +01:00
|
|
|
component=where((compHelper<=Integer(posMu-LmuHalf)),
|
2019-06-01 23:56:14 +01:00
|
|
|
component+Complex(Lmu),
|
|
|
|
component);
|
|
|
|
}
|
|
|
|
ScalarRho+=component*component*fact;
|
2019-05-23 16:38:13 +01:00
|
|
|
}
|
|
|
|
|
2019-06-01 23:56:14 +01:00
|
|
|
//time component of momentum phase
|
|
|
|
LatticeCoordinate(component, dim);
|
2019-08-12 14:57:11 +01:00
|
|
|
ScalarRho+=(i*(mom_.at(dim)*2*Pi/env().getDim(dim)))*component;
|
2019-06-02 11:52:05 +01:00
|
|
|
|
|
|
|
//compute scalar result
|
2019-08-12 14:57:11 +01:00
|
|
|
ScalarRho=exp(ScalarRho)*Complex(std::pow(sqrt(2*Pi)*par().width,-dim));
|
2019-06-02 11:52:05 +01:00
|
|
|
|
|
|
|
//select time slices
|
|
|
|
LatticeCoordinate(compHelper, dim);
|
2019-06-02 12:36:57 +01:00
|
|
|
ScalarRho=where((compHelper>=par().tA && compHelper<=par().tB),
|
2019-06-02 00:12:15 +01:00
|
|
|
ScalarRho,
|
|
|
|
0.*ScalarRho);
|
2019-06-01 23:56:14 +01:00
|
|
|
|
2019-06-02 11:52:05 +01:00
|
|
|
//compute output field rho
|
|
|
|
rho=ScalarRho*idMat;
|
2019-05-23 16:38:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
END_MODULE_NAMESPACE
|
|
|
|
|
|
|
|
END_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
#endif // Hadrons_MSource_Gauss_hpp_
|