Bridge++  Ver.2.1.3
test_HMC_Domainwall_Moebius_Nf2_PV.cpp
Go to the documentation of this file.
1 
10 #include "test.h"
11 
14 
15 #include "lib/Fopr/fopr_Smeared.h"
16 
19 
20 #include "lib/HMC/hmc_General.h"
22 
23 #include "lib/IO/gaugeConfig.h"
24 
26 
27 #include "lib/Tools/file_utils.h"
29 
30 //====================================================================
32 
40  const std::string test_name = "HMC.Domainwall.Moebius_Nf2_PV";
41 
42  //- test-private parameters
43  namespace {
44  const std::string filename_input
45  = "test_HMC_Domainwall_Moebius_Nf2_PV.yaml";
46  }
47 
48  //- prototype declaration
49  int update_Moebius_Nf2_PV(void);
50 
51 #ifdef USE_TESTMANAGER_AUTOREGISTER
52  namespace {
53 #if defined(USE_GROUP_SU2)
54  // Nc=2 is not available.
55 #else
56  static const bool is_registered = TestManager::RegisterTest(
58 #endif
59  }
60 #endif
61 
62 //====================================================================
64 {
65  // ##### parameter setup #####
66  const int Nc = CommonParameters::Nc();
67  const int Nvol = CommonParameters::Nvol();
68  const int Ndim = CommonParameters::Ndim();
69 
70  const Parameters params_all = ParameterManager::read(filename_input);
71 
72  const Parameters params_test = params_all.lookup("Test_HMC_Domainwall");
73  const Parameters params_action_G = params_all.lookup("Action_G");
74  const Parameters params_proj = params_all.lookup("Projection");
75  const Parameters params_smear = params_all.lookup("Smear");
76  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
77  const Parameters params_dw = params_all.lookup("Fopr_Domainwall");
78  const Parameters params_dw_pv = params_all.lookup("Fopr_Domainwall_PauliVillars");
79  const Parameters params_solver_MD = params_all.lookup("Solver_MD");
80  const Parameters params_solver_H = params_all.lookup("Solver_H");
81  const Parameters params_integrator = params_all.lookup("Builder_Integrator");
82  const Parameters params_hmc = params_all.lookup("HMC_General");
83 
84  const string gconf_status = params_test.get_string("gauge_config_status");
85  const string gconf_read_type
86  = params_test.get_string("gauge_config_type_input");
87  const string readfile = params_test.get_string("config_filename_input");
88  const string gconf_write_type
89  = params_test.get_string("gauge_config_type_output");
90  const string writefile = params_test.get_string("config_filename_output");
91  const string rand_type = params_test.get_string("random_number_type");
92  int i_conf = params_test.get_int("trajectory_number");
93  const int Ntraj = params_test.get_int("trajectory_number_step");
94  const int i_save_conf = params_test.get_int("save_config_interval");
95  const string vlevel = params_test.get_string("verbose_level");
96 
97  const bool do_check = params_test.is_set("expected_result");
98  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
99 
100  const string action_G_type = params_action_G.get_string("action_type") ;
101  const string gmset_type = params_dw.get_string("gamma_matrix_type");
102  const string proj_type = params_proj.get_string("projection_type");
103  const string smear_type = params_smear.get_string("smear_type");
104  const string solver_MD_type = params_solver_MD.get_string("solver_type");
105  const string solver_H_type = params_solver_H.get_string("solver_type");
106  const int Nlevels = params_integrator.get_int("number_of_levels");
107 
108  const std::vector<int> level_action
109  = params_integrator.get_int_vector("level_of_actions");
110 
112 
113  //- print input parameters
114  vout.general(vl, " gconf_status = %s\n", gconf_status.c_str());
115  vout.general(vl, " gconf_read_type = %s\n", gconf_read_type.c_str());
116  vout.general(vl, " readfile = %s\n", readfile.c_str());
117  vout.general(vl, " gconf_write_type = %s\n", gconf_write_type.c_str());
118  vout.general(vl, " writefile = %s\n", writefile.c_str());
119  vout.general(vl, " rand_type = %s\n", rand_type.c_str());
120  vout.general(vl, " i_conf = %d\n", i_conf);
121  vout.general(vl, " Ntraj = %d\n", Ntraj);
122  vout.general(vl, " i_save_conf = %d\n", i_save_conf);
123  vout.general(vl, " vlevel = %s\n", vlevel.c_str());
124  vout.general(vl, " gmset_type = %s\n", gmset_type.c_str());
125  vout.general(vl, " proj_type = %s\n", proj_type.c_str());
126  vout.general(vl, " smear_type = %s\n", smear_type.c_str());
127  vout.general(vl, " solver_MD_type = %s\n", solver_MD_type.c_str());
128  vout.general(vl, " solver_H_type = %s\n", solver_H_type.c_str());
129  vout.general(vl, "\n");
130 
131  //- input parameter check
132  int err = 0;
133  err += ParameterCheck::non_NULL(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",
140  test_name.c_str());
141  exit(EXIT_FAILURE);
142  }
143 
144  if (proj_type == "Stout_SU3") {
145  if (CommonParameters::Nc() != 3) {
146  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n",
148  return EXIT_SKIP;
149  }
150  }
151 
152  // ##### object setup #####
153  Field_G U(Nvol, Ndim);
154 
155  if (gconf_status == "Continue") {
156  GaugeConfig(gconf_read_type).read(U, readfile);
157  } else if (gconf_status == "Cold_start") {
158  GaugeConfig("Unit").read(U);
159  } else if (gconf_status == "Hot_start") {
160  GaugeConfig("Random").read(U);
161  } else {
162  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n",
163  test_name.c_str(), gconf_status.c_str());
164  exit(EXIT_FAILURE);
165  }
166 
167  GaugeConfig gconf_write(gconf_write_type);
168 
169  //#### gauge part ####
170  unique_ptr<Action> action_G(
171  Action::New(action_G_type, params_action_G));
172 
173  //#### smearing ####
174  unique_ptr<Projection> proj(
175  Projection::New(proj_type, params_proj));
176  unique_ptr<Smear> smear(
177  Smear::New(smear_type, proj.get(), params_smear));
178 
179  unique_ptr<ForceSmear> force_smear(
180  ForceSmear::New(smear_type, proj.get(), params_smear));
181 
182  unique_ptr<Director_Smear> dr_smear(
183  new Director_Smear(smear.get(), params_dr_smear));
184 
185  //#### dynamical part ####
186  unique_ptr<Fopr> fopr_dw(
187  Fopr::New("Domainwall", params_dw));
188 
189  unique_ptr<Force> forceF_dw(
190  new Force_F_Domainwall(params_dw));
191 
192  unique_ptr<Fopr> fopr_smear(
193  Fopr::New("Smeared", fopr_dw.get(), dr_smear.get()));
194 
195  unique_ptr<Force> forceF_smear(
196  new Force_F_Smeared(forceF_dw.get(), force_smear.get(),
197  dr_smear.get()));
198 
199  unique_ptr<Solver> solver_MD(
200  Solver::New(solver_MD_type, fopr_smear.get(), params_solver_MD));
201 
202  unique_ptr<Fprop> fprop_MD(
203  new Fprop_Standard_lex(solver_MD.get()));
204 
205  unique_ptr<Solver> solver_H(
206  Solver::New(solver_H_type, fopr_smear.get(), params_solver_H));
207 
208  unique_ptr<Fprop> fprop_H(
209  new Fprop_Standard_lex(solver_H.get()));
210 
211  //#### Pauli-Villars part ####
212  unique_ptr<Fopr> fopr_dw_pv(
213  Fopr::New("Domainwall", params_dw_pv));
214 
215  unique_ptr<Force> forceF_dw_pv(
216  new Force_F_Domainwall(params_dw_pv));
217 
218  unique_ptr<Fopr> fopr_smear_pv(
219  Fopr::New("Smeared", fopr_dw_pv.get(), dr_smear.get()));
220 
221  unique_ptr<Force> forceF_smear_pv(
222  new Force_F_Smeared(forceF_dw_pv.get(), force_smear.get(),
223  dr_smear.get()));
224 
225  unique_ptr<Solver> solver_H_pv(
226  Solver::New(solver_H_type, fopr_smear_pv.get(), params_solver_H));
227 
228  unique_ptr<Fprop> fprop_H_pv(
229  new Fprop_Standard_lex(solver_H_pv.get()));
230 
231  //#### settting ratio action ####
232  unique_ptr<Action> action_F(
233  new Action_F_Ratio_lex(fopr_smear_pv.get(), forceF_smear_pv.get(),
234  fopr_smear.get(), forceF_smear.get(),
235  fprop_H_pv.get(),
236  fprop_MD.get(), fprop_H.get()));
237 
238  //#### settting actions ####
239  ActionList actions(Nlevels);
240  actions.append(level_action[0], action_F.get());
241  actions.append(level_action[1], action_G.get());
242 
243  std::vector<Director *> directors(1);
244  directors[0] = static_cast<Director *>(dr_smear.get());
245 
246  unique_ptr<Builder_Integrator> builder(
247  new Builder_Integrator(actions, directors, params_integrator));
248 
249  Integrator *integrator = builder->build();
250 
251  unique_ptr<RandomNumbers> rand(new RandomNumbers_Mseries(i_conf));
252 
253  HMC_General hmc(actions, directors, integrator, rand.get(), params_hmc);
254 
255  Timer timer(test_name);
256 
257  // #### Execution main part ####
258  timer.start();
259 
260  vout.general(vl, "HMC: Ntraj = %d\n", Ntraj);
261 
262  double result = 0.0;
263  for (int traj = 0; traj < Ntraj; ++traj) {
264  vout.general(vl, "\n");
265  vout.general(vl, "---------------------------------------------------\n");
266  vout.general(vl, "traj = %d\n", traj);
267 
268  result = hmc.update(U);
269 
270  if ((i_conf + traj + 1) % i_save_conf == 0) {
271  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
272  gconf_write.write_file(U, filename);
273  }
274  }
275 
276  gconf_write.write_file(U, writefile);
277 
278  timer.report();
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 }
288 
289 } // 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_Moebius_Nf2_PV.cpp:39
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:203
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:281
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:34
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
builder_Integrator.h
ActionList
lists of actions at respective integrator levels.
Definition: action_list.h:40
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_Moebius_Nf2_PV.cpp:40
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
Director_Smear
Manager of smeared configurations.
Definition: director_Smear.h:32
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
Test_HMC_Domainwall::update_Moebius_Nf2_PV
int update_Moebius_Nf2_PV(void)
Definition: test_HMC_Domainwall_Moebius_Nf2_PV.cpp:63
FileUtils::generate_filename
std::string generate_filename(const char *fmt,...)
Definition: file_utils.cpp:17
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:195
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:31
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:242
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:45
Action_F_Ratio_lex
HMC action for Hasenbusch preconditioned fermions.
Definition: action_F_Ratio_lex.h:41
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:262
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:572
TestManager::RegisterTest
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:69