CHROMA
t_unprec_wilson_force.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_unprec_wilson_force");
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  // Finish
185 
186  exit(0);
187 }
188 
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)