Bridge++  Ver. 2.0.2
test_HMC_Clover_RHMC_Nf2p1_eo.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
19 
20 #include "Fopr/fopr_Clover_eo.h"
21 #include "Fopr/fopr_Smeared_eo.h"
22 #include "Fopr/fopr_Smeared.h"
23 
26 
27 #include "HMC/hmc_General.h"
28 #include "HMC/builder_Integrator.h"
29 
30 #include "IO/gaugeConfig.h"
31 
33 
34 #include "Tools/file_utils.h"
37 
38 //====================================================================
40 
57 namespace Test_HMC_Clover {
58  const std::string test_name = "HMC.Clover.RHMC_Nf2p1_eo";
59 
60  //- test-private parameters
61  namespace {
62  const std::string filename_input = "test_HMC_Clover_RHMC_Nf2p1.yaml";
63  }
64 
65  //- prototype declaration
66  int RHMC_Nf2p1_eo(void);
67 
68 #ifdef USE_TESTMANAGER_AUTOREGISTER
69  namespace {
70 #if defined(USE_GROUP_SU2)
71  // Nc=2 is not available.
72 #else
73  static const bool is_registered = TestManager::RegisterTest(
74  test_name,
76  );
77 #endif
78  }
79 #endif
80 
81  //====================================================================
82  int RHMC_Nf2p1_eo(void)
83  {
84  // ##### parameter setup #####
85  const int Nc = CommonParameters::Nc();
86  const int Nvol = CommonParameters::Nvol();
87  const int Ndim = CommonParameters::Ndim();
88 
89  const Parameters params_all = ParameterManager::read(filename_input);
90 
91  const Parameters params_test = params_all.lookup("Test_HMC_Clover");
92  const Parameters params_action_G = params_all.lookup("Action_G");
93  const Parameters params_fopr_Nf2 = params_all.lookup("Fopr_Nf2");
94  const Parameters params_fopr_Nf2_prec = params_all.lookup("Fopr_Nf2_prec");
95  const Parameters params_fopr_Nf1 = params_all.lookup("Fopr_Nf1");
96  const Parameters params_proj = params_all.lookup("Projection");
97  const Parameters params_smear = params_all.lookup("Smear");
98  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
99  const Parameters params_rational_MD = params_all.lookup("Fopr_Rational_MD");
100  const Parameters params_rational_H = params_all.lookup("Fopr_Rational_H");
101  const Parameters params_solver_Nf2_MD = params_all.lookup("Solver_Nf2_MD");
102  const Parameters params_solver_Nf2_H = params_all.lookup("Solver_Nf2_H");
103  const Parameters params_solver_Nf2_MD_prec = params_all.lookup("Solver_Nf2_MD_prec");
104  const Parameters params_solver_Nf2_H_prec = params_all.lookup("Solver_Nf2_H_prec");
105  const Parameters params_integrator = params_all.lookup("Builder_Integrator");
106  const Parameters params_hmc = params_all.lookup("HMC_General");
107 
108  const string str_gconf_status = params_test.get_string("gauge_config_status");
109  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
110  const string readfile = params_test.get_string("config_filename_input");
111  const string str_gconf_write = params_test.get_string("gauge_config_type_output");
112  const string writefile = params_test.get_string("config_filename_output");
113  const string str_rand_type = params_test.get_string("random_number_type");
114  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
115  int i_conf = params_test.get_int("trajectory_number");
116  const int Ntraj = params_test.get_int("trajectory_number_step");
117  const int i_save_conf = params_test.get_int("save_config_interval");
118  const string str_vlevel = params_test.get_string("verbose_level");
119 
120  const bool do_check = params_test.is_set("expected_result");
121  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
122 
123  const string str_action_G_type = params_action_G.get_string("action_type");
124  const string str_fopr_Nf2_type = params_fopr_Nf2.get_string("fermion_type");
125  const string str_fopr_Nf2_prec_type = params_fopr_Nf2_prec.get_string("fermion_type");
126  const string str_fopr_Nf1_type = params_fopr_Nf1.get_string("fermion_type");
127  const string str_gmset_type = params_fopr_Nf2.get_string("gamma_matrix_type");
128  const string str_proj_type = params_proj.get_string("projection_type");
129  const string str_smear_type = params_smear.get_string("smear_type");
130  // const int Nsmear = params_dr_smear.get_int("number_of_smearing");
131  const string str_solver_Nf2_MD_type = params_solver_Nf2_MD.get_string("solver_type");
132  const string str_solver_Nf2_H_type = params_solver_Nf2_H.get_string("solver_type");
133  const string str_solver_Nf2_MD_prec_type = params_solver_Nf2_MD_prec.get_string("solver_type");
134  const string str_solver_Nf2_H_prec_type = params_solver_Nf2_H_prec.get_string("solver_type");
135  const int Nlevels = params_integrator.get_int("number_of_levels");
136  const std::vector<int> level_action = params_integrator.get_int_vector("level_of_actions");
137 
138  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
139 
140  //- print input parameters
141  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
142  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
143  vout.general(vl, " readfile = %s\n", readfile.c_str());
144  vout.general(vl, " gconf_write = %s\n", str_gconf_write.c_str());
145  vout.general(vl, " writefile = %s\n", writefile.c_str());
146  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
147  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
148  vout.general(vl, " seed = %lu\n", seed);
149  vout.general(vl, " i_conf = %d\n", i_conf);
150  vout.general(vl, " Ntraj = %d\n", Ntraj);
151  vout.general(vl, " i_save_conf = %d\n", i_save_conf);
152  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
153  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
154  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
155  vout.general(vl, " solver_Nf2_MD_type = %s\n", str_solver_Nf2_MD_type.c_str());
156  vout.general(vl, " solver_Nf2_H_type = %s\n", str_solver_Nf2_H_type.c_str());
157  vout.general(vl, " solver_Nf2_MD_prec_type = %s\n", str_solver_Nf2_MD_prec_type.c_str());
158  vout.general(vl, " solver_Nf2_H_prec_type = %s\n", str_solver_Nf2_H_prec_type.c_str());
159  vout.general(vl, "\n");
160 
161  //- input parameter check
162  int err = 0;
163  err += ParameterCheck::non_NULL(str_gconf_status);
164  err += ParameterCheck::non_negative(i_conf);
165  err += ParameterCheck::non_negative(Ntraj);
166  err += ParameterCheck::non_negative(i_save_conf);
167 
168  if (err) {
169  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
170  exit(EXIT_FAILURE);
171  }
172 
173  if ((str_solver_Nf2_MD_type == "CG") || (str_solver_Nf2_H_type == "CG") ||
174  (str_solver_Nf2_MD_prec_type == "CG") || (str_solver_Nf2_H_prec_type == "CG")) {
175  vout.crucial(vl, "Error at %s: CG can not be adopted. Use CGNE,CGNR, instead.\n", test_name.c_str());
176  exit(EXIT_FAILURE);
177  }
178 
179  // if ( (Nsmear > 0) && (str_proj_type == "Stout_SU3") ) {
180  if (str_proj_type == "Stout_SU3") {
181  if (CommonParameters::Nc() != 3) {
182  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
183  return EXIT_SKIP;
184  }
185  }
186 
187 
188  RandomNumberManager::initialize(str_rand_type, seed);
189 
190 
191  // ##### object setup #####
192  Field_G U(Nvol, Ndim);
193 
194  if (str_gconf_status == "Continue") {
195  GaugeConfig(str_gconf_read).read(U, readfile);
196  } else if (str_gconf_status == "Cold_start") {
197  GaugeConfig("Unit").read(U);
198  } else if (str_gconf_status == "Hot_start") {
199  GaugeConfig("Random").read(U);
200  } else {
201  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
202  exit(EXIT_FAILURE);
203  }
204 
205  GaugeConfig gconf_write(str_gconf_write);
206 
207 
208  unique_ptr<Action> action_G(Action::New(str_action_G_type, params_action_G));
209 
210 
211  //-- smear part
212  unique_ptr<Projection> proj(Projection::New(str_proj_type, params_proj));
213  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj.get(), params_smear));
214 
215  unique_ptr<ForceSmear> force_smear(ForceSmear::New(str_smear_type, proj.get(), params_smear));
216 
217  unique_ptr<Director_Smear> dr_smear(new Director_Smear(smear.get(), params_dr_smear));
218 
219 
220  //-- N_f=2 part
221  unique_ptr<Fopr> fopr_Nf2(Fopr::New(str_fopr_Nf2_type, params_fopr_Nf2));
222 
223  unique_ptr<Force> force_fopr_Nf2(new Force_F_Clover_Nf2(params_fopr_Nf2));
224 
225  unique_ptr<Fopr> fopr_smear_Nf2(Fopr::New("Smeared", fopr_Nf2.get(), dr_smear.get()));
226  unique_ptr<Force> force_fopr_smear_Nf2(new Force_F_Smeared(force_fopr_Nf2.get(), force_smear.get(), dr_smear.get()));
227 
228  //- NB1 fopr_Nf2_eo->set_config is performed in Action_F_Standard_eo.
229  // NB2 fopr_Nf2_eo->set_mode is performed in fprop.
230  unique_ptr<Fopr> fopr_Nf2_eo(Fopr::New(str_fopr_Nf2_type + "_eo", params_fopr_Nf2));
231 
232  unique_ptr<Fopr> fopr_smear_Nf2_eo(Fopr::New("Smeared_eo", fopr_Nf2_eo.get(), dr_smear.get()));
233 
234  unique_ptr<Solver> solver_Nf2_eo_MD(Solver::New(str_solver_Nf2_MD_type, fopr_smear_Nf2_eo.get(), params_solver_Nf2_MD));
235  unique_ptr<Fprop> fprop_Nf2_eo_MD(new Fprop_Standard_eo(solver_Nf2_eo_MD.get()));
236 
237  unique_ptr<Solver> solver_Nf2_eo_H(Solver::New(str_solver_Nf2_H_type, fopr_smear_Nf2_eo.get(), params_solver_Nf2_H));
238  unique_ptr<Fprop> fprop_Nf2_eo_H(new Fprop_Standard_eo(solver_Nf2_eo_H.get()));
239 
240  //-- N_f=2 part (preconditioner)
241  unique_ptr<Fopr> fopr_Nf2_prec(Fopr::New(str_fopr_Nf2_prec_type, params_fopr_Nf2_prec));
242 
243  unique_ptr<Force> force_fopr_Nf2_prec(new Force_F_Clover_Nf2(params_fopr_Nf2_prec));
244 
245  unique_ptr<Fopr> fopr_smear_Nf2_prec(Fopr::New("Smeared", fopr_Nf2_prec.get(), dr_smear.get()));
246  unique_ptr<Force> force_fopr_smear_Nf2_prec(new Force_F_Smeared(force_fopr_Nf2_prec.get(), force_smear.get(), dr_smear.get()));
247 
248  //- NB1 fopr_Nf2_eo_prec->set_config is performed in Action_F_Standard_eo.
249  // NB2 fopr_Nf2_eo_prec->set_mode is performed in fprop.
250  unique_ptr<Fopr> fopr_Nf2_eo_prec(Fopr::New(str_fopr_Nf2_prec_type + "_eo", params_fopr_Nf2_prec));
251 
252  unique_ptr<Fopr> fopr_smear_Nf2_eo_prec(Fopr::New("Smeared_eo", fopr_Nf2_eo_prec.get(), dr_smear.get()));
253 
254  unique_ptr<Solver> solver_Nf2_eo_MD_prec(Solver::New(str_solver_Nf2_MD_type, fopr_smear_Nf2_eo_prec.get(), params_solver_Nf2_MD));
255  unique_ptr<Fprop> fprop_Nf2_eo_MD_prec(new Fprop_Standard_eo(solver_Nf2_eo_MD_prec.get()));
256 
257  unique_ptr<Solver> solver_Nf2_eo_H_prec(Solver::New(str_solver_Nf2_H_type, fopr_smear_Nf2_eo_prec.get(), params_solver_Nf2_H));
258  unique_ptr<Fprop> fprop_Nf2_eo_H_prec(new Fprop_Standard_eo(solver_Nf2_eo_H_prec.get()));
259 
260 
261  unique_ptr<Action> action_F_Nf2_prec(new Action_F_Standard_eo(fopr_smear_Nf2_prec.get(), force_fopr_smear_Nf2_prec.get(), fprop_Nf2_eo_MD_prec.get(), fprop_Nf2_eo_H_prec.get()));
262 
263  unique_ptr<Action> action_F_Nf2_d(new Action_F_Ratio_eo(fopr_smear_Nf2_prec.get(), force_fopr_smear_Nf2_prec.get(), fopr_smear_Nf2.get(), force_fopr_smear_Nf2.get(), fprop_Nf2_eo_H_prec.get(), fprop_Nf2_eo_MD.get(), fprop_Nf2_eo_H.get()));
264 
265  //-- N_f=1 part
266  unique_ptr<Fopr> fopr_Nf1(Fopr::New(str_fopr_Nf1_type, params_fopr_Nf1));
267 
268  //- NB. create Force_F_Nf2, then apply rational approximation
269  unique_ptr<Force> force_fopr_Nf1(new Force_F_Clover_Nf2(params_fopr_Nf1));
270 
271  //- NB. Langevin needs params_rational_H
272  unique_ptr<Fopr> fopr_r1(Fopr::New("Rational", fopr_Nf1.get(), params_rational_H));
273  unique_ptr<Fopr> fopr_smear_Nf1_langev(Fopr::New("Smeared", fopr_r1.get(), dr_smear.get()));
274 
275  //- NB. Hamiltonian needs params_rational_MD
276  unique_ptr<Fopr> fopr_r2(Fopr::New("Rational", fopr_Nf1.get(), params_rational_MD));
277  unique_ptr<Fopr> fopr_smear_Nf1_H(Fopr::New("Smeared", fopr_r2.get(), dr_smear.get()));
278 
279  unique_ptr<Force> force_fopr_Nf1_MD(new Force_F_Rational(fopr_Nf1.get(), force_fopr_Nf1.get(), params_rational_MD));
280  unique_ptr<Force> force_fopr_smear_Nf1_MD(new Force_F_Smeared(force_fopr_Nf1_MD.get(), force_smear.get(), dr_smear.get()));
281 
282 
283  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()));
284 
285 
286  ActionList actions(Nlevels);
287  actions.append(level_action[0], action_F_Nf2_d.get());
288  actions.append(level_action[1], action_F_Nf2_prec.get());
289  actions.append(level_action[2], action_F_Nf1.get());
290  actions.append(level_action[3], action_G.get());
291 
292  std::vector<Director *> directors(1);
293  directors[0] = static_cast<Director *>(dr_smear.get());
294 
295  unique_ptr<Builder_Integrator> builder(new Builder_Integrator(actions, directors, params_integrator));
296  Integrator *integrator = builder->build();
297 
298 
299  //- Random number is initialized with a parameter specified by i_conf
300  unique_ptr<RandomNumbers> rand(new RandomNumbers_Mseries(i_conf));
301 
302 
303  HMC_General hmc(actions, directors, integrator, rand.get(), params_hmc);
304 
305  Timer timer(test_name);
306 
307 
308  // #### Execution main part ####
309  timer.start();
310 
311  vout.general(vl, "HMC start: Ntraj = %d\n", Ntraj);
312 
313  double result = 0.0;
314  for (int traj = 0; traj < Ntraj; ++traj) {
315  vout.general(vl, "\n");
316  vout.general(vl, "---------------------------------------------------\n");
317  vout.general(vl, "traj = %d\n", traj);
318 
319  result = hmc.update(U);
320 
321  if ((i_conf + traj + 1) % i_save_conf == 0) {
322  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
323  gconf_write.write_file(U, filename);
324  }
325  }
326 
327  gconf_write.write_file(U, writefile);
328 
329  timer.report();
330 
332 
333 
334  if (do_check) {
335  return Test::verify(result, expected_result);
336  } else {
337  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
338  return EXIT_SKIP;
339  }
340  }
341 } // 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
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
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_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
fprop_Standard_eo.h
RandomNumberManager::initialize
static bool initialize(const std::string &rng_type, unsigned long seed)
Definition: randomNumberManager.cpp:57
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::RHMC_Nf2p1_eo
int RHMC_Nf2p1_eo(void)
Definition: test_HMC_Clover_RHMC_Nf2p1_eo.cpp:82
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
Action_F_Ratio_eo
HMC action for Hasenbusch preconditioned fermions.
Definition: action_F_Ratio_eo.h:41
FileUtils::generate_filename
std::string generate_filename(const char *fmt,...)
Definition: file_utils.cpp:17
randomNumberManager.h
action_F_Ratio_eo.h
fopr_Clover_eo.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
Action_F_Standard_eo
Standard even-odd preconditioned fermion action for HMC.
Definition: action_F_Standard_eo.h:37
Fprop_Standard_eo
Get quark propagator for Fopr with even-odd site index.
Definition: fprop_Standard_eo.h:38
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
fopr_Smeared_eo.h
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42
Field_G
SU(N) gauge field.
Definition: field_G.h:38
action_F_Standard_eo.h
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
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