CHROMA
t_prec_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  const Real& Mass,
9  multi1d<LatticeColorMatrix> & ds_u,
11  const LatticeFermion& psi)
12 {
13  START_CODE();
14 
15  ds_u.resize(Nd);
16 
17  Real prefactor = Real(1)/(4*(Real(Nd) + Mass));
18 
19  LatticeColorMatrix utmp_1=zero;
20  LatticeFermion phi=zero;
21  LatticeFermion rho=zero;
22  LatticeFermion sigma=zero;;
23 
24  LatticeFermion ftmp_2;
25 
26  // Do the usual Wilson fermion dS_f/dU
27  // const LinearOperatorProxy<LatticeFermion> A(linOp(u));
29 
30  // Need the wilson dslash
31  // Use u from state with BC's on
32  const multi1d<LatticeColorMatrix>& u = state->getLinks();
33  WilsonDslash D(u);
34 
35  // phi = M(u)*psi
36 
37  (*M)(phi, psi, PLUS);
38 
39  /* rho = Dslash(0<-1) * psi */
40  D.apply(rho, psi, PLUS, 0);
41 
42  /* sigma = Dslash_dag(0 <- 1) * phi */
43  D.apply(sigma, phi, MINUS, 0);
44 
45  for(int mu = 0; mu < Nd; ++mu) {
46 
47  // ftmp_2(x) = -(psi(x) - ftmp_2(x)) = -(1 - gamma(mu))*psi( x )
48  ftmp_2[rb[1]] = Gamma(1<<mu) * psi;
49  ftmp_2[rb[1]] -= psi;
50 
51 
52  // utmp_1 = - Trace_spin [ ( 1 - gamma(mu) )*psi_{x+mu)*sigma^{dagger} ]
53  // = - Trace_spin [ sigma^{dagger} ( 1 - gamma_mu ) psi_{x+mu} ]
54  utmp_1[rb[0]] = -traceSpin( outerProduct( shift(ftmp_2, FORWARD, mu), sigma) );
55 
56 
57  // ftmp_2 = phi + ftmp_2 = (1 + gamma(mu))*phi( x)
58  ftmp_2[rb[1]] = Gamma(1<<mu) * phi;
59  ftmp_2[rb[1]] += phi;
60 
61  // utmp_1 += ( 1 + gamma(mu) )*phi_{x+mu)*rho^{dagger}_x
62  utmp_1[rb[0]] += traceSpin( outerProduct( shift(ftmp_2, FORWARD, mu), rho) );
63 
64  // ds_u[mu][0] += u[mu][0] * utmp_1
65  // = u[mu][0] [ ( 1 - gamma(mu) )*psi_{x+mu)*sigma^{dagger}_x
66  // + ( 1 + gamma(mu) )*phi_{x+mu)*rho^{dagger}_x ]
67  ds_u[mu][rb[0]] = prefactor * u[mu] * utmp_1;
68 
69  // Checkerboard 1
70 
71  // ftmp_2 = -(rho - ftmp_2) = -(1 - gamma(mu))*rho( x )
72  ftmp_2[rb[0]] = Gamma(1<<mu)*rho;
73  ftmp_2[rb[0]] -= rho;
74 
75  // utmp_1 = ( 1 - gamma(mu) )*rho_{x+mu)*phi^{dagger}_x
76  utmp_1[rb[1]] = -traceSpin( outerProduct( shift(ftmp_2, FORWARD, mu), phi) );
77 
78  // ftmp_2 = (gamma(mu))*sigma
79  ftmp_2[rb[0]] = Gamma(1<<mu)*sigma;
80  ftmp_2[rb[0]] += sigma;
81 
82 
83  utmp_1[rb[1]] += traceSpin( outerProduct( shift(ftmp_2, FORWARD, mu), psi) );
84  ds_u[mu][rb[1]] = prefactor * u[mu] * utmp_1;
85 
86  }
87 
88  END_CODE();
89 }
90 
91 void funky_new_dsdu(const EvenOddPrecLinearOperator<LatticeFermion, multi1d<LatticeColorMatrix> >& M,
92  multi1d<LatticeColorMatrix> & ds_u,
93  const LatticeFermion& X) {
94  LatticeFermion Y;
95  M(Y,X,PLUS);
96 
97  // The 2 flavour derivative is:
98  // -Xdag ( Mdag^{dot} M + M^dag M^{dot} ) X
99  // = -Xdag Mdag^dot M X - Xdag Mdat M^{dot}X
100  // = -Xdag Mdag^dot Y - Ydag M^dot X
101  // = -( Xdag Mdag^dot Y + Ydat M^dot X )
102 
103  // Do the X^dag Mdag^dot Y term
104  ds_u = zero;
105  M.deriv(ds_u, X, Y, MINUS);
106 
107  // Do the Ydag M^dot X term
108  multi1d<LatticeColorMatrix> F_tmp(Nd);
109  F_tmp = zero;
110  M.deriv(F_tmp, Y, X, PLUS);
111 
112  // Add them and put in the minus sign
113  for(int mu=0; mu < Nd; mu++) {
114 
115  ds_u[mu] += F_tmp[mu];
116  ds_u[mu] *= Real(-1);
117 
118  }
119 
120 
121 }
122 
123 
124 int main(int argc, char *argv[])
125 {
126  // Initialise QDP
127  Chroma::initialize(&argc, &argv);
128 
129  // Setup a small lattice
130  const int nrow_arr[] = {2, 2, 2, 2};
131  multi1d<int> nrow(Nd);
132  nrow=nrow_arr;
133  Layout::setLattSize(nrow);
134  Layout::create();
135 
136 
137  multi1d<LatticeColorMatrix> u(Nd);
138  {
139  XMLReader file_xml;
140  XMLReader config_xml;
141  Cfg_t foo; foo.cfg_type=CFG_TYPE_UNIT;
142  // Cfg_t foo; foo.cfg_type=CFG_TYPE_SZIN; foo.cfg_file="./CFGIN";
143  gaugeStartup(file_xml, config_xml, u, foo);
144  }
145 
146  XMLFileWriter xml_out("./XMLDAT");
147  push(xml_out, "t_prec_wilson_force");
148 
149  multi1d<LatticeColorMatrix> p(Nd);
150  multi1d<LatticeFermion> phi(1);
151 
152 
153  // Get Periodic Gauge Boundaries
155  Real betaMC = Real(5.7);
156  WilsonGaugeAct S_pg_MC(gbc, betaMC);
157 
158  multi1d<int> boundary(Nd);
159  boundary[0] = 1;
160  boundary[1] = 1;
161  boundary[2] = 1;
162  boundary[3] =-1;
163 
164  // Now set up a ferm act
166 
167  // Now make up an array of handles
168  Real m = Real(0.1);
169  EvenOddPrecWilsonFermAct S_f_MC(fbc, m);
170 
172 
173  multi1d<LatticeColorMatrix> dsdu_1(Nd);
174  multi1d<LatticeColorMatrix> dsdu_2(Nd);
175 
176  LatticeFermion psi;
177  gaussian(psi);
178  // for(int mu=0; mu < Nd; mu++) {
179  // dsdu_1[mu] = zero;
180  // dsdu_2[mu] = zero;
181  // }
182 
183  // S_f_MC.dsdu(dsdu_1, state, psi);
184  //S_f_MC.dsdu2(dsdu_2, state, psi);
185 
186  prec_wilson_dsdu(S_f_MC, m, dsdu_1, state, psi);
187 
189 
190 
191  funky_new_dsdu(*M_w, dsdu_2, psi);
192 
193  for(int mu=0; mu < Nd; mu++) {
194  taproj(dsdu_1[mu]);
195  taproj(dsdu_2[mu]);
196 
197  push(xml_out, "dsdu");
198  write(xml_out, "dsdu_1", dsdu_1[mu]);
199  write(xml_out, "dsdu_2", dsdu_2[mu]);
200  pop(xml_out);
201 
202  LatticeColorMatrix dsdu_diff=dsdu_1[mu] - dsdu_2[mu];
203 
204  Double sum_diff=norm2(dsdu_diff);
205  QDPIO::cout << "Mu = " << mu << " Sum Diff=" << sum_diff << std::endl;
206 
207  push(xml_out, "ForceDiff");
208  write(xml_out, "mu", mu);
209  write(xml_out, "dsdu_diff", dsdu_diff);
210  pop(xml_out);
211  }
212 
213  pop(xml_out);
214  xml_out.close();
215 
216  // Finish
218 
219  exit(0);
220 }
221 
Primary include file for CHROMA in application codes.
Even-odd preconditioned linear operator.
Definition: eoprec_linop.h:92
Even-odd preconditioned Wilson fermion action.
EvenOddPrecConstDetLinearOperator< T, P, Q > * linOp(Handle< FermState< T, P, Q > > state) const
Produce a linear operator for this action.
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
General Wilson-Dirac dslash.
Definition: lwldslash_w.h:48
Concrete class for all gauge actions with simple boundary conditions.
Definition: simple_fermbc.h:42
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.
void apply(T &chi, const T &psi, enum PlusMinus isign, int cb) const
General Wilson-Dirac dslash.
Definition: lwldslash_w.h:228
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
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > const multi1d< Real > & Mass
Definition: pbg5p_w.cc:29
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
Double zero
Definition: invbicg.cc:106
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 EvenOddPrecLinearOperator< LatticeFermion, multi1d< LatticeColorMatrix > > &M, multi1d< LatticeColorMatrix > &ds_u, const LatticeFermion &X)
void prec_wilson_dsdu(const EvenOddPrecWilsonFermAct &S, const Real &Mass, multi1d< LatticeColorMatrix > &ds_u, Handle< const ConnectState > state, const LatticeFermion &psi)