1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-09 05:30:46 +01:00

MSource::Gauss add mom parameter + avoid Cshifts

This commit is contained in:
Nils Asmussen 2019-06-01 23:56:14 +01:00
parent f569813b60
commit 8d540a4e85

View File

@ -11,6 +11,7 @@ BEGIN_HADRONS_NAMESPACE
* Gauss * * Gauss *
* result[n] = 1/(sqrt(2*pi)*width)^dim * * result[n] = 1/(sqrt(2*pi)*width)^dim *
* * exp(-|n-position|^2/(2*width^2)) * * * exp(-|n-position|^2/(2*width^2)) *
* * exp(i*2*pi/L*mom*n) *
* where: * * where: *
* n=(n[0],n[1],...,n[dim-1]) (lattice coordinate) * * n=(n[0],n[1],...,n[dim-1]) (lattice coordinate) *
* dim=Nd-1 * * dim=Nd-1 *
@ -22,6 +23,7 @@ class GaussPar: Serializable
public: public:
GRID_SERIALIZABLE_CLASS_MEMBERS(GaussPar, GRID_SERIALIZABLE_CLASS_MEMBERS(GaussPar,
std::string, position, std::string, position,
std::string, mom,
double, width); double, width);
}; };
@ -43,9 +45,11 @@ public:
virtual void execute(void); virtual void execute(void);
private: private:
std::vector<int> position_; std::vector<int> position_;
std::vector<int> mom_;
}; };
MODULE_REGISTER_TMP(Gauss, TGauss<FIMPL>, MSource); MODULE_REGISTER_TMP(Gauss, TGauss<FIMPL>, MSource);
MODULE_REGISTER_TMP(ScalarGauss, TGauss<ScalarImplCR>, MSource);
/****************************************************************************** /******************************************************************************
* TGauss implementation * * TGauss implementation *
@ -77,40 +81,79 @@ std::vector<std::string> TGauss<FImpl>::getOutput(void)
template <typename FImpl> template <typename FImpl>
void TGauss<FImpl>::setup(void) void TGauss<FImpl>::setup(void)
{ {
position_ = strToVec<int>(par().position); auto parse_vector = [](const std::string &vec, int dim,
if(position_.size() != env().getNd()-1) { const std::string &desc)
HADRONS_ERROR(Size, std::string("position has ") {
+ std::to_string(position_.size()) + " instead of " std::vector<int> res = strToVec<int>(vec);
+ std::to_string(env().getNd()-1) + " components"); 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, "component");
envTmpLat(ComplexField, "ScalarRho");
envTmp(LatticeInteger, "compHelper", 1, envGetGrid(ComplexField));
} }
// execution /////////////////////////////////////////////////////////////////// // execution ///////////////////////////////////////////////////////////////////
template <typename FImpl> template <typename FImpl>
void TGauss<FImpl>::execute(void) void TGauss<FImpl>::execute(void)
{ {
auto &rho = envGet(ComplexField, getName()); auto &rho = envGet(PropagatorField, getName());
envGetTmp(ComplexField, component); envGetTmp(ComplexField, component);
envGetTmp(ComplexField, ScalarRho);
envGetTmp(LatticeInteger, compHelper);
const int dim=env().getNd()-1; 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 Complex i(0.0, 1.0);
const SitePropagator idMat=[](){ SitePropagator s; s=1.; return s; }();
rho=zero; ScalarRho=zero;
for(int mu=0; mu<dim; mu++) { for(int mu=0; mu<dim; mu++) {
LatticeCoordinate(component, mu);
//FIXME: the next three lines are very inefficient...
// should not need any communication (Cshift) here
assert(env().getDim(mu)%2==0); assert(env().getDim(mu)%2==0);
component-=Complex(env().getDim(mu)/2-1); assert(position_[mu]>=0 && position_[mu]<env().getDim(mu));
component=Cshift(component, mu, env().getDim(mu)/2-1 -position_[mu]);
rho+=component*component*fact;
}
rho=exp(rho);
rho*=static_cast<Complex>(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(posMu<Lmu/2)
{
component=where((compHelper>vTLmuHalf),
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 END_MODULE_NAMESPACE