Bridge++  Version 1.5.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 "test.h"
15 
16 #include "IO/gaugeConfig.h"
17 
19 
20 #include "Smear/smear.h"
21 
23 
24 //====================================================================
26 
35 namespace Test_TopologicalCharge {
36  const std::string test_name = "TopologicalCharge";
37 
38  //- test-private parameters
39  namespace {
40  const std::string filename_input = "test_TopologicalCharge.yaml";
41  }
42 
43  //- prototype declaration
44  int topological_charge(void);
45 
46 #ifdef USE_TESTMANAGER_AUTOREGISTER
47  namespace {
48 #if defined(USE_GROUP_SU2)
49  // Nc=2 is not available.
50 #else
51  static const bool is_registered = TestManager::RegisterTest(
52  test_name,
54  );
55 #endif
56  }
57 #endif
58 
59  //====================================================================
61  {
62  // #### parameter setup ####
63  const int Nvol = CommonParameters::Nvol();
64  const int Ndim = CommonParameters::Ndim();
65 
66  const Parameters params_all = ParameterManager::read(filename_input);
67 
68  const Parameters params_test = params_all.lookup("Test_TopologicalCharge");
69  const Parameters params_topo = params_all.lookup("TopologicalCharge");
70  const Parameters params_proj = params_all.lookup("Projection");
71  const Parameters params_smear = params_all.lookup("Smear");
72 
73  const string str_gconf_status = params_test.get_string("gauge_config_status");
74  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
75  const string readfile = params_test.get_string("config_filename_input");
76  const string str_rand_type = params_test.get_string("random_number_type");
77  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
78  const int Nsmear = params_test.get_int("number_of_max_smearing");
79  const int Nmeas = params_test.get_int("number_of_measurement_step");
80  const string str_vlevel = params_test.get_string("verbose_level");
81 
82  const bool do_check = params_test.is_set("expected_result");
83  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
84 
85  const string str_proj_type = params_proj.get_string("projection_type");
86  const string str_smear_type = params_smear.get_string("smear_type");
87 
88  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
89 
90  //- print input parameters
91  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
92  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
93  vout.general(vl, " readfile = %s\n", readfile.c_str());
94  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
95  vout.general(vl, " seed = %lu\n", seed);
96  vout.general(vl, " Nsmear = %d\n", Nsmear);
97  vout.general(vl, " Nmeas = %d\n", Nmeas);
98  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
99  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
100  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
101  vout.general(vl, "\n");
102 
103  //- input parameter check
104  int err = 0;
105  err += ParameterCheck::non_NULL(str_gconf_status);
106 
107  if (err) {
108  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
109  exit(EXIT_FAILURE);
110  }
111 
112 
113  RandomNumberManager::initialize(str_rand_type, seed);
114 
115 
116  // #### Set up a gauge configuration ####
117  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
118 
119  if (str_gconf_status == "Continue") {
120  GaugeConfig(str_gconf_read).read(U, readfile);
121  } else if (str_gconf_status == "Cold_start") {
122  GaugeConfig("Unit").read(U);
123  } else if (str_gconf_status == "Hot_start") {
124  GaugeConfig("Random").read(U);
125  } else {
126  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
127  exit(EXIT_FAILURE);
128  }
129 
130 
131  // #### object setup #####
133  topological_charge->set_parameters(params_topo);
134 
135  unique_ptr<Projection> proj(Projection::New(str_proj_type));
136  proj->set_parameters(params_proj);
137 
138  const unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
139  smear->set_parameters(params_smear);
140 
141  const unique_ptr<Timer> timer(new Timer(test_name));
142 
143 
144  // #### Execution main part ####
145  timer->start();
146 
147  Field_G Uorg(Nvol, Ndim);
148  Uorg = *U;
149 
150  double result = 0.0;
151  for (int i_smear = 0; i_smear <= Nsmear; ++i_smear) {
152  Field_G Usmear(Nvol, Ndim);
153  if (i_smear == 0) copy(Usmear, Uorg);
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:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
virtual void set_parameters(const Parameters &param)=0
void general(const char *format,...)
Definition: bridgeIO.cpp:197
virtual void set_parameters(const Parameters &)=0
double measure(const Field_G &U)
main function to measure Topological Charge. The field strength is constructed inside the function...
int get_int(const string &key) const
Definition: parameters.cpp:192
Class for parameters.
Definition: parameters.h:46
void copy(Field &y, const Field &x)
copy(y, x): y = x
Definition: field.cpp:532
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 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
virtual void smear(Field_G &, const Field_G &)=0
int non_NULL(const std::string v)
bool is_set(const string &key) const
Definition: parameters.cpp:528
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
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:78
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:221
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.