Bridge++  Ver. 2.0.2
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  Field_G U(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 
134  unique_ptr<Projection> proj(Projection::New(str_proj_type, params_proj));
135  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj.get(), params_smear));
136 
137  Timer timer(test_name);
138 
139 
140  // #### Execution main part ####
141  timer.start();
142 
143  Field_G Uorg(Nvol, Ndim);
144  Uorg = U;
145 
146  double result = 0.0;
147  for (int i_smear = 0; i_smear <= Nsmear; ++i_smear) {
148  Field_G Usmear(Nvol, Ndim);
149  if (i_smear == 0) copy(Usmear, Uorg);
150  if (i_smear > 0) smear->smear(Usmear, Uorg);
151 
152  if ((i_smear % Nmeas) == 0) {
153  result = topological_charge.measure(Usmear);
154 
155  vout.general(vl, "i_smear,Q = %d %20.16e\n", i_smear, result);
156  vout.general(vl, "\n");
157  }
158 
159  Uorg = Usmear;
160  }
161 
162  timer.report();
163 
165 
166 
167  if (do_check) {
168  return Test::verify(result, expected_result);
169  } else {
170  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
171  return EXIT_SKIP;
172  }
173  }
174 } // namespace Test_TopologicalCharge
topologicalCharge.h
Test::verify
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Test_TopologicalCharge::test_name
const std::string test_name
Definition: test_TopologicalCharge.cpp:36
ParameterCheck::non_NULL
int non_NULL(const std::string v)
Definition: parameterCheck.cpp:65
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:219
GaugeConfig::read
void read(Field_G &U, const string &filename=string())
Definition: gaugeConfig.cpp:121
gaugeConfig.h
CommonParameters::Nvol
static int Nvol()
Definition: commonParameters.h:109
Test_TopologicalCharge::topological_charge
int topological_charge(void)
Definition: test_TopologicalCharge.cpp:60
Timer
Definition: timer.h:31
RandomNumberManager::finalize
static void finalize()
Definition: randomNumberManager.cpp:80
copy
void copy(Field &y, const Field &x)
copy(y, x): y = x
Definition: field.cpp:212
RandomNumberManager::initialize
static bool initialize(const std::string &rng_type, unsigned long seed)
Definition: randomNumberManager.cpp:57
Timer::start
void start()
Definition: timer.cpp:44
ParameterCheck::vl
Bridge::VerboseLevel vl
Definition: parameterCheck.cpp:18
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
Test_TopologicalCharge
Test of Topological Charge measurement.
Definition: testlist.h:285
Parameters::get_unsigned_long
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:209
TopologicalCharge
Topological Charge measurement.
Definition: topologicalCharge.h:43
EXIT_SKIP
#define EXIT_SKIP
Definition: test.h: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
smear.h
Parameters::is_set
bool is_set(const string &key) const
Definition: parameters.cpp:525
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
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42
Field_G
SU(N) gauge field.
Definition: field_G.h:38
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
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