2018-02-26 19:24:19 +00:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
2018-09-01 21:30:30 +01:00
|
|
|
Source file: Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp
|
2018-02-26 19:24:19 +00:00
|
|
|
|
2019-02-05 18:55:24 +00:00
|
|
|
Copyright (C) 2015-2019
|
2018-02-26 19:24:19 +00:00
|
|
|
|
|
|
|
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 */
|
2018-02-26 19:22:43 +00:00
|
|
|
#ifndef Hadrons_MSolver_LocalCoherenceLanczos_hpp_
|
|
|
|
#define Hadrons_MSolver_LocalCoherenceLanczos_hpp_
|
|
|
|
|
2018-08-28 15:00:40 +01:00
|
|
|
#include <Hadrons/Global.hpp>
|
|
|
|
#include <Hadrons/Module.hpp>
|
|
|
|
#include <Hadrons/ModuleFactory.hpp>
|
|
|
|
#include <Hadrons/EigenPack.hpp>
|
2018-02-26 19:22:43 +00:00
|
|
|
|
|
|
|
BEGIN_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
/******************************************************************************
|
2018-03-02 14:29:54 +00:00
|
|
|
* Local coherence Lanczos eigensolver *
|
|
|
|
*****************************************************************************/
|
2018-02-26 19:22:43 +00:00
|
|
|
BEGIN_MODULE_NAMESPACE(MSolver)
|
|
|
|
|
|
|
|
class LocalCoherenceLanczosPar: Serializable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(LocalCoherenceLanczosPar,
|
2018-03-01 12:57:28 +00:00
|
|
|
std::string, action,
|
2018-03-13 13:51:09 +00:00
|
|
|
bool, doCoarse,
|
2018-03-01 12:57:28 +00:00
|
|
|
LanczosParams, fineParams,
|
|
|
|
LanczosParams, coarseParams,
|
|
|
|
ChebyParams, smoother,
|
|
|
|
RealD, coarseRelaxTol,
|
|
|
|
std::string, blockSize,
|
2018-05-07 17:25:36 +01:00
|
|
|
std::string, output,
|
|
|
|
bool, multiFile);
|
2018-02-26 19:22:43 +00:00
|
|
|
};
|
|
|
|
|
2018-11-05 11:41:10 +00:00
|
|
|
template <typename FImpl, int nBasis, typename FImplIo = FImpl>
|
2018-02-26 19:22:43 +00:00
|
|
|
class TLocalCoherenceLanczos: public Module<LocalCoherenceLanczosPar>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FERM_TYPE_ALIASES(FImpl,);
|
2018-03-01 12:53:16 +00:00
|
|
|
typedef LocalCoherenceLanczos<typename FImpl::SiteSpinor,
|
|
|
|
typename FImpl::SiteComplex,
|
2018-11-05 11:41:10 +00:00
|
|
|
nBasis> LCL;
|
|
|
|
typedef BaseFermionEigenPack<FImpl> BasePack;
|
|
|
|
typedef CoarseFermionEigenPack<FImpl, nBasis, FImplIo> CoarsePack;
|
2019-02-05 21:56:51 +00:00
|
|
|
typedef typename CoarsePack::Field Field;
|
|
|
|
typedef typename CoarsePack::FieldIo FieldIo;
|
|
|
|
typedef typename CoarsePack::CoarseField CoarseField;
|
|
|
|
typedef typename CoarsePack::CoarseFieldIo CoarseFieldIo;
|
2018-11-05 11:41:10 +00:00
|
|
|
typedef HADRONS_DEFAULT_SCHUR_OP<FMat, FermionField> SchurFMat;
|
2018-02-26 19:22:43 +00:00
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
TLocalCoherenceLanczos(const std::string name);
|
|
|
|
// destructor
|
2018-04-24 17:20:25 +01:00
|
|
|
virtual ~TLocalCoherenceLanczos(void) {};
|
2018-02-26 19:22:43 +00:00
|
|
|
// 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);
|
|
|
|
};
|
|
|
|
|
2018-04-23 17:35:01 +01:00
|
|
|
MODULE_REGISTER_TMP(LocalCoherenceLanczos, ARG(TLocalCoherenceLanczos<FIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>), MSolver);
|
|
|
|
MODULE_REGISTER_TMP(ZLocalCoherenceLanczos, ARG(TLocalCoherenceLanczos<ZFIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>), MSolver);
|
2018-11-05 11:41:10 +00:00
|
|
|
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
|
|
|
MODULE_REGISTER_TMP(LocalCoherenceLanczosIo32, ARG(TLocalCoherenceLanczos<FIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS, FIMPLF>), MSolver);
|
|
|
|
MODULE_REGISTER_TMP(ZLocalCoherenceLanczosIo32, ARG(TLocalCoherenceLanczos<ZFIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS, ZFIMPLF>), MSolver);
|
|
|
|
#endif
|
2018-02-26 19:22:43 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
2018-03-02 14:29:54 +00:00
|
|
|
* TLocalCoherenceLanczos implementation *
|
2018-02-26 19:22:43 +00:00
|
|
|
******************************************************************************/
|
|
|
|
// constructor /////////////////////////////////////////////////////////////////
|
2018-11-05 11:41:10 +00:00
|
|
|
template <typename FImpl, int nBasis, typename FImplIo>
|
|
|
|
TLocalCoherenceLanczos<FImpl, nBasis, FImplIo>::TLocalCoherenceLanczos(const std::string name)
|
2018-02-26 19:22:43 +00:00
|
|
|
: Module<LocalCoherenceLanczosPar>(name)
|
2018-03-13 16:10:36 +00:00
|
|
|
{}
|
2018-02-26 19:22:43 +00:00
|
|
|
|
|
|
|
// dependencies/products ///////////////////////////////////////////////////////
|
2018-11-05 11:41:10 +00:00
|
|
|
template <typename FImpl, int nBasis, typename FImplIo>
|
|
|
|
std::vector<std::string> TLocalCoherenceLanczos<FImpl, nBasis, FImplIo>::getInput(void)
|
2018-02-26 19:22:43 +00:00
|
|
|
{
|
|
|
|
std::vector<std::string> in = {par().action};
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2018-11-05 11:41:10 +00:00
|
|
|
template <typename FImpl, int nBasis, typename FImplIo>
|
|
|
|
std::vector<std::string> TLocalCoherenceLanczos<FImpl, nBasis, FImplIo>::getOutput(void)
|
2018-02-26 19:22:43 +00:00
|
|
|
{
|
2018-03-13 16:10:36 +00:00
|
|
|
std::vector<std::string> out = {getName()};
|
2018-02-26 19:22:43 +00:00
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup ///////////////////////////////////////////////////////////////////////
|
2018-11-05 11:41:10 +00:00
|
|
|
template <typename FImpl, int nBasis, typename FImplIo>
|
|
|
|
void TLocalCoherenceLanczos<FImpl, nBasis, FImplIo>::setup(void)
|
2018-02-26 19:22:43 +00:00
|
|
|
{
|
|
|
|
LOG(Message) << "Setting up local coherence Lanczos eigensolver for"
|
|
|
|
<< " action '" << par().action << "' (" << nBasis
|
|
|
|
<< " eigenvectors)..." << std::endl;
|
|
|
|
|
2018-03-13 13:51:09 +00:00
|
|
|
unsigned int Ls = env().getObjectLs(par().action);
|
|
|
|
auto blockSize = strToVec<int>(par().blockSize);
|
2019-02-05 21:56:51 +00:00
|
|
|
GridBase *gridIo = nullptr, *gridCoarseIo = nullptr;
|
|
|
|
|
|
|
|
if (typeHash<Field>() != typeHash<FieldIo>())
|
|
|
|
{
|
|
|
|
gridIo = envGetRbGrid(FieldIo, Ls);
|
|
|
|
}
|
|
|
|
if (typeHash<CoarseField>() != typeHash<CoarseFieldIo>())
|
|
|
|
{
|
|
|
|
gridCoarseIo = envGetCoarseGrid(CoarseFieldIo, blockSize, Ls);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto cg = envGetCoarseGrid(CoarseField, blockSize, Ls);
|
2018-04-03 17:42:21 +01:00
|
|
|
int cNm = (par().doCoarse) ? par().coarseParams.Nm : 0;
|
2018-03-13 13:51:09 +00:00
|
|
|
|
|
|
|
LOG(Message) << "Coarse grid: " << cg->GlobalDimensions() << std::endl;
|
|
|
|
envCreateDerived(BasePack, CoarsePack, getName(), Ls,
|
2019-02-05 21:56:51 +00:00
|
|
|
par().fineParams.Nm, cNm, envGetRbGrid(Field, Ls), cg,
|
|
|
|
gridIo, gridCoarseIo);
|
2018-03-13 13:51:09 +00:00
|
|
|
|
2018-03-13 16:10:36 +00:00
|
|
|
auto &epack = envGetDerived(BasePack, CoarsePack, getName());
|
2018-03-13 13:51:09 +00:00
|
|
|
|
|
|
|
envTmp(SchurFMat, "mat", Ls, envGet(FMat, par().action));
|
2018-02-26 19:22:43 +00:00
|
|
|
envGetTmp(SchurFMat, mat);
|
2019-02-05 21:56:51 +00:00
|
|
|
envTmp(LCL, "solver", Ls, envGetRbGrid(Field, Ls), cg, mat,
|
2018-03-13 13:51:09 +00:00
|
|
|
Odd, epack.evec, epack.evecCoarse, epack.eval, epack.evalCoarse);
|
2018-02-26 19:22:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// execution ///////////////////////////////////////////////////////////////////
|
2018-11-05 11:41:10 +00:00
|
|
|
template <typename FImpl, int nBasis, typename FImplIo>
|
|
|
|
void TLocalCoherenceLanczos<FImpl, nBasis, FImplIo>::execute(void)
|
2018-02-26 19:22:43 +00:00
|
|
|
{
|
2018-02-27 13:46:59 +00:00
|
|
|
auto &finePar = par().fineParams;
|
|
|
|
auto &coarsePar = par().coarseParams;
|
2018-03-13 16:10:36 +00:00
|
|
|
auto &epack = envGetDerived(BasePack, CoarsePack, getName());
|
2018-02-27 13:46:59 +00:00
|
|
|
|
2018-04-06 19:29:53 +01:00
|
|
|
epack.record.operatorXml = vm().getModule(par().action)->parString();
|
|
|
|
epack.record.solverXml = parString();
|
2018-02-26 19:22:43 +00:00
|
|
|
envGetTmp(LCL, solver);
|
2018-03-13 13:51:09 +00:00
|
|
|
LOG(Message) << "Performing fine grid IRL -- Nstop= "
|
|
|
|
<< finePar.Nstop << ", Nk= " << finePar.Nk << ", Nm= "
|
|
|
|
<< finePar.Nm << std::endl;
|
|
|
|
solver.calcFine(finePar.Cheby, finePar.Nstop, finePar.Nk, finePar.Nm,
|
|
|
|
finePar.resid,finePar.MaxIt, finePar.betastp,
|
|
|
|
finePar.MinRes);
|
|
|
|
solver.testFine(finePar.resid*100.0);
|
2018-04-03 17:42:21 +01:00
|
|
|
if (!par().output.empty())
|
|
|
|
{
|
2018-05-07 17:25:36 +01:00
|
|
|
epack.writeFine(par().output, par().multiFile, vm().getTrajectory());
|
2018-04-03 17:42:21 +01:00
|
|
|
}
|
2018-03-13 13:51:09 +00:00
|
|
|
if (par().doCoarse)
|
2018-02-26 19:22:43 +00:00
|
|
|
{
|
|
|
|
LOG(Message) << "Orthogonalising" << std::endl;
|
|
|
|
solver.Orthogonalise();
|
|
|
|
LOG(Message) << "Performing coarse grid IRL -- Nstop= "
|
2018-03-13 13:51:09 +00:00
|
|
|
<< coarsePar.Nstop << ", Nk= " << coarsePar.Nk << ", Nm= "
|
|
|
|
<< coarsePar.Nm << std::endl;
|
2018-02-27 13:46:59 +00:00
|
|
|
solver.calcCoarse(coarsePar.Cheby, par().smoother, par().coarseRelaxTol,
|
2018-03-13 13:51:09 +00:00
|
|
|
coarsePar.Nstop, coarsePar.Nk, coarsePar.Nm,
|
2018-02-27 13:46:59 +00:00
|
|
|
coarsePar.resid, coarsePar.MaxIt, coarsePar.betastp,
|
|
|
|
coarsePar.MinRes);
|
2018-03-02 10:18:33 +00:00
|
|
|
solver.testCoarse(coarsePar.resid*100.0, par().smoother,
|
2018-03-13 13:51:09 +00:00
|
|
|
par().coarseRelaxTol);
|
2018-04-04 16:36:37 +01:00
|
|
|
if (!par().output.empty())
|
|
|
|
{
|
2018-05-07 17:25:36 +01:00
|
|
|
epack.writeCoarse(par().output, par().multiFile, vm().getTrajectory());
|
2018-04-04 16:36:37 +01:00
|
|
|
}
|
2018-02-26 19:22:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
END_MODULE_NAMESPACE
|
|
|
|
|
|
|
|
END_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
#endif // Hadrons_MSolver_LocalCoherenceLanczos_hpp_
|