Grid 0.7.0
TwoFlavourRatioEO4DPseudoFermion.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#pragma once
31
33
35// Two flavour ratio
37template<class Impl>
38class TwoFlavourRatioEO4DPseudoFermionAction : public Action<typename Impl::GaugeField> {
39public:
41
42private:
44 FermionOperator<Impl> & NumOp;// the basic operator
45 FermionOperator<Impl> & DenOp;// the basic operator
46
51
52 FermionField phi4; // the pseudo fermion field for this trajectory
53
54public:
74
75 virtual std::string action_name(){return "TwoFlavourRatioEO4DPseudoFermionAction";}
76
77 virtual std::string LogParameters(){
78 std::stringstream sstream;
79 sstream << GridLogMessage << "["<<action_name()<<"] has no parameters" << std::endl;
80 return sstream.str();
81 }
82
83 virtual void refresh(const GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG& pRNG) {
84
85 // P(phi) = e^{- phi^dag (V^dag M^-dag)_11 (M^-1 V)_11 phi}
86 //
87 // NumOp == V
88 // DenOp == M
89 //
90 // Take phi = (V^{-1} M)_11 eta ; eta = (M^{-1} V)_11 Phi
91 //
92 // P(eta) = e^{- eta^dag eta}
93 //
94 // e^{x^2/2 sig^2} => sig^2 = 0.5.
95 //
96 // So eta should be of width sig = 1/sqrt(2) and must multiply by 0.707....
97 //
98 RealD scale = std::sqrt(0.5);
99
100 FermionField eta4(NumOp.GaugeGrid());
101 FermionField eta5(NumOp.FermionGrid());
102 FermionField tmp(NumOp.FermionGrid());
103 FermionField phi5(NumOp.FermionGrid());
104
105 gaussian(pRNG,eta4);
106 NumOp.ImportFourDimPseudoFermion(eta4,eta5);
107 NumOp.ImportGauge(U);
108 DenOp.ImportGauge(U);
109
110 SchurRedBlackDiagMooeeSolve<FermionField> PrecSolve(HeatbathSolver);
111
112 DenOp.M(eta5,tmp); // M eta
113 PrecSolve(NumOp,tmp,phi5); // phi = V^-1 M eta
114 phi5=phi5*scale;
115 std::cout << GridLogMessage << "4d pf refresh "<< norm2(phi5)<<"\n";
116 // Project to 4d
117 NumOp.ExportFourDimPseudoFermion(phi5,phi4);
118
119 };
120
122 // S = phi^dag (V^dag M^-dag)_11 (M^-1 V)_11 phi
124 virtual RealD S(const GaugeField &U) {
125
126 NumOp.ImportGauge(U);
127 DenOp.ImportGauge(U);
128
129 FermionField Y4(NumOp.GaugeGrid());
130 FermionField X(NumOp.FermionGrid());
131 FermionField Y(NumOp.FermionGrid());
132 FermionField phi5(NumOp.FermionGrid());
133
134 MdagMLinearOperator<FermionOperator<Impl> ,FermionField> MdagMOp(DenOp);
135 SchurRedBlackDiagMooeeSolve<FermionField> PrecSolve(ActionSolver);
136
137 NumOp.ImportFourDimPseudoFermion(phi4,phi5);
138 NumOp.M(phi5,X); // X= V phi
139 PrecSolve(DenOp,X,Y); // Y= (MdagM)^-1 Mdag Vdag phi = M^-1 V phi
140 NumOp.ExportFourDimPseudoFermion(Y,Y4);
141
142 RealD action = norm2(Y4);
143
144 return action;
145 };
146
148 // dS/du = 2 Re phi^dag (V^dag M^-dag)_11 (M^-1 d V)_11 phi
149 // - 2 Re phi^dag (dV^dag M^-dag)_11 (M^-1 dM M^-1 V)_11 phi
151 virtual void deriv(const GaugeField &U,GaugeField & dSdU) {
152
153 NumOp.ImportGauge(U);
154 DenOp.ImportGauge(U);
155
156 FermionField X(NumOp.FermionGrid());
157 FermionField Y(NumOp.FermionGrid());
158 FermionField phi(NumOp.FermionGrid());
159 FermionField Vphi(NumOp.FermionGrid());
160 FermionField MinvVphi(NumOp.FermionGrid());
161 FermionField tmp4(NumOp.GaugeGrid());
162 FermionField MdagInvMinvVphi(NumOp.FermionGrid());
163
164 GaugeField force(NumOp.GaugeGrid());
165
166 //Y=V phi
167 //X = (Mdag V phi
168 //Y = (Mdag M)^-1 Mdag V phi = M^-1 V Phi
169 NumOp.ImportFourDimPseudoFermion(phi4,phi);
170 NumOp.M(phi,Vphi); // V phi
171 SchurRedBlackDiagMooeeSolve<FermionField> PrecSolve(DerivativeSolver);
172 PrecSolve(DenOp,Vphi,MinvVphi);// M^-1 V phi
173 std::cout << GridLogMessage << "4d deriv solve "<< norm2(MinvVphi)<<"\n";
174
175 // Projects onto the physical space and back
176 NumOp.ExportFourDimPseudoFermion(MinvVphi,tmp4);
177 NumOp.ImportFourDimPseudoFermion(tmp4,Y);
178
179 SchurRedBlackDiagMooeeDagSolve<FermionField> PrecDagSolve(DerivativeDagSolver);
180 // X = proj M^-dag V phi
181 // Need an adjoint solve
182 PrecDagSolve(DenOp,Y,MdagInvMinvVphi);
183 std::cout << GridLogMessage << "4d deriv solve dag "<< norm2(MdagInvMinvVphi)<<"\n";
184
185 // phi^dag (Vdag Mdag^-1) (M^-1 dV) phi
186 NumOp.MDeriv(force ,MdagInvMinvVphi , phi, DaggerNo ); dSdU=force;
187
188 // phi^dag (dVdag Mdag^-1) (M^-1 V) phi
189 NumOp.MDeriv(force , phi, MdagInvMinvVphi ,DaggerYes ); dSdU=dSdU+force;
190
191 // - 2 Re phi^dag (dV^dag M^-dag)_11 (M^-1 dM M^-1 V)_11 phi
192 DenOp.MDeriv(force,MdagInvMinvVphi,MinvVphi,DaggerNo); dSdU=dSdU-force;
193 DenOp.MDeriv(force,MinvVphi,MdagInvMinvVphi,DaggerYes); dSdU=dSdU-force;
194
195 dSdU *= -1.0;
196 //dSdU = - Ta(dSdU);
197
198 };
199};
200
202
203
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
virtual std::string action_name()
Report the name of the action.
OperatorFunction< FermionField > & DerivativeDagSolver
TwoFlavourRatioEO4DPseudoFermionAction(FermionOperator< Impl > &_NumOp, FermionOperator< Impl > &_DenOp, OperatorFunction< FermionField > &DS, OperatorFunction< FermionField > &AS)
TwoFlavourRatioEO4DPseudoFermionAction(FermionOperator< Impl > &_NumOp, FermionOperator< Impl > &_DenOp, OperatorFunction< FermionField > &DS, OperatorFunction< FermionField > &DDS, OperatorFunction< FermionField > &AS, OperatorFunction< FermionField > &HS)
virtual RealD S(const GaugeField &U)
Evaluate this action with the given gauge field.
virtual void deriv(const GaugeField &U, GaugeField &dSdU)
virtual void refresh(const GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG)
Refresh pseudofermion fields.
virtual std::string LogParameters()
Print the parameters of the action.
OperatorFunction< FermionField > & DerivativeSolver