2018-03-02 17:56:00 +00:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
2018-09-01 21:30:30 +01:00
|
|
|
Source file: Hadrons/Modules/MScalarSUN/Utils.hpp
|
2018-03-02 17:56:00 +00:00
|
|
|
|
|
|
|
Copyright (C) 2015-2018
|
|
|
|
|
|
|
|
Author: Antonin Portelli <antonin.portelli@me.com>
|
|
|
|
|
|
|
|
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 */
|
2018-03-02 17:34:23 +00:00
|
|
|
#ifndef Hadrons_MScalarSUN_Utils_hpp_
|
|
|
|
#define Hadrons_MScalarSUN_Utils_hpp_
|
|
|
|
|
2018-08-28 15:00:40 +01:00
|
|
|
#include <Hadrons/Global.hpp>
|
|
|
|
#include <Hadrons/Module.hpp>
|
2018-03-02 17:34:23 +00:00
|
|
|
|
|
|
|
BEGIN_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
BEGIN_MODULE_NAMESPACE(MScalarSUN)
|
|
|
|
|
|
|
|
GRID_SERIALIZABLE_ENUM(DiffType, undef, forward, 1, backward, 2, central, 3);
|
|
|
|
|
|
|
|
template <typename Field>
|
|
|
|
inline void dmu(Field &out, const Field &in, const unsigned int mu, const DiffType type)
|
|
|
|
{
|
|
|
|
auto & env = Environment::getInstance();
|
|
|
|
|
|
|
|
if (mu >= env.getNd())
|
|
|
|
{
|
2018-04-25 16:49:14 +01:00
|
|
|
HADRONS_ERROR(Range, "Derivative direction out of range");
|
2018-03-02 17:34:23 +00:00
|
|
|
}
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case DiffType::backward:
|
|
|
|
out = in - Cshift(in, mu, -1);
|
|
|
|
break;
|
|
|
|
case DiffType::forward:
|
|
|
|
out = Cshift(in, mu, 1) - in;
|
|
|
|
break;
|
|
|
|
case DiffType::central:
|
|
|
|
out = 0.5*(Cshift(in, mu, 1) - Cshift(in, mu, -1));
|
|
|
|
break;
|
|
|
|
default:
|
2018-04-25 16:49:14 +01:00
|
|
|
HADRONS_ERROR(Argument, "Derivative type invalid");
|
2018-03-02 17:34:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Field>
|
|
|
|
inline void dmuAcc(Field &out, const Field &in, const unsigned int mu, const DiffType type)
|
|
|
|
{
|
|
|
|
auto & env = Environment::getInstance();
|
|
|
|
|
|
|
|
if (mu >= env.getNd())
|
|
|
|
{
|
2018-04-25 16:49:14 +01:00
|
|
|
HADRONS_ERROR(Range, "Derivative direction out of range");
|
2018-03-02 17:34:23 +00:00
|
|
|
}
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case DiffType::backward:
|
|
|
|
out += in - Cshift(in, mu, -1);
|
|
|
|
break;
|
|
|
|
case DiffType::forward:
|
|
|
|
out += Cshift(in, mu, 1) - in;
|
|
|
|
break;
|
|
|
|
case DiffType::central:
|
|
|
|
out += 0.5*(Cshift(in, mu, 1) - Cshift(in, mu, -1));
|
|
|
|
break;
|
|
|
|
default:
|
2018-04-25 16:49:14 +01:00
|
|
|
HADRONS_ERROR(Argument, "Derivative type invalid");
|
2018-03-02 17:34:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-18 20:49:26 +01:00
|
|
|
template <class SinkSite, class SourceSite>
|
|
|
|
std::vector<Complex> makeTwoPoint(const std::vector<SinkSite> &sink,
|
|
|
|
const std::vector<SourceSite> &source,
|
|
|
|
const double factor = 1.)
|
|
|
|
{
|
|
|
|
assert(sink.size() == source.size());
|
|
|
|
|
|
|
|
unsigned int nt = sink.size();
|
|
|
|
std::vector<Complex> res(nt, 0.);
|
|
|
|
|
|
|
|
for (unsigned int dt = 0; dt < nt; ++dt)
|
|
|
|
{
|
|
|
|
for (unsigned int t = 0; t < nt; ++t)
|
|
|
|
{
|
2018-10-08 15:14:08 +01:00
|
|
|
res[dt] += trace(sink[(t+dt)%nt]*adj(source[t]));
|
2018-05-18 20:49:26 +01:00
|
|
|
}
|
|
|
|
res[dt] *= factor/static_cast<double>(nt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2018-04-24 19:49:27 +01:00
|
|
|
inline std::string varName(const std::string name, const std::string suf)
|
|
|
|
{
|
|
|
|
return name + "_" + suf;
|
|
|
|
}
|
|
|
|
|
2018-03-02 17:34:23 +00:00
|
|
|
inline std::string varName(const std::string name, const unsigned int mu)
|
|
|
|
{
|
2018-04-24 19:49:27 +01:00
|
|
|
return varName(name, std::to_string(mu));
|
2018-03-02 17:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline std::string varName(const std::string name, const unsigned int mu,
|
|
|
|
const unsigned int nu)
|
|
|
|
{
|
2018-04-24 19:49:27 +01:00
|
|
|
return varName(name, std::to_string(mu) + "_" + std::to_string(nu));
|
2018-03-02 17:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
END_MODULE_NAMESPACE
|
|
|
|
|
|
|
|
END_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
#endif // Hadrons_MScalarSUN_Utils_hpp_
|