Bridge++  Version 1.4.4
 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 
17 #ifdef USE_FACTORY
18 namespace {
19  Fopr *create_object(Fopr *fopr)
20  {
21  return new Fopr_Rational(fopr);
22  }
23 
24 
25  bool init = Fopr::Factory_fopr::Register("Rational", create_object);
26 }
27 #endif
28 
29 
30 
31 const std::string Fopr_Rational::class_name = "Fopr_Rational";
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, n_exp, d_exp;
42  double x_min, x_max;
43  int Niter;
44  double Stop_cond;
45 
46  int err = 0;
47  err += params.fetch_int("number_of_poles", Np);
48  err += params.fetch_int("exponent_numerator", n_exp);
49  err += params.fetch_int("exponent_denominator", d_exp);
50  err += params.fetch_double("lower_bound", x_min);
51  err += params.fetch_double("upper_bound", x_max);
52  err += params.fetch_int("maximum_number_of_iteration", Niter);
53  err += params.fetch_double("convergence_criterion_squared", Stop_cond);
54 
55  if (err) {
56  vout.crucial(m_vl, "Error at %s: input parameter not found.\n", class_name.c_str());
57  exit(EXIT_FAILURE);
58  }
59 
60 
61  set_parameters(Np, n_exp, d_exp, x_min, x_max, Niter, Stop_cond);
62 }
63 
64 
65 //====================================================================
66 void Fopr_Rational::set_parameters(int Np, int n_exp, int d_exp,
67  double x_min, double x_max,
68  int Niter, double Stop_cond)
69 {
70  //- print input parameters
71  vout.general(m_vl, "%s:\n", class_name.c_str());
72  vout.general(m_vl, " Np = %d\n", Np);
73  vout.general(m_vl, " n_exp = %d\n", n_exp);
74  vout.general(m_vl, " d_exp = %d\n", d_exp);
75  vout.general(m_vl, " x_min = %12.8f\n", x_min);
76  vout.general(m_vl, " x_max = %12.8f\n", x_max);
77  vout.general(m_vl, " Niter = %d\n", Niter);
78  vout.general(m_vl, " Stop_cond = %8.2e\n", Stop_cond);
79 
80  //- range check
81  int err = 0;
82  err += ParameterCheck::non_zero(Np);
83  err += ParameterCheck::non_zero(n_exp);
84  err += ParameterCheck::non_zero(d_exp);
85  // NB. x_min,x_max=0 is allowed.
86  err += ParameterCheck::non_zero(Niter);
87  err += ParameterCheck::square_non_zero(Stop_cond);
88 
89  if (err) {
90  vout.crucial(m_vl, "Error at %s: parameter range check failed.\n", class_name.c_str());
91  exit(EXIT_FAILURE);
92  }
93 
94  //- store values
95  m_Np = Np;
96  m_n_exp = n_exp;
97  m_d_exp = d_exp;
98  m_x_min = x_min;
99  m_x_max = x_max;
100  m_Niter = Niter;
101  m_Stop_cond = Stop_cond;
102 
103  //- post-process
104  init_parameters();
105 }
106 
107 
108 //====================================================================
110 {
111  int Nin = m_fopr->field_nin();
112  int Nvol = m_fopr->field_nvol();
113  int Nex = m_fopr->field_nex();
114 
115  int Nshift = m_Np;
116 
117  double x_min2 = m_x_min * m_x_min;
118  double x_max2 = m_x_max * m_x_max;
119 
120  m_cl.resize(m_Np);
121  m_bl.resize(m_Np);
122 
123  m_xq.resize(m_Np);
124  for (int i = 0; i < Nshift; ++i) {
125  m_xq[i].reset(Nin, Nvol, Nex);
126  }
127 
129 
130  Math_Rational rational;
131  rational.set_parameters(m_Np, m_n_exp, m_d_exp, x_min2, x_max2);
132  rational.get_parameters(m_a0, m_bl, m_cl);
133 
134  vout.general(m_vl, " a0 = %18.14f\n", m_a0);
135  for (int i = 0; i < m_Np; i++) {
136  vout.general(m_vl, " bl[%d] = %18.14f cl[%d] = %18.14f\n",
137  i, m_bl[i], i, m_cl[i]);
138  }
139 }
140 
141 
142 //====================================================================
143 void Fopr_Rational::mult(Field& v, const Field& b)
144 {
145  int Nconv;
146  double diff;
147 
148  assert(v.nin() == b.nin());
149  assert(v.nvol() == b.nvol());
150  assert(v.nex() == b.nex());
151 
152  vout.general(m_vl, " Shift solver in rational function\n");
153  vout.general(m_vl, " Number of shift values = %d\n", m_Np);
154 
155  m_fopr->set_mode("DdagD");
156  m_solver->solve(m_xq, m_cl, b, Nconv, diff);
157 
158  vout.general(m_vl, " diff(max) = %22.15e \n", diff);
159 
160  copy(v, b);
161  scal(v, m_a0); // v *= m_a0;
162  for (int i = 0; i < m_Np; i++) {
163  axpy(v, m_bl[i], m_xq[i]); // v += m_bl[i] * m_xq[i];
164  }
165 }
166 
167 
168 //====================================================================
169 double Fopr_Rational::func(double x)
170 {
171  double y = m_a0;
172 
173  for (int k = 0; k < m_Np; ++k) {
174  y += m_bl[k] / (x + m_cl[k]);
175  }
176 
177  return y;
178 }
179 
180 
181 //====================================================================
182 //============================================================END=====
void scal(Field &x, const double a)
scal(x, a): x = a * x
Definition: field.cpp:282
void get_parameters(double &norm, std::vector< double > &res, std::vector< double > &pole)
Fermion operator for rational approximation.
Definition: fopr_Rational.h:41
BridgeIO vout
Definition: bridgeIO.cpp:495
void general(const char *format,...)
Definition: bridgeIO.cpp:195
void set_parameters(const Parameters &params)
std::vector< Field > m_xq
Definition: fopr_Rational.h:59
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
Multishift Conjugate Gradient solver.
void init_parameters()
Class for parameters.
Definition: parameters.h:46
void copy(Field &y, const Field &x)
copy(y, x): y = x
Definition: field.cpp:381
void mult(Field &v, const Field &f)
multiplies fermion operator to a given field (2nd argument)
std::vector< double > m_cl
Definition: fopr_Rational.h:57
virtual int field_nin()=0
returns the on-site d.o.f. for which the fermion operator is defined.
Determionation of coefficients of rational approximation.
Definition: math_Rational.h:41
int square_non_zero(const double v)
Definition: checker.cpp:41
int nin() const
Definition: field.h:115
double m_Stop_cond
Definition: fopr_Rational.h:51
Shiftsolver_CG * m_solver
Definition: fopr_Rational.h:54
Bridge::VerboseLevel m_vl
Definition: fopr.h:128
int fetch_int(const string &key, int &value) const
Definition: parameters.cpp:230
virtual int field_nex()=0
returns the external d.o.f. for which the fermion operator is defined.
int nex() const
Definition: field.h:117
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
double func(double x)
static const std::string class_name
Definition: fopr_Rational.h:44
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:96
std::vector< double > m_bl
Definition: fopr_Rational.h:58
Base class of fermion operator family.
Definition: fopr.h:47
string get_string(const string &key) const
Definition: parameters.cpp:116
virtual int field_nvol()=0
returns the volume for which the fermion operator is defined.
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
void solve(std::vector< Field > &solution, const std::vector< double > &shift, const Field &source, int &Nconv, double &diff)