Bridge++  Ver. 1.2.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fopr_Rational_SF.cpp
Go to the documentation of this file.
1 
14 #include "fopr_Rational_SF.h"
15 
16 #ifdef USE_PARAMETERS_FACTORY
17 #include "parameters_factory.h"
18 #endif
19 
20 //- parameter entry
21 namespace {
22  void append_entry(Parameters& param)
23  {
24  param.Register_int("number_of_poles", 0);
25  param.Register_int("exponent_numerator", 0);
26  param.Register_int("exponent_denominator", 0);
27  param.Register_double("lower_bound", 0.0);
28  param.Register_double("upper_bound", 0.0);
29  param.Register_int("maximum_number_of_iteration", 0);
30  param.Register_double("convergence_criterion_squared", 0.0);
31 
32  param.Register_string("verbose_level", "NULL");
33  }
34 
35 
36 #ifdef USE_PARAMETERS_FACTORY
37  bool init_param = ParametersFactory::Register("Fopr.Rational_SF", append_entry);
38 #endif
39 }
40 //- end
41 
42 //- parameters class
44 //- end
45 
46 const std::string Fopr_Rational_SF::class_name = "Fopr_Rational_SF";
47 
48 //====================================================================
50 {
51  const string str_vlevel = params.get_string("verbose_level");
52 
53  m_vl = vout.set_verbose_level(str_vlevel);
54 
55  //- fetch and check input parameters
56  int Np, n_exp, d_exp;
57  double x_min, x_max;
58  int Niter;
59  double Stop_cond;
60 
61  int err = 0;
62  err += params.fetch_int("number_of_poles", Np);
63  err += params.fetch_int("exponent_numerator", n_exp);
64  err += params.fetch_int("exponent_denominator", d_exp);
65  err += params.fetch_double("lower_bound", x_min);
66  err += params.fetch_double("upper_bound", x_max);
67  err += params.fetch_int("maximum_number_of_iteration", Niter);
68  err += params.fetch_double("convergence_criterion_squared", Stop_cond);
69 
70  if (err) {
71  vout.crucial(m_vl, "%s: fetch error, input parameter not found.\n", class_name.c_str());
72  abort();
73  }
74 
75 
76  set_parameters(Np, n_exp, d_exp, x_min, x_max, Niter, Stop_cond);
77 }
78 
79 
80 //====================================================================
81 void Fopr_Rational_SF::set_parameters(int Np, int n_exp, int d_exp,
82  double x_min, double x_max,
83  int Niter, double Stop_cond)
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, " n_exp = %d\n", n_exp);
89  vout.general(m_vl, " d_exp = %d\n", d_exp);
90  vout.general(m_vl, " x_min = %10.6f\n", x_min);
91  vout.general(m_vl, " x_max = %10.6f\n", x_max);
92  vout.general(m_vl, " Niter = %d\n", Niter);
93  vout.general(m_vl, " Stop_cond = %10.6f\n", Stop_cond);
94 
95  //- range check
96  int err = 0;
97  err += ParameterCheck::non_zero(Np);
98  err += ParameterCheck::non_zero(n_exp);
99  err += ParameterCheck::non_zero(d_exp);
100  // NB. x_min,x_max == 0 is allowed.
101  err += ParameterCheck::non_zero(Niter);
102  err += ParameterCheck::square_non_zero(Stop_cond);
103 
104  if (err) {
105  vout.crucial(m_vl, "%s: parameter range check failed.\n", class_name.c_str());
106  abort();
107  }
108 
109  //- store values
110  m_Np = Np;
111  m_n_exp = n_exp;
112  m_d_exp = d_exp;
113  m_x_min = x_min;
114  m_x_max = x_max;
115  m_Niter = Niter;
116  m_Stop_cond = Stop_cond;
117 
118  //- post-process
119  init_parameters();
120 }
121 
122 
123 //====================================================================
125 {
126  int Nin = m_fopr->field_nin();
127  int Nvol = m_fopr->field_nvol();
128  int Nex = m_fopr->field_nex();
129 
130  int Nshift = m_Np;
131 
132  double x_min2 = m_x_min * m_x_min;
133  double x_max2 = m_x_max * m_x_max;
134 
135  m_cl.resize(m_Np);
136  m_bl.resize(m_Np);
137 
138  m_xq.resize(m_Np);
139  for (int i = 0; i < Nshift; ++i) {
140  m_xq[i].reset(Nin, Nvol, Nex);
141  }
142 
144 
145  Math_Rational rational;
146  rational.set_parameters(m_Np, m_n_exp, m_d_exp, x_min2, x_max2);
147  rational.get_parameters(m_a0, m_bl, m_cl);
148 
149  vout.general(m_vl, " a0 = %18.14f\n", m_a0);
150  for (int i = 0; i < m_Np; i++) {
151  vout.general(m_vl, " bl[%d] = %18.14f cl[%d] = %18.14f\n",
152  i, m_bl[i], i, m_cl[i]);
153  }
154 }
155 
156 
157 //====================================================================
158 
167 {
168  int Nconv;
169  double diff;
170 
171  Field_F_SF set_zero;
172 
173  Field v(b);
174 
175  vout.general(m_vl, " Shift solver in rational function\n");
176  vout.general(m_vl, " Number of shift values = %d\n", m_Np);
177 
178  set_zero.set_boundary_zero(v);
179 
180  m_fopr->set_mode("DdagD");
181  m_solver->solve(m_xq, m_cl, v, Nconv, diff);
182 
183  vout.general(m_vl, " diff(max) = %22.15e \n", diff);
184 
185  v = b;
186  v *= m_a0;
187  for (int i = 0; i < m_Np; i++) {
188  v += m_bl[i] * m_xq[i];
189  }
190 
191  set_zero.set_boundary_zero(v);
192 
193  return v;
194 }
195 
196 
197 //====================================================================
198 double Fopr_Rational_SF::func(double x)
199 {
200  double y = m_a0;
201 
202  for (int k = 0; k < m_Np; ++k) {
203  y += m_bl[k] / (x + m_cl[k]);
204  }
205 
206  return y;
207 }
208 
209 
210 //====================================================================
211 //============================================================END=====
BridgeIO vout
Definition: bridgeIO.cpp:207
std::valarray< double > m_cl
void Register_string(const string &, const string &)
Definition: parameters.cpp:352
void general(const char *format,...)
Definition: bridgeIO.cpp:38
void Register_int(const string &, const int)
Definition: parameters.cpp:331
void set_parameters(const Parameters &params)
void get_parameters(double &norm, std::valarray< double > &res, std::valarray< double > &pole)
Container of Field-type object.
Definition: field.h:37
Multishift Conjugate Gradient solver.
static const std::string class_name
Class for parameters.
Definition: parameters.h:40
virtual int field_nin()=0
returns the on-site d.o.f. for which the fermion operator is defined.
int square_non_zero(const double v)
Definition: checker.cpp:41
void set_parameters(const Parameters &params)
std::valarray< Field > m_xq
Bridge::VerboseLevel m_vl
Definition: fopr.h:99
virtual int field_nex()=0
returns the external d.o.f. for which the fermion operator is defined.
void crucial(const char *format,...)
Definition: bridgeIO.cpp:26
Shiftsolver_CG * m_solver
void solve(std::valarray< Field > &solution, std::valarray< double > shift, const Field &source, int &Nconv, double &diff)
static bool Register(const std::string &realm, const creator_callback &cb)
void set_boundary_zero(Field &f)
Definition: field_F_SF.h:56
const Field mult(const Field &f)
int non_zero(const double v)
Definition: checker.cpp:31
virtual void set_mode(std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: fopr.h:75
void Register_double(const string &, const double)
Definition: parameters.cpp:324
std::valarray< double > m_bl
double func(double x)
int fetch_double(const string &key, double &val) const
Definition: parameters.cpp:124
string get_string(const string &key) const
Definition: parameters.cpp:85
virtual int field_nvol()=0
returns the volume for which the fermion operator is defined.
int fetch_int(const string &key, int &val) const
Definition: parameters.cpp:141
A class generated to add a function for the SF.
Definition: field_F_SF.h:33
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:191