Bridge++  Version 1.4.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_HMC_Clover_SF_RHMC_Nf2p1.cpp
Go to the documentation of this file.
1 
14 #include "Tests/test.h"
15 
18 
19 #include "Fopr/fopr_Rational_SF.h"
20 #include "Fopr/fopr_Smeared.h"
21 
24 
25 #include "HMC/hmc_General.h"
26 #include "HMC/builder_Integrator.h"
27 
28 #include "IO/gaugeConfig.h"
29 
30 #include "Smear/projection.h"
31 
32 #include "Tools/file_utils.h"
35 
36 //====================================================================
38 
66 namespace Test_HMC_Clover_SF {
67  const std::string test_name = "HMC.Clover_SF.RHMC_Nf2p1";
68 
69  //- test-private parameters
70  namespace {
71  const std::string filename_input = "test_HMC_Clover_SF_RHMC_Nf2p1.yaml";
72  }
73 
74  //- prototype declaration
75  int RHMC_Nf2p1(void);
76 
77 #ifdef USE_TESTMANAGER_AUTOREGISTER
78  namespace {
79 #if defined(USE_GROUP_SU2)
80  // Nc=2 is not available.
81 #else
82  static const bool is_registered = TestManager::RegisterTest(
83  test_name,
85  );
86 #endif
87  }
88 #endif
89 
90  //====================================================================
91  int RHMC_Nf2p1(void)
92  {
93  // ##### parameter setup #####
94  int Nc = CommonParameters::Nc();
95  int Nvol = CommonParameters::Nvol();
96  int Ndim = CommonParameters::Ndim();
97 
98  Parameters params_all = ParameterManager::read(filename_input);
99 
100  Parameters params_test = params_all.lookup("Test_HMC_Clover_SF");
101  Parameters params_action_G = params_all.lookup("Action_G");
102  Parameters params_fopr_Nf2 = params_all.lookup("Fopr_Nf2");
103  Parameters params_fopr_Nf1 = params_all.lookup("Fopr_Nf1");
104  Parameters params_proj = params_all.lookup("Projection");
105  Parameters params_smear = params_all.lookup("Smear");
106  Parameters params_dr_smear = params_all.lookup("Director_Smear");
107  Parameters params_rational_MD = params_all.lookup("Fopr_Rational_MD");
108  Parameters params_rational_H = params_all.lookup("Fopr_Rational_H");
109  Parameters params_integrator = params_all.lookup("Builder_Integrator");
110  Parameters params_hmc = params_all.lookup("HMC_General");
111 
112  const string str_gconf_status = params_test.get_string("gauge_config_status");
113  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
114  const string readfile = params_test.get_string("config_filename_input");
115  const string str_gconf_write = params_test.get_string("gauge_config_type_output");
116  const string writefile = params_test.get_string("config_filename_output");
117  const string str_rand_type = params_test.get_string("random_number_type");
118  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
119  int i_conf = params_test.get_int("trajectory_number");
120  int Ntraj = params_test.get_int("trajectory_number_step");
121  const int i_save_conf = params_test.get_int("save_config_interval");
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  const string str_fopr_Nf2_type = params_fopr_Nf2.get_string("fermion_type");
129  const string str_fopr_Nf1_type = params_fopr_Nf1.get_string("fermion_type");
130  const string str_gmset_type = params_fopr_Nf2.get_string("gamma_matrix_type");
131  const string str_proj_type = params_proj.get_string("projection_type");
132  const string str_smear_type = params_smear.get_string("smear_type");
133  const int Nlevels = params_integrator.get_int("number_of_levels");
134  const std::vector<int> level_action = params_integrator.get_int_vector("level_of_actions");
135 
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, " i_conf = %d\n", i_conf);
147  vout.general(vl, " Ntraj = %d\n", Ntraj);
148  vout.general(vl, " i_save_conf = %d\n", i_save_conf);
149  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
150  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
151  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
152  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
153  vout.general(vl, "\n");
154 
155  //- input parameter check
156  int err = 0;
157  err += ParameterCheck::non_NULL(str_gconf_status);
158  err += ParameterCheck::non_negative(i_conf);
159  err += ParameterCheck::non_negative(Ntraj);
160  err += ParameterCheck::non_negative(i_save_conf);
161 
162  if (err) {
163  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
164  exit(EXIT_FAILURE);
165  }
166 
167 
168  RandomNumberManager::initialize(str_rand_type, seed);
169 
170 
171  // ##### object setup #####
172  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
173 
174  if (str_gconf_status == "Continue") {
175  GaugeConfig(str_gconf_read).read(U, readfile);
176  } else if (str_gconf_status == "Cold_start") {
177  GaugeConfig("Unit").read(U);
178  } else if (str_gconf_status == "Hot_start") {
179  GaugeConfig("Random").read(U);
180  } else {
181  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
182  exit(EXIT_FAILURE);
183  }
184 
185  unique_ptr<GaugeConfig> gconf_write(new GaugeConfig(str_gconf_write));
186 
187 
188  unique_ptr<Action> action_G(Action::New(str_action_G_type));
189  action_G->set_parameters(params_action_G);
190 
191  //-- N_f=2 part
192  unique_ptr<Fopr> fopr_Nf2(new Fopr_Clover_SF());
193  fopr_Nf2->set_parameters(params_fopr_Nf2);
194  unique_ptr<Force> force_fopr_Nf2(new Force_F_Clover_SF());
195  force_fopr_Nf2->set_parameters(params_fopr_Nf2);
196 
197  unique_ptr<Projection> proj(Projection::New(str_proj_type));
198  proj->set_parameters(params_proj);
199 
200  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
201  smear->set_parameters(params_smear);
202 
203  unique_ptr<ForceSmear> force_smear(ForceSmear::New(str_smear_type, proj));
204  force_smear->set_parameters(params_smear);
205 
206  unique_ptr<Director> dr_smear(new Director_Smear(smear));
207  dr_smear->set_parameters(params_dr_smear);
208 
209  unique_ptr<Fopr> fopr_smear(Fopr::New("Smeared", fopr_Nf2, dr_smear));
210  unique_ptr<Force> force_fopr_smear(
211  new Force_F_Smeared(force_fopr_Nf2, force_smear, dr_smear));
212 
213 
214  unique_ptr<Action> action_F_Nf2(
215  new Action_F_Standard_SF(fopr_smear, force_fopr_smear));
216 
217 
218  //-- N_f=1 part
219  unique_ptr<Fopr> fopr_Nf1(new Fopr_Clover_SF());
220  fopr_Nf1->set_parameters(params_fopr_Nf1);
221 
222  unique_ptr<Force> force_fopr_Nf1(new Force_F_Clover_SF());
223  force_fopr_Nf1->set_parameters(params_fopr_Nf1);
224 
225  unique_ptr<Fopr> fopr_r1(Fopr::New("Rational_SF", fopr_Nf1));
226  fopr_r1->set_parameters(params_rational_H);
227  unique_ptr<Fopr> fopr_langev(Fopr::New("Smeared", fopr_r1, dr_smear));
228 
229  unique_ptr<Fopr> fopr_r2(Fopr::New("Rational_SF", fopr_Nf1));
230  fopr_r2->set_parameters(params_rational_MD);
231  unique_ptr<Fopr> fopr_H(Fopr::New("Smeared", fopr_r2, dr_smear));
232 
233  unique_ptr<Force> force_fopr_r2(new Force_F_Rational(fopr_Nf1, force_fopr_Nf1));
234  force_fopr_r2->set_parameters(params_rational_MD);
235 
236  unique_ptr<Force> force_fopr_MD(
237  new Force_F_Smeared(force_fopr_r2,
238  force_smear, dr_smear));
239 
240  unique_ptr<Action> action_F_Nf1(
241  new Action_F_Rational_SF(fopr_langev,
242  fopr_H,
243  force_fopr_MD));
244 
245 
246  ActionList actions(Nlevels);
247  actions.append(level_action[0], action_F_Nf2);
248  actions.append(level_action[1], action_F_Nf1);
249  actions.append(level_action[2], action_G);
250 
251  std::vector<Director *> directors(1);
252  directors[0] = (Director *)dr_smear.get();
253 
254  unique_ptr<Builder_Integrator> builder(new Builder_Integrator(actions, directors));
255  builder->set_parameters(params_integrator);
256  Integrator *integrator = builder->build();
257 
258  //- Mersenne Twister for random number generator
259  //- for i_conf == 0
260  // std::vector<unsigned long> seed(4);
261  // seed[0] = 0x6a92;
262  // seed[1] = 0x3708;
263  // seed[2] = 0xab41;
264  // seed[3] = 0x5c52;
265  // unique_ptr<RandomNumbers> rand(new RandomNumbers_MT19937(seed));
267 
268  HMC_General hmc(actions, directors, integrator, rand);
269  hmc.set_parameters(params_hmc);
270 
271  unique_ptr<Timer> timer(new Timer(test_name));
272 
273 
274  // #### Execution main part ####
275  timer->start();
276 
277  vout.general(vl, "RHMC start: Ntraj = %d\n", Ntraj);
278 
279  double result = 0.0;
280  for (int traj = 0; traj < Ntraj; ++traj) {
281  vout.general(vl, "\n");
282  vout.general(vl, "---------------------------------------------------\n");
283  vout.general(vl, "traj = %d\n", traj);
284 
285  result = hmc.update(*U);
286 
287  if ((i_conf + traj + 1) % i_save_conf == 0) {
288  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
289  gconf_write->write_file(U, filename);
290  }
291  }
292 
293  gconf_write->write_file(U, writefile);
294 
295  // if (Communicator::nodeid() == 0) {
296  // rand->writefile("rand_MT");
297  // }
298 
299  timer->report();
300 
302 
303 
304  if (do_check) {
305  return Test::verify(result, expected_result);
306  } else {
307  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
308  return EXIT_SKIP;
309  }
310  }
311 } // namespace Test_HMC_Clover_SF
#define EXIT_SKIP
Definition: test.h:17
BridgeIO vout
Definition: bridgeIO.cpp:495
void detailed(const char *format,...)
Definition: bridgeIO.cpp:212
virtual void set_parameters(const Parameters &param)=0
void set_parameters(const Parameters &params)
void general(const char *format,...)
Definition: bridgeIO.cpp:195
General HMC update class.
Definition: hmc_General.h:46
virtual void set_parameters(const Parameters &)=0
const std::string test_name
int get_int(const string &key) const
Definition: parameters.cpp:87
Class for parameters.
Definition: parameters.h:46
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:29
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 set_parameters(const Parameters &params)
Manager of commonly used data object in HMC.
Definition: director.h:37
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
std::string generate_filename(const char *fmt,...)
Definition: file_utils.cpp:17
pointer get() const
virtual void set_parameters(const Parameters &)=0
Force calculation for clover quark action with SF BC.
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
virtual void set_parameters(const Parameters &params)=0
static void read(const std::string &params_file, Parameters &params)
action class for RHMC, with externally constructed Fopr_Rational.
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:42
double update(Field_G &)
void write_file(Field_G *U, const string &filename)
Definition: gaugeConfig.h:107
Force calculation for smeared fermion operators.
int non_negative(const int v)
Definition: checker.cpp:21
virtual void set_parameters(const Parameters &)=0
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
vector< int > get_int_vector(const string &key) const
Definition: parameters.cpp:145
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
virtual void set_parameters(const Parameters &)=0
Builder of MD integrator for HMC.
Standard fermion action with SF BC for HMC.
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
Force calculation for smeared fermion operators.
Clover fermion operator.