Bridge++  Ver. 1.3.x
action_F_Rational.cpp
Go to the documentation of this file.
1 
14 #include "action_F_Rational.h"
15 
16 #ifdef USE_PARAMETERS_FACTORY
17 #include "parameters_factory.h"
18 #endif
19 
20 //- parameter entries
21 namespace {
22  void append_entry(Parameters& param)
23  {
24  param.Register_int("Np", 0);
25  param.Register_int("n_exp", 0);
26  param.Register_int("d_exp", 0);
27  param.Register_double("x_min", 0.0);
28  param.Register_double("x_max", 0.0);
29  param.Register_int("Niter", 0);
30  param.Register_double("Stop_cond", 0.0);
31 
32  param.Register_string("verbose_level", "NULL");
33  }
34 
35 
36 #ifdef USE_PARAMETERS_FACTORY
37  bool init_param = ParametersFactory::Register("Action.F_Rational", append_entry);
38 #endif
39 }
40 //- end
41 
42 //- parameters class
44 //- end
45 
46 const std::string Action_F_Rational::class_name = "Action_F_Rational";
47 
48 //====================================================================
50 {
51  const string str_vlevel = params.get_string("verbose_level");
52 
53  m_vl = vout.set_verbose_level(str_vlevel);
54 
55  //- fetch and check input parameters
56  int Np, n_exp, d_exp;
57  double x_min, x_max;
58  int Niter;
59  double Stop_cond;
60 
61  int err = 0;
62  err += params.fetch_int("Np", Np);
63  err += params.fetch_int("n_exp", n_exp);
64  err += params.fetch_int("d_exp", d_exp);
65  err += params.fetch_double("x_min", x_min);
66  err += params.fetch_double("x_max", x_max);
67  err += params.fetch_int("Niter", Niter);
68  err += params.fetch_double("Stop_cond", Stop_cond);
69 
70  if (err) {
71  vout.crucial(m_vl, "%s: fetch error, input parameter not found.\n", class_name.c_str());
72  exit(EXIT_FAILURE);
73  }
74 
75 
76  set_parameters(Np, n_exp, d_exp, x_min, x_max, Niter, Stop_cond);
77 }
78 
79 
80 //====================================================================
81 void Action_F_Rational::set_parameters(int Np, int n_exp, int d_exp,
82  double x_min, double x_max,
83  int Niter, double Stop_cond)
84 {
85  //- print input parameters
86  vout.general(m_vl, "%s:\n", class_name.c_str());
87  vout.general(m_vl, " Np = %4d\n", Np);
88  vout.general(m_vl, " n_exp = %4d\n", n_exp);
89  vout.general(m_vl, " d_exp = %4d\n", d_exp);
90  vout.general(m_vl, " x_min = %8.4f\n", x_min);
91  vout.general(m_vl, " x_max = %8.4f\n", x_max);
92  vout.general(m_vl, " Niter = %6d\n", Niter);
93  vout.general(m_vl, " Stop_cond = %8.2e\n", Stop_cond);
94 
95  //- range check
96  int err = 0;
97  err += ParameterCheck::non_zero(Np);
98  err += ParameterCheck::non_zero(n_exp);
99  err += ParameterCheck::non_zero(d_exp);
100  // NB. x_min,x_max == 0 is allowed.
101  err += ParameterCheck::non_negative(Niter);
102  err += ParameterCheck::square_non_zero(Stop_cond);
103 
104  if (err) {
105  vout.crucial(m_vl, "%s: parameter range check failed.\n", class_name.c_str());
106  exit(EXIT_FAILURE);
107  }
108 
109  //- store values
110  m_Np = Np;
111  m_n_exp = n_exp;
112  m_d_exp = d_exp;
113  m_x_min = x_min;
114  m_x_max = x_max;
115  m_Niter = Niter;
116  m_Stop_cond = Stop_cond;
117 
118  //- post-process
119  setup();
120 }
121 
122 
123 //====================================================================
125 {
126  int Nc = CommonParameters::Nc();
127  int Nvol = CommonParameters::Nvol();
128  int Ndim = CommonParameters::Ndim();
129  int NinG = 2 * Nc * Nc;
130 
131  // rational operator for Langevin step.
133  int d_exp2 = 2 * m_d_exp;
136 
137  // rational operator for Hamiltonian calculation.
139  int n_expm = -m_n_exp;
142 
143  // force of rational operator
147 }
148 
149 
150 //====================================================================
152 {
153  delete m_force_rational;
154  delete m_fopr_H;
155  delete m_fopr_langev;
156 }
157 
158 
159 //====================================================================
161 {
162  int NinF = m_fopr->field_nin();
163  int NvolF = m_fopr->field_nvol();
164  int NexF = m_fopr->field_nex();
165  int size_psf = NinF * NvolF * NexF * CommonParameters::NPE();
166 
167  m_psf.reset(NinF, NvolF, NexF);
168 
169  vout.general(m_vl, " %s: %s\n", class_name.c_str(), m_label.c_str());
170 
171  Field xi(NinF, NvolF, NexF);
172  rand->gauss_lex_global(xi);
173 
175  //m_psf = m_fopr_langev->mult(xi);
176  m_fopr_langev->mult(m_psf, xi);
177 
178  double xi2 = xi.norm();
179  double H_psf = xi2 * xi2;
180 
181  vout.general(m_vl, " H_Frational = %18.8f\n", H_psf);
182  vout.general(m_vl, " H_F/dof = %18.8f\n", H_psf / size_psf);
183 
184  return H_psf;
185 }
186 
187 
188 //====================================================================
190 {
191  int NinF = m_fopr->field_nin();
192  int NvolF = m_fopr->field_nvol();
193  int NexF = m_fopr->field_nex();
194  int size_psf = NinF * NvolF * NexF * CommonParameters::NPE();
195 
196  Field v1(NinF, NvolF, NexF);
197 
198  vout.general(m_vl, " %s: %s\n", class_name.c_str(), m_label.c_str());
199 
201  m_fopr_H->mult(v1, m_psf);
202 
203  double H_psf = dot(v1, m_psf);
204 
205  vout.general(m_vl, " H_Frational = %18.8f\n", H_psf);
206  vout.general(m_vl, " H_F/dof = %18.8f\n", H_psf / size_psf);
207 
208  return H_psf;
209 }
210 
211 
212 //====================================================================
214 {
215  int Nvol = m_U->nvol();
216  int Nex = m_U->nex();
217 
218  Field_G force(Nvol, Nex), force1(Nvol, Nex);
219 
220  vout.general(m_vl, " %s: %s\n", class_name.c_str(), m_label.c_str());
221 
224 
225  double Fave, Fmax, Fdev;
226  force.stat(Fave, Fmax, Fdev);
227  vout.general(m_vl, " Frational_ave = %12.6f Frational_max = %12.6f Frational_dev = %12.6f\n",
228  Fave, Fmax, Fdev);
229 
230  return force;
231 }
232 
233 
234 //====================================================================
235 //============================================================END=====
Fermion operator for rational approximation.
Definition: fopr_Rational.h:48
BridgeIO vout
Definition: bridgeIO.cpp:278
void Register_string(const string &, const string &)
Definition: parameters.cpp:351
static const std::string class_name
double dot(const Field &y, const Field &x)
Definition: field.cpp:46
void general(const char *format,...)
Definition: bridgeIO.cpp:65
void Register_int(const string &, const int)
Definition: parameters.cpp:330
Container of Field-type object.
Definition: field.h:39
int nvol() const
Definition: field.h:116
Class for parameters.
Definition: parameters.h:38
const Field force()
returns the force for updating conjugate momentum.
void mult(Field &v, const Field &f)
multiplies fermion operator to a given field (2nd argument)
double calcH()
calculation of Hamiltonian.
virtual void gauss_lex_global(Field &)
gaussian random number defined on global lattice.
virtual int field_nin()=0
returns the on-site d.o.f. for which the fermion operator is defined.
int square_non_zero(const double v)
Definition: checker.cpp:41
Fopr_Rational * m_fopr_H
SU(N) gauge field.
Definition: field_G.h:38
void reset(const int Nin, const int Nvol, const int Nex, const element_type cmpl=COMPLEX)
Definition: field.h:84
double norm() const
Definition: field.h:240
void set_config(Field *U)
setting pointer to the gauge configuration.
Definition: fopr_Rational.h:84
void set_config(Field *U)
virtual int field_nex()=0
returns the external d.o.f. for which the fermion operator is defined.
int nex() const
Definition: field.h:117
virtual void force_core(Field &, const Field &)
Definition: force.cpp:19
void tidyup()
destruct class instances constructed in setup()
void crucial(const char *format,...)
Definition: bridgeIO.cpp:48
double langevin(RandomNumbers *)
Langevin step called at the beginning of HMC.
void set_parameters(const Parameters &params)
setting parameters and creating class instances.
static bool Register(const std::string &realm, const creator_callback &cb)
Bridge::VerboseLevel m_vl
Definition: action.h:81
Base class of random number generators.
Definition: randomNumbers.h:39
void set_parameters(const Parameters &params)
void setup()
creating instances. called from set_parameters().
int non_zero(const double v)
Definition: checker.cpp:31
Fopr_Rational * m_fopr_langev
void stat(double &Fave, double &Fmax, double &Fdev) const
determines the statistics of the field. average, maximum value, and deviation is determined over glob...
Definition: field.cpp:516
int non_negative(const int v)
Definition: checker.cpp:21
void Register_double(const string &, const double)
Definition: parameters.cpp:323
int fetch_double(const string &key, double &val) const
Definition: parameters.cpp:124
void set_parameters(const Parameters &params)
string get_string(const string &key) const
Definition: parameters.cpp:87
virtual int field_nvol()=0
returns the volume for which the fermion operator is defined.
Force_F_Rational * m_force_rational
int fetch_int(const string &key, int &val) const
Definition: parameters.cpp:141
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:28
static int NPE()