Grid 0.7.0
NormalEquations.h
Go to the documentation of this file.
1/*************************************************************************************
2
3 Grid physics library, www.github.com/paboyle/Grid
4
5 Source file: ./lib/algorithms/iterative/NormalEquations.h
6
7 Copyright (C) 2015
8
9Author: Peter Boyle <paboyle@ph.ed.ac.uk>
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License along
22 with this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25 See the full license in the file "LICENSE" in the top level distribution directory
26*************************************************************************************/
27/* END LEGAL */
28#ifndef GRID_NORMAL_EQUATIONS_H
29#define GRID_NORMAL_EQUATIONS_H
30
32
34// Take a matrix and form an NE solver calling a Herm solver
36template<class Field> class NormalEquations : public LinearFunction<Field>{
37private:
41public:
42
44 // Wrap the usual normal equations trick
48 : _Matrix(Matrix), _HermitianSolver(HermitianSolver), _Guess(Guess) {};
49
50 void operator() (const Field &in, Field &out){
51
52 Field src(in.Grid());
53 Field tmp(in.Grid());
54
56 _Matrix.Mdag(in,src);
57 _Guess(src,out);
58 _HermitianSolver(MdagMOp,src,out); // Mdag M out = Mdag in
59
60 }
61};
62
63template<class Field> class NormalResidual : public LinearFunction<Field>{
64private:
68public:
69
71 // Wrap the usual normal equations trick
75 : _Matrix(Matrix), _HermitianSolver(HermitianSolver), _Guess(Guess) {};
76
77 void operator() (const Field &in, Field &out){
78
79 Field res(in.Grid());
80 Field tmp(in.Grid());
81
83 _Guess(in,res);
84 _HermitianSolver(MMdagOp,in,res); // M Mdag res = in ;
85 _Matrix.Mdag(res,out); // out = Mdag res
86 }
87};
88
89template<class Field> class HPDSolver : public LinearFunction<Field> {
90private:
94public:
95
97 // Wrap the usual normal equations trick
100 OperatorFunction<Field> &HermitianSolver,
101 LinearFunction<Field> &Guess)
102 : _Matrix(Matrix), _HermitianSolver(HermitianSolver), _Guess(Guess) {};
103
104 void operator() (const Field &in, Field &out){
105
106 _Guess(in,out);
107 _HermitianSolver(_Matrix,in,out); //M out = in
108
109 }
110};
111
112
113template<class Field> class MdagMSolver : public LinearFunction<Field> {
114private:
118public:
119
121 // Wrap the usual normal equations trick
124 LinearFunction<Field> &Guess)
125 : _Matrix(Matrix), _HermitianSolver(HermitianSolver), _Guess(Guess) {};
126
127 void operator() (const Field &in, Field &out){
128
130 _Guess(in,out);
131
132 _HermitianSolver(MdagMOp,in,out); // Mdag M out = Mdag in
133
134 }
135};
136
138#endif
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
HPDSolver(LinearOperatorBase< Field > &Matrix, OperatorFunction< Field > &HermitianSolver, LinearFunction< Field > &Guess)
OperatorFunction< Field > & _HermitianSolver
void operator()(const Field &in, Field &out)
LinearOperatorBase< Field > & _Matrix
LinearFunction< Field > & _Guess
OperatorFunction< Field > & _HermitianSolver
MdagMSolver(SparseMatrixBase< Field > &Matrix, OperatorFunction< Field > &HermitianSolver, LinearFunction< Field > &Guess)
SparseMatrixBase< Field > & _Matrix
LinearFunction< Field > & _Guess
void operator()(const Field &in, Field &out)
void operator()(const Field &in, Field &out)
LinearFunction< Field > & _Guess
SparseMatrixBase< Field > & _Matrix
OperatorFunction< Field > & _HermitianSolver
NormalEquations(SparseMatrixBase< Field > &Matrix, OperatorFunction< Field > &HermitianSolver, LinearFunction< Field > &Guess)
NormalResidual(SparseMatrixBase< Field > &Matrix, OperatorFunction< Field > &HermitianSolver, LinearFunction< Field > &Guess)
OperatorFunction< Field > & _HermitianSolver
void operator()(const Field &in, Field &out)
LinearFunction< Field > & _Guess
SparseMatrixBase< Field > & _Matrix