mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-13 04:37:05 +01:00
Merge branch 'develop' into feature/gpu-port
This commit is contained in:
746
Hadrons/A2AMatrix.hpp
Normal file
746
Hadrons/A2AMatrix.hpp
Normal file
@ -0,0 +1,746 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/A2AMatrix.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
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 A2A_Matrix_hpp_
|
||||
#define A2A_Matrix_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/TimerArray.hpp>
|
||||
#include <Grid/Eigen/unsupported/CXX11/Tensor>
|
||||
#ifdef USE_MKL
|
||||
#include "mkl.h"
|
||||
#include "mkl_cblas.h"
|
||||
#endif
|
||||
|
||||
#ifndef HADRONS_A2AM_NAME
|
||||
#define HADRONS_A2AM_NAME "a2aMatrix"
|
||||
#endif
|
||||
|
||||
#ifndef HADRONS_A2AM_IO_TYPE
|
||||
#define HADRONS_A2AM_IO_TYPE ComplexF
|
||||
#endif
|
||||
|
||||
#define HADRONS_A2AM_PARALLEL_IO
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
// general A2A matrix set based on Eigen tensors and Grid-allocated memory
|
||||
// Dimensions:
|
||||
// 0 - ext - external field (momentum, EM field, ...)
|
||||
// 1 - str - spin-color structure
|
||||
// 2 - t - timeslice
|
||||
// 3 - i - left A2A mode index
|
||||
// 4 - j - right A2A mode index
|
||||
template <typename T>
|
||||
using A2AMatrixSet = Eigen::TensorMap<Eigen::Tensor<T, 5, Eigen::RowMajor>>;
|
||||
|
||||
template <typename T>
|
||||
using A2AMatrix = Eigen::Matrix<T, -1, -1, Eigen::RowMajor>;
|
||||
|
||||
template <typename T>
|
||||
using A2AMatrixTr = Eigen::Matrix<T, -1, -1, Eigen::ColMajor>;
|
||||
|
||||
/******************************************************************************
|
||||
* Abstract class for A2A kernels *
|
||||
******************************************************************************/
|
||||
template <typename T, typename Field>
|
||||
class A2AKernel
|
||||
{
|
||||
public:
|
||||
A2AKernel(void) = default;
|
||||
virtual ~A2AKernel(void) = default;
|
||||
virtual void operator()(A2AMatrixSet<T> &m, const Field *left, const Field *right,
|
||||
const unsigned int orthogDim, double &time) = 0;
|
||||
virtual double flops(const unsigned int blockSizei, const unsigned int blockSizej) = 0;
|
||||
virtual double bytes(const unsigned int blockSizei, const unsigned int blockSizej) = 0;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* Class to handle A2A matrix block HDF5 I/O *
|
||||
******************************************************************************/
|
||||
template <typename T>
|
||||
class A2AMatrixIo
|
||||
{
|
||||
public:
|
||||
// constructors
|
||||
A2AMatrixIo(void) = default;
|
||||
A2AMatrixIo(std::string filename, std::string dataname,
|
||||
const unsigned int nt, const unsigned int ni = 0,
|
||||
const unsigned int nj = 0);
|
||||
// destructor
|
||||
~A2AMatrixIo(void) = default;
|
||||
// access
|
||||
unsigned int getNi(void) const;
|
||||
unsigned int getNj(void) const;
|
||||
unsigned int getNt(void) const;
|
||||
size_t getSize(void) const;
|
||||
// file allocation
|
||||
template <typename MetadataType>
|
||||
void initFile(const MetadataType &d, const unsigned int chunkSize);
|
||||
// block I/O
|
||||
void saveBlock(const T *data, const unsigned int i, const unsigned int j,
|
||||
const unsigned int blockSizei, const unsigned int blockSizej);
|
||||
void saveBlock(const A2AMatrixSet<T> &m, const unsigned int ext, const unsigned int str,
|
||||
const unsigned int i, const unsigned int j);
|
||||
template <template <class> class Vec, typename VecT>
|
||||
void load(Vec<VecT> &v, double *tRead = nullptr);
|
||||
private:
|
||||
std::string filename_{""}, dataname_{""};
|
||||
unsigned int nt_{0}, ni_{0}, nj_{0};
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* Wrapper for A2A matrix block computation *
|
||||
******************************************************************************/
|
||||
template <typename T, typename Field, typename MetadataType, typename TIo = T>
|
||||
class A2AMatrixBlockComputation
|
||||
{
|
||||
private:
|
||||
struct IoHelper
|
||||
{
|
||||
A2AMatrixIo<TIo> io;
|
||||
MetadataType md;
|
||||
unsigned int e, s, i, j;
|
||||
};
|
||||
typedef std::function<std::string(const unsigned int, const unsigned int)> FilenameFn;
|
||||
typedef std::function<MetadataType(const unsigned int, const unsigned int)> MetadataFn;
|
||||
public:
|
||||
// constructor
|
||||
A2AMatrixBlockComputation(GridBase *grid,
|
||||
const unsigned int orthogDim,
|
||||
const unsigned int next,
|
||||
const unsigned int nstr,
|
||||
const unsigned int blockSize,
|
||||
const unsigned int cacheBlockSize,
|
||||
TimerArray *tArray = nullptr);
|
||||
// execution
|
||||
void execute(const std::vector<Field> &left,
|
||||
const std::vector<Field> &right,
|
||||
A2AKernel<T, Field> &kernel,
|
||||
const FilenameFn &ionameFn,
|
||||
const FilenameFn &filenameFn,
|
||||
const MetadataFn &metadataFn);
|
||||
private:
|
||||
// I/O handler
|
||||
void saveBlock(const A2AMatrixSet<TIo> &m, IoHelper &h);
|
||||
private:
|
||||
TimerArray *tArray_;
|
||||
GridBase *grid_;
|
||||
unsigned int orthogDim_, nt_, next_, nstr_, blockSize_, cacheBlockSize_;
|
||||
Vector<T> mCache_;
|
||||
Vector<TIo> mBuf_;
|
||||
std::vector<IoHelper> nodeIo_;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* A2A matrix contraction kernels *
|
||||
******************************************************************************/
|
||||
class A2AContraction
|
||||
{
|
||||
public:
|
||||
// accTrMul(acc, a, b): acc += tr(a*b)
|
||||
template <typename C, typename MatLeft, typename MatRight>
|
||||
static inline void accTrMul(C &acc, const MatLeft &a, const MatRight &b)
|
||||
{
|
||||
if ((MatLeft::Options == Eigen::RowMajor) and
|
||||
(MatRight::Options == Eigen::ColMajor))
|
||||
{
|
||||
parallel_for (unsigned int r = 0; r < a.rows(); ++r)
|
||||
{
|
||||
C tmp;
|
||||
#ifdef USE_MKL
|
||||
dotuRow(tmp, r, a, b);
|
||||
#else
|
||||
tmp = a.row(r).conjugate().dot(b.col(r));
|
||||
#endif
|
||||
parallel_critical
|
||||
{
|
||||
acc += tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
parallel_for (unsigned int c = 0; c < a.cols(); ++c)
|
||||
{
|
||||
C tmp;
|
||||
#ifdef USE_MKL
|
||||
dotuCol(tmp, c, a, b);
|
||||
#else
|
||||
tmp = a.col(c).conjugate().dot(b.row(c));
|
||||
#endif
|
||||
parallel_critical
|
||||
{
|
||||
acc += tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename MatLeft, typename MatRight>
|
||||
static inline double accTrMulFlops(const MatLeft &a, const MatRight &b)
|
||||
{
|
||||
double n = a.rows()*a.cols();
|
||||
|
||||
return 8.*n;
|
||||
}
|
||||
|
||||
// mul(res, a, b): res = a*b
|
||||
#ifdef USE_MKL
|
||||
template <template <class, int...> class Mat, int... Opts>
|
||||
static inline void mul(Mat<ComplexD, Opts...> &res,
|
||||
const Mat<ComplexD, Opts...> &a,
|
||||
const Mat<ComplexD, Opts...> &b)
|
||||
{
|
||||
static const ComplexD one(1., 0.), zero(0., 0.);
|
||||
|
||||
if ((res.rows() != a.rows()) or (res.cols() != b.cols()))
|
||||
{
|
||||
res.resize(a.rows(), b.cols());
|
||||
}
|
||||
if (Mat<ComplexD, Opts...>::Options == Eigen::RowMajor)
|
||||
{
|
||||
cblas_zgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, a.rows(), b.cols(),
|
||||
a.cols(), &one, a.data(), a.cols(), b.data(), b.cols(), &zero,
|
||||
res.data(), res.cols());
|
||||
}
|
||||
else if (Mat<ComplexD, Opts...>::Options == Eigen::ColMajor)
|
||||
{
|
||||
cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, a.rows(), b.cols(),
|
||||
a.cols(), &one, a.data(), a.rows(), b.data(), b.rows(), &zero,
|
||||
res.data(), res.rows());
|
||||
}
|
||||
}
|
||||
|
||||
template <template <class, int...> class Mat, int... Opts>
|
||||
static inline void mul(Mat<ComplexF, Opts...> &res,
|
||||
const Mat<ComplexF, Opts...> &a,
|
||||
const Mat<ComplexF, Opts...> &b)
|
||||
{
|
||||
static const ComplexF one(1., 0.), zero(0., 0.);
|
||||
|
||||
if ((res.rows() != a.rows()) or (res.cols() != b.cols()))
|
||||
{
|
||||
res.resize(a.rows(), b.cols());
|
||||
}
|
||||
if (Mat<ComplexF, Opts...>::Options == Eigen::RowMajor)
|
||||
{
|
||||
cblas_cgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, a.rows(), b.cols(),
|
||||
a.cols(), &one, a.data(), a.cols(), b.data(), b.cols(), &zero,
|
||||
res.data(), res.cols());
|
||||
}
|
||||
else if (Mat<ComplexF, Opts...>::Options == Eigen::ColMajor)
|
||||
{
|
||||
cblas_cgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, a.rows(), b.cols(),
|
||||
a.cols(), &one, a.data(), a.rows(), b.data(), b.rows(), &zero,
|
||||
res.data(), res.rows());
|
||||
}
|
||||
}
|
||||
#else
|
||||
template <typename Mat>
|
||||
static inline void mul(Mat &res, const Mat &a, const Mat &b)
|
||||
{
|
||||
res = a*b;
|
||||
}
|
||||
#endif
|
||||
template <typename Mat>
|
||||
static inline double mulFlops(const Mat &a, const Mat &b)
|
||||
{
|
||||
double nr = a.rows(), nc = a.cols();
|
||||
|
||||
return nr*nr*(6.*nc + 2.*(nc - 1.));
|
||||
}
|
||||
private:
|
||||
template <typename C, typename MatLeft, typename MatRight>
|
||||
static inline void makeDotRowPt(C * &aPt, unsigned int &aInc, C * &bPt,
|
||||
unsigned int &bInc, const unsigned int aRow,
|
||||
const MatLeft &a, const MatRight &b)
|
||||
{
|
||||
if (MatLeft::Options == Eigen::RowMajor)
|
||||
{
|
||||
aPt = a.data() + aRow*a.cols();
|
||||
aInc = 1;
|
||||
}
|
||||
else if (MatLeft::Options == Eigen::ColMajor)
|
||||
{
|
||||
aPt = a.data() + aRow;
|
||||
aInc = a.rows();
|
||||
}
|
||||
if (MatRight::Options == Eigen::RowMajor)
|
||||
{
|
||||
bPt = b.data() + aRow;
|
||||
bInc = b.cols();
|
||||
}
|
||||
else if (MatRight::Options == Eigen::ColMajor)
|
||||
{
|
||||
bPt = b.data() + aRow*b.rows();
|
||||
bInc = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_MKL
|
||||
template <typename C, typename MatLeft, typename MatRight>
|
||||
static inline void makeDotColPt(C * &aPt, unsigned int &aInc, C * &bPt,
|
||||
unsigned int &bInc, const unsigned int aCol,
|
||||
const MatLeft &a, const MatRight &b)
|
||||
{
|
||||
if (MatLeft::Options == Eigen::RowMajor)
|
||||
{
|
||||
aPt = a.data() + aCol;
|
||||
aInc = a.cols();
|
||||
}
|
||||
else if (MatLeft::Options == Eigen::ColMajor)
|
||||
{
|
||||
aPt = a.data() + aCol*a.rows();
|
||||
aInc = 1;
|
||||
}
|
||||
if (MatRight::Options == Eigen::RowMajor)
|
||||
{
|
||||
bPt = b.data() + aCol*b.cols();
|
||||
bInc = 1;
|
||||
}
|
||||
else if (MatRight::Options == Eigen::ColMajor)
|
||||
{
|
||||
bPt = b.data() + aCol;
|
||||
bInc = b.rows();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename MatLeft, typename MatRight>
|
||||
static inline void dotuRow(ComplexF &res, const unsigned int aRow,
|
||||
const MatLeft &a, const MatRight &b)
|
||||
{
|
||||
const ComplexF *aPt, *bPt;
|
||||
unsigned int aInc, bInc;
|
||||
|
||||
makeDotRowPt(aPt, aInc, bPt, bInc, aRow, a, b);
|
||||
cblas_cdotu_sub(a.cols(), aPt, aInc, bPt, bInc, &res);
|
||||
}
|
||||
|
||||
template <typename MatLeft, typename MatRight>
|
||||
static inline void dotuCol(ComplexF &res, const unsigned int aCol,
|
||||
const MatLeft &a, const MatRight &b)
|
||||
{
|
||||
const ComplexF *aPt, *bPt;
|
||||
unsigned int aInc, bInc;
|
||||
|
||||
makeDotColPt(aPt, aInc, bPt, bInc, aCol, a, b);
|
||||
cblas_cdotu_sub(a.rows(), aPt, aInc, bPt, bInc, &res);
|
||||
}
|
||||
|
||||
template <typename MatLeft, typename MatRight>
|
||||
static inline void dotuRow(ComplexD &res, const unsigned int aRow,
|
||||
const MatLeft &a, const MatRight &b)
|
||||
{
|
||||
const ComplexD *aPt, *bPt;
|
||||
unsigned int aInc, bInc;
|
||||
|
||||
makeDotRowPt(aPt, aInc, bPt, bInc, aRow, a, b);
|
||||
cblas_zdotu_sub(a.cols(), aPt, aInc, bPt, bInc, &res);
|
||||
}
|
||||
|
||||
template <typename MatLeft, typename MatRight>
|
||||
static inline void dotuCol(ComplexD &res, const unsigned int aCol,
|
||||
const MatLeft &a, const MatRight &b)
|
||||
{
|
||||
const ComplexD *aPt, *bPt;
|
||||
unsigned int aInc, bInc;
|
||||
|
||||
makeDotColPt(aPt, aInc, bPt, bInc, aCol, a, b);
|
||||
cblas_zdotu_sub(a.rows(), aPt, aInc, bPt, bInc, &res);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* A2AMatrixIo template implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
A2AMatrixIo<T>::A2AMatrixIo(std::string filename, std::string dataname,
|
||||
const unsigned int nt, const unsigned int ni,
|
||||
const unsigned int nj)
|
||||
: filename_(filename), dataname_(dataname)
|
||||
, nt_(nt), ni_(ni), nj_(nj)
|
||||
{}
|
||||
|
||||
// access //////////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
unsigned int A2AMatrixIo<T>::getNt(void) const
|
||||
{
|
||||
return nt_;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
unsigned int A2AMatrixIo<T>::getNi(void) const
|
||||
{
|
||||
return ni_;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
unsigned int A2AMatrixIo<T>::getNj(void) const
|
||||
{
|
||||
return nj_;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t A2AMatrixIo<T>::getSize(void) const
|
||||
{
|
||||
return nt_*ni_*nj_*sizeof(T);
|
||||
}
|
||||
|
||||
// file allocation /////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
template <typename MetadataType>
|
||||
void A2AMatrixIo<T>::initFile(const MetadataType &d, const unsigned int chunkSize)
|
||||
{
|
||||
#ifdef HAVE_HDF5
|
||||
std::vector<hsize_t> dim = {static_cast<hsize_t>(nt_),
|
||||
static_cast<hsize_t>(ni_),
|
||||
static_cast<hsize_t>(nj_)},
|
||||
chunk = {static_cast<hsize_t>(nt_),
|
||||
static_cast<hsize_t>(chunkSize),
|
||||
static_cast<hsize_t>(chunkSize)};
|
||||
H5NS::DataSpace dataspace(dim.size(), dim.data());
|
||||
H5NS::DataSet dataset;
|
||||
H5NS::DSetCreatPropList plist;
|
||||
|
||||
// create empty file just with metadata
|
||||
{
|
||||
Hdf5Writer writer(filename_);
|
||||
write(writer, dataname_, d);
|
||||
}
|
||||
|
||||
// create the dataset
|
||||
Hdf5Reader reader(filename_, false);
|
||||
|
||||
push(reader, dataname_);
|
||||
auto &group = reader.getGroup();
|
||||
plist.setChunk(chunk.size(), chunk.data());
|
||||
plist.setFletcher32();
|
||||
dataset = group.createDataSet(HADRONS_A2AM_NAME, Hdf5Type<T>::type(), dataspace, plist);
|
||||
#else
|
||||
HADRONS_ERROR(Implementation, "all-to-all matrix I/O needs HDF5 library");
|
||||
#endif
|
||||
}
|
||||
|
||||
// block I/O ///////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
void A2AMatrixIo<T>::saveBlock(const T *data,
|
||||
const unsigned int i,
|
||||
const unsigned int j,
|
||||
const unsigned int blockSizei,
|
||||
const unsigned int blockSizej)
|
||||
{
|
||||
#ifdef HAVE_HDF5
|
||||
Hdf5Reader reader(filename_, false);
|
||||
std::vector<hsize_t> count = {nt_, blockSizei, blockSizej},
|
||||
offset = {0, static_cast<hsize_t>(i),
|
||||
static_cast<hsize_t>(j)},
|
||||
stride = {1, 1, 1},
|
||||
block = {1, 1, 1};
|
||||
H5NS::DataSpace memspace(count.size(), count.data()), dataspace;
|
||||
H5NS::DataSet dataset;
|
||||
size_t shift;
|
||||
|
||||
push(reader, dataname_);
|
||||
auto &group = reader.getGroup();
|
||||
dataset = group.openDataSet(HADRONS_A2AM_NAME);
|
||||
dataspace = dataset.getSpace();
|
||||
dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data(),
|
||||
stride.data(), block.data());
|
||||
dataset.write(data, Hdf5Type<T>::type(), memspace, dataspace);
|
||||
#else
|
||||
HADRONS_ERROR(Implementation, "all-to-all matrix I/O needs HDF5 library");
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void A2AMatrixIo<T>::saveBlock(const A2AMatrixSet<T> &m,
|
||||
const unsigned int ext, const unsigned int str,
|
||||
const unsigned int i, const unsigned int j)
|
||||
{
|
||||
unsigned int blockSizei = m.dimension(3);
|
||||
unsigned int blockSizej = m.dimension(4);
|
||||
unsigned int nstr = m.dimension(1);
|
||||
size_t offset = (ext*nstr + str)*nt_*blockSizei*blockSizej;
|
||||
|
||||
saveBlock(m.data() + offset, i, j, blockSizei, blockSizej);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <template <class> class Vec, typename VecT>
|
||||
void A2AMatrixIo<T>::load(Vec<VecT> &v, double *tRead)
|
||||
{
|
||||
#ifdef HAVE_HDF5
|
||||
Hdf5Reader reader(filename_);
|
||||
std::vector<hsize_t> hdim;
|
||||
H5NS::DataSet dataset;
|
||||
H5NS::DataSpace dataspace;
|
||||
H5NS::CompType datatype;
|
||||
|
||||
push(reader, dataname_);
|
||||
auto &group = reader.getGroup();
|
||||
dataset = group.openDataSet(HADRONS_A2AM_NAME);
|
||||
datatype = dataset.getCompType();
|
||||
dataspace = dataset.getSpace();
|
||||
hdim.resize(dataspace.getSimpleExtentNdims());
|
||||
dataspace.getSimpleExtentDims(hdim.data());
|
||||
if ((nt_*ni_*nj_ != 0) and
|
||||
((hdim[0] != nt_) or (hdim[1] != ni_) or (hdim[2] != nj_)))
|
||||
{
|
||||
HADRONS_ERROR(Size, "all-to-all matrix size mismatch (got "
|
||||
+ std::to_string(hdim[0]) + "x" + std::to_string(hdim[1]) + "x"
|
||||
+ std::to_string(hdim[2]) + ", expected "
|
||||
+ std::to_string(nt_) + "x" + std::to_string(ni_) + "x"
|
||||
+ std::to_string(nj_));
|
||||
}
|
||||
else if (ni_*nj_ == 0)
|
||||
{
|
||||
if (hdim[0] != nt_)
|
||||
{
|
||||
HADRONS_ERROR(Size, "all-to-all time size mismatch (got "
|
||||
+ std::to_string(hdim[0]) + ", expected "
|
||||
+ std::to_string(nt_) + ")");
|
||||
}
|
||||
ni_ = hdim[1];
|
||||
nj_ = hdim[2];
|
||||
}
|
||||
|
||||
A2AMatrix<T> buf(ni_, nj_);
|
||||
std::vector<hsize_t> count = {1, static_cast<hsize_t>(ni_),
|
||||
static_cast<hsize_t>(nj_)},
|
||||
stride = {1, 1, 1},
|
||||
block = {1, 1, 1},
|
||||
memCount = {static_cast<hsize_t>(ni_),
|
||||
static_cast<hsize_t>(nj_)};
|
||||
H5NS::DataSpace memspace(memCount.size(), memCount.data());
|
||||
|
||||
std::cout << "Loading timeslice";
|
||||
std::cout.flush();
|
||||
*tRead = 0.;
|
||||
for (unsigned int tp1 = nt_; tp1 > 0; --tp1)
|
||||
{
|
||||
unsigned int t = tp1 - 1;
|
||||
std::vector<hsize_t> offset = {static_cast<hsize_t>(t), 0, 0};
|
||||
|
||||
if (t % 10 == 0)
|
||||
{
|
||||
std::cout << " " << t;
|
||||
std::cout.flush();
|
||||
}
|
||||
dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data(),
|
||||
stride.data(), block.data());
|
||||
if (tRead) *tRead -= usecond();
|
||||
dataset.read(buf.data(), datatype, memspace, dataspace);
|
||||
if (tRead) *tRead += usecond();
|
||||
v[t] = buf.template cast<VecT>();
|
||||
}
|
||||
std::cout << std::endl;
|
||||
#else
|
||||
HADRONS_ERROR(Implementation, "all-to-all matrix I/O needs HDF5 library");
|
||||
#endif
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* A2AMatrixBlockComputation template implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename T, typename Field, typename MetadataType, typename TIo>
|
||||
A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
||||
::A2AMatrixBlockComputation(GridBase *grid,
|
||||
const unsigned int orthogDim,
|
||||
const unsigned int next,
|
||||
const unsigned int nstr,
|
||||
const unsigned int blockSize,
|
||||
const unsigned int cacheBlockSize,
|
||||
TimerArray *tArray)
|
||||
: grid_(grid), nt_(grid->GlobalDimensions()[orthogDim]), orthogDim_(orthogDim)
|
||||
, next_(next), nstr_(nstr), blockSize_(blockSize), cacheBlockSize_(cacheBlockSize)
|
||||
, tArray_(tArray)
|
||||
{
|
||||
mCache_.resize(nt_*next_*nstr_*cacheBlockSize_*cacheBlockSize_);
|
||||
mBuf_.resize(nt_*next_*nstr_*blockSize_*blockSize_);
|
||||
}
|
||||
|
||||
#define START_TIMER(name) if (tArray_) tArray_->startTimer(name)
|
||||
#define STOP_TIMER(name) if (tArray_) tArray_->stopTimer(name)
|
||||
#define GET_TIMER(name) ((tArray_ != nullptr) ? tArray_->getDTimer(name) : 0.)
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename T, typename Field, typename MetadataType, typename TIo>
|
||||
void A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
||||
::execute(const std::vector<Field> &left, const std::vector<Field> &right,
|
||||
A2AKernel<T, Field> &kernel, const FilenameFn &ionameFn,
|
||||
const FilenameFn &filenameFn, const MetadataFn &metadataFn)
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// i,j is first loop over blockSize_ factors
|
||||
// ii,jj is second loop over cacheBlockSize_ factors for high perf contractions
|
||||
// iii,jjj are loops within cacheBlock
|
||||
// Total index is sum of these i+ii+iii etc...
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int N_i = left.size();
|
||||
int N_j = right.size();
|
||||
double flops, bytes, t_kernel;
|
||||
double nodes = grid_->NodeCount();
|
||||
|
||||
int NBlock_i = N_i/blockSize_ + (((N_i % blockSize_) != 0) ? 1 : 0);
|
||||
int NBlock_j = N_j/blockSize_ + (((N_j % blockSize_) != 0) ? 1 : 0);
|
||||
|
||||
for(int i=0;i<N_i;i+=blockSize_)
|
||||
for(int j=0;j<N_j;j+=blockSize_)
|
||||
{
|
||||
// Get the W and V vectors for this block^2 set of terms
|
||||
int N_ii = MIN(N_i-i,blockSize_);
|
||||
int N_jj = MIN(N_j-j,blockSize_);
|
||||
A2AMatrixSet<TIo> mBlock(mBuf_.data(), next_, nstr_, nt_, N_ii, N_jj);
|
||||
|
||||
LOG(Message) << "All-to-all matrix block "
|
||||
<< j/blockSize_ + NBlock_j*i/blockSize_ + 1
|
||||
<< "/" << NBlock_i*NBlock_j << " [" << i <<" .. "
|
||||
<< i+N_ii-1 << ", " << j <<" .. " << j+N_jj-1 << "]"
|
||||
<< std::endl;
|
||||
// Series of cache blocked chunks of the contractions within this block
|
||||
flops = 0.0;
|
||||
bytes = 0.0;
|
||||
t_kernel = 0.0;
|
||||
for(int ii=0;ii<N_ii;ii+=cacheBlockSize_)
|
||||
for(int jj=0;jj<N_jj;jj+=cacheBlockSize_)
|
||||
{
|
||||
double t;
|
||||
int N_iii = MIN(N_ii-ii,cacheBlockSize_);
|
||||
int N_jjj = MIN(N_jj-jj,cacheBlockSize_);
|
||||
A2AMatrixSet<T> mCacheBlock(mCache_.data(), next_, nstr_, nt_, N_iii, N_jjj);
|
||||
|
||||
START_TIMER("kernel");
|
||||
kernel(mCacheBlock, &left[i+ii], &right[j+jj], orthogDim_, t);
|
||||
STOP_TIMER("kernel");
|
||||
t_kernel += t;
|
||||
flops += kernel.flops(N_iii, N_jjj);
|
||||
bytes += kernel.bytes(N_iii, N_jjj);
|
||||
|
||||
START_TIMER("cache copy");
|
||||
parallel_for_nest5(int e =0;e<next_;e++)
|
||||
for(int s =0;s< nstr_;s++)
|
||||
for(int t =0;t< nt_;t++)
|
||||
for(int iii=0;iii< N_iii;iii++)
|
||||
for(int jjj=0;jjj< N_jjj;jjj++)
|
||||
{
|
||||
mBlock(e,s,t,ii+iii,jj+jjj) = mCacheBlock(e,s,t,iii,jjj);
|
||||
}
|
||||
STOP_TIMER("cache copy");
|
||||
}
|
||||
|
||||
// perf
|
||||
LOG(Message) << "Kernel perf " << flops/t_kernel/1.0e3/nodes
|
||||
<< " Gflop/s/node " << std::endl;
|
||||
LOG(Message) << "Kernel perf " << bytes/t_kernel*1.0e6/1024/1024/1024/nodes
|
||||
<< " GB/s/node " << std::endl;
|
||||
|
||||
// IO
|
||||
double blockSize, ioTime;
|
||||
unsigned int myRank = grid_->ThisRank(), nRank = grid_->RankCount();
|
||||
|
||||
LOG(Message) << "Writing block to disk" << std::endl;
|
||||
ioTime = -GET_TIMER("IO: write block");
|
||||
START_TIMER("IO: total");
|
||||
makeFileDir(filenameFn(0, 0), grid_);
|
||||
#ifdef HADRONS_A2AM_PARALLEL_IO
|
||||
grid_->Barrier();
|
||||
// make task list for current node
|
||||
nodeIo_.clear();
|
||||
for(int f = myRank; f < next_*nstr_; f += nRank)
|
||||
{
|
||||
IoHelper h;
|
||||
|
||||
h.i = i;
|
||||
h.j = j;
|
||||
h.e = f/nstr_;
|
||||
h.s = f % nstr_;
|
||||
h.io = A2AMatrixIo<TIo>(filenameFn(h.e, h.s),
|
||||
ionameFn(h.e, h.s), nt_, N_i, N_j);
|
||||
h.md = metadataFn(h.e, h.s);
|
||||
nodeIo_.push_back(h);
|
||||
}
|
||||
// parallel IO
|
||||
for (auto &h: nodeIo_)
|
||||
{
|
||||
saveBlock(mBlock, h);
|
||||
}
|
||||
grid_->Barrier();
|
||||
#else
|
||||
// serial IO, for testing purposes only
|
||||
for(int e = 0; e < next_; e++)
|
||||
for(int s = 0; s < nstr_; s++)
|
||||
{
|
||||
IoHelper h;
|
||||
|
||||
h.i = i;
|
||||
h.j = j;
|
||||
h.e = e;
|
||||
h.s = s;
|
||||
h.io = A2AMatrixIo<TIo>(filenameFn(h.e, h.s),
|
||||
ionameFn(h.e, h.s), nt_, N_i, N_j);
|
||||
h.md = metadataFn(h.e, h.s);
|
||||
saveBlock(mfBlock, h);
|
||||
}
|
||||
#endif
|
||||
STOP_TIMER("IO: total");
|
||||
blockSize = static_cast<double>(next_*nstr_*nt_*N_ii*N_jj*sizeof(TIo));
|
||||
ioTime += GET_TIMER("IO: write block");
|
||||
LOG(Message) << "HDF5 IO done " << sizeString(blockSize) << " in "
|
||||
<< ioTime << " us ("
|
||||
<< blockSize/ioTime*1.0e6/1024/1024
|
||||
<< " MB/s)" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// I/O handler /////////////////////////////////////////////////////////////////
|
||||
template <typename T, typename Field, typename MetadataType, typename TIo>
|
||||
void A2AMatrixBlockComputation<T, Field, MetadataType, TIo>
|
||||
::saveBlock(const A2AMatrixSet<TIo> &m, IoHelper &h)
|
||||
{
|
||||
if ((h.i == 0) and (h.j == 0))
|
||||
{
|
||||
START_TIMER("IO: file creation");
|
||||
h.io.initFile(h.md, blockSize_);
|
||||
STOP_TIMER("IO: file creation");
|
||||
}
|
||||
START_TIMER("IO: write block");
|
||||
h.io.saveBlock(m, h.e, h.s, h.i, h.j);
|
||||
STOP_TIMER("IO: write block");
|
||||
}
|
||||
|
||||
#undef START_TIMER
|
||||
#undef STOP_TIMER
|
||||
#undef GET_TIMER
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // A2A_Matrix_hpp_
|
342
Hadrons/A2AVectors.hpp
Normal file
342
Hadrons/A2AVectors.hpp
Normal file
@ -0,0 +1,342 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/A2AVectors.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: fionnoh <fionnoh@gmail.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 */
|
||||
#ifndef A2A_Vectors_hpp_
|
||||
#define A2A_Vectors_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Environment.hpp>
|
||||
#include <Hadrons/Solver.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Class to generate V & W all-to-all vectors *
|
||||
******************************************************************************/
|
||||
template <typename FImpl>
|
||||
class A2AVectorsSchurDiagTwo
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
SOLVER_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
A2AVectorsSchurDiagTwo(FMat &action, Solver &solver);
|
||||
virtual ~A2AVectorsSchurDiagTwo(void) = default;
|
||||
void makeLowModeV(FermionField &vout,
|
||||
const FermionField &evec, const Real &eval);
|
||||
void makeLowModeV5D(FermionField &vout_4d, FermionField &vout_5d,
|
||||
const FermionField &evec, const Real &eval);
|
||||
void makeLowModeW(FermionField &wout,
|
||||
const FermionField &evec, const Real &eval);
|
||||
void makeLowModeW5D(FermionField &wout_4d, FermionField &wout_5d,
|
||||
const FermionField &evec, const Real &eval);
|
||||
void makeHighModeV(FermionField &vout, const FermionField &noise);
|
||||
void makeHighModeV5D(FermionField &vout_4d, FermionField &vout_5d,
|
||||
const FermionField &noise_5d);
|
||||
void makeHighModeW(FermionField &wout, const FermionField &noise);
|
||||
void makeHighModeW5D(FermionField &vout_5d, FermionField &wout_5d,
|
||||
const FermionField &noise_5d);
|
||||
private:
|
||||
FMat &action_;
|
||||
Solver &solver_;
|
||||
GridBase *fGrid_, *frbGrid_, *gGrid_;
|
||||
bool is5d_;
|
||||
FermionField src_o_, sol_e_, sol_o_, tmp_, tmp5_;
|
||||
SchurDiagTwoOperator<FMat, FermionField> op_;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* Methods for V & W all-to-all vectors I/O *
|
||||
******************************************************************************/
|
||||
class A2AVectorsIo
|
||||
{
|
||||
public:
|
||||
struct Record: Serializable
|
||||
{
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Record,
|
||||
unsigned int, index);
|
||||
Record(void): index(0) {}
|
||||
};
|
||||
public:
|
||||
template <typename Field>
|
||||
static void write(const std::string fileStem, std::vector<Field> &vec,
|
||||
const bool multiFile, const int trajectory = -1);
|
||||
template <typename Field>
|
||||
static void read(std::vector<Field> &vec, const std::string fileStem,
|
||||
const bool multiFile, const int trajectory = -1);
|
||||
private:
|
||||
static inline std::string vecFilename(const std::string stem, const int traj,
|
||||
const bool multiFile)
|
||||
{
|
||||
std::string t = (traj < 0) ? "" : ("." + std::to_string(traj));
|
||||
|
||||
if (multiFile)
|
||||
{
|
||||
return stem + t;
|
||||
}
|
||||
else
|
||||
{
|
||||
return stem + t + ".bin";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* A2AVectorsSchurDiagTwo template implementation *
|
||||
******************************************************************************/
|
||||
template <typename FImpl>
|
||||
A2AVectorsSchurDiagTwo<FImpl>::A2AVectorsSchurDiagTwo(FMat &action, Solver &solver)
|
||||
: action_(action)
|
||||
, solver_(solver)
|
||||
, fGrid_(action_.FermionGrid())
|
||||
, frbGrid_(action_.FermionRedBlackGrid())
|
||||
, gGrid_(action_.GaugeGrid())
|
||||
, src_o_(frbGrid_)
|
||||
, sol_e_(frbGrid_)
|
||||
, sol_o_(frbGrid_)
|
||||
, tmp_(frbGrid_)
|
||||
, tmp5_(fGrid_)
|
||||
, op_(action_)
|
||||
{}
|
||||
|
||||
template <typename FImpl>
|
||||
void A2AVectorsSchurDiagTwo<FImpl>::makeLowModeV(FermionField &vout, const FermionField &evec, const Real &eval)
|
||||
{
|
||||
src_o_ = evec;
|
||||
src_o_.Checkerboard() = Odd;
|
||||
pickCheckerboard(Even, sol_e_, vout);
|
||||
pickCheckerboard(Odd, sol_o_, vout);
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// v_ie = -(1/eval_i) * MeeInv Meo MooInv evec_i
|
||||
/////////////////////////////////////////////////////
|
||||
action_.MooeeInv(src_o_, tmp_);
|
||||
assert(tmp_.Checkerboard() == Odd);
|
||||
action_.Meooe(tmp_, sol_e_);
|
||||
assert(sol_e_.Checkerboard() == Even);
|
||||
action_.MooeeInv(sol_e_, tmp_);
|
||||
assert(tmp_.Checkerboard() == Even);
|
||||
sol_e_ = (-1.0 / eval) * tmp_;
|
||||
assert(sol_e_.Checkerboard() == Even);
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// v_io = (1/eval_i) * MooInv evec_i
|
||||
/////////////////////////////////////////////////////
|
||||
action_.MooeeInv(src_o_, tmp_);
|
||||
assert(tmp_.Checkerboard() == Odd);
|
||||
sol_o_ = (1.0 / eval) * tmp_;
|
||||
assert(sol_o_.Checkerboard() == Odd);
|
||||
setCheckerboard(vout, sol_e_);
|
||||
assert(sol_e_.Checkerboard() == Even);
|
||||
setCheckerboard(vout, sol_o_);
|
||||
assert(sol_o_.Checkerboard() == Odd);
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
void A2AVectorsSchurDiagTwo<FImpl>::makeLowModeV5D(FermionField &vout_4d, FermionField &vout_5d, const FermionField &evec, const Real &eval)
|
||||
{
|
||||
makeLowModeV(vout_5d, evec, eval);
|
||||
action_.ExportPhysicalFermionSolution(vout_5d, vout_4d);
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
void A2AVectorsSchurDiagTwo<FImpl>::makeLowModeW(FermionField &wout, const FermionField &evec, const Real &eval)
|
||||
{
|
||||
src_o_ = evec;
|
||||
src_o_.Checkerboard() = Odd;
|
||||
pickCheckerboard(Even, sol_e_, wout);
|
||||
pickCheckerboard(Odd, sol_o_, wout);
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// w_ie = - MeeInvDag MoeDag Doo evec_i
|
||||
/////////////////////////////////////////////////////
|
||||
op_.Mpc(src_o_, tmp_);
|
||||
assert(tmp_.Checkerboard() == Odd);
|
||||
action_.MeooeDag(tmp_, sol_e_);
|
||||
assert(sol_e_.Checkerboard() == Even);
|
||||
action_.MooeeInvDag(sol_e_, tmp_);
|
||||
assert(tmp_.Checkerboard() == Even);
|
||||
sol_e_ = (-1.0) * tmp_;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// w_io = Doo evec_i
|
||||
/////////////////////////////////////////////////////
|
||||
op_.Mpc(src_o_, sol_o_);
|
||||
assert(sol_o_.Checkerboard() == Odd);
|
||||
setCheckerboard(wout, sol_e_);
|
||||
assert(sol_e_.Checkerboard() == Even);
|
||||
setCheckerboard(wout, sol_o_);
|
||||
assert(sol_o_.Checkerboard() == Odd);
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
void A2AVectorsSchurDiagTwo<FImpl>::makeLowModeW5D(FermionField &wout_4d,
|
||||
FermionField &wout_5d,
|
||||
const FermionField &evec,
|
||||
const Real &eval)
|
||||
{
|
||||
makeLowModeW(tmp5_, evec, eval);
|
||||
action_.DminusDag(tmp5_, wout_5d);
|
||||
action_.ExportPhysicalFermionSource(wout_5d, wout_4d);
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
void A2AVectorsSchurDiagTwo<FImpl>::makeHighModeV(FermionField &vout,
|
||||
const FermionField &noise)
|
||||
{
|
||||
solver_(vout, noise);
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
void A2AVectorsSchurDiagTwo<FImpl>::makeHighModeV5D(FermionField &vout_4d,
|
||||
FermionField &vout_5d,
|
||||
const FermionField &noise)
|
||||
{
|
||||
if (noise.Grid()->Dimensions() == fGrid_->Dimensions() - 1)
|
||||
{
|
||||
action_.ImportPhysicalFermionSource(noise, tmp5_);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp5_ = noise;
|
||||
}
|
||||
makeHighModeV(vout_5d, tmp5_);
|
||||
action_.ExportPhysicalFermionSolution(vout_5d, vout_4d);
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
void A2AVectorsSchurDiagTwo<FImpl>::makeHighModeW(FermionField &wout,
|
||||
const FermionField &noise)
|
||||
{
|
||||
wout = noise;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
void A2AVectorsSchurDiagTwo<FImpl>::makeHighModeW5D(FermionField &wout_4d,
|
||||
FermionField &wout_5d,
|
||||
const FermionField &noise)
|
||||
{
|
||||
if (noise.Grid()->Dimensions() == fGrid_->Dimensions() - 1)
|
||||
{
|
||||
action_.ImportUnphysicalFermion(noise, wout_5d);
|
||||
wout_4d = noise;
|
||||
}
|
||||
else
|
||||
{
|
||||
wout_5d = noise;
|
||||
action_.ExportPhysicalFermionSource(wout_5d, wout_4d);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* all-to-all vectors I/O template implementation *
|
||||
******************************************************************************/
|
||||
template <typename Field>
|
||||
void A2AVectorsIo::write(const std::string fileStem, std::vector<Field> &vec,
|
||||
const bool multiFile, const int trajectory)
|
||||
{
|
||||
Record record;
|
||||
GridBase *grid = vec[0].Grid();
|
||||
ScidacWriter binWriter(grid->IsBoss());
|
||||
std::string filename = vecFilename(fileStem, trajectory, multiFile);
|
||||
|
||||
if (multiFile)
|
||||
{
|
||||
std::string fullFilename;
|
||||
|
||||
for (unsigned int i = 0; i < vec.size(); ++i)
|
||||
{
|
||||
fullFilename = filename + "/elem" + std::to_string(i) + ".bin";
|
||||
|
||||
LOG(Message) << "Writing vector " << i << std::endl;
|
||||
makeFileDir(fullFilename, grid);
|
||||
binWriter.open(fullFilename);
|
||||
record.index = i;
|
||||
binWriter.writeScidacFieldRecord(vec[i], record);
|
||||
binWriter.close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
makeFileDir(filename, grid);
|
||||
binWriter.open(filename);
|
||||
for (unsigned int i = 0; i < vec.size(); ++i)
|
||||
{
|
||||
LOG(Message) << "Writing vector " << i << std::endl;
|
||||
record.index = i;
|
||||
binWriter.writeScidacFieldRecord(vec[i], record);
|
||||
}
|
||||
binWriter.close();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Field>
|
||||
void A2AVectorsIo::read(std::vector<Field> &vec, const std::string fileStem,
|
||||
const bool multiFile, const int trajectory)
|
||||
{
|
||||
Record record;
|
||||
ScidacReader binReader;
|
||||
std::string filename = vecFilename(fileStem, trajectory, multiFile);
|
||||
|
||||
if (multiFile)
|
||||
{
|
||||
std::string fullFilename;
|
||||
|
||||
for (unsigned int i = 0; i < vec.size(); ++i)
|
||||
{
|
||||
fullFilename = filename + "/elem" + std::to_string(i) + ".bin";
|
||||
|
||||
LOG(Message) << "Reading vector " << i << std::endl;
|
||||
binReader.open(fullFilename);
|
||||
binReader.readScidacFieldRecord(vec[i], record);
|
||||
binReader.close();
|
||||
if (record.index != i)
|
||||
{
|
||||
HADRONS_ERROR(Io, "vector index mismatch");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
binReader.open(filename);
|
||||
for (unsigned int i = 0; i < vec.size(); ++i)
|
||||
{
|
||||
LOG(Message) << "Reading vector " << i << std::endl;
|
||||
binReader.readScidacFieldRecord(vec[i], record);
|
||||
if (record.index != i)
|
||||
{
|
||||
HADRONS_ERROR(Io, "vector index mismatch");
|
||||
}
|
||||
}
|
||||
binReader.close();
|
||||
}
|
||||
}
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // A2A_Vectors_hpp_
|
268
Hadrons/Application.cc
Normal file
268
Hadrons/Application.cc
Normal file
@ -0,0 +1,268 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Application.cc
|
||||
|
||||
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 */
|
||||
|
||||
#include <Hadrons/Application.hpp>
|
||||
#include <Hadrons/GeneticScheduler.hpp>
|
||||
#include <Hadrons/Modules.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
|
||||
using namespace Hadrons;
|
||||
|
||||
#define BIG_SEP "================"
|
||||
#define SEP "----------------"
|
||||
|
||||
/******************************************************************************
|
||||
* Application implementation *
|
||||
******************************************************************************/
|
||||
// constructors ////////////////////////////////////////////////////////////////
|
||||
#define MACOUT(macro) macro << " (" << #macro << ")"
|
||||
#define MACOUTS(macro) HADRONS_STR(macro) << " (" << #macro << ")"
|
||||
|
||||
Application::Application(void)
|
||||
{
|
||||
initLogger();
|
||||
auto dim = GridDefaultLatt(), mpi = GridDefaultMpi(), loc(dim);
|
||||
locVol_ = 1;
|
||||
for (unsigned int d = 0; d < dim.size(); ++d)
|
||||
{
|
||||
loc[d] /= mpi[d];
|
||||
locVol_ *= loc[d];
|
||||
}
|
||||
LOG(Message) << "====== HADRONS APPLICATION INITIALISATION ======" << std::endl;
|
||||
LOG(Message) << "** Dimensions" << std::endl;
|
||||
LOG(Message) << "Global lattice: " << dim << std::endl;
|
||||
LOG(Message) << "MPI partition : " << mpi << std::endl;
|
||||
LOG(Message) << "Local lattice : " << loc << std::endl;
|
||||
LOG(Message) << std::endl;
|
||||
LOG(Message) << "** Default parameters (and associated C macros)" << std::endl;
|
||||
LOG(Message) << "ASCII output precision : " << MACOUT(DEFAULT_ASCII_PREC) << std::endl;
|
||||
LOG(Message) << "Fermion implementation : " << MACOUTS(FIMPLBASE) << std::endl;
|
||||
LOG(Message) << "z-Fermion implementation: " << MACOUTS(ZFIMPLBASE) << std::endl;
|
||||
LOG(Message) << "Scalar implementation : " << MACOUTS(SIMPLBASE) << std::endl;
|
||||
LOG(Message) << "Gauge implementation : " << MACOUTS(GIMPLBASE) << std::endl;
|
||||
LOG(Message) << "Eigenvector base size : "
|
||||
<< MACOUT(HADRONS_DEFAULT_LANCZOS_NBASIS) << std::endl;
|
||||
LOG(Message) << "Schur decomposition : " << MACOUTS(HADRONS_DEFAULT_SCHUR) << std::endl;
|
||||
LOG(Message) << std::endl;
|
||||
}
|
||||
|
||||
Application::Application(const Application::GlobalPar &par)
|
||||
: Application()
|
||||
{
|
||||
setPar(par);
|
||||
}
|
||||
|
||||
Application::Application(const std::string parameterFileName)
|
||||
: Application()
|
||||
{
|
||||
parameterFileName_ = parameterFileName;
|
||||
}
|
||||
|
||||
// access //////////////////////////////////////////////////////////////////////
|
||||
void Application::setPar(const Application::GlobalPar &par)
|
||||
{
|
||||
par_ = par;
|
||||
}
|
||||
|
||||
const Application::GlobalPar & Application::getPar(void)
|
||||
{
|
||||
return par_;
|
||||
}
|
||||
|
||||
// execute /////////////////////////////////////////////////////////////////////
|
||||
void Application::run(void)
|
||||
{
|
||||
LOG(Message) << "====== HADRONS APPLICATION START ======" << std::endl;
|
||||
if (!parameterFileName_.empty() and (vm().getNModule() == 0))
|
||||
{
|
||||
parseParameterFile(parameterFileName_);
|
||||
}
|
||||
if (getPar().runId.empty())
|
||||
{
|
||||
HADRONS_ERROR(Definition, "run id is empty");
|
||||
}
|
||||
LOG(Message) << "RUN ID '" << getPar().runId << "'" << std::endl;
|
||||
BinaryIO::latticeWriteMaxRetry = getPar().parallelWriteMaxRetry;
|
||||
LOG(Message) << "Attempt(s) for resilient parallel I/O: "
|
||||
<< BinaryIO::latticeWriteMaxRetry << std::endl;
|
||||
vm().setRunId(getPar().runId);
|
||||
vm().printContent();
|
||||
env().printContent();
|
||||
schedule();
|
||||
printSchedule();
|
||||
if (!getPar().graphFile.empty())
|
||||
{
|
||||
makeFileDir(getPar().graphFile, env().getGrid());
|
||||
vm().dumpModuleGraph(getPar().graphFile);
|
||||
}
|
||||
configLoop();
|
||||
}
|
||||
|
||||
// parse parameter file ////////////////////////////////////////////////////////
|
||||
class ObjectId: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(ObjectId,
|
||||
std::string, name,
|
||||
std::string, type);
|
||||
};
|
||||
|
||||
void Application::parseParameterFile(const std::string parameterFileName)
|
||||
{
|
||||
XmlReader reader(parameterFileName);
|
||||
GlobalPar par;
|
||||
ObjectId id;
|
||||
|
||||
LOG(Message) << "Building application from '" << parameterFileName << "'..." << std::endl;
|
||||
read(reader, "parameters", par);
|
||||
setPar(par);
|
||||
if (!push(reader, "modules"))
|
||||
{
|
||||
HADRONS_ERROR(Parsing, "Cannot open node 'modules' in parameter file '"
|
||||
+ parameterFileName + "'");
|
||||
}
|
||||
if (!push(reader, "module"))
|
||||
{
|
||||
HADRONS_ERROR(Parsing, "Cannot open node 'modules/module' in parameter file '"
|
||||
+ parameterFileName + "'");
|
||||
}
|
||||
do
|
||||
{
|
||||
read(reader, "id", id);
|
||||
vm().createModule(id.name, id.type, reader);
|
||||
} while (reader.nextElement("module"));
|
||||
pop(reader);
|
||||
pop(reader);
|
||||
}
|
||||
|
||||
void Application::saveParameterFile(const std::string parameterFileName)
|
||||
{
|
||||
LOG(Message) << "Saving application to '" << parameterFileName << "'..." << std::endl;
|
||||
if (env().getGrid()->IsBoss())
|
||||
{
|
||||
XmlWriter writer(parameterFileName);
|
||||
ObjectId id;
|
||||
const unsigned int nMod = vm().getNModule();
|
||||
|
||||
write(writer, "parameters", getPar());
|
||||
push(writer, "modules");
|
||||
for (unsigned int i = 0; i < nMod; ++i)
|
||||
{
|
||||
push(writer, "module");
|
||||
id.name = vm().getModuleName(i);
|
||||
id.type = vm().getModule(i)->getRegisteredName();
|
||||
write(writer, "id", id);
|
||||
vm().getModule(i)->saveParameters(writer, "options");
|
||||
pop(writer);
|
||||
}
|
||||
pop(writer);
|
||||
pop(writer);
|
||||
}
|
||||
}
|
||||
|
||||
// schedule computation ////////////////////////////////////////////////////////
|
||||
void Application::schedule(void)
|
||||
{
|
||||
if (!scheduled_ and !loadedSchedule_)
|
||||
{
|
||||
program_ = vm().schedule(par_.genetic);
|
||||
scheduled_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Application::saveSchedule(const std::string filename)
|
||||
{
|
||||
LOG(Message) << "Saving current schedule to '" << filename << "'..."
|
||||
<< std::endl;
|
||||
if (env().getGrid()->IsBoss())
|
||||
{
|
||||
TextWriter writer(filename);
|
||||
std::vector<std::string> program;
|
||||
|
||||
if (!scheduled_)
|
||||
{
|
||||
HADRONS_ERROR(Definition, "Computation not scheduled");
|
||||
}
|
||||
|
||||
for (auto address: program_)
|
||||
{
|
||||
program.push_back(vm().getModuleName(address));
|
||||
}
|
||||
write(writer, "schedule", program);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::loadSchedule(const std::string filename)
|
||||
{
|
||||
TextReader reader(filename);
|
||||
std::vector<std::string> program;
|
||||
|
||||
LOG(Message) << "Loading schedule from '" << filename << "'..."
|
||||
<< std::endl;
|
||||
read(reader, "schedule", program);
|
||||
program_.clear();
|
||||
for (auto &name: program)
|
||||
{
|
||||
program_.push_back(vm().getModuleAddress(name));
|
||||
}
|
||||
loadedSchedule_ = true;
|
||||
scheduled_ = true;
|
||||
}
|
||||
|
||||
void Application::printSchedule(void)
|
||||
{
|
||||
if (!scheduled_ and !loadedSchedule_)
|
||||
{
|
||||
HADRONS_ERROR(Definition, "Computation not scheduled");
|
||||
}
|
||||
auto peak = vm().memoryNeeded(program_);
|
||||
LOG(Message) << "Schedule (memory needed: " << sizeString(peak) << "):"
|
||||
<< std::endl;
|
||||
for (unsigned int i = 0; i < program_.size(); ++i)
|
||||
{
|
||||
LOG(Message) << std::setw(4) << i + 1 << ": "
|
||||
<< vm().getModuleName(program_[i]) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// loop on configurations //////////////////////////////////////////////////////
|
||||
void Application::configLoop(void)
|
||||
{
|
||||
auto range = par_.trajCounter;
|
||||
|
||||
for (unsigned int t = range.start; t < range.end; t += range.step)
|
||||
{
|
||||
LOG(Message) << BIG_SEP << " Starting measurement for trajectory " << t
|
||||
<< " " << BIG_SEP << std::endl;
|
||||
vm().setTrajectory(t);
|
||||
vm().executeProgram(program_);
|
||||
}
|
||||
LOG(Message) << BIG_SEP << " End of measurement " << BIG_SEP << std::endl;
|
||||
env().freeAll();
|
||||
}
|
124
Hadrons/Application.hpp
Normal file
124
Hadrons/Application.hpp
Normal file
@ -0,0 +1,124 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Application.hpp
|
||||
|
||||
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 */
|
||||
|
||||
#ifndef Hadrons_Application_hpp_
|
||||
#define Hadrons_Application_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/VirtualMachine.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Main program manager *
|
||||
******************************************************************************/
|
||||
class Application
|
||||
{
|
||||
public:
|
||||
class TrajRange: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(TrajRange,
|
||||
unsigned int, start,
|
||||
unsigned int, end,
|
||||
unsigned int, step);
|
||||
};
|
||||
class GlobalPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar,
|
||||
TrajRange, trajCounter,
|
||||
VirtualMachine::GeneticPar, genetic,
|
||||
std::string, runId,
|
||||
std::string, graphFile,
|
||||
int, parallelWriteMaxRetry);
|
||||
GlobalPar(void): parallelWriteMaxRetry{-1} {}
|
||||
};
|
||||
public:
|
||||
// constructors
|
||||
Application(void);
|
||||
Application(const GlobalPar &par);
|
||||
Application(const std::string parameterFileName);
|
||||
// destructor
|
||||
virtual ~Application(void) = default;
|
||||
// access
|
||||
void setPar(const GlobalPar &par);
|
||||
const GlobalPar & getPar(void);
|
||||
// module creation
|
||||
template <typename M>
|
||||
void createModule(const std::string name);
|
||||
template <typename M>
|
||||
void createModule(const std::string name, const typename M::Par &par);
|
||||
// execute
|
||||
void run(void);
|
||||
// XML parameter file I/O
|
||||
void parseParameterFile(const std::string parameterFileName);
|
||||
void saveParameterFile(const std::string parameterFileName);
|
||||
// schedule computation
|
||||
void schedule(void);
|
||||
void saveSchedule(const std::string filename);
|
||||
void loadSchedule(const std::string filename);
|
||||
void printSchedule(void);
|
||||
// loop on configurations
|
||||
void configLoop(void);
|
||||
private:
|
||||
// environment shortcut
|
||||
DEFINE_ENV_ALIAS;
|
||||
// virtual machine shortcut
|
||||
DEFINE_VM_ALIAS;
|
||||
private:
|
||||
long unsigned int locVol_;
|
||||
std::string parameterFileName_{""};
|
||||
GlobalPar par_;
|
||||
VirtualMachine::Program program_;
|
||||
bool scheduled_{false}, loadedSchedule_{false};
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* Application template implementation *
|
||||
******************************************************************************/
|
||||
// module creation /////////////////////////////////////////////////////////////
|
||||
template <typename M>
|
||||
void Application::createModule(const std::string name)
|
||||
{
|
||||
vm().createModule<M>(name);
|
||||
scheduled_ = false;
|
||||
}
|
||||
|
||||
template <typename M>
|
||||
void Application::createModule(const std::string name,
|
||||
const typename M::Par &par)
|
||||
{
|
||||
vm().createModule<M>(name, par);
|
||||
scheduled_ = false;
|
||||
}
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Application_hpp_
|
249
Hadrons/DilutedNoise.hpp
Normal file
249
Hadrons/DilutedNoise.hpp
Normal file
@ -0,0 +1,249 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/DilutedNoise.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Vera Guelpers <Vera.Guelpers@ed.ac.uk>
|
||||
|
||||
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_DilutedNoise_hpp_
|
||||
#define Hadrons_DilutedNoise_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Abstract container for diluted noise *
|
||||
******************************************************************************/
|
||||
template <typename FImpl>
|
||||
class DilutedNoise
|
||||
{
|
||||
public:
|
||||
typedef typename FImpl::FermionField FermionField;
|
||||
public:
|
||||
// constructor/destructor
|
||||
DilutedNoise(GridCartesian *g);
|
||||
DilutedNoise(GridCartesian *g, const unsigned int nNoise);
|
||||
virtual ~DilutedNoise(void) = default;
|
||||
// access
|
||||
std::vector<FermionField> & getNoise(void);
|
||||
const std::vector<FermionField> & getNoise(void) const;
|
||||
const FermionField & operator[](const unsigned int i) const;
|
||||
FermionField & operator[](const unsigned int i);
|
||||
void resize(const unsigned int nNoise);
|
||||
unsigned int size(void) const;
|
||||
GridCartesian *getGrid(void) const;
|
||||
// generate noise (pure virtual)
|
||||
virtual void generateNoise(GridParallelRNG &rng) = 0;
|
||||
private:
|
||||
std::vector<FermionField> noise_;
|
||||
GridCartesian *grid_;
|
||||
unsigned int nNoise_;
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TimeDilutedSpinColorDiagonalNoise: public DilutedNoise<FImpl>
|
||||
{
|
||||
public:
|
||||
typedef typename FImpl::FermionField FermionField;
|
||||
public:
|
||||
// constructor/destructor
|
||||
TimeDilutedSpinColorDiagonalNoise(GridCartesian *g);
|
||||
virtual ~TimeDilutedSpinColorDiagonalNoise(void) = default;
|
||||
// generate noise
|
||||
virtual void generateNoise(GridParallelRNG &rng);
|
||||
private:
|
||||
unsigned int nt_;
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class FullVolumeSpinColorDiagonalNoise: public DilutedNoise<FImpl>
|
||||
{
|
||||
public:
|
||||
typedef typename FImpl::FermionField FermionField;
|
||||
public:
|
||||
// constructor/destructor
|
||||
FullVolumeSpinColorDiagonalNoise(GridCartesian *g, unsigned int n_src);
|
||||
virtual ~FullVolumeSpinColorDiagonalNoise(void) = default;
|
||||
// generate noise
|
||||
virtual void generateNoise(GridParallelRNG &rng);
|
||||
private:
|
||||
unsigned int nSrc_;
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* DilutedNoise template implementation *
|
||||
******************************************************************************/
|
||||
template <typename FImpl>
|
||||
DilutedNoise<FImpl>::DilutedNoise(GridCartesian *g)
|
||||
: grid_(g)
|
||||
{}
|
||||
|
||||
template <typename FImpl>
|
||||
DilutedNoise<FImpl>::DilutedNoise(GridCartesian *g,
|
||||
const unsigned int nNoise)
|
||||
: DilutedNoise(g)
|
||||
{
|
||||
resize(nNoise);
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<typename DilutedNoise<FImpl>::FermionField> & DilutedNoise<FImpl>::
|
||||
getNoise(void)
|
||||
{
|
||||
return noise_;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
const std::vector<typename DilutedNoise<FImpl>::FermionField> & DilutedNoise<FImpl>::
|
||||
getNoise(void) const
|
||||
{
|
||||
return noise_;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
const typename DilutedNoise<FImpl>::FermionField &
|
||||
DilutedNoise<FImpl>::operator[](const unsigned int i) const
|
||||
{
|
||||
return noise_[i];
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
typename DilutedNoise<FImpl>::FermionField &
|
||||
DilutedNoise<FImpl>::operator[](const unsigned int i)
|
||||
{
|
||||
return noise_[i];
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
void DilutedNoise<FImpl>::resize(const unsigned int nNoise)
|
||||
{
|
||||
nNoise_ = nNoise;
|
||||
noise_.resize(nNoise, grid_);
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
unsigned int DilutedNoise<FImpl>::size(void) const
|
||||
{
|
||||
return noise_.size();
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
GridCartesian * DilutedNoise<FImpl>::getGrid(void) const
|
||||
{
|
||||
return grid_;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* TimeDilutedSpinColorDiagonalNoise template implementation *
|
||||
******************************************************************************/
|
||||
template <typename FImpl>
|
||||
TimeDilutedSpinColorDiagonalNoise<FImpl>::
|
||||
TimeDilutedSpinColorDiagonalNoise(GridCartesian *g)
|
||||
: DilutedNoise<FImpl>(g)
|
||||
{
|
||||
nt_ = this->getGrid()->GlobalDimensions().size();
|
||||
this->resize(nt_*Ns*FImpl::Dimension);
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
void TimeDilutedSpinColorDiagonalNoise<FImpl>::generateNoise(GridParallelRNG &rng)
|
||||
{
|
||||
typedef decltype(peekColour((*this)[0], 0)) SpinField;
|
||||
|
||||
auto &noise = *this;
|
||||
auto g = this->getGrid();
|
||||
auto nd = g->GlobalDimensions().size();
|
||||
auto nc = FImpl::Dimension;
|
||||
Complex shift(1., 1.);
|
||||
Lattice<iScalar<vInteger>> tLat(g);
|
||||
LatticeComplex eta(g), etaCut(g);
|
||||
SpinField etas(g);
|
||||
unsigned int i = 0;
|
||||
|
||||
LatticeCoordinate(tLat, nd - 1);
|
||||
bernoulli(rng, eta);
|
||||
eta = (2.*eta - shift)*(1./::sqrt(2.));
|
||||
for (unsigned int t = 0; t < nt_; ++t)
|
||||
{
|
||||
etaCut = where((tLat == t), eta, 0.*eta);
|
||||
for (unsigned int s = 0; s < Ns; ++s)
|
||||
{
|
||||
etas = Zero();
|
||||
pokeSpin(etas, etaCut, s);
|
||||
for (unsigned int c = 0; c < nc; ++c)
|
||||
{
|
||||
noise[i] = Zero();
|
||||
pokeColour(noise[i], etas, c);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* FullVolumeSpinColorDiagonalNoise template implementation *
|
||||
******************************************************************************/
|
||||
template <typename FImpl>
|
||||
FullVolumeSpinColorDiagonalNoise<FImpl>::
|
||||
FullVolumeSpinColorDiagonalNoise(GridCartesian *g, unsigned int nSrc)
|
||||
: DilutedNoise<FImpl>(g, nSrc*Ns*FImpl::Dimension), nSrc_(nSrc)
|
||||
{}
|
||||
|
||||
template <typename FImpl>
|
||||
void FullVolumeSpinColorDiagonalNoise<FImpl>::generateNoise(GridParallelRNG &rng)
|
||||
{
|
||||
typedef decltype(peekColour((*this)[0], 0)) SpinField;
|
||||
|
||||
auto &noise = *this;
|
||||
auto g = this->getGrid();
|
||||
auto nd = g->GlobalDimensions().size();
|
||||
auto nc = FImpl::Dimension;
|
||||
Complex shift(1., 1.);
|
||||
LatticeComplex eta(g);
|
||||
SpinField etas(g);
|
||||
unsigned int i = 0;
|
||||
|
||||
bernoulli(rng, eta);
|
||||
eta = (2.*eta - shift)*(1./::sqrt(2.));
|
||||
for (unsigned int n = 0; n < nSrc_; ++n)
|
||||
{
|
||||
for (unsigned int s = 0; s < Ns; ++s)
|
||||
{
|
||||
etas = Zero();
|
||||
pokeSpin(etas, eta, s);
|
||||
for (unsigned int c = 0; c < nc; ++c)
|
||||
{
|
||||
noise[i] = Zero();
|
||||
pokeColour(noise[i], etas, c);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_DilutedNoise_hpp_
|
442
Hadrons/DiskVector.hpp
Normal file
442
Hadrons/DiskVector.hpp
Normal file
@ -0,0 +1,442 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/DiskVector.hpp
|
||||
|
||||
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 */
|
||||
#ifndef Hadrons_DiskVector_hpp_
|
||||
#define Hadrons_DiskVector_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/A2AMatrix.hpp>
|
||||
#include <deque>
|
||||
#include <sys/stat.h>
|
||||
#include <ftw.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef DV_DEBUG
|
||||
#define DV_DEBUG_MSG(dv, stream) LOG(Debug) << "diskvector " << (dv) << ": " << stream << std::endl
|
||||
#else
|
||||
#define DV_DEBUG_MSG(dv, stream)
|
||||
#endif
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Abstract base class *
|
||||
******************************************************************************/
|
||||
template <typename T>
|
||||
class DiskVectorBase
|
||||
{
|
||||
public:
|
||||
typedef T ObjectType;
|
||||
|
||||
// helper for read/write vector access
|
||||
class RwAccessHelper
|
||||
{
|
||||
public:
|
||||
RwAccessHelper(DiskVectorBase<T> &master, const unsigned int i)
|
||||
: master_(master), cmaster_(master), i_(i) {}
|
||||
|
||||
// operator=: somebody is trying to store a vector element
|
||||
// write to cache and tag as modified
|
||||
T &operator=(const T &obj) const
|
||||
{
|
||||
auto &cache = *master_.cachePtr_;
|
||||
auto &modified = *master_.modifiedPtr_;
|
||||
auto &index = *master_.indexPtr_;
|
||||
|
||||
DV_DEBUG_MSG(&master_, "writing to " << i_);
|
||||
master_.cacheInsert(i_, obj);
|
||||
modified[index.at(i_)] = true;
|
||||
|
||||
return cache[index.at(i_)];
|
||||
}
|
||||
|
||||
// implicit cast to const object reference and redirection
|
||||
// to the const operator[] for read-only operations
|
||||
operator const T&() const
|
||||
{
|
||||
return cmaster_[i_];
|
||||
}
|
||||
private:
|
||||
DiskVectorBase<T> &master_;
|
||||
const DiskVectorBase<T> &cmaster_;
|
||||
const unsigned int i_;
|
||||
};
|
||||
public:
|
||||
DiskVectorBase(const std::string dirname, const unsigned int size = 0,
|
||||
const unsigned int cacheSize = 1, const bool clean = true);
|
||||
DiskVectorBase(DiskVectorBase<T> &&v) = default;
|
||||
virtual ~DiskVectorBase(void);
|
||||
const T & operator[](const unsigned int i) const;
|
||||
RwAccessHelper operator[](const unsigned int i);
|
||||
double hitRatio(void) const;
|
||||
void resetStat(void);
|
||||
private:
|
||||
virtual void load(T &obj, const std::string filename) const = 0;
|
||||
virtual void save(const std::string filename, const T &obj) const = 0;
|
||||
virtual std::string filename(const unsigned int i) const;
|
||||
void evict(void) const;
|
||||
void fetch(const unsigned int i) const;
|
||||
void cacheInsert(const unsigned int i, const T &obj) const;
|
||||
void clean(void);
|
||||
private:
|
||||
std::string dirname_;
|
||||
unsigned int size_, cacheSize_;
|
||||
double access_{0.}, hit_{0.};
|
||||
bool clean_;
|
||||
// using pointers to allow modifications when class is const
|
||||
// semantic: const means data unmodified, but cache modification allowed
|
||||
std::unique_ptr<std::vector<T>> cachePtr_;
|
||||
std::unique_ptr<std::vector<bool>> modifiedPtr_;
|
||||
std::unique_ptr<std::map<unsigned int, unsigned int>> indexPtr_;
|
||||
std::unique_ptr<std::stack<unsigned int>> freePtr_;
|
||||
std::unique_ptr<std::deque<unsigned int>> loadsPtr_;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* Specialisation for serialisable classes *
|
||||
******************************************************************************/
|
||||
template <typename T, typename Reader, typename Writer>
|
||||
class SerializableDiskVector: public DiskVectorBase<T>
|
||||
{
|
||||
public:
|
||||
using DiskVectorBase<T>::DiskVectorBase;
|
||||
private:
|
||||
virtual void load(T &obj, const std::string filename) const
|
||||
{
|
||||
Reader reader(filename);
|
||||
|
||||
read(reader, basename(filename), obj);
|
||||
}
|
||||
|
||||
virtual void save(const std::string filename, const T &obj) const
|
||||
{
|
||||
Writer writer(filename);
|
||||
|
||||
write(writer, basename(filename), obj);
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* Specialisation for Eigen matrices *
|
||||
******************************************************************************/
|
||||
template <typename T>
|
||||
using EigenDiskVectorMat = A2AMatrix<T>;
|
||||
|
||||
template <typename T>
|
||||
class EigenDiskVector: public DiskVectorBase<EigenDiskVectorMat<T>>
|
||||
{
|
||||
public:
|
||||
using DiskVectorBase<EigenDiskVectorMat<T>>::DiskVectorBase;
|
||||
typedef EigenDiskVectorMat<T> Matrix;
|
||||
public:
|
||||
T operator()(const unsigned int i, const Eigen::Index j,
|
||||
const Eigen::Index k) const
|
||||
{
|
||||
return (*this)[i](j, k);
|
||||
}
|
||||
private:
|
||||
virtual void load(EigenDiskVectorMat<T> &obj, const std::string filename) const
|
||||
{
|
||||
std::ifstream f(filename, std::ios::binary);
|
||||
uint32_t crc, check;
|
||||
Eigen::Index nRow, nCol;
|
||||
size_t matSize;
|
||||
double tRead, tHash;
|
||||
|
||||
f.read(reinterpret_cast<char *>(&crc), sizeof(crc));
|
||||
f.read(reinterpret_cast<char *>(&nRow), sizeof(nRow));
|
||||
f.read(reinterpret_cast<char *>(&nCol), sizeof(nCol));
|
||||
obj.resize(nRow, nCol);
|
||||
matSize = nRow*nCol*sizeof(T);
|
||||
tRead = -usecond();
|
||||
f.read(reinterpret_cast<char *>(obj.data()), matSize);
|
||||
tRead += usecond();
|
||||
tHash = -usecond();
|
||||
#ifdef USE_IPP
|
||||
check = GridChecksum::crc32c(obj.data(), matSize);
|
||||
#else
|
||||
check = GridChecksum::crc32(obj.data(), matSize);
|
||||
#endif
|
||||
tHash += usecond();
|
||||
DV_DEBUG_MSG(this, "Eigen read " << tRead/1.0e6 << " sec " << matSize/tRead*1.0e6/1024/1024 << " MB/s");
|
||||
DV_DEBUG_MSG(this, "Eigen crc32 " << std::hex << check << std::dec
|
||||
<< " " << tHash/1.0e6 << " sec " << matSize/tHash*1.0e6/1024/1024 << " MB/s");
|
||||
if (crc != check)
|
||||
{
|
||||
HADRONS_ERROR(Io, "checksum failed")
|
||||
}
|
||||
}
|
||||
|
||||
virtual void save(const std::string filename, const EigenDiskVectorMat<T> &obj) const
|
||||
{
|
||||
std::ofstream f(filename, std::ios::binary);
|
||||
uint32_t crc;
|
||||
Eigen::Index nRow, nCol;
|
||||
size_t matSize;
|
||||
double tWrite, tHash;
|
||||
|
||||
nRow = obj.rows();
|
||||
nCol = obj.cols();
|
||||
matSize = nRow*nCol*sizeof(T);
|
||||
tHash = -usecond();
|
||||
#ifdef USE_IPP
|
||||
crc = GridChecksum::crc32c(obj.data(), matSize);
|
||||
#else
|
||||
crc = GridChecksum::crc32(obj.data(), matSize);
|
||||
#endif
|
||||
tHash += usecond();
|
||||
f.write(reinterpret_cast<char *>(&crc), sizeof(crc));
|
||||
f.write(reinterpret_cast<char *>(&nRow), sizeof(nRow));
|
||||
f.write(reinterpret_cast<char *>(&nCol), sizeof(nCol));
|
||||
tWrite = -usecond();
|
||||
f.write(reinterpret_cast<const char *>(obj.data()), matSize);
|
||||
tWrite += usecond();
|
||||
DV_DEBUG_MSG(this, "Eigen write " << tWrite/1.0e6 << " sec " << matSize/tWrite*1.0e6/1024/1024 << " MB/s");
|
||||
DV_DEBUG_MSG(this, "Eigen crc32 " << std::hex << crc << std::dec
|
||||
<< " " << tHash/1.0e6 << " sec " << matSize/tHash*1.0e6/1024/1024 << " MB/s");
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* DiskVectorBase implementation *
|
||||
******************************************************************************/
|
||||
template <typename T>
|
||||
DiskVectorBase<T>::DiskVectorBase(const std::string dirname,
|
||||
const unsigned int size,
|
||||
const unsigned int cacheSize,
|
||||
const bool clean)
|
||||
: dirname_(dirname), size_(size), cacheSize_(cacheSize), clean_(clean)
|
||||
, cachePtr_(new std::vector<T>(size))
|
||||
, modifiedPtr_(new std::vector<bool>(size, false))
|
||||
, indexPtr_(new std::map<unsigned int, unsigned int>())
|
||||
, freePtr_(new std::stack<unsigned int>)
|
||||
, loadsPtr_(new std::deque<unsigned int>())
|
||||
{
|
||||
struct stat s;
|
||||
|
||||
if(stat(dirname.c_str(), &s) == 0)
|
||||
{
|
||||
HADRONS_ERROR(Io, "directory '" + dirname + "' already exists")
|
||||
}
|
||||
mkdir(dirname);
|
||||
for (unsigned int i = 0; i < cacheSize_; ++i)
|
||||
{
|
||||
freePtr_->push(i);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
DiskVectorBase<T>::~DiskVectorBase(void)
|
||||
{
|
||||
if (clean_)
|
||||
{
|
||||
clean();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T & DiskVectorBase<T>::operator[](const unsigned int i) const
|
||||
{
|
||||
auto &cache = *cachePtr_;
|
||||
auto &index = *indexPtr_;
|
||||
auto &freeInd = *freePtr_;
|
||||
auto &loads = *loadsPtr_;
|
||||
|
||||
DV_DEBUG_MSG(this, "accessing " << i << " (RO)");
|
||||
|
||||
if (i >= size_)
|
||||
{
|
||||
HADRONS_ERROR(Size, "index out of range");
|
||||
}
|
||||
const_cast<double &>(access_)++;
|
||||
if (index.find(i) == index.end())
|
||||
{
|
||||
// cache miss
|
||||
DV_DEBUG_MSG(this, "cache miss");
|
||||
fetch(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
DV_DEBUG_MSG(this, "cache hit");
|
||||
|
||||
auto pos = std::find(loads.begin(), loads.end(), i);
|
||||
|
||||
const_cast<double &>(hit_)++;
|
||||
loads.erase(pos);
|
||||
loads.push_back(i);
|
||||
}
|
||||
|
||||
#ifdef DV_DEBUG
|
||||
std::string msg;
|
||||
|
||||
for (auto &p: loads)
|
||||
{
|
||||
msg += std::to_string(p) + " ";
|
||||
}
|
||||
DV_DEBUG_MSG(this, "in cache: " << msg);
|
||||
#endif
|
||||
|
||||
return cache[index.at(i)];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename DiskVectorBase<T>::RwAccessHelper DiskVectorBase<T>::operator[](const unsigned int i)
|
||||
{
|
||||
DV_DEBUG_MSG(this, "accessing " << i << " (RW)");
|
||||
|
||||
if (i >= size_)
|
||||
{
|
||||
HADRONS_ERROR(Size, "index out of range");
|
||||
}
|
||||
|
||||
return RwAccessHelper(*this, i);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
double DiskVectorBase<T>::hitRatio(void) const
|
||||
{
|
||||
return hit_/access_;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void DiskVectorBase<T>::resetStat(void)
|
||||
{
|
||||
access_ = 0.;
|
||||
hit_ = 0.;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string DiskVectorBase<T>::filename(const unsigned int i) const
|
||||
{
|
||||
return dirname_ + "/elem_" + std::to_string(i);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void DiskVectorBase<T>::evict(void) const
|
||||
{
|
||||
auto &cache = *cachePtr_;
|
||||
auto &modified = *modifiedPtr_;
|
||||
auto &index = *indexPtr_;
|
||||
auto &freeInd = *freePtr_;
|
||||
auto &loads = *loadsPtr_;
|
||||
|
||||
if (index.size() >= cacheSize_)
|
||||
{
|
||||
unsigned int i = loads.front();
|
||||
|
||||
DV_DEBUG_MSG(this, "evicting " << i);
|
||||
if (modified[index.at(i)])
|
||||
{
|
||||
DV_DEBUG_MSG(this, "element " << i << " modified, saving to disk");
|
||||
save(filename(i), cache[index.at(i)]);
|
||||
}
|
||||
freeInd.push(index.at(i));
|
||||
index.erase(i);
|
||||
loads.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void DiskVectorBase<T>::fetch(const unsigned int i) const
|
||||
{
|
||||
auto &cache = *cachePtr_;
|
||||
auto &modified = *modifiedPtr_;
|
||||
auto &index = *indexPtr_;
|
||||
auto &freeInd = *freePtr_;
|
||||
auto &loads = *loadsPtr_;
|
||||
|
||||
struct stat s;
|
||||
|
||||
DV_DEBUG_MSG(this, "loading " << i << " from disk");
|
||||
|
||||
evict();
|
||||
|
||||
if(stat(filename(i).c_str(), &s) != 0)
|
||||
{
|
||||
HADRONS_ERROR(Io, "disk vector element " + std::to_string(i) + " uninitialised");
|
||||
}
|
||||
index[i] = freeInd.top();
|
||||
freeInd.pop();
|
||||
load(cache[index.at(i)], filename(i));
|
||||
loads.push_back(i);
|
||||
modified[index.at(i)] = false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void DiskVectorBase<T>::cacheInsert(const unsigned int i, const T &obj) const
|
||||
{
|
||||
auto &cache = *cachePtr_;
|
||||
auto &modified = *modifiedPtr_;
|
||||
auto &index = *indexPtr_;
|
||||
auto &freeInd = *freePtr_;
|
||||
auto &loads = *loadsPtr_;
|
||||
|
||||
evict();
|
||||
index[i] = freeInd.top();
|
||||
freeInd.pop();
|
||||
cache[index.at(i)] = obj;
|
||||
loads.push_back(i);
|
||||
modified[index.at(i)] = false;
|
||||
|
||||
#ifdef DV_DEBUG
|
||||
std::string msg;
|
||||
|
||||
for (auto &p: loads)
|
||||
{
|
||||
msg += std::to_string(p) + " ";
|
||||
}
|
||||
DV_DEBUG_MSG(this, "in cache: " << msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DV_DEBUG
|
||||
#undef DV_DEBUG_MSG
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
void DiskVectorBase<T>::clean(void)
|
||||
{
|
||||
auto unlink = [](const char *fpath, const struct stat *sb,
|
||||
int typeflag, struct FTW *ftwbuf)
|
||||
{
|
||||
int rv = remove(fpath);
|
||||
|
||||
if (rv)
|
||||
{
|
||||
HADRONS_ERROR(Io, "cannot remove '" + std::string(fpath) + "': "
|
||||
+ std::string(std::strerror(errno)));
|
||||
}
|
||||
|
||||
return rv;
|
||||
};
|
||||
|
||||
nftw(dirname_.c_str(), unlink, 64, FTW_DEPTH | FTW_PHYS);
|
||||
}
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_DiskVector_hpp_
|
414
Hadrons/EigenPack.hpp
Normal file
414
Hadrons/EigenPack.hpp
Normal file
@ -0,0 +1,414 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/EigenPack.hpp
|
||||
|
||||
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 */
|
||||
#ifndef Hadrons_EigenPack_hpp_
|
||||
#define Hadrons_EigenPack_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Grid/algorithms/iterative/Deflation.h>
|
||||
#include <Grid/algorithms/iterative/LocalCoherenceLanczos.h>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
// Lanczos type
|
||||
#ifndef HADRONS_DEFAULT_LANCZOS_NBASIS
|
||||
#define HADRONS_DEFAULT_LANCZOS_NBASIS 60
|
||||
#endif
|
||||
|
||||
#define HADRONS_DUMP_EP_METADATA(record) \
|
||||
LOG(Message) << "Eigenpack metadata:" << std::endl;\
|
||||
LOG(Message) << "* operator" << std::endl;\
|
||||
LOG(Message) << (record).operatorXml << std::endl;\
|
||||
LOG(Message) << "* solver" << std::endl;\
|
||||
LOG(Message) << (record).solverXml << std::endl;
|
||||
|
||||
struct PackRecord
|
||||
{
|
||||
std::string operatorXml, solverXml;
|
||||
};
|
||||
|
||||
struct VecRecord: Serializable
|
||||
{
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(VecRecord,
|
||||
unsigned int, index,
|
||||
double, eval);
|
||||
VecRecord(void): index(0), eval(0.) {}
|
||||
};
|
||||
|
||||
namespace EigenPackIo
|
||||
{
|
||||
inline void readHeader(PackRecord &record, ScidacReader &binReader)
|
||||
{
|
||||
std::string recordXml;
|
||||
|
||||
binReader.readLimeObject(recordXml, SCIDAC_FILE_XML);
|
||||
XmlReader xmlReader(recordXml, true, "eigenPackPar");
|
||||
xmlReader.push();
|
||||
xmlReader.readCurrentSubtree(record.operatorXml);
|
||||
xmlReader.nextElement();
|
||||
xmlReader.readCurrentSubtree(record.solverXml);
|
||||
}
|
||||
|
||||
template <typename T, typename TIo = T>
|
||||
void readElement(T &evec, RealD &eval, const unsigned int index,
|
||||
ScidacReader &binReader, TIo *ioBuf = nullptr)
|
||||
{
|
||||
VecRecord vecRecord;
|
||||
|
||||
LOG(Message) << "Reading eigenvector " << index << std::endl;
|
||||
if (ioBuf == nullptr)
|
||||
{
|
||||
binReader.readScidacFieldRecord(evec, vecRecord);
|
||||
}
|
||||
else
|
||||
{
|
||||
binReader.readScidacFieldRecord(*ioBuf, vecRecord);
|
||||
precisionChange(evec, *ioBuf);
|
||||
}
|
||||
if (vecRecord.index != index)
|
||||
{
|
||||
HADRONS_ERROR(Io, "Eigenvector " + std::to_string(index) + " has a"
|
||||
+ " wrong index (expected " + std::to_string(vecRecord.index)
|
||||
+ ")");
|
||||
}
|
||||
eval = vecRecord.eval;
|
||||
}
|
||||
|
||||
template <typename T, typename TIo = T>
|
||||
static void readPack(std::vector<T> &evec, std::vector<RealD> &eval,
|
||||
PackRecord &record, const std::string filename,
|
||||
const unsigned int size, bool multiFile,
|
||||
GridBase *gridIo = nullptr)
|
||||
{
|
||||
std::unique_ptr<TIo> ioBuf{nullptr};
|
||||
ScidacReader binReader;
|
||||
|
||||
if (typeHash<T>() != typeHash<TIo>())
|
||||
{
|
||||
if (gridIo == nullptr)
|
||||
{
|
||||
HADRONS_ERROR(Definition,
|
||||
"I/O type different from vector type but null I/O grid passed");
|
||||
}
|
||||
ioBuf.reset(new TIo(gridIo));
|
||||
}
|
||||
if (multiFile)
|
||||
{
|
||||
std::string fullFilename;
|
||||
|
||||
for(int k = 0; k < size; ++k)
|
||||
{
|
||||
fullFilename = filename + "/v" + std::to_string(k) + ".bin";
|
||||
binReader.open(fullFilename);
|
||||
readHeader(record, binReader);
|
||||
readElement(evec[k], eval[k], k, binReader, ioBuf.get());
|
||||
binReader.close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
binReader.open(filename);
|
||||
readHeader(record, binReader);
|
||||
for(int k = 0; k < size; ++k)
|
||||
{
|
||||
readElement(evec[k], eval[k], k, binReader, ioBuf.get());
|
||||
}
|
||||
binReader.close();
|
||||
}
|
||||
}
|
||||
|
||||
inline void writeHeader(ScidacWriter &binWriter, PackRecord &record)
|
||||
{
|
||||
XmlWriter xmlWriter("", "eigenPackPar");
|
||||
|
||||
xmlWriter.pushXmlString(record.operatorXml);
|
||||
xmlWriter.pushXmlString(record.solverXml);
|
||||
binWriter.writeLimeObject(1, 1, xmlWriter, "parameters", SCIDAC_FILE_XML);
|
||||
}
|
||||
|
||||
template <typename T, typename TIo = T>
|
||||
void writeElement(ScidacWriter &binWriter, T &evec, RealD &eval,
|
||||
const unsigned int index, TIo *ioBuf,
|
||||
T *testBuf = nullptr)
|
||||
{
|
||||
VecRecord vecRecord;
|
||||
|
||||
LOG(Message) << "Writing eigenvector " << index << std::endl;
|
||||
vecRecord.eval = eval;
|
||||
vecRecord.index = index;
|
||||
if ((ioBuf == nullptr) || (testBuf == nullptr))
|
||||
{
|
||||
binWriter.writeScidacFieldRecord(evec, vecRecord, DEFAULT_ASCII_PREC);
|
||||
}
|
||||
else
|
||||
{
|
||||
precisionChange(*ioBuf, evec);
|
||||
precisionChange(*testBuf, *ioBuf);
|
||||
*testBuf -= evec;
|
||||
LOG(Message) << "Precision diff norm^2 " << norm2(*testBuf) << std::endl;
|
||||
binWriter.writeScidacFieldRecord(*ioBuf, vecRecord, DEFAULT_ASCII_PREC);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename TIo = T>
|
||||
static void writePack(const std::string filename, std::vector<T> &evec,
|
||||
std::vector<RealD> &eval, PackRecord &record,
|
||||
const unsigned int size, bool multiFile,
|
||||
GridBase *gridIo = nullptr)
|
||||
{
|
||||
GridBase *grid = evec[0].Grid();
|
||||
std::unique_ptr<TIo> ioBuf{nullptr};
|
||||
std::unique_ptr<T> testBuf{nullptr};
|
||||
ScidacWriter binWriter(grid->IsBoss());
|
||||
|
||||
if (typeHash<T>() != typeHash<TIo>())
|
||||
{
|
||||
if (gridIo == nullptr)
|
||||
{
|
||||
HADRONS_ERROR(Definition,
|
||||
"I/O type different from vector type but null I/O grid passed");
|
||||
}
|
||||
ioBuf.reset(new TIo(gridIo));
|
||||
testBuf.reset(new T(grid));
|
||||
}
|
||||
if (multiFile)
|
||||
{
|
||||
std::string fullFilename;
|
||||
|
||||
for(int k = 0; k < size; ++k)
|
||||
{
|
||||
fullFilename = filename + "/v" + std::to_string(k) + ".bin";
|
||||
|
||||
makeFileDir(fullFilename, grid);
|
||||
binWriter.open(fullFilename);
|
||||
writeHeader(binWriter, record);
|
||||
writeElement(binWriter, evec[k], eval[k], k, ioBuf.get(), testBuf.get());
|
||||
binWriter.close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
makeFileDir(filename, grid);
|
||||
binWriter.open(filename);
|
||||
writeHeader(binWriter, record);
|
||||
for(int k = 0; k < size; ++k)
|
||||
{
|
||||
writeElement(binWriter, evec[k], eval[k], k, ioBuf.get(), testBuf.get());
|
||||
}
|
||||
binWriter.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
class BaseEigenPack
|
||||
{
|
||||
public:
|
||||
typedef F Field;
|
||||
public:
|
||||
std::vector<RealD> eval;
|
||||
std::vector<F> evec;
|
||||
PackRecord record;
|
||||
public:
|
||||
BaseEigenPack(void) = default;
|
||||
BaseEigenPack(const size_t size, GridBase *grid)
|
||||
{
|
||||
resize(size, grid);
|
||||
}
|
||||
virtual ~BaseEigenPack(void) = default;
|
||||
void resize(const size_t size, GridBase *grid)
|
||||
{
|
||||
eval.resize(size);
|
||||
evec.resize(size, grid);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename F, typename FIo = F>
|
||||
class EigenPack: public BaseEigenPack<F>
|
||||
{
|
||||
public:
|
||||
typedef F Field;
|
||||
typedef FIo FieldIo;
|
||||
public:
|
||||
EigenPack(void) = default;
|
||||
virtual ~EigenPack(void) = default;
|
||||
|
||||
EigenPack(const size_t size, GridBase *grid, GridBase *gridIo = nullptr)
|
||||
: BaseEigenPack<F>(size, grid)
|
||||
{
|
||||
if (typeHash<F>() != typeHash<FIo>())
|
||||
{
|
||||
if (gridIo == nullptr)
|
||||
{
|
||||
HADRONS_ERROR(Definition,
|
||||
"I/O type different from vector type but null I/O grid passed");
|
||||
}
|
||||
}
|
||||
gridIo_ = gridIo;
|
||||
}
|
||||
|
||||
virtual void read(const std::string fileStem, const bool multiFile, const int traj = -1)
|
||||
{
|
||||
EigenPackIo::readPack<F, FIo>(this->evec, this->eval, this->record,
|
||||
evecFilename(fileStem, traj, multiFile),
|
||||
this->evec.size(), multiFile, gridIo_);
|
||||
HADRONS_DUMP_EP_METADATA(this->record);
|
||||
}
|
||||
|
||||
virtual void write(const std::string fileStem, const bool multiFile, const int traj = -1)
|
||||
{
|
||||
EigenPackIo::writePack<F, FIo>(evecFilename(fileStem, traj, multiFile),
|
||||
this->evec, this->eval, this->record,
|
||||
this->evec.size(), multiFile, gridIo_);
|
||||
}
|
||||
protected:
|
||||
std::string evecFilename(const std::string stem, const int traj, const bool multiFile)
|
||||
{
|
||||
std::string t = (traj < 0) ? "" : ("." + std::to_string(traj));
|
||||
|
||||
if (multiFile)
|
||||
{
|
||||
return stem + t;
|
||||
}
|
||||
else
|
||||
{
|
||||
return stem + t + ".bin";
|
||||
}
|
||||
}
|
||||
protected:
|
||||
GridBase *gridIo_;
|
||||
};
|
||||
|
||||
template <typename FineF, typename CoarseF,
|
||||
typename FineFIo = FineF, typename CoarseFIo = CoarseF>
|
||||
class CoarseEigenPack: public EigenPack<FineF, FineFIo>
|
||||
{
|
||||
public:
|
||||
typedef CoarseF CoarseField;
|
||||
std::vector<CoarseF> evecCoarse;
|
||||
std::vector<RealD> evalCoarse;
|
||||
public:
|
||||
CoarseEigenPack(void) = default;
|
||||
virtual ~CoarseEigenPack(void) = default;
|
||||
|
||||
CoarseEigenPack(const size_t sizeFine, const size_t sizeCoarse,
|
||||
GridBase *gridFine, GridBase *gridCoarse,
|
||||
GridBase *gridFineIo = nullptr,
|
||||
GridBase *gridCoarseIo = nullptr)
|
||||
{
|
||||
if (typeHash<FineF>() != typeHash<FineFIo>())
|
||||
{
|
||||
if (gridFineIo == nullptr)
|
||||
{
|
||||
HADRONS_ERROR(Definition,
|
||||
"Fine I/O type different from vector type but null fine I/O grid passed");
|
||||
}
|
||||
}
|
||||
if (typeHash<CoarseF>() != typeHash<CoarseFIo>())
|
||||
{
|
||||
if (gridCoarseIo == nullptr)
|
||||
{
|
||||
HADRONS_ERROR(Definition,
|
||||
"Coarse I/O type different from vector type but null coarse I/O grid passed");
|
||||
}
|
||||
}
|
||||
this->gridIo_ = gridFineIo;
|
||||
gridCoarseIo_ = gridCoarseIo;
|
||||
resize(sizeFine, sizeCoarse, gridFine, gridCoarse);
|
||||
}
|
||||
|
||||
void resize(const size_t sizeFine, const size_t sizeCoarse,
|
||||
GridBase *gridFine, GridBase *gridCoarse)
|
||||
{
|
||||
EigenPack<FineF, FineFIo>::resize(sizeFine, gridFine);
|
||||
evalCoarse.resize(sizeCoarse);
|
||||
evecCoarse.resize(sizeCoarse, gridCoarse);
|
||||
}
|
||||
|
||||
void readFine(const std::string fileStem, const bool multiFile, const int traj = -1)
|
||||
{
|
||||
EigenPack<FineF, FineFIo>::read(fileStem + "_fine", multiFile, traj);
|
||||
}
|
||||
|
||||
void readCoarse(const std::string fileStem, const bool multiFile, const int traj = -1)
|
||||
{
|
||||
PackRecord dummy;
|
||||
|
||||
EigenPackIo::readPack<CoarseF, CoarseFIo>(evecCoarse, evalCoarse, dummy,
|
||||
this->evecFilename(fileStem + "_coarse", traj, multiFile),
|
||||
evecCoarse.size(), multiFile, gridCoarseIo_);
|
||||
}
|
||||
|
||||
virtual void read(const std::string fileStem, const bool multiFile, const int traj = -1)
|
||||
{
|
||||
readFine(fileStem, multiFile, traj);
|
||||
readCoarse(fileStem, multiFile, traj);
|
||||
}
|
||||
|
||||
void writeFine(const std::string fileStem, const bool multiFile, const int traj = -1)
|
||||
{
|
||||
EigenPack<FineF, FineFIo>::write(fileStem + "_fine", multiFile, traj);
|
||||
}
|
||||
|
||||
void writeCoarse(const std::string fileStem, const bool multiFile, const int traj = -1)
|
||||
{
|
||||
EigenPackIo::writePack<CoarseF, CoarseFIo>(this->evecFilename(fileStem + "_coarse", traj, multiFile),
|
||||
evecCoarse, evalCoarse, this->record,
|
||||
evecCoarse.size(), multiFile, gridCoarseIo_);
|
||||
}
|
||||
|
||||
virtual void write(const std::string fileStem, const bool multiFile, const int traj = -1)
|
||||
{
|
||||
writeFine(fileStem, multiFile, traj);
|
||||
writeCoarse(fileStem, multiFile, traj);
|
||||
}
|
||||
private:
|
||||
GridBase *gridCoarseIo_;
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
using BaseFermionEigenPack = BaseEigenPack<typename FImpl::FermionField>;
|
||||
|
||||
template <typename FImpl, typename FImplIo = FImpl>
|
||||
using FermionEigenPack = EigenPack<typename FImpl::FermionField, typename FImplIo::FermionField>;
|
||||
|
||||
template <typename FImpl, int nBasis, typename FImplIo = FImpl>
|
||||
using CoarseFermionEigenPack = CoarseEigenPack<
|
||||
typename FImpl::FermionField,
|
||||
typename LocalCoherenceLanczos<typename FImpl::SiteSpinor,
|
||||
typename FImpl::SiteComplex,
|
||||
nBasis>::CoarseField,
|
||||
typename FImplIo::FermionField,
|
||||
typename LocalCoherenceLanczos<typename FImplIo::SiteSpinor,
|
||||
typename FImplIo::SiteComplex,
|
||||
nBasis>::CoarseField>;
|
||||
|
||||
#undef HADRONS_DUMP_EP_METADATA
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_EigenPack_hpp_
|
334
Hadrons/Environment.cc
Normal file
334
Hadrons/Environment.cc
Normal file
@ -0,0 +1,334 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Environment.cc
|
||||
|
||||
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 */
|
||||
|
||||
#include <Hadrons/Environment.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
|
||||
using namespace Hadrons;
|
||||
|
||||
#define ERROR_NO_ADDRESS(address)\
|
||||
HADRONS_ERROR_REF(ObjectDefinition, "no object with address " + std::to_string(address), address);
|
||||
|
||||
/******************************************************************************
|
||||
* Environment implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
Environment::Environment(void)
|
||||
{
|
||||
dim_ = GridDefaultLatt().toVector();
|
||||
nd_ = dim_.size();
|
||||
createGrid<vComplex>(1);
|
||||
vol_ = 1.;
|
||||
for (auto d: dim_)
|
||||
{
|
||||
vol_ *= d;
|
||||
}
|
||||
rng4d_.reset(new GridParallelRNG(getGrid()));
|
||||
}
|
||||
|
||||
// grids ///////////////////////////////////////////////////////////////////////
|
||||
unsigned int Environment::getNd(void) const
|
||||
{
|
||||
return nd_;
|
||||
}
|
||||
|
||||
std::vector<int> Environment::getDim(void) const
|
||||
{
|
||||
return dim_;
|
||||
}
|
||||
|
||||
int Environment::getDim(const unsigned int mu) const
|
||||
{
|
||||
return dim_[mu];
|
||||
}
|
||||
|
||||
double Environment::getVolume(void) const
|
||||
{
|
||||
return vol_;
|
||||
}
|
||||
|
||||
// random number generator /////////////////////////////////////////////////////
|
||||
GridParallelRNG * Environment::get4dRng(void) const
|
||||
{
|
||||
return rng4d_.get();
|
||||
}
|
||||
|
||||
// general memory management ///////////////////////////////////////////////////
|
||||
void Environment::addObject(const std::string name, const int moduleAddress)
|
||||
{
|
||||
if (!hasObject(name))
|
||||
{
|
||||
ObjInfo info;
|
||||
|
||||
info.name = name;
|
||||
info.module = moduleAddress;
|
||||
info.data = nullptr;
|
||||
object_.push_back(std::move(info));
|
||||
objectAddress_[name] = static_cast<unsigned int>(object_.size() - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
HADRONS_ERROR_REF(ObjectDefinition, "object '" + name + "' already exists",
|
||||
getObjectAddress(name));
|
||||
}
|
||||
}
|
||||
|
||||
void Environment::setObjectModule(const unsigned int objAddress,
|
||||
const int modAddress)
|
||||
{
|
||||
object_[objAddress].module = modAddress;
|
||||
}
|
||||
|
||||
unsigned int Environment::getMaxAddress(void) const
|
||||
{
|
||||
return object_.size();
|
||||
}
|
||||
|
||||
unsigned int Environment::getObjectAddress(const std::string name) const
|
||||
{
|
||||
if (hasObject(name))
|
||||
{
|
||||
return objectAddress_.at(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
HADRONS_ERROR(Definition, "no object with name '" + name + "'");
|
||||
}
|
||||
}
|
||||
|
||||
std::string Environment::getObjectName(const unsigned int address) const
|
||||
{
|
||||
if (hasObject(address))
|
||||
{
|
||||
return object_[address].name;
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_NO_ADDRESS(address);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Environment::getObjectType(const unsigned int address) const
|
||||
{
|
||||
if (hasObject(address))
|
||||
{
|
||||
if (object_[address].type)
|
||||
{
|
||||
return typeName(object_[address].type);
|
||||
}
|
||||
else
|
||||
{
|
||||
return "<no type>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_NO_ADDRESS(address);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Environment::getObjectType(const std::string name) const
|
||||
{
|
||||
return getObjectType(getObjectAddress(name));
|
||||
}
|
||||
|
||||
Environment::Size Environment::getObjectSize(const unsigned int address) const
|
||||
{
|
||||
if (hasObject(address))
|
||||
{
|
||||
return object_[address].size;
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_NO_ADDRESS(address);
|
||||
}
|
||||
}
|
||||
|
||||
Environment::Size Environment::getObjectSize(const std::string name) const
|
||||
{
|
||||
return getObjectSize(getObjectAddress(name));
|
||||
}
|
||||
|
||||
Environment::Storage Environment::getObjectStorage(const unsigned int address) const
|
||||
{
|
||||
if (hasObject(address))
|
||||
{
|
||||
return object_[address].storage;
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_NO_ADDRESS(address);
|
||||
}
|
||||
}
|
||||
|
||||
Environment::Storage Environment::getObjectStorage(const std::string name) const
|
||||
{
|
||||
return getObjectStorage(getObjectAddress(name));
|
||||
}
|
||||
|
||||
int Environment::getObjectModule(const unsigned int address) const
|
||||
{
|
||||
if (hasObject(address))
|
||||
{
|
||||
return object_[address].module;
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_NO_ADDRESS(address);
|
||||
}
|
||||
}
|
||||
|
||||
int Environment::getObjectModule(const std::string name) const
|
||||
{
|
||||
return getObjectModule(getObjectAddress(name));
|
||||
}
|
||||
|
||||
unsigned int Environment::getObjectLs(const unsigned int address) const
|
||||
{
|
||||
if (hasCreatedObject(address))
|
||||
{
|
||||
return object_[address].Ls;
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_NO_ADDRESS(address);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int Environment::getObjectLs(const std::string name) const
|
||||
{
|
||||
return getObjectLs(getObjectAddress(name));
|
||||
}
|
||||
|
||||
bool Environment::hasObject(const unsigned int address) const
|
||||
{
|
||||
return (address < object_.size());
|
||||
}
|
||||
|
||||
bool Environment::hasObject(const std::string name) const
|
||||
{
|
||||
auto it = objectAddress_.find(name);
|
||||
|
||||
return ((it != objectAddress_.end()) and hasObject(it->second));
|
||||
}
|
||||
|
||||
bool Environment::hasCreatedObject(const unsigned int address) const
|
||||
{
|
||||
if (hasObject(address))
|
||||
{
|
||||
return (object_[address].data != nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Environment::hasCreatedObject(const std::string name) const
|
||||
{
|
||||
if (hasObject(name))
|
||||
{
|
||||
return hasCreatedObject(getObjectAddress(name));
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Environment::isObject5d(const unsigned int address) const
|
||||
{
|
||||
return (getObjectLs(address) > 1);
|
||||
}
|
||||
|
||||
bool Environment::isObject5d(const std::string name) const
|
||||
{
|
||||
return (getObjectLs(name) > 1);
|
||||
}
|
||||
|
||||
Environment::Size Environment::getTotalSize(void) const
|
||||
{
|
||||
Environment::Size size = 0;
|
||||
|
||||
for (auto &o: object_)
|
||||
{
|
||||
size += o.size;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
void Environment::freeObject(const unsigned int address)
|
||||
{
|
||||
if (hasCreatedObject(address))
|
||||
{
|
||||
LOG(Message) << "Destroying object '" << object_[address].name
|
||||
<< "'" << std::endl;
|
||||
}
|
||||
object_[address].size = 0;
|
||||
object_[address].type = nullptr;
|
||||
object_[address].data.reset(nullptr);
|
||||
}
|
||||
|
||||
void Environment::freeObject(const std::string name)
|
||||
{
|
||||
freeObject(getObjectAddress(name));
|
||||
}
|
||||
|
||||
void Environment::freeAll(void)
|
||||
{
|
||||
for (unsigned int i = 0; i < object_.size(); ++i)
|
||||
{
|
||||
freeObject(i);
|
||||
}
|
||||
}
|
||||
|
||||
void Environment::protectObjects(const bool protect)
|
||||
{
|
||||
protect_ = protect;
|
||||
}
|
||||
|
||||
bool Environment::objectsProtected(void) const
|
||||
{
|
||||
return protect_;
|
||||
}
|
||||
|
||||
// print environment content ///////////////////////////////////////////////////
|
||||
void Environment::printContent(void) const
|
||||
{
|
||||
LOG(Debug) << "Objects: " << std::endl;
|
||||
for (unsigned int i = 0; i < object_.size(); ++i)
|
||||
{
|
||||
LOG(Debug) << std::setw(4) << i << ": "
|
||||
<< getObjectName(i) << " ("
|
||||
<< sizeString(getObjectSize(i)) << ")" << std::endl;
|
||||
}
|
||||
}
|
585
Hadrons/Environment.hpp
Normal file
585
Hadrons/Environment.hpp
Normal file
@ -0,0 +1,585 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Environment.hpp
|
||||
|
||||
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 */
|
||||
|
||||
#ifndef Hadrons_Environment_hpp_
|
||||
#define Hadrons_Environment_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Global environment *
|
||||
******************************************************************************/
|
||||
class Object
|
||||
{
|
||||
public:
|
||||
Object(void) = default;
|
||||
virtual ~Object(void) = default;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class Holder: public Object
|
||||
{
|
||||
public:
|
||||
Holder(void) = default;
|
||||
Holder(T *pt);
|
||||
virtual ~Holder(void) = default;
|
||||
T & get(void) const;
|
||||
T * getPt(void) const;
|
||||
void reset(T *pt);
|
||||
private:
|
||||
std::unique_ptr<T> objPt_{nullptr};
|
||||
};
|
||||
|
||||
#define DEFINE_ENV_ALIAS \
|
||||
inline Environment & env(void) const\
|
||||
{\
|
||||
return Environment::getInstance();\
|
||||
}
|
||||
|
||||
#define DEFINE_ENV_LAMBDA \
|
||||
auto env = [](void)->Environment &{return Environment::getInstance();}
|
||||
|
||||
class Environment
|
||||
{
|
||||
SINGLETON(Environment);
|
||||
public:
|
||||
typedef SITE_SIZE_TYPE Size;
|
||||
typedef std::unique_ptr<GridCartesian> GridPt;
|
||||
typedef std::unique_ptr<GridRedBlackCartesian> GridRbPt;
|
||||
typedef std::unique_ptr<GridParallelRNG> RngPt;
|
||||
enum class Storage {object, cache, temporary};
|
||||
private:
|
||||
struct ObjInfo
|
||||
{
|
||||
Size size{0};
|
||||
Storage storage{Storage::object};
|
||||
unsigned int Ls{0};
|
||||
const std::type_info *type{nullptr}, *derivedType{nullptr};
|
||||
std::string name;
|
||||
int module{-1};
|
||||
std::unique_ptr<Object> data{nullptr};
|
||||
};
|
||||
typedef std::pair<size_t, unsigned int> FineGridKey;
|
||||
typedef std::pair<size_t, std::vector<int>> CoarseGridKey;
|
||||
public:
|
||||
// grids
|
||||
template <typename VType = vComplex>
|
||||
void createGrid(const unsigned int Ls);
|
||||
template <typename VType = vComplex>
|
||||
void createCoarseGrid(const std::vector<int> &blockSize,
|
||||
const unsigned int Ls);
|
||||
template <typename VType = vComplex>
|
||||
GridCartesian * getGrid(void);
|
||||
template <typename VType = vComplex>
|
||||
GridRedBlackCartesian * getRbGrid(void);
|
||||
template <typename VType = vComplex>
|
||||
GridCartesian * getCoarseGrid(const std::vector<int> &blockSize);
|
||||
template <typename VType = vComplex>
|
||||
GridCartesian * getGrid(const unsigned int Ls);
|
||||
template <typename VType = vComplex>
|
||||
GridRedBlackCartesian * getRbGrid(const unsigned int Ls);
|
||||
template <typename VType = vComplex>
|
||||
GridCartesian * getCoarseGrid(const std::vector<int> &blockSize,
|
||||
const unsigned int Ls);
|
||||
std::vector<int> getDim(void) const;
|
||||
int getDim(const unsigned int mu) const;
|
||||
unsigned int getNd(void) const;
|
||||
double getVolume(void) const;
|
||||
// random number generator
|
||||
GridParallelRNG * get4dRng(void) const;
|
||||
// general memory management
|
||||
void addObject(const std::string name,
|
||||
const int moduleAddress = -1);
|
||||
template <typename B, typename T, typename ... Ts>
|
||||
void createDerivedObject(const std::string name,
|
||||
const Environment::Storage storage,
|
||||
const unsigned int Ls,
|
||||
Ts && ... args);
|
||||
template <typename T, typename ... Ts>
|
||||
void createObject(const std::string name,
|
||||
const Environment::Storage storage,
|
||||
const unsigned int Ls,
|
||||
Ts && ... args);
|
||||
void setObjectModule(const unsigned int objAddress,
|
||||
const int modAddress);
|
||||
template <typename B, typename T>
|
||||
T * getDerivedObject(const unsigned int address) const;
|
||||
template <typename B, typename T>
|
||||
T * getDerivedObject(const std::string name) const;
|
||||
template <typename T>
|
||||
T * getObject(const unsigned int address) const;
|
||||
template <typename T>
|
||||
T * getObject(const std::string name) const;
|
||||
unsigned int getMaxAddress(void) const;
|
||||
unsigned int getObjectAddress(const std::string name) const;
|
||||
std::string getObjectName(const unsigned int address) const;
|
||||
std::string getObjectType(const unsigned int address) const;
|
||||
std::string getObjectType(const std::string name) const;
|
||||
Size getObjectSize(const unsigned int address) const;
|
||||
Size getObjectSize(const std::string name) const;
|
||||
Storage getObjectStorage(const unsigned int address) const;
|
||||
Storage getObjectStorage(const std::string name) const;
|
||||
int getObjectModule(const unsigned int address) const;
|
||||
int getObjectModule(const std::string name) const;
|
||||
unsigned int getObjectLs(const unsigned int address) const;
|
||||
unsigned int getObjectLs(const std::string name) const;
|
||||
bool hasObject(const unsigned int address) const;
|
||||
bool hasObject(const std::string name) const;
|
||||
bool hasCreatedObject(const unsigned int address) const;
|
||||
bool hasCreatedObject(const std::string name) const;
|
||||
bool isObject5d(const unsigned int address) const;
|
||||
bool isObject5d(const std::string name) const;
|
||||
template <typename T>
|
||||
bool isObjectOfType(const unsigned int address) const;
|
||||
template <typename T>
|
||||
bool isObjectOfType(const std::string name) const;
|
||||
Environment::Size getTotalSize(void) const;
|
||||
void freeObject(const unsigned int address);
|
||||
void freeObject(const std::string name);
|
||||
void freeAll(void);
|
||||
void protectObjects(const bool protect);
|
||||
bool objectsProtected(void) const;
|
||||
// print environment content
|
||||
void printContent(void) const;
|
||||
private:
|
||||
// general
|
||||
double vol_;
|
||||
bool protect_{true};
|
||||
// grids
|
||||
std::vector<int> dim_;
|
||||
std::map<FineGridKey, GridPt> grid4d_;
|
||||
std::map<FineGridKey, GridPt> grid5d_;
|
||||
std::map<FineGridKey, GridRbPt> gridRb4d_;
|
||||
std::map<FineGridKey, GridRbPt> gridRb5d_;
|
||||
std::map<CoarseGridKey, GridPt> gridCoarse4d_;
|
||||
std::map<CoarseGridKey, GridPt> gridCoarse5d_;
|
||||
unsigned int nd_;
|
||||
// random number generator
|
||||
RngPt rng4d_;
|
||||
// object store
|
||||
std::vector<ObjInfo> object_;
|
||||
std::map<std::string, unsigned int> objectAddress_;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* Holder template implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Holder<T>::Holder(T *pt)
|
||||
: objPt_(pt)
|
||||
{}
|
||||
|
||||
// access //////////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
T & Holder<T>::get(void) const
|
||||
{
|
||||
return *objPt_.get();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T * Holder<T>::getPt(void) const
|
||||
{
|
||||
return objPt_.get();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Holder<T>::reset(T *pt)
|
||||
{
|
||||
objPt_.reset(pt);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Environment template implementation *
|
||||
******************************************************************************/
|
||||
// grids ///////////////////////////////////////////////////////////////////////
|
||||
#define HADRONS_DUMP_GRID(...)\
|
||||
LOG(Debug) << "New grid " << (__VA_ARGS__) << std::endl;\
|
||||
LOG(Debug) << " - cb : " << (__VA_ARGS__)->_isCheckerBoarded << std::endl;\
|
||||
LOG(Debug) << " - fdim: " << (__VA_ARGS__)->_fdimensions << std::endl;\
|
||||
LOG(Debug) << " - gdim: " << (__VA_ARGS__)->_gdimensions << std::endl;\
|
||||
LOG(Debug) << " - ldim: " << (__VA_ARGS__)->_ldimensions << std::endl;\
|
||||
LOG(Debug) << " - rdim: " << (__VA_ARGS__)->_rdimensions << std::endl;
|
||||
|
||||
template <typename VType>
|
||||
void Environment::createGrid(const unsigned int Ls)
|
||||
{
|
||||
size_t hash = typeHash<VType>();
|
||||
|
||||
if (grid4d_.find({hash, 1}) == grid4d_.end())
|
||||
{
|
||||
grid4d_[{hash, 1}].reset(
|
||||
SpaceTimeGrid::makeFourDimGrid(getDim(),
|
||||
GridDefaultSimd(getNd(), VType::Nsimd()),
|
||||
GridDefaultMpi()));
|
||||
HADRONS_DUMP_GRID(grid4d_[{hash, 1}].get());
|
||||
gridRb4d_[{hash, 1}].reset(
|
||||
SpaceTimeGrid::makeFourDimRedBlackGrid(grid4d_[{hash, 1}].get()));
|
||||
HADRONS_DUMP_GRID(gridRb4d_[{hash, 1}].get());
|
||||
}
|
||||
if (grid5d_.find({hash, Ls}) == grid5d_.end())
|
||||
{
|
||||
auto g = grid4d_[{hash, 1}].get();
|
||||
|
||||
grid5d_[{hash, Ls}].reset(SpaceTimeGrid::makeFiveDimGrid(Ls, g));
|
||||
HADRONS_DUMP_GRID(grid5d_[{hash, Ls}].get());
|
||||
gridRb5d_[{hash, Ls}].reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls, g));
|
||||
HADRONS_DUMP_GRID(gridRb5d_[{hash, Ls}].get());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VType>
|
||||
void Environment::createCoarseGrid(const std::vector<int> &blockSize,
|
||||
const unsigned int Ls)
|
||||
{
|
||||
int nd = getNd();
|
||||
std::vector<int> fineDim = getDim(), coarseDim(nd);
|
||||
unsigned int cLs;
|
||||
auto key4d = blockSize, key5d = blockSize;
|
||||
size_t hash = typeHash<VType>();
|
||||
|
||||
createGrid(Ls);
|
||||
for (int d = 0; d < coarseDim.size(); d++)
|
||||
{
|
||||
coarseDim[d] = fineDim[d]/blockSize[d];
|
||||
if (coarseDim[d]*blockSize[d] != fineDim[d])
|
||||
{
|
||||
HADRONS_ERROR(Size, "Fine dimension " + std::to_string(d)
|
||||
+ " (" + std::to_string(fineDim[d])
|
||||
+ ") not divisible by coarse dimension ("
|
||||
+ std::to_string(coarseDim[d]) + ")");
|
||||
}
|
||||
}
|
||||
if (blockSize.size() > nd)
|
||||
{
|
||||
cLs = Ls/blockSize[nd];
|
||||
if (cLs*blockSize[nd] != Ls)
|
||||
{
|
||||
HADRONS_ERROR(Size, "Fine Ls (" + std::to_string(Ls)
|
||||
+ ") not divisible by coarse Ls ("
|
||||
+ std::to_string(cLs) + ")");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cLs = Ls;
|
||||
}
|
||||
key4d.resize(nd);
|
||||
key5d.push_back(Ls);
|
||||
|
||||
CoarseGridKey hkey4d = {hash, key4d}, hkey5d = {hash, key5d};
|
||||
|
||||
if (gridCoarse4d_.find(hkey4d) == gridCoarse4d_.end())
|
||||
{
|
||||
gridCoarse4d_[hkey4d].reset(
|
||||
SpaceTimeGrid::makeFourDimGrid(coarseDim,
|
||||
GridDefaultSimd(nd, VType::Nsimd()), GridDefaultMpi()));
|
||||
HADRONS_DUMP_GRID(gridCoarse4d_[hkey4d].get());
|
||||
}
|
||||
if (gridCoarse5d_.find(hkey5d) == gridCoarse5d_.end())
|
||||
{
|
||||
gridCoarse5d_[hkey5d].reset(
|
||||
SpaceTimeGrid::makeFiveDimGrid(cLs, gridCoarse4d_[hkey4d].get()));
|
||||
HADRONS_DUMP_GRID(gridCoarse5d_[hkey5d].get());
|
||||
}
|
||||
}
|
||||
|
||||
#undef HADRONS_DUMP_GRID
|
||||
|
||||
template <typename VType>
|
||||
GridCartesian * Environment::getGrid(void)
|
||||
{
|
||||
FineGridKey key = {typeHash<VType>(), 1};
|
||||
|
||||
auto it = grid4d_.find(key);
|
||||
|
||||
if (it != grid4d_.end())
|
||||
{
|
||||
return it->second.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
createGrid<VType>(1);
|
||||
|
||||
return grid4d_.at(key).get();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VType>
|
||||
GridRedBlackCartesian * Environment::getRbGrid(void)
|
||||
{
|
||||
FineGridKey key = {typeHash<VType>(), 1};
|
||||
auto it = gridRb4d_.find(key);
|
||||
|
||||
if (it != gridRb4d_.end())
|
||||
{
|
||||
return it->second.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
createGrid<VType>(1);
|
||||
|
||||
return gridRb4d_.at(key).get();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VType>
|
||||
GridCartesian * Environment::getCoarseGrid(const std::vector<int> &blockSize)
|
||||
{
|
||||
std::vector<int> s = blockSize;
|
||||
|
||||
s.resize(getNd());
|
||||
|
||||
CoarseGridKey key = {typeHash<VType>(), s};
|
||||
auto it = gridCoarse4d_.find(key);
|
||||
|
||||
if (it != gridCoarse4d_.end())
|
||||
{
|
||||
return it->second.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
createCoarseGrid<VType>(blockSize, 1);
|
||||
|
||||
return gridCoarse4d_.at(key).get();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VType>
|
||||
GridCartesian * Environment::getGrid(const unsigned int Ls)
|
||||
{
|
||||
FineGridKey key = {typeHash<VType>(), Ls};
|
||||
auto it = grid5d_.find(key);
|
||||
|
||||
if (it != grid5d_.end())
|
||||
{
|
||||
return it->second.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
createGrid<VType>(Ls);
|
||||
|
||||
return grid5d_.at(key).get();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VType>
|
||||
GridRedBlackCartesian * Environment::getRbGrid(const unsigned int Ls)
|
||||
{
|
||||
FineGridKey key = {typeHash<VType>(), Ls};
|
||||
auto it = gridRb5d_.find(key);
|
||||
|
||||
if (it != gridRb5d_.end())
|
||||
{
|
||||
return it->second.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
createGrid<VType>(Ls);
|
||||
|
||||
return gridRb5d_.at(key).get();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VType>
|
||||
GridCartesian * Environment::getCoarseGrid(const std::vector<int> &blockSize,
|
||||
const unsigned int Ls)
|
||||
{
|
||||
std::vector<int> s = blockSize;
|
||||
|
||||
s.push_back(Ls);
|
||||
|
||||
CoarseGridKey key = {typeHash<VType>(), s};
|
||||
|
||||
auto it = gridCoarse5d_.find(key);
|
||||
if (it != gridCoarse5d_.end())
|
||||
{
|
||||
return it->second.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
createCoarseGrid<VType>(blockSize, Ls);
|
||||
|
||||
return gridCoarse5d_.at(key).get();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// general memory management ///////////////////////////////////////////////////
|
||||
template <typename B, typename T, typename ... Ts>
|
||||
void Environment::createDerivedObject(const std::string name,
|
||||
const Environment::Storage storage,
|
||||
const unsigned int Ls,
|
||||
Ts && ... args)
|
||||
{
|
||||
if (!hasObject(name))
|
||||
{
|
||||
addObject(name);
|
||||
}
|
||||
|
||||
unsigned int address = getObjectAddress(name);
|
||||
|
||||
if (!object_[address].data or !objectsProtected())
|
||||
{
|
||||
MemoryStats memStats;
|
||||
|
||||
if (!MemoryProfiler::stats)
|
||||
{
|
||||
MemoryProfiler::stats = &memStats;
|
||||
}
|
||||
size_t initMem = MemoryProfiler::stats->currentlyAllocated;
|
||||
object_[address].storage = storage;
|
||||
object_[address].Ls = Ls;
|
||||
object_[address].data.reset(new Holder<B>(new T(std::forward<Ts>(args)...)));
|
||||
object_[address].size = MemoryProfiler::stats->maxAllocated - initMem;
|
||||
object_[address].type = typeIdPt<B>();
|
||||
object_[address].derivedType = typeIdPt<T>();
|
||||
if (MemoryProfiler::stats == &memStats)
|
||||
{
|
||||
MemoryProfiler::stats = nullptr;
|
||||
}
|
||||
}
|
||||
// object already exists, no error if it is a cache, error otherwise
|
||||
else if ((object_[address].storage != Storage::cache) or
|
||||
(object_[address].storage != storage) or
|
||||
(object_[address].name != name) or
|
||||
(typeHash(object_[address].type) != typeHash<B>()) or
|
||||
(typeHash(object_[address].derivedType) != typeHash<T>()))
|
||||
{
|
||||
HADRONS_ERROR_REF(ObjectDefinition, "object '" + name + "' already allocated", address);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename ... Ts>
|
||||
void Environment::createObject(const std::string name,
|
||||
const Environment::Storage storage,
|
||||
const unsigned int Ls,
|
||||
Ts && ... args)
|
||||
{
|
||||
createDerivedObject<T, T>(name, storage, Ls, std::forward<Ts>(args)...);
|
||||
}
|
||||
|
||||
template <typename B, typename T>
|
||||
T * Environment::getDerivedObject(const unsigned int address) const
|
||||
{
|
||||
if (hasObject(address))
|
||||
{
|
||||
if (hasCreatedObject(address))
|
||||
{
|
||||
if (auto h = dynamic_cast<Holder<B> *>(object_[address].data.get()))
|
||||
{
|
||||
if (&typeid(T) == &typeid(B))
|
||||
{
|
||||
return dynamic_cast<T *>(h->getPt());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (auto hder = dynamic_cast<T *>(h->getPt()))
|
||||
{
|
||||
return hder;
|
||||
}
|
||||
else
|
||||
{
|
||||
HADRONS_ERROR_REF(ObjectType, "object with address " +
|
||||
std::to_string(address) +
|
||||
" cannot be casted to '" + typeName(&typeid(T)) +
|
||||
"' (has type '" + typeName(&typeid(h->get())) + "')", address);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HADRONS_ERROR_REF(ObjectType, "object with address " +
|
||||
std::to_string(address) +
|
||||
" does not have type '" + typeName(&typeid(B)) +
|
||||
"' (has type '" + getObjectType(address) + "')", address);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HADRONS_ERROR_REF(ObjectDefinition, "object with address " +
|
||||
std::to_string(address) + " is empty", address);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HADRONS_ERROR_REF(ObjectDefinition, "no object with address " +
|
||||
std::to_string(address), address);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename B, typename T>
|
||||
T * Environment::getDerivedObject(const std::string name) const
|
||||
{
|
||||
return getDerivedObject<B, T>(getObjectAddress(name));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T * Environment::getObject(const unsigned int address) const
|
||||
{
|
||||
return getDerivedObject<T, T>(address);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T * Environment::getObject(const std::string name) const
|
||||
{
|
||||
return getObject<T>(getObjectAddress(name));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Environment::isObjectOfType(const unsigned int address) const
|
||||
{
|
||||
if (hasObject(address))
|
||||
{
|
||||
if (auto h = dynamic_cast<Holder<T> *>(object_[address].data.get()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HADRONS_ERROR_REF(ObjectDefinition, "no object with address "
|
||||
+ std::to_string(address), address);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Environment::isObjectOfType(const std::string name) const
|
||||
{
|
||||
return isObjectOfType<T>(getObjectAddress(name));
|
||||
}
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Environment_hpp_
|
102
Hadrons/Exceptions.cc
Normal file
102
Hadrons/Exceptions.cc
Normal file
@ -0,0 +1,102 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Exceptions.cc
|
||||
|
||||
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 */
|
||||
|
||||
#include <Hadrons/Exceptions.hpp>
|
||||
#include <Hadrons/VirtualMachine.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
|
||||
#ifndef ERR_SUFF
|
||||
#define ERR_SUFF " (" + loc + ")"
|
||||
#endif
|
||||
|
||||
#define CTOR_EXC(name, init) \
|
||||
name::name(std::string msg, std::string loc)\
|
||||
:init\
|
||||
{}
|
||||
|
||||
#define CTOR_EXC_REF(name, init) \
|
||||
name::name(std::string msg, std::string loc, const unsigned int address)\
|
||||
:init\
|
||||
{}
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace Exceptions;
|
||||
|
||||
// backtrace cache
|
||||
std::vector<std::string> Grid::Hadrons::Exceptions::backtraceStr;
|
||||
|
||||
// logic errors
|
||||
CTOR_EXC(Logic, logic_error(msg + ERR_SUFF))
|
||||
CTOR_EXC(Definition, Logic("definition error: " + msg, loc))
|
||||
CTOR_EXC(Implementation, Logic("implementation error: " + msg, loc))
|
||||
CTOR_EXC(Range, Logic("range error: " + msg, loc))
|
||||
CTOR_EXC(Size, Logic("size error: " + msg, loc))
|
||||
|
||||
// runtime errors
|
||||
CTOR_EXC(Runtime, runtime_error(msg + ERR_SUFF))
|
||||
CTOR_EXC(Argument, Runtime("argument error: " + msg, loc))
|
||||
CTOR_EXC(Io, Runtime("IO error: " + msg, loc))
|
||||
CTOR_EXC(Memory, Runtime("memory error: " + msg, loc))
|
||||
CTOR_EXC(Parsing, Runtime("parsing error: " + msg, loc))
|
||||
CTOR_EXC(Program, Runtime("program error: " + msg, loc))
|
||||
CTOR_EXC(System, Runtime("system error: " + msg, loc))
|
||||
|
||||
// virtual machine errors
|
||||
CTOR_EXC_REF(ObjectDefinition, RuntimeRef("object definition error: " + msg, loc, address));
|
||||
CTOR_EXC_REF(ObjectType, RuntimeRef("object type error: " + msg, loc, address));
|
||||
|
||||
// abort functions
|
||||
void Grid::Hadrons::Exceptions::abort(const std::exception& e)
|
||||
{
|
||||
auto &vm = VirtualMachine::getInstance();
|
||||
int mod = vm.getCurrentModule();
|
||||
|
||||
LOG(Error) << "FATAL ERROR -- Exception " << typeName(&typeid(e))
|
||||
<< std::endl;
|
||||
if (mod >= 0)
|
||||
{
|
||||
LOG(Error) << "During execution of module '"
|
||||
<< vm.getModuleName(mod) << "' (address " << mod << ")"
|
||||
<< std::endl;
|
||||
}
|
||||
LOG(Error) << e.what() << std::endl;
|
||||
if (!backtraceStr.empty())
|
||||
{
|
||||
LOG(Error) << "-- BACKTRACE --------------" << std::endl;
|
||||
for (auto &s: backtraceStr)
|
||||
{
|
||||
LOG(Error) << s << std::endl;
|
||||
}
|
||||
LOG(Error) << "---------------------------" << std::endl;
|
||||
}
|
||||
LOG(Error) << "Aborting program" << std::endl;
|
||||
Grid_finalize();
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
129
Hadrons/Exceptions.hpp
Normal file
129
Hadrons/Exceptions.hpp
Normal file
@ -0,0 +1,129 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Exceptions.hpp
|
||||
|
||||
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 */
|
||||
|
||||
#ifndef Hadrons_Exceptions_hpp_
|
||||
#define Hadrons_Exceptions_hpp_
|
||||
|
||||
#include <stdexcept>
|
||||
#include <execinfo.h>
|
||||
#ifndef Hadrons_Global_hpp_
|
||||
#include <Hadrons/Global.hpp>
|
||||
#endif
|
||||
|
||||
#define HADRONS_SRC_LOC std::string(__FUNCTION__) + " at " \
|
||||
+ std::string(__FILE__) + ":" + std::to_string(__LINE__)
|
||||
#define HADRONS_BACKTRACE_MAX 128
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
#define HADRONS_CACHE_BACKTRACE \
|
||||
{\
|
||||
void* _callstack[HADRONS_BACKTRACE_MAX];\
|
||||
int _i, _frames = backtrace(_callstack, HADRONS_BACKTRACE_MAX);\
|
||||
char** _strs = backtrace_symbols(_callstack, _frames);\
|
||||
Grid::Hadrons::Exceptions::backtraceStr.clear();\
|
||||
for (_i = 0; _i < _frames; ++_i)\
|
||||
{\
|
||||
Hadrons::Exceptions::backtraceStr.push_back(std::string(_strs[_i]));\
|
||||
}\
|
||||
free(_strs);\
|
||||
}
|
||||
#else
|
||||
#define HADRONS_CACHE_BACKTRACE \
|
||||
Grid::Hadrons::Exceptions::backtraceStr.clear();\
|
||||
Grid::Hadrons::Exceptions::backtraceStr.push_back("<backtrace not supported>");
|
||||
#endif
|
||||
|
||||
#define HADRONS_ERROR(exc, msg)\
|
||||
HADRONS_CACHE_BACKTRACE \
|
||||
throw(Exceptions::exc(msg, HADRONS_SRC_LOC));
|
||||
|
||||
#define HADRONS_ERROR_REF(exc, msg, address)\
|
||||
HADRONS_CACHE_BACKTRACE \
|
||||
throw(Exceptions::exc(msg, HADRONS_SRC_LOC, address));
|
||||
|
||||
#define DECL_EXC(name, base) \
|
||||
class name: public base\
|
||||
{\
|
||||
public:\
|
||||
name(std::string msg, std::string loc);\
|
||||
}
|
||||
|
||||
#define DECL_EXC_REF(name, base) \
|
||||
class name: public base\
|
||||
{\
|
||||
public:\
|
||||
name(std::string msg, std::string loc, const unsigned int address);\
|
||||
}
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
namespace Exceptions
|
||||
{
|
||||
// backtrace cache
|
||||
extern std::vector<std::string> backtraceStr;
|
||||
|
||||
// logic errors
|
||||
DECL_EXC(Logic, std::logic_error);
|
||||
DECL_EXC(Definition, Logic);
|
||||
DECL_EXC(Implementation, Logic);
|
||||
DECL_EXC(Range, Logic);
|
||||
DECL_EXC(Size, Logic);
|
||||
|
||||
// runtime errors
|
||||
DECL_EXC(Runtime, std::runtime_error);
|
||||
DECL_EXC(Argument, Runtime);
|
||||
DECL_EXC(Io, Runtime);
|
||||
DECL_EXC(Memory, Runtime);
|
||||
DECL_EXC(Parsing, Runtime);
|
||||
DECL_EXC(Program, Runtime);
|
||||
DECL_EXC(System, Runtime);
|
||||
|
||||
// virtual machine errors
|
||||
class RuntimeRef: public Runtime
|
||||
{
|
||||
public:
|
||||
RuntimeRef(std::string msg, std::string loc, const unsigned int address)
|
||||
: Runtime(msg, loc), address_(address)
|
||||
{}
|
||||
unsigned int getAddress(void) const
|
||||
{
|
||||
return address_;
|
||||
}
|
||||
private:
|
||||
unsigned int address_;
|
||||
};
|
||||
|
||||
DECL_EXC_REF(ObjectDefinition, RuntimeRef);
|
||||
DECL_EXC_REF(ObjectType, RuntimeRef);
|
||||
|
||||
// abort functions
|
||||
void abort(const std::exception& e);
|
||||
}
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Exceptions_hpp_
|
105
Hadrons/Factory.hpp
Normal file
105
Hadrons/Factory.hpp
Normal file
@ -0,0 +1,105 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Factory.hpp
|
||||
|
||||
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 */
|
||||
|
||||
#ifndef Hadrons_Factory_hpp_
|
||||
#define Hadrons_Factory_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* abstract factory class *
|
||||
******************************************************************************/
|
||||
template <typename T>
|
||||
class Factory
|
||||
{
|
||||
public:
|
||||
typedef std::function<std::unique_ptr<T>(const std::string)> Func;
|
||||
public:
|
||||
// constructor
|
||||
Factory(void) = default;
|
||||
// destructor
|
||||
virtual ~Factory(void) = default;
|
||||
// registration
|
||||
void registerBuilder(const std::string type, const Func &f);
|
||||
// get builder list
|
||||
std::vector<std::string> getBuilderList(void) const;
|
||||
// factory
|
||||
std::unique_ptr<T> create(const std::string type,
|
||||
const std::string name) const;
|
||||
private:
|
||||
std::map<std::string, Func> builder_;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* template implementation *
|
||||
******************************************************************************/
|
||||
// registration ////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
void Factory<T>::registerBuilder(const std::string type, const Func &f)
|
||||
{
|
||||
builder_[type] = f;
|
||||
}
|
||||
|
||||
// get module list /////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
std::vector<std::string> Factory<T>::getBuilderList(void) const
|
||||
{
|
||||
std::vector<std::string> list;
|
||||
|
||||
for (auto &b: builder_)
|
||||
{
|
||||
list.push_back(b.first);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
// factory /////////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
std::unique_ptr<T> Factory<T>::create(const std::string type,
|
||||
const std::string name) const
|
||||
{
|
||||
Func func;
|
||||
|
||||
try
|
||||
{
|
||||
func = builder_.at(type);
|
||||
}
|
||||
catch (std::out_of_range &)
|
||||
{
|
||||
HADRONS_ERROR(Argument, "object of type '" + type + "' unknown");
|
||||
}
|
||||
|
||||
return func(name);
|
||||
}
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Factory_hpp_
|
321
Hadrons/GeneticScheduler.hpp
Normal file
321
Hadrons/GeneticScheduler.hpp
Normal file
@ -0,0 +1,321 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/GeneticScheduler.hpp
|
||||
|
||||
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 */
|
||||
|
||||
#ifndef Hadrons_GeneticScheduler_hpp_
|
||||
#define Hadrons_GeneticScheduler_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Graph.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Scheduler based on a genetic algorithm *
|
||||
******************************************************************************/
|
||||
template <typename V, typename T>
|
||||
class GeneticScheduler
|
||||
{
|
||||
public:
|
||||
typedef std::vector<T> Gene;
|
||||
typedef std::pair<Gene *, Gene *> GenePair;
|
||||
typedef std::function<V(const Gene &)> ObjFunc;
|
||||
struct Parameters
|
||||
{
|
||||
double mutationRate;
|
||||
unsigned int popSize, seed;
|
||||
};
|
||||
public:
|
||||
// constructor
|
||||
GeneticScheduler(Graph<T> &graph, const ObjFunc &func,
|
||||
const Parameters &par);
|
||||
// destructor
|
||||
virtual ~GeneticScheduler(void) = default;
|
||||
// access
|
||||
const Gene & getMinSchedule(void);
|
||||
V getMinValue(void);
|
||||
// reset population
|
||||
void initPopulation(void);
|
||||
// breed a new generation
|
||||
void nextGeneration(void);
|
||||
// heuristic benchmarks
|
||||
void benchmarkCrossover(const unsigned int nIt);
|
||||
// print population
|
||||
friend std::ostream & operator<<(std::ostream &out,
|
||||
const GeneticScheduler<V, T> &s)
|
||||
{
|
||||
out << "[";
|
||||
for (auto &p: s.population_)
|
||||
{
|
||||
out << p.first << ", ";
|
||||
}
|
||||
out << "\b\b]";
|
||||
|
||||
return out;
|
||||
}
|
||||
private:
|
||||
void doCrossover(void);
|
||||
void doMutation(void);
|
||||
// genetic operators
|
||||
GenePair selectPair(void);
|
||||
void crossover(Gene &c1, Gene &c2, const Gene &p1, const Gene &p2);
|
||||
void mutation(Gene &m, const Gene &c);
|
||||
|
||||
private:
|
||||
Graph<T> &graph_;
|
||||
const ObjFunc &func_;
|
||||
const Parameters par_;
|
||||
std::multimap<V, Gene> population_;
|
||||
std::mt19937 gen_;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* template implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename V, typename T>
|
||||
GeneticScheduler<V, T>::GeneticScheduler(Graph<T> &graph, const ObjFunc &func,
|
||||
const Parameters &par)
|
||||
: graph_(graph)
|
||||
, func_(func)
|
||||
, par_(par)
|
||||
{
|
||||
gen_.seed(par_.seed);
|
||||
}
|
||||
|
||||
// access //////////////////////////////////////////////////////////////////////
|
||||
template <typename V, typename T>
|
||||
const typename GeneticScheduler<V, T>::Gene &
|
||||
GeneticScheduler<V, T>::getMinSchedule(void)
|
||||
{
|
||||
return population_.begin()->second;
|
||||
}
|
||||
|
||||
template <typename V, typename T>
|
||||
V GeneticScheduler<V, T>::getMinValue(void)
|
||||
{
|
||||
return population_.begin()->first;
|
||||
}
|
||||
|
||||
// breed a new generation //////////////////////////////////////////////////////
|
||||
template <typename V, typename T>
|
||||
void GeneticScheduler<V, T>::nextGeneration(void)
|
||||
{
|
||||
// random initialization of the population if necessary
|
||||
if (population_.size() != par_.popSize)
|
||||
{
|
||||
initPopulation();
|
||||
}
|
||||
//LOG(Debug) << "Starting population:\n" << *this << std::endl;
|
||||
|
||||
// random mutations
|
||||
for (unsigned int i = 0; i < par_.popSize; ++i)
|
||||
{
|
||||
doMutation();
|
||||
}
|
||||
//LOG(Debug) << "After mutations:\n" << *this << std::endl;
|
||||
|
||||
// mating
|
||||
for (unsigned int i = 0; i < par_.popSize/2; ++i)
|
||||
{
|
||||
doCrossover();
|
||||
}
|
||||
//LOG(Debug) << "After mating:\n" << *this << std::endl;
|
||||
|
||||
// grim reaper
|
||||
auto it = population_.begin();
|
||||
|
||||
std::advance(it, par_.popSize);
|
||||
population_.erase(it, population_.end());
|
||||
//LOG(Debug) << "After grim reaper:\n" << *this << std::endl;
|
||||
}
|
||||
|
||||
// evolution steps /////////////////////////////////////////////////////////////
|
||||
template <typename V, typename T>
|
||||
void GeneticScheduler<V, T>::initPopulation(void)
|
||||
{
|
||||
population_.clear();
|
||||
for (unsigned int i = 0; i < par_.popSize; ++i)
|
||||
{
|
||||
auto p = graph_.topoSort(gen_);
|
||||
|
||||
population_.insert(std::make_pair(func_(p), p));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename V, typename T>
|
||||
void GeneticScheduler<V, T>::doCrossover(void)
|
||||
{
|
||||
auto p = selectPair();
|
||||
Gene &p1 = *(p.first), &p2 = *(p.second);
|
||||
Gene c1, c2;
|
||||
|
||||
crossover(c1, c2, p1, p2);
|
||||
thread_critical
|
||||
{
|
||||
population_.insert(std::make_pair(func_(c1), c1));
|
||||
population_.insert(std::make_pair(func_(c2), c2));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename V, typename T>
|
||||
void GeneticScheduler<V, T>::doMutation(void)
|
||||
{
|
||||
std::uniform_real_distribution<double> mdis(0., 1.);
|
||||
std::uniform_int_distribution<unsigned int> pdis(0, population_.size() - 1);
|
||||
|
||||
if (mdis(gen_) < par_.mutationRate)
|
||||
{
|
||||
Gene m;
|
||||
auto it = population_.begin();
|
||||
|
||||
std::advance(it, pdis(gen_));
|
||||
mutation(m, it->second);
|
||||
thread_critical
|
||||
{
|
||||
population_.insert(std::make_pair(func_(m), m));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// genetic operators ///////////////////////////////////////////////////////////
|
||||
template <typename V, typename T>
|
||||
typename GeneticScheduler<V, T>::GenePair GeneticScheduler<V, T>::selectPair(void)
|
||||
{
|
||||
std::vector<double> prob;
|
||||
unsigned int ind;
|
||||
Gene *p1, *p2;
|
||||
const double max = population_.rbegin()->first;
|
||||
|
||||
|
||||
for (auto &c: population_)
|
||||
{
|
||||
prob.push_back(std::exp((c.first-1.)/max));
|
||||
}
|
||||
std::discrete_distribution<unsigned int> dis1(prob.begin(), prob.end());
|
||||
auto rIt = population_.begin();
|
||||
ind = dis1(gen_);
|
||||
std::advance(rIt, ind);
|
||||
p1 = &(rIt->second);
|
||||
prob[ind] = 0.;
|
||||
std::discrete_distribution<unsigned int> dis2(prob.begin(), prob.end());
|
||||
rIt = population_.begin();
|
||||
std::advance(rIt, dis2(gen_));
|
||||
p2 = &(rIt->second);
|
||||
|
||||
return std::make_pair(p1, p2);
|
||||
}
|
||||
|
||||
template <typename V, typename T>
|
||||
void GeneticScheduler<V, T>::crossover(Gene &c1, Gene &c2, const Gene &p1,
|
||||
const Gene &p2)
|
||||
{
|
||||
Gene buf;
|
||||
std::uniform_int_distribution<unsigned int> dis(0, p1.size() - 1);
|
||||
unsigned int cut = dis(gen_);
|
||||
|
||||
c1.clear();
|
||||
buf = p2;
|
||||
for (unsigned int i = 0; i < cut; ++i)
|
||||
{
|
||||
c1.push_back(p1[i]);
|
||||
buf.erase(std::find(buf.begin(), buf.end(), p1[i]));
|
||||
}
|
||||
for (unsigned int i = 0; i < buf.size(); ++i)
|
||||
{
|
||||
c1.push_back(buf[i]);
|
||||
}
|
||||
c2.clear();
|
||||
buf = p2;
|
||||
for (unsigned int i = cut; i < p1.size(); ++i)
|
||||
{
|
||||
buf.erase(std::find(buf.begin(), buf.end(), p1[i]));
|
||||
}
|
||||
for (unsigned int i = 0; i < buf.size(); ++i)
|
||||
{
|
||||
c2.push_back(buf[i]);
|
||||
}
|
||||
for (unsigned int i = cut; i < p1.size(); ++i)
|
||||
{
|
||||
c2.push_back(p1[i]);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename V, typename T>
|
||||
void GeneticScheduler<V, T>::mutation(Gene &m, const Gene &c)
|
||||
{
|
||||
Gene buf;
|
||||
std::uniform_int_distribution<unsigned int> dis(0, c.size() - 1);
|
||||
unsigned int cut = dis(gen_);
|
||||
Graph<T> g1 = graph_, g2 = graph_;
|
||||
|
||||
for (unsigned int i = 0; i < cut; ++i)
|
||||
{
|
||||
g1.removeVertex(c[i]);
|
||||
}
|
||||
for (unsigned int i = cut; i < c.size(); ++i)
|
||||
{
|
||||
g2.removeVertex(c[i]);
|
||||
}
|
||||
if (g1.size() > 0)
|
||||
{
|
||||
buf = g1.topoSort(gen_);
|
||||
}
|
||||
if (g2.size() > 0)
|
||||
{
|
||||
m = g2.topoSort(gen_);
|
||||
}
|
||||
for (unsigned int i = cut; i < c.size(); ++i)
|
||||
{
|
||||
m.push_back(buf[i - cut]);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename V, typename T>
|
||||
void GeneticScheduler<V, T>::benchmarkCrossover(const unsigned int nIt)
|
||||
{
|
||||
Gene p1, p2, c1, c2;
|
||||
double neg = 0., eq = 0., pos = 0., total;
|
||||
int improvement;
|
||||
|
||||
LOG(Message) << "Benchmarking crossover..." << std::endl;
|
||||
for (unsigned int i = 0; i < nIt; ++i)
|
||||
{
|
||||
p1 = graph_.topoSort(gen_);
|
||||
p2 = graph_.topoSort(gen_);
|
||||
crossover(c1, c2, p1, p2);
|
||||
improvement = (func_(c1) + func_(c2) - func_(p1) - func_(p2))/2;
|
||||
if (improvement < 0) neg++; else if (improvement == 0) eq++; else pos++;
|
||||
}
|
||||
total = neg + eq + pos;
|
||||
LOG(Message) << " -: " << neg/total << " =: " << eq/total
|
||||
<< " +: " << pos/total << std::endl;
|
||||
}
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_GeneticScheduler_hpp_
|
214
Hadrons/Global.cc
Normal file
214
Hadrons/Global.cc
Normal file
@ -0,0 +1,214 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Global.cc
|
||||
|
||||
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 */
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace QCD;
|
||||
using namespace Hadrons;
|
||||
|
||||
HadronsLogger Hadrons::HadronsLogError(1,"Error");
|
||||
HadronsLogger Hadrons::HadronsLogWarning(1,"Warning");
|
||||
HadronsLogger Hadrons::HadronsLogMessage(1,"Message");
|
||||
HadronsLogger Hadrons::HadronsLogIterative(1,"Iterative");
|
||||
HadronsLogger Hadrons::HadronsLogDebug(1,"Debug");
|
||||
HadronsLogger Hadrons::HadronsLogIRL(1,"IRL");
|
||||
|
||||
void Hadrons::initLogger(void)
|
||||
{
|
||||
auto w = std::string("Hadrons").length();
|
||||
int cw = 8;
|
||||
|
||||
|
||||
GridLogError.setTopWidth(w);
|
||||
GridLogWarning.setTopWidth(w);
|
||||
GridLogMessage.setTopWidth(w);
|
||||
GridLogIterative.setTopWidth(w);
|
||||
GridLogDebug.setTopWidth(w);
|
||||
GridLogIRL.setTopWidth(w);
|
||||
GridLogError.setChanWidth(cw);
|
||||
GridLogWarning.setChanWidth(cw);
|
||||
GridLogMessage.setChanWidth(cw);
|
||||
GridLogIterative.setChanWidth(cw);
|
||||
GridLogDebug.setChanWidth(cw);
|
||||
GridLogIRL.setChanWidth(cw);
|
||||
HadronsLogError.Active(true);
|
||||
HadronsLogWarning.Active(true);
|
||||
HadronsLogMessage.Active(GridLogMessage.isActive());
|
||||
HadronsLogIterative.Active(GridLogIterative.isActive());
|
||||
HadronsLogDebug.Active(GridLogDebug.isActive());
|
||||
HadronsLogIRL.Active(GridLogIRL.isActive());
|
||||
HadronsLogError.setChanWidth(cw);
|
||||
HadronsLogWarning.setChanWidth(cw);
|
||||
HadronsLogMessage.setChanWidth(cw);
|
||||
HadronsLogIterative.setChanWidth(cw);
|
||||
HadronsLogDebug.setChanWidth(cw);
|
||||
HadronsLogIRL.setChanWidth(cw);
|
||||
}
|
||||
|
||||
// type utilities //////////////////////////////////////////////////////////////
|
||||
size_t Hadrons::typeHash(const std::type_info *info)
|
||||
{
|
||||
return info->hash_code();
|
||||
}
|
||||
|
||||
constexpr unsigned int maxNameSize = 1024u;
|
||||
|
||||
std::string Hadrons::typeName(const std::type_info *info)
|
||||
{
|
||||
char *buf;
|
||||
std::string name;
|
||||
|
||||
buf = abi::__cxa_demangle(info->name(), nullptr, nullptr, nullptr);
|
||||
name = buf;
|
||||
free(buf);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
// default writers/readers /////////////////////////////////////////////////////
|
||||
#ifdef HAVE_HDF5
|
||||
const std::string Hadrons::resultFileExt = "h5";
|
||||
#else
|
||||
const std::string Hadrons::resultFileExt = "xml";
|
||||
#endif
|
||||
|
||||
// recursive mkdir /////////////////////////////////////////////////////////////
|
||||
int Hadrons::mkdir(const std::string dirName)
|
||||
{
|
||||
if (!dirName.empty() and access(dirName.c_str(), R_OK|W_OK|X_OK))
|
||||
{
|
||||
mode_t mode755;
|
||||
char tmp[MAX_PATH_LENGTH];
|
||||
char *p = NULL;
|
||||
size_t len;
|
||||
|
||||
mode755 = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "%s", dirName.c_str());
|
||||
len = strlen(tmp);
|
||||
if(tmp[len - 1] == '/')
|
||||
{
|
||||
tmp[len - 1] = 0;
|
||||
}
|
||||
for(p = tmp + 1; *p; p++)
|
||||
{
|
||||
if(*p == '/')
|
||||
{
|
||||
*p = 0;
|
||||
::mkdir(tmp, mode755);
|
||||
*p = '/';
|
||||
}
|
||||
}
|
||||
|
||||
return ::mkdir(tmp, mode755);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Hadrons::basename(const std::string &s)
|
||||
{
|
||||
constexpr char sep = '/';
|
||||
size_t i = s.rfind(sep, s.length());
|
||||
|
||||
if (i != std::string::npos)
|
||||
{
|
||||
return s.substr(i+1, s.length() - i);
|
||||
}
|
||||
else
|
||||
{
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Hadrons::dirname(const std::string &s)
|
||||
{
|
||||
constexpr char sep = '/';
|
||||
size_t i = s.rfind(sep, s.length());
|
||||
|
||||
if (i != std::string::npos)
|
||||
{
|
||||
return s.substr(0, i);
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void Hadrons::makeFileDir(const std::string filename, GridBase *g)
|
||||
{
|
||||
bool doIt = true;
|
||||
|
||||
if (g)
|
||||
{
|
||||
doIt = g->IsBoss();
|
||||
}
|
||||
if (doIt)
|
||||
{
|
||||
std::string dir = dirname(filename);
|
||||
int status = mkdir(dir);
|
||||
|
||||
if (status)
|
||||
{
|
||||
HADRONS_ERROR(Io, "cannot create directory '" + dir
|
||||
+ "' ( " + std::strerror(errno) + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Hadrons::printTimeProfile(const std::map<std::string, GridTime> &timing,
|
||||
GridTime total)
|
||||
{
|
||||
typedef decltype(total.count()) Count;
|
||||
|
||||
std::map<Count, std::string, std::greater<Count>> rtiming;
|
||||
const double dtotal = static_cast<double>(total.count());
|
||||
auto cf = std::cout.flags();
|
||||
auto p = std::cout.precision();
|
||||
unsigned int width = 0;
|
||||
|
||||
for (auto &t: timing)
|
||||
{
|
||||
width = std::max(width, static_cast<unsigned int>(t.first.length()));
|
||||
rtiming[t.second.count()] = t.first;
|
||||
}
|
||||
for (auto &rt: rtiming)
|
||||
{
|
||||
LOG(Message) << std::setw(width) << rt.second << ": "
|
||||
<< rt.first << " us (" << std::fixed
|
||||
<< std::setprecision(1)
|
||||
<< static_cast<double>(rt.first)/dtotal*100 << "%)"
|
||||
<< std::endl;
|
||||
}
|
||||
std::cout.flags(cf);
|
||||
std::cout.precision(p);
|
||||
}
|
270
Hadrons/Global.hpp
Normal file
270
Hadrons/Global.hpp
Normal file
@ -0,0 +1,270 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Global.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.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 */
|
||||
|
||||
#ifndef Hadrons_Global_hpp_
|
||||
#define Hadrons_Global_hpp_
|
||||
|
||||
#include <set>
|
||||
#include <stack>
|
||||
#include <regex>
|
||||
#include <Grid/Grid.h>
|
||||
#include <cxxabi.h>
|
||||
|
||||
#ifndef SITE_SIZE_TYPE
|
||||
#define SITE_SIZE_TYPE size_t
|
||||
#endif
|
||||
|
||||
#ifndef DEFAULT_ASCII_PREC
|
||||
#define DEFAULT_ASCII_PREC 16
|
||||
#endif
|
||||
|
||||
/* the 'using Grid::operator<<;' statement prevents a very nasty compilation
|
||||
* error with GCC 5 (clang & GCC 6 compile fine without it).
|
||||
*/
|
||||
|
||||
#define BEGIN_HADRONS_NAMESPACE \
|
||||
namespace Grid {\
|
||||
using namespace QCD;\
|
||||
namespace Hadrons {\
|
||||
using Grid::operator<<;\
|
||||
using Grid::operator>>;
|
||||
#define END_HADRONS_NAMESPACE }}
|
||||
|
||||
#define BEGIN_MODULE_NAMESPACE(name)\
|
||||
namespace name {\
|
||||
using Grid::operator<<;\
|
||||
using Grid::operator>>;
|
||||
|
||||
#define END_MODULE_NAMESPACE }
|
||||
|
||||
#define _HADRONS_IMPL(impl, sub) impl##sub
|
||||
#define HADRONS_IMPL(impl, sub) _HADRONS_IMPL(impl, sub)
|
||||
|
||||
#ifndef FIMPLBASE
|
||||
#define FIMPLBASE WilsonImpl
|
||||
#endif
|
||||
#define FIMPL HADRONS_IMPL(FIMPLBASE, R)
|
||||
#define FIMPLF HADRONS_IMPL(FIMPLBASE, F)
|
||||
#define FIMPLD HADRONS_IMPL(FIMPLBASE, D)
|
||||
|
||||
#ifndef ZFIMPLBASE
|
||||
#define ZFIMPLBASE ZWilsonImpl
|
||||
#endif
|
||||
#define ZFIMPL HADRONS_IMPL(ZFIMPLBASE, R)
|
||||
#define ZFIMPLF HADRONS_IMPL(ZFIMPLBASE, F)
|
||||
#define ZFIMPLD HADRONS_IMPL(ZFIMPLBASE, D)
|
||||
|
||||
#ifndef SIMPLBASE
|
||||
#define SIMPLBASE ScalarImplC
|
||||
#endif
|
||||
#define SIMPL HADRONS_IMPL(SIMPLBASE, R)
|
||||
#define SIMPLF HADRONS_IMPL(SIMPLBASE, F)
|
||||
#define SIMPLD HADRONS_IMPL(SIMPLBASE, D)
|
||||
|
||||
#ifndef GIMPLBASE
|
||||
#define GIMPLBASE PeriodicGimpl
|
||||
#endif
|
||||
#define GIMPL HADRONS_IMPL(GIMPLBASE, R)
|
||||
#define GIMPLF HADRONS_IMPL(GIMPLBASE, F)
|
||||
#define GIMPLD HADRONS_IMPL(GIMPLBASE, D)
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
// type aliases
|
||||
#define BASIC_TYPE_ALIASES(Impl, suffix)\
|
||||
typedef typename Impl::Field ScalarField##suffix;\
|
||||
typedef typename Impl::PropagatorField PropagatorField##suffix;\
|
||||
typedef typename Impl::SitePropagator::scalar_object SitePropagator##suffix;\
|
||||
typedef std::vector<SitePropagator##suffix> SlicedPropagator##suffix;
|
||||
|
||||
#define FERM_TYPE_ALIASES(FImpl, suffix)\
|
||||
BASIC_TYPE_ALIASES(FImpl, suffix);\
|
||||
typedef FermionOperator<FImpl> FMat##suffix;\
|
||||
typedef typename FImpl::FermionField FermionField##suffix;\
|
||||
typedef typename FImpl::GaugeField GaugeField##suffix;\
|
||||
typedef typename FImpl::DoubledGaugeField DoubledGaugeField##suffix;\
|
||||
typedef typename FImpl::ComplexField ComplexField##suffix;
|
||||
|
||||
#define GAUGE_TYPE_ALIASES(GImpl, suffix)\
|
||||
typedef typename GImpl::GaugeField GaugeField##suffix;
|
||||
|
||||
#define SOLVER_TYPE_ALIASES(FImpl, suffix)\
|
||||
typedef Solver<FImpl> Solver##suffix;
|
||||
|
||||
#define SINK_TYPE_ALIASES(suffix)\
|
||||
typedef std::function<SlicedPropagator##suffix\
|
||||
(const PropagatorField##suffix &)> SinkFn##suffix;
|
||||
|
||||
// logger
|
||||
class HadronsLogger: public Logger
|
||||
{
|
||||
public:
|
||||
HadronsLogger(int on, std::string nm): Logger("Hadrons", on, nm,
|
||||
GridLogColours, "BLACK"){};
|
||||
};
|
||||
|
||||
#define LOG(channel) std::cout << HadronsLog##channel
|
||||
#define HADRONS_DEBUG_VAR(var) LOG(Debug) << #var << "= " << (var) << std::endl;
|
||||
|
||||
extern HadronsLogger HadronsLogError;
|
||||
extern HadronsLogger HadronsLogWarning;
|
||||
extern HadronsLogger HadronsLogMessage;
|
||||
extern HadronsLogger HadronsLogIterative;
|
||||
extern HadronsLogger HadronsLogDebug;
|
||||
extern HadronsLogger HadronsLogIRL;
|
||||
|
||||
void initLogger(void);
|
||||
|
||||
// singleton pattern
|
||||
#define SINGLETON(name)\
|
||||
public:\
|
||||
name(const name &e) = delete;\
|
||||
void operator=(const name &e) = delete;\
|
||||
static name & getInstance(void)\
|
||||
{\
|
||||
static name e;\
|
||||
return e;\
|
||||
}\
|
||||
private:\
|
||||
name(void);
|
||||
|
||||
#define SINGLETON_DEFCTOR(name)\
|
||||
public:\
|
||||
name(const name &e) = delete;\
|
||||
void operator=(const name &e) = delete;\
|
||||
static name & getInstance(void)\
|
||||
{\
|
||||
static name e;\
|
||||
return e;\
|
||||
}\
|
||||
private:\
|
||||
name(void) = default;
|
||||
|
||||
// type utilities
|
||||
template <typename T>
|
||||
const std::type_info * typeIdPt(const T &x)
|
||||
{
|
||||
return &typeid(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const std::type_info * typeIdPt(void)
|
||||
{
|
||||
return &typeid(T);
|
||||
}
|
||||
|
||||
size_t typeHash(const std::type_info *info);
|
||||
|
||||
template <typename T>
|
||||
size_t typeHash(const T &x)
|
||||
{
|
||||
return typeHash(typeIdPt(x));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t typeHash(void)
|
||||
{
|
||||
return typeHash(typeIdPt<T>());
|
||||
}
|
||||
|
||||
std::string typeName(const std::type_info *info);
|
||||
|
||||
template <typename T>
|
||||
std::string typeName(const T &x)
|
||||
{
|
||||
return typeName(typeIdPt(x));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string typeName(void)
|
||||
{
|
||||
return typeName(typeIdPt<T>());
|
||||
}
|
||||
|
||||
// default writers/readers
|
||||
extern const std::string resultFileExt;
|
||||
|
||||
#ifdef HAVE_HDF5
|
||||
typedef Hdf5Reader ResultReader;
|
||||
typedef Hdf5Writer ResultWriter;
|
||||
#else
|
||||
typedef XmlReader ResultReader;
|
||||
typedef XmlWriter ResultWriter;
|
||||
#endif
|
||||
|
||||
#define RESULT_FILE_NAME(name, traj) \
|
||||
name + "." + std::to_string(traj) + "." + resultFileExt
|
||||
|
||||
// recursive mkdir
|
||||
#define MAX_PATH_LENGTH 512u
|
||||
int mkdir(const std::string dirName);
|
||||
std::string basename(const std::string &s);
|
||||
std::string dirname(const std::string &s);
|
||||
void makeFileDir(const std::string filename, GridBase *g = nullptr);
|
||||
|
||||
// default Schur convention
|
||||
#ifndef HADRONS_DEFAULT_SCHUR
|
||||
#define HADRONS_DEFAULT_SCHUR DiagTwo
|
||||
#endif
|
||||
#define _HADRONS_SCHUR_OP_(conv) Schur##conv##Operator
|
||||
#define HADRONS_SCHUR_OP(conv) _HADRONS_SCHUR_OP_(conv)
|
||||
#define HADRONS_DEFAULT_SCHUR_OP HADRONS_SCHUR_OP(HADRONS_DEFAULT_SCHUR)
|
||||
#define _HADRONS_SCHUR_SOLVE_(conv) SchurRedBlack##conv##Solve
|
||||
#define HADRONS_SCHUR_SOLVE(conv) _HADRONS_SCHUR_SOLVE_(conv)
|
||||
#define HADRONS_DEFAULT_SCHUR_SOLVE HADRONS_SCHUR_SOLVE(HADRONS_DEFAULT_SCHUR)
|
||||
#define _HADRONS_SCHUR_A2A_(conv) A2AVectorsSchur##conv
|
||||
#define HADRONS_SCHUR_A2A(conv) _HADRONS_SCHUR_A2A_(conv)
|
||||
#define HADRONS_DEFAULT_SCHUR_A2A HADRONS_SCHUR_A2A(HADRONS_DEFAULT_SCHUR)
|
||||
|
||||
// stringify macro
|
||||
#define _HADRONS_STR(x) #x
|
||||
#define HADRONS_STR(x) _HADRONS_STR(x)
|
||||
|
||||
// pretty print time profile
|
||||
void printTimeProfile(const std::map<std::string, GridTime> &timing, GridTime total);
|
||||
|
||||
// token replacement utility
|
||||
template <typename T>
|
||||
void tokenReplace(std::string &str, const std::string token,
|
||||
const T &x, const std::string mark = "@")
|
||||
{
|
||||
std::string fullToken = mark + token + mark;
|
||||
|
||||
auto pos = str.find(fullToken);
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
str.replace(pos, fullToken.size(), std::to_string(x));
|
||||
}
|
||||
}
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#include <Hadrons/Exceptions.hpp>
|
||||
|
||||
#endif // Hadrons_Global_hpp_
|
759
Hadrons/Graph.hpp
Normal file
759
Hadrons/Graph.hpp
Normal file
@ -0,0 +1,759 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Graph.hpp
|
||||
|
||||
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 */
|
||||
|
||||
#ifndef Hadrons_Graph_hpp_
|
||||
#define Hadrons_Graph_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Oriented graph class *
|
||||
******************************************************************************/
|
||||
// I/O for edges
|
||||
template <typename T>
|
||||
std::ostream & operator<<(std::ostream &out, const std::pair<T, T> &e)
|
||||
{
|
||||
out << "\"" << e.first << "\" -> \"" << e.second << "\"";
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// main class
|
||||
template <typename T>
|
||||
class Graph
|
||||
{
|
||||
public:
|
||||
typedef std::pair<T, T> Edge;
|
||||
public:
|
||||
// constructor
|
||||
Graph(void);
|
||||
// destructor
|
||||
virtual ~Graph(void) = default;
|
||||
// access
|
||||
void addVertex(const T &value);
|
||||
void addEdge(const Edge &e);
|
||||
void addEdge(const T &start, const T &end);
|
||||
std::vector<T> getVertices(void) const;
|
||||
void removeVertex(const T &value);
|
||||
void removeEdge(const Edge &e);
|
||||
void removeEdge(const T &start, const T &end);
|
||||
unsigned int size(void) const;
|
||||
// tests
|
||||
bool gotValue(const T &value) const;
|
||||
// graph topological manipulations
|
||||
std::vector<T> getAdjacentVertices(const T &value) const;
|
||||
std::vector<T> getChildren(const T &value) const;
|
||||
std::vector<T> getParents(const T &value) const;
|
||||
std::vector<T> getRoots(void) const;
|
||||
std::vector<Graph<T>> getConnectedComponents(void) const;
|
||||
std::vector<T> topoSort(void);
|
||||
template <typename Gen>
|
||||
std::vector<T> topoSort(Gen &gen);
|
||||
std::vector<std::vector<T>> allTopoSort(void);
|
||||
// I/O
|
||||
friend std::ostream & operator<<(std::ostream &out, const Graph<T> &g)
|
||||
{
|
||||
out << "{";
|
||||
for (auto &e: g.edgeSet_)
|
||||
{
|
||||
out << e << ", ";
|
||||
}
|
||||
if (g.edgeSet_.size() != 0)
|
||||
{
|
||||
out << "\b\b";
|
||||
}
|
||||
out << "}";
|
||||
|
||||
return out;
|
||||
}
|
||||
private:
|
||||
// vertex marking
|
||||
void mark(const T &value, const bool doMark = true);
|
||||
void markAll(const bool doMark = true);
|
||||
void unmark(const T &value);
|
||||
void unmarkAll(void);
|
||||
bool isMarked(const T &value) const;
|
||||
const T * getFirstMarked(const bool isMarked = true) const;
|
||||
template <typename Gen>
|
||||
const T * getRandomMarked(const bool isMarked, Gen &gen);
|
||||
const T * getFirstUnmarked(void) const;
|
||||
template <typename Gen>
|
||||
const T * getRandomUnmarked(Gen &gen);
|
||||
// prune marked/unmarked vertices
|
||||
void removeMarked(const bool isMarked = true);
|
||||
void removeUnmarked(void);
|
||||
// depth-first search marking
|
||||
void depthFirstSearch(void);
|
||||
void depthFirstSearch(const T &root);
|
||||
private:
|
||||
std::map<T, bool> isMarked_;
|
||||
std::set<Edge> edgeSet_;
|
||||
};
|
||||
|
||||
// build depedency matrix from topological sorts
|
||||
template <typename T>
|
||||
std::map<T, std::map<T, bool>>
|
||||
makeDependencyMatrix(const std::vector<std::vector<T>> &topSort);
|
||||
|
||||
/******************************************************************************
|
||||
* template implementation *
|
||||
******************************************************************************
|
||||
* in all the following V is the number of vertex and E is the number of edge
|
||||
* in the worst case E = V^2
|
||||
*/
|
||||
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Graph<T>::Graph(void)
|
||||
{}
|
||||
|
||||
// access //////////////////////////////////////////////////////////////////////
|
||||
// complexity: log(V)
|
||||
template <typename T>
|
||||
void Graph<T>::addVertex(const T &value)
|
||||
{
|
||||
isMarked_[value] = false;
|
||||
}
|
||||
|
||||
// complexity: O(log(V))
|
||||
template <typename T>
|
||||
void Graph<T>::addEdge(const Edge &e)
|
||||
{
|
||||
addVertex(e.first);
|
||||
addVertex(e.second);
|
||||
edgeSet_.insert(e);
|
||||
}
|
||||
|
||||
// complexity: O(log(V))
|
||||
template <typename T>
|
||||
void Graph<T>::addEdge(const T &start, const T &end)
|
||||
{
|
||||
addEdge(Edge(start, end));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> Graph<T>::getVertices(void) const
|
||||
{
|
||||
std::vector<T> vertex;
|
||||
|
||||
for (auto &v: isMarked_)
|
||||
{
|
||||
vertex.push_back(v.first);
|
||||
}
|
||||
|
||||
return vertex;
|
||||
}
|
||||
|
||||
// complexity: O(V*log(V))
|
||||
template <typename T>
|
||||
void Graph<T>::removeVertex(const T &value)
|
||||
{
|
||||
// remove vertex from the mark table
|
||||
auto vIt = isMarked_.find(value);
|
||||
|
||||
if (vIt != isMarked_.end())
|
||||
{
|
||||
isMarked_.erase(vIt);
|
||||
}
|
||||
else
|
||||
{
|
||||
HADRONS_ERROR(Range, "vertex does not exists");
|
||||
}
|
||||
|
||||
// remove all edges containing the vertex
|
||||
auto pred = [&value](const Edge &e)
|
||||
{
|
||||
return ((e.first == value) or (e.second == value));
|
||||
};
|
||||
auto eIt = find_if(edgeSet_.begin(), edgeSet_.end(), pred);
|
||||
|
||||
while (eIt != edgeSet_.end())
|
||||
{
|
||||
edgeSet_.erase(eIt);
|
||||
eIt = find_if(edgeSet_.begin(), edgeSet_.end(), pred);
|
||||
}
|
||||
}
|
||||
|
||||
// complexity: O(log(V))
|
||||
template <typename T>
|
||||
void Graph<T>::removeEdge(const Edge &e)
|
||||
{
|
||||
auto eIt = edgeSet_.find(e);
|
||||
|
||||
if (eIt != edgeSet_.end())
|
||||
{
|
||||
edgeSet_.erase(eIt);
|
||||
}
|
||||
else
|
||||
{
|
||||
HADRONS_ERROR(Range, "edge does not exists");
|
||||
}
|
||||
}
|
||||
|
||||
// complexity: O(log(V))
|
||||
template <typename T>
|
||||
void Graph<T>::removeEdge(const T &start, const T &end)
|
||||
{
|
||||
removeEdge(Edge(start, end));
|
||||
}
|
||||
|
||||
// complexity: O(1)
|
||||
template <typename T>
|
||||
unsigned int Graph<T>::size(void) const
|
||||
{
|
||||
return isMarked_.size();
|
||||
}
|
||||
|
||||
// tests ///////////////////////////////////////////////////////////////////////
|
||||
// complexity: O(log(V))
|
||||
template <typename T>
|
||||
bool Graph<T>::gotValue(const T &value) const
|
||||
{
|
||||
auto it = isMarked_.find(value);
|
||||
|
||||
if (it == isMarked_.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// vertex marking //////////////////////////////////////////////////////////////
|
||||
// complexity: O(log(V))
|
||||
template <typename T>
|
||||
void Graph<T>::mark(const T &value, const bool doMark)
|
||||
{
|
||||
if (gotValue(value))
|
||||
{
|
||||
isMarked_[value] = doMark;
|
||||
}
|
||||
else
|
||||
{
|
||||
HADRONS_ERROR(Range, "vertex does not exists");
|
||||
}
|
||||
}
|
||||
|
||||
// complexity: O(V*log(V))
|
||||
template <typename T>
|
||||
void Graph<T>::markAll(const bool doMark)
|
||||
{
|
||||
for (auto &v: isMarked_)
|
||||
{
|
||||
mark(v.first, doMark);
|
||||
}
|
||||
}
|
||||
|
||||
// complexity: O(log(V))
|
||||
template <typename T>
|
||||
void Graph<T>::unmark(const T &value)
|
||||
{
|
||||
mark(value, false);
|
||||
}
|
||||
|
||||
// complexity: O(V*log(V))
|
||||
template <typename T>
|
||||
void Graph<T>::unmarkAll(void)
|
||||
{
|
||||
markAll(false);
|
||||
}
|
||||
|
||||
// complexity: O(log(V))
|
||||
template <typename T>
|
||||
bool Graph<T>::isMarked(const T &value) const
|
||||
{
|
||||
if (gotValue(value))
|
||||
{
|
||||
return isMarked_.at(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
HADRONS_ERROR(Range, "vertex does not exists");
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// complexity: O(log(V))
|
||||
template <typename T>
|
||||
const T * Graph<T>::getFirstMarked(const bool isMarked) const
|
||||
{
|
||||
auto pred = [&isMarked](const std::pair<T, bool> &v)
|
||||
{
|
||||
return (v.second == isMarked);
|
||||
};
|
||||
auto vIt = std::find_if(isMarked_.begin(), isMarked_.end(), pred);
|
||||
|
||||
if (vIt != isMarked_.end())
|
||||
{
|
||||
return &(vIt->first);
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// complexity: O(log(V))
|
||||
template <typename T>
|
||||
template <typename Gen>
|
||||
const T * Graph<T>::getRandomMarked(const bool isMarked, Gen &gen)
|
||||
{
|
||||
auto pred = [&isMarked](const std::pair<T, bool> &v)
|
||||
{
|
||||
return (v.second == isMarked);
|
||||
};
|
||||
std::uniform_int_distribution<unsigned int> dis(0, size() - 1);
|
||||
auto rIt = isMarked_.begin();
|
||||
|
||||
std::advance(rIt, dis(gen));
|
||||
auto vIt = std::find_if(rIt, isMarked_.end(), pred);
|
||||
if (vIt != isMarked_.end())
|
||||
{
|
||||
return &(vIt->first);
|
||||
}
|
||||
else
|
||||
{
|
||||
vIt = std::find_if(isMarked_.begin(), rIt, pred);
|
||||
if (vIt != rIt)
|
||||
{
|
||||
return &(vIt->first);
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// complexity: O(log(V))
|
||||
template <typename T>
|
||||
const T * Graph<T>::getFirstUnmarked(void) const
|
||||
{
|
||||
return getFirstMarked(false);
|
||||
}
|
||||
|
||||
// complexity: O(log(V))
|
||||
template <typename T>
|
||||
template <typename Gen>
|
||||
const T * Graph<T>::getRandomUnmarked(Gen &gen)
|
||||
{
|
||||
return getRandomMarked(false, gen);
|
||||
}
|
||||
|
||||
// prune marked/unmarked vertices //////////////////////////////////////////////
|
||||
// complexity: O(V^2*log(V))
|
||||
template <typename T>
|
||||
void Graph<T>::removeMarked(const bool isMarked)
|
||||
{
|
||||
auto isMarkedCopy = isMarked_;
|
||||
|
||||
for (auto &v: isMarkedCopy)
|
||||
{
|
||||
if (v.second == isMarked)
|
||||
{
|
||||
removeVertex(v.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// complexity: O(V^2*log(V))
|
||||
template <typename T>
|
||||
void Graph<T>::removeUnmarked(void)
|
||||
{
|
||||
removeMarked(false);
|
||||
}
|
||||
|
||||
// depth-first search marking //////////////////////////////////////////////////
|
||||
// complexity: O(V*log(V))
|
||||
template <typename T>
|
||||
void Graph<T>::depthFirstSearch(void)
|
||||
{
|
||||
depthFirstSearch(isMarked_.begin()->first);
|
||||
}
|
||||
|
||||
// complexity: O(V*log(V))
|
||||
template <typename T>
|
||||
void Graph<T>::depthFirstSearch(const T &root)
|
||||
{
|
||||
std::vector<T> adjacentVertex;
|
||||
|
||||
mark(root);
|
||||
adjacentVertex = getAdjacentVertices(root);
|
||||
for (auto &v: adjacentVertex)
|
||||
{
|
||||
if (!isMarked(v))
|
||||
{
|
||||
depthFirstSearch(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// graph topological manipulations /////////////////////////////////////////////
|
||||
// complexity: O(V*log(V))
|
||||
template <typename T>
|
||||
std::vector<T> Graph<T>::getAdjacentVertices(const T &value) const
|
||||
{
|
||||
std::vector<T> adjacentVertex;
|
||||
|
||||
auto pred = [&value](const Edge &e)
|
||||
{
|
||||
return ((e.first == value) or (e.second == value));
|
||||
};
|
||||
auto eIt = std::find_if(edgeSet_.begin(), edgeSet_.end(), pred);
|
||||
|
||||
while (eIt != edgeSet_.end())
|
||||
{
|
||||
if (eIt->first == value)
|
||||
{
|
||||
adjacentVertex.push_back((*eIt).second);
|
||||
}
|
||||
else if (eIt->second == value)
|
||||
{
|
||||
adjacentVertex.push_back((*eIt).first);
|
||||
}
|
||||
eIt = std::find_if(++eIt, edgeSet_.end(), pred);
|
||||
}
|
||||
|
||||
return adjacentVertex;
|
||||
}
|
||||
|
||||
// complexity: O(V*log(V))
|
||||
template <typename T>
|
||||
std::vector<T> Graph<T>::getChildren(const T &value) const
|
||||
{
|
||||
std::vector<T> child;
|
||||
|
||||
auto pred = [&value](const Edge &e)
|
||||
{
|
||||
return (e.first == value);
|
||||
};
|
||||
auto eIt = std::find_if(edgeSet_.begin(), edgeSet_.end(), pred);
|
||||
|
||||
while (eIt != edgeSet_.end())
|
||||
{
|
||||
child.push_back((*eIt).second);
|
||||
eIt = std::find_if(++eIt, edgeSet_.end(), pred);
|
||||
}
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
// complexity: O(V*log(V))
|
||||
template <typename T>
|
||||
std::vector<T> Graph<T>::getParents(const T &value) const
|
||||
{
|
||||
std::vector<T> parent;
|
||||
|
||||
auto pred = [&value](const Edge &e)
|
||||
{
|
||||
return (e.second == value);
|
||||
};
|
||||
auto eIt = std::find_if(edgeSet_.begin(), edgeSet_.end(), pred);
|
||||
|
||||
while (eIt != edgeSet_.end())
|
||||
{
|
||||
parent.push_back((*eIt).first);
|
||||
eIt = std::find_if(++eIt, edgeSet_.end(), pred);
|
||||
}
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
// complexity: O(V^2*log(V))
|
||||
template <typename T>
|
||||
std::vector<T> Graph<T>::getRoots(void) const
|
||||
{
|
||||
std::vector<T> root;
|
||||
|
||||
for (auto &v: isMarked_)
|
||||
{
|
||||
auto parent = getParents(v.first);
|
||||
|
||||
if (parent.size() == 0)
|
||||
{
|
||||
root.push_back(v.first);
|
||||
}
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
// complexity: O(V^2*log(V))
|
||||
template <typename T>
|
||||
std::vector<Graph<T>> Graph<T>::getConnectedComponents(void) const
|
||||
{
|
||||
std::vector<Graph<T>> res;
|
||||
Graph<T> copy(*this);
|
||||
|
||||
while (copy.size() > 0)
|
||||
{
|
||||
copy.depthFirstSearch();
|
||||
res.push_back(copy);
|
||||
res.back().removeUnmarked();
|
||||
res.back().unmarkAll();
|
||||
copy.removeMarked();
|
||||
copy.unmarkAll();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// topological sort using a directed DFS algorithm
|
||||
// complexity: O(V*log(V))
|
||||
template <typename T>
|
||||
std::vector<T> Graph<T>::topoSort(void)
|
||||
{
|
||||
std::stack<T> buf;
|
||||
std::vector<T> res;
|
||||
const T *vPt;
|
||||
std::map<T, bool> tmpMarked(isMarked_);
|
||||
|
||||
// visit function
|
||||
std::function<void(const T &)> visit = [&](const T &v)
|
||||
{
|
||||
if (tmpMarked.at(v))
|
||||
{
|
||||
HADRONS_ERROR(Range, "cannot topologically sort a cyclic graph");
|
||||
}
|
||||
if (!isMarked(v))
|
||||
{
|
||||
std::vector<T> child = getChildren(v);
|
||||
|
||||
tmpMarked[v] = true;
|
||||
for (auto &c: child)
|
||||
{
|
||||
visit(c);
|
||||
}
|
||||
mark(v);
|
||||
tmpMarked[v] = false;
|
||||
buf.push(v);
|
||||
}
|
||||
};
|
||||
|
||||
// reset temporary marks
|
||||
for (auto &v: tmpMarked)
|
||||
{
|
||||
tmpMarked.at(v.first) = false;
|
||||
}
|
||||
|
||||
// loop on unmarked vertices
|
||||
unmarkAll();
|
||||
vPt = getFirstUnmarked();
|
||||
while (vPt)
|
||||
{
|
||||
visit(*vPt);
|
||||
vPt = getFirstUnmarked();
|
||||
}
|
||||
unmarkAll();
|
||||
|
||||
// create result vector
|
||||
while (!buf.empty())
|
||||
{
|
||||
res.push_back(buf.top());
|
||||
buf.pop();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// random version of the topological sort
|
||||
// complexity: O(V*log(V))
|
||||
template <typename T>
|
||||
template <typename Gen>
|
||||
std::vector<T> Graph<T>::topoSort(Gen &gen)
|
||||
{
|
||||
std::stack<T> buf;
|
||||
std::vector<T> res;
|
||||
const T *vPt;
|
||||
std::map<T, bool> tmpMarked(isMarked_);
|
||||
|
||||
// visit function
|
||||
std::function<void(const T &)> visit = [&](const T &v)
|
||||
{
|
||||
if (tmpMarked.at(v))
|
||||
{
|
||||
HADRONS_ERROR(Range, "cannot topologically sort a cyclic graph");
|
||||
}
|
||||
if (!isMarked(v))
|
||||
{
|
||||
std::vector<T> child = getChildren(v);
|
||||
|
||||
tmpMarked[v] = true;
|
||||
std::shuffle(child.begin(), child.end(), gen);
|
||||
for (auto &c: child)
|
||||
{
|
||||
visit(c);
|
||||
}
|
||||
mark(v);
|
||||
tmpMarked[v] = false;
|
||||
buf.push(v);
|
||||
}
|
||||
};
|
||||
|
||||
// reset temporary marks
|
||||
for (auto &v: tmpMarked)
|
||||
{
|
||||
tmpMarked.at(v.first) = false;
|
||||
}
|
||||
|
||||
// loop on unmarked vertices
|
||||
unmarkAll();
|
||||
vPt = getRandomUnmarked(gen);
|
||||
while (vPt)
|
||||
{
|
||||
visit(*vPt);
|
||||
vPt = getRandomUnmarked(gen);
|
||||
}
|
||||
unmarkAll();
|
||||
|
||||
// create result vector
|
||||
while (!buf.empty())
|
||||
{
|
||||
res.push_back(buf.top());
|
||||
buf.pop();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// generate all possible topological sorts
|
||||
// Y. L. Varol & D. Rotem, Comput. J. 24(1), pp. 83–84, 1981
|
||||
// http://comjnl.oupjournals.org/cgi/doi/10.1093/comjnl/24.1.83
|
||||
// complexity: O(V*log(V)) (from the paper, but really ?)
|
||||
template <typename T>
|
||||
std::vector<std::vector<T>> Graph<T>::allTopoSort(void)
|
||||
{
|
||||
std::vector<std::vector<T>> res;
|
||||
std::map<T, std::map<T, bool>> iMat;
|
||||
|
||||
// create incidence matrix
|
||||
for (auto &v1: isMarked_)
|
||||
for (auto &v2: isMarked_)
|
||||
{
|
||||
iMat[v1.first][v2.first] = false;
|
||||
}
|
||||
for (auto &v: isMarked_)
|
||||
{
|
||||
auto cVec = getChildren(v.first);
|
||||
|
||||
for (auto &c: cVec)
|
||||
{
|
||||
iMat[v.first][c] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// generate initial topological sort
|
||||
res.push_back(topoSort());
|
||||
|
||||
// generate all other topological sorts by permutation
|
||||
std::vector<T> p = res[0];
|
||||
const unsigned int n = size();
|
||||
std::vector<unsigned int> loc(n);
|
||||
unsigned int i, k, k1;
|
||||
T obj_k, obj_k1;
|
||||
bool isFinal;
|
||||
|
||||
for (unsigned int j = 0; j < n; ++j)
|
||||
{
|
||||
loc[j] = j;
|
||||
}
|
||||
i = 0;
|
||||
while (i < n-1)
|
||||
{
|
||||
k = loc[i];
|
||||
k1 = k + 1;
|
||||
obj_k = p[k];
|
||||
if (k1 >= n)
|
||||
{
|
||||
isFinal = true;
|
||||
obj_k1 = obj_k;
|
||||
}
|
||||
else
|
||||
{
|
||||
isFinal = false;
|
||||
obj_k1 = p[k1];
|
||||
}
|
||||
if (iMat[res[0][i]][obj_k1] or isFinal)
|
||||
{
|
||||
for (unsigned int l = k; l >= i + 1; --l)
|
||||
{
|
||||
p[l] = p[l-1];
|
||||
}
|
||||
p[i] = obj_k;
|
||||
loc[i] = i;
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
p[k] = obj_k1;
|
||||
p[k1] = obj_k;
|
||||
loc[i] = k1;
|
||||
i = 0;
|
||||
res.push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// build depedency matrix from topological sorts ///////////////////////////////
|
||||
// complexity: something like O(V^2*log(V!))
|
||||
template <typename T>
|
||||
std::map<T, std::map<T, bool>>
|
||||
makeDependencyMatrix(const std::vector<std::vector<T>> &topSort)
|
||||
{
|
||||
std::map<T, std::map<T, bool>> m;
|
||||
const std::vector<T> &vList = topSort[0];
|
||||
|
||||
for (auto &v1: vList)
|
||||
for (auto &v2: vList)
|
||||
{
|
||||
bool dep = true;
|
||||
|
||||
for (auto &t: topSort)
|
||||
{
|
||||
auto i1 = std::find(t.begin(), t.end(), v1);
|
||||
auto i2 = std::find(t.begin(), t.end(), v2);
|
||||
|
||||
dep = dep and (i1 - i2 > 0);
|
||||
if (!dep) break;
|
||||
}
|
||||
m[v1][v2] = dep;
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Graph_hpp_
|
37
Hadrons/Makefile.am
Normal file
37
Hadrons/Makefile.am
Normal file
@ -0,0 +1,37 @@
|
||||
SUBDIRS = . Utilities
|
||||
|
||||
lib_LIBRARIES = libHadrons.a
|
||||
|
||||
include modules.inc
|
||||
|
||||
libHadrons_a_SOURCES = \
|
||||
Application.cc \
|
||||
Environment.cc \
|
||||
Exceptions.cc \
|
||||
Global.cc \
|
||||
Module.cc \
|
||||
TimerArray.cc \
|
||||
VirtualMachine.cc \
|
||||
$(modules_cc)
|
||||
|
||||
libHadrons_adir = $(includedir)/Hadrons
|
||||
nobase_libHadrons_a_HEADERS = \
|
||||
A2AVectors.hpp \
|
||||
A2AMatrix.hpp \
|
||||
Application.hpp \
|
||||
DilutedNoise.hpp \
|
||||
DiskVector.hpp \
|
||||
EigenPack.hpp \
|
||||
Environment.hpp \
|
||||
Exceptions.hpp \
|
||||
Factory.hpp \
|
||||
GeneticScheduler.hpp \
|
||||
Global.hpp \
|
||||
Graph.hpp \
|
||||
Module.hpp \
|
||||
Modules.hpp \
|
||||
ModuleFactory.hpp \
|
||||
Solver.hpp \
|
||||
TimerArray.hpp \
|
||||
VirtualMachine.hpp \
|
||||
$(modules_hpp)
|
95
Hadrons/Module.cc
Normal file
95
Hadrons/Module.cc
Normal file
@ -0,0 +1,95 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Module.cc
|
||||
|
||||
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 */
|
||||
|
||||
#include <Hadrons/Module.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
|
||||
using namespace Hadrons;
|
||||
|
||||
/******************************************************************************
|
||||
* ModuleBase implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
ModuleBase::ModuleBase(const std::string name)
|
||||
: name_(name)
|
||||
{}
|
||||
|
||||
// access //////////////////////////////////////////////////////////////////////
|
||||
std::string ModuleBase::getName(void) const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
// get factory registration name if available
|
||||
std::string ModuleBase::getRegisteredName(void)
|
||||
{
|
||||
HADRONS_ERROR(Definition, "module '" + getName() + "' has no registered type"
|
||||
+ " in the factory");
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void ModuleBase::operator()(void)
|
||||
{
|
||||
resetTimers();
|
||||
startTimer("_total");
|
||||
startTimer("_setup");
|
||||
setup();
|
||||
stopTimer("_setup");
|
||||
startTimer("_execute");
|
||||
execute();
|
||||
stopAllTimers();
|
||||
}
|
||||
|
||||
std::string ModuleBase::makeSeedString(void)
|
||||
{
|
||||
std::string seed;
|
||||
|
||||
if (!vm().getRunId().empty())
|
||||
{
|
||||
seed += vm().getRunId() + "-";
|
||||
}
|
||||
seed += getName() + "-" + std::to_string(vm().getTrajectory());
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
||||
GridParallelRNG & ModuleBase::rng4d(void)
|
||||
{
|
||||
auto &r = *env().get4dRng();
|
||||
|
||||
if (makeSeedString() != seed_)
|
||||
{
|
||||
seed_ = makeSeedString();
|
||||
LOG(Message) << "Seeding 4D RNG " << &r << " with string '"
|
||||
<< seed_ << "'" << std::endl;
|
||||
r.SeedUniqueString(seed_);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
287
Hadrons/Module.hpp
Normal file
287
Hadrons/Module.hpp
Normal file
@ -0,0 +1,287 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Module.hpp
|
||||
|
||||
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 */
|
||||
|
||||
#ifndef Hadrons_Module_hpp_
|
||||
#define Hadrons_Module_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/TimerArray.hpp>
|
||||
#include <Hadrons/VirtualMachine.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
// module registration macros
|
||||
#define MODULE_REGISTER(mod, base, ns)\
|
||||
class mod: public base\
|
||||
{\
|
||||
public:\
|
||||
typedef base Base;\
|
||||
using Base::Base;\
|
||||
virtual std::string getRegisteredName(void)\
|
||||
{\
|
||||
return std::string(#ns "::" #mod);\
|
||||
}\
|
||||
};\
|
||||
class ns##mod##ModuleRegistrar\
|
||||
{\
|
||||
public:\
|
||||
ns##mod##ModuleRegistrar(void)\
|
||||
{\
|
||||
ModuleFactory &modFac = ModuleFactory::getInstance();\
|
||||
modFac.registerBuilder(#ns "::" #mod, [&](const std::string name)\
|
||||
{\
|
||||
return std::unique_ptr<ns::mod>(new ns::mod(name));\
|
||||
});\
|
||||
}\
|
||||
};\
|
||||
static ns##mod##ModuleRegistrar ns##mod##ModuleRegistrarInstance;
|
||||
|
||||
#define MODULE_REGISTER_TMP(mod, base, ns)\
|
||||
extern template class base;\
|
||||
MODULE_REGISTER(mod, ARG(base), ns);
|
||||
|
||||
#define ARG(...) __VA_ARGS__
|
||||
#define HADRONS_MACRO_REDIRECT_12(arg1, arg2, macro, ...) macro
|
||||
#define HADRONS_MACRO_REDIRECT_23(arg1, arg2, arg3, macro, ...) macro
|
||||
|
||||
#define envGetGrid4(latticeType)\
|
||||
env().template getGrid<typename latticeType::vector_type>()
|
||||
|
||||
#define envGetGrid5(latticeType, Ls)\
|
||||
env().template getGrid<typename latticeType::vector_type>(Ls)
|
||||
|
||||
#define envGetGrid(...)\
|
||||
HADRONS_MACRO_REDIRECT_12(__VA_ARGS__, envGetGrid5, envGetGrid4)(__VA_ARGS__)
|
||||
|
||||
#define envGetRbGrid4(latticeType)\
|
||||
env().template getRbGrid<typename latticeType::vector_type>()
|
||||
|
||||
#define envGetRbGrid5(latticeType, Ls)\
|
||||
env().template getRbGrid<typename latticeType::vector_type>(Ls)
|
||||
|
||||
#define envGetRbGrid(...)\
|
||||
HADRONS_MACRO_REDIRECT_12(__VA_ARGS__, envGetRbGrid5, envGetRbGrid4)(__VA_ARGS__)
|
||||
|
||||
#define envGet(type, name)\
|
||||
*env().template getObject<type>(name)
|
||||
|
||||
#define envGetDerived(base, type, name)\
|
||||
*env().template getDerivedObject<base, type>(name)
|
||||
|
||||
#define envGetTmp(type, var)\
|
||||
type &var = *env().template getObject<type>(getName() + "_tmp_" + #var)
|
||||
|
||||
#define envHasType(type, name)\
|
||||
env().template isObjectOfType<type>(name)
|
||||
|
||||
#define envCreate(type, name, Ls, ...)\
|
||||
env().template createObject<type>(name, Environment::Storage::object, Ls, __VA_ARGS__)
|
||||
|
||||
#define envCreateDerived(base, type, name, Ls, ...)\
|
||||
env().template createDerivedObject<base, type>(name, Environment::Storage::object, Ls, __VA_ARGS__)
|
||||
|
||||
#define envCreateLat4(type, name)\
|
||||
envCreate(type, name, 1, envGetGrid(type))
|
||||
|
||||
#define envCreateLat5(type, name, Ls)\
|
||||
envCreate(type, name, Ls, envGetGrid(type, Ls))
|
||||
|
||||
#define envCreateLat(...)\
|
||||
HADRONS_MACRO_REDIRECT_23(__VA_ARGS__, envCreateLat5, envCreateLat4)(__VA_ARGS__)
|
||||
|
||||
#define envCache(type, name, Ls, ...)\
|
||||
env().template createObject<type>(name, Environment::Storage::cache, Ls, __VA_ARGS__)
|
||||
|
||||
#define envCacheLat4(type, name)\
|
||||
envCache(type, name, 1, envGetGrid(type))
|
||||
|
||||
#define envCacheLat5(type, name, Ls)\
|
||||
envCache(type, name, Ls, envGetGrid(type, Ls))
|
||||
|
||||
#define envCacheLat(...)\
|
||||
HADRONS_MACRO_REDIRECT_23(__VA_ARGS__, envCacheLat5, envCacheLat4)(__VA_ARGS__)
|
||||
|
||||
#define envTmp(type, name, Ls, ...)\
|
||||
env().template createObject<type>(getName() + "_tmp_" + name, \
|
||||
Environment::Storage::temporary, Ls, __VA_ARGS__)
|
||||
|
||||
#define envTmpLat4(type, name)\
|
||||
envTmp(type, name, 1, envGetGrid(type))
|
||||
|
||||
#define envTmpLat5(type, name, Ls)\
|
||||
envTmp(type, name, Ls, envGetGrid(type, Ls))
|
||||
|
||||
#define envTmpLat(...)\
|
||||
HADRONS_MACRO_REDIRECT_23(__VA_ARGS__, envTmpLat5, envTmpLat4)(__VA_ARGS__)
|
||||
|
||||
#define saveResult(ioStem, name, result)\
|
||||
if (env().getGrid()->IsBoss() and !ioStem.empty())\
|
||||
{\
|
||||
makeFileDir(ioStem, env().getGrid());\
|
||||
{\
|
||||
ResultWriter _writer(RESULT_FILE_NAME(ioStem, vm().getTrajectory()));\
|
||||
write(_writer, name, result);\
|
||||
}\
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Module class *
|
||||
******************************************************************************/
|
||||
// base class
|
||||
class ModuleBase: public TimerArray
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
ModuleBase(const std::string name);
|
||||
// destructor
|
||||
virtual ~ModuleBase(void) = default;
|
||||
// access
|
||||
std::string getName(void) const;
|
||||
// get factory registration name if available
|
||||
virtual std::string getRegisteredName(void);
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void) = 0;
|
||||
virtual std::vector<std::string> getReference(void)
|
||||
{
|
||||
return std::vector<std::string>(0);
|
||||
};
|
||||
virtual std::vector<std::string> getOutput(void) = 0;
|
||||
// parse parameters
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name) = 0;
|
||||
virtual void saveParameters(XmlWriter &writer, const std::string name) = 0;
|
||||
// parameter string
|
||||
virtual std::string parString(void) const = 0;
|
||||
// setup
|
||||
virtual void setup(void) {};
|
||||
virtual void execute(void) = 0;
|
||||
// execution
|
||||
void operator()(void);
|
||||
protected:
|
||||
// environment shortcut
|
||||
DEFINE_ENV_ALIAS;
|
||||
// virtual machine shortcut
|
||||
DEFINE_VM_ALIAS;
|
||||
// RNG seeded from module string
|
||||
GridParallelRNG &rng4d(void);
|
||||
private:
|
||||
std::string makeSeedString(void);
|
||||
private:
|
||||
std::string name_, currentTimer_, seed_;
|
||||
std::map<std::string, GridStopWatch> timer_;
|
||||
};
|
||||
|
||||
// derived class, templating the parameter class
|
||||
template <typename P>
|
||||
class Module: public ModuleBase
|
||||
{
|
||||
public:
|
||||
typedef P Par;
|
||||
public:
|
||||
// constructor
|
||||
Module(const std::string name);
|
||||
// destructor
|
||||
virtual ~Module(void) = default;
|
||||
// parse parameters
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name);
|
||||
virtual void saveParameters(XmlWriter &writer, const std::string name);
|
||||
// parameter string
|
||||
virtual std::string parString(void) const;
|
||||
// parameter access
|
||||
const P & par(void) const;
|
||||
void setPar(const P &par);
|
||||
private:
|
||||
P par_;
|
||||
};
|
||||
|
||||
// no parameter type
|
||||
class NoPar {};
|
||||
|
||||
template <>
|
||||
class Module<NoPar>: public ModuleBase
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
Module(const std::string name): ModuleBase(name) {};
|
||||
// destructor
|
||||
virtual ~Module(void) = default;
|
||||
// parse parameters (do nothing)
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name) {};
|
||||
virtual void saveParameters(XmlWriter &writer, const std::string name)
|
||||
{
|
||||
push(writer, "options");
|
||||
pop(writer);
|
||||
};
|
||||
// parameter string (empty)
|
||||
virtual std::string parString(void) const {return "";};
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* Template implementation *
|
||||
******************************************************************************/
|
||||
template <typename P>
|
||||
Module<P>::Module(const std::string name)
|
||||
: ModuleBase(name)
|
||||
{}
|
||||
|
||||
template <typename P>
|
||||
void Module<P>::parseParameters(XmlReader &reader, const std::string name)
|
||||
{
|
||||
read(reader, name, par_);
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
void Module<P>::saveParameters(XmlWriter &writer, const std::string name)
|
||||
{
|
||||
write(writer, name, par_);
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
std::string Module<P>::parString(void) const
|
||||
{
|
||||
XmlWriter writer("", "");
|
||||
|
||||
write(writer, par_.SerialisableClassName(), par_);
|
||||
|
||||
return writer.string();
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
const P & Module<P>::par(void) const
|
||||
{
|
||||
return par_;
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
void Module<P>::setPar(const P &par)
|
||||
{
|
||||
par_ = par;
|
||||
}
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Module_hpp_
|
48
Hadrons/ModuleFactory.hpp
Normal file
48
Hadrons/ModuleFactory.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/ModuleFactory.hpp
|
||||
|
||||
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 */
|
||||
|
||||
#ifndef Hadrons_ModuleFactory_hpp_
|
||||
#define Hadrons_ModuleFactory_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Factory.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* ModuleFactory *
|
||||
******************************************************************************/
|
||||
class ModuleFactory: public Factory<ModuleBase>
|
||||
{
|
||||
SINGLETON_DEFCTOR(ModuleFactory)
|
||||
};
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_ModuleFactory_hpp_
|
74
Hadrons/Modules.hpp
Normal file
74
Hadrons/Modules.hpp
Normal file
@ -0,0 +1,74 @@
|
||||
#include <Hadrons/Modules/MContraction/Baryon.hpp>
|
||||
#include <Hadrons/Modules/MContraction/A2AAslashField.hpp>
|
||||
#include <Hadrons/Modules/MContraction/A2AMesonField.hpp>
|
||||
#include <Hadrons/Modules/MContraction/Meson.hpp>
|
||||
#include <Hadrons/Modules/MContraction/WeakHamiltonian.hpp>
|
||||
#include <Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp>
|
||||
#include <Hadrons/Modules/MContraction/DiscLoop.hpp>
|
||||
#include <Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp>
|
||||
#include <Hadrons/Modules/MContraction/Gamma3pt.hpp>
|
||||
#include <Hadrons/Modules/MContraction/WardIdentity.hpp>
|
||||
#include <Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp>
|
||||
#include <Hadrons/Modules/MFermion/FreeProp.hpp>
|
||||
#include <Hadrons/Modules/MFermion/GaugeProp.hpp>
|
||||
#include <Hadrons/Modules/MSource/SeqGamma.hpp>
|
||||
#include <Hadrons/Modules/MSource/Point.hpp>
|
||||
#include <Hadrons/Modules/MSource/Wall.hpp>
|
||||
#include <Hadrons/Modules/MSource/Z2.hpp>
|
||||
#include <Hadrons/Modules/MSource/SeqConserved.hpp>
|
||||
#include <Hadrons/Modules/MSource/Momentum.hpp>
|
||||
#include <Hadrons/Modules/MSink/Smear.hpp>
|
||||
#include <Hadrons/Modules/MSink/Point.hpp>
|
||||
#include <Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.hpp>
|
||||
#include <Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp>
|
||||
#include <Hadrons/Modules/MSolver/Guesser.hpp>
|
||||
#include <Hadrons/Modules/MSolver/RBPrecCG.hpp>
|
||||
#include <Hadrons/Modules/MSolver/A2AVectors.hpp>
|
||||
#include <Hadrons/Modules/MSolver/A2AAslashVectors.hpp>
|
||||
#include <Hadrons/Modules/MGauge/UnitEm.hpp>
|
||||
#include <Hadrons/Modules/MGauge/StoutSmearing.hpp>
|
||||
#include <Hadrons/Modules/MGauge/Unit.hpp>
|
||||
#include <Hadrons/Modules/MGauge/Electrify.hpp>
|
||||
#include <Hadrons/Modules/MGauge/Random.hpp>
|
||||
#include <Hadrons/Modules/MGauge/GaugeFix.hpp>
|
||||
#include <Hadrons/Modules/MGauge/FundtoHirep.hpp>
|
||||
#include <Hadrons/Modules/MGauge/StochEm.hpp>
|
||||
#include <Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp>
|
||||
#include <Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.hpp>
|
||||
#include <Hadrons/Modules/MUtilities/PrecisionCast.hpp>
|
||||
#include <Hadrons/Modules/MUtilities/RandomVectors.hpp>
|
||||
#include <Hadrons/Modules/MUtilities/TestSeqGamma.hpp>
|
||||
#include <Hadrons/Modules/MUtilities/TestSeqConserved.hpp>
|
||||
#include <Hadrons/Modules/MLoop/NoiseLoop.hpp>
|
||||
#include <Hadrons/Modules/MScalar/FreeProp.hpp>
|
||||
#include <Hadrons/Modules/MScalar/VPCounterTerms.hpp>
|
||||
#include <Hadrons/Modules/MScalar/ScalarVP.hpp>
|
||||
#include <Hadrons/Modules/MScalar/Scalar.hpp>
|
||||
#include <Hadrons/Modules/MScalar/ChargedProp.hpp>
|
||||
#include <Hadrons/Modules/MNPR/Bilinear.hpp>
|
||||
#include <Hadrons/Modules/MNPR/Amputate.hpp>
|
||||
#include <Hadrons/Modules/MNPR/FourQuark.hpp>
|
||||
#include <Hadrons/Modules/MAction/DWF.hpp>
|
||||
#include <Hadrons/Modules/MAction/MobiusDWF.hpp>
|
||||
#include <Hadrons/Modules/MAction/Wilson.hpp>
|
||||
#include <Hadrons/Modules/MAction/WilsonClover.hpp>
|
||||
#include <Hadrons/Modules/MAction/ZMobiusDWF.hpp>
|
||||
#include <Hadrons/Modules/MAction/ScaledDWF.hpp>
|
||||
#include <Hadrons/Modules/MScalarSUN/StochFreeField.hpp>
|
||||
#include <Hadrons/Modules/MScalarSUN/TwoPointNPR.hpp>
|
||||
#include <Hadrons/Modules/MScalarSUN/ShiftProbe.hpp>
|
||||
#include <Hadrons/Modules/MScalarSUN/Div.hpp>
|
||||
#include <Hadrons/Modules/MScalarSUN/TrMag.hpp>
|
||||
#include <Hadrons/Modules/MScalarSUN/EMT.hpp>
|
||||
#include <Hadrons/Modules/MScalarSUN/TwoPoint.hpp>
|
||||
#include <Hadrons/Modules/MScalarSUN/TrPhi.hpp>
|
||||
#include <Hadrons/Modules/MScalarSUN/Utils.hpp>
|
||||
#include <Hadrons/Modules/MScalarSUN/TransProj.hpp>
|
||||
#include <Hadrons/Modules/MScalarSUN/Grad.hpp>
|
||||
#include <Hadrons/Modules/MScalarSUN/TrKinetic.hpp>
|
||||
#include <Hadrons/Modules/MIO/LoadEigenPack.hpp>
|
||||
#include <Hadrons/Modules/MIO/LoadNersc.hpp>
|
||||
#include <Hadrons/Modules/MIO/LoadA2AVectors.hpp>
|
||||
#include <Hadrons/Modules/MIO/LoadCosmHol.hpp>
|
||||
#include <Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp>
|
||||
#include <Hadrons/Modules/MIO/LoadBinary.hpp>
|
37
Hadrons/Modules/MAction/DWF.cc
Normal file
37
Hadrons/Modules/MAction/DWF.cc
Normal file
@ -0,0 +1,37 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MAction/DWF.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MAction/DWF.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MAction;
|
||||
|
||||
template class Grid::Hadrons::MAction::TDWF<FIMPL>;
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
template class Grid::Hadrons::MAction::TDWF<FIMPLF>;
|
||||
#endif
|
139
Hadrons/Modules/MAction/DWF.hpp
Normal file
139
Hadrons/Modules/MAction/DWF.hpp
Normal file
@ -0,0 +1,139 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MAction/DWF.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.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 */
|
||||
|
||||
#ifndef Hadrons_MAction_DWF_hpp_
|
||||
#define Hadrons_MAction_DWF_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Domain wall quark action *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MAction)
|
||||
|
||||
class DWFPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(DWFPar,
|
||||
std::string, gauge,
|
||||
unsigned int, Ls,
|
||||
double , mass,
|
||||
double , M5,
|
||||
std::string , boundary,
|
||||
std::string , twist);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TDWF: public Module<DWFPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TDWF(const std::string name);
|
||||
// destructor
|
||||
virtual ~TDWF(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(DWF, TDWF<FIMPL>, MAction);
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
MODULE_REGISTER_TMP(DWFF, TDWF<FIMPLF>, MAction);
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* DWF template implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TDWF<FImpl>::TDWF(const std::string name)
|
||||
: Module<DWFPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TDWF<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().gauge};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TDWF<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TDWF<FImpl>::setup(void)
|
||||
{
|
||||
LOG(Message) << "Setting up domain wall fermion matrix with m= "
|
||||
<< par().mass << ", M5= " << par().M5 << " and Ls= "
|
||||
<< par().Ls << " using gauge field '" << par().gauge << "'"
|
||||
<< std::endl;
|
||||
LOG(Message) << "Fermion boundary conditions: " << par().boundary
|
||||
<< std::endl;
|
||||
|
||||
auto &U = envGet(GaugeField, par().gauge);
|
||||
auto &g4 = *envGetGrid(FermionField);
|
||||
auto &grb4 = *envGetRbGrid(FermionField);
|
||||
auto &g5 = *envGetGrid(FermionField, par().Ls);
|
||||
auto &grb5 = *envGetRbGrid(FermionField, par().Ls);
|
||||
typename DomainWallFermion<FImpl>::ImplParams implParams;
|
||||
implParams.boundary_phases = strToVec<Complex>(par().boundary);
|
||||
implParams.twist_n_2pi_L = strToVec<Real>(par().twist);
|
||||
envCreateDerived(FMat, DomainWallFermion<FImpl>, getName(), par().Ls, U, g5,
|
||||
grb5, g4, grb4, par().mass, par().M5, implParams);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TDWF<FImpl>::execute(void)
|
||||
{}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MAction_DWF_hpp_
|
37
Hadrons/Modules/MAction/MobiusDWF.cc
Normal file
37
Hadrons/Modules/MAction/MobiusDWF.cc
Normal file
@ -0,0 +1,37 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MAction/MobiusDWF.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MAction/MobiusDWF.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MAction;
|
||||
|
||||
template class Grid::Hadrons::MAction::TMobiusDWF<FIMPL>;
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
template class Grid::Hadrons::MAction::TMobiusDWF<FIMPLF>;
|
||||
#endif
|
140
Hadrons/Modules/MAction/MobiusDWF.hpp
Normal file
140
Hadrons/Modules/MAction/MobiusDWF.hpp
Normal file
@ -0,0 +1,140 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MAction/MobiusDWF.hpp
|
||||
|
||||
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 */
|
||||
#ifndef Hadrons_MAction_MobiusDWF_hpp_
|
||||
#define Hadrons_MAction_MobiusDWF_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Mobius domain-wall fermion action *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MAction)
|
||||
|
||||
class MobiusDWFPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(MobiusDWFPar,
|
||||
std::string , gauge,
|
||||
unsigned int, Ls,
|
||||
double , mass,
|
||||
double , M5,
|
||||
double , b,
|
||||
double , c,
|
||||
std::string , boundary,
|
||||
std::string , twist);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TMobiusDWF: public Module<MobiusDWFPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TMobiusDWF(const std::string name);
|
||||
// destructor
|
||||
virtual ~TMobiusDWF(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(MobiusDWF, TMobiusDWF<FIMPL>, MAction);
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
MODULE_REGISTER_TMP(MobiusDWFF, TMobiusDWF<FIMPLF>, MAction);
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* TMobiusDWF implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TMobiusDWF<FImpl>::TMobiusDWF(const std::string name)
|
||||
: Module<MobiusDWFPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TMobiusDWF<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().gauge};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TMobiusDWF<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TMobiusDWF<FImpl>::setup(void)
|
||||
{
|
||||
LOG(Message) << "Setting up Mobius domain wall fermion matrix with m= "
|
||||
<< par().mass << ", M5= " << par().M5 << ", Ls= " << par().Ls
|
||||
<< ", b= " << par().b << ", c= " << par().c
|
||||
<< " using gauge field '" << par().gauge << "'"
|
||||
<< std::endl;
|
||||
LOG(Message) << "Fermion boundary conditions: " << par().boundary
|
||||
<< std::endl;
|
||||
|
||||
auto &U = envGet(GaugeField, par().gauge);
|
||||
auto &g4 = *envGetGrid(FermionField);
|
||||
auto &grb4 = *envGetRbGrid(FermionField);
|
||||
auto &g5 = *envGetGrid(FermionField, par().Ls);
|
||||
auto &grb5 = *envGetRbGrid(FermionField, par().Ls);
|
||||
typename MobiusFermion<FImpl>::ImplParams implParams;
|
||||
implParams.boundary_phases = strToVec<Complex>(par().boundary);
|
||||
implParams.twist_n_2pi_L = strToVec<Real>(par().twist);
|
||||
envCreateDerived(FMat, MobiusFermion<FImpl>, getName(), par().Ls, U, g5,
|
||||
grb5, g4, grb4, par().mass, par().M5, par().b, par().c,
|
||||
implParams);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TMobiusDWF<FImpl>::execute(void)
|
||||
{}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MAction_MobiusDWF_hpp_
|
37
Hadrons/Modules/MAction/ScaledDWF.cc
Normal file
37
Hadrons/Modules/MAction/ScaledDWF.cc
Normal file
@ -0,0 +1,37 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MAction/ScaledDWF.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MAction/ScaledDWF.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MAction;
|
||||
|
||||
template class Grid::Hadrons::MAction::TScaledDWF<FIMPL>;
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
template class Grid::Hadrons::MAction::TScaledDWF<FIMPLF>;
|
||||
#endif
|
139
Hadrons/Modules/MAction/ScaledDWF.hpp
Normal file
139
Hadrons/Modules/MAction/ScaledDWF.hpp
Normal file
@ -0,0 +1,139 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MAction/ScaledDWF.hpp
|
||||
|
||||
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 */
|
||||
#ifndef Hadrons_MAction_ScaledDWF_hpp_
|
||||
#define Hadrons_MAction_ScaledDWF_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Scaled domain wall fermion *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MAction)
|
||||
|
||||
class ScaledDWFPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(ScaledDWFPar,
|
||||
std::string , gauge,
|
||||
unsigned int, Ls,
|
||||
double , mass,
|
||||
double , M5,
|
||||
double , scale,
|
||||
std::string , boundary,
|
||||
std::string , twist);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TScaledDWF: public Module<ScaledDWFPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TScaledDWF(const std::string name);
|
||||
// destructor
|
||||
virtual ~TScaledDWF(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(ScaledDWF, TScaledDWF<FIMPL>, MAction);
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
MODULE_REGISTER_TMP(ScaledDWFF, TScaledDWF<FIMPLF>, MAction);
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* TScaledDWF implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TScaledDWF<FImpl>::TScaledDWF(const std::string name)
|
||||
: Module<ScaledDWFPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TScaledDWF<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().gauge};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TScaledDWF<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TScaledDWF<FImpl>::setup(void)
|
||||
{
|
||||
LOG(Message) << "Setting up scaled domain wall fermion matrix with m= "
|
||||
<< par().mass << ", M5= " << par().M5 << ", Ls= " << par().Ls
|
||||
<< ", scale= " << par().scale
|
||||
<< " using gauge field '" << par().gauge << "'"
|
||||
<< std::endl;
|
||||
LOG(Message) << "Fermion boundary conditions: " << par().boundary
|
||||
<< std::endl;
|
||||
|
||||
auto &U = envGet(GaugeField, par().gauge);
|
||||
auto &g4 = *envGetGrid(FermionField);
|
||||
auto &grb4 = *envGetRbGrid(FermionField);
|
||||
auto &g5 = *envGetGrid(FermionField, par().Ls);
|
||||
auto &grb5 = *envGetRbGrid(FermionField, par().Ls);
|
||||
typename ScaledShamirFermion<FImpl>::ImplParams implParams;
|
||||
implParams.boundary_phases = strToVec<Complex>(par().boundary);
|
||||
implParams.twist_n_2pi_L = strToVec<Real>(par().twist);
|
||||
envCreateDerived(FMat, ScaledShamirFermion<FImpl>, getName(), par().Ls, U, g5,
|
||||
grb5, g4, grb4, par().mass, par().M5, par().scale,
|
||||
implParams);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TScaledDWF<FImpl>::execute(void)
|
||||
{}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MAction_ScaledDWF_hpp_
|
37
Hadrons/Modules/MAction/Wilson.cc
Normal file
37
Hadrons/Modules/MAction/Wilson.cc
Normal file
@ -0,0 +1,37 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MAction/Wilson.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MAction/Wilson.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MAction;
|
||||
|
||||
template class Grid::Hadrons::MAction::TWilson<FIMPL>;
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
template class Grid::Hadrons::MAction::TWilson<FIMPLF>;
|
||||
#endif
|
134
Hadrons/Modules/MAction/Wilson.hpp
Normal file
134
Hadrons/Modules/MAction/Wilson.hpp
Normal file
@ -0,0 +1,134 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MAction/Wilson.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.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 */
|
||||
|
||||
#ifndef Hadrons_MAction_Wilson_hpp_
|
||||
#define Hadrons_MAction_Wilson_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* TWilson quark action *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MAction)
|
||||
|
||||
class WilsonPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonPar,
|
||||
std::string, gauge,
|
||||
double , mass,
|
||||
std::string, boundary,
|
||||
std::string, string,
|
||||
std::string, twist);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TWilson: public Module<WilsonPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TWilson(const std::string name);
|
||||
// destructor
|
||||
virtual ~TWilson(void) {};
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(Wilson, TWilson<FIMPL>, MAction);
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
MODULE_REGISTER_TMP(WilsonF, TWilson<FIMPLF>, MAction);
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* TWilson template implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TWilson<FImpl>::TWilson(const std::string name)
|
||||
: Module<WilsonPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TWilson<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().gauge};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TWilson<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TWilson<FImpl>::setup(void)
|
||||
{
|
||||
LOG(Message) << "Setting up Wilson fermion matrix with m= " << par().mass
|
||||
<< " using gauge field '" << par().gauge << "'" << std::endl;
|
||||
LOG(Message) << "Fermion boundary conditions: " << par().boundary
|
||||
<< std::endl;
|
||||
|
||||
auto &U = envGet(GaugeField, par().gauge);
|
||||
auto &grid = *envGetGrid(FermionField);
|
||||
auto &gridRb = *envGetRbGrid(FermionField);
|
||||
typename WilsonFermion<FImpl>::ImplParams implParams;
|
||||
implParams.boundary_phases = strToVec<Complex>(par().boundary);
|
||||
implParams.twist_n_2pi_L = strToVec<Real>(par().twist);
|
||||
envCreateDerived(FMat, WilsonFermion<FImpl>, getName(), 1, U, grid, gridRb,
|
||||
par().mass, implParams);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TWilson<FImpl>::execute()
|
||||
{}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Wilson_hpp_
|
37
Hadrons/Modules/MAction/WilsonClover.cc
Normal file
37
Hadrons/Modules/MAction/WilsonClover.cc
Normal file
@ -0,0 +1,37 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MAction/WilsonClover.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MAction/WilsonClover.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MAction;
|
||||
|
||||
template class Grid::Hadrons::MAction::TWilsonClover<FIMPL>;
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
template class Grid::Hadrons::MAction::TWilsonClover<FIMPLF>;
|
||||
#endif
|
140
Hadrons/Modules/MAction/WilsonClover.hpp
Normal file
140
Hadrons/Modules/MAction/WilsonClover.hpp
Normal file
@ -0,0 +1,140 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MAction/WilsonClover.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Guido Cossu <guido.cossu@ed.ac.uk>
|
||||
Author: pretidav <david.preti@csic.es>
|
||||
|
||||
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_MAction_WilsonClover_hpp_
|
||||
#define Hadrons_MAction_WilsonClover_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Wilson clover quark action *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MAction)
|
||||
|
||||
class WilsonCloverPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonCloverPar,
|
||||
std::string, gauge,
|
||||
double , mass,
|
||||
double , csw_r,
|
||||
double , csw_t,
|
||||
WilsonAnisotropyCoefficients ,clover_anisotropy,
|
||||
std::string, boundary,
|
||||
std::string, twist
|
||||
);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TWilsonClover: public Module<WilsonCloverPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TWilsonClover(const std::string name);
|
||||
// destructor
|
||||
virtual ~TWilsonClover(void) {};
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(WilsonClover, TWilsonClover<FIMPL>, MAction);
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
MODULE_REGISTER_TMP(WilsonCloverF, TWilsonClover<FIMPLF>, MAction);
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* TWilsonClover template implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TWilsonClover<FImpl>::TWilsonClover(const std::string name)
|
||||
: Module<WilsonCloverPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TWilsonClover<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().gauge};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TWilsonClover<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TWilsonClover<FImpl>::setup(void)
|
||||
{
|
||||
LOG(Message) << "Setting up Wilson clover fermion matrix with m= " << par().mass
|
||||
<< " using gauge field '" << par().gauge << "'" << std::endl;
|
||||
LOG(Message) << "Fermion boundary conditions: " << par().boundary
|
||||
<< std::endl;
|
||||
LOG(Message) << "Clover term csw_r: " << par().csw_r
|
||||
<< " csw_t: " << par().csw_t
|
||||
<< std::endl;
|
||||
auto &U = envGet(GaugeField, par().gauge);
|
||||
auto &grid = *envGetGrid(FermionField);
|
||||
auto &gridRb = *envGetRbGrid(FermionField);
|
||||
typename WilsonCloverFermion<FImpl>::ImplParams implParams;
|
||||
implParams.boundary_phases = strToVec<Complex>(par().boundary);
|
||||
implParams.twist_n_2pi_L = strToVec<Real>(par().twist);
|
||||
envCreateDerived(FMat, WilsonCloverFermion<FImpl>, getName(), 1, U, grid,
|
||||
gridRb, par().mass, par().csw_r, par().csw_t,
|
||||
par().clover_anisotropy, implParams);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TWilsonClover<FImpl>::execute()
|
||||
{}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_WilsonClover_hpp_
|
37
Hadrons/Modules/MAction/ZMobiusDWF.cc
Normal file
37
Hadrons/Modules/MAction/ZMobiusDWF.cc
Normal file
@ -0,0 +1,37 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MAction/ZMobiusDWF.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MAction/ZMobiusDWF.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MAction;
|
||||
|
||||
template class Grid::Hadrons::MAction::TZMobiusDWF<ZFIMPL>;
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
template class Grid::Hadrons::MAction::TZMobiusDWF<ZFIMPLF>;
|
||||
#endif
|
148
Hadrons/Modules/MAction/ZMobiusDWF.hpp
Normal file
148
Hadrons/Modules/MAction/ZMobiusDWF.hpp
Normal file
@ -0,0 +1,148 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MAction/ZMobiusDWF.hpp
|
||||
|
||||
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 */
|
||||
#ifndef Hadrons_MAction_ZMobiusDWF_hpp_
|
||||
#define Hadrons_MAction_ZMobiusDWF_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* z-Mobius domain-wall fermion action *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MAction)
|
||||
|
||||
class ZMobiusDWFPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(ZMobiusDWFPar,
|
||||
std::string , gauge,
|
||||
unsigned int , Ls,
|
||||
double , mass,
|
||||
double , M5,
|
||||
double , b,
|
||||
double , c,
|
||||
std::vector<std::complex<double>>, omega,
|
||||
std::string , boundary,
|
||||
std::string , twist);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TZMobiusDWF: public Module<ZMobiusDWFPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TZMobiusDWF(const std::string name);
|
||||
// destructor
|
||||
virtual ~TZMobiusDWF(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(ZMobiusDWF, TZMobiusDWF<ZFIMPL>, MAction);
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
MODULE_REGISTER_TMP(ZMobiusDWFF, TZMobiusDWF<ZFIMPLF>, MAction);
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* TZMobiusDWF implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TZMobiusDWF<FImpl>::TZMobiusDWF(const std::string name)
|
||||
: Module<ZMobiusDWFPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TZMobiusDWF<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().gauge};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TZMobiusDWF<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TZMobiusDWF<FImpl>::setup(void)
|
||||
{
|
||||
LOG(Message) << "Setting up z-Mobius domain wall fermion matrix with m= "
|
||||
<< par().mass << ", M5= " << par().M5 << ", Ls= " << par().Ls
|
||||
<< ", b= " << par().b << ", c= " << par().c
|
||||
<< " using gauge field '" << par().gauge << "'"
|
||||
<< std::endl;
|
||||
LOG(Message) << "Omegas: " << std::endl;
|
||||
for (unsigned int i = 0; i < par().omega.size(); ++i)
|
||||
{
|
||||
LOG(Message) << " omega[" << i << "]= " << par().omega[i] << std::endl;
|
||||
}
|
||||
LOG(Message) << "Fermion boundary conditions: " << par().boundary
|
||||
<< std::endl;
|
||||
|
||||
env().createGrid(par().Ls);
|
||||
auto &U = envGet(GaugeField, par().gauge);
|
||||
auto &g4 = *envGetGrid(FermionField);
|
||||
auto &grb4 = *envGetRbGrid(FermionField);
|
||||
auto &g5 = *envGetGrid(FermionField, par().Ls);
|
||||
auto &grb5 = *envGetRbGrid(FermionField, par().Ls);
|
||||
auto omega = par().omega;
|
||||
typename ZMobiusFermion<FImpl>::ImplParams implParams;
|
||||
implParams.boundary_phases = strToVec<Complex>(par().boundary);
|
||||
implParams.twist_n_2pi_L = strToVec<Real>(par().twist);
|
||||
envCreateDerived(FMat, ZMobiusFermion<FImpl>, getName(), par().Ls, U, g5,
|
||||
grb5, g4, grb4, par().mass, par().M5, omega,
|
||||
par().b, par().c, implParams);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TZMobiusDWF<FImpl>::execute(void)
|
||||
{}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MAction_ZMobiusDWF_hpp_
|
34
Hadrons/Modules/MContraction/A2AAslashField.cc
Normal file
34
Hadrons/Modules/MContraction/A2AAslashField.cc
Normal file
@ -0,0 +1,34 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/A2AAslashField.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MContraction/A2AAslashField.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MContraction;
|
||||
|
||||
template class Grid::Hadrons::MContraction::TA2AAslashField<FIMPL, PhotonR>;
|
246
Hadrons/Modules/MContraction/A2AAslashField.hpp
Normal file
246
Hadrons/Modules/MContraction/A2AAslashField.hpp
Normal file
@ -0,0 +1,246 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/A2AAslashField.hpp
|
||||
|
||||
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 */
|
||||
#ifndef Hadrons_MContraction_A2AAslashField_hpp_
|
||||
#define Hadrons_MContraction_A2AAslashField_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Hadrons/A2AMatrix.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* A2AAslashField *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MContraction)
|
||||
|
||||
class A2AAslashFieldPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(A2AAslashFieldPar,
|
||||
int, cacheBlock,
|
||||
int, block,
|
||||
std::string, left,
|
||||
std::string, right,
|
||||
std::string, output,
|
||||
std::vector<std::string>, emField);
|
||||
};
|
||||
|
||||
class A2AAslashFieldMetadata: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(A2AAslashFieldMetadata,
|
||||
std::string, emFieldName);
|
||||
};
|
||||
|
||||
template <typename T, typename FImpl>
|
||||
class AslashFieldKernel: public A2AKernel<T, typename FImpl::FermionField>
|
||||
{
|
||||
public:
|
||||
typedef typename FImpl::FermionField FermionField;
|
||||
public:
|
||||
AslashFieldKernel(const std::vector<LatticeComplex> &emB0,
|
||||
const std::vector<LatticeComplex> &emB1,
|
||||
GridBase *grid)
|
||||
: emB0_(emB0), emB1_(emB1), grid_(grid)
|
||||
{
|
||||
vol_ = 1.;
|
||||
for (auto &d: grid_->GlobalDimensions())
|
||||
{
|
||||
vol_ *= d;
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~AslashFieldKernel(void) = default;
|
||||
virtual void operator()(A2AMatrixSet<T> &m, const FermionField *left,
|
||||
const FermionField *right,
|
||||
const unsigned int orthogDim, double &t)
|
||||
{
|
||||
A2Autils<FImpl>::AslashField(m, left, right, emB0_, emB1_, orthogDim, &t);
|
||||
}
|
||||
|
||||
virtual double flops(const unsigned int blockSizei, const unsigned int blockSizej)
|
||||
{
|
||||
return 0.;
|
||||
}
|
||||
|
||||
virtual double bytes(const unsigned int blockSizei, const unsigned int blockSizej)
|
||||
{
|
||||
return 0.;
|
||||
}
|
||||
private:
|
||||
const std::vector<LatticeComplex> &emB0_, &emB1_;
|
||||
GridBase *grid_;
|
||||
double vol_;
|
||||
};
|
||||
|
||||
template <typename FImpl, typename PhotonImpl>
|
||||
class TA2AAslashField: public Module<A2AAslashFieldPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
typedef typename PhotonImpl::GaugeField EmField;
|
||||
typedef A2AMatrixBlockComputation<Complex,
|
||||
FermionField,
|
||||
A2AAslashFieldMetadata,
|
||||
HADRONS_A2AM_IO_TYPE> Computation;
|
||||
typedef AslashFieldKernel<Complex, FImpl> Kernel;
|
||||
public:
|
||||
// constructor
|
||||
TA2AAslashField(const std::string name);
|
||||
// destructor
|
||||
virtual ~TA2AAslashField(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(A2AAslashField, ARG(TA2AAslashField<FIMPL, PhotonR>), MContraction);
|
||||
|
||||
/******************************************************************************
|
||||
* TA2AAslashField implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl, typename PhotonImpl>
|
||||
TA2AAslashField<FImpl, PhotonImpl>::TA2AAslashField(const std::string name)
|
||||
: Module<A2AAslashFieldPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl, typename PhotonImpl>
|
||||
std::vector<std::string> TA2AAslashField<FImpl, PhotonImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = par().emField;
|
||||
|
||||
in.push_back(par().left);
|
||||
in.push_back(par().right);
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl, typename PhotonImpl>
|
||||
std::vector<std::string> TA2AAslashField<FImpl, PhotonImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl, typename PhotonImpl>
|
||||
void TA2AAslashField<FImpl, PhotonImpl>::setup(void)
|
||||
{
|
||||
envTmp(Computation, "computation", 1, envGetGrid(FermionField),
|
||||
env().getNd() - 1, par().emField.size(), 1, par().block,
|
||||
par().cacheBlock, this);
|
||||
envTmp(std::vector<ComplexField>, "B0", 1,
|
||||
par().emField.size(), envGetGrid(ComplexField));
|
||||
envTmp(std::vector<ComplexField>, "B1", 1,
|
||||
par().emField.size(), envGetGrid(ComplexField));
|
||||
envTmpLat(ComplexField, "Amu");
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl, typename PhotonImpl>
|
||||
void TA2AAslashField<FImpl, PhotonImpl>::execute(void)
|
||||
{
|
||||
auto &left = envGet(std::vector<FermionField>, par().left);
|
||||
auto &right = envGet(std::vector<FermionField>, par().right);
|
||||
|
||||
int nt = env().getDim().back();
|
||||
int N_i = left.size();
|
||||
int N_j = right.size();
|
||||
int nem = par().emField.size();
|
||||
int block = par().block;
|
||||
int cacheBlock = par().cacheBlock;
|
||||
|
||||
LOG(Message) << "Computing all-to-all A-slash fields" << std::endl;
|
||||
LOG(Message) << "Left: '" << par().left << "' Right: '" << par().right << "'" << std::endl;
|
||||
LOG(Message) << "EM fields:" << std::endl;
|
||||
for (auto &name: par().emField)
|
||||
{
|
||||
LOG(Message) << " " << name << std::endl;
|
||||
}
|
||||
LOG(Message) << "A-slash field size: " << nt << "*" << N_i << "*" << N_j
|
||||
<< " (filesize " << sizeString(nt*N_i*N_j*sizeof(HADRONS_A2AM_IO_TYPE))
|
||||
<< "/EM field)" << std::endl;
|
||||
|
||||
// preparing "B" complexified fields
|
||||
startTimer("Complexify EM fields");
|
||||
envGetTmp(std::vector<ComplexField>, B0);
|
||||
envGetTmp(std::vector<ComplexField>, B1);
|
||||
for (unsigned int i = 0; i < par().emField.size(); ++i)
|
||||
{
|
||||
auto &A = envGet(EmField, par().emField[i]);
|
||||
envGetTmp(ComplexField, Amu);
|
||||
|
||||
B0[i] = peekLorentz(A, 0);
|
||||
B0[i] += timesI(peekLorentz(A, 1));
|
||||
B1[i] = peekLorentz(A, 2);
|
||||
B1[i] += timesI(peekLorentz(A, 3));
|
||||
}
|
||||
stopTimer("Complexify EM fields");
|
||||
|
||||
// I/O name & metadata lambdas
|
||||
auto ionameFn = [this](const unsigned int em, const unsigned int dummy)
|
||||
{
|
||||
return par().emField[em];
|
||||
};
|
||||
|
||||
auto filenameFn = [this, &ionameFn](const unsigned int em, const unsigned int dummy)
|
||||
{
|
||||
return par().output + "." + std::to_string(vm().getTrajectory())
|
||||
+ "/" + ionameFn(em, dummy) + ".h5";
|
||||
};
|
||||
|
||||
auto metadataFn = [this](const unsigned int em, const unsigned int dummy)
|
||||
{
|
||||
A2AAslashFieldMetadata md;
|
||||
|
||||
md.emFieldName = par().emField[em];
|
||||
|
||||
return md;
|
||||
};
|
||||
|
||||
// executing computation
|
||||
Kernel kernel(B0, B1, envGetGrid(FermionField));
|
||||
|
||||
envGetTmp(Computation, computation);
|
||||
computation.execute(left, right, kernel, ionameFn, filenameFn, metadataFn);
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MContraction_A2AAslashField_hpp_
|
35
Hadrons/Modules/MContraction/A2AMesonField.cc
Normal file
35
Hadrons/Modules/MContraction/A2AMesonField.cc
Normal file
@ -0,0 +1,35 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/A2AMesonField.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MContraction/A2AMesonField.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MContraction;
|
||||
|
||||
template class Grid::Hadrons::MContraction::TA2AMesonField<FIMPL>;
|
315
Hadrons/Modules/MContraction/A2AMesonField.hpp
Normal file
315
Hadrons/Modules/MContraction/A2AMesonField.hpp
Normal file
@ -0,0 +1,315 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/A2AMesonField.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
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_MContraction_A2AMesonField_hpp_
|
||||
#define Hadrons_MContraction_A2AMesonField_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Hadrons/A2AMatrix.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* All-to-all meson field creation *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MContraction)
|
||||
|
||||
class A2AMesonFieldPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(A2AMesonFieldPar,
|
||||
int, cacheBlock,
|
||||
int, block,
|
||||
std::string, left,
|
||||
std::string, right,
|
||||
std::string, output,
|
||||
std::string, gammas,
|
||||
std::vector<std::string>, mom);
|
||||
};
|
||||
|
||||
class A2AMesonFieldMetadata: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(A2AMesonFieldMetadata,
|
||||
std::vector<RealF>, momentum,
|
||||
Gamma::Algebra, gamma);
|
||||
};
|
||||
|
||||
template <typename T, typename FImpl>
|
||||
class MesonFieldKernel: public A2AKernel<T, typename FImpl::FermionField>
|
||||
{
|
||||
public:
|
||||
typedef typename FImpl::FermionField FermionField;
|
||||
public:
|
||||
MesonFieldKernel(const std::vector<Gamma::Algebra> &gamma,
|
||||
const std::vector<LatticeComplex> &mom,
|
||||
GridBase *grid)
|
||||
: gamma_(gamma), mom_(mom), grid_(grid)
|
||||
{
|
||||
vol_ = 1.;
|
||||
for (auto &d: grid_->GlobalDimensions())
|
||||
{
|
||||
vol_ *= d;
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~MesonFieldKernel(void) = default;
|
||||
virtual void operator()(A2AMatrixSet<T> &m, const FermionField *left,
|
||||
const FermionField *right,
|
||||
const unsigned int orthogDim, double &t)
|
||||
{
|
||||
A2Autils<FImpl>::MesonField(m, left, right, gamma_, mom_, orthogDim, &t);
|
||||
}
|
||||
|
||||
virtual double flops(const unsigned int blockSizei, const unsigned int blockSizej)
|
||||
{
|
||||
return vol_*(2*8.0+6.0+8.0*mom_.size())*blockSizei*blockSizej*gamma_.size();
|
||||
}
|
||||
|
||||
virtual double bytes(const unsigned int blockSizei, const unsigned int blockSizej)
|
||||
{
|
||||
return vol_*(12.0*sizeof(T))*blockSizei*blockSizej
|
||||
+ vol_*(2.0*sizeof(T)*mom_.size())*blockSizei*blockSizej*gamma_.size();
|
||||
}
|
||||
private:
|
||||
const std::vector<Gamma::Algebra> &gamma_;
|
||||
const std::vector<LatticeComplex> &mom_;
|
||||
GridBase *grid_;
|
||||
double vol_;
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TA2AMesonField : public Module<A2AMesonFieldPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
typedef A2AMatrixBlockComputation<Complex,
|
||||
FermionField,
|
||||
A2AMesonFieldMetadata,
|
||||
HADRONS_A2AM_IO_TYPE> Computation;
|
||||
typedef MesonFieldKernel<Complex, FImpl> Kernel;
|
||||
public:
|
||||
// constructor
|
||||
TA2AMesonField(const std::string name);
|
||||
// destructor
|
||||
virtual ~TA2AMesonField(void){};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
private:
|
||||
bool hasPhase_{false};
|
||||
std::string momphName_;
|
||||
std::vector<Gamma::Algebra> gamma_;
|
||||
std::vector<std::vector<Real>> mom_;
|
||||
};
|
||||
|
||||
MODULE_REGISTER(A2AMesonField, ARG(TA2AMesonField<FIMPL>), MContraction);
|
||||
|
||||
/******************************************************************************
|
||||
* TA2AMesonField implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TA2AMesonField<FImpl>::TA2AMesonField(const std::string name)
|
||||
: Module<A2AMesonFieldPar>(name)
|
||||
, momphName_(name + "_momph")
|
||||
{
|
||||
}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TA2AMesonField<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().left, par().right};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TA2AMesonField<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TA2AMesonField<FImpl>::setup(void)
|
||||
{
|
||||
gamma_.clear();
|
||||
mom_.clear();
|
||||
if (par().gammas == "all")
|
||||
{
|
||||
gamma_ = {
|
||||
Gamma::Algebra::Gamma5,
|
||||
Gamma::Algebra::Identity,
|
||||
Gamma::Algebra::GammaX,
|
||||
Gamma::Algebra::GammaY,
|
||||
Gamma::Algebra::GammaZ,
|
||||
Gamma::Algebra::GammaT,
|
||||
Gamma::Algebra::GammaXGamma5,
|
||||
Gamma::Algebra::GammaYGamma5,
|
||||
Gamma::Algebra::GammaZGamma5,
|
||||
Gamma::Algebra::GammaTGamma5,
|
||||
Gamma::Algebra::SigmaXY,
|
||||
Gamma::Algebra::SigmaXZ,
|
||||
Gamma::Algebra::SigmaXT,
|
||||
Gamma::Algebra::SigmaYZ,
|
||||
Gamma::Algebra::SigmaYT,
|
||||
Gamma::Algebra::SigmaZT
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
gamma_ = strToVec<Gamma::Algebra>(par().gammas);
|
||||
}
|
||||
for (auto &pstr: par().mom)
|
||||
{
|
||||
auto p = strToVec<Real>(pstr);
|
||||
|
||||
if (p.size() != env().getNd() - 1)
|
||||
{
|
||||
HADRONS_ERROR(Size, "Momentum has " + std::to_string(p.size())
|
||||
+ " components instead of "
|
||||
+ std::to_string(env().getNd() - 1));
|
||||
}
|
||||
mom_.push_back(p);
|
||||
}
|
||||
envCache(std::vector<ComplexField>, momphName_, 1,
|
||||
par().mom.size(), envGetGrid(ComplexField));
|
||||
envTmpLat(ComplexField, "coor");
|
||||
envTmp(Computation, "computation", 1, envGetGrid(FermionField),
|
||||
env().getNd() - 1, mom_.size(), gamma_.size(), par().block,
|
||||
par().cacheBlock, this);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TA2AMesonField<FImpl>::execute(void)
|
||||
{
|
||||
auto &left = envGet(std::vector<FermionField>, par().left);
|
||||
auto &right = envGet(std::vector<FermionField>, par().right);
|
||||
|
||||
int nt = env().getDim().back();
|
||||
int N_i = left.size();
|
||||
int N_j = right.size();
|
||||
int ngamma = gamma_.size();
|
||||
int nmom = mom_.size();
|
||||
int block = par().block;
|
||||
int cacheBlock = par().cacheBlock;
|
||||
|
||||
LOG(Message) << "Computing all-to-all meson fields" << std::endl;
|
||||
LOG(Message) << "Left: '" << par().left << "' Right: '" << par().right << "'" << std::endl;
|
||||
LOG(Message) << "Momenta:" << std::endl;
|
||||
for (auto &p: mom_)
|
||||
{
|
||||
LOG(Message) << " " << p << std::endl;
|
||||
}
|
||||
LOG(Message) << "Spin bilinears:" << std::endl;
|
||||
for (auto &g: gamma_)
|
||||
{
|
||||
LOG(Message) << " " << g << std::endl;
|
||||
}
|
||||
LOG(Message) << "Meson field size: " << nt << "*" << N_i << "*" << N_j
|
||||
<< " (filesize " << sizeString(nt*N_i*N_j*sizeof(HADRONS_A2AM_IO_TYPE))
|
||||
<< "/momentum/bilinear)" << std::endl;
|
||||
|
||||
auto &ph = envGet(std::vector<ComplexField>, momphName_);
|
||||
|
||||
if (!hasPhase_)
|
||||
{
|
||||
startTimer("Momentum phases");
|
||||
for (unsigned int j = 0; j < nmom; ++j)
|
||||
{
|
||||
Complex i(0.0,1.0);
|
||||
std::vector<Real> p;
|
||||
|
||||
envGetTmp(ComplexField, coor);
|
||||
ph[j] = Zero();
|
||||
for(unsigned int mu = 0; mu < mom_[j].size(); mu++)
|
||||
{
|
||||
LatticeCoordinate(coor, mu);
|
||||
ph[j] = ph[j] + (mom_[j][mu]/env().getDim(mu))*coor;
|
||||
}
|
||||
ph[j] = exp((Real)(2*M_PI)*i*ph[j]);
|
||||
}
|
||||
hasPhase_ = true;
|
||||
stopTimer("Momentum phases");
|
||||
}
|
||||
|
||||
auto ionameFn = [this](const unsigned int m, const unsigned int g)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << gamma_[g] << "_";
|
||||
for (unsigned int mu = 0; mu < mom_[m].size(); ++mu)
|
||||
{
|
||||
ss << mom_[m][mu] << ((mu == mom_[m].size() - 1) ? "" : "_");
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
};
|
||||
|
||||
auto filenameFn = [this, &ionameFn](const unsigned int m, const unsigned int g)
|
||||
{
|
||||
return par().output + "." + std::to_string(vm().getTrajectory())
|
||||
+ "/" + ionameFn(m, g) + ".h5";
|
||||
};
|
||||
|
||||
auto metadataFn = [this](const unsigned int m, const unsigned int g)
|
||||
{
|
||||
A2AMesonFieldMetadata md;
|
||||
|
||||
for (auto pmu: mom_[m])
|
||||
{
|
||||
md.momentum.push_back(pmu);
|
||||
}
|
||||
md.gamma = gamma_[g];
|
||||
|
||||
return md;
|
||||
};
|
||||
|
||||
Kernel kernel(gamma_, ph, envGetGrid(FermionField));
|
||||
|
||||
envGetTmp(Computation, computation);
|
||||
computation.execute(left, right, kernel, ionameFn, filenameFn, metadataFn);
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MContraction_A2AMesonField_hpp_
|
35
Hadrons/Modules/MContraction/Baryon.cc
Normal file
35
Hadrons/Modules/MContraction/Baryon.cc
Normal file
@ -0,0 +1,35 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/Baryon.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MContraction/Baryon.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MContraction;
|
||||
|
||||
template class Grid::Hadrons::MContraction::TBaryon<FIMPL,FIMPL,FIMPL>;
|
||||
|
140
Hadrons/Modules/MContraction/Baryon.hpp
Normal file
140
Hadrons/Modules/MContraction/Baryon.hpp
Normal file
@ -0,0 +1,140 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/Baryon.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.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 */
|
||||
|
||||
#ifndef Hadrons_MContraction_Baryon_hpp_
|
||||
#define Hadrons_MContraction_Baryon_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Baryon *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MContraction)
|
||||
|
||||
class BaryonPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(BaryonPar,
|
||||
std::string, q1,
|
||||
std::string, q2,
|
||||
std::string, q3,
|
||||
std::string, output);
|
||||
};
|
||||
|
||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
|
||||
class TBaryon: public Module<BaryonPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl1, 1);
|
||||
FERM_TYPE_ALIASES(FImpl2, 2);
|
||||
FERM_TYPE_ALIASES(FImpl3, 3);
|
||||
class Result: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
|
||||
std::vector<std::vector<std::vector<Complex>>>, corr);
|
||||
};
|
||||
public:
|
||||
// constructor
|
||||
TBaryon(const std::string name);
|
||||
// destructor
|
||||
virtual ~TBaryon(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(Baryon, ARG(TBaryon<FIMPL, FIMPL, FIMPL>), MContraction);
|
||||
|
||||
/******************************************************************************
|
||||
* TBaryon implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
|
||||
TBaryon<FImpl1, FImpl2, FImpl3>::TBaryon(const std::string name)
|
||||
: Module<BaryonPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
|
||||
std::vector<std::string> TBaryon<FImpl1, FImpl2, FImpl3>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> input = {par().q1, par().q2, par().q3};
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
|
||||
std::vector<std::string> TBaryon<FImpl1, FImpl2, FImpl3>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
|
||||
void TBaryon<FImpl1, FImpl2, FImpl3>::setup(void)
|
||||
{
|
||||
envTmpLat(LatticeComplex, "c");
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
|
||||
void TBaryon<FImpl1, FImpl2, FImpl3>::execute(void)
|
||||
{
|
||||
LOG(Message) << "Computing baryon contractions '" << getName() << "' using"
|
||||
<< " quarks '" << par().q1 << "', '" << par().q2 << "', and '"
|
||||
<< par().q3 << "'" << std::endl;
|
||||
|
||||
auto &q1 = envGet(PropagatorField1, par().q1);
|
||||
auto &q2 = envGet(PropagatorField2, par().q2);
|
||||
auto &q3 = envGet(PropagatorField3, par().q2);
|
||||
envGetTmp(LatticeComplex, c);
|
||||
Result result;
|
||||
|
||||
// FIXME: do contractions
|
||||
|
||||
// saveResult(par().output, "meson", result);
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MContraction_Baryon_hpp_
|
35
Hadrons/Modules/MContraction/DiscLoop.cc
Normal file
35
Hadrons/Modules/MContraction/DiscLoop.cc
Normal file
@ -0,0 +1,35 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/DiscLoop.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MContraction/DiscLoop.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MContraction;
|
||||
|
||||
template class Grid::Hadrons::MContraction::TDiscLoop<FIMPL>;
|
||||
|
143
Hadrons/Modules/MContraction/DiscLoop.hpp
Normal file
143
Hadrons/Modules/MContraction/DiscLoop.hpp
Normal file
@ -0,0 +1,143 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/DiscLoop.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.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 */
|
||||
|
||||
#ifndef Hadrons_MContraction_DiscLoop_hpp_
|
||||
#define Hadrons_MContraction_DiscLoop_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* DiscLoop *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MContraction)
|
||||
|
||||
class DiscLoopPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(DiscLoopPar,
|
||||
std::string, q_loop,
|
||||
Gamma::Algebra, gamma,
|
||||
std::string, output);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TDiscLoop: public Module<DiscLoopPar>
|
||||
{
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
class Result: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
|
||||
Gamma::Algebra, gamma,
|
||||
std::vector<Complex>, corr);
|
||||
};
|
||||
public:
|
||||
// constructor
|
||||
TDiscLoop(const std::string name);
|
||||
// destructor
|
||||
virtual ~TDiscLoop(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(DiscLoop, TDiscLoop<FIMPL>, MContraction);
|
||||
|
||||
/******************************************************************************
|
||||
* TDiscLoop implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TDiscLoop<FImpl>::TDiscLoop(const std::string name)
|
||||
: Module<DiscLoopPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TDiscLoop<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().q_loop};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TDiscLoop<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TDiscLoop<FImpl>::setup(void)
|
||||
{
|
||||
envTmpLat(LatticeComplex, "c");
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TDiscLoop<FImpl>::execute(void)
|
||||
{
|
||||
LOG(Message) << "Computing disconnected loop contraction '" << getName()
|
||||
<< "' using '" << par().q_loop << "' with " << par().gamma
|
||||
<< " insertion." << std::endl;
|
||||
|
||||
auto &q_loop = envGet(PropagatorField, par().q_loop);
|
||||
Gamma gamma(par().gamma);
|
||||
std::vector<TComplex> buf;
|
||||
Result result;
|
||||
|
||||
envGetTmp(LatticeComplex, c);
|
||||
c = trace(gamma*q_loop);
|
||||
sliceSum(c, buf, Tp);
|
||||
result.gamma = par().gamma;
|
||||
result.corr.resize(buf.size());
|
||||
for (unsigned int t = 0; t < buf.size(); ++t)
|
||||
{
|
||||
result.corr[t] = TensorRemove(buf[t]);
|
||||
}
|
||||
saveResult(par().output, "disc", result);
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MContraction_DiscLoop_hpp_
|
35
Hadrons/Modules/MContraction/Gamma3pt.cc
Normal file
35
Hadrons/Modules/MContraction/Gamma3pt.cc
Normal file
@ -0,0 +1,35 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/Gamma3pt.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MContraction/Gamma3pt.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MContraction;
|
||||
|
||||
template class Grid::Hadrons::MContraction::TGamma3pt<FIMPL,FIMPL,FIMPL>;
|
||||
|
184
Hadrons/Modules/MContraction/Gamma3pt.hpp
Normal file
184
Hadrons/Modules/MContraction/Gamma3pt.hpp
Normal file
@ -0,0 +1,184 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/Gamma3pt.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.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 */
|
||||
|
||||
#ifndef Hadrons_MContraction_Gamma3pt_hpp_
|
||||
#define Hadrons_MContraction_Gamma3pt_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/*
|
||||
* 3pt contraction with gamma matrix insertion.
|
||||
*
|
||||
* Schematic:
|
||||
*
|
||||
* q2 q3
|
||||
* /----<------*------<----¬
|
||||
* / gamma \
|
||||
* / \
|
||||
* i * * f
|
||||
* \ /
|
||||
* \ /
|
||||
* \----------->----------/
|
||||
* q1
|
||||
*
|
||||
* trace(g5*q1*adj(q2)*g5*gamma*q3)
|
||||
*
|
||||
* options:
|
||||
* - q1: sink smeared propagator, source at i
|
||||
* - q2: propagator, source at i
|
||||
* - q3: propagator, source at f
|
||||
* - gamma: gamma matrix to insert
|
||||
* - tSnk: sink position for propagator q1.
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* Gamma3pt *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MContraction)
|
||||
|
||||
class Gamma3ptPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Gamma3ptPar,
|
||||
std::string, q1,
|
||||
std::string, q2,
|
||||
std::string, q3,
|
||||
Gamma::Algebra, gamma,
|
||||
unsigned int, tSnk,
|
||||
std::string, output);
|
||||
};
|
||||
|
||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
|
||||
class TGamma3pt: public Module<Gamma3ptPar>
|
||||
{
|
||||
FERM_TYPE_ALIASES(FImpl1, 1);
|
||||
FERM_TYPE_ALIASES(FImpl2, 2);
|
||||
FERM_TYPE_ALIASES(FImpl3, 3);
|
||||
class Result: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
|
||||
Gamma::Algebra, gamma,
|
||||
std::vector<Complex>, corr);
|
||||
};
|
||||
public:
|
||||
// constructor
|
||||
TGamma3pt(const std::string name);
|
||||
// destructor
|
||||
virtual ~TGamma3pt(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(Gamma3pt, ARG(TGamma3pt<FIMPL, FIMPL, FIMPL>), MContraction);
|
||||
|
||||
/******************************************************************************
|
||||
* TGamma3pt implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
|
||||
TGamma3pt<FImpl1, FImpl2, FImpl3>::TGamma3pt(const std::string name)
|
||||
: Module<Gamma3ptPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
|
||||
std::vector<std::string> TGamma3pt<FImpl1, FImpl2, FImpl3>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().q1, par().q2, par().q3};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
|
||||
std::vector<std::string> TGamma3pt<FImpl1, FImpl2, FImpl3>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
|
||||
void TGamma3pt<FImpl1, FImpl2, FImpl3>::setup(void)
|
||||
{
|
||||
envTmpLat(LatticeComplex, "c");
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
|
||||
void TGamma3pt<FImpl1, FImpl2, FImpl3>::execute(void)
|
||||
{
|
||||
LOG(Message) << "Computing 3pt contractions '" << getName() << "' using"
|
||||
<< " quarks '" << par().q1 << "', '" << par().q2 << "' and '"
|
||||
<< par().q3 << "', with " << par().gamma << " insertion."
|
||||
<< std::endl;
|
||||
|
||||
// Initialise variables. q2 and q3 are normal propagators, q1 may be
|
||||
// sink smeared.
|
||||
auto &q1 = envGet(SlicedPropagator1, par().q1);
|
||||
auto &q2 = envGet(PropagatorField2, par().q2);
|
||||
auto &q3 = envGet(PropagatorField2, par().q3);
|
||||
Gamma g5(Gamma::Algebra::Gamma5);
|
||||
Gamma gamma(par().gamma);
|
||||
std::vector<TComplex> buf;
|
||||
Result result;
|
||||
|
||||
// Extract relevant timeslice of sinked propagator q1, then contract &
|
||||
// sum over all spacial positions of gamma insertion.
|
||||
SitePropagator1 q1Snk = q1[par().tSnk];
|
||||
envGetTmp(LatticeComplex, c);
|
||||
c = trace(g5*q1Snk*adj(q2)*(g5*gamma)*q3);
|
||||
sliceSum(c, buf, Tp);
|
||||
|
||||
result.gamma = par().gamma;
|
||||
result.corr.resize(buf.size());
|
||||
for (unsigned int t = 0; t < buf.size(); ++t)
|
||||
{
|
||||
result.corr[t] = TensorRemove(buf[t]);
|
||||
}
|
||||
saveResult(par().output, "gamma3pt", result);
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MContraction_Gamma3pt_hpp_
|
35
Hadrons/Modules/MContraction/Meson.cc
Normal file
35
Hadrons/Modules/MContraction/Meson.cc
Normal file
@ -0,0 +1,35 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/Meson.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MContraction/Meson.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MContraction;
|
||||
|
||||
template class Grid::Hadrons::MContraction::TMeson<FIMPL,FIMPL>;
|
||||
|
249
Hadrons/Modules/MContraction/Meson.hpp
Normal file
249
Hadrons/Modules/MContraction/Meson.hpp
Normal file
@ -0,0 +1,249 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/Meson.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.com>
|
||||
Author: Vera Guelpers <vmg1n14@soton.ac.uk>
|
||||
|
||||
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_MContraction_Meson_hpp_
|
||||
#define Hadrons_MContraction_Meson_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/*
|
||||
|
||||
Meson contractions
|
||||
-----------------------------
|
||||
|
||||
* options:
|
||||
- q1: input propagator 1 (string)
|
||||
- q2: input propagator 2 (string)
|
||||
- gammas: gamma products to insert at sink & source, pairs of gamma matrices
|
||||
(space-separated strings) in round brackets (i.e. (g_sink g_src)),
|
||||
in a sequence (e.g. "(Gamma5 Gamma5)(Gamma5 GammaT)").
|
||||
|
||||
Special values: "all" - perform all possible contractions.
|
||||
- sink: module to compute the sink to use in contraction (string).
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* TMeson *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MContraction)
|
||||
|
||||
typedef std::pair<Gamma::Algebra, Gamma::Algebra> GammaPair;
|
||||
|
||||
class MesonPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(MesonPar,
|
||||
std::string, q1,
|
||||
std::string, q2,
|
||||
std::string, gammas,
|
||||
std::string, sink,
|
||||
std::string, output);
|
||||
};
|
||||
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
class TMeson: public Module<MesonPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl1, 1);
|
||||
FERM_TYPE_ALIASES(FImpl2, 2);
|
||||
BASIC_TYPE_ALIASES(ScalarImplCR, Scalar);
|
||||
SINK_TYPE_ALIASES(Scalar);
|
||||
class Result: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
|
||||
Gamma::Algebra, gamma_snk,
|
||||
Gamma::Algebra, gamma_src,
|
||||
std::vector<Complex>, corr);
|
||||
};
|
||||
public:
|
||||
// constructor
|
||||
TMeson(const std::string name);
|
||||
// destructor
|
||||
virtual ~TMeson(void) {};
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
virtual void parseGammaString(std::vector<GammaPair> &gammaList);
|
||||
protected:
|
||||
// execution
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(Meson, ARG(TMeson<FIMPL, FIMPL>), MContraction);
|
||||
|
||||
/******************************************************************************
|
||||
* TMeson implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
TMeson<FImpl1, FImpl2>::TMeson(const std::string name)
|
||||
: Module<MesonPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
std::vector<std::string> TMeson<FImpl1, FImpl2>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> input = {par().q1, par().q2, par().sink};
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
std::vector<std::string> TMeson<FImpl1, FImpl2>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> output = {};
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
void TMeson<FImpl1, FImpl2>::parseGammaString(std::vector<GammaPair> &gammaList)
|
||||
{
|
||||
gammaList.clear();
|
||||
// Determine gamma matrices to insert at source/sink.
|
||||
if (par().gammas.compare("all") == 0)
|
||||
{
|
||||
// Do all contractions.
|
||||
for (unsigned int i = 1; i < Gamma::nGamma; i += 2)
|
||||
{
|
||||
for (unsigned int j = 1; j < Gamma::nGamma; j += 2)
|
||||
{
|
||||
gammaList.push_back(std::make_pair((Gamma::Algebra)i,
|
||||
(Gamma::Algebra)j));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Parse individual contractions from input string.
|
||||
gammaList = strToVec<GammaPair>(par().gammas);
|
||||
}
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
void TMeson<FImpl1, FImpl2>::setup(void)
|
||||
{
|
||||
envTmpLat(LatticeComplex, "c");
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
#define mesonConnected(q1, q2, gSnk, gSrc) \
|
||||
(g5*(gSnk))*(q1)*(adj(gSrc)*g5)*adj(q2)
|
||||
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
void TMeson<FImpl1, FImpl2>::execute(void)
|
||||
{
|
||||
LOG(Message) << "Computing meson contractions '" << getName() << "' using"
|
||||
<< " quarks '" << par().q1 << "' and '" << par().q2 << "'"
|
||||
<< std::endl;
|
||||
|
||||
std::vector<TComplex> buf;
|
||||
std::vector<Result> result;
|
||||
Gamma g5(Gamma::Algebra::Gamma5);
|
||||
std::vector<GammaPair> gammaList;
|
||||
int nt = env().getDim(Tp);
|
||||
|
||||
parseGammaString(gammaList);
|
||||
result.resize(gammaList.size());
|
||||
for (unsigned int i = 0; i < result.size(); ++i)
|
||||
{
|
||||
result[i].gamma_snk = gammaList[i].first;
|
||||
result[i].gamma_src = gammaList[i].second;
|
||||
result[i].corr.resize(nt);
|
||||
}
|
||||
if (envHasType(SlicedPropagator1, par().q1) and
|
||||
envHasType(SlicedPropagator2, par().q2))
|
||||
{
|
||||
auto &q1 = envGet(SlicedPropagator1, par().q1);
|
||||
auto &q2 = envGet(SlicedPropagator2, par().q2);
|
||||
|
||||
LOG(Message) << "(propagator already sinked)" << std::endl;
|
||||
for (unsigned int i = 0; i < result.size(); ++i)
|
||||
{
|
||||
Gamma gSnk(gammaList[i].first);
|
||||
Gamma gSrc(gammaList[i].second);
|
||||
|
||||
for (unsigned int t = 0; t < buf.size(); ++t)
|
||||
{
|
||||
result[i].corr[t] = TensorRemove(trace(mesonConnected(q1[t], q2[t], gSnk, gSrc)));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto &q1 = envGet(PropagatorField1, par().q1);
|
||||
auto &q2 = envGet(PropagatorField2, par().q2);
|
||||
|
||||
envGetTmp(LatticeComplex, c);
|
||||
LOG(Message) << "(using sink '" << par().sink << "')" << std::endl;
|
||||
for (unsigned int i = 0; i < result.size(); ++i)
|
||||
{
|
||||
Gamma gSnk(gammaList[i].first);
|
||||
Gamma gSrc(gammaList[i].second);
|
||||
std::string ns;
|
||||
|
||||
ns = vm().getModuleNamespace(env().getObjectModule(par().sink));
|
||||
if (ns == "MSource")
|
||||
{
|
||||
PropagatorField1 &sink = envGet(PropagatorField1, par().sink);
|
||||
|
||||
c = trace(mesonConnected(q1, q2, gSnk, gSrc)*sink);
|
||||
sliceSum(c, buf, Tp);
|
||||
}
|
||||
else if (ns == "MSink")
|
||||
{
|
||||
SinkFnScalar &sink = envGet(SinkFnScalar, par().sink);
|
||||
|
||||
c = trace(mesonConnected(q1, q2, gSnk, gSrc));
|
||||
buf = sink(c);
|
||||
}
|
||||
for (unsigned int t = 0; t < buf.size(); ++t)
|
||||
{
|
||||
result[i].corr[t] = TensorRemove(buf[t]);
|
||||
}
|
||||
}
|
||||
}
|
||||
saveResult(par().output, "meson", result);
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MContraction_Meson_hpp_
|
35
Hadrons/Modules/MContraction/WardIdentity.cc
Normal file
35
Hadrons/Modules/MContraction/WardIdentity.cc
Normal file
@ -0,0 +1,35 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/WardIdentity.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MContraction/WardIdentity.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MContraction;
|
||||
|
||||
template class Grid::Hadrons::MContraction::TWardIdentity<FIMPL>;
|
||||
|
224
Hadrons/Modules/MContraction/WardIdentity.hpp
Normal file
224
Hadrons/Modules/MContraction/WardIdentity.hpp
Normal file
@ -0,0 +1,224 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/WardIdentity.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.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 */
|
||||
|
||||
#ifndef Hadrons_MContraction_WardIdentity_hpp_
|
||||
#define Hadrons_MContraction_WardIdentity_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/*
|
||||
Ward Identity contractions
|
||||
-----------------------------
|
||||
|
||||
* options:
|
||||
- q: propagator, 5D if available (string)
|
||||
- action: action module used for propagator solution (string)
|
||||
- mass: mass of quark (double)
|
||||
- test_axial: whether or not to test PCAC relation.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* WardIdentity *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MContraction)
|
||||
|
||||
class WardIdentityPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(WardIdentityPar,
|
||||
std::string, q,
|
||||
std::string, action,
|
||||
double, mass,
|
||||
bool, test_axial);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TWardIdentity: public Module<WardIdentityPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TWardIdentity(const std::string name);
|
||||
// destructor
|
||||
virtual ~TWardIdentity(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
private:
|
||||
unsigned int Ls_;
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(WardIdentity, TWardIdentity<FIMPL>, MContraction);
|
||||
|
||||
/******************************************************************************
|
||||
* TWardIdentity implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TWardIdentity<FImpl>::TWardIdentity(const std::string name)
|
||||
: Module<WardIdentityPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TWardIdentity<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().q, par().action};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TWardIdentity<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TWardIdentity<FImpl>::setup(void)
|
||||
{
|
||||
Ls_ = env().getObjectLs(par().q);
|
||||
if (Ls_ != env().getObjectLs(par().action))
|
||||
{
|
||||
HADRONS_ERROR(Size, "Ls mismatch between quark action and propagator");
|
||||
}
|
||||
envTmpLat(PropagatorField, "tmp");
|
||||
envTmpLat(PropagatorField, "vector_WI");
|
||||
if (par().test_axial)
|
||||
{
|
||||
envTmpLat(PropagatorField, "psi");
|
||||
envTmpLat(LatticeComplex, "PP");
|
||||
envTmpLat(LatticeComplex, "axial_defect");
|
||||
envTmpLat(LatticeComplex, "PJ5q");
|
||||
}
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TWardIdentity<FImpl>::execute(void)
|
||||
{
|
||||
LOG(Message) << "Performing Ward Identity checks for quark '" << par().q
|
||||
<< "'." << std::endl;
|
||||
|
||||
auto &q = envGet(PropagatorField, par().q);
|
||||
auto &act = envGet(FMat, par().action);
|
||||
Gamma g5(Gamma::Algebra::Gamma5);
|
||||
|
||||
// Compute D_mu V_mu, D here is backward derivative.
|
||||
envGetTmp(PropagatorField, tmp);
|
||||
envGetTmp(PropagatorField, vector_WI);
|
||||
vector_WI = Zero();
|
||||
for (unsigned int mu = 0; mu < Nd; ++mu)
|
||||
{
|
||||
act.ContractConservedCurrent(q, q, tmp, Current::Vector, mu);
|
||||
tmp -= Cshift(tmp, mu, -1);
|
||||
vector_WI += tmp;
|
||||
}
|
||||
|
||||
// Test ward identity D_mu V_mu = 0;
|
||||
LOG(Message) << "Vector Ward Identity check Delta_mu V_mu = "
|
||||
<< norm2(vector_WI) << std::endl;
|
||||
|
||||
if (par().test_axial)
|
||||
{
|
||||
envGetTmp(PropagatorField, psi);
|
||||
envGetTmp(LatticeComplex, PP);
|
||||
envGetTmp(LatticeComplex, axial_defect);
|
||||
envGetTmp(LatticeComplex, PJ5q);
|
||||
std::vector<TComplex> axial_buf;
|
||||
|
||||
// Compute <P|D_mu A_mu>, D is backwards derivative.
|
||||
axial_defect = Zero();
|
||||
for (unsigned int mu = 0; mu < Nd; ++mu)
|
||||
{
|
||||
act.ContractConservedCurrent(q, q, tmp, Current::Axial, mu);
|
||||
tmp -= Cshift(tmp, mu, -1);
|
||||
axial_defect += trace(g5*tmp);
|
||||
}
|
||||
|
||||
// Get <P|J5q> for 5D (Zero(); for 4D) and <P|P>.
|
||||
PJ5q = Zero();
|
||||
if (Ls_ > 1)
|
||||
{
|
||||
// <P|P>
|
||||
ExtractSlice(tmp, q, 0, 0);
|
||||
psi = 0.5 * (tmp - g5*tmp);
|
||||
ExtractSlice(tmp, q, Ls_ - 1, 0);
|
||||
psi += 0.5 * (tmp + g5*tmp);
|
||||
PP = trace(adj(psi)*psi);
|
||||
|
||||
// <P|5Jq>
|
||||
ExtractSlice(tmp, q, Ls_/2 - 1, 0);
|
||||
psi = 0.5 * (tmp + g5*tmp);
|
||||
ExtractSlice(tmp, q, Ls_/2, 0);
|
||||
psi += 0.5 * (tmp - g5*tmp);
|
||||
PJ5q = trace(adj(psi)*psi);
|
||||
}
|
||||
else
|
||||
{
|
||||
PP = trace(adj(q)*q);
|
||||
}
|
||||
|
||||
// Test ward identity <P|D_mu A_mu> = 2m<P|P> + 2<P|J5q>
|
||||
LOG(Message) << "|D_mu A_mu|^2 = " << norm2(axial_defect) << std::endl;
|
||||
LOG(Message) << "|PP|^2 = " << norm2(PP) << std::endl;
|
||||
LOG(Message) << "|PJ5q|^2 = " << norm2(PJ5q) << std::endl;
|
||||
LOG(Message) << "Axial Ward Identity defect Delta_mu A_mu = "
|
||||
<< norm2(axial_defect) << std::endl;
|
||||
|
||||
// Axial defect by timeslice.
|
||||
axial_defect -= 2.*(par().mass*PP + PJ5q);
|
||||
LOG(Message) << "Check Axial defect by timeslice" << std::endl;
|
||||
sliceSum(axial_defect, axial_buf, Tp);
|
||||
for (int t = 0; t < axial_buf.size(); ++t)
|
||||
{
|
||||
LOG(Message) << "t = " << t << ": "
|
||||
<< TensorRemove(axial_buf[t]) << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_WardIdentity_hpp_
|
118
Hadrons/Modules/MContraction/WeakHamiltonian.hpp
Normal file
118
Hadrons/Modules/MContraction/WeakHamiltonian.hpp
Normal file
@ -0,0 +1,118 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/WeakHamiltonian.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.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 */
|
||||
|
||||
#ifndef Hadrons_MContraction_WeakHamiltonian_hpp_
|
||||
#define Hadrons_MContraction_WeakHamiltonian_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* WeakHamiltonian *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MContraction)
|
||||
|
||||
/*******************************************************************************
|
||||
* Utilities for contractions involving the Weak Hamiltonian.
|
||||
******************************************************************************/
|
||||
//// Sum and store correlator.
|
||||
#define MAKE_DIAG(exp, buf, res, n)\
|
||||
sliceSum(exp, buf, Tp);\
|
||||
res.name = (n);\
|
||||
res.corr.resize(buf.size());\
|
||||
for (unsigned int t = 0; t < buf.size(); ++t)\
|
||||
{\
|
||||
res.corr[t] = TensorRemove(buf[t]);\
|
||||
}
|
||||
|
||||
//// Contraction of mu index: use 'mu' variable in exp.
|
||||
#define SUM_MU(buf,exp)\
|
||||
buf = Zero(); \
|
||||
for (unsigned int mu = 0; mu < ndim; ++mu)\
|
||||
{\
|
||||
buf += exp;\
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
i_V = 0,
|
||||
i_A = 1,
|
||||
n_i = 2
|
||||
};
|
||||
|
||||
class WeakHamiltonianPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(WeakHamiltonianPar,
|
||||
std::string, q1,
|
||||
std::string, q2,
|
||||
std::string, q3,
|
||||
std::string, q4,
|
||||
unsigned int, tSnk,
|
||||
std::string, output);
|
||||
};
|
||||
|
||||
#define MAKE_WEAK_MODULE(modname)\
|
||||
class T##modname: public Module<WeakHamiltonianPar>\
|
||||
{\
|
||||
public:\
|
||||
FERM_TYPE_ALIASES(FIMPL,)\
|
||||
class Result: Serializable\
|
||||
{\
|
||||
public:\
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Result,\
|
||||
std::string, name,\
|
||||
std::vector<Complex>, corr);\
|
||||
};\
|
||||
public:\
|
||||
/* constructor */ \
|
||||
T##modname(const std::string name);\
|
||||
/* destructor */ \
|
||||
virtual ~T##modname(void) {};\
|
||||
/* dependency relation */ \
|
||||
virtual std::vector<std::string> getInput(void);\
|
||||
virtual std::vector<std::string> getOutput(void);\
|
||||
public:\
|
||||
std::vector<std::string> VA_label = {"V", "A"};\
|
||||
protected:\
|
||||
/* setup */ \
|
||||
virtual void setup(void);\
|
||||
/* execution */ \
|
||||
virtual void execute(void);\
|
||||
};\
|
||||
MODULE_REGISTER(modname, T##modname, MContraction);
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MContraction_WeakHamiltonian_hpp_
|
151
Hadrons/Modules/MContraction/WeakHamiltonianEye.cc
Normal file
151
Hadrons/Modules/MContraction/WeakHamiltonianEye.cc
Normal file
@ -0,0 +1,151 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/WeakHamiltonianEye.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.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 */
|
||||
|
||||
#include <Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MContraction;
|
||||
|
||||
/*
|
||||
* Weak Hamiltonian current-current contractions, Eye-type.
|
||||
*
|
||||
* These contractions are generated by the Q1 and Q2 operators in the physical
|
||||
* basis (see e.g. Fig 3 of arXiv:1507.03094).
|
||||
*
|
||||
* Schematics: q4 |
|
||||
* /-<-¬ |
|
||||
* / \ | q2 q3
|
||||
* \ / | /----<------*------<----¬
|
||||
* q2 \ / q3 | / /-*-¬ \
|
||||
* /-----<-----* *-----<----¬ | / / \ \
|
||||
* i * H_W * f | i * \ / q4 * f
|
||||
* \ / | \ \->-/ /
|
||||
* \ / | \ /
|
||||
* \---------->---------/ | \----------->----------/
|
||||
* q1 | q1
|
||||
* |
|
||||
* Saucer (S) | Eye (E)
|
||||
*
|
||||
* S: trace(q3*g5*q1*adj(q2)*g5*gL[mu][p_1]*q4*gL[mu][p_2])
|
||||
* E: trace(q3*g5*q1*adj(q2)*g5*gL[mu][p_1])*trace(q4*gL[mu][p_2])
|
||||
*
|
||||
* Note q1 must be sink smeared.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* TWeakHamiltonianEye implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
TWeakHamiltonianEye::TWeakHamiltonianEye(const std::string name)
|
||||
: Module<WeakHamiltonianPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> TWeakHamiltonianEye::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().q1, par().q2, par().q3, par().q4};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
std::vector<std::string> TWeakHamiltonianEye::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
void TWeakHamiltonianEye::setup(void)
|
||||
{
|
||||
unsigned int ndim = env().getNd();
|
||||
|
||||
envTmpLat(LatticeComplex, "expbuf");
|
||||
envTmpLat(PropagatorField, "tmp1");
|
||||
envTmpLat(LatticeComplex, "tmp2");
|
||||
envTmp(std::vector<PropagatorField>, "S_body", 1, ndim, PropagatorField(env().getGrid()));
|
||||
envTmp(std::vector<PropagatorField>, "S_loop", 1, ndim, PropagatorField(env().getGrid()));
|
||||
envTmp(std::vector<LatticeComplex>, "E_body", 1, ndim, LatticeComplex(env().getGrid()));
|
||||
envTmp(std::vector<LatticeComplex>, "E_loop", 1, ndim, LatticeComplex(env().getGrid()));
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void TWeakHamiltonianEye::execute(void)
|
||||
{
|
||||
LOG(Message) << "Computing Weak Hamiltonian (Eye type) contractions '"
|
||||
<< getName() << "' using quarks '" << par().q1 << "', '"
|
||||
<< par().q2 << ", '" << par().q3 << "' and '" << par().q4
|
||||
<< "'." << std::endl;
|
||||
|
||||
auto &q1 = envGet(SlicedPropagator, par().q1);
|
||||
auto &q2 = envGet(PropagatorField, par().q2);
|
||||
auto &q3 = envGet(PropagatorField, par().q3);
|
||||
auto &q4 = envGet(PropagatorField, par().q4);
|
||||
Gamma g5 = Gamma(Gamma::Algebra::Gamma5);
|
||||
std::vector<TComplex> corrbuf;
|
||||
std::vector<Result> result(n_eye_diag);
|
||||
unsigned int ndim = env().getNd();
|
||||
|
||||
envGetTmp(LatticeComplex, expbuf);
|
||||
envGetTmp(PropagatorField, tmp1);
|
||||
envGetTmp(LatticeComplex, tmp2);
|
||||
envGetTmp(std::vector<PropagatorField>, S_body);
|
||||
envGetTmp(std::vector<PropagatorField>, S_loop);
|
||||
envGetTmp(std::vector<LatticeComplex>, E_body);
|
||||
envGetTmp(std::vector<LatticeComplex>, E_loop);
|
||||
|
||||
// Get sink timeslice of q1.
|
||||
SitePropagator q1Snk = q1[par().tSnk];
|
||||
|
||||
// Setup for S-type contractions.
|
||||
for (int mu = 0; mu < ndim; ++mu)
|
||||
{
|
||||
S_body[mu] = MAKE_SE_BODY(q1Snk, q2, q3, GammaL(Gamma::gmu[mu]));
|
||||
S_loop[mu] = MAKE_SE_LOOP(q4, GammaL(Gamma::gmu[mu]));
|
||||
}
|
||||
|
||||
// Perform S-type contractions.
|
||||
SUM_MU(expbuf, trace(S_body[mu]*S_loop[mu]))
|
||||
MAKE_DIAG(expbuf, corrbuf, result[S_diag], "HW_S")
|
||||
|
||||
// Recycle sub-expressions for E-type contractions.
|
||||
for (unsigned int mu = 0; mu < ndim; ++mu)
|
||||
{
|
||||
E_body[mu] = trace(S_body[mu]);
|
||||
E_loop[mu] = trace(S_loop[mu]);
|
||||
}
|
||||
|
||||
// Perform E-type contractions.
|
||||
SUM_MU(expbuf, E_body[mu]*E_loop[mu])
|
||||
MAKE_DIAG(expbuf, corrbuf, result[E_diag], "HW_E")
|
||||
|
||||
// IO
|
||||
saveResult(par().output, "HW_Eye", result);
|
||||
}
|
59
Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp
Normal file
59
Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp
Normal file
@ -0,0 +1,59 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.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 */
|
||||
|
||||
#ifndef Hadrons_MContraction_WeakHamiltonianEye_hpp_
|
||||
#define Hadrons_MContraction_WeakHamiltonianEye_hpp_
|
||||
|
||||
#include <Hadrons/Modules/MContraction/WeakHamiltonian.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* WeakHamiltonianEye *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MContraction)
|
||||
|
||||
enum
|
||||
{
|
||||
S_diag = 0,
|
||||
E_diag = 1,
|
||||
n_eye_diag = 2
|
||||
};
|
||||
|
||||
// Saucer and Eye subdiagram contractions.
|
||||
#define MAKE_SE_BODY(Q_1, Q_2, Q_3, gamma) (Q_3*g5*Q_1*adj(Q_2)*g5*gamma)
|
||||
#define MAKE_SE_LOOP(Q_loop, gamma) (Q_loop*gamma)
|
||||
|
||||
MAKE_WEAK_MODULE(WeakHamiltonianEye)
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MContraction_WeakHamiltonianEye_hpp_
|
148
Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc
Normal file
148
Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc
Normal file
@ -0,0 +1,148 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.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 */
|
||||
|
||||
#include <Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MContraction;
|
||||
|
||||
/*
|
||||
* Weak Hamiltonian current-current contractions, Non-Eye-type.
|
||||
*
|
||||
* These contractions are generated by the Q1 and Q2 operators in the physical
|
||||
* basis (see e.g. Fig 3 of arXiv:1507.03094).
|
||||
*
|
||||
* Schematic:
|
||||
* q2 q3 | q2 q3
|
||||
* /--<--¬ /--<--¬ | /--<--¬ /--<--¬
|
||||
* / \ / \ | / \ / \
|
||||
* / \ / \ | / \ / \
|
||||
* / \ / \ | / \ / \
|
||||
* i * * H_W * f | i * * * H_W * f
|
||||
* \ * | | \ / \ /
|
||||
* \ / \ / | \ / \ /
|
||||
* \ / \ / | \ / \ /
|
||||
* \ / \ / | \-->--/ \-->--/
|
||||
* \-->--/ \-->--/ | q1 q4
|
||||
* q1 q4 |
|
||||
* Connected (C) | Wing (W)
|
||||
*
|
||||
* C: trace(q1*adj(q2)*g5*gL[mu]*q3*adj(q4)*g5*gL[mu])
|
||||
* W: trace(q1*adj(q2)*g5*gL[mu])*trace(q3*adj(q4)*g5*gL[mu])
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* TWeakHamiltonianNonEye implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
TWeakHamiltonianNonEye::TWeakHamiltonianNonEye(const std::string name)
|
||||
: Module<WeakHamiltonianPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> TWeakHamiltonianNonEye::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().q1, par().q2, par().q3, par().q4};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
std::vector<std::string> TWeakHamiltonianNonEye::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
void TWeakHamiltonianNonEye::setup(void)
|
||||
{
|
||||
unsigned int ndim = env().getNd();
|
||||
|
||||
envTmpLat(LatticeComplex, "expbuf");
|
||||
envTmpLat(PropagatorField, "tmp1");
|
||||
envTmpLat(LatticeComplex, "tmp2");
|
||||
envTmp(std::vector<PropagatorField>, "C_i_side_loop", 1, ndim, PropagatorField(env().getGrid()));
|
||||
envTmp(std::vector<PropagatorField>, "C_f_side_loop", 1, ndim, PropagatorField(env().getGrid()));
|
||||
envTmp(std::vector<LatticeComplex>, "W_i_side_loop", 1, ndim, LatticeComplex(env().getGrid()));
|
||||
envTmp(std::vector<LatticeComplex>, "W_f_side_loop", 1, ndim, LatticeComplex(env().getGrid()));
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void TWeakHamiltonianNonEye::execute(void)
|
||||
{
|
||||
LOG(Message) << "Computing Weak Hamiltonian (Non-Eye type) contractions '"
|
||||
<< getName() << "' using quarks '" << par().q1 << "', '"
|
||||
<< par().q2 << ", '" << par().q3 << "' and '" << par().q4
|
||||
<< "'." << std::endl;
|
||||
|
||||
auto &q1 = envGet(PropagatorField, par().q1);
|
||||
auto &q2 = envGet(PropagatorField, par().q2);
|
||||
auto &q3 = envGet(PropagatorField, par().q3);
|
||||
auto &q4 = envGet(PropagatorField, par().q4);
|
||||
Gamma g5 = Gamma(Gamma::Algebra::Gamma5);
|
||||
std::vector<TComplex> corrbuf;
|
||||
std::vector<Result> result(n_noneye_diag);
|
||||
unsigned int ndim = env().getNd();
|
||||
|
||||
envGetTmp(LatticeComplex, expbuf);
|
||||
envGetTmp(PropagatorField, tmp1);
|
||||
envGetTmp(LatticeComplex, tmp2);
|
||||
envGetTmp(std::vector<PropagatorField>, C_i_side_loop);
|
||||
envGetTmp(std::vector<PropagatorField>, C_f_side_loop);
|
||||
envGetTmp(std::vector<LatticeComplex>, W_i_side_loop);
|
||||
envGetTmp(std::vector<LatticeComplex>, W_f_side_loop);
|
||||
|
||||
// Setup for C-type contractions.
|
||||
for (int mu = 0; mu < ndim; ++mu)
|
||||
{
|
||||
C_i_side_loop[mu] = MAKE_CW_SUBDIAG(q1, q2, GammaL(Gamma::gmu[mu]));
|
||||
C_f_side_loop[mu] = MAKE_CW_SUBDIAG(q3, q4, GammaL(Gamma::gmu[mu]));
|
||||
}
|
||||
|
||||
// Perform C-type contractions.
|
||||
SUM_MU(expbuf, trace(C_i_side_loop[mu]*C_f_side_loop[mu]))
|
||||
MAKE_DIAG(expbuf, corrbuf, result[C_diag], "HW_C")
|
||||
|
||||
// Recycle sub-expressions for W-type contractions.
|
||||
for (unsigned int mu = 0; mu < ndim; ++mu)
|
||||
{
|
||||
W_i_side_loop[mu] = trace(C_i_side_loop[mu]);
|
||||
W_f_side_loop[mu] = trace(C_f_side_loop[mu]);
|
||||
}
|
||||
|
||||
// Perform W-type contractions.
|
||||
SUM_MU(expbuf, W_i_side_loop[mu]*W_f_side_loop[mu])
|
||||
MAKE_DIAG(expbuf, corrbuf, result[W_diag], "HW_W")
|
||||
|
||||
// IO
|
||||
saveResult(par().output, "HW_NonEye", result);
|
||||
}
|
58
Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp
Normal file
58
Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp
Normal file
@ -0,0 +1,58 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.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 */
|
||||
|
||||
#ifndef Hadrons_MContraction_WeakHamiltonianNonEye_hpp_
|
||||
#define Hadrons_MContraction_WeakHamiltonianNonEye_hpp_
|
||||
|
||||
#include <Hadrons/Modules/MContraction/WeakHamiltonian.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* WeakHamiltonianNonEye *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MContraction)
|
||||
|
||||
enum
|
||||
{
|
||||
W_diag = 0,
|
||||
C_diag = 1,
|
||||
n_noneye_diag = 2
|
||||
};
|
||||
|
||||
// Wing and Connected subdiagram contractions
|
||||
#define MAKE_CW_SUBDIAG(Q_1, Q_2, gamma) (Q_1*adj(Q_2)*g5*gamma)
|
||||
|
||||
MAKE_WEAK_MODULE(WeakHamiltonianNonEye)
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MContraction_WeakHamiltonianNonEye_hpp_
|
142
Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc
Normal file
142
Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc
Normal file
@ -0,0 +1,142 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.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 */
|
||||
|
||||
#include <Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MContraction;
|
||||
|
||||
/*
|
||||
* Weak Hamiltonian + current contractions, disconnected topology for neutral
|
||||
* mesons.
|
||||
*
|
||||
* These contractions are generated by operators Q_1,...,10 of the dS=1 Weak
|
||||
* Hamiltonian in the physical basis and an additional current J (see e.g.
|
||||
* Fig 11 of arXiv:1507.03094).
|
||||
*
|
||||
* Schematic:
|
||||
*
|
||||
* q2 q4 q3
|
||||
* /--<--¬ /---<--¬ /---<--¬
|
||||
* / \ / \ / \
|
||||
* i * * H_W | J * * f
|
||||
* \ / \ / \ /
|
||||
* \--->---/ \-------/ \------/
|
||||
* q1
|
||||
*
|
||||
* options
|
||||
* - q1: input propagator 1 (string)
|
||||
* - q2: input propagator 2 (string)
|
||||
* - q3: input propagator 3 (string), assumed to be sequential propagator
|
||||
* - q4: input propagator 4 (string), assumed to be a loop
|
||||
*
|
||||
* type 1: trace(q1*adj(q2)*g5*gL[mu])*trace(loop*gL[mu])*trace(q3*g5)
|
||||
* type 2: trace(q1*adj(q2)*g5*gL[mu]*loop*gL[mu])*trace(q3*g5)
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* TWeakNeutral4ptDisc implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
TWeakNeutral4ptDisc::TWeakNeutral4ptDisc(const std::string name)
|
||||
: Module<WeakHamiltonianPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> TWeakNeutral4ptDisc::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().q1, par().q2, par().q3, par().q4};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
std::vector<std::string> TWeakNeutral4ptDisc::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
void TWeakNeutral4ptDisc::setup(void)
|
||||
{
|
||||
unsigned int ndim = env().getNd();
|
||||
|
||||
envTmpLat(LatticeComplex, "expbuf");
|
||||
envTmpLat(PropagatorField, "tmp");
|
||||
envTmpLat(LatticeComplex, "curr");
|
||||
envTmp(std::vector<PropagatorField>, "meson", 1, ndim, PropagatorField(env().getGrid()));
|
||||
envTmp(std::vector<PropagatorField>, "loop", 1, ndim, PropagatorField(env().getGrid()));
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void TWeakNeutral4ptDisc::execute(void)
|
||||
{
|
||||
LOG(Message) << "Computing Weak Hamiltonian neutral disconnected contractions '"
|
||||
<< getName() << "' using quarks '" << par().q1 << "', '"
|
||||
<< par().q2 << ", '" << par().q3 << "' and '" << par().q4
|
||||
<< "'." << std::endl;
|
||||
|
||||
auto &q1 = envGet(PropagatorField, par().q1);
|
||||
auto &q2 = envGet(PropagatorField, par().q2);
|
||||
auto &q3 = envGet(PropagatorField, par().q3);
|
||||
auto &q4 = envGet(PropagatorField, par().q4);
|
||||
Gamma g5 = Gamma(Gamma::Algebra::Gamma5);
|
||||
std::vector<TComplex> corrbuf;
|
||||
std::vector<Result> result(n_neut_disc_diag);
|
||||
unsigned int ndim = env().getNd();
|
||||
|
||||
envGetTmp(LatticeComplex, expbuf);
|
||||
envGetTmp(PropagatorField, tmp);
|
||||
envGetTmp(LatticeComplex, curr);
|
||||
envGetTmp(std::vector<PropagatorField>, meson);
|
||||
envGetTmp(std::vector<PropagatorField>, loop);
|
||||
|
||||
// Setup for type 1 contractions.
|
||||
for (int mu = 0; mu < ndim; ++mu)
|
||||
{
|
||||
meson[mu] = MAKE_DISC_MESON(q1, q2, GammaL(Gamma::gmu[mu]));
|
||||
loop[mu] = MAKE_DISC_LOOP(q4, GammaL(Gamma::gmu[mu]));
|
||||
}
|
||||
curr = MAKE_DISC_CURR(q3, GammaL(Gamma::Algebra::Gamma5));
|
||||
|
||||
// Perform type 1 contractions.
|
||||
SUM_MU(expbuf, trace(meson[mu]*loop[mu]))
|
||||
expbuf *= curr;
|
||||
MAKE_DIAG(expbuf, corrbuf, result[neut_disc_1_diag], "HW_disc0_1")
|
||||
|
||||
// Perform type 2 contractions.
|
||||
SUM_MU(expbuf, trace(meson[mu])*trace(loop[mu]))
|
||||
expbuf *= curr;
|
||||
MAKE_DIAG(expbuf, corrbuf, result[neut_disc_2_diag], "HW_disc0_2")
|
||||
|
||||
// IO
|
||||
saveResult(par().output, "HW_disc0", result);
|
||||
}
|
60
Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp
Normal file
60
Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp
Normal file
@ -0,0 +1,60 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.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 */
|
||||
|
||||
#ifndef Hadrons_MContraction_WeakNeutral4ptDisc_hpp_
|
||||
#define Hadrons_MContraction_WeakNeutral4ptDisc_hpp_
|
||||
|
||||
#include <Hadrons/Modules/MContraction/WeakHamiltonian.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* WeakNeutral4ptDisc *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MContraction)
|
||||
|
||||
enum
|
||||
{
|
||||
neut_disc_1_diag = 0,
|
||||
neut_disc_2_diag = 1,
|
||||
n_neut_disc_diag = 2
|
||||
};
|
||||
|
||||
// Neutral 4pt disconnected subdiagram contractions.
|
||||
#define MAKE_DISC_MESON(Q_1, Q_2, gamma) (Q_1*adj(Q_2)*g5*gamma)
|
||||
#define MAKE_DISC_LOOP(Q_LOOP, gamma) (Q_LOOP*gamma)
|
||||
#define MAKE_DISC_CURR(Q_c, gamma) (trace(Q_c*gamma))
|
||||
|
||||
MAKE_WEAK_MODULE(WeakNeutral4ptDisc)
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MContraction_WeakNeutral4ptDisc_hpp_
|
36
Hadrons/Modules/MFermion/FreeProp.cc
Normal file
36
Hadrons/Modules/MFermion/FreeProp.cc
Normal file
@ -0,0 +1,36 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MFermion/FreeProp.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Vera Guelpers <vmg1n14@soton.ac.uk>
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MFermion/FreeProp.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MFermion;
|
||||
|
||||
template class Grid::Hadrons::MFermion::TFreeProp<FIMPL>;
|
||||
|
188
Hadrons/Modules/MFermion/FreeProp.hpp
Normal file
188
Hadrons/Modules/MFermion/FreeProp.hpp
Normal file
@ -0,0 +1,188 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MFermion/FreeProp.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Vera Guelpers <vmg1n14@soton.ac.uk>
|
||||
|
||||
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_MFermion_FreeProp_hpp_
|
||||
#define Hadrons_MFermion_FreeProp_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* FreeProp *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MFermion)
|
||||
|
||||
class FreePropPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(FreePropPar,
|
||||
std::string, source,
|
||||
std::string, action,
|
||||
double, mass,
|
||||
std::string, twist);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TFreeProp: public Module<FreePropPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TFreeProp(const std::string name);
|
||||
// destructor
|
||||
virtual ~TFreeProp(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
private:
|
||||
unsigned int Ls_;
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(FreeProp, TFreeProp<FIMPL>, MFermion);
|
||||
|
||||
/******************************************************************************
|
||||
* TFreeProp implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TFreeProp<FImpl>::TFreeProp(const std::string name)
|
||||
: Module<FreePropPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TFreeProp<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().source, par().action};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TFreeProp<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName(), getName() + "_5d"};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TFreeProp<FImpl>::setup(void)
|
||||
{
|
||||
Ls_ = env().getObjectLs(par().action);
|
||||
envCreateLat(PropagatorField, getName());
|
||||
envTmpLat(FermionField, "source", Ls_);
|
||||
envTmpLat(FermionField, "sol", Ls_);
|
||||
envTmpLat(FermionField, "tmp");
|
||||
if (Ls_ > 1)
|
||||
{
|
||||
envCreateLat(PropagatorField, getName() + "_5d", Ls_);
|
||||
}
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TFreeProp<FImpl>::execute(void)
|
||||
{
|
||||
LOG(Message) << "Computing free fermion propagator '" << getName() << "'"
|
||||
<< std::endl;
|
||||
|
||||
std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d");
|
||||
auto &prop = envGet(PropagatorField, propName);
|
||||
auto &fullSrc = envGet(PropagatorField, par().source);
|
||||
auto &mat = envGet(FMat, par().action);
|
||||
RealD mass = par().mass;
|
||||
|
||||
envGetTmp(FermionField, source);
|
||||
envGetTmp(FermionField, sol);
|
||||
envGetTmp(FermionField, tmp);
|
||||
LOG(Message) << "Calculating a free Propagator with mass " << mass
|
||||
<< " using the action '" << par().action
|
||||
<< "' on source '" << par().source << "'" << std::endl;
|
||||
for (unsigned int s = 0; s < Ns; ++s)
|
||||
for (unsigned int c = 0; c < FImpl::Dimension; ++c)
|
||||
{
|
||||
LOG(Message) << "Calculation for spin= " << s << ", color= " << c
|
||||
<< std::endl;
|
||||
// source conversion for 4D sources
|
||||
if (!env().isObject5d(par().source))
|
||||
{
|
||||
if (Ls_ == 1)
|
||||
{
|
||||
PropToFerm<FImpl>(source, fullSrc, s, c);
|
||||
}
|
||||
else
|
||||
{
|
||||
PropToFerm<FImpl>(tmp, fullSrc, s, c);
|
||||
mat.ImportPhysicalFermionSource(tmp, source);
|
||||
}
|
||||
}
|
||||
// source conversion for 5D sources
|
||||
else
|
||||
{
|
||||
if (Ls_ != env().getObjectLs(par().source))
|
||||
{
|
||||
HADRONS_ERROR(Size, "Ls mismatch between quark action and source");
|
||||
}
|
||||
else
|
||||
{
|
||||
PropToFerm<FImpl>(source, fullSrc, s, c);
|
||||
}
|
||||
}
|
||||
sol = Zero();
|
||||
std::vector<double> twist = strToVec<double>(par().twist);
|
||||
if(twist.size() != Nd) HADRONS_ERROR(Size, "number of twist angles does not match number of dimensions");
|
||||
mat.FreePropagator(source,sol,mass,twist);
|
||||
FermToProp<FImpl>(prop, sol, s, c);
|
||||
// create 4D propagators from 5D one if necessary
|
||||
if (Ls_ > 1)
|
||||
{
|
||||
PropagatorField &p4d = envGet(PropagatorField, getName());
|
||||
mat.ExportPhysicalFermionSolution(sol, tmp);
|
||||
FermToProp<FImpl>(p4d, tmp, s, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MFermion_FreeProp_hpp_
|
35
Hadrons/Modules/MFermion/GaugeProp.cc
Normal file
35
Hadrons/Modules/MFermion/GaugeProp.cc
Normal file
@ -0,0 +1,35 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MFermion/GaugeProp.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MFermion/GaugeProp.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MFermion;
|
||||
|
||||
template class Grid::Hadrons::MFermion::TGaugeProp<FIMPL>;
|
||||
template class Grid::Hadrons::MFermion::TGaugeProp<ZFIMPL>;
|
191
Hadrons/Modules/MFermion/GaugeProp.hpp
Normal file
191
Hadrons/Modules/MFermion/GaugeProp.hpp
Normal file
@ -0,0 +1,191 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MFermion/GaugeProp.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Guido Cossu <guido.cossu@ed.ac.uk>
|
||||
Author: Lanny91 <andrew.lawson@gmail.com>
|
||||
Author: pretidav <david.preti@csic.es>
|
||||
|
||||
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_MFermion_GaugeProp_hpp_
|
||||
#define Hadrons_MFermion_GaugeProp_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Hadrons/Solver.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* GaugeProp *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MFermion)
|
||||
|
||||
class GaugePropPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(GaugePropPar,
|
||||
std::string, source,
|
||||
std::string, solver);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TGaugeProp: public Module<GaugePropPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
SOLVER_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TGaugeProp(const std::string name);
|
||||
// destructor
|
||||
virtual ~TGaugeProp(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
private:
|
||||
unsigned int Ls_;
|
||||
Solver *solver_{nullptr};
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(GaugeProp, TGaugeProp<FIMPL>, MFermion);
|
||||
MODULE_REGISTER_TMP(ZGaugeProp, TGaugeProp<ZFIMPL>, MFermion);
|
||||
|
||||
/******************************************************************************
|
||||
* TGaugeProp implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TGaugeProp<FImpl>::TGaugeProp(const std::string name)
|
||||
: Module<GaugePropPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TGaugeProp<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().source, par().solver};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TGaugeProp<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName(), getName() + "_5d"};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TGaugeProp<FImpl>::setup(void)
|
||||
{
|
||||
Ls_ = env().getObjectLs(par().solver);
|
||||
envCreateLat(PropagatorField, getName());
|
||||
envTmpLat(FermionField, "source", Ls_);
|
||||
envTmpLat(FermionField, "sol", Ls_);
|
||||
envTmpLat(FermionField, "tmp");
|
||||
if (Ls_ > 1)
|
||||
{
|
||||
envCreateLat(PropagatorField, getName() + "_5d", Ls_);
|
||||
}
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TGaugeProp<FImpl>::execute(void)
|
||||
{
|
||||
LOG(Message) << "Computing quark propagator '" << getName() << "'"
|
||||
<< std::endl;
|
||||
|
||||
std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d");
|
||||
auto &prop = envGet(PropagatorField, propName);
|
||||
auto &fullSrc = envGet(PropagatorField, par().source);
|
||||
auto &solver = envGet(Solver, par().solver);
|
||||
auto &mat = solver.getFMat();
|
||||
|
||||
envGetTmp(FermionField, source);
|
||||
envGetTmp(FermionField, sol);
|
||||
envGetTmp(FermionField, tmp);
|
||||
LOG(Message) << "Inverting using solver '" << par().solver
|
||||
<< "' on source '" << par().source << "'" << std::endl;
|
||||
for (unsigned int s = 0; s < Ns; ++s)
|
||||
for (unsigned int c = 0; c < FImpl::Dimension; ++c)
|
||||
{
|
||||
LOG(Message) << "Inversion for spin= " << s << ", color= " << c
|
||||
<< std::endl;
|
||||
// source conversion for 4D sources
|
||||
LOG(Message) << "Import source" << std::endl;
|
||||
if (!env().isObject5d(par().source))
|
||||
{
|
||||
if (Ls_ == 1)
|
||||
{
|
||||
PropToFerm<FImpl>(source, fullSrc, s, c);
|
||||
}
|
||||
else
|
||||
{
|
||||
PropToFerm<FImpl>(tmp, fullSrc, s, c);
|
||||
mat.ImportPhysicalFermionSource(tmp, source);
|
||||
}
|
||||
}
|
||||
// source conversion for 5D sources
|
||||
else
|
||||
{
|
||||
if (Ls_ != env().getObjectLs(par().source))
|
||||
{
|
||||
HADRONS_ERROR(Size, "Ls mismatch between quark action and source");
|
||||
}
|
||||
else
|
||||
{
|
||||
PropToFerm<FImpl>(source, fullSrc, s, c);
|
||||
}
|
||||
}
|
||||
sol = Zero();
|
||||
LOG(Message) << "Solve" << std::endl;
|
||||
solver(sol, source);
|
||||
LOG(Message) << "Export solution" << std::endl;
|
||||
FermToProp<FImpl>(prop, sol, s, c);
|
||||
// create 4D propagators from 5D one if necessary
|
||||
if (Ls_ > 1)
|
||||
{
|
||||
PropagatorField &p4d = envGet(PropagatorField, getName());
|
||||
mat.ExportPhysicalFermionSolution(sol, tmp);
|
||||
FermToProp<FImpl>(p4d, tmp, s, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MFermion_GaugeProp_hpp_
|
34
Hadrons/Modules/MGauge/Electrify.cc
Normal file
34
Hadrons/Modules/MGauge/Electrify.cc
Normal file
@ -0,0 +1,34 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/Electrify.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Vera Guelpers <Vera.Guelpers@ed.ac.uk>
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MGauge/Electrify.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MGauge;
|
||||
|
||||
template class Grid::Hadrons::MGauge::TElectrify<GIMPL>;
|
151
Hadrons/Modules/MGauge/Electrify.hpp
Normal file
151
Hadrons/Modules/MGauge/Electrify.hpp
Normal file
@ -0,0 +1,151 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/Electrify.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Vera Guelpers <Vera.Guelpers@ed.ac.uk>
|
||||
|
||||
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_MGauge_Electrify_hpp_
|
||||
#define Hadrons_MGauge_Electrify_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Electrify gauge *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MGauge)
|
||||
|
||||
/****************************************************************************
|
||||
* Electrify a gauge field:
|
||||
*
|
||||
* Ue_mu(x) = U_mu(x)*exp(ieqA_mu(x))
|
||||
*
|
||||
* with
|
||||
*
|
||||
* - gauge: U_mu(x): gauge field
|
||||
* - emField: A_mu(x): electromagnetic photon field
|
||||
* - e: value for the elementary charge
|
||||
* - q: charge in units of e
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
class ElectrifyPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(ElectrifyPar,
|
||||
std::string, gauge,
|
||||
std::string, emField,
|
||||
double, e,
|
||||
double, charge);
|
||||
};
|
||||
|
||||
template <typename GImpl>
|
||||
class TElectrify: public Module<ElectrifyPar>
|
||||
{
|
||||
public:
|
||||
GAUGE_TYPE_ALIASES(GImpl,);
|
||||
public:
|
||||
typedef PhotonR::GaugeField EmField;
|
||||
public:
|
||||
// constructor
|
||||
TElectrify(const std::string name);
|
||||
// destructor
|
||||
virtual ~TElectrify(void) {};
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(Electrify, TElectrify<GIMPL>, MGauge);
|
||||
|
||||
/******************************************************************************
|
||||
* TElectrify implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
TElectrify<GImpl>::TElectrify(const std::string name)
|
||||
: Module<ElectrifyPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
std::vector<std::string> TElectrify<GImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().gauge, par().emField};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename GImpl>
|
||||
std::vector<std::string> TElectrify<GImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
void TElectrify<GImpl>::setup(void)
|
||||
{
|
||||
envCreateLat(GaugeField, getName());
|
||||
envTmpLat(LatticeComplex, "eiAmu");
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
void TElectrify<GImpl>::execute(void)
|
||||
{
|
||||
LOG(Message) << "Electrify the gauge field " << par().gauge << " using the photon field "
|
||||
<< par().emField << " with charge e*q= " << par().e << "*" << par().charge << std::endl;
|
||||
|
||||
auto &Ue = envGet(GaugeField, getName());
|
||||
auto &U = envGet(GaugeField, par().gauge);
|
||||
auto &A = envGet(EmField, par().emField);
|
||||
envGetTmp(LatticeComplex, eiAmu);
|
||||
|
||||
Complex i(0.0,1.0);
|
||||
|
||||
for(unsigned int mu = 0; mu < env().getNd(); mu++)
|
||||
{
|
||||
eiAmu = exp(i * (Real)(par().e * par().charge) * PeekIndex<LorentzIndex>(A, mu));
|
||||
PokeIndex<LorentzIndex>(Ue, PeekIndex<LorentzIndex>(U, mu) * eiAmu, mu);
|
||||
}
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MGauge_Electrify_hpp_
|
79
Hadrons/Modules/MGauge/FundtoHirep.cc
Normal file
79
Hadrons/Modules/MGauge/FundtoHirep.cc
Normal file
@ -0,0 +1,79 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/FundtoHirep.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Guido Cossu <guido.cossu@ed.ac.uk>
|
||||
Author: pretidav <david.preti@csic.es>
|
||||
|
||||
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 */
|
||||
|
||||
#include <Hadrons/Modules/MGauge/FundtoHirep.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MGauge;
|
||||
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <class Rep>
|
||||
TFundtoHirep<Rep>::TFundtoHirep(const std::string name)
|
||||
: Module<FundtoHirepPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <class Rep>
|
||||
std::vector<std::string> TFundtoHirep<Rep>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().gaugeconf};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <class Rep>
|
||||
std::vector<std::string> TFundtoHirep<Rep>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename Rep>
|
||||
void TFundtoHirep<Rep>::setup(void)
|
||||
{
|
||||
envCreateLat(Rep::LatticeField, getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <class Rep>
|
||||
void TFundtoHirep<Rep>::execute(void)
|
||||
{
|
||||
LOG(Message) << "Transforming Representation" << std::endl;
|
||||
|
||||
auto &U = envGet(LatticeGaugeField, par().gaugeconf);
|
||||
auto &URep = envGet(Rep::LatticeField, getName());
|
||||
|
||||
Rep TargetRepresentation(U._grid);
|
||||
TargetRepresentation.update_representation(U);
|
||||
URep = TargetRepresentation.U;
|
||||
}
|
76
Hadrons/Modules/MGauge/FundtoHirep.hpp
Normal file
76
Hadrons/Modules/MGauge/FundtoHirep.hpp
Normal file
@ -0,0 +1,76 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/FundtoHirep.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: pretidav <david.preti@csic.es>
|
||||
|
||||
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_MGauge_FundtoHirep_hpp_
|
||||
#define Hadrons_MGauge_FundtoHirep_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Load a NERSC configuration *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MGauge)
|
||||
|
||||
class FundtoHirepPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(FundtoHirepPar,
|
||||
std::string, gaugeconf);
|
||||
};
|
||||
|
||||
template <class Rep>
|
||||
class TFundtoHirep: public Module<FundtoHirepPar>
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
TFundtoHirep(const std::string name);
|
||||
// destructor
|
||||
virtual ~TFundtoHirep(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
void setup(void);
|
||||
// execution
|
||||
void execute(void);
|
||||
};
|
||||
|
||||
//MODULE_REGISTER_TMP(FundtoAdjoint, TFundtoHirep<AdjointRepresentation>, MGauge);
|
||||
//MODULE_REGISTER_TMP(FundtoTwoIndexSym, TFundtoHirep<TwoIndexSymmetricRepresentation>, MGauge);
|
||||
//MODULE_REGISTER_TMP(FundtoTwoIndexAsym, TFundtoHirep<TwoIndexAntiSymmetricRepresentation>, MGauge);
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MGauge_FundtoHirep_hpp_
|
36
Hadrons/Modules/MGauge/GaugeFix.cc
Normal file
36
Hadrons/Modules/MGauge/GaugeFix.cc
Normal file
@ -0,0 +1,36 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/GaugeFix.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
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 */
|
||||
|
||||
#include <Hadrons/Modules/MGauge/GaugeFix.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MGauge;
|
||||
|
||||
template class Grid::Hadrons::MGauge::TGaugeFix<GIMPL>;
|
135
Hadrons/Modules/MGauge/GaugeFix.hpp
Normal file
135
Hadrons/Modules/MGauge/GaugeFix.hpp
Normal file
@ -0,0 +1,135 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/GaugeFix.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
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_MGaugeFix_hpp_
|
||||
#define Hadrons_MGaugeFix_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Grid/qcd/utils/GaugeFix.h>
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Fix gauge *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MGauge)
|
||||
|
||||
class GaugeFixPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(GaugeFixPar,
|
||||
std::string, gauge,
|
||||
Real, alpha,
|
||||
int, maxiter,
|
||||
Real, Omega_tol,
|
||||
Real, Phi_tol,
|
||||
bool, Fourier);
|
||||
};
|
||||
|
||||
template <typename GImpl>
|
||||
class TGaugeFix: public Module<GaugeFixPar>
|
||||
{
|
||||
public:
|
||||
GAUGE_TYPE_ALIASES(GImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TGaugeFix(const std::string name);
|
||||
// destructor
|
||||
virtual ~TGaugeFix(void) {};
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(GaugeFix, TGaugeFix<GIMPL>, MGauge);
|
||||
|
||||
/******************************************************************************
|
||||
* TGaugeFix implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
TGaugeFix<GImpl>::TGaugeFix(const std::string name)
|
||||
: Module<GaugeFixPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
std::vector<std::string> TGaugeFix<GImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().gauge};
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename GImpl>
|
||||
std::vector<std::string> TGaugeFix<GImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
void TGaugeFix<GImpl>::setup(void)
|
||||
{
|
||||
envCreateLat(GaugeField, getName());
|
||||
}
|
||||
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
void TGaugeFix<GImpl>::execute(void)
|
||||
//Loads the gauge and fixes it
|
||||
{
|
||||
std::cout << "executing" << std::endl;
|
||||
LOG(Message) << "Fixing the Gauge" << std::endl;
|
||||
LOG(Message) << par().gauge << std::endl;
|
||||
auto &U = envGet(GaugeField, par().gauge);
|
||||
auto &Umu = envGet(GaugeField, getName());
|
||||
LOG(Message) << "Gauge Field fetched" << std::endl;
|
||||
//do we allow maxiter etc to be user set?
|
||||
Real alpha = par().alpha;
|
||||
int maxiter = par().maxiter;
|
||||
Real Omega_tol = par().Omega_tol;
|
||||
Real Phi_tol = par().Phi_tol;
|
||||
bool Fourier = par().Fourier;
|
||||
FourierAcceleratedGaugeFixer<PeriodicGimplR>::SteepestDescentGaugeFix(U,alpha,maxiter,Omega_tol,Phi_tol,Fourier);
|
||||
Umu = U;
|
||||
LOG(Message) << "Gauge Fixed" << std::endl;
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MGaugeFix_hpp_
|
34
Hadrons/Modules/MGauge/Random.cc
Normal file
34
Hadrons/Modules/MGauge/Random.cc
Normal file
@ -0,0 +1,34 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/Random.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MGauge/Random.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MGauge;
|
||||
|
||||
template class Grid::Hadrons::MGauge::TRandom<GIMPL>;
|
112
Hadrons/Modules/MGauge/Random.hpp
Normal file
112
Hadrons/Modules/MGauge/Random.hpp
Normal file
@ -0,0 +1,112 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/Random.hpp
|
||||
|
||||
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 */
|
||||
|
||||
#ifndef Hadrons_MGauge_Random_hpp_
|
||||
#define Hadrons_MGauge_Random_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Random gauge *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MGauge)
|
||||
|
||||
template <typename GImpl>
|
||||
class TRandom: public Module<NoPar>
|
||||
{
|
||||
public:
|
||||
GAUGE_TYPE_ALIASES(GImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TRandom(const std::string name);
|
||||
// destructor
|
||||
virtual ~TRandom(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(Random, TRandom<GIMPL>, MGauge);
|
||||
|
||||
/******************************************************************************
|
||||
* TRandom implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
TRandom<GImpl>::TRandom(const std::string name)
|
||||
: Module<NoPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
std::vector<std::string> TRandom<GImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename GImpl>
|
||||
std::vector<std::string> TRandom<GImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
void TRandom<GImpl>::setup(void)
|
||||
{
|
||||
envCreateLat(GaugeField, getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
void TRandom<GImpl>::execute(void)
|
||||
{
|
||||
LOG(Message) << "Generating random gauge configuration" << std::endl;
|
||||
|
||||
auto &U = envGet(GaugeField, getName());
|
||||
GImpl::HotConfiguration(rng4d(), U);
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MGauge_Random_hpp_
|
85
Hadrons/Modules/MGauge/StochEm.cc
Normal file
85
Hadrons/Modules/MGauge/StochEm.cc
Normal file
@ -0,0 +1,85 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/StochEm.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: James Harrison <jch1g10@soton.ac.uk>
|
||||
Author: Vera Guelpers <vmg1n14@soton.ac.uk>
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MGauge/StochEm.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MGauge;
|
||||
|
||||
/******************************************************************************
|
||||
* TStochEm implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
TStochEm::TStochEm(const std::string name)
|
||||
: Module<StochEmPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> TStochEm::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
std::vector<std::string> TStochEm::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
void TStochEm::setup(void)
|
||||
{
|
||||
weightDone_ = env().hasCreatedObject("_" + getName() + "_weight");
|
||||
envCacheLat(EmComp, "_" + getName() + "_weight");
|
||||
envCreateLat(EmField, getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void TStochEm::execute(void)
|
||||
{
|
||||
LOG(Message) << "Generating stochastic EM potential..." << std::endl;
|
||||
|
||||
std::vector<Real> improvements = strToVec<Real>(par().improvement);
|
||||
PhotonR photon(par().gauge, par().zmScheme, improvements, par().G0_qedInf);
|
||||
auto &a = envGet(EmField, getName());
|
||||
auto &w = envGet(EmComp, "_" + getName() + "_weight");
|
||||
|
||||
if (!weightDone_)
|
||||
{
|
||||
LOG(Message) << "Caching stochastic EM potential weight (gauge: "
|
||||
<< par().gauge << ", zero-mode scheme: "
|
||||
<< par().zmScheme << ")..." << std::endl;
|
||||
photon.StochasticWeight(w);
|
||||
}
|
||||
photon.StochasticField(a, rng4d(), w);
|
||||
}
|
82
Hadrons/Modules/MGauge/StochEm.hpp
Normal file
82
Hadrons/Modules/MGauge/StochEm.hpp
Normal file
@ -0,0 +1,82 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/StochEm.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: James Harrison <jch1g10@soton.ac.uk>
|
||||
Author: Vera Guelpers <vmg1n14@soton.ac.uk>
|
||||
|
||||
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_MGauge_StochEm_hpp_
|
||||
#define Hadrons_MGauge_StochEm_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* StochEm *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MGauge)
|
||||
|
||||
class StochEmPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(StochEmPar,
|
||||
PhotonR::Gauge, gauge,
|
||||
PhotonR::ZmScheme, zmScheme,
|
||||
std::string, improvement,
|
||||
Real, G0_qedInf);
|
||||
};
|
||||
|
||||
class TStochEm: public Module<StochEmPar>
|
||||
{
|
||||
public:
|
||||
typedef PhotonR::GaugeField EmField;
|
||||
typedef PhotonR::GaugeLinkField EmComp;
|
||||
public:
|
||||
// constructor
|
||||
TStochEm(const std::string name);
|
||||
// destructor
|
||||
virtual ~TStochEm(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
private:
|
||||
bool weightDone_;
|
||||
};
|
||||
|
||||
MODULE_REGISTER(StochEm, TStochEm, MGauge);
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MGauge_StochEm_hpp_
|
34
Hadrons/Modules/MGauge/StoutSmearing.cc
Normal file
34
Hadrons/Modules/MGauge/StoutSmearing.cc
Normal file
@ -0,0 +1,34 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/StoutSmearing.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MGauge/StoutSmearing.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MGauge;
|
||||
|
||||
template class Grid::Hadrons::MGauge::TStoutSmearing<GIMPL>;
|
135
Hadrons/Modules/MGauge/StoutSmearing.hpp
Normal file
135
Hadrons/Modules/MGauge/StoutSmearing.hpp
Normal file
@ -0,0 +1,135 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/StoutSmearing.hpp
|
||||
|
||||
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 */
|
||||
#ifndef Hadrons_MGauge_StoutSmearing_hpp_
|
||||
#define Hadrons_MGauge_StoutSmearing_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Stout smearing *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MGauge)
|
||||
|
||||
class StoutSmearingPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(StoutSmearingPar,
|
||||
std::string, gauge,
|
||||
unsigned int, steps,
|
||||
double, rho);
|
||||
};
|
||||
|
||||
template <typename GImpl>
|
||||
class TStoutSmearing: public Module<StoutSmearingPar>
|
||||
{
|
||||
public:
|
||||
GAUGE_TYPE_ALIASES(GImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TStoutSmearing(const std::string name);
|
||||
// destructor
|
||||
virtual ~TStoutSmearing(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(StoutSmearing, TStoutSmearing<GIMPL>, MGauge);
|
||||
|
||||
/******************************************************************************
|
||||
* TStoutSmearing implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
TStoutSmearing<GImpl>::TStoutSmearing(const std::string name)
|
||||
: Module<StoutSmearingPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
std::vector<std::string> TStoutSmearing<GImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().gauge};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename GImpl>
|
||||
std::vector<std::string> TStoutSmearing<GImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
void TStoutSmearing<GImpl>::setup(void)
|
||||
{
|
||||
envCreateLat(GaugeField, getName());
|
||||
envTmpLat(GaugeField, "buf");
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
void TStoutSmearing<GImpl>::execute(void)
|
||||
{
|
||||
LOG(Message) << "Smearing '" << par().gauge << "' with " << par().steps
|
||||
<< " step" << ((par().steps > 1) ? "s" : "")
|
||||
<< " of stout smearing and rho= " << par().rho << std::endl;
|
||||
|
||||
Smear_Stout<GImpl> smearer(par().rho);
|
||||
auto &U = envGet(GaugeField, par().gauge);
|
||||
auto &Usmr = envGet(GaugeField, getName());
|
||||
|
||||
envGetTmp(GaugeField, buf);
|
||||
buf = U;
|
||||
LOG(Message) << "plaquette= " << WilsonLoops<GImpl>::avgPlaquette(U)
|
||||
<< std::endl;
|
||||
for (unsigned int n = 0; n < par().steps; ++n)
|
||||
{
|
||||
smearer.smear(Usmr, buf);
|
||||
buf = Usmr;
|
||||
LOG(Message) << "plaquette= " << WilsonLoops<GImpl>::avgPlaquette(Usmr)
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MGauge_StoutSmearing_hpp_
|
34
Hadrons/Modules/MGauge/Unit.cc
Normal file
34
Hadrons/Modules/MGauge/Unit.cc
Normal file
@ -0,0 +1,34 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/Unit.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MGauge/Unit.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MGauge;
|
||||
|
||||
template class Grid::Hadrons::MGauge::TUnit<GIMPL>;
|
110
Hadrons/Modules/MGauge/Unit.hpp
Normal file
110
Hadrons/Modules/MGauge/Unit.hpp
Normal file
@ -0,0 +1,110 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/Unit.hpp
|
||||
|
||||
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 */
|
||||
|
||||
#ifndef Hadrons_MGauge_Unit_hpp_
|
||||
#define Hadrons_MGauge_Unit_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Unit gauge *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MGauge)
|
||||
|
||||
template <typename GImpl>
|
||||
class TUnit: public Module<NoPar>
|
||||
{
|
||||
public:
|
||||
GAUGE_TYPE_ALIASES(GImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TUnit(const std::string name);
|
||||
// destructor
|
||||
virtual ~TUnit(void) {};
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(Unit, TUnit<GIMPL>, MGauge);
|
||||
|
||||
/******************************************************************************
|
||||
* TUnit implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
TUnit<GImpl>::TUnit(const std::string name)
|
||||
: Module<NoPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
std::vector<std::string> TUnit<GImpl>::getInput(void)
|
||||
{
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
template <typename GImpl>
|
||||
std::vector<std::string> TUnit<GImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
void TUnit<GImpl>::setup(void)
|
||||
{
|
||||
envCreateLat(GaugeField, getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
void TUnit<GImpl>::execute(void)
|
||||
{
|
||||
LOG(Message) << "Creating unit gauge configuration" << std::endl;
|
||||
|
||||
auto &U = envGet(GaugeField, getName());
|
||||
GImpl::ColdConfiguration(rng4d(), U);
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MGauge_Unit_hpp_
|
69
Hadrons/Modules/MGauge/UnitEm.cc
Normal file
69
Hadrons/Modules/MGauge/UnitEm.cc
Normal file
@ -0,0 +1,69 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/UnitEm.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: James Harrison <jch1g10@soton.ac.uk>
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MGauge/UnitEm.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MGauge;
|
||||
|
||||
/******************************************************************************
|
||||
* TStochEm implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
TUnitEm::TUnitEm(const std::string name)
|
||||
: Module<NoPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> TUnitEm::getInput(void)
|
||||
{
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
std::vector<std::string> TUnitEm::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
void TUnitEm::setup(void)
|
||||
{
|
||||
envCreateLat(EmField, getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void TUnitEm::execute(void)
|
||||
{
|
||||
PhotonR photon(0, 0); // Just chose arbitrary input values here
|
||||
auto &a = envGet(EmField, getName());
|
||||
LOG(Message) << "Generating unit EM potential..." << std::endl;
|
||||
photon.UnitField(a);
|
||||
}
|
69
Hadrons/Modules/MGauge/UnitEm.hpp
Normal file
69
Hadrons/Modules/MGauge/UnitEm.hpp
Normal file
@ -0,0 +1,69 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MGauge/UnitEm.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: James Harrison <jch1g10@soton.ac.uk>
|
||||
|
||||
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_MGauge_UnitEm_hpp_
|
||||
#define Hadrons_MGauge_UnitEm_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* StochEm *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MGauge)
|
||||
|
||||
class TUnitEm: public Module<NoPar>
|
||||
{
|
||||
public:
|
||||
typedef PhotonR::GaugeField EmField;
|
||||
typedef PhotonR::GaugeLinkField EmComp;
|
||||
public:
|
||||
// constructor
|
||||
TUnitEm(const std::string name);
|
||||
// destructor
|
||||
virtual ~TUnitEm(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER(UnitEm, TUnitEm, MGauge);
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MGauge_UnitEm_hpp_
|
34
Hadrons/Modules/MIO/LoadA2AVectors.cc
Normal file
34
Hadrons/Modules/MIO/LoadA2AVectors.cc
Normal file
@ -0,0 +1,34 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MIO/LoadA2AVectors.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MIO/LoadA2AVectors.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MIO;
|
||||
|
||||
template class Grid::Hadrons::MIO::TLoadA2AVectors<FIMPL>;
|
120
Hadrons/Modules/MIO/LoadA2AVectors.hpp
Normal file
120
Hadrons/Modules/MIO/LoadA2AVectors.hpp
Normal file
@ -0,0 +1,120 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MIO/LoadA2AVectors.hpp
|
||||
|
||||
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 */
|
||||
#ifndef Hadrons_MIO_LoadA2AVectors_hpp_
|
||||
#define Hadrons_MIO_LoadA2AVectors_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Hadrons/A2AVectors.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Module to load all-to-all vectors *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MIO)
|
||||
|
||||
class LoadA2AVectorsPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(LoadA2AVectorsPar,
|
||||
std::string, filestem,
|
||||
bool, multiFile,
|
||||
unsigned int, size);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TLoadA2AVectors: public Module<LoadA2AVectorsPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TLoadA2AVectors(const std::string name);
|
||||
// destructor
|
||||
virtual ~TLoadA2AVectors(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(LoadA2AVectors, TLoadA2AVectors<FIMPL>, MIO);
|
||||
|
||||
/******************************************************************************
|
||||
* TLoadA2AVectors implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TLoadA2AVectors<FImpl>::TLoadA2AVectors(const std::string name)
|
||||
: Module<LoadA2AVectorsPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TLoadA2AVectors<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TLoadA2AVectors<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TLoadA2AVectors<FImpl>::setup(void)
|
||||
{
|
||||
envCreate(std::vector<FermionField>, getName(), 1, par().size,
|
||||
envGetGrid(FermionField));
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TLoadA2AVectors<FImpl>::execute(void)
|
||||
{
|
||||
auto &vec = envGet(std::vector<FermionField>, getName());
|
||||
|
||||
A2AVectorsIo::read(vec, par().filestem, par().multiFile, vm().getTrajectory());
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MIO_LoadA2AVectors_hpp_
|
40
Hadrons/Modules/MIO/LoadBinary.cc
Normal file
40
Hadrons/Modules/MIO/LoadBinary.cc
Normal file
@ -0,0 +1,40 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MIO/LoadBinary.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MIO/LoadBinary.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MIO;
|
||||
|
||||
template class Grid::Hadrons::MIO::TLoadBinary<GIMPL>;
|
||||
template class Grid::Hadrons::MIO::TLoadBinary<ScalarNxNAdjImplR<2>>;
|
||||
template class Grid::Hadrons::MIO::TLoadBinary<ScalarNxNAdjImplR<3>>;
|
||||
template class Grid::Hadrons::MIO::TLoadBinary<ScalarNxNAdjImplR<4>>;
|
||||
template class Grid::Hadrons::MIO::TLoadBinary<ScalarNxNAdjImplR<5>>;
|
||||
template class Grid::Hadrons::MIO::TLoadBinary<ScalarNxNAdjImplR<6>>;
|
||||
|
140
Hadrons/Modules/MIO/LoadBinary.hpp
Normal file
140
Hadrons/Modules/MIO/LoadBinary.hpp
Normal file
@ -0,0 +1,140 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MIO/LoadBinary.hpp
|
||||
|
||||
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 */
|
||||
#ifndef Hadrons_MIO_LoadBinary_hpp_
|
||||
#define Hadrons_MIO_LoadBinary_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Load a binary configurations *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MIO)
|
||||
|
||||
class LoadBinaryPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(LoadBinaryPar,
|
||||
std::string, file,
|
||||
std::string, format);
|
||||
};
|
||||
|
||||
template <typename Impl>
|
||||
class TLoadBinary: public Module<LoadBinaryPar>
|
||||
{
|
||||
public:
|
||||
typedef typename Impl::Field Field;
|
||||
typedef typename Impl::Simd Simd;
|
||||
typedef typename Field::vector_object vobj;
|
||||
typedef typename vobj::scalar_object sobj;
|
||||
typedef typename sobj::DoublePrecision sobj_double;
|
||||
typedef BinarySimpleMunger<sobj_double, sobj> Munger;
|
||||
public:
|
||||
// constructor
|
||||
TLoadBinary(const std::string name);
|
||||
// destructor
|
||||
virtual ~TLoadBinary(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(LoadBinary, TLoadBinary<GIMPL>, MIO);
|
||||
MODULE_REGISTER_TMP(LoadBinaryScalarSU2, TLoadBinary<ScalarNxNAdjImplR<2>>, MIO);
|
||||
MODULE_REGISTER_TMP(LoadBinaryScalarSU3, TLoadBinary<ScalarNxNAdjImplR<3>>, MIO);
|
||||
MODULE_REGISTER_TMP(LoadBinaryScalarSU4, TLoadBinary<ScalarNxNAdjImplR<4>>, MIO);
|
||||
MODULE_REGISTER_TMP(LoadBinaryScalarSU5, TLoadBinary<ScalarNxNAdjImplR<5>>, MIO);
|
||||
MODULE_REGISTER_TMP(LoadBinaryScalarSU6, TLoadBinary<ScalarNxNAdjImplR<6>>, MIO);
|
||||
|
||||
/******************************************************************************
|
||||
* TLoadBinary implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename Impl>
|
||||
TLoadBinary<Impl>::TLoadBinary(const std::string name)
|
||||
: Module<LoadBinaryPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename Impl>
|
||||
std::vector<std::string> TLoadBinary<Impl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
std::vector<std::string> TLoadBinary<Impl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename Impl>
|
||||
void TLoadBinary<Impl>::setup(void)
|
||||
{
|
||||
envCreateLat(Field, getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename Impl>
|
||||
void TLoadBinary<Impl>::execute(void)
|
||||
{
|
||||
Munger munge;
|
||||
uint32_t nersc_csum, scidac_csuma, scidac_csumb;
|
||||
auto &U = envGet(Field, getName());
|
||||
std::string filename = par().file + "."
|
||||
+ std::to_string(vm().getTrajectory());
|
||||
|
||||
LOG(Message) << "Loading " << par().format
|
||||
<< " binary configuration from file '" << filename
|
||||
<< "'" << std::endl;
|
||||
BinaryIO::readLatticeObject<vobj, sobj_double>(U, filename, munge, 0,
|
||||
par().format, nersc_csum,
|
||||
scidac_csuma, scidac_csumb);
|
||||
LOG(Message) << "Checksums:" << std::endl;
|
||||
LOG(Message) << " NERSC " << nersc_csum << std::endl;
|
||||
LOG(Message) << " SciDAC A " << scidac_csuma << std::endl;
|
||||
LOG(Message) << " SciDAC B " << scidac_csumb << std::endl;
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MIO_LoadBinary_hpp_
|
35
Hadrons/Modules/MIO/LoadCoarseEigenPack.cc
Normal file
35
Hadrons/Modules/MIO/LoadCoarseEigenPack.cc
Normal file
@ -0,0 +1,35 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MIO/LoadCoarseEigenPack.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MIO;
|
||||
|
||||
template class Grid::Hadrons::MIO::TLoadCoarseEigenPack<CoarseFermionEigenPack<FIMPL,HADRONS_DEFAULT_LANCZOS_NBASIS>>;
|
||||
|
135
Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp
Normal file
135
Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp
Normal file
@ -0,0 +1,135 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp
|
||||
|
||||
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 */
|
||||
#ifndef Hadrons_MIO_LoadCoarseEigenPack_hpp_
|
||||
#define Hadrons_MIO_LoadCoarseEigenPack_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Hadrons/EigenPack.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Load local coherence eigen vectors/values package *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MIO)
|
||||
|
||||
class LoadCoarseEigenPackPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(LoadCoarseEigenPackPar,
|
||||
std::string, filestem,
|
||||
bool, multiFile,
|
||||
unsigned int, sizeFine,
|
||||
unsigned int, sizeCoarse,
|
||||
unsigned int, Ls,
|
||||
std::vector<int>, blockSize);
|
||||
};
|
||||
|
||||
template <typename Pack>
|
||||
class TLoadCoarseEigenPack: public Module<LoadCoarseEigenPackPar>
|
||||
{
|
||||
public:
|
||||
typedef CoarseEigenPack<typename Pack::Field, typename Pack::CoarseField> BasePack;
|
||||
template <typename vtype>
|
||||
using iImplScalar = iScalar<iScalar<iScalar<vtype>>>;
|
||||
typedef iImplScalar<typename Pack::Field::vector_type> SiteComplex;
|
||||
public:
|
||||
// constructor
|
||||
TLoadCoarseEigenPack(const std::string name);
|
||||
// destructor
|
||||
virtual ~TLoadCoarseEigenPack(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(LoadCoarseFermionEigenPack, ARG(TLoadCoarseEigenPack<CoarseFermionEigenPack<FIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>>), MIO);
|
||||
|
||||
/******************************************************************************
|
||||
* TLoadCoarseEigenPack implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
TLoadCoarseEigenPack<Pack>::TLoadCoarseEigenPack(const std::string name)
|
||||
: Module<LoadCoarseEigenPackPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
std::vector<std::string> TLoadCoarseEigenPack<Pack>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename Pack>
|
||||
std::vector<std::string> TLoadCoarseEigenPack<Pack>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
void TLoadCoarseEigenPack<Pack>::setup(void)
|
||||
{
|
||||
env().createGrid(par().Ls);
|
||||
env().createCoarseGrid(par().blockSize, par().Ls);
|
||||
envCreateDerived(BasePack, Pack, getName(), par().Ls, par().sizeFine,
|
||||
par().sizeCoarse, env().getRbGrid(par().Ls),
|
||||
env().getCoarseGrid(par().blockSize, par().Ls));
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
void TLoadCoarseEigenPack<Pack>::execute(void)
|
||||
{
|
||||
auto cg = env().getCoarseGrid(par().blockSize, par().Ls);
|
||||
auto &epack = envGetDerived(BasePack, Pack, getName());
|
||||
Lattice<SiteComplex> dummy(cg);
|
||||
|
||||
epack.read(par().filestem, par().multiFile, vm().getTrajectory());
|
||||
LOG(Message) << "Block Gramm-Schmidt pass 1"<< std::endl;
|
||||
blockOrthogonalise(dummy, epack.evec);
|
||||
LOG(Message) << "Block Gramm-Schmidt pass 2"<< std::endl;
|
||||
blockOrthogonalise(dummy, epack.evec);
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MIO_LoadCoarseEigenPack_hpp_
|
38
Hadrons/Modules/MIO/LoadCosmHol.cc
Normal file
38
Hadrons/Modules/MIO/LoadCosmHol.cc
Normal file
@ -0,0 +1,38 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MIO/LoadCosmHol.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MIO/LoadCosmHol.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MIO;
|
||||
|
||||
template class Grid::Hadrons::MIO::TLoadCosmHol<ScalarNxNAdjImplR<2>>;
|
||||
template class Grid::Hadrons::MIO::TLoadCosmHol<ScalarNxNAdjImplR<3>>;
|
||||
template class Grid::Hadrons::MIO::TLoadCosmHol<ScalarNxNAdjImplR<4>>;
|
||||
template class Grid::Hadrons::MIO::TLoadCosmHol<ScalarNxNAdjImplR<5>>;
|
||||
template class Grid::Hadrons::MIO::TLoadCosmHol<ScalarNxNAdjImplR<6>>;
|
146
Hadrons/Modules/MIO/LoadCosmHol.hpp
Normal file
146
Hadrons/Modules/MIO/LoadCosmHol.hpp
Normal file
@ -0,0 +1,146 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MIO/LoadCosmHol.hpp
|
||||
|
||||
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 */
|
||||
#ifndef Hadrons_MIO_LoadCosmHol_hpp_
|
||||
#define Hadrons_MIO_LoadCosmHol_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Load scalar SU(N) configurations *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MIO)
|
||||
|
||||
class LoadCosmHolPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(LoadCosmHolPar,
|
||||
std::string, file);
|
||||
};
|
||||
|
||||
class ScalarActionParameters: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(ScalarActionParameters,
|
||||
double, mass_squared,
|
||||
double, lambda,
|
||||
double, g);
|
||||
};
|
||||
|
||||
template <typename SImpl>
|
||||
class TLoadCosmHol: public Module<LoadCosmHolPar>
|
||||
{
|
||||
public:
|
||||
typedef typename SImpl::Field Field;
|
||||
public:
|
||||
// constructor
|
||||
TLoadCosmHol(const std::string name);
|
||||
// destructor
|
||||
virtual ~TLoadCosmHol(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(LoadCosmHolSU2, TLoadCosmHol<ScalarNxNAdjImplR<2>>, MIO);
|
||||
MODULE_REGISTER_TMP(LoadCosmHolSU3, TLoadCosmHol<ScalarNxNAdjImplR<3>>, MIO);
|
||||
MODULE_REGISTER_TMP(LoadCosmHolSU4, TLoadCosmHol<ScalarNxNAdjImplR<4>>, MIO);
|
||||
MODULE_REGISTER_TMP(LoadCosmHolSU5, TLoadCosmHol<ScalarNxNAdjImplR<5>>, MIO);
|
||||
MODULE_REGISTER_TMP(LoadCosmHolSU6, TLoadCosmHol<ScalarNxNAdjImplR<6>>, MIO);
|
||||
|
||||
/******************************************************************************
|
||||
* TLoadCosmHol implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename SImpl>
|
||||
TLoadCosmHol<SImpl>::TLoadCosmHol(const std::string name)
|
||||
: Module<LoadCosmHolPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename SImpl>
|
||||
std::vector<std::string> TLoadCosmHol<SImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename SImpl>
|
||||
std::vector<std::string> TLoadCosmHol<SImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename SImpl>
|
||||
void TLoadCosmHol<SImpl>::setup(void)
|
||||
{
|
||||
envCreateLat(Field, getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename SImpl>
|
||||
void TLoadCosmHol<SImpl>::execute(void)
|
||||
{
|
||||
ScalarActionParameters md;
|
||||
std::string filename = par().file + "."
|
||||
+ std::to_string(vm().getTrajectory());
|
||||
ScidacReader reader;
|
||||
const unsigned int N = SImpl::Group::Dimension;
|
||||
auto &phi = envGet(Field, getName());
|
||||
|
||||
LOG(Message) << "Loading CosmHol configuration from file '" << filename
|
||||
<< "'" << std::endl;
|
||||
reader.open(filename);
|
||||
reader.readScidacFieldRecord(phi, md);
|
||||
reader.close();
|
||||
LOG(Message) << "tr(phi^2) = "
|
||||
<< -TensorRemove(sum(trace(phi*phi))).real()/env().getVolume()
|
||||
<< std::endl;
|
||||
LOG(Message) << "Configuration parameters:" << std::endl;
|
||||
LOG(Message) << " N = " << N << std::endl;
|
||||
LOG(Message) << " m^2 = " << md.mass_squared << std::endl;
|
||||
LOG(Message) << "lambda = " << md.lambda << std::endl;
|
||||
LOG(Message) << " g = " << md.g << std::endl;
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MIO_LoadCosmHol_hpp_
|
37
Hadrons/Modules/MIO/LoadEigenPack.cc
Normal file
37
Hadrons/Modules/MIO/LoadEigenPack.cc
Normal file
@ -0,0 +1,37 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MIO/LoadEigenPack.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MIO/LoadEigenPack.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MIO;
|
||||
|
||||
template class Grid::Hadrons::MIO::TLoadEigenPack<FermionEigenPack<FIMPL>>;
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
template class Grid::Hadrons::MIO::TLoadEigenPack<FermionEigenPack<FIMPL, FIMPLF>>;
|
||||
#endif
|
133
Hadrons/Modules/MIO/LoadEigenPack.hpp
Normal file
133
Hadrons/Modules/MIO/LoadEigenPack.hpp
Normal file
@ -0,0 +1,133 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MIO/LoadEigenPack.hpp
|
||||
|
||||
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 */
|
||||
#ifndef Hadrons_MIO_LoadEigenPack_hpp_
|
||||
#define Hadrons_MIO_LoadEigenPack_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Hadrons/EigenPack.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Load eigen vectors/values package *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MIO)
|
||||
|
||||
class LoadEigenPackPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(LoadEigenPackPar,
|
||||
std::string, filestem,
|
||||
bool, multiFile,
|
||||
unsigned int, size,
|
||||
unsigned int, Ls);
|
||||
};
|
||||
|
||||
template <typename Pack>
|
||||
class TLoadEigenPack: public Module<LoadEigenPackPar>
|
||||
{
|
||||
public:
|
||||
typedef typename Pack::Field Field;
|
||||
typedef typename Pack::FieldIo FieldIo;
|
||||
typedef BaseEigenPack<Field> BasePack;
|
||||
public:
|
||||
// constructor
|
||||
TLoadEigenPack(const std::string name);
|
||||
// destructor
|
||||
virtual ~TLoadEigenPack(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(LoadFermionEigenPack, TLoadEigenPack<FermionEigenPack<FIMPL>>, MIO);
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
MODULE_REGISTER_TMP(LoadFermionEigenPackIo32, ARG(TLoadEigenPack<FermionEigenPack<FIMPL, FIMPLF>>), MIO);
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* TLoadEigenPack implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
TLoadEigenPack<Pack>::TLoadEigenPack(const std::string name)
|
||||
: Module<LoadEigenPackPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
std::vector<std::string> TLoadEigenPack<Pack>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename Pack>
|
||||
std::vector<std::string> TLoadEigenPack<Pack>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
void TLoadEigenPack<Pack>::setup(void)
|
||||
{
|
||||
GridBase *gridIo = nullptr;
|
||||
|
||||
if (typeHash<Field>() != typeHash<FieldIo>())
|
||||
{
|
||||
gridIo = envGetRbGrid(FieldIo, par().Ls);
|
||||
}
|
||||
envCreateDerived(BasePack, Pack, getName(), par().Ls, par().size,
|
||||
envGetRbGrid(Field, par().Ls), gridIo);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
void TLoadEigenPack<Pack>::execute(void)
|
||||
{
|
||||
auto &epack = envGetDerived(BasePack, Pack, getName());
|
||||
|
||||
epack.read(par().filestem, par().multiFile, vm().getTrajectory());
|
||||
epack.eval.resize(par().size);
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MIO_LoadEigenPack_hpp_
|
34
Hadrons/Modules/MIO/LoadNersc.cc
Normal file
34
Hadrons/Modules/MIO/LoadNersc.cc
Normal file
@ -0,0 +1,34 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MIO/LoadNersc.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MIO/LoadNersc.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MIO;
|
||||
|
||||
template class Grid::Hadrons::MIO::TLoadNersc<GIMPL>;
|
121
Hadrons/Modules/MIO/LoadNersc.hpp
Normal file
121
Hadrons/Modules/MIO/LoadNersc.hpp
Normal file
@ -0,0 +1,121 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MIO/LoadNersc.hpp
|
||||
|
||||
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 */
|
||||
#ifndef Hadrons_MIO_LoadNersc_hpp_
|
||||
#define Hadrons_MIO_LoadNersc_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Load a NERSC configuration *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MIO)
|
||||
|
||||
class LoadNerscPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(LoadNerscPar,
|
||||
std::string, file);
|
||||
};
|
||||
|
||||
template <typename GImpl>
|
||||
class TLoadNersc: public Module<LoadNerscPar>
|
||||
{
|
||||
public:
|
||||
GAUGE_TYPE_ALIASES(GImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TLoadNersc(const std::string name);
|
||||
// destructor
|
||||
virtual ~TLoadNersc(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(LoadNersc, TLoadNersc<GIMPL>, MIO);
|
||||
|
||||
/******************************************************************************
|
||||
* TLoadNersc implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
TLoadNersc<GImpl>::TLoadNersc(const std::string name)
|
||||
: Module<LoadNerscPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
std::vector<std::string> TLoadNersc<GImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename GImpl>
|
||||
std::vector<std::string> TLoadNersc<GImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
void TLoadNersc<GImpl>::setup(void)
|
||||
{
|
||||
envCreateLat(GaugeField, getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename GImpl>
|
||||
void TLoadNersc<GImpl>::execute(void)
|
||||
{
|
||||
FieldMetaData header;
|
||||
std::string fileName = par().file + "."
|
||||
+ std::to_string(vm().getTrajectory());
|
||||
LOG(Message) << "Loading NERSC configuration from file '" << fileName
|
||||
<< "'" << std::endl;
|
||||
|
||||
auto &U = envGet(GaugeField, getName());
|
||||
NerscIO::readConfiguration(U, header, fileName);
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MIO_LoadNersc_hpp_
|
35
Hadrons/Modules/MLoop/NoiseLoop.cc
Normal file
35
Hadrons/Modules/MLoop/NoiseLoop.cc
Normal file
@ -0,0 +1,35 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MLoop/NoiseLoop.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MLoop/NoiseLoop.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MLoop;
|
||||
|
||||
template class Grid::Hadrons::MLoop::TNoiseLoop<FIMPL>;
|
||||
|
134
Hadrons/Modules/MLoop/NoiseLoop.hpp
Normal file
134
Hadrons/Modules/MLoop/NoiseLoop.hpp
Normal file
@ -0,0 +1,134 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MLoop/NoiseLoop.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Lanny91 <andrew.lawson@gmail.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 */
|
||||
|
||||
#ifndef Hadrons_MLoop_NoiseLoop_hpp_
|
||||
#define Hadrons_MLoop_NoiseLoop_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/*
|
||||
|
||||
Noise loop propagator
|
||||
-----------------------------
|
||||
* loop_x = q_x * adj(eta_x)
|
||||
|
||||
* options:
|
||||
- q = Result of inversion on noise source.
|
||||
- eta = noise source.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* NoiseLoop *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MLoop)
|
||||
|
||||
class NoiseLoopPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(NoiseLoopPar,
|
||||
std::string, q,
|
||||
std::string, eta);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TNoiseLoop: public Module<NoiseLoopPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TNoiseLoop(const std::string name);
|
||||
// destructor
|
||||
virtual ~TNoiseLoop(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(NoiseLoop, TNoiseLoop<FIMPL>, MLoop);
|
||||
|
||||
/******************************************************************************
|
||||
* TNoiseLoop implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TNoiseLoop<FImpl>::TNoiseLoop(const std::string name)
|
||||
: Module<NoiseLoopPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TNoiseLoop<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().q, par().eta};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TNoiseLoop<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TNoiseLoop<FImpl>::setup(void)
|
||||
{
|
||||
envCreateLat(PropagatorField, getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TNoiseLoop<FImpl>::execute(void)
|
||||
{
|
||||
auto &loop = envGet(PropagatorField, getName());
|
||||
auto &q = envGet(PropagatorField, par().q);
|
||||
auto &eta = envGet(PropagatorField, par().eta);
|
||||
loop = q*adj(eta);
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MLoop_NoiseLoop_hpp_
|
36
Hadrons/Modules/MNPR/Amputate.cc
Normal file
36
Hadrons/Modules/MNPR/Amputate.cc
Normal file
@ -0,0 +1,36 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MNPR/Amputate.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MNPR/Amputate.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MNPR;
|
||||
|
||||
template class Grid::Hadrons::MNPR::TAmputate<FIMPL,FIMPL>;
|
||||
|
200
Hadrons/Modules/MNPR/Amputate.hpp
Normal file
200
Hadrons/Modules/MNPR/Amputate.hpp
Normal file
@ -0,0 +1,200 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MNPR/Amputate.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Julia Kettle J.R.Kettle-2@sms.ed.ac.uk
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
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_Amputate_hpp_
|
||||
#define Hadrons_Amputate_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Grid/Eigen/LU>
|
||||
//#include <Grid/qcd/utils/PropagatorUtils.h>
|
||||
//#include <Grid/serialisation/Serialisation.h>
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* TAmputate *
|
||||
Performs bilinear contractions of the type tr[g5*adj(Sout)*g5*G*Sin]
|
||||
Suitable for non exceptional momenta
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MNPR)
|
||||
|
||||
class AmputatePar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(AmputatePar,
|
||||
std::string, Sin, //need to make this a propogator type?
|
||||
std::string, Sout, //same
|
||||
std::string, vertex,
|
||||
std::string, pin,
|
||||
std::string, pout,
|
||||
std::string, output,
|
||||
std::string, input);
|
||||
};
|
||||
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
class TAmputate: public Module<AmputatePar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl1, 1);
|
||||
FERM_TYPE_ALIASES(FImpl2, 2);
|
||||
class Result: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
|
||||
std::vector<Complex>, Vamp,
|
||||
);
|
||||
};
|
||||
public:
|
||||
// constructor
|
||||
TAmputate(const std::string name);
|
||||
// destructor
|
||||
virtual ~TAmputate(void) {};
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
virtual SpinColourMatrix invertspincolmat(SpinColourMatrix &scmat);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(Amputate, ARG(TAmputate<FIMPL, FIMPL>), MNPR);
|
||||
|
||||
/******************************************************************************
|
||||
* TAmputate implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
TAmputate<FImpl1, FImpl2>::TAmputate(const std::string name)
|
||||
: Module<AmputatePar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
std::vector<std::string> TAmputate<FImpl1, FImpl2>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> input = {par().Sin, par().Sout, par().vertex};
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
std::vector<std::string> TAmputate<FImpl1, FImpl2>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> output = {getName()};
|
||||
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
// Invert spin colour matrix using Eigen
|
||||
template <typename Fimpl1, typename Fimpl2>
|
||||
SpinColourMatrix TAmputate<Fimpl1, Fimpl2>::invertspincolmat(SpinColourMatrix &scmat)
|
||||
{
|
||||
Eigen::MatrixXcf scmat_2d(Ns*Nc,Ns*Nc);
|
||||
for(int ic=0; ic<Nc; ic++){
|
||||
for(int jc=0; jc<Nc; jc++){
|
||||
for(int is=0; is<Ns; is++){
|
||||
for(int js=0; js<Ns; js++){
|
||||
scmat_2d(Ns*ic+is,Ns*jc+js) = scmat()(is,js)(ic,jc);
|
||||
}}
|
||||
}}
|
||||
Eigen::MatrixXcf scmat_2d_inv = scmat_2d.inverse();
|
||||
SpinColourMatrix scmat_inv;
|
||||
for(int ic=0; ic<Nc; ic++){
|
||||
for(int jc=0; jc<Nc; jc++){
|
||||
for(int is=0; is<Ns; is++){
|
||||
for(int js=0; js<Ns; js++){
|
||||
scmat_inv()(is,js)(ic,jc) = scmat_2d_inv(Ns*ic+is,Ns*jc+js);
|
||||
}}
|
||||
}}
|
||||
return scmat_inv;
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
void TAmputate<FImpl1, FImpl2>::execute(void)
|
||||
{
|
||||
LOG(Message) << "Computing bilinear amputations '" << getName() << "' using"
|
||||
<< " momentum '" << par().Sin << "' and '" << par().Sout << "'"
|
||||
<< std::endl;
|
||||
BinaryWriter writer(par().output);
|
||||
PropagatorField1 &Sin = *env().template getObject<PropagatorField1>(par().Sin); //Do these have the phases taken into account?? Don't think so. FIX
|
||||
PropagatorField2 &Sout = *env().template getObject<PropagatorField2>(par().Sout);
|
||||
std::vector<int> pin = strToVec<int>(par().pin), pout = strToVec<int>(par().pout);
|
||||
std::vector<Real> latt_size(pin.begin(), pin.end());
|
||||
LatticeComplex pdotxin(env().getGrid()), pdotxout(env().getGrid()), coor(env().getGrid());
|
||||
LOG(Message) << "Propagators set up " << std::endl;
|
||||
std::vector<SpinColourMatrix> vertex; // Let's read from file here
|
||||
Gamma g5(Gamma::Algebra::Gamma5);
|
||||
Result result;
|
||||
LOG(Message) << "reading file - " << par().input << std::endl;
|
||||
BinaryReader reader(par().input);
|
||||
Complex Ci(0.0,1.0);
|
||||
|
||||
std::string svertex;
|
||||
read(reader,"vertex", vertex);
|
||||
LOG(Message) << "vertex read" << std::endl;
|
||||
|
||||
pdotxin=Zero();
|
||||
pdotxout=Zero();
|
||||
for (unsigned int mu = 0; mu < 4; ++mu)
|
||||
{
|
||||
Real TwoPiL = M_PI * 2.0/ latt_size[mu];
|
||||
LatticeCoordinate(coor,mu);
|
||||
pdotxin = pdotxin +(TwoPiL * pin[mu]) * coor;
|
||||
pdotxout= pdotxout +(TwoPiL * pout[mu]) * coor;
|
||||
}
|
||||
Sin = Sin*exp(-Ci*pdotxin); //phase corrections
|
||||
Sout = Sout*exp(-Ci*pdotxout);
|
||||
|
||||
SpinColourMatrix Sin_mom = sum(Sin);
|
||||
SpinColourMatrix Sout_mom = sum(Sout);
|
||||
LOG(Message) << "summed over lattice" << std::endl;
|
||||
|
||||
LOG(Message) << "Lattice -> spincolourmatrix conversion" << std::endl;
|
||||
|
||||
SpinColourMatrix Sin_inv = invertspincolmat(Sin_mom);
|
||||
SpinColourMatrix Sout_inv = invertspincolmat(Sout_mom);
|
||||
LOG(Message) << "Inversions done" << std::endl;
|
||||
|
||||
result.Vamp.resize(Gamma::nGamma/2);
|
||||
for( int mu=0; mu < Gamma::nGamma/2; mu++){
|
||||
Gamma::Algebra gam = mu;
|
||||
result.Vamp[mu] = 1/12.0*trace(adj(Gamma(mu*2+1))*g5*Sout_inv*g5*vertex[mu]*Sin_inv);
|
||||
LOG(Message) << "Vamp[" << mu << "] - " << result.Vamp[mu] << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Amputate_hpp_
|
36
Hadrons/Modules/MNPR/Bilinear.cc
Normal file
36
Hadrons/Modules/MNPR/Bilinear.cc
Normal file
@ -0,0 +1,36 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MNPR/Bilinear.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MNPR/Bilinear.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MNPR;
|
||||
|
||||
template class Grid::Hadrons::MNPR::TBilinear<FIMPL,FIMPL>;
|
||||
|
225
Hadrons/Modules/MNPR/Bilinear.hpp
Normal file
225
Hadrons/Modules/MNPR/Bilinear.hpp
Normal file
@ -0,0 +1,225 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MNPR/Bilinear.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Julia Kettle J.R.Kettle-2@sms.ed.ac.uk
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
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_Bilinear_hpp_
|
||||
#define Hadrons_Bilinear_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
//#include <Grid/qcd/utils/PropagatorUtils.h>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* TBilinear *
|
||||
Performs bilinear contractions of the type tr[g5*adj(Sout)*g5*G*Sin]
|
||||
Suitable for non exceptional momenta in Rome-Southampton NPR
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MNPR)
|
||||
|
||||
class BilinearPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(BilinearPar,
|
||||
std::string, Sin,
|
||||
std::string, Sout,
|
||||
std::string, pin,
|
||||
std::string, pout,
|
||||
std::string, output);
|
||||
};
|
||||
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
class TBilinear: public Module<BilinearPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl1, 1);
|
||||
FERM_TYPE_ALIASES(FImpl2, 2);
|
||||
class Result: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
|
||||
std::vector<SpinColourMatrix>, bilinear);
|
||||
};
|
||||
public:
|
||||
// constructor
|
||||
TBilinear(const std::string name);
|
||||
// destructor
|
||||
virtual ~TBilinear(void) {};
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
//LatticeSpinColourMatrix PhaseProps(LatticeSpinColourMatrix S, std::vector<Real> p);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(Bilinear, ARG(TBilinear<FIMPL, FIMPL>), MNPR);
|
||||
|
||||
/******************************************************************************
|
||||
* TBilinear implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
TBilinear<FImpl1, FImpl2>::TBilinear(const std::string name)
|
||||
: Module<BilinearPar>(name)
|
||||
{}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
void TBilinear<FImpl1, FImpl2>::setup(void)
|
||||
{
|
||||
//env().template registerLattice<LatticeSpinColourMatrix>(getName());
|
||||
//env().template registerObject<SpinColourMatrix>(getName());
|
||||
}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
std::vector<std::string> TBilinear<FImpl1, FImpl2>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> input = {par().Sin, par().Sout};
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
std::vector<std::string> TBilinear<FImpl1, FImpl2>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/*
|
||||
/////Phase propagators//////////////////////////
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
LatticeSpinColourMatrix TBilinear<FImpl1, FImpl2>::PhaseProps(LatticeSpinColourMatrix S, std::vector<Real> p)
|
||||
{
|
||||
GridBase *grid = S._grid;
|
||||
LatticeComplex pdotx(grid), coor(grid);
|
||||
std::vector<int> latt_size = grid->_fdimensions;
|
||||
Complex Ci(0.0,1.0);
|
||||
pdotx=Zero();
|
||||
for (unsigned int mu = 0; mu < 4; ++mu)
|
||||
{
|
||||
Real TwoPiL = M_PI * 2.0/ latt_size[mu];
|
||||
LatticeCoordinate(coor,mu);
|
||||
pdotx = pdotx +(TwoPiL * p[mu]) * coor;
|
||||
}
|
||||
S = S*exp(-Ci*pdotx);
|
||||
return S;
|
||||
}
|
||||
*/
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
void TBilinear<FImpl1, FImpl2>::execute(void)
|
||||
{
|
||||
/**************************************************************************
|
||||
|
||||
Compute the bilinear vertex needed for the NPR.
|
||||
V(G) = sum_x [ g5 * adj(S'(x,p2)) * g5 * G * S'(x,p1) ]_{si,sj,ci,cj}
|
||||
G is one of the 16 gamma vertices [I,gmu,g5,g5gmu,sig(mu,nu)]
|
||||
|
||||
* G
|
||||
/ \
|
||||
p1/ \p2
|
||||
/ \
|
||||
/ \
|
||||
|
||||
Returns a spin-colour matrix, with indices si,sj, ci,cj
|
||||
|
||||
Conventions:
|
||||
p1 - incoming momenta
|
||||
p2 - outgoing momenta
|
||||
q = (p1-p2)
|
||||
**************************************************************************/
|
||||
|
||||
LOG(Message) << "Computing bilinear contractions '" << getName() << "' using"
|
||||
<< " momentum '" << par().Sin << "' and '" << par().Sout << "'"
|
||||
<< std::endl;
|
||||
|
||||
BinaryWriter writer(par().output);
|
||||
|
||||
|
||||
// Propogators
|
||||
LatticeSpinColourMatrix &Sin = *env().template getObject<LatticeSpinColourMatrix>(par().Sin);
|
||||
LatticeSpinColourMatrix &Sout = *env().template getObject<LatticeSpinColourMatrix>(par().Sout);
|
||||
LatticeComplex pdotxin(env().getGrid()), pdotxout(env().getGrid()), coor(env().getGrid());
|
||||
// momentum on legs
|
||||
std::vector<Real> pin = strToVec<Real>(par().pin), pout = strToVec<Real>(par().pout);
|
||||
std::vector<Real> latt_size(pin.begin(), pin.end());
|
||||
//bilinears
|
||||
LatticeSpinColourMatrix bilinear_x(env().getGrid());
|
||||
SpinColourMatrix bilinear;
|
||||
Gamma g5(Gamma::Algebra::Gamma5);
|
||||
Result result;
|
||||
Complex Ci(0.0,1.0);
|
||||
|
||||
//
|
||||
|
||||
pdotxin=Zero();
|
||||
pdotxout=Zero();
|
||||
for (unsigned int mu = 0; mu < 4; ++mu)
|
||||
{
|
||||
Real TwoPiL = M_PI * 2.0/ latt_size[mu];
|
||||
LatticeCoordinate(coor,mu);
|
||||
pdotxin = pdotxin +(TwoPiL * pin[mu]) * coor;
|
||||
pdotxout= pdotxout +(TwoPiL * pout[mu]) * coor;
|
||||
}
|
||||
Sin = Sin*exp(-Ci*pdotxin); //phase corrections
|
||||
Sout = Sout*exp(-Ci*pdotxout);
|
||||
|
||||
////Set up gamma vector//////////////////////////
|
||||
std::vector<Gamma> gammavector;
|
||||
for( int i=0; i<Gamma::nGamma; i++){
|
||||
Gamma::Algebra gam = i;
|
||||
gammavector.push_back(Gamma(gam));
|
||||
}
|
||||
result.bilinear.resize(Gamma::nGamma);
|
||||
/////////////////////////////////////////////////
|
||||
//LatticeSpinMatrix temp = g5*Sout;
|
||||
////////Form Vertex//////////////////////////////
|
||||
for (int i=0; i < Gamma::nGamma; i++){
|
||||
bilinear_x = g5*adj(Sout)*g5*gammavector[i]*Sin;
|
||||
result.bilinear[i] = sum(bilinear_x); //sum over lattice sites
|
||||
}
|
||||
//////////////////////////////////////////////////
|
||||
write(writer, par().output, result.bilinear);
|
||||
LOG(Message) << "Complete. Writing results to " << par().output << std:: endl;
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Bilinear_hpp_
|
36
Hadrons/Modules/MNPR/FourQuark.cc
Normal file
36
Hadrons/Modules/MNPR/FourQuark.cc
Normal file
@ -0,0 +1,36 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MNPR/FourQuark.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MNPR/FourQuark.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MNPR;
|
||||
|
||||
template class Grid::Hadrons::MNPR::TFourQuark<FIMPL,FIMPL>;
|
||||
|
277
Hadrons/Modules/MNPR/FourQuark.hpp
Normal file
277
Hadrons/Modules/MNPR/FourQuark.hpp
Normal file
@ -0,0 +1,277 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MNPR/FourQuark.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Julia Kettle J.R.Kettle-2@sms.ed.ac.uk
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
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_FourQuark_hpp_
|
||||
#define Hadrons_FourQuark_hpp_
|
||||
|
||||
#include <typeinfo>
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Grid/serialisation/Serialisation.h>
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* TFourQuark *
|
||||
Performs fourquark contractions of the type tr[g5*adj(Sout)*g5*G*Sin]
|
||||
Suitable for non exceptional momenta
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MNPR)
|
||||
|
||||
class FourQuarkPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(FourQuarkPar,
|
||||
std::string, Sin, //need to make this a propogator type?
|
||||
std::string, Sout, //same
|
||||
std::string, pin,
|
||||
std::string, pout,
|
||||
bool, fullbasis,
|
||||
std::string, output);
|
||||
};
|
||||
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
class TFourQuark: public Module<FourQuarkPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl1, 1);
|
||||
FERM_TYPE_ALIASES(FImpl2, 2);
|
||||
class Result: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
|
||||
std::vector<SpinColourSpinColourMatrix>, fourquark);
|
||||
};
|
||||
public:
|
||||
// constructor
|
||||
TFourQuark(const std::string name);
|
||||
// destructor
|
||||
virtual ~TFourQuark(void) {};
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void tensorprod(LatticeSpinColourSpinColourMatrix &lret, LatticeSpinColourMatrix a, LatticeSpinColourMatrix b);
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(FourQuark, ARG(TFourQuark<FIMPL, FIMPL>), MNPR);
|
||||
|
||||
/******************************************************************************
|
||||
* TFourQuark implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
TFourQuark<FImpl1, FImpl2>::TFourQuark(const std::string name)
|
||||
: Module<FourQuarkPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
std::vector<std::string> TFourQuark<FImpl1, FImpl2>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> input = {par().Sin, par().Sout};
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
std::vector<std::string> TFourQuark<FImpl1, FImpl2>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> output = {getName()};
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
void TFourQuark<FImpl1, FImpl2>::tensorprod(LatticeSpinColourSpinColourMatrix &lret, LatticeSpinColourMatrix a, LatticeSpinColourMatrix b)
|
||||
{
|
||||
#if 0
|
||||
parallel_for(auto site=lret.begin();site<lret.end();site++) {
|
||||
for (int si; si < 4; ++si){
|
||||
for(int sj; sj <4; ++sj){
|
||||
for (int ci; ci < 3; ++ci){
|
||||
for (int cj; cj < 3; ++cj){
|
||||
for (int sk; sk < 4; ++sk){
|
||||
for(int sl; sl <4; ++sl){
|
||||
for (int ck; ck < 3; ++ck){
|
||||
for (int cl; cl < 3; ++cl){
|
||||
lret[site]()(si,sj)(ci,cj)(sk,sl)(ck,cl)=a[site]()(si,sj)(ci,cj)*b[site]()(sk,sl)(ck,cl);
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
}
|
||||
#else
|
||||
// FIXME ; is there a general need for this construct ? In which case we should encapsulate the
|
||||
// below loops in a helper function.
|
||||
//LOG(Message) << "sp co mat a is - " << a << std::endl;
|
||||
//LOG(Message) << "sp co mat b is - " << b << std::endl;
|
||||
auto lret_v = lret.View();
|
||||
auto a_v = a.View();
|
||||
auto b_v = b.View();
|
||||
parallel_for(auto site=lret_v.begin();site<lret_v.end();site++) {
|
||||
vTComplex left;
|
||||
for(int si=0; si < Ns; ++si){
|
||||
for(int sj=0; sj < Ns; ++sj){
|
||||
for (int ci=0; ci < Nc; ++ci){
|
||||
for (int cj=0; cj < Nc; ++cj){
|
||||
//LOG(Message) << "si, sj, ci, cj - " << si << ", " << sj << ", "<< ci << ", "<< cj << std::endl;
|
||||
left()()() = a_v[site]()(si,sj)(ci,cj);
|
||||
//LOG(Message) << left << std::endl;
|
||||
lret_v[site]()(si,sj)(ci,cj)=left()*b_v[site]();
|
||||
}}
|
||||
}}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
void TFourQuark<FImpl1, FImpl2>::setup(void)
|
||||
{
|
||||
envCreateLat(LatticeSpinColourMatrix, getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl1, typename FImpl2>
|
||||
void TFourQuark<FImpl1, FImpl2>::execute(void)
|
||||
{
|
||||
|
||||
/*********************************************************************************
|
||||
|
||||
TFourQuark : Creates the four quark vertex required for the NPR of four-quark ops
|
||||
|
||||
V_{Gamma_1,Gamma_2} = sum_x [ ( g5 * adj(S'(x,p2)) * g5 * G1 * S'(x,p1) )_ci,cj;si,sj x ( g5 * adj(S'(x,p2)) * g5 * G2 S'(x,p1) )_ck,cl;sk,cl ]
|
||||
|
||||
Create a bilinear vertex for G1 and G2 the spin and colour indices are kept free. Where there are 16 potential Gs.
|
||||
We then find the outer product of V1 and V2, keeping the spin and colour indices uncontracted
|
||||
Then this is summed over the lattice coordinate
|
||||
Result is a SpinColourSpinColourMatrix - with 4 colour and 4 spin indices.
|
||||
We have up to 256 of these including the offdiag (G1 != G2).
|
||||
|
||||
\ /
|
||||
\p1 p1/
|
||||
\ /
|
||||
\ /
|
||||
G1 * * G2
|
||||
/ \
|
||||
/ \
|
||||
/p2 p2\
|
||||
/ \
|
||||
|
||||
*********************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
LOG(Message) << "Computing fourquark contractions '" << getName() << "' using"
|
||||
<< " momentum '" << par().Sin << "' and '" << par().Sout << "'"
|
||||
<< std::endl;
|
||||
|
||||
BinaryWriter writer(par().output);
|
||||
|
||||
PropagatorField1 &Sin = *env().template getObject<PropagatorField1>(par().Sin);
|
||||
PropagatorField2 &Sout = *env().template getObject<PropagatorField2>(par().Sout);
|
||||
std::vector<Real> pin = strToVec<Real>(par().pin), pout = strToVec<Real>(par().pout);
|
||||
bool fullbasis = par().fullbasis;
|
||||
Gamma g5(Gamma::Algebra::Gamma5);
|
||||
Result result;
|
||||
std::vector<Real> latt_size(pin.begin(), pin.end());
|
||||
LatticeComplex pdotxin(env().getGrid()), pdotxout(env().getGrid()), coor(env().getGrid());
|
||||
LatticeSpinColourMatrix bilinear_mu(env().getGrid()), bilinear_nu(env().getGrid());
|
||||
LatticeSpinColourSpinColourMatrix lret(env().getGrid());
|
||||
Complex Ci(0.0,1.0);
|
||||
|
||||
//Phase propagators
|
||||
//Sin = Grid::QCD::PropUtils::PhaseProps(Sin,pin);
|
||||
//Sout = Grid::QCD::PropUtils::PhaseProps(Sout,pout);
|
||||
|
||||
//find p.x for in and out so phase can be accounted for in propagators
|
||||
pdotxin=Zero();
|
||||
pdotxout=Zero();
|
||||
for (unsigned int mu = 0; mu < 4; ++mu)
|
||||
{
|
||||
Real TwoPiL = M_PI * 2.0/ latt_size[mu];
|
||||
LatticeCoordinate(coor,mu);
|
||||
pdotxin = pdotxin +(TwoPiL * pin[mu]) * coor;
|
||||
pdotxout= pdotxout +(TwoPiL * pout[mu]) * coor;
|
||||
}
|
||||
Sin = Sin*exp(-Ci*pdotxin); //phase corrections
|
||||
Sout = Sout*exp(-Ci*pdotxout);
|
||||
|
||||
|
||||
//Set up Gammas
|
||||
std::vector<Gamma> gammavector;
|
||||
for( int i=1; i<Gamma::nGamma; i+=2){
|
||||
Gamma::Algebra gam = i;
|
||||
gammavector.push_back(Gamma(gam));
|
||||
}
|
||||
|
||||
lret = Zero();
|
||||
if (fullbasis == true){ // all combinations of mu and nu
|
||||
result.fourquark.resize(Gamma::nGamma/2*Gamma::nGamma/2);
|
||||
for( int mu=0; mu<Gamma::nGamma/2; mu++){
|
||||
bilinear_mu = g5*adj(Sout)*g5*gammavector[mu]*Sin;
|
||||
for ( int nu=0; nu<Gamma::nGamma; nu++){
|
||||
LatticeSpinColourMatrix bilinear_nu(env().getGrid());
|
||||
bilinear_nu = g5*adj(Sout)*g5*gammavector[nu]*Sin;
|
||||
LOG(Message) << "bilinear_nu for nu = " << nu << " is - " << bilinear_mu << std::endl;
|
||||
result.fourquark[mu*Gamma::nGamma/2 + nu] = Zero();
|
||||
tensorprod(lret,bilinear_mu,bilinear_nu);
|
||||
result.fourquark[mu*Gamma::nGamma/2 + nu] = sum(lret);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result.fourquark.resize(Gamma::nGamma/2);
|
||||
for ( int mu=0; mu<1; mu++){
|
||||
//for( int mu=0; mu<Gamma::nGamma/2; mu++ ){
|
||||
bilinear_mu = g5*adj(Sout)*g5*gammavector[mu]*Sin;
|
||||
//LOG(Message) << "bilinear_mu for mu = " << mu << " is - " << bilinear_mu << std::endl;
|
||||
result.fourquark[mu] = Zero();
|
||||
tensorprod(lret,bilinear_mu,bilinear_mu); //tensor outer product
|
||||
result.fourquark[mu] = sum(lret);
|
||||
}
|
||||
}
|
||||
write(writer, "fourquark", result.fourquark);
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_FourQuark_hpp_
|
36
Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.cc
Normal file
36
Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.cc
Normal file
@ -0,0 +1,36 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Vera Guelpers <Vera.Guelpers@ed.ac.uk>
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MNoise;
|
||||
|
||||
template class Grid::Hadrons::MNoise::TFullVolumeSpinColorDiagonal<FIMPL>;
|
||||
template class Grid::Hadrons::MNoise::TFullVolumeSpinColorDiagonal<ZFIMPL>;
|
121
Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.hpp
Normal file
121
Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.hpp
Normal file
@ -0,0 +1,121 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Vera Guelpers <Vera.Guelpers@ed.ac.uk>
|
||||
|
||||
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_MNoise_FullVolumeSpinColorDiagonal_hpp_
|
||||
#define Hadrons_MNoise_FullVolumeSpinColorDiagonal_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Hadrons/DilutedNoise.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Generate full volume spin-color diagonal noise *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MNoise)
|
||||
|
||||
class FullVolumeSpinColorDiagonalPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(FullVolumeSpinColorDiagonalPar,
|
||||
unsigned int, nsrc);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TFullVolumeSpinColorDiagonal: public Module<FullVolumeSpinColorDiagonalPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TFullVolumeSpinColorDiagonal(const std::string name);
|
||||
// destructor
|
||||
virtual ~TFullVolumeSpinColorDiagonal(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(FullVolumeSpinColorDiagonal, TFullVolumeSpinColorDiagonal<FIMPL>, MNoise);
|
||||
MODULE_REGISTER_TMP(ZFullVolumeSpinColorDiagonal, TFullVolumeSpinColorDiagonal<ZFIMPL>, MNoise);
|
||||
|
||||
/******************************************************************************
|
||||
* TFullVolumeSpinColorDiagonal implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TFullVolumeSpinColorDiagonal<FImpl>::TFullVolumeSpinColorDiagonal(const std::string name)
|
||||
: Module<FullVolumeSpinColorDiagonalPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TFullVolumeSpinColorDiagonal<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TFullVolumeSpinColorDiagonal<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TFullVolumeSpinColorDiagonal<FImpl>::setup(void)
|
||||
{
|
||||
envCreateDerived(DilutedNoise<FImpl>,
|
||||
FullVolumeSpinColorDiagonalNoise<FImpl>,
|
||||
getName(), 1, envGetGrid(FermionField), par().nsrc);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TFullVolumeSpinColorDiagonal<FImpl>::execute(void)
|
||||
{
|
||||
auto &noise = envGet(DilutedNoise<FImpl>, getName());
|
||||
LOG(Message) << "Generating full volume, spin-color diagonal noise" << std::endl;
|
||||
noise.generateNoise(rng4d());
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MNoise_FullVolumeSpinColorDiagonal_hpp_
|
35
Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc
Normal file
35
Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc
Normal file
@ -0,0 +1,35 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MNoise;
|
||||
|
||||
template class Grid::Hadrons::MNoise::TTimeDilutedSpinColorDiagonal<FIMPL>;
|
||||
template class Grid::Hadrons::MNoise::TTimeDilutedSpinColorDiagonal<ZFIMPL>;
|
114
Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp
Normal file
114
Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp
Normal file
@ -0,0 +1,114 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp
|
||||
|
||||
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 */
|
||||
#ifndef Hadrons_MNoise_TimeDilutedSpinColorDiagonal_hpp_
|
||||
#define Hadrons_MNoise_TimeDilutedSpinColorDiagonal_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Hadrons/DilutedNoise.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Generate time diluted spin-color diagonal noise *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MNoise)
|
||||
|
||||
template <typename FImpl>
|
||||
class TTimeDilutedSpinColorDiagonal: public Module<NoPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TTimeDilutedSpinColorDiagonal(const std::string name);
|
||||
// destructor
|
||||
virtual ~TTimeDilutedSpinColorDiagonal(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(TimeDilutedSpinColorDiagonal, TTimeDilutedSpinColorDiagonal<FIMPL>, MNoise);
|
||||
MODULE_REGISTER_TMP(ZTimeDilutedSpinColorDiagonal, TTimeDilutedSpinColorDiagonal<ZFIMPL>, MNoise);
|
||||
|
||||
/******************************************************************************
|
||||
* TTimeDilutedSpinColorDiagonal implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TTimeDilutedSpinColorDiagonal<FImpl>::TTimeDilutedSpinColorDiagonal(const std::string name)
|
||||
: Module<NoPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TTimeDilutedSpinColorDiagonal<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TTimeDilutedSpinColorDiagonal<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TTimeDilutedSpinColorDiagonal<FImpl>::setup(void)
|
||||
{
|
||||
envCreateDerived(DilutedNoise<FImpl>,
|
||||
TimeDilutedSpinColorDiagonalNoise<FImpl>,
|
||||
getName(), 1, envGetGrid(FermionField));
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TTimeDilutedSpinColorDiagonal<FImpl>::execute(void)
|
||||
{
|
||||
auto &noise = envGet(DilutedNoise<FImpl>, getName());
|
||||
|
||||
LOG(Message) << "Generating time-diluted, spin-color diagonal noise" << std::endl;
|
||||
noise.generateNoise(rng4d());
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MNoise_TimeDilutedSpinColorDiagonal_hpp_
|
312
Hadrons/Modules/MScalar/ChargedProp.cc
Normal file
312
Hadrons/Modules/MScalar/ChargedProp.cc
Normal file
@ -0,0 +1,312 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MScalar/ChargedProp.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: James Harrison <jch1g10@soton.ac.uk>
|
||||
|
||||
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 */
|
||||
#include <Hadrons/Modules/MScalar/ChargedProp.hpp>
|
||||
#include <Hadrons/Modules/MScalar/Scalar.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MScalar;
|
||||
|
||||
/******************************************************************************
|
||||
* TChargedProp implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
TChargedProp::TChargedProp(const std::string name)
|
||||
: Module<ChargedPropPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> TChargedProp::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().source, par().emField};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
std::vector<std::string> TChargedProp::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName(), getName()+"_0", getName()+"_Q",
|
||||
getName()+"_Sun", getName()+"_Tad"};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
void TChargedProp::setup(void)
|
||||
{
|
||||
freeMomPropName_ = FREEMOMPROP(par().mass);
|
||||
phaseName_.clear();
|
||||
for (unsigned int mu = 0; mu < env().getNd(); ++mu)
|
||||
{
|
||||
phaseName_.push_back("_shiftphase_" + std::to_string(mu));
|
||||
}
|
||||
GFSrcName_ = getName() + "_DinvSrc";
|
||||
prop0Name_ = getName() + "_0";
|
||||
propQName_ = getName() + "_Q";
|
||||
propSunName_ = getName() + "_Sun";
|
||||
propTadName_ = getName() + "_Tad";
|
||||
fftName_ = getName() + "_fft";
|
||||
|
||||
freeMomPropDone_ = env().hasCreatedObject(freeMomPropName_);
|
||||
GFSrcDone_ = env().hasCreatedObject(GFSrcName_);
|
||||
phasesDone_ = env().hasCreatedObject(phaseName_[0]);
|
||||
prop0Done_ = env().hasCreatedObject(prop0Name_);
|
||||
envCacheLat(ScalarField, freeMomPropName_);
|
||||
for (unsigned int mu = 0; mu < env().getNd(); ++mu)
|
||||
{
|
||||
envCacheLat(ScalarField, phaseName_[mu]);
|
||||
}
|
||||
envCacheLat(ScalarField, GFSrcName_);
|
||||
envCacheLat(ScalarField, prop0Name_);
|
||||
envCreateLat(ScalarField, getName());
|
||||
envCreateLat(ScalarField, propQName_);
|
||||
envCreateLat(ScalarField, propSunName_);
|
||||
envCreateLat(ScalarField, propTadName_);
|
||||
envTmpLat(ScalarField, "buf");
|
||||
envTmpLat(ScalarField, "result");
|
||||
envTmpLat(ScalarField, "Amu");
|
||||
envCache(FFT, fftName_, 1, env().getGrid());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void TChargedProp::execute(void)
|
||||
{
|
||||
// CACHING ANALYTIC EXPRESSIONS
|
||||
makeCaches();
|
||||
|
||||
// PROPAGATOR CALCULATION
|
||||
LOG(Message) << "Computing charged scalar propagator"
|
||||
<< " (mass= " << par().mass
|
||||
<< ", charge= " << par().charge << ")..." << std::endl;
|
||||
|
||||
auto &prop = envGet(ScalarField, getName());
|
||||
auto &prop0 = envGet(ScalarField, prop0Name_);
|
||||
auto &propQ = envGet(ScalarField, propQName_);
|
||||
auto &propSun = envGet(ScalarField, propSunName_);
|
||||
auto &propTad = envGet(ScalarField, propTadName_);
|
||||
auto &GFSrc = envGet(ScalarField, GFSrcName_);
|
||||
auto &G = envGet(ScalarField, freeMomPropName_);
|
||||
auto &fft = envGet(FFT, fftName_);
|
||||
double q = par().charge;
|
||||
envGetTmp(ScalarField, buf);
|
||||
|
||||
// -G*momD1*G*F*Src (momD1 = F*D1*Finv)
|
||||
propQ = GFSrc;
|
||||
momD1(propQ, fft);
|
||||
propQ = -G*propQ;
|
||||
propSun = -propQ;
|
||||
fft.FFT_dim(propQ, propQ, env().getNd()-1, FFT::backward);
|
||||
|
||||
// G*momD1*G*momD1*G*F*Src (here buf = G*momD1*G*F*Src)
|
||||
momD1(propSun, fft);
|
||||
propSun = G*propSun;
|
||||
fft.FFT_dim(propSun, propSun, env().getNd()-1, FFT::backward);
|
||||
|
||||
// -G*momD2*G*F*Src (momD2 = F*D2*Finv)
|
||||
propTad = GFSrc;
|
||||
momD2(propTad, fft);
|
||||
propTad = -G*propTad;
|
||||
fft.FFT_dim(propTad, propTad, env().getNd()-1, FFT::backward);
|
||||
|
||||
// full charged scalar propagator
|
||||
fft.FFT_dim(buf, GFSrc, env().getNd()-1, FFT::backward);
|
||||
prop = buf + q*propQ + q*q*propSun + q*q*propTad;
|
||||
|
||||
// OUTPUT IF NECESSARY
|
||||
if (!par().output.empty())
|
||||
{
|
||||
Result result;
|
||||
TComplex site;
|
||||
std::vector<int> siteCoor;
|
||||
|
||||
LOG(Message) << "Saving momentum-projected propagator to '"
|
||||
<< RESULT_FILE_NAME(par().output, vm().getTrajectory()) << "'..."
|
||||
<< std::endl;
|
||||
result.projection.resize(par().outputMom.size());
|
||||
result.lattice_size = env().getGrid()->FullDimensions().toVector();
|
||||
result.mass = par().mass;
|
||||
result.charge = q;
|
||||
siteCoor.resize(env().getNd());
|
||||
for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
|
||||
{
|
||||
result.projection[i_p].momentum = strToVec<int>(par().outputMom[i_p]);
|
||||
|
||||
LOG(Message) << "Calculating (" << par().outputMom[i_p]
|
||||
<< ") momentum projection" << std::endl;
|
||||
|
||||
result.projection[i_p].corr_0.resize(env().getGrid()->FullDimensions()[env().getNd()-1]);
|
||||
result.projection[i_p].corr.resize(env().getGrid()->FullDimensions()[env().getNd()-1]);
|
||||
result.projection[i_p].corr_Q.resize(env().getGrid()->FullDimensions()[env().getNd()-1]);
|
||||
result.projection[i_p].corr_Sun.resize(env().getGrid()->FullDimensions()[env().getNd()-1]);
|
||||
result.projection[i_p].corr_Tad.resize(env().getGrid()->FullDimensions()[env().getNd()-1]);
|
||||
|
||||
for (unsigned int j = 0; j < env().getNd()-1; ++j)
|
||||
{
|
||||
siteCoor[j] = result.projection[i_p].momentum[j];
|
||||
}
|
||||
|
||||
for (unsigned int t = 0; t < result.projection[i_p].corr.size(); ++t)
|
||||
{
|
||||
siteCoor[env().getNd()-1] = t;
|
||||
peekSite(site, prop, siteCoor);
|
||||
result.projection[i_p].corr[t]=TensorRemove(site);
|
||||
peekSite(site, buf, siteCoor);
|
||||
result.projection[i_p].corr_0[t]=TensorRemove(site);
|
||||
peekSite(site, propQ, siteCoor);
|
||||
result.projection[i_p].corr_Q[t]=TensorRemove(site);
|
||||
peekSite(site, propSun, siteCoor);
|
||||
result.projection[i_p].corr_Sun[t]=TensorRemove(site);
|
||||
peekSite(site, propTad, siteCoor);
|
||||
result.projection[i_p].corr_Tad[t]=TensorRemove(site);
|
||||
}
|
||||
}
|
||||
saveResult(par().output, "prop", result);
|
||||
}
|
||||
|
||||
std::vector<int> mask(env().getNd(),1);
|
||||
mask[env().getNd()-1] = 0;
|
||||
fft.FFT_dim_mask(prop, prop, mask, FFT::backward);
|
||||
fft.FFT_dim_mask(propQ, propQ, mask, FFT::backward);
|
||||
fft.FFT_dim_mask(propSun, propSun, mask, FFT::backward);
|
||||
fft.FFT_dim_mask(propTad, propTad, mask, FFT::backward);
|
||||
}
|
||||
|
||||
void TChargedProp::makeCaches(void)
|
||||
{
|
||||
auto &freeMomProp = envGet(ScalarField, freeMomPropName_);
|
||||
auto &GFSrc = envGet(ScalarField, GFSrcName_);
|
||||
auto &prop0 = envGet(ScalarField, prop0Name_);
|
||||
auto &fft = envGet(FFT, fftName_);
|
||||
|
||||
if (!freeMomPropDone_)
|
||||
{
|
||||
LOG(Message) << "Caching momentum-space free scalar propagator"
|
||||
<< " (mass= " << par().mass << ")..." << std::endl;
|
||||
SIMPL::MomentumSpacePropagator(freeMomProp, par().mass);
|
||||
}
|
||||
if (!GFSrcDone_)
|
||||
{
|
||||
auto &source = envGet(ScalarField, par().source);
|
||||
|
||||
LOG(Message) << "Caching G*F*src..." << std::endl;
|
||||
fft.FFT_all_dim(GFSrc, source, FFT::forward);
|
||||
GFSrc = freeMomProp*GFSrc;
|
||||
}
|
||||
if (!prop0Done_)
|
||||
{
|
||||
LOG(Message) << "Caching position-space free scalar propagator..."
|
||||
<< std::endl;
|
||||
fft.FFT_all_dim(prop0, GFSrc, FFT::backward);
|
||||
}
|
||||
if (!phasesDone_)
|
||||
{
|
||||
auto l = env().getGrid()->FullDimensions();
|
||||
Complex ci(0.0,1.0);
|
||||
|
||||
LOG(Message) << "Caching shift phases..." << std::endl;
|
||||
for (unsigned int mu = 0; mu < env().getNd(); ++mu)
|
||||
{
|
||||
Real twoPiL = M_PI*2./l[mu];
|
||||
auto &phmu = envGet(ScalarField, phaseName_[mu]);
|
||||
|
||||
LatticeCoordinate(phmu, mu);
|
||||
phmu = exp(ci*twoPiL*phmu);
|
||||
phase_.push_back(&phmu);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
phase_.clear();
|
||||
for (unsigned int mu = 0; mu < env().getNd(); ++mu)
|
||||
{
|
||||
phase_.push_back(env().getObject<ScalarField>(phaseName_[mu]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TChargedProp::momD1(ScalarField &s, FFT &fft)
|
||||
{
|
||||
auto &A = envGet(EmField, par().emField);
|
||||
Complex ci(0.0,1.0);
|
||||
|
||||
envGetTmp(ScalarField, buf);
|
||||
envGetTmp(ScalarField, result);
|
||||
envGetTmp(ScalarField, Amu);
|
||||
|
||||
result = Zero();
|
||||
for (unsigned int mu = 0; mu < env().getNd(); ++mu)
|
||||
{
|
||||
Amu = peekLorentz(A, mu);
|
||||
buf = (*phase_[mu])*s;
|
||||
fft.FFT_all_dim(buf, buf, FFT::backward);
|
||||
buf = Amu*buf;
|
||||
fft.FFT_all_dim(buf, buf, FFT::forward);
|
||||
result = result - ci*buf;
|
||||
}
|
||||
fft.FFT_all_dim(s, s, FFT::backward);
|
||||
for (unsigned int mu = 0; mu < env().getNd(); ++mu)
|
||||
{
|
||||
Amu = peekLorentz(A, mu);
|
||||
buf = Amu*s;
|
||||
fft.FFT_all_dim(buf, buf, FFT::forward);
|
||||
result = result + ci*adj(*phase_[mu])*buf;
|
||||
}
|
||||
|
||||
s = result;
|
||||
}
|
||||
|
||||
void TChargedProp::momD2(ScalarField &s, FFT &fft)
|
||||
{
|
||||
auto &A = envGet(EmField, par().emField);
|
||||
|
||||
envGetTmp(ScalarField, buf);
|
||||
envGetTmp(ScalarField, result);
|
||||
envGetTmp(ScalarField, Amu);
|
||||
|
||||
result = Zero();
|
||||
for (unsigned int mu = 0; mu < env().getNd(); ++mu)
|
||||
{
|
||||
Amu = peekLorentz(A, mu);
|
||||
buf = (*phase_[mu])*s;
|
||||
fft.FFT_all_dim(buf, buf, FFT::backward);
|
||||
buf = Amu*Amu*buf;
|
||||
fft.FFT_all_dim(buf, buf, FFT::forward);
|
||||
result = result + .5*buf;
|
||||
}
|
||||
fft.FFT_all_dim(s, s, FFT::backward);
|
||||
for (unsigned int mu = 0; mu < env().getNd(); ++mu)
|
||||
{
|
||||
Amu = peekLorentz(A, mu);
|
||||
buf = Amu*Amu*s;
|
||||
fft.FFT_all_dim(buf, buf, FFT::forward);
|
||||
result = result + .5*adj(*phase_[mu])*buf;
|
||||
}
|
||||
|
||||
s = result;
|
||||
}
|
113
Hadrons/Modules/MScalar/ChargedProp.hpp
Normal file
113
Hadrons/Modules/MScalar/ChargedProp.hpp
Normal file
@ -0,0 +1,113 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MScalar/ChargedProp.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: James Harrison <jch1g10@soton.ac.uk>
|
||||
|
||||
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_MScalar_ChargedProp_hpp_
|
||||
#define Hadrons_MScalar_ChargedProp_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Charged scalar propagator *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MScalar)
|
||||
|
||||
class ChargedPropPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(ChargedPropPar,
|
||||
std::string, emField,
|
||||
std::string, source,
|
||||
double, mass,
|
||||
double, charge,
|
||||
std::string, output,
|
||||
std::vector<std::string>, outputMom);
|
||||
};
|
||||
|
||||
class TChargedProp: public Module<ChargedPropPar>
|
||||
{
|
||||
public:
|
||||
BASIC_TYPE_ALIASES(SIMPL,);
|
||||
typedef PhotonR::GaugeField EmField;
|
||||
typedef PhotonR::GaugeLinkField EmComp;
|
||||
class Result: Serializable
|
||||
{
|
||||
public:
|
||||
class Projection: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Projection,
|
||||
std::vector<int>, momentum,
|
||||
std::vector<Complex>, corr,
|
||||
std::vector<Complex>, corr_0,
|
||||
std::vector<Complex>, corr_Q,
|
||||
std::vector<Complex>, corr_Sun,
|
||||
std::vector<Complex>, corr_Tad);
|
||||
};
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
|
||||
std::vector<int>, lattice_size,
|
||||
double, mass,
|
||||
double, charge,
|
||||
std::vector<Projection>, projection);
|
||||
};
|
||||
public:
|
||||
// constructor
|
||||
TChargedProp(const std::string name);
|
||||
// destructor
|
||||
virtual ~TChargedProp(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
private:
|
||||
void makeCaches(void);
|
||||
void momD1(ScalarField &s, FFT &fft);
|
||||
void momD2(ScalarField &s, FFT &fft);
|
||||
private:
|
||||
bool freeMomPropDone_, GFSrcDone_, prop0Done_,
|
||||
phasesDone_;
|
||||
std::string freeMomPropName_, GFSrcName_, prop0Name_,
|
||||
propQName_, propSunName_, propTadName_, fftName_;
|
||||
std::vector<std::string> phaseName_;
|
||||
std::vector<ScalarField *> phase_;
|
||||
};
|
||||
|
||||
MODULE_REGISTER(ChargedProp, TChargedProp, MScalar);
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MScalar_ChargedProp_hpp_
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user