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