CHROMA
sf_sh_source_const.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Shell source construction for Schroedinger Functional
3  */
4 
5 #include "chromabase.h"
6 #include "handle.h"
7 #include "fermbc.h"
8 
12 
15 #include "meas/sources/srcfil.h"
16 #include "util/ferm/transf.h"
17 
20 
23 
26 
27 namespace Chroma
28 {
29 
30  //! Hooks to register the class
31  namespace SFShellQuarkSourceConstEnv
32  {
33  namespace
34  {
35  //! Callback function
36  QuarkSourceConstruction<LatticePropagator>* createProp(XMLReader& xml_in,
37  const std::string& path)
38  {
39  return new SourceConst<LatticePropagator>(Params(xml_in, path));
40  }
41 
42  //! Local registration flag
43  bool registered = false;
44 
45  //! Name to be used
46  const std::string name("SF_SHELL_SOURCE");
47  }
48 
49  //! Return the name
50  std::string getName() {return name;}
51 
52  //! Register all the factories
53  bool registerAll()
54  {
55  bool success = true;
56  if (! registered)
57  {
58  success &= PlusMinusEnv::registered;
60  success &= LinkSmearingEnv::registerAll();
61  success &= QuarkSmearingEnv::registerAll();
63  success &= Chroma::ThePropSourceConstructionFactory::Instance().registerObject(name, createProp);
64 
65  registered = true;
66  }
67  return success;
68  }
69 
70 
71  //! Read parameters
73  {
74  j_decay = -1;
75  t_srce.resize(Nd);
76  t_srce = 0;
77  }
78 
79  //! Read parameters
80  Params::Params(XMLReader& xml, const std::string& path)
81  {
82  XMLReader paramtop(xml, path);
83 
84  int version;
85  read(paramtop, "version", version);
86 
87  switch (version)
88  {
89  case 1:
90  break;
91 
92  default:
93  QDPIO::cerr << __func__ << ": parameter version " << version
94  << " unsupported." << std::endl;
95  QDP_abort(1);
96  }
97 
98  quark_smearing = readXMLGroup(paramtop, "SmearingParam", "wvf_kind");
99 
100  if (paramtop.count("Displacement") != 0)
101  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
102  else
104 
105  if (paramtop.count("LinkSmearing") != 0)
106  link_smearing = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
107  else
109 
110  fermbc = readXMLGroup(paramtop, "FermionBC", "FermBC");
111 
112  read(paramtop, "direction", direction);
113  read(paramtop, "t_srce", t_srce);
114  read(paramtop, "j_decay", j_decay);
115 
116  // Sanity check
117  if (j_decay < 0 || j_decay >= Nd)
118  {
119  QDPIO::cerr << name << ": invalid j_decay=" << j_decay << std::endl;
120  QDP_abort(1);
121  }
122  }
123 
124 
125  // Writer
126  void Params::writeXML(XMLWriter& xml, const std::string& path) const
127  {
128  push(xml, path);
129 
130  int version = 1;
131  write(xml, "version", version);
132  write(xml, "SourceType", SFShellQuarkSourceConstEnv::name);
133  write(xml, "direction", direction);
134  write(xml, "t_srce", t_srce);
135  write(xml, "j_decay", j_decay);
136  xml << quark_smearing.xml;
137  xml << quark_displacement.xml;
138  xml << link_smearing.xml;
139  xml << fermbc.xml;
140 
141  pop(xml);
142  }
143 
144 
145 
146  //! Construct the source
147  template<>
148  LatticePropagator
149  SourceConst<LatticePropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
150  {
151  QDPIO::cout << "SF Shell source" << std::endl;
152 
153  // Source
154  LatticePropagator quark_source;
155 
156  // Spin projectors
157  int jd = 1 << params.j_decay;
158  SpinMatrix g_one = 1.0;
159  SpinMatrix P_plus = 0.5*(g_one + (Gamma(jd) * g_one));
160  SpinMatrix P_minus = 0.5*(g_one - (Gamma(jd) * g_one));
161 
162  try
163  {
164  //
165  // Smear the gauge field if needed
166  //
167  multi1d<LatticeColorMatrix> u_smr = u;
168  {
169  std::istringstream xml_l(params.link_smearing.xml);
170  XMLReader linktop(xml_l);
171  QDPIO::cout << "Link smearing type = " << params.link_smearing.id << std::endl;
172 
174  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.link_smearing.id,
175  linktop,
177  (*linkSmearing)(u_smr);
178  }
179 
180  //
181  // Create the quark smearing object
182  //
183  std::istringstream xml_s(params.quark_smearing.xml);
184  XMLReader smeartop(xml_s);
185  QDPIO::cout << "Quark smearing type = " << params.quark_smearing.id << std::endl;
186 
188  quarkSmearing(ThePropSmearingFactory::Instance().createObject(params.quark_smearing.id,
189  smeartop,
191 
192  //
193  // Create the quark displacement object
194  //
195  std::istringstream xml_d(params.quark_displacement.xml);
196  XMLReader displacetop(xml_d);
197  QDPIO::cout << "Displacement type = " << params.quark_displacement.id << std::endl;
198 
200  quarkDisplacement(ThePropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
201  displacetop,
203 
204  //
205  // Create the FermBC object
206  //
207  std::istringstream xml_f(params.fermbc.xml);
208  XMLReader fermbctop(xml_f);
209  QDPIO::cout << "FermBC type = " << params.fermbc.id << std::endl;
210 
211  Handle< FermBC<LatticeFermion,
212  multi1d<LatticeColorMatrix>,
213  multi1d<LatticeColorMatrix> > >
215  fermbctop,
216  params.fermbc.path));
217 
218  // Need to downcast to the appropriate BC
219  const SchrFermBC& fermbc = dynamic_cast<const SchrFermBC&>(*fbc);
220 
221  // Location of upper wall source
222  // Check it is legit
223  int tmin = fermbc.getDecayMin();
224  int tmax = fermbc.getDecayMax();
225  int t0 = (params.direction == MINUS) ? tmax : tmin;
226  if (t0 != params.t_srce[params.j_decay])
227  {
228  QDPIO::cerr << name << ": time slice source location does not agree with this FermBC" << std::endl;
229  QDP_abort(1);
230  }
231 
232  // Create the source
233  for(int color_source = 0; color_source < Nc; ++color_source)
234  {
235  QDPIO::cout << "color = " << color_source << std::endl;
236 
237  LatticeColorVector src_color_vec = zero;
238 
239  // Make a point source at coordinates t_srce
240  srcfil(src_color_vec, params.t_srce, color_source);
241 
242  for(int spin_source = 0; spin_source < Ns; ++spin_source)
243  {
244  QDPIO::cout << "spin = " << spin_source << std::endl;
245 
246  // Insert a ColorVector into spin index spin_source
247  // This only overwrites sections, so need to initialize first
248  LatticeFermion tmp1 = zero;
249  CvToFerm(src_color_vec, tmp1, spin_source);
250 
251  LatticeFermion chi;
252  switch (params.direction)
253  {
254  case MINUS:
255  chi = P_minus * (u[params.j_decay] * tmp1);
256  break;
257 
258  case PLUS:
259  chi = shift(P_plus * (adj(u[params.j_decay]) * tmp1), BACKWARD, params.j_decay);
260  break;
261 
262  default:
263  QDPIO::cerr << name << ": illegal direction" << std::endl;
264  QDP_abort(1);
265  }
266 
267  /*
268  * Move the source to the appropriate components
269  * of quark source.
270  */
271  FermToProp(chi, quark_source, color_source, spin_source);
272  }
273  }
274 
275 
276  // Smear the colour source
277  // displace the point source first, then smear
278  // displacement has to be taken along negative direction.
279  (*quarkDisplacement)(quark_source, u_smr, MINUS);
280 
281  // do the smearing
282  (*quarkSmearing)(quark_source, u_smr);
283  }
284  catch(std::bad_cast)
285  {
286  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
287  QDP_abort(1);
288  }
289  catch(const std::string& e)
290  {
291  QDPIO::cerr << name << ": Caught Exception smearing: " << e << std::endl;
292  QDP_abort(1);
293  }
294 
295  return quark_source;
296  }
297 
298  } // namespace SFShellQuarkSourceConstEnv
299 
300 } // namespace Chroma
Primary include file for CHROMA library code.
Base class for all fermion action boundary conditions.
Definition: fermbc.h:20
Class for counted reference semantics.
Definition: handle.h:33
Base class for quark source construction.
Shell source construction for Schroedinger Functional.
T operator()(const multi1d< LatticeColorMatrix > &u) const
Construct the source.
Abstract class for all gauge action boundary conditions with Schroedinger BC.
virtual int getDecayMin() const =0
Starting slice in decay direction.
virtual int getDecayMax() const =0
Ending slice in decay direction.
static T & Instance()
Definition: singleton.h:432
Fermion action boundary conditions.
Fermion Boundary Condition factories.
All Wilson-type fermion boundary conditions.
void CvToFerm(const LatticeColorVectorF &a, LatticeFermionF &b, int spin_index)
Convert (insert) a LatticeColorVector into a LatticeFermion.
Definition: transf.cc:18
void FermToProp(const LatticeFermionF &a, LatticePropagatorF &b, int color_index, int spin_index)
Insert a LatticeFermion into a LatticePropagator.
Definition: transf.cc:98
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.
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
void srcfil(LatticeFermion &a, const multi1d< int > &coord, int color_index, int spin_index)
Fill a specific color and spin index with 1.0.
Definition: srcfil.cc:23
Class for counted reference semantics.
Params params
Nd
Definition: meslate.cc:74
static bool registered
Local registration flag.
const std::string name
Name to be used.
GroupXML_t nullXMLGroup()
Returns a no-linksmearing group.
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
GroupXML_t nullXMLGroup()
Returns a no-displacement group.
bool registerAll()
Register all the factories.
std::string getName()
Return the name.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
@ MINUS
Definition: chromabase.h:45
@ PLUS
Definition: chromabase.h:45
multi1d< LatticeFermion > chi(Ncb)
pop(xml_out)
Double zero
Definition: invbicg.cc:106
::std::string string
Definition: gtest.h:1979
#define BACKWARD
Definition: primitives.h:83
All quark displacement constructors.
Factory for producing quark displacement objects.
All quark smearing constructors.
Factory for producing quark smearing objects.
Fermion action boundary conditions.
Shell source construction for Schroedinger Functional.
Factory for producing quark prop sources.
Point source construction.
void writeXML(XMLWriter &out, const std::string &path) const