CHROMA
mom_source_const.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Momentum (wall) source construction
3  */
4 
5 #include "chromabase.h"
6 
9 #include "util/ft/sftmom.h"
10 #include "util/ferm/transf.h"
11 
12 namespace Chroma
13 {
14  // Read parameters
15  void read(XMLReader& xml, const std::string& path, MomWallQuarkSourceConstEnv::Params& param)
16  {
18  param = tmp;
19  }
20 
21  // Writer
22  void write(XMLWriter& xml, const std::string& path, const MomWallQuarkSourceConstEnv::Params& param)
23  {
24  param.writeXML(xml, path);
25  }
26 
27 
28  //! Fill a specific color and spin index with 1.0 within a volume
29  /*! \ingroup sources */
30  void boxfil(LatticeFermion& a, int color_index, int spin_index)
31  {
32  START_CODE();
33 
34  if (color_index >= Nc || color_index < 0)
35  QDP_error_exit("invalid color index", color_index);
36 
37  if (spin_index >= Ns || spin_index < 0)
38  QDP_error_exit("invalid spin index", spin_index);
39 
40  // Write ONE to all field
41  Real one = 1;
42  Complex sitecomp = cmplx(one,0);
43  ColorVector sitecolor = zero;
44  Fermion sitefield = zero;
45 
46  pokeSpin(sitefield,
47  pokeColor(sitecolor,sitecomp,color_index),
48  spin_index);
49 
50  // Broadcast to all sites
51  a = sitefield; // QDP (not installed version) now supports construct OLattice = OScalar
52 
53  END_CODE();
54  }
55 
56 
57  //! Hooks to register the class
58  namespace MomWallQuarkSourceConstEnv
59  {
60  namespace
61  {
62  //! Callback function
63  QuarkSourceConstruction<LatticePropagator>* createProp(XMLReader& xml_in,
64  const std::string& path)
65  {
66  return new SourceConst<LatticePropagator>(Params(xml_in, path));
67  }
68 
69  //! Name to be used
70  const std::string name("MOMENTUM_VOLUME_SOURCE");
71 
72  //! Local registration flag
73  bool registered = false;
74  }
75 
76  //! Return the name
77  std::string getName() {return name;}
78 
79  //! Register all the factories
80  bool registerAll()
81  {
82  bool success = true;
83  if (! registered)
84  {
85  success &= Chroma::ThePropSourceConstructionFactory::Instance().registerObject(name, createProp);
86  registered = true;
87  }
88  return success;
89  }
90 
91 
92  //! Initialize
94  {
95  j_decay = -1;
96  av_mom = false ;
97  }
98 
99 
100  //! Read parameters
101  Params::Params(XMLReader& xml, const std::string& path)
102  {
103  XMLReader paramtop(xml, path);
104 
105  int version;
106  read(paramtop, "version", version);
107 
108  switch (version)
109  {
110  case 1:
111  break;
112 
113  default:
114  QDPIO::cerr << __func__ << ": parameter version " << version
115  << " unsupported." << std::endl;
116  QDP_abort(1);
117  }
118 
119  read(paramtop, "j_decay", j_decay);
120  read(paramtop, "t_srce", t_srce);
121  read(paramtop, "av_mom", av_mom) ;
122  read(paramtop, "mom", mom);
123 
124  if (mom.size() != Nd)
125  {
126  QDPIO::cerr << name << ": wrong size of mom array: expected length=" << Nd << std::endl;
127  QDP_abort(1);
128  }
129  }
130 
131 
132  // Writer
133  void Params::writeXML(XMLWriter& xml, const std::string& path) const
134  {
135  push(xml, path);
136 
137  int version = 1;
138  write(xml, "version", version);
139 
140  write(xml, "mom", mom);
141  write(xml, "av_mom", av_mom) ;
142  write(xml, "j_decay", j_decay);
143  write(xml, "t_srce", t_srce);
144 
145  pop(xml);
146  }
147 
148 
149  //! Construct the source
150  template<>
151  LatticePropagator
152  SourceConst<LatticePropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
153  {
154  QDPIO::cout << "Volume Momentum Source" << std::endl;
155 
156  LatticeComplex phase ;
157  // Initialize the slow Fourier transform phases
158  if(params.av_mom){
159  multi1d<int> mom3(Nd-1);
160  for(int mu=0,j=0; mu < Nd; ++mu){
161  if (mu != params.j_decay)
162  mom3[j++] = params.mom[mu];
163  }
164  //just get one momentum. the one we want!
165  SftMom phases(0, params.t_srce, mom3, params.av_mom, params.j_decay);
166  mom3 = phases.canonicalOrder(mom3);
167  Real fact = twopi * Real(params.mom[params.j_decay]) / Real(Layout::lattSize()[params.j_decay]);
168  phase = cos( fact * QDP::Layout::latticeCoordinate(params.j_decay) );
169  /**
170  for (int sink_mom_num=0; sink_mom_num < phases.numMom(); ++sink_mom_num){
171  multi1d<int> mom = phases.canonicalOrder(phases.numToMom(sink_mom_num));
172  if (mom == mom3)
173  phase *= phases[sink_mom_num];
174  }**/
175  phase *= phases[0];
176  multi1d<int> mom = phases.canonicalOrder(phases.numToMom(0));
177  QDPIO::cout<<"Source momentum (averaged over equivalent momenta): " ;
178  QDPIO::cout<<mom[0]<<mom[1]<<mom[2]<<std::endl;
179  }
180  else{ // do not use momentum averaged sources
181  SftMom phases(0, params.t_srce, params.mom);
182  phase = phases[0] ;
183  multi1d<int> mom = phases.numToMom(0) ;
184  QDPIO::cout<<"Source momentum: " ;
185  QDPIO::cout<<mom[0]<<mom[1]<<mom[2]<<mom[3]<<std::endl;
186  }
187 
188  // Create the quark source
189  LatticePropagator quark_source;
190  for(int color_source = 0; color_source < Nc; ++color_source)
191  {
192  for(int spin_source = 0; spin_source < Ns; ++spin_source)
193  {
194  // MomWall fill a fermion source. Insert it into the propagator source
195  LatticeFermion chi;
196  boxfil(chi, color_source, spin_source);
197  // Multiply in the time direction phases (not handled in sftmom)
198  chi *= phase;
199  FermToProp(chi, quark_source, color_source, spin_source);
200  }
201  }
202 
203  return quark_source;
204  }
205 
206  }
207 
208 }
Primary include file for CHROMA library code.
T operator()(const multi1d< LatticeColorMatrix > &u) const
Construct the source.
Base class for quark source construction.
Fourier transform phase factor support.
Definition: sftmom.h:35
multi1d< int > canonicalOrder(const multi1d< int > &mom) const
Canonically order an array of momenta.
Definition: sftmom.cc:464
multi1d< int > numToMom(int mom_num) const
Convert momenta id to actual array of momenta.
Definition: sftmom.h:78
static T & Instance()
Definition: singleton.h:432
int mu
Definition: cool.cc:24
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.
void boxfil(LatticeFermion &a, int color_index, int spin_index)
Fill a specific color and spin index with 1.0 within a volume.
Params params
unsigned j
Definition: ldumul_w.cc:35
Nd
Definition: meslate.cc:74
Fixed momentum (wall) source construction.
static bool registered
Local registration flag.
const std::string name
Name to be used.
std::string getName()
Return the name.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
QDP_error_exit("too many BiCG iterations", n_count, rsd_sq, cp, c, re_rvr, im_rvr, re_a, im_a, re_b, im_b)
static multi1d< LatticeColorMatrix > u
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
Double one
Definition: invbicg.cc:105
push(xml_out,"Condensates")
multi1d< LatticeFermion > chi(Ncb)
const Real twopi
Definition: chromabase.h:55
Complex a
Definition: invbicg.cc:95
pop(xml_out)
START_CODE()
Double zero
Definition: invbicg.cc:106
::std::string string
Definition: gtest.h:1979
Fourier transform phase factor support.
Factory for producing quark prop sources.
void writeXML(XMLWriter &in, const std::string &path) const