mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 07:55:35 +00:00
moved perambulator definition to shared header file
This commit is contained in:
parent
46b05aa9c5
commit
0a82fae45c
124
Hadrons/DistilVectors.hpp
Normal file
124
Hadrons/DistilVectors.hpp
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
/*************************************************************************************
|
||||||
|
|
||||||
|
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 Distil_Vectors_hpp_
|
||||||
|
#define Distil_Vectors_hpp_
|
||||||
|
|
||||||
|
#include <Hadrons/Global.hpp>
|
||||||
|
#include <Hadrons/Environment.hpp>
|
||||||
|
#include <Hadrons/Solver.hpp>
|
||||||
|
|
||||||
|
BEGIN_HADRONS_NAMESPACE
|
||||||
|
|
||||||
|
template<typename LatticeObj>
|
||||||
|
class Perambulator : Serializable{
|
||||||
|
// TODO: The next line makes friends across all combinations
|
||||||
|
// (not much of a problem given all public anyway ...)
|
||||||
|
// FYI, the bug here was that I forgot that the friend is templated
|
||||||
|
template<typename T> friend std::ostream & operator<<(std::ostream &os, const Perambulator<T>& p);
|
||||||
|
protected:
|
||||||
|
public:
|
||||||
|
GRID_SERIALIZABLE_CLASS_MEMBERS( Perambulator,
|
||||||
|
std::string, ID, // Allows owner to specialise
|
||||||
|
std::string, Provenance, // For info only
|
||||||
|
std::vector<int>, dimensions,
|
||||||
|
std::vector<LatticeObj>, perambulator,
|
||||||
|
// Following items are redundant, but useful
|
||||||
|
int, nd, // Number of dimensions
|
||||||
|
size_t, NumElements); // Number of elements
|
||||||
|
protected:
|
||||||
|
// Constructor common code
|
||||||
|
inline void ConstructCommon(const int * Dimensions) {
|
||||||
|
assert(nd > 0);
|
||||||
|
dimensions.resize(nd);
|
||||||
|
NumElements = 1;
|
||||||
|
for(int i = 0 ; i < nd ; i++) {
|
||||||
|
assert(Dimensions[i] > 0);
|
||||||
|
NumElements *= (size_t) Dimensions[i];
|
||||||
|
dimensions[i] = Dimensions[i];
|
||||||
|
}
|
||||||
|
//const LatticeObj perambulatorDefault;
|
||||||
|
perambulator.resize(NumElements);//,perambulatorDefault);
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
// Constructor with dimensions passed as std::vector<int>
|
||||||
|
inline Perambulator(const std::vector<int> & Dimensions)
|
||||||
|
: nd {(int) Dimensions.size()} {
|
||||||
|
ConstructCommon( &Dimensions[0] ); }
|
||||||
|
|
||||||
|
// Constructor with dimensions passed as std::vector<int>
|
||||||
|
inline Perambulator(const std::vector<int> & Dimensions, const std::string sID)
|
||||||
|
: nd {(int) Dimensions.size()}, ID(sID) {
|
||||||
|
ConstructCommon( &Dimensions[0] ); }
|
||||||
|
|
||||||
|
// Constructor with dimensions passed as std::vector<int>
|
||||||
|
inline Perambulator(const std::vector<int> & Dimensions, const std::string sID, const std::string sProvenance)
|
||||||
|
: nd {(int) Dimensions.size()}, ID(sID), Provenance(sProvenance) {
|
||||||
|
ConstructCommon( &Dimensions[0] ); }
|
||||||
|
|
||||||
|
// Constructor with dimensions passed as individual parameters
|
||||||
|
// FYI: The caller is free to ignore the names and use the indices however they see fit
|
||||||
|
inline Perambulator(int NumNoise, int NumEvec=1, int NumTime=1, int NumSpin=1, int I_k=1, int I_t=1, int I_s=1) {
|
||||||
|
int Dimensions[]={NumNoise,NumEvec,NumTime,NumSpin,I_k,I_t,I_s};
|
||||||
|
nd = sizeof(Dimensions)/sizeof(Dimensions[0]);
|
||||||
|
while( nd > 1 && Dimensions[nd-1] == 1 )
|
||||||
|
nd--;
|
||||||
|
ConstructCommon( Dimensions );
|
||||||
|
}
|
||||||
|
|
||||||
|
inline LatticeObj & operator()(size_t count, const int * Coord) {
|
||||||
|
assert( count == nd );
|
||||||
|
assert( Coord );
|
||||||
|
size_t idx = 0;
|
||||||
|
// C memory order (???)
|
||||||
|
for( int d = 0 ; d < nd ; d++ ) {
|
||||||
|
assert( Coord[d] < dimensions[d] );
|
||||||
|
idx *= (size_t) dimensions[d];
|
||||||
|
idx += (size_t) Coord[d];
|
||||||
|
}
|
||||||
|
return perambulator[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline LatticeObj & operator()(const std::vector<int> Coord) {
|
||||||
|
return operator()(Coord.size(), &Coord[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline LatticeObj & operator()(int idxNoise, int idxEvec=0, int idxTime=0, int idxSpin=0, int I_k=0, int I_t=0, int I_s=0) {
|
||||||
|
int MyIndex[]={idxNoise,idxEvec,idxTime,idxSpin,I_k,I_t,I_s};
|
||||||
|
int i = sizeof(MyIndex)/sizeof(MyIndex[0]);
|
||||||
|
assert( i >= nd );
|
||||||
|
while( i > nd )
|
||||||
|
assert(MyIndex[--i] == 0);
|
||||||
|
return operator()(i, MyIndex);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
END_HADRONS_NAMESPACE
|
||||||
|
|
||||||
|
#endif // Distil_Vectors_hpp_
|
@ -8,92 +8,10 @@
|
|||||||
#include <Hadrons/EigenPack.hpp>
|
#include <Hadrons/EigenPack.hpp>
|
||||||
#include <Hadrons/A2AVectors.hpp>
|
#include <Hadrons/A2AVectors.hpp>
|
||||||
#include <Hadrons/DilutedNoise.hpp>
|
#include <Hadrons/DilutedNoise.hpp>
|
||||||
|
#include <Hadrons/DistilVectors.hpp>
|
||||||
|
|
||||||
BEGIN_HADRONS_NAMESPACE
|
BEGIN_HADRONS_NAMESPACE
|
||||||
|
|
||||||
template<typename LatticeObj>
|
|
||||||
class Perambulator : Serializable{
|
|
||||||
// TODO: The next line makes friends across all combinations
|
|
||||||
// (not much of a problem given all public anyway ...)
|
|
||||||
// FYI, the bug here was that I forgot that the friend is templated
|
|
||||||
template<typename T> friend std::ostream & operator<<(std::ostream &os, const Perambulator<T>& p);
|
|
||||||
protected:
|
|
||||||
public:
|
|
||||||
GRID_SERIALIZABLE_CLASS_MEMBERS( Perambulator,
|
|
||||||
std::string, ID, // Allows owner to specialise
|
|
||||||
std::string, Provenance, // For info only
|
|
||||||
std::vector<int>, dimensions,
|
|
||||||
std::vector<LatticeObj>, perambulator,
|
|
||||||
// Following items are redundant, but useful
|
|
||||||
int, nd, // Number of dimensions
|
|
||||||
size_t, NumElements); // Number of elements
|
|
||||||
protected:
|
|
||||||
// Constructor common code
|
|
||||||
inline void ConstructCommon(const int * Dimensions) {
|
|
||||||
assert(nd > 0);
|
|
||||||
dimensions.resize(nd);
|
|
||||||
NumElements = 1;
|
|
||||||
for(int i = 0 ; i < nd ; i++) {
|
|
||||||
assert(Dimensions[i] > 0);
|
|
||||||
NumElements *= (size_t) Dimensions[i];
|
|
||||||
dimensions[i] = Dimensions[i];
|
|
||||||
}
|
|
||||||
//const LatticeObj perambulatorDefault;
|
|
||||||
perambulator.resize(NumElements);//,perambulatorDefault);
|
|
||||||
}
|
|
||||||
public:
|
|
||||||
// Constructor with dimensions passed as std::vector<int>
|
|
||||||
inline Perambulator(const std::vector<int> & Dimensions)
|
|
||||||
: nd {(int) Dimensions.size()} {
|
|
||||||
ConstructCommon( &Dimensions[0] ); }
|
|
||||||
|
|
||||||
// Constructor with dimensions passed as std::vector<int>
|
|
||||||
inline Perambulator(const std::vector<int> & Dimensions, const std::string sID)
|
|
||||||
: nd {(int) Dimensions.size()}, ID(sID) {
|
|
||||||
ConstructCommon( &Dimensions[0] ); }
|
|
||||||
|
|
||||||
// Constructor with dimensions passed as std::vector<int>
|
|
||||||
inline Perambulator(const std::vector<int> & Dimensions, const std::string sID, const std::string sProvenance)
|
|
||||||
: nd {(int) Dimensions.size()}, ID(sID), Provenance(sProvenance) {
|
|
||||||
ConstructCommon( &Dimensions[0] ); }
|
|
||||||
|
|
||||||
// Constructor with dimensions passed as individual parameters
|
|
||||||
// FYI: The caller is free to ignore the names and use the indices however they see fit
|
|
||||||
inline Perambulator(int NumNoise, int NumEvec=1, int NumTime=1, int NumSpin=1, int I_k=1, int I_t=1, int I_s=1) {
|
|
||||||
int Dimensions[]={NumNoise,NumEvec,NumTime,NumSpin,I_k,I_t,I_s};
|
|
||||||
nd = sizeof(Dimensions)/sizeof(Dimensions[0]);
|
|
||||||
while( nd > 1 && Dimensions[nd-1] == 1 )
|
|
||||||
nd--;
|
|
||||||
ConstructCommon( Dimensions );
|
|
||||||
}
|
|
||||||
|
|
||||||
inline LatticeObj & operator()(size_t count, const int * Coord) {
|
|
||||||
assert( count == nd );
|
|
||||||
assert( Coord );
|
|
||||||
size_t idx = 0;
|
|
||||||
// C memory order (???)
|
|
||||||
for( int d = 0 ; d < nd ; d++ ) {
|
|
||||||
assert( Coord[d] < dimensions[d] );
|
|
||||||
idx *= (size_t) dimensions[d];
|
|
||||||
idx += (size_t) Coord[d];
|
|
||||||
}
|
|
||||||
return perambulator[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline LatticeObj & operator()(const std::vector<int> Coord) {
|
|
||||||
return operator()(Coord.size(), &Coord[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline LatticeObj & operator()(int idxNoise, int idxEvec=0, int idxTime=0, int idxSpin=0, int I_k=0, int I_t=0, int I_s=0) {
|
|
||||||
int MyIndex[]={idxNoise,idxEvec,idxTime,idxSpin,I_k,I_t,I_s};
|
|
||||||
int i = sizeof(MyIndex)/sizeof(MyIndex[0]);
|
|
||||||
assert( i >= nd );
|
|
||||||
while( i > nd )
|
|
||||||
assert(MyIndex[--i] == 0);
|
|
||||||
return operator()(i, MyIndex);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* DistilVectors *
|
* DistilVectors *
|
||||||
|
@ -1,32 +1,40 @@
|
|||||||
#ifndef Hadrons_MDistil_perambulator_l_hpp_
|
#ifndef Hadrons_MDistil_PerambLight_hpp_
|
||||||
#define Hadrons_MDistil_perambulator_l_hpp_
|
#define Hadrons_MDistil_PerambLight_hpp_
|
||||||
|
|
||||||
#include <Hadrons/Global.hpp>
|
#include <Hadrons/Global.hpp>
|
||||||
#include <Hadrons/Module.hpp>
|
#include <Hadrons/Module.hpp>
|
||||||
#include <Hadrons/ModuleFactory.hpp>
|
#include <Hadrons/ModuleFactory.hpp>
|
||||||
|
#include <Hadrons/Solver.hpp>
|
||||||
|
#include <Hadrons/EigenPack.hpp>
|
||||||
|
#include <Hadrons/A2AVectors.hpp>
|
||||||
|
#include <Hadrons/DilutedNoise.hpp>
|
||||||
|
#include <Hadrons/DistilVectors.hpp>
|
||||||
|
|
||||||
BEGIN_HADRONS_NAMESPACE
|
BEGIN_HADRONS_NAMESPACE
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* perambulator_l *
|
* PerambLight *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
BEGIN_MODULE_NAMESPACE(MDistil)
|
BEGIN_MODULE_NAMESPACE(MDistil)
|
||||||
|
|
||||||
class perambulator_lPar: Serializable
|
class PerambLightPar: Serializable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GRID_SERIALIZABLE_CLASS_MEMBERS(perambulator_lPar,
|
GRID_SERIALIZABLE_CLASS_MEMBERS(PerambLightPar,
|
||||||
unsigned int, i);
|
std::string, noise,
|
||||||
|
std::string, eigenPack,
|
||||||
|
bool, multiFile);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename FImpl>
|
template <typename FImpl>
|
||||||
class Tperambulator_l: public Module<perambulator_lPar>
|
class TPerambLight: public Module<PerambLightPar>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// constructor
|
// constructor
|
||||||
Tperambulator_l(const std::string name);
|
TPerambLight(const std::string name);
|
||||||
// destructor
|
// destructor
|
||||||
virtual ~Tperambulator_l(void) {};
|
virtual ~TPerambLight(void) {};
|
||||||
// dependency relation
|
// dependency relation
|
||||||
virtual std::vector<std::string> getInput(void);
|
virtual std::vector<std::string> getInput(void);
|
||||||
virtual std::vector<std::string> getOutput(void);
|
virtual std::vector<std::string> getOutput(void);
|
||||||
@ -36,81 +44,55 @@ public:
|
|||||||
virtual void execute(void);
|
virtual void execute(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
MODULE_REGISTER_TMP(perambulator_l, Tperambulator_l<FIMPL>, MDistil);
|
MODULE_REGISTER_TMP(PerambLight, TPerambLight<FIMPL>, MDistil);
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Tperambulator_l implementation *
|
* TPerambLight implementation *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
// constructor /////////////////////////////////////////////////////////////////
|
// constructor /////////////////////////////////////////////////////////////////
|
||||||
template <typename FImpl>
|
template <typename FImpl>
|
||||||
Tperambulator_l<FImpl>::Tperambulator_l(const std::string name)
|
TPerambLight<FImpl>::TPerambLight(const std::string name)
|
||||||
: Module<perambulator_lPar>(name)
|
: Module<PerambLightPar>(name)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// dependencies/products ///////////////////////////////////////////////////////
|
// dependencies/products ///////////////////////////////////////////////////////
|
||||||
template <typename FImpl>
|
template <typename FImpl>
|
||||||
std::vector<std::string> Tperambulator_l<FImpl>::getInput(void)
|
std::vector<std::string> TPerambLight<FImpl>::getInput(void)
|
||||||
{
|
{
|
||||||
std::vector<std::string> in;
|
std::vector<std::string> in;
|
||||||
|
|
||||||
|
in.push_back(par().noise);
|
||||||
|
in.push_back(par().eigenPack);
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename FImpl>
|
template <typename FImpl>
|
||||||
std::vector<std::string> Tperambulator_l<FImpl>::getOutput(void)
|
std::vector<std::string> TPerambLight<FImpl>::getOutput(void)
|
||||||
{
|
{
|
||||||
std::vector<std::string> out = {getName()};
|
std::vector<std::string> out = {getName() + "_perambulator_light"};
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup ///////////////////////////////////////////////////////////////////////
|
// setup ///////////////////////////////////////////////////////////////////////
|
||||||
template <typename FImpl>
|
template <typename FImpl>
|
||||||
void Tperambulator_l<FImpl>::setup(void)
|
void TPerambLight<FImpl>::setup(void)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
std::cout << "Compute perambulator from timeslice " << tsrc << std::endl;
|
|
||||||
|
|
||||||
LatticeSpinColourVector dist_source(grid4d);
|
auto &noise = envGet(std::vector<std::vector<std::vector<SpinVector>>>, par().noise);
|
||||||
LatticeSpinColourVector tmp2(grid4d);
|
|
||||||
LatticeSpinColourVector tmp3d(grid3d);
|
int nvec = 6;
|
||||||
LatticeColourVector tmp3d_nospin(grid3d);
|
int Nt=64;
|
||||||
LatticeColourVector evec3d(grid3d);
|
|
||||||
LatticeColourVector tmp_nospin(grid4d);
|
|
||||||
|
|
||||||
LatticeColourVector result_tmp(grid3d);
|
envCreate(Perambulator<SpinVector>, getName() + "_perambulator_light", 1,
|
||||||
|
noise.size() *nvec*Nt);
|
||||||
|
|
||||||
LatticeSpinVector peramb_tmp(grid4d);
|
|
||||||
LatticeFermion result(grid4d); result=zero; //Fermion = SpinColourVector!!!
|
|
||||||
LatticeFermion result_single_component(grid4d); result_single_component=zero; //Fermion = SpinColourVector!!!
|
|
||||||
LatticeColourVector result_nospin(grid4d); result_nospin=zero; //Fermion = SpinColourVector!!!
|
|
||||||
LatticeColourVector result_3d(grid3d); result_3d=zero; //Fermion = SpinColourVector!!!
|
|
||||||
LatticeFermion result_test(grid3d); result_test=zero; //Fermion = SpinColourVector!!!
|
|
||||||
|
|
||||||
|
|
||||||
Real mass=SPar.mass; // TODO Infile
|
|
||||||
Real M5 =SPar.M5; // TODO Infile
|
|
||||||
std::cout << "init RBG " << std::endl;
|
|
||||||
GridRedBlackCartesian RBGrid(grid4d);
|
|
||||||
std::cout << "init RBG done" << std::endl;
|
|
||||||
|
|
||||||
GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(DPar.Ls,grid4d);
|
|
||||||
GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(DPar.Ls,grid4d);
|
|
||||||
|
|
||||||
typedef DomainWallFermionR FermionAction;
|
|
||||||
|
|
||||||
FermionAction Dop(Umu,*FGrid,*FrbGrid,*grid4d,RBGrid,mass,M5);
|
|
||||||
|
|
||||||
MdagMLinearOperator<FermionAction,LatticeFermion> HermOp(Dop);
|
|
||||||
ConjugateGradient<LatticeFermion> CG(SPar.CGPrecision,SPar.MaxIterations);
|
|
||||||
SchurRedBlackDiagMooeeSolve<LatticeFermion> SchurSolver(CG);
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// execution ///////////////////////////////////////////////////////////////////
|
// execution ///////////////////////////////////////////////////////////////////
|
||||||
template <typename FImpl>
|
template <typename FImpl>
|
||||||
void Tperambulator_l<FImpl>::execute(void)
|
void TPerambLight<FImpl>::execute(void)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
for (int inoise = 0; inoise < nnoise; inoise++) {
|
for (int inoise = 0; inoise < nnoise; inoise++) {
|
||||||
@ -180,4 +162,4 @@ END_MODULE_NAMESPACE
|
|||||||
|
|
||||||
END_HADRONS_NAMESPACE
|
END_HADRONS_NAMESPACE
|
||||||
|
|
||||||
#endif // Hadrons_MDistil_perambulator_l_hpp_
|
#endif // Hadrons_MDistil_PerambLight_hpp_
|
||||||
|
Loading…
Reference in New Issue
Block a user