Bridge++  Ver. 1.2.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_HotStart_Unitary.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "gaugeConfig.h"
17 
18 #include "randomNumbers_Mseries.h"
19 
20 //====================================================================
22 
27 namespace Test_HotStart {
28  const std::string test_name = "HotStart.Unitary";
29 
30  //- test-private parameters
31  namespace {
32  const std::string filename_input = "test_HotStart_Unitary.yaml";
33  const std::string filename_output = "stdout";
34 
35  class Parameters_Test_HotStart : public Parameters {
36  public:
37  Parameters_Test_HotStart()
38  {
39  Register_string("verbose_level", "NULL");
40 
41  Register_double("expected_result", 0.0);
42  }
43  };
44  }
45 
46  //- prototype declaration
47  int unitary(void);
48 
49 #ifdef USE_TESTMANAGER_AUTOREGISTER
50  namespace {
51 #if defined(USE_GROUP_SU2)
52  // Nc=2 is not available.
53 #else
54  static const bool is_registered = TestManager::RegisterTest(
55  test_name,
56  unitary
57  );
58 #endif
59  }
60 #endif
61 
62  //====================================================================
63  int unitary(void)
64  {
65  int Nc = CommonParameters::Nc();
66  int Nvol = CommonParameters::Nvol();
67  int Ndim = CommonParameters::Ndim();
68 
69  Parameters *params_test = new Parameters_Test_HotStart;
70  Parameters *params_all = new Parameters;
71 
72  params_all->Register_Parameters("Test_HotStart", params_test);
73 
74  ParameterManager_YAML params_manager;
75  params_manager.read_params(filename_input, params_all);
76 
77  const string str_vlevel = params_test->get_string("verbose_level");
78 
79  const bool do_check = params_test->is_set("expected_result");
80  const double expected_result = do_check ? params_test->get_double("expected_result") : 0.0;
81 
83 
84 
85  // #### Set up a gauge configuration ####
86  Field_G *U = new Field_G(Nvol, Ndim);
87 
88  RandomNumbers_Mseries rand(1234567);
89  U->set_random(&rand);
90 
91 
92  // #### object setup #####
93  Timer *timer = new Timer(test_name);
94 
95 
96  // #### Execution main part ####
97  timer->start();
98 
99  Mat_SU_N link(Nc);
100  Mat_SU_N unity(Nc);
101 
102  double av = 0;
103  for (int site = 0; site < Nvol; ++site) {
104  for (int mu = 0; mu < Ndim; ++mu) {
105  U->mat(link, site, mu);
106  unity.unit();
107  unity *= -1.0;
108 
109  // |UU^\dag - I|
110  unity.multadd_nd(link, link);
111  av += sqrt(unity.norm2());
112  }
113  }
114 
115  double av_all = Communicator::reduce_sum(av);
116  int Nlink = CommonParameters::Lvol() * Ndim;
117 
118  vout.general(vl, "\n");
119  vout.general(vl, "Raondom SU(%d):\n", Nc);
120  vout.general(vl, " number of matrix = %10d\n", Nlink);
121  vout.general(vl, " ave |UU^dag - I| = %23.16e\n", av_all / Nlink);
122 
123  double result = av_all / Nlink;
124 
125  timer->report();
126 
127 
128  // ##### tidy up #####
129  delete params_test;
130  delete params_all;
131 
132  delete timer;
133 
134  delete U;
135 
136 
137  if (do_check) {
138  return Test::verify(expected_result, result);
139  } else {
140  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
141  return EXIT_SKIP;
142  }
143  }
144 } // namespace Test_HotStart
#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
void general(const char *format,...)
Definition: bridgeIO.cpp:38
const std::string test_name
Class for parameters.
Definition: parameters.h:40
static int Lvol()
void set_random(RandomNumbers *rand)
Definition: field_G_imp.cpp:62
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:79
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 start()
Definition: timer.cpp:44
void multadd_nd(const Mat_SU_N &u1, const Mat_SU_N &u2)
Definition: mat_SU_N.h:215
void Register_Parameters(const string &, Parameters *const)
Definition: parameters.cpp:359
double norm2()
Definition: mat_SU_N.h:155
Bridge::VerboseLevel vl
Definition: checker.cpp:18
VerboseLevel
Definition: bridgeIO.h:25
Mat_SU_N & unit()
Definition: mat_SU_N.h:373
static int reduce_sum(int count, double *recv_buf, double *send_buf, int pattern=0)
make a global sum of an array of double over the communicator. pattern specifies the dimensions to be...
Parameter manager with YAML parser.
Definition: timer.h:31
int verify(const double expected, const double result)
Definition: test.cpp:27
string get_string(const string &key) const
Definition: parameters.cpp:85
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
Mat_SU_N mat(const int site, const int mn=0) const
Definition: field_G.h:110
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:191