Bridge++  Version 1.6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_HMC_Clover_SF_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_General.h"
24 #include "HMC/builder_Integrator.h"
25 
26 #include "IO/gaugeConfig.h"
27 
28 #include "Tools/file_utils.h"
31 
32 //====================================================================
34 
63 namespace Test_HMC_Clover_SF {
64  const std::string test_name = "HMC.Clover_SF.Nf2";
65 
66  //- test-private parameters
67  namespace {
68  const std::string filename_input = "test_HMC_Clover_SF_Nf2.yaml";
69  }
70 
71  //- prototype declaration
72  int update_Nf2(void);
73 
74 #ifdef USE_TESTMANAGER_AUTOREGISTER
75  namespace {
76 #if defined(USE_GROUP_SU2)
77  // Nc=2 is not available.
78 #else
79  static const bool is_registered = TestManager::RegisterTest(
80  test_name,
82  );
83 #endif
84  }
85 #endif
86 
87  //====================================================================
88  int update_Nf2(void)
89  {
90  // ##### parameter setup #####
91  const int Nc = CommonParameters::Nc();
92  const int Nvol = CommonParameters::Nvol();
93  const int Ndim = CommonParameters::Ndim();
94 
95  const Parameters params_all = ParameterManager::read(filename_input);
96 
97  const Parameters params_test = params_all.lookup("Test_HMC_Clover_SF");
98  const Parameters params_action_G = params_all.lookup("Action_G");
99  const Parameters params_fopr = params_all.lookup("Fopr");
100  const Parameters params_proj = params_all.lookup("Projection");
101  const Parameters params_smear = params_all.lookup("Smear");
102  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
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_type = params_fopr.get_string("fermion_type");
123  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
124  const string str_proj_type = params_proj.get_string("projection_type");
125  const string str_smear_type = params_smear.get_string("smear_type");
126  // const int Nsmear = params_dr_smear.get_int("number_of_smearing");
127  const int Nlevels = params_integrator.get_int("number_of_levels");
128  const std::vector<int> level_action = params_integrator.get_int_vector("level_of_actions");
129 
130  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
131 
132  //- print input parameters
133  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
134  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
135  vout.general(vl, " readfile = %s\n", readfile.c_str());
136  vout.general(vl, " gconf_write = %s\n", str_gconf_write.c_str());
137  vout.general(vl, " writefile = %s\n", writefile.c_str());
138  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
139  vout.general(vl, " seed = %lu\n", seed);
140  vout.general(vl, " i_conf = %d\n", i_conf);
141  vout.general(vl, " Ntraj = %d\n", Ntraj);
142  vout.general(vl, " i_save_conf = %d\n", i_save_conf);
143  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
144  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
145  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
146  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
147  vout.general(vl, "\n");
148 
149  //- input parameter check
150  int err = 0;
151  err += ParameterCheck::non_NULL(str_gconf_status);
152  err += ParameterCheck::non_negative(i_conf);
153  err += ParameterCheck::non_negative(Ntraj);
154  err += ParameterCheck::non_negative(i_save_conf);
155 
156  if (err) {
157  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
158  exit(EXIT_FAILURE);
159  }
160 
161  // if ( (Nsmear > 0) && (str_proj_type == "Stout_SU3") ) {
162  if (str_proj_type == "Stout_SU3") {
163  if (CommonParameters::Nc() != 3) {
164  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
165  return EXIT_SKIP;
166  }
167  }
168 
169 
170  RandomNumberManager::initialize(str_rand_type, seed);
171 
172 
173  // ##### object setup #####
174  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
175 
176  if (str_gconf_status == "Continue") {
177  GaugeConfig(str_gconf_read).read(U, readfile);
178  } else if (str_gconf_status == "Cold_start") {
179  GaugeConfig("Unit").read(U);
180  } else if (str_gconf_status == "Hot_start") {
181  GaugeConfig("Random").read(U);
182  } else {
183  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
184  exit(EXIT_FAILURE);
185  }
186 
187  const unique_ptr<GaugeConfig> gconf_write(new GaugeConfig(str_gconf_write));
188 
189 
190  unique_ptr<Action> action_G(Action::New(str_action_G_type));
191  action_G->set_parameters(params_action_G);
192 
193  //-- N_f=2 part
194  unique_ptr<Fopr> fopr(new Fopr_Clover_SF());
195  fopr->set_parameters(params_fopr);
196  unique_ptr<Force> force_fopr(new Force_F_Clover_SF());
197  force_fopr->set_parameters(params_fopr);
198 
199  unique_ptr<Projection> proj(Projection::New(str_proj_type));
200  proj->set_parameters(params_proj);
201 
202  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
203  smear->set_parameters(params_smear);
204 
205  unique_ptr<ForceSmear> force_smear(ForceSmear::New(str_smear_type, proj));
206  force_smear->set_parameters(params_smear);
207 
208  unique_ptr<Director> dr_smear(new Director_Smear(smear));
209  dr_smear->set_parameters(params_dr_smear);
210 
211  unique_ptr<Fopr> fopr_smear(Fopr::New("Smeared", fopr, dr_smear));
212  unique_ptr<Force> force_fopr_smear(
213  new Force_F_Smeared(force_fopr, force_smear, dr_smear));
214 
215 
216  unique_ptr<Action> action_F_Nf2(
217  new Action_F_Standard_SF(fopr_smear, force_fopr_smear));
218 
219 
220  ActionList actions(Nlevels);
221  actions.append(level_action[0], action_F_Nf2);
222  actions.append(level_action[1], action_G);
223 
224  std::vector<Director *> directors(1);
225  directors[0] = (Director *)dr_smear.get();
226 
227  const unique_ptr<Builder_Integrator> builder(new Builder_Integrator(actions, directors));
228  builder->set_parameters(params_integrator);
229  Integrator *integrator = builder->build();
230 
231  //- M series random number intialization
232  // int ndelay = 200000;
233  // RandomNumbers_Mseries rand(ndelay);
234 
235  //- Mersenne Twister for random number generator.
236  //- for i_conf == 0
237  // std::vector<unsigned long> seed(4);
238  // seed[0] = 0x6a92;
239  // seed[1] = 0x3708;
240  // seed[2] = 0xab41;
241  // seed[3] = 0x5c52;
242  // unique_ptr<RandomNumbers> rand(new RandomNumbers_MT19937(seed));
244 
245  HMC_General hmc(actions, directors, integrator, rand);
246  hmc.set_parameters(params_hmc);
247 
248  const unique_ptr<Timer> timer(new Timer(test_name));
249 
250 
251  // #### Execution main part ####
252  timer->start();
253 
254  vout.general(vl, "HMC start: Ntraj = %d\n", Ntraj);
255 
256  double result = 0.0;
257  for (int traj = 0; traj < Ntraj; ++traj) {
258  vout.general(vl, "\n");
259  vout.general(vl, "traj = %d\n", traj);
260 
261  result = hmc.update(*U);
262 
263  if ((i_conf + traj + 1) % i_save_conf == 0) {
264  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
265  gconf_write->write_file(U, filename);
266  }
267  }
268 
269  gconf_write->write_file(U, writefile);
270 
271  // if (Communicator::nodeid() == 0) {
272  // rand->writefile("rand_MT");
273  // }
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_SF
#define EXIT_SKIP
Definition: test.h:17
BridgeIO vout
Definition: bridgeIO.cpp:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
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
const std::string test_name
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
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
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)
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)
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:110
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:79
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.
Standard fermion action with SF BC for HMC.
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
Clover fermion operator.