Bridge++  Ver. 2.0.2
test_HMC_Clover_RHMC_Nf2p1.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
19 
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 
31 
32 #include "Tools/file_utils.h"
35 
36 //====================================================================
38 
55 namespace Test_HMC_Clover {
56  const std::string test_name = "HMC.Clover.RHMC_Nf2p1";
57 
58  //- test-private parameters
59  namespace {
60  const std::string filename_input = "test_HMC_Clover_RHMC_Nf2p1.yaml";
61  }
62 
63  //- prototype declaration
64  int RHMC_Nf2p1(void);
65 
66 #ifdef USE_TESTMANAGER_AUTOREGISTER
67  namespace {
68 #if defined(USE_GROUP_SU2)
69  // Nc=2 is not available.
70 #else
71  static const bool is_registered = TestManager::RegisterTest(
72  test_name,
74  );
75 #endif
76  }
77 #endif
78 
79  //====================================================================
80  int RHMC_Nf2p1(void)
81  {
82  // ##### parameter setup #####
83  const int Nc = CommonParameters::Nc();
84  const int Nvol = CommonParameters::Nvol();
85  const int Ndim = CommonParameters::Ndim();
86 
87  const Parameters params_all = ParameterManager::read(filename_input);
88 
89  const Parameters params_test = params_all.lookup("Test_HMC_Clover");
90  const Parameters params_action_G = params_all.lookup("Action_G");
91  const Parameters params_fopr_Nf2 = params_all.lookup("Fopr_Nf2");
92  const Parameters params_fopr_Nf2_prec = params_all.lookup("Fopr_Nf2_prec");
93  const Parameters params_fopr_Nf1 = params_all.lookup("Fopr_Nf1");
94  const Parameters params_proj = params_all.lookup("Projection");
95  const Parameters params_smear = params_all.lookup("Smear");
96  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
97  const Parameters params_rational_MD = params_all.lookup("Fopr_Rational_MD");
98  const Parameters params_rational_H = params_all.lookup("Fopr_Rational_H");
99  const Parameters params_solver_Nf2_MD = params_all.lookup("Solver_Nf2_MD");
100  const Parameters params_solver_Nf2_H = params_all.lookup("Solver_Nf2_H");
101  const Parameters params_solver_Nf2_MD_prec = params_all.lookup("Solver_Nf2_MD_prec");
102  const Parameters params_solver_Nf2_H_prec = params_all.lookup("Solver_Nf2_H_prec");
103  const Parameters params_integrator = params_all.lookup("Builder_Integrator");
104  const Parameters params_hmc = params_all.lookup("HMC_General");
105 
106  const string str_gconf_status = params_test.get_string("gauge_config_status");
107  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
108  const string readfile = params_test.get_string("config_filename_input");
109  const string str_gconf_write = params_test.get_string("gauge_config_type_output");
110  const string writefile = params_test.get_string("config_filename_output");
111  const string str_rand_type = params_test.get_string("random_number_type");
112  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
113  int i_conf = params_test.get_int("trajectory_number");
114  const int Ntraj = params_test.get_int("trajectory_number_step");
115  const int i_save_conf = params_test.get_int("save_config_interval");
116  const string str_vlevel = params_test.get_string("verbose_level");
117 
118  const bool do_check = params_test.is_set("expected_result");
119  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
120 
121  const string str_action_G_type = params_action_G.get_string("action_type");
122  const string str_fopr_Nf2_type = params_fopr_Nf2.get_string("fermion_type");
123  const string str_fopr_Nf2_prec_type = params_fopr_Nf2_prec.get_string("fermion_type");
124  const string str_fopr_Nf1_type = params_fopr_Nf1.get_string("fermion_type");
125  const string str_gmset_type = params_fopr_Nf2.get_string("gamma_matrix_type");
126  const string str_proj_type = params_proj.get_string("projection_type");
127  const string str_smear_type = params_smear.get_string("smear_type");
128  // const int Nsmear = params_dr_smear.get_int("number_of_smearing");
129  const string str_solver_Nf2_MD_type = params_solver_Nf2_MD.get_string("solver_type");
130  const string str_solver_Nf2_H_type = params_solver_Nf2_H.get_string("solver_type");
131  const string str_solver_Nf2_MD_prec_type = params_solver_Nf2_MD_prec.get_string("solver_type");
132  const string str_solver_Nf2_H_prec_type = params_solver_Nf2_H_prec.get_string("solver_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 
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, " 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, " solver_Nf2_MD_type = %s\n", str_solver_Nf2_MD_type.c_str());
154  vout.general(vl, " solver_Nf2_H_type = %s\n", str_solver_Nf2_H_type.c_str());
155  vout.general(vl, " solver_Nf2_MD_prec_type = %s\n", str_solver_Nf2_MD_prec_type.c_str());
156  vout.general(vl, " solver_Nf2_H_prec_type = %s\n", str_solver_Nf2_H_prec_type.c_str());
157  vout.general(vl, "\n");
158 
159  //- input parameter check
160  int err = 0;
161  err += ParameterCheck::non_NULL(str_gconf_status);
162  err += ParameterCheck::non_negative(i_conf);
163  err += ParameterCheck::non_negative(Ntraj);
164  err += ParameterCheck::non_negative(i_save_conf);
165 
166  if (err) {
167  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
168  exit(EXIT_FAILURE);
169  }
170 
171  // if ( (Nsmear > 0) && (str_proj_type == "Stout_SU3") ) {
172  if (str_proj_type == "Stout_SU3") {
173  if (CommonParameters::Nc() != 3) {
174  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
175  return EXIT_SKIP;
176  }
177  }
178 
179 
180  RandomNumberManager::initialize(str_rand_type, seed);
181 
182 
183  // ##### object setup #####
184  Field_G U(Nvol, Ndim);
185 
186  if (str_gconf_status == "Continue") {
187  GaugeConfig(str_gconf_read).read(U, readfile);
188  } else if (str_gconf_status == "Cold_start") {
189  GaugeConfig("Unit").read(U);
190  } else if (str_gconf_status == "Hot_start") {
191  GaugeConfig("Random").read(U);
192  } else {
193  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
194  exit(EXIT_FAILURE);
195  }
196 
197  GaugeConfig gconf_write(str_gconf_write);
198 
199 
200  unique_ptr<Action> action_G(Action::New(str_action_G_type, params_action_G));
201 
202 
203  //-- smear part
204  unique_ptr<Projection> proj(Projection::New(str_proj_type, params_proj));
205  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj.get(), params_smear));
206 
207  unique_ptr<ForceSmear> force_smear(ForceSmear::New(str_smear_type, proj.get(), params_smear));
208 
209  unique_ptr<Director_Smear> dr_smear(new Director_Smear(smear.get(), params_dr_smear));
210 
211 
212  //-- N_f=2 part
213  unique_ptr<Fopr> fopr_Nf2(Fopr::New(str_fopr_Nf2_type, params_fopr_Nf2));
214 
215  unique_ptr<Force> force_fopr_Nf2(new Force_F_Clover_Nf2(params_fopr_Nf2));
216 
217  unique_ptr<Fopr> fopr_smear_Nf2(Fopr::New("Smeared", fopr_Nf2.get(), dr_smear.get()));
218  unique_ptr<Force> force_fopr_smear_Nf2(new Force_F_Smeared(force_fopr_Nf2.get(), force_smear.get(), dr_smear.get()));
219 
220  unique_ptr<Solver> solver_Nf2_MD(Solver::New(str_solver_Nf2_MD_type, fopr_smear_Nf2.get(), params_solver_Nf2_MD));
221  unique_ptr<Fprop> fprop_Nf2_MD(new Fprop_Standard_lex(solver_Nf2_MD.get()));
222 
223  unique_ptr<Solver> solver_Nf2_H(Solver::New(str_solver_Nf2_H_type, fopr_smear_Nf2.get(), params_solver_Nf2_H));
224  unique_ptr<Fprop> fprop_Nf2_H(new Fprop_Standard_lex(solver_Nf2_H.get()));
225 
226 
227  //-- N_f=2 part (preconditioner)
228  unique_ptr<Fopr> fopr_Nf2_prec(Fopr::New(str_fopr_Nf2_prec_type, params_fopr_Nf2_prec));
229 
230  unique_ptr<Force> force_fopr_Nf2_prec(new Force_F_Clover_Nf2(params_fopr_Nf2_prec));
231 
232  unique_ptr<Fopr> fopr_smear_Nf2_prec(Fopr::New("Smeared", fopr_Nf2_prec.get(), dr_smear.get()));
233  unique_ptr<Force> force_fopr_smear_Nf2_prec(new Force_F_Smeared(force_fopr_Nf2_prec.get(), force_smear.get(), dr_smear.get()));
234 
235  unique_ptr<Solver> solver_Nf2_MD_prec(Solver::New(str_solver_Nf2_MD_prec_type, fopr_smear_Nf2_prec.get(), params_solver_Nf2_MD_prec));
236  unique_ptr<Fprop> fprop_Nf2_MD_prec(new Fprop_Standard_lex(solver_Nf2_MD_prec.get()));
237 
238  unique_ptr<Solver> solver_Nf2_H_prec(Solver::New(str_solver_Nf2_H_prec_type, fopr_smear_Nf2_prec.get(), params_solver_Nf2_H_prec));
239  unique_ptr<Fprop> fprop_Nf2_H_prec(new Fprop_Standard_lex(solver_Nf2_H_prec.get()));
240 
241 
242  unique_ptr<Action> action_F_Nf2_prec(new Action_F_Standard_lex(fopr_smear_Nf2_prec.get(), force_fopr_smear_Nf2_prec.get(), fprop_Nf2_MD_prec.get(), fprop_Nf2_H_prec.get()));
243 
244  unique_ptr<Action> action_F_Nf2_d(new Action_F_Ratio_lex(fopr_smear_Nf2_prec.get(), force_fopr_smear_Nf2_prec.get(), fopr_smear_Nf2.get(), force_fopr_smear_Nf2.get(), fprop_Nf2_H_prec.get(), fprop_Nf2_MD.get(), fprop_Nf2_H.get()));
245 
246 
247  //-- N_f=1 part
248  unique_ptr<Fopr> fopr_Nf1(Fopr::New(str_fopr_Nf1_type, params_fopr_Nf1));
249 
250  //- NB. create Force_F_Nf2, then apply rational approximation
251  unique_ptr<Force> force_fopr_Nf1(new Force_F_Clover_Nf2(params_fopr_Nf1));
252 
253  //- NB. Langevin needs params_rational_H
254  unique_ptr<Fopr> fopr_r1(Fopr::New("Rational", fopr_Nf1.get(), params_rational_H));
255  unique_ptr<Fopr> fopr_smear_Nf1_langev(Fopr::New("Smeared", fopr_r1.get(), dr_smear.get()));
256 
257  //- NB. Hamiltonian needs params_rational_MD
258  unique_ptr<Fopr> fopr_r2(Fopr::New("Rational", fopr_Nf1.get(), params_rational_MD));
259  unique_ptr<Fopr> fopr_smear_Nf1_H(Fopr::New("Smeared", fopr_r2.get(), dr_smear.get()));
260 
261  unique_ptr<Force> force_fopr_Nf1_MD(new Force_F_Rational(fopr_Nf1.get(), force_fopr_Nf1.get(), params_rational_MD));
262  unique_ptr<Force> force_fopr_smear_Nf1_MD(new Force_F_Smeared(force_fopr_Nf1_MD.get(), force_smear.get(), dr_smear.get()));
263 
264 
265  unique_ptr<Action> action_F_Nf1(new Action_F_Rational(fopr_smear_Nf1_langev.get(), fopr_smear_Nf1_H.get(), force_fopr_smear_Nf1_MD.get()));
266 
267 
268  ActionList actions(Nlevels);
269  actions.append(level_action[0], action_F_Nf2_d.get());
270  actions.append(level_action[1], action_F_Nf2_prec.get());
271  actions.append(level_action[2], action_F_Nf1.get());
272  actions.append(level_action[3], action_G.get());
273 
274  std::vector<Director *> directors(1);
275  directors[0] = static_cast<Director *>(dr_smear.get());
276 
277  unique_ptr<Builder_Integrator> builder(new Builder_Integrator(actions, directors, params_integrator));
278  Integrator *integrator = builder->build();
279 
280  //- Random number is initialized with a parameter specified by i_conf
281  unique_ptr<RandomNumbers> rand(new RandomNumbers_Mseries(i_conf));
282 
283  HMC_General hmc(actions, directors, integrator, rand.get(), params_hmc);
284 
285  Timer timer(test_name);
286 
287 
288  // #### Execution main part ####
289  timer.start();
290 
291  vout.general(vl, "HMC start: Ntraj = %d\n", Ntraj);
292 
293  double result = 0.0;
294  for (int traj = 0; traj < Ntraj; ++traj) {
295  vout.general(vl, "\n");
296  vout.general(vl, "---------------------------------------------------\n");
297  vout.general(vl, "traj = %d\n", traj);
298 
299  result = hmc.update(U);
300 
301  if ((i_conf + traj + 1) % i_save_conf == 0) {
302  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
303  gconf_write.write_file(U, filename);
304  }
305  }
306 
307  gconf_write.write_file(U, writefile);
308 
309  timer.report();
310 
312 
313 
314  if (do_check) {
315  return Test::verify(result, expected_result);
316  } else {
317  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
318  return EXIT_SKIP;
319  }
320  }
321 } // namespace Test_HMC_Clover
Test::verify
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
randomNumbers_Mseries.h
action_F_Rational.h
ParameterCheck::non_NULL
int non_NULL(const std::string v)
Definition: parameterCheck.cpp:65
Fprop_Standard_lex
Get quark propagator for Fopr with lexical site index.
Definition: fprop_Standard_lex.h:33
HMC_General::update
double update(Field_G &)
Definition: hmc_General.cpp:196
CommonParameters::Ndim
static int Ndim()
Definition: commonParameters.h:117
Parameters
Class for parameters.
Definition: parameters.h:46
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::write_file
void write_file(Field_G &U, const string &filename)
Definition: gaugeConfig.h:103
fprop_Standard_lex.h
gaugeConfig.h
CommonParameters::Nvol
static int Nvol()
Definition: commonParameters.h:109
Force_F_Smeared
Force calculation for smeared fermion operators.
Definition: force_F_Smeared.h:39
action_F_Ratio_lex.h
action_F_Standard_lex.h
Action_F_Rational
action class for RHMC, with externally constructed Fopr_Rational.
Definition: action_F_Rational.h:37
ParameterCheck::non_negative
int non_negative(const int v)
Definition: parameterCheck.cpp:21
force_F_Smeared.h
Parameters::get_int_vector
vector< int > get_int_vector(const string &key) const
Definition: parameters.cpp:267
Timer
Definition: timer.h:31
RandomNumberManager::finalize
static void finalize()
Definition: randomNumberManager.cpp:80
builder_Integrator.h
ActionList
lists of actions at respective integrator levels.
Definition: action_list.h:40
RandomNumberManager::initialize
static bool initialize(const std::string &rng_type, unsigned long seed)
Definition: randomNumberManager.cpp:57
Test_HMC_Clover::RHMC_Nf2p1
int RHMC_Nf2p1(void)
Definition: test_HMC_Clover_RHMC_Nf2p1.cpp:80
Builder_Integrator
Builder of MD integrator for HMC.
Definition: builder_Integrator.h:39
Timer::start
void start()
Definition: timer.cpp:44
CommonParameters::Nc
static int Nc()
Definition: commonParameters.h:115
hmc_General.h
Force_F_Clover_Nf2
Force calculation for clover quark action.
Definition: force_F_Clover_Nf2.h:35
ParameterCheck::vl
Bridge::VerboseLevel vl
Definition: parameterCheck.cpp:18
RandomNumbers_Mseries
Random number generator base on M-series.
Definition: randomNumbers_Mseries.h:46
file_utils.h
test.h
force_F_Clover_Nf2.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_HMC_Clover::test_name
const std::string test_name
Definition: test_HMC_Clover_Nf2.cpp:52
Director_Smear
Manager of smeared configurations.
Definition: director_Smear.h:39
Parameters::get_unsigned_long
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:209
HMC_General
General HMC update class.
Definition: hmc_General.h:45
EXIT_SKIP
#define EXIT_SKIP
Definition: test.h:17
ActionList::append
bool append(const int level, Action *action)
Definition: action_list.cpp:27
FileUtils::generate_filename
std::string generate_filename(const char *fmt,...)
Definition: file_utils.cpp:17
randomNumberManager.h
GaugeConfig
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:80
Bridge::BridgeIO::set_verbose_level
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:133
Parameters::is_set
bool is_set(const string &key) const
Definition: parameters.cpp:525
Director
Manager of commonly used data object in HMC.
Definition: director.h:37
fopr_Smeared.h
Parameters::get_string
string get_string(const string &key) const
Definition: parameters.cpp:221
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Test_HMC_Clover
Test of HMC update for clover fermions.
Definition: test_HMC_Clover_Nf2.cpp:51
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42
Action_F_Ratio_lex
HMC action for Hasenbusch preconditioned fermions.
Definition: action_F_Ratio_lex.h:42
Field_G
SU(N) gauge field.
Definition: field_G.h:38
Integrator
Base class of Integrator class family.
Definition: integrator.h:29
Force_F_Rational
Force calculation for smeared fermion operators.
Definition: force_F_Rational.h:39
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
Action_F_Standard_lex
Standard fermion action for HMC.
Definition: action_F_Standard_lex.h:37
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