mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-16 23:07:05 +01:00
Hadrons: eigen packs I/O and deflation interface
This commit is contained in:
@ -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