/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/TrKinetic.hpp Copyright (C) 2015-2019 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_TrKinetic_hpp_ #define Hadrons_MScalarSUN_TrKinetic_hpp_ #include #include #include #include BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Trace of kinetic term * ******************************************************************************/ BEGIN_MODULE_NAMESPACE(MScalarSUN) class TrKineticPar: Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(TrKineticPar, std::string, field, DiffType, type, std::string, output); }; class TrKineticResult: Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(TrKineticResult, std::vector>, value, DiffType, type); }; template class TTrKinetic: public Module { public: typedef typename SImpl::Field Field; typedef typename SImpl::ComplexField ComplexField; public: // constructor TTrKinetic(const std::string name); // destructor virtual ~TTrKinetic(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(TrKineticSU2, TTrKinetic>, MScalarSUN); MODULE_REGISTER_TMP(TrKineticSU3, TTrKinetic>, MScalarSUN); MODULE_REGISTER_TMP(TrKineticSU4, TTrKinetic>, MScalarSUN); MODULE_REGISTER_TMP(TrKineticSU5, TTrKinetic>, MScalarSUN); MODULE_REGISTER_TMP(TrKineticSU6, TTrKinetic>, MScalarSUN); /****************************************************************************** * TTrKinetic implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// template TTrKinetic::TTrKinetic(const std::string name) : Module(name) {} // dependencies/products /////////////////////////////////////////////////////// template std::vector TTrKinetic::getInput(void) { std::vector in = {par().field}; return in; } template std::vector TTrKinetic::getOutput(void) { std::vector out ; for (unsigned int mu = 0; mu < env().getNd(); ++mu) for (unsigned int nu = mu; nu < env().getNd(); ++nu) { out.push_back(varName(getName(), mu, nu)); } out.push_back(varName(getName(), "sum")); return out; } // setup /////////////////////////////////////////////////////////////////////// template void TTrKinetic::setup(void) { for (unsigned int mu = 0; mu < env().getNd(); ++mu) for (unsigned int nu = mu; nu < env().getNd(); ++nu) { envCreateLat(ComplexField, varName(getName(), mu, nu)); } envCreateLat(ComplexField, varName(getName(), "sum")); envTmp(std::vector, "der", 1, env().getNd(), envGetGrid(Field)); } // execution /////////////////////////////////////////////////////////////////// template void TTrKinetic::execute(void) { LOG(Message) << "Computing tr(d_mu phi*d_nu phi) using " << par().type << " derivative" << std::endl; const unsigned int nd = env().getNd(); TrKineticResult result; auto &phi = envGet(Field, par().field); auto &sumkin = envGet(ComplexField, varName(getName(), "sum")); envGetTmp(std::vector, der); sumkin = zero; if (!par().output.empty()) { result.type = par().type; result.value.resize(nd, std::vector(nd)); } for (unsigned int mu = 0; mu < nd; ++mu) { dmu(der[mu], phi, mu, par().type); } for (unsigned int mu = 0; mu < nd; ++mu) for (unsigned int nu = mu; nu < nd; ++nu) { auto &out = envGet(ComplexField, varName(getName(), mu, nu)); out = -trace(der[mu]*der[nu]); if (mu == nu) { sumkin += out; } if (!par().output.empty()) { result.value[mu][nu] = TensorRemove(sum(out)); result.value[mu][nu] = result.value[nu][mu]; } } saveResult(par().output, "trkinetic", result); } END_MODULE_NAMESPACE END_HADRONS_NAMESPACE #endif // Hadrons_MScalarSUN_TrKinetic_hpp_