Grid 0.7.0
Bounds.h
Go to the documentation of this file.
1#pragma once
2
4
5 template<class Field>
7 Field &Phi,
8 RealD hi)
9 {
10 // Eigenvalue bound check at high end
11 PowerMethod<Field> power_method;
12 auto lambda_max = power_method(HermOp,Phi);
13 std::cout << GridLogMessage << "Pseudofermion action lamda_max "<<lambda_max<<"( bound "<<hi<<")"<<std::endl;
14 assert( (lambda_max < hi) && " High Bounds Check on operator failed" );
15 }
16
17 template<class Field> void ChebyBoundsCheck(LinearOperatorBase<Field> &HermOp,
18 Field &GaussNoise,
19 RealD lo,RealD hi)
20 {
21 int orderfilter = 1000;
22 Chebyshev<Field> Cheb(lo,hi,orderfilter);
23
24 GridBase *FermionGrid = GaussNoise.Grid();
25
26 Field X(FermionGrid);
27 Field Z(FermionGrid);
28
29 X=GaussNoise;
30 RealD Nx = norm2(X);
31 Cheb(HermOp,X,Z);
32 RealD Nz = norm2(Z);
33
34 std::cout << "************************* "<<std::endl;
35 std::cout << " noise = "<<Nx<<std::endl;
36 std::cout << " Cheb x noise = "<<Nz<<std::endl;
37 std::cout << " Ratio = "<<Nz/Nx<<std::endl;
38 std::cout << "************************* "<<std::endl;
39 assert( ((Nz/Nx)<1.0) && " ChebyBoundsCheck ");
40 }
41
42 template<class Field> void InverseSqrtBoundsCheck(int MaxIter,double tol,
44 Field &GaussNoise,
45 MultiShiftFunction &PowerNegHalf)
46 {
47 GridBase *FermionGrid = GaussNoise.Grid();
48
49 Field X(FermionGrid);
50 Field Y(FermionGrid);
51 Field Z(FermionGrid);
52
53 X=GaussNoise;
54 RealD Nx = norm2(X);
55
56 ConjugateGradientMultiShift<Field> msCG(MaxIter,PowerNegHalf);
57 msCG(HermOp,X,Y);
58 msCG(HermOp,Y,Z);
59
60 RealD Nz = norm2(Z);
61
62 HermOp.HermOp(Z,Y);
63 RealD Ny = norm2(Y);
64
65 X=X-Y;
66 RealD Nd = norm2(X);
67 std::cout << "************************* "<<std::endl;
68 std::cout << " | noise |^2 = "<<Nx<<std::endl;
69 std::cout << " | (MdagM^-1/2)^2 noise |^2 = "<<Nz<<std::endl;
70 std::cout << " | MdagM (MdagM^-1/2)^2 noise |^2 = "<<Ny<<std::endl;
71 std::cout << " | noise - MdagM (MdagM^-1/2)^2 noise |^2 = "<<Nd<<std::endl;
72 std::cout << " | noise - MdagM (MdagM^-1/2)^2 noise|/|noise| = " << std::sqrt(Nd/Nx) << std::endl;
73 std::cout << "************************* "<<std::endl;
74 assert( (std::sqrt(Nd/Nx)<tol) && " InverseSqrtBoundsCheck ");
75 }
76
77 /* For a HermOp = M^dag M, check the approximation of HermOp^{-1/inv_pow}
78 by computing |X - HermOp * [ Hermop^{-1/inv_pow} ]^{inv_pow} X| < tol
79 for noise X (aka GaussNoise).
80 ApproxNegPow should be the rational approximation for X^{-1/inv_pow}
81 */
82 template<class Field> void InversePowerBoundsCheck(int inv_pow,
83 int MaxIter,double tol,
85 Field &GaussNoise,
86 MultiShiftFunction &ApproxNegPow)
87 {
88 GridBase *FermionGrid = GaussNoise.Grid();
89
90 Field X(FermionGrid);
91 Field Y(FermionGrid);
92 Field Z(FermionGrid);
93
94 Field tmp1(FermionGrid), tmp2(FermionGrid);
95
96 X=GaussNoise;
97 RealD Nx = norm2(X);
98
99 ConjugateGradientMultiShift<Field> msCG(MaxIter,ApproxNegPow);
100
101 tmp1 = X;
102
103 Field* in = &tmp1;
104 Field* out = &tmp2;
105 for(int i=0;i<inv_pow;i++){ //apply [ Hermop^{-1/inv_pow} ]^{inv_pow} X = HermOp^{-1} X
106 msCG(HermOp, *in, *out); //backwards conventions!
107 if(i!=inv_pow-1) std::swap(in, out);
108 }
109 Z = *out;
110
111 RealD Nz = norm2(Z);
112
113 HermOp.HermOp(Z,Y);
114 RealD Ny = norm2(Y);
115
116 X=X-Y;
117 RealD Nd = norm2(X);
118 std::cout << "************************* "<<std::endl;
119 std::cout << " | noise |^2 = "<<Nx<<std::endl;
120 std::cout << " | (MdagM^-1/" << inv_pow << ")^" << inv_pow << " noise |^2 = "<<Nz<<std::endl;
121 std::cout << " | MdagM (MdagM^-1/" << inv_pow << ")^" << inv_pow << " noise |^2 = "<<Ny<<std::endl;
122 std::cout << " | noise - MdagM (MdagM^-1/" << inv_pow << ")^" << inv_pow << " noise |^2 = "<<Nd<<std::endl;
123 std::cout << " | noise - MdagM (MdagM^-1/" << inv_pow << ")^" << inv_pow << " noise |/| noise | = "<<std::sqrt(Nd/Nx)<<std::endl;
124 std::cout << "************************* "<<std::endl;
125 assert( (std::sqrt(Nd/Nx)<tol) && " InversePowerBoundsCheck ");
126 }
127
129
void InverseSqrtBoundsCheck(int MaxIter, double tol, LinearOperatorBase< Field > &HermOp, Field &GaussNoise, MultiShiftFunction &PowerNegHalf)
Definition Bounds.h:42
void ChebyBoundsCheck(LinearOperatorBase< Field > &HermOp, Field &GaussNoise, RealD lo, RealD hi)
Definition Bounds.h:17
void InversePowerBoundsCheck(int inv_pow, int MaxIter, double tol, LinearOperatorBase< Field > &HermOp, Field &GaussNoise, MultiShiftFunction &ApproxNegPow)
Definition Bounds.h:82
void HighBoundCheck(LinearOperatorBase< Field > &HermOp, Field &Phi, RealD hi)
Definition Bounds.h:6
RealD norm2(const Lattice< vobj > &arg)
GridLogger GridLogMessage(1, "Message", GridLogColours, "NORMAL")
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
static constexpr int Nd
Definition QCD.h:52
double RealD
Definition Simd.h:61
virtual void HermOp(const Field &in, Field &out)=0