CHROMA
t_solver_accum.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Test 4d fermion actions
3  */
4 
5 #include <iostream>
6 #include <cstdio>
7 
8 #include "chroma.h"
9 
10 
14 
15 using namespace Chroma;
16 
17 //! To insure linking of code, place the registered code flags here
18 /*! This is the bit of code that dictates what fermacts are in use */
20 {
21  bool foo = true;
22  // All actions
29 
30  return foo;
31 }
32 
33 
34 
35 int main(int argc, char **argv)
36 {
37  // Put the machine into a known state
38  Chroma::initialize(&argc, &argv);
39 
40  QDPIO::cout << "linkage=" << linkage_hack() << std::endl;
41 
42 
43  multi1d<int> nrow(Nd);
44  for(int i=0; i < Nd-1; i++) {
45  nrow[i] = 4;
46  }
47  nrow[Nd-1] = 16;
48 
49  // Specify lattice size, shape, etc.
50  Layout::setLattSize(nrow);
51  Layout::create();
52 
53  QDPIO::cout << "t_temp_prec" << std::endl;
54 
55  // Start up a weak field
56  struct Cfg_t config = { CFG_TYPE_WEAK_FIELD, "dummy" };
57  multi1d<LatticeColorMatrix> u(Nd);
58  XMLReader gauge_file_xml, gauge_xml;
59  gaugeStartup(gauge_file_xml, gauge_xml, u, config);
60  // Check if the gauge field configuration is unitarized
62 
63  // Instantiate XML writer for XMLDAT
64  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
65  push(xml_out, "t_temp_prec");
66  proginfo(xml_out); // Print out basic program info
67 
68 
69  // Calculate some gauge invariant observables just for info.
70  MesPlq(xml_out, "Observables", u);
71  xml_out.flush();
72  pop(xml_out);
73 
74  XMLReader xml_in("./t_solver_accum.ini.xml");
75  ReadRatApproxEnv::Params rat_approx_param;
76  GroupXML_t fermact_group, fermact_5d_group,
77  inv_param_group;
78 
79  try {
80  XMLReader paramtop(xml_in, "/Params");
81  fermact_group=readXMLGroup(paramtop,
82  "./FermionAction",
83  "FermAct");
84 
85  fermact_5d_group = readXMLGroup(paramtop,
86  "./FermionAction5D",
87  "FermAct");
88 
89  QDPIO::cout << "fermact group read" << std::endl;
90  inv_param_group=readXMLGroup(paramtop,
91  "./InvertParam",
92  "invType");
93 
94  QDPIO::cout << "inv_param_group read" << std::endl;
95 
96 
97  read(paramtop, "./Approximation", rat_approx_param);
98  QDPIO::cout << "Approx Read" << std::endl;
99  }
100  catch(const std::string& e) {
101  QDPIO::cerr << "XML Error returned : " << e << std::endl;
102  QDP_abort(1);
103  }
104 
105  // Typedefs to save typing
106  typedef LatticeFermion T;
107  typedef multi1d<LatticeColorMatrix> P;
108  typedef multi1d<LatticeColorMatrix> Q;
109 
110  try {
111  std::istringstream fermact_xml_is( fermact_group.xml);
112  XMLReader fermact_reader(fermact_xml_is);
113  // Create unprec and Prec actions
115  S( TheWilsonTypeFermActFactory::Instance().createObject(fermact_group.id,
116  fermact_reader,
117  fermact_group.path) );
118 
119 
120  // Now create a FermState
121  Handle< FermState<T, P, Q> > fs( S->createState(u) );
122  Handle< MdagMMultiSystemSolver<T> > multi_solver( S->mInvMdagM(fs, inv_param_group) );
123  Handle< MdagMMultiSystemSolverAccumulate<T> > multi_solver_acc( S->mInvMdagMAcc(fs, inv_param_group) );
124 
125  Handle< LinearOperator<T> > M(S->linOp(fs));
126 
127 
128  const Subset& subset = M->subset();
129 
130  LatticeFermion rhs;
131  gaussian(rhs, subset); // Use this as a source
132 
133 
134  LatticeFermion psi1, psi2; // The two answers
135 
136  RemezCoeff_t pfe, ipfe;
137  ReadRatApprox approx_reader(rat_approx_param);
138  approx_reader(pfe, ipfe);
139 
140  // Work with pfe
141  QDPIO::cout << "Working With PFE: A = " << pfe.norm << std::endl;
142  for(int i=0; i < pfe.pole.size(); i++) {
143  QDPIO::cout << " res["<<i<<"]=" << pfe.res[i] << " pole[" << i
144  << "]=" << pfe.pole[i] << std::endl;
145  }
146 
147  {
148  {
149 
150  multi1d<LatticeFermion> temp_ferms(pfe.pole.size());
151  for(int i=0; i < temp_ferms.size(); i++) {
152  temp_ferms[i][subset] = zero;
153  }
154  (*multi_solver)(temp_ferms, pfe.pole,rhs);
155 
156 
157  psi1[subset] = pfe.norm*rhs;
158 
159  for(int i=0; i < temp_ferms.size(); i++) {
160  psi1[subset] += pfe.res[i] * temp_ferms[i];
161  }
162  }
163 
164  /* Do the accumulated solver */
165  (*multi_solver_acc)(psi2,
166  pfe.norm,
167  pfe.res,
168  pfe.pole,
169  rhs);
170 
171 
172  // Compare psi1 and psi2;
173  LatticeFermion diff;
174  diff[subset] = psi1-psi2;
175  Double n1 = sqrt(norm2(diff, subset));
176  Double n2 = sqrt(norm2(psi1, subset));
177 
178  QDPIO::cout << "|| psi1 - psi2 ||=" << n1 << std::endl;
179  QDPIO::cout << "|| psi1 - psi2 ||/||psi1||= " << n1/n2 << std::endl;
180 
181  }
182 
183 
184 
185  // Now Array versions
186  std::istringstream fermact_5d_xml_is( fermact_5d_group.xml);
187  XMLReader fermact_5d_reader(fermact_5d_xml_is);
188 
190  S5( TheWilsonTypeFermAct5DFactory::Instance().createObject(fermact_5d_group.id,
191  fermact_5d_reader,
192  fermact_5d_group.path) );
193 
194 
195  // Now create a FermState
196  Handle< FermState<T, P, Q> > fs5( S5->createState(u) );
197  Handle< MdagMMultiSystemSolverArray<T> > multi_solver_5d( S5->mInvMdagM(fs, inv_param_group) );
198  Handle< MdagMMultiSystemSolverAccumulateArray<T> > multi_solver_acc_5d( S5->mInvMdagMAcc(fs, inv_param_group) );
199 
200  Handle< LinearOperatorArray<T> > M5(S5->linOp(fs));
201 
202 
203  const Subset& sub5 = M5->subset();
204  const int N5 = M5->size();
205 
206  multi1d<LatticeFermion> psi5(N5);
207  multi1d<LatticeFermion> psi5_2(N5);
208  multi1d<LatticeFermion> rhs5(N5);
209  for(int n=0; n < N5; n++) {
210  psi5[n][sub5] = zero;
211  psi5_2[n][sub5] = zero;
212  gaussian(rhs5[n],sub5);
213  }
214 
215  {
216  multi1d<multi1d<LatticeFermion> > tmp5(pfe.pole.size());
217  for(int i=0; i< pfe.pole.size(); i++) {
218  tmp5[i].resize(N5);
219  for(int n=0; n < N5; n++) {
220  tmp5[i][n][sub5]=zero;
221  }
222  }
223 
224  (*multi_solver_5d)(tmp5, pfe.pole, rhs5);
225 
226  for(int n=0; n < N5; n++) {
227  psi5[n][sub5] = pfe.norm*rhs5[n];
228  }
229  for(int i=0; i < pfe.pole.size(); i++) {
230  for(int n=0; n < N5; n++) {
231  psi5[n][sub5] += pfe.res[i] * tmp5[i][n];
232  }
233  }
234  }
235 
236  (*multi_solver_acc_5d)(psi5_2, pfe.norm, pfe.res, pfe.pole, rhs5);
237 
238  multi1d<LatticeFermion> diff5(N5);
239  for(int n=0; n < N5; n++) {
240  diff5[n][sub5] = psi5_2[n] - psi5[n];
241  }
242  Double norm5_diff = norm2(diff5, sub5);
243  Double norm5_psi = norm2(psi5, sub5);
244  QDPIO::cout << "|| psi5_1 - psi5_2 ||=" << norm5_diff << std::endl;
245  QDPIO::cout << "|| psi5_1 - psi5_2 ||/||psi5_1||= " << norm5_diff/norm5_psi << std::endl;
246 
247  }
248  catch(const std::string& e) {
249  QDPIO::cerr << "Caught exception: " << e << std::endl;
250  }
251 
252  // Time to bolt
254 
255  exit(0);
256 }
Primary include file for CHROMA in application codes.
Class for counted reference semantics.
Definition: handle.h:33
Remez type of rational approximations.
static T & Instance()
Definition: singleton.h:432
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void unitarityCheck(const multi1d< LatticeColorMatrixF3 > &u)
Check the unitarity of color matrix in SU(N)
Definition: unit_check.cc:20
void gaugeStartup(XMLReader &gauge_file_xml, XMLReader &gauge_xml, multi1d< LatticeColorMatrix > &u, Cfg_t &cfg)
Initialize the gauge fields.
void proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
@ CFG_TYPE_WEAK_FIELD
unsigned n
Definition: ldumul_w.cc:36
Nd
Definition: meslate.cc:74
Register MdagM system solvers.
Register MdagM system solvers.
multi1d< LatticeColorMatrix > P
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
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
LinOpSysSolverMGProtoClover::Q Q
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
int i
Definition: pbg5p_w.cc:55
void initialize(int *argc, char ***argv)
Chroma initialisation routine.
Definition: chroma_init.cc:114
void finalize(void)
Chroma finalization routine.
Definition: chroma_init.cc:308
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
Double zero
Definition: invbicg.cc:106
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
Remez-type rational approximation.
Gauge configuration structure.
Definition: cfgtype_io.h:16
Hold group xml and type id.
Params for Remez type rational approximation.
Convenient structure to package Remez coeffs.
Definition: remez_coeff.h:19
multi1d< Real > pole
Definition: remez_coeff.h:21
multi1d< Real > res
Definition: remez_coeff.h:20
bool linkage_hack()
To insure linking of code, place the registered code flags here.
int main(int argc, char **argv)