Bridge++  Ver. 2.0.2
test_HMC_Domainwall_Nf2_PV.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
18 
19 #include "Fopr/fopr_Smeared.h"
20 
23 
24 #include "HMC/hmc_General.h"
25 #include "HMC/builder_Integrator.h"
26 
27 #include "IO/gaugeConfig.h"
28 
30 
31 #include "Tools/file_utils.h"
34 
35 //====================================================================
37 
50 namespace Test_HMC_Domainwall {
51  const std::string test_name = "HMC.Domainwall.Nf2_PV";
52 
53  //- test-private parameters
54  namespace {
55  const std::string filename_input = "test_HMC_Domainwall_Nf2_PV.yaml";
56  }
57 
58  //- prototype declaration
59  int update_Nf2_PV(void);
60 
61 #ifdef USE_TESTMANAGER_AUTOREGISTER
62  namespace {
63 #if defined(USE_GROUP_SU2)
64  // Nc=2 is not available.
65 #else
66  static const bool is_registered = TestManager::RegisterTest(
67  test_name,
69  );
70 #endif
71  }
72 #endif
73 
74  //====================================================================
75  int update_Nf2_PV(void)
76  {
77  // ##### parameter setup #####
78  const int Nc = CommonParameters::Nc();
79  const int Nvol = CommonParameters::Nvol();
80  const int Ndim = CommonParameters::Ndim();
81 
82  const Parameters params_all = ParameterManager::read(filename_input);
83 
84  const Parameters params_test = params_all.lookup("Test_HMC_Domainwall");
85  const Parameters params_action_G = params_all.lookup("Action_G");
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_dw = params_all.lookup("Fopr_Domainwall");
90  const Parameters params_dw_pv = params_all.lookup("Fopr_Domainwall_PauliVillars");
91  const Parameters params_solver_MD = params_all.lookup("Solver_MD");
92  const Parameters params_solver_H = params_all.lookup("Solver_H");
93  const Parameters params_integrator = params_all.lookup("Builder_Integrator");
94  const Parameters params_hmc = params_all.lookup("HMC_General");
95 
96  const string str_gconf_status = params_test.get_string("gauge_config_status");
97  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
98  const string readfile = params_test.get_string("config_filename_input");
99  const string str_gconf_write = params_test.get_string("gauge_config_type_output");
100  const string writefile = params_test.get_string("config_filename_output");
101  const string str_rand_type = params_test.get_string("random_number_type");
102  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
103  int i_conf = params_test.get_int("trajectory_number");
104  const int Ntraj = params_test.get_int("trajectory_number_step");
105  const int i_save_conf = params_test.get_int("save_config_interval");
106  const string str_vlevel = params_test.get_string("verbose_level");
107 
108  const bool do_check = params_test.is_set("expected_result");
109  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
110 
111  const string str_action_G_type = params_action_G.get_string("action_type");
112  const string str_gmset_type = params_dw.get_string("gamma_matrix_type");
113  const string str_proj_type = params_proj.get_string("projection_type");
114  const string str_smear_type = params_smear.get_string("smear_type");
115  // const int Nsmear = params_dr_smear.get_int("number_of_smearing");
116  const string str_solver_MD_type = params_solver_MD.get_string("solver_type");
117  const string str_solver_H_type = params_solver_H.get_string("solver_type");
118  const int Nlevels = params_integrator.get_int("number_of_levels");
119  const std::vector<int> level_action = params_integrator.get_int_vector("level_of_actions");
120 
121  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
122 
123  //- print input parameters
124  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
125  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
126  vout.general(vl, " readfile = %s\n", readfile.c_str());
127  vout.general(vl, " gconf_write = %s\n", str_gconf_write.c_str());
128  vout.general(vl, " writefile = %s\n", writefile.c_str());
129  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
130  vout.general(vl, " seed = %lu\n", seed);
131  vout.general(vl, " i_conf = %d\n", i_conf);
132  vout.general(vl, " Ntraj = %d\n", Ntraj);
133  vout.general(vl, " i_save_conf = %d\n", i_save_conf);
134  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
135  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
136  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
137  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
138  vout.general(vl, " solver_MD_type = %s\n", str_solver_MD_type.c_str());
139  vout.general(vl, " solver_H_type = %s\n", str_solver_H_type.c_str());
140  vout.general(vl, "\n");
141 
142  //- input parameter check
143  int err = 0;
144  err += ParameterCheck::non_NULL(str_gconf_status);
145  err += ParameterCheck::non_negative(i_conf);
146  err += ParameterCheck::non_negative(Ntraj);
147  err += ParameterCheck::non_negative(i_save_conf);
148 
149  if (err) {
150  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
151  exit(EXIT_FAILURE);
152  }
153 
154  // if ( (Nsmear > 0) && (str_proj_type == "Stout_SU3") ) {
155  if (str_proj_type == "Stout_SU3") {
156  if (CommonParameters::Nc() != 3) {
157  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
158  return EXIT_SKIP;
159  }
160  }
161 
162 
163  RandomNumberManager::initialize(str_rand_type, seed);
164 
165 
166  // ##### object setup #####
167  Field_G U(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  GaugeConfig gconf_write(str_gconf_write);
181 
182 
183  unique_ptr<Action> action_G(Action::New(str_action_G_type, params_action_G));
184 
185 
186  unique_ptr<Projection> proj(Projection::New(str_proj_type, params_proj));
187  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj.get(), params_smear));
188 
189  unique_ptr<ForceSmear> force_smear(ForceSmear::New(str_smear_type, proj.get(), params_smear));
190 
191  unique_ptr<Director_Smear> dr_smear(new Director_Smear(smear.get(), params_dr_smear));
192 
193  // Fopr *fopr_w = Fopr::New("Wilson", str_gmset_type);
194  // Fopr *fopr_dw = Fopr::New("Domainwall", fopr_w, params_dw);
195  unique_ptr<Fopr> fopr_dw(Fopr::New("Domainwall", params_dw));
196 
197  unique_ptr<Force> force_fopr_dw(new Force_F_Domainwall(params_dw));
198 
199  unique_ptr<Fopr> fopr_smear(Fopr::New("Smeared", fopr_dw.get(), dr_smear.get()));
200  unique_ptr<Force> force_fopr_smear(new Force_F_Smeared(force_fopr_dw.get(), force_smear.get(), dr_smear.get()));
201 
202 
203  unique_ptr<Solver> solver_MD(Solver::New(str_solver_MD_type, fopr_smear.get(), params_solver_MD));
204  unique_ptr<Fprop> fprop_MD(new Fprop_Standard_lex(solver_MD.get()));
205 
206  unique_ptr<Solver> solver_H(Solver::New(str_solver_H_type, fopr_smear.get(), params_solver_H));
207  unique_ptr<Fprop> fprop_H(new Fprop_Standard_lex(solver_H.get()));
208 
209 
210  //- Pauli-Villars
211  // Fopr *fopr_dw_pv = Fopr::New("Domainwall", fopr_w, params_dw_pv);
212  unique_ptr<Fopr> fopr_dw_pv(Fopr::New("Domainwall", params_dw_pv));
213 
214  unique_ptr<Force> force_fopr_dw_pv(new Force_F_Domainwall(params_dw_pv));
215 
216  unique_ptr<Fopr> fopr_smear_pv(Fopr::New("Smeared", fopr_dw_pv.get(), dr_smear.get()));
217  unique_ptr<Force> force_fopr_smear_pv(new Force_F_Smeared(force_fopr_dw_pv.get(), force_smear.get(), dr_smear.get()));
218 
219 
220  unique_ptr<Solver> solver_H_pv(Solver::New(str_solver_H_type, fopr_smear_pv.get(), params_solver_H));
221  unique_ptr<Fprop> fprop_H_pv(new Fprop_Standard_lex(solver_H_pv.get()));
222 
223 
224  unique_ptr<Action> action_F(new Action_F_Ratio_lex(fopr_smear_pv.get(), force_fopr_smear_pv.get(), fopr_smear.get(), force_fopr_smear.get(), fprop_H_pv.get(), fprop_MD.get(), fprop_H.get()));
225 
226 
227  ActionList actions(Nlevels);
228  actions.append(level_action[0], action_F.get());
229  actions.append(level_action[1], action_G.get());
230 
231  std::vector<Director *> directors(1);
232  directors[0] = static_cast<Director *>(dr_smear.get());
233 
234  unique_ptr<Builder_Integrator> builder(new Builder_Integrator(actions, directors, params_integrator));
235  Integrator *integrator = builder->build();
236 
237  unique_ptr<RandomNumbers> rand(new RandomNumbers_Mseries(i_conf));
238 
239  HMC_General hmc(actions, directors, integrator, rand.get(), params_hmc);
240 
241  Timer timer(test_name);
242 
243 
244  // #### Execution main part ####
245  timer.start();
246 
247  vout.general(vl, "HMC: Ntraj = %d\n", Ntraj);
248 
249  double result = 0.0;
250  for (int traj = 0; traj < Ntraj; ++traj) {
251  vout.general(vl, "\n");
252  vout.general(vl, "---------------------------------------------------\n");
253  vout.general(vl, "traj = %d\n", traj);
254 
255  result = hmc.update(U);
256 
257  if ((i_conf + traj + 1) % i_save_conf == 0) {
258  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
259  gconf_write.write_file(U, filename);
260  }
261  }
262 
263  gconf_write.write_file(U, writefile);
264 
265  timer.report();
266 
268 
269 
270  if (do_check) {
271  return Test::verify(result, expected_result);
272  } else {
273  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
274  return EXIT_SKIP;
275  }
276  }
277 } // namespace Test_HMC_Domainwall
Test::verify
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Test_HMC_Domainwall
Test of HMC update for domain-wall fermion operator.
Definition: test_HMC_Domainwall_Nf2.cpp:50
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_Smeared
Force calculation for smeared fermion operators.
Definition: force_F_Smeared.h:39
action_F_Ratio_lex.h
action_F_Standard_lex.h
ParameterCheck::non_negative
int non_negative(const int v)
Definition: parameterCheck.cpp:21
force_F_Smeared.h
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
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
file_utils.h
test.h
Test_HMC_Domainwall::test_name
const std::string test_name
Definition: test_HMC_Domainwall_Nf2.cpp:51
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
Test_HMC_Domainwall::update_Nf2_PV
int update_Nf2_PV(void)
Definition: test_HMC_Domainwall_Nf2_PV.cpp:75
Director_Smear
Manager of smeared configurations.
Definition: director_Smear.h:39
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
Force_F_Domainwall
Force calculation for domain-wall fermions.
Definition: force_F_Domainwall.h:36
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
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42
Action_F_Ratio_lex
HMC action for Hasenbusch preconditioned fermions.
Definition: action_F_Ratio_lex.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
force_F_Domainwall.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