CHROMA
two_flavor_polyprec_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_polyprec_monomial_w_h__
8 #define __two_flavor_polyprec_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, "TwoFlavorExactPolyPrecWilsonTypeFermMonomial");
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  Phi X;
73 
74  // Get X out here
75  int n_count = this->getX(X,s);
76 
77  lin->deriv(F, X, X, PLUS);
78 
79  for(int mu=0; mu < F.size(); ++mu)
80  F[mu] *= Real(-1);
81 
82  // F now holds derivative with respect to possibly fat links
83  // now derive it with respect to the thin links if needs be
84  state->deriv(F);
85 
86  write(xml_out, "n_count", n_count);
87  monitorForces(xml_out, "Forces", F);
88 
89  pop(xml_out);
90 
91  END_CODE();
92  }
93 
94  //! Refresh pseudofermions
95  virtual void refreshInternalFields(const AbsFieldState<P,Q>& field_state)
96  {
97  START_CODE();
98 
99  // Heatbath all the fields
100 
101  // Get at the ferion action for piece i
103 
104  // Create a Connect State, apply fermionic boundaries
105  Handle< FermState<Phi,P,Q> > f_state(FA.createState(field_state.getQ()));
106 
107  // Create a linear operator
110 
111  Phi eta=zero;
112 
113  // Fill the eta field with gaussian noise
114  gaussian(eta, H->subset());
115 
116  // Account for fermion BC by modifying the proposed field
117  FA.getFermBC().modifyF(eta);
118 
119  // Temporary: Move to correct normalisation
120  eta *= sqrt(0.5);
121 
122  // Now HIT IT with the ROCK!!!! (Or in this case H)
123  Phi tmp;
124  (*H)(tmp, eta, PLUS);
125  Poly->applyA(getPhi(), tmp, PLUS);
126  QDPIO::cout << "TwoFlavPolyWilson4DMonomial: resetting Predictor after field refresh" << std::endl;
127  getMDSolutionPredictor().reset();
128 
129  END_CODE();
130  }
131 
132  //! Copy pseudofermions if any
133  virtual void setInternalFields(const Monomial<P,Q>& m)
134  {
135  START_CODE();
136 
137  try {
139 
140  getPhi() = fm.getPhi();
141  }
142  catch(std::bad_cast) {
143  QDPIO::cerr << "Failed to cast input Monomial to TwoFlavorExactPolyPrecWilsonTypeFermMonomial " << std::endl;
144  QDP_abort(1);
145  }
146 
147  END_CODE();
148  }
149 
150  //! Reset predictors
151  virtual void resetPredictors(void) {
152  getMDSolutionPredictor().reset();
153 
154  }
155 
156  protected:
157  //! Accessor for pseudofermion with Pf index i (read only)
158  virtual const Phi& getPhi(void) const = 0;
159 
160  //! mutator for pseudofermion with Pf index i
161  virtual Phi& getPhi(void) = 0;
162 
163  //! Get at fermion action
164  virtual const PolyWilsonTypeFermAct<Phi,P,Q>& getFermAct(void) const = 0;
165 
166  //! Get inverter params
167  virtual const GroupXML_t& getInvParams(void) const = 0;
168 
169  //! Get the initial guess predictor
171 
172  //! Get (Q*P(Q^2)*Q)^{-1} phi
173  virtual int getX(Phi& X, const AbsFieldState<P,Q>& s)
174  {
175  START_CODE();
176 
177  // Grab the fermact
179 
180  // Make the state
182 
183  // Guess is passed in
184 
185  // Get linop
187 
188  // Solve [Q*P(Q^2)*Q]^{-1} X = phi
189  // Get system solver
191 
192  // Do the inversion...
193  (getMDSolutionPredictor())(X, *M, getPhi());
194  SystemSolverResults_t res = (*invPolyPrec)(X, getPhi());
195  (getMDSolutionPredictor()).newVector(X);
196 
197  END_CODE();
198 
199  return res.n_count;
200  }
201 
202  };
203 
204 
205  //-------------------------------------------------------------------------------------------
206  //! Exact 2 degen flavor unpreconditioned fermact monomial
207  /*! @ingroup monomial
208  *
209  * Exact 2 degen flavor unpreconditioned fermact monomial.
210  *
211  * CAVEAT: I assume there is only 1 pseudofermion field in the following
212  * so called TwoFlavorExactPolyPrec monomial.
213  */
214  template<typename P, typename Q, typename Phi>
216  {
217  public:
218  //! virtual destructor:
220 
221  //! Compute the total action
222  virtual Double S(const AbsFieldState<P,Q>& s)
223  {
224  START_CODE();
225 
226  // Self identification/encapsulation Rule
227  XMLWriter& xml_out = TheXMLLogWriter::Instance();
228  push(xml_out, "TwoFlavorExactPolyPrecUnprecWilsonTypeFermMonomial");
229 
230  Phi X;
231 
232  // Energy calc doesnt use Chrono Predictor
233  X = zero;
234  QDPIO::cout << "TwoFlavPolyWilson4DMonomial: resetting Predictor before energy calc solve" << std::endl;
236  int n_count = this->getX(X,s);
237 
238  // Action on the entire lattice
239  Double action = innerProductReal(getPhi(), X);
240 
241  write(xml_out, "n_count", n_count);
242  write(xml_out, "S", action);
243  pop(xml_out);
244 
245  END_CODE();
246 
247  return action;
248  }
249 
250 
251  protected:
252  //! Accessor for pseudofermion with Pf index i (read only)
253  virtual const Phi& getPhi(void) const = 0;
254 
255  //! mutator for pseudofermion with Pf index i
256  virtual Phi& getPhi(void) = 0;
257 
258  //! Get at fermion action
259  virtual const PolyWilsonTypeFermAct<Phi,P,Q>& getFermAct(void) const = 0;
260 
261  //! Get inverter params
262  virtual const GroupXML_t& getInvParams(void) const = 0;
263 
264  //! Get at the chronological predcitor
266  };
267 
268 
269  //-------------------------------------------------------------------------------------------
270  //! Exact 2 degen flavor even-odd preconditioned fermact monomial
271  /*! @ingroup monomial
272  *
273  * Exact 2 degen flavor even-odd preconditioned fermact monomial.
274  * Can supply a default dsdq algorithm
275  */
276  template<typename P, typename Q, typename Phi>
278  {
279  public:
280  //! virtual destructor:
282 
283  //! Even even contribution (eg ln det Clover)
284  virtual Double S_even_even(const AbsFieldState<P,Q>& s) = 0;
285 
286  //! Compute the odd odd contribution (eg
288  {
289  START_CODE();
290 
291  XMLWriter& xml_out = TheXMLLogWriter::Instance();
292  push(xml_out, "S_odd_odd");
293 
295 
296  Handle< FermState<Phi,P,Q> > bc_g_state = FA.createState(s.getQ());
297 
298  // Need way to get gauge state from AbsFieldState<P,Q>
299  Handle< DiffLinearOperator<Phi,P,Q> > lin(FA.linOp(bc_g_state));
300  // Get the X fields
301  Phi X;
302 
303  // Action calc doesnt use chrono predictor use zero guess
304  X[ lin->subset() ] = zero;
305 
306  // getX noe always uses chrono predictor. Best to Nuke it therefore
307  QDPIO::cout << "TwoFlavPolyWilson4DMonomial: resetting Predictor before energy calc solve" << std::endl;
309  int n_count = this->getX(X, s);
310  Double action = innerProductReal(getPhi(), X, lin->subset());
311 
312  write(xml_out, "n_count", n_count);
313  write(xml_out, "S_oo", action);
314  pop(xml_out);
315 
316  END_CODE();
317 
318  return action;
319  }
320 
321  //! Compute the total action
323  {
324  START_CODE();
325 
326  XMLWriter& xml_out=TheXMLLogWriter::Instance();
327  push(xml_out, "TwoFlavorExactPolyPrecEvenOddPrecWilsonTypeFermMonomial");
328 
329  Double action = S_even_even(s) + S_odd_odd(s);
330 
331  write(xml_out, "S", action);
332  pop(xml_out);
333 
334  END_CODE();
335 
336  return action;
337  }
338 
339  protected:
340  //! Get at fermion action
341  virtual const PolyWilsonTypeFermAct<Phi,P,Q>& getFermAct() const = 0;
342 
343  //! Get inverter params
344  virtual const GroupXML_t& getInvParams(void) const = 0;
345 
346  //! Accessor for pseudofermion with Pf index i (read only)
347  virtual const Phi& getPhi(void) const = 0;
348 
349  //! mutator for pseudofermion with Pf index i
350  virtual Phi& getPhi(void) = 0;
351 
353  };
354 
355 
356  //-------------------------------------------------------------------------------------------
357  //! Exact 2 degen flavor even-odd preconditioned fermact monomial
358  /*! @ingroup monomial
359  *
360  * Exact 2 degen flavor even-odd preconditioned fermact monomial.
361  * Constand even even determinant so can supplyt
362  */
363  template<typename P, typename Q, typename Phi>
365  {
366  public:
367  //! virtual destructor:
369 
370  //! Even even contribution (eg For this kind of Monomial it is 0)
372  return Double(0);
373  }
374 
375  // Inherit everything from Base Class
376  protected:
377  //! Get at fermion action
378  virtual const PolyWilsonTypeFermAct<Phi,P,Q>& getFermAct() const = 0;
379  };
380 
381 }
382 
383 
384 #endif
Monomials - gauge action or fermion binlinear contributions for HMC.
Chronological predictor for HMC.
Abstract interface for a Chronological Solution predictor.
Abstract field state.
Definition: field_state.h:27
virtual const Q & getQ(void) const =0
virtual DiffLinearOperator< T, Q, P > * linOp(Handle< FermState< T, P, Q > > state) const =0
Produce a linear operator for this action.
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 DiffLinearOperator< T, P, Q > * polyPrecLinOp(Handle< FermState< T, P, Q > > state) const =0
Produce a polynomial preconditioned 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 Double S_even_even(const AbsFieldState< P, Q > &s)
Even even contribution (eg For this kind of Monomial it is 0)
virtual const PolyWilsonTypeFermAct< Phi, P, Q > & getFermAct() const =0
Get at fermion action.
Exact 2 degen flavor even-odd preconditioned fermact monomial.
virtual Phi & getPhi(void)=0
mutator for pseudofermion with Pf index i
Double S(const AbsFieldState< P, Q > &s)
Compute the total action.
virtual AbsChronologicalPredictor4D< Phi > & getMDSolutionPredictor(void)=0
Get the initial guess predictor.
virtual const Phi & getPhi(void) const =0
Accessor for pseudofermion with Pf index i (read only)
virtual Double S_even_even(const AbsFieldState< P, Q > &s)=0
Even even contribution (eg ln det Clover)
virtual const GroupXML_t & getInvParams(void) const =0
Get inverter params.
virtual const PolyWilsonTypeFermAct< Phi, P, Q > & getFermAct() const =0
Get at fermion action.
virtual Double S_odd_odd(const AbsFieldState< P, Q > &s)
Compute the odd odd contribution (eg.
virtual const Phi & getPhi(void) const =0
Accessor for pseudofermion with Pf index i (read only)
virtual AbsChronologicalPredictor4D< Phi > & getMDSolutionPredictor(void)=0
Get the initial guess predictor.
virtual void dsdq(P &F, const AbsFieldState< P, Q > &s)
Compute dsdq for the system...
virtual Phi & getPhi(void)=0
mutator for pseudofermion with Pf index i
virtual Double S(const AbsFieldState< P, Q > &s)=0
Compute the total action.
virtual const GroupXML_t & getInvParams(void) const =0
Get inverter params.
virtual void refreshInternalFields(const AbsFieldState< P, Q > &field_state)
Refresh pseudofermions.
virtual const PolyWilsonTypeFermAct< Phi, P, Q > & getFermAct(void) const =0
Get at fermion action.
virtual void setInternalFields(const Monomial< P, Q > &m)
Copy pseudofermions if any.
virtual int getX(Phi &X, const AbsFieldState< P, Q > &s)
Get (Q*P(Q^2)*Q)^{-1} phi.
Exact 2 degen flavor unpreconditioned fermact monomial.
virtual const PolyWilsonTypeFermAct< Phi, P, Q > & getFermAct(void) const =0
Get at fermion action.
virtual 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 Phi & getPhi(void)=0
mutator for pseudofermion with Pf index i
virtual AbsChronologicalPredictor4D< Phi > & getMDSolutionPredictor(void)=0
Get at the chronological predcitor.
virtual const GroupXML_t & getInvParams(void) const =0
Get inverter params.
virtual LinearOperator< T > * hermitianLinOp(Handle< FermState< T, P, Q > > state) const =0
Produce a hermitian version of the linear operator.
int mu
Definition: cool.cc:24
Helper function for calculating forces.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
void reset()
Reset the default gauge field state.
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")
@ 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
multi1d< LatticeColorMatrix > P
Definition: t_clover.cc:13
Class structure for polynomial fermion actions.
static INTERNAL_PRECISION F