CHROMA
t_leapfrog.cc
Go to the documentation of this file.
1 
2 #include "chroma.h"
3 #include <string>
7 
8 // Specials
10 
11 using namespace Chroma;
12 
13 //! To insure linking of code, place the registered code flags here
14 /*! This is the bit of code that dictates what fermacts are in use */
15 bool linkageHack(void)
16 {
17  bool foo = true;
18 
19  // Gauge Monomials
21 
22  // Ferm Monomials
24 
25  // MD Integrators
27 
28  // Chrono predictor
30 
31  // Inline Measurements
33 
34  return foo;
35 }
36 
37 
38 int main(int argc, char *argv[])
39 {
40  Chroma::initialize(&argc, &argv);
41 
42  START_CODE();
43 
44  // Chroma Init stuff -- Open DATA and XMLDAT
45  QDPIO::cout << "Linkage = " << linkageHack() << std::endl;
46 
47  // Snarf it all
48  XMLReader param_in(Chroma::getXMLInputFileName());
49  XMLReader paramtop(param_in, "/LeapfrogTest");
50 
51  multi1d<int> nrow(Nd);
52 
53  try {
54  read(paramtop, "nrow", nrow);
55  }
56  catch(const std::string& e) {
57  QDPIO::cerr << "Unable to read nrow from XML: " << e << std::endl;
58  QDP_abort(1);
59  }
60 
61  Layout::setLattSize(nrow);
62  Layout::create();
63 
64 
65  // Dump output
66  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
67  XMLFileWriter& xml_log = Chroma::getXMLLogInstance();
68  push(xml_out, "t_leapfrog");
69  push(xml_log, "t_leapfrog");
70 
71  // Read Parameters
72  multi1d<int> boundary(Nd); // Ferm BC's
73  std::string monomial_name; // String for Factory
74 
75 
76  Cfg_t cfg;
77  try {
78  read(paramtop, "./GaugeStartup", cfg);
79  }
80  catch( const std::string& e ) {
81  QDPIO::cerr << " Error reading XML " << e << std::endl;
82  QDP_abort(1);
83  }
84 
85  multi1d<LatticeColorMatrix> u(Nd);
86  {
87  XMLReader file_xml;
88  XMLReader config_xml;
89 
90  gaugeStartup(file_xml, config_xml, u, cfg);
91  }
92 
93  {
94  bool monitorForcesP = true;
95 
96  if( paramtop.count("./MonitorForces") == 1 ) {
97  read(paramtop, "./MonitorForces", monitorForcesP );
98  }
99 
100  QDPIO::cout << "MonitorForces is " << monitorForcesP << std::endl;
102  }
103 
104  // Try and create an array of monomials:
105  try {
106  readNamedMonomialArray(paramtop, "./Monomials");
107  }
108  catch(const std::string& e) {
109  QDPIO::cout << "Failed to read monomials " << std::endl;
110  QDP_abort(1);
111  }
112 
113  ExactHamiltonianParams ham_params(paramtop, "./Hamiltonian");
114  ExactHamiltonian H(ham_params);
115 
116  // create toplevel integrator
117  LCMToplevelIntegratorParams int_par(paramtop, "./MDIntegrator");
118  LCMToplevelIntegrator the_integrator(int_par);
119 
120  // Fictitious momenta for now
121  multi1d<LatticeColorMatrix> p(Nd);
122 
123  // Get some noise into the momenta...
124  for(int mu=0; mu<Nd; mu++) {
125  gaussian(p[mu]);
126  p[mu] *= sqrt(0.5);
127  taproj(p[mu]);
128  }
129 
130  QDPIO::cout << "create state" << std::endl;
131 
132  // Create a field state
133  GaugeFieldState gauge_state(p,u);
134 
135 
136  QDPIO::cout << "exact ham" << std::endl;
137 
138 
139  Double KE_old, PE_old;
140 
141  QDPIO::cout << "fields" << std::endl;
142 
143 
144  H.refreshInternalFields(gauge_state);
145 
146  QDPIO::cout << "mesE" << std::endl;
147 
148  H.mesE(gauge_state, KE_old, PE_old);
149 
150  QDPIO::cout << "Initial energies: KE =" << KE_old << " PE = " << PE_old <<std::endl;
151 
152  QDPIO::cout << "Copying copy list" << std::endl;
153  // Setup fields
154  the_integrator.copyFields();
155 
156  QDPIO::cout << "Performing trajectory" << std::endl;
157  QDP::StopWatch swatch;
158  swatch.reset();
159  swatch.start();
160  // Do a trajectory
161  the_integrator(gauge_state, the_integrator.getTrajLength());
162  swatch.stop();
163  double total_time = swatch.getTimeInSeconds();
164  QDPIO::cout << "Trajectory took: " << total_time << " sec" <<std::endl;
165 
166  QDPIO::cout << "Rect force took: " << RectGaugeActEnv::getTime()
167  << " sec. " << Real(100)*RectGaugeActEnv::getTime()/total_time
168  << " % of total" << std::endl;
169 
170  QDPIO::cout << "Other force took: "
172  << Real(100)*PlaqPlusSpatialTwoPlaqGaugeActEnv::getTime()/total_time
173  << " % of total" << std::endl;
174 
175  QDPIO::cout << "Expmat took: "<< ExpMatEnv::getTime() << " sec. "
176  << Real(100)*ExpMatEnv::getTime()/total_time
177  << " % of total" << std::endl;
178 
179  QDPIO::cout << "Reunit took: "<< ReunitEnv::getTime() << " sec. "
180  << Real(100)*ReunitEnv::getTime()/total_time
181  << " % of total" << std::endl;
182 
183  QDPIO::cout << "Taproj took: "<< TaprojEnv::getTime() << " sec. "
184  << Real(100)*TaprojEnv::getTime()/total_time
185  << " % of total" << std::endl;
186 
187  QDPIO::cout << "Stout Smearing Took:"<< StoutLinkTimings::getSmearingTime() << " secs. "
188  << Real(100)*StoutLinkTimings::getSmearingTime()/total_time
189  <<" % of total " << std::endl;
190 
191  QDPIO::cout << "Stout Force Recursion Took:"<< StoutLinkTimings::getForceTime() << " secs. "
192  << Real(100)*StoutLinkTimings::getForceTime()/total_time
193  <<" % of total " << std::endl;
194 
195  QDPIO::cout << "Stout Force Functions Took:" << StoutLinkTimings::getFunctionsTime() << " secs "
196  << Real(100)*StoutLinkTimings::getFunctionsTime()/total_time
197  <<" % of total " << std::endl;
198 
199  double deficit = swatch.getTimeInSeconds()
202  - ExpMatEnv::getTime()
203  - ReunitEnv::getTime()
207 
208  QDPIO::cout << "Time deficit : " << deficit << " sec. "<< Real(100)*deficit/ total_time << " % of total" << std::endl;
209 
210  QDPIO::cout << "Measuring final energies" << std::endl;
211 
212  Double KE_new, PE_new;
213  H.mesE(gauge_state, KE_new, PE_new);
214  QDPIO::cout << "Final energies: KE =" << KE_new << " PE = " << PE_new <<std::endl;
215 
216 
217  Double deltaPE = PE_new - PE_old;
218  Double deltaKE = KE_new - KE_old;
219 
220  QDPIO::cout << "DeltaPE = " << deltaPE << std::endl;
221  QDPIO::cout << "DeltaKE = " << deltaKE << std::endl;
222 
223  QDPIO::cout << "DeltaE = " << deltaKE + deltaPE <<std::endl;
224  push(xml_log, "DeltaE");
225  write(xml_log, "DeltaKE", deltaKE);
226  write(xml_log, "DeltaPE", deltaPE);
227  write(xml_log, "DeltaH", (deltaKE+deltaPE));
228  pop(xml_log);
229  pop(xml_log); // t_leapfrog
230  pop(xml_out); // t_leapfrog
231 // xml_out.close();
232 
233  END_CODE();
234 
235  // Finish
237  exit(0);
238 }
Primary include file for CHROMA in application codes.
virtual void mesE(const AbsFieldState< P, Q > &s, Double &KE, Double &PE) const
The Exact Hamiltonian Class - supplies internal field refreshment and energy calculations.
void refreshInternalFields(const AbsFieldState< multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > &s)
Internal Field Refreshment.
Pure gauge field state.
Definition: field_state.h:83
void copyFields(void) const
Copy fields between the monomials of a copy list.
Real getTrajLength(void) const
Get the length of a trajectory.
int mu
Definition: cool.cc:24
Exact Hamiltonians.
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 taproj(LatticeColorMatrix &a)
Take the traceless antihermitian projection of a color matrix.
Definition: taproj.cc:31
void gaugeStartup(XMLReader &gauge_file_xml, XMLReader &gauge_xml, multi1d< LatticeColorMatrix > &u, Cfg_t &cfg)
Initialize the gauge fields.
void readNamedMonomialArray(XMLReader &xml, const std::string &path)
Read an array of named monomials from an XML reader. use factory to create the monomials and put them...
Definition: monomial_io.cc:106
Nd
Definition: meslate.cc:74
bool registerAll()
Register all the factories.
double getTime()
Definition: expmat.cc:21
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
double getTime()
Definition: reunit.cc:30
double getTime()
Definition: taproj.cc:15
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
XMLFileWriter & getXMLLogInstance()
Get xml log instance.
Definition: chroma_init.cc:378
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
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
bool linkageHack(void)
Definition: const_hmc.cc:660
void setForceMonitoring(bool monitorP)
std::string getXMLInputFileName()
Get input file name.
Definition: chroma_init.cc:88
pop(xml_out)
START_CODE()
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
Rectangle gauge action.
Gauge configuration structure.
Definition: cfgtype_io.h:16
Parameter structure for new Hamiltonian.
A Structure to hold the top level parameters.
int main(int argc, char *argv[])
Definition: t_leapfrog.cc:38