/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MScalarSUN/TrPhi.hpp Copyright (C) 2015-2018 Author: Antonin Portelli 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_TrPhi_hpp_ #define Hadrons_MScalarSUN_TrPhi_hpp_ #include #include #include #include BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Trace of powers of a scalar field * ******************************************************************************/ BEGIN_MODULE_NAMESPACE(MScalarSUN) class TrPhiPar: Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(TrPhiPar, std::string, field, unsigned int, maxPow, std::string, output); }; class TrPhiResult: Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(TrPhiResult, std::string, op, Real, value); }; template class TTrPhi: public Module { public: typedef typename SImpl::Field Field; typedef typename SImpl::ComplexField ComplexField; public: // constructor TTrPhi(const std::string name); // destructor virtual ~TTrPhi(void) {}; // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); // setup virtual void setup(void); // execution virtual void execute(void); }; MODULE_REGISTER_TMP(TrPhiSU2, TTrPhi>, MScalarSUN); MODULE_REGISTER_TMP(TrPhiSU3, TTrPhi>, MScalarSUN); MODULE_REGISTER_TMP(TrPhiSU4, TTrPhi>, MScalarSUN); MODULE_REGISTER_TMP(TrPhiSU5, TTrPhi>, MScalarSUN); MODULE_REGISTER_TMP(TrPhiSU6, TTrPhi>, MScalarSUN); /****************************************************************************** * TTrPhi implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// template TTrPhi::TTrPhi(const std::string name) : Module(name) {} // dependencies/products /////////////////////////////////////////////////////// template std::vector TTrPhi::getInput(void) { std::vector in = {par().field}; return in; } template std::vector TTrPhi::getOutput(void) { std::vector out; for (unsigned int n = 2; n <= par().maxPow; n += 2) { out.push_back(varName(getName(), n)); } return out; } // setup /////////////////////////////////////////////////////////////////////// template void TTrPhi::setup(void) { if (par().maxPow < 2) { HADRONS_ERROR(Size, "'maxPow' should be at least equal to 2"); } envTmpLat(Field, "phi2"); envTmpLat(Field, "buf"); for (unsigned int n = 2; n <= par().maxPow; n += 2) { envCreateLat(ComplexField, varName(getName(), n)); } } // execution /////////////////////////////////////////////////////////////////// template void TTrPhi::execute(void) { LOG(Message) << "Computing tr(phi^n) for n even up to " << par().maxPow << std::endl; std::vector result; auto &phi = envGet(Field, par().field); envGetTmp(Field, phi2); envGetTmp(Field, buf); buf = 1.; phi2 = -phi*phi; for (unsigned int n = 2; n <= par().maxPow; n += 2) { auto &phin = envGet(ComplexField, varName(getName(), n)); buf = buf*phi2; phin = trace(buf); if (!par().output.empty()) { TrPhiResult r; r.op = "tr(phi^" + std::to_string(n) + ")"; r.value = TensorRemove(sum(phin)).real(); result.push_back(r); } } if (result.size() > 0) { saveResult(par().output, "trphi", result); } } END_MODULE_NAMESPACE END_HADRONS_NAMESPACE #endif // Hadrons_MScalarSUN_TrPhi_hpp_