CHROMA
extfield_aggregate_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief External field aggregate
3  */
4 
5 #include "chromabase.h"
6 
9 
10 #include "state.h"
11 #include "create_state.h"
12 
13 
14 namespace Chroma
15 {
16 
17  //! External fields
18  /*! \ingroup fermstates */
19  namespace ExternalFieldEnv
20  {
21 
22  //construct the antisymmetric tensor
23  int epsilon(int i, int j, int k){
24  if( (i==j)||(j==k)|| (k==i) )
25  return 0 ;
26  if( ((i<j)&&(j<k)) || ((j<k)&&(k<i)) || ((k<i)&&(i<j)) )
27  return 1 ;
28  else
29  return -1 ;
30  }
31 
32 
33  //! Reader
34  /*! @ingroup sources */
35  void read(XMLReader& xml, const std::string& path, ExternalFieldEnv::ConstantMagneticParams& param){
36 
37  XMLReader paramtop(xml, path);
38 
39  int version;
40  read(paramtop, "version", version);
41 
42  switch (version)
43  {
44  case 1:
45  break;
46 
47  default:
48  QDPIO::cerr << __func__ << ": parameter version " << version
49  << " unsupported." << std::endl;
50  QDP_abort(1);
51  }
52  read(paramtop, "t_dir", param.t_dir);
53  read(paramtop, "y_dir", param.y_dir);
54  read(paramtop, "b_dir", param.b_dir);
55  read(paramtop, "Bfield", param.Bfield);
56  if(paramtop.count("patch") !=0 )
57  read(paramtop, "patch", param.patch);
58  else
59  param.patch = false ;
60  }
61 
62  //! Writer
63  /*! @ingroup sources */
64  void write(XMLWriter& xml, const std::string& path, const ExternalFieldEnv::ConstantMagneticParams& param){
65 
66  push(xml,path);
67  int version;
68  write(xml, "version", version);
69  write(xml, "t_dir", param.t_dir);
70  write(xml, "y_dir", param.y_dir);
71  write(xml, "b_dir", param.b_dir);
72  write(xml, "Bfield", param.Bfield);
73  write(xml, "patch", param.patch);
74  pop(xml);
75  }
76 
77 
78  //! Reader
79  /*! @ingroup sources */
80  void read(XMLReader& xml, const std::string& path, ExternalFieldEnv::LinearElectricParams& param){
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  read(paramtop, "t_dir", param.t_dir);
98  read(paramtop, "x_dir", param.x_dir);
99  read(paramtop, "x_src", param.x_src);
100  read(paramtop, "Efield", param.Efield);
101  if(paramtop.count("patch") !=0 )
102  read(paramtop, "patch", param.patch);
103  else
104  param.patch = false ;
105  }
106 
107  //! Writer
108  /*! @ingroup sources */
109  void write(XMLWriter& xml, const std::string& path, const ExternalFieldEnv::LinearElectricParams& param){
110 
111  push(xml,path);
112  int version;
113  write(xml, "version", version);
114  write(xml, "t_dir", param.t_dir);
115  write(xml, "x_dir", param.x_dir);
116  write(xml, "x_src", param.x_src);
117  write(xml, "Efield", param.Efield);
118  write(xml, "patch", param.patch);
119  pop(xml);
120  }
121 
122 
123  //! Anonymous namespace
124  namespace
125  {
126 
127  //-------------------- callback functions ---------------------------------------
128 
129  //! Construct zero
130  ExternalField* zeroFunc(XMLReader& xml_in,
131  const std::string& path)
132  {
133  return new ZeroExternalField();
134  }
135 
136  //! Construct constant magnetic field
137  ExternalField* ConstantMagneticFunc(XMLReader& xml_in,
138  const std::string& path)
139  {
140  ConstantMagneticParams p ;
141  ExternalFieldEnv::read(xml_in,path,p);
142  return new ConstantMagneticExternalField(p);
143  }
144 
145 
146  //! Construct linear electric field
147  ExternalField* LinearElectricFunc(XMLReader& xml_in,
148  const std::string& path)
149  {
150  LinearElectricParams p ;
151  ExternalFieldEnv::read(xml_in,path,p);
152  return new LinearElectricExternalField(p);
153  }
154 
155 
156  } // end anonymous namespace
157 
158 
159 
161  const std::string& path){
162  XMLReader paramtop(xml, path);
163 
164  std::string name ;
165  std::string ext_field_path = "ExternalField";
166 
167  read(paramtop, ext_field_path+"/Name", name);
168  QDPIO::cout<<"Found external field: "<<name<<std::endl ;
169 
170  //Handle< ExternalField > ef ; // just to make the code compile
171 
172  /* THE FOLLOWING BIT DOES NOT WORK... why??? NEED FIX*/
173  Handle< ExternalField > ef(Chroma::TheExternalFieldFactory::Instance().createObject(name,paramtop,ext_field_path)) ;
174  /**/
175 
176  return ef ;
177  }
178 
179  // Construct linear function
180  LatticeComplex
182  {
183  START_CODE();
184 
185  LatticeComplex d = 1;
186 
187  END_CODE();
188  return d;
189  }
190 
191  // Construct constant magnetic field. Needs fix up...
192  LatticeComplex
194  {
195  START_CODE();
196 
197  LatticeComplex U ;
198  if(mu!=t_dir){
199  Real A;
200  if(Nd==4){
201  if(mu==y_dir){
203  QDPIO::cout<<__func__<<" A_"<<mu<<"="<<A<<std::endl ;
204  LatticeReal B = A*Layout::latticeCoordinate(x_dir) ;
205  U = cmplx(cos(B),sin(B));
206  return U ;
207  }
208  if((mu==x_dir)&&(patch)){// do the patch
209  LatticeBoolean XX = (Layout::latticeCoordinate(x_dir)==
210  (Layout::lattSize()[x_dir] - 1) ) ;
211  LatticeReal B = -Bfield*XX*Layout::lattSize()[y_dir]*
212  Layout::latticeCoordinate(y_dir) ;
213 
214  U = cmplx(cos(B),sin(B));
215  return U ;
216  }
217  }
218  else//do nothing
219  QDPIO::cerr<<"OOOPS! don't know how to set up magnetic field in other than 4 dimenssions\n";
220  }
221  U = 1.0 ;
222  QDPIO::cout<<__func__<<" A_"<<mu<<"= 0"<<std::endl ;
223  END_CODE();
224  return U;
225  }
226 
227 
228  // Construct linear Electric field. Needs fix up...
229  LatticeComplex
231  {
232  START_CODE();
233 
234  LatticeComplex U ;
235  Real A0;
236  A0 = -(0.5)*Efield;
237  if(mu==t_dir){
238  QDPIO::cout<<__func__<<" A_"<<mu<<"="<<A0<<std::endl ;
239  // This line is -1/2 * Efield * (z-z0) * (z-z0-1) to get the correct E-field
240  LatticeReal E = A0*(Layout::latticeCoordinate(x_dir)-x_src)*(Layout::latticeCoordinate(x_dir)-x_src - 1) ;
241  U = cmplx(cos(E),sin(E));
242  return U ;
243  }
244  if((mu==x_dir)&&(patch)){// do the patch for the e-field
245  LatticeBoolean XX = (Layout::latticeCoordinate(x_dir)==
246  (Layout::lattSize()[x_dir] - 1) ) ;
247  LatticeReal E = -A0*XX*(Layout::lattSize()[x_dir]-1)*(Layout::lattSize()[x_dir]-2)*
248  Layout::latticeCoordinate(t_dir) ;
249 
250  U = cmplx(cos(E),sin(E));
251  return U ;
252  }
253 
254  U = 1.0 ;
255  QDPIO::cout<<__func__<<" A_"<<mu<<"= 0"<<std::endl ;
256  END_CODE();
257  return U;
258  }
259 
260 
261  //! Local registration flag
262  static bool registered = false;
263 
264  //! Register all the factories
265  bool registerAll()
266  {
267  bool success = true;
268  if (! registered)
269  {
270  //! Register all the factories
271  success &= Chroma::TheExternalFieldFactory::Instance().registerObject(std::string("ZERO"), zeroFunc);
272  //QDPIO::cerr<<"registered ZERO external field\n";
273 
274  success &= Chroma::TheExternalFieldFactory::Instance().registerObject(std::string("CONSTANT_MAGNETIC"), ConstantMagneticFunc);
275  //QDPIO::cerr<<"registered CONSTANT_MAGNETIC field\n";
276 
277  success &= Chroma::TheExternalFieldFactory::Instance().registerObject(std::string("LINEAR_ELECTRIC"), LinearElectricFunc);
278  //QDPIO::cerr<<"registered LINEAR_ELECTRIC field\n";
279 
280  registered = true;
281  }
282  return success;
283  }
284  } // end namespace ExternalFieldEnv
285 
286 } // end namespace Chroma
287 
288 
289 
290 
Primary include file for CHROMA library code.
LatticeComplex operator()(int dummy) const
Return the field.
LatticeComplex operator()(int dummy) const
Return the field.
LatticeComplex operator()(int dir) const
Return the field.
Base class for external fields.
Definition: extfield.h:20
Class for counted reference semantics.
Definition: handle.h:33
static T & Instance()
Definition: singleton.h:432
int mu
Definition: cool.cc:24
Create a connection state.
External field functions.
External field factory.
void write(XMLWriter &xml, const std::string &path, const ExternalFieldEnv::ConstantMagneticParams &param)
Writer.
void read(XMLReader &xml, const std::string &path, ExternalFieldEnv::ConstantMagneticParams &param)
Reader.
unsigned j
Definition: ldumul_w.cc:35
Nd
Definition: meslate.cc:74
const std::string name
Name to be used.
Handle< ExternalField > reader(XMLReader &xml, const std::string &path)
int epsilon(int i, int j, int k)
static bool registered
Local registration flag.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
pop(xml_out)
DComplex d
Definition: invbicg.cc:99
START_CODE()
A(A, psi, r, Ncb, PLUS)
int k
Definition: invbicg.cc:119
::std::string string
Definition: gtest.h:1979
Support class for fermion actions and linear operators.
multi1d< LatticeColorMatrix > U