/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MScalarSUN/Grad.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_Grad_hpp_ #define Hadrons_MScalarSUN_Grad_hpp_ #include #include #include #include BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Gradient of a complex field * ******************************************************************************/ BEGIN_MODULE_NAMESPACE(MScalarSUN) class GradPar: Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(GradPar, std::string, op, DiffType, type, std::string, output); }; template class TGrad: public Module { public: typedef typename SImpl::Field Field; typedef typename SImpl::ComplexField ComplexField; class Result: Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(Result, DiffType, type, Complex, value); }; public: // constructor TGrad(const std::string name); // destructor virtual ~TGrad(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(GradSU2, TGrad>, MScalarSUN); MODULE_REGISTER_TMP(GradSU3, TGrad>, MScalarSUN); MODULE_REGISTER_TMP(GradSU4, TGrad>, MScalarSUN); MODULE_REGISTER_TMP(GradSU5, TGrad>, MScalarSUN); MODULE_REGISTER_TMP(GradSU6, TGrad>, MScalarSUN); /****************************************************************************** * TGrad implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// template TGrad::TGrad(const std::string name) : Module(name) {} // dependencies/products /////////////////////////////////////////////////////// template std::vector TGrad::getInput(void) { std::vector in = {par().op}; return in; } template std::vector TGrad::getOutput(void) { std::vector out; const auto nd = env().getNd(); for (unsigned int mu = 0; mu < nd; ++mu) { out.push_back(varName(getName(), mu)); } return out; } // setup /////////////////////////////////////////////////////////////////////// template void TGrad::setup(void) { const auto nd = env().getNd(); for (unsigned int mu = 0; mu < nd; ++mu) { envCreateLat(ComplexField, varName(getName(), mu)); } } // execution /////////////////////////////////////////////////////////////////// template void TGrad::execute(void) { const auto nd = env().getNd(); LOG(Message) << "Computing the " << par().type << " gradient of '" << par().op << "'" << std::endl; std::vector result; auto &op = envGet(ComplexField, par().op); for (unsigned int mu = 0; mu < nd; ++mu) { auto &der = envGet(ComplexField, varName(getName(), mu)); dmu(der, op, mu, par().type); if (!par().output.empty()) { Result r; r.type = par().type; r.value = TensorRemove(sum(der)); result.push_back(r); } } if (result.size() > 0) { saveResult(par().output, "grad", result); } } END_MODULE_NAMESPACE END_HADRONS_NAMESPACE #endif // Hadrons_MScalarSUN_Grad_hpp_