Bridge++  Ver. 2.0.2
afopr_Wilson_Chemical-tmpl.h
Go to the documentation of this file.
1 
16 
17 #ifdef USE_FACTORY_AUTOREGISTER
18 namespace {
20 }
21 #endif
22 
23 template<typename AFIELD>
25  = "AFopr_Wilson_Chemical<AFIELD>";
26 
27 //====================================================================
28 template<typename AFIELD>
30 {
32 
33  m_vl = CommonParameters::Vlevel();
34  m_is_initial_step = true;
35 
36  vout.general(m_vl, "%s: construction\n", class_name.c_str());
38 
39  int Nc = CommonParameters::Nc();
40  int Nd = CommonParameters::Nd();
41  m_NinF = 2 * Nc * Nd;
42  m_Nvol = CommonParameters::Nvol();
43  m_Ndim = CommonParameters::Ndim();
44 
45  m_boundary.resize(m_Ndim);
46 
47  std::string kernel_type;
48  if (!params.fetch_string("kernel_type", kernel_type)) {
49  m_kernel_type = kernel_type;
50  } else {
51  m_kernel_type = "Wilson"; // default
52  vout.general("kernel_type is set to default: %s\n",
53  m_kernel_type.c_str());
54  }
55 
56  std::string repr;
57  if (!params.fetch_string("gamma_matrix_type", repr)) {
58  m_repr = repr;
59  } else {
60  m_repr = "Dirac"; // default
61  }
62  if ((m_repr != "Dirac") && (m_repr != "Chiral")) {
63  vout.crucial("Error in %s: irrelevant mult mode = %s\n",
64  class_name.c_str(), m_repr.c_str());
65  exit(EXIT_FAILURE);
66  }
67 
68  set_parameters(params);
69 
70  m_U = 0;
71 
72  m_fopr_w = AFopr<AFIELD>::New(m_kernel_type, params);
73 
75 
76  m_v1.reset(m_NinF, m_Nvol, 1);
77  m_v2.reset(m_NinF, m_Nvol, 1);
78 
79  m_is_initial_step = false;
80 
81  vout.general(m_vl, "%s: construction finished.\n",
82  class_name.c_str());
83 }
84 
85 
86 //====================================================================
87 template<typename AFIELD>
88 void AFopr_Wilson_Chemical<AFIELD>::init(const std::string repr)
89 {
91 
92  m_vl = CommonParameters::Vlevel();
93  m_is_initial_step = true;
94 
95  vout.general(m_vl, "%s: construction (obsolete)\n",
96  class_name.c_str());
98 
99  int Nc = CommonParameters::Nc();
100  int Nd = CommonParameters::Nd();
101  m_NinF = 2 * Nc * Nd;
102  m_Nvol = CommonParameters::Nvol();
103  m_Ndim = CommonParameters::Ndim();
104 
105  m_boundary.resize(m_Ndim);
106 
107  std::string kernel_type;
108  m_kernel_type = "Wilson";
109 
110  m_repr = repr;
111  if ((m_repr != "Dirac") && (m_repr != "Chiral")) {
112  vout.crucial("Error in %s: irrelevant mult mode = %s\n",
113  class_name.c_str(), m_repr.c_str());
114  exit(EXIT_FAILURE);
115  }
116 
117  m_U = 0;
118 
119  m_fopr_w = AFopr<AFIELD>::New(m_kernel_type, m_repr);
120 
122 
123  m_v1.reset(m_NinF, m_Nvol, 1);
124  m_v2.reset(m_NinF, m_Nvol, 1);
125 
126  m_is_initial_step = false;
127 
128  vout.general(m_vl, "%s: construction finished.\n",
129  class_name.c_str());
130 }
131 
132 
133 //====================================================================
134 template<typename AFIELD>
136 {
137  delete m_fopr_w;
138 }
139 
140 
141 //====================================================================
142 template<typename AFIELD>
144  const Parameters& params)
145 {
146 #pragma omp barrier
147  int ith = ThreadManager::get_thread_id();
148  std::string vlevel;
149  if (!params.fetch_string("verbose_level", vlevel)) {
150  if (ith == 0) m_vl = vout.set_verbose_level(vlevel);
151  }
152 #pragma omp barrier
153 
154  //- fetch and check input parameters
155  double kappa, mu;
156  std::vector<int> bc;
157 
158  int err = 0;
159  err += params.fetch_double("hopping_parameter", kappa);
160  err += params.fetch_double("chemical_potential", mu);
161  err += params.fetch_int_vector("boundary_condition", bc);
162 
163  if (err) {
164  vout.crucial(m_vl, "Error at %s: input parameter not found.\n",
165  class_name.c_str());
166  exit(EXIT_FAILURE);
167  }
168 
169  set_parameters_impl(real_t(kappa), real_t(mu), bc);
170 
171  if (!m_is_initial_step) {
173  m_fopr_w->set_parameters(params);
175  }
176 }
177 
178 
179 //====================================================================
180 template<typename AFIELD>
182  const real_t kappa,
183  const real_t mu,
184  const std::vector<int> bc)
185 {
186  assert(bc.size() == m_Ndim);
187 
188 #pragma omp barrier
189  int ith = ThreadManager::get_thread_id();
190  if (ith == 0) {
191  m_kappa = kappa;
192  m_mu = mu;
193  m_boundary = bc;
194  m_exp_mu = exp(mu);
195  }
196 #pragma omp barrier
197 
198  vout.general(m_vl, "%s: input parameters\n", class_name.c_str());
199  vout.general(m_vl, " kernel_type = %s\n", m_kernel_type.c_str());
200  vout.general(m_vl, " gamma matrix type = %s\n", m_repr.c_str());
201  vout.general(m_vl, " kappa = %12.8f\n", m_kappa);
202  vout.general(m_vl, " mu = %12.8f\n", m_mu);
203  for (int dir = 0; dir < m_Ndim; ++dir) {
204  vout.general(m_vl, " boundary[%d] = %2d\n", dir, m_boundary[dir]);
205  }
206 }
207 
208 
209 //====================================================================
210 template<typename AFIELD>
212  Parameters& params) const
213 {
214  params.set_double("hopping_parameter", m_kappa);
215  params.set_double("chemical_potential", m_mu);
216  params.set_int_vector("boundary_condition", m_boundary);
217 
218  params.set_string("kernel_type", m_kernel_type);
219  params.set_string("gamma_matrix_type", m_repr);
220 
221  params.set_string("verbose_level", vout.get_verbose_level(m_vl));
222 }
223 
224 
225 //====================================================================
226 template<typename AFIELD>
228 {
229 #pragma omp barrier
230 
231  int ith = ThreadManager::get_thread_id();
232  if (ith == 0) m_U = (Field_G *)U;
233 #pragma omp barrier
234 
235  m_fopr_w->set_config(U);
236 }
237 
238 
239 //====================================================================
240 template<typename AFIELD>
241 void AFopr_Wilson_Chemical<AFIELD>::set_mode(const std::string mode)
242 {
243 #pragma omp barrier
244 
245  int ith = ThreadManager::get_thread_id();
246  if (ith == 0) m_mode = mode;
247 #pragma omp barrier
248 
249  m_fopr_w->set_mode(mode);
250 }
251 
252 
253 //====================================================================
254 template<typename AFIELD>
256 {
257  if (m_mode == "D") {
258  D(v, w);
259  } else if (m_mode == "Ddag") {
260  Ddag(v, w);
261  } else if (m_mode == "DdagD") {
262  DdagD(v, w);
263  } else if (m_mode == "H") {
264  H(v, w);
265  } else {
266  vout.crucial(m_vl, "Error at %s: irrelevant input mode:\n",
267  class_name.c_str(), m_mode.c_str());
268  exit(EXIT_FAILURE);
269  }
270 }
271 
272 
273 //====================================================================
274 template<typename AFIELD>
276 {
277  if (m_mode == "D") {
278  Ddag(v, w);
279  } else if (m_mode == "Ddag") {
280  D(v, w);
281  } else if (m_mode == "DdagD") {
282  DdagD(v, w);
283  } else if (m_mode == "H") {
284  Hdag(v, w);
285  } else {
286  vout.crucial(m_vl, "Error at %s: irrelevant input mode:\n",
287  class_name.c_str(), m_mode.c_str());
288  exit(EXIT_FAILURE);
289  }
290 }
291 
292 
293 //====================================================================
294 template<typename AFIELD>
296 {
297  Dspc(v, w);
298 
299  m_v1.set(0.0); // v = 0.0;
300 #pragma omp barrier
301 
302  m_fopr_w->mult_up(3, m_v1, w);
303  // v.addpart_ex(0, m_v1, 0, -m_kappa * m_exp_mu);
304  axpy(v, -m_kappa * m_exp_mu, m_v1);
305 
306  m_v1.set(0.0); // v = 0.0;
307 #pragma omp barrier
308 
309  m_fopr_w->mult_dn(3, m_v1, w);
310  axpy(v, -m_kappa / m_exp_mu, m_v1);
311 
312 #pragma omp barrier
313 }
314 
315 
316 //====================================================================
317 template<typename AFIELD>
319 {
320  Dspc(v, w);
321 
322  m_v1.set(0.0); // v = 0.0;
323 #pragma omp barrier
324 
325  m_fopr_w->mult_up(3, m_v1, w);
326  axpy(v, -m_kappa / m_exp_mu, m_v1);
327 
328  m_v1.set(0.0); // v = 0.0;
329 #pragma omp barrier
330 
331  m_fopr_w->mult_dn(3, m_v1, w);
332  axpy(v, -m_kappa * m_exp_mu, m_v1);
333 
334 #pragma omp barrier
335 }
336 
337 
338 //====================================================================
339 template<typename AFIELD>
341 {
342  v.set(0.0);
343 
344  m_fopr_w->mult_up(0, v, w);
345  m_fopr_w->mult_dn(0, v, w);
346 
347  m_fopr_w->mult_up(1, v, w);
348  m_fopr_w->mult_dn(1, v, w);
349 
350  m_fopr_w->mult_up(2, v, w);
351  m_fopr_w->mult_dn(2, v, w);
352 
353  aypx(-m_kappa, v, w);
354  // scal(v, -m_kappa); // w *= -m_kappa;
355  // axpy(v, 1.0, w); // w += f;
356 #pragma omp barrier
357 }
358 
359 
360 //====================================================================
361 template<typename AFIELD>
363 {
364  m_fopr_w->mult_gm5(v, w);
365 }
366 
367 
368 //====================================================================
369 template<typename AFIELD>
371  AFIELD& v, const AFIELD& w)
372 {
373  m_v1.set(0.0); // vt = 0.0;
374 #pragma omp barrier
375 
376  m_fopr_w->mult_up(mu, m_v1, w);
377  m_fopr_w->mult_gm5(v, m_v1);
378 }
379 
380 
381 //====================================================================
382 template<typename AFIELD>
384 {
385  D(m_v2, w);
386  mult_gm5(v, m_v2);
387  Dminmu(m_v2, v);
388  mult_gm5(v, m_v2);
389 }
390 
391 
392 //====================================================================
393 template<typename AFIELD>
395 {
396  mult_gm5(v, w);
397  Dminmu(m_v2, v);
398  mult_gm5(v, m_v2);
399 }
400 
401 
402 //====================================================================
403 template<typename AFIELD>
405 {
406  D(m_v2, w);
407  mult_gm5(v, m_v2);
408 }
409 
410 
411 //====================================================================
412 template<typename AFIELD>
414 {
415  Dminmu(m_v2, w);
416  mult_gm5(v, m_v2);
417 }
418 
419 
420 //====================================================================
421 template<typename AFIELD>
423 {
424  int NPE = CommonParameters::NPE();
425 
426  double gflop_w = m_fopr_w->flop_count();
427 
428  double gflop_tm = 2.0 * double(m_NinF) * double(m_Nvol)
429  * double(NPE) * 1.0e-9;
430 
431  if ((m_mode == "DdagD") || (m_mode == "DDdag")) gflop_tm *= 2;
432 
433  double gflop = gflop_w + gflop_tm;
434 
435  return gflop;
436 }
437 
438 
439 //============================================================END=====
AFopr_Wilson_Chemical::Dspc
void Dspc(AFIELD &, const AFIELD &)
Definition: afopr_Wilson_Chemical-tmpl.h:340
Parameters::set_string
void set_string(const string &key, const string &value)
Definition: parameters.cpp:39
AFopr_Wilson_Chemical::mult_dag
void mult_dag(AFIELD &v, const AFIELD &w)
hermitian conjugate of mult.
Definition: afopr_Wilson_Chemical-tmpl.h:275
AFopr
Definition: afopr.h:48
AFopr_Wilson_Chemical::D
void D(AFIELD &, const AFIELD &)
Definition: afopr_Wilson_Chemical-tmpl.h:295
AFopr_Wilson_Chemical::set_parameters_impl
void set_parameters_impl(const real_t kappa, const real_t mu, const std::vector< int > bc)
sets parameters given as values: private for composite operator.
Definition: afopr_Wilson_Chemical-tmpl.h:181
CommonParameters::Ndim
static int Ndim()
Definition: commonParameters.h:117
Field::set
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:175
Parameters
Class for parameters.
Definition: parameters.h:46
Parameters::set_double
void set_double(const string &key, const double value)
Definition: parameters.cpp:33
Bridge::BridgeIO::decrease_indent
void decrease_indent()
Definition: bridgeIO.h:86
AFopr_Wilson_Chemical::mult_gm5
void mult_gm5(AFIELD &, const AFIELD &)
multiplies gamma_5 matrix.
Definition: afopr_Wilson_Chemical-tmpl.h:362
Bridge::BridgeIO::increase_indent
void increase_indent()
Definition: bridgeIO.h:85
CommonParameters::Nvol
static int Nvol()
Definition: commonParameters.h:109
AFopr_Wilson_Chemical
Wilson fermion operator with chemical potential.
Definition: afopr_Wilson_Chemical.h:35
aypx
void aypx(const double a, Field &y, const Field &x)
aypx(y, a, x): y := a * y + x
Definition: field.cpp:509
AFopr_Wilson_Chemical::tidyup
void tidyup()
Definition: afopr_Wilson_Chemical-tmpl.h:135
axpy
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:380
real_t
double real_t
Definition: bridgeQXS_Clover_coarse_double.cpp:16
AFopr_Wilson_Chemical::set_parameters
void set_parameters(const Parameters &params)
sets parameters by a Parameter object: to be implemented in a subclass.
Definition: afopr_Wilson_Chemical-tmpl.h:143
AFopr_Wilson_Chemical::real_t
AFIELD::real_t real_t
Definition: afopr_Wilson_Chemical.h:39
AFopr_Wilson_Chemical::DdagD
void DdagD(AFIELD &, const AFIELD &)
Definition: afopr_Wilson_Chemical-tmpl.h:383
CommonParameters::Nc
static int Nc()
Definition: commonParameters.h:115
AFopr_Wilson_Chemical::H
void H(AFIELD &, const AFIELD &)
Definition: afopr_Wilson_Chemical-tmpl.h:404
AFopr_Wilson_Chemical::flop_count
double flop_count()
this returns the number of floating point operations.
Definition: afopr_Wilson_Chemical-tmpl.h:422
Parameters::fetch_int_vector
int fetch_int_vector(const string &key, vector< int > &value) const
Definition: parameters.cpp:429
threadManager.h
AFopr_Wilson_Chemical::set_mode
void set_mode(const std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: afopr_Wilson_Chemical-tmpl.h:241
afopr_Wilson_Chemical.h
AFopr_Wilson_Chemical::set_config
void set_config(Field *U)
sets the gauge configuration.
Definition: afopr_Wilson_Chemical-tmpl.h:227
CommonParameters::NPE
static int NPE()
Definition: commonParameters.h:101
Parameters::set_int_vector
void set_int_vector(const string &key, const vector< int > &value)
Definition: parameters.cpp:45
AFopr_Wilson_Chemical::Hdag
void Hdag(AFIELD &, const AFIELD &)
Definition: afopr_Wilson_Chemical-tmpl.h:413
CommonParameters::Nd
static int Nd()
Definition: commonParameters.h:116
CommonParameters::Vlevel
static Bridge::VerboseLevel Vlevel()
Definition: commonParameters.h:122
Bridge::BridgeIO::set_verbose_level
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:133
AFopr_Wilson_Chemical::Ddag
void Ddag(AFIELD &, const AFIELD &)
Definition: afopr_Wilson_Chemical-tmpl.h:394
AFopr_Wilson_Chemical::mult_gm5p
void mult_gm5p(const int mu, AFIELD &v, const AFIELD &w)
Definition: afopr_Wilson_Chemical-tmpl.h:370
Parameters::fetch_string
int fetch_string(const string &key, string &value) const
Definition: parameters.cpp:378
Parameters::fetch_double
int fetch_double(const string &key, double &value) const
Definition: parameters.cpp:327
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
AFopr_Wilson_Chemical::init
void init(const std::string repr)
Definition: afopr_Wilson_Chemical-tmpl.h:88
Field
Container of Field-type object.
Definition: field.h:46
ThreadManager::get_thread_id
static int get_thread_id()
returns thread id.
Definition: threadManager.cpp:253
AFopr_Wilson_Chemical::get_parameters
void get_parameters(Parameters &params) const
gets parameters by a Parameter object: to be implemented in a subclass.
Definition: afopr_Wilson_Chemical-tmpl.h:211
Field_G
SU(N) gauge field.
Definition: field_G.h:38
AFopr_Wilson_Chemical::Dminmu
void Dminmu(AFIELD &, const AFIELD &)
Definition: afopr_Wilson_Chemical-tmpl.h:318
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
ThreadManager::assert_single_thread
static void assert_single_thread(const std::string &class_name)
assert currently running on single thread.
Definition: threadManager.cpp:372
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
Bridge::BridgeIO::get_verbose_level
static std::string get_verbose_level(const VerboseLevel vl)
Definition: bridgeIO.cpp:154
AFopr_Wilson_Chemical::mult
void mult(AFIELD &v, const AFIELD &w)
multiplies fermion operator to a given field.
Definition: afopr_Wilson_Chemical-tmpl.h:255