Bridge++  Version 1.4.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_TopologicalCharge.cpp
Go to the documentation of this file.
1 
14 #include "Tests/test.h"
15 
16 #include "IO/gaugeConfig.h"
17 
19 
20 #include "Smear/projection.h"
21 #include "Smear/smear.h"
22 
24 
25 //====================================================================
27 
36 namespace Test_TopologicalCharge {
37  const std::string test_name = "TopologicalCharge";
38 
39  //- test-private parameters
40  namespace {
41  const std::string filename_input = "test_TopologicalCharge.yaml";
42  }
43 
44  //- prototype declaration
45  int topological_charge(void);
46 
47 #ifdef USE_TESTMANAGER_AUTOREGISTER
48  namespace {
49 #if defined(USE_GROUP_SU2)
50  // Nc=2 is not available.
51 #else
52  static const bool is_registered = TestManager::RegisterTest(
53  test_name,
55  );
56 #endif
57  }
58 #endif
59 
60  //====================================================================
62  {
63  // #### parameter setup ####
64  int Nvol = CommonParameters::Nvol();
65  int Ndim = CommonParameters::Ndim();
66 
67  Parameters params_all = ParameterManager::read(filename_input);
68 
69  Parameters params_test = params_all.lookup("Test_TopologicalCharge");
70  Parameters params_topo = params_all.lookup("TopologicalCharge");
71  Parameters params_proj = params_all.lookup("Projection");
72  Parameters params_smear = params_all.lookup("Smear");
73 
74  const string str_gconf_status = params_test.get_string("gauge_config_status");
75  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
76  const string readfile = params_test.get_string("config_filename_input");
77  const string str_rand_type = params_test.get_string("random_number_type");
78  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
79  const int Nsmear = params_test.get_int("number_of_max_smearing");
80  const int Nmeas = params_test.get_int("number_of_measurement_step");
81  const string str_vlevel = params_test.get_string("verbose_level");
82 
83  const bool do_check = params_test.is_set("expected_result");
84  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
85 
86  const string str_proj_type = params_proj.get_string("projection_type");
87  const string str_smear_type = params_smear.get_string("smear_type");
88 
90 
91  //- print input parameters
92  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
93  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
94  vout.general(vl, " readfile = %s\n", readfile.c_str());
95  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
96  vout.general(vl, " seed = %lu\n", seed);
97  vout.general(vl, " Nsmear = %d\n", Nsmear);
98  vout.general(vl, " Nmeas = %d\n", Nmeas);
99  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
100  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
101  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
102  vout.general(vl, "\n");
103 
104  //- input parameter check
105  int err = 0;
106  err += ParameterCheck::non_NULL(str_gconf_status);
107 
108  if (err) {
109  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
110  exit(EXIT_FAILURE);
111  }
112 
113 
114  RandomNumberManager::initialize(str_rand_type, seed);
115 
116 
117  // #### Set up a gauge configuration ####
118  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
119 
120  if (str_gconf_status == "Continue") {
121  GaugeConfig(str_gconf_read).read(U, readfile);
122  } else if (str_gconf_status == "Cold_start") {
123  GaugeConfig("Unit").read(U);
124  } else if (str_gconf_status == "Hot_start") {
125  GaugeConfig("Random").read(U);
126  } else {
127  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
128  exit(EXIT_FAILURE);
129  }
130 
131 
132  // #### object setup #####
134  topological_charge->set_parameters(params_topo);
135 
136  unique_ptr<Projection> proj(Projection::New(str_proj_type));
137  proj->set_parameters(params_proj);
138 
139  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
140  smear->set_parameters(params_smear);
141 
142  unique_ptr<Timer> timer(new Timer(test_name));
143 
144 
145  // #### Execution main part ####
146  timer->start();
147 
148  Field_G Uorg(Nvol, Ndim), Usmear(Nvol, Ndim);
149  Uorg = *U;
150  Usmear = *U;
151 
152  double result = 0.0;
153  for (int i_smear = 0; i_smear <= Nsmear; ++i_smear) {
154  if (i_smear > 0) smear->smear(Usmear, Uorg);
155 
156  if ((i_smear % Nmeas) == 0) {
157  result = topological_charge->measure(Usmear);
158 
159  vout.general(vl, "i_smear,Q = %d %20.16e\n", i_smear, result);
160  vout.general(vl, "\n");
161  }
162 
163  Uorg = Usmear;
164  }
165 
166  timer->report();
167 
169 
170 
171  if (do_check) {
172  return Test::verify(result, expected_result);
173  } else {
174  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
175  return EXIT_SKIP;
176  }
177  }
178 } // namespace Test_TopologicalCharge
#define EXIT_SKIP
Definition: test.h:17
BridgeIO vout
Definition: bridgeIO.cpp:495
void detailed(const char *format,...)
Definition: bridgeIO.cpp:212
virtual void set_parameters(const Parameters &param)=0
void general(const char *format,...)
Definition: bridgeIO.cpp:195
double measure(Field_G &U)
main function to measure Topological Charge.
virtual void set_parameters(const Parameters &)=0
int get_int(const string &key) const
Definition: parameters.cpp:87
Class for parameters.
Definition: parameters.h:46
Parameters lookup(const string &key) const
Definition: parameters.h:78
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 read(Field_G *U, const string &filename=string())
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:104
double get_double(const string &key) const
Definition: parameters.cpp:70
virtual void smear(Field_G &, const Field_G &)=0
int non_NULL(const std::string v)
Definition: checker.cpp:61
bool is_set(const string &key) const
Definition: parameters.cpp:396
void start()
Definition: timer.cpp:44
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
static void read(const std::string &params_file, Parameters &params)
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Bridge::VerboseLevel vl
Definition: checker.cpp:18
VerboseLevel
Definition: bridgeIO.h:42
virtual void set_parameters(const Parameters &params)
setting parameters.
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:75
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:116
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
Topological Charge measurement.