CHROMA
two_flavor_ratio_conv_conv_monomial5d_w.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*! @file
4  * @brief Two flavor Monomials - gauge action or fermion binlinear contributions for HMC
5  */
6 
7 #ifndef __two_flavor_ratio_conv_conv_monomial5d_w_h__
8 #define __two_flavor_ratio_conv_conv_monomial5d_w_h__
9 
15 #include <typeinfo> // For std::bad_cast
16 namespace Chroma
17 {
18  //-------------------------------------------------------------------------------------------
19  //! Exact 2 degen flavor RatioConvConv like fermact monomial in extra dimensions
20  /*! @ingroup monomial
21  *
22  * Exact 2 degen flavor RatioConvConv like fermact monomial. Preconditioning is not
23  * specified yet.
24  * Can supply a default dsdq and pseudoferm refresh algorithm
25  *
26  * Note most of the code is the same here as in the usual 2 flavour
27  * case. The only real change is that instead of the PV field, I now
28  * use the preconditioning matrix. -- This leads to evil code duplication.
29  * Think about abstracting this better.
30  * CAVEAT: I assume there is only 1 pseudofermion field in the following
31  * so called TwoFlavorExact actions.
32  */
33  template<typename P, typename Q, typename Phi>
35  {
36  public:
37  //! virtual destructor:
39 
40  //! Compute the total action
41  virtual Double S(const AbsFieldState<P,Q>& s) = 0;
42 
43  //! Compute dsdq for the system...
44  /*! Actions of the form chi^dag*(M^dag*M)*chi */
45  virtual void dsdq(P& F, const AbsFieldState<P,Q>& s)
46  {
47  START_CODE();
48 
49  // SelfIdentification/Encapsultaion Rule
50  XMLWriter& xml_out = TheXMLLogWriter::Instance();
51  push(xml_out, "TwoFlavorExactRatioConvConvWilsonTypeFermMonomial5D");
52 
53  /**** Identical code for unprec and even-odd prec case *****/
54 
55  // S_f = chi^dag*M_2*(M^dag*M)^(-1)*M_2^dag*chi
56  // Here, M is some 5D operator and M_2 is the preconditioning
57  // linop, which plays a role identical to the Pauli-Villars matrix
58  // in the normal case. The Pauli Villars matrices cancel between
59  // numerator and denominator.
60  //
61  // Need
62  // dS_f/dU = chi^dag * dM_2 * (M^dag*M)^(-1) * M_2^dag * chi
63  // - chi^dag * M_2 * (M^dag*M)^(-1) * [d(M^dag)*M + M^dag*dM] * M_2^dag * (M^dag*M)^(-1) * chi
64  // + chi^dag * M_2 * (M^dag*M)^(-1) * d(M_2^dag) * chi
65  //
66  // = chi^dag * dM_2 * psi
67  // - psi^dag * [d(M^dag)*M + M^dag*dM] * psi
68  // + psi^dag * d(M_2^dag) * chi
69  //
70  // where psi = (M^dag*M)^(-1) * M_2^dag * chi
71  //
72  // In Balint's notation, the result is
73  // \dot{S} = chi^dag*\dot(M_2)*X - X^dag*\dot{M}^\dag*Y - Y^dag\dot{M}*X + X*\dot{M_2}^dag*chi
74  // where
75  // X = (M^dag*M)^(-1)*M_2^dag*chi Y = M*X = (M^dag)^(-1)*M_2^dag*chi
76  // In Robert's notation, X -> psi .
77  //
80 
81  // Create a state for linop
83 
84  // Get linear operator
86 
87  // Get the mass-style preconditioning linear operator
89 
90  // Get/construct the pseudofermion solution
91  multi1d<Phi> X(FA.size()), Y(FA.size());
92 
93  // Move these to get X
94  int n_count = this->getX(X,s);
95 
96  (*M)(Y, X, PLUS);
97 
98  // First M_2 contribution
99  M_2->deriv(F, getPhi(), X, PLUS);
100 
101  // Last M_2 contribution
102  P F_tmp;
103  M_2->deriv(F_tmp, X, getPhi(), MINUS);
104  F += F_tmp; // NOTE SIGN
105 
106  P FM;
107  M->deriv(FM, X, Y, MINUS);
108 
109  // fold M^dag into X^dag -> Y !!
110  M->deriv(F_tmp, Y, X, PLUS);
111  FM += F_tmp; // NOTE SIGN
112 
113  // Combine forces
114  F -= FM;
115 
116  // Recurse only once
117  state->deriv(F);
118 
119  write(xml_out, "n_count", n_count);
120  monitorForces(xml_out, "Forces", F);
121 
122  pop(xml_out);
123 
124  END_CODE();
125  }
126 
127  //! Refresh pseudofermions
128  virtual void refreshInternalFields(const AbsFieldState<P,Q>& field_state)
129  {
130  START_CODE();
131 
132  // Heatbath all the fields
133 
134  // Get at the ferion action for piece i
137 
138  // Create a Connect State, apply fermionic boundaries
139  Handle< FermState<Phi,P,Q> > f_state(FA.createState(field_state.getQ()));
140 
141  // Create a linear operator
143 
144  // Get the mass-style preconditioning linear operator
145  Handle< DiffLinearOperatorArray<Phi,P,Q> > M_2(precFA.linOp(f_state));
146 
147  const int N5 = FA.size();
148  multi1d<Phi> eta(N5);
149  eta = zero;
150 
151  getPhi() = zero;
152 
153 
154  // Fill the eta field with gaussian noise
155  for(int s=0; s < N5; ++s) {
156  gaussian(eta[s], M->subset());
157  }
158 
159  // Account for fermion BC by modifying the proposed field
160  FA.getFermBC().modifyF(eta);
161 
162  // Temporary: Move to correct normalisation
163  for(int s=0; s < N5; ++s)
164  eta[s][M->subset()] *= sqrt(0.5);
165 
166  // Build phi = M_2 * (M_2^dag*M_2)^(-1) * M^dag * eta
167  multi1d<Phi> tmp(N5);
168 
169  tmp=zero;
170 
171  (*M)(tmp, eta, MINUS);
172 
173  // Solve (V^dag*V)*eta = tmp
174  // Get system solver
175  Handle< MdagMSystemSolverArray<Phi> > invMdagM(precFA.invMdagM(f_state, getNumerInvParams()));
176 
177  // Do the inversion
178  SystemSolverResults_t res = (*invMdagM)(eta, tmp);
179 
180  // Finally, get phi
181  (*M_2)(getPhi(), eta, PLUS);
182 
183  // Reset the chronological predictor
184  QDPIO::cout << "TwoFlavRatioConvConvWilson5DMonomial: resetting Predictor at end of field refresh" << std::endl;
185  getMDSolutionPredictor().reset();
186 
187  END_CODE();
188  }
189 
190  virtual void setInternalFields(const Monomial<P,Q>& m)
191  {
192  START_CODE();
193 
194  try {
196 
197  // Do a resize here -- otherwise if the fields have not yet
198  // been refreshed there may be trouble
199  getPhi().resize(fm.getPhi().size());
200 
201  for(int i=0 ; i < fm.getPhi().size(); i++) {
202  (getPhi())[i] = (fm.getPhi())[i];
203  }
204  }
205  catch(std::bad_cast) {
206  QDPIO::cerr << "Failed to cast input Monomial to TwoFlavorExactRatioConvConvWilsonTypeFermMonomial5D" << std::endl;
207  QDP_abort(1);
208  }
209 
210 
211  END_CODE();
212  }
213 
214  //! Reset predictors
215  virtual void resetPredictors() {
216  getMDSolutionPredictor().reset();
217 
218  }
219 
220  protected:
221  //! Accessor for pseudofermion with Pf index i (read only)
222  virtual const multi1d<Phi>& getPhi() const = 0;
223 
224  //! mutator for pseudofermion with Pf index i
225  virtual multi1d<Phi>& getPhi() = 0;
226 
227  //! Get at fermion action
229  {return getNumerFermAct();}
230 
231  //! Get at fermion action
232  virtual const WilsonTypeFermAct5D<Phi,P,Q>& getNumerFermAct() const = 0;
233 
234  //! Get at fermion action
235  virtual const WilsonTypeFermAct5D<Phi,P,Q>& getDenomFermAct() const = 0;
236 
237  //! Get inverter params
238  virtual const GroupXML_t getNumerInvParams() const = 0;
239 
240  //! Get the initial guess predictor
242 
243  //! Get (M^dagM)^{-1} phi
244  virtual int getX(multi1d<Phi>& X, const AbsFieldState<P,Q>& s)
245  {
246  START_CODE();
247 
248  // Grab the fermact
251 
252  // Make the state
254 
255  // Get linop
257  // Get PV
259 
260  multi1d<Phi> MPrecDagPhi(FA.size());
261 
262  (*M_prec)(MPrecDagPhi, getPhi(), MINUS);
263 
264  // Get system solver
266 
267  // CG Chrono predictor needs MdagM
269  (getMDSolutionPredictor())(X, *MdagM, MPrecDagPhi);
270 
271  // Do the inversion
272  SystemSolverResults_t res = (*invMdagM)(X, MPrecDagPhi);
273 
274  // Register the new std::vector
275  (getMDSolutionPredictor()).newVector(X);
276 
277  return res.n_count;
278 
279  END_CODE();
280  }
281 
282  };
283 
284 
285  //-------------------------------------------------------------------------------------------
286  //! Exact 2 degen flavor unpreconditioned fermact monomial living in extra dimensions
287  /*! @ingroup monomial
288  *
289  * Exact 2 degen flavor unpreconditioned fermact monomial.
290  *
291  * CAVEAT: I assume there is only 1 pseudofermion field in the following
292  * so called TwoFlavorExact actions.
293  */
294  template<typename P, typename Q, typename Phi>
296  {
297  public:
298  //! virtual destructor:
300 
301  //! Compute the total action
302  virtual Double S(const AbsFieldState<P,Q>& s)
303  {
304  START_CODE();
305 
306  // SelfEncapsulation/Identification Rule
307  XMLWriter& xml_out = TheXMLLogWriter::Instance();
308  push(xml_out, "TwoFlavorExactUnprecRatioConvConvWilsonTypeFermMonomial5D");
309 
310  // Get at the ferion action for piece i
312 
313  // Create a Connect State, apply fermionic boundaries
314  Handle< FermState<Phi,P,Q> > f_state(FA_prec.createState(s.getQ()));
315  Handle< DiffLinearOperatorArray<Phi,P,Q> > M_prec(FA_prec.linOp(f_state));
316 
317  multi1d<Phi> X(FA_prec.size());
318  multi1d<Phi> tmp(FA_prec.size());
319 
320  // Paranoia -- to deal with subsets.
321  tmp = zero;
322 
323  // Energy calc does not use chrono predictor
324  X = zero;
325 
326  // X is now (M^dagM)^{-1} V^{dag} phi
327 
328  // getX() now always uses Chrono predictor. Best to Nuke it for
329  // energy calcs
330  QDPIO::cout << "TwoFlavRatioConvConvWilson5DMonomial: resetting Predictor before energy calc solve" << std::endl;
331  getMDSolutionPredictor().reset();
332  int n_count = this->getX(X,s);
333 
334  // tmp is now V (M^dag M)^{-1} V^{dag} phi
335  (*M_prec)(tmp, X, PLUS);
336 
337  // Action on the entire lattice
338  Double action = zero;
339  for(int s=0; s < FA_prec.size(); ++s)
340  action += innerProductReal(getPhi()[s], tmp[s]);
341 
342  write(xml_out, "n_count", n_count);
343  write(xml_out, "S", action);
344  pop(xml_out);
345 
346  END_CODE();
347 
348  return action;
349  }
350 
351 
352  protected:
353  //! Accessor for pseudofermion with Pf index i (read only)
354  virtual const multi1d<Phi>& getPhi() const = 0;
355 
356  //! mutator for pseudofermion with Pf index i
357  virtual multi1d<Phi>& getPhi() = 0;
358 
359  //! Get at fermion action
361 
362  //! Get at fermion action
364 
365  //! Get inverter params
366  virtual const GroupXML_t getNumerInvParams() const = 0;
367 
368  //! Get the initial guess predictor
370  };
371 
372 
373  //-------------------------------------------------------------------------------------------
374  //! Exact 2 degen flavor even-odd preconditioned fermact monomial living in extra dimensions
375  /*! @ingroup monomial
376  *
377  * Exact 2 degen flavor even-odd preconditioned fermact monomial.
378  * Can supply a default dsdq algorithm
379  */
380  template<typename P, typename Q, typename Phi>
382  {
383  public:
384  //! virtual destructor:
386 
387  //! Even even contribution (eg ln det Clover)
388  virtual Double S_even_even(const AbsFieldState<P,Q>& s) = 0;
389 
390  //! Compute the odd odd contribution (eg
392  {
393  START_CODE();
394 
395  XMLWriter& xml_out = TheXMLLogWriter::Instance();
396  push(xml_out, "S_odd_odd");
397 
400 
401  Handle< FermState<Phi,P,Q> > bc_g_state(FA.createState(s.getQ()));
402 
403  // Need way to get gauge state from AbsFieldState<P,Q>
405 
406  Handle< EvenOddPrecLinearOperatorArray<Phi,P,Q> > M_prec(FA_prec.linOp(bc_g_state));
407  // Get the X fields
408  multi1d<Phi> X(FA.size());
409 
410  // X is now (M^dag M)^{-1} V^dag phi
411 
412  // Chrono predictor not used in energy calculation
413  X = zero;
414 
415  // Get X now always uses predictor. Best to nuke it therefore
416  QDPIO::cout << "TwoFlavRatioConvConvWilson5DMonomial: resetting Predictor before energy calc solve" << std::endl;
417  getMDSolutionPredictor().reset();
418  int n_count = this->getX(X, s);
419 
420  multi1d<Phi> tmp(FA.size());
421  (*M_prec)(tmp, X, PLUS);
422 
423  Double action = zero;
424  // Total odd-subset action. NOTE: QDP has norm2(multi1d) but not innerProd
425  for(int s=0; s < FA.size(); ++s)
426  action += innerProductReal(getPhi()[s], tmp[s], lin->subset());
427 
428 
429  write(xml_out, "n_count", n_count);
430  write(xml_out, "S_oo", action);
431  pop(xml_out);
432 
433  END_CODE();
434 
435  return action;
436  }
437 
438  //! Compute the total action
440  {
441  START_CODE();
442 
443  XMLWriter& xml_out=TheXMLLogWriter::Instance();
444  push(xml_out, "TwoFlavorExactEvenOddPrecRatioConvConvWilsonTypeFermMonomial5D");
445 
446  Double action = S_even_even(s) + S_odd_odd(s);
447 
448  write(xml_out, "S", action);
449  pop(xml_out);
450 
451  END_CODE();
452 
453  return action;
454  }
455 
456  protected:
457  //! Get at fermion action
459 
460  //! Get at fermion action
462 
463  //! Get inverter params
464  virtual const GroupXML_t getNumerInvParams() const = 0;
465 
466  //! Get the initial guess predictor
468 
469  //! Accessor for pseudofermion with Pf index i (read only)
470  virtual const multi1d<Phi>& getPhi() const = 0;
471 
472  //! mutator for pseudofermion with Pf index i
473  virtual multi1d<Phi>& getPhi() = 0;
474  };
475 
476  //-------------------------------------------------------------------------------------------
477  //! Exact 2 degen flavor even-odd preconditioned fermact monomial living in extra dimensions
478  /*! @ingroup monomial
479  *
480  * Exact 2 degen flavor even-odd preconditioned fermact monomial.
481  * Can supply a default dsdq algorithm
482  */
483  template<typename P, typename Q, typename Phi>
485  {
486  public:
487  //! virtual destructor:
489 
490  //! Even even contribution (eg ln det Clover)
492  return Double(0);
493  }
494 
495  protected:
496  //! Get at fermion action
499  };
500 
501 
502 
503 }
504 
505 
506 #endif
Monomials - gauge action or fermion binlinear contributions for HMC.
Chronological predictor for HMC.
Abstract interface for a Chronological Solution predictor in 5D.
Abstract field state.
Definition: field_state.h:27
virtual const Q & getQ(void) const =0
virtual DiffLinearOperatorArray< T, P, Q > * linOp(Handle< FermState< T, P, Q > > state) const =0
Produce a linear operator for this action.
Even-odd preconditioned Wilson-like fermion actions including derivatives.
Even-odd preconditioned Wilson-like fermion actions including derivatives.
virtual EvenOddPrecLinearOperatorArray< T, P, Q > * linOp(Handle< FermState< T, P, Q > > state) const =0
Override to produce an even-odd prec. linear operator for this action.
Fermionic monomials (binlinears in fermion fields)
Definition: abs_monomial.h:280
virtual int size() const =0
Expected length of array index.
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
static T & Instance()
Definition: singleton.h:432
Exact 2 degen flavor even-odd preconditioned fermact monomial living in extra dimensions.
virtual Double S_even_even(const AbsFieldState< P, Q > &s)
Even even contribution (eg ln det Clover)
virtual const EvenOddPrecConstDetWilsonTypeFermAct5D< Phi, P, Q > & getDenomFermAct() const =0
Get at fermion action.
virtual const EvenOddPrecConstDetWilsonTypeFermAct5D< Phi, P, Q > & getNumerFermAct() const =0
Get at fermion action.
Exact 2 degen flavor even-odd preconditioned fermact monomial living in extra dimensions.
virtual const GroupXML_t getNumerInvParams() const =0
Get inverter params.
virtual multi1d< Phi > & getPhi()=0
mutator for pseudofermion with Pf index i
virtual const multi1d< Phi > & getPhi() const =0
Accessor for pseudofermion with Pf index i (read only)
virtual const EvenOddPrecWilsonTypeFermAct5D< Phi, P, Q > & getDenomFermAct() const =0
Get at fermion action.
virtual Double S_odd_odd(const AbsFieldState< P, Q > &s)
Compute the odd odd contribution (eg.
virtual Double S_even_even(const AbsFieldState< P, Q > &s)=0
Even even contribution (eg ln det Clover)
virtual const EvenOddPrecWilsonTypeFermAct5D< Phi, P, Q > & getNumerFermAct() const =0
Get at fermion action.
virtual AbsChronologicalPredictor5D< Phi > & getMDSolutionPredictor()=0
Get the initial guess predictor.
Exact 2 degen flavor RatioConvConv like fermact monomial in extra dimensions.
virtual const WilsonTypeFermAct5D< Phi, P, Q > & getDenomFermAct() const =0
Get at fermion action.
virtual const multi1d< Phi > & getPhi() const =0
Accessor for pseudofermion with Pf index i (read only)
virtual multi1d< Phi > & getPhi()=0
mutator for pseudofermion with Pf index i
virtual const WilsonTypeFermAct5D< Phi, P, Q > & getNumerFermAct() const =0
Get at fermion action.
virtual void dsdq(P &F, const AbsFieldState< P, Q > &s)
Compute dsdq for the system...
virtual Double S(const AbsFieldState< P, Q > &s)=0
Compute the total action.
virtual const WilsonTypeFermAct5D< Phi, P, Q > & getFermAct() const
Get at fermion action.
virtual void refreshInternalFields(const AbsFieldState< P, Q > &field_state)
Refresh pseudofermions.
virtual int getX(multi1d< Phi > &X, const AbsFieldState< P, Q > &s)
Get (M^dagM)^{-1} phi.
virtual AbsChronologicalPredictor5D< Phi > & getMDSolutionPredictor()=0
Get the initial guess predictor.
virtual void setInternalFields(const Monomial< P, Q > &m)
Copy pseudofermions if any.
virtual const GroupXML_t getNumerInvParams() const =0
Get inverter params.
Exact 2 degen flavor unpreconditioned fermact monomial living in extra dimensions.
virtual const multi1d< Phi > & getPhi() const =0
Accessor for pseudofermion with Pf index i (read only)
virtual Double S(const AbsFieldState< P, Q > &s)
Compute the total action.
virtual multi1d< Phi > & getPhi()=0
mutator for pseudofermion with Pf index i
virtual AbsChronologicalPredictor5D< Phi > & getMDSolutionPredictor()=0
Get the initial guess predictor.
virtual const GroupXML_t getNumerInvParams() const =0
Get inverter params.
virtual const UnprecWilsonTypeFermAct5D< Phi, P, Q > & getDenomFermAct() const =0
Get at fermion action.
virtual const UnprecWilsonTypeFermAct5D< Phi, P, Q > & getNumerFermAct() const =0
Get at fermion action.
Unpreconditioned Wilson-like fermion actions in extra dims with derivatives.
Definition: fermact.orig.h:571
Wilson-like fermion actions.
Definition: fermact.orig.h:403
virtual MdagMSystemSolverArray< T > * invMdagM(Handle< FermState< T, P, Q > > state, const GroupXML_t &invParam) const
Return a linear operator solver for this action to solve MdagM*psi=chi.
virtual DiffLinearOperatorArray< 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:410
Even-odd const determinant Wilson-like fermact.
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
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
int n_count
Definition: invbicg.cc:78
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
@ 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
Wilson-like fermion actions.
static INTERNAL_PRECISION F