Bridge++  Ver. 2.0.2
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),
32  m_impl(0)
33 {
34  initialize();
35  set_parameters(params);
36 }
37 
38 
39 //====================================================================
41 {
42  m_Nprec = 0;
43  m_Estep = 0.0;
44 }
45 
46 
47 //====================================================================
49 {
50  if (m_impl) delete m_impl;
51 }
52 
53 
54 //====================================================================
56 {
57  std::string vlevel;
58  if (!params.fetch_string("verbose_level", vlevel)) {
59  m_vl = vout.set_verbose_level(vlevel);
60  }
61 
62  //- fetch and check input parameters
63  int Norder_RK;
64  double Estep;
65  int Nprec;
66  bool adaptive;
67  double tolerance, safety;
68 
69  int err = 0;
70  err += params.fetch_int("order_of_RungeKutta", Norder_RK);
71  err += params.fetch_double("step_size", Estep);
72  err += params.fetch_int("order_of_approx_for_exp_iP", Nprec);
73 
74  err += params.fetch_bool("adaptive", adaptive);
75 
76  if (adaptive) { // mandatory only if adaptive is on.
77  err += params.fetch_double("tolerance", tolerance);
78  err += params.fetch_double("safety_factor", safety);
79  } else {
80  params.fetch_double("tolerance", tolerance);
81  params.fetch_double("safety_factor", safety);
82  }
83 
84  if (err) {
85  vout.crucial(m_vl, "Error at %s: input parameter not found\n", class_name.c_str());
86  exit(EXIT_FAILURE);
87  }
88 
89  set_parameters(Norder_RK, Estep, Nprec, adaptive, tolerance, safety);
90 }
91 
92 
93 //====================================================================
95 {
96  params.set_int("order_of_RungeKutta", m_Norder_RK);
97  params.set_double("step_size", m_Estep);
98  params.set_int("order_of_approx_for_exp_iP", m_Nprec);
99 
100  params.set_bool("adaptive", m_is_adaptive);
101 
102  if (m_is_adaptive) { // mandatory only if adaptive is on.
103  params.set_double("tolerance", m_tolerance);
104  params.set_double("safety_factor", m_safety);
105  }
106 
107  params.set_string("verbose_level", vout.get_verbose_level(m_vl));
108 }
109 
110 
111 //====================================================================
112 void GradientFlow::set_parameters(const int Norder_RK,
113  const double Estep, const int Nprec,
114  const int adaptive,
115  const double tolerance, const double safety)
116 {
117  vout.crucial(m_vl, "%s: warning: integer variable for adaptive is obsolete. use boolean parameter.\n", class_name.c_str());
118 
119  return set_parameters(Norder_RK, Estep, Nprec, ((adaptive == 0) ? false : true), tolerance, safety);
120 }
121 
122 
123 //====================================================================
124 void GradientFlow::set_parameters(const int Norder_RK,
125  const double Estep, const int Nprec,
126  const bool adaptive,
127  const double tolerance, const double safety)
128 {
129  //- print input parameters
130  vout.general(m_vl, "%s:\n", class_name.c_str());
131  vout.general(m_vl, " Norder_RK = %d\n", Norder_RK);
132  vout.general(m_vl, " Estep = %10.6f\n", Estep);
133  vout.general(m_vl, " Nprec = %d\n", Nprec);
134  vout.general(m_vl, " adaptive = %s\n", (adaptive ? "true" : "false"));
135  vout.general(m_vl, " tolerance = %10.6e\n", tolerance);
136  vout.general(m_vl, " safety = %10.6f\n", safety);
137 
138 
139  //- range check
140  int err = 0;
141  err += ParameterCheck::non_negative(Norder_RK);
142  err += ParameterCheck::square_non_zero(Estep);
143  err += ParameterCheck::non_negative(Nprec);
144  err += ParameterCheck::non_negative(tolerance);
145  err += ParameterCheck::non_negative(safety);
146 
147  if (err) {
148  vout.crucial(m_vl, "Error at %s: parameter range check failed\n", class_name.c_str());
149  exit(EXIT_FAILURE);
150  }
151 
152  //- store values
153  m_Norder_RK = Norder_RK; // order of Runge-Kutta
154  m_Estep = Estep; // step size (SA)
155  m_Nprec = Nprec; // order of approximation for e^{iP} (SA)
156 
157  m_is_adaptive = adaptive;
158  m_tolerance = tolerance;
159  m_safety = safety;
160 
162 }
163 
164 
165 //====================================================================
166 void GradientFlow::set_parameter_Norder_RK(const int Norder_RK, bool is_adaptive)
167 {
168  m_Norder_RK = Norder_RK;
169 
170  switch (Norder_RK)
171  {
172  case 1:
174  break;
175 
176  case 2:
178  break;
179 
180  case 3:
182  break;
183 
184  case 4:
186  break;
187 
188  default:
189  vout.crucial(m_vl, "Error at %s: order of Runge-Kutta is out of range\n", class_name.c_str());
190  exit(EXIT_FAILURE);
191  }
192 
193  if (is_adaptive) {
195  }
196 }
197 
198 
199 //====================================================================
200 double GradientFlow::evolve(double& t, Field_G& U)
201 {
202  double plaq = m_staple.plaquette(U);
203 
204  vout.general(m_vl, "\n");
205  vout.general(m_vl, " plaq_org = %.16f\n", plaq); // write-out
206 
207  //- time evolution (SA)
208  m_impl->flow(t, m_Estep, U);
209 
210  plaq = m_staple.plaquette(U);
211 
212  vout.general(m_vl, " (t, plaq) = %.8f %.16f\n", t, plaq);
213 
214  return t * t * 36.0 * (1.0 - plaq);
215 }
216 
217 
218 //====================================================================
219 //============================================================END=====
Parameters::set_bool
void set_bool(const string &key, const bool value)
Definition: parameters.cpp:30
GradientFlow_RungeKutta::flow
virtual void flow(double &t, double &Estep, Field_G &U)=0
gradientFlow.h
Parameters::set_string
void set_string(const string &key, const string &value)
Definition: parameters.cpp:39
GradientFlow::m_staple
Staple_lex m_staple
Definition: gradientFlow.h:64
CommonParameters
Common parameter class: provides parameters as singleton.
Definition: commonParameters.h:42
GradientFlow::m_action
Action * m_action
Definition: gradientFlow.h:63
GradientFlow::GradientFlow
GradientFlow(Action *action)
Definition: gradientFlow.cpp:19
Parameters
Class for parameters.
Definition: parameters.h:46
Staple_lex::plaquette
double plaquette(const Field_G &)
calculates plaquette value.
Definition: staple_lex.cpp:89
Parameters::set_double
void set_double(const string &key, const double value)
Definition: parameters.cpp:33
GradientFlow::m_vl
Bridge::VerboseLevel m_vl
Definition: gradientFlow.h:53
GradientFlow::m_is_adaptive
bool m_is_adaptive
Definition: gradientFlow.h:61
ParameterCheck::non_negative
int non_negative(const int v)
Definition: parameterCheck.cpp:21
GradientFlow::initialize
void initialize()
Definition: gradientFlow.cpp:40
GradientFlow::m_tolerance
double m_tolerance
Definition: gradientFlow.h:59
Action
Base class of HMC action class family.
Definition: action.h:36
Parameters::fetch_bool
int fetch_bool(const string &key, bool &value) const
Definition: parameters.cpp:391
GradientFlow::m_impl
GradientFlow_RungeKutta * m_impl
Definition: gradientFlow.h:66
GradientFlow::m_safety
double m_safety
Definition: gradientFlow.h:60
GradientFlow_AdaptiveRungeKutta
GradientFlow_AdaptiveRungeKutta construction.
Definition: gradientFlow_AdaptiveRungeKutta.h:34
GradientFlow::class_name
static const std::string class_name
Definition: gradientFlow.h:50
GradientFlow_RungeKutta_2nd
GradientFlow_RungeKutta_2nd construction.
Definition: gradientFlow_RungeKutta_2nd.h:29
GradientFlow::m_Estep
double m_Estep
Definition: gradientFlow.h:57
GradientFlow::get_parameters
void get_parameters(Parameters &params) const
Definition: gradientFlow.cpp:94
ParameterCheck::square_non_zero
int square_non_zero(const double v)
Definition: parameterCheck.cpp:43
GradientFlow::set_parameter_Norder_RK
void set_parameter_Norder_RK(const int order, const bool is_adaptive)
Definition: gradientFlow.cpp:166
GradientFlow_RungeKutta_4th
GradientFlow_RungeKutta_4th construction.
Definition: gradientFlow_RungeKutta_4th.h:30
GradientFlow::~GradientFlow
~GradientFlow()
Definition: gradientFlow.cpp:48
GradientFlow::m_Norder_RK
int m_Norder_RK
Definition: gradientFlow.h:56
GradientFlow_RungeKutta_3rd
GradientFlow_RungeKutta_3rd construction.
Definition: gradientFlow_RungeKutta_3rd.h:30
Bridge::BridgeIO::set_verbose_level
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:133
GradientFlow::evolve
double evolve(double &t, Field_G &U)
Definition: gradientFlow.cpp:200
GradientFlow_RungeKutta_1st
GradientFlow_RungeKutta_1st construction.
Definition: gradientFlow_RungeKutta_1st.h:29
Parameters::set_int
void set_int(const string &key, const int value)
Definition: parameters.cpp:36
Parameters::fetch_string
int fetch_string(const string &key, string &value) const
Definition: parameters.cpp:378
Parameters::fetch_double
int fetch_double(const string &key, double &value) const
Definition: parameters.cpp:327
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
GradientFlow::set_parameters
void set_parameters(const Parameters &params)
Definition: gradientFlow.cpp:55
Field_G
SU(N) gauge field.
Definition: field_G.h:38
Parameters::fetch_int
int fetch_int(const string &key, int &value) const
Definition: parameters.cpp:346
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
GradientFlow::m_Nprec
int m_Nprec
Definition: gradientFlow.h:58
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
Bridge::BridgeIO::get_verbose_level
static std::string get_verbose_level(const VerboseLevel vl)
Definition: bridgeIO.cpp:154