Bridge++  Version 1.4.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 "Tests/test.h"
15 
16 #include "IO/gaugeConfig.h"
17 
18 #include "Field/shiftField_lex.h"
20 
22 
23 //====================================================================
25 
34 namespace Test_Gauge {
35  const std::string test_name = "Gauge.Shift";
36 
37  //- test-private parameters
38  namespace {
39  const std::string filename_input = "test_Gauge_lex.yaml";
40  }
41 
42  //- prototype declaration
43  int shift(void);
44 
45 #ifdef USE_TESTMANAGER_AUTOREGISTER
46  namespace {
47 #if defined(USE_GROUP_SU2)
48  // Nc=2 is not available.
49 #else
50  static const bool is_registered = TestManager::RegisterTest(
51  test_name,
52  shift
53  );
54 #endif
55  }
56 #endif
57 
58  //====================================================================
59  int shift(void)
60  {
61  // ##### parameter setup #####
62  int Nvol = CommonParameters::Nvol();
63  int Ndim = CommonParameters::Ndim();
64 
65  Parameters params_all = ParameterManager::read(filename_input);
66 
67  Parameters params_test = params_all.lookup("Test_Gauge");
68 
69  const string str_gconf_status = params_test.get_string("gauge_config_status");
70  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
71  const string readfile = params_test.get_string("config_filename_input");
72  const string str_rand_type = params_test.get_string("random_number_type");
73  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
74  const string str_vlevel = params_test.get_string("verbose_level");
75 
76  const bool do_check = params_test.is_set("expected_result");
77  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
78 
80 
81  //- print input parameters
82  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
83  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
84  vout.general(vl, " readfile = %s\n", readfile.c_str());
85  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
86  vout.general(vl, " seed = %lu\n", seed);
87  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
88  vout.general(vl, "\n");
89 
90  //- input parameter check
91  int err = 0;
92  err += ParameterCheck::non_NULL(str_gconf_status);
93 
94  if (err) {
95  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
96  exit(EXIT_FAILURE);
97  }
98 
99 
100  RandomNumberManager::initialize(str_rand_type, seed);
101 
102 
103  // #### object setup #####
104  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
105 
106  if (str_gconf_status == "Continue") {
107  GaugeConfig(str_gconf_read).read(U, readfile);
108  } else if (str_gconf_status == "Cold_start") {
109  GaugeConfig("Unit").read(U);
110  } else if (str_gconf_status == "Hot_start") {
111  GaugeConfig("Random").read(U);
112  } else {
113  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
114  exit(EXIT_FAILURE);
115  }
116 
117  unique_ptr<Index_lex> index(new Index_lex);
119 
120  unique_ptr<Field_G> U2(new Field_G(Nvol, Ndim));
122 
123  unique_ptr<Timer> timer(new Timer(test_name));
124 
125 
126  // #### Execution main part ####
127  timer->start();
128 
129  shift.backward(*U2, *U, 3);
130  vout.general(vl, "U = %.8f\n", U->cmp(17, index->site(0, 0, 0, 0), 2));
131  vout.general(vl, "U2 = %.8f\n", U2->cmp(17, index->site(0, 0, 0, 7), 2));
132  vout.general(vl, "\n");
133 
134  shift.forward(*U2, *U, 0);
135  vout.general(vl, "U = %.8f\n", U->cmp(17, index->site(0, 0, 0, 0), 3));
136  vout.general(vl, "U2 = %.8f\n", U2->cmp(17, index->site(1, 0, 0, 0), 3));
137  vout.general(vl, "\n");
138 
139  double result;
140  int nodeid = Communicator::nodeid();
141 
142  result = staple->plaquette(*U);
143  vout.general(vl, "plaq (original field) = %d %.8f\n", nodeid, result);
144 
145  result = staple->plaquette(*U2);
146  vout.general(vl, "plaq (shifted field) = %d %.8f\n", nodeid, result);
147 
148  timer->report();
149 
151 
152 
153  if (do_check) {
154  return Test::verify(result, expected_result);
155  } else {
156  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
157  return EXIT_SKIP;
158  }
159  }
160 } // 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
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:195
int shift(void)
double plaquette(const Field_G &)
calculates plaquette value.
Definition: staple_lex.cpp:46
double cmp(const int jin, const int site, const int jex) const
Definition: field.h:132
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)
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:104
double get_double(const string &key) const
Definition: parameters.cpp:70
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
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
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:75
Definition: timer.h:31
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
void forward(Field &, const Field &, const int mu)