Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Gauge_Plaquette.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "IO/gaugeConfig.h"
17 
19 
21 
22 //====================================================================
24 
34 namespace Test_Gauge {
35  const std::string test_name = "Gauge.Plaquette";
36 
37  //- test-private parameters
38  namespace {
39  // const std::string filename_input = "test_Gauge.yaml";
40  }
41 
42  //- prototype declaration
43  // int plaquette(void);
44  int plaquette(const std::string&);
45 
46  //- plaq for various types of index
48  {
49  return plaquette("test_Gauge_lex.yaml");
50  }
51 
52 
54  {
55  return plaquette("test_Gauge_eo.yaml");
56  }
57 
58 
59 #ifdef USE_TESTMANAGER_AUTOREGISTER
60  namespace {
61 #if defined(USE_GROUP_SU2)
62  // Nc=2 is not available.
63 #else
64  static const bool is_registered_lex = TestManager::RegisterTest(
65  "Gauge.Plaquette.lex",
67  );
68 
69  static const bool is_registered_eo = TestManager::RegisterTest(
70  "Gauge.Plaquette.eo",
72  );
73 #endif
74  }
75 #endif
76 
77  //====================================================================
78  int plaquette(const std::string& filename_input)
79  {
80  // ##### parameter setup #####
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_Gauge");
87  const Parameters params_staple = params_all.lookup("Staple");
88 
89  const string str_gconf_status = params_test.get_string("gauge_config_status");
90  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
91  const string readfile = params_test.get_string("config_filename_input");
92  const string str_rand_type = params_test.get_string("random_number_type");
93  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
94  const string str_vlevel = params_test.get_string("verbose_level");
95 
96  const bool do_check = params_test.is_set("expected_result");
97  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
98 
99  const string str_index_type = params_staple.get_string("index_type");
100 
101  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
102 
103  //- print input parameters
104  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
105  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
106  vout.general(vl, " readfile = %s\n", readfile.c_str());
107  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
108  vout.general(vl, " seed = %lu\n", seed);
109  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
110  vout.general(vl, "\n");
111 
112  //- input parameter check
113  int err = 0;
114  err += ParameterCheck::non_NULL(str_gconf_status);
115 
116  if (err) {
117  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
118  exit(EXIT_FAILURE);
119  }
120 
121  RandomNumberManager::initialize(str_rand_type, seed);
122 
123 
124  // #### Set up a gauge configuration ####
125  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
126 
127  if (str_gconf_status == "Continue") {
128  GaugeConfig(str_gconf_read).read(U, readfile);
129  } else if (str_gconf_status == "Cold_start") {
130  GaugeConfig("Unit").read(U);
131  } else if (str_gconf_status == "Hot_start") {
132  GaugeConfig("Random").read(U);
133  } else {
134  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
135  exit(EXIT_FAILURE);
136  }
137 
138 
139  // #### object setup #####
140  const unique_ptr<Staple> staple(Staple::New(str_index_type));
141  staple->set_parameters(params_staple);
142 
143  const unique_ptr<Timer> timer(new Timer(test_name));
144 
145 
146  // #### Execution main part ####
147  timer->start();
148 
149  const double result = staple->plaquette(*U);
150 
151  timer->report();
152 
154 
155 
156  if (do_check) {
157  return Test::verify(result, expected_result);
158  } else {
159  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
160  return EXIT_SKIP;
161  }
162  }
163 } // namespace Test_Gauge
#define EXIT_SKIP
Definition: test.h:17
BridgeIO vout
Definition: bridgeIO.cpp:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
void general(const char *format,...)
Definition: bridgeIO.cpp:197
virtual double plaquette(const Field_G &)=0
calculates plaquette value.
Class for parameters.
Definition: parameters.h:46
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
const std::string test_name
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
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
int plaquette(const std::string &)
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:78
Definition: timer.h:31
virtual void set_parameters(const Parameters &params)=0
setting parameters.
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