CHROMA
sf_wave_source_const.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief plane wave 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/walfil_w.h"
16 #include "util/ferm/transf.h"
17 #include "util/ft/single_phase.h"
18 
19 namespace Chroma
20 {
21  //! Hooks to register the class
22  namespace SFWaveQuarkSourceConstEnv
23  {
24  namespace
25  {
26  //! Callback function
27  QuarkSourceConstruction<LatticePropagator>* createProp(XMLReader& xml_in,
28  const std::string& path)
29  {
30  return new SourceConst<LatticePropagator>(Params(xml_in, path));
31  }
32 
33  //! Name to be used
34  const std::string name("SF_WAVE_SOURCE");
35 
36  //! Local registration flag
37  bool registered = false;
38  }
39 
40  //! Return the name
41  std::string getName() {return name;}
42 
43  //! Register all the factories
44  bool registerAll()
45  {
46  bool success = true;
47  if (! registered)
48  {
49  success &= PlusMinusEnv::registered;
51  success &= Chroma::ThePropSourceConstructionFactory::Instance().registerObject(name, createProp);
52  registered = true;
53  }
54  return success;
55  }
56 
57 
58  //! Initialize
60  {
61  j_decay = -1;
62  t_source = -1;
63  }
64 
65 
66  //! Read parameters
67  Params::Params(XMLReader& xml, const std::string& path)
68  {
69  XMLReader paramtop(xml, path);
70 
71  int version;
72  read(paramtop, "version", version);
73 
74  switch (version)
75  {
76  case 1:
77  break;
78 
79  default:
80  QDPIO::cerr << __func__ << ": parameter version " << version
81  << " unsupported." << std::endl;
82  QDP_abort(1);
83  }
84 
85  fermbc = readXMLGroup(paramtop, "FermionBC", "FermBC");
86 
87  read(paramtop, "direction", direction);
88  read(paramtop, "j_decay", j_decay);
89  read(paramtop, "t_source", t_source);
90  read(paramtop, "mom", mom) ;
91  // Sanity check
92  if (j_decay < 0 || j_decay >= Nd)
93  {
94  QDPIO::cerr << name << ": invalid j_decay=" << j_decay << std::endl;
95  QDP_abort(1);
96  }
97  }
98 
99 
100  // Writer
101  void Params::writeXML(XMLWriter& xml, const std::string& path) const
102  {
103  push(xml, path);
104 
105  int version = 1;
106  write(xml, "version", version);
107  write(xml, "SourceType", SFWaveQuarkSourceConstEnv::name);
108  write(xml, "direction", direction);
109  write(xml, "j_decay", j_decay);
110  write(xml, "t_source", t_source);
111  write(xml, "mom", mom);
112  xml << fermbc.xml;
113  pop(xml);
114  }
115 
116 
117  //! Construct the source
118  template<>
119  LatticePropagator
120  SourceConst<LatticePropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
121  {
122  QDPIO::cout << "SF Wave source" << std::endl;
123 
124  // Create the quark source
125  LatticePropagator quark_source;
126 
127  // Spin projectors
128  int jd = 1 << params.j_decay;
129  SpinMatrix g_one = 1.0;
130  SpinMatrix P_plus = 0.5*(g_one + (Gamma(jd) * g_one));
131  SpinMatrix P_minus = 0.5*(g_one - (Gamma(jd) * g_one));
132 
133  try
134  {
135  //
136  // Create the FermBC object
137  //
138  std::istringstream xml_s(params.fermbc.xml);
139  XMLReader fermbctop(xml_s);
140  QDPIO::cout << "FermBC type = " << params.fermbc.id << std::endl;
141 
142  Handle< FermBC<LatticeFermion,
143  multi1d<LatticeColorMatrix>,
144  multi1d<LatticeColorMatrix> > >
146  fermbctop,
147  params.fermbc.path));
148 
149  // Need to downcast to the appropriate BC
150  const SchrFermBC& fermbc = dynamic_cast<const SchrFermBC&>(*fbc);
151 
152  // Location of upper wave source
153  // Check it is legit
154  int tmin = fermbc.getDecayMin();
155  int tmax = fermbc.getDecayMax();
156  int t0 = (params.direction == MINUS) ? tmax : tmin;
157  if (t0 != params.t_source)
158  {
159  QDPIO::cerr << name << ": time slice source location does not agree with this FermBC" << std::endl;
160  QDP_abort(1);
161  }
162 
163  LatticeComplex phase ;
164  {
165  multi1d<int> tt(Nd); tt=0 ;
166  phase = singlePhase(tt,params.mom);
167  }
168  // Create the source
169  for(int color_source = 0; color_source < Nc; ++color_source)
170  {
171  for(int spin_source = 0; spin_source < Ns; ++spin_source)
172  {
173  // Wave fill a fermion source. Insert it into the propagator source
174  LatticeFermion tmp1;
175  walfil(tmp1,
177  params.j_decay,
178  color_source, spin_source);
179  tmp1=phase*tmp1 ;// tmp1 is 1 on the source zero everywhere else
180  //now tmp1 contains the phase
181  LatticeFermion chi;
182  switch (params.direction)
183  {
184  case MINUS:
185  chi = P_minus * (u[params.j_decay] * tmp1);
186  break;
187 
188  case PLUS:
189  chi = shift(P_plus * (adj(u[params.j_decay]) * tmp1), BACKWARD, params.j_decay);
190  break;
191 
192  default:
193  QDPIO::cerr << name << ": illegal direction" << std::endl;
194  QDP_abort(1);
195  }
196 
197  FermToProp(chi, quark_source, color_source, spin_source);
198  }
199  }
200  }
201  catch(std::bad_cast)
202  {
203  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
204  QDP_abort(1);
205  }
206  catch(const std::string& e)
207  {
208  QDPIO::cerr << name << ": Caught Exception in applying source or creating fermbc: " << e << std::endl;
209  QDP_abort(1);
210  }
211 
212 
213  return quark_source;
214  }
215 
216  } // namespace SFWaveQuarkSourceConstEnv
217 
218 } // 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.
Wave 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 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.
LatticeComplex singlePhase(const multi1d< int > &t_srce, const multi1d< int > &sink_mom, int j_decay)
A single exp(ip.x) phase used in hadron construction.
Definition: single_phase.cc:13
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
void walfil(LatticeStaggeredFermion &a, int slice, int mu, int color_index, int src_index)
Fill a specific color and spin index with 1.0 on a wall.
Definition: walfil_s.cc:36
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.
bool registerAll()
Register all the factories.
std::string getName()
Return the name.
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)
::std::string string
Definition: gtest.h:1979
#define BACKWARD
Definition: primitives.h:83
Fermion action boundary conditions.
Wave source construction fpr Schroedinger Functional.
Compute a single phase factor.
Factory for producing quark prop sources.
void writeXML(XMLWriter &in, const std::string &path) const
Wall source construction.