Bridge++  Ver. 1.1.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fopr_Clover_eo.cpp
Go to the documentation of this file.
1 
14 #include "fopr_Clover_eo.h"
15 
16 #ifdef USE_PARAMETERS_FACTORY
17 #include "parameters_factory.h"
18 #endif
19 
20 using std::valarray;
21 
22 //====================================================================
23 //- parameter entries
24 namespace {
25  void append_entry(Parameters& param)
26  {
27  param.Register_double("hopping_parameter", 0.0);
28  param.Register_double("clover_coefficient", 0.0);
29  param.Register_int_vector("boundary_condition", std::valarray<int>());
30 
31  param.Register_string("verbose_level", "NULL");
32  }
33 
34 
35 #ifdef USE_PARAMETERS_FACTORY
36  bool init_param = ParametersFactory::Register("Fopr.Clover_eo", append_entry);
37 #endif
38 }
39 //- end
40 
41 //- parameters class
43 //- end
44 
45 //====================================================================
47 {
48  const string str_vlevel = params.get_string("verbose_level");
49 
50  m_vl = vout.set_verbose_level(str_vlevel);
51 
52  //- fetch and check input parameters
53  double kappa, cSW;
54  valarray<int> bc;
55 
56  int err = 0;
57  err += params.fetch_double("hopping_parameter", kappa);
58  err += params.fetch_double("clover_coefficient", cSW);
59  err += params.fetch_int_vector("boundary_condition", bc);
60 
61  if (err) {
62  vout.crucial(m_vl, "Fopr_Clover_eo: fetch error, input parameter not found.\n");
63  abort();
64  }
65 
66 
67  set_parameters(kappa, cSW, bc);
68 }
69 
70 
71 //====================================================================
72 void Fopr_Clover_eo::set_parameters(const double kappa, const double cSW,
73  const std::valarray<int> bc)
74 {
75  //- print input parameters
76  vout.general(m_vl, "Parameters of Fopr_Clover_eo:\n");
77  vout.general(m_vl, " kappa = %8.4f\n", kappa);
78  vout.general(m_vl, " cSW = %8.4f\n", cSW);
79  for (int mu = 0; mu < m_Ndim; ++mu) {
80  vout.general(m_vl, " boundary[%d] = %2d\n", mu, bc[mu]);
81  }
82 
83  //- range check
84  // NB. kappa,cSW == 0 is allowed.
85  assert(bc.size() == m_Ndim);
86 
87  //- store values
88  m_kappa = kappa;
89  m_cSW = cSW;
90 
91  assert(bc.size() == m_Ndim);
92  for (int mu = 0; mu < m_Ndim; ++mu) {
93  m_boundary[mu] = bc[mu];
94  }
95 
96  //- propagate parameters to components
99 }
100 
101 
102 //====================================================================
104 {
105  int Ndim = CommonParameters::Ndim();
106  int Nvol = CommonParameters::Nvol();
107 
108  // if (m_Ueo == 0) {
109  // Field_G* Ueo = new Field_G(Nvol,Ndim);
110  // m_idx.convertField(*Ueo, *U);
111  // m_Ueo = Ueo;
112  // }
113  m_idx.convertField(*m_Ueo, *U);
114 
115  // m_fopr_w->set_config( m_Ueo);
116  m_fopr_w->set_config(U);
118 
119  solve_csw_inv();
120 }
121 
122 
123 //====================================================================
125  const Field& b)
126 {
127  int Nin = b.nin();
128  int Nex = b.nex();
129  Field be(Nin, m_Nvol2, Nex);
130  Field tmp(Nin, m_Nvol2, Nex);
131 
132  m_idx.convertField(tmp, b, 0);
133  be = (Field)mult_csw_inv((Field_F)tmp, 0);
134 
135  m_idx.convertField(tmp, b, 1);
136  bo = (Field)mult_csw_inv((Field_F)tmp, 1);
137 
138  Be.reset(Nin, m_Nvol2, Nex);
139  Be = be - (Field)Meo(bo, 0);
140 }
141 
142 
144  const Field& xe, const Field& bo)
145 {
146  int Nin = xe.nin();
147  int Nex = xe.nex();
148  Field xo(Nin, m_Nvol2, Nex);
149 
150  xo = bo - (Field)Meo(xe, 1);
151 
152  x.reset(Nin, m_Nvol2 * 2, Nex);
153 
154  m_idx.reverseField(x, xe, 0);
155  m_idx.reverseField(x, xo, 1);
156 }
157 
158 
159 //====================================================================
161  const Field& b)
162 {
163  int Nin = b.nin();
164  int Nex = b.nex();
165  Field be(Nin, m_Nvol2, Nex);
166  Field tmp(Nin, m_Nvol2, Nex);
167 
168  m_idx.convertField(tmp, b, 0);
169  be = (Field)mult_csw_inv((Field_F)tmp, 0);
170  m_idx.convertField(tmp, b, 1);
171  bo = (Field)mult_csw_inv((Field_F)tmp, 1);
172 
173  Be.reset(Nin, m_Nvol2, Nex);
174  Be = be - (Field)Mdageo(bo, 0);
175 }
176 
177 
179  const Field& xe, const Field& bo)
180 {
181  int Nin = xe.nin();
182  int Nex = xe.nex();
183  Field xo(Nin, m_Nvol2, Nex);
184 
185  xo = bo - (Field)Mdageo(xe, 1);
186 
187  x.reset(Nin, m_Nvol2 * 2, Nex);
188  m_idx.reverseField(x, xe, 0);
189  m_idx.reverseField(x, xo, 1);
190 }
191 
192 
193 //====================================================================
195 {
196  double eps2 = CommonParameters::epsilon_criterion2();
197 
198  Parameters *params_solver = ParametersFactory::New("Solver");
199 
200  params_solver->set_string("solver_type", "CG");
201  params_solver->set_int("maximum_number_of_iteration", 1000);
202  params_solver->set_double("convergence_criterion_squared", 1.0e-30);
203  //- NB. set VerboseLevel to CRUCIAL to suppress frequent messages.
204  params_solver->set_string("verbose_level", "Crucial");
205 
206  int Nconv;
207  double diff;
208 
209  Solver *solver = new Solver_CG(m_fopr_csw);
210  solver->set_parameters(*params_solver);
211 
212  Field_F w(m_Nvol2);
213  Field_F w2(m_Nvol2);
214 
215  for (int ispin = 0; ispin < m_Nd; ++ispin) {
216  for (int icolor = 0; icolor < m_Nc; ++icolor) {
217  int spin_color = icolor + m_Nc * ispin;
218  w = 0.0;
219  for (int isite = 0; isite < m_Nvol2; ++isite) {
220  w.set_ri(icolor, ispin, isite, 0, 1, 0);
221  }
222 
223  if (m_cSW * m_cSW < eps2) {
224  m_fee_inv->setpart_ex(spin_color, w, 0);
225  m_foo_inv->setpart_ex(spin_color, w, 0);
226  } else {
227  m_fopr_csw->set_mode("even");
228  solver->solve(w2, w, Nconv, diff);
229  m_fee_inv->setpart_ex(spin_color, w2, 0);
230 
231  vout.detailed(m_vl, " Nconv,diff = %d %12.4e\n", Nconv, diff);
232 
233  m_fopr_csw->set_mode("odd");
234  solver->solve(w2, w, Nconv, diff);
235  m_foo_inv->setpart_ex(spin_color, w2, 0);
236 
237  vout.detailed(m_vl, " Nconv,diff = %d %12.4e\n", Nconv, diff);
238  }
239  }
240  }
241 
242  delete params_solver;
243  delete solver;
244 }
245 
246 
247 //====================================================================
248 const Field_F Fopr_Clover_eo::mult_csw_inv(const Field_F& f, const int ieo)
249 {
250  int nex = f.nex();
251  Field_F w(m_Nvol2, nex);
252  Field_F *csw_inv;
253 
254  if (ieo == 0) {
255  csw_inv = m_fee_inv;
256  } else if (ieo == 1) {
257  csw_inv = m_foo_inv;
258  } else {
259  vout.crucial(m_vl, "Fopr_clover_eo: wrong parameter, ieo=%d.\n", ieo);
260  abort();
261  }
262 
263  for (int iex = 0; iex < nex; ++iex) {
264  for (int isite = 0; isite < m_Nvol2; ++isite) {
265  for (int ispin = 0; ispin < m_Nd; ++ispin) {
266  for (int icolor = 0; icolor < m_Nc; ++icolor) {
267  double re = 0;
268  double im = 0;
269 
270  for (int jspin = 0; jspin < m_Nd; ++jspin) {
271  for (int jcolor = 0; jcolor < m_Nc; ++jcolor) {
272  int spin_color = jcolor + m_Nc * jspin;
273 
274  re += csw_inv->cmp_r(icolor, ispin, isite, spin_color) *
275  f.cmp_r(jcolor, jspin, isite, iex);
276  re -= csw_inv->cmp_i(icolor, ispin, isite, spin_color) *
277  f.cmp_i(jcolor, jspin, isite, iex);
278 
279  im += csw_inv->cmp_r(icolor, ispin, isite, spin_color) *
280  f.cmp_i(jcolor, jspin, isite, iex);
281  im += csw_inv->cmp_i(icolor, ispin, isite, spin_color) *
282  f.cmp_r(jcolor, jspin, isite, iex);
283  }
284  }
285 
286  w.set_ri(icolor, ispin, isite, iex, re, im);
287  }
288  }
289  }
290  }
291 
292  return w;
293 }
294 
295 
296 //====================================================================
297 const Field_G Fopr_Clover_eo::trSigmaInv(const int mu, const int nu)
298 {
299  int nex_finv = m_fee_inv->nex();
300  Vec_SU_N v;
301  Field_F sigma_inv(m_Nvol, nex_finv);
302  Field_G tr_sigma_inv(m_Nvol, 1);
303  {
304  Field_F sigma_eo_inv(m_Nvol2, nex_finv);
305  mult_isigma(sigma_eo_inv, *m_fee_inv, mu, nu);
306  m_idx.reverseField(sigma_inv, sigma_eo_inv, 0);
307  mult_isigma(sigma_eo_inv, *m_foo_inv, mu, nu);
308  m_idx.reverseField(sigma_inv, sigma_eo_inv, 1);
309  }
310 
311  for (int isite = 0; isite < m_Nvol; ++isite) {
312  for (int ispin = 0; ispin < m_Nd; ++ispin) {
313  for (int icolor = 0; icolor < m_Nc; ++icolor) {
314  v = sigma_inv.vec(ispin, isite, icolor + m_Nc * ispin);
315  for (int jcolor = 0; jcolor < m_Nc; ++jcolor) {
316  int cc = icolor + m_Nc * jcolor;
317  tr_sigma_inv.set_r(cc, isite, 0, v.r(jcolor));
318  tr_sigma_inv.set_i(cc, isite, 0, v.i(jcolor));
319  }
320  }
321  }
322  }
323  return tr_sigma_inv;
324 }
325 
326 
327 //====================================================================
328 //============================================================END=====