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