Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gradientFlow.cpp
Go to the documentation of this file.
1 
14 #include "gradientFlow.h"
15 
16 const std::string GradientFlow::class_name = "GradientFlow";
17 
18 //====================================================================
20  : m_vl(CommonParameters::Vlevel()),
21  m_action(action),
22  m_impl(0)
23 {
24  initialize();
25 }
26 
27 
28 //====================================================================
30  : m_vl(CommonParameters::Vlevel()),
31  m_action(action.get()),
32  m_impl(0)
33 {
34  initialize();
35 }
36 
37 
38 //====================================================================
40 {
41  m_Nprec = 0;
42  m_Estep = 0.0;
43 }
44 
45 
46 //====================================================================
48 {
49  if (m_impl) delete m_impl;
50 }
51 
52 
53 //====================================================================
55 {
56  const string str_vlevel = params.get_string("verbose_level");
57 
58  m_vl = vout.set_verbose_level(str_vlevel);
59 
60  //- fetch and check input parameters
61  int Norder_RK;
62  double Estep;
63  int Nprec;
64  bool adaptive;
65  double tolerance, safety;
66 
67  int err = 0;
68  err += params.fetch_int("order_of_RungeKutta", Norder_RK);
69  err += params.fetch_double("step_size", Estep);
70  err += params.fetch_int("order_of_approx_for_exp_iP", Nprec);
71 
72  err += params.fetch_bool("adaptive", adaptive);
73 
74  if (adaptive) { // mandatory only if adaptive is on.
75  err += params.fetch_double("tolerance", tolerance);
76  err += params.fetch_double("safety_factor", safety);
77  } else {
78  params.fetch_double("tolerance", tolerance);
79  params.fetch_double("safety_factor", safety);
80  }
81 
82  if (err) {
83  vout.crucial(m_vl, "Error at %s: input parameter not found\n", class_name.c_str());
84  exit(EXIT_FAILURE);
85  }
86 
87  set_parameters(Norder_RK, Estep, Nprec, adaptive, tolerance, safety);
88 }
89 
90 
91 //====================================================================
92 void GradientFlow::set_parameters(const int Norder_RK,
93  const double Estep, const int Nprec,
94  const int adaptive,
95  const double tolerance, const double safety)
96 {
97  vout.crucial(m_vl, "%s: warning: integer variable for adaptive is obsolete. use boolean parameter.\n", class_name.c_str());
98 
99  return set_parameters(Norder_RK, Estep, Nprec, ((adaptive == 0) ? false : true), tolerance, safety);
100 }
101 
102 
103 //====================================================================
104 void GradientFlow::set_parameters(const int Norder_RK,
105  const double Estep, const int Nprec,
106  const bool adaptive,
107  const double tolerance, const double safety)
108 {
109  //- print input parameters
110  vout.general(m_vl, "%s:\n", class_name.c_str());
111  vout.general(m_vl, " Norder_RK = %d\n", Norder_RK);
112  vout.general(m_vl, " Estep = %10.6f\n", Estep);
113  vout.general(m_vl, " Nprec = %d\n", Nprec);
114  vout.general(m_vl, " adaptive = %s\n", (adaptive ? "true" : "false"));
115  vout.general(m_vl, " tolerance = %10.6e\n", tolerance);
116  vout.general(m_vl, " safety = %10.6f\n", safety);
117 
118 
119  //- range check
120  int err = 0;
121  err += ParameterCheck::non_negative(Norder_RK);
122  err += ParameterCheck::square_non_zero(Estep);
123  err += ParameterCheck::non_negative(Nprec);
124  err += ParameterCheck::non_negative(tolerance);
125  err += ParameterCheck::non_negative(safety);
126 
127  if (err) {
128  vout.crucial(m_vl, "Error at %s: parameter range check failed\n", class_name.c_str());
129  exit(EXIT_FAILURE);
130  }
131 
132  //- store values
133  m_Norder_RK = Norder_RK; // order of Runge-Kutta
134  m_Estep = Estep; // step size (SA)
135  m_Nprec = Nprec; // order of approximation for e^{iP} (SA)
136 
137  m_is_adaptive = adaptive;
138  m_tolerance = tolerance;
139  m_safety = safety;
140 
142 }
143 
144 
145 //====================================================================
146 void GradientFlow::set_parameter_Norder_RK(const int Norder_RK, bool is_adaptive)
147 {
148  m_Norder_RK = Norder_RK;
149 
150  switch (Norder_RK)
151  {
152  case 1:
154  break;
155 
156  case 2:
158  break;
159 
160  case 3:
162  break;
163 
164  case 4:
166  break;
167 
168  default:
169  vout.crucial(m_vl, "Error at %s: order of Runge-Kutta is out of range\n", class_name.c_str());
170  exit(EXIT_FAILURE);
171  }
172 
173  if (is_adaptive) {
175  }
176 }
177 
178 
179 //====================================================================
180 double GradientFlow::evolve(double& t, Field_G& U)
181 {
182  double plaq = m_staple.plaquette(U);
183 
184  vout.general(m_vl, "\n");
185  vout.general(m_vl, " plaq_org = %.16f\n", plaq); // write-out
186 
187  //- time evolution (SA)
188  m_impl->flow(t, m_Estep, U);
189 
190  plaq = m_staple.plaquette(U);
191 
192  vout.general(m_vl, " (t, plaq) = %.8f %.16f\n", t, plaq);
193 
194  return t * t * 36.0 * (1.0 - plaq);
195 }
196 
197 
198 //====================================================================
199 //============================================================END=====
static const std::string class_name
Definition: gradientFlow.h:50
double m_Estep
Definition: gradientFlow.h:57
BridgeIO vout
Definition: bridgeIO.cpp:503
Action * m_action
Definition: gradientFlow.h:63
int fetch_bool(const string &key, bool &value) const
Definition: parameters.cpp:391
void general(const char *format,...)
Definition: bridgeIO.cpp:197
double evolve(double &t, Field_G &U)
int fetch_double(const string &key, double &value) const
Definition: parameters.cpp:327
double plaquette(const Field_G &)
calculates plaquette value.
Definition: staple_lex.cpp:38
GradientFlow_AdaptiveRungeKutta construction.
GradientFlow_RungeKutta_2nd construction.
GradientFlow(Action *action)
Class for parameters.
Definition: parameters.h:46
GradientFlow_RungeKutta * m_impl
Definition: gradientFlow.h:66
Base class of HMC action class family.
Definition: action.h:36
GradientFlow_RungeKutta_4th construction.
int square_non_zero(const double v)
GradientFlow_RungeKutta_3rd construction.
double m_tolerance
Definition: gradientFlow.h:59
SU(N) gauge field.
Definition: field_G.h:38
void set_parameter_Norder_RK(const int order, const bool is_adaptive)
GradientFlow_RungeKutta_1st construction.
int fetch_int(const string &key, int &value) const
Definition: parameters.cpp:346
Common parameter class: provides parameters as singleton.
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
virtual void flow(double &t, double &Estep, Field_G &U)=0
Bridge::VerboseLevel m_vl
Definition: gradientFlow.h:53
int non_negative(const int v)
bool m_is_adaptive
Definition: gradientFlow.h:61
double m_safety
Definition: gradientFlow.h:60
string get_string(const string &key) const
Definition: parameters.cpp:221
void initialize()
void set_parameters(const Parameters &params)
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
Staple_lex m_staple
Definition: gradientFlow.h:64