CHROMA
t_hamsys.cc
Go to the documentation of this file.
1 #include "chroma.h"
2 
3 #include <iostream>
4 
5 using namespace Chroma;
6 
7 
8 int main(int argc, char *argv[])
9 {
10  // Initialise QDP
11  Chroma::initialize(&argc, &argv);
12 
13  // Setup a small lattice
14  const int nrow_arr[] = {4, 4, 4, 4};
15  multi1d<int> nrow(Nd);
16  nrow=nrow_arr;
17  Layout::setLattSize(nrow);
18  Layout::create();
19 
20  multi1d<LatticeColorMatrix> u(Nd);
21  {
22  XMLReader file_xml;
23  XMLReader config_xml;
25  // Cfg_t foo; foo.cfg_type=CFG_TYPE_SZIN; foo.cfg_file="./CFGOUT";
26  gaugeStartup(file_xml, config_xml, u, foo);
27  }
28 
29 
30  multi1d<LatticeColorMatrix> p(Nd);
31 
32 #if 0
33  for(int mu = 0; mu < Nd; mu++) {
34 
35  gaussian(p[mu]);
36  taproj(p[mu]);
37 
38  }
39 #endif
40 
41  // Get Periodic Gauge Boundaries
43 
44  Real betaMC = Real(5.7);
45  Real betaMD = Real(5.7);
46 
47  // Get a Wilson Gauge Action
48  // For the Monte Carlo
49  WilsonGaugeAct S_pg_MC(gbc, betaMC);
50 
51  // For the MD
52  WilsonGaugeAct S_pg_MD(gbc, betaMD);
53 
54  // Generate Hamiltonians
55  ExactPureGaugeHamiltonian H_MC(S_pg_MC);
56  ExactPureGaugeHamiltonian H_MD(S_pg_MD);
57 
58  // Generate the symplectic updates with respect to H_MD
59  PureGaugeSympUpdates leaps(H_MD);
60 
61  // Test the integrator -- for energy conservation, and reversibility
62 #if 0
63  XMLFileWriter lf_xml("./LEAPFROG_TESTS");
64  push(lf_xml, "LeapFrogTests");
65 
66  // Energy conservation
67  // Do trajectories of length 1, changing dtau from 0.01 to 0.2
68  for(Real dtau=0.01; toBool(dtau < 0.2); dtau +=Real(0.01)) {
69  Real tau = Real(1);
70  PureGaugePQPLeapFrog lf(leaps, dtau, tau);
71  PureGaugeFieldState old_state(p, u);
72  PureGaugeFieldState working_state(p, u);
73 
74  Double KE_old, PE_old;
75  H_MD.mesE(working_state, KE_old, PE_old);
76 
77  // DO a traj
78  lf(working_state, lf_xml);
79 
80  Double KE_new, PE_new;
81  H_MD.mesE(working_state, KE_new, PE_new);
82 
83  // Flip Momenta
84  for(int mu = 0; mu < Nd; mu++) {
85  working_state.getP()[mu] *= Real(-1);
86  }
87 
88  // Do reverse traj
89  // DO a traj
90  lf(working_state, lf_xml);
91 
92  // Flip Momenta
93  for(int mu = 0; mu < Nd; mu++) {
94  working_state.getP()[mu] *= Real(-1);
95  }
96 
97  Double KE_new2, PE_new2;
98  H_MD.mesE(working_state, KE_new2, PE_new2);
99 
100  Double deltaKE = KE_new - KE_old;
101  Double deltaPE = PE_new - PE_old;
102  Double deltaH = deltaKE + deltaPE;
103  Double ddKE = KE_new2 - KE_old;
104  Double ddPE = PE_new2 - PE_old;
105  Double ddH = ddKE - ddPE;
106 
107  push(lf_xml, "elem");
108  write(lf_xml, "tau", tau);
109  write(lf_xml, "dt", dtau);
110  write(lf_xml, "delH", deltaH);
111  write(lf_xml, "delKE", deltaKE);
112  write(lf_xml, "delPE", deltaPE);
113  write(lf_xml, "delDelH", ddH);
114  write(lf_xml, "ddPE", ddPE);
115  write(lf_xml, "ddKE", ddKE);
116  pop(lf_xml);
117 
118  QDPIO::cout << " dt = " << dtau << " deltaH = " << deltaH << std::endl;
119  QDPIO::cout << " delta KE = " << deltaKE
120  << " delta PE = " << deltaPE
121  << " dPE/dKE = " << deltaPE/deltaKE << std::endl;
122 
123  QDPIO::cout << " delta delta H = " << ddH
124  << " delta delta KE = " << ddKE
125  << " delta delta PE = " << ddPE<< std::endl << std::endl;
126  }
127  pop(lf_xml);
128  lf_xml.close();
129 #endif
130 
131  // Step Sizes
132  Real tau = Real(1);
133  Real dt = Real(0.1);
134  PureGaugePQPLeapFrog leapfrog(leaps, dt, tau);
135 
136 
137  // Create the HMC
138  PureGaugeHMCTraj HMC(H_MC, leapfrog);
139 
140  XMLFileWriter monitorHMC("HMC");
141  push(monitorHMC, "HMCTest");
142  PureGaugeFieldState mc_state(p, u);
143 
144 
145 
146  for(int i=0; i < 100000; i++) {
147 
148  // Do trajectory
149  HMC(mc_state, true, monitorHMC);
150 
151  // Do measurements
152  push(monitorHMC, "Measurements");
153 
154  // -1 because it is the last trajectory
155  write(monitorHMC, "HMCtraj", HMC.getTrajNum()-1);
156 
158  MesPlq(mc_state.getQ(), w_plaq, s_plaq, t_plaq, link);
159  write(monitorHMC, "w_plaq", w_plaq);
160 
161  pop(monitorHMC);
162 
163  QDPIO::cout << "Traj: " << HMC.getTrajNum()-1 << " w_plaq = " << w_plaq << std::endl;
164 
165  }
166 
167  pop(monitorHMC);
168  monitorHMC.close();
169  // Finish
170 
172  exit(0);
173 }
174 
Primary include file for CHROMA in application codes.
Class for counted reference semantics.
Definition: handle.h:33
Wilson gauge action.
EXTERN Real dt
int mu
Definition: cool.cc:24
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.
@ CFG_TYPE_DISORDERED
Nd
Definition: meslate.cc:74
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
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
FloatingPoint< double > Double
Definition: gtest.h:7351
Double link
Definition: pade_trln_w.cc:146
Double t_plaq
Definition: pade_trln_w.cc:145
Double w_plaq
Definition: pade_trln_w.cc:143
Double s_plaq
Definition: pade_trln_w.cc:144
#define HMC
Definition: primitives.h:63
Gauge configuration structure.
Definition: cfgtype_io.h:16
CfgType cfg_type
Definition: cfgtype_io.h:17
int main(int argc, char *argv[])
Definition: t_hamsys.cc:8