CHROMA
t_dwf4d.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 //! To insure linking of code, place the registered code flags here
13 /*! This is the bit of code that dictates what fermacts are in use */
15 {
16  bool foo = true;
17 
18  // All actions
20 
21  return foo;
22 }
23 
24 
25 /*
26  * Input
27  */
28 // Parameters which must be determined from the XML input
29 // and written to the XML output
30 struct Param_t
31 {
32  multi1d<int> nrow; // Lattice dimension
33  GroupXML_t invParam; // Inverter parameters
34 };
35 
36 //! Mega-structure of all input
38 {
43 };
44 
45 //! Parameters for running code
46 void read(XMLReader& xml, const std::string& path, Param_t& param)
47 {
48  XMLReader paramtop(xml, path);
49  read(paramtop, "nrow", param.nrow);
50  param.invParam = readXMLGroup(paramtop, "/InvertParam", "invType");
51 }
52 
53 
54 // Reader for input parameters
55 void read(XMLReader& xml, const std::string& path, Test_input_t& input)
56 {
57  XMLReader inputtop(xml, path);
58 
59  // Read all the input groups
60  try
61  {
62  // Read program parameters
63  read(inputtop, "Param", input.param);
64 
65  // Read in the gauge configuration info
66  read(inputtop, "Cfg", input.cfg);
67 
68  // Read 4D action stuff
69  {
70  XMLReader xml_action(inputtop, "Action4D");
71  std::ostringstream os;
72  xml_action.print(os);
73  input.action_4d = os.str();
74  }
75 
76  // Read 5D action stuff
77  {
78  XMLReader xml_action(inputtop, "Action5D");
79  std::ostringstream os;
80  xml_action.print(os);
81  input.action_5d = os.str();
82  }
83  }
84  catch (const std::string& e)
85  {
86  QDPIO::cerr << "Error reading test data: " << e << std::endl;
87  throw;
88  }
89 }
90 
91 
92 
93 
94 int main(int argc, char **argv)
95 {
96  // Put the machine into a known state
97  Chroma::initialize(&argc, &argv);
98 
99  QDPIO::cout << "linkage=" << linkage_hack() << std::endl;
100 
101  // Input parameter structure
102  Test_input_t input;
103 
104  // Instantiate xml reader for DATA
105  XMLReader xml_in(Chroma::getXMLInputFileName());
106 
107  // Read data
108  read(xml_in, "/t_dwf4d", input);
109 
110  // Specify lattice size, shape, etc.
111  Layout::setLattSize(input.param.nrow);
112  Layout::create();
113 
114  QDPIO::cout << "t_dwf4d" << std::endl;
115 
116  // Read in the configuration along with relevant information.
117  multi1d<LatticeColorMatrix> u(Nd);
118  XMLReader gauge_file_xml, gauge_xml;
119 
120  // Start up the gauge field
121  gaugeStartup(gauge_file_xml, gauge_xml, u, input.cfg);
122 
123  // Instantiate XML writer for XMLDAT
124 // XMLFileWriter xml_out("t_dwf4d.xml");
125  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
126  push(xml_out, "t_dwf4d");
127 
128  proginfo(xml_out); // Print out basic program info
129 
130  // Write out the input
131  write(xml_out, "Input", xml_in);
132 
133  // Write out the config header
134  write(xml_out, "Config_info", gauge_xml);
135 
136  // Check if the gauge field configuration is unitarized
137  unitarityCheck(u);
138 
139  // Calculate some gauge invariant observables just for info.
140  MesPlq(xml_out, "Observables", u);
141  xml_out.flush();
142 
143  //
144  // Initialize fermion action
145  //
146  std::istringstream xml_s_5d(input.action_5d);
147  std::istringstream xml_s_4d(input.action_4d);
148  XMLReader fermacttop_5d(xml_s_5d);
149  XMLReader fermacttop_4d(xml_s_4d);
150  const std::string fermact_path_5d = "/Action5D/FermionAction";
151  const std::string fermact_path_4d = "/Action4D/FermionAction";
152  std::string fermact_5d;
153  std::string fermact_4d;
154 
155  try
156  {
157  read(fermacttop_5d, fermact_path_5d + "/FermAct", fermact_5d);
158  read(fermacttop_4d, fermact_path_4d + "/FermAct", fermact_4d);
159  }
160  catch (const std::string& e)
161  {
162  QDPIO::cerr << "Error reading fermact: " << e << std::endl;
163  throw;
164  }
165  catch (const char* e)
166  {
167  QDPIO::cerr << "Error reading fermact: " << e << std::endl;
168  throw;
169  }
170 
171  QDPIO::cout << "FermAct5D = " << fermact_5d << std::endl;
172  QDPIO::cout << "FermAct4D = " << fermact_4d << std::endl;
173 
174 
175  // Deal with auxiliary (and polymorphic) state information
176  // eigenvectors, eigenvalues etc. The XML for this should be
177  // stored as a std::string called "stateInfo" in the param struct.
178 
179  try {
180 
181  // Make a reader for the stateInfo
182  const std::string state_info_path_5d = "/Action5D/StateInfo";
183  const std::string state_info_path_4d = "/Action4D/StateInfo";
184  XMLReader state_info_xml_5d(fermacttop_5d,state_info_path_5d);
185  XMLReader state_info_xml_4d(fermacttop_4d,state_info_path_4d);
186 
187  // Typedefs to save typing
188  typedef LatticeFermion T;
189  typedef multi1d<LatticeColorMatrix> P;
190  typedef multi1d<LatticeColorMatrix> Q;
191 
192  // DWF-like 5D Wilson-Type stuff
193  bool success = false;
194 
195  QDPIO::cerr << "create dwf = " << fermact_5d << std::endl;
196 
198  S_f_5d(TheWilsonTypeFermAct5DFactory::Instance().createObject(fermact_5d,
199  fermacttop_5d,
200  fermact_path_5d));
201 
202  Handle< FermState<T,P,Q> > state_5d(S_f_5d->createState(u,
203  state_info_xml_5d,
204  state_info_path_5d));
205 
206  // Overlap-like stuff
207  QDPIO::cerr << "create overlap" << std::endl;
209  S_f_4d(TheWilsonTypeFermActFactory::Instance().createObject(fermact_4d,
210  fermacttop_4d,
211  fermact_path_4d));
212 
213 
214  Handle< FermState<T,P,Q> > state_4d(S_f_4d->createState(u,
215  state_info_xml_4d,
216  state_info_path_4d));
217 
218 
219  //-------------------------------------------------------------------------------
220  Handle< LinearOperator<T> > A5(S_f_5d->linOp4D(state_5d,S_f_5d->getQuarkMass(),input.param.invParam));
221  Handle< LinearOperator<T> > A4(S_f_4d->linOp(state_4d));
222 
223  LatticeFermion psi, chi;
224 
225  random(psi);
226  random(chi);
227 
228  LatticeFermion tmp1,tmp2;
229  QDPIO::cout << "A5 plus" << std::endl;
230  (*A5)(tmp1, psi, PLUS);
231  DComplex nn5_plus = innerProduct(chi, tmp1);
232  QDPIO::cout << "A5 minus" << std::endl;
233  (*A5)(tmp2, chi, MINUS);
234  DComplex nn5_minus = innerProduct(tmp2, psi);
235 
236  LatticeFermion tmp3,tmp4;
237  QDPIO::cout << "A4 plus" << std::endl;
238  (*A4)(tmp3, psi, PLUS);
239  DComplex nn4_plus = innerProduct(chi, tmp3);
240  QDPIO::cout << "A4 minus" << std::endl;
241  (*A4)(tmp4, chi, MINUS);
242  DComplex nn4_minus = innerProduct(tmp4, psi);
243 
244  push(xml_out,"Innerprods");
245  write(xml_out, "nn5_plus", nn5_plus);
246  write(xml_out, "nn4_plus", nn4_plus);
247  write(xml_out, "norm_diff_plus", Real(norm2(tmp1-tmp3)));
248  write(xml_out, "nn5_minus", nn5_minus);
249  write(xml_out, "nn4_minus", nn4_minus);
250  write(xml_out, "norm_diff_minus", Real(norm2(tmp2-tmp4)));
251  pop(xml_out);
252 
253  }
254  catch (const std::string& e)
255  {
256  QDPIO::cerr << "Error in t_dwf4d: " << e << std::endl;
257  throw;
258  }
259  catch (const char* e)
260  {
261  QDPIO::cerr << "Error in t_dwf4d: " << e << std::endl;
262  throw;
263  }
264 
265  pop(xml_out);
266 
267  // Time to bolt
269 
270  exit(0);
271 }
Primary include file for CHROMA in application codes.
Class for counted reference semantics.
Definition: handle.h:33
static T & Instance()
Definition: singleton.h:432
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 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.
Nd
Definition: meslate.cc:74
Double tmp2
Definition: mesq.cc:30
Double tmp3
Definition: mesq.cc:31
multi1d< LatticeColorMatrix > P
BinaryReturn< C1, C2, FnInnerProduct >::Type_t innerProduct(const QDPSubType< T1, C1 > &s1, const QDPType< T2, C2 > &s2)
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
LinOpSysSolverMGProtoClover::Q Q
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
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)
std::string getXMLInputFileName()
Get input file name.
Definition: chroma_init.cc:88
LatticeFermion psi
Definition: mespbg5p_w.cc:35
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
::std::string string
Definition: gtest.h:1979
Gauge configuration structure.
Definition: cfgtype_io.h:16
Hold group xml and type id.
Parameters for running program.
Definition: qpropadd.cc:17
SysSolverCGParams invParam
GroupXML_t invParam
Definition: t_dwf4d.cc:33
multi1d< int > nrow
Definition: qpropadd.cc:18
Mega-structure of all input.
Definition: t_dwf4d.cc:38
std::string action_4d
Definition: t_dwf4d.cc:42
Param_t param
Definition: t_dwf4d.cc:39
std::string action_5d
Definition: t_dwf4d.cc:41
Cfg_t cfg
Definition: t_dwf4d.cc:40
bool linkage_hack()
To insure linking of code, place the registered code flags here.
Definition: t_dwf4d.cc:14
int main(int argc, char **argv)
Definition: t_dwf4d.cc:94