CHROMA
two_flavor_polynomial_monomial_w.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*! @file
4  * @brief Two flavor Monomials
5  */
6 
7 #ifndef __two_flavor_polynomial_monomial_w_h__
8 #define __two_flavor_polynomial_monomial_w_h__
9 
10 #include "wilstype_polyfermact_w.h"
14 
15 #include <typeinfo>
16 
17 namespace Chroma
18 {
19  //-------------------------------------------------------------------------------------------
20  //! Exact 2 degen flavor fermact monomial
21  /*! @ingroup monomial
22  *
23  * Exact 2 degen flavor fermact monomial. Preconditioning is not
24  * specified yet.
25  * Can supply a default dsdq and pseudoferm refresh algorithm
26  *
27  * CAVEAT: I assume there is only 1 pseudofermion field in the following
28  * so called TwoFlavorExact monomial.
29  */
30  template<typename P, typename Q, typename Phi>
32  {
33  public:
34  //! virtual destructor:
36 
37  //! Compute the total action
38  virtual Double S(const AbsFieldState<P,Q>& s) = 0;
39 
40  //! Compute dsdq for the system...
41  /*! Monomial of the form chi^dag*(M^dag*M)*chi */
42  virtual void dsdq(P& F, const AbsFieldState<P,Q>& s)
43  {
44  START_CODE();
45 
46  // Self Description/Encapsulation Rule
47  XMLWriter& xml_out = TheXMLLogWriter::Instance();
48  push(xml_out, "TwoFlavorExactPolynomialWilsonTypeFermMonomial");
49 
50  /**** Identical code for unprec and even-odd prec case *****/
51 
52  // S_f chi^dag*(M^dag*M)^(-1)*chi
53  // Here, M is some operator.
54  //
55  // Need
56  // dS_f/dU = - psi^dag * [d(M^dag)*M + M^dag*dM] * psi, psi = (M^dag*M)^(-1)*chi
57  //
58  // In Balint's notation, the result is
59  // \dot{S} = -X^dag*\dot{M}^\dag*Y - Y^dag\dot{M}*X
60  // where
61  // X = (M^dag*M)^(-1)*chi Y = M*X = (M^dag)^(-1)*chi
62  // In Robert's notation, X -> psi .
63  //
65 
66  // Create a state for linop
68 
69  // Need way to get gauge state from AbsFieldState<P,Q>
71 
72  lin->deriv(F, getPhi(), getPhi(), PLUS);
73 
74  // F now holds derivative with respect to possibly fat links
75  // now derive it with respect to the thin links if needs be
76  state->deriv(F);
77 
78  monitorForces(xml_out, "Forces", F);
79 
80  pop(xml_out);
81 
82  END_CODE();
83  }
84 
85  //! Refresh pseudofermions
86  virtual void refreshInternalFields(const AbsFieldState<P,Q>& field_state)
87  {
88  START_CODE();
89 
90  // Heatbath all the fields
91  // Self Description/Encapsulation Rule
92  XMLWriter& xml_out = TheXMLLogWriter::Instance();
93  push(xml_out, "TwoFlavorExactPolynomialWilsonTypeFermMonomial");
94 
95  // Get at the ferion action for piece i
97 
98  // Create a Connect State, apply fermionic boundaries
99  Handle< FermState<Phi,P,Q> > f_state(FA.createState(field_state.getQ()));
100 
101  // Create a linear operator
104 
105  Phi eta = zero;
106 
107  // Fill the eta field with gaussian noise
108  gaussian(eta, MdagM->subset());
109 
110  // Account for fermion BC by modifying the proposed field
111  FA.getFermBC().modifyF(eta);
112 
113  // Temporary: Move to correct normalisation
114  eta *= sqrt(0.5);
115 
116  // Now HIT IT with the ROCK!!!! (Or in this case H)
117  Phi tmp1, tmp2;
118  Poly->applyA(tmp1, eta, MINUS);
119  (*MdagM)(tmp2, tmp1, PLUS);
120 
121  // Solve [Q*P(Q^2)*Q]^{-1} tmp2 = phi
122  // Get system solver
123  Handle< PolyPrecSystemSolver<Phi> > invPolyPrec(FA.invPolyPrec(f_state, getInvParams()));
124 
125  // Do the inversion
126  SystemSolverResults_t res = (*invPolyPrec)(getPhi(), tmp2);
127 
128  write(xml_out, "n_count", res.n_count);
129  pop(xml_out);
130 
131  END_CODE();
132  }
133 
134  //! Copy pseudofermions if any
135  virtual void setInternalFields(const Monomial<P,Q>& m)
136  {
137  START_CODE();
138 
139  try {
141 
142  getPhi() = fm.getPhi();
143  }
144  catch(std::bad_cast) {
145  QDPIO::cerr << "Failed to cast input Monomial to TwoFlavorExactPolynomialWilsonTypeFermMonomial " << std::endl;
146  QDP_abort(1);
147  }
148 
149  END_CODE();
150  }
151 
152  protected:
153  //! Accessor for pseudofermion with Pf index i (read only)
154  virtual const Phi& getPhi(void) const = 0;
155 
156  //! mutator for pseudofermion with Pf index i
157  virtual Phi& getPhi(void) = 0;
158 
159  //! Get at fermion action
160  virtual const PolyWilsonTypeFermAct<Phi,P,Q>& getFermAct(void) const = 0;
161 
162  //! Get inverter params
163  virtual const GroupXML_t& getInvParams(void) const = 0;
164  };
165 
166 
167  //-------------------------------------------------------------------------------------------
168  //! Exact 2 degen flavor unpreconditioned fermact monomial
169  /*! @ingroup monomial
170  *
171  * Exact 2 degen flavor unpreconditioned fermact monomial.
172  *
173  * CAVEAT: I assume there is only 1 pseudofermion field in the following
174  * so called TwoFlavorExactPolynomial monomial.
175  */
176  template<typename P, typename Q, typename Phi>
178  {
179  public:
180  //! virtual destructor:
182 
183  //! Compute the total action
184  virtual Double S(const AbsFieldState<P,Q>& s)
185  {
186  START_CODE();
187 
188  // Self identification/encapsulation Rule
189  XMLWriter& xml_out = TheXMLLogWriter::Instance();
190  push(xml_out, "TwoFlavorExactPolynomialUnprecWilsonTypeFermMonomial");
191 
192  // Get at the fermion action
194 
195  // Create a Connect State, apply fermionic boundaries
197 
198  // Create a linear operator
200 
201  // Energy calc doesnt use Chrono Predictor
202  Phi X = zero;
203 
204  // Action on the entire lattice
205  (*Poly)(X, getPhi(), PLUS);
206 
207  Double action = innerProductReal(getPhi(), X);
208 
209  int n_count = 0;
210  write(xml_out, "n_count", n_count);
211  write(xml_out, "S", action);
212  pop(xml_out);
213 
214  END_CODE();
215 
216  return action;
217  }
218 
219 
220  protected:
221  //! Accessor for pseudofermion with Pf index i (read only)
222  virtual const Phi& getPhi(void) const = 0;
223 
224  //! mutator for pseudofermion with Pf index i
225  virtual Phi& getPhi(void) = 0;
226 
227  //! Get at fermion action
228  virtual const PolyWilsonTypeFermAct<Phi,P,Q>& getFermAct(void) const = 0;
229 
230  //! Get inverter params
231  virtual const GroupXML_t& getInvParams(void) const = 0;
232  };
233 
234 
235  //-------------------------------------------------------------------------------------------
236  //! Exact 2 degen flavor even-odd preconditioned fermact monomial
237  /*! @ingroup monomial
238  *
239  * Exact 2 degen flavor even-odd preconditioned fermact monomial.
240  * Can supply a default dsdq algorithm
241  */
242  template<typename P, typename Q, typename Phi>
244  {
245  public:
246  //! virtual destructor:
248 
249  //! Even even contribution (eg ln det Clover)
250  virtual Double S_even_even(const AbsFieldState<P,Q>& s) = 0;
251 
252  //! Compute the odd odd contribution (eg
254  {
255  START_CODE();
256 
257  XMLWriter& xml_out = TheXMLLogWriter::Instance();
258  push(xml_out, "S_odd_odd");
259 
261 
263 
264  // Create a linear operator
266 
267  // Energy calc doesnt use Chrono Predictor
268  Phi X = zero;
269 
270  // Action on the entire lattice
271  (*Poly)(X, getPhi(), PLUS);
272 
273  Double action = innerProductReal(getPhi(), X, Poly->subset());
274 
275  int n_count = 0;
276  write(xml_out, "n_count", n_count);
277  write(xml_out, "S_oo", action);
278  pop(xml_out);
279 
280  END_CODE();
281 
282  return action;
283  }
284 
285  //! Compute the total action
287  {
288  START_CODE();
289 
290  XMLWriter& xml_out=TheXMLLogWriter::Instance();
291  push(xml_out, "TwoFlavorExactPolynomialEvenOddPrecWilsonTypeFermMonomial");
292 
293  Double action = S_even_even(s) + S_odd_odd(s);
294 
295  write(xml_out, "S", action);
296  pop(xml_out);
297 
298  END_CODE();
299 
300  return action;
301  }
302 
303  protected:
304  //! Get at fermion action
305  virtual const PolyWilsonTypeFermAct<Phi,P,Q>& getFermAct() const = 0;
306 
307  //! Get inverter params
308  virtual const GroupXML_t& getInvParams(void) const = 0;
309 
310  //! Accessor for pseudofermion with Pf index i (read only)
311  virtual const Phi& getPhi(void) const = 0;
312 
313  //! mutator for pseudofermion with Pf index i
314  virtual Phi& getPhi(void) = 0;
315  };
316 
317 
318  //-------------------------------------------------------------------------------------------
319  //! Exact 2 degen flavor even-odd preconditioned fermact monomial
320  /*! @ingroup monomial
321  *
322  * Exact 2 degen flavor even-odd preconditioned fermact monomial.
323  * Constand even even determinant so can supplyt
324  */
325  template<typename P, typename Q, typename Phi>
327  {
328  public:
329  //! virtual destructor:
331 
332  //! Even even contribution (eg For this kind of Monomial it is 0)
334  return Double(0);
335  }
336 
337  // Inherit everything from Base Class
338  protected:
339  //! Get at fermion action
340  virtual const PolyWilsonTypeFermAct<Phi,P,Q>& getFermAct() const = 0;
341  };
342 
343 }
344 
345 
346 #endif
Monomials - gauge action or fermion binlinear contributions for HMC.
Chronological predictor for HMC.
Abstract field state.
Definition: field_state.h:27
virtual const Q & getQ(void) const =0
Fermionic monomials (binlinears in fermion fields)
Definition: abs_monomial.h:243
virtual const FermBC< T, P, Q > & getFermBC() const
Return the fermion BC object for this action.
Definition: fermact.h:79
virtual FermState< T, P, Q > * createState(const Q &q) const
Given links (coordinates Q) create the state needed for the linear operators.
Definition: fermact.h:59
Class for counted reference semantics.
Definition: handle.h:33
An abstract monomial class, for inexact algorithms.
Definition: abs_monomial.h:43
Polynomial Wilson-like fermion actions with derivatives.
virtual PolyLinearOperator< T, P, Q > * polyLinOp(Handle< FermState< T, P, Q > > state) const =0
Produce a polynomial linear operator for this action.
virtual PolyPrecSystemSolver< T > * invPolyPrec(Handle< FermState< T, P, Q > > state, const GroupXML_t &invParam) const =0
Return a linear operator solver for this action to solve M*psi=chi.
static T & Instance()
Definition: singleton.h:432
Exact 2 degen flavor even-odd preconditioned fermact monomial.
virtual const PolyWilsonTypeFermAct< Phi, P, Q > & getFermAct() const =0
Get at fermion action.
virtual Double S_even_even(const AbsFieldState< P, Q > &s)
Even even contribution (eg For this kind of Monomial it is 0)
Exact 2 degen flavor even-odd preconditioned fermact monomial.
virtual const Phi & getPhi(void) const =0
Accessor for pseudofermion with Pf index i (read only)
virtual Phi & getPhi(void)=0
mutator for pseudofermion with Pf index i
virtual Double S_even_even(const AbsFieldState< P, Q > &s)=0
Even even contribution (eg ln det Clover)
virtual Double S_odd_odd(const AbsFieldState< P, Q > &s)
Compute the odd odd contribution (eg.
virtual const PolyWilsonTypeFermAct< Phi, P, Q > & getFermAct() const =0
Get at fermion action.
virtual const GroupXML_t & getInvParams(void) const =0
Get inverter params.
Double S(const AbsFieldState< P, Q > &s)
Compute the total action.
virtual const Phi & getPhi(void) const =0
Accessor for pseudofermion with Pf index i (read only)
virtual void dsdq(P &F, const AbsFieldState< P, Q > &s)
Compute dsdq for the system...
virtual const PolyWilsonTypeFermAct< Phi, P, Q > & getFermAct(void) const =0
Get at fermion action.
virtual Phi & getPhi(void)=0
mutator for pseudofermion with Pf index i
virtual void refreshInternalFields(const AbsFieldState< P, Q > &field_state)
Refresh pseudofermions.
virtual const GroupXML_t & getInvParams(void) const =0
Get inverter params.
virtual void setInternalFields(const Monomial< P, Q > &m)
Copy pseudofermions if any.
virtual Double S(const AbsFieldState< P, Q > &s)=0
Compute the total action.
Exact 2 degen flavor unpreconditioned fermact monomial.
virtual const PolyWilsonTypeFermAct< Phi, P, Q > & getFermAct(void) const =0
Get at fermion action.
virtual const GroupXML_t & getInvParams(void) const =0
Get inverter params.
virtual const Phi & getPhi(void) const =0
Accessor for pseudofermion with Pf index i (read only)
virtual Phi & getPhi(void)=0
mutator for pseudofermion with Pf index i
virtual Double S(const AbsFieldState< P, Q > &s)
Compute the total action.
virtual DiffLinearOperator< T, P, Q > * lMdagM(Handle< FermState< T, P, Q > > state) const
Produce a linear operator M^dag.M for this action.
Definition: fermact.orig.h:351
Helper function for calculating forces.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
void monitorForces(XMLWriter &xml_out, const std::string &path, const multi1d< LatticeColorMatrix > &F)
Calculate and write out forces.
static int m[4]
Definition: make_seeds.cc:16
Double tmp2
Definition: mesq.cc:30
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
int n_count
Definition: invbicg.cc:78
push(xml_out,"Condensates")
@ MINUS
Definition: chromabase.h:45
@ PLUS
Definition: chromabase.h:45
pop(xml_out)
LatticeFermion eta
Definition: mespbg5p_w.cc:37
START_CODE()
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
Double zero
Definition: invbicg.cc:106
multi1d< LatticeFermion > s(Ncb)
FloatingPoint< double > Double
Definition: gtest.h:7351
Hold group xml and type id.
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Handle< LinearOperator< T > > MdagM
multi1d< LatticeColorMatrix > P
Definition: t_clover.cc:13
Class structure for polynomial fermion actions.
static INTERNAL_PRECISION F