CHROMA
t_unprec_twoflav_wilson_monomial.cc
Go to the documentation of this file.
1 #include "chroma.h"
2 
3 using namespace Chroma;
4 
5 //! To insure linking of code, place the registered code flags here
6 /*! This is the bit of code that dictates what fermacts are in use */
8 {
9  bool foo = true;
10 
11  // 4D actions
13 
14  // 4D Monomials
16  return foo;
17 }
18 
19 //! Old dsdu routine
21  multi1d<LatticeColorMatrix>& ds_u,
22  multi1d<LatticeColorMatrix>& u_,
23  const LatticeFermion& psi)
24 {
25  START_CODE();
26 
27  // Apply BC's
29 
30  // Get at the U matrices
31  const multi1d<LatticeColorMatrix>& u = state->getLinks();
32 
33  // Get a linear operator
35 
36  // Compute MY
37  LatticeFermion Y;
38  (*M)(Y, psi, PLUS);
39 
40  // Usually this is Kappa. In our normalisation it is 0.5
41  // I am adding in a factor of -1 to be consistent with the sign
42  // convention for the preconditioned one. (We can always take this out
43  // later
44  Real prefactor=Real(0.5);
45 
46  // Two temporaries
47  LatticeFermion f_tmp;
48  LatticeColorMatrix u_tmp;
49  for(int mu = 0; mu < Nd; mu++)
50  {
51  // f_tmp = (1 + gamma_mu) Y
52  f_tmp = Gamma(1<<mu)*Y;
53  f_tmp += Y;
54 
55  // trace_spin ( ( 1 + gamma_mu ) Y_x+mu X^{dag}_x )
56 // u_tmp = traceSpin(outerProduct(shift(f_tmp, FORWARD, mu),psi));
57  LatticeFermion foo = shift(f_tmp, FORWARD, mu);
58  u_tmp = traceSpin(outerProduct(foo,psi));
59 
60  // f_tmp = -(1 -gamma_mu) X
61  f_tmp = Gamma(1<<mu)*psi;
62  f_tmp -= psi;
63 
64  // +trace_spin( ( 1 - gamma_mu) X_x+mu Y^{dag}_x)
65 // u_tmp -= traceSpin(outerProduct(shift(f_tmp, FORWARD, mu),Y));
66  foo = shift(f_tmp, FORWARD, mu);
67  u_tmp -= traceSpin(outerProduct(foo,Y));
68 
69  // accumulate with prefactor
70  ds_u[mu] = prefactor*( u[mu]*u_tmp );
71  }
72 
73  END_CODE();
74 }
75 
76 int main(int argc, char *argv[])
77 {
78  // Initialise QDP
79  Chroma::initialize(&argc, &argv);
80 
81  // Setup a small lattice
82  const int nrow_arr[] = {2, 2, 2, 2};
83  multi1d<int> nrow(Nd);
84  nrow=nrow_arr;
85  Layout::setLattSize(nrow);
86  Layout::create();
87 
88 
89  multi1d<LatticeColorMatrix> u(Nd);
90  {
91  XMLReader file_xml;
92  XMLReader config_xml;
94  // Cfg_t foo; foo.cfg_type=CFG_TYPE_SZIN; foo.cfg_file="./CFGIN";
95  gaugeStartup(file_xml, config_xml, u, foo);
96  }
97 
98  // Dump output
99  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
100  push(xml_out, "t_monomial");
101 
102  // Read Parameters
103  std::string monomial_name; // String for Factory
104  XMLReader param_in(Chroma::getXMLInputFileName());
105 
107  multi1d<LatticeColorMatrix> > > S_w;
108  try {
109 
110  // Snarf it all
111  XMLReader paramtop(param_in, "/MonomialTest");
112  // Get the std::string for the factory
113  read(paramtop, "Monomial", S_w);
114  }
115  catch(const std::string& e) {
116  QDPIO::cerr << "Error reading XML" << std::endl;
117  QDP_abort(1);
118  }
119 
120  // Fictitious momenta for now
121  multi1d<LatticeColorMatrix> p(Nd);
122  for(int mu=0; mu<Nd; mu++) {
123  gaussian(p[mu]);
124  }
125 
126  // Create a field state
127  GaugeFieldState gauge_state(p,u);
128 
129  // Refresh Pseudofermions
130  S_w->refreshInternalFields(gauge_state);
131 
132  // Compute Force from Monomial
133  multi1d<LatticeColorMatrix> dsdq(Nd);
134  S_w->dsdq(dsdq, gauge_state);
135 
136  // Compute action from monomial
137  Double monomial_S = S_w->S(gauge_state);
138  QDPIO::cout << "monomial_S = " << monomial_S << std::endl;
139 
140  // Check against normal version
141  // Downcast for direct handling
142  UnprecTwoFlavorWilsonFermMonomial& S_down = dynamic_cast<UnprecTwoFlavorWilsonFermMonomial&>(*S_w);
143 
144  // Use the debug accessors
145  const LatticeFermion& phi = S_down.debugGetPhi();
146 
147  LatticeFermion X=zero;
148  // This will repeat the solve... need to put caching in at some stage
149  S_down.debugGetX(X, gauge_state);
150 
151  // My energy measurement
152  Double my_S = innerProductReal(phi,X);
153  QDPIO::cout << "My S = " << my_S << std::endl;
154 
155  // Compute force the old fashioned way
156  // Get at the FermAct
157  const UnprecWilsonFermAct& S_f = S_down.debugGetFermAct();
158  multi1d<LatticeColorMatrix> dsdq2(Nd);
159 
160  // Call the old force routine
161  wilson_dsdu(S_f, dsdq2, gauge_state.getQ(), X);
162 
163  // Compare to new force
164  for(int mu=0; mu < Nd; mu++) {
165  taproj(dsdq[mu]);
166  taproj(dsdq2[mu]);
167 
168  push(xml_out, "dsdu");
169  write(xml_out, "dsdu_1", dsdq[mu]);
170  write(xml_out, "dsdu_2", dsdq2[mu]);
171  pop(xml_out);
172 
173  LatticeColorMatrix dsdu_diff=dsdq[mu] - dsdq2[mu];
174 
175  Double sum_diff=norm2(dsdu_diff);
176  QDPIO::cout << "Mu = " << mu << " Sum Diff=" << sum_diff << std::endl;
177 
178  push(xml_out, "ForceDiff");
179  write(xml_out, "mu", mu);
180  write(xml_out, "dsdu_diff", dsdu_diff);
181  pop(xml_out);
182  }
183 
184  // End
185  pop(xml_out);
186  xml_out.close();
187 
188  // Finish
190 
191  exit(0);
192 }
Primary include file for CHROMA in application codes.
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
Pure gauge field state.
Definition: field_state.h:83
const multi1d< LatticeColorMatrix > & getQ(void) const
Definition: field_state.h:118
Class for counted reference semantics.
Definition: handle.h:33
Unpreconditioned Wilson fermion action.
UnprecLinearOperator< T, P, Q > * linOp(Handle< FermState< T, P, Q > > state) const
Produce a linear operator for this action.
int mu
Definition: cool.cc:24
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
void taproj(LatticeColorMatrix &a)
Take the traceless antihermitian projection of a color matrix.
Definition: taproj.cc:31
void gaugeStartup(XMLReader &gauge_file_xml, XMLReader &gauge_xml, multi1d< LatticeColorMatrix > &u, Cfg_t &cfg)
Initialize the gauge fields.
@ CFG_TYPE_DISORDERED
Nd
Definition: meslate.cc:74
LatticeReal phi
Definition: mesq.cc:27
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
void initialize(int *argc, char ***argv)
Chroma initialisation routine.
Definition: chroma_init.cc:114
@ PLUS
Definition: chromabase.h:45
void finalize(void)
Chroma finalization routine.
Definition: chroma_init.cc:308
std::string getXMLInputFileName()
Get input file name.
Definition: chroma_init.cc:88
LatticeFermion psi
Definition: mespbg5p_w.cc:35
pop(xml_out)
START_CODE()
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
const WilsonTypeFermAct< multi1d< LatticeFermion > > & S_f
Definition: pbg5p_w.cc:27
Double zero
Definition: invbicg.cc:106
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
#define FORWARD
Definition: primitives.h:82
Gauge configuration structure.
Definition: cfgtype_io.h:16
CfgType cfg_type
Definition: cfgtype_io.h:17
bool linkage_hack()
To insure linking of code, place the registered code flags here.
int main(int argc, char *argv[])
void wilson_dsdu(const UnprecWilsonFermAct &S, multi1d< LatticeColorMatrix > &ds_u, multi1d< LatticeColorMatrix > &u_, const LatticeFermion &psi)
Old dsdu routine.