CHROMA
t_dwflinop.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_dwflinop.xml");
70  push(xml, "t_dwflinop");
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  // Typedefs to save typing
88  typedef LatticeFermion T;
89  typedef multi1d<LatticeColorMatrix> P;
90  typedef multi1d<LatticeColorMatrix> Q;
91 
92  // Create a FermBC
94 
95  Real WilsonMass = 1.5;
96  Real m_q = 0.1;
97 #if 1
98  int N5 = 8;
99  UnprecDWFermActArray S_f(cfs, WilsonMass, m_q, N5);
100 #else
101  int N5 = 9;
102  UnprecOvExtFermActArray S_f(cfs, WilsonMass, m_q, N5);
103 #endif
104 
105  Handle< FermState<T,P,Q> > state(S_f.createState(u));
107 
108  multi1d<LatticeFermion> psi(N5), chi(N5);
109 
110 #if 1
111  for(int m=0; m < N5; ++m)
112  random(psi[m]);
113 
114  for(int m=0; m < N5; ++m)
115  random(chi[m]);
116 #else
117  readSzinFerm(psi, "t_invert.psi0");
118  readSzinFerm(chi, "t_invert.chi0");
119 #endif
120 
121  multi1d<LatticeFermion> tmp1(N5);
122  (*A)(tmp1, psi, PLUS);
123  DComplex nn1 = innerProduct(chi[0], tmp1[0]);
124  for(int m=1; m < N5; ++m)
125  nn1 += innerProduct(chi[m], tmp1[m]);
126 
127  multi1d<LatticeFermion> tmp2(N5);
128  (*A)(tmp2, chi, MINUS);
129  DComplex nn2 = innerProduct(tmp2[0], psi[0]);
130  for(int m=1; m < N5; ++m)
131  nn2 += innerProduct(tmp2[m], psi[m]);
132 
133  push(xml,"innerprods");
134  write(xml, "norm_psi", Real(norm2(psi)));
135  write(xml, "norm_chi", Real(norm2(chi)));
136  write(xml, "nn1", nn1);
137  write(xml, "nn2", nn2);
138  pop(xml);
139 
140 
141 #if 0
142  if (N5 != Ls)
143  QDP_error_exit("N5 != Ls");
144 
145  // Create a FermBC
146  UnprecDWFermAct S_f_dwf(cfs, WilsonMass, m_q);
147  LatticeDWFermion psi5, chi5, tmp1a;
148 
149  for(int m=0; m < N5; ++m)
150  {
151  pokeDW(psi5, psi[m], m);
152  pokeDW(chi5, chi[m], m);
153  pokeDW(tmp1a, tmp1[m], m);
154  }
155 
156  const LinearOperatorProxy<LatticeDWFermion> B(S_f_dwf.linOp(u));
157 
158  LatticeDWFermion tmp5a;
159  B(tmp5a, psi5, PLUS);
160  DComplex nd1 = innerProduct(chi5, tmp5a);
161 
162  LatticeDWFermion tmp5b;
163  B(tmp5b, chi5, MINUS);
164  DComplex nd2 = innerProduct(tmp5b, psi5);
165 
166  push(xml,"innerprods_dwf");
167  write(xml, "norm_psi5", Real(norm2(psi5)));
168  write(xml, "norm_chi5", Real(norm2(chi5)));
169  write(xml, "nd1", nd1);
170  write(xml, "nd2", nd2);
171  write(xml, "norm_tmp1_tmp1a", Real(norm2(tmp5a-tmp1a)));
172  pop(xml);
173 
174 #endif
175 
176 #if 0
177 
178  // Test inverter
179  QDPIO::cout << "|psi|^2 = " << norm2(psi) << std::endl;
180  QDPIO::cout << "|chi|^2 = " << norm2(chi) << std::endl;
181 
182  chi = A(psi, PLUS);
183 
184  QDPIO::cout << "|chi|^2 = " << norm2(chi) << std::endl;
185 
186  Real RsdCG = 1.0e-5;
187  int MaxCG = 1000;
188  int n_count;
189  InvCG2(*A, chi, psi, RsdCG, MaxCG, n_count); // subtelty here: deref A to get object pointed by handle
190 
191 
192  multi1d<LatticeFermion> psi2(N5), chi2(N5);
193 
194  readSzinFerm(psi2, "t_invert.psi1");
195  readSzinFerm(chi2, "t_invert.chi1");
196 
197  for(int m=0; m < N5; ++m)
198  {
199  tmp1[m] = psi2[m] - psi[m];
200  tmp2[m] = chi2[m] - chi[m];
201  }
202 
203  QDPIO::cout << "|psi2-psi|^2 = " << norm2(tmp1) << std::endl;
204  QDPIO::cout << "|chi2-chi|^2 = " << norm2(tmp2) << std::endl;
205 
206 
207  LatticePropagator quark_propagator, quark_prop_source;
208  XMLBufferWriter xml_buf;
209  int ncg_had;
210 
211  quark_prop_source = 1;
212  quark_propagator = zero;
213 
214  quarkProp4(quark_propagator, xml_buf, quark_prop_source,
215  S_f, u, CG_INVERTER, RsdCG, MaxCG, ncg_had);
216 
217  LatticePropagator q2;
218  XMLReader prop_xml;
219  readSzinQprop(prop_xml, q2, "szin.prop");
220 
221  QDPIO::cout << "|quark_prop|^2 = " << norm2(quark_propagator) << std::endl;
222  QDPIO::cout << "|q2|^2 = " << norm2(q2) << std::endl;
223  QDPIO::cout << "|q2-quark_prop|^2 = " << norm2(q2-quark_propagator) << std::endl;
224 #endif
225 
226  pop(xml);
227 
228  // Time to bolt
230 
231  exit(0);
232 }
Primary include file for CHROMA in application codes.
Create a simple ferm connection state.
Class for counted reference semantics.
Definition: handle.h:33
Unpreconditioned domain-wall fermion action.
Unpreconditioned Extended-Overlap (N&N) linear operator.
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.
SystemSolverResults_t InvCG2(const LinearOperator< LatticeFermionF > &M, const LatticeFermionF &chi, LatticeFermionF &psi, const Real &RsdCG, int MaxCG)
Conjugate-Gradient (CGNE) algorithm for a generic Linear Operator.
Definition: invcg2.cc:240
void readSzinFerm(LatticeFermion &q, const std::string &file)
Read a SZIN fermion. This is a simple memory dump reader.
void readSzinQprop(XMLReader &xml, LatticePropagator &q, const std::string &file)
Read a SZIN propagator file. 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
void quarkProp4(LatticeStaggeredPropagator &q_sol, XMLWriter &xml_out, const LatticeStaggeredPropagator &q_src, const StaggeredTypeFermAct< LatticeStaggeredFermion, multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > &S_f, Handle< FermState< LatticeStaggeredFermion, multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > > state, const GroupXML_t &invParam, QuarkSpinType quarkSpinType, int &ncg_had)
Given a complete propagator as a source, this does all the inversions needed.
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
multi1d< LatticeColorMatrix > P
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)
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > const multi1d< Real > enum InvType invType const multi1d< Real > & RsdCG
Definition: pbg5p_w.cc:30
QDP_error_exit("too many BiCG iterations", n_count, rsd_sq, cp, c, re_rvr, im_rvr, re_a, im_a, re_b, im_b)
static multi1d< LatticeColorMatrix > u
int n_count
Definition: invbicg.cc:78
LinOpSysSolverMGProtoClover::Q Q
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > const multi1d< Real > enum InvType invType const multi1d< Real > int MaxCG
Definition: pbg5p_w.cc:32
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)
A(A, psi, r, Ncb, PLUS)
int cb
Definition: invbicg.cc:120
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
const WilsonTypeFermAct< multi1d< LatticeFermion > > & S_f
Definition: pbg5p_w.cc:27
Double zero
Definition: invbicg.cc:106
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_dwflinop.cc:57