CHROMA
sf_pt_source_const.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Point 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"
20 #include "util/ferm/transf.h"
21 
22 namespace Chroma
23 {
24  //! Hooks to register the class
25  namespace SFPointQuarkSourceConstEnv
26  {
27  namespace
28  {
29  //! Callback function
30  QuarkSourceConstruction<LatticePropagator>* createProp(XMLReader& xml_in,
31  const std::string& path)
32  {
33  return new SourceConst<LatticePropagator>(Params(xml_in, path));
34  }
35 
36  //! Callback function
37  QuarkSourceConstruction<LatticeStaggeredPropagator>* createStagProp(XMLReader& xml_in,
38  const std::string& path)
39  {
40  return new SourceConst<LatticeStaggeredPropagator>(Params(xml_in, path));
41  }
42 
43  //! Local registration flag
44  bool registered = false;
45 
46  //! Name to be used
47  const std::string name("SF_POINT_SOURCE");
48  }
49 
50  //! Return the name
51  std::string getName() {return name;}
52 
53  //! Register all the factories
54  bool registerAll()
55  {
56  bool success = true;
57  if (! registered)
58  {
59  success &= PlusMinusEnv::registered;
61  success &= LinkSmearingEnv::registerAll();
63  success &= Chroma::ThePropSourceConstructionFactory::Instance().registerObject(name, createProp);
64  success &= Chroma::TheStagPropSourceConstructionFactory::Instance().registerObject(name, createStagProp);
65  registered = true;
66  }
67  return success;
68  }
69 
70  //! Initialize
72  {
73  j_decay = -1;
74  t_srce.resize(Nd);
75  t_srce = 0;
76  }
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  fermbc = readXMLGroup(paramtop, "FermionBC", "FermBC");
99  read(paramtop, "direction", direction);
100  read(paramtop, "j_decay", j_decay);
101  read(paramtop, "t_srce", t_srce);
102 
103  if (paramtop.count("Displacement") != 0)
104  quark_displacement = readXMLGroup(paramtop, "Displacement", "DisplacementType");
105  else
107 
108  if (paramtop.count("LinkSmearing") != 0)
109  link_smearing = readXMLGroup(paramtop, "LinkSmearing", "LinkSmearingType");
110  else
112 
113  // Sanity check
114  if (j_decay < 0 || j_decay >= Nd)
115  {
116  QDPIO::cerr << name << ": invalid j_decay=" << j_decay << std::endl;
117  QDP_abort(1);
118  }
119  }
120 
121 
122  // Writer
123  void Params::writeXML(XMLWriter& xml, const std::string& path) const
124  {
125  push(xml, path);
126 
127  int version = 1;
128  write(xml, "version", version);
129 
130  write(xml, "SourceType", SFPointQuarkSourceConstEnv::name);
131  write(xml, "direction", direction);
132  write(xml, "j_decay", j_decay);
133  write(xml, "t_srce", t_srce);
134  xml << link_smearing.xml;
135  xml << quark_displacement.xml;
136  xml << fermbc.xml;
137  pop(xml);
138  }
139 
140 
141 
142  //! Construct the source
143  template<>
144  LatticePropagator
145  SourceConst<LatticePropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
146  {
147  QDPIO::cout << "SF Point source" << std::endl;
148 
149  // Create the quark source
150  LatticePropagator quark_source;
151 
152  // Spin projectors
153  int jd = 1 << params.j_decay;
154  SpinMatrix g_one = 1.0;
155  SpinMatrix P_plus = 0.5*(g_one + (Gamma(jd) * g_one));
156  SpinMatrix P_minus = 0.5*(g_one - (Gamma(jd) * g_one));
157 
158  try
159  {
160  //
161  // Smear the gauge field if needed
162  //
163  multi1d<LatticeColorMatrix> u_smr = u;
164  {
165  std::istringstream xml_l(params.link_smearing.xml);
166  XMLReader linktop(xml_l);
167  QDPIO::cout << "Link smearing type = " << params.link_smearing.id << std::endl;
168 
170  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.link_smearing.id,
171  linktop,
173  (*linkSmearing)(u_smr);
174  }
175 
176  //
177  // Create the quark displacement object
178  //
179  std::istringstream xml_d(params.quark_displacement.xml);
180  XMLReader displacetop(xml_d);
181 
183  quarkDisplacement(ThePropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
184  displacetop,
186 
187  //
188  // Create the FermBC object
189  //
190  std::istringstream xml_s(params.fermbc.xml);
191  XMLReader fermbctop(xml_s);
192  QDPIO::cout << "FermBC type = " << params.fermbc.id << std::endl;
193 
194  Handle< FermBC<LatticeFermion,
195  multi1d<LatticeColorMatrix>,
196  multi1d<LatticeColorMatrix> > >
198  fermbctop,
199  params.fermbc.path));
200 
201  // Need to downcast to the appropriate BC
202  const SchrFermBC& fermbc = dynamic_cast<const SchrFermBC&>(*fbc);
203 
204  // Location of upper wall source
205  // Check it is legit
206  int tmin = fermbc.getDecayMin();
207  int tmax = fermbc.getDecayMax();
208  int t0 = (params.direction == MINUS) ? tmax : tmin;
209  if (t0 != params.t_srce[params.j_decay])
210  {
211  QDPIO::cerr << name << ": time slice source location does not agree with this FermBC" << std::endl;
212  QDP_abort(1);
213  }
214 
215 
216  // Create the source
217  for(int color_source = 0; color_source < Nc; ++color_source)
218  {
219  QDPIO::cout << "color = " << color_source << std::endl;
220 
221  LatticeColorVector src_color_vec = zero;
222 
223  // Make a point source at coordinates t_source
224  srcfil(src_color_vec, params.t_srce, color_source);
225 
226  for(int spin_source = 0; spin_source < Ns; ++spin_source)
227  {
228  QDPIO::cout << "spin = " << spin_source << std::endl;
229 
230  // Insert a ColorVector into spin index spin_source
231  // This only overwrites sections, so need to initialize first
232  LatticeFermion tmp1 = zero;
233  CvToFerm(src_color_vec, tmp1, spin_source);
234 
235  LatticeFermion chi;
236  switch (params.direction)
237  {
238  case MINUS:
239  chi = P_minus * (u[params.j_decay] * tmp1);
240  break;
241 
242  case PLUS:
243  chi = shift(P_plus * (adj(u[params.j_decay]) * tmp1), BACKWARD, params.j_decay);
244  break;
245 
246  default:
247  QDPIO::cerr << name << ": illegal direction" << std::endl;
248  QDP_abort(1);
249  }
250 
251  /*
252  * Move the source to the appropriate components
253  * of quark source.
254  */
255  FermToProp(chi, quark_source, color_source, spin_source);
256  }
257  }
258 
259  // displace the point source first, then smear
260  // displacement has to be taken along negative direction.
261  (*quarkDisplacement)(quark_source, u_smr, MINUS);
262 
263  }
264  catch(std::bad_cast)
265  {
266  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
267  QDP_abort(1);
268  }
269  catch(const std::string& e)
270  {
271  QDPIO::cerr << name << ": Caught Exception in source construction: " << e << std::endl;
272  QDP_abort(1);
273  }
274 
275  return quark_source;
276  }
277 
278 
279 
280  //! Construct the source
281  template<>
282  LatticeStaggeredPropagator
283  SourceConst<LatticeStaggeredPropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
284  {
285  QDPIO::cout << "Point source" << std::endl;
286 
287  // Create the quark source
288  LatticeStaggeredPropagator quark_source;
289 
290  try
291  {
292  //
293  // Smear the gauge field if needed
294  //
295  multi1d<LatticeColorMatrix> u_smr = u;
296  {
297  std::istringstream xml_l(params.link_smearing.xml);
298  XMLReader linktop(xml_l);
299  QDPIO::cout << "Link smearing type = " << params.link_smearing.id << std::endl;
300 
302  linkSmearing(TheLinkSmearingFactory::Instance().createObject(params.link_smearing.id,
303  linktop,
305  (*linkSmearing)(u_smr);
306  }
307 
308  //
309  // Create the quark displacement object
310  //
311  std::istringstream xml_d(params.quark_displacement.xml);
312  XMLReader displacetop(xml_d);
313 
315  quarkDisplacement(TheStagPropDisplacementFactory::Instance().createObject(params.quark_displacement.id,
316  displacetop,
318 
319  for(int color_source = 0; color_source < Nc; ++color_source)
320  {
321  QDPIO::cout << "color = " << color_source << std::endl;
322 
323  LatticeColorVector src_color_vec = zero;
324 
325  // Make a point source at coordinates t_source
326  srcfil(src_color_vec, params.t_srce, color_source);
327 
328  // Insert a ColorVector into spin index spin_source
329  // This only overwrites sections, so need to initialize first
330  LatticeStaggeredFermion chi = zero;
331 
332  CvToFerm(src_color_vec, chi);
333 
334  /*
335  * Move the source to the appropriate components
336  * of quark source.
337  */
338  FermToProp(chi, quark_source, color_source);
339  }
340 
341  // displace the point source first, then smear
342  // displacement has to be taken along negative direction.
343  (*quarkDisplacement)(quark_source, u_smr, MINUS);
344 
345  }
346  catch(const std::string& e)
347  {
348  QDPIO::cerr << name << ": Caught Exception in source construction: " << e << std::endl;
349  QDP_abort(1);
350  }
351 
352  return quark_source;
353  }
354 
355  }
356 
357 }
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.
Point 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.
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.
Fermion action boundary conditions.
Point source construction for Schroedinger Functional.
Factory for producing quark prop sources.
Point source construction.
void writeXML(XMLWriter &in, const std::string &path) const