Bridge++  Version 1.4.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 "Tests/test.h"
14 
15 #include "IO/gaugeConfig.h"
16 
19 
21 
22 //====================================================================
24 
33 namespace Test_GradientFlow {
34  const std::string test_name = "GradientFlow.Nf0";
35 
36  const std::string test_name_RK1 = "GradientFlow.Nf0.RK1";
37  const std::string test_name_RK2 = "GradientFlow.Nf0.RK2";
38  const std::string test_name_RK3 = "GradientFlow.Nf0.RK3";
39  const std::string test_name_RK4 = "GradientFlow.Nf0.RK4";
40  const std::string test_name_RK_adaptive = "GradientFlow.Nf0.RK_adaptive";
41 
42  //- test-private parameters
43  namespace {
44  const std::string filename_input_RK1 = "test_GradientFlow_Nf0_RK1.yaml";
45  const std::string filename_input_RK2 = "test_GradientFlow_Nf0_RK2.yaml";
46  const std::string filename_input_RK3 = "test_GradientFlow_Nf0_RK3.yaml";
47  const std::string filename_input_RK4 = "test_GradientFlow_Nf0_RK4.yaml";
48  const std::string filename_input_RK_adaptive = "test_GradientFlow_Nf0_RK_adaptive.yaml";
49  }
50 
51  //- prototype declaration
52  int update(const std::string& filename_input);
53 
55  { return update(filename_input_RK1); }
56 
58  { return update(filename_input_RK2); }
59 
61  { return update(filename_input_RK3); }
62 
64  { return update(filename_input_RK4); }
65 
67  { return update(filename_input_RK_adaptive); }
68 
69 #ifdef USE_TESTMANAGER_AUTOREGISTER
70  namespace {
71 #if defined(USE_GROUP_SU2)
72  // Nc=2 is not available.
73 #else
74  static const bool is_registered_RK1 = TestManager::RegisterTest(
77  );
78  static const bool is_registered_RK2 = TestManager::RegisterTest(
81  );
82  static const bool is_registered_RK3 = TestManager::RegisterTest(
85  );
86  static const bool is_registered_RK4 = TestManager::RegisterTest(
89  );
90  static const bool is_registered_RK_adaptive = TestManager::RegisterTest(
93  );
94 #endif
95  }
96 #endif
97 
98  //====================================================================
99  int update(const std::string& filename_input)
100  {
101  // #### parameter setup ####
102  int Nvol = CommonParameters::Nvol();
103  int Ndim = CommonParameters::Ndim();
104  int Nc = CommonParameters::Nc();
105 
106  Parameters params_all = ParameterManager::read(filename_input);
107 
108  Parameters params_test = params_all.lookup("Test_GradientFlow");
109  Parameters params_action_G = params_all.lookup("Action_G");
110  Parameters params_g_flow = params_all.lookup("GradientFlow");
111  Parameters params_energy_density = params_all.lookup("EnergyDensity");
112 
113  const string str_gconf_status = params_test.get_string("gauge_config_status");
114  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
115  const string readfile = params_test.get_string("config_filename_input");
116  const string str_gconf_write = params_test.get_string("gauge_config_type_output");
117  const string writefile = params_test.get_string("config_filename_output");
118  const string str_rand_type = params_test.get_string("random_number_type");
119  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
120  const int Nstep = params_test.get_int("number_of_steps");
121  const double t_flow_max = params_test.get_double("max_flow_time");
122  const string str_vlevel = params_test.get_string("verbose_level");
123 
124  const bool do_check = params_test.is_set("expected_result");
125  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
126 
127  const string str_action_G_type = params_action_G.get_string("action_type");
128 
130 
131  //- print input parameters
132  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
133  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
134  vout.general(vl, " readfile = %s\n", readfile.c_str());
135  vout.general(vl, " gconf_write = %s\n", str_gconf_write.c_str());
136  vout.general(vl, " writefile = %s\n", writefile.c_str());
137  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
138  vout.general(vl, " seed = %lu\n", seed);
139  vout.general(vl, " Nstep = %d\n", Nstep);
140  vout.general(vl, " t_flow_max = %10.6f\n", t_flow_max);
141  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
142  vout.general(vl, "\n");
143 
144  //- input parameter check
145  int err = 0;
146  err += ParameterCheck::non_NULL(str_gconf_status);
147 
148  if (err) {
149  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
150  exit(EXIT_FAILURE);
151  }
152 
153 
154  RandomNumberManager::initialize(str_rand_type, seed);
155 
156 
157  // #### object setup #####
158  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
159 
160  if (str_gconf_status == "Continue") {
161  GaugeConfig(str_gconf_read).read(U, readfile);
162  } else if (str_gconf_status == "Cold_start") {
163  GaugeConfig("Unit").read(U);
164  } else if (str_gconf_status == "Hot_start") {
165  GaugeConfig("Random").read(U);
166  } else {
167  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
168  exit(EXIT_FAILURE);
169  }
170 
171  unique_ptr<Action> action_G(Action::New(str_action_G_type));
172  //- beta is overwritten to be Nc in GradientFlow
173  params_action_G.set_double("beta", static_cast<double>(Nc));
174  action_G->set_parameters(params_action_G);
175 
176  unique_ptr<GradientFlow> g_flow(new GradientFlow(action_G));
177  g_flow->set_parameters(params_g_flow);
178 
179  unique_ptr<EnergyDensity> energy_density(new EnergyDensity);
180  energy_density->set_parameters(params_energy_density);
181 
182  unique_ptr<Timer> timer(new Timer(test_name));
183 
184 
185  // #### Execution main part ####
186  timer->start();
187 
188  double t_flow = 0.0;
189  double result = 0.0;
190 
191  for (int i = 0; i < Nstep; ++i) {
192  result = g_flow->evolve(t_flow, *U);
193 
194  double t2 = t_flow * t_flow;
195  double E_plaq = energy_density->E_plaq(*U);
196  double E_clover = energy_density->E_clover(*U);
197 
198  vout.general(vl, " (t, t^2 E_plaq, t^2 E_clover) = %.8f %.16f %.16f\n",
199  t_flow, t2 * E_plaq, t2 * E_clover);
200 
201 
202  if (t_flow > t_flow_max) break;
203  }
204 
205  timer->report();
206 
208 
209 
210  if (do_check) {
211  return Test::verify(result, expected_result);
212  } else {
213  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
214  return EXIT_SKIP;
215  }
216  }
217 } // namespace Test_GradientFlow
#define EXIT_SKIP
Definition: test.h:17
BridgeIO vout
Definition: bridgeIO.cpp:495
void detailed(const char *format,...)
Definition: bridgeIO.cpp:212
double E_plaq(const Field_G &U)
void general(const char *format,...)
Definition: bridgeIO.cpp:195
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:87
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)
setting parameters.
int update(const std::string &filename_input)
const std::string test_name_RK2
Parameters lookup(const string &key) const
Definition: parameters.h:78
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:104
double get_double(const string &key) const
Definition: parameters.cpp:70
energy density measurement.
Definition: energyDensity.h:32
const std::string test_name_RK3
int non_NULL(const std::string v)
Definition: checker.cpp:61
bool is_set(const string &key) const
Definition: parameters.cpp:396
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:46
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:28
Bridge::VerboseLevel vl
Definition: checker.cpp:18
VerboseLevel
Definition: bridgeIO.h:42
const std::string test_name_RK4
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:75
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:116
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