Bridge++  Ver. 1.2.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_GradientFlow.cpp
Go to the documentation of this file.
1 
13 #include "test.h"
14 
15 #include "gaugeConfig.h"
16 
17 #include "action_G_Plaq.h"
18 #include "action_G_Rectangle.h"
19 
20 #include "gradientFlow.h"
21 
22 #include "randomNumbers_Mseries.h"
23 
24 //====================================================================
26 
33 namespace Test_GradientFlow {
34  const std::string test_name = "GradientFlow";
35 
36  //- test-private parameters
37  namespace {
38  const std::string filename_input = "test_GradientFlow.yaml";
39  const std::string filename_output = "stdout";
40 
41  class Parameters_Test_GradientFlow : public Parameters {
42  public:
43  Parameters_Test_GradientFlow()
44  {
45  Register_string("gauge_config_status", "NULL");
46  Register_string("gauge_config_type_input", "NULL");
47  Register_string("config_filename_input", "NULL");
48 
49  Register_string("gauge_config_type_output", "NULL");
50  Register_string("config_filename_output", "NULL");
51 
52  Register_string("verbose_level", "NULL");
53 
54  Register_double("expected_result", 0.0);
55  }
56  };
57  }
58 
59  //- prototype declaration
60  int update(void);
61 
62 #ifdef USE_TESTMANAGER_AUTOREGISTER
63  namespace {
64 #if defined(USE_GROUP_SU2)
65  // Nc=2 is not available.
66 #else
67  static const bool is_registered = TestManager::RegisterTest(
68  test_name,
69  update
70  );
71 #endif
72  }
73 #endif
74 
75  //====================================================================
76  int update(void)
77  {
78  // #### parameter setup ####
79  int Nvol = CommonParameters::Nvol();
80  int Ndim = CommonParameters::Ndim();
81  int Nc = CommonParameters::Nc();
82 
83  Parameters *params_test = new Parameters_Test_GradientFlow;
84  Parameters *params_action_G = ParametersFactory::New("Action.G_Plaq");
85  Parameters *params_g_flow = ParametersFactory::New("GradientFlow");
86  Parameters *params_all = new Parameters;
87 
88  params_all->Register_Parameters("Test_GradientFlow", params_test);
89  params_all->Register_Parameters("Action_G_Plaq", params_action_G);
90  params_all->Register_Parameters("GradientFlow", params_g_flow);
91 
92  ParameterManager_YAML params_manager;
93  params_manager.read_params(filename_input, params_all);
94 
95  const string str_gconf_status = params_test->get_string("gauge_config_status");
96  const string str_gconf_read = params_test->get_string("gauge_config_type_input");
97  const string readfile = params_test->get_string("config_filename_input");
98  const string str_gconf_write = params_test->get_string("gauge_config_type_output");
99  const string writefile = params_test->get_string("config_filename_output");
100  const string str_vlevel = params_test->get_string("verbose_level");
101 
102  const bool do_check = params_test->is_set("expected_result");
103  const double expected_result = do_check ? params_test->get_double("expected_result") : 0.0;
104 
106 
107  //- print input parameters
108  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
109  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
110  vout.general(vl, " readfile = %s\n", readfile.c_str());
111  vout.general(vl, " gconf_write = %s\n", str_gconf_write.c_str());
112  vout.general(vl, " writefile = %s\n", writefile.c_str());
113  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
114  vout.general(vl, "\n");
115 
116  //- input parameter check
117  int err = 0;
118  err += ParameterCheck::non_NULL(str_gconf_status);
119 
120  if (err) {
121  vout.crucial(vl, "%s: Input parameters have not been set.\n", test_name.c_str());
122  abort();
123  }
124 
125 
126  // #### object setup #####
127  Field_G *U = new Field_G(Nvol, Ndim);
128  GaugeConfig *gconf_read = new GaugeConfig(str_gconf_read);
129 
130  if (str_gconf_status == "Continue") {
131  gconf_read->read_file((Field *)U, readfile);
132  } else if (str_gconf_status == "Cold_start") {
133  U->set_unit();
134  } else if (str_gconf_status == "Hot_start") {
135  RandomNumbers_Mseries rand(1234567);
136  U->set_random(&rand);
137  } else {
138  vout.crucial(vl, "%s: unsupported gconf status \"%s\".\n", test_name.c_str(), str_gconf_status.c_str());
139  abort();
140  }
141 
142  Action_G_Plaq *action_G = new Action_G_Plaq;
143  //- beta is overwritten to be Nc in GradientFlow
144  params_action_G->set_double("beta", static_cast<double>(Nc));
145  action_G->set_parameters(*params_action_G);
146 
147  GradientFlow *g_flow = new GradientFlow((Action * )action_G);
148  g_flow->set_parameters(*params_g_flow);
149 
150  Timer *timer = new Timer(test_name);
151 
152 
153  // #### Execution main part ####
154  timer->start();
155 
156  double result = g_flow->evolve(*U); // mod. by (SM)
157 
158  timer->report();
159 
160 
161  // #### tydy up ####
162  delete params_test;
163  delete params_action_G;
164  delete params_g_flow;
165  delete params_all;
166 
167  delete timer;
168 
169  delete U;
170  delete gconf_read;
171 
172  delete g_flow;
173  delete action_G;
174 
175 
176  if (do_check) {
177  return Test::verify(expected_result, result);
178  } else {
179  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
180  return EXIT_SKIP;
181  }
182  }
183 } // namespace Test_GradientFlow
#define EXIT_SKIP
Definition: test.h:17
Random number generator base on M-series.
BridgeIO vout
Definition: bridgeIO.cpp:207
void read_params(const std::string &params_file, Parameters *params)
read parameters from file.
void detailed(const char *format,...)
Definition: bridgeIO.cpp:50
void set_parameters(const Parameters &params)
void general(const char *format,...)
Definition: bridgeIO.cpp:38
const std::string test_name
Container of Field-type object.
Definition: field.h:37
Class for parameters.
Definition: parameters.h:40
static Parameters * New(const std::string &realm)
void set_random(RandomNumbers *rand)
Definition: field_G_imp.cpp:62
Base class of HMC action class family.
Definition: action.h:35
void set_unit()
Definition: field_G_imp.cpp:39
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:79
SU(N) gauge field.
Definition: field_G.h:36
bool is_set(const string &) const
Definition: parameters.cpp:366
double get_double(const string &key) const
Definition: parameters.cpp:25
int non_NULL(const std::string v)
Definition: checker.cpp:61
void start()
Definition: timer.cpp:44
double evolve(Field_G &U)
void crucial(const char *format,...)
Definition: bridgeIO.cpp:26
void Register_Parameters(const string &, Parameters *const)
Definition: parameters.cpp:359
void set_double(const string &key, const double value)
Definition: parameters.cpp:271
Bridge::VerboseLevel vl
Definition: checker.cpp:18
VerboseLevel
Definition: bridgeIO.h:25
Parameter manager with YAML parser.
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:56
Definition: timer.h:31
int verify(const double expected, const double result)
Definition: test.cpp:27
void read_file(Field *u, const string &filename)
Definition: gaugeConfig.cpp:85
string get_string(const string &key) const
Definition: parameters.cpp:85
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:191