/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSource/SeqConserved.hpp Copyright (C) 2015-2018 Author: Antonin Portelli Author: Lanny91 Author: Vera Guelpers 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_MSource_SeqConserved_hpp_ #define Hadrons_MSource_SeqConserved_hpp_ #include #include #include BEGIN_HADRONS_NAMESPACE /* Sequential source with insertion of conserved current. Additionally optional insertion of a photon field A_\mu(x). ----------------------------- * src_x = sum_{mu=mu_min}^{mu_max} q_x * theta(x_3 - tA) * theta(tB - x_3) * J_mu * exp(i x.mom) (* A_\mu(x)) * options: - q: input propagator (string) - action: fermion action used for propagator q (string) - tA: begin timeslice (integer) - tB: end timesilce (integer) - curr_type: type of conserved current to insert (Current) - mu_min: begin Lorentz Index (integer) - mu_max: end Lorentz Index (integer) - mom: momentum insertion, space-separated float sequence (e.g ".1 .2 1. 0.") - photon: optional photon field (string) */ /****************************************************************************** * SeqConserved * ******************************************************************************/ BEGIN_MODULE_NAMESPACE(MSource) class SeqConservedPar: Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(SeqConservedPar, std::string, q, std::string, action, unsigned int, tA, unsigned int, tB, Current, curr_type, unsigned int, mu_min, unsigned int, mu_max, std::string, mom, std::string, photon); }; template class TSeqConserved: public Module { public: FERM_TYPE_ALIASES(FImpl,); public: typedef PhotonR::GaugeField EmField; public: // constructor TSeqConserved(const std::string name); // destructor virtual ~TSeqConserved(void) {}; // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); protected: // setup virtual void setup(void); // execution virtual void execute(void); private: bool SeqhasPhase_{false}; std::string SeqmomphName_; }; MODULE_REGISTER_TMP(SeqConserved, TSeqConserved, MSource); /****************************************************************************** * TSeqConserved implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// template TSeqConserved::TSeqConserved(const std::string name) : Module(name) , SeqmomphName_ (name + "_Seqmomph") {} // dependencies/products /////////////////////////////////////////////////////// template std::vector TSeqConserved::getInput(void) { std::vector in = {par().q, par().action}; if (!par().photon.empty()) in.push_back(par().photon); return in; } template std::vector TSeqConserved::getOutput(void) { std::vector out = {getName()}; return out; } // setup /////////////////////////////////////////////////////////////////////// template void TSeqConserved::setup(void) { auto Ls_ = env().getObjectLs(par().action); envCreateLat(PropagatorField, getName(), Ls_); envTmpLat(PropagatorField, "src_tmp",Ls_); envCacheLat(LatticeComplex, SeqmomphName_); envTmpLat(LatticeComplex, "coor"); envTmpLat(LatticeComplex, "latt_compl"); } // execution /////////////////////////////////////////////////////////////////// template void TSeqConserved::execute(void) { if (par().tA == par().tB) { LOG(Message) << "Generating sequential source with conserved " << par().curr_type << " current at " << "t = " << par().tA << " summed over the indices " << par().mu_min << " <= mu <= " << par().mu_max << std::endl; } else { LOG(Message) << "Generating sequential source with conserved " << par().curr_type << " current for " << par().tA << " <= t <= " << par().tB << " summed over the indices " << par().mu_min << " <= mu <= " << par().mu_max << std::endl; } auto &src = envGet(PropagatorField, getName()); envGetTmp(PropagatorField, src_tmp); src_tmp = src; auto &q = envGet(PropagatorField, par().q); auto &mat = envGet(FMat, par().action); envGetTmp(LatticeComplex, latt_compl); src = Zero(); //exp(ipx) auto &mom_phase = envGet(LatticeComplex, SeqmomphName_); if (!SeqhasPhase_) { std::vector mom = strToVec(par().mom); mom_phase = Zero(); Complex i(0.0,1.0); envGetTmp(LatticeComplex, coor); for(unsigned int mu = 0; mu < env().getNd(); mu++) { LatticeCoordinate(coor, mu); mom_phase = mom_phase + (mom[mu]/env().getDim(mu))*coor; } mom_phase = exp((Real)(2*M_PI)*i*mom_phase); SeqhasPhase_ = true; } LOG(Message) << "Inserting momentum " << strToVec(par().mom) << std::endl; if (!par().photon.empty()) { LOG(Message) << "Inserting the stochastic photon field " << par().photon << std::endl; } for(unsigned int mu=par().mu_min;mu<=par().mu_max;mu++) { if (!par().photon.empty()) { //Get the stochastic photon field, if required auto &stoch_photon = envGet(EmField, par().photon); latt_compl = PeekIndex(stoch_photon, mu) * mom_phase; } else { latt_compl = mom_phase; } mat.SeqConservedCurrent(q, src_tmp, par().curr_type, mu, par().tA, par().tB, latt_compl); src += src_tmp; } } END_MODULE_NAMESPACE END_HADRONS_NAMESPACE #endif // Hadrons_MSource_SeqConserved_hpp_