Bridge++  Ver. 1.3.x
fopr_Chebyshev.cpp
Go to the documentation of this file.
1 
14 #include "fopr_Chebyshev.h"
15 
16 #ifdef USE_PARAMETERS_FACTORY
17 #include "parameters_factory.h"
18 #endif
19 
20 #ifdef USE_FACTORY
21 namespace {
22  Fopr *create_object(Fopr *fopr)
23  {
24  return new Fopr_Chebyshev(fopr);
25  }
26 
27 
28  bool init = Fopr::Factory_fopr::Register("Chevyshev", create_object);
29 }
30 #endif
31 
32 //- parameter entries
33 namespace {
34  void append_entry(Parameters& param)
35  {
36  param.Register_int("degree_of_polynomial", 0);
37  param.Register_double("threshold_value", 0.0);
38  param.Register_double("upper_bound", 0.0);
39 
40  param.Register_string("verbose_level", "NULL");
41  }
42 
43 
44 #ifdef USE_PARAMETERS_FACTORY
45  bool init_param = ParametersFactory::Register("Fopr.Chebyshev", append_entry);
46 #endif
47 }
48 //- end
49 
50 //- parameters class
52 //- end
53 
54 const std::string Fopr_Chebyshev::class_name = "Fopr_Chebyshev";
55 
56 //====================================================================
58 {
59  const string str_vlevel = params.get_string("verbose_level");
60 
61  m_vl = vout.set_verbose_level(str_vlevel);
62 
63  //- fetch and check input parameters
64  int Np;
65  double v_threshold, v_max;
66 
67  int err = 0;
68  err += params.fetch_int("degree_of_polynomial", Np);
69  err += params.fetch_double("threshold_value", v_threshold);
70  err += params.fetch_double("upper_bound", v_max);
71 
72  if (err) {
73  vout.crucial(m_vl, "%s: fetch error, input parameter not found.\n", class_name.c_str());
74  exit(EXIT_FAILURE);
75  }
76 
77 
78  set_parameters(Np, v_threshold, v_max);
79 }
80 
81 
82 //====================================================================
83 void Fopr_Chebyshev::set_parameters(int Np, double v_threshold, double v_max)
84 {
85  //- print input parameters
86  vout.general(m_vl, "Parameters of %s:\n", class_name.c_str());
87  vout.general(m_vl, " Np = %d\n", Np);
88  vout.general(m_vl, " v_threshold = %16.8e\n", v_threshold);
89  vout.general(m_vl, " v_max = %16.8e\n", v_max);
90 
91 
92  //- range check
93  int err = 0;
95  // NB. v_threshold,v_max == 0 is allowed.
96 
97  if (err) {
98  vout.crucial(m_vl, "%s: parameter range check failed.\n", class_name.c_str());
99  exit(EXIT_FAILURE);
100  }
101 
102  //- store values
103  m_Npcb = Np;
104 
105  double b_max = v_max / v_threshold;
106  double r = 2.0 / (b_max * b_max - 1.0);
107  double s = v_threshold / sqrt(0.5 * r);
108 
109  m_Fcb1 = 2.0 / (s * s);
110  m_Fcb2 = -(1.0 + r);
111 
112  vout.general(m_vl, " Fcb1 = %16.8e\n", m_Fcb1);
113  vout.general(m_vl, " Fcb2 = %16.8e\n", m_Fcb2);
114 }
115 
116 
117 //====================================================================
118 void Fopr_Chebyshev::mult(Field& v, const Field& w)
119 {
120  std::vector<Field> dj(3);
121  int Nin = w.nin();
122  int Nvol = w.nvol();
123  int Nex = w.nex();
124 
125  assert(v.nin() == Nin);
126  assert(v.nvol() == Nvol);
127  assert(v.nex() == Nex);
128 
129  for (int k = 0; k < 3; ++k) {
130  dj[k].reset(Nin, Nvol, Nex);
131  }
132 
133  dj[0] = w;
134  scal(dj[0], -1.0);
135  dj[1].set(0.0);
136 
137  int jn = 2;
138  int jp1 = 1;
139  int jp2 = 0;
140 
141  for (int j = m_Npcb; j >= 2; --j) {
142  m_fopr->mult(dj[jn], dj[jp1]);
143  scal(dj[jn], m_Fcb1);
144  axpy(dj[jn], m_Fcb2, dj[jp1]);
145 
146  scal(dj[jn], 2.0);
147  axpy(dj[jn], -1.0, dj[jp2]);
148 
149  jn = (jn + 1) % 3;
150  jp1 = (jp1 + 1) % 3;
151  jp2 = (jp2 + 1) % 3;
152  }
153 
154  m_fopr->mult(v, dj[jp1]);
155  scal(v, m_Fcb1);
156  axpy(v, m_Fcb2, dj[jp1]);
157  axpy(v, -1.0, dj[jp2]);
158 }
159 
160 
161 //====================================================================
162 double Fopr_Chebyshev::mult(double x)
163 {
164  std::vector<double> dj(3);
165 
166  dj[0] = -1.0;
167  dj[1] = 0.0;
168 
169  int jn = 2;
170  int jp1 = 1;
171  int jp2 = 0;
172 
173  for (int j = m_Npcb; j >= 2; --j) {
174  dj[jn] = x * dj[jp1];
175  dj[jn] *= m_Fcb1;
176  dj[jn] += m_Fcb2 * dj[jp1];
177 
178  dj[jn] *= 2.0;
179  dj[jn] -= 1.0 * dj[jp2];
180 
181  jn = (jn + 1) % 3;
182  jp1 = (jp1 + 1) % 3;
183  jp2 = (jp2 + 1) % 3;
184  }
185 
186  double v = x * dj[jp1];
187  v *= m_Fcb1;
188  v += m_Fcb2 * dj[jp1];
189  v -= dj[jp2];
190 
191  return v;
192 }
193 
194 
195 //====================================================================
196 //============================================================END=====
void scal(Field &x, const double a)
scal(x, a): x = a * x
Definition: field.cpp:282
BridgeIO vout
Definition: bridgeIO.cpp:278
void Register_string(const string &, const string &)
Definition: parameters.cpp:351
void general(const char *format,...)
Definition: bridgeIO.cpp:65
void Register_int(const string &, const int)
Definition: parameters.cpp:330
Container of Field-type object.
Definition: field.h:39
int nvol() const
Definition: field.h:116
Class for parameters.
Definition: parameters.h:38
int nin() const
Definition: field.h:115
Bridge::VerboseLevel m_vl
Definition: fopr.h:113
void mult(Field &v, const Field &f)
multiplies fermion operator to a given field (2nd argument)
int nex() const
Definition: field.h:117
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:168
void crucial(const char *format,...)
Definition: bridgeIO.cpp:48
static bool Register(const std::string &realm, const creator_callback &cb)
void set_parameters(const Parameters &params)
virtual void mult(Field &, const Field &)=0
multiplies fermion operator to a given field (2nd argument)
int non_negative(const int v)
Definition: checker.cpp:21
void Register_double(const string &, const double)
Definition: parameters.cpp:323
static const std::string class_name
Base class of fermion operator family.
Definition: fopr.h:49
int fetch_double(const string &key, double &val) const
Definition: parameters.cpp:124
string get_string(const string &key) const
Definition: parameters.cpp:87
int fetch_int(const string &key, int &val) const
Definition: parameters.cpp:141
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:28