2018-02-26 19:24:19 +00:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
|
|
|
Source file: extras/Hadrons/Modules/MSolver/LocalCoherenceLanczos.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 */
|
2018-02-26 19:22:43 +00:00
|
|
|
#ifndef Hadrons_MSolver_LocalCoherenceLanczos_hpp_
|
|
|
|
#define Hadrons_MSolver_LocalCoherenceLanczos_hpp_
|
|
|
|
|
|
|
|
#include <Grid/Hadrons/Global.hpp>
|
|
|
|
#include <Grid/Hadrons/Module.hpp>
|
|
|
|
#include <Grid/Hadrons/ModuleFactory.hpp>
|
2018-02-27 13:46:59 +00:00
|
|
|
#include <Grid/Hadrons/LanczosUtils.hpp>
|
2018-02-26 19:22:43 +00:00
|
|
|
|
|
|
|
BEGIN_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* LocalCoherenceLanczos *
|
|
|
|
******************************************************************************/
|
|
|
|
BEGIN_MODULE_NAMESPACE(MSolver)
|
|
|
|
|
|
|
|
class LocalCoherenceLanczosPar: Serializable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(LocalCoherenceLanczosPar,
|
|
|
|
std::string, action,
|
|
|
|
int, doFine,
|
|
|
|
int, doCoarse,
|
|
|
|
LanczosParams, fineParams,
|
|
|
|
LanczosParams, coarseParams,
|
|
|
|
ChebyParams, smoother,
|
|
|
|
RealD, coarseRelaxTol,
|
2018-02-27 13:46:59 +00:00
|
|
|
std::string, blockSize,
|
|
|
|
std::string, output);
|
2018-02-26 19:22:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename FImpl, int nBasis>
|
|
|
|
class TLocalCoherenceLanczos: public Module<LocalCoherenceLanczosPar>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FERM_TYPE_ALIASES(FImpl,);
|
2018-02-27 13:46:59 +00:00
|
|
|
typedef LCL<FImpl, nBasis> LCL;
|
|
|
|
typedef FineEigenPack<FImpl> FineEigenPack;
|
|
|
|
typedef CoarseEigenPack<FImpl, nBasis> CoarseEigenPack;
|
2018-02-26 19:22:43 +00:00
|
|
|
typedef SchurDiagMooeeOperator<FMat, FermionField> SchurFMat;
|
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
TLocalCoherenceLanczos(const std::string name);
|
|
|
|
// destructor
|
|
|
|
virtual ~TLocalCoherenceLanczos(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);
|
|
|
|
private:
|
|
|
|
void makeCoarseGrid(void);
|
|
|
|
private:
|
|
|
|
std::vector<int> coarseDim_;
|
|
|
|
int Ls_, cLs_{1};
|
|
|
|
std::unique_ptr<GridCartesian> coarseGrid4_{nullptr};
|
|
|
|
std::unique_ptr<GridCartesian> coarseGrid_{nullptr};
|
|
|
|
std::unique_ptr<GridRedBlackCartesian> coarseGrid4Rb_{nullptr};
|
|
|
|
std::unique_ptr<GridRedBlackCartesian> coarseGridRb_{nullptr};
|
2018-02-27 13:46:59 +00:00
|
|
|
std::string fineName_, coarseName_;
|
2018-02-26 19:22:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_REGISTER_NS(LocalCoherenceLanczos,
|
2018-02-27 13:46:59 +00:00
|
|
|
ARG(TLocalCoherenceLanczos<FIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>),
|
|
|
|
MSolver);
|
2018-02-26 19:22:43 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* TLocalCoherenceLanczos implementation *
|
|
|
|
******************************************************************************/
|
|
|
|
// constructor /////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl, int nBasis>
|
|
|
|
TLocalCoherenceLanczos<FImpl, nBasis>::TLocalCoherenceLanczos(const std::string name)
|
|
|
|
: Module<LocalCoherenceLanczosPar>(name)
|
|
|
|
{
|
2018-02-27 13:46:59 +00:00
|
|
|
fineName_ = getName() + "_fine";
|
|
|
|
coarseName_ = getName() + "_coarse";
|
2018-02-26 19:22:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// dependencies/products ///////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl, int nBasis>
|
|
|
|
std::vector<std::string> TLocalCoherenceLanczos<FImpl, nBasis>::getInput(void)
|
|
|
|
{
|
|
|
|
std::vector<std::string> in = {par().action};
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FImpl, int nBasis>
|
|
|
|
std::vector<std::string> TLocalCoherenceLanczos<FImpl, nBasis>::getOutput(void)
|
|
|
|
{
|
2018-02-27 13:46:59 +00:00
|
|
|
std::vector<std::string> out = {fineName_, coarseName_};
|
2018-02-26 19:22:43 +00:00
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup ///////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl, int nBasis>
|
|
|
|
void TLocalCoherenceLanczos<FImpl, nBasis>::makeCoarseGrid(void)
|
|
|
|
{
|
|
|
|
int nd = env().getNd();
|
|
|
|
std::vector<int> blockSize = strToVec<int>(par().blockSize);
|
|
|
|
auto fineDim = env().getDim();
|
|
|
|
|
|
|
|
Ls_ = env().getObjectLs(par().action);
|
|
|
|
env().createGrid(Ls_);
|
|
|
|
coarseDim_.resize(nd);
|
|
|
|
for (int d = 0; d < coarseDim_.size(); d++)
|
|
|
|
{
|
|
|
|
coarseDim_[d] = fineDim[d]/blockSize[d];
|
|
|
|
if (coarseDim_[d]*blockSize[d] != fineDim[d])
|
|
|
|
{
|
|
|
|
HADRON_ERROR(Size, "Fine dimension " + std::to_string(d)
|
|
|
|
+ " (" + std::to_string(fineDim[d])
|
|
|
|
+ ") not divisible by coarse dimension ("
|
|
|
|
+ std::to_string(coarseDim_[d]) + ")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (blockSize.size() > nd)
|
|
|
|
{
|
|
|
|
cLs_ = Ls_/blockSize[nd];
|
|
|
|
if (cLs_*blockSize[nd] != Ls_)
|
|
|
|
{
|
|
|
|
HADRON_ERROR(Size, "Fine Ls (" + std::to_string(Ls_)
|
|
|
|
+ ") not divisible by coarse Ls ("
|
|
|
|
+ std::to_string(cLs_) + ")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Ls_ > 1)
|
|
|
|
{
|
|
|
|
coarseGrid4_.reset(SpaceTimeGrid::makeFourDimGrid(
|
|
|
|
coarseDim_, GridDefaultSimd(nd, vComplex::Nsimd()),
|
|
|
|
GridDefaultMpi()));
|
|
|
|
coarseGrid4Rb_.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(coarseGrid4_.get()));
|
|
|
|
coarseGrid_.reset(SpaceTimeGrid::makeFiveDimGrid(cLs_, coarseGrid4_.get()));
|
|
|
|
coarseGridRb_.reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(cLs_, coarseGrid4_.get()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
coarseGrid_.reset(SpaceTimeGrid::makeFourDimGrid(
|
|
|
|
coarseDim_, GridDefaultSimd(nd, vComplex::Nsimd()),
|
|
|
|
GridDefaultMpi()));
|
|
|
|
coarseGridRb_.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(coarseGrid_.get()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FImpl, int nBasis>
|
|
|
|
void TLocalCoherenceLanczos<FImpl, nBasis>::setup(void)
|
|
|
|
{
|
|
|
|
LOG(Message) << "Setting up local coherence Lanczos eigensolver for"
|
|
|
|
<< " action '" << par().action << "' (" << nBasis
|
|
|
|
<< " eigenvectors)..." << std::endl;
|
|
|
|
|
|
|
|
if (!coarseGrid_)
|
|
|
|
{
|
|
|
|
makeCoarseGrid();
|
|
|
|
}
|
2018-02-27 13:46:59 +00:00
|
|
|
envCreate(FineEigenPack, fineName_, Ls_, par().fineParams.Nm,
|
2018-02-26 19:22:43 +00:00
|
|
|
env().getRbGrid(Ls_));
|
2018-02-27 13:46:59 +00:00
|
|
|
envCreate(CoarseEigenPack, coarseName_, Ls_, par().coarseParams.Nm,
|
2018-02-26 19:22:43 +00:00
|
|
|
coarseGridRb_.get());
|
2018-02-27 13:46:59 +00:00
|
|
|
auto &fine = envGet(FineEigenPack, fineName_);
|
|
|
|
auto &coarse = envGet(CoarseEigenPack, coarseName_);
|
2018-02-26 19:22:43 +00:00
|
|
|
envTmp(SchurFMat, "mat", Ls_, envGet(FMat, par().action));
|
|
|
|
envGetTmp(SchurFMat, mat);
|
2018-02-27 13:46:59 +00:00
|
|
|
envTmp(LCL, "solver", Ls_, env().getRbGrid(Ls_), coarseGridRb_.get(), mat,
|
|
|
|
Odd, fine.evec, coarse.evec, fine.eval, coarse.eval);
|
2018-02-26 19:22:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// execution ///////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl, int nBasis>
|
|
|
|
void TLocalCoherenceLanczos<FImpl, nBasis>::execute(void)
|
|
|
|
{
|
2018-02-27 13:46:59 +00:00
|
|
|
auto &finePar = par().fineParams;
|
|
|
|
auto &coarsePar = par().coarseParams;
|
|
|
|
auto &fine = envGet(FineEigenPack, fineName_);
|
|
|
|
auto &coarse = envGet(CoarseEigenPack, coarseName_);
|
|
|
|
|
2018-02-26 19:22:43 +00:00
|
|
|
envGetTmp(LCL, solver);
|
|
|
|
if (par().doFine)
|
|
|
|
{
|
|
|
|
LOG(Message) << "Performing fine grid IRL -- Nstop= "
|
2018-02-27 13:46:59 +00:00
|
|
|
<< 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);
|
2018-02-26 19:22:43 +00:00
|
|
|
LOG(Message) << "Orthogonalising" << std::endl;
|
|
|
|
solver.Orthogonalise();
|
2018-02-27 13:46:59 +00:00
|
|
|
if (!par().output.empty())
|
|
|
|
{
|
|
|
|
fine.write(par().output + "_fine");
|
|
|
|
}
|
2018-02-26 19:22:43 +00:00
|
|
|
}
|
|
|
|
if (par().doCoarse)
|
|
|
|
{
|
|
|
|
LOG(Message) << "Performing coarse grid IRL -- Nstop= "
|
2018-02-27 13:46:59 +00:00
|
|
|
<< coarsePar.Nstop << ", Nk= " << coarsePar.Nk << ", Nm= "
|
|
|
|
<< coarsePar.Nm << std::endl;
|
|
|
|
solver.calcCoarse(coarsePar.Cheby, par().smoother, par().coarseRelaxTol,
|
|
|
|
coarsePar.Nstop, coarsePar.Nk, coarsePar.Nm,
|
|
|
|
coarsePar.resid, coarsePar.MaxIt, coarsePar.betastp,
|
|
|
|
coarsePar.MinRes);
|
|
|
|
if (!par().output.empty())
|
|
|
|
{
|
|
|
|
coarse.write(par().output + "_coarse");
|
|
|
|
}
|
2018-02-26 19:22:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
END_MODULE_NAMESPACE
|
|
|
|
|
|
|
|
END_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
#endif // Hadrons_MSolver_LocalCoherenceLanczos_hpp_
|