Bridge++  Ver. 1.2.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
35 namespace Test_Gauge {
36  const std::string test_name = "Gauge.Shift";
37 
38  //- test-private parameters
39  namespace {
40  const std::string filename_input = "test_Gauge.yaml";
41  const std::string filename_output = "stdout";
42 
43  class Parameters_Test_Gauge : public Parameters {
44  public:
45  Parameters_Test_Gauge()
46  {
47  Register_string("gauge_config_status", "NULL");
48  Register_string("gauge_config_type_input", "NULL");
49  Register_string("config_filename_input", "NULL");
50 
51  Register_string("verbose_level", "NULL");
52 
53  Register_double("expected_result", 0.0);
54  }
55  };
56  }
57 
58  //- prototype declaration
59  int shift(void);
60 
61 #ifdef USE_TESTMANAGER_AUTOREGISTER
62  namespace {
63 #if defined(USE_GROUP_SU2)
64  // Nc=2 is not available.
65 #else
66  static const bool is_registered = TestManager::RegisterTest(
67  test_name,
68  shift
69  );
70 #endif
71  }
72 #endif
73 
74  //====================================================================
75  int shift(void)
76  {
77  // ##### parameter setup #####
78  int Nvol = CommonParameters::Nvol();
79  int Ndim = CommonParameters::Ndim();
80 
81  Parameters *params_test = new Parameters_Test_Gauge;
82  Parameters *params_all = new Parameters;
83 
84  params_all->Register_Parameters("Test_Gauge", params_test);
85 
86  ParameterManager_YAML params_manager;
87  params_manager.read_params(filename_input, params_all);
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_vlevel = params_test->get_string("verbose_level");
93 
94  const bool do_check = params_test->is_set("expected_result");
95  const double expected_result = do_check ? params_test->get_double("expected_result") : 0.0;
96 
98 
99  //- print input parameters
100  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
101  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
102  vout.general(vl, " readfile = %s\n", readfile.c_str());
103  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
104  vout.general(vl, "\n");
105 
106  //- input parameter check
107  int err = 0;
108  err += ParameterCheck::non_NULL(str_gconf_status);
109 
110  if (err) {
111  vout.crucial(vl, "%s: Input parameters have not been set.\n", test_name.c_str());
112  abort();
113  }
114 
115 
116  // #### object setup #####
117  Field_G *U = new Field_G(Nvol, Ndim);
118  GaugeConfig *gconf_read = new GaugeConfig(str_gconf_read);
119 
120  if (str_gconf_status == "Continue") {
121  gconf_read->read_file((Field *)U, readfile);
122  } else if (str_gconf_status == "Cold_start") {
123  U->set_unit();
124  } else if (str_gconf_status == "Hot_start") {
125  RandomNumbers_Mseries rand(1234567);
126  U->set_random(&rand);
127  } else {
128  vout.crucial(vl, "%s: unsupported gconf status \"%s\".\n", test_name.c_str(), str_gconf_status.c_str());
129  abort();
130  }
131 
132  Index_lex *index = new Index_lex;
134 
135  Field_G *U2 = new Field_G(Nvol, Ndim);
136  Staples *staple = new Staples;
137 
138  Timer *timer = new Timer(test_name);
139 
140 
141  // #### Execution main part ####
142  timer->start();
143 
144  shift.backward(*U2, *U, 3);
145  vout.general(vl, "U = %.8f\n", U->cmp(17, index->site(0, 0, 0, 0), 2));
146  vout.general(vl, "U2 = %.8f\n", U2->cmp(17, index->site(0, 0, 0, 7), 2));
147  vout.general(vl, "\n");
148 
149  shift.forward(*U2, *U, 0);
150  vout.general(vl, "U = %.8f\n", U->cmp(17, index->site(0, 0, 0, 0), 3));
151  vout.general(vl, "U2 = %.8f\n", U2->cmp(17, index->site(1, 0, 0, 0), 3));
152  vout.general(vl, "\n");
153 
154  double result;
155  int nodeid = Communicator::nodeid();
156 
157  result = staple->plaquette(*U);
158  vout.general(vl, "plaq (original field) = %d %.8f\n", nodeid, result);
159 
160  result = staple->plaquette(*U2);
161  vout.general(vl, "plaq (shifted field) = %d %.8f\n", nodeid, result);
162 
163  timer->report();
164 
165 
166  // #### tydy up ####
167  delete params_test;
168  delete params_all;
169 
170  delete timer;
171 
172  delete U;
173  delete U2;
174  delete gconf_read;
175 
176  delete staple; // added by s.motoki[12/06/05].
177  delete index; // added by s.motoki[12/06/05].
178 
179 
180  if (do_check) {
181  return Test::verify(expected_result, result);
182  } else {
183  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
184  return EXIT_SKIP;
185  }
186  }
187 } // namespace Test_Gauge
#define EXIT_SKIP
Definition: test.h:17
Random number generator base on M-series.
BridgeIO vout
Definition: bridgeIO.cpp:207
void read_params(const std::string &params_file, Parameters *params)
read parameters from file.
void detailed(const char *format,...)
Definition: bridgeIO.cpp:50
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:38
int shift(void)
Container of Field-type object.
Definition: field.h:37
double plaquette(const Field_G &)
calculates plaquette value.
Definition: staples.cpp:32
double cmp(const int jin, const int site, const int jex) const
Definition: field.h:108
Class for parameters.
Definition: parameters.h:40
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:79
const std::string test_name
SU(N) gauge field.
Definition: field_G.h:36
bool is_set(const string &) const
Definition: parameters.cpp:366
double get_double(const string &key) const
Definition: parameters.cpp:25
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:26
void Register_Parameters(const string &, Parameters *const)
Definition: parameters.cpp:359
Bridge::VerboseLevel vl
Definition: checker.cpp:18
VerboseLevel
Definition: bridgeIO.h:25
Methods to shift a field in the lexical site index.
Parameter manager with YAML parser.
static int nodeid()
alternative name for self().
Definition: communicator.h:88
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:56
Definition: timer.h:31
int verify(const double expected, const double result)
Definition: test.cpp:27
void read_file(Field *u, const string &filename)
Definition: gaugeConfig.cpp:85
string get_string(const string &key) const
Definition: parameters.cpp:85
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:191
void forward(Field &, const Field &, const int mu)