Bridge++  Ver. 2.0.2
fprop_Wilson_Shift.cpp
Go to the documentation of this file.
1 
14 #include "fprop_Wilson_Shift.h"
15 
16 const std::string Fprop_Wilson_Shift::class_name = "Fprop_Wilson_Shift";
17 
18 //====================================================================
20 {
21  std::string vlevel;
22  if (!params.fetch_string("verbose_level", vlevel)) {
23  m_vl = vout.set_verbose_level(vlevel);
24  }
25 
26  //- fetch and check input parameters
27  int Nshift;
28  std::vector<double> sigma;
29  int Niter;
30  double Stop_cond;
31 
32  int err = 0;
33  err += params.fetch_int("number_of_shifts", Nshift);
34  err += params.fetch_double_vector("shifted_mass_difference", sigma);
35  err += params.fetch_int("maximum_number_of_iteration", Niter);
36  err += params.fetch_double("convergence_criterion_squared", Stop_cond);
37 
38  if (err) {
39  vout.crucial(m_vl, "Error at %s: input parameter not found.\n", class_name.c_str());
40  exit(EXIT_FAILURE);
41  }
42 
43 
44  set_parameters(Nshift, sigma, Niter, Stop_cond);
45 }
46 
47 
48 //====================================================================
50 {
51  params.set_int("number_of_shifts", m_Nshift);
52  params.set_double_vector("shifted_mass_difference", m_sigma);
53  params.set_int("maximum_number_of_iteration", m_Niter);
54  params.set_double("convergence_criterion_squared", m_Stop_cond);
55 
56  params.set_string("verbose_level", vout.get_verbose_level(m_vl));
57 }
58 
59 
60 //====================================================================
61 void Fprop_Wilson_Shift::set_parameters(const int Nshift, const std::vector<double> sigma,
62  const int Niter, const double Stop_cond)
63 {
64  //- print input parameters
65  vout.general(m_vl, "%s:\n", class_name.c_str());
66  vout.general(m_vl, " Nshift = %d\n", Nshift);
67  for (int i = 0; i < Nshift; ++i) {
68  vout.general(m_vl, " sigma[%d] = %16.8e\n", i, sigma[i]);
69  }
70  vout.general(m_vl, " Niter = %d\n", Niter);
71  vout.general(m_vl, " Stop_cond = %8.2e\n", Stop_cond);
72 
73  //- range check
74  // NB. Nshift,sigma == 0 is allowed.
75  int err = 0;
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_Nshift = Nshift;
86  m_sigma.resize(Nshift);
87  m_sigma = sigma;
88 
89  m_Niter = Niter;
90  m_Stop_cond = Stop_cond;
91 }
92 
93 
94 //====================================================================
95 double Fprop_Wilson_Shift::invert_D(std::vector<Field_F> *xq2, const Field_F& b)
96 {
97  const int Nin = b.nin();
98  const int Nvol = b.nvol();
99  const int Nex = b.nex();
100 
101  const int Nshift = m_Nshift;
102 
103  std::vector<double> sigma = m_sigma;
104 
105  std::vector<Field> xq(Nshift);
106 
107  for (int i = 0; i < Nshift; ++i) {
108  xq[i].reset(Nin, Nvol, Nex);
109  }
110 
111  int Nconv = 0;
112  double diff = 1.0;
113 
114 
115  // vout.general(m_vl, "size of xq = %d\n", xq->size());
116  // vout.general(m_vl, "size of xq[0] = %d\n", xq[0].nvol());
117 
118  vout.general(m_vl, "%s:\n", class_name.c_str());
119  vout.general(m_vl, " Number of shift values = %d\n", sigma.size());
120  assert(xq2->size() == sigma.size());
121 
122  m_fopr->set_mode("DdagD");
123 
124  // std::vector<Field_F>* xq2 = new std::vector<Field_F>;
125 
126  /*
127  std::vector<Field_F>* xq2;
128  xq2->resize(xq->size());
129  for(int i=0; i<xq->size(); ++i){
130  xq2[i] = (Field*) xq[i];
131  }
132  */
133 
135  solver.solve(xq, sigma, (Field)b, Nconv, diff);
136 
137  vout.general(m_vl, " residues of solutions(2):\n");
138 
139  // Field version: works
140  Field s((Field)b);
141  Field x((Field)b);
142  Field t((Field)b);
143 
144  double diff1 = 1.0; // superficial initialization
145  for (int i = 0; i < Nshift; ++i) {
146  x = xq[i];
147  double sg = sigma[i];
148  m_fopr->mult(s, x);
149  axpy(s, sg, x);
150  axpy(s, -1.0, t);
151  diff1 = dot(s, s);
152 
153  vout.general(m_vl, "i_shift,diff = %6d %22.15e\n", i, diff1);
154  }
155 
156  for (int i = 0; i < Nshift; ++i) {
157  (*xq2)[i] = (Field_F)xq[i];
158  }
159 
160  const double result = diff1;
161 
162  return result;
163 }
Fprop_Wilson_Shift::invert_D
double invert_D(std::vector< Field_F > *, const Field_F &)
Definition: fprop_Wilson_Shift.cpp:95
Org::Fopr_Wilson::set_mode
void set_mode(const std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: fopr_Wilson_impl.cpp:200
Parameters::set_string
void set_string(const string &key, const string &value)
Definition: parameters.cpp:39
Parameters
Class for parameters.
Definition: parameters.h:46
Parameters::set_double
void set_double(const string &key, const double value)
Definition: parameters.cpp:33
Fprop_Wilson_Shift::m_Stop_cond
double m_Stop_cond
Definition: fprop_Wilson_Shift.h:50
Field::nex
int nex() const
Definition: field.h:128
Fprop_Wilson_Shift::m_Niter
int m_Niter
Definition: fprop_Wilson_Shift.h:49
axpy
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:380
dot
double dot(const Field &y, const Field &x)
Definition: field.cpp:576
Parameters::set_double_vector
void set_double_vector(const string &key, const vector< double > &value)
Definition: parameters.cpp:42
Field::nin
int nin() const
Definition: field.h:126
Fprop_Wilson_Shift::m_Nshift
int m_Nshift
Definition: fprop_Wilson_Shift.h:52
Fprop_Wilson_Shift::m_fopr
Fopr_Wilson * m_fopr
Definition: fprop_Wilson_Shift.h:46
fprop_Wilson_Shift.h
ParameterCheck::square_non_zero
int square_non_zero(const double v)
Definition: parameterCheck.cpp:43
Org::Fopr_Wilson::mult
void mult(Field &v, const Field &w)
multiplies fermion operator to a given field.
Definition: fopr_Wilson_impl.cpp:210
Field::nvol
int nvol() const
Definition: field.h:127
Test_Solver_Wilson::solver
int solver(const std::string &)
Definition: test_Solver_Wilson.cpp:134
Fprop_Wilson_Shift::m_sigma
std::vector< double > m_sigma
Definition: fprop_Wilson_Shift.h:53
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
Parameters::set_int
void set_int(const string &key, const int value)
Definition: parameters.cpp:36
Parameters::fetch_string
int fetch_string(const string &key, string &value) const
Definition: parameters.cpp:378
Field_F
Wilson-type fermion field.
Definition: field_F.h:37
Parameters::fetch_double
int fetch_double(const string &key, double &value) const
Definition: parameters.cpp:327
Fprop_Wilson_Shift::m_vl
Bridge::VerboseLevel m_vl
Definition: fprop_Wilson_Shift.h:43
Fprop_Wilson_Shift::set_parameters
void set_parameters(const Parameters &params)
Definition: fprop_Wilson_Shift.cpp:19
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Field
Container of Field-type object.
Definition: field.h:46
AShiftsolver_CG
Multishift Conjugate Gradient solver.
Definition: ashiftsolver_CG.h:32
Parameters::fetch_double_vector
int fetch_double_vector(const string &key, vector< double > &value) const
Definition: parameters.cpp:410
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
Fprop_Wilson_Shift::get_parameters
void get_parameters(Parameters &params) const
Definition: fprop_Wilson_Shift.cpp:49
Fprop_Wilson_Shift::class_name
static const std::string class_name
Definition: fprop_Wilson_Shift.h:40
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