From 8d540a4e85424d29afdc99f1a415b4bba2927d58 Mon Sep 17 00:00:00 2001 From: Nils Asmussen Date: Sat, 1 Jun 2019 23:56:14 +0100 Subject: [PATCH] MSource::Gauss add mom parameter + avoid Cshifts --- Hadrons/Modules/MSource/Gauss.hpp | 81 +++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 19 deletions(-) diff --git a/Hadrons/Modules/MSource/Gauss.hpp b/Hadrons/Modules/MSource/Gauss.hpp index d213b73b..ce5b8cfe 100644 --- a/Hadrons/Modules/MSource/Gauss.hpp +++ b/Hadrons/Modules/MSource/Gauss.hpp @@ -11,6 +11,7 @@ BEGIN_HADRONS_NAMESPACE * Gauss * * result[n] = 1/(sqrt(2*pi)*width)^dim * * * exp(-|n-position|^2/(2*width^2)) * + * * exp(i*2*pi/L*mom*n) * * where: * * n=(n[0],n[1],...,n[dim-1]) (lattice coordinate) * * dim=Nd-1 * @@ -22,6 +23,7 @@ class GaussPar: Serializable public: GRID_SERIALIZABLE_CLASS_MEMBERS(GaussPar, std::string, position, + std::string, mom, double, width); }; @@ -43,9 +45,11 @@ public: virtual void execute(void); private: std::vector position_; + std::vector mom_; }; MODULE_REGISTER_TMP(Gauss, TGauss, MSource); +MODULE_REGISTER_TMP(ScalarGauss, TGauss, MSource); /****************************************************************************** * TGauss implementation * @@ -77,40 +81,79 @@ std::vector TGauss::getOutput(void) template void TGauss::setup(void) { - position_ = strToVec(par().position); - if(position_.size() != env().getNd()-1) { - HADRONS_ERROR(Size, std::string("position has ") - + std::to_string(position_.size()) + " instead of " - + std::to_string(env().getNd()-1) + " components"); - } + auto parse_vector = [](const std::string &vec, int dim, + const std::string &desc) + { + std::vector res = strToVec(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(ComplexField, getName()); + envCreateLat(PropagatorField, getName()); envTmpLat(ComplexField, "component"); + envTmpLat(ComplexField, "ScalarRho"); + envTmp(LatticeInteger, "compHelper", 1, envGetGrid(ComplexField)); } // execution /////////////////////////////////////////////////////////////////// template void TGauss::execute(void) { - auto &rho = envGet(ComplexField, getName()); + auto &rho = envGet(PropagatorField, getName()); envGetTmp(ComplexField, component); + envGetTmp(ComplexField, ScalarRho); + envGetTmp(LatticeInteger, compHelper); const int dim=env().getNd()-1; - const double fact=-0.5/std::pow(par().width,2); + const Real fact=-0.5/std::pow(par().width,2); const Complex i(0.0, 1.0); + const SitePropagator idMat=[](){ SitePropagator s; s=1.; return s; }(); - rho=zero; + ScalarRho=zero; for(int mu=0; mu=0 && position_[mu](std::pow(sqrt(2*M_PI)*par().width,dim)); + const int Lmu=env().getDim(mu); + const int LmuHalf=Lmu/2; + const int posMu=position_[mu]; + const vTInteger vTLmuHalf=LmuHalf; + const vTInteger vTposMu=posMu; + + LatticeCoordinate(component, mu); + LatticeCoordinate(compHelper, mu); + + //spatial dimensions of momentum phase + ScalarRho+=(i*(mom_[mu]*2*M_PI/Lmu))*component; + + //Gauss distribution + component-=Complex(posMu); + compHelper-=vTposMu; + if(posMuvTLmuHalf), + component-Complex(Lmu), + component); + } + else + { + component=where((compHelper<=-vTLmuHalf), + component+Complex(Lmu), + component); + } + ScalarRho+=component*component*fact; + } + + //time component of momentum phase + LatticeCoordinate(component, dim); + ScalarRho+=(i*(mom_.at(dim)*2*M_PI/env().getDim(dim)))*component; + + rho=(exp(ScalarRho)*Complex(std::pow(sqrt(2*M_PI)*par().width,dim)))*idMat; } END_MODULE_NAMESPACE