Bridge++  Version 1.4.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  int 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_int("adaptive", adaptive);
73 
74  if (adaptive != 0) { // 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 //====================================================================
93  const int Norder_RK,
94  const double Estep, const int Nprec,
95  const int adaptive,
96  const double tolerance, const double safety)
97 {
98  //- print input parameters
99  vout.general(m_vl, "%s:\n", class_name.c_str());
100  vout.general(m_vl, " Norder_RK = %d\n", Norder_RK);
101  vout.general(m_vl, " Estep = %10.6f\n", Estep);
102  vout.general(m_vl, " Nprec = %d\n", Nprec);
103  vout.general(m_vl, " adaptive = %d\n", adaptive);
104  vout.general(m_vl, " tolerance = %10.6e\n", tolerance);
105  vout.general(m_vl, " safety = %10.6f\n", safety);
106 
107 
108  //- range check
109  int err = 0;
110  err += ParameterCheck::non_negative(Norder_RK);
111  err += ParameterCheck::square_non_zero(Estep);
112  err += ParameterCheck::non_negative(Nprec);
113  err += ParameterCheck::non_negative(tolerance);
114  err += ParameterCheck::non_negative(safety);
115 
116  if (err) {
117  vout.crucial(m_vl, "Error at %s: parameter range check failed\n", class_name.c_str());
118  exit(EXIT_FAILURE);
119  }
120 
121  //- store values
122  m_Norder_RK = Norder_RK; // order of Runge-Kutta
123  m_Estep = Estep; // step size (SA)
124  m_Nprec = Nprec; // order of approximation for e^{iP} (SA)
125 
126  m_is_adaptive = (adaptive == 0) ? false : true;
127  m_tolerance = tolerance;
128  m_safety = safety;
129 
131 }
132 
133 
134 //====================================================================
135 void GradientFlow::set_parameter_Norder_RK(const int Norder_RK, bool is_adaptive)
136 {
137  m_Norder_RK = Norder_RK;
138 
139  switch (Norder_RK)
140  {
141  case 1:
143  break;
144 
145  case 2:
147  break;
148 
149  case 3:
151  break;
152 
153  case 4:
155  break;
156 
157  default:
158  vout.crucial(m_vl, "Error at %s: order of Runge-Kutta is out of range\n", class_name.c_str());
159  exit(EXIT_FAILURE);
160  }
161 
162  if (is_adaptive) {
164  }
165 }
166 
167 
168 //====================================================================
169 double GradientFlow::evolve(double& t, Field_G& U)
170 {
171  double plaq = m_staple.plaquette(U);
172 
173  vout.general(m_vl, "\n");
174  vout.general(m_vl, " plaq_org = %.16f\n", plaq); // write-out
175 
176  //- time evolution (SA)
177  m_impl->flow(t, m_Estep, U);
178 
179  plaq = m_staple.plaquette(U);
180 
181  vout.general(m_vl, " (t, plaq) = %.8f %.16f\n", t, plaq);
182 
183  return t * t * 36.0 * (1.0 - plaq);
184 }
185 
186 
187 //====================================================================
188 //============================================================END=====
static const std::string class_name
Definition: gradientFlow.h:49
double m_Estep
Definition: gradientFlow.h:56
BridgeIO vout
Definition: bridgeIO.cpp:495
Action * m_action
Definition: gradientFlow.h:62
void general(const char *format,...)
Definition: bridgeIO.cpp:195
double evolve(double &t, Field_G &U)
int fetch_double(const string &key, double &value) const
Definition: parameters.cpp:211
double plaquette(const Field_G &)
calculates plaquette value.
Definition: staple_lex.cpp:46
GradientFlow_AdaptiveRungeKutta construction.
GradientFlow_RungeKutta_2nd construction.
GradientFlow(Action *action)
Class for parameters.
Definition: parameters.h:46
GradientFlow_RungeKutta * m_impl
Definition: gradientFlow.h:65
Base class of HMC action class family.
Definition: action.h:36
GradientFlow_RungeKutta_4th construction.
int square_non_zero(const double v)
Definition: checker.cpp:41
GradientFlow_RungeKutta_3rd construction.
double m_tolerance
Definition: gradientFlow.h:58
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:230
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:52
int non_negative(const int v)
Definition: checker.cpp:21
bool m_is_adaptive
Definition: gradientFlow.h:60
double m_safety
Definition: gradientFlow.h:59
string get_string(const string &key) const
Definition: parameters.cpp:116
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:63