1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-09-20 17:25:37 +01:00

Hadrons: Scalar SU(N) utility functions

This commit is contained in:
Antonin Portelli 2018-03-02 17:34:23 +00:00
parent 550142bd6a
commit 614a0e8277
8 changed files with 97 additions and 62 deletions

View File

@ -65,6 +65,7 @@ See the full license in the file "LICENSE" in the top level distribution directo
#include <Grid/Hadrons/Modules/MScalarSUN/TrMag.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/TwoPoint.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/TrPhi.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/Utils.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/TrKinetic.hpp>
#include <Grid/Hadrons/Modules/MIO/LoadNersc.hpp>
#include <Grid/Hadrons/Modules/MIO/LoadBinary.hpp>

View File

@ -31,6 +31,7 @@ See the full license in the file "LICENSE" in the top level distribution directo
#include <Grid/Hadrons/Global.hpp>
#include <Grid/Hadrons/Module.hpp>
#include <Grid/Hadrons/ModuleFactory.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/Utils.hpp>
BEGIN_HADRONS_NAMESPACE
@ -42,7 +43,6 @@ BEGIN_MODULE_NAMESPACE(MScalarSUN)
class DivPar: Serializable
{
public:
GRID_SERIALIZABLE_ENUM(DiffType, undef, forward, 1, backward, 2, central, 3);
GRID_SERIALIZABLE_CLASS_MEMBERS(DivPar,
std::vector<std::string>, op,
DiffType, type,
@ -59,8 +59,8 @@ public:
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
DivPar::DiffType, type,
Complex, value);
DiffType, type,
Complex, value);
};
public:
// constructor
@ -135,18 +135,7 @@ void TDiv<SImpl>::execute(void)
for (unsigned int mu = 0; mu < nd; ++mu)
{
auto &op = envGet(ComplexField, par().op[mu]);
switch(par().type)
{
case DivPar::DiffType::backward:
div += op - Cshift(op, mu, -1);
break;
case DivPar::DiffType::forward:
div += Cshift(op, mu, 1) - op;
break;
case DivPar::DiffType::central:
div += 0.5*(Cshift(op, mu, 1) - Cshift(op, mu, -1));
break;
}
dmuAcc(div, op, mu, par().type);
}
if (!par().output.empty())
{

View File

@ -31,6 +31,7 @@ See the full license in the file "LICENSE" in the top level distribution directo
#include <Grid/Hadrons/Global.hpp>
#include <Grid/Hadrons/Module.hpp>
#include <Grid/Hadrons/ModuleFactory.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/Utils.hpp>
BEGIN_HADRONS_NAMESPACE
@ -42,7 +43,6 @@ BEGIN_MODULE_NAMESPACE(MScalarSUN)
class TrKineticPar: Serializable
{
public:
GRID_SERIALIZABLE_ENUM(DiffType, undef, forward, 1, backward, 2, central, 3);
GRID_SERIALIZABLE_CLASS_MEMBERS(TrKineticPar,
std::string, field,
DiffType, type,
@ -74,9 +74,6 @@ public:
virtual void setup(void);
// execution
virtual void execute(void);
private:
std::string outName(const unsigned int mu, const unsigned int nu);
std::string bufName(const unsigned int mu);
};
MODULE_REGISTER_NS(TrKineticSU2, TTrKinetic<ScalarNxNAdjImplR<2>>, MScalarSUN);
@ -111,7 +108,7 @@ std::vector<std::string> TTrKinetic<SImpl>::getOutput(void)
for (unsigned int mu = 0; mu < env().getNd(); ++mu)
for (unsigned int nu = mu; nu < env().getNd(); ++nu)
{
out.push_back(outName(mu, nu));
out.push_back(varName(getName(), mu, nu));
}
return out;
@ -124,7 +121,7 @@ void TTrKinetic<SImpl>::setup(void)
for (unsigned int mu = 0; mu < env().getNd(); ++mu)
for (unsigned int nu = mu; nu < env().getNd(); ++nu)
{
envCreateLat(ComplexField, outName(mu, nu));
envCreateLat(ComplexField, varName(getName(), mu, nu));
}
envTmp(std::vector<Field>, "der", 1, env().getNd(), env().getGrid());
}
@ -142,23 +139,12 @@ void TTrKinetic<SImpl>::execute(void)
envGetTmp(std::vector<Field>, der);
for (unsigned int mu = 0; mu < env().getNd(); ++mu)
{
switch(par().type)
{
case TrKineticPar::DiffType::backward:
der[mu] = phi - Cshift(phi, mu, -1);
break;
case TrKineticPar::DiffType::forward:
der[mu] = Cshift(phi, mu, 1) - phi;
break;
case TrKineticPar::DiffType::central:
der[mu] = 0.5*(Cshift(phi, mu, 1) - Cshift(phi, mu, -1));
break;
}
dmu(der[mu], phi, mu, par().type);
}
for (unsigned int mu = 0; mu < env().getNd(); ++mu)
for (unsigned int nu = mu; nu < env().getNd(); ++nu)
{
auto &out = envGet(ComplexField, outName(mu, nu));
auto &out = envGet(ComplexField, varName(getName(), mu, nu));
out = -trace(der[mu]*der[nu]);
if (!par().output.empty())
@ -177,21 +163,6 @@ void TTrKinetic<SImpl>::execute(void)
}
}
// variable name generators ////////////////////////////////////////////////////
template <typename SImpl>
std::string TTrKinetic<SImpl>::outName(const unsigned int mu,
const unsigned int nu)
{
return getName() + "_" + std::to_string(mu) + "_" + std::to_string(nu);
}
template <typename SImpl>
std::string TTrKinetic<SImpl>::bufName(const unsigned int mu)
{
return "d_" + std::to_string(mu);
}
END_MODULE_NAMESPACE
END_HADRONS_NAMESPACE

