Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_HMC_Clover_Isochemical_Nf2.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
17 
18 #include "Fopr/fopr_Smeared.h"
19 
22 
23 #include "HMC/hmc_General.h"
24 #include "HMC/builder_Integrator.h"
25 
26 #include "IO/gaugeConfig.h"
27 
32 
33 #include "Tools/file_utils.h"
36 
37 //====================================================================
39 
52 namespace Test_HMC_Clover_Isochemical {
53  const std::string test_name = "HMC.Clover_Isochemical.Nf2";
54 
55  //- test-private parameters
56  namespace {
57  const std::string filename_input = "test_HMC_Clover_Isochemical_Nf2.yaml";
58  }
59 
60  //- prototype declaration
61  int update_Nf2(void);
62 
63 #ifdef USE_TESTMANAGER_AUTOREGISTER
64  namespace {
65 #if defined(USE_GROUP_SU2)
66  // Nc=2 is not available.
67 #else
68  static const bool is_registered = TestManager::RegisterTest(
69  test_name,
71  );
72 #endif
73  }
74 #endif
75 
76  //====================================================================
77  int update_Nf2(void)
78  {
79  // ##### parameter setup #####
80  const int Nc = CommonParameters::Nc();
81  const int Nvol = CommonParameters::Nvol();
82  const int Ndim = CommonParameters::Ndim();
83 
84  const Parameters params_all = ParameterManager::read(filename_input);
85 
86  const Parameters params_test = params_all.lookup("Test_HMC_Clover_Isochemical");
87  const Parameters params_action_G = params_all.lookup("Action_G");
88  const Parameters params_fopr = params_all.lookup("Fopr");
89  const Parameters params_proj = params_all.lookup("Projection");
90  const Parameters params_smear = params_all.lookup("Smear");
91  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
92  const Parameters params_solver_MD = params_all.lookup("Solver_MD");
93  const Parameters params_solver_H = params_all.lookup("Solver_H");
94  const Parameters params_integrator = params_all.lookup("Builder_Integrator");
95  const Parameters params_hmc = params_all.lookup("HMC_General");
96 
97  const string str_gconf_status = params_test.get_string("gauge_config_status");
98  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
99  const string readfile = params_test.get_string("config_filename_input");
100  const string str_gconf_write = params_test.get_string("gauge_config_type_output");
101  const string writefile = params_test.get_string("config_filename_output");
102  const string str_rand_type = params_test.get_string("random_number_type");
103  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
104  int i_conf = params_test.get_int("trajectory_number");
105  const int Ntraj = params_test.get_int("trajectory_number_step");
106  const int i_save_conf = params_test.get_int("save_config_interval");
107  const int i_seed_noise = params_test.get_int("int_seed_for_noise");
108  const string str_vlevel = params_test.get_string("verbose_level");
109 
110  const bool do_check = params_test.is_set("expected_result");
111  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
112 
113  const string str_action_G_type = params_action_G.get_string("action_type");
114  const string str_fopr_type = params_fopr.get_string("fermion_type");
115  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
116  const string str_proj_type = params_proj.get_string("projection_type");
117  const string str_smear_type = params_smear.get_string("smear_type");
118  const string str_solver_MD_type = params_solver_MD.get_string("solver_type");
119  const string str_solver_H_type = params_solver_H.get_string("solver_type");
120  const int Nlevels = params_integrator.get_int("number_of_levels");
121  const std::vector<int> level_action = params_integrator.get_int_vector("level_of_actions");
122 
123  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
124 
125  //- print input parameters
126  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
127  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
128  vout.general(vl, " readfile = %s\n", readfile.c_str());
129  vout.general(vl, " gconf_write = %s\n", str_gconf_write.c_str());
130  vout.general(vl, " writefile = %s\n", writefile.c_str());
131  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
132  vout.general(vl, " seed = %lu\n", seed);
133  vout.general(vl, " i_conf = %d\n", i_conf);
134  vout.general(vl, " Ntraj = %d\n", Ntraj);
135  vout.general(vl, " i_save_conf = %d\n", i_save_conf);
136  vout.general(vl, " i_seed_noise = %d\n", i_seed_noise);
137  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
138  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
139  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
140  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
141  vout.general(vl, " solver_MD_type = %s\n", str_solver_MD_type.c_str());
142  vout.general(vl, " solver_H_type = %s\n", str_solver_H_type.c_str());
143  vout.general(vl, "\n");
144 
145  //- input parameter check
146  int err = 0;
147  err += ParameterCheck::non_NULL(str_gconf_status);
148  err += ParameterCheck::non_negative(i_conf);
149  err += ParameterCheck::non_negative(Ntraj);
150  err += ParameterCheck::non_negative(i_save_conf);
151 
152  if (err) {
153  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
154  exit(EXIT_FAILURE);
155  }
156 
157  RandomNumberManager::initialize(str_rand_type, seed);
158 
159 
160  // ##### object setup #####
161  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
162 
163  if (str_gconf_status == "Continue") {
164  GaugeConfig(str_gconf_read).read(U, readfile);
165  } else if (str_gconf_status == "Cold_start") {
166  GaugeConfig("Unit").read(U);
167  } else if (str_gconf_status == "Hot_start") {
168  GaugeConfig("Random").read(U);
169  } else {
170  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
171  exit(EXIT_FAILURE);
172  }
173 
174  const unique_ptr<GaugeConfig> gconf_write(new GaugeConfig(str_gconf_write));
175 
176 
177  unique_ptr<Action> action_G(Action::New(str_action_G_type));
178  action_G->set_parameters(params_action_G);
179 
180  //-- N_f=2 part
181  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
182  fopr->set_parameters(params_fopr);
183 
184  unique_ptr<Force> force_fopr(new Force_F_Clover_Nf2_Isochemical(str_gmset_type));
185  // define fermion force (SA)
186  force_fopr->set_parameters(params_fopr);
187 
188  // define smearing method (SA)
189  unique_ptr<Projection> proj(Projection::New(str_proj_type));
190  proj->set_parameters(params_proj);
191 
192  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
193  smear->set_parameters(params_smear);
194 
195  // define force smearing method (SA)
196  unique_ptr<ForceSmear> force_smear(ForceSmear::New(str_smear_type, proj));
197  force_smear->set_parameters(params_smear);
198 
199  unique_ptr<Director> dr_smear(new Director_Smear(smear));
200  dr_smear->set_parameters(params_dr_smear);
201 
202  unique_ptr<Fopr> fopr_smear(Fopr::New("Smeared", fopr, dr_smear));
203  // define smeared fermion operator (SA)
204  unique_ptr<Force> force_fopr_smear(
205  new Force_F_Smeared(force_fopr, force_smear, dr_smear));
206  // define smeared fermion force (SA)
207 
208 
209  unique_ptr<Solver> solver_MD(Solver::New(str_solver_MD_type, fopr_smear));
210  solver_MD->set_parameters(params_solver_MD);
211  unique_ptr<Fprop> fprop_MD(new Fprop_Standard_lex(solver_MD));
212 
213  unique_ptr<Solver> solver_H(Solver::New(str_solver_H_type, fopr_smear));
214  solver_H->set_parameters(params_solver_H);
215  unique_ptr<Fprop> fprop_H(new Fprop_Standard_lex(solver_H));
216 
217  unique_ptr<Action> action_F(
218  new Action_F_Standard_lex(fopr_smear, force_fopr_smear,
219  fprop_MD, fprop_H));
220  // define fermion action (SA)
221 
222 
223  ActionList actions(Nlevels);
224  actions.append(level_action[0], action_F);
225  actions.append(level_action[1], action_G);
226 
227  std::vector<Director *> directors(1);
228  directors[0] = (Director *)dr_smear.get(); // register director[0] (SA)
229 
230  const unique_ptr<Builder_Integrator> builder(new Builder_Integrator(actions, directors));
231  builder->set_parameters(params_integrator);
232  Integrator *integrator = builder->build();
233 
234  //- Random number is initialized with a parameter specified by i_conf
236 
237  HMC_General hmc(actions, directors, integrator, rand); // define hmc_leapfrog (SA)
238  hmc.set_parameters(params_hmc);
239 
240 
241  const unique_ptr<PolyakovLoop> ploop(new PolyakovLoop());
242 
243  unique_ptr<RandomNumbers> rand_nv(new RandomNumbers_Mseries(i_seed_noise));
244  unique_ptr<NoiseVector> nv(new NoiseVector_Z2(rand_nv));
246  new QuarkNumberSusceptibility_Wilson(fopr_smear, fprop_H, nv));
247  quark_suscept->set_parameters(params_test);
248 
249  const unique_ptr<Timer> timer(new Timer(test_name));
250 
251 
252  // #### Execution main part ####
253  timer->start();
254 
255  vout.general(vl, "HMC: Ntraj = %d\n", Ntraj);
256 
257  const dcomplex ploop0 = ploop->measure_ploop(*U);
258  vout.general(vl, "Polyakov loop = %e %e\n", real(ploop0), imag(ploop0));
259 
260  double result = 0.0;
261  for (int traj = 0; traj < Ntraj; ++traj) {
262  vout.general(vl, "\n");
263  vout.general(vl, "traj = %d\n", traj);
264 
265  result = hmc.update(*U); // hmc update (SA)
266 
267  if ((i_conf + traj + 1) % i_save_conf == 0) {
268  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
269  gconf_write->write_file(U, filename);
270  }
271 
272  dcomplex ploop1 = ploop->measure_ploop(*U);
273  vout.general(vl, "Polyakov loop = %e %e\n", real(ploop1), imag(ploop1));
274 
275  double result_quark_suscept1 = quark_suscept->measure();
276  }
277 
278  gconf_write->write_file(U, writefile);
279 
280  timer->report();
281 
283 
284 
285  if (do_check) {
286  return Test::verify(result, expected_result);
287  } else {
288  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
289  return EXIT_SKIP;
290  }
291  }
292 } // namespace Test_HMC_Clover_Isochemical
#define EXIT_SKIP
Definition: test.h:17
Random number generator base on M-series.
BridgeIO vout
Definition: bridgeIO.cpp:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
virtual void set_parameters(const Parameters &param)=0
void set_parameters(const Parameters &params)
void general(const char *format,...)
Definition: bridgeIO.cpp:197
Force calculation for clover quark action.
General HMC update class.
Definition: hmc_General.h:45
virtual void set_parameters(const Parameters &)=0
int get_int(const string &key) const
Definition: parameters.cpp:192
Class for parameters.
Definition: parameters.h:46
bool append(const int level, Action *action)
Definition: action_list.cpp:27
virtual void set_parameters(const Parameters &param)=0
Base class of Integrator class family.
Definition: integrator.h:29
virtual void set_parameters(const Parameters &params)=0
Parameters lookup(const string &key) const
Definition: parameters.h:79
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:69
static bool initialize(const std::string &rng_type, unsigned long seed)
SU(N) gauge field.
Definition: field_G.h:38
void set_parameters(const Parameters &params)
Manager of commonly used data object in HMC.
Definition: director.h:37
void read(Field_G *U, const string &filename=string())
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:209
double get_double(const string &key) const
Definition: parameters.cpp:175
std::string generate_filename(const char *fmt,...)
Definition: file_utils.cpp:17
Polyakov loop measurement.
Definition: polyakovLoop.h:40
Quark number susceptibility for the Wilson-type fermion.
pointer get() const
virtual void set_parameters(const Parameters &)=0
double measure()
measure tr1 = Tr[D1*Sq], tr2 = Tr[D2*Sq], tr3 = Tr[D1*Sq*D1*Sq].
int non_NULL(const std::string v)
bool is_set(const string &key) const
Definition: parameters.cpp:528
void start()
Definition: timer.cpp:44
Get quark propagator for Fopr with lexical site index.
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
virtual void set_parameters(const Parameters &params)=0
static void read(const std::string &params_file, Parameters &params)
lists of actions at respective integrator levels.
Definition: action_list.h:40
Manager of smeared configurations.
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Bridge::VerboseLevel vl
VerboseLevel
Definition: bridgeIO.h:42
double update(Field_G &)
void write_file(Field_G *U, const string &filename)
Definition: gaugeConfig.h:109
Force calculation for smeared fermion operators.
int non_negative(const int v)
virtual void set_parameters(const Parameters &)=0
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:78
Definition: timer.h:31
Z2 Noise vector for a trace calculation.
string get_string(const string &key) const
Definition: parameters.cpp:221
vector< int > get_int_vector(const string &key) const
Definition: parameters.cpp:267
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
virtual void set_parameters(const Parameters &)=0
Builder of MD integrator for HMC.
Standard fermion action for HMC.
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
dcomplex measure_ploop(const Field_G &U)
Polyakov loop measurement.