Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  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 Nshift;
27  std::vector<double> sigma;
28  int Niter;
29  double Stop_cond;
30 
31  int err = 0;
32  err += params.fetch_int("number_of_shifts", Nshift);
33  err += params.fetch_double_vector("shifted_mass_difference", sigma);
34  err += params.fetch_int("maximum_number_of_iteration", Niter);
35  err += params.fetch_double("convergence_criterion_squared", Stop_cond);
36 
37  if (err) {
38  vout.crucial(m_vl, "Error at %s: input parameter not found.\n", class_name.c_str());
39  exit(EXIT_FAILURE);
40  }
41 
42 
43  set_parameters(Nshift, sigma, Niter, Stop_cond);
44 }
45 
46 
47 //====================================================================
48 void Fprop_Wilson_Shift::set_parameters(const int Nshift, const std::vector<double> sigma,
49  const int Niter, const double Stop_cond)
50 {
51  //- print input parameters
52  vout.general(m_vl, "%s:\n", class_name.c_str());
53  vout.general(m_vl, " Nshift = %d\n", Nshift);
54  for (int i = 0; i < Nshift; ++i) {
55  vout.general(m_vl, " sigma[%d] = %16.8e\n", i, sigma[i]);
56  }
57  vout.general(m_vl, " Niter = %d\n", Niter);
58  vout.general(m_vl, " Stop_cond = %8.2e\n", Stop_cond);
59 
60  //- range check
61  // NB. Nshift,sigma == 0 is allowed.
62  int err = 0;
63  err += ParameterCheck::non_zero(Niter);
64  err += ParameterCheck::square_non_zero(Stop_cond);
65 
66  if (err) {
67  vout.crucial(m_vl, "Error at %s: parameter range check failed.\n", class_name.c_str());
68  exit(EXIT_FAILURE);
69  }
70 
71  //- store values
72  m_Nshift = Nshift;
73  m_sigma.resize(Nshift);
74  m_sigma = sigma;
75 
76  m_Niter = Niter;
77  m_Stop_cond = Stop_cond;
78 }
79 
80 
81 //====================================================================
82 double Fprop_Wilson_Shift::invert_D(std::vector<Field_F> *xq2, const Field_F& b)
83 {
84  const int Nin = b.nin();
85  const int Nvol = b.nvol();
86  const int Nex = b.nex();
87 
88  const int Nshift = m_Nshift;
89 
90  std::vector<double> sigma = m_sigma;
91 
92  std::vector<Field> xq(Nshift);
93 
94  for (int i = 0; i < Nshift; ++i) {
95  xq[i].reset(Nin, Nvol, Nex);
96  }
97 
98  int Nconv = 0;
99  double diff = 1.0;
100 
101 
102  // vout.general(m_vl, "size of xq = %d\n", xq->size());
103  // vout.general(m_vl, "size of xq[0] = %d\n", xq[0].nvol());
104 
105  vout.general(m_vl, "%s:\n", class_name.c_str());
106  vout.general(m_vl, " Number of shift values = %d\n", sigma.size());
107  assert(xq2->size() == sigma.size());
108 
109  m_fopr->set_mode("DdagD");
110 
111  // std::vector<Field_F>* xq2 = new std::vector<Field_F>;
112 
113  /*
114  std::vector<Field_F>* xq2;
115  xq2->resize(xq->size());
116  for(int i=0; i<xq->size(); ++i){
117  xq2[i] = (Field*) xq[i];
118  }
119  */
120 
122  solver->solve(xq, sigma, (Field)b, Nconv, diff);
123 
124  vout.general(m_vl, " residues of solutions(2):\n");
125 
126  // Field version: works
127  Field s((Field)b);
128  Field x((Field)b);
129  Field t((Field)b);
130 
131  double diff1 = 1.0; // superficial initialization
132  for (int i = 0; i < Nshift; ++i) {
133  x = xq[i];
134  double sg = sigma[i];
135  m_fopr->mult(s, x);
136  axpy(s, sg, x);
137  axpy(s, -1.0, t);
138  diff1 = dot(s, s);
139 
140  vout.general(m_vl, "i_shift,diff = %6d %22.15e\n", i, diff1);
141  }
142 
143  for (int i = 0; i < Nshift; ++i) {
144  (*xq2)[i] = (Field_F)xq[i];
145  }
146 
147  const double result = diff1;
148 
149  return result;
150 }
BridgeIO vout
Definition: bridgeIO.cpp:503
int fetch_double_vector(const string &key, vector< double > &value) const
Definition: parameters.cpp:410
double dot(const Field &y, const Field &x)
Definition: field.cpp:46
void general(const char *format,...)
Definition: bridgeIO.cpp:197
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
int nvol() const
Definition: field.h:127
Multishift Conjugate Gradient solver.
static const std::string class_name
Class for parameters.
Definition: parameters.h:46
Wilson-type fermion field.
Definition: field_F.h:37
int square_non_zero(const double v)
int nin() const
Definition: field.h:126
std::vector< double > m_sigma
int fetch_int(const string &key, int &value) const
Definition: parameters.cpp:346
int nex() const
Definition: field.h:128
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:319
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
int non_zero(const double v)
Bridge::VerboseLevel m_vl
void mult(Field &v, const Field &f)
multiplies fermion operator to a given field (2nd argument)
void set_parameters(const Parameters &params)
double invert_D(std::vector< Field_F > *, const Field_F &)
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)
void set_mode(const std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...