CHROMA
t_prec_contfrac.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <cstdio>
4 #include "chroma.h"
5 
6 using namespace Chroma;
7 
8 struct App_input_t {
9  Cfg_t cfg;
11  multi1d<int> nrow;
12  multi1d<int> boundary;
15 };
16 
17 // Reader for input parameters
18 void read(XMLReader& xml, const std::string& path, App_input_t& input)
19 {
20  XMLReader inputtop(xml, path);
21 
22  // Read the input
23  try
24  {
25  // Read in the gauge configuration info
26  read(inputtop, "Cfg", input.cfg);
27  read(inputtop, "nrow", input.nrow);
28  read(inputtop, "UnprecFermAct", input.p_unprec);
29  read(inputtop, "PrecFermAct", input.p_prec);
30  }
31  catch (const std::string& e)
32  {
33  QDPIO::cerr << "Error reading data: " << e << std::endl;
34  throw;
35  }
36 }
37 
38 
39 int main(int argc, char **argv)
40 {
41  // Put the machine into a known state
42  Chroma::initialize(&argc, &argv);
43 
44  App_input_t input;
45  XMLReader xml_in(Chroma::getXMLInputFileName());
46 
47  try {
48  read(xml_in, "/ContFracTest", input);
49  }
50  catch( const std::string& e) {
51  QDPIO::cerr << "Caught Exception : " << e << std::endl;
52  QDP_abort(1);
53  }
54 
55 
56  // Setup the lattice
57  Layout::setLattSize(input.nrow);
58  Layout::create();
59 
60  multi1d<LatticeColorMatrix> u(Nd);
61  XMLReader gauge_file_xml, gauge_xml;
62  gaugeStartup(gauge_file_xml, gauge_xml, u, input.cfg);
63 
64  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
65  push(xml_out,"ContFracTest");
66 
67 
68  // Measure the plaquette on the gauge
69  MesPlq(xml_out, "Observables", u);
70  xml_out.flush();
71 
72  // Initialize fermion actions
73  UnprecOvlapContFrac5DFermActArray S_unprec(fbc, input.p_unprec);
75 
76 
77  // Create an overlap state
78  std::istringstream state_info_is(input.stateInfo);
79  XMLReader state_info_xml(state_info_is);
80  std::string state_info_path="/StateInfo";
81 
82  Handle< const ConnectState > state(S_prec.createState(u, state_info_xml, state_info_path));
83 
84  // Make an unprec linOp
85  Handle< const UnprecLinearOperator< multi1d<LatticeFermion>, multi1d<LatticeColorMatrix> > > M_u( S_unprec.linOp(state) );
86 
87  // Make the prec linOp
88  Handle< const EvenOddPrecLinearOperator< multi1d<LatticeFermion>, multi1d<LatticeColorMatrix> > > M_e( S_prec.linOp(state));
89 
90  QDPIO::cout << "Unprec LinOp size = " << M_u->size() << std::endl;
91  QDPIO::cout << "Prec LinOp size = " << M_e->size() << std::endl;
92 
93  int N5 = M_u->size();
94  multi1d<LatticeFermion> s(N5);
95  multi1d<LatticeFermion> Mu_s(N5);
96  multi1d<LatticeFermion> Me_s(N5);
97  multi1d<LatticeFermion> r(N5);
98 
99  for(int i=0; i<N5; i++) {
100  gaussian(s[i]);
101  Mu_s[i]=zero;
102  Me_s[i]=zero;
103  r[i] = zero;
104  }
105 
106  // Normalise Gaussien
107  Double s_norm10 = norm2(s[0]);
108  for(int i=1; i < s.size(); i++) {
109  s_norm10 += norm2(s[i]);
110  }
111 
112  for(int i=0; i < s.size(); i++) {
113  s[i] /= sqrt(s_norm10);
114  }
115 
116 
117  (*M_u)(Mu_s, s, PLUS);
118  (*M_e).unprecLinOp(Me_s, s, PLUS);
119 
120  for(int i=0; i < N5; i++) {
121  r[i] = Mu_s[i] - Me_s[i];
122  QDPIO::cout << "i[0]= " << i << " || r [" << i << "] || = "
123  << sqrt(norm2(r[i], rb[0])) << std::endl;
124  QDPIO::cout << "i[1]= " << i << " || r [" << i << "] || = "
125  << sqrt(norm2(r[i], rb[1])) << std::endl;
126  }
127 
128  Mu_s = zero;
129  Me_s = zero;
130  (*M_u)(Mu_s, s, MINUS);
131  (*M_e).unprecLinOp(Me_s, s, MINUS);
132 
133  for(int i=0; i < N5; i++) {
134  r[i] = Mu_s[i] - Me_s[i];
135  QDPIO::cout << "i = " << i << " || r [" << i << "] || = "
136  << sqrt(norm2(r[i])) << std::endl;
137  }
138 
139  // Now some solver tests
140  multi1d<LatticeFermion> source(N5);
141  for(int i=0; i < N5; i++) {
142  gaussian(source[i]);
143  }
144  Double source_norm = sqrt(norm2(source));
145  for(int i=0; i < N5; i++) {
146  source[i] /= source_norm;
147  }
148 
149  multi1d<LatticeFermion> unprec_source(N5);
150  multi1d<LatticeFermion> prec_source(N5);
151  for(int i=0; i < N5; i++) {
152  unprec_source[i] = source[i];
153  prec_source[i] = source[i];
154  }
155 
156  multi1d<LatticeFermion> unprec_soln(N5);
157  multi1d<LatticeFermion> prec_soln(N5);
158  unprec_soln = zero;
159  prec_soln = zero;
160 
161  Real RsdCG = Real(1.0e-6);
162  int MaxCG = 500;
163  int n_count_prec=0;
164  int n_count_unprec=0;
165 
166  // Solve the unpreconditioned system:
167  {
168  multi1d<LatticeFermion> tmp(N5);
169  (*M_u)(tmp, unprec_source, MINUS);
170  InvCG2(*M_u, tmp, unprec_soln, RsdCG, MaxCG, n_count_unprec);
171  }
172 
173  // Solve the preconditioned system.
174  //
175  // Set up source on odd checkerboards
176  // S_e = source_e
177  // S_o = source_o - QoeQee^{-1} source_e
178  {
179  multi1d<LatticeFermion> tmp(N5);
180  multi1d<LatticeFermion> tmp2(N5);
181  tmp=zero;
182  tmp2=zero;
183  M_e->evenEvenInvLinOp(tmp, prec_source, PLUS);
184  M_e->oddEvenLinOp(tmp2, tmp, PLUS);
185 
186  multi1d<LatticeFermion> tmp_source(N5);
187  for(int i=0; i < N5; i++) {
188  // Take the even piece of the normal source
189  tmp_source[i][rb[0]] = prec_source[i];
190 
191  // Take the odd piece - QoeQee^{-1} even piece
192  tmp_source[i][rb[1]] = prec_source[i] - tmp2[i];
193  }
194 
195  // CGNE on the odd source only
196  multi1d<LatticeFermion> cgne_source(N5);
197  multi1d<LatticeFermion> tmp_soln(N5);
198  cgne_source=zero;
199  tmp_soln=zero;
200 
201  (*M_e)(cgne_source, tmp_source, MINUS);
202  InvCG2(*M_e, cgne_source, tmp_soln, RsdCG, MaxCG, n_count_prec);
203 
204  // Now reconstruct the solutions.
205  tmp = zero;
206  tmp2 = zero;
207  // tmp1 = D_eo tmp_soln_o
208  M_e->evenOddLinOp(tmp, tmp_soln, PLUS);
209 
210  // tmp2 = S_e - tmp_1
211  for(int i=0; i < N5; i++) {
212  tmp2[i][rb[0]] = tmp_source[i] - tmp[i];
213  }
214  M_e->evenEvenInvLinOp(prec_soln, tmp2, PLUS);
215 
216  // Copy off parts
217  for(int i=0; i < N5; i++) {
218  prec_soln[i][rb[1]] = tmp_soln[i];
219  }
220  }
221 
222  // Check the solutions
223  (*M_u)(r, unprec_soln, PLUS);
224  Double r_norm =Double(0);
225  for(int i=0; i < N5; i++) {
226  r[i] -= source[i];
227  r_norm += norm2(r[i]);
228  }
229  QDPIO::cout << "|| source - M_u unprec_soln || = " << sqrt(r_norm) << std::endl;
230 
231  (*M_u)(r, prec_soln, PLUS);
232  r_norm=0;
233  for(int i=0; i < N5; i++) {
234  r[i] -= source[i];
235  r_norm += norm2(r[i]);
236  }
237  QDPIO::cout << "|| source - M_u prec_soln || = " << sqrt(r_norm) << std::endl;
238 
239  (*M_e).unprecLinOp(r, unprec_soln, PLUS);
240  r_norm=0;
241  for(int i=0; i < N5; i++) {
242  r[i] -= source[i];
243  r_norm += norm2(r[i]);
244  }
245  QDPIO::cout << "|| source - M_e unprec_soln || = " << sqrt(r_norm) << std::endl;
246 
247  (*M_e).unprecLinOp(r, prec_soln, PLUS);
248  r_norm=0;
249  for(int i=0; i < N5; i++) {
250  r[i] -= source[i];
251  r_norm += norm2(r[i]);
252  }
253  QDPIO::cout << "|| source - M_e prec_soln || = " << sqrt(r_norm) << std::endl;
254 
255  // Test EvenEvenInv LinOp
256  {
257  multi1d<LatticeFermion> f_even(N5);
258  multi1d<LatticeFermion> t1(N5);
259  multi1d<LatticeFermion> t2(N5);
260 
261  f_even = zero;
262  t1=zero;
263  t2=zero;
264  for(int i=0; i < N5; i++) {
265  f_even[i][rb[1]] = zero ; // Zilch out the odd ones
266  f_even[i][rb[0]] = source[i];
267  }
268 
269  M_e->evenEvenLinOp(t1, f_even, PLUS);
270  M_e->evenEvenInvLinOp(t2, t1, PLUS);
271 
272  r_norm=0;
273  for(int i=0; i < N5; i++) {
274  r[i][rb[0]] = t2[i];
275  r[i][rb[0]] -= f_even[i];
276 
277  r_norm += norm2(r[i], rb[0]);
278  }
279  QDPIO::cout << "|| source_even - Qee^{-1}Qee sorce_even || = "
280  << sqrt(r_norm) << std::endl;
281 
282  }
283  pop(xml_out);
285 
286  exit(0);
287 }
Primary include file for CHROMA in application codes.
5D continued fraction overlap action (Borici,Wenger, Edwards)
EvenOddPrecConstDetLinearOperatorArray< T, P, Q > * linOp(Handle< FermState< T, P, Q > > state) const
Produce a linear operator for this 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
5D continued fraction overlap action (Borici,Wenger, Edwards)
UnprecLinearOperatorArray< T, P, Q > * linOp(Handle< FermState< T, P, Q > > state) const
Produce a linear operator for this action.
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void gaugeStartup(XMLReader &gauge_file_xml, XMLReader &gauge_xml, multi1d< LatticeColorMatrix > &u, Cfg_t &cfg)
Initialize the gauge fields.
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
Nd
Definition: meslate.cc:74
Double tmp2
Definition: mesq.cc:30
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
static multi1d< LatticeColorMatrix > u
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > const multi1d< Real > enum InvType invType const multi1d< Real > int MaxCG
Definition: pbg5p_w.cc:32
int i
Definition: pbg5p_w.cc:55
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
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
Double zero
Definition: invbicg.cc:106
multi1d< LatticeFermion > s(Ncb)
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
Double r_norm
Definition: pade_trln_w.cc:86
UnprecOvlapContFrac5DFermActParams p_unprec
EvenOddPrecOvlapContFrac5DFermActParams p_prec
multi1d< int > nrow
Definition: t_invborici.cc:22
std::string stateInfo
Gauge configuration structure.
Definition: cfgtype_io.h:16
int main(int argc, char **argv)