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