mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-13 20:57:06 +01:00
Merge branch 'develop' into feature/bgq-asm
This commit is contained in:
@ -40,7 +40,7 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
#include <Grid/GridCore.h>
|
||||
#include <Grid/GridQCDcore.h>
|
||||
#include <Grid/qcd/action/Actions.h>
|
||||
#include <Grid/qcd/action/Action.h>
|
||||
#include <Grid/qcd/smearing/Smearing.h>
|
||||
#include <Grid/qcd/hmc/HMC_aggregate.h>
|
||||
|
||||
|
@ -61,12 +61,12 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
///////////////////
|
||||
#include "Config.h"
|
||||
|
||||
#include <Grid/serialisation/Serialisation.h>
|
||||
#include <Grid/perfmon/Timer.h>
|
||||
#include <Grid/perfmon/PerfCount.h>
|
||||
#include <Grid/log/Log.h>
|
||||
#include <Grid/allocator/AlignedAllocator.h>
|
||||
#include <Grid/simd/Simd.h>
|
||||
#include <Grid/serialisation/Serialisation.h>
|
||||
#include <Grid/threads/Threads.h>
|
||||
#include <Grid/util/Util.h>
|
||||
#include <Grid/communicator/Communicator.h>
|
||||
|
@ -27,7 +27,6 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
|
||||
#ifndef GRID_QCD_CORE_H
|
||||
#define GRID_QCD_CORE_H
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
extra_sources=
|
||||
extra_headers=
|
||||
if BUILD_COMMS_MPI
|
||||
extra_sources+=communicator/Communicator_mpi.cc
|
||||
extra_sources+=communicator/Communicator_base.cc
|
||||
@ -24,6 +25,12 @@ if BUILD_COMMS_NONE
|
||||
extra_sources+=communicator/Communicator_base.cc
|
||||
endif
|
||||
|
||||
if BUILD_HDF5
|
||||
extra_sources+=serialisation/Hdf5IO.cc
|
||||
extra_headers+=serialisation/Hdf5IO.h
|
||||
extra_headers+=serialisation/Hdf5Type.h
|
||||
endif
|
||||
|
||||
#
|
||||
# Libraries
|
||||
#
|
||||
@ -32,6 +39,9 @@ include Eigen.inc
|
||||
|
||||
lib_LIBRARIES = libGrid.a
|
||||
|
||||
libGrid_a_SOURCES = $(CCFILES) $(extra_sources)
|
||||
CCFILES += $(extra_sources)
|
||||
HFILES += $(extra_headers)
|
||||
|
||||
libGrid_a_SOURCES = $(CCFILES)
|
||||
libGrid_adir = $(pkgincludedir)
|
||||
nobase_dist_pkginclude_HEADERS = $(HFILES) $(eigen_files) Config.h
|
||||
|
@ -16,7 +16,7 @@
|
||||
#define INCLUDED_ALG_REMEZ_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <Grid/Config.h>
|
||||
#include <Config.h>
|
||||
|
||||
#ifdef HAVE_LIBGMP
|
||||
#include "bigfloat.h"
|
||||
|
@ -45,6 +45,8 @@ class ConjugateGradient : public OperatorFunction<Field> {
|
||||
// Defaults true.
|
||||
RealD Tolerance;
|
||||
Integer MaxIterations;
|
||||
Integer IterationsToComplete; //Number of iterations the CG took to finish. Filled in upon completion
|
||||
|
||||
ConjugateGradient(RealD tol, Integer maxit, bool err_on_no_conv = true)
|
||||
: Tolerance(tol),
|
||||
MaxIterations(maxit),
|
||||
@ -155,13 +157,14 @@ class ConjugateGradient : public OperatorFunction<Field> {
|
||||
std::cout << std::endl;
|
||||
|
||||
if (ErrorOnNoConverge) assert(true_residual / Tolerance < 10000.0);
|
||||
|
||||
IterationsToComplete = k;
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::cout << GridLogMessage << "ConjugateGradient did NOT converge"
|
||||
<< std::endl;
|
||||
if (ErrorOnNoConverge) assert(0);
|
||||
IterationsToComplete = k;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ namespace Grid {
|
||||
class MixedPrecisionConjugateGradient : public LinearFunction<FieldD> {
|
||||
public:
|
||||
RealD Tolerance;
|
||||
RealD InnerTolerance; //Initial tolerance for inner CG. Defaults to Tolerance but can be changed
|
||||
Integer MaxInnerIterations;
|
||||
Integer MaxOuterIterations;
|
||||
GridBase* SinglePrecGrid; //Grid for single-precision fields
|
||||
@ -42,12 +43,16 @@ namespace Grid {
|
||||
LinearOperatorBase<FieldF> &Linop_f;
|
||||
LinearOperatorBase<FieldD> &Linop_d;
|
||||
|
||||
Integer TotalInnerIterations; //Number of inner CG iterations
|
||||
Integer TotalOuterIterations; //Number of restarts
|
||||
Integer TotalFinalStepIterations; //Number of CG iterations in final patch-up step
|
||||
|
||||
//Option to speed up *inner single precision* solves using a LinearFunction that produces a guess
|
||||
LinearFunction<FieldF> *guesser;
|
||||
|
||||
MixedPrecisionConjugateGradient(RealD tol, Integer maxinnerit, Integer maxouterit, GridBase* _sp_grid, LinearOperatorBase<FieldF> &_Linop_f, LinearOperatorBase<FieldD> &_Linop_d) :
|
||||
Linop_f(_Linop_f), Linop_d(_Linop_d),
|
||||
Tolerance(tol), MaxInnerIterations(maxinnerit), MaxOuterIterations(maxouterit), SinglePrecGrid(_sp_grid),
|
||||
Tolerance(tol), InnerTolerance(tol), MaxInnerIterations(maxinnerit), MaxOuterIterations(maxouterit), SinglePrecGrid(_sp_grid),
|
||||
OuterLoopNormMult(100.), guesser(NULL){ };
|
||||
|
||||
void useGuesser(LinearFunction<FieldF> &g){
|
||||
@ -55,6 +60,8 @@ namespace Grid {
|
||||
}
|
||||
|
||||
void operator() (const FieldD &src_d_in, FieldD &sol_d){
|
||||
TotalInnerIterations = 0;
|
||||
|
||||
GridStopWatch TotalTimer;
|
||||
TotalTimer.Start();
|
||||
|
||||
@ -74,7 +81,7 @@ namespace Grid {
|
||||
FieldD src_d(DoublePrecGrid);
|
||||
src_d = src_d_in; //source for next inner iteration, computed from residual during operation
|
||||
|
||||
RealD inner_tol = Tolerance;
|
||||
RealD inner_tol = InnerTolerance;
|
||||
|
||||
FieldF src_f(SinglePrecGrid);
|
||||
src_f.checkerboard = cb;
|
||||
@ -89,7 +96,9 @@ namespace Grid {
|
||||
|
||||
GridStopWatch PrecChangeTimer;
|
||||
|
||||
for(Integer outer_iter = 0; outer_iter < MaxOuterIterations; outer_iter++){
|
||||
Integer &outer_iter = TotalOuterIterations; //so it will be equal to the final iteration count
|
||||
|
||||
for(outer_iter = 0; outer_iter < MaxOuterIterations; outer_iter++){
|
||||
//Compute double precision rsd and also new RHS vector.
|
||||
Linop_d.HermOp(sol_d, tmp_d);
|
||||
RealD norm = axpy_norm(src_d, -1., tmp_d, src_d_in); //src_d is residual vector
|
||||
@ -117,6 +126,7 @@ namespace Grid {
|
||||
InnerCGtimer.Start();
|
||||
CG_f(Linop_f, src_f, sol_f);
|
||||
InnerCGtimer.Stop();
|
||||
TotalInnerIterations += CG_f.IterationsToComplete;
|
||||
|
||||
//Convert sol back to double and add to double prec solution
|
||||
PrecChangeTimer.Start();
|
||||
@ -131,9 +141,11 @@ namespace Grid {
|
||||
|
||||
ConjugateGradient<FieldD> CG_d(Tolerance, MaxInnerIterations);
|
||||
CG_d(Linop_d, src_d_in, sol_d);
|
||||
TotalFinalStepIterations = CG_d.IterationsToComplete;
|
||||
|
||||
TotalTimer.Stop();
|
||||
std::cout<<GridLogMessage<<"MixedPrecisionConjugateGradient: Total " << TotalTimer.Elapsed() << " Precision change " << PrecChangeTimer.Elapsed() << " Inner CG total " << InnerCGtimer.Elapsed() << std::endl;
|
||||
std::cout<<GridLogMessage<<"MixedPrecisionConjugateGradient: Inner CG iterations " << TotalInnerIterations << " Restarts " << TotalOuterIterations << " Final CG iterations " << TotalFinalStepIterations << std::endl;
|
||||
std::cout<<GridLogMessage<<"MixedPrecisionConjugateGradient: Total time " << TotalTimer.Elapsed() << " Precision change " << PrecChangeTimer.Elapsed() << " Inner CG total " << InnerCGtimer.Elapsed() << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -36,7 +36,7 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
#include <iomanip>
|
||||
#include <complex>
|
||||
#include <typeinfo>
|
||||
#include <Grid.h>
|
||||
#include <Grid/Grid.h>
|
||||
|
||||
|
||||
/** Sign function **/
|
||||
|
@ -30,6 +30,7 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
#define GRID_LATTICE_RNG_H
|
||||
|
||||
#include <random>
|
||||
#include <Grid/sitmo_rng/sitmo_prng_engine.hpp>
|
||||
|
||||
namespace Grid {
|
||||
|
||||
@ -127,10 +128,14 @@ namespace Grid {
|
||||
typedef uint64_t RngStateType;
|
||||
typedef std::ranlux48 RngEngine;
|
||||
static const int RngStateCount = 15;
|
||||
#else
|
||||
#elif RNG_MT19937
|
||||
typedef std::mt19937 RngEngine;
|
||||
typedef uint32_t RngStateType;
|
||||
static const int RngStateCount = std::mt19937::state_size;
|
||||
#elif RNG_SITMO
|
||||
typedef sitmo::prng_engine RngEngine;
|
||||
typedef uint64_t RngStateType;
|
||||
static const int RngStateCount = 4;
|
||||
#endif
|
||||
std::vector<RngEngine> _generators;
|
||||
std::vector<std::uniform_real_distribution<RealD>> _uniform;
|
||||
|
@ -429,7 +429,7 @@ void ExtractSlice(Lattice<vobj> &lowDim, Lattice<vobj> & higherDim,int slice, in
|
||||
std::vector<int> lcoor(nl);
|
||||
std::vector<int> hcoor(nh);
|
||||
lg->LocalIndexToLocalCoor(idx,lcoor);
|
||||
ddl=0;
|
||||
int ddl=0;
|
||||
hcoor[orthog] = slice;
|
||||
for(int d=0;d<nh;d++){
|
||||
if ( d!=orthog ) {
|
||||
|
@ -2,10 +2,8 @@
|
||||
#include <Grid/perfmon/PerfCount.h>
|
||||
#include <Grid/perfmon/Stat.h>
|
||||
|
||||
|
||||
namespace Grid {
|
||||
|
||||
|
||||
bool PmuStat::pmu_initialized=false;
|
||||
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
#ifndef SOURCE_PUGIXML_CPP
|
||||
#define SOURCE_PUGIXML_CPP
|
||||
|
||||
#include <pugixml/pugixml.h>
|
||||
#include <Grid/pugixml/pugixml.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@ -30,23 +30,18 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#ifndef GRID_QCD_ACTIONS_H
|
||||
#define GRID_QCD_ACTIONS_H
|
||||
|
||||
// * Linear operators (Hermitian and non-hermitian) .. my LinearOperator
|
||||
// * System solvers (Hermitian and non-hermitian) .. my OperatorFunction
|
||||
// * MultiShift System solvers (Hermitian and non-hermitian) .. my OperatorFunction
|
||||
#ifndef GRID_QCD_ACTION_H
|
||||
#define GRID_QCD_ACTION_H
|
||||
|
||||
////////////////////////////////////////////
|
||||
// Abstract base interface
|
||||
////////////////////////////////////////////
|
||||
#include <Grid/qcd/action/ActionCore.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Fermion actions; prevent coupling fermion.cc files to other headers
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
#include <Grid/qcd/action/fermion/FermionCore.h>
|
||||
#include <Grid/qcd/action/fermion/Fermion.h>
|
||||
|
||||
////////////////////////////////////////
|
||||
// Pseudo fermion combinations for HMC
|
||||
////////////////////////////////////////
|
||||
|
@ -25,8 +25,8 @@ Author: Peter Boyle <pabobyle@ph.ed.ac.uk>
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#ifndef GRID_QCD_FERMION_ACTIONS_H
|
||||
#define GRID_QCD_FERMION_ACTIONS_H
|
||||
#ifndef GRID_QCD_FERMION_H
|
||||
#define GRID_QCD_FERMION_H
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Explicit explicit template instantiation is still required in the .cc files
|
||||
|
@ -28,6 +28,7 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
/* END LEGAL */
|
||||
#include <Grid/qcd/action/fermion/FermionCore.h>
|
||||
#include <Grid/qcd/action/fermion/PartialFractionFermion5D.h>
|
||||
|
||||
namespace Grid {
|
||||
namespace QCD {
|
||||
|
||||
|
@ -134,7 +134,6 @@ void WilsonFermion<Impl>::MooeeInvDag(const FermionField &in, FermionField &out)
|
||||
out.checkerboard = in.checkerboard;
|
||||
MooeeInv(in,out);
|
||||
}
|
||||
|
||||
template<class Impl>
|
||||
void WilsonFermion<Impl>::MomentumSpacePropagator(FermionField &out, const FermionField &in,RealD _m)
|
||||
{
|
||||
@ -145,11 +144,11 @@ void WilsonFermion<Impl>::MomentumSpacePropagator(FermionField &out, const Fermi
|
||||
// what type LatticeComplex
|
||||
conformable(_grid,out._grid);
|
||||
|
||||
Gamma::GammaMatrix Gmu [] = {
|
||||
Gamma::GammaX,
|
||||
Gamma::GammaY,
|
||||
Gamma::GammaZ,
|
||||
Gamma::GammaT
|
||||
Gamma::Algebra Gmu [] = {
|
||||
Gamma::Algebra::GammaX,
|
||||
Gamma::Algebra::GammaY,
|
||||
Gamma::Algebra::GammaZ,
|
||||
Gamma::Algebra::GammaT
|
||||
};
|
||||
|
||||
std::vector<int> latt_size = _grid->_fdimensions;
|
||||
|
@ -563,11 +563,11 @@ void WilsonFermion5D<Impl>::MomentumSpacePropagatorHt(FermionField &out,const Fe
|
||||
typedef iSinglet<ScalComplex> Tcomplex;
|
||||
typedef Lattice<iSinglet<vector_type> > LatComplex;
|
||||
|
||||
Gamma::GammaMatrix Gmu [] = {
|
||||
Gamma::GammaX,
|
||||
Gamma::GammaY,
|
||||
Gamma::GammaZ,
|
||||
Gamma::GammaT
|
||||
Gamma::Algebra Gmu [] = {
|
||||
Gamma::Algebra::GammaX,
|
||||
Gamma::Algebra::GammaY,
|
||||
Gamma::Algebra::GammaZ,
|
||||
Gamma::Algebra::GammaT
|
||||
};
|
||||
|
||||
std::vector<int> latt_size = _grid->_fdimensions;
|
||||
@ -634,11 +634,11 @@ void WilsonFermion5D<Impl>::MomentumSpacePropagatorHt(FermionField &out,const Fe
|
||||
template<class Impl>
|
||||
void WilsonFermion5D<Impl>::MomentumSpacePropagatorHw(FermionField &out,const FermionField &in,RealD mass)
|
||||
{
|
||||
Gamma::GammaMatrix Gmu [] = {
|
||||
Gamma::GammaX,
|
||||
Gamma::GammaY,
|
||||
Gamma::GammaZ,
|
||||
Gamma::GammaT
|
||||
Gamma::Algebra Gmu [] = {
|
||||
Gamma::Algebra::GammaX,
|
||||
Gamma::Algebra::GammaY,
|
||||
Gamma::Algebra::GammaZ,
|
||||
Gamma::Algebra::GammaT
|
||||
};
|
||||
|
||||
GridBase *_grid = _FourDimGrid;
|
||||
|
@ -29,6 +29,7 @@ directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#include <Grid/qcd/action/fermion/FermionCore.h>
|
||||
|
||||
namespace Grid {
|
||||
namespace QCD {
|
||||
|
||||
|
@ -32,7 +32,6 @@ Author: Guido Cossu <guido.cossu@ed.ac.uk>
|
||||
|
||||
#include <Grid/qcd/action/fermion/FermionCore.h>
|
||||
|
||||
|
||||
namespace Grid {
|
||||
namespace QCD {
|
||||
|
||||
|
@ -80,7 +80,7 @@ class Gamma5HermitianLinearOperator : public LinearOperatorBase<Field> {
|
||||
Matrix &_Mat;
|
||||
Gamma g5;
|
||||
public:
|
||||
Gamma5HermitianLinearOperator(Matrix &Mat): _Mat(Mat), g5(Gamma::Gamma5) {};
|
||||
Gamma5HermitianLinearOperator(Matrix &Mat): _Mat(Mat), g5(Gamma::Algebra::Gamma5) {};
|
||||
void Op (const Field &in, Field &out){
|
||||
HermOp(in,out);
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ See the full license in the file "LICENSE" in the top level distribution
|
||||
directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#ifndef GRID_QCD_GAUGE_AGGREGATE_H
|
||||
#define GRID_QCD_GAUGE_AGGREGATE_H
|
||||
#ifndef GRID_QCD_GAUGE_H
|
||||
#define GRID_QCD_GAUGE_H
|
||||
|
||||
#include <Grid/qcd/action/gauge/GaugeImpl.h>
|
||||
#include <Grid/qcd/utils/WilsonLoops.h>
|
||||
|
@ -1,96 +0,0 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: ./lib/qcd/spin/Dirac.cc
|
||||
|
||||
Copyright (C) 2015
|
||||
|
||||
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 <Grid/GridCore.h>
|
||||
#include <Grid/GridQCDcore.h>
|
||||
|
||||
namespace Grid {
|
||||
|
||||
namespace QCD {
|
||||
|
||||
Gamma::GammaMatrix Gamma::GammaMatrices [] = {
|
||||
Gamma::Identity,
|
||||
Gamma::GammaX,
|
||||
Gamma::GammaY,
|
||||
Gamma::GammaZ,
|
||||
Gamma::GammaT,
|
||||
Gamma::Gamma5,
|
||||
Gamma::MinusIdentity,
|
||||
Gamma::MinusGammaX,
|
||||
Gamma::MinusGammaY,
|
||||
Gamma::MinusGammaZ,
|
||||
Gamma::MinusGammaT,
|
||||
Gamma::MinusGamma5
|
||||
};
|
||||
const char *Gamma::GammaMatrixNames[] = {
|
||||
"Identity ",
|
||||
"GammaX ",
|
||||
"GammaY ",
|
||||
"GammaZ ",
|
||||
"GammaT ",
|
||||
"Gamma5 ",
|
||||
"-Identity",
|
||||
"-GammaX ",
|
||||
"-GammaY ",
|
||||
"-GammaZ ",
|
||||
"-GammaT ",
|
||||
"-Gamma5 ",
|
||||
" "
|
||||
};
|
||||
|
||||
SpinMatrix makeGammaProd(const unsigned int i)
|
||||
{
|
||||
SpinMatrix g;
|
||||
|
||||
g = 1.;
|
||||
if (i & 0x1)
|
||||
{
|
||||
g = g*Gamma(Gamma::GammaMatrix::GammaX);
|
||||
}
|
||||
if (i & 0x2)
|
||||
{
|
||||
g = g*Gamma(Gamma::GammaMatrix::GammaY);
|
||||
}
|
||||
if (i & 0x4)
|
||||
{
|
||||
g = g*Gamma(Gamma::GammaMatrix::GammaZ);
|
||||
}
|
||||
if (i & 0x8)
|
||||
{
|
||||
g = g*Gamma(Gamma::GammaMatrix::GammaT);
|
||||
}
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
// void sprojMul( vHalfSpinColourVector &out,vColourMatrix &u, vSpinColourVector &in){
|
||||
// vHalfSpinColourVector hspin;
|
||||
// spProjXp(hspin,in);
|
||||
// mult(&out,&u,&hspin);
|
||||
// }
|
||||
}
|
||||
}
|
@ -1,628 +1,232 @@
|
||||
/*************************************************************************************
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: ./lib/qcd/spin/Dirac.h
|
||||
Source file: lib/qcd/spin/Dirac.h
|
||||
|
||||
Copyright (C) 2015
|
||||
Copyright (C) 2015
|
||||
Copyright (C) 2016
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
Author: Peter Boyle <peterboyle@Peters-MacBook-Pro-2.local>
|
||||
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 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.
|
||||
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.
|
||||
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 */
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#ifndef GRID_QCD_DIRAC_H
|
||||
#define GRID_QCD_DIRAC_H
|
||||
namespace Grid{
|
||||
|
||||
// Gamma matrices using the code generated by the Mathematica notebook
|
||||
// gamma-gen/gamma-gen.nb in Gamma.cc & Gamma.h
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <Grid/qcd/spin/Gamma.h>
|
||||
|
||||
namespace Grid {
|
||||
|
||||
// Dirac algebra adjoint operator (not in QCD:: to overload other adj)
|
||||
inline QCD::Gamma adj(const QCD::Gamma &g)
|
||||
{
|
||||
return QCD::Gamma (QCD::Gamma::adj[g.g]);
|
||||
}
|
||||
|
||||
namespace QCD {
|
||||
|
||||
// Dirac algebra mutliplication operator
|
||||
inline Gamma operator*(const Gamma &g1, const Gamma &g2)
|
||||
{
|
||||
return Gamma (Gamma::mul[g1.g][g2.g]);
|
||||
}
|
||||
|
||||
class Gamma {
|
||||
// general left multiply
|
||||
template<class vtype>
|
||||
inline auto operator*(const Gamma &G, const iScalar<vtype> &arg)
|
||||
->typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,SpinorIndex>::notvalue,iScalar<vtype>>::type
|
||||
{
|
||||
iScalar<vtype> ret;
|
||||
ret._internal=G*arg._internal;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public:
|
||||
template<class vtype,int N>
|
||||
inline auto operator*(const Gamma &G, const iVector<vtype, N> &arg)
|
||||
->typename std::enable_if<matchGridTensorIndex<iVector<vtype,N>,SpinorIndex>::notvalue,iVector<vtype,N>>::type
|
||||
{
|
||||
iVector<vtype,N> ret;
|
||||
for(int i=0;i<N;i++){
|
||||
ret._internal[i]=G*arg._internal[i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
const int Ns=4;
|
||||
|
||||
enum GammaMatrix {
|
||||
Identity,
|
||||
GammaX,
|
||||
GammaY,
|
||||
GammaZ,
|
||||
GammaT,
|
||||
Gamma5,
|
||||
MinusIdentity,
|
||||
MinusGammaX,
|
||||
MinusGammaY,
|
||||
MinusGammaZ,
|
||||
MinusGammaT,
|
||||
MinusGamma5
|
||||
// GammaXGamma5, // Rest are composite (willing to take hit for two calls sequentially)
|
||||
// GammaYGamma5, // as they are less commonly used.
|
||||
// GammaZGamma5,
|
||||
// GammaTGamma5,
|
||||
// SigmaXY,
|
||||
// SigmaXZ,
|
||||
// SigmaYZ,
|
||||
// SigmaXT,
|
||||
// SigmaYT,
|
||||
// SigmaZT,
|
||||
// MinusGammaXGamma5, easiest to form by composition
|
||||
// MinusGammaYGamma5, as performance is not critical for these
|
||||
// MinusGammaZGamma5,
|
||||
// MinusGammaTGamma5,
|
||||
// MinusSigmaXY,
|
||||
// MinusSigmaXZ,
|
||||
// MinusSigmaYZ,
|
||||
// MinusSigmaXT,
|
||||
// MinusSigmaYT,
|
||||
// MinusSigmaZT
|
||||
};
|
||||
|
||||
static GammaMatrix GammaMatrices[];
|
||||
static const char *GammaMatrixNames[];
|
||||
template<class vtype, int N>
|
||||
inline auto operator*(const Gamma &G, const iMatrix<vtype, N> &arg)
|
||||
->typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,SpinorIndex>::notvalue,iMatrix<vtype,N>>::type
|
||||
{
|
||||
iMatrix<vtype,N> ret;
|
||||
for(int i=0;i<N;i++){
|
||||
for(int j=0;j<N;j++){
|
||||
ret._internal[i][j]=G*arg._internal[i][j];
|
||||
}}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Gamma (GammaMatrix g) { _g=g; }
|
||||
// general right multiply
|
||||
template<class vtype>
|
||||
inline auto operator*(const iScalar<vtype> &arg, const Gamma &G)
|
||||
->typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,SpinorIndex>::notvalue,iScalar<vtype>>::type
|
||||
{
|
||||
iScalar<vtype> ret;
|
||||
ret._internal=arg._internal*G;
|
||||
return ret;
|
||||
}
|
||||
|
||||
GammaMatrix _g;
|
||||
template<class vtype, int N>
|
||||
inline auto operator * (const iMatrix<vtype, N> &arg, const Gamma &G)
|
||||
->typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,SpinorIndex>::notvalue,iMatrix<vtype,N>>::type
|
||||
{
|
||||
iMatrix<vtype,N> ret;
|
||||
for(int i=0;i<N;i++){
|
||||
for(int j=0;j<N;j++){
|
||||
ret._internal[i][j]=arg._internal[i][j]*G;
|
||||
}}
|
||||
return ret;
|
||||
}
|
||||
|
||||
};
|
||||
// Gamma-left matrices gL_mu = g_mu*(1 - g5)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class GammaL
|
||||
{
|
||||
public:
|
||||
typedef Gamma::Algebra Algebra;
|
||||
Gamma gamma;
|
||||
public:
|
||||
GammaL(const Algebra initg): gamma(initg) {}
|
||||
GammaL(const Gamma initg): gamma(initg) {}
|
||||
};
|
||||
|
||||
// vector multiply
|
||||
template<class vtype>
|
||||
inline auto operator*(const GammaL &gl, const iVector<vtype, Ns> &arg)
|
||||
->typename std::enable_if<matchGridTensorIndex<iVector<vtype, Ns>, SpinorIndex>::value, iVector<vtype, Ns>>::type
|
||||
{
|
||||
iVector<vtype, Ns> buf;
|
||||
|
||||
// Make gamma products (Chroma convention)
|
||||
SpinMatrix makeGammaProd(const unsigned int i);
|
||||
|
||||
/* Gx
|
||||
* 0 0 0 i
|
||||
* 0 0 i 0
|
||||
* 0 -i 0 0
|
||||
* -i 0 0 0
|
||||
*/
|
||||
// right multiplication makes sense for matrix args, not for vector since there is
|
||||
// no concept of row versus columnar indices
|
||||
template<class vtype> inline void rmultMinusGammaX(iMatrix<vtype,Ns> &ret,const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(i,0) = timesI(rhs(i,3));
|
||||
ret(i,1) = timesI(rhs(i,2));
|
||||
ret(i,2) = timesMinusI(rhs(i,1));
|
||||
ret(i,3) = timesMinusI(rhs(i,0));
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void rmultGammaX(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(i,0) = timesMinusI(rhs(i,3));
|
||||
ret(i,1) = timesMinusI(rhs(i,2));
|
||||
ret(i,2) = timesI(rhs(i,1));
|
||||
ret(i,3) = timesI(rhs(i,0));
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void multGammaX(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(0,i) = timesI(rhs(3,i));
|
||||
ret(1,i) = timesI(rhs(2,i));
|
||||
ret(2,i) = timesMinusI(rhs(1,i));
|
||||
ret(3,i) = timesMinusI(rhs(0,i));
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void multMinusGammaX(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(0,i) = timesMinusI(rhs(3,i));
|
||||
ret(1,i) = timesMinusI(rhs(2,i));
|
||||
ret(2,i) = timesI(rhs(1,i));
|
||||
ret(3,i) = timesI(rhs(0,i));
|
||||
}
|
||||
};
|
||||
buf(0) = 0.;
|
||||
buf(1) = 0.;
|
||||
buf(2) = 2.*arg(2);
|
||||
buf(3) = 2.*arg(3);
|
||||
|
||||
return gl.gamma*buf;
|
||||
};
|
||||
|
||||
template<class vtype> inline void multGammaX(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
|
||||
ret._internal[0] = timesI(rhs._internal[3]);
|
||||
ret._internal[1] = timesI(rhs._internal[2]);
|
||||
ret._internal[2] = timesMinusI(rhs._internal[1]);
|
||||
ret._internal[3] = timesMinusI(rhs._internal[0]);
|
||||
};
|
||||
template<class vtype> inline void multMinusGammaX(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
|
||||
ret(0) = timesMinusI(rhs(3));
|
||||
ret(1) = timesMinusI(rhs(2));
|
||||
ret(2) = timesI(rhs(1));
|
||||
ret(3) = timesI(rhs(0));
|
||||
};
|
||||
// matrix left multiply
|
||||
template<class vtype>
|
||||
inline auto operator*(const GammaL &gl, const iMatrix<vtype, Ns> &arg)
|
||||
->typename std::enable_if<matchGridTensorIndex<iMatrix<vtype, Ns>, SpinorIndex>::value, iMatrix<vtype, Ns>>::type
|
||||
{
|
||||
iMatrix<vtype, Ns> buf;
|
||||
|
||||
for(unsigned int i = 0; i < Ns; ++i)
|
||||
{
|
||||
buf(0, i) = 0.;
|
||||
buf(1, i) = 0.;
|
||||
buf(2, i) = 2.*arg(2, i);
|
||||
buf(3, i) = 2.*arg(3, i);
|
||||
}
|
||||
|
||||
return gl.gamma*buf;
|
||||
};
|
||||
|
||||
// matrix right multiply
|
||||
template<class vtype>
|
||||
inline auto operator*(const iMatrix<vtype, Ns> &arg, const GammaL &gl)
|
||||
->typename std::enable_if<matchGridTensorIndex<iMatrix<vtype, Ns>, SpinorIndex>::value, iMatrix<vtype, Ns>>::type
|
||||
{
|
||||
iMatrix<vtype, Ns> buf;
|
||||
|
||||
buf = arg*gl.gamma;
|
||||
for(unsigned int i = 0; i < Ns; ++i)
|
||||
{
|
||||
buf(i, 0) = 0.;
|
||||
buf(i, 1) = 0.;
|
||||
buf(i, 2) = 2.*buf(i, 2);
|
||||
buf(i, 3) = 2.*buf(i, 3);
|
||||
}
|
||||
|
||||
return buf;
|
||||
};
|
||||
|
||||
/*Gy
|
||||
* 0 0 0 -1 [0] -+ [3]
|
||||
* 0 0 1 0 [1] +- [2]
|
||||
* 0 1 0 0
|
||||
* -1 0 0 0
|
||||
*/
|
||||
template<class vtype> inline void rmultGammaY(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(i,0) = -rhs(i,3);
|
||||
ret(i,1) = rhs(i,2);
|
||||
ret(i,2) = rhs(i,1);
|
||||
ret(i,3) = -rhs(i,0);
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void rmultMinusGammaY(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(i,0) = rhs(i,3);
|
||||
ret(i,1) = -rhs(i,2);
|
||||
ret(i,2) = -rhs(i,1);
|
||||
ret(i,3) = rhs(i,0);
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void multGammaY(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(0,i) = -rhs(3,i);
|
||||
ret(1,i) = rhs(2,i);
|
||||
ret(2,i) = rhs(1,i);
|
||||
ret(3,i) = -rhs(0,i);
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void multMinusGammaY(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(0,i) = rhs(3,i);
|
||||
ret(1,i) = -rhs(2,i);
|
||||
ret(2,i) = -rhs(1,i);
|
||||
ret(3,i) = rhs(0,i);
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void multGammaY(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
|
||||
ret(0) = -rhs(3);
|
||||
ret(1) = rhs(2);
|
||||
ret(2) = rhs(1);
|
||||
ret(3) = -rhs(0);
|
||||
};
|
||||
template<class vtype> inline void multMinusGammaY(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
|
||||
ret(0) = rhs(3);
|
||||
ret(1) = -rhs(2);
|
||||
ret(2) = -rhs(1);
|
||||
ret(3) = rhs(0);
|
||||
};
|
||||
/*Gz
|
||||
* 0 0 i 0 [0]+-i[2]
|
||||
* 0 0 0 -i [1]-+i[3]
|
||||
* -i 0 0 0
|
||||
* 0 i 0 0
|
||||
*/
|
||||
template<class vtype> inline void rmultGammaZ(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(i,0) = timesMinusI(rhs(i,2));
|
||||
ret(i,1) = timesI(rhs(i,3));
|
||||
ret(i,2) = timesI(rhs(i,0));
|
||||
ret(i,3) = timesMinusI(rhs(i,1));
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void rmultMinusGammaZ(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(i,0) = timesI(rhs(i,2));
|
||||
ret(i,1) = timesMinusI(rhs(i,3));
|
||||
ret(i,2) = timesMinusI(rhs(i,0));
|
||||
ret(i,3) = timesI(rhs(i,1));
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void multGammaZ(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(0,i) = timesI(rhs(2,i));
|
||||
ret(1,i) =timesMinusI(rhs(3,i));
|
||||
ret(2,i) =timesMinusI(rhs(0,i));
|
||||
ret(3,i) = timesI(rhs(1,i));
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void multMinusGammaZ(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(0,i) = timesMinusI(rhs(2,i));
|
||||
ret(1,i) = timesI(rhs(3,i));
|
||||
ret(2,i) = timesI(rhs(0,i));
|
||||
ret(3,i) = timesMinusI(rhs(1,i));
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void multGammaZ(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
|
||||
ret(0) = timesI(rhs(2));
|
||||
ret(1) =timesMinusI(rhs(3));
|
||||
ret(2) =timesMinusI(rhs(0));
|
||||
ret(3) = timesI(rhs(1));
|
||||
};
|
||||
template<class vtype> inline void multMinusGammaZ(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
|
||||
ret(0) = timesMinusI(rhs(2));
|
||||
ret(1) = timesI(rhs(3));
|
||||
ret(2) = timesI(rhs(0));
|
||||
ret(3) = timesMinusI(rhs(1));
|
||||
};
|
||||
/*Gt
|
||||
* 0 0 1 0 [0]+-[2]
|
||||
* 0 0 0 1 [1]+-[3]
|
||||
* 1 0 0 0
|
||||
* 0 1 0 0
|
||||
*/
|
||||
template<class vtype> inline void rmultGammaT(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(i,0) = rhs(i,2);
|
||||
ret(i,1) = rhs(i,3);
|
||||
ret(i,2) = rhs(i,0);
|
||||
ret(i,3) = rhs(i,1);
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void rmultMinusGammaT(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(i,0) =- rhs(i,2);
|
||||
ret(i,1) =- rhs(i,3);
|
||||
ret(i,2) =- rhs(i,0);
|
||||
ret(i,3) =- rhs(i,1);
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void multGammaT(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(0,i) = rhs(2,i);
|
||||
ret(1,i) = rhs(3,i);
|
||||
ret(2,i) = rhs(0,i);
|
||||
ret(3,i) = rhs(1,i);
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void multMinusGammaT(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(0,i) =-rhs(2,i);
|
||||
ret(1,i) =-rhs(3,i);
|
||||
ret(2,i) =-rhs(0,i);
|
||||
ret(3,i) =-rhs(1,i);
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void multGammaT(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
|
||||
ret(0) = rhs(2);
|
||||
ret(1) = rhs(3);
|
||||
ret(2) = rhs(0);
|
||||
ret(3) = rhs(1);
|
||||
};
|
||||
template<class vtype> inline void multMinusGammaT(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
|
||||
ret(0) =-rhs(2);
|
||||
ret(1) =-rhs(3);
|
||||
ret(2) =-rhs(0);
|
||||
ret(3) =-rhs(1);
|
||||
};
|
||||
/*G5
|
||||
* 1 0 0 0 [0]+-[2]
|
||||
* 0 1 0 0 [1]+-[3]
|
||||
* 0 0 -1 0
|
||||
* 0 0 0 -1
|
||||
*/
|
||||
template<class vtype> inline void rmultGamma5(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(i,0) = rhs(i,0);
|
||||
ret(i,1) = rhs(i,1);
|
||||
ret(i,2) =-rhs(i,2);
|
||||
ret(i,3) =-rhs(i,3);
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void rmultMinusGamma5(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(i,0) =-rhs(i,0);
|
||||
ret(i,1) =-rhs(i,1);
|
||||
ret(i,2) = rhs(i,2);
|
||||
ret(i,3) = rhs(i,3);
|
||||
}
|
||||
};
|
||||
//general left multiply
|
||||
template<class vtype>
|
||||
inline auto operator*(const GammaL &gl, const iScalar<vtype> &arg)
|
||||
->typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,SpinorIndex>::notvalue,iScalar<vtype>>::type
|
||||
{
|
||||
iScalar<vtype> ret;
|
||||
ret._internal=gl*arg._internal;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class vtype> inline void multGamma5(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(0,i) = rhs(0,i);
|
||||
ret(1,i) = rhs(1,i);
|
||||
ret(2,i) =-rhs(2,i);
|
||||
ret(3,i) =-rhs(3,i);
|
||||
}
|
||||
};
|
||||
template<class vtype> inline void multMinusGamma5(iMatrix<vtype,Ns> &ret, const iMatrix<vtype,Ns> &rhs){
|
||||
for(int i=0;i<Ns;i++){
|
||||
ret(0,i) =-rhs(0,i);
|
||||
ret(1,i) =-rhs(1,i);
|
||||
ret(2,i) = rhs(2,i);
|
||||
ret(3,i) = rhs(3,i);
|
||||
}
|
||||
};
|
||||
template<class vtype,int N>
|
||||
inline auto operator*(const GammaL &gl, const iVector<vtype, N> &arg)
|
||||
->typename std::enable_if<matchGridTensorIndex<iVector<vtype,N>,SpinorIndex>::notvalue,iVector<vtype,N>>::type
|
||||
{
|
||||
iVector<vtype,N> ret;
|
||||
for(int i=0;i<N;i++){
|
||||
ret._internal[i]=gl*arg._internal[i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class vtype> inline void multGamma5(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
|
||||
ret(0) = rhs(0);
|
||||
ret(1) = rhs(1);
|
||||
ret(2) =-rhs(2);
|
||||
ret(3) =-rhs(3);
|
||||
};
|
||||
template<class vtype> inline void multMinusGamma5(iVector<vtype,Ns> &ret, const iVector<vtype,Ns> &rhs){
|
||||
ret(0) =-rhs(0);
|
||||
ret(1) =-rhs(1);
|
||||
ret(2) = rhs(2);
|
||||
ret(3) = rhs(3);
|
||||
};
|
||||
template<class vtype, int N>
|
||||
inline auto operator*(const GammaL &gl, const iMatrix<vtype, N> &arg)
|
||||
->typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,SpinorIndex>::notvalue,iMatrix<vtype,N>>::type
|
||||
{
|
||||
iMatrix<vtype,N> ret;
|
||||
for(int i=0;i<N;i++){
|
||||
for(int j=0;j<N;j++){
|
||||
ret._internal[i][j]=gl*arg._internal[i][j];
|
||||
}}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//general right multiply
|
||||
template<class vtype>
|
||||
inline auto operator*(const iScalar<vtype> &arg, const GammaL &gl)
|
||||
->typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,SpinorIndex>::notvalue,iScalar<vtype>>::type
|
||||
{
|
||||
iScalar<vtype> ret;
|
||||
ret._internal=arg._internal*gl;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class vtype, int N>
|
||||
inline auto operator * (const iMatrix<vtype, N> &arg, const GammaL &gl)
|
||||
->typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,SpinorIndex>::notvalue,iMatrix<vtype,N>>::type
|
||||
{
|
||||
iMatrix<vtype,N> ret;
|
||||
for(int i=0;i<N;i++){
|
||||
for(int j=0;j<N;j++){
|
||||
ret._internal[i][j]=arg._internal[i][j]*gl;
|
||||
}}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef GRID_WARN_SUBOPTIMAL
|
||||
#warning "Optimisation alert switch over to multGammaX early "
|
||||
#endif
|
||||
}}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Operator * : first case this is not a spin index, so recurse
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// FIXME
|
||||
//
|
||||
// Optimisation; switch over to a "multGammaX(ret._internal,arg._internal)" style early and
|
||||
// note that doing so from the lattice operator will avoid copy back and case switch overhead, as
|
||||
// was done for the tensor math operator to remove operator * notation early
|
||||
//
|
||||
|
||||
//left multiply
|
||||
template<class vtype> inline auto operator * ( const Gamma &G,const iScalar<vtype> &arg) ->
|
||||
typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,SpinorIndex>::notvalue,iScalar<vtype> >::type
|
||||
|
||||
{
|
||||
iScalar<vtype> ret;
|
||||
ret._internal=G*arg._internal;
|
||||
return ret;
|
||||
}
|
||||
template<class vtype,int N> inline auto operator * ( const Gamma &G,const iVector<vtype,N> &arg) ->
|
||||
typename std::enable_if<matchGridTensorIndex<iVector<vtype,N>,SpinorIndex>::notvalue,iVector<vtype,N> >::type
|
||||
{
|
||||
iVector<vtype,N> ret;
|
||||
for(int i=0;i<N;i++){
|
||||
ret._internal[i]=G*arg._internal[i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
template<class vtype,int N> inline auto operator * ( const Gamma &G,const iMatrix<vtype,N> &arg) ->
|
||||
typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,SpinorIndex>::notvalue,iMatrix<vtype,N> >::type
|
||||
{
|
||||
iMatrix<vtype,N> ret;
|
||||
for(int i=0;i<N;i++){
|
||||
for(int j=0;j<N;j++){
|
||||
ret._internal[i][j]=G*arg._internal[i][j];
|
||||
}}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//right multiply
|
||||
template<class vtype> inline auto operator * (const iScalar<vtype> &arg, const Gamma &G) ->
|
||||
typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,SpinorIndex>::notvalue,iScalar<vtype> >::type
|
||||
|
||||
{
|
||||
iScalar<vtype> ret;
|
||||
ret._internal=arg._internal*G;
|
||||
return ret;
|
||||
}
|
||||
template<class vtype,int N> inline auto operator * (const iVector<vtype,N> &arg, const Gamma &G) ->
|
||||
typename std::enable_if<matchGridTensorIndex<iVector<vtype,N>,SpinorIndex>::notvalue,iVector<vtype,N> >::type
|
||||
{
|
||||
iVector<vtype,N> ret;
|
||||
for(int i=0;i<N;i++){
|
||||
ret._internal=arg._internal[i]*G;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
template<class vtype,int N> inline auto operator * (const iMatrix<vtype,N> &arg, const Gamma &G) ->
|
||||
typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,SpinorIndex>::notvalue,iMatrix<vtype,N> >::type
|
||||
{
|
||||
iMatrix<vtype,N> ret;
|
||||
for(int i=0;i<N;i++){
|
||||
for(int j=0;j<N;j++){
|
||||
ret._internal[i][j]=arg._internal[i][j]*G;
|
||||
}}
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// When we hit the spin index this matches and we stop
|
||||
////////////////////////////////////////////////////////
|
||||
template<class vtype> inline auto operator * ( const Gamma &G,const iMatrix<vtype,Ns> &arg) ->
|
||||
typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,Ns>,SpinorIndex>::value,iMatrix<vtype,Ns> >::type
|
||||
{
|
||||
iMatrix<vtype,Ns> ret;
|
||||
switch (G._g) {
|
||||
case Gamma::Identity:
|
||||
ret = arg;
|
||||
break;
|
||||
case Gamma::MinusIdentity:
|
||||
ret = -arg;
|
||||
break;
|
||||
case Gamma::GammaX:
|
||||
multGammaX(ret,arg);
|
||||
break;
|
||||
case Gamma::MinusGammaX:
|
||||
multMinusGammaX(ret,arg);
|
||||
break;
|
||||
case Gamma::GammaY:
|
||||
multGammaY(ret,arg);
|
||||
break;
|
||||
case Gamma::MinusGammaY:
|
||||
multMinusGammaY(ret,arg);
|
||||
break;
|
||||
case Gamma::GammaZ:
|
||||
multGammaZ(ret,arg);
|
||||
break;
|
||||
case Gamma::MinusGammaZ:
|
||||
multMinusGammaZ(ret,arg);
|
||||
break;
|
||||
case Gamma::GammaT:
|
||||
multGammaT(ret,arg);
|
||||
break;
|
||||
case Gamma::MinusGammaT:
|
||||
multMinusGammaT(ret,arg);
|
||||
break;
|
||||
case Gamma::Gamma5:
|
||||
multGamma5(ret,arg);
|
||||
break;
|
||||
case Gamma::MinusGamma5:
|
||||
multMinusGamma5(ret,arg);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
// Could have used type trait for Matrix/vector and then an enable if to share code
|
||||
template<class vtype> inline auto operator * ( const Gamma &G,const iVector<vtype,Ns> &arg) ->
|
||||
typename std::enable_if<matchGridTensorIndex<iVector<vtype,Ns>,SpinorIndex>::value,iVector<vtype,Ns> >::type
|
||||
{
|
||||
iVector<vtype,Ns> ret;
|
||||
switch (G._g) {
|
||||
case Gamma::Identity:
|
||||
ret = arg;
|
||||
break;
|
||||
case Gamma::MinusIdentity:
|
||||
ret = -arg;
|
||||
break;
|
||||
case Gamma::GammaX:
|
||||
multGammaX(ret,arg);
|
||||
break;
|
||||
case Gamma::MinusGammaX:
|
||||
multMinusGammaX(ret,arg);
|
||||
break;
|
||||
case Gamma::GammaY:
|
||||
multGammaY(ret,arg);
|
||||
break;
|
||||
case Gamma::MinusGammaY:
|
||||
multMinusGammaY(ret,arg);
|
||||
break;
|
||||
case Gamma::GammaZ:
|
||||
multGammaZ(ret,arg);
|
||||
break;
|
||||
case Gamma::MinusGammaZ:
|
||||
multMinusGammaZ(ret,arg);
|
||||
break;
|
||||
case Gamma::GammaT:
|
||||
multGammaT(ret,arg);
|
||||
break;
|
||||
case Gamma::MinusGammaT:
|
||||
multMinusGammaT(ret,arg);
|
||||
break;
|
||||
case Gamma::Gamma5:
|
||||
multGamma5(ret,arg);
|
||||
break;
|
||||
case Gamma::MinusGamma5:
|
||||
multMinusGamma5(ret,arg);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class vtype> inline auto operator * (const iMatrix<vtype,Ns> &arg, const Gamma &G) ->
|
||||
typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,Ns>,SpinorIndex>::value,iMatrix<vtype,Ns> >::type
|
||||
{
|
||||
iMatrix<vtype,Ns> ret;
|
||||
switch (G._g) {
|
||||
case Gamma::Identity:
|
||||
ret = arg;
|
||||
break;
|
||||
case Gamma::MinusIdentity:
|
||||
ret = -arg;
|
||||
break;
|
||||
case Gamma::GammaX:
|
||||
rmultGammaX(ret,arg);
|
||||
break;
|
||||
case Gamma::MinusGammaX:
|
||||
rmultMinusGammaX(ret,arg);
|
||||
break;
|
||||
case Gamma::GammaY:
|
||||
rmultGammaY(ret,arg);
|
||||
break;
|
||||
case Gamma::MinusGammaY:
|
||||
rmultMinusGammaY(ret,arg);
|
||||
break;
|
||||
case Gamma::GammaZ:
|
||||
rmultGammaZ(ret,arg);
|
||||
break;
|
||||
case Gamma::MinusGammaZ:
|
||||
rmultMinusGammaZ(ret,arg);
|
||||
break;
|
||||
case Gamma::GammaT:
|
||||
rmultGammaT(ret,arg);
|
||||
break;
|
||||
case Gamma::MinusGammaT:
|
||||
rmultMinusGammaT(ret,arg);
|
||||
break;
|
||||
case Gamma::Gamma5:
|
||||
rmultGamma5(ret,arg);
|
||||
break;
|
||||
case Gamma::MinusGamma5:
|
||||
rmultMinusGamma5(ret,arg);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* Output from test
|
||||
./Grid_gamma
|
||||
Identity((1,0),(0,0),(0,0),(0,0))
|
||||
((0,0),(1,0),(0,0),(0,0))
|
||||
((0,0),(0,0),(1,0),(0,0))
|
||||
((0,0),(0,0),(0,0),(1,0)) OK
|
||||
|
||||
GammaX ((0,0),(0,0),(0,0),(0,1))
|
||||
((0,0),(0,0),(0,1),(0,0))
|
||||
((0,0),(0,-1),(0,0),(0,0))
|
||||
((0,-1),(0,0),(0,0),(0,0)) OK
|
||||
* Gx
|
||||
* 0 0 0 i
|
||||
* 0 0 i 0
|
||||
* 0 -i 0 0
|
||||
* -i 0 0 0
|
||||
|
||||
GammaY ((-0,-0),(-0,-0),(-0,-0),(-1,-0))
|
||||
((0,0),(0,0),(1,0),(0,0))
|
||||
((0,0),(1,0),(0,0),(0,0)) OK
|
||||
((-1,-0),(-0,-0),(-0,-0),(-0,-0))
|
||||
*Gy
|
||||
* 0 0 0 -1 [0] -+ [3]
|
||||
* 0 0 1 0 [1] +- [2]
|
||||
* 0 1 0 0
|
||||
* -1 0 0 0
|
||||
|
||||
GammaZ ((0,0),(0,0),(0,1),(0,0))
|
||||
((0,0),(0,0),(0,0),(0,-1))
|
||||
((0,-1),(0,0),(0,0),(0,0))
|
||||
((0,0),(0,1),(0,0),(0,0)) OK
|
||||
* 0 0 i 0 [0]+-i[2]
|
||||
* 0 0 0 -i [1]-+i[3]
|
||||
* -i 0 0 0
|
||||
* 0 i 0 0
|
||||
|
||||
GammaT ((0,0),(0,0),(1,0),(0,0))
|
||||
((0,0),(0,0),(0,0),(1,0)) OK
|
||||
((1,0),(0,0),(0,0),(0,0))
|
||||
((0,0),(1,0),(0,0),(0,0))
|
||||
* 0 0 1 0 [0]+-[2]
|
||||
* 0 0 0 1 [1]+-[3]
|
||||
* 1 0 0 0
|
||||
* 0 1 0 0
|
||||
|
||||
Gamma5 ((1,0),(0,0),(0,0),(0,0))
|
||||
((0,0),(1,0),(0,0),(0,0))
|
||||
((-0,-0),(-0,-0),(-1,-0),(-0,-0))
|
||||
((-0,-0),(-0,-0),(-0,-0),(-1,-0))
|
||||
* 1 0 0 0 [0]+-[2]
|
||||
* 0 1 0 0 [1]+-[3] OK
|
||||
* 0 0 -1 0
|
||||
* 0 0 0 -1
|
||||
*/
|
||||
|
||||
} //namespace QCD
|
||||
} // Grid
|
||||
#endif
|
||||
|
1140
lib/qcd/spin/Gamma.cc
Normal file
1140
lib/qcd/spin/Gamma.cc
Normal file
File diff suppressed because it is too large
Load Diff
1348
lib/qcd/spin/Gamma.h
Normal file
1348
lib/qcd/spin/Gamma.h
Normal file
File diff suppressed because it is too large
Load Diff
1488
lib/qcd/spin/gamma-gen/gamma-gen.nb
Normal file
1488
lib/qcd/spin/gamma-gen/gamma-gen.nb
Normal file
File diff suppressed because it is too large
Load Diff
@ -47,7 +47,7 @@ void axpibg5x(Lattice<vobj> &z,const Lattice<vobj> &x,Coeff a,Coeff b)
|
||||
|
||||
GridBase *grid=x._grid;
|
||||
|
||||
Gamma G5(Gamma::Gamma5);
|
||||
Gamma G5(Gamma::Algebra::Gamma5);
|
||||
parallel_for(int ss=0;ss<grid->oSites();ss++){
|
||||
vobj tmp;
|
||||
tmp = a*x._odata[ss];
|
||||
@ -78,7 +78,8 @@ void ag5xpby_ssp(Lattice<vobj> &z,Coeff a,const Lattice<vobj> &x,Coeff b,const L
|
||||
conformable(x,z);
|
||||
GridBase *grid=x._grid;
|
||||
int Ls = grid->_rdimensions[0];
|
||||
Gamma G5(Gamma::Gamma5);
|
||||
|
||||
Gamma G5(Gamma::Algebra::Gamma5);
|
||||
parallel_for(int ss=0;ss<grid->oSites();ss+=Ls){ // adds Ls
|
||||
vobj tmp;
|
||||
tmp = G5*x._odata[ss+s]*a;
|
||||
@ -95,7 +96,7 @@ void axpbg5y_ssp(Lattice<vobj> &z,Coeff a,const Lattice<vobj> &x,Coeff b,const L
|
||||
conformable(x,z);
|
||||
GridBase *grid=x._grid;
|
||||
int Ls = grid->_rdimensions[0];
|
||||
Gamma G5(Gamma::Gamma5);
|
||||
Gamma G5(Gamma::Algebra::Gamma5);
|
||||
parallel_for(int ss=0;ss<grid->oSites();ss+=Ls){ // adds Ls
|
||||
vobj tmp;
|
||||
tmp = G5*y._odata[ss+sp]*b;
|
||||
@ -112,7 +113,8 @@ void ag5xpbg5y_ssp(Lattice<vobj> &z,Coeff a,const Lattice<vobj> &x,Coeff b,const
|
||||
conformable(x,z);
|
||||
GridBase *grid=x._grid;
|
||||
int Ls = grid->_rdimensions[0];
|
||||
Gamma G5(Gamma::Gamma5);
|
||||
|
||||
Gamma G5(Gamma::Algebra::Gamma5);
|
||||
parallel_for(int ss=0;ss<grid->oSites();ss+=Ls){ // adds Ls
|
||||
vobj tmp1;
|
||||
vobj tmp2;
|
||||
@ -161,8 +163,8 @@ void G5R5(Lattice<vobj> &z,const Lattice<vobj> &x)
|
||||
z.checkerboard = x.checkerboard;
|
||||
conformable(x,z);
|
||||
int Ls = grid->_rdimensions[0];
|
||||
Gamma G5(Gamma::Gamma5);
|
||||
parallel_for(int ss=0;ss<grid->oSites();ss+=Ls){ // adds Ls
|
||||
Gamma G5(Gamma::Algebra::Gamma5);
|
||||
parallel_for(int ss=0;ss<grid->oSites();ss+=Ls) {
|
||||
vobj tmp;
|
||||
for(int s=0;s<Ls;s++){
|
||||
int sp = Ls-1-s;
|
||||
|
@ -32,6 +32,7 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Grid {
|
||||
// Vector IO utilities ///////////////////////////////////////////////////////
|
||||
// helper function to read space-separated values
|
||||
template <typename T>
|
||||
std::vector<T> strToVec(const std::string s)
|
||||
@ -67,6 +68,77 @@ namespace Grid {
|
||||
return os;
|
||||
}
|
||||
|
||||
// Vector element trait //////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
struct element
|
||||
{
|
||||
typedef T type;
|
||||
static constexpr bool is_number = false;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct element<std::vector<T>>
|
||||
{
|
||||
typedef typename element<T>::type type;
|
||||
static constexpr bool is_number = std::is_arithmetic<T>::value
|
||||
or is_complex<T>::value
|
||||
or element<T>::is_number;
|
||||
};
|
||||
|
||||
// Vector flatening utility class ////////////////////////////////////////////
|
||||
// Class to flatten a multidimensional std::vector
|
||||
template <typename V>
|
||||
class Flatten
|
||||
{
|
||||
public:
|
||||
typedef typename element<V>::type Element;
|
||||
public:
|
||||
explicit Flatten(const V &vector);
|
||||
const V & getVector(void);
|
||||
const std::vector<Element> & getFlatVector(void);
|
||||
const std::vector<size_t> & getDim(void);
|
||||
private:
|
||||
void accumulate(const Element &e);
|
||||
template <typename W>
|
||||
void accumulate(const W &v);
|
||||
void accumulateDim(const Element &e);
|
||||
template <typename W>
|
||||
void accumulateDim(const W &v);
|
||||
private:
|
||||
const V &vector_;
|
||||
std::vector<Element> flatVector_;
|
||||
std::vector<size_t> dim_;
|
||||
};
|
||||
|
||||
|
||||
// Class to reconstruct a multidimensional std::vector
|
||||
template <typename V>
|
||||
class Reconstruct
|
||||
{
|
||||
public:
|
||||
typedef typename element<V>::type Element;
|
||||
public:
|
||||
Reconstruct(const std::vector<Element> &flatVector,
|
||||
const std::vector<size_t> &dim);
|
||||
const V & getVector(void);
|
||||
const std::vector<Element> & getFlatVector(void);
|
||||
const std::vector<size_t> & getDim(void);
|
||||
private:
|
||||
void fill(std::vector<Element> &v);
|
||||
template <typename W>
|
||||
void fill(W &v);
|
||||
void resize(std::vector<Element> &v, const unsigned int dim);
|
||||
template <typename W>
|
||||
void resize(W &v, const unsigned int dim);
|
||||
private:
|
||||
V vector_;
|
||||
const std::vector<Element> &flatVector_;
|
||||
std::vector<size_t> dim_;
|
||||
size_t ind_{0};
|
||||
unsigned int dimInd_{0};
|
||||
};
|
||||
|
||||
// Abstract writer/reader classes ////////////////////////////////////////////
|
||||
// static polymorphism implemented using CRTP idiom
|
||||
class Serializable;
|
||||
|
||||
@ -83,12 +155,7 @@ namespace Grid {
|
||||
typename std::enable_if<std::is_base_of<Serializable, U>::value, void>::type
|
||||
write(const std::string& s, const U &output);
|
||||
template <typename U>
|
||||
typename std::enable_if<std::is_enum<U>::value, void>::type
|
||||
write(const std::string& s, const U &output);
|
||||
template <typename U>
|
||||
typename std::enable_if<
|
||||
!(std::is_base_of<Serializable, U>::value or std::is_enum<U>::value),
|
||||
void>::type
|
||||
typename std::enable_if<!std::is_base_of<Serializable, U>::value, void>::type
|
||||
write(const std::string& s, const U &output);
|
||||
private:
|
||||
T *upcast;
|
||||
@ -107,12 +174,7 @@ namespace Grid {
|
||||
typename std::enable_if<std::is_base_of<Serializable, U>::value, void>::type
|
||||
read(const std::string& s, U &output);
|
||||
template <typename U>
|
||||
typename std::enable_if<std::is_enum<U>::value, void>::type
|
||||
read(const std::string& s, U &output);
|
||||
template <typename U>
|
||||
typename std::enable_if<
|
||||
!(std::is_base_of<Serializable, U>::value or std::is_enum<U>::value),
|
||||
void>::type
|
||||
typename std::enable_if<!std::is_base_of<Serializable, U>::value, void>::type
|
||||
read(const std::string& s, U &output);
|
||||
protected:
|
||||
template <typename U>
|
||||
@ -142,7 +204,128 @@ namespace Grid {
|
||||
}
|
||||
};
|
||||
|
||||
// Generic writer interface
|
||||
// Flatten class template implementation /////////////////////////////////////
|
||||
template <typename V>
|
||||
void Flatten<V>::accumulate(const Element &e)
|
||||
{
|
||||
flatVector_.push_back(e);
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
template <typename W>
|
||||
void Flatten<V>::accumulate(const W &v)
|
||||
{
|
||||
for (auto &e: v)
|
||||
{
|
||||
accumulate(e);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
void Flatten<V>::accumulateDim(const Element &e) {};
|
||||
|
||||
template <typename V>
|
||||
template <typename W>
|
||||
void Flatten<V>::accumulateDim(const W &v)
|
||||
{
|
||||
dim_.push_back(v.size());
|
||||
accumulateDim(v[0]);
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
Flatten<V>::Flatten(const V &vector)
|
||||
: vector_(vector)
|
||||
{
|
||||
accumulate(vector_);
|
||||
accumulateDim(vector_);
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
const V & Flatten<V>::getVector(void)
|
||||
{
|
||||
return vector_;
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
const std::vector<typename Flatten<V>::Element> &
|
||||
Flatten<V>::getFlatVector(void)
|
||||
{
|
||||
return flatVector_;
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
const std::vector<size_t> & Flatten<V>::getDim(void)
|
||||
{
|
||||
return dim_;
|
||||
}
|
||||
|
||||
// Reconstruct class template implementation /////////////////////////////////
|
||||
template <typename V>
|
||||
void Reconstruct<V>::fill(std::vector<Element> &v)
|
||||
{
|
||||
for (auto &e: v)
|
||||
{
|
||||
e = flatVector_[ind_++];
|
||||
}
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
template <typename W>
|
||||
void Reconstruct<V>::fill(W &v)
|
||||
{
|
||||
for (auto &e: v)
|
||||
{
|
||||
fill(e);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
void Reconstruct<V>::resize(std::vector<Element> &v, const unsigned int dim)
|
||||
{
|
||||
v.resize(dim_[dim]);
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
template <typename W>
|
||||
void Reconstruct<V>::resize(W &v, const unsigned int dim)
|
||||
{
|
||||
v.resize(dim_[dim]);
|
||||
for (auto &e: v)
|
||||
{
|
||||
resize(e, dim + 1);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
Reconstruct<V>::Reconstruct(const std::vector<Element> &flatVector,
|
||||
const std::vector<size_t> &dim)
|
||||
: flatVector_(flatVector)
|
||||
, dim_(dim)
|
||||
{
|
||||
resize(vector_, 0);
|
||||
fill(vector_);
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
const V & Reconstruct<V>::getVector(void)
|
||||
{
|
||||
return vector_;
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
const std::vector<typename Reconstruct<V>::Element> &
|
||||
Reconstruct<V>::getFlatVector(void)
|
||||
{
|
||||
return flatVector_;
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
const std::vector<size_t> & Reconstruct<V>::getDim(void)
|
||||
{
|
||||
return dim_;
|
||||
}
|
||||
|
||||
// Generic writer interface //////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline void push(Writer<T> &w, const std::string &s)
|
||||
{
|
||||
@ -221,23 +404,13 @@ namespace Grid {
|
||||
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
typename std::enable_if<std::is_enum<U>::value, void>::type
|
||||
Writer<T>::write(const std::string &s, const U &output)
|
||||
{
|
||||
EnumIO<U>::write(*this, s, output);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
typename std::enable_if<
|
||||
!(std::is_base_of<Serializable, U>::value or std::is_enum<U>::value),
|
||||
void>::type
|
||||
typename std::enable_if<!std::is_base_of<Serializable, U>::value, void>::type
|
||||
Writer<T>::write(const std::string &s, const U &output)
|
||||
{
|
||||
upcast->writeDefault(s, output);
|
||||
}
|
||||
|
||||
// Reader template implementation ////////////////////////////////////////////
|
||||
// Reader template implementation
|
||||
template <typename T>
|
||||
Reader<T>::Reader(void)
|
||||
{
|
||||
@ -266,17 +439,7 @@ namespace Grid {
|
||||
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
typename std::enable_if<std::is_enum<U>::value, void>::type
|
||||
Reader<T>::read(const std::string &s, U &output)
|
||||
{
|
||||
EnumIO<U>::read(*this, s, output);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
typename std::enable_if<
|
||||
!(std::is_base_of<Serializable, U>::value or std::is_enum<U>::value),
|
||||
void>::type
|
||||
typename std::enable_if<!std::is_base_of<Serializable, U>::value, void>::type
|
||||
Reader<T>::read(const std::string &s, U &output)
|
||||
{
|
||||
upcast->readDefault(s, output);
|
||||
@ -300,7 +463,6 @@ namespace Grid {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -26,7 +26,6 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
|
||||
#include <Grid/GridCore.h>
|
||||
|
||||
using namespace Grid;
|
||||
|
103
lib/serialisation/Hdf5IO.cc
Normal file
103
lib/serialisation/Hdf5IO.cc
Normal file
@ -0,0 +1,103 @@
|
||||
#include <Grid/Grid.h>
|
||||
|
||||
using namespace Grid;
|
||||
#ifndef H5_NO_NAMESPACE
|
||||
using namespace H5NS;
|
||||
#endif
|
||||
|
||||
// Writer implementation ///////////////////////////////////////////////////////
|
||||
Hdf5Writer::Hdf5Writer(const std::string &fileName)
|
||||
: fileName_(fileName)
|
||||
, file_(fileName.c_str(), H5F_ACC_TRUNC)
|
||||
{
|
||||
group_ = file_.openGroup("/");
|
||||
writeSingleAttribute(dataSetThres_, HDF5_GRID_GUARD "dataset_threshold",
|
||||
Hdf5Type<unsigned int>::type());
|
||||
}
|
||||
|
||||
void Hdf5Writer::push(const std::string &s)
|
||||
{
|
||||
group_ = group_.createGroup(s);
|
||||
path_.push_back(s);
|
||||
}
|
||||
|
||||
void Hdf5Writer::pop(void)
|
||||
{
|
||||
path_.pop_back();
|
||||
if (path_.empty())
|
||||
{
|
||||
group_ = file_.openGroup("/");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto binOp = [](const std::string &a, const std::string &b)->std::string
|
||||
{
|
||||
return a + "/" + b;
|
||||
};
|
||||
|
||||
group_ = group_.openGroup(std::accumulate(path_.begin(), path_.end(),
|
||||
std::string(""), binOp));
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
void Hdf5Writer::writeDefault(const std::string &s, const std::string &x)
|
||||
{
|
||||
StrType strType(PredType::C_S1, x.size());
|
||||
|
||||
writeSingleAttribute(*(x.data()), s, strType);
|
||||
}
|
||||
|
||||
void Hdf5Writer::writeDefault(const std::string &s, const char *x)
|
||||
{
|
||||
std::string sx(x);
|
||||
|
||||
writeDefault(s, sx);
|
||||
}
|
||||
|
||||
// Reader implementation ///////////////////////////////////////////////////////
|
||||
Hdf5Reader::Hdf5Reader(const std::string &fileName)
|
||||
: fileName_(fileName)
|
||||
, file_(fileName.c_str(), H5F_ACC_RDONLY)
|
||||
{
|
||||
group_ = file_.openGroup("/");
|
||||
readSingleAttribute(dataSetThres_, HDF5_GRID_GUARD "dataset_threshold",
|
||||
Hdf5Type<unsigned int>::type());
|
||||
}
|
||||
|
||||
void Hdf5Reader::push(const std::string &s)
|
||||
{
|
||||
group_ = group_.openGroup(s);
|
||||
path_.push_back(s);
|
||||
}
|
||||
|
||||
void Hdf5Reader::pop(void)
|
||||
{
|
||||
path_.pop_back();
|
||||
if (path_.empty())
|
||||
{
|
||||
group_ = file_.openGroup("/");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto binOp = [](const std::string &a, const std::string &b)->std::string
|
||||
{
|
||||
return a + "/" + b;
|
||||
};
|
||||
|
||||
group_ = group_.openGroup(std::accumulate(path_.begin(), path_.end(),
|
||||
std::string(""), binOp));
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
void Hdf5Reader::readDefault(const std::string &s, std::string &x)
|
||||
{
|
||||
Attribute attribute;
|
||||
|
||||
attribute = group_.openAttribute(s);
|
||||
StrType strType = attribute.getStrType();
|
||||
|
||||
x.resize(strType.getSize());
|
||||
attribute.read(strType, &(x[0]));
|
||||
}
|
242
lib/serialisation/Hdf5IO.h
Normal file
242
lib/serialisation/Hdf5IO.h
Normal file
@ -0,0 +1,242 @@
|
||||
#ifndef GRID_SERIALISATION_HDF5_H
|
||||
#define GRID_SERIALISATION_HDF5_H
|
||||
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <H5Cpp.h>
|
||||
#include "Hdf5Type.h"
|
||||
|
||||
#ifndef H5_NO_NAMESPACE
|
||||
#define H5NS H5
|
||||
#endif
|
||||
|
||||
// default thresold above which datasets are used instead of attributes
|
||||
#ifndef HDF5_DEF_DATASET_THRES
|
||||
#define HDF5_DEF_DATASET_THRES 6u
|
||||
#endif
|
||||
|
||||
// name guard for Grid metadata
|
||||
#define HDF5_GRID_GUARD "_Grid_"
|
||||
|
||||
namespace Grid
|
||||
{
|
||||
class Hdf5Writer: public Writer<Hdf5Writer>
|
||||
{
|
||||
public:
|
||||
Hdf5Writer(const std::string &fileName);
|
||||
virtual ~Hdf5Writer(void) = default;
|
||||
void push(const std::string &s);
|
||||
void pop(void);
|
||||
void writeDefault(const std::string &s, const char *x);
|
||||
template <typename U>
|
||||
void writeDefault(const std::string &s, const U &x);
|
||||
template <typename U>
|
||||
typename std::enable_if<element<std::vector<U>>::is_number, void>::type
|
||||
writeDefault(const std::string &s, const std::vector<U> &x);
|
||||
template <typename U>
|
||||
typename std::enable_if<!element<std::vector<U>>::is_number, void>::type
|
||||
writeDefault(const std::string &s, const std::vector<U> &x);
|
||||
private:
|
||||
template <typename U>
|
||||
void writeSingleAttribute(const U &x, const std::string &name,
|
||||
const H5NS::DataType &type);
|
||||
private:
|
||||
std::string fileName_;
|
||||
std::vector<std::string> path_;
|
||||
H5NS::H5File file_;
|
||||
H5NS::Group group_;
|
||||
unsigned int dataSetThres_{HDF5_DEF_DATASET_THRES};
|
||||
};
|
||||
|
||||
class Hdf5Reader: public Reader<Hdf5Reader>
|
||||
{
|
||||
public:
|
||||
Hdf5Reader(const std::string &fileName);
|
||||
virtual ~Hdf5Reader(void) = default;
|
||||
void push(const std::string &s);
|
||||
void pop(void);
|
||||
template <typename U>
|
||||
void readDefault(const std::string &s, U &output);
|
||||
template <typename U>
|
||||
typename std::enable_if<element<std::vector<U>>::is_number, void>::type
|
||||
readDefault(const std::string &s, std::vector<U> &x);
|
||||
template <typename U>
|
||||
typename std::enable_if<!element<std::vector<U>>::is_number, void>::type
|
||||
readDefault(const std::string &s, std::vector<U> &x);
|
||||
private:
|
||||
template <typename U>
|
||||
void readSingleAttribute(U &x, const std::string &name,
|
||||
const H5NS::DataType &type);
|
||||
private:
|
||||
std::string fileName_;
|
||||
std::vector<std::string> path_;
|
||||
H5NS::H5File file_;
|
||||
H5NS::Group group_;
|
||||
unsigned int dataSetThres_;
|
||||
};
|
||||
|
||||
// Writer template implementation ////////////////////////////////////////////
|
||||
template <typename U>
|
||||
void Hdf5Writer::writeSingleAttribute(const U &x, const std::string &name,
|
||||
const H5NS::DataType &type)
|
||||
{
|
||||
H5NS::Attribute attribute;
|
||||
hsize_t attrDim = 1;
|
||||
H5NS::DataSpace attrSpace(1, &attrDim);
|
||||
|
||||
attribute = group_.createAttribute(name, type, attrSpace);
|
||||
attribute.write(type, &x);
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
void Hdf5Writer::writeDefault(const std::string &s, const U &x)
|
||||
{
|
||||
writeSingleAttribute(x, s, Hdf5Type<U>::type());
|
||||
}
|
||||
|
||||
template <>
|
||||
void Hdf5Writer::writeDefault(const std::string &s, const std::string &x);
|
||||
|
||||
template <typename U>
|
||||
typename std::enable_if<element<std::vector<U>>::is_number, void>::type
|
||||
Hdf5Writer::writeDefault(const std::string &s, const std::vector<U> &x)
|
||||
{
|
||||
// alias to element type
|
||||
typedef typename element<std::vector<U>>::type Element;
|
||||
|
||||
// flatten the vector and getting dimensions
|
||||
Flatten<std::vector<U>> flat(x);
|
||||
std::vector<hsize_t> dim;
|
||||
const auto &flatx = flat.getFlatVector();
|
||||
|
||||
for (auto &d: flat.getDim())
|
||||
{
|
||||
dim.push_back(d);
|
||||
}
|
||||
|
||||
// write to file
|
||||
H5NS::DataSpace dataSpace(dim.size(), dim.data());
|
||||
|
||||
if (flatx.size() > dataSetThres_)
|
||||
{
|
||||
H5NS::DataSet dataSet;
|
||||
|
||||
dataSet = group_.createDataSet(s, Hdf5Type<Element>::type(), dataSpace);
|
||||
dataSet.write(flatx.data(), Hdf5Type<Element>::type());
|
||||
}
|
||||
else
|
||||
{
|
||||
H5NS::Attribute attribute;
|
||||
|
||||
attribute = group_.createAttribute(s, Hdf5Type<Element>::type(), dataSpace);
|
||||
attribute.write(Hdf5Type<Element>::type(), flatx.data());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
typename std::enable_if<!element<std::vector<U>>::is_number, void>::type
|
||||
Hdf5Writer::writeDefault(const std::string &s, const std::vector<U> &x)
|
||||
{
|
||||
push(s);
|
||||
writeSingleAttribute(x.size(), HDF5_GRID_GUARD "vector_size",
|
||||
Hdf5Type<uint64_t>::type());
|
||||
for (hsize_t i = 0; i < x.size(); ++i)
|
||||
{
|
||||
write(s + "_" + std::to_string(i), x[i]);
|
||||
}
|
||||
pop();
|
||||
}
|
||||
|
||||
// Reader template implementation ////////////////////////////////////////////
|
||||
template <typename U>
|
||||
void Hdf5Reader::readSingleAttribute(U &x, const std::string &name,
|
||||
const H5NS::DataType &type)
|
||||
{
|
||||
H5NS::Attribute attribute;
|
||||
|
||||
attribute = group_.openAttribute(name);
|
||||
attribute.read(type, &x);
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
void Hdf5Reader::readDefault(const std::string &s, U &output)
|
||||
{
|
||||
readSingleAttribute(output, s, Hdf5Type<U>::type());
|
||||
}
|
||||
|
||||
template <>
|
||||
void Hdf5Reader::readDefault(const std::string &s, std::string &x);
|
||||
|
||||
template <typename U>
|
||||
typename std::enable_if<element<std::vector<U>>::is_number, void>::type
|
||||
Hdf5Reader::readDefault(const std::string &s, std::vector<U> &x)
|
||||
{
|
||||
// alias to element type
|
||||
typedef typename element<std::vector<U>>::type Element;
|
||||
|
||||
// read the dimensions
|
||||
H5NS::DataSpace dataSpace;
|
||||
std::vector<hsize_t> hdim;
|
||||
std::vector<size_t> dim;
|
||||
hsize_t size = 1;
|
||||
|
||||
if (group_.attrExists(s))
|
||||
{
|
||||
dataSpace = group_.openAttribute(s).getSpace();
|
||||
}
|
||||
else
|
||||
{
|
||||
dataSpace = group_.openDataSet(s).getSpace();
|
||||
}
|
||||
hdim.resize(dataSpace.getSimpleExtentNdims());
|
||||
dataSpace.getSimpleExtentDims(hdim.data());
|
||||
for (auto &d: hdim)
|
||||
{
|
||||
dim.push_back(d);
|
||||
size *= d;
|
||||
}
|
||||
|
||||
// read the flat vector
|
||||
std::vector<Element> buf(size);
|
||||
|
||||
if (size > dataSetThres_)
|
||||
{
|
||||
H5NS::DataSet dataSet;
|
||||
|
||||
dataSet = group_.openDataSet(s);
|
||||
dataSet.read(buf.data(), Hdf5Type<Element>::type());
|
||||
}
|
||||
else
|
||||
{
|
||||
H5NS::Attribute attribute;
|
||||
|
||||
attribute = group_.openAttribute(s);
|
||||
attribute.read(Hdf5Type<Element>::type(), buf.data());
|
||||
}
|
||||
|
||||
// reconstruct the multidimensional vector
|
||||
Reconstruct<std::vector<U>> r(buf, dim);
|
||||
|
||||
x = r.getVector();
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
typename std::enable_if<!element<std::vector<U>>::is_number, void>::type
|
||||
Hdf5Reader::readDefault(const std::string &s, std::vector<U> &x)
|
||||
{
|
||||
uint64_t size;
|
||||
|
||||
push(s);
|
||||
readSingleAttribute(size, HDF5_GRID_GUARD "vector_size",
|
||||
Hdf5Type<uint64_t>::type());
|
||||
x.resize(size);
|
||||
for (hsize_t i = 0; i < x.size(); ++i)
|
||||
{
|
||||
read(s + "_" + std::to_string(i), x[i]);
|
||||
}
|
||||
pop();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
77
lib/serialisation/Hdf5Type.h
Normal file
77
lib/serialisation/Hdf5Type.h
Normal file
@ -0,0 +1,77 @@
|
||||
#ifndef GRID_SERIALISATION_HDF5_TYPE_H
|
||||
#define GRID_SERIALISATION_HDF5_TYPE_H
|
||||
|
||||
#include <H5Cpp.h>
|
||||
#include <complex>
|
||||
#include <memory>
|
||||
|
||||
#ifndef H5_NO_NAMESPACE
|
||||
#define H5NS H5
|
||||
#endif
|
||||
|
||||
#define HDF5_NATIVE_TYPE(predType, cType)\
|
||||
template <>\
|
||||
class Hdf5Type<cType>\
|
||||
{\
|
||||
public:\
|
||||
static inline const H5NS::DataType & type(void)\
|
||||
{\
|
||||
return H5NS::PredType::predType;\
|
||||
}\
|
||||
static constexpr bool isNative = true;\
|
||||
};
|
||||
|
||||
#define DEFINE_HDF5_NATIVE_TYPES \
|
||||
HDF5_NATIVE_TYPE(NATIVE_B8, bool);\
|
||||
HDF5_NATIVE_TYPE(NATIVE_CHAR, char);\
|
||||
HDF5_NATIVE_TYPE(NATIVE_SCHAR, signed char);\
|
||||
HDF5_NATIVE_TYPE(NATIVE_UCHAR, unsigned char);\
|
||||
HDF5_NATIVE_TYPE(NATIVE_SHORT, short);\
|
||||
HDF5_NATIVE_TYPE(NATIVE_USHORT, unsigned short);\
|
||||
HDF5_NATIVE_TYPE(NATIVE_INT, int);\
|
||||
HDF5_NATIVE_TYPE(NATIVE_UINT, unsigned int);\
|
||||
HDF5_NATIVE_TYPE(NATIVE_LONG, long);\
|
||||
HDF5_NATIVE_TYPE(NATIVE_ULONG, unsigned long);\
|
||||
HDF5_NATIVE_TYPE(NATIVE_LLONG, long long);\
|
||||
HDF5_NATIVE_TYPE(NATIVE_ULLONG, unsigned long long);\
|
||||
HDF5_NATIVE_TYPE(NATIVE_FLOAT, float);\
|
||||
HDF5_NATIVE_TYPE(NATIVE_DOUBLE, double);\
|
||||
HDF5_NATIVE_TYPE(NATIVE_LDOUBLE, long double);
|
||||
|
||||
namespace Grid
|
||||
{
|
||||
template <typename T> class Hdf5Type
|
||||
{
|
||||
public:
|
||||
static constexpr bool isNative = false;
|
||||
};
|
||||
|
||||
DEFINE_HDF5_NATIVE_TYPES;
|
||||
|
||||
template <typename R>
|
||||
class Hdf5Type<std::complex<R>>
|
||||
{
|
||||
public:
|
||||
static inline const H5NS::DataType & type(void)
|
||||
{
|
||||
if (typePtr_ == nullptr)
|
||||
{
|
||||
typePtr_.reset(new H5NS::CompType(sizeof(std::complex<R>)));
|
||||
typePtr_->insertMember("re", 0, Hdf5Type<R>::type());
|
||||
typePtr_->insertMember("im", sizeof(R), Hdf5Type<R>::type());
|
||||
}
|
||||
|
||||
return *typePtr_;
|
||||
}
|
||||
static constexpr bool isNative = false;
|
||||
private:
|
||||
static std::unique_ptr<H5NS::CompType> typePtr_;
|
||||
};
|
||||
|
||||
template <typename R>
|
||||
std::unique_ptr<H5NS::CompType> Hdf5Type<std::complex<R>>::typePtr_ = nullptr;
|
||||
}
|
||||
|
||||
#undef HDF5_NATIVE_TYPE
|
||||
|
||||
#endif /* GRID_SERIALISATION_HDF5_TYPE_H */
|
@ -109,40 +109,36 @@ THE SOFTWARE.
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define GRID_MACRO_MEMBER(A,B) A B;
|
||||
#define GRID_MACRO_COMP_MEMBER(A,B) result = (result and (lhs. B == rhs. B));
|
||||
#define GRID_MACRO_OS_WRITE_MEMBER(A,B) os<< #A <<" "#B <<" = "<< obj. B <<" ; " <<std::endl;
|
||||
#define GRID_MACRO_READ_MEMBER(A,B) Grid::read(RD,#B,obj. B);
|
||||
#define GRID_MACRO_WRITE_MEMBER(A,B) Grid::write(WR,#B,obj. B);
|
||||
|
||||
#define GRID_SERIALIZABLE_CLASS_MEMBERS(cname,...) \
|
||||
\
|
||||
\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_MEMBER,__VA_ARGS__)) \
|
||||
\
|
||||
\
|
||||
template <typename T>\
|
||||
static inline void write(Writer<T> &WR,const std::string &s, const cname &obj){ \
|
||||
push(WR,s);\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_WRITE_MEMBER,__VA_ARGS__)) \
|
||||
pop(WR);\
|
||||
} \
|
||||
\
|
||||
\
|
||||
template <typename T>\
|
||||
static inline void read(Reader<T> &RD,const std::string &s, cname &obj){ \
|
||||
push(RD,s);\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_READ_MEMBER,__VA_ARGS__)) \
|
||||
pop(RD);\
|
||||
} \
|
||||
\
|
||||
\
|
||||
friend inline std::ostream & operator << (std::ostream &os, const cname &obj ) { \
|
||||
os<<"class "<<#cname<<" {"<<std::endl;\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_OS_WRITE_MEMBER,__VA_ARGS__)) \
|
||||
os<<"}"; \
|
||||
return os;\
|
||||
};
|
||||
|
||||
|
||||
#define GRID_SERIALIZABLE_CLASS_MEMBERS(cname,...)\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_MEMBER,__VA_ARGS__))\
|
||||
template <typename T>\
|
||||
static inline void write(Writer<T> &WR,const std::string &s, const cname &obj){ \
|
||||
push(WR,s);\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_WRITE_MEMBER,__VA_ARGS__)) \
|
||||
pop(WR);\
|
||||
}\
|
||||
template <typename T>\
|
||||
static inline void read(Reader<T> &RD,const std::string &s, cname &obj){ \
|
||||
push(RD,s);\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_READ_MEMBER,__VA_ARGS__)) \
|
||||
pop(RD);\
|
||||
}\
|
||||
friend inline std::ostream & operator << (std::ostream &os, const cname &obj ) { \
|
||||
os<<"class "<<#cname<<" {"<<std::endl;\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_OS_WRITE_MEMBER,__VA_ARGS__)) \
|
||||
os<<"}"; \
|
||||
return os;\
|
||||
}\
|
||||
friend inline bool operator==(const cname &lhs, const cname &rhs) {\
|
||||
bool result = true;\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_COMP_MEMBER,__VA_ARGS__))\
|
||||
return result;\
|
||||
}
|
||||
|
||||
#define GRID_ENUM_TYPE(obj) std::remove_reference<decltype(obj)>::type
|
||||
#define GRID_MACRO_ENUMVAL(A,B) A = B,
|
||||
@ -150,44 +146,61 @@ THE SOFTWARE.
|
||||
#define GRID_MACRO_ENUMTEST(A,B) else if (buf == #A) {obj = GRID_ENUM_TYPE(obj)::A;}
|
||||
#define GRID_MACRO_ENUMCASEIO(A,B) case GRID_ENUM_TYPE(obj)::A: os << #A; break;
|
||||
|
||||
namespace Grid {
|
||||
template <typename U>
|
||||
class EnumIO {};
|
||||
}
|
||||
|
||||
#define GRID_SERIALIZABLE_ENUM(name,undefname,...)\
|
||||
enum class name {\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_ENUMVAL,__VA_ARGS__))\
|
||||
undefname = -1\
|
||||
class name: public Grid::Serializable\
|
||||
{\
|
||||
public:\
|
||||
enum\
|
||||
{\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_ENUMVAL,__VA_ARGS__))\
|
||||
undefname = -1\
|
||||
};\
|
||||
public:\
|
||||
name(void): value_(undefname) {};\
|
||||
name(int value): value_(value) {};\
|
||||
template <typename T>\
|
||||
static inline void write(Grid::Writer<T> &WR,const std::string &s, const name &obj)\
|
||||
{\
|
||||
switch (obj.value_)\
|
||||
{\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_ENUMCASE,__VA_ARGS__))\
|
||||
default: Grid::write(WR,s,#undefname); break;\
|
||||
}\
|
||||
}\
|
||||
\
|
||||
template<>\
|
||||
class EnumIO<name> {\
|
||||
public:\
|
||||
template <typename T>\
|
||||
static inline void write(Writer<T> &WR,const std::string &s, const name &obj){ \
|
||||
switch (obj) {\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_ENUMCASE,__VA_ARGS__))\
|
||||
default: Grid::write(WR,s,#undefname); break;\
|
||||
}\
|
||||
}\
|
||||
\
|
||||
template <typename T>\
|
||||
static inline void read(Reader<T> &RD,const std::string &s, name &obj){ \
|
||||
std::string buf;\
|
||||
Grid::read(RD, s, buf);\
|
||||
if (buf == #undefname) {obj = name::undefname;}\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_ENUMTEST,__VA_ARGS__))\
|
||||
else {obj = name::undefname;}\
|
||||
}\
|
||||
};\
|
||||
\
|
||||
inline std::ostream & operator << (std::ostream &os, const name &obj ) { \
|
||||
template <typename T>\
|
||||
static inline void read(Grid::Reader<T> &RD,const std::string &s, name &obj)\
|
||||
{\
|
||||
std::string buf;\
|
||||
Grid::read(RD, s, buf);\
|
||||
if (buf == #undefname) {obj = name::undefname;}\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_ENUMTEST,__VA_ARGS__))\
|
||||
else {obj = name::undefname;}\
|
||||
}\
|
||||
inline operator int(void) const\
|
||||
{\
|
||||
return value_;\
|
||||
}\
|
||||
inline friend std::ostream & operator<<(std::ostream &os, const name &obj)\
|
||||
{\
|
||||
switch (obj) {\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_ENUMCASEIO,__VA_ARGS__))\
|
||||
default: os << #undefname; break;\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_ENUMCASEIO,__VA_ARGS__))\
|
||||
default: os << #undefname; break;\
|
||||
}\
|
||||
return os;\
|
||||
};
|
||||
}\
|
||||
inline friend std::istream & operator>>(std::istream &is, name &obj)\
|
||||
{\
|
||||
std::string buf;\
|
||||
is >> buf;\
|
||||
if (buf == #undefname) {obj = name::undefname;}\
|
||||
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_ENUMTEST,__VA_ARGS__))\
|
||||
else {obj = name::undefname;}\
|
||||
return is;\
|
||||
}\
|
||||
private:\
|
||||
int value_;\
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -36,6 +36,9 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
#include "BinaryIO.h"
|
||||
#include "TextIO.h"
|
||||
#include "XmlIO.h"
|
||||
#ifdef HAVE_HDF5
|
||||
#include "Hdf5IO.h"
|
||||
#endif
|
||||
//////////////////////////////////////////
|
||||
// Todo:
|
||||
//////////////////////////////////////////
|
||||
|
390
lib/sitmo_rng/sitmo_prng_engine.hpp
Normal file
390
lib/sitmo_rng/sitmo_prng_engine.hpp
Normal file
@ -0,0 +1,390 @@
|
||||
// Copyright (c) 2012-2016 M.A. (Thijs) van den Berg, http://sitmo.com/
|
||||
//
|
||||
// Use, modification and distribution are subject to the MIT Software License.
|
||||
//
|
||||
// The MIT License (MIT)
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
// version history:
|
||||
// version 1, 6 Sep 2012
|
||||
// version 2, 10 Dec 2013
|
||||
// bug fix in the discard() routine, it was discarding to many elements
|
||||
// added the version() method
|
||||
// version 3...5, 13 Dec 2013
|
||||
// fixed type-conversion earning
|
||||
// fixed potential issues with constructor template matching
|
||||
// version 6, 4 March 2016
|
||||
// made min() max() constexpr for C+11 compiler (thanks to James Joseph Balamuta)
|
||||
|
||||
#ifndef SITMO_PRNG_ENGINE_HPP
|
||||
#define SITMO_PRNG_ENGINE_HPP
|
||||
#include <iostream>
|
||||
|
||||
#ifdef __GNUC__
|
||||
#include <stdint.h> // respecting the C99 standard.
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
typedef unsigned __int64 uint64_t; // Visual Studio 6.0(VC6) and newer..
|
||||
typedef unsigned __int32 uint32_t;
|
||||
#endif
|
||||
|
||||
// Double mixing function
|
||||
#define MIX2(x0,x1,rx,z0,z1,rz) \
|
||||
x0 += x1; \
|
||||
z0 += z1; \
|
||||
x1 = (x1 << rx) | (x1 >> (64-rx)); \
|
||||
z1 = (z1 << rz) | (z1 >> (64-rz)); \
|
||||
x1 ^= x0; \
|
||||
z1 ^= z0;
|
||||
|
||||
|
||||
// Double mixing function with key adition
|
||||
#define MIXK(x0,x1,rx,z0,z1,rz,k0,k1,l0,l1) \
|
||||
x1 += k1; \
|
||||
z1 += l1; \
|
||||
x0 += x1+k0; \
|
||||
z0 += z1+l0; \
|
||||
x1 = (x1 << rx) | (x1 >> (64-rx)); \
|
||||
z1 = (z1 << rz) | (z1 >> (64-rz)); \
|
||||
x1 ^= x0; \
|
||||
z1 ^= z0; \
|
||||
|
||||
|
||||
namespace sitmo {
|
||||
|
||||
// enable_if for C__98 compilers
|
||||
template<bool C, typename T = void>
|
||||
struct sitmo_enable_if { typedef T type; };
|
||||
|
||||
template<typename T>
|
||||
struct sitmo_enable_if<false, T> { };
|
||||
|
||||
// SFINAE check for the existence of a "void generate(int*,int*)"member function
|
||||
template<typename T>
|
||||
struct has_generate_template
|
||||
{
|
||||
typedef char (&Two)[2];;
|
||||
template<typename F, void (F::*)(int *, int *)> struct helper {};
|
||||
template<typename C> static char test(helper<C, &C::template generate<int*> >*);
|
||||
template<typename C> static Two test(...);
|
||||
static bool const value = sizeof(test<T>(0)) == sizeof(char);
|
||||
};
|
||||
|
||||
|
||||
class prng_engine
|
||||
{
|
||||
public:
|
||||
// "req" are requirements as stated in the C++ 11 draft n3242=11-0012
|
||||
//
|
||||
// req: 26.5.1.3 Uniform random number generator requirements, p.906, table 116, row 1
|
||||
typedef uint32_t result_type;
|
||||
|
||||
// req: 26.5.1.3 Uniform random number generator requirements, p.906, table 116, row 3 & 4
|
||||
#if __cplusplus <= 199711L
|
||||
static result_type (min)() { return 0; }
|
||||
static result_type (max)() { return 0xFFFFFFFF; }
|
||||
#else
|
||||
static constexpr result_type (min)() { return 0; }
|
||||
static constexpr result_type (max)() { return 0xFFFFFFFF; }
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------
|
||||
// Constructors
|
||||
// -------------------------------------------------
|
||||
|
||||
// req: 26.5.1.4 Random number engine requirements, p.907 table 117, row 1
|
||||
// Creates an engine with the same initial state as all other
|
||||
// default-constructed engines of type E.
|
||||
prng_engine()
|
||||
{
|
||||
seed();
|
||||
}
|
||||
|
||||
// req: 26.5.1.4 Random number engine requirements, p.907 table 117, row 2
|
||||
// Creates an engine that compares equal to x.
|
||||
prng_engine(const prng_engine& x)
|
||||
{
|
||||
for (unsigned short i=0; i<4; ++i) {
|
||||
_s[i] = x._s[i];
|
||||
_k[i] = x._k[i];
|
||||
_o[i] = x._o[i];
|
||||
}
|
||||
_o_counter = x._o_counter;
|
||||
}
|
||||
|
||||
|
||||
// req: 26.5.1.4 Random number engine requirements, p.907 table 117, row 3
|
||||
// Creates an engine with initial O(size of state) state determined by s.
|
||||
prng_engine(uint32_t s)
|
||||
{
|
||||
seed(s);
|
||||
}
|
||||
|
||||
// req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 4
|
||||
// Creates an engine with an initial state that depends on a sequence
|
||||
// produced by one call to q.generate.
|
||||
template<class Seq>
|
||||
prng_engine(Seq& q, typename sitmo_enable_if< has_generate_template<Seq>::value >::type* = 0 )
|
||||
{
|
||||
seed(q);
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// Seeding
|
||||
// -------------------------------------------------
|
||||
|
||||
// req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 5
|
||||
void seed()
|
||||
{
|
||||
for (unsigned short i=0; i<4; ++i) {
|
||||
_k[i] = 0;
|
||||
_s[i] = 0;
|
||||
}
|
||||
_o_counter = 0;
|
||||
|
||||
_o[0] = 0x09218ebde6c85537;
|
||||
_o[1] = 0x55941f5266d86105;
|
||||
_o[2] = 0x4bd25e16282434dc;
|
||||
_o[3] = 0xee29ec846bd2e40b;
|
||||
}
|
||||
|
||||
// req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 6
|
||||
// s needs to be of return_type, which is uint32_t
|
||||
void seed(uint32_t s)
|
||||
{
|
||||
for (unsigned short i=0; i<4; ++i) {
|
||||
_k[i] = 0;
|
||||
_s[i] = 0;
|
||||
}
|
||||
_k[0] = s;
|
||||
_o_counter = 0;
|
||||
|
||||
encrypt_counter();
|
||||
}
|
||||
|
||||
// req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 7
|
||||
template<class Seq>
|
||||
void seed(Seq& q, typename sitmo_enable_if< has_generate_template<Seq>::value >::type* = 0 )
|
||||
{
|
||||
typename Seq::result_type w[8];
|
||||
q.generate(&w[0], &w[8]);
|
||||
|
||||
for (unsigned short i=0; i<4; ++i) {
|
||||
_k[i] = ( static_cast<uint64_t>(w[2*i]) << 32) | w[2*i+1];
|
||||
_s[i] = 0;
|
||||
}
|
||||
_o_counter = 0;
|
||||
|
||||
encrypt_counter();
|
||||
}
|
||||
|
||||
// req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 8
|
||||
// Advances e’s state ei to ei+1 = TA(ei) and returns GA(ei).
|
||||
uint32_t operator()()
|
||||
{
|
||||
// can we return a value from the current block?
|
||||
if (_o_counter < 8) {
|
||||
unsigned short _o_index = _o_counter >> 1;
|
||||
_o_counter++;
|
||||
if (_o_counter&1)
|
||||
return _o[_o_index] & 0xFFFFFFFF;
|
||||
else
|
||||
return _o[_o_index] >> 32;
|
||||
}
|
||||
|
||||
// generate a new block and return the first 32 bits
|
||||
inc_counter();
|
||||
encrypt_counter();
|
||||
_o_counter = 1; // the next call
|
||||
return _o[0] & 0xFFFFFFFF; // this call
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// misc
|
||||
// -------------------------------------------------
|
||||
|
||||
// req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 9
|
||||
// Advances e’s state ei to ei+z by any means equivalent to z
|
||||
// consecutive calls e().
|
||||
void discard(uint64_t z)
|
||||
{
|
||||
// check if we stay in the current block
|
||||
if (z < 8 - _o_counter) {
|
||||
_o_counter += static_cast<unsigned short>(z);
|
||||
return;
|
||||
}
|
||||
|
||||
// we will have to generate a new block...
|
||||
z -= (8 - _o_counter); // discard the remainder of the current blok
|
||||
_o_counter = z % 8; // set the pointer in the correct element in the new block
|
||||
z -= _o_counter; // update z
|
||||
z >>= 3; // the number of buffers is elements/8
|
||||
++z; // and one more because we crossed the buffer line
|
||||
inc_counter(z);
|
||||
encrypt_counter();
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// IO
|
||||
// -------------------------------------------------
|
||||
template<class CharT, class Traits>
|
||||
friend std::basic_ostream<CharT,Traits>&
|
||||
operator<<(std::basic_ostream<CharT,Traits>& os, const prng_engine& s) {
|
||||
for (unsigned short i=0; i<4; ++i)
|
||||
os << s._k[i] << ' ' << s._s[i] << ' ' << s._o[i] << ' ';
|
||||
os << s._o_counter;
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class CharT, class Traits>
|
||||
friend std::basic_istream<CharT,Traits>&
|
||||
operator>>(std::basic_istream<CharT,Traits>& is, prng_engine& s) {
|
||||
for (unsigned short i=0; i<4; ++i)
|
||||
is >> s._k[i] >> s._s[i] >> s._o[i];
|
||||
is >> s._o_counter;
|
||||
return is;
|
||||
}
|
||||
// req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 10
|
||||
// This operator is an equivalence relation. With Sx and Sy as the infinite
|
||||
// sequences of values that would be generated by repeated future calls to
|
||||
// x() and y(), respectively, returns true if Sx = Sy; else returns false.
|
||||
bool operator==(const prng_engine& y)
|
||||
{
|
||||
if (_o_counter != y._o_counter) return false;
|
||||
for (unsigned short i=0; i<4; ++i) {
|
||||
if (_s[i] != y._s[i]) return false;
|
||||
if (_k[i] != y._k[i]) return false;
|
||||
if (_o[i] != y._o[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 11
|
||||
bool operator!=(const prng_engine& y)
|
||||
{
|
||||
return !(*this == y);
|
||||
}
|
||||
|
||||
// Extra function to set the key
|
||||
void set_key(uint64_t k0=0, uint64_t k1=0, uint64_t k2=0, uint64_t k3=0)
|
||||
{
|
||||
_k[0] = k0; _k[1] = k1; _k[2] = k2; _k[3] = k3;
|
||||
encrypt_counter();
|
||||
}
|
||||
|
||||
// set the counter
|
||||
void set_counter(uint64_t s0=0, uint64_t s1=0, uint64_t s2=0, uint64_t s3=0, unsigned short o_counter=0)
|
||||
{
|
||||
_s[0] = s0;
|
||||
_s[1] = s1;
|
||||
_s[2] = s2;
|
||||
_s[3] = s3;
|
||||
_o_counter = o_counter % 8;
|
||||
encrypt_counter();
|
||||
}
|
||||
|
||||
|
||||
// versioning
|
||||
uint32_t version()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
private:
|
||||
void encrypt_counter()
|
||||
{
|
||||
uint64_t b[4];
|
||||
uint64_t k[5];
|
||||
|
||||
for (unsigned short i=0; i<4; ++i) b[i] = _s[i];
|
||||
for (unsigned short i=0; i<4; ++i) k[i] = _k[i];
|
||||
|
||||
k[4] = 0x1BD11BDAA9FC1A22 ^ k[0] ^ k[1] ^ k[2] ^ k[3];
|
||||
|
||||
MIXK(b[0], b[1], 14, b[2], b[3], 16, k[0], k[1], k[2], k[3]);
|
||||
MIX2(b[0], b[3], 52, b[2], b[1], 57);
|
||||
MIX2(b[0], b[1], 23, b[2], b[3], 40);
|
||||
MIX2(b[0], b[3], 5, b[2], b[1], 37);
|
||||
MIXK(b[0], b[1], 25, b[2], b[3], 33, k[1], k[2], k[3], k[4]+1);
|
||||
MIX2(b[0], b[3], 46, b[2], b[1], 12);
|
||||
MIX2(b[0], b[1], 58, b[2], b[3], 22);
|
||||
MIX2(b[0], b[3], 32, b[2], b[1], 32);
|
||||
|
||||
MIXK(b[0], b[1], 14, b[2], b[3], 16, k[2], k[3], k[4], k[0]+2);
|
||||
MIX2(b[0], b[3], 52, b[2], b[1], 57);
|
||||
MIX2(b[0], b[1], 23, b[2], b[3], 40);
|
||||
MIX2(b[0], b[3], 5, b[2], b[1], 37);
|
||||
MIXK(b[0], b[1], 25, b[2], b[3], 33, k[3], k[4], k[0], k[1]+3);
|
||||
|
||||
MIX2(b[0], b[3], 46, b[2], b[1], 12);
|
||||
MIX2(b[0], b[1], 58, b[2], b[3], 22);
|
||||
MIX2(b[0], b[3], 32, b[2], b[1], 32);
|
||||
|
||||
MIXK(b[0], b[1], 14, b[2], b[3], 16, k[4], k[0], k[1], k[2]+4);
|
||||
MIX2(b[0], b[3], 52, b[2], b[1], 57);
|
||||
MIX2(b[0], b[1], 23, b[2], b[3], 40);
|
||||
MIX2(b[0], b[3], 5, b[2], b[1], 37);
|
||||
|
||||
for (unsigned int i=0; i<4; ++i) _o[i] = b[i] + k[i];
|
||||
_o[3] += 5;
|
||||
}
|
||||
|
||||
void inc_counter()
|
||||
{
|
||||
++_s[0];
|
||||
if (_s[0] != 0) return;
|
||||
|
||||
++_s[1];
|
||||
if (_s[1] != 0) return;
|
||||
|
||||
++_s[2];
|
||||
if (_s[2] != 0) return;
|
||||
|
||||
++_s[3];
|
||||
}
|
||||
|
||||
void inc_counter(uint64_t z)
|
||||
{
|
||||
if (z > 0xFFFFFFFFFFFFFFFF - _s[0]) { // check if we will overflow the first 64 bit int
|
||||
++_s[1];
|
||||
if (_s[1] == 0) {
|
||||
++_s[2];
|
||||
if (_s[2] == 0) {
|
||||
++_s[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
_s[0] += z;
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t _k[4]; // key
|
||||
uint64_t _s[4]; // state (counter)
|
||||
uint64_t _o[4]; // cipher output 4 * 64 bit = 256 bit output
|
||||
unsigned short _o_counter; // output chunk counter, the 256 random bits in _o
|
||||
// are returned in eight 32 bit chunks
|
||||
};
|
||||
|
||||
|
||||
} // namespace sitmo
|
||||
|
||||
#undef MIXK
|
||||
#undef MIX2
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user