Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_HMC_Wilson_Leapfrog_Nf2.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
17 
18 #include "Fopr/fopr_Smeared.h"
19 
22 
23 #include "HMC/hmc_Leapfrog.h"
24 
25 #include "IO/gaugeConfig.h"
26 
28 
29 #include "Tools/file_utils.h"
32 
33 //====================================================================
35 
49 namespace Test_HMC_Wilson {
50  const std::string test_name = "HMC.Wilson.Leapfrog_Nf2";
51 
52  //- test-private parameters
53  namespace {
54  const std::string filename_input = "test_HMC_Wilson_Leapfrog_Nf2.yaml";
55  }
56 
57  //- prototype declaration
58  int leapfrog_Nf2(void);
59 
60 #ifdef USE_TESTMANAGER_AUTOREGISTER
61  namespace {
62 #if defined(USE_GROUP_SU2)
63  // Nc=2 is not available.
64 #else
65  static const bool is_registered = TestManager::RegisterTest(
66  test_name,
68  );
69 #endif
70  }
71 #endif
72 
73  //====================================================================
74  int leapfrog_Nf2(void)
75  {
76  // ##### parameter setup #####
77  const int Nc = CommonParameters::Nc();
78  const int Nvol = CommonParameters::Nvol();
79  const int Ndim = CommonParameters::Ndim();
80 
81  const Parameters params_all = ParameterManager::read(filename_input);
82 
83  const Parameters params_test = params_all.lookup("Test_HMC_Wilson");
84  const Parameters params_action_G = params_all.lookup("Action_G");
85  const Parameters params_fopr = params_all.lookup("Fopr");
86  const Parameters params_proj = params_all.lookup("Projection");
87  const Parameters params_smear = params_all.lookup("Smear");
88  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
89  const Parameters params_solver_MD = params_all.lookup("Solver_MD");
90  const Parameters params_solver_H = params_all.lookup("Solver_H");
91  const Parameters params_hmc = params_all.lookup("HMC_Leapfrog");
92 
93  const string str_gconf_status = params_test.get_string("gauge_config_status");
94  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
95  const string readfile = params_test.get_string("config_filename_input");
96  const string str_gconf_write = params_test.get_string("gauge_config_type_output");
97  const string writefile = params_test.get_string("config_filename_output");
98  const string str_rand_type = params_test.get_string("random_number_type");
99  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
100  int i_conf = params_test.get_int("trajectory_number");
101  const int Ntraj = params_test.get_int("trajectory_number_step");
102  const int i_save_conf = params_test.get_int("save_config_interval");
103  const string str_vlevel = params_test.get_string("verbose_level");
104 
105  const bool do_check = params_test.is_set("expected_result");
106  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
107 
108  const string str_action_G_type = params_action_G.get_string("action_type");
109  const string str_fopr_type = params_fopr.get_string("fermion_type");
110  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
111  const string str_proj_type = params_proj.get_string("projection_type");
112  const string str_smear_type = params_smear.get_string("smear_type");
113  const string str_solver_MD_type = params_solver_MD.get_string("solver_type");
114  const string str_solver_H_type = params_solver_H.get_string("solver_type");
115 
116  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
117 
118  //- print input parameters
119  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
120  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
121  vout.general(vl, " readfile = %s\n", readfile.c_str());
122  vout.general(vl, " gconf_write = %s\n", str_gconf_write.c_str());
123  vout.general(vl, " writefile = %s\n", writefile.c_str());
124  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
125  vout.general(vl, " seed = %lu\n", seed);
126  vout.general(vl, " i_conf = %d\n", i_conf);
127  vout.general(vl, " Ntraj = %d\n", Ntraj);
128  vout.general(vl, " i_save_conf = %d\n", i_save_conf);
129  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
130  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
131  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
132  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
133  vout.general(vl, " solver_MD_type = %s\n", str_solver_MD_type.c_str());
134  vout.general(vl, " solver_H_type = %s\n", str_solver_H_type.c_str());
135  vout.general(vl, "\n");
136 
137  //- input parameter check
138  int err = 0;
139  err += ParameterCheck::non_NULL(str_gconf_status);
140  err += ParameterCheck::non_negative(i_conf);
141  err += ParameterCheck::non_negative(Ntraj);
142  err += ParameterCheck::non_negative(i_save_conf);
143 
144  if (err) {
145  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
146  exit(EXIT_FAILURE);
147  }
148 
149 
150  RandomNumberManager::initialize(str_rand_type, seed);
151 
152 
153  // ##### object setup #####
154  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
155 
156  if (str_gconf_status == "Continue") {
157  GaugeConfig(str_gconf_read).read(U, readfile);
158  } else if (str_gconf_status == "Cold_start") {
159  GaugeConfig("Unit").read(U);
160  } else if (str_gconf_status == "Hot_start") {
161  GaugeConfig("Random").read(U);
162  } else {
163  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
164  exit(EXIT_FAILURE);
165  }
166 
167  const unique_ptr<GaugeConfig> gconf_write(new GaugeConfig(str_gconf_write));
168 
169 
170  unique_ptr<Action> action_G(Action::New(str_action_G_type));
171  action_G->set_parameters(params_action_G);
172 
173  //-- N_f=2 part
174  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
175  fopr->set_parameters(params_fopr);
176 
177  unique_ptr<Force> force_fopr(new Force_F_Wilson_Nf2(str_gmset_type));
178  // define fermion force (SA)
179  force_fopr->set_parameters(params_fopr);
180 
181  // define smearing method (SA)
182  unique_ptr<Projection> proj(Projection::New(str_proj_type));
183  proj->set_parameters(params_proj);
184 
185  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
186  smear->set_parameters(params_smear);
187 
188  // define force smearing method (SA)
189  unique_ptr<ForceSmear> force_smear(ForceSmear::New(str_smear_type, proj));
190  force_smear->set_parameters(params_smear);
191 
192  unique_ptr<Director> dr_smear(new Director_Smear(smear));
193  dr_smear->set_parameters(params_dr_smear);
194 
195  unique_ptr<Fopr> fopr_smear(Fopr::New("Smeared", fopr, dr_smear));
196  // define smeared fermion operator (SA)
197  unique_ptr<Force> force_fopr_smear(
198  new Force_F_Smeared(force_fopr, force_smear, dr_smear));
199  // define smeared fermion force (SA)
200 
201  unique_ptr<Solver> solver_MD(Solver::New(str_solver_MD_type, fopr_smear));
202  solver_MD->set_parameters(params_solver_MD);
203  unique_ptr<Fprop> fprop_MD(new Fprop_Standard_lex(solver_MD));
204 
205  unique_ptr<Solver> solver_H(Solver::New(str_solver_H_type, fopr_smear));
206  solver_H->set_parameters(params_solver_H);
207  unique_ptr<Fprop> fprop_H(new Fprop_Standard_lex(solver_H));
208 
209  unique_ptr<Action> action_F(
210  new Action_F_Standard_lex(fopr_smear, force_fopr_smear,
211  fprop_MD, fprop_H));
212  // define fermion action (SA)
213 
214 
215  ActionList actions(1); // one level
216  actions.append(0, action_F); // register actions at level0
217  actions.append(0, action_G);
218 
219  std::vector<Director *> directors(1);
220  directors[0] = (Director *)dr_smear.get(); // register director[0] (SA)
221 
222  //- Random number is initialized with a parameter specified by i_conf
224 
225  HMC_Leapfrog hmc(actions, directors, rand); // define hmc_leapfrog (SA)
226  hmc.set_parameters(params_hmc);
227 
228  const unique_ptr<Timer> timer(new Timer(test_name));
229 
230 
231  // #### Execution main part ####
232  timer->start();
233 
234  vout.general(vl, "HMC: Ntraj = %d\n", Ntraj); // a number of trajectory (SA)
235 
236  double result = 0.0;
237  for (int traj = 0; traj < Ntraj; ++traj) {
238  vout.general(vl, "\n");
239  vout.general(vl, "traj = %d\n", traj);
240 
241  result = hmc.update(*U); // hmc update (SA)
242 
243  if ((i_conf + traj + 1) % i_save_conf == 0) {
244  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
245  gconf_write->write_file(U, filename);
246  }
247  }
248 
249  gconf_write->write_file(U, writefile);
250 
251  timer->report();
252 
254 
255 
256  if (do_check) {
257  return Test::verify(result, expected_result);
258  } else {
259  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
260  return EXIT_SKIP;
261  }
262  }
263 } // namespace Test_HMC_Wilson
#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
void set_parameters(const Parameters &params)
virtual void set_parameters(const Parameters &param)=0
void general(const char *format,...)
Definition: bridgeIO.cpp:197
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
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
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
double update(Field_G &)
pointer get() const
virtual void set_parameters(const Parameters &)=0
HMC with single level leapfrog intetgrator.
Definition: hmc_Leapfrog.h:44
int non_NULL(const std::string v)
bool is_set(const string &key) const
Definition: parameters.cpp:528
void start()
Definition: timer.cpp:44
Get quark propagator for Fopr with lexical site index.
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)
Force for the standard Wilson fermion operator.
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
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
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
virtual void set_parameters(const Parameters &)=0
Standard fermion action for HMC.
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131