Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
force_F_Rational.cpp
Go to the documentation of this file.
1 
14 #include "force_F_Rational.h"
15 
16 const std::string Force_F_Rational::class_name = "Force_F_Rational";
17 
18 //====================================================================
20 {
21  const string str_vlevel = params.get_string("verbose_level");
22 
23  m_vl = vout.set_verbose_level(str_vlevel);
24 
25  //- fetch and check input parameters
26  int Np, n_exp, d_exp;
27  double x_min, x_max;
28  int Niter;
29  double Stop_cond;
30 
31  int err = 0;
32  err += params.fetch_int("number_of_poles", Np);
33  err += params.fetch_int("exponent_numerator", n_exp);
34  err += params.fetch_int("exponent_denominator", d_exp);
35  err += params.fetch_double("lower_bound", x_min);
36  err += params.fetch_double("upper_bound", x_max);
37  err += params.fetch_int("maximum_number_of_iteration", Niter);
38  err += params.fetch_double("convergence_criterion_squared", Stop_cond);
39 
40  if (err) {
41  vout.crucial(m_vl, "Error at %s: input parameter not found.\n", class_name.c_str());
42  exit(EXIT_FAILURE);
43  }
44 
45 
46  set_parameters(Np, n_exp, d_exp, x_min, x_max, Niter, Stop_cond);
47 }
48 
49 
50 //====================================================================
51 void Force_F_Rational::set_parameters(const int Np, const int n_exp, const int d_exp,
52  const double x_min, const double x_max,
53  const int Niter, const double Stop_cond)
54 {
55  //- print input parameters
56  vout.general(m_vl, "%s:\n", class_name.c_str());
57  vout.general(m_vl, " Np = %d\n", Np);
58  vout.general(m_vl, " n_exp = %d\n", n_exp);
59  vout.general(m_vl, " d_exp = %d\n", d_exp);
60  vout.general(m_vl, " x_min = %12.8f\n", x_min);
61  vout.general(m_vl, " x_max = %12.8f\n", x_max);
62  vout.general(m_vl, " Niter = %d\n", Niter);
63  vout.general(m_vl, " Stop_cond = %8.2e\n", Stop_cond);
64 
65  //- range check
66  int err = 0;
67  err += ParameterCheck::non_zero(Np);
68  err += ParameterCheck::non_zero(n_exp);
69  err += ParameterCheck::non_zero(d_exp);
70  // NB. x_min,x_max=0 is allowed.
71  err += ParameterCheck::non_zero(Niter);
72  err += ParameterCheck::square_non_zero(Stop_cond);
73 
74  if (err) {
75  vout.crucial(m_vl, "Error at %s: parameter range check failed.\n", class_name.c_str());
76  exit(EXIT_FAILURE);
77  }
78 
79  //- store values
80  m_Np = Np;
81  m_n_exp = n_exp;
82  m_d_exp = d_exp;
83  m_x_min = x_min;
84  m_x_max = x_max;
85  m_Niter = Niter;
86  m_Stop_cond = Stop_cond;
87 
88  //- post-process
89  m_cl.resize(m_Np);
90  m_bl.resize(m_Np);
91 
92  //- Rational approximation
93  const double x_min2 = m_x_min * m_x_min;
94  const double x_max2 = m_x_max * m_x_max;
95 
96  Math_Rational rational;
97  rational.set_parameters(m_Np, m_n_exp, m_d_exp, x_min2, x_max2);
98  rational.get_parameters(m_a0, m_bl, m_cl);
99 
100  vout.general(m_vl, " a0 = %18.14f\n", m_a0);
101  for (int i = 0; i < m_Np; i++) {
102  vout.general(m_vl, " bl[%d] = %18.14f cl[%d] = %18.14f\n",
103  i, m_bl[i], i, m_cl[i]);
104  }
105 }
106 
107 
108 //====================================================================
109 void Force_F_Rational::force_udiv(Field& force_, const Field& eta_)
110 {
111  const int Nvol = CommonParameters::Nvol();
112  const int Ndim = CommonParameters::Ndim();
113 
114  Field_G force(Nvol, Ndim);
115  Field_F eta(eta_);
116 
117  force_udiv_impl(force, eta);
118 
119  copy(force_, force); // force_ = force;
120 }
121 
122 
123 //====================================================================
125 {
126  const int Nvol = CommonParameters::Nvol();
127  const int Ndim = CommonParameters::Ndim();
128 
129  const int NinF = eta.nin();
130  const int NvolF = eta.nvol();
131  const int NexF = eta.nex();
132 
133  //- Shiftsolver
134  const int Nshift = m_Np;
135 
136  std::vector<Field> psi(Nshift);
137 
138  for (int i = 0; i < Nshift; ++i) {
139  psi[i].reset(NinF, NvolF, NexF);
140  }
141 
142  vout.general(m_vl, " Shift solver in force calculation\n");
143  vout.general(m_vl, " Number of shift values = %d\n", m_cl.size());
144  m_fopr->set_mode("DdagD");
145 
147  int Nconv;
148  double diff;
149  solver->solve(psi, m_cl, eta, Nconv, diff);
150  vout.general(m_vl, " diff(max) = %22.15e \n", diff);
151 
152  force.set(0.0);
153 
154  for (int i = 0; i < Nshift; ++i) {
155  Field_G force1(Nvol, Ndim);
156  m_force->force_udiv(force1, psi[i]);
157  scal(force1, m_bl[i]); // force1 *= m_bl[i];
158  axpy(force, 1.0, force1); // force += force1;
159  }
160 }
161 
162 
163 //====================================================================
165 {
166  vout.crucial(m_vl, "Error at %s: not implemented.\n", __func__);
167  exit(EXIT_FAILURE);
168 }
169 
170 
171 //====================================================================
173 {
174  vout.crucial(m_vl, "Error at %s: not implemented.\n", __func__);
175  exit(EXIT_FAILURE);
176 }
177 
178 
179 //====================================================================
180 //===========================================================END======
void scal(Field &x, const double a)
scal(x, a): x = a * x
Definition: field.cpp:433
void get_parameters(double &norm, std::vector< double > &res, std::vector< double > &pole)
BridgeIO vout
Definition: bridgeIO.cpp:503
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:175
void general(const char *format,...)
Definition: bridgeIO.cpp:197
Bridge::VerboseLevel m_vl
Definition: force_F.h:69
void set_parameters(const Parameters &params)
virtual void set_mode(const std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: fopr.h:94
int solver(const std::string &)
Container of Field-type object.
Definition: field.h:45
int fetch_double(const string &key, double &value) const
Definition: parameters.cpp:327
std::vector< double > m_bl
int nvol() const
Definition: field.h:127
Multishift Conjugate Gradient solver.
Class for parameters.
Definition: parameters.h:46
void copy(Field &y, const Field &x)
copy(y, x): y = x
Definition: field.cpp:532
std::vector< double > m_cl
Wilson-type fermion field.
Definition: field_F.h:37
Determionation of coefficients of rational approximation.
Definition: math_Rational.h:40
int square_non_zero(const double v)
int nin() const
Definition: field.h:126
SU(N) gauge field.
Definition: field_G.h:38
int fetch_int(const string &key, int &value) const
Definition: parameters.cpp:346
void force_core1(Field &, const Field &, const Field &)
static const std::string class_name
int nex() const
Definition: field.h:128
void force_udiv_impl(Field_G &, const Field_F &)
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:319
virtual void force_udiv(Field &, const Field &)
Definition: force_F.h:61
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
void force_udiv1(Field &, const Field &, const Field &)
int non_zero(const double v)
void force_udiv(Field &, const Field &)
void set_parameters(const Parameters &params)
string get_string(const string &key) const
Definition: parameters.cpp:221
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)