Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_GradientFlow_Nf0.cpp
Go to the documentation of this file.
1 
13 #include "test.h"
14 
15 #include "IO/gaugeConfig.h"
16 
19 
21 
22 //====================================================================
24 
39 namespace Test_GradientFlow {
40  const std::string test_name = "GradientFlow.Nf0";
41 
42  const std::string test_name_RK1 = "GradientFlow.Nf0.RK1";
43  const std::string test_name_RK2 = "GradientFlow.Nf0.RK2";
44  const std::string test_name_RK3 = "GradientFlow.Nf0.RK3";
45  const std::string test_name_RK4 = "GradientFlow.Nf0.RK4";
46  const std::string test_name_RK_adaptive = "GradientFlow.Nf0.RK_adaptive";
47 
48  //- test-private parameters
49  namespace {
50  const std::string filename_input_RK1 = "test_GradientFlow_Nf0_RK1.yaml";
51  const std::string filename_input_RK2 = "test_GradientFlow_Nf0_RK2.yaml";
52  const std::string filename_input_RK3 = "test_GradientFlow_Nf0_RK3.yaml";
53  const std::string filename_input_RK4 = "test_GradientFlow_Nf0_RK4.yaml";
54  const std::string filename_input_RK_adaptive = "test_GradientFlow_Nf0_RK_adaptive.yaml";
55  }
56 
57  //- prototype declaration
58  int update(const std::string& filename_input);
59 
61  { return update(filename_input_RK1); }
62 
64  { return update(filename_input_RK2); }
65 
67  { return update(filename_input_RK3); }
68 
70  { return update(filename_input_RK4); }
71 
73  { return update(filename_input_RK_adaptive); }
74 
75 #ifdef USE_TESTMANAGER_AUTOREGISTER
76  namespace {
77 #if defined(USE_GROUP_SU2)
78  // Nc=2 is not available.
79 #else
80  static const bool is_registered_RK1 = TestManager::RegisterTest(
83  );
84  static const bool is_registered_RK2 = TestManager::RegisterTest(
87  );
88  static const bool is_registered_RK3 = TestManager::RegisterTest(
91  );
92  static const bool is_registered_RK4 = TestManager::RegisterTest(
95  );
96  static const bool is_registered_RK_adaptive = TestManager::RegisterTest(
99  );
100 #endif
101  }
102 #endif
103 
104  //====================================================================
105  int update(const std::string& filename_input)
106  {
107  // #### parameter setup ####
108  const int Nvol = CommonParameters::Nvol();
109  const int Ndim = CommonParameters::Ndim();
110  const int Nc = CommonParameters::Nc();
111 
112  const Parameters params_all = ParameterManager::read(filename_input);
113 
114  const Parameters params_test = params_all.lookup("Test_GradientFlow");
115  //- NB. additional parameter for action_G is set in the following object setup
116  Parameters params_action_G = params_all.lookup("Action_G");
117  const Parameters params_g_flow = params_all.lookup("GradientFlow");
118  const Parameters params_energy_density = params_all.lookup("EnergyDensity");
119 
120  const string str_gconf_status = params_test.get_string("gauge_config_status");
121  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
122  const string readfile = params_test.get_string("config_filename_input");
123  const string str_gconf_write = params_test.get_string("gauge_config_type_output");
124  const string writefile = params_test.get_string("config_filename_output");
125  const string str_rand_type = params_test.get_string("random_number_type");
126  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
127  const int Nstep = params_test.get_int("number_of_steps");
128  const double t_flow_max = params_test.get_double("max_flow_time");
129  const string str_vlevel = params_test.get_string("verbose_level");
130 
131  const bool do_check = params_test.is_set("expected_result");
132  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
133 
134  const string str_action_G_type = params_action_G.get_string("action_type");
135 
136  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
137 
138  //- print input parameters
139  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
140  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
141  vout.general(vl, " readfile = %s\n", readfile.c_str());
142  vout.general(vl, " gconf_write = %s\n", str_gconf_write.c_str());
143  vout.general(vl, " writefile = %s\n", writefile.c_str());
144  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
145  vout.general(vl, " seed = %lu\n", seed);
146  vout.general(vl, " Nstep = %d\n", Nstep);
147  vout.general(vl, " t_flow_max = %10.6f\n", t_flow_max);
148  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
149  vout.general(vl, "\n");
150 
151  //- input parameter check
152  int err = 0;
153  err += ParameterCheck::non_NULL(str_gconf_status);
154 
155  if (err) {
156  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
157  exit(EXIT_FAILURE);
158  }
159 
160 
161  RandomNumberManager::initialize(str_rand_type, seed);
162 
163 
164  // #### object setup #####
165  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
166 
167  if (str_gconf_status == "Continue") {
168  GaugeConfig(str_gconf_read).read(U, readfile);
169  } else if (str_gconf_status == "Cold_start") {
170  GaugeConfig("Unit").read(U);
171  } else if (str_gconf_status == "Hot_start") {
172  GaugeConfig("Random").read(U);
173  } else {
174  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
175  exit(EXIT_FAILURE);
176  }
177 
178  unique_ptr<Action> action_G(Action::New(str_action_G_type));
179  //- beta is overwritten to be Nc in GradientFlow
180  params_action_G.set_double("beta", static_cast<double>(Nc));
181  action_G->set_parameters(params_action_G);
182 
183  const unique_ptr<GradientFlow> g_flow(new GradientFlow(action_G));
184  g_flow->set_parameters(params_g_flow);
185 
187  energy_density->set_parameters(params_energy_density);
188 
189  const unique_ptr<Timer> timer(new Timer(test_name));
190 
191 
192  // #### Execution main part ####
193  timer->start();
194 
195  double t_flow = 0.0;
196  double result = 0.0;
197 
198  for (int i = 0; i < Nstep; ++i) {
199  result = g_flow->evolve(t_flow, *U);
200 
201  double t2 = t_flow * t_flow;
202  double E_plaq = energy_density->E_plaq(*U);
203  double E_clover = energy_density->E_clover(*U);
204 
205  vout.general(vl, " (t, t^2 E_plaq, t^2 E_clover) = %.8f %.16f %.16f\n",
206  t_flow, t2 * E_plaq, t2 * E_clover);
207 
208 
209  if (t_flow > t_flow_max) break;
210  }
211 
212  timer->report();
213 
215 
216 
217  if (do_check) {
218  //- NB. verification criterion is loosed for RK_adaptive,
219  // due to its severe sensitivity to rounding errors
220  if (filename_input == "test_GradientFlow_Nf0_RK_adaptive.yaml") {
221  return Test::verify(result, expected_result, 1.0e-10);
222  } else {
223  return Test::verify(result, expected_result);
224  }
225  } else {
226  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
227  return EXIT_SKIP;
228  }
229  }
230 } // namespace Test_GradientFlow
#define EXIT_SKIP
Definition: test.h:17
BridgeIO vout
Definition: bridgeIO.cpp:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
double E_plaq(const Field_G &U)
void general(const char *format,...)
Definition: bridgeIO.cpp:197
const std::string test_name
double evolve(double &t, Field_G &U)
double E_clover(const Field_G &U)
int get_int(const string &key) const
Definition: parameters.cpp:192
Class for parameters.
Definition: parameters.h:46
const std::string test_name_RK1
const std::string test_name_RK_adaptive
virtual void set_parameters(const Parameters &param)=0
virtual void set_parameters(const Parameters &params)
int update(const std::string &filename_input)
const std::string test_name_RK2
Parameters lookup(const string &key) const
Definition: parameters.h:79
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:69
static bool initialize(const std::string &rng_type, unsigned long seed)
SU(N) gauge field.
Definition: field_G.h:38
void read(Field_G *U, const string &filename=string())
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:209
double get_double(const string &key) const
Definition: parameters.cpp:175
energy density measurement.
Definition: energyDensity.h:29
const std::string test_name_RK3
int non_NULL(const std::string v)
bool is_set(const string &key) const
Definition: parameters.cpp:528
void start()
Definition: timer.cpp:44
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
static void read(const std::string &params_file, Parameters &params)
GradientFlow construction.
Definition: gradientFlow.h:47
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
void set_double(const string &key, const double value)
Definition: parameters.cpp:33
Bridge::VerboseLevel vl
VerboseLevel
Definition: bridgeIO.h:42
const std::string test_name_RK4
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:78
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:221
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
void set_parameters(const Parameters &params)
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131