Bridge++  Ver. 2.0.2
fopr_Rational_SF.cpp
Go to the documentation of this file.
1 
14 #include "fopr_Rational_SF.h"
15 
16 #ifdef USE_FACTORY_AUTOREGISTER
17 namespace {
18  bool init = Fopr_Rational_SF::register_factory();
19 }
20 #endif
21 
22 const std::string Fopr_Rational_SF::class_name = "Fopr_Rational_SF";
23 
24 //====================================================================
26 {
27  std::string vlevel;
28  if (!params.fetch_string("verbose_level", vlevel)) {
29  m_vl = vout.set_verbose_level(vlevel);
30  }
31 
32  //- fetch and check input parameters
33  int Np, n_exp, d_exp;
34  double x_min, x_max;
35  int Niter;
36  double Stop_cond;
37 
38  int err = 0;
39  err += params.fetch_int("number_of_poles", Np);
40  err += params.fetch_int("exponent_numerator", n_exp);
41  err += params.fetch_int("exponent_denominator", d_exp);
42  err += params.fetch_double("lower_bound", x_min);
43  err += params.fetch_double("upper_bound", x_max);
44  err += params.fetch_int("maximum_number_of_iteration", Niter);
45  err += params.fetch_double("convergence_criterion_squared", Stop_cond);
46 
47  if (err) {
48  vout.crucial(m_vl, "Error at %s: input parameter not found.\n", class_name.c_str());
49  exit(EXIT_FAILURE);
50  }
51 
52 
53  set_parameters(Np, n_exp, d_exp, x_min, x_max, Niter, Stop_cond);
54 }
55 
56 
57 //====================================================================
59 {
60  params.set_int("number_of_poles", m_Np);
61  params.set_int("exponent_numerator", m_n_exp);
62  params.set_int("exponent_denominator", m_d_exp);
63  params.set_double("lower_bound", m_x_min);
64  params.set_double("upper_bound", m_x_max);
65  params.set_int("maximum_number_of_iteration", m_Niter);
66  params.set_double("convergence_criterion_squared", m_Stop_cond);
67 
68  params.set_string("verbose_level", vout.get_verbose_level(m_vl));
69 }
70 
71 
72 //====================================================================
73 void Fopr_Rational_SF::set_parameters(const int Np, const int n_exp, const int d_exp,
74  const double x_min, const double x_max,
75  const int Niter, const double Stop_cond)
76 {
77  //- print input parameters
78  vout.general(m_vl, "%s:\n", class_name.c_str());
79  vout.general(m_vl, " Np = %d\n", Np);
80  vout.general(m_vl, " n_exp = %d\n", n_exp);
81  vout.general(m_vl, " d_exp = %d\n", d_exp);
82  vout.general(m_vl, " x_min = %12.8f\n", x_min);
83  vout.general(m_vl, " x_max = %12.8f\n", x_max);
84  vout.general(m_vl, " Niter = %d\n", Niter);
85  vout.general(m_vl, " Stop_cond = %8.2e\n", Stop_cond);
86 
87  //- range check
88  int err = 0;
89  err += ParameterCheck::non_zero(Np);
90  err += ParameterCheck::non_zero(n_exp);
91  err += ParameterCheck::non_zero(d_exp);
92  // NB. x_min,x_max == 0 is allowed.
93  err += ParameterCheck::non_zero(Niter);
94  err += ParameterCheck::square_non_zero(Stop_cond);
95 
96  if (err) {
97  vout.crucial(m_vl, "Error at %s: parameter range check failed.\n", class_name.c_str());
98  exit(EXIT_FAILURE);
99  }
100 
101  //- store values
102  m_Np = Np;
103  m_n_exp = n_exp;
104  m_d_exp = d_exp;
105  m_x_min = x_min;
106  m_x_max = x_max;
107  m_Niter = Niter;
108  m_Stop_cond = Stop_cond;
109 
110  //- post-process
111  init_parameters();
112 }
113 
114 
115 //====================================================================
117 {
118  const int Nin = m_fopr->field_nin();
119  const int Nvol = m_fopr->field_nvol();
120  const int Nex = m_fopr->field_nex();
121 
122  const int Nshift = m_Np;
123 
124  const double x_min2 = m_x_min * m_x_min;
125  const double x_max2 = m_x_max * m_x_max;
126 
127  m_cl.resize(m_Np);
128  m_bl.resize(m_Np);
129 
130  m_xq.resize(m_Np);
131  for (int i = 0; i < Nshift; ++i) {
132  m_xq[i].reset(Nin, Nvol, Nex);
133  }
134 
136 
137  Math_Rational rational;
138  rational.set_parameters(m_Np, m_n_exp, m_d_exp, x_min2, x_max2);
139  rational.get_parameters(m_a0, m_bl, m_cl);
140 
141  vout.general(m_vl, " a0 = %18.14f\n", m_a0);
142  for (int i = 0; i < m_Np; i++) {
143  vout.general(m_vl, " bl[%d] = %18.14f cl[%d] = %18.14f\n",
144  i, m_bl[i], i, m_cl[i]);
145  }
146 }
147 
148 
149 //====================================================================
150 
159 {
160  assert(v.nin() == b.nin());
161  assert(v.nvol() == b.nvol());
162  assert(v.nex() == b.nex());
163 
164  copy(v, b);
165 
166  vout.general(m_vl, " Shift solver in rational function\n");
167  vout.general(m_vl, " Number of shift values = %d\n", m_Np);
168 
170 
171  int Nconv;
172  double diff;
173 
174  m_fopr->set_mode("DdagD");
175  m_solver->solve(m_xq, m_cl, v, Nconv, diff);
176 
177  vout.general(m_vl, " diff(max) = %22.15e \n", diff);
178 
179  copy(v, b); // v = b;
180  scal(v, m_a0); // v *= m_a0;
181  for (int i = 0; i < m_Np; i++) {
182  axpy(v, m_bl[i], m_xq[i]); // v += m_bl[i] * m_xq[i];
183  }
184 
186 }
187 
188 
189 //====================================================================
190 double Fopr_Rational_SF::func(const double x)
191 {
192  double y = m_a0;
193 
194  for (int k = 0; k < m_Np; ++k) {
195  y += m_bl[k] / (x + m_cl[k]);
196  }
197 
198  return y;
199 }
200 
201 
202 //====================================================================
204 {
205  //- Counting of floating point operations in giga unit.
206  // not implemented, yet.
207 
208  vout.general(m_vl, "Warning at %s: flop_count() has not been implemented.\n", class_name.c_str());
209 
210  const double gflop = 0.0;
211 
212  return gflop;
213 }
214 
215 
216 //====================================================================
217 //============================================================END=====
Parameters::set_string
void set_string(const string &key, const string &value)
Definition: parameters.cpp:39
Parameters
Class for parameters.
Definition: parameters.h:46
Fopr_Rational_SF::init_parameters
void init_parameters()
Definition: fopr_Rational_SF.cpp:116
Fopr_Rational_SF::m_Np
int m_Np
Definition: fopr_Rational_SF.h:52
Parameters::set_double
void set_double(const string &key, const double value)
Definition: parameters.cpp:33
AFopr::field_nex
virtual int field_nex()=0
returns the external degree of freedom of the fermion field.
Fopr_Rational_SF::m_d_exp
int m_d_exp
Definition: fopr_Rational_SF.h:53
Field::nex
int nex() const
Definition: field.h:128
fopr_Rational_SF.h
Fopr_Rational_SF::get_parameters
void get_parameters(Parameters &params) const
gets parameters by a Parameter object: to be implemented in a subclass.
Definition: fopr_Rational_SF.cpp:58
Math_Rational::get_parameters
void get_parameters(double &norm, std::vector< double > &res, std::vector< double > &pole)
Definition: math_Rational.cpp:100
Fopr_Rational_SF::m_fopr
Fopr * m_fopr
Definition: fopr_Rational_SF.h:58
axpy
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:380
Fopr_Rational_SF::m_x_min
double m_x_min
Definition: fopr_Rational_SF.h:54
Fopr_Rational_SF::m_a0
double m_a0
Definition: fopr_Rational_SF.h:61
AFopr::set_mode
virtual void set_mode(std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: afopr.h:81
Field::nin
int nin() const
Definition: field.h:126
copy
void copy(Field &y, const Field &x)
copy(y, x): y = x
Definition: field.cpp:212
Math_Rational::set_parameters
void set_parameters(const Parameters &params)
Definition: math_Rational.cpp:20
Field_SF::set_boundary_zero
void set_boundary_zero(Field_G &u)
Definition: field_SF.cpp:96
AShiftsolver_CG::solve
void solve(std::vector< FIELD > &solution, const std::vector< double > &shift, const FIELD &source, int &Nconv, double &diff)
Definition: ashiftsolver_CG-tmpl.h:88
Fopr_Rational_SF::m_solver
Shiftsolver_CG * m_solver
Definition: fopr_Rational_SF.h:59
Fopr_Rational_SF::flop_count
double flop_count()
this returns the number of floating point operations.
Definition: fopr_Rational_SF.cpp:203
AFopr::field_nvol
virtual int field_nvol()=0
returns the volume of the fermion field.
Fopr_Rational_SF::m_bl
std::vector< double > m_bl
Definition: fopr_Rational_SF.h:63
Fopr_Rational_SF::set_parameters
void set_parameters(const Parameters &params)
sets parameters by a Parameter object: to be implemented in a subclass.
Definition: fopr_Rational_SF.cpp:25
ParameterCheck::square_non_zero
int square_non_zero(const double v)
Definition: parameterCheck.cpp:43
Field::nvol
int nvol() const
Definition: field.h:127
Shiftsolver_CG
AShiftsolver_CG< Field, Fopr > Shiftsolver_CG
Multishift Conjugate Gradient solver.
Definition: shiftsolver_CG.h:35
Fopr_Rational_SF::class_name
static const std::string class_name
Definition: fopr_Rational_SF.h:47
Fopr_Rational_SF::mult
void mult(Field &v, const Field &f)
Definition: fopr_Rational_SF.cpp:158
Fopr_Rational_SF::m_Niter
int m_Niter
Definition: fopr_Rational_SF.h:55
Bridge::BridgeIO::set_verbose_level
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:133
ParameterCheck::non_zero
int non_zero(const double v)
Definition: parameterCheck.cpp:32
Fopr_Rational_SF::m_cl
std::vector< double > m_cl
Definition: fopr_Rational_SF.h:62
Fopr_Rational_SF::m_vl
Bridge::VerboseLevel m_vl
Definition: fopr_Rational_SF.h:50
Parameters::set_int
void set_int(const string &key, const int value)
Definition: parameters.cpp:36
scal
void scal(Field &x, const double a)
scal(x, a): x = a * x
Definition: field.cpp:261
Fopr_Rational_SF::m_Stop_cond
double m_Stop_cond
Definition: fopr_Rational_SF.h:56
Parameters::fetch_string
int fetch_string(const string &key, string &value) const
Definition: parameters.cpp:378
Parameters::fetch_double
int fetch_double(const string &key, double &value) const
Definition: parameters.cpp:327
Fopr_Rational_SF::m_x_max
double m_x_max
Definition: fopr_Rational_SF.h:54
Fopr_Rational_SF::m_xq
std::vector< Field > m_xq
Definition: fopr_Rational_SF.h:64
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Fopr_Rational_SF::func
double func(const double x)
Definition: fopr_Rational_SF.cpp:190
Fopr_Rational_SF::m_n_exp
int m_n_exp
Definition: fopr_Rational_SF.h:53
Field
Container of Field-type object.
Definition: field.h:46
AFopr::field_nin
virtual int field_nin()=0
returns the on-site degree of freedom of the fermion field.
Math_Rational
Determionation of coefficients of rational approximation.
Definition: math_Rational.h:40
Parameters::fetch_int
int fetch_int(const string &key, int &value) const
Definition: parameters.cpp:346
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
Bridge::BridgeIO::get_verbose_level
static std::string get_verbose_level(const VerboseLevel vl)
Definition: bridgeIO.cpp:154