Bridge++  Ver. 2.0.2
afopr_Rational-tmpl.h
Go to the documentation of this file.
1 
14 #include "Fopr/afopr_Rational.h"
15 
19 
20 //#ifdef USE_FACTORY_AUTOREGISTER
21 //namespace {
22 // bool init = Fopr_Rational::register_factory();
23 //}
24 //#endif
25 
26 template<typename AFIELD>
27 const std::string AFopr_Rational<AFIELD>::class_name = "AFopr_Rational";
28 
29 //====================================================================
30 template<typename AFIELD>
32 {
33  std::string vlevel;
34  if (!params.fetch_string("verbose_level", vlevel)) {
35  m_vl = vout.set_verbose_level(vlevel);
36  }
37 
38  //- fetch and check input parameters
39  int Np, n_exp, d_exp;
40  double x_min, x_max;
41  int Niter;
42  double Stop_cond;
43 
44  int err = 0;
45  err += params.fetch_int("number_of_poles", Np);
46  err += params.fetch_int("exponent_numerator", n_exp);
47  err += params.fetch_int("exponent_denominator", d_exp);
48  err += params.fetch_double("lower_bound", x_min);
49  err += params.fetch_double("upper_bound", x_max);
50  err += params.fetch_int("maximum_number_of_iteration", Niter);
51  err += params.fetch_double("convergence_criterion_squared", Stop_cond);
52 
53  if (err) {
54  vout.crucial(m_vl, "Error at %s: input parameter not found.\n",
55  class_name.c_str());
56  exit(EXIT_FAILURE);
57  }
58 
59  set_parameters(Np, n_exp, d_exp, real_t(x_min), real_t(x_max),
60  Niter, real_t(Stop_cond));
61 }
62 
63 
64 //====================================================================
65 template<typename AFIELD>
67 {
68  params.set_int("number_of_poles", m_Np);
69  params.set_int("exponent_numerator", m_n_exp);
70  params.set_int("exponent_denominator", m_d_exp);
71  params.set_double("lower_bound", double(m_x_min));
72  params.set_double("upper_bound", double(m_x_max));
73  params.set_int("maximum_number_of_iteration", m_Niter);
74  params.set_double("convergence_criterion_squared", double(m_Stop_cond));
75 
76  params.set_string("verbose_level", vout.get_verbose_level(m_vl));
77 }
78 
79 
80 //====================================================================
81 template<typename AFIELD>
83  const int Np,
84  const int n_exp, const int d_exp,
85  const real_t x_min, const real_t x_max,
86  const int Niter, const real_t Stop_cond)
87 {
88  //- print input parameters
89  vout.general(m_vl, "%s:\n", class_name.c_str());
90  vout.general(m_vl, " Np = %d\n", Np);
91  vout.general(m_vl, " n_exp = %d\n", n_exp);
92  vout.general(m_vl, " d_exp = %d\n", d_exp);
93  vout.general(m_vl, " x_min = %12.8f\n", x_min);
94  vout.general(m_vl, " x_max = %12.8f\n", x_max);
95  vout.general(m_vl, " Niter = %d\n", Niter);
96  vout.general(m_vl, " Stop_cond = %8.2e\n", Stop_cond);
97 
98  //- range check
99  int err = 0;
100  err += ParameterCheck::non_zero(Np);
101  err += ParameterCheck::non_zero(n_exp);
102  err += ParameterCheck::non_zero(d_exp);
103  // NB. x_min,x_max=0 is allowed.
104  err += ParameterCheck::non_zero(Niter);
105  err += ParameterCheck::square_non_zero(Stop_cond);
106 
107  if (err) {
108  vout.crucial(m_vl, "Error at %s: parameter range check failed.\n", class_name.c_str());
109  exit(EXIT_FAILURE);
110  }
111 
112  //- store values
113  m_Np = Np;
114  m_n_exp = n_exp;
115  m_d_exp = d_exp;
116  m_x_min = x_min;
117  m_x_max = x_max;
118  m_Niter = Niter;
119  m_Stop_cond = Stop_cond;
120 
121  //- post-process
122  init_parameters();
123 }
124 
125 
126 
127 //====================================================================
128 template<typename AFIELD>
130 {
131  m_fopr->set_config(U);
132 }
133 
134 //====================================================================
135 template<typename AFIELD>
137 {
138  const int Nin = m_fopr->field_nin();
139  const int Nvol = m_fopr->field_nvol();
140  const int Nex = m_fopr->field_nex();
141 
142  const int Nshift = m_Np;
143 
144  const double x_min2 = m_x_min * m_x_min;
145  const double x_max2 = m_x_max * m_x_max;
146 
147  m_cl.resize(m_Np);
148  m_bl.resize(m_Np);
149 
150  m_xq.resize(m_Np);
151  for (int i = 0; i < Nshift; ++i) {
152  m_xq[i].reset(Nin, Nvol, Nex);
153  }
154 
155  m_solver = new AShiftsolver_CG<AFIELD, AFopr<AFIELD> >(
156  m_fopr, m_Niter, m_Stop_cond);
157 
158  std::vector<double> bl(m_Np), cl(m_Np);
159  double a0;
160 
161  Math_Rational rational;
162  rational.set_parameters(m_Np, m_n_exp, m_d_exp,
163  double(x_min2), double(x_max2));
164  rational.get_parameters(a0, bl, cl);
165 
166  m_a0 = a0;
167 
168  vout.general(m_vl, " a0 = %18.14f\n", m_a0);
169  for (int i = 0; i < m_Np; i++) {
170  m_bl[i] = real_t(bl[i]);
171  m_cl[i] = real_t(cl[i]);
172  vout.general(m_vl, " bl[%d] = %18.14f cl[%d] = %18.14f\n",
173  i, m_bl[i], i, m_cl[i]);
174  }
175 }
176 
177 
178 //====================================================================
179 template<typename AFIELD>
181 {
182 #pragma omp barrier
183 
184  assert(v.nin() == b.nin());
185  assert(v.nvol() == b.nvol());
186  assert(v.nex() == b.nex());
187 
188  vout.general(m_vl, "Shift solver in rational function\n");
190 
191  vout.detailed(m_vl, "Number of shift values = %d\n", m_Np);
192 
193  int Nconv;
194  real_t diff;
195 
196  m_fopr->set_mode("DdagD");
197  m_solver->solve(m_xq, m_cl, b, Nconv, diff);
198 
199  vout.general(m_vl, "diff(max) = %22.15e \n", diff);
200 
201  copy(v, b);
202  scal(v, real_t(m_a0));
203  for (int i = 0; i < m_Np; i++) {
204  axpy(v, real_t(m_bl[i]), m_xq[i]);
205  }
207 
208 #pragma omp barrier
209 }
210 
211 
212 //====================================================================
213 template<typename AFIELD>
215 {
216  real_t y = m_a0;
217 
218  for (int k = 0; k < m_Np; ++k) {
219  y += m_bl[k] / (x + m_cl[k]);
220  }
221 
222  return y;
223 }
224 
225 
226 //============================================================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
AFopr_Rational::mult
void mult(AFIELD &v, const AFIELD &f)
multiplies fermion operator to a given field.
Definition: afopr_Rational-tmpl.h:180
AFopr_Rational::set_parameters
void set_parameters(const Parameters &params)
sets parameters by a Parameter object: to be implemented in a subclass.
Definition: afopr_Rational-tmpl.h:31
Parameters::set_double
void set_double(const string &key, const double value)
Definition: parameters.cpp:33
Bridge::BridgeIO::decrease_indent
void decrease_indent()
Definition: bridgeIO.h:86
AFopr_Rational::func
real_t func(const real_t x)
Definition: afopr_Rational-tmpl.h:214
Bridge::BridgeIO::increase_indent
void increase_indent()
Definition: bridgeIO.h:85
Bridge::BridgeIO::detailed
void detailed(const char *format,...)
Definition: bridgeIO.cpp:219
Field::nex
int nex() const
Definition: field.h:128
Math_Rational::get_parameters
void get_parameters(double &norm, std::vector< double > &res, std::vector< double > &pole)
Definition: math_Rational.cpp:100
axpy
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:380
real_t
double real_t
Definition: bridgeQXS_Clover_coarse_double.cpp:16
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
Field::real_t
double real_t
Definition: field.h:51
Math_Rational::set_parameters
void set_parameters(const Parameters &params)
Definition: math_Rational.cpp:20
afopr_Rational.h
AFopr_Rational::get_parameters
void get_parameters(Parameters &params) const
gets parameters by a Parameter object: to be implemented in a subclass.
Definition: afopr_Rational-tmpl.h:66
ParameterCheck::square_non_zero
int square_non_zero(const double v)
Definition: parameterCheck.cpp:43
threadManager.h
AFopr_Rational
Fermion operator for rational approximation.
Definition: afopr_Rational.h:42
Field::nvol
int nvol() const
Definition: field.h:127
AFopr_Rational::real_t
AFIELD::real_t real_t
Definition: afopr_Rational.h:45
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
AFopr_Rational::set_config
void set_config(Field *U)
sets the gauge configuration.
Definition: afopr_Rational-tmpl.h:129
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
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
commonParameters.h
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Field
Container of Field-type object.
Definition: field.h:46
communicator.h
AShiftsolver_CG
Multishift Conjugate Gradient solver.
Definition: ashiftsolver_CG.h:32
AFopr_Rational::init_parameters
void init_parameters()
Definition: afopr_Rational-tmpl.h:136
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