Bridge++  Version 1.5.4
 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 "IO/gaugeConfig.h"
17 
19 
21 
22 //====================================================================
24 
33 namespace Test_Gauge {
34  const std::string test_name = "Gauge.Shift";
35 
36  //- test-private parameters
37  namespace {
38  const std::string filename_input = "test_Gauge_lex.yaml";
39  }
40 
41  //- prototype declaration
42  int shift(void);
43 
44 #ifdef USE_TESTMANAGER_AUTOREGISTER
45  namespace {
46 #if defined(USE_GROUP_SU2)
47  // Nc=2 is not available.
48 #else
49  static const bool is_registered = TestManager::RegisterTest(
50  test_name,
51  shift
52  );
53 #endif
54  }
55 #endif
56 
57  //====================================================================
58  int shift(void)
59  {
60  // ##### parameter setup #####
61  const int Nvol = CommonParameters::Nvol();
62  const int Ndim = CommonParameters::Ndim();
63 
64  const Parameters params_all = ParameterManager::read(filename_input);
65 
66  const Parameters params_test = params_all.lookup("Test_Gauge");
67 
68  const string str_gconf_status = params_test.get_string("gauge_config_status");
69  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
70  const string readfile = params_test.get_string("config_filename_input");
71  const string str_rand_type = params_test.get_string("random_number_type");
72  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
73  const string str_vlevel = params_test.get_string("verbose_level");
74 
75  const bool do_check = params_test.is_set("expected_result");
76  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
77 
78  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
79 
80  //- print input parameters
81  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
82  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
83  vout.general(vl, " readfile = %s\n", readfile.c_str());
84  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
85  vout.general(vl, " seed = %lu\n", seed);
86  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
87  vout.general(vl, "\n");
88 
89  //- input parameter check
90  int err = 0;
91  err += ParameterCheck::non_NULL(str_gconf_status);
92 
93  if (err) {
94  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
95  exit(EXIT_FAILURE);
96  }
97 
98 
99  RandomNumberManager::initialize(str_rand_type, seed);
100 
101 
102  // #### object setup #####
103  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
104 
105  if (str_gconf_status == "Continue") {
106  GaugeConfig(str_gconf_read).read(U, readfile);
107  } else if (str_gconf_status == "Cold_start") {
108  GaugeConfig("Unit").read(U);
109  } else if (str_gconf_status == "Hot_start") {
110  GaugeConfig("Random").read(U);
111  } else {
112  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
113  exit(EXIT_FAILURE);
114  }
115  vout.general(vl, "\n");
116 
117  const unique_ptr<Index_lex> index(new Index_lex);
118  const unique_ptr<Staple_lex> staple(new Staple_lex);
119 
121  unique_ptr<Field_G> U2(new Field_G(Nvol, Ndim));
122 
123  const unique_ptr<Timer> timer(new Timer(test_name));
124 
125 
126  // #### Execution main part ####
127  const int Lt = CommonParameters::Lt();
128  const int Lx = CommonParameters::Lx();
129 
130  const int Nt = CommonParameters::Nt();
131  const int Nx = CommonParameters::Nx();
132 
133  const int ipe_x = Communicator::ipe(0);
134  const int ipe_y = Communicator::ipe(1);
135  const int ipe_z = Communicator::ipe(2);
136  const int ipe_t = Communicator::ipe(3);
137 
138  const int t_global = Lt - 1;
139  const int node_t = t_global / Nt;
140  const int it_shift = t_global - ipe_t * Nt;
141 
142  const int x_global = 1;
143  const int node_x = x_global / Nx;
144  const int ix_shift = x_global - ipe_x * Nx;
145 
146 
147  timer->start();
148 
149 
150  shift.backward(*U2, *U, 3);
151  vout.general(vl, "U(before backward) = %.8f\n", U->cmp(17, index->site(0, 0, 0, 0), 2));
152 
153  if ( (ipe_x == 0) && (ipe_y == 0) && (ipe_z == 0) ) {
154  if (ipe_t == node_t) {
155  vout.general(vl, Communicator::nodeid(), "U(after backward) = %.8f\n", U2->cmp(17, index->site(0, 0, 0, it_shift), 2));
156  }
157  }
159  vout.general(vl, "\n");
160 
161 
162  shift.forward(*U2, *U, 0);
163  vout.general(vl, "U(before forward) = %.8f\n", U->cmp(17, index->site(0, 0, 0, 0), 3));
164 
165  if ( (ipe_y == 0) && (ipe_z == 0) && (ipe_t == 0) ) {
166  if (ipe_x == node_x) {
167  vout.general(vl, Communicator::nodeid(), "U(after forward) = %.8f\n", U2->cmp(17, index->site(ix_shift, 0, 0, 0), 3));
168  }
169  }
171  vout.general(vl, "\n");
172 
173 
174  vout.general(vl, "original field:\n");
175  double result = staple->plaquette(*U);
176  vout.general(vl, "\n");
177 
178  vout.general(vl, "shifted field:\n");
179  result = staple->plaquette(*U2);
180  vout.general(vl, "\n");
181 
182 
183  timer->report();
184 
186 
187 
188  if (do_check) {
189  return Test::verify(result, expected_result);
190  } else {
191  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
192  return EXIT_SKIP;
193  }
194  }
195 } // 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
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:197
int shift(void)
double plaquette(const Field_G &)
calculates plaquette value.
Definition: staple_lex.cpp:38
double cmp(const int jin, const int site, const int jex) const
Definition: field.h:143
Class for parameters.
Definition: parameters.h:46
static int ipe(const int dir)
logical coordinate of current proc.
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)
Staple construction.
Definition: staple_lex.h:39
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
void backward(Field &, const Field &, const int mu)
Lexical site index.
Definition: index_lex.h:34
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
static int sync()
synchronize within small world.
Methods to shift a field in the lexical site index.
static int nodeid()
alternative name for self().
Definition: communicator.h:105
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:78
Definition: timer.h:31
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
void forward(Field &, const Field &, const int mu)