CHROMA
t_neflinop.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <cstdio>
4 
5 #include "chroma.h"
6 
7 #include "qdp_util.h"
8 
9 using namespace Chroma;
10 
11 
12 //! Read a SZIN fermion. This is a simple memory dump reader.
13 /*!
14  * \ingroup io
15  *
16  * \param q lattice fermion ( Modify )
17  * \param file path ( Read )
18  */
19 
20 void readSzinFerm(multi1d<LatticeFermion>& q, const std::string& file)
21 {
22  BinaryFileReader cfg_in(file);
23 
24  //
25  // Read propagator field
26  //
27  multi1d<int> lattsize_cb = Layout::lattSize();
28  lattsize_cb[0] /= 2; // checkerboard in the x-direction in szin
29 
30  // Read prop
31  for(int s=0; s < q.size(); ++s)
32  {
33  for(int cb=0; cb < 2; ++cb)
34  {
35  for(int sitecb=0; sitecb < Layout::vol()/2; ++sitecb)
36  {
37  multi1d<int> coord = crtesn(sitecb, lattsize_cb);
38 
39  // construct the checkerboard offset
40  int sum = 0;
41  for(int m=1; m<Nd; m++)
42  sum += coord[m];
43 
44  // The true lattice x-coord
45  coord[0] = 2*coord[0] + ((sum + cb) & 1);
46 
47  read(cfg_in, q[s], coord); // Read in a site propagator
48  }
49  }
50  }
51 
52  cfg_in.close();
53 }
54 
55 
56 
57 int main(int argc, char **argv)
58 {
59  // Put the machine into a known state
60  Chroma::initialize(&argc, &argv);
61 
62  // Setup the layout
63  const int foo[] = {4,4,4,4};
64  multi1d<int> nrow(Nd);
65  nrow = foo; // Use only Nd elements
66  Layout::setLattSize(nrow);
67  Layout::create();
68 
69  XMLFileWriter xml("t_neflinop.xml");
70  push(xml, "t_neflinop");
71 
72  //! Test out dslash
73  multi1d<LatticeColorMatrix> u(Nd);
74 #if 1
75  for(int m=0; m < u.size(); ++m)
76  gaussian(u[m]);
77 #else
78  XMLReader gauge_xml;
79  readSzin(gauge_xml, u, "small.cfg");
80 #endif
81 
82  // Create the BC objects
83  const int bnd[] = {1,1,1,1};
84  multi1d<int> boundary(Nd);
85  boundary = bnd;
86 
87  // Create a FermBC
88  Handle<FermBC<multi1d<LatticeFermion> > > fbc_a(new SimpleFermBC<multi1d<LatticeFermion> >(boundary));
89 
90  Real WilsonMass = 1.5;
91  Real m_q = 0.1;
92  int N5 = 8;
93 
94  multi1d<LatticeFermion> psi(N5), chi(N5),saveUprec(N5), savePrec(N5),tt(N5);
95 
96  for(int m=0; m < N5; ++m)
97  random(psi[m]);
98 
99  for(int m=0; m < N5; ++m)
100  random(chi[m]);
101 
102 
103  //#define SHAMIR
104 #define BORICI
105  {
106  //Shamir DWF case
107 #ifdef SHAMIR
108  UnprecDWFermActArray S_DWF(fbc_a, WilsonMass, m_q, N5);
109  UnprecNEFFermActArray S_NEF(fbc_a, WilsonMass, 1.0, 0, m_q, N5);
110 #endif
111  //Borici DWF case
112 #ifdef BORICI
113  UnprecOvDWFermActArray S_DWF(fbc_a, WilsonMass, m_q, N5);
114  UnprecNEFFermActArray S_NEF(fbc_a, WilsonMass, 1.0, 1.0, m_q, N5);
115 #endif
116 
117  Handle<const ConnectState> stateDWF(S_DWF.createState(u));
119 
120  Handle<const ConnectState> stateNEF(S_NEF.createState(u));
122 
123  multi1d<LatticeFermion> tmp1(N5);
124  (*Adwf)(tmp1, psi, PLUS);
125  multi1d<LatticeFermion> tmp2(N5);
126  (*Anef)(tmp2, psi, PLUS);
127 
128  saveUprec = tmp2 ;
129 
130  multi1d<LatticeFermion> diff(N5);
131  for(int m=0; m < N5; ++m)
132  diff[m] = tmp2[m]-tmp1[m] ;
133 
134 
135 
136  (*Anef)(tmp1, psi, PLUS);
137  DComplex nn1 = innerProduct(chi[0], tmp1[0]);
138  for(int m=1; m < N5; ++m)
139  nn1 += innerProduct(chi[m], tmp1[m]);
140 
141  (*Anef)(tmp2, chi, MINUS);
142  DComplex nn2 = innerProduct(tmp2[0], psi[0]);
143  for(int m=1; m < N5; ++m)
144  nn2 += innerProduct(tmp2[m], psi[m]);
145 
146 
147 
148  push(xml,"innerprods");
149  write(xml, "norm_psi" , Real(norm2(psi )));
150  write(xml, "norm_chi" , Real(norm2(chi )));
151  write(xml, "norm_tmp1", Real(norm2(tmp1)));
152  write(xml, "norm_tmp2", Real(norm2(tmp2)));
153  write(xml, "norm_diff", Real(norm2(diff)));
154  write(xml, "nn1", nn1);
155  write(xml, "nn2", nn2);
156 
157  pop(xml);
158 }
159 
160  {
161  //Shamir case
162 #ifdef SHAMIR
163  EvenOddPrecDWFermActArray S_DWF(fbc_a, WilsonMass, m_q, N5);
164  EvenOddPrecNEFFermActArray S_NEF(fbc_a, WilsonMass, 1.0, 0, m_q, N5);
165 #endif
166  //Borici DWF case
167 #ifdef BORICI
168  EvenOddPrecOvDWFermActArray S_DWF(fbc_a, WilsonMass, m_q, N5);
169  EvenOddPrecNEFFermActArray S_NEF(fbc_a, WilsonMass, 1.0, 1.0, m_q, N5);
170 #endif
171 
172  Handle<const ConnectState> stateDWF(S_DWF.createState(u));
174 
175  Handle<const ConnectState> stateNEF(S_NEF.createState(u));
177 
178  multi1d<LatticeFermion> tmp1(N5);
179  (*Adwf)(tmp1, psi, PLUS);
180  multi1d<LatticeFermion> tmp2(N5);
181  (*Anef)(tmp2, psi, PLUS);
182 
183  (*Anef).unprecLinOp(savePrec,psi,PLUS);
184 
185  for(int m=0; m < N5; ++m){
186  tmp2[m][rb[0]] = tmp1[m] ;
187  }
188 
189  multi1d<LatticeFermion> diff(N5);
190  for(int m=0; m < N5; ++m)
191  diff[m] = tmp2[m]-tmp1[m] ;
192 
193 
194 
195  (*Anef)(tmp1, psi, PLUS);
196  DComplex nn1 = innerProduct(chi[0], tmp1[0]);
197  for(int m=1; m < N5; ++m)
198  nn1 += innerProduct(chi[m], tmp1[m]);
199 
200  (*Anef)(tmp2, chi, MINUS);
201  DComplex nn2 = innerProduct(tmp2[0], psi[0]);
202  for(int m=1; m < N5; ++m)
203  nn2 += innerProduct(tmp2[m], psi[m]);
204 
205 
206 
207  push(xml,"prec_innerprods");
208  write(xml, "norm_psi" , Real(norm2(psi )));
209  write(xml, "norm_chi" , Real(norm2(chi )));
210  //write(xml, "norm_tmp1", Real(norm2(tmp1)));
211  //write(xml, "norm_tmp2", Real(norm2(tmp2)));
212  write(xml, "norm_diff", Real(norm2(diff)));
213  write(xml, "nn1", nn1);
214  write(xml, "nn2", nn2);
215 
216  pop(xml);
217  }
218  for(int m=0; m < N5; ++m)
219  tt[m] = savePrec[m]- saveUprec[m] ;
220 
221  push(xml,"prec_minus_unprec_innerprods");
222  write(xml, "norm_Prec_minus_Uprec", Real(norm2(tt)));
223  pop(xml);
224 
225  //TEST THE individual pieces of the operator
226  {
227  //Shamir case
228 #ifdef SHAMIR
229  EvenOddPrecDWFermActArray S_DWF(fbc_a, WilsonMass, m_q, N5);
230  EvenOddPrecNEFFermActArray S_NEF(fbc_a, WilsonMass, 1.0, 0, m_q, N5);
231 #endif
232  //Borici DWF case
233 #ifdef BORICI
234  EvenOddPrecOvDWFermActArray S_DWF(fbc_a, WilsonMass, m_q, N5);
235  EvenOddPrecNEFFermActArray S_NEF(fbc_a, WilsonMass, 1.0, 1.0, m_q, N5);
236 #endif
237 
238  Handle<const ConnectState> stateDWF(S_DWF.createState(u));
240 
241  Handle<const ConnectState> stateNEF(S_NEF.createState(u));
243 
244  multi1d<LatticeFermion> tmp1(N5);
245  multi1d<LatticeFermion> tmp2(N5),diff_ee(N5), diff_oo(N5),diff_eo(N5) ;
246  multi1d<LatticeFermion> diff_oe(N5),diff_inv_ee(N5),diff_inv_oo(N5) ;
247 
248  (*Adwf).evenEvenLinOp(tmp1, psi, PLUS);
249  (*Anef).evenEvenLinOp(tmp2, psi, PLUS);
250 
251  for(int m=0; m < N5; ++m)
252  diff_ee[m] = tmp2[m]-tmp1[m] ;
253 
254  (*Adwf).oddOddLinOp(tmp1, psi, PLUS);
255  (*Anef).oddOddLinOp(tmp2, psi, PLUS);
256 
257  for(int m=0; m < N5; ++m)
258  diff_oo[m] = tmp2[m]-tmp1[m] ;
259 
260  (*Adwf).evenEvenInvLinOp(tmp1, psi, PLUS);
261  (*Anef).evenEvenInvLinOp(tmp2, psi, PLUS);
262 
263  for(int m=0; m < N5; ++m)
264  diff_inv_ee[m] = tmp2[m]-tmp1[m] ;
265 
266  (*Adwf).evenOddLinOp(tmp1, psi, PLUS);
267  (*Anef).evenOddLinOp(tmp2, psi, PLUS);
268 
269  for(int m=0; m < N5; ++m)
270  diff_eo[m] = tmp2[m]-tmp1[m] ;
271 
272  (*Adwf).oddEvenLinOp(tmp1, psi, PLUS);
273  (*Anef).oddEvenLinOp(tmp2, psi, PLUS);
274 
275  for(int m=0; m < N5; ++m)
276  diff_oe[m] = tmp2[m]-tmp1[m] ;
277 
278  push(xml,"prec_pieces_PLUS");
279  write(xml, "norm_ee" , Real(norm2(diff_ee)));
280  write(xml, "norm_oo" , Real(norm2(diff_oo)));
281  write(xml, "norm_eo" , Real(norm2(diff_eo)));
282  write(xml, "norm_oe" , Real(norm2(diff_oe)));
283 
284  write(xml, "norm_inv_ee" , Real(norm2(diff_inv_ee)));
285 
286  pop(xml);
287 
288  (*Adwf).evenEvenLinOp(tmp1, psi, MINUS);
289  (*Anef).evenEvenLinOp(tmp2, psi, MINUS);
290 
291  for(int m=0; m < N5; ++m)
292  diff_ee[m] = tmp2[m]-tmp1[m] ;
293 
294  (*Adwf).oddOddLinOp(tmp1, psi, MINUS);
295  (*Anef).oddOddLinOp(tmp2, psi, MINUS);
296 
297  for(int m=0; m < N5; ++m)
298  diff_oo[m] = tmp2[m]-tmp1[m] ;
299 
300  (*Adwf).evenEvenInvLinOp(tmp1, psi, MINUS);
301  (*Anef).evenEvenInvLinOp(tmp2, psi, MINUS);
302 
303  for(int m=0; m < N5; ++m)
304  diff_inv_ee[m] = tmp2[m]-tmp1[m] ;
305 
306  (*Adwf).evenOddLinOp(tmp1, psi, MINUS);
307  (*Anef).evenOddLinOp(tmp2, psi, MINUS);
308 
309  for(int m=0; m < N5; ++m)
310  diff_eo[m] = tmp2[m]-tmp1[m] ;
311 
312  (*Adwf).oddEvenLinOp(tmp1, psi, MINUS);
313  (*Anef).oddEvenLinOp(tmp2, psi, MINUS);
314 
315  for(int m=0; m < N5; ++m)
316  diff_oe[m] = tmp2[m]-tmp1[m] ;
317 
318  push(xml,"prec_pieces_MINUS");
319  write(xml, "norm_ee" , Real(norm2(diff_ee)));
320  write(xml, "norm_oo" , Real(norm2(diff_oo)));
321  write(xml, "norm_eo" , Real(norm2(diff_eo)));
322  write(xml, "norm_oe" , Real(norm2(diff_oe)));
323 
324  write(xml, "norm_inv_ee" , Real(norm2(diff_inv_ee)));
325 
326  pop(xml);
327 
328  }
329 
330  pop(xml);
331 
332  // Time to bolt
334 
335  exit(0);
336 }
Primary include file for CHROMA in application codes.
4D style even-odd preconditioned domain-wall fermion action
virtual EvenOddPrecDWLikeLinOpBaseArray< T, P, Q > * linOp(Handle< FermState< T, P, Q > > state) const
Override to produce a DWF-link even-odd prec. linear operator for this action.
4D style even-odd preconditioned domain-wall fermion action
4D style even-odd preconditioned Overlap-DWF (Borici) action
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
Concrete class for all gauge actions with simple boundary conditions.
Definition: simple_fermbc.h:42
Unpreconditioned domain-wall fermion action.
virtual UnprecDWLikeLinOpBaseArray< T, P, Q > * linOp(Handle< FermState< T, P, Q > > state) const
Override to produce a DWF-link unprec. linear operator for this action.
Unpreconditioned NEF fermion action.
Unpreconditioned Overlap-style (Borici) OvDWF fermion action.
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 readSzinFerm(LatticeFermion &q, const std::string &file)
Read a SZIN fermion. This is a simple memory dump reader.
void readSzin(SzinGauge_t &header, multi1d< LatticeColorMatrix > &u, const std::string &cfg_file)
Read a SZIN configuration file.
Definition: readszin.cc:31
static int m[4]
Definition: make_seeds.cc:16
multi1d< int > coord(Nd)
Nd
Definition: meslate.cc:74
Double q
Definition: mesq.cc:17
Double tmp2
Definition: mesq.cc:30
BinaryReturn< C1, C2, FnInnerProduct >::Type_t innerProduct(const QDPSubType< T1, C1 > &s1, const QDPType< T2, C2 > &s2)
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
@ MINUS
Definition: chromabase.h:45
@ PLUS
Definition: chromabase.h:45
void finalize(void)
Chroma finalization routine.
Definition: chroma_init.cc:308
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
pop(xml_out)
int cb
Definition: invbicg.cc:120
multi1d< LatticeFermion > s(Ncb)
::std::string string
Definition: gtest.h:1979
Double sum
Definition: qtopcor.cc:37
int main(int argc, char **argv)
Definition: t_neflinop.cc:57