Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_HMC_Clover_Nf2_eo.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
17 
18 #include "Fopr/fopr_Clover_eo.h"
19 #include "Fopr/fopr_Smeared_eo.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 
31 
32 #include "Tools/file_utils.h"
35 
36 //====================================================================
38 
55 namespace Test_HMC_Clover {
56  const std::string test_name = "HMC.Clover.Nf2_eo";
57 
58  //- test-private parameters
59  namespace {
60  const std::string filename_input = "test_HMC_Clover_Nf2.yaml";
61  }
62 
63  //- prototype declaration
64  int update_Nf2_eo(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 update_Nf2_eo(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 = params_all.lookup("Fopr");
92  const Parameters params_proj = params_all.lookup("Projection");
93  const Parameters params_smear = params_all.lookup("Smear");
94  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
95  const Parameters params_solver_MD = params_all.lookup("Solver_MD");
96  const Parameters params_solver_H = params_all.lookup("Solver_H");
97  const Parameters params_integrator = params_all.lookup("Builder_Integrator");
98  const Parameters params_hmc = params_all.lookup("HMC_General");
99 
100  const string str_gconf_status = params_test.get_string("gauge_config_status");
101  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
102  const string readfile = params_test.get_string("config_filename_input");
103  const string str_gconf_write = params_test.get_string("gauge_config_type_output");
104  const string writefile = params_test.get_string("config_filename_output");
105  const string str_rand_type = params_test.get_string("random_number_type");
106  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
107  int i_conf = params_test.get_int("trajectory_number");
108  const int Ntraj = params_test.get_int("trajectory_number_step");
109  const int i_save_conf = params_test.get_int("save_config_interval");
110  const string str_vlevel = params_test.get_string("verbose_level");
111 
112  const bool do_check = params_test.is_set("expected_result");
113  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
114 
115  const string str_action_G_type = params_action_G.get_string("action_type");
116  const string str_fopr_type = params_fopr.get_string("fermion_type");
117  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
118  const string str_proj_type = params_proj.get_string("projection_type");
119  const string str_smear_type = params_smear.get_string("smear_type");
120  const string str_solver_MD_type = params_solver_MD.get_string("solver_type");
121  const string str_solver_H_type = params_solver_H.get_string("solver_type");
122  const int Nlevels = params_integrator.get_int("number_of_levels");
123  const std::vector<int> level_action = params_integrator.get_int_vector("level_of_actions");
124 
125  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
126 
127  //- print input parameters
128  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
129  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
130  vout.general(vl, " readfile = %s\n", readfile.c_str());
131  vout.general(vl, " gconf_write = %s\n", str_gconf_write.c_str());
132  vout.general(vl, " writefile = %s\n", writefile.c_str());
133  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
134  vout.general(vl, " seed = %lu\n", seed);
135  vout.general(vl, " i_conf = %d\n", i_conf);
136  vout.general(vl, " Ntraj = %d\n", Ntraj);
137  vout.general(vl, " i_save_conf = %d\n", i_save_conf);
138  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
139  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
140  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
141  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
142  vout.general(vl, " solver_MD_type = %s\n", str_solver_MD_type.c_str());
143  vout.general(vl, " solver_H_type = %s\n", str_solver_H_type.c_str());
144  vout.general(vl, "\n");
145 
146  //- input parameter check
147  int err = 0;
148  err += ParameterCheck::non_NULL(str_gconf_status);
149  err += ParameterCheck::non_negative(i_conf);
150  err += ParameterCheck::non_negative(Ntraj);
151  err += ParameterCheck::non_negative(i_save_conf);
152 
153  if (err) {
154  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
155  exit(EXIT_FAILURE);
156  }
157 
158  if ((str_solver_MD_type == "CG") || (str_solver_H_type == "CG")) {
159  vout.crucial(vl, "Error at %s: CG can not be adopted. Use CGNE,CGNR, instead.\n", test_name.c_str());
160  exit(EXIT_FAILURE);
161  }
162 
163  RandomNumberManager::initialize(str_rand_type, seed);
164 
165 
166  // ##### object setup #####
167  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
168 
169  if (str_gconf_status == "Continue") {
170  GaugeConfig(str_gconf_read).read(U, readfile);
171  } else if (str_gconf_status == "Cold_start") {
172  GaugeConfig("Unit").read(U);
173  } else if (str_gconf_status == "Hot_start") {
174  GaugeConfig("Random").read(U);
175  } else {
176  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
177  exit(EXIT_FAILURE);
178  }
179 
180  const unique_ptr<GaugeConfig> gconf_write(new GaugeConfig(str_gconf_write));
181 
182 
183  unique_ptr<Action> action_G(Action::New(str_action_G_type));
184  action_G->set_parameters(params_action_G);
185 
186  //-- N_f=2 part
187  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
188  fopr->set_parameters(params_fopr);
189 
190  unique_ptr<Force> force_fopr(new Force_F_Clover_Nf2(str_gmset_type));
191  // define fermion force (SA)
192  force_fopr->set_parameters(params_fopr);
193 
194  // define smearing method (SA)
195  unique_ptr<Projection> proj(Projection::New(str_proj_type));
196  proj->set_parameters(params_proj);
197 
198  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
199  smear->set_parameters(params_smear);
200 
201  // define force smearing method (SA)
202  unique_ptr<ForceSmear> force_smear(ForceSmear::New(str_smear_type, proj));
203  force_smear->set_parameters(params_smear);
204 
205  unique_ptr<Director> dr_smear(new Director_Smear(smear));
206  dr_smear->set_parameters(params_dr_smear);
207 
208  unique_ptr<Fopr> fopr_smear(Fopr::New("Smeared", fopr, dr_smear));
209  // define smeared fermion operator (SA)
210  unique_ptr<Force> force_fopr_smear(
211  new Force_F_Smeared(force_fopr, force_smear, dr_smear));
212  // define smeared fermion force (SA)
213 
214  //- NB1 fopr_eo->set_config is performed in Action_F_Standard_eo.
215  // NB2 fopr_eo->set_mode is performed in fprop.
216  unique_ptr<Fopr> fopr_eo(Fopr::New(str_fopr_type + "_eo", str_gmset_type));
217  fopr_eo->set_parameters(params_fopr);
218 
219  unique_ptr<Fopr> fopr_smear_eo(Fopr::New("Smeared_eo", fopr_eo, dr_smear));
220 
221  unique_ptr<Solver> solver_eo_MD(Solver::New(str_solver_MD_type, fopr_smear_eo));
222  solver_eo_MD->set_parameters(params_solver_MD);
223  unique_ptr<Fprop> fprop_eo_MD(new Fprop_Standard_eo(solver_eo_MD));
224 
225  unique_ptr<Solver> solver_eo_H(Solver::New(str_solver_H_type, fopr_smear_eo));
226  solver_eo_H->set_parameters(params_solver_H);
227  unique_ptr<Fprop> fprop_eo_H(new Fprop_Standard_eo(solver_eo_H));
228 
229  unique_ptr<Action> action_F(
230  new Action_F_Standard_eo(fopr_smear, force_fopr_smear,
231  fprop_eo_MD, fprop_eo_H));
232  // define fermion action (SA)
233 
234 
235  ActionList actions(Nlevels);
236  actions.append(level_action[0], action_F);
237  actions.append(level_action[1], action_G);
238 
239  std::vector<Director *> directors(1);
240  directors[0] = (Director *)dr_smear.get(); // register director[0] (SA)
241 
242  const unique_ptr<Builder_Integrator> builder(new Builder_Integrator(actions, directors));
243  builder->set_parameters(params_integrator);
244  Integrator *integrator = builder->build();
245 
246  //- Random number is initialized with a parameter specified by i_conf
248 
249  HMC_General hmc(actions, directors, integrator, rand); // define hmc_leapfrog (SA)
250  hmc.set_parameters(params_hmc);
251 
252  const unique_ptr<Timer> timer(new Timer(test_name));
253 
254 
255  // #### Execution main part ####
256  timer->start();
257 
258  vout.general(vl, "HMC: Ntraj = %d\n", Ntraj); // a number of trajectory (SA)
259 
260  double result = 0.0;
261  for (int traj = 0; traj < Ntraj; ++traj) {
262  vout.general(vl, "\n");
263  vout.general(vl, "traj = %d\n", traj);
264 
265  result = hmc.update(*U); // hmc update (SA)
266 
267  if ((i_conf + traj + 1) % i_save_conf == 0) {
268  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
269  gconf_write->write_file(U, filename);
270  }
271  }
272 
273  gconf_write->write_file(U, writefile);
274 
275  timer->report();
276 
278 
279 
280  if (do_check) {
281  return Test::verify(result, expected_result);
282  } else {
283  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
284  return EXIT_SKIP;
285  }
286  }
287 } // namespace Test_HMC_Clover
#define EXIT_SKIP
Definition: test.h:17
Random number generator base on M-series.
BridgeIO vout
Definition: bridgeIO.cpp:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
Standard even-odd preconditioned fermion action for HMC.
virtual void set_parameters(const Parameters &param)=0
void set_parameters(const Parameters &params)
void general(const char *format,...)
Definition: bridgeIO.cpp:197
General HMC update class.
Definition: hmc_General.h:45
virtual void set_parameters(const Parameters &)=0
int get_int(const string &key) const
Definition: parameters.cpp:192
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
virtual void set_parameters(const Parameters &params)=0
Parameters lookup(const string &key) const
Definition: parameters.h:79
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:209
double get_double(const string &key) const
Definition: parameters.cpp:175
std::string generate_filename(const char *fmt,...)
Definition: file_utils.cpp:17
Get quark propagator for Fopr with even-odd site index.
Force calculation for clover quark action.
pointer get() const
virtual void set_parameters(const Parameters &)=0
int non_NULL(const std::string v)
bool is_set(const string &key) const
Definition: parameters.cpp:528
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)
const std::string test_name
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
VerboseLevel
Definition: bridgeIO.h:42
double update(Field_G &)
void write_file(Field_G *U, const string &filename)
Definition: gaugeConfig.h:109
Force calculation for smeared fermion operators.
int non_negative(const int v)
virtual void set_parameters(const Parameters &)=0
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:78
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:221
vector< int > get_int_vector(const string &key) const
Definition: parameters.cpp:267
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.
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131