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