Bridge++  Ver. 1.2.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  abort();
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  abort();
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  m_force.reset(NinG, Nvol, Ndim);
132 
133  // rational operator for Langevin step.
135  int d_exp2 = 2 * m_d_exp;
138 
139  // rational operator for Hamiltonian calculation.
141  int n_expm = -m_n_exp;
144 
145  // force of rational operator
149 
150  // link variable update flag
151  m_status_linkv = 0;
152 }
153 
154 
155 //====================================================================
157 {
158  delete m_force_rational;
159  delete m_fopr_H;
160  delete m_fopr_langev;
161 }
162 
163 
164 //====================================================================
166 {
167  int NinF = m_fopr->field_nin();
168  int NvolF = m_fopr->field_nvol();
169  int NexF = m_fopr->field_nex();
170  int size_psf = NinF * NvolF * NexF * CommonParameters::NPE();
171 
172  m_psf.reset(NinF, NvolF, NexF);
173 
174  vout.general(m_vl, " %s: %s\n", class_name.c_str(), m_label.c_str());
175 
176  Field xi(NinF, NvolF, NexF);
177  rand->gauss_lex_global(xi);
178 
180  m_psf = m_fopr_langev->mult(xi);
181 
182  double xi2 = xi.norm();
183  double H_psf = xi2 * xi2;
184 
185  vout.general(m_vl, " H_Frational = %18.8f\n", H_psf);
186  vout.general(m_vl, " H_F/dof = %18.8f\n", H_psf / size_psf);
187 
188  return H_psf;
189 }
190 
191 
192 //====================================================================
194 {
195  int NinF = m_fopr->field_nin();
196  int NvolF = m_fopr->field_nvol();
197  int NexF = m_fopr->field_nex();
198  int size_psf = NinF * NvolF * NexF * CommonParameters::NPE();
199 
200  Field v1(NinF, NvolF, NexF);
201 
202  vout.general(m_vl, " %s: %s\n", class_name.c_str(), m_label.c_str());
203 
205  v1 = m_fopr_H->mult(m_psf);
206 
207  double H_psf = v1 * m_psf;
208 
209  vout.general(m_vl, " H_Frational = %18.8f\n", H_psf);
210  vout.general(m_vl, " H_F/dof = %18.8f\n", H_psf / size_psf);
211 
212  return H_psf;
213 }
214 
215 
216 //====================================================================
218 {
219  if (m_status_linkv == 0) {
220  int Nvol = m_U->nvol();
221  int Nex = m_U->nex();
222 
223  Field_G force(Nvol, Nex), force1(Nvol, Nex);
224 
225  vout.general(m_vl, " %s: %s\n", class_name.c_str(), m_label.c_str());
226 
229 
230  m_force = (Field)force;
231  ++m_status_linkv;
232 
233  double Fave, Fmax, Fdev;
234  m_force.stat(Fave, Fmax, Fdev);
235  vout.general(m_vl, " Frational_ave = %12.6f Frational_max = %12.6f Frational_dev = %12.6f\n",
236  Fave, Fmax, Fdev);
237 
238  return m_force;
239  } else {
240  vout.general(m_vl, " %s returns previous force.\n", class_name.c_str());
241  return m_force;
242  }
243 }
244 
245 
246 //====================================================================
247 //============================================================END=====
Fermion operator for rational approximation.
Definition: fopr_Rational.h:46
BridgeIO vout
Definition: bridgeIO.cpp:207
void Register_string(const string &, const string &)
Definition: parameters.cpp:352
static const std::string class_name
void general(const char *format,...)
Definition: bridgeIO.cpp:38
void Register_int(const string &, const int)
Definition: parameters.cpp:331
Container of Field-type object.
Definition: field.h:37
int nvol() const
Definition: field.h:101
const Field mult(const Field &f)
multiplies fermion operator to a given field and returns the resultant field.
Class for parameters.
Definition: parameters.h:40
const Field force()
returns the force for updating conjugate momentum.
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:36
void reset(const int Nin, const int Nvol, const int Nex, const element_type cmpl=COMPLEX)
Definition: field.h:82
double norm() const
Definition: field.h:210
void set_config(Field *U)
setting pointer to the gauge configuration.
Definition: fopr_Rational.h:80
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:102
virtual void force_core(Field &, const Field &)
Definition: force.cpp:58
void tidyup()
destruct class instances constructed in setup()
void crucial(const char *format,...)
Definition: bridgeIO.cpp:26
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:64
Base class of random number generators.
Definition: randomNumbers.h:40
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:544
int non_negative(const int v)
Definition: checker.cpp:21
void Register_double(const string &, const double)
Definition: parameters.cpp:324
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:85
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:191
static int NPE()