Bridge++  Ver. 1.2.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fopr_Rational.cpp
Go to the documentation of this file.
1 
14 #include "fopr_Rational.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", append_entry);
38 #endif
39 }
40 //- end
41 
42 //- parameters class
44 //- end
45 
46 const std::string Fopr_Rational::class_name = "Fopr_Rational";
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::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 //====================================================================
159 {
160  int Nconv;
161  double diff;
162 
163  vout.general(m_vl, " Shift solver in rational function\n");
164  vout.general(m_vl, " Number of shift values = %d\n", m_Np);
165 
166  m_fopr->set_mode("DdagD");
167  m_solver->solve(m_xq, m_cl, b, Nconv, diff);
168 
169  vout.general(m_vl, " diff(max) = %22.15e \n", diff);
170 
171  Field v(b);
172  v *= m_a0;
173  for (int i = 0; i < m_Np; i++) {
174  v += m_bl[i] * m_xq[i];
175  }
176 
177  return v;
178 }
179 
180 
181 //====================================================================
182 double Fopr_Rational::func(double x)
183 {
184  double y = m_a0;
185 
186  for (int k = 0; k < m_Np; ++k) {
187  y += m_bl[k] / (x + m_cl[k]);
188  }
189 
190  return y;
191 }
192 
193 
194 //====================================================================
195 //============================================================END=====
BridgeIO vout
Definition: bridgeIO.cpp:207
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.
const Field mult(const Field &f)
multiplies fermion operator to a given field and returns the resultant field.
void init_parameters()
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.
std::valarray< double > m_cl
Definition: fopr_Rational.h:62
int square_non_zero(const double v)
Definition: checker.cpp:41
double m_Stop_cond
Definition: fopr_Rational.h:56
Shiftsolver_CG * m_solver
Definition: fopr_Rational.h:59
std::valarray< double > m_bl
Definition: fopr_Rational.h:63
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
std::valarray< Field > m_xq
Definition: fopr_Rational.h:64
double func(double x)
void solve(std::valarray< Field > &solution, std::valarray< double > shift, const Field &source, int &Nconv, double &diff)
static const std::string class_name
Definition: fopr_Rational.h:49
static bool Register(const std::string &realm, const creator_callback &cb)
void set_parameters(const Parameters &params)
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
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
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:191