CHROMA
inv_rel_cg1.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief Conjugate-Gradient algorithm for a generic Linear Operator
4  */
5 
6 #ifndef __inv_rel_cg1__
7 #define __inv_rel_cg1__
8 
9 #include "linearop.h"
10 
11 namespace Chroma {
12 
13 //! Conjugate-Gradient (CGNE) algorithm for a generic Linear Operator
14 /*! \ingroup invert
15  * This subroutine uses the Conjugate Gradient (CG) algorithm to find
16  * the solution of the set of linear equations
17  *
18  * Chi = A . Psi
19  *
20  * where A is hermitian
21  *
22  * Algorithm:
23 
24  * Psi[0] := initial guess; Linear interpolation (argument)
25  * r[0] := Chi - A. Psi[0] ; Initial residual
26  * p[1] := r[0] ; Initial direction
27  * c := cp := || r[0] ||^2
28  * zeta := 1/c;
29  *
30  * IF |r[0]| <= RsdCG |Chi| THEN RETURN; Converged?
31  * FOR k FROM 1 TO MaxCG DO CG iterations
32  * inner_tol := RsdCG*||chi||*||p||*sqrt(zeta)
33  *
34  * q := A(inner_tol) p
35  *
36  * a[k] := |r[k-1]|**2 / <q,p[k]> ;
37  * Psi[k] += a[k] p[k] ; New solution std::vector
38  * r[k] -= a[k] q ; New residual
39  * c := <r , r>
40  * zeta := zeta + 1/c
41  *
42  * b[k+1] := |r[k]|**2 / |r[k-1]|**2 = c/cp;
43  * p[k+1] := r[k] + b[k+1] p[k]; New direction
44  *
45  * cp := c
46  * IF ( c < RsdCG^2 || chi || ) RETURN
47  *
48  * Arguments:
49  *
50  * \param A Linear Operator (Read)
51  * \param chi Source (Read)
52  * \param psi Solution (Modify)
53  * \param RsdCG CG residual accuracy (Read)
54  * \param MaxCG Maximum CG iterations (Read)
55  * \param n_count Number of CG iteration (Write)
56  *
57  * Local Variables:
58  *
59  * p Direction std::vector
60  * r Residual std::vector
61  * cp | r[k] |**2
62  * c | r[k-1] |**2
63  * k CG iteration counter
64  * a a[k]
65  * b b[k+1]
66  * d < p[k], A.p[k] >
67  * ap Temporary for M.p
68  *
69  * Subroutines:
70  * +
71  * A Apply matrix M or M to std::vector
72  *
73  * Operations:
74  *
75  * 2 A + 2 Nc Ns + N_Count ( 2 A + 10 Nc Ns )
76  */
77 
78 template<typename T>
79 void InvRelCG1(const LinearOperator<T>& A,
80  const T& chi,
81  T& psi,
82  const Real& RsdCG,
83  int MaxCG,
84  int& n_count);
85 
86 } // end namespace Chroma
87 
88 
89 #endif
void InvRelCG1(const LinearOperator< LatticeFermion > &A, const LatticeFermion &chi, LatticeFermion &psi, const Real &RsdCG, int MaxCG, int &n_count)
Conjugate-Gradient (CGNE) algorithm for a generic Linear Operator.
Definition: inv_rel_cg1.cc:144
Linear Operators.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > const multi1d< Real > enum InvType invType const multi1d< Real > & RsdCG
Definition: pbg5p_w.cc:30
int n_count
Definition: invbicg.cc:78
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > const multi1d< Real > enum InvType invType const multi1d< Real > int MaxCG
Definition: pbg5p_w.cc:32
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
A(A, psi, r, Ncb, PLUS)
LatticeFermion T
Definition: t_clover.cc:11