CHROMA
t_hamsys_ferm.cc
Go to the documentation of this file.
1 #include "chroma.h"
2 
3 #include <iostream>
4 
5 using namespace Chroma;
6 
8  multi1d<LatticeColorMatrix> & ds_u,
10  const LatticeFermion& psi)
11 {
12  START_CODE();
13 
14  // Get at the U matrices
15  const multi1d<LatticeColorMatrix>& u = state->getLinks();
16 
17  // Get a linear operator
19 
20  // Compute MY
21  LatticeFermion Y;
22  (*M)(Y, psi, PLUS);
23 
24  // Usually this is Kappa. In our normalisation it is 0.5
25  // I am adding in a factor of -1 to be consistent with the sign
26  // convention for the preconditioned one. (We can always take this out
27  // later
28  Real prefactor=Real(0.5);
29 
30  // Two temporaries
31  LatticeFermion f_tmp;
32  LatticeColorMatrix u_tmp;
33  for(int mu = 0; mu < Nd; mu++)
34  {
35  // f_tmp = (1 + gamma_mu) Y
36  f_tmp = Gamma(1<<mu)*Y;
37  f_tmp += Y;
38 
39  // trace_spin ( ( 1 + gamma_mu ) Y_x+mu X^{dag}_x )
40 // u_tmp = traceSpin(outerProduct(shift(f_tmp, FORWARD, mu),psi));
41  LatticeFermion foo = shift(f_tmp, FORWARD, mu);
42  u_tmp = traceSpin(outerProduct(foo,psi));
43 
44  // f_tmp = -(1 -gamma_mu) X
45  f_tmp = Gamma(1<<mu)*psi;
46  f_tmp -= psi;
47 
48  // +trace_spin( ( 1 - gamma_mu) X_x+mu Y^{dag}_x)
49 // u_tmp -= traceSpin(outerProduct(shift(f_tmp, FORWARD, mu),Y));
50  foo = shift(f_tmp, FORWARD, mu);
51  u_tmp -= traceSpin(outerProduct(foo,Y));
52 
53  // accumulate with prefactor
54  ds_u[mu] = prefactor*( u[mu]*u_tmp );
55  }
56 
57  END_CODE();
58 }
59 
60 void funky_new_dsdu(const UnprecLinearOperator<LatticeFermion, multi1d<LatticeColorMatrix> >& M,
61  multi1d<LatticeColorMatrix> & ds_u,
62  const LatticeFermion& X) {
63  LatticeFermion Y;
64  M(Y,X,PLUS);
65 
66  // The 2 flavour derivative is:
67  // -Xdag ( Mdag^{dot} M + M^dag M^{dot} ) X
68  // = -Xdag Mdag^dot M X - Xdag Mdat M^{dot}X
69  // = -Xdag Mdag^dot Y - Ydag M^dot X
70  // = -( Xdag Mdag^dot Y + Ydat M^dot X )
71 
72  // Do the X^dag Mdag^dot Y term
73  M.deriv(ds_u, X, Y, MINUS);
74 
75  // Do the Ydag M^dot X term
76  multi1d<LatticeColorMatrix> F_tmp(Nd);
77  M.deriv(F_tmp, Y, X, PLUS);
78 
79  // Add them and put in the minus sign
80  for(int mu=0; mu < Nd; mu++) {
81 
82  ds_u[mu] += F_tmp[mu];
83  ds_u[mu] *= Real(-1);
84 
85  }
86 
87 
88 }
89 
90 
91 int main(int argc, char *argv[])
92 {
93  // Initialise QDP
94  Chroma::initialize(&argc, &argv);
95 
96  // Setup a small lattice
97  const int nrow_arr[] = {2, 2, 2, 2};
98  multi1d<int> nrow(Nd);
99  nrow=nrow_arr;
100  Layout::setLattSize(nrow);
101  Layout::create();
102 
103 
104  multi1d<LatticeColorMatrix> u(Nd);
105  {
106  XMLReader file_xml;
107  XMLReader config_xml;
109  // Cfg_t foo; foo.cfg_type=CFG_TYPE_SZIN; foo.cfg_file="./CFGIN";
110  gaugeStartup(file_xml, config_xml, u, foo);
111  }
112 
113  XMLFileWriter xml_out("./XMLDAT");
114  push(xml_out, "t_hamsys_ferm");
115 
116  multi1d<LatticeColorMatrix> p(Nd);
117  multi1d<LatticeFermion> phi(1);
118 
119 
120  // Get Periodic Gauge Boundaries
122  Real betaMC = Real(5.7);
123  WilsonGaugeAct S_pg_MC(gbc, betaMC);
124 
125  multi1d<int> boundary(Nd);
126  boundary[0] = 1;
127  boundary[1] = 1;
128  boundary[2] = 1;
129  boundary[3] = -1;
130 
131  // Now set up a ferm act
133 
134  // Now make up an array of handles
135  Real m = Real(0.1);
136  UnprecWilsonFermAct S_f_MC(fbc, m);
137 
139 
140  multi1d<LatticeColorMatrix> dsdu_1(Nd);
141  multi1d<LatticeColorMatrix> dsdu_2(Nd);
142 
143  LatticeFermion psi;
144  gaussian(psi);
145  // for(int mu=0; mu < Nd; mu++) {
146  // dsdu_1[mu] = zero;
147  // dsdu_2[mu] = zero;
148  // }
149 
150  // S_f_MC.dsdu(dsdu_1, state, psi);
151  //S_f_MC.dsdu2(dsdu_2, state, psi);
152 
153  wilson_dsdu(S_f_MC, dsdu_1, state, psi);
154 
156 
157 
158  funky_new_dsdu(*M_w, dsdu_2, psi);
159 
160  for(int mu=0; mu < Nd; mu++) {
161  taproj(dsdu_1[mu]);
162  taproj(dsdu_2[mu]);
163 
164  push(xml_out, "dsdu");
165  write(xml_out, "dsdu_1", dsdu_1[mu]);
166  write(xml_out, "dsdu_2", dsdu_2[mu]);
167  pop(xml_out);
168 
169  LatticeColorMatrix dsdu_diff=dsdu_1[mu] - dsdu_2[mu];
170 
171  Double sum_diff=norm2(dsdu_diff);
172  QDPIO::cout << "Mu = " << mu << " Sum Diff=" << sum_diff << std::endl;
173 
174  push(xml_out, "ForceDiff");
175  write(xml_out, "mu", mu);
176  write(xml_out, "dsdu_diff", dsdu_diff);
177  pop(xml_out);
178  }
179 
180  pop(xml_out);
181  xml_out.close();
182 
183 
184  /*
185  Real Nd_pm = Real(Nd) + m;
186 
187  // Now the inverter params -- this will need cleaning up
188  InvertParam_t inv_params_MC;
189  inv_params_MC.invType = CG_INVERTER;
190  inv_params_MC.RsdCG = Real(1.0e-7);
191  inv_params_MC.MaxCG = 500;
192 
193  // Now the Hamiltonian
194  TwoFlavorDegenFermHamiltonian<WilsonGaugeAct,UnprecWilsonFermAct> H_MC( S_pg_MC, S_f_MC, inv_params_MC);
195 
196 
197  GaugeFermFieldState mc_state(p,u,phi);
198  MomRefreshGaussian(mc_state, H_MC);
199  PseudoFermionHeatbath(mc_state, H_MC);
200 
201  GaugeFermSympUpdates leaps(H_MC);
202  XMLFileWriter lf_xml("./LEAPFROG_TESTS");
203  push(lf_xml, "LeapFrogTests");
204 
205  // Energy conservation
206  // Do trajectories of length 1, changing dtau from 0.01 to 0.2
207  for(Real dtau=0.005; toBool(dtau < 0.4); dtau +=Real(0.005)) {
208  Real tau = Real(1);
209  GaugeFermPQPLeapFrog lf(leaps, dtau, tau);
210  GaugeFermFieldState old_state(mc_state);
211  GaugeFermFieldState working_state(mc_state);
212 
213  Double KE_old, GE_old, FE_old, PE_old;
214  H_MC.mesE(working_state, KE_old, GE_old, FE_old);
215  PE_old = GE_old + FE_old;
216 
217  // DO a traj
218  lf(working_state, lf_xml);
219 
220  Double KE_new, GE_new, FE_new, PE_new;
221  H_MC.mesE(working_state, KE_new, GE_new, FE_new);
222  PE_new = GE_new + FE_new;
223 
224  // Flip Momenta
225  for(int mu = 0; mu < Nd; mu++) {
226  working_state.getP()[mu] *= Real(-1);
227  }
228 
229  // Do reverse traj
230  // DO a traj
231  lf(working_state, lf_xml);
232 
233  // Flip Momenta
234  for(int mu = 0; mu < Nd; mu++) {
235  working_state.getP()[mu] *= Real(-1);
236  }
237 
238  Double KE_new2, GE_new2, FE_new2, PE_new2;
239  H_MC.mesE(working_state, KE_new2, GE_new2, FE_new2);
240  PE_new2 = GE_new2 + FE_new2;
241 
242 
243  Double deltaKE = KE_new - KE_old;
244  Double deltaGE = GE_new - GE_old;
245  Double deltaFE = FE_new - FE_old;
246  Double deltaPE = PE_new - PE_old;
247  Double deltaH = fabs(deltaKE + deltaPE);
248  Double ddKE = KE_new2 - KE_old;
249  Double ddPE = PE_new2 - PE_old;
250  Double ddGE = GE_new2 - GE_old;
251  Double ddFE = FE_new2 - FE_old;
252  Double ddH = ddKE + ddGE +ddFE;
253 
254  push(lf_xml, "elem");
255  write(lf_xml, "tau", tau);
256  write(lf_xml, "dt", dtau);
257  write(lf_xml, "delH", deltaH);
258  write(lf_xml, "delKE", deltaKE);
259  write(lf_xml, "delPE", deltaPE);
260  write(lf_xml, "delGE", deltaGE);
261  write(lf_xml, "delFE", deltaFE);
262 
263  write(lf_xml, "ddH", ddH);
264  write(lf_xml, "ddKE", ddKE);
265  write(lf_xml, "ddPE", ddPE);
266  write(lf_xml, "ddGE", ddGE);
267  write(lf_xml, "ddFE", ddFE);
268  pop(lf_xml);
269 
270  QDPIO::cout << " dt = " << dtau << " deltaH = " << deltaH << std::endl;
271  QDPIO::cout << " delta KE = " << deltaKE
272  << " delta PE = " << deltaPE
273  << " delta GE = " << deltaGE
274  << " delta FE = " << deltaFE
275  << " dPE/dKE = " << deltaPE/deltaKE << std::endl;
276 
277  QDPIO::cout << " delta delta H = " << ddH
278  << " delta delta KE = " << ddKE
279  << " delta delta PE = " << ddPE<< std::endl << std::endl;
280  }
281  pop(lf_xml);
282  lf_xml.close();
283 
284 
285  Real tau = Real(1);
286  Real dt = Real(0.1);
287  GaugeFermPQPLeapFrog leapfrog(leaps, dt, tau);
288  GaugeFermHMCTraj HMC(H_MC, leapfrog);
289  XMLFileWriter monitorHMC("HMC");
290  push(monitorHMC, "HMCTest");
291 
292  mc_state.getQ() = u;
293 
294  for(int i=0; i < 500; i++) {
295  // Do trajectory
296  HMC(mc_state, true, monitorHMC);
297 
298  // Do measurements
299  push(monitorHMC, "Measurements");
300 
301  // -1 because it belongs to the previous trajectory
302  write(monitorHMC, "HMCtraj", HMC.getTrajNum()-1);
303 
304  Double w_plaq, s_plaq,t_plaq, link;
305  MesPlq(mc_state.getQ(), w_plaq, s_plaq, t_plaq, link);
306  write(monitorHMC, "w_plaq", w_plaq);
307 
308  pop(monitorHMC);
309 
310  QDPIO::cout << "Traj: " << HMC.getTrajNum()-1 << " w_plaq = " << w_plaq << std::endl;
311 
312  }
313 
314  pop(monitorHMC);
315  monitorHMC.close();
316  // Finish.
317  */
318 
319  // Finish
321 
322  exit(0);
323 }
324 
Primary include file for CHROMA in application codes.
virtual FermState< T, P, Q > * createState(const Q &q) const
Given links (coordinates Q) create the state needed for the linear operators.
Definition: fermact.h:59
Class for counted reference semantics.
Definition: handle.h:33
Concrete class for all gauge actions with simple boundary conditions.
Definition: simple_fermbc.h:42
Unpreconditioned linear operator including derivatives.
Definition: linearop.h:185
Unpreconditioned Wilson fermion action.
UnprecLinearOperator< T, P, Q > * linOp(Handle< FermState< T, P, Q > > state) const
Produce a linear operator for this action.
Wilson gauge action.
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
static int m[4]
Definition: make_seeds.cc:16
Nd
Definition: meslate.cc:74
LatticeReal phi
Definition: mesq.cc:27
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
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
LatticeFermion psi
Definition: mespbg5p_w.cc:35
pop(xml_out)
START_CODE()
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
FloatingPoint< double > Double
Definition: gtest.h:7351
#define FORWARD
Definition: primitives.h:82
Gauge configuration structure.
Definition: cfgtype_io.h:16
CfgType cfg_type
Definition: cfgtype_io.h:17
int main(int argc, char *argv[])
void funky_new_dsdu(const UnprecLinearOperator< LatticeFermion, multi1d< LatticeColorMatrix > > &M, multi1d< LatticeColorMatrix > &ds_u, const LatticeFermion &X)
void wilson_dsdu(const UnprecWilsonFermAct &S, multi1d< LatticeColorMatrix > &ds_u, Handle< const ConnectState > state, const LatticeFermion &psi)
Definition: t_hamsys_ferm.cc:7