Bridge++  Ver. 2.0.2
afopr_Chebyshev-tmpl.h
Go to the documentation of this file.
1 
11 
13 
14 
15 template<typename AFIELD>
17  = "AFopr_Chebyshev";
18 //====================================================================
19 template<typename AFIELD>
21 {
23  m_vl = CommonParameters::Vlevel();
24 
25  vout.general(m_vl, "%s: construction\n", class_name.c_str());
27 
28  m_NinF = m_fopr->field_nin();
29  m_Nvol = m_fopr->field_nvol();
30  m_NexF = m_fopr->field_nex();
31 
32  vout.general(m_vl, "kernel: %s\n", m_fopr->class_name.c_str());
33 
34  set_parameters(params);
35 
36  m_dj.resize(3);
37  for (int k = 0; k < 3; ++k) {
38  m_dj[k].reset(m_NinF, m_Nvol, m_NexF);
39  }
40 
42  vout.general(m_vl, "%s: construction finished.\n",
43  class_name.c_str());
44 }
45 
46 
47 //====================================================================
48 template<typename AFIELD>
50 {
52 
53  m_vl = CommonParameters::Vlevel();
54 
55  vout.general(m_vl, "%s: construction (obsoletre)\n",
56  class_name.c_str());
58 
59  m_NinF = m_fopr->field_nin();
60  m_Nvol = m_fopr->field_nvol();
61  m_NexF = m_fopr->field_nex();
62 
63  m_dj.resize(3);
64  for (int k = 0; k < 3; ++k) {
65  m_dj[k].reset(m_NinF, m_Nvol, m_NexF);
66  }
67 
68  vout.general(m_vl, "kernel: %s\n", m_fopr->class_name.c_str());
69 
71  vout.general(m_vl, "%s: construction finished.\n",
72  class_name.c_str());
73 }
74 
75 
76 //====================================================================
77 template<typename AFIELD>
79 {
80  // do nothing.
81 }
82 
83 
84 //====================================================================
85 template<typename AFIELD>
87 {
88  std::string vlevel;
89  if (!params.fetch_string("verbose_level", vlevel)) {
90  m_vl = vout.set_verbose_level(vlevel);
91  }
92 
93  //- fetch and check input parameters
94  int Np;
95  double v_threshold, v_max;
96 
97  int err = 0;
98  err += params.fetch_int("degree_of_polynomial", Np);
99  err += params.fetch_double("threshold_value", v_threshold);
100  err += params.fetch_double("upper_bound", v_max);
101 
102  if (err) {
103  vout.crucial(m_vl, "Error at %s: input parameter not found.\n",
104  class_name.c_str());
105  exit(EXIT_FAILURE);
106  }
107 
108  set_parameters(Np, real_t(v_threshold), real_t(v_max));
109 }
110 
111 
112 //====================================================================
113 template<typename AFIELD>
115  const real_t Vthrs,
116  const real_t Vmax)
117 {
118  //- range check
119  int err = 0;
120  err += ParameterCheck::non_negative(Np);
121  // NB. Vthrs, Vmax == 0 is allowed.
122 
123  if (err) {
124  vout.crucial(m_vl, "Error at %s: parameter range check failed.\n",
125  class_name.c_str());
126  exit(EXIT_FAILURE);
127  }
128 
129  int ith = ThreadManager::get_thread_id();
130 
131  if (ith == 0) {
132  m_Npcb = Np;
133 
134  m_Vthrs = real_t(Vthrs);
135  m_Vmax = real_t(Vmax);
136 
137  real_t b_max = Vmax / Vthrs;
138  real_t r = 2.0 / (b_max * b_max - 1.0);
139  real_t s = Vthrs / sqrt(0.5 * r);
140 
141  m_Fcb1 = 2.0 / (s * s);
142  m_Fcb2 = -(1.0 + r);
143  }
144 
145  //- print input parameters
146  vout.general(m_vl, "%s: input parameters\n", class_name.c_str());
147  vout.general(m_vl, " Np = %d\n", Np);
148  vout.general(m_vl, " Vthrs = %16.8e\n", Vthrs);
149  vout.general(m_vl, " Vmax = %16.8e\n", Vmax);
150  vout.general(m_vl, " Fcb1 = %16.8e\n", m_Fcb1);
151  vout.general(m_vl, " Fcb2 = %16.8e\n", m_Fcb2);
152 }
153 
154 
155 //====================================================================
156 template<typename AFIELD>
158 {
159  params.set_int("degree_of_polynomial", m_Npcb);
160  params.set_double("threshold_value", m_Vthrs);
161  params.set_double("upper_bound", m_Vmax);
162 
163  params.set_string("verbose_level", vout.get_verbose_level(m_vl));
164 }
165 
166 
167 //====================================================================
168 template<typename AFIELD>
170 {
171  m_fopr->set_config(U);
172 }
173 
174 
175 //====================================================================
176 template<typename AFIELD>
177 void AFopr_Chebyshev<AFIELD>::set_mode(std::string mode)
178 {
179  m_mode = mode;
180  m_fopr->set_mode(mode);
181 }
182 
183 
184 //====================================================================
185 template<typename AFIELD>
187 {
188  return m_mode;
189 }
190 
191 
192 //====================================================================
193 template<typename AFIELD>
195 {
196  v.check_size(m_NinF, m_Nvol, m_NexF);
197  w.check_size(m_NinF, m_Nvol, m_NexF);
198 
199  copy(m_dj[0], w);
200  scal(m_dj[0], real_t(-1.0));
201  m_dj[1].set(real_t(0.0));
202 
203  int jn = 2;
204  int jp1 = 1;
205  int jp2 = 0;
206 
207  for (int j = m_Npcb; j >= 2; --j) {
208  m_fopr->mult(m_dj[jn], m_dj[jp1]);
209  scal(m_dj[jn], m_Fcb1);
210  axpy(m_dj[jn], m_Fcb2, m_dj[jp1]);
211 
212  scal(m_dj[jn], real_t(2.0));
213  axpy(m_dj[jn], real_t(-1.0), m_dj[jp2]);
214 
215  jn = (jn + 1) % 3;
216  jp1 = (jp1 + 1) % 3;
217  jp2 = (jp2 + 1) % 3;
218  }
219 
220  m_fopr->mult(v, m_dj[jp1]);
221  scal(v, m_Fcb1);
222  axpy(v, m_Fcb2, m_dj[jp1]);
223  axpy(v, real_t(-1.0), m_dj[jp2]);
224 }
225 
226 
227 //====================================================================
228 template<typename AFIELD>
230 {
231  std::vector<real_t> dj(3);
232 
233  dj[0] = -1.0;
234  dj[1] = 0.0;
235 
236  int jn = 2;
237  int jp1 = 1;
238  int jp2 = 0;
239 
240  for (int j = m_Npcb; j >= 2; --j) {
241  dj[jn] = x * dj[jp1];
242  dj[jn] *= m_Fcb1;
243  dj[jn] += m_Fcb2 * dj[jp1];
244 
245  dj[jn] *= 2.0;
246  dj[jn] -= 1.0 * dj[jp2];
247 
248  jn = (jn + 1) % 3;
249  jp1 = (jp1 + 1) % 3;
250  jp2 = (jp2 + 1) % 3;
251  }
252 
253  v = x * dj[jp1];
254  v *= m_Fcb1;
255  v += m_Fcb2 * dj[jp1];
256  v -= dj[jp2];
257 }
258 
259 
260 //====================================================================
261 template<typename AFIELD>
263 {
264  real_t v;
265  mult(v, x);
266  return v;
267 }
268 
269 
270 //====================================================================
271 template<typename AFIELD>
273 {
274  return 0.0;
275 }
276 
277 
278 //============================================================END=====
AFopr_Chebyshev::set_config
void set_config(Field *U)
setting gauge configuration.
Definition: afopr_Chebyshev-tmpl.h:169
AFopr_Chebyshev::flop_count
double flop_count()
returns the number of floating point operations.
Definition: afopr_Chebyshev-tmpl.h:272
Parameters::set_string
void set_string(const string &key, const string &value)
Definition: parameters.cpp:39
afopr_Chebyshev.h
AFopr_Chebyshev::real_t
AFIELD::real_t real_t
Definition: afopr_Chebyshev.h:38
Parameters
Class for parameters.
Definition: parameters.h:46
AFopr_Chebyshev::mult
void mult(AFIELD &v, const AFIELD &w)
multiplies fermion operator to a given field.
Definition: afopr_Chebyshev-tmpl.h:194
AFopr_Chebyshev::set_parameters
void set_parameters(const Parameters &params)
setting parameters with a Parameter object.
Definition: afopr_Chebyshev-tmpl.h:86
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
Field::check_size
bool check_size(const int nin, const int nvol, const int nex) const
checking size parameters. [23 May 2016 H.Matsufuru]
Definition: field.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
ParameterCheck::non_negative
int non_negative(const int v)
Definition: parameterCheck.cpp:21
copy
void copy(Field &y, const Field &x)
copy(y, x): y = x
Definition: field.cpp:212
Field::real_t
double real_t
Definition: field.h:51
AFopr_Chebyshev::tidyup
void tidyup()
final cleanup.
Definition: afopr_Chebyshev-tmpl.h:78
AFopr_Chebyshev::init
void init()
initial setup (obsolete).
Definition: afopr_Chebyshev-tmpl.h:49
AFopr_Chebyshev::get_parameters
void get_parameters(Parameters &params) const
gets parameters by a Parameter object: to be implemented in a subclass.
Definition: afopr_Chebyshev-tmpl.h:157
threadManager.h
Test_Mult::mult
int mult(const std::string &)
Definition: test_Mult.cpp:169
AFopr_Chebyshev::get_mode
std::string get_mode() const
returns the current mult mode.
Definition: afopr_Chebyshev-tmpl.h:186
CommonParameters::Vlevel
static Bridge::VerboseLevel Vlevel()
Definition: commonParameters.h:122
AFopr_Chebyshev
Chebyshev polynomial.
Definition: afopr_Chebyshev.h:34
AFopr_Chebyshev::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_Chebyshev-tmpl.h:177
Bridge::BridgeIO::set_verbose_level
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:133
Parameters::set_int
void set_int(const string &key, const int value)
Definition: parameters.cpp:36
scal
void scal(Field &x, const double a)
scal(x, a): x = a * x
Definition: field.cpp:261
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
Parameters::fetch_int
int fetch_int(const string &key, int &value) const
Definition: parameters.cpp:346
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