View File

@ -31,6 +31,7 @@ See the full license in the file "LICENSE" in the top level distribution directo
#include <Grid/Hadrons/Global.hpp>
#include <Grid/Hadrons/Module.hpp>
#include <Grid/Hadrons/ModuleFactory.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/Utils.hpp>
BEGIN_HADRONS_NAMESPACE

View File

@ -31,6 +31,7 @@ See the full license in the file "LICENSE" in the top level distribution directo
#include <Grid/Hadrons/Global.hpp>
#include <Grid/Hadrons/Module.hpp>
#include <Grid/Hadrons/ModuleFactory.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/Utils.hpp>
BEGIN_HADRONS_NAMESPACE
@ -73,9 +74,6 @@ public:
virtual void setup(void);
// execution
virtual void execute(void);
private:
// output name generator
std::string outName(const unsigned int n);
};
MODULE_REGISTER_NS(TrPhiSU2, TTrPhi<ScalarNxNAdjImplR<2>>, MScalarSUN);
@ -109,7 +107,7 @@ std::vector<std::string> TTrPhi<SImpl>::getOutput(void)
for (unsigned int n = 2; n <= par().maxPow; n += 2)
{
out.push_back(outName(n));
out.push_back(varName(getName(), n));
}
return out;
@ -127,7 +125,7 @@ void TTrPhi<SImpl>::setup(void)
envTmpLat(Field, "buf");
for (unsigned int n = 2; n <= par().maxPow; n += 2)
{
envCreateLat(ComplexField, outName(n));
envCreateLat(ComplexField, varName(getName(), n));
}
}
@ -147,7 +145,7 @@ void TTrPhi<SImpl>::execute(void)
phi2 = -phi*phi;
for (unsigned int n = 2; n <= par().maxPow; n += 2)
{
auto &phin = envGet(ComplexField, outName(n));
auto &phin = envGet(ComplexField, varName(getName(), n));
buf = buf*phi2;
phin = trace(buf);
@ -166,13 +164,6 @@ void TTrPhi<SImpl>::execute(void)
}
}
// output name generator ///////////////////////////////////////////////////////
template <typename SImpl>
std::string TTrPhi<SImpl>::outName(const unsigned int n)
{
return getName() + "_" + std::to_string(n);
}
END_MODULE_NAMESPACE
END_HADRONS_NAMESPACE

View File

@ -31,6 +31,7 @@ See the full license in the file "LICENSE" in the top level distribution directo
#include <Grid/Hadrons/Global.hpp>
#include <Grid/Hadrons/Module.hpp>
#include <Grid/Hadrons/ModuleFactory.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/Utils.hpp>
BEGIN_HADRONS_NAMESPACE

View File

@ -0,0 +1,80 @@
#ifndef Hadrons_MScalarSUN_Utils_hpp_
#define Hadrons_MScalarSUN_Utils_hpp_
#include <Grid/Hadrons/Global.hpp>
#include <Grid/Hadrons/Module.hpp>
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())
{
HADRON_ERROR(Range, "Derivative direction out of range");
}
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:
HADRON_ERROR(Argument, "Derivative type invalid");
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())
{
HADRON_ERROR(Range, "Derivative direction out of range");
}
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:
HADRON_ERROR(Argument, "Derivative type invalid");
break;
}
}
inline std::string varName(const std::string name, const unsigned int mu)
{
return name + "_" + std::to_string(mu);
}
inline std::string varName(const std::string name, const unsigned int mu,
const unsigned int nu)
{
return name + "_" + std::to_string(mu) + "_" + std::to_string(nu);
}
END_MODULE_NAMESPACE
END_HADRONS_NAMESPACE
#endif // Hadrons_MScalarSUN_Utils_hpp_

View File

@ -48,6 +48,7 @@ modules_hpp =\
Modules/MScalarSUN/TrMag.hpp \
Modules/MScalarSUN/TwoPoint.hpp \
Modules/MScalarSUN/TrPhi.hpp \
Modules/MScalarSUN/Utils.hpp \
Modules/MScalarSUN/TrKinetic.hpp \
Modules/MIO/LoadNersc.hpp \
Modules/MIO/LoadBinary.hpp