diff --git a/Grid/algorithms/deflation/Deflation.h b/Grid/algorithms/deflation/Deflation.h new file mode 100644 index 00000000..1a8f97c9 --- /dev/null +++ b/Grid/algorithms/deflation/Deflation.h @@ -0,0 +1,157 @@ + /************************************************************************************* + + Grid physics library, www.github.com/paboyle/Grid + + Source file: ./lib/algorithms/iterative/ImplicitlyRestartedLanczos.h + + Copyright (C) 2015 + +Author: Peter Boyle + + 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 GRID_DEFLATION_H +#define GRID_DEFLATION_H + +namespace Grid { + +template +class ZeroGuesser: public LinearFunction { +public: + using LinearFunction::operator(); + virtual void operator()(const Field &src, Field &guess) { guess = Zero(); }; +}; +template +class DoNothingGuesser: public LinearFunction { +public: + using LinearFunction::operator(); + virtual void operator()(const Field &src, Field &guess) { }; +}; +template +class SourceGuesser: public LinearFunction { +public: + using LinearFunction::operator(); + virtual void operator()(const Field &src, Field &guess) { guess = src; }; +}; + +//////////////////////////////// +// Fine grid deflation +//////////////////////////////// +template +class DeflatedGuesser: public LinearFunction { +private: + const std::vector &evec; + const std::vector &eval; + const unsigned int N; + +public: + using LinearFunction::operator(); + + DeflatedGuesser(const std::vector & _evec,const std::vector & _eval) + : DeflatedGuesser(_evec, _eval, _evec.size()) + {} + + DeflatedGuesser(const std::vector & _evec, const std::vector & _eval, const unsigned int _N) + : evec(_evec), eval(_eval), N(_N) + { + assert(evec.size()==eval.size()); + assert(N <= evec.size()); + } + + virtual void operator()(const Field &src,Field &guess) { + guess = Zero(); + for (int i=0;i +class LocalCoherenceDeflatedGuesser: public LinearFunction { +private: + const std::vector &subspace; + const std::vector &evec_coarse; + const std::vector &eval_coarse; +public: + + using LinearFunction::operator(); + LocalCoherenceDeflatedGuesser(const std::vector &_subspace, + const std::vector &_evec_coarse, + const std::vector &_eval_coarse) + : subspace(_subspace), + evec_coarse(_evec_coarse), + eval_coarse(_eval_coarse) + { + } + + void operator()(const FineField &src,FineField &guess) { + int N = (int)evec_coarse.size(); + CoarseField src_coarse(evec_coarse[0].Grid()); + CoarseField guess_coarse(evec_coarse[0].Grid()); guess_coarse = Zero(); + blockProject(src_coarse,src,subspace); + for (int i=0;i &src,std::vector &guess) { + int Nevec = (int)evec_coarse.size(); + int Nsrc = (int)src.size(); + // make temp variables + std::vector src_coarse(Nsrc,evec_coarse[0].Grid()); + std::vector guess_coarse(Nsrc,evec_coarse[0].Grid()); + //Preporcessing + std::cout << GridLogMessage << "Start BlockProject for loop" << std::endl; + for (int j=0;j