inline_polar_source_w.cc

Go to the documentation of this file.
00001 // $Id: inline_polar_source_w.cc,v 1.4 2007/02/25 22:39:28 edwards Exp $
00002 // Code for sequential source construction
00003 
00004 #error "THIS CODE IS NOT READY YET"
00005 
00006 #include <iostream>
00007 #include <cstdio>
00008 
00009 #include "chroma.h"
00010 
00011 using namespace Chroma;
00012 
00013 
00014 /*
00015  * Input 
00016  */
00017 
00018 //! Propagators
00019 struct Prop_t
00020 {
00021   string           prop_file;  // The file is expected to be in SciDAC format!
00022   string           seqsource_file;  // The file is expected to be in SciDAC format!
00023   QDP_volfmt_t     seqsource_volfmt;
00024 };
00025 
00026 
00027 //! Mega-structure of all input
00028 struct SeqSource_input_t
00029 {
00030   PropSource_t      param;
00031   Cfg_t             cfg;
00032   Prop_t            prop;
00033 };
00034 
00035 
00036 //! Propagator parameters
00037 void read(XMLReader& xml, const string& path, Prop_t& input)
00038 {
00039   XMLReader inputtop(xml, path);
00040 
00041   read(inputtop, "prop_file", input.prop_file);
00042   read(inputtop, "seqsource_file", input.seqsource_file);
00043   read(inputtop, "seqsource_volfmt", input.seqsource_volfmt);
00044 }
00045 
00046 
00047 // Reader for input parameters
00048 void read(XMLReader& xml, const string& path, SeqSource_input_t& input)
00049 {
00050   XMLReader inputtop(xml, path);
00051 
00052   // Read the input
00053   try
00054   {
00055     // The parameters holds the version number
00056     read(inputtop, "Param", input.param);
00057 
00058     // Read in the gauge configuration info
00059     read(inputtop, "Cfg", input.cfg);
00060 
00061     // Read in the forward_prop/seqsource info
00062     read(inputtop, "Prop", input.prop);
00063   }
00064   catch (const string& e) 
00065   {
00066     QDPIO::cerr << "Error reading data: " << e << endl;
00067     throw;
00068   }
00069 }
00070 
00071 
00072 //! Sequential source generation
00073 /*
00074  *  \defgroup seqsource Sequential source generation
00075  *  \ingroup main
00076  *
00077  *  Read quark propagators, convert into sequential sources
00078  *
00079  */
00080 
00081 int main(int argc, char **argv)
00082 {
00083   // Put the machine into a known state
00084   QDP_initialize(&argc, &argv);
00085 
00086   START_CODE();
00087 
00088   // Input parameter structure
00089   SeqSource_input_t  input;
00090 
00091   // Instantiate xml reader for DATA
00092   XMLReader xml_in("DATA");
00093 
00094   // Read data
00095   read(xml_in, "/seqsource", input);
00096 
00097   // Specify lattice size, shape, etc.
00098   Layout::setLattSize(input.param.nrow);
00099   Layout::create();
00100 
00101   // Sanity checks
00102   QDPIO::cout << endl << "     Gauge group: SU(" << Nc << ")" << endl;
00103 
00104   QDPIO::cout << "     Computing sequential source of type "
00105               << input.param.source_type << endl;
00106   
00107   QDPIO::cout << "     Volume: " << input.param.nrow[0];
00108   for (int i=1; i<Nd; ++i) {
00109     QDPIO::cout << " x " << input.param.nrow[i];
00110   }
00111   QDPIO::cout << endl;
00112 
00113 
00114   // Read in the configuration along with relevant information.
00115   multi1d<LatticeColorMatrix> u(Nd);
00116   XMLReader gauge_file_xml, gauge_xml;
00117 
00118   // Startup gauge
00119   gaugeStartup(gauge_file_xml, gauge_xml, u, input.cfg);
00120 
00121   // Instantiate XML writer for XMLDAT
00122   XMLFileWriter xml_out("XMLDAT");
00123   push(xml_out, "seqsource");
00124 
00125   proginfo(xml_out);    // Print out basic program info
00126 
00127   // Write out the input
00128   write(xml_out, "Input", xml_in);
00129 
00130   // Write out the config header
00131   write(xml_out, "Config_info", gauge_xml);
00132 
00133   push(xml_out, "Output_version");
00134   write(xml_out, "out_version", 1);
00135   pop(xml_out);
00136 
00137   xml_out.flush();
00138 
00139 
00140   // Check if the gauge field configuration is unitarized
00141   unitarityCheck(u);
00142 
00143   // Calculate some gauge invariant observables just for info.
00144   Double w_plaq, s_plaq, t_plaq, link;
00145   MesPlq(u, w_plaq, s_plaq, t_plaq, link);
00146 
00147   push(xml_out, "Observables");
00148   write(xml_out, "w_plaq", w_plaq);
00149   write(xml_out, "s_plaq", s_plaq);
00150   write(xml_out, "t_plaq", t_plaq);
00151   write(xml_out, "link", link);
00152   pop(xml_out);
00153 
00154   xml_out.flush();
00155 
00156 
00157   //
00158   // Read the quark propagator and extract headers
00159   //
00160   LatticePropagator quark_propagator;
00161   ChromaProp_t prop_header;
00162   PropSource_t source_header;
00163   {
00164     XMLReader prop_file_xml, prop_record_xml;
00165 
00166     QDPIO::cout << "Attempt to read forward propagator" << endl;
00167     readQprop(prop_file_xml, 
00168               prop_record_xml, quark_propagator,
00169               input.prop.prop_file, QDPIO_SERIAL);
00170     QDPIO::cout << "Forward propagator successfully read" << endl;
00171    
00172     // Try to invert this record XML into a ChromaProp struct
00173     // Also pull out the id of this source
00174     try
00175     {
00176       read(prop_record_xml, "/Propagator/ForwardProp", prop_header);
00177       read(prop_record_xml, "/Propagator/PropSource", source_header);
00178     }
00179     catch (const string& e) 
00180     {
00181       QDPIO::cerr << "Error extracting forward_prop header: " << e << endl;
00182       throw;
00183     }
00184 
00185     // Save prop input
00186     write(xml_out, "Propagator_info", prop_record_xml);
00187   }
00188 
00189   // Derived from input prop
00190   int  j_decay = source_header.j_decay;
00191 // multi1d<int> boundary = prop_header.boundary;   // not currently needed
00192   multi1d<int> t_source = source_header.t_source;
00193 
00194   // Initialize the slow Fourier transform phases
00195   SftMom phases(0, true, j_decay);
00196 
00197   // Sanity check - write out the norm2 of the forward prop in the j_decay direction
00198   // Use this for any possible verification
00199   {
00200     multi1d<Double> forward_prop_corr = sumMulti(localNorm2(quark_propagator), 
00201                                                  phases.getSet());
00202 
00203     push(xml_out, "Forward_prop_correlator");
00204     write(xml_out, "forward_prop_corr", forward_prop_corr);
00205     pop(xml_out);
00206   }
00207 
00208   //------------------ Start main body of calculations -----------------------------
00209 
00210   //
00211   // Construct the sequential source
00212   //
00213   LatticePropagator quark_prop_src = zero;
00214   LatticePropagator quark_prop_tmp;
00215   LatticeColorMatrix uu;
00216   multi1d<LatticeColorMatrix> ua(Nd);
00217   LatticeComplex a;
00218   Real alocr, aloci;
00219   Complex aloc;
00220   multi1d<int> size = input.param.nrow;
00221   multi1d<int> coords(Nd);
00222 
00223 // Create a LatticeComplex em field
00224 
00225   for (int i=0; i<size[0]; ++i) {
00226   for (int j=0; j<size[1]; ++j) {
00227   for (int k=0; k<size[2]; ++k) {
00228   for (int l=0; l<size[3]; ++l) {
00229 
00230 // If we want to do a magnetic insertion (note the pretty arbitrary,
00231 // but not completely stupid, strength of the external gauge field -
00232 // in final results, this strength is an overall factor and will be
00233 // divided out in data analysis):
00234 
00235 //    alocr=0.0;
00236 //    aloci = (float) j;
00237 //
00238 //    if ( j > (size[1]/2) ) {
00239 //      aloci = aloci - (float) size[1];
00240 //    };
00241 //
00242 //    aloci=aloci*10.0*6.2831852/(size[1]*size[0]);
00243 
00244 
00245 // If we want to do an electric insertion:
00246 
00247 //    alocr=0.0;
00248 //    aloci = (float) l;
00249 //    aloci=aloci*10.0*6.2831852/(size[2]*size[3]);
00250 
00251 
00252 //  If we want to do an A^2 insertion (electric):
00253 
00254     alocr = (float) (l*l);
00255     aloci = 0.0;
00256     alocr=alocr*10.0*6.2831852/(size[2]*size[3]);
00257     alocr=alocr*10.0*6.2831852/(size[2]*size[3]);
00258     alocr=alocr*(-0.5000000);
00259 
00260 
00261 //  So let's write that into the field:
00262 
00263     aloc = cmplx(alocr,aloci);
00264     coords[0]=i;
00265     coords[1]=j;
00266     coords[2]=k;
00267     coords[3]=l;
00268     pokeSite(a, aloc, coords);
00269   };
00270   };
00271   };
00272   };
00273 
00274 // ok, so now we have a LatticeComplex containing our em field
00275 // next, make a LatticeColorMatrix out of it
00276 
00277   ua[0] = zero;
00278   ua[1] = zero;
00279   ua[2] = zero;
00280   ua[3] = zero;
00281 
00282 // Pick which component of the gauge field we're making nontrivial
00283 // (for electric insertion, ua[2], for magnetic insertion, ua[0]);
00284 
00285   for (int elem=0; elem<Nc; ++elem) {
00286 //    pokeColor(ua[0], a, elem, elem);
00287 //    pokeColor(ua[1], a, elem, elem);
00288     pokeColor(ua[2], a, elem, elem);
00289 //    pokeColor(ua[3], a, elem, elem);
00290   };
00291 
00292 // and now put it all together ...
00293 
00294   int i=1;
00295 
00296   for (int j=0; j<Nd; ++j) {
00297 
00298   uu = ua[j]*u[j];
00299   quark_prop_tmp = quark_prop_src;
00300   quark_prop_src = quark_prop_tmp - uu*shift(quark_propagator, FORWARD, j);
00301   quark_prop_tmp = quark_prop_src;
00302   quark_prop_src = quark_prop_tmp + uu*(Gamma(i)*shift(quark_propagator, FORWARD, j));
00303   quark_prop_tmp = quark_prop_src;
00304   quark_prop_src = quark_prop_tmp - adj(shift(uu, BACKWARD, j))*shift(quark_propagator, BACKWARD, j);
00305   quark_prop_tmp = quark_prop_src;
00306   quark_prop_src = quark_prop_tmp - adj(shift(uu, BACKWARD, j))*(Gamma(i)*shift(quark_propagator, BACKWARD, j));
00307   i=i*2;
00308 
00309   };
00310 
00311   Double factor=0.5000000;
00312   quark_prop_tmp = quark_prop_src;
00313 
00314 //  If we want to apply the Wilson Dirac operator (in the absence of
00315 //  external fields - this is just for testing):
00316 //  Double kappa=0.11000000;
00317 //  quark_prop_src = (factor/kappa)*quark_propagator+factor*quark_prop_tmp;
00318 
00319 //  If we want to insert a coupling to the external em field:
00320   quark_prop_src = factor*quark_prop_tmp;
00321 
00322 //  If we just want to apply the identity operation (just for test
00323 //  purposes):
00324 //  quark_prop_src = quark_propagator;
00325 
00326 
00327   // Sanity check - write out the norm2 of the propagator source in the j_decay direction
00328   // Use this for any possible verification
00329   {
00330     multi1d<Double> seqsource_corr = sumMulti(localNorm2(quark_prop_src), 
00331                                               phases.getSet());
00332         
00333     push(xml_out, "SeqSource_correlator");
00334     write(xml_out, "seqsource_corr", seqsource_corr);
00335     pop(xml_out);
00336   }
00337 
00338 
00339   /*
00340    *  Write the sequential source out to disk
00341    */
00342   {
00343     XMLBufferWriter file_xml;
00344     push(file_xml, "make_source");
00345     write(file_xml, "id", uniqueId());  // NOTE: new ID form
00346     pop(file_xml);
00347 
00348     XMLBufferWriter record_xml;
00349     push(record_xml, "MakeSource");
00350     write(record_xml, "PropSource", input.param);
00351     write(record_xml, "Config_info", gauge_xml);
00352     pop(record_xml);  // SequentialSource
00353 
00354     // Write the seqsource
00355     writeQprop(file_xml, record_xml, quark_prop_src,
00356                input.prop.seqsource_file, 
00357                input.prop.seqsource_volfmt, QDPIO_SERIAL);
00358 
00359     QDPIO::cout << "Sequential source successfully written" << endl;
00360   }
00361 
00362   pop(xml_out);    // seqsource
00363 
00364   xml_out.close();
00365   xml_in.close();
00366 
00367   // Time to bolt
00368   QDP_finalize();
00369 
00370   END_CODE();
00371 
00372   exit(0);
00373 }
00374 

Generated on Sun Nov 22 04:32:47 2009 for CHROMA by  doxygen 1.4.7