Bridge++  Ver. 1.3.x
test_HMC_Clover_SF_RHMC_Nf2p1.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "fopr_Clover_SF.h"
17 #include "force_F_Clover_SF.h"
18 #include "action_F_Standard_SF.h"
19 #include "staples_SF.h"
20 
21 #include "fopr_Rational_SF.h"
23 
24 #include "action.h"
25 #include "gaugeConfig.h"
26 #include "randomNumbers_Mseries.h"
27 #include "randomNumbers_MT19937.h"
28 #include "solver.h"
29 
30 #include "director_Smear.h"
31 #include "fopr_Smeared.h"
32 #include "force_F_Smeared.h"
33 #include "forceSmear.h"
34 #include "projection.h"
35 #include "smear.h"
36 
37 #include "hmc_General.h"
38 #include "builder_Integrator.h"
39 #include "file_utils.h"
40 
41 //====================================================================
43 
71 namespace Test_HMC_Clover_SF {
72  const std::string test_name = "HMC.Clover_SF.RHMC_Nf2p1";
73 
74  //- test-private parameters
75  namespace {
76  const std::string filename_input = "test_HMC_Clover_SF_RHMC_Nf2p1.yaml";
77  const std::string filename_output = "stdout";
78 
79  class Parameters_Test_HMC_Clover_SF : public Parameters {
80  public:
81  Parameters_Test_HMC_Clover_SF()
82  {
83  Register_string("gauge_config_status", "NULL");
84 
85  Register_string("gauge_config_type_input", "NULL");
86  Register_string("config_filename_input", "NULL");
87 
88  Register_string("gauge_config_type_output", "NULL");
89  Register_string("config_filename_output", "NULL");
90 
91  Register_string("verbose_level", "NULL");
92 
93  Register_int("trajectory_number", 0);
94  Register_int("trajectory_number_step", 0);
95  Register_int("save_config_interval", 0);
96 
97  Register_double("expected_result", 0.0);
98  }
99  };
100  }
101 
102  //- prototype declaration
103  int RHMC_Nf2p1(void);
104 
105 #ifdef USE_TESTMANAGER_AUTOREGISTER
106  namespace {
107 #if defined(USE_GROUP_SU2)
108  // Nc=2 is not available.
109 #else
110  static const bool is_registered = TestManager::RegisterTest(
111  test_name,
112  RHMC_Nf2p1
113  );
114 #endif
115  }
116 #endif
117 
118  //====================================================================
119  int RHMC_Nf2p1(void)
120  {
121  // ##### parameter setup #####
122  int Nc = CommonParameters::Nc();
123  int Nvol = CommonParameters::Nvol();
124  int Ndim = CommonParameters::Ndim();
125 
126  unique_ptr<Parameters> params_test(new Parameters_Test_HMC_Clover_SF);
127  unique_ptr<Parameters> params_action_G(ParametersFactory::New("Action"));
128  unique_ptr<Parameters> params_fopr_Nf2(ParametersFactory::New("Fopr"));
129  unique_ptr<Parameters> params_fopr_Nf1(ParametersFactory::New("Fopr"));
130  unique_ptr<Parameters> params_proj(ParametersFactory::New("Projection"));
131  unique_ptr<Parameters> params_smear(ParametersFactory::New("Smear"));
132  unique_ptr<Parameters> params_dr_smear(ParametersFactory::New("Director_Smear"));
133  unique_ptr<Parameters> params_rational_H(ParametersFactory::New("Fopr.Rational"));
134  unique_ptr<Parameters> params_rational_MD(ParametersFactory::New("Fopr.Rational"));
135  unique_ptr<Parameters> params_integrator(ParametersFactory::New("Builder_Integrator"));
136  unique_ptr<Parameters> params_hmc(ParametersFactory::New("HMC.General"));
137  unique_ptr<Parameters> params_all(new Parameters);
138 
139  params_all->Register_Parameters("Test_HMC_Clover_SF", params_test);
140  params_all->Register_Parameters("Action_G", params_action_G);
141  params_all->Register_Parameters("Fopr_Nf2", params_fopr_Nf2);
142  params_all->Register_Parameters("Fopr_Nf1", params_fopr_Nf1);
143  params_all->Register_Parameters("Projection", params_proj);
144  params_all->Register_Parameters("Smear", params_smear);
145  params_all->Register_Parameters("Director_Smear", params_dr_smear);
146  params_all->Register_Parameters("Fopr_Rational_H", params_rational_H);
147  params_all->Register_Parameters("Fopr_Rational_MD", params_rational_MD);
148  params_all->Register_Parameters("Builder_Integrator", params_integrator);
149  params_all->Register_Parameters("HMC_General", params_hmc);
150 
151  ParameterManager::read(filename_input, params_all);
152 
153  const string str_gconf_status = params_test->get_string("gauge_config_status");
154  const string str_gconf_read = params_test->get_string("gauge_config_type_input");
155  const string readfile = params_test->get_string("config_filename_input");
156  const string str_gconf_write = params_test->get_string("gauge_config_type_output");
157  const string writefile = params_test->get_string("config_filename_output");
158  int i_conf = params_test->get_int("trajectory_number");
159  int Ntraj = params_test->get_int("trajectory_number_step");
160  const int i_save_conf = params_test->get_int("save_config_interval");
161  const string str_vlevel = params_test->get_string("verbose_level");
162 
163  const bool do_check = params_test->is_set("expected_result");
164  const double expected_result = do_check ? params_test->get_double("expected_result") : 0.0;
165 
166  const string str_action_G_type = params_action_G->get_string("action_type");
167  const string str_fopr_Nf2_type = params_fopr_Nf2->get_string("fermion_type");
168  const string str_fopr_Nf1_type = params_fopr_Nf1->get_string("fermion_type");
169  const string str_gmset_type = params_fopr_Nf2->get_string("gamma_matrix_type");
170  const string str_proj_type = params_proj->get_string("projection_type");
171  const string str_smear_type = params_smear->get_string("smear_type");
172  const int Nlevels = params_integrator->get_int("number_of_levels");
173  const std::vector<int> level_action = params_integrator->get_int_vector("level_of_actions");
174 
176 
177  //- print input parameters
178  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
179  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
180  vout.general(vl, " readfile = %s\n", readfile.c_str());
181  vout.general(vl, " gconf_write = %s\n", str_gconf_write.c_str());
182  vout.general(vl, " writefile = %s\n", writefile.c_str());
183  vout.general(vl, " i_conf = %d\n", i_conf);
184  vout.general(vl, " Ntraj = %d\n", Ntraj);
185  vout.general(vl, " i_save_conf = %d\n", i_save_conf);
186  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
187  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
188  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
189  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
190  vout.general(vl, "\n");
191 
192  //- input parameter check
193  int err = 0;
194  err += ParameterCheck::non_NULL(str_gconf_status);
195  err += ParameterCheck::non_negative(i_conf);
196  err += ParameterCheck::non_negative(Ntraj);
197  err += ParameterCheck::non_negative(i_save_conf);
198 
199  if (err) {
200  vout.crucial(vl, "%s: Input parameters have not been set.\n", test_name.c_str());
201  exit(EXIT_FAILURE);
202  }
203 
204 
205  // ##### object setup #####
206  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
207  unique_ptr<GaugeConfig> gconf_read(new GaugeConfig(str_gconf_read));
208  unique_ptr<GaugeConfig> gconf_write(new GaugeConfig(str_gconf_write));
209 
210  if (str_gconf_status == "Continue") {
211  gconf_read->read_file(U, readfile);
212  } else if (str_gconf_status == "Cold_start") {
213  U->set_unit();
214  } else if (str_gconf_status == "Hot_start") {
215  int i_seed_noise = 1234567;
216  unique_ptr<RandomNumbers> rand(new RandomNumbers_Mseries(i_seed_noise));
217  U->set_random(rand);
218  } else {
219  vout.crucial(vl, "%s: unsupported gconf status \"%s\".\n", test_name.c_str(), str_gconf_status.c_str());
220  exit(EXIT_FAILURE);
221  }
222 
223  unique_ptr<Action> action_G(Action::New(str_action_G_type));
224  action_G->set_parameters(*params_action_G);
225 
226  //-- N_f=2 part
227  unique_ptr<Fopr> fopr_Nf2(new Fopr_Clover_SF());
228  fopr_Nf2->set_parameters(*params_fopr_Nf2);
229  unique_ptr<Force> force_fopr_Nf2(new Force_F_Clover_SF());
230  force_fopr_Nf2->set_parameters(*params_fopr_Nf2);
231 
232  unique_ptr<Projection> proj(Projection::New(str_proj_type));
233  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
234  smear->set_parameters(*params_smear);
235 
236  unique_ptr<ForceSmear> force_smear(ForceSmear::New(str_smear_type, proj));
237  force_smear->set_parameters(*params_smear);
238 
239  unique_ptr<Director> dr_smear(new Director_Smear(smear));
240  dr_smear->set_parameters(*params_dr_smear);
241 
242  unique_ptr<Fopr> fopr_smear(Fopr::New("Smeared", fopr_Nf2, dr_smear));
243  unique_ptr<Force> force_fopr_smear(
244  new Force_F_Smeared(force_fopr_Nf2, force_smear, dr_smear));
245 
246 
247  unique_ptr<Action> action_F_Nf2(
248  new Action_F_Standard_SF(fopr_smear, force_fopr_smear));
249 
250 
251  //-- N_f=1 part
252  unique_ptr<Fopr> fopr_Nf1(new Fopr_Clover_SF());
253  fopr_Nf1->set_parameters(*params_fopr_Nf1);
254 
255  unique_ptr<Force> force_fopr_Nf1(new Force_F_Clover_SF());
256  force_fopr_Nf1->set_parameters(*params_fopr_Nf1);
257 
258  unique_ptr<Fopr> fopr_r1(Fopr::New("Rational_SF", fopr_Nf1));
259  fopr_r1->set_parameters(*params_rational_H);
260  unique_ptr<Fopr> fopr_langev(Fopr::New("Smeared", fopr_r1, dr_smear));
261 
262  unique_ptr<Fopr> fopr_r2(Fopr::New("Rational_SF", fopr_Nf1));
263  fopr_r2->set_parameters(*params_rational_MD);
264  unique_ptr<Fopr> fopr_H(Fopr::New("Smeared", fopr_r2, dr_smear));
265 
266  unique_ptr<Force> force_fopr_r2(new Force_F_Rational(fopr_Nf1, force_fopr_Nf1));
267  force_fopr_r2->set_parameters(*params_rational_MD);
268 
269  unique_ptr<Force> force_fopr_MD(
270  new Force_F_Smeared(force_fopr_r2,
271  force_smear, dr_smear));
272 
273  unique_ptr<Action> action_F_Nf1(
274  new Action_F_Rational_frame_SF(fopr_langev,
275  fopr_H,
276  force_fopr_MD));
277 
278 
279  ActionList actions(Nlevels);
280  actions.append(level_action[0], action_F_Nf2);
281  actions.append(level_action[1], action_F_Nf1);
282  actions.append(level_action[2], action_G);
283 
284  std::vector<Director *> directors(1);
285  directors[0] = (Director *)dr_smear.get();
286 
287  unique_ptr<Builder_Integrator> builder(new Builder_Integrator(actions, directors));
288  builder->set_parameters(*params_integrator);
289  Integrator *integrator = builder->build();
290 
291  //- Mersenne Twister for random number generator
292  //- for i_conf == 0
293  // std::vector<unsigned long> seed(4);
294  // seed[0] = 0x6a92;
295  // seed[1] = 0x3708;
296  // seed[2] = 0xab41;
297  // seed[3] = 0x5c52;
298  // unique_ptr<RandomNumbers> rand(new RandomNumbers_MT19937(seed));
300 
301  HMC_General hmc(actions, directors, integrator, rand);
302  hmc.set_parameters(*params_hmc);
303 
304  unique_ptr<Timer> timer(new Timer(test_name));
305 
306 
307  // #### Execution main part ####
308  timer->start();
309 
310  vout.general(vl, "RHMC start: Ntraj = %d\n", Ntraj);
311 
312  double result = 0.0;
313  for (int traj = 0; traj < Ntraj; ++traj) {
314  vout.general(vl, "\n");
315  vout.general(vl, "---------------------------------------------------\n");
316  vout.general(vl, "traj = %d\n", traj);
317 
318  result = hmc.update(*U);
319 
320  if ((i_conf + traj + 1) % i_save_conf == 0) {
321  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
322  gconf_write->write_file(U, filename);
323  }
324  }
325 
326  gconf_write->write_file(U, writefile);
327 
328  // if (Communicator::nodeid() == 0) {
329  // rand->writefile("rand_MT");
330  // }
331 
332  timer->report();
333 
334 
335  if (do_check) {
336  return Test::verify(result, expected_result);
337  } else {
338  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
339  return EXIT_SKIP;
340  }
341  }
342 } // namespace Test_HMC_Clover_SF
#define EXIT_SKIP
Definition: test.h:17
Random number generator base on M-series.
BridgeIO vout
Definition: bridgeIO.cpp:278
void detailed(const char *format,...)
Definition: bridgeIO.cpp:82
void set_parameters(const Parameters &params)
void general(const char *format,...)
Definition: bridgeIO.cpp:65
virtual void set_parameters(const Parameters &)=0
const std::string test_name
int get_int(const string &key) const
Definition: parameters.cpp:42
Class for parameters.
Definition: parameters.h:38
static Parameters * New(const std::string &realm)
void read_file(Field *U, const string &filename)
Definition: gaugeConfig.cpp:56
void set_random(RandomNumbers *rand)
Definition: field_G_imp.cpp:62
bool append(const int level, Action *action)
Definition: action_list.cpp:27
virtual void set_parameters(const Parameters &param)=0
Base class of Integrator class family.
Definition: integrator.h:31
std::vector< int > get_int_vector(const string &key) const
Definition: parameters.cpp:72
void set_unit()
Definition: field_G_imp.cpp:39
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:80
SU(N) gauge field.
Definition: field_G.h:38
void set_parameters(const Parameters &params)
Manager of commonly used data object in HMC.
Definition: director.h:37
bool is_set(const string &) const
Definition: parameters.cpp:372
double get_double(const string &key) const
Definition: parameters.cpp:27
std::string generate_filename(const char *fmt,...)
Definition: file_utils.cpp:17
pointer get() const
void write_file(Field *U, const string &filename)
Definition: gaugeConfig.cpp:80
virtual void set_parameters(const Parameters &)=0
int non_NULL(const std::string v)
Definition: checker.cpp:61
void start()
Definition: timer.cpp:44
void crucial(const char *format,...)
Definition: bridgeIO.cpp:48
virtual void set_parameters(const Parameters &params)=0
void Register_Parameters(const string &, Parameters *const)
Definition: parameters.cpp:358
lists of actions at respective integrator levels.
Definition: action_list.h:40
Manager of smeared configurations.
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Bridge::VerboseLevel vl
Definition: checker.cpp:18
VerboseLevel
Definition: bridgeIO.h:39
double update(Field_G &)
Force calculation for smeared fermion operators.
int non_negative(const int v)
Definition: checker.cpp:21
static void read(const std::string &params_file, Parameters *params)
Test of HMC update for clover fermions with SF.
virtual void set_parameters(const Parameters &)=0
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:61
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:87
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
virtual void set_parameters(const Parameters &)=0
Standard fermion action with SF BC for HMC.
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:28