CHROMA
t_prec_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  const Real& Mass,
22  multi1d<LatticeColorMatrix> & ds_u,
24  const LatticeFermion& psi)
25 {
26  START_CODE();
27 
28  ds_u.resize(Nd);
29 
30  Real prefactor = Real(1)/(4*(Real(Nd) + Mass));
31 
32  LatticeColorMatrix utmp_1=zero;
33  LatticeFermion phi=zero;
34  LatticeFermion rho=zero;
35  LatticeFermion sigma=zero;;
36 
37  LatticeFermion ftmp_2;
38 
39  // Do the usual Wilson fermion dS_f/dU
40  // const LinearOperatorProxy<LatticeFermion> A(linOp(u));
42 
43  // Need the wilson dslash
44  // Use u from state with BC's on
45  const multi1d<LatticeColorMatrix>& u = state->getLinks();
46  WilsonDslash D(u);
47 
48  // phi = M(u)*psi
49 
50  (*M)(phi, psi, PLUS);
51 
52  /* rho = Dslash(0<-1) * psi */
53  D.apply(rho, psi, PLUS, 0);
54 
55  /* sigma = Dslash_dag(0 <- 1) * phi */
56  D.apply(sigma, phi, MINUS, 0);
57 
58  for(int mu = 0; mu < Nd; ++mu) {
59 
60  // ftmp_2(x) = -(psi(x) - ftmp_2(x)) = -(1 - gamma(mu))*psi( x )
61  ftmp_2[rb[1]] = Gamma(1<<mu) * psi;
62  ftmp_2[rb[1]] -= psi;
63 
64 
65  // utmp_1 = - Trace_spin [ ( 1 - gamma(mu) )*psi_{x+mu)*sigma^{dagger} ]
66  // = - Trace_spin [ sigma^{dagger} ( 1 - gamma_mu ) psi_{x+mu} ]
67  utmp_1[rb[0]] = -traceSpin( outerProduct( shift(ftmp_2, FORWARD, mu), sigma) );
68 
69 
70  // ftmp_2 = phi + ftmp_2 = (1 + gamma(mu))*phi( x)
71  ftmp_2[rb[1]] = Gamma(1<<mu) * phi;
72  ftmp_2[rb[1]] += phi;
73 
74  // utmp_1 += ( 1 + gamma(mu) )*phi_{x+mu)*rho^{dagger}_x
75  utmp_1[rb[0]] += traceSpin( outerProduct( shift(ftmp_2, FORWARD, mu), rho) );
76 
77  // ds_u[mu][0] += u[mu][0] * utmp_1
78  // = u[mu][0] [ ( 1 - gamma(mu) )*psi_{x+mu)*sigma^{dagger}_x
79  // + ( 1 + gamma(mu) )*phi_{x+mu)*rho^{dagger}_x ]
80  ds_u[mu][rb[0]] = prefactor * u[mu] * utmp_1;
81 
82  // Checkerboard 1
83 
84  // ftmp_2 = -(rho - ftmp_2) = -(1 - gamma(mu))*rho( x )
85  ftmp_2[rb[0]] = Gamma(1<<mu)*rho;
86  ftmp_2[rb[0]] -= rho;
87 
88  // utmp_1 = ( 1 - gamma(mu) )*rho_{x+mu)*phi^{dagger}_x
89  utmp_1[rb[1]] = -traceSpin( outerProduct( shift(ftmp_2, FORWARD, mu), phi) );
90 
91  // ftmp_2 = (gamma(mu))*sigma
92  ftmp_2[rb[0]] = Gamma(1<<mu)*sigma;
93  ftmp_2[rb[0]] += sigma;
94 
95 
96  utmp_1[rb[1]] += traceSpin( outerProduct( shift(ftmp_2, FORWARD, mu), psi) );
97  ds_u[mu][rb[1]] = prefactor * u[mu] * utmp_1;
98 
99  }
100 }
101 
102 int main(int argc, char *argv[])
103 {
104  // Initialise QDP
105  Chroma::initialize(&argc, &argv);
106 
107  // Setup a small lattice
108  const int nrow_arr[] = {2, 2, 2, 2};
109  multi1d<int> nrow(Nd);
110  nrow=nrow_arr;
111  Layout::setLattSize(nrow);
112  Layout::create();
113 
114 
115  multi1d<LatticeColorMatrix> u(Nd);
116  {
117  XMLReader file_xml;
118  XMLReader config_xml;
120  // Cfg_t foo; foo.cfg_type=CFG_TYPE_SZIN; foo.cfg_file="./CFGIN";
121  gaugeStartup(file_xml, config_xml, u, foo);
122  }
123 
124  // Dump output
125  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
126  push(xml_out, "t_monomial");
127 
128  // Read Parameters
129  std::string monomial_name; // String for Factory
130  XMLReader param_in(Chroma::getXMLInputFileName());
132  multi1d<LatticeColorMatrix> > >
133  S_w;
134 
135  try {
136 
137  // Snarf it all
138  XMLReader paramtop(param_in, "/MonomialTest");
139 
140  // Get the std::string for the factory
141  read(paramtop, "Monomial", S_w);
142  }
143  catch(const std::string& e) {
144  QDPIO::cerr << "Error reading XML" << std::endl;
145  QDP_abort(1);
146  }
147 
148 
149  // Fictitious momenta for now
150  multi1d<LatticeColorMatrix> p(Nd);
151  for(int mu=0; mu<Nd; mu++) {
152  gaussian(p[mu]);
153  }
154 
155  // Create a field state
156  GaugeFieldState gauge_state(p,u);
157 
158  // Refresh Pseudofermions
159  S_w->refreshInternalFields(gauge_state);
160 
161  // Compute Force from Monomial
162  multi1d<LatticeColorMatrix> dsdq(Nd);
163  S_w->dsdq(dsdq, gauge_state);
164 
165  // Compute action from monomial
166  Double monomial_S = S_w->S(gauge_state);
167  QDPIO::cout << "monomial_S = " << monomial_S << std::endl;
168 
169  // Check against normal version
170  // Downcast for direct handling
171  EvenOddPrecTwoFlavorWilsonFermMonomial& S_down = dynamic_cast<EvenOddPrecTwoFlavorWilsonFermMonomial&>(*S_w);
172 
173  // Use the debug accessors
174  const LatticeFermion& phi = S_down.debugGetPhi();
175 
176  LatticeFermion X=zero;
177  // This will repeat the solve... need to put caching in at some stage
178  S_down.debugGetX(X, gauge_state);
179 
180 
181  // Compute force the old fashioned way
182  // Get at the FermAct
183  const EvenOddPrecWilsonFermAct& S_f = S_down.debugGetFermAct();
184 
185  // Need this connec state to make a linOp and for the old
186  // Force routine
187  Handle<const ConnectState> c_state(S_f.createState(gauge_state.getQ()));
188 
189  // Get a linOp for the subset
191 
192  // My energy measurement
193  Double my_S = innerProductReal(phi,X, M->subset());
194  QDPIO::cout << "My S = " << my_S << std::endl;
195 
196  // Call the old force routine
197  multi1d<LatticeColorMatrix> dsdq2(Nd);
198 
199  // Call old force term
200  prec_wilson_dsdu(S_f, S_f.getQuarkMass(), dsdq2, c_state, X);
201 
202  // Compare to new force
203  for(int mu=0; mu < Nd; mu++) {
204  taproj(dsdq[mu]);
205  taproj(dsdq2[mu]);
206 
207  push(xml_out, "dsdu");
208  write(xml_out, "dsdu_1", dsdq[mu]);
209  write(xml_out, "dsdu_2", dsdq2[mu]);
210  pop(xml_out);
211 
212  LatticeColorMatrix dsdu_diff=dsdq[mu] - dsdq2[mu];
213 
214  Double sum_diff=norm2(dsdu_diff);
215  QDPIO::cout << "Mu = " << mu << " Sum Diff=" << sum_diff << std::endl;
216 
217  push(xml_out, "ForceDiff");
218  write(xml_out, "mu", mu);
219  write(xml_out, "dsdu_diff", dsdu_diff);
220  pop(xml_out);
221  }
222 
223  // End
224  pop(xml_out);
225  xml_out.close();
226 
227  // Finish
229 
230  exit(0);
231 }
Primary include file for CHROMA in application codes.
Even-odd preconditioned Wilson fermion action.
EvenOddPrecConstDetLinearOperator< T, P, Q > * linOp(Handle< FermState< T, P, Q > > state) const
Produce a linear operator for this action.
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
General Wilson-Dirac dslash.
Definition: lwldslash_w.h:48
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
void apply(T &chi, const T &psi, enum PlusMinus isign, int cb) const
General Wilson-Dirac dslash.
Definition: lwldslash_w.h:228
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
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > const multi1d< Real > & Mass
Definition: pbg5p_w.cc:29
push(xml_out,"Condensates")
void initialize(int *argc, char ***argv)
Chroma initialisation routine.
Definition: chroma_init.cc:114
@ MINUS
Definition: chromabase.h:45
@ 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 prec_wilson_dsdu(const EvenOddPrecWilsonFermAct &S, const Real &Mass, multi1d< LatticeColorMatrix > &ds_u, Handle< const ConnectState > state, const LatticeFermion &psi)
Old dsdu routine.