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