CHROMA
inline_polar_source_w.cc
Go to the documentation of this file.
1 // Code for sequential source construction
2 
3 #error "THIS CODE IS NOT READY YET"
4 
5 #include <iostream>
6 #include <cstdio>
7 
8 #include "chroma.h"
9 
10 using namespace Chroma;
11 
12 
13 /*
14  * Input
15  */
16 
17 //! Propagators
18 struct Prop_t
19 {
20  std::string prop_file; // The file is expected to be in SciDAC format!
21  std::string seqsource_file; // The file is expected to be in SciDAC format!
22  QDP_volfmt_t seqsource_volfmt;
23 };
24 
25 
26 //! Mega-structure of all input
28 {
29  PropSource_t param;
32 };
33 
34 
35 //! Propagator parameters
36 void read(XMLReader& xml, const std::string& path, Prop_t& input)
37 {
38  XMLReader inputtop(xml, path);
39 
40  read(inputtop, "prop_file", input.prop_file);
41  read(inputtop, "seqsource_file", input.seqsource_file);
42  read(inputtop, "seqsource_volfmt", input.seqsource_volfmt);
43 }
44 
45 
46 // Reader for input parameters
47 void read(XMLReader& xml, const std::string& path, SeqSource_input_t& input)
48 {
49  XMLReader inputtop(xml, path);
50 
51  // Read the input
52  try
53  {
54  // The parameters holds the version number
55  read(inputtop, "Param", input.param);
56 
57  // Read in the gauge configuration info
58  read(inputtop, "Cfg", input.cfg);
59 
60  // Read in the forward_prop/seqsource info
61  read(inputtop, "Prop", input.prop);
62  }
63  catch (const std::string& e)
64  {
65  QDPIO::cerr << "Error reading data: " << e << std::endl;
66  throw;
67  }
68 }
69 
70 
71 //! Sequential source generation
72 /*
73  * \defgroup seqsource Sequential source generation
74  * \ingroup main
75  *
76  * Read quark propagators, convert into sequential sources
77  *
78  */
79 
80 int main(int argc, char **argv)
81 {
82  // Put the machine into a known state
83  QDP_initialize(&argc, &argv);
84 
85  START_CODE();
86 
87  // Input parameter structure
88  SeqSource_input_t input;
89 
90  // Instantiate xml reader for DATA
91  XMLReader xml_in("DATA");
92 
93  // Read data
94  read(xml_in, "/seqsource", input);
95 
96  // Specify lattice size, shape, etc.
97  Layout::setLattSize(input.param.nrow);
98  Layout::create();
99 
100  // Sanity checks
101  QDPIO::cout << std::endl << " Gauge group: SU(" << Nc << ")" << std::endl;
102 
103  QDPIO::cout << " Computing sequential source of type "
104  << input.param.source_type << std::endl;
105 
106  QDPIO::cout << " Volume: " << input.param.nrow[0];
107  for (int i=1; i<Nd; ++i) {
108  QDPIO::cout << " x " << input.param.nrow[i];
109  }
110  QDPIO::cout << std::endl;
111 
112 
113  // Read in the configuration along with relevant information.
114  multi1d<LatticeColorMatrix> u(Nd);
115  XMLReader gauge_file_xml, gauge_xml;
116 
117  // Startup gauge
118  gaugeStartup(gauge_file_xml, gauge_xml, u, input.cfg);
119 
120  // Instantiate XML writer for XMLDAT
121  XMLFileWriter xml_out("XMLDAT");
122  push(xml_out, "seqsource");
123 
124  proginfo(xml_out); // Print out basic program info
125 
126  // Write out the input
127  write(xml_out, "Input", xml_in);
128 
129  // Write out the config header
130  write(xml_out, "Config_info", gauge_xml);
131 
132  push(xml_out, "Output_version");
133  write(xml_out, "out_version", 1);
134  pop(xml_out);
135 
136  xml_out.flush();
137 
138 
139  // Check if the gauge field configuration is unitarized
140  unitarityCheck(u);
141 
142  // Calculate some gauge invariant observables just for info.
145 
146  push(xml_out, "Observables");
147  write(xml_out, "w_plaq", w_plaq);
148  write(xml_out, "s_plaq", s_plaq);
149  write(xml_out, "t_plaq", t_plaq);
150  write(xml_out, "link", link);
151  pop(xml_out);
152 
153  xml_out.flush();
154 
155 
156  //
157  // Read the quark propagator and extract headers
158  //
159  LatticePropagator quark_propagator;
161  PropSource_t source_header;
162  {
163  XMLReader prop_file_xml, prop_record_xml;
164 
165  QDPIO::cout << "Attempt to read forward propagator" << std::endl;
166  readQprop(prop_file_xml,
167  prop_record_xml, quark_propagator,
168  input.prop.prop_file, QDPIO_SERIAL);
169  QDPIO::cout << "Forward propagator successfully read" << std::endl;
170 
171  // Try to invert this record XML into a ChromaProp struct
172  // Also pull out the id of this source
173  try
174  {
175  read(prop_record_xml, "/Propagator/ForwardProp", prop_header);
176  read(prop_record_xml, "/Propagator/PropSource", source_header);
177  }
178  catch (const std::string& e)
179  {
180  QDPIO::cerr << "Error extracting forward_prop header: " << e << std::endl;
181  throw;
182  }
183 
184  // Save prop input
185  write(xml_out, "Propagator_info", prop_record_xml);
186  }
187 
188  // Derived from input prop
189  int j_decay = source_header.j_decay;
190 // multi1d<int> boundary = prop_header.boundary; // not currently needed
191  multi1d<int> t_source = source_header.t_source;
192 
193  // Initialize the slow Fourier transform phases
194  SftMom phases(0, true, j_decay);
195 
196  // Sanity check - write out the norm2 of the forward prop in the j_decay direction
197  // Use this for any possible verification
198  {
199  multi1d<Double> forward_prop_corr = sumMulti(localNorm2(quark_propagator),
200  phases.getSet());
201 
202  push(xml_out, "Forward_prop_correlator");
203  write(xml_out, "forward_prop_corr", forward_prop_corr);
204  pop(xml_out);
205  }
206 
207  //------------------ Start main body of calculations -----------------------------
208 
209  //
210  // Construct the sequential source
211  //
212  LatticePropagator quark_prop_src = zero;
213  LatticePropagator quark_prop_tmp;
214  LatticeColorMatrix uu;
215  multi1d<LatticeColorMatrix> ua(Nd);
216  LatticeComplex a;
217  Real alocr, aloci;
218  Complex aloc;
219  multi1d<int> size = input.param.nrow;
220  multi1d<int> coords(Nd);
221 
222 // Create a LatticeComplex em field
223 
224  for (int i=0; i<size[0]; ++i) {
225  for (int j=0; j<size[1]; ++j) {
226  for (int k=0; k<size[2]; ++k) {
227  for (int l=0; l<size[3]; ++l) {
228 
229 // If we want to do a magnetic insertion (note the pretty arbitrary,
230 // but not completely stupid, strength of the external gauge field -
231 // in final results, this strength is an overall factor and will be
232 // divided out in data analysis):
233 
234 // alocr=0.0;
235 // aloci = (float) j;
236 //
237 // if ( j > (size[1]/2) ) {
238 // aloci = aloci - (float) size[1];
239 // };
240 //
241 // aloci=aloci*10.0*6.2831852/(size[1]*size[0]);
242 
243 
244 // If we want to do an electric insertion:
245 
246 // alocr=0.0;
247 // aloci = (float) l;
248 // aloci=aloci*10.0*6.2831852/(size[2]*size[3]);
249 
250 
251 // If we want to do an A^2 insertion (electric):
252 
253  alocr = (float) (l*l);
254  aloci = 0.0;
255  alocr=alocr*10.0*6.2831852/(size[2]*size[3]);
256  alocr=alocr*10.0*6.2831852/(size[2]*size[3]);
257  alocr=alocr*(-0.5000000);
258 
259 
260 // So let's write that into the field:
261 
262  aloc = cmplx(alocr,aloci);
263  coords[0]=i;
264  coords[1]=j;
265  coords[2]=k;
266  coords[3]=l;
267  pokeSite(a, aloc, coords);
268  };
269  };
270  };
271  };
272 
273 // ok, so now we have a LatticeComplex containing our em field
274 // next, make a LatticeColorMatrix out of it
275 
276  ua[0] = zero;
277  ua[1] = zero;
278  ua[2] = zero;
279  ua[3] = zero;
280 
281 // Pick which component of the gauge field we're making nontrivial
282 // (for electric insertion, ua[2], for magnetic insertion, ua[0]);
283 
284  for (int elem=0; elem<Nc; ++elem) {
285 // pokeColor(ua[0], a, elem, elem);
286 // pokeColor(ua[1], a, elem, elem);
287  pokeColor(ua[2], a, elem, elem);
288 // pokeColor(ua[3], a, elem, elem);
289  };
290 
291 // and now put it all together ...
292 
293  int i=1;
294 
295  for (int j=0; j<Nd; ++j) {
296 
297  uu = ua[j]*u[j];
298  quark_prop_tmp = quark_prop_src;
299  quark_prop_src = quark_prop_tmp - uu*shift(quark_propagator, FORWARD, j);
300  quark_prop_tmp = quark_prop_src;
301  quark_prop_src = quark_prop_tmp + uu*(Gamma(i)*shift(quark_propagator, FORWARD, j));
302  quark_prop_tmp = quark_prop_src;
303  quark_prop_src = quark_prop_tmp - adj(shift(uu, BACKWARD, j))*shift(quark_propagator, BACKWARD, j);
304  quark_prop_tmp = quark_prop_src;
305  quark_prop_src = quark_prop_tmp - adj(shift(uu, BACKWARD, j))*(Gamma(i)*shift(quark_propagator, BACKWARD, j));
306  i=i*2;
307 
308  };
309 
310  Double factor=0.5000000;
311  quark_prop_tmp = quark_prop_src;
312 
313 // If we want to apply the Wilson Dirac operator (in the absence of
314 // external fields - this is just for testing):
315 // Double kappa=0.11000000;
316 // quark_prop_src = (factor/kappa)*quark_propagator+factor*quark_prop_tmp;
317 
318 // If we want to insert a coupling to the external em field:
319  quark_prop_src = factor*quark_prop_tmp;
320 
321 // If we just want to apply the identity operation (just for test
322 // purposes):
323 // quark_prop_src = quark_propagator;
324 
325 
326  // Sanity check - write out the norm2 of the propagator source in the j_decay direction
327  // Use this for any possible verification
328  {
329  multi1d<Double> seqsource_corr = sumMulti(localNorm2(quark_prop_src),
330  phases.getSet());
331 
332  push(xml_out, "SeqSource_correlator");
333  write(xml_out, "seqsource_corr", seqsource_corr);
334  pop(xml_out);
335  }
336 
337 
338  /*
339  * Write the sequential source out to disk
340  */
341  {
342  XMLBufferWriter file_xml;
343  push(file_xml, "make_source");
344  write(file_xml, "id", uniqueId()); // NOTE: new ID form
345  pop(file_xml);
346 
347  XMLBufferWriter record_xml;
348  push(record_xml, "MakeSource");
349  write(record_xml, "PropSource", input.param);
350  write(record_xml, "Config_info", gauge_xml);
351  pop(record_xml); // SequentialSource
352 
353  // Write the seqsource
354  writeQprop(file_xml, record_xml, quark_prop_src,
355  input.prop.seqsource_file,
356  input.prop.seqsource_volfmt, QDPIO_SERIAL);
357 
358  QDPIO::cout << "Sequential source successfully written" << std::endl;
359  }
360 
361  pop(xml_out); // seqsource
362 
363  xml_out.close();
364  xml_in.close();
365 
366  // Time to bolt
367  QDP_finalize();
368 
369  END_CODE();
370 
371  exit(0);
372 }
373 
Primary include file for CHROMA in application codes.
Fourier transform phase factor support.
Definition: sftmom.h:35
const Set & getSet() const
The set to be used in sumMulti.
Definition: sftmom.h:57
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.
std::string uniqueId()
Return a unique id.
Definition: unique_id.cc:18
void proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
ForwardProp_t prop_header
int main(int argc, char **argv)
Sequential source generation.
unsigned j
Definition: ldumul_w.cc:35
int j_decay
Definition: meslate.cc:22
Nd
Definition: meslate.cc:74
multi1d< int > coords(const int x, const int y, const int z, const int t)
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
void readQprop(XMLReader &file_xml, XMLReader &record_xml, LatticePropagator &quark_prop, const std::string &file, QDP_serialparallel_t serpar)
Read a Chroma propagator.
Definition: qprop_io.cc:1573
void writeQprop(XMLBufferWriter &file_xml, XMLBufferWriter &record_xml, const LatticePropagator &quark_prop, const std::string &file, QDP_volfmt_t volfmt, QDP_serialparallel_t serpar)
Write a Chroma propagator.
Definition: qprop_io.cc:1532
Complex a
Definition: invbicg.cc:95
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
START_CODE()
Double zero
Definition: invbicg.cc:106
int k
Definition: invbicg.cc:119
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
Double link
Definition: pade_trln_w.cc:146
Double t_plaq
Definition: pade_trln_w.cc:145
int l
Definition: pade_trln_w.cc:111
Double w_plaq
Definition: pade_trln_w.cc:143
Double s_plaq
Definition: pade_trln_w.cc:144
#define FORWARD
Definition: primitives.h:82
#define BACKWARD
Definition: primitives.h:83
Gauge configuration structure.
Definition: cfgtype_io.h:16
Propagator parameters.
Definition: qprop_io.h:75
Propagators.
std::string prop_file
std::string seqsource_file
QDP_volfmt_t seqsource_volfmt
Mega-structure of all input.