Grid 0.7.0
TwoFlavourRatio.h
Go to the documentation of this file.
1/*************************************************************************************
2
3 Grid physics library, www.github.com/paboyle/Grid
4
5 Source file: ./lib/qcd/action/pseudofermion/TwoFlavourRatio.h
6
7 Copyright (C) 2015
8
9Author: Peter Boyle <paboyle@ph.ed.ac.uk>
10Author: Peter Boyle <peterboyle@Peters-MacBook-Pro-2.local>
11Author: paboyle <paboyle@ph.ed.ac.uk>
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License along
24 with this program; if not, write to the Free Software Foundation, Inc.,
25 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26
27 See the full license in the file "LICENSE" in the top level distribution directory
28*************************************************************************************/
29/* END LEGAL */
30#ifndef QCD_PSEUDOFERMION_TWO_FLAVOUR_RATIO_H
31#define QCD_PSEUDOFERMION_TWO_FLAVOUR_RATIO_H
32
34
36// Two flavour ratio
38template<class Impl>
39class TwoFlavourRatioPseudoFermionAction : public Action<typename Impl::GaugeField> {
40public:
42
43private:
44 FermionOperator<Impl> & NumOp;// the basic operator
45 FermionOperator<Impl> & DenOp;// the basic operator
46
49
50 FermionField Phi; // the pseudo fermion field for this trajectory
51
52public:
58
59 virtual std::string action_name(){return "TwoFlavourRatioPseudoFermionAction";}
60
61 virtual std::string LogParameters(){
62 std::stringstream sstream;
63 sstream << GridLogMessage << "["<<action_name()<<"] has no parameters" << std::endl;
64 return sstream.str();
65 }
66
67 virtual void refresh(const GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG& pRNG) {
68
69 // P(phi) = e^{- phi^dag V (MdagM)^-1 Vdag phi}
70 //
71 // NumOp == V
72 // DenOp == M
73 //
74 // Take phi = Vdag^{-1} Mdag eta ; eta = Mdag^{-1} Vdag Phi
75 //
76 // P(eta) = e^{- eta^dag eta}
77 //
78 // e^{x^2/2 sig^2} => sig^2 = 0.5.
79 //
80 // So eta should be of width sig = 1/sqrt(2) and must multiply by 0.707....
81 //
82 RealD scale = std::sqrt(0.5);
83
84 FermionField eta(NumOp.FermionGrid());
85 FermionField tmp(NumOp.FermionGrid());
86
87 gaussian(pRNG,eta);
88
89 NumOp.ImportGauge(U);
90 DenOp.ImportGauge(U);
91
92 // Note: this hard codes normal equations type solvers; alternate implementation needed for
93 // non-herm style solvers.
95
96 DenOp.Mdag(eta,Phi); // Mdag eta
97 tmp = Zero();
98 ActionSolver(MdagMOp,Phi,tmp); // (VdagV)^-1 Mdag eta = V^-1 Vdag^-1 Mdag eta
99 NumOp.M(tmp,Phi); // Vdag^-1 Mdag eta
100
101 Phi=Phi*scale;
102
103 };
104
106 // S = phi^dag V (Mdag M)^-1 Vdag phi
108 virtual RealD S(const GaugeField &U) {
109
110 NumOp.ImportGauge(U);
111 DenOp.ImportGauge(U);
112
113 FermionField X(NumOp.FermionGrid());
114 FermionField Y(NumOp.FermionGrid());
115
116 MdagMLinearOperator<FermionOperator<Impl> ,FermionField> MdagMOp(DenOp);
117
118 NumOp.Mdag(Phi,Y); // Y= Vdag phi
119 X=Zero();
120 ActionSolver(MdagMOp,Y,X); // X= (MdagM)^-1 Vdag phi
121 DenOp.M(X,Y); // Y= Mdag^-1 Vdag phi
122
123 RealD action = norm2(Y);
124
125 return action;
126 };
127
129 // dS/du = phi^dag dV (Mdag M)^-1 V^dag phi
130 // - phi^dag V (Mdag M)^-1 [ Mdag dM + dMdag M ] (Mdag M)^-1 V^dag phi
131 // + phi^dag V (Mdag M)^-1 dV^dag phi
133 virtual void deriv(const GaugeField &U,GaugeField & dSdU) {
134
135 NumOp.ImportGauge(U);
136 DenOp.ImportGauge(U);
137
138 MdagMLinearOperator<FermionOperator<Impl> ,FermionField> MdagMOp(DenOp);
139
140 FermionField X(NumOp.FermionGrid());
141 FermionField Y(NumOp.FermionGrid());
142
143 GaugeField force(NumOp.GaugeGrid());
144
145
146 //Y=Vdag phi
147 //X = (Mdag M)^-1 V^dag phi
148 //Y = (Mdag)^-1 V^dag phi
149 NumOp.Mdag(Phi,Y); // Y= Vdag phi
150 X=Zero();
151 DerivativeSolver(MdagMOp,Y,X); // X= (MdagM)^-1 Vdag phi
152 DenOp.M(X,Y); // Y= Mdag^-1 Vdag phi
153
154 // phi^dag V (Mdag M)^-1 dV^dag phi
155 NumOp.MDeriv(force , X, Phi, DaggerYes ); dSdU=force;
156
157 // phi^dag dV (Mdag M)^-1 V^dag phi
158 NumOp.MDeriv(force , Phi, X ,DaggerNo ); dSdU=dSdU+force;
159
160 // - phi^dag V (Mdag M)^-1 Mdag dM (Mdag M)^-1 V^dag phi
161 // - phi^dag V (Mdag M)^-1 dMdag M (Mdag M)^-1 V^dag phi
162 DenOp.MDeriv(force,Y,X,DaggerNo); dSdU=dSdU-force;
163 DenOp.MDeriv(force,X,Y,DaggerYes); dSdU=dSdU-force;
164
165 dSdU *= -1.0;
166 //dSdU = - Ta(dSdU);
167
168 };
169};
170
172
173#endif
RealD norm2(const Lattice< vobj > &arg)
void gaussian(GridParallelRNG &rng, Lattice< vobj > &l)
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 DaggerYes
Definition QCD.h:70
static constexpr int DaggerNo
Definition QCD.h:69
double RealD
Definition Simd.h:61
static INTERNAL_PRECISION U
Definition Zolotarev.cc:230
Base class for all actions.
Definition ActionBase.h:64
FermionOperator< Impl > & DenOp
virtual std::string action_name()
Report the name of the action.
virtual void refresh(const GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG)
Refresh pseudofermion fields.
virtual RealD S(const GaugeField &U)
Evaluate this action with the given gauge field.
virtual void deriv(const GaugeField &U, GaugeField &dSdU)
FermionOperator< Impl > & NumOp
OperatorFunction< FermionField > & DerivativeSolver
TwoFlavourRatioPseudoFermionAction(FermionOperator< Impl > &_NumOp, FermionOperator< Impl > &_DenOp, OperatorFunction< FermionField > &DS, OperatorFunction< FermionField > &AS)
virtual std::string LogParameters()
Print the parameters of the action.
OperatorFunction< FermionField > & ActionSolver
Definition Simd.h:194