Bridge++  Ver. 2.0.2
test_HMC_Clover_SF_RHMC_Nf2p1.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
18 
19 #include "Fopr/fopr_Rational_SF.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 
30 #include "Tools/file_utils.h"
33 
34 //====================================================================
36 
65 namespace Test_HMC_Clover_SF {
66  const std::string test_name = "HMC.Clover_SF.RHMC_Nf2p1";
67 
68  //- test-private parameters
69  namespace {
70  const std::string filename_input = "test_HMC_Clover_SF_RHMC_Nf2p1.yaml";
71  }
72 
73  //- prototype declaration
74  int RHMC_Nf2p1(void);
75 
76 #ifdef USE_TESTMANAGER_AUTOREGISTER
77  namespace {
78 #if defined(USE_GROUP_SU2)
79  // Nc=2 is not available.
80 #else
81  static const bool is_registered = TestManager::RegisterTest(
82  test_name,
84  );
85 #endif
86  }
87 #endif
88 
89  //====================================================================
90  int RHMC_Nf2p1(void)
91  {
92  // ##### parameter setup #####
93  const int Nc = CommonParameters::Nc();
94  const int Nvol = CommonParameters::Nvol();
95  const int Ndim = CommonParameters::Ndim();
96 
97  const Parameters params_all = ParameterManager::read(filename_input);
98 
99  const Parameters params_test = params_all.lookup("Test_HMC_Clover_SF");
100  const Parameters params_action_G = params_all.lookup("Action_G");
101  const Parameters params_fopr_Nf2 = params_all.lookup("Fopr_Nf2");
102  const Parameters params_fopr_Nf1 = params_all.lookup("Fopr_Nf1");
103  const Parameters params_proj = params_all.lookup("Projection");
104  const Parameters params_smear = params_all.lookup("Smear");
105  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
106  const Parameters params_rational_MD = params_all.lookup("Fopr_Rational_MD");
107  const Parameters params_rational_H = params_all.lookup("Fopr_Rational_H");
108  const Parameters params_integrator = params_all.lookup("Builder_Integrator");
109  const Parameters params_hmc = params_all.lookup("HMC_General");
110 
111  const string str_gconf_status = params_test.get_string("gauge_config_status");
112  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
113  const string readfile = params_test.get_string("config_filename_input");
114  const string str_gconf_write = params_test.get_string("gauge_config_type_output");
115  const string writefile = params_test.get_string("config_filename_output");
116  const string str_rand_type = params_test.get_string("random_number_type");
117  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
118  int i_conf = params_test.get_int("trajectory_number");
119  const int Ntraj = params_test.get_int("trajectory_number_step");
120  const int i_save_conf = params_test.get_int("save_config_interval");
121  const string str_vlevel = params_test.get_string("verbose_level");
122 
123  const bool do_check = params_test.is_set("expected_result");
124  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
125 
126  const string str_action_G_type = params_action_G.get_string("action_type");
127  const string str_fopr_Nf2_type = params_fopr_Nf2.get_string("fermion_type");
128  const string str_fopr_Nf1_type = params_fopr_Nf1.get_string("fermion_type");
129  const string str_gmset_type = params_fopr_Nf2.get_string("gamma_matrix_type");
130  const string str_proj_type = params_proj.get_string("projection_type");
131  const string str_smear_type = params_smear.get_string("smear_type");
132  // const int Nsmear = params_dr_smear.get_int("number_of_smearing");
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, "\n");
154 
155  //- input parameter check
156  int err = 0;
157  err += ParameterCheck::non_NULL(str_gconf_status);
158  err += ParameterCheck::non_negative(i_conf);
159  err += ParameterCheck::non_negative(Ntraj);
160  err += ParameterCheck::non_negative(i_save_conf);
161 
162  if (err) {
163  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
164  exit(EXIT_FAILURE);
165  }
166 
167  // if ( (Nsmear > 0) && (str_proj_type == "Stout_SU3") ) {
168  if (str_proj_type == "Stout_SU3") {
169  if (CommonParameters::Nc() != 3) {
170  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
171  return EXIT_SKIP;
172  }
173  }
174 
175 
176  RandomNumberManager::initialize(str_rand_type, seed);
177 
178 
179  // ##### object setup #####
180  Field_G U(Nvol, Ndim);
181 
182  if (str_gconf_status == "Continue") {
183  GaugeConfig(str_gconf_read).read(U, readfile);
184  } else if (str_gconf_status == "Cold_start") {
185  GaugeConfig("Unit").read(U);
186  } else if (str_gconf_status == "Hot_start") {
187  GaugeConfig("Random").read(U);
188  } else {
189  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
190  exit(EXIT_FAILURE);
191  }
192 
193  GaugeConfig gconf_write(str_gconf_write);
194 
195 
196  unique_ptr<Action> action_G(Action::New(str_action_G_type, params_action_G));
197 
198  //-- N_f=2 part
199  unique_ptr<Fopr> fopr_Nf2(new Fopr_Clover_SF(params_fopr_Nf2));
200  unique_ptr<Force> force_fopr_Nf2(new Force_F_Clover_SF(params_fopr_Nf2));
201 
202  unique_ptr<Projection> proj(Projection::New(str_proj_type, params_proj));
203 
204  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj.get(), params_smear));
205 
206  unique_ptr<ForceSmear> force_smear(ForceSmear::New(str_smear_type, proj.get(), params_smear));
207 
208  unique_ptr<Director_Smear> dr_smear(new Director_Smear(smear.get(), params_dr_smear));
209 
210  unique_ptr<Fopr> fopr_smear(Fopr::New("Smeared", fopr_Nf2.get(), dr_smear.get()));
211  unique_ptr<Force> force_fopr_smear(new Force_F_Smeared(force_fopr_Nf2.get(), force_smear.get(), dr_smear.get()));
212 
213 
214  unique_ptr<Action> action_F_Nf2(new Action_F_Standard_SF(fopr_smear.get(), force_fopr_smear.get()));
215 
216 
217  //-- N_f=1 part
218  unique_ptr<Fopr> fopr_Nf1(new Fopr_Clover_SF(params_fopr_Nf1));
219 
220  unique_ptr<Force> force_fopr_Nf1(new Force_F_Clover_SF(params_fopr_Nf1));
221 
222  unique_ptr<Fopr> fopr_r1(Fopr::New("Rational_SF", fopr_Nf1.get(), params_rational_H));
223  unique_ptr<Fopr> fopr_langev(Fopr::New("Smeared", fopr_r1.get(), dr_smear.get()));
224 
225  unique_ptr<Fopr> fopr_r2(Fopr::New("Rational_SF", fopr_Nf1.get(), params_rational_MD));
226  unique_ptr<Fopr> fopr_H(Fopr::New("Smeared", fopr_r2.get(), dr_smear.get()));
227 
228  unique_ptr<Force> force_fopr_r2(new Force_F_Rational(fopr_Nf1.get(), force_fopr_Nf1.get(), params_rational_MD));
229 
230  unique_ptr<Force> force_fopr_MD(new Force_F_Smeared(force_fopr_r2.get(), force_smear.get(), dr_smear.get()));
231 
232  unique_ptr<Action> action_F_Nf1(new Action_F_Rational_SF(fopr_langev.get(), fopr_H.get(), force_fopr_MD.get()));
233 
234 
235  ActionList actions(Nlevels);
236  actions.append(level_action[0], action_F_Nf2.get());
237  actions.append(level_action[1], action_F_Nf1.get());
238  actions.append(level_action[2], action_G.get());
239 
240  std::vector<Director *> directors(1);
241  directors[0] = static_cast<Director *>(dr_smear.get());
242 
243  unique_ptr<Builder_Integrator> builder(new Builder_Integrator(actions, directors, params_integrator));
244  Integrator *integrator = builder->build();
245 
246  //- Mersenne Twister for random number generator
247  //- for i_conf == 0
248  // std::vector<unsigned long> seed(4);
249  // seed[0] = 0x6a92;
250  // seed[1] = 0x3708;
251  // seed[2] = 0xab41;
252  // seed[3] = 0x5c52;
253  // RandomNumbers *rand = new RandomNumbers_MT19937(seed);
254  unique_ptr<RandomNumbers> rand(new RandomNumbers_MT19937(i_conf));
255 
256  HMC_General hmc(actions, directors, integrator, rand.get(), params_hmc);
257 
258  Timer timer(test_name);
259 
260 
261  // #### Execution main part ####
262  timer.start();
263 
264  vout.general(vl, "RHMC start: Ntraj = %d\n", Ntraj);
265 
266  double result = 0.0;
267  for (int traj = 0; traj < Ntraj; ++traj) {
268  vout.general(vl, "\n");
269  vout.general(vl, "---------------------------------------------------\n");
270  vout.general(vl, "traj = %d\n", traj);
271 
272  result = hmc.update(U);
273 
274  if ((i_conf + traj + 1) % i_save_conf == 0) {
275  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
276  gconf_write.write_file(U, filename);
277  }
278  }
279 
280  gconf_write.write_file(U, writefile);
281 
282  // if (Communicator::nodeid() == 0) {
283  // rand->writefile("rand_MT");
284  // }
285 
286  timer.report();
287 
289 
290 
291  if (do_check) {
292  return Test::verify(result, expected_result);
293  } else {
294  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
295  return EXIT_SKIP;
296  }
297  }
298 } // namespace Test_HMC_Clover_SF
Test::verify
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Test_HMC_Clover_SF
Test of HMC update for clover fermions with SF.
Definition: test_HMC_Clover_SF_Nf2.cpp:63
Test_HMC_Clover_SF::test_name
const std::string test_name
Definition: test_HMC_Clover_SF_Nf2.cpp:64
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
RandomNumbers_MT19937
Definition: randomNumbers_MT19937.h:43
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
fopr_Rational_SF.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_Standard_SF.h
ParameterCheck::non_negative
int non_negative(const int v)
Definition: parameterCheck.cpp:21
Force_F_Clover_SF
Force calculation for clover quark action with SF BC.
Definition: force_F_Clover_SF.h:38
force_F_Smeared.h
Parameters::get_int_vector
vector< int > get_int_vector(const string &key) const
Definition: parameters.cpp:267
Fopr_Clover_SF
Clover fermion operator.
Definition: fopr_Clover_SF.h:44
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
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
ParameterCheck::vl
Bridge::VerboseLevel vl
Definition: parameterCheck.cpp:18
file_utils.h
test.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
Action_F_Standard_SF
Standard fermion action with SF BC for HMC.
Definition: action_F_Standard_SF.h:53
Director_Smear
Manager of smeared configurations.
Definition: director_Smear.h:39
randomNumbers_MT19937.h
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
Action_F_Rational_SF
action class for RHMC, with externally constructed Fopr_Rational.
Definition: action_F_Rational_SF.h:39
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
force_F_Clover_SF.h
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.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
Test_HMC_Clover_SF::RHMC_Nf2p1
int RHMC_Nf2p1(void)
Definition: test_HMC_Clover_SF_RHMC_Nf2p1.cpp:90
action_F_Rational_SF.h
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