From 830168ec377e246bf5bcfe54a70d3e9dde8df5a1 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sat, 4 Aug 2018 12:32:58 +0100 Subject: [PATCH] Hadrons: first try at diluted noise class (tested) --- extras/Hadrons/DilutedNoise.hpp | 157 ++++++++++++++ extras/Hadrons/Modules.hpp | 101 ++++----- .../MNoise/TimeDilutedSpinColorDiagonal.cc | 7 + .../MNoise/TimeDilutedSpinColorDiagonal.hpp | 83 +++++++ extras/Hadrons/modules.inc | 203 +++++++++--------- 5 files changed, 400 insertions(+), 151 deletions(-) create mode 100644 extras/Hadrons/DilutedNoise.hpp create mode 100644 extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc create mode 100644 extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp diff --git a/extras/Hadrons/DilutedNoise.hpp b/extras/Hadrons/DilutedNoise.hpp new file mode 100644 index 00000000..04bb2beb --- /dev/null +++ b/extras/Hadrons/DilutedNoise.hpp @@ -0,0 +1,157 @@ +#ifndef Hadrons_DilutedNoise_hpp_ +#define Hadrons_DilutedNoise_hpp_ + +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Abstract container for diluted noise * + ******************************************************************************/ +template +class DilutedNoise +{ +public: + typedef typename FImpl::FermionField FermionField; +public: + // constructor/destructor + DilutedNoise(GridCartesian *g); + DilutedNoise(GridCartesian *g, const unsigned int nNoise); + virtual ~DilutedNoise(void) = default; + // access + const FermionField & operator[](const unsigned int i) const; + FermionField & operator[](const unsigned int i); + void resize(const unsigned int nNoise); + unsigned int size(void) const; + unsigned int getNNoise(void) const; + GridCartesian *getGrid(void) const; + // generate noise (pure virtual) + virtual void generateNoise(GridParallelRNG &rng) = 0; +private: + std::vector noise_; + GridCartesian *grid_; + unsigned int nNoise_; +}; + +template +class TimeDilutedSpinColorDiagonalNoise: public DilutedNoise +{ +public: + typedef typename FImpl::FermionField FermionField; +public: + // constructor/destructor + TimeDilutedSpinColorDiagonalNoise(GridCartesian *g); + virtual ~TimeDilutedSpinColorDiagonalNoise(void) = default; + // generate noise + virtual void generateNoise(GridParallelRNG &rng); +private: + unsigned int nt_; +}; + +/****************************************************************************** + * DilutedNoise template implementation * + ******************************************************************************/ +template +DilutedNoise::DilutedNoise(GridCartesian *g) +: grid_(g) +{} + +template +DilutedNoise::DilutedNoise(GridCartesian *g, + const unsigned int nNoise) +: DilutedNoise(g) +{ + resize(nNoise); +} + +template +void DilutedNoise::resize(const unsigned int nNoise) +{ + nNoise_ = nNoise; + noise_.resize(nNoise, grid_); +} + +template +unsigned int DilutedNoise::size(void) const +{ + return noise_.size(); +} + +template +unsigned int DilutedNoise::getNNoise(void) const +{ + return nNoise_; +} + +template +GridCartesian * DilutedNoise::getGrid(void) const +{ + return grid_; +} + +template +const typename DilutedNoise::FermionField & +DilutedNoise::operator[](const unsigned int i) const +{ + return noise_[i]; +} + +template +typename DilutedNoise::FermionField & +DilutedNoise::operator[](const unsigned int i) +{ + return noise_[i]; +} + +/****************************************************************************** + * TimeDilutedSpinColorDiagonalNoise template implementation * + ******************************************************************************/ +template +TimeDilutedSpinColorDiagonalNoise:: +TimeDilutedSpinColorDiagonalNoise(GridCartesian *g) +: DilutedNoise(g) +{ + nt_ = this->getGrid()->GlobalDimensions().back(); + this->resize(nt_*Ns*FImpl::Dimension); +} + +template +void TimeDilutedSpinColorDiagonalNoise::generateNoise(GridParallelRNG &rng) +{ + typedef decltype(peekColour((*this)[0], 0)) SpinField; + + auto &noise = *this; + auto g = this->getGrid(); + auto nd = g->GlobalDimensions().size(); + auto nc = FImpl::Dimension; + Complex shift(1., 1.); + Lattice> tLat(g); + LatticeComplex eta(g), etaCut(g); + SpinField etas(g); + unsigned int i = 0; + + LatticeCoordinate(tLat, nd - 1); + bernoulli(rng, eta); + eta = (2.*eta - shift)*(1./::sqrt(2.)); + std::cout << eta << std::endl; + for (unsigned int t = 0; t < nt_; ++t) + { + etaCut = where((tLat == t), eta, 0.*eta); + for (unsigned int s = 0; s < Ns; ++s) + { + etas = zero; + pokeSpin(etas, etaCut, s); + for (unsigned int c = 0; c < nc; ++c) + { + noise[i] = zero; + pokeColour(noise[i], etas, c); + std::cout << noise[i] << std::endl; + i++; + } + } + } +} + +END_HADRONS_NAMESPACE + +#endif // Hadrons_DilutedNoise_hpp_ \ No newline at end of file diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index 500a0e72..aa8a3aa1 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -1,59 +1,60 @@ -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include #include -#include +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc b/extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc new file mode 100644 index 00000000..e02c359a --- /dev/null +++ b/extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc @@ -0,0 +1,7 @@ +#include + +using namespace Grid; +using namespace Hadrons; +using namespace MNoise; + +template class Grid::Hadrons::MNoise::TTimeDilutedSpinColorDiagonal; diff --git a/extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp b/extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp new file mode 100644 index 00000000..aba45e08 --- /dev/null +++ b/extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp @@ -0,0 +1,83 @@ +#ifndef Hadrons_MNoise_TimeDilutedSpinColorDiagonal_hpp_ +#define Hadrons_MNoise_TimeDilutedSpinColorDiagonal_hpp_ + +#include +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Generate time diluted spin-color diagonal noise * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MNoise) + +template +class TTimeDilutedSpinColorDiagonal: public Module +{ +public: + // constructor + TTimeDilutedSpinColorDiagonal(const std::string name); + // destructor + virtual ~TTimeDilutedSpinColorDiagonal(void) {}; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +MODULE_REGISTER_TMP(TimeDilutedSpinColorDiagonal, TTimeDilutedSpinColorDiagonal, MNoise); + +/****************************************************************************** + * TTimeDilutedSpinColorDiagonal implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TTimeDilutedSpinColorDiagonal::TTimeDilutedSpinColorDiagonal(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TTimeDilutedSpinColorDiagonal::getInput(void) +{ + std::vector in; + + return in; +} + +template +std::vector TTimeDilutedSpinColorDiagonal::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TTimeDilutedSpinColorDiagonal::setup(void) +{ + envCreateDerived(DilutedNoise, + TimeDilutedSpinColorDiagonalNoise, + getName(), 1, env().getGrid()); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TTimeDilutedSpinColorDiagonal::execute(void) +{ + auto &noise = envGet(DilutedNoise, getName()); + + noise.generateNoise(*env().get4dRng()); +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_MNoise_TimeDilutedSpinColorDiagonal_hpp_ diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index 72585866..7933cb97 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -1,120 +1,121 @@ modules_cc =\ - Modules/MScalarSUN/ShiftProbe.cc \ - Modules/MScalarSUN/Grad.cc \ - Modules/MScalarSUN/TwoPointNPR.cc \ - Modules/MScalarSUN/Div.cc \ - Modules/MScalarSUN/TrMag.cc \ - Modules/MScalarSUN/TransProj.cc \ - Modules/MScalarSUN/TwoPoint.cc \ - Modules/MScalarSUN/TrKinetic.cc \ - Modules/MScalarSUN/TrPhi.cc \ - Modules/MScalarSUN/EMT.cc \ - Modules/MScalarSUN/TimeMomProbe.cc \ - Modules/MScalarSUN/StochFreeField.cc \ + Modules/MContraction/WeakHamiltonianEye.cc \ + Modules/MContraction/Baryon.cc \ + Modules/MContraction/Meson.cc \ + Modules/MContraction/WeakNeutral4ptDisc.cc \ + Modules/MContraction/WeakHamiltonianNonEye.cc \ + Modules/MContraction/WardIdentity.cc \ + Modules/MContraction/A2AMesonField.cc \ + Modules/MContraction/DiscLoop.cc \ + Modules/MContraction/Gamma3pt.cc \ + Modules/MFermion/FreeProp.cc \ + Modules/MFermion/GaugeProp.cc \ + Modules/MSource/Point.cc \ + Modules/MSource/Wall.cc \ + Modules/MSource/SeqConserved.cc \ + Modules/MSource/SeqGamma.cc \ + Modules/MSource/Z2.cc \ + Modules/MSink/Point.cc \ + Modules/MSink/Smear.cc \ + Modules/MSolver/A2AVectors.cc \ + Modules/MSolver/RBPrecCG.cc \ + Modules/MSolver/LocalCoherenceLanczos.cc \ + Modules/MGauge/StoutSmearing.cc \ + Modules/MGauge/Unit.cc \ + Modules/MGauge/UnitEm.cc \ + Modules/MGauge/StochEm.cc \ + Modules/MGauge/Random.cc \ + Modules/MGauge/FundtoHirep.cc \ + Modules/MNoise/TimeDilutedSpinColorDiagonal.cc \ + Modules/MUtilities/TestSeqGamma.cc \ + Modules/MUtilities/TestSeqConserved.cc \ + Modules/MLoop/NoiseLoop.cc \ Modules/MScalar/FreeProp.cc \ Modules/MScalar/VPCounterTerms.cc \ Modules/MScalar/ChargedProp.cc \ Modules/MScalar/ScalarVP.cc \ - Modules/MLoop/NoiseLoop.cc \ - Modules/MIO/LoadBinary.cc \ - Modules/MIO/LoadCoarseEigenPack.cc \ - Modules/MIO/LoadNersc.cc \ - Modules/MIO/LoadEigenPack.cc \ - Modules/MSink/Smear.cc \ - Modules/MSink/Point.cc \ - Modules/MFermion/FreeProp.cc \ - Modules/MFermion/GaugeProp.cc \ - Modules/MGauge/Random.cc \ - Modules/MGauge/StochEm.cc \ - Modules/MGauge/StoutSmearing.cc \ - Modules/MGauge/Unit.cc \ - Modules/MGauge/Random.cc \ - Modules/MGauge/UnitEm.cc \ - Modules/MGauge/FundtoHirep.cc \ - Modules/MUtilities/TestSeqGamma.cc \ - Modules/MUtilities/TestSeqConserved.cc \ - Modules/MSource/Z2.cc \ - Modules/MSource/Point.cc \ - Modules/MSource/SeqGamma.cc \ - Modules/MSource/Wall.cc \ - Modules/MSource/SeqConserved.cc \ - Modules/MContraction/Meson.cc \ - Modules/MContraction/WardIdentity.cc \ - Modules/MContraction/WeakHamiltonianNonEye.cc \ - Modules/MContraction/Baryon.cc \ - Modules/MContraction/DiscLoop.cc \ - Modules/MContraction/WeakHamiltonianEye.cc \ - Modules/MContraction/A2AMesonField.cc \ - Modules/MContraction/WeakNeutral4ptDisc.cc \ - Modules/MContraction/Gamma3pt.cc \ - Modules/MAction/MobiusDWF.cc \ - Modules/MAction/WilsonClover.cc \ Modules/MAction/Wilson.cc \ + Modules/MAction/MobiusDWF.cc \ + Modules/MAction/ZMobiusDWF.cc \ + Modules/MAction/WilsonClover.cc \ Modules/MAction/DWF.cc \ Modules/MAction/ScaledDWF.cc \ - Modules/MAction/ZMobiusDWF.cc \ - Modules/MSolver/A2AVectors.cc \ - Modules/MSolver/RBPrecCG.cc \ - Modules/MSolver/LocalCoherenceLanczos.cc + Modules/MScalarSUN/TrPhi.cc \ + Modules/MScalarSUN/Grad.cc \ + Modules/MScalarSUN/TimeMomProbe.cc \ + Modules/MScalarSUN/TrMag.cc \ + Modules/MScalarSUN/TrKinetic.cc \ + Modules/MScalarSUN/EMT.cc \ + Modules/MScalarSUN/ShiftProbe.cc \ + Modules/MScalarSUN/TransProj.cc \ + Modules/MScalarSUN/StochFreeField.cc \ + Modules/MScalarSUN/TwoPoint.cc \ + Modules/MScalarSUN/TwoPointNPR.cc \ + Modules/MScalarSUN/Div.cc \ + Modules/MIO/LoadEigenPack.cc \ + Modules/MIO/LoadBinary.cc \ + Modules/MIO/LoadNersc.cc \ + Modules/MIO/LoadCoarseEigenPack.cc modules_hpp =\ - Modules/MScalarSUN/TrKinetic.hpp \ - Modules/MScalarSUN/TimeMomProbe.hpp \ + Modules/MContraction/Baryon.hpp \ + Modules/MContraction/A2AMesonField.hpp \ + Modules/MContraction/Meson.hpp \ + Modules/MContraction/WeakHamiltonian.hpp \ + Modules/MContraction/WeakHamiltonianNonEye.hpp \ + Modules/MContraction/DiscLoop.hpp \ + Modules/MContraction/WeakNeutral4ptDisc.hpp \ + Modules/MContraction/Gamma3pt.hpp \ + Modules/MContraction/WardIdentity.hpp \ + Modules/MContraction/WeakHamiltonianEye.hpp \ + Modules/MFermion/FreeProp.hpp \ + Modules/MFermion/GaugeProp.hpp \ + Modules/MSource/SeqGamma.hpp \ + Modules/MSource/Point.hpp \ + Modules/MSource/Wall.hpp \ + Modules/MSource/Z2.hpp \ + Modules/MSource/SeqConserved.hpp \ + Modules/MSink/Smear.hpp \ + Modules/MSink/Point.hpp \ + Modules/MSolver/LocalCoherenceLanczos.hpp \ + Modules/MSolver/RBPrecCG.hpp \ + Modules/MSolver/A2AVectors.hpp \ + Modules/MGauge/UnitEm.hpp \ + Modules/MGauge/StoutSmearing.hpp \ + Modules/MGauge/Unit.hpp \ + Modules/MGauge/Random.hpp \ + Modules/MGauge/FundtoHirep.hpp \ + Modules/MGauge/StochEm.hpp \ + Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp \ + Modules/MUtilities/TestSeqGamma.hpp \ + Modules/MUtilities/TestSeqConserved.hpp \ + Modules/MLoop/NoiseLoop.hpp \ + Modules/MScalar/FreeProp.hpp \ + Modules/MScalar/VPCounterTerms.hpp \ + Modules/MScalar/ScalarVP.hpp \ + Modules/MScalar/Scalar.hpp \ + Modules/MScalar/ChargedProp.hpp \ + Modules/MAction/DWF.hpp \ + Modules/MAction/MobiusDWF.hpp \ + Modules/MAction/Wilson.hpp \ + Modules/MAction/WilsonClover.hpp \ + Modules/MAction/ZMobiusDWF.hpp \ + Modules/MAction/ScaledDWF.hpp \ Modules/MScalarSUN/StochFreeField.hpp \ Modules/MScalarSUN/TwoPointNPR.hpp \ - Modules/MScalarSUN/Grad.hpp \ - Modules/MScalarSUN/TransProj.hpp \ - Modules/MScalarSUN/Div.hpp \ - Modules/MScalarSUN/TrMag.hpp \ Modules/MScalarSUN/ShiftProbe.hpp \ - Modules/MScalarSUN/Utils.hpp \ + Modules/MScalarSUN/Div.hpp \ + Modules/MScalarSUN/TimeMomProbe.hpp \ + Modules/MScalarSUN/TrMag.hpp \ Modules/MScalarSUN/EMT.hpp \ Modules/MScalarSUN/TwoPoint.hpp \ Modules/MScalarSUN/TrPhi.hpp \ - Modules/MScalar/FreeProp.hpp \ - Modules/MScalar/Scalar.hpp \ - Modules/MScalar/ScalarVP.hpp \ - Modules/MScalar/ChargedProp.hpp \ - Modules/MScalar/VPCounterTerms.hpp \ - Modules/MLoop/NoiseLoop.hpp \ + Modules/MScalarSUN/Utils.hpp \ + Modules/MScalarSUN/TransProj.hpp \ + Modules/MScalarSUN/Grad.hpp \ + Modules/MScalarSUN/TrKinetic.hpp \ Modules/MIO/LoadEigenPack.hpp \ - Modules/MIO/LoadCoarseEigenPack.hpp \ - Modules/MIO/LoadBinary.hpp \ Modules/MIO/LoadNersc.hpp \ - Modules/MSink/Smear.hpp \ - Modules/MSink/Point.hpp \ - Modules/MFermion/FreeProp.hpp \ - Modules/MFermion/GaugeProp.hpp \ - Modules/MGauge/FundtoHirep.hpp \ - Modules/MGauge/Random.hpp \ - Modules/MGauge/StoutSmearing.hpp \ - Modules/MGauge/Unit.hpp \ - Modules/MGauge/StochEm.hpp \ - Modules/MGauge/UnitEm.hpp \ - Modules/MUtilities/TestSeqGamma.hpp \ - Modules/MUtilities/TestSeqConserved.hpp \ - Modules/MSource/SeqConserved.hpp \ - Modules/MSource/Z2.hpp \ - Modules/MSource/Wall.hpp \ - Modules/MSource/SeqGamma.hpp \ - Modules/MSource/Point.hpp \ - Modules/MContraction/WeakHamiltonianEye.hpp \ - Modules/MContraction/Baryon.hpp \ - Modules/MContraction/Meson.hpp \ - Modules/MContraction/WeakHamiltonian.hpp \ - Modules/MContraction/WeakNeutral4ptDisc.hpp \ - Modules/MContraction/Gamma3pt.hpp \ - Modules/MContraction/DiscLoop.hpp \ - Modules/MContraction/WeakHamiltonianNonEye.hpp \ - Modules/MContraction/WardIdentity.hpp \ - Modules/MContraction/A2AMesonField.hpp \ - Modules/MAction/WilsonClover.hpp \ - Modules/MAction/ScaledDWF.hpp \ - Modules/MAction/MobiusDWF.hpp \ - Modules/MAction/Wilson.hpp \ - Modules/MAction/DWF.hpp \ - Modules/MAction/ZMobiusDWF.hpp \ - Modules/MSolver/RBPrecCG.hpp \ - Modules/MSolver/LocalCoherenceLanczos.hpp \ - Modules/MSolver/A2AVectors.hpp + Modules/MIO/LoadCoarseEigenPack.hpp \ + Modules/MIO/LoadBinary.hpp