CHROMA
rndz2wall_source_const.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Random Z2 wall source construction
3  */
4 
5 #include "chromabase.h"
6 
9 #include "util/ferm/transf.h"
10 
11 namespace Chroma
12 {
13  // Read parameters
14  void read(XMLReader& xml, const std::string& path, RandZ2WallQuarkSourceConstEnv::Params& param)
15  {
17  param = tmp;
18  }
19 
20  // Writer
21  void write(XMLWriter& xml, const std::string& path, const RandZ2WallQuarkSourceConstEnv::Params& param)
22  {
23  param.writeXML(xml, path);
24  }
25 
26 
27 
28  //! Hooks to register the class
29  namespace RandZ2WallQuarkSourceConstEnv
30  {
31  namespace
32  {
33  //! Callback function
34  QuarkSourceConstruction<LatticePropagator>* createProp(XMLReader& xml_in,
35  const std::string& path)
36  {
37  return new SourceConst<LatticePropagator>(Params(xml_in, path));
38  }
39 
40  //! Local registration flag
41  bool registered = false;
42 
43  //! Name to be used
44  const std::string name("RAND_Z2_WALL_SOURCE");
45  }
46 
47  //! Return the name
48  std::string getName() {return name;}
49 
50  //! Register all the factories
51  bool registerAll()
52  {
53  bool success = true;
54  if (! registered)
55  {
56  success &= Chroma::ThePropSourceConstructionFactory::Instance().registerObject(name, createProp);
57  registered = true;
58  }
59  return success;
60  }
61 
62 
63  //! Initialize
65  {
66  j_decay = -1;
67  t_source = -1;
68  }
69 
70 
71  //! Read parameters
72  Params::Params(XMLReader& xml, const std::string& path)
73  {
74  XMLReader paramtop(xml, path);
75 
76  int version;
77  read(paramtop, "version", version);
78 
79  switch (version)
80  {
81  case 1:
82  break;
83 
84  default:
85  QDPIO::cerr << __func__ << ": parameter version " << version
86  << " unsupported." << std::endl;
87  QDP_abort(1);
88  }
89 
90  read(paramtop, "ran_seed", ran_seed);
91 
92  /**
93 #if 0
94 #warning "CHECK IF SETTING SEED IS DESIRED BEHAVIOR"
95  //
96  // WARNING!!! Not sure this is the desired behavior
97  //
98  read(paramtop, "ran_seed", ran_seed);
99  QDP::RNG::setrn(ran_seed);
100 #else
101 #warning "CHECK IF GRABBING SEED IS DESIRED BEHAVIOR"
102  QDP::RNG::savern(ran_seed);
103 #endif
104  **/
105 
106  read(paramtop, "j_decay", j_decay);
107  read(paramtop, "t_source", t_source);
108  }
109 
110 
111  // Writer
112  void Params::writeXML(XMLWriter& xml, const std::string& path) const
113  {
114  push(xml, path);
115 
116  int version = 1;
117  write(xml, "version", version);
118  write(xml, "ran_seed", ran_seed);
119  write(xml, "j_decay", j_decay);
120  write(xml, "t_source", t_source);
121  pop(xml);
122  }
123 
124 
125  //! Construct the source
126  template<>
127  LatticePropagator
128  SourceConst<LatticePropagator>::operator()(const multi1d<LatticeColorMatrix>& u) const
129  {
130  QDPIO::cout << "Rand Z2 Wall source" << std::endl;
131 
132 
133  // Save current seed
134  Seed ran_seed;
135  QDP::RNG::savern(ran_seed);
136 
137  // Set the seed to desired value
139 
140 
141 
142  // Create the quark source
143  LatticePropagator quark_source;
144 
145  multi1d<LatticeColorVector> tmp_color_vec(Nc);
146 
147  LatticeReal rnd;
148  LatticeReal ar, ai;
149  LatticeComplex z;
150 
151  random(rnd);
152  ar = where( rnd>0.5, LatticeReal(sqrt(0.5)), LatticeReal(-sqrt(0.5)) );
153  random(rnd);
154  ai = where( rnd>0.5, LatticeReal(sqrt(0.5)), LatticeReal(-sqrt(0.5)) );
155  z = cmplx(ar, ai);
156 
157  for(int i=0; i<Nc; i++) {
158  tmp_color_vec[i] = zero;
159  pokeColor(tmp_color_vec[i], z, i);
160  }
161 
162  for(int color_source = 0; color_source < Nc; ++color_source)
163  {
164  QDPIO::cout << "color = " << color_source << std::endl;
165 
166  LatticeColorVector src_color_vec = zero;
167 
168  int mu = params.j_decay;
169  int slice = params.t_source;
170  src_color_vec = where( Layout::latticeCoordinate(mu) == slice,
171  tmp_color_vec[color_source],
172  LatticeColorVector(zero));
173 
174  for(int spin_source = 0; spin_source < Ns; ++spin_source)
175  {
176  QDPIO::cout << "spin = " << spin_source << std::endl;
177 
178  // Insert a ColorVector into spin index spin_source
179  // This only overwrites sections, so need to initialize first
180  LatticeFermion chi = zero;
181 
182  CvToFerm(src_color_vec, chi, spin_source);
183 
184 
185  /*
186  * Move the source to the appropriate components
187  * of quark source.
188  */
189  FermToProp(chi, quark_source, color_source, spin_source);
190  }
191  }
192 
193 
194  // Reset the seed
195  QDP::RNG::setrn(ran_seed);
196 
197  return quark_source;
198  }
199 
200  }
201 
202 }
Primary include file for CHROMA library code.
Base class for quark source construction.
T operator()(const multi1d< LatticeColorMatrix > &u) const
Construct the source.
static T & Instance()
Definition: singleton.h:432
int mu
Definition: cool.cc:24
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.
Params params
void setrn(int iseed[4])
Definition: make_seeds.cc:38
void savern(int iseed[4])
Definition: make_seeds.cc:46
int z
Definition: meslate.cc:36
static bool registered
Local registration flag.
const std::string name
Name to be used.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
multi1d< LatticeFermion > chi(Ncb)
pop(xml_out)
Double zero
Definition: invbicg.cc:106
::std::string string
Definition: gtest.h:1979
Random Z2 wall source construction.
Factory for producing quark prop sources.
void writeXML(XMLWriter &in, const std::string &path) const