Bridge++  Version 1.5.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 #ifdef USE_FACTORY_AUTOREGISTER
17 namespace {
18  bool init = Fopr_Chebyshev::register_factory();
19 }
20 #endif
21 
22 const std::string Fopr_Chebyshev::class_name = "Fopr_Chebyshev";
23 
24 //====================================================================
26 {
27  const string str_vlevel = params.get_string("verbose_level");
28 
29  m_vl = vout.set_verbose_level(str_vlevel);
30 
31  //- fetch and check input parameters
32  int Np;
33  double v_threshold, v_max;
34 
35  int err = 0;
36  err += params.fetch_int("degree_of_polynomial", Np);
37  err += params.fetch_double("threshold_value", v_threshold);
38  err += params.fetch_double("upper_bound", v_max);
39 
40  if (err) {
41  vout.crucial(m_vl, "Error at %s: input parameter not found.\n", class_name.c_str());
42  exit(EXIT_FAILURE);
43  }
44 
45 
46  set_parameters(Np, v_threshold, v_max);
47 }
48 
49 
50 //====================================================================
51 void Fopr_Chebyshev::set_parameters(const int Np, const double v_threshold, const double v_max)
52 {
53  //- print input parameters
54  vout.general(m_vl, "%s:\n", class_name.c_str());
55  vout.general(m_vl, " Np = %d\n", Np);
56  vout.general(m_vl, " v_threshold = %16.8e\n", v_threshold);
57  vout.general(m_vl, " v_max = %16.8e\n", v_max);
58 
59 
60  //- range check
61  int err = 0;
63  // NB. v_threshold,v_max == 0 is allowed.
64 
65  if (err) {
66  vout.crucial(m_vl, "Error at %s: parameter range check failed.\n", class_name.c_str());
67  exit(EXIT_FAILURE);
68  }
69 
70  //- store values
71  m_Npcb = Np;
72 
73  const double b_max = v_max / v_threshold;
74  const double r = 2.0 / (b_max * b_max - 1.0);
75  const double s = v_threshold / sqrt(0.5 * r);
76 
77  m_Fcb1 = 2.0 / (s * s);
78  m_Fcb2 = -(1.0 + r);
79 
80  vout.general(m_vl, " Fcb1 = %16.8e\n", m_Fcb1);
81  vout.general(m_vl, " Fcb2 = %16.8e\n", m_Fcb2);
82 }
83 
84 
85 //====================================================================
86 void Fopr_Chebyshev::mult(Field& v, const Field& w)
87 {
88  assert(v.nin() == w.nin());
89  assert(v.nvol() == w.nvol());
90  assert(v.nex() == w.nex());
91 
92  const int Nin = w.nin();
93  const int Nvol = w.nvol();
94  const int Nex = w.nex();
95 
96  std::vector<Field> dj(3);
97  for (int k = 0; k < 3; ++k) {
98  dj[k].reset(Nin, Nvol, Nex);
99  }
100 
101  dj[0] = w;
102  scal(dj[0], -1.0);
103  dj[1].set(0.0);
104 
105  int jn = 2;
106  int jp1 = 1;
107  int jp2 = 0;
108 
109  for (int j = m_Npcb; j >= 2; --j) {
110  m_fopr->mult(dj[jn], dj[jp1]);
111  scal(dj[jn], m_Fcb1);
112  axpy(dj[jn], m_Fcb2, dj[jp1]);
113 
114  scal(dj[jn], 2.0);
115  axpy(dj[jn], -1.0, dj[jp2]);
116 
117  jn = (jn + 1) % 3;
118  jp1 = (jp1 + 1) % 3;
119  jp2 = (jp2 + 1) % 3;
120  }
121 
122  m_fopr->mult(v, dj[jp1]);
123  scal(v, m_Fcb1);
124  axpy(v, m_Fcb2, dj[jp1]);
125  axpy(v, -1.0, dj[jp2]);
126 }
127 
128 
129 //====================================================================
130 double Fopr_Chebyshev::mult(const double x)
131 {
132  std::vector<double> dj(3);
133 
134  dj[0] = -1.0;
135  dj[1] = 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  dj[jn] = x * dj[jp1];
143  dj[jn] *= m_Fcb1;
144  dj[jn] += m_Fcb2 * dj[jp1];
145 
146  dj[jn] *= 2.0;
147  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  double v = x * dj[jp1];
155  v *= m_Fcb1;
156  v += m_Fcb2 * dj[jp1];
157  v -= dj[jp2];
158 
159  return v;
160 }
161 
162 
163 //====================================================================
164 //============================================================END=====
void scal(Field &x, const double a)
scal(x, a): x = a * x
Definition: field.cpp:433
BridgeIO vout
Definition: bridgeIO.cpp:503
void general(const char *format,...)
Definition: bridgeIO.cpp:197
Container of Field-type object.
Definition: field.h:45
int fetch_double(const string &key, double &value) const
Definition: parameters.cpp:327
int nvol() const
Definition: field.h:127
Class for parameters.
Definition: parameters.h:46
int nin() const
Definition: field.h:126
Bridge::VerboseLevel m_vl
Definition: fopr.h:127
int fetch_int(const string &key, int &value) const
Definition: parameters.cpp:346
void mult(Field &v, const Field &f)
multiplies fermion operator to a given field (2nd argument)
int nex() const
Definition: field.h:128
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:319
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)
static const std::string class_name
string get_string(const string &key) const
Definition: parameters.cpp:221
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131