Bridge++  Ver. 2.0.2
test_HMC_Wilson_TwistedMass_Nf2.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
17 
19 
20 #include "HMC/hmc_General.h"
21 #include "HMC/builder_Integrator.h"
22 
23 #include "IO/gaugeConfig.h"
24 
26 
27 #include "Tools/file_utils.h"
30 
31 //====================================================================
33 
46  const std::string test_name = "HMC.Wilson_TwistedMass.Nf2";
47 
48  //- test-private parameters
49  namespace {
50  const std::string filename_input = "test_HMC_Wilson_TwistedMass_Nf2.yaml";
51  }
52 
53  //- prototype declaration
54  int update_Nf2(void);
55 
56 #ifdef USE_TESTMANAGER_AUTOREGISTER
57  namespace {
58 #if defined(USE_GROUP_SU2)
59  // Nc=2 is not available.
60 #else
61  static const bool is_registered = TestManager::RegisterTest(
62  test_name,
64  );
65 #endif
66  }
67 #endif
68 
69  //====================================================================
70  int update_Nf2(void)
71  {
72  // ##### parameter setup #####
73  const int Nc = CommonParameters::Nc();
74  const int Nd = CommonParameters::Nd();
75  const int Nvol = CommonParameters::Nvol();
76  const int Ndim = CommonParameters::Ndim();
77  const int NinG = 2 * Nc * Nc;
78 
79  const Parameters params_all = ParameterManager::read(filename_input);
80 
81  const Parameters params_test = params_all.lookup("Test_HMC_Wilson_TwistedMass");
82  const Parameters params_action_G = params_all.lookup("Action_G");
83  const Parameters params_fopr = params_all.lookup("Fopr");
84  const Parameters params_solver_MD = params_all.lookup("Solver_MD");
85  const Parameters params_solver_H = params_all.lookup("Solver_H");
86  const Parameters params_integrator = params_all.lookup("Builder_Integrator");
87  const Parameters params_hmc = params_all.lookup("HMC_General");
88 
89  const string str_gconf_status = params_test.get_string("gauge_config_status");
90  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
91  const string readfile = params_test.get_string("config_filename_input");
92  const string str_gconf_write = params_test.get_string("gauge_config_type_output");
93  const string writefile = params_test.get_string("config_filename_output");
94  const string str_rand_type = params_test.get_string("random_number_type");
95  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
96  int i_conf = params_test.get_int("trajectory_number");
97  const int Ntraj = params_test.get_int("trajectory_number_step");
98  const int i_save_conf = params_test.get_int("save_config_interval");
99  const string str_vlevel = params_test.get_string("verbose_level");
100 
101  const bool do_check = params_test.is_set("expected_result");
102  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
103 
104  const string str_action_G_type = params_action_G.get_string("action_type");
105  const string str_fopr_type = params_fopr.get_string("fermion_type");
106  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
107  const string str_solver_MD_type = params_solver_MD.get_string("solver_type");
108  const string str_solver_H_type = params_solver_H.get_string("solver_type");
109  const int Nlevels = params_integrator.get_int("number_of_levels");
110  const std::vector<int> level_action = params_integrator.get_int_vector("level_of_actions");
111 
112  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
113 
114  //- print input parameters
115  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
116  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
117  vout.general(vl, " readfile = %s\n", readfile.c_str());
118  vout.general(vl, " gconf_write = %s\n", str_gconf_write.c_str());
119  vout.general(vl, " writefile = %s\n", writefile.c_str());
120  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
121  vout.general(vl, " seed = %lu\n", seed);
122  vout.general(vl, " i_conf = %d\n", i_conf);
123  vout.general(vl, " Ntraj = %d\n", Ntraj);
124  vout.general(vl, " i_save_conf = %d\n", i_save_conf);
125  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
126  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
127  vout.general(vl, " solver_MD_type = %s\n", str_solver_MD_type.c_str());
128  vout.general(vl, " solver_H_type = %s\n", str_solver_H_type.c_str());
129  vout.general(vl, "\n");
130 
131  //- input parameter check
132  int err = 0;
133  err += ParameterCheck::non_NULL(str_gconf_status);
134  err += ParameterCheck::non_negative(i_conf);
135  err += ParameterCheck::non_negative(Ntraj);
136  err += ParameterCheck::non_negative(i_save_conf);
137 
138  if (err) {
139  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
140  exit(EXIT_FAILURE);
141  }
142 
143 
144  RandomNumberManager::initialize(str_rand_type, seed);
145 
146 
147  // ##### object setup #####
148  Field_G U(Nvol, Ndim);
149 
150  if (str_gconf_status == "Continue") {
151  GaugeConfig(str_gconf_read).read(U, readfile);
152  } else if (str_gconf_status == "Cold_start") {
153  GaugeConfig("Unit").read(U);
154  } else if (str_gconf_status == "Hot_start") {
155  GaugeConfig("Random").read(U);
156  } else {
157  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
158  exit(EXIT_FAILURE);
159  }
160 
161  GaugeConfig gconf_write(str_gconf_write);
162 
163 
164  unique_ptr<Action> action_G(Action::New(str_action_G_type, params_action_G));
165 
166  //-- N_f=2 part
167  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, params_fopr));
168  unique_ptr<Force> force_fopr(new Force_F_Wilson_TwistedMass_Nf2(params_fopr));
169 
170  unique_ptr<Solver> solver_MD(Solver::New(str_solver_MD_type, fopr.get(), params_solver_MD));
171  unique_ptr<Fprop> fprop_MD(new Fprop_Standard_lex(solver_MD.get()));
172 
173  unique_ptr<Solver> solver_H(Solver::New(str_solver_H_type, fopr.get(), params_solver_H));
174  unique_ptr<Fprop> fprop_H(new Fprop_Standard_lex(solver_H.get()));
175 
176  unique_ptr<Action> action_F(new Action_F_Standard_lex(fopr.get(), force_fopr.get(), fprop_MD.get(), fprop_H.get()));
177 
178 
179  ActionList actions(Nlevels);
180  actions.append(level_action[0], action_F.get());
181  actions.append(level_action[1], action_G.get());
182 
183  unique_ptr<Builder_Integrator> builder(new Builder_Integrator(actions, params_integrator));
184  Integrator *integrator = builder->build();
185 
186  unique_ptr<RandomNumbers> rand(new RandomNumbers_Mseries(i_conf));
187 
188  HMC_General hmc(actions, integrator, rand.get(), params_hmc);
189 
190  Timer timer(test_name);
191 
192 
193  // #### Execution main part ####
194  timer.start();
195 
196  vout.general(vl, "HMC: Ntraj = %d\n", Ntraj);
197 
198  double result = 0.0;
199  for (int traj = 0; traj < Ntraj; ++traj) {
200  vout.general(vl, "\n");
201  vout.general(vl, "traj = %d\n", traj);
202 
203  result = hmc.update(U);
204 
205  if ((i_conf + traj + 1) % i_save_conf == 0) {
206  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
207  gconf_write.write_file(U, filename);
208  }
209  }
210 
211  gconf_write.write_file(U, writefile);
212 
213  timer.report();
214 
216 
217 
218  if (do_check) {
219  return Test::verify(result, expected_result);
220  } else {
221  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
222  return EXIT_SKIP;
223  }
224  }
225 } // namespace Test_HMC_Wilson_TwistedMass
Test::verify
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
randomNumbers_Mseries.h
ParameterCheck::non_NULL
int non_NULL(const std::string v)
Definition: parameterCheck.cpp:65
Fprop_Standard_lex
Get quark propagator for Fopr with lexical site index.
Definition: fprop_Standard_lex.h:33
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
fprop_Standard_lex.h
gaugeConfig.h
CommonParameters::Nvol
static int Nvol()
Definition: commonParameters.h:109
force_F_Wilson_TwistedMass_Nf2.h
action_F_Standard_lex.h
ParameterCheck::non_negative
int non_negative(const int v)
Definition: parameterCheck.cpp:21
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
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
Test_HMC_Wilson_TwistedMass::test_name
const std::string test_name
Definition: test_HMC_Wilson_TwistedMass_Nf2.cpp:46
hmc_General.h
ParameterCheck::vl
Bridge::VerboseLevel vl
Definition: parameterCheck.cpp:18
RandomNumbers_Mseries
Random number generator base on M-series.
Definition: randomNumbers_Mseries.h:46
Test_HMC_Wilson_TwistedMass
HMC test of twisted-mass Wilson fermion.
Definition: test_HMC_Wilson_TwistedMass_Nf2.cpp:45
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
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
CommonParameters::Nd
static int Nd()
Definition: commonParameters.h:116
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
Force_F_Wilson_TwistedMass_Nf2
Force for the twisted-mass Wilson fermion operator.
Definition: force_F_Wilson_TwistedMass_Nf2.h:39
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
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
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
Action_F_Standard_lex
Standard fermion action for HMC.
Definition: action_F_Standard_lex.h:37
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
Test_HMC_Wilson_TwistedMass::update_Nf2
int update_Nf2(void)
Definition: test_HMC_Wilson_TwistedMass_Nf2.cpp:70