Bridge++  Ver. 2.0.2
test_HMC_Clover_Isochemical_RHMC_Nf2p1.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
19 
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 
34 
35 #include "Tools/file_utils.h"
36 #include "Tools/math_Rational.h"
39 
40 //====================================================================
42 
59  const std::string test_name = "HMC.Clover_Isochemical.RHMC_Nf2p1";
60 
61  //- test-private parameters
62  namespace {
63  const std::string filename_input = "test_HMC_Clover_Isochemical_RHMC_Nf2p1.yaml";
64  }
65 
66  //- prototype declaration
67  int RHMC_Nf2p1(void);
68 
69 #ifdef USE_TESTMANAGER_AUTOREGISTER
70  namespace {
71 #if defined(USE_GROUP_SU2)
72  // Nc=2 is not available.
73 #else
74  static const bool is_registered = TestManager::RegisterTest(
75  test_name,
77  );
78 #endif
79  }
80 #endif
81 
82  //====================================================================
83  int RHMC_Nf2p1(void)
84  {
85  // ##### parameter setup #####
86  const int Nc = CommonParameters::Nc();
87  const int Nvol = CommonParameters::Nvol();
88  const int Ndim = CommonParameters::Ndim();
89 
90  const Parameters params_all = ParameterManager::read(filename_input);
91 
92  const Parameters params_test = params_all.lookup("Test_HMC_Clover_Isochemical");
93  const Parameters params_action_G = params_all.lookup("Action_G");
94  const Parameters params_fopr_Nf2 = params_all.lookup("Fopr_Nf2");
95  const Parameters params_fopr_Nf2_prec = params_all.lookup("Fopr_Nf2_prec");
96  const Parameters params_fopr_Nf1 = params_all.lookup("Fopr_Nf1");
97  const Parameters params_proj = params_all.lookup("Projection");
98  const Parameters params_smear = params_all.lookup("Smear");
99  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
100  const Parameters params_rational_MD = params_all.lookup("Fopr_Rational_MD");
101  const Parameters params_rational_H = params_all.lookup("Fopr_Rational_H");
102  const Parameters params_solver_Nf2_MD = params_all.lookup("Solver_Nf2_MD");
103  const Parameters params_solver_Nf2_H = params_all.lookup("Solver_Nf2_H");
104  const Parameters params_solver_Nf2_MD_prec = params_all.lookup("Solver_Nf2_MD_prec");
105  const Parameters params_solver_Nf2_H_prec = params_all.lookup("Solver_Nf2_H_prec");
106  const Parameters params_integrator = params_all.lookup("Builder_Integrator");
107  const Parameters params_hmc = params_all.lookup("HMC_General");
108 
109  const string str_gconf_status = params_test.get_string("gauge_config_status");
110  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
111  const string readfile = params_test.get_string("config_filename_input");
112  const string str_gconf_write = params_test.get_string("gauge_config_type_output");
113  const string writefile = params_test.get_string("config_filename_output");
114  const string str_rand_type = params_test.get_string("random_number_type");
115  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
116  int i_conf = params_test.get_int("trajectory_number");
117  const int Ntraj = params_test.get_int("trajectory_number_step");
118  const int i_save_conf = params_test.get_int("save_config_interval");
119  const int i_seed_noise = params_test.get_int("int_seed_for_noise");
120  const string str_vlevel = params_test.get_string("verbose_level");
121 
122  const bool do_check = params_test.is_set("expected_result");
123  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
124 
125  const string str_action_G_type = params_action_G.get_string("action_type");
126  const string str_fopr_Nf2_type = params_fopr_Nf2.get_string("fermion_type");
127  const string str_fopr_Nf2_prec_type = params_fopr_Nf2_prec.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 string str_solver_Nf2_MD_type = params_solver_Nf2_MD.get_string("solver_type");
134  const string str_solver_Nf2_H_type = params_solver_Nf2_H.get_string("solver_type");
135  const string str_solver_Nf2_MD_prec_type = params_solver_Nf2_MD_prec.get_string("solver_type");
136  const string str_solver_Nf2_H_prec_type = params_solver_Nf2_H_prec.get_string("solver_type");
137  const int Nlevels = params_integrator.get_int("number_of_levels");
138  const std::vector<int> level_action = params_integrator.get_int_vector("level_of_actions");
139 
140  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
141 
142  //- print input parameters
143  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
144  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
145  vout.general(vl, " readfile = %s\n", readfile.c_str());
146  vout.general(vl, " gconf_write = %s\n", str_gconf_write.c_str());
147  vout.general(vl, " writefile = %s\n", writefile.c_str());
148  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
149  vout.general(vl, " seed = %lu\n", seed);
150  vout.general(vl, " i_conf = %d\n", i_conf);
151  vout.general(vl, " Ntraj = %d\n", Ntraj);
152  vout.general(vl, " i_save_conf = %d\n", i_save_conf);
153  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
154  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
155  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
156  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
157  vout.general(vl, " solver_Nf2_MD_type = %s\n", str_solver_Nf2_MD_type.c_str());
158  vout.general(vl, " solver_Nf2_H_type = %s\n", str_solver_Nf2_H_type.c_str());
159  vout.general(vl, " solver_Nf2_MD_prec_type = %s\n", str_solver_Nf2_MD_prec_type.c_str());
160  vout.general(vl, " solver_Nf2_H_prec_type = %s\n", str_solver_Nf2_H_prec_type.c_str());
161 
162  //- input parameter check
163  int err = 0;
164  err += ParameterCheck::non_NULL(str_gconf_status);
165  err += ParameterCheck::non_negative(i_conf);
166  err += ParameterCheck::non_negative(Ntraj);
167  err += ParameterCheck::non_negative(i_save_conf);
168 
169  if (err) {
170  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
171  exit(EXIT_FAILURE);
172  }
173 
174  // if ( (Nsmear > 0) && (str_proj_type == "Stout_SU3") ) {
175  if (str_proj_type == "Stout_SU3") {
176  if (CommonParameters::Nc() != 3) {
177  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
178  return EXIT_SKIP;
179  }
180  }
181 
182 
183  RandomNumberManager::initialize(str_rand_type, seed);
184 
185 
186  // ##### object setup #####
187  Field_G U(Nvol, Ndim);
188 
189  if (str_gconf_status == "Continue") {
190  GaugeConfig(str_gconf_read).read(U, readfile);
191  } else if (str_gconf_status == "Cold_start") {
192  GaugeConfig("Unit").read(U);
193  } else if (str_gconf_status == "Hot_start") {
194  GaugeConfig("Random").read(U);
195  } else {
196  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
197  exit(EXIT_FAILURE);
198  }
199 
200  GaugeConfig gconf_write(str_gconf_write);
201 
202 
203  //-- gauge part
204  unique_ptr<Action> action_G(Action::New(str_action_G_type, params_action_G));
205 
206  //-- smear part
207  unique_ptr<Projection> proj(Projection::New(str_proj_type, params_proj));
208  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj.get(), params_smear));
209 
210  unique_ptr<ForceSmear> force_smear(ForceSmear::New(str_smear_type, proj.get(), params_smear));
211 
212  unique_ptr<Director_Smear> dr_smear(new Director_Smear(smear.get(), params_dr_smear));
213 
214 
215  //-- N_f=2 part
216  unique_ptr<Fopr> fopr_Nf2(new Fopr_Clover_Chemical(params_fopr_Nf2));
217  unique_ptr<Force> force_fopr_Nf2(new Force_F_Clover_Nf2_Isochemical(params_fopr_Nf2));
218 
219  unique_ptr<Fopr> fopr_smear_Nf2(new Fopr_Smeared(fopr_Nf2.get(), dr_smear.get()));
220  unique_ptr<Force> force_fopr_smear_Nf2(new Force_F_Smeared(force_fopr_Nf2.get(), force_smear.get(), dr_smear.get()));
221 
222  unique_ptr<Solver> solver_Nf2_MD(Solver::New(str_solver_Nf2_MD_type, fopr_smear_Nf2.get(), params_solver_Nf2_MD));
223  unique_ptr<Fprop> fprop_Nf2_MD(new Fprop_Standard_lex(solver_Nf2_MD.get()));
224 
225  unique_ptr<Solver> solver_Nf2_H(Solver::New(str_solver_Nf2_H_type, fopr_smear_Nf2.get(), params_solver_Nf2_H));
226  unique_ptr<Fprop> fprop_Nf2_H(new Fprop_Standard_lex(solver_Nf2_H.get()));
227 
228 
229  //-- N_f=2 part (preconditioner)
230  unique_ptr<Fopr> fopr_Nf2_prec(new Fopr_Clover_Chemical(params_fopr_Nf2_prec));
231  unique_ptr<Force> force_fopr_Nf2_prec(new Force_F_Clover_Nf2_Isochemical(params_fopr_Nf2_prec));
232 
233  unique_ptr<Fopr> fopr_smear_Nf2_prec(new Fopr_Smeared(fopr_Nf2_prec.get(), dr_smear.get()));
234  unique_ptr<Force> force_fopr_smear_Nf2_prec(new Force_F_Smeared(force_fopr_Nf2_prec.get(), force_smear.get(), dr_smear.get()));
235 
236  unique_ptr<Solver> solver_Nf2_MD_prec(Solver::New(str_solver_Nf2_MD_prec_type, fopr_smear_Nf2_prec.get(), params_solver_Nf2_MD_prec));
237  unique_ptr<Fprop> fprop_Nf2_MD_prec(new Fprop_Standard_lex(solver_Nf2_MD_prec.get()));
238 
239  unique_ptr<Solver> solver_Nf2_H_prec(Solver::New(str_solver_Nf2_H_prec_type, fopr_smear_Nf2_prec.get(), params_solver_Nf2_H_prec));
240  unique_ptr<Fprop> fprop_Nf2_H_prec(new Fprop_Standard_lex(solver_Nf2_H_prec.get()));
241 
242 
243  unique_ptr<Action> action_F_Nf2_prec(new Action_F_Standard_lex(fopr_smear_Nf2_prec.get(), force_fopr_smear_Nf2_prec.get(), fprop_Nf2_MD_prec.get(), fprop_Nf2_H_prec.get()));
244 
245  unique_ptr<Action> action_F_Nf2_d(new Action_F_Ratio_lex(fopr_smear_Nf2_prec.get(), force_fopr_smear_Nf2_prec.get(), fopr_smear_Nf2.get(), force_fopr_smear_Nf2.get(), fprop_Nf2_H_prec.get(), fprop_Nf2_MD.get(), fprop_Nf2_H.get()));
246 
247 
248  //-- N_f=1 part
249  unique_ptr<Fopr> fopr_Nf1(new Fopr_Clover_Chemical(params_fopr_Nf1));
250 
251  //- NB. create Force_F_Nf2, then apply rational approximation
252  unique_ptr<Force> force_fopr_Nf1(new Force_F_Clover_Nf2_Isochemical(params_fopr_Nf1));
253 
254  //- NB. Langevin needs params_rational_H
255  unique_ptr<Fopr> fopr_r1(new Fopr_Rational(fopr_Nf1.get(), params_rational_H));
256  unique_ptr<Fopr> fopr_smear_Nf1_langev(new Fopr_Smeared(fopr_r1.get(), dr_smear.get()));
257 
258  //- NB. Hamiltonian needs params_rational_MD
259  unique_ptr<Fopr> fopr_r2(new Fopr_Rational(fopr_Nf1.get(), params_rational_MD));
260  unique_ptr<Fopr> fopr_smear_Nf1_H(new Fopr_Smeared(fopr_r2.get(), dr_smear.get()));
261 
262  unique_ptr<Force> force_fopr_Nf1_MD(new Force_F_Rational(fopr_Nf1.get(), force_fopr_Nf1.get(), params_rational_MD));
263  unique_ptr<Force> force_fopr_smear_Nf1_MD(new Force_F_Smeared(force_fopr_Nf1_MD.get(), force_smear.get(), dr_smear.get()));
264 
265 
266  unique_ptr<Action> action_F_Nf1(new Action_F_Rational(fopr_smear_Nf1_langev.get(), fopr_smear_Nf1_H.get(), force_fopr_smear_Nf1_MD.get()));
267 
268 
269  ActionList actions(Nlevels);
270  actions.append(level_action[0], action_F_Nf2_d.get());
271  actions.append(level_action[1], action_F_Nf2_prec.get());
272  actions.append(level_action[2], action_F_Nf1.get());
273  actions.append(level_action[3], action_G.get());
274 
275  std::vector<Director *> directors(1);
276  directors[0] = static_cast<Director *>(dr_smear.get());
277 
278  unique_ptr<Builder_Integrator> builder(new Builder_Integrator(actions, directors, params_integrator));
279  Integrator *integrator = builder->build();
280 
281  //- Random number is initialized with a parameter specified by i_conf
282  unique_ptr<RandomNumbers> rand(new RandomNumbers_Mseries(i_conf));
283 
284  HMC_General hmc(actions, directors, integrator, rand.get(), params_hmc);
285 
286 
287  unique_ptr<PolyakovLoop> ploop(new PolyakovLoop);
288 
289  unique_ptr<RandomNumbers> rand_nv(new RandomNumbers_Mseries(i_seed_noise));
290  unique_ptr<NoiseVector> nv(new NoiseVector_Z2(rand_nv.get()));
291  unique_ptr<QuarkNumberSusceptibility_Wilson> quark_suscept(new QuarkNumberSusceptibility_Wilson(fopr_smear_Nf2.get(), fprop_Nf2_H.get(), nv.get(), params_test));
292 
293  Timer timer(test_name);
294 
295 
296  // #### Execution main part ####
297  timer.start();
298 
299  vout.general(vl, "HMC start: Ntraj = %d\n", Ntraj);
300 
301  const dcomplex ploop0 = ploop->measure_ploop(U);
302  vout.general(vl, "Polyakov loop = %e %e\n", real(ploop0), imag(ploop0));
303 
304  fopr_smear_Nf2->set_config(&U);
305  const double result_quark_suscept0 = quark_suscept->measure();
306 
307  double result = 0.0;
308  for (int traj = 0; traj < Ntraj; ++traj) {
309  vout.general(vl, "\n");
310  vout.general(vl, "---------------------------------------------------\n");
311  vout.general(vl, "traj = %d\n", traj);
312 
313  result = hmc.update(U);
314 
315  if ((i_conf + traj + 1) % i_save_conf == 0) {
316  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
317  gconf_write.write_file(U, filename);
318  }
319 
320  dcomplex ploop1 = ploop->measure_ploop(U);
321  vout.general(vl, "Polyakov loop = %e %e\n", real(ploop1), imag(ploop1));
322 
323  fopr_smear_Nf2->set_config(&U);
324  double result_quark_suscept1 = quark_suscept->measure();
325  }
326 
327  gconf_write.write_file(U, writefile);
328 
329  timer.report();
330 
332 
333 
334  if (do_check) {
335  return Test::verify(result, expected_result);
336  } else {
337  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
338  return EXIT_SKIP;
339  }
340  }
341 } // namespace Test_HMC_Clover_Isochemical
Test_HMC_Clover_Isochemical::RHMC_Nf2p1
int RHMC_Nf2p1(void)
Definition: test_HMC_Clover_Isochemical_RHMC_Nf2p1.cpp:83
Test::verify
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Test_HMC_Clover_Isochemical
Test of HMC update for clover fermions with isochemical potential.
Definition: test_HMC_Clover_Isochemical_Nf2.cpp:53
randomNumbers_Mseries.h
action_F_Rational.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
Fopr_Clover_Chemical
AFopr_Clover_Chemical< Field > Fopr_Clover_Chemical
Definition: fopr_Clover_Chemical.h:19
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
polyakovLoop.h
Action_F_Rational
action class for RHMC, with externally constructed Fopr_Rational.
Definition: action_F_Rational.h:37
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
QuarkNumberSusceptibility_Wilson
Quark number susceptibility for the Wilson-type fermion.
Definition: quarkNumberSusceptibility_Wilson.h:37
ActionList
lists of actions at respective integrator levels.
Definition: action_list.h:40
math_Rational.h
RandomNumberManager::initialize
static bool initialize(const std::string &rng_type, unsigned long seed)
Definition: randomNumberManager.cpp:57
Fopr_Rational
AFopr_Rational< Field > Fopr_Rational
Fermion operator for rational approximation.
Definition: fopr_Rational.h:46
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
noiseVector_Z2.h
ParameterCheck::vl
Bridge::VerboseLevel vl
Definition: parameterCheck.cpp:18
RandomNumbers_Mseries
Random number generator base on M-series.
Definition: randomNumbers_Mseries.h:46
quarkNumberSusceptibility_Wilson.h
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
Fopr_Smeared
smeared fermion operator.
Definition: fopr_Smeared.h:41
NoiseVector_Z2
Z2 Noise vector for a trace calculation.
Definition: noiseVector_Z2.h:28
Director_Smear
Manager of smeared configurations.
Definition: director_Smear.h:39
PolyakovLoop
Polyakov loop measurement.
Definition: polyakovLoop.h:41
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
Director
Manager of commonly used data object in HMC.
Definition: director.h:37
Test_HMC_Clover_Isochemical::test_name
const std::string test_name
Definition: test_HMC_Clover_Isochemical_Nf2.cpp:54
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_Nf2_Isochemical.h
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
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
Force_F_Clover_Nf2_Isochemical
Force calculation for clover quark action.
Definition: force_F_Clover_Nf2_Isochemical.h:36
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