Bridge++  Ver. 2.0.2
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  Field_G U(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  //- beta is overwritten to be Nc in GradientFlow
179  params_action_G.set_double("beta", static_cast<double>(Nc));
180 
181  unique_ptr<Action> action_G(Action::New(str_action_G_type, params_action_G));
182 
183  GradientFlow g_flow(action_G.get(), params_g_flow);
184 
185  EnergyDensity energy_density(params_energy_density);
186 
187  Timer timer(test_name);
188 
189 
190  // #### Execution main part ####
191  timer.start();
192 
193  double t_flow = 0.0;
194  double result = 0.0;
195 
196  for (int i = 0; i < Nstep; ++i) {
197  result = g_flow.evolve(t_flow, U);
198 
199  double t2 = t_flow * t_flow;
200  double E_plaq = energy_density.E_plaq(U);
201  double E_clover = energy_density.E_clover(U);
202 
203  vout.general(vl, " (t, t^2 E_plaq, t^2 E_clover) = %.8f %.16f %.16f\n",
204  t_flow, t2 * E_plaq, t2 * E_clover);
205 
206 
207  if (t_flow > t_flow_max) break;
208  }
209 
210  timer.report();
211 
213 
214 
215  if (do_check) {
216  //- NB. verification criterion is loosed for RK_adaptive,
217  // due to its severe sensitivity to rounding errors
218  if (filename_input == "test_GradientFlow_Nf0_RK_adaptive.yaml") {
219  return Test::verify(result, expected_result, 1.0e-10);
220  } else {
221  return Test::verify(result, expected_result);
222  }
223  } else {
224  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
225  return EXIT_SKIP;
226  }
227  }
228 } // namespace Test_GradientFlow
EnergyDensity
energy density measurement.
Definition: energyDensity.h:29
Test::verify
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Test_GradientFlow::run_test_RK1
int run_test_RK1()
Definition: test_GradientFlow_Nf0.cpp:60
ParameterCheck::non_NULL
int non_NULL(const std::string v)
Definition: parameterCheck.cpp:65
gradientFlow.h
Test_GradientFlow::run_test_RK2
int run_test_RK2()
Definition: test_GradientFlow_Nf0.cpp:63
CommonParameters::Ndim
static int Ndim()
Definition: commonParameters.h:117
Parameters
Class for parameters.
Definition: parameters.h:46
Parameters::set_double
void set_double(const string &key, const double value)
Definition: parameters.cpp:33
Parameters::get_int
int get_int(const string &key) const
Definition: parameters.cpp:192
Bridge::BridgeIO::detailed
void detailed(const char *format,...)
Definition: bridgeIO.cpp:219
GaugeConfig::read
void read(Field_G &U, const string &filename=string())
Definition: gaugeConfig.cpp:121
gaugeConfig.h
CommonParameters::Nvol
static int Nvol()
Definition: commonParameters.h:109
Test_GradientFlow::run_test_RK4
int run_test_RK4()
Definition: test_GradientFlow_Nf0.cpp:69
energyDensity.h
Timer
Definition: timer.h:31
RandomNumberManager::finalize
static void finalize()
Definition: randomNumberManager.cpp:80
Test_GradientFlow
Test of gradientFlow.
Definition: test_GradientFlow_Nf0.cpp:39
RandomNumberManager::initialize
static bool initialize(const std::string &rng_type, unsigned long seed)
Definition: randomNumberManager.cpp:57
Test_GradientFlow::test_name_RK3
const std::string test_name_RK3
Definition: test_GradientFlow_Nf0.cpp:44
Timer::start
void start()
Definition: timer.cpp:44
CommonParameters::Nc
static int Nc()
Definition: commonParameters.h:115
ParameterCheck::vl
Bridge::VerboseLevel vl
Definition: parameterCheck.cpp:18
Test_Gauge::energy_density
int energy_density(void)
Definition: test_Gauge_EnergyDensity.cpp:53
Test_GradientFlow::test_name_RK4
const std::string test_name_RK4
Definition: test_GradientFlow_Nf0.cpp:45
test.h
ParameterManager::read
static void read(const std::string &params_file, Parameters &params)
Definition: parameterManager.cpp:33
Parameters::get_double
double get_double(const string &key) const
Definition: parameters.cpp:175
Test_GradientFlow::test_name
const std::string test_name
Definition: test_GradientFlow_Nf0.cpp:40
Parameters::get_unsigned_long
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:209
EXIT_SKIP
#define EXIT_SKIP
Definition: test.h:17
randomNumberManager.h
GaugeConfig
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:80
Test_GradientFlow::run_test_RK_adaptive
int run_test_RK_adaptive()
Definition: test_GradientFlow_Nf0.cpp:72
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
Parameters::is_set
bool is_set(const string &key) const
Definition: parameters.cpp:525
Test_GradientFlow::test_name_RK2
const std::string test_name_RK2
Definition: test_GradientFlow_Nf0.cpp:43
Test_GradientFlow::run_test_RK3
int run_test_RK3()
Definition: test_GradientFlow_Nf0.cpp:66
Test_GradientFlow::test_name_RK_adaptive
const std::string test_name_RK_adaptive
Definition: test_GradientFlow_Nf0.cpp:46
Parameters::get_string
string get_string(const string &key) const
Definition: parameters.cpp:221
Test_GradientFlow::test_name_RK1
const std::string test_name_RK1
Definition: test_GradientFlow_Nf0.cpp:42
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42
Field_G
SU(N) gauge field.
Definition: field_G.h:38
GradientFlow
GradientFlow construction.
Definition: gradientFlow.h:47
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
Test_GradientFlow::update
int update(const std::string &filename_input)
Definition: test_GradientFlow_Nf0.cpp:105
Parameters::lookup
Parameters lookup(const string &key) const
Definition: parameters.h:79
Timer::report
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
TestManager::RegisterTest
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:69