CHROMA
two_flavor_multihasen_cancel_monomial_w.h
Go to the documentation of this file.
1 /* Multi-Hasenbusch cancel monomial term for both
2  * symm and asymm even-odd precondition
3  */
4 #ifndef __TWO_FLAVOR_MULTIHASEN_CANCEL_MONOMIAL_W_H__
5 #define __TWO_FLAVOR_MULTIHASEN_CANCEL_MONOMIAL_W_H__
6 
10 #include "chromabase.h"
23 
24 
25 namespace Chroma
26 {
27  // Symmetric preconditioned
28  namespace SymEvenOddPrecConstDetTwoFlavorWilsonMultihasenCancelMonomialEnv
29  {
30  bool registerAll();
31  }
32 
33  // Asymmetric preconditioned
34  namespace EvenOddPrecConstDetTwoFlavorWilsonMultihasenCancelMonomialEnv
35  {
36  bool registerAll();
37  }
38 
39  template<typename T, typename P, typename Q,
40  template<typename, typename, typename> class FAType,
41  template<typename, typename, typename> class LOType>
43  public ExactWilsonTypeFermMonomial<P,Q,T>
44  {
45  // same as old monomial body but replace the specific FermionAction
46  // typename with "FAType" and every specific LinearOperator type with
47  // LOType
48  public:
55 
57 
58  virtual Double S(const AbsFieldState<P,Q>& s)
59  {
60  START_CODE();
61 
62  XMLWriter& xml_out = TheXMLLogWriter::Instance();
63  push(xml_out, "S");
64 
65  const FAType<T,P,Q>& FA = getFermAct();
66  Handle<FermState<T,P,Q> > state = FA.createState(s.getQ());
67 
68  // Get the X fields
69  T X;
70  Handle<LOType<T,P,Q> > base_op(FA.linOp(state));
71 
72  // Shifted lineart operator with mass parameter mu
74  M(new TwistedShiftedLinOp<T,P,Q,LOType>(*base_op, mu));
75  X[M->subset()] = zero;
76  // Energy calc doesnt use Chrono Predictor
77  QDPIO::cout << "TwoFlavWilson4DCancelMonomial: resetting Predictor before energy calc solve" << std::endl;
79 
80  // Get system solver
81  const GroupXML_t& invParam = getInvParams();
82  std::istringstream xml(invParam.xml);
83  XMLReader paramtop(xml);
85  invMdagM(TheMdagMFermSystemSolverFactory::Instance().createObject(
86  invParam.id, paramtop, invParam.path, state, M));
87  // Solve MdagM X = eta
88  SystemSolverResults_t res = (*invMdagM)(X, getPhi());
89  QDPIO::cout<<"2FlavCancel::invert, n_count = "<<res.n_count<<std::endl;
90 
91  // Action
92  Double action = innerProductReal(getPhi(), X, M->subset());
93  write(xml_out, "n_count", res.n_count);
94  write(xml_out, "S", action);
95  pop(xml_out);
96 
97  END_CODE();
98  return action;
99  }
100 
101  virtual void dsdq(P& F, const AbsFieldState<P,Q>& s)
102  {
103  START_CODE();
104 
105  XMLWriter& xml_out = TheXMLLogWriter::Instance();
106  push(xml_out, "TwoFlavorWilsonTypeMultihasenCancelMonomial");
107 
108  const FAType<T,P,Q>& FA = getFermAct();
109  Handle<FermState<T,P,Q> > state = FA.createState(s.getQ());
110 
111  Handle<LOType<T,P,Q> > base_op(FA.linOp(state));
112 
113  // Shifted lineart operator with mass parameter mu
115  M(new TwistedShiftedLinOp<T,P,Q,LOType>(*base_op, mu));
116 
117  // Get system solver
118  const GroupXML_t& invParam = getInvParams();
119  std::istringstream xml(invParam.xml);
120  XMLReader paramtop(xml);
122  invMdagM(TheMdagMFermSystemSolverFactory::Instance().createObject(
123  invParam.id, paramtop, invParam.path, state, M));
124  T X;
125  // Solve MdagM X = eta
126  SystemSolverResults_t res = (*invMdagM)(X, getPhi(),getMDSolutionPredictor());
127  QDPIO::cout << "2FlavCancel::invert, n_count = " << res.n_count << std::endl;
128 
129  P F_tmp;
130  T Y;
131  (*M)(Y, X, PLUS);
132 
133  // cast linearop to difflinearop
134  const DiffLinearOperator<T,P,Q>& diffM =
135  dynamic_cast<const DiffLinearOperator<T,P,Q>&>(*M);
136  diffM.deriv(F, X, Y, MINUS);
137  diffM.deriv(F_tmp, Y, X, PLUS);
138  F += F_tmp;
139 
140  for(int i=0; i<Nd; ++i){
141  F[i] *= Real(-1);
142  }
143 
144  state->deriv(F);
145 
146  write(xml_out, "n_count", res.n_count);
147  monitorForces(xml_out, "Forces", F);
148 
149  pop(xml_out);
150  END_CODE();
151  }
152 
154  {
155  START_CODE();
156 
157  const FAType<T,P,Q>& FA = getFermAct();
158  Handle<FermState<T,P,Q> > state = FA.createState(s.getQ());
159 
160  Handle<LOType<T,P,Q> > base_op(FA.linOp(state));
161 
162  // Shifted lineart operator with mass parameter mu
164  M(new TwistedShiftedLinOp<T,P,Q,LOType>(*base_op, mu));
165 
166  T eta = zero;
167  gaussian(eta, M->subset());
168  FA.getFermBC().modifyF(eta);
169 
170  eta *= sqrt(0.5);
171  (*M)(getPhi(), eta, MINUS);
172 
173  QDPIO::cout << "TwoFlavWilson4DCancelMonomial: resetting Predictor after field refresh" << std::endl;
174  getMDSolutionPredictor().reset();
175 
176  END_CODE();
177  }
178 
179  virtual void setInternalFields(const Monomial<P,Q>& m)
180  {
181  START_CODE();
182  try{
185  getPhi() = fm.getPhi();
186  }
187  catch(std::bad_cast){
188  QDPIO::cerr<<"Failed to cast input Monomial to PrecConstDetTwoFlavorWilsonMultihasenCancelMonomial "<<std::endl;
189  QDP_abort(1);
190  }
191  END_CODE();
192  }
193  virtual void resetPredictors(void){
194  getMDSolutionPredictor().reset();
195  }
196 
197  protected:
198  virtual const T& getPhi(void) const {
199  return phi;
200  }
201  virtual T& getPhi(void){
202  return phi;
203  }
204  const FAType<T,P,Q>& getFermAct(void) const{
205  return *fermact;
206  }
207  const GroupXML_t& getInvParams(void) const{
208  return inv_param;
209  }
211  return *chrono_predictor;
212  }
213 
214  private:
217  // Pseudofermion field phi
220  // Shifted mass parameter
221  Real mu;
224  };
225 
226  template<typename T, typename P, typename Q,
227  template<typename, typename, typename> class FAType,
228  template<typename, typename, typename> class LOType>
232  {
233  START_CODE();
234  inv_param = param.inv_param;
235  std::istringstream is(param.fermact.xml);
236  XMLReader fermact_reader(is);
237  QDPIO::cout<<__func__<<": construct "
238  <<param.fermact.id<<std::endl;
239 
240  WilsonTypeFermAct<T,P,Q>* tmp_act =
241  TheWilsonTypeFermActFactory::Instance().createObject(param.fermact.id,
242  fermact_reader,
243  param.fermact.path);
244  FAType<T,P,Q>* downcast=dynamic_cast<FAType<T,P,Q>* >(tmp_act);
245 
246  if(downcast == 0x0){
247  QDPIO::cerr<<__func__<<": unable to downcast FermAct"<<std::endl;
248  QDP_abort(1);
249  }
250  fermact = downcast;
251 
252  mu = param.mu;
253 
255  if(param.predictor.xml == ""){
257  }else{
258  try{
259  std::istringstream chrono_is(param.predictor.xml);
260  XMLReader chrono_xml(chrono_is);
262  chrono_xml,
263  param.predictor.path);
264  }catch(const std::string& e){
265  QDPIO::cerr<<"Caught Excepthion Reading XML: "<<e<<std::endl;
266  QDP_abort(1);
267  }
268  }
269  if(tmp == 0x0){
270  QDPIO::cerr<<"Failed to create ZeroGuess4DChronoPredictor"<<std::endl;
271  QDP_abort(1);
272  }
273  chrono_predictor = tmp;
274  END_CODE();
275  }
276 
277 }//end namespace Chroma
278 
279 #endif
Monomials - gauge action or fermion binlinear contributions for HMC.
Primary include file for CHROMA library code.
Monomial factories.
Abstract interface for a Chronological Solution predictor.
Abstract field state.
Definition: field_state.h:27
Differentiable Linear Operator.
Definition: linearop.h:98
virtual void deriv(P &ds_u, const T &chi, const T &psi, enum PlusMinus isign) const
Apply the derivative of the operator onto a source std::vector.
Definition: linearop.h:108
Fermionic monomials (binlinears in fermion fields)
Definition: abs_monomial.h:243
Class for counted reference semantics.
Definition: handle.h:33
An abstract monomial class, for inexact algorithms.
Definition: abs_monomial.h:43
void operator=(const PrecConstDetTwoFlavorWilsonMultihasenCancelMonomial &)
PrecConstDetTwoFlavorWilsonMultihasenCancelMonomial(const PrecConstDetTwoFlavorWilsonMultihasenCancelMonomial &m)
virtual void setInternalFields(const Monomial< P, Q > &m)
Copy pseudofermions if any.
virtual Double S(const AbsFieldState< P, Q > &s)
Compute the total action.
virtual void refreshInternalFields(const AbsFieldState< P, Q > &s)
Refresh pseudofermions.
virtual void dsdq(P &F, const AbsFieldState< P, Q > &s)
Compute dsdq for the system... Not specified how to actually do this.
const FAType< T, P, Q > & getFermAct(void) const
Get at fermion action for pseudofermion field i.
static T & Instance()
Definition: singleton.h:432
Wilson-like fermion actions.
Definition: fermact.orig.h:344
Zero initial guess predictor.
int mu
Definition: cool.cc:24
Even-odd const determinant Wilson-like fermact.
Even-odd const determinant Wilson-like fermact.
Fermion action factories.
All Wilson-type fermion actions.
Field state.
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
Nd
Definition: meslate.cc:74
Monomial factories.
multi1d< LatticeColorMatrix > P
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
LinOpSysSolverMGProtoClover::Q Q
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
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
::std::string string
Definition: gtest.h:1979
Symmetric even-odd const determinant Wilson-like fermact.
Symmetric even-odd const determinant Wilson-like fermact.
Hold group xml and type id.
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Factory for producing system solvers for MdagM*psi = chi.
multi1d< LatticeColorMatrix > P
Definition: t_clover.cc:13
Two-flavor monomial params cancel term for multi-Hasenbusch prec.
Zero initial guess predictor.
static INTERNAL_PRECISION F