From 41f73ec0836fd5ec3093edba4174b466815cf799 Mon Sep 17 00:00:00 2001 From: David Murphy Date: Wed, 16 Aug 2017 12:37:38 -0400 Subject: [PATCH] Add ChronoForecast class for forecasting solutions across poles in the EOFA heatbath --- lib/algorithms/Algorithms.h | 3 +- lib/algorithms/approx/Forecast.h | 152 +++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 lib/algorithms/approx/Forecast.h diff --git a/lib/algorithms/Algorithms.h b/lib/algorithms/Algorithms.h index 5123c7a1..361ccd9c 100644 --- a/lib/algorithms/Algorithms.h +++ b/lib/algorithms/Algorithms.h @@ -1,6 +1,6 @@ /************************************************************************************* - Grid physics library, www.github.com/paboyle/Grid + Grid physics library, www.github.com/paboyle/Grid Source file: ./lib/Algorithms.h @@ -37,6 +37,7 @@ Author: Peter Boyle #include #include #include +#include #include #include diff --git a/lib/algorithms/approx/Forecast.h b/lib/algorithms/approx/Forecast.h new file mode 100644 index 00000000..87eb84a6 --- /dev/null +++ b/lib/algorithms/approx/Forecast.h @@ -0,0 +1,152 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: ./lib/algorithms/approx/Forecast.h + +Copyright (C) 2015 + +Author: Peter Boyle +Author: paboyle +Author: David Murphy + +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 INCLUDED_FORECAST_H +#define INCLUDED_FORECAST_H + +namespace Grid { + + // Abstract base class. + // Takes a matrix (Mat), a source (phi), and a vector of Fields (chi) + // and returns a forecasted solution to the system D*psi = phi (psi). + template + class Forecast + { + public: + virtual Field operator()(Matrix &Mat, const Field& phi, const std::vector& chi) = 0; + }; + + // Implementation of Brower et al.'s chronological inverter (arXiv:hep-lat/9509012), + // used to forecast solutions across poles of the EOFA heatbath. + // + // Modified from CPS (cps_pp/src/util/dirac_op/d_op_base/comsrc/minresext.C) + template + class ChronoForecast : public Forecast + { + public: + Field operator()(Matrix &Mat, const Field& phi, const std::vector& prev_solns) + { + int degree = prev_solns.size(); + Field chi(phi); // forecasted solution + + // Trivial cases + if(degree == 0){ chi = zero; return chi; } + else if(degree == 1){ return prev_solns[0]; } + + RealD dot; + ComplexD xp; + Field r(phi); // residual + Field Mv(phi); + std::vector v(prev_solns); // orthonormalized previous solutions + std::vector MdagMv(degree,phi); + + // Array to hold the matrix elements + std::vector> G(degree, std::vector(degree)); + + // Solution and source vectors + std::vector a(degree); + std::vector b(degree); + + // Orthonormalize the vector basis + for(int i=0; i std::abs(G[k][k])){ k = j; } } + if(k != i){ + xp = b[k]; + b[k] = b[i]; + b[i] = xp; + for(int j=0; j=0; i--){ + a[i] = 0.0; + for(int j=i+1; j