Bridge++  Ver. 1.3.x
test_Gauge_Shift.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "index_lex.h"
17 // #include "index_eo.h"
18 
19 #include "gaugeConfig.h"
20 #include "staples.h"
21 
22 #include "shiftField_lex.h"
23 
24 #include "randomNumbers_Mseries.h"
25 
26 //====================================================================
28 
37 namespace Test_Gauge {
38  const std::string test_name = "Gauge.Shift";
39 
40  //- test-private parameters
41  namespace {
42  const std::string filename_input = "test_Gauge.yaml";
43  const std::string filename_output = "stdout";
44 
45  class Parameters_Test_Gauge : public Parameters {
46  public:
47  Parameters_Test_Gauge()
48  {
49  Register_string("gauge_config_status", "NULL");
50  Register_string("gauge_config_type_input", "NULL");
51  Register_string("config_filename_input", "NULL");
52 
53  Register_string("verbose_level", "NULL");
54 
55  Register_double("expected_result", 0.0);
56  }
57  };
58  }
59 
60  //- prototype declaration
61  int shift(void);
62 
63 #ifdef USE_TESTMANAGER_AUTOREGISTER
64  namespace {
65 #if defined(USE_GROUP_SU2)
66  // Nc=2 is not available.
67 #else
68  static const bool is_registered = TestManager::RegisterTest(
69  test_name,
70  shift
71  );
72 #endif
73  }
74 #endif
75 
76  //====================================================================
77  int shift(void)
78  {
79  // ##### parameter setup #####
80  int Nvol = CommonParameters::Nvol();
81  int Ndim = CommonParameters::Ndim();
82 
83  unique_ptr<Parameters> params_test(new Parameters_Test_Gauge);
84  unique_ptr<Parameters> params_all(new Parameters);
85 
86  params_all->Register_Parameters("Test_Gauge", params_test);
87 
88  ParameterManager::read(filename_input, params_all);
89 
90  const string str_gconf_status = params_test->get_string("gauge_config_status");
91  const string str_gconf_read = params_test->get_string("gauge_config_type_input");
92  const string readfile = params_test->get_string("config_filename_input");
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 
99 
100  //- print input parameters
101  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
102  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
103  vout.general(vl, " readfile = %s\n", readfile.c_str());
104  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
105  vout.general(vl, "\n");
106 
107  //- input parameter check
108  int err = 0;
109  err += ParameterCheck::non_NULL(str_gconf_status);
110 
111  if (err) {
112  vout.crucial(vl, "%s: Input parameters have not been set.\n", test_name.c_str());
113  exit(EXIT_FAILURE);
114  }
115 
116 
117  // #### object setup #####
118  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
119  unique_ptr<GaugeConfig> gconf_read(new GaugeConfig(str_gconf_read));
120 
121  if (str_gconf_status == "Continue") {
122  gconf_read->read_file(U, readfile);
123  } else if (str_gconf_status == "Cold_start") {
124  U->set_unit();
125  } else if (str_gconf_status == "Hot_start") {
126  int i_seed_noise = 1234567;
127  unique_ptr<RandomNumbers> rand(new RandomNumbers_Mseries(i_seed_noise));
128  U->set_random(rand);
129  } else {
130  vout.crucial(vl, "%s: unsupported gconf status \"%s\".\n", test_name.c_str(), str_gconf_status.c_str());
131  exit(EXIT_FAILURE);
132  }
133 
134  unique_ptr<Index_lex> index(new Index_lex);
136 
137  unique_ptr<Field_G> U2(new Field_G(Nvol, Ndim));
138  unique_ptr<Staples> staple(new Staples);
139 
140  unique_ptr<Timer> timer(new Timer(test_name));
141 
142 
143  // #### Execution main part ####
144  timer->start();
145 
146  shift.backward(*U2, *U, 3);
147  vout.general(vl, "U = %.8f\n", U->cmp(17, index->site(0, 0, 0, 0), 2));
148  vout.general(vl, "U2 = %.8f\n", U2->cmp(17, index->site(0, 0, 0, 7), 2));
149  vout.general(vl, "\n");
150 
151  shift.forward(*U2, *U, 0);
152  vout.general(vl, "U = %.8f\n", U->cmp(17, index->site(0, 0, 0, 0), 3));
153  vout.general(vl, "U2 = %.8f\n", U2->cmp(17, index->site(1, 0, 0, 0), 3));
154  vout.general(vl, "\n");
155 
156  double result;
157  int nodeid = Communicator::nodeid();
158 
159  result = staple->plaquette(*U);
160  vout.general(vl, "plaq (original field) = %d %.8f\n", nodeid, result);
161 
162  result = staple->plaquette(*U2);
163  vout.general(vl, "plaq (shifted field) = %d %.8f\n", nodeid, result);
164 
165  timer->report();
166 
167 
168  if (do_check) {
169  return Test::verify(result, expected_result);
170  } else {
171  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
172  return EXIT_SKIP;
173  }
174  }
175 } // namespace Test_Gauge
#define EXIT_SKIP
Definition: test.h:17
Random number generator base on M-series.
BridgeIO vout
Definition: bridgeIO.cpp:278
void detailed(const char *format,...)
Definition: bridgeIO.cpp:82
Staple construction.
Definition: staples.h:40
int site(const int &x, const int &y, const int &z, const int &t) const
Definition: index_lex.h:53
void general(const char *format,...)
Definition: bridgeIO.cpp:65
int shift(void)
double plaquette(const Field_G &)
calculates plaquette value.
Definition: staples.cpp:36
double cmp(const int jin, const int site, const int jex) const
Definition: field.h:123
Class for parameters.
Definition: parameters.h:38
void read_file(Field *U, const string &filename)
Definition: gaugeConfig.cpp:56
void set_random(RandomNumbers *rand)
Definition: field_G_imp.cpp:62
void set_unit()
Definition: field_G_imp.cpp:39
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:80
const std::string test_name
SU(N) gauge field.
Definition: field_G.h:38
bool is_set(const string &) const
Definition: parameters.cpp:372
Test of gauge quantities.
double get_double(const string &key) const
Definition: parameters.cpp:27
void backward(Field &, const Field &, const int mu)
Lexical site index.
Definition: index_lex.h:34
int non_NULL(const std::string v)
Definition: checker.cpp:61
void start()
Definition: timer.cpp:44
void crucial(const char *format,...)
Definition: bridgeIO.cpp:48
void Register_Parameters(const string &, Parameters *const)
Definition: parameters.cpp:358
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:39
static void read(const std::string &params_file, Parameters *params)
Methods to shift a field in the lexical site index.
static int nodeid()
alternative name for self().
Definition: communicator.h:92
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:61
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:87
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:28
void forward(Field &, const Field &, const int mu)