Bridge++  Version 1.4.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 "Tests/test.h"
15 
16 #include "IO/gaugeConfig.h"
18 
20 
21 //====================================================================
23 
33 namespace Test_Gauge {
34  const std::string test_name = "Gauge.Plaquette";
35 
36  //- test-private parameters
37  namespace {
38  // const std::string filename_input = "test_Gauge.yaml";
39  }
40 
41  //- prototype declaration
42  // int plaquette(void);
43  int plaquette(const std::string&);
44 
45  //- plaq for various types of index
47  {
48  return plaquette("test_Gauge_lex.yaml");
49  }
50 
51 
53  {
54  return plaquette("test_Gauge_eo.yaml");
55  }
56 
57 
58 #ifdef USE_TESTMANAGER_AUTOREGISTER
59  namespace {
60 #if defined(USE_GROUP_SU2)
61  // Nc=2 is not available.
62 #else
63  static const bool is_registered_lex = TestManager::RegisterTest(
64  "Gauge.Plaquette.lex",
66  );
67 
68  static const bool is_registered_eo = TestManager::RegisterTest(
69  "Gauge.Plaquette.eo",
71  );
72 #endif
73  }
74 #endif
75 
76  //====================================================================
77  int plaquette(const std::string& filename_input)
78  {
79  // ##### parameter setup #####
80  int Nvol = CommonParameters::Nvol();
81  int Ndim = CommonParameters::Ndim();
82 
83  Parameters params_all = ParameterManager::read(filename_input);
84 
85  Parameters params_test = params_all.lookup("Test_Gauge");
86  Parameters params_staple = params_all.lookup("Staple");
87 
88  const string str_gconf_status = params_test.get_string("gauge_config_status");
89  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
90  const string readfile = params_test.get_string("config_filename_input");
91  const string str_rand_type = params_test.get_string("random_number_type");
92  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
93  const string str_vlevel = params_test.get_string("verbose_level");
94 
95  const bool do_check = params_test.is_set("expected_result");
96  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
97 
98  const string str_index_type = params_staple.get_string("index_type");
99 
101 
102  //- print input parameters
103  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
104  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
105  vout.general(vl, " readfile = %s\n", readfile.c_str());
106  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
107  vout.general(vl, " seed = %lu\n", seed);
108  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
109  vout.general(vl, "\n");
110 
111  //- input parameter check
112  int err = 0;
113  err += ParameterCheck::non_NULL(str_gconf_status);
114 
115  if (err) {
116  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
117  exit(EXIT_FAILURE);
118  }
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  unique_ptr<Staple> staple(Staple::New(str_index_type));
141  staple->set_parameters(params_staple);
142 
143  unique_ptr<Timer> timer(new Timer(test_name));
144 
145 
146  // #### Execution main part ####
147  timer->start();
148 
149  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:495
void detailed(const char *format,...)
Definition: bridgeIO.cpp:212
void general(const char *format,...)
Definition: bridgeIO.cpp:195
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:78
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:104
double get_double(const string &key) const
Definition: parameters.cpp:70
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
int plaquette(const std::string &)
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:75
Definition: timer.h:31
virtual void set_parameters(const Parameters &params)=0
setting parameters.
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