mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-17 15:27:06 +01:00
Hadrons: eigen packs I/O and deflation interface
This commit is contained in:
@ -42,7 +42,8 @@ TFundtoHirep<Rep>::TFundtoHirep(const std::string name)
|
||||
template <class Rep>
|
||||
std::vector<std::string> TFundtoHirep<Rep>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
std::vector<std::string> in = {par().gaugeconf};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
@ -50,6 +51,7 @@ template <class Rep>
|
||||
std::vector<std::string> TFundtoHirep<Rep>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -57,19 +59,19 @@ std::vector<std::string> TFundtoHirep<Rep>::getOutput(void)
|
||||
template <typename Rep>
|
||||
void TFundtoHirep<Rep>::setup(void)
|
||||
{
|
||||
envCreateLat(typename Rep::LatticeField, getName());
|
||||
envCreateLat(Rep::LatticeField, getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <class Rep>
|
||||
void TFundtoHirep<Rep>::execute(void)
|
||||
{
|
||||
auto &U = *env().template getObject<LatticeGaugeField>(par().gaugeconf);
|
||||
LOG(Message) << "Transforming Representation" << std::endl;
|
||||
|
||||
auto &U = envGet(LatticeGaugeField, par().gaugeconf);
|
||||
auto &URep = envGet(Rep::LatticeField, getName());
|
||||
|
||||
Rep TargetRepresentation(U._grid);
|
||||
TargetRepresentation.update_representation(U);
|
||||
|
||||
auto &URep = envGet(typename Rep::LatticeField, getName());
|
||||
URep = TargetRepresentation.U;
|
||||
}
|
||||
|
126
extras/Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp
Normal file
126
extras/Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp
Normal file
@ -0,0 +1,126 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: extras/Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#ifndef Hadrons_MIO_LoadCoarseEigenPack_hpp_
|
||||
#define Hadrons_MIO_LoadCoarseEigenPack_hpp_
|
||||
|
||||
#include <Grid/Hadrons/Global.hpp>
|
||||
#include <Grid/Hadrons/Module.hpp>
|
||||
#include <Grid/Hadrons/ModuleFactory.hpp>
|
||||
#include <Grid/Hadrons/EigenPack.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Load local coherence eigen vectors/values package *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MIO)
|
||||
|
||||
class LoadCoarseEigenPackPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(LoadCoarseEigenPackPar,
|
||||
std::string, filestem,
|
||||
unsigned int, sizeFine,
|
||||
unsigned int, sizeCoarse,
|
||||
unsigned int, Ls,
|
||||
std::vector<int>, blockSize);
|
||||
};
|
||||
|
||||
template <typename Pack>
|
||||
class TLoadCoarseEigenPack: public Module<LoadCoarseEigenPackPar>
|
||||
{
|
||||
public:
|
||||
typedef CoarseEigenPack<typename Pack::Field, typename Pack::CoarseField> BasePack;
|
||||
public:
|
||||
// constructor
|
||||
TLoadCoarseEigenPack(const std::string name);
|
||||
// destructor
|
||||
virtual ~TLoadCoarseEigenPack(void) = default;
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_NS(LoadCoarseFermionEigenPack,
|
||||
ARG(TLoadCoarseEigenPack<CoarseFermionEigenPack<FIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>>), MIO);
|
||||
|
||||
/******************************************************************************
|
||||
* TLoadCoarseEigenPack implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
TLoadCoarseEigenPack<Pack>::TLoadCoarseEigenPack(const std::string name)
|
||||
: Module<LoadCoarseEigenPackPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
std::vector<std::string> TLoadCoarseEigenPack<Pack>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename Pack>
|
||||
std::vector<std::string> TLoadCoarseEigenPack<Pack>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
void TLoadCoarseEigenPack<Pack>::setup(void)
|
||||
{
|
||||
env().createGrid(par().Ls);
|
||||
env().createCoarseGrid(par().blockSize, par().Ls);
|
||||
envCreateDerived(BasePack, Pack, getName(), par().Ls, par().sizeFine,
|
||||
par().sizeCoarse, env().getRbGrid(par().Ls),
|
||||
env().getCoarseGrid(par().blockSize, par().Ls));
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
void TLoadCoarseEigenPack<Pack>::execute(void)
|
||||
{
|
||||
auto &epack = envGetDerived(BasePack, Pack, getName());
|
||||
|
||||
epack.read(par().filestem, vm().getTrajectory());
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MIO_LoadCoarseEigenPack_hpp_
|
121
extras/Hadrons/Modules/MIO/LoadEigenPack.hpp
Normal file
121
extras/Hadrons/Modules/MIO/LoadEigenPack.hpp
Normal file
@ -0,0 +1,121 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: extras/Hadrons/Modules/MIO/LoadEigenPack.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#ifndef Hadrons_MIO_LoadEigenPack_hpp_
|
||||
#define Hadrons_MIO_LoadEigenPack_hpp_
|
||||
|
||||
#include <Grid/Hadrons/Global.hpp>
|
||||
#include <Grid/Hadrons/Module.hpp>
|
||||
#include <Grid/Hadrons/ModuleFactory.hpp>
|
||||
#include <Grid/Hadrons/EigenPack.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Load eigen vectors/values package *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MIO)
|
||||
|
||||
class LoadEigenPackPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(LoadEigenPackPar,
|
||||
std::string, filestem,
|
||||
unsigned int, size,
|
||||
unsigned int, Ls);
|
||||
};
|
||||
|
||||
template <typename Pack>
|
||||
class TLoadEigenPack: public Module<LoadEigenPackPar>
|
||||
{
|
||||
public:
|
||||
typedef EigenPack<typename Pack::Field> BasePack;
|
||||
public:
|
||||
// constructor
|
||||
TLoadEigenPack(const std::string name);
|
||||
// destructor
|
||||
virtual ~TLoadEigenPack(void) = default;
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_NS(LoadFermionEigenPack, TLoadEigenPack<FermionEigenPack<FIMPL>>, MIO);
|
||||
|
||||
/******************************************************************************
|
||||
* TLoadEigenPack implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
TLoadEigenPack<Pack>::TLoadEigenPack(const std::string name)
|
||||
: Module<LoadEigenPackPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
std::vector<std::string> TLoadEigenPack<Pack>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename Pack>
|
||||
std::vector<std::string> TLoadEigenPack<Pack>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
void TLoadEigenPack<Pack>::setup(void)
|
||||
{
|
||||
env().createGrid(par().Ls);
|
||||
envCreateDerived(BasePack, Pack, getName(), par().Ls, par().size,
|
||||
env().getRbGrid(par().Ls));
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename Pack>
|
||||
void TLoadEigenPack<Pack>::execute(void)
|
||||
{
|
||||
auto &epack = envGetDerived(BasePack, Pack, getName());
|
||||
|
||||
epack.read(par().filestem, vm().getTrajectory());
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MIO_LoadEigenPack_hpp_
|
@ -32,6 +32,7 @@ See the full license in the file "LICENSE" in the top level distribution directo
|
||||
#include <Grid/Hadrons/Global.hpp>
|
||||
#include <Grid/Hadrons/Module.hpp>
|
||||
#include <Grid/Hadrons/ModuleFactory.hpp>
|
||||
#include <Grid/Hadrons/EigenPack.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
@ -44,15 +45,22 @@ class RBPrecCGPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(RBPrecCGPar ,
|
||||
std::string , action,
|
||||
unsigned int , maxIteration,
|
||||
double , residual);
|
||||
std::string , action,
|
||||
unsigned int, maxIteration,
|
||||
double , residual,
|
||||
std::string , eigenPack);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
template <typename FImpl, int nBasis>
|
||||
class TRBPrecCG: public Module<RBPrecCGPar>
|
||||
{
|
||||
public:
|
||||
typedef FermionEigenPack<FImpl> EPack;
|
||||
typedef CoarseFermionEigenPack<FImpl, nBasis> CoarseEPack;
|
||||
typedef DeflatedGuesser<typename FImpl::FermionField> FineGuesser;
|
||||
typedef LocalCoherenceDeflatedGuesser<
|
||||
typename FImpl::FermionField,
|
||||
typename CoarseEPack::CoarseField> CoarseGuesser;
|
||||
FGS_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
// constructor
|
||||
@ -70,37 +78,39 @@ protected:
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_NS(RBPrecCG, TRBPrecCG<FIMPL>, MSolver);
|
||||
MODULE_REGISTER_NS(ZRBPrecCG, TRBPrecCG<ZFIMPL>, MSolver);
|
||||
MODULE_REGISTER_NS(RBPrecCG,
|
||||
ARG(TRBPrecCG<FIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>), MSolver);
|
||||
MODULE_REGISTER_NS(ZRBPrecCG,
|
||||
ARG(TRBPrecCG<ZFIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>), MSolver);
|
||||
|
||||
/******************************************************************************
|
||||
* TRBPrecCG template implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TRBPrecCG<FImpl>::TRBPrecCG(const std::string name)
|
||||
template <typename FImpl, int nBasis>
|
||||
TRBPrecCG<FImpl, nBasis>::TRBPrecCG(const std::string name)
|
||||
: Module(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TRBPrecCG<FImpl>::getInput(void)
|
||||
template <typename FImpl, int nBasis>
|
||||
std::vector<std::string> TRBPrecCG<FImpl, nBasis>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TRBPrecCG<FImpl>::getReference(void)
|
||||
template <typename FImpl, int nBasis>
|
||||
std::vector<std::string> TRBPrecCG<FImpl, nBasis>::getReference(void)
|
||||
{
|
||||
std::vector<std::string> ref = {par().action};
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TRBPrecCG<FImpl>::getOutput(void)
|
||||
template <typename FImpl, int nBasis>
|
||||
std::vector<std::string> TRBPrecCG<FImpl, nBasis>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
@ -108,8 +118,8 @@ std::vector<std::string> TRBPrecCG<FImpl>::getOutput(void)
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TRBPrecCG<FImpl>::setup(void)
|
||||
template <typename FImpl, int nBasis>
|
||||
void TRBPrecCG<FImpl, nBasis>::setup(void)
|
||||
{
|
||||
if (par().maxIteration == 0)
|
||||
{
|
||||
@ -121,23 +131,49 @@ void TRBPrecCG<FImpl>::setup(void)
|
||||
<< par().residual << ", maximum iteration "
|
||||
<< par().maxIteration << std::endl;
|
||||
|
||||
auto Ls = env().getObjectLs(par().action);
|
||||
auto &mat = envGet(FMat, par().action);
|
||||
auto solver = [&mat, this](FermionField &sol, const FermionField &source)
|
||||
auto Ls = env().getObjectLs(par().action);
|
||||
auto &mat = envGet(FMat, par().action);
|
||||
std::string guesserName = getName() + "_guesser";
|
||||
|
||||
if (par().eigenPack.empty())
|
||||
{
|
||||
env().template createDerivedObject<Guesser<FermionField>, ZeroGuesser<FermionField>>
|
||||
(guesserName, Environment::Storage::object, Ls);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
auto &epack = envGetDerived(EPack, CoarseEPack, par().eigenPack);
|
||||
|
||||
envCreateDerived(Guesser<FermionField>, CoarseGuesser,
|
||||
guesserName, Ls, epack.evec, epack.evecCoarse,
|
||||
epack.evalCoarse);
|
||||
}
|
||||
catch (Exceptions::Definition &e)
|
||||
{
|
||||
auto &epack = envGet(EPack, par().eigenPack);
|
||||
|
||||
envCreateDerived(Guesser<FermionField>, FineGuesser,
|
||||
guesserName, Ls, epack.evec, epack.eval);
|
||||
}
|
||||
}
|
||||
auto &guesser = envGet(Guesser<FermionField>, guesserName);
|
||||
auto solver = [&mat, &guesser, this](FermionField &sol, const FermionField &source)
|
||||
{
|
||||
ConjugateGradient<FermionField> cg(par().residual,
|
||||
par().maxIteration);
|
||||
HADRONS_DEFAULT_SCHUR_SOLVE<FermionField> schurSolver(cg);
|
||||
|
||||
schurSolver(mat, source, sol);
|
||||
schurSolver(mat, source, sol, guesser);
|
||||
};
|
||||
envCreate(SolverFn, getName(), Ls, solver);
|
||||
}
|
||||
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TRBPrecCG<FImpl>::execute(void)
|
||||
template <typename FImpl, int nBasis>
|
||||
void TRBPrecCG<FImpl, nBasis>::execute(void)
|
||||
{}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
Reference in New Issue
Block a user