Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_HotStart_Eigenvalue.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "IO/gaugeConfig.h"
17 
18 #include "Tools/eigen_QR_Cmplx.h"
20 
21 //====================================================================
23 
30 namespace Test_HotStart {
31  const std::string test_name = "HotStart.Eigenvalue";
32 
33  //- test-private parameters
34  namespace {
35  const std::string filename_input = "test_HotStart_Eigenvalue.yaml";
36  }
37 
38  //- prototype declaration
39  int eigenvalue(void);
40 
41 #ifdef USE_TESTMANAGER_AUTOREGISTER
42  namespace {
43 #if defined(USE_GROUP_SU2)
44  // Nc=2 is not available.
45 #else
46  static const bool is_registered = TestManager::RegisterTest(
47  test_name,
49  );
50 #endif
51  }
52 #endif
53 
54  //====================================================================
55  int eigenvalue(void)
56  {
57  const int Nc = CommonParameters::Nc();
58  const int Ndim = CommonParameters::Ndim();
59  const int Nvol = CommonParameters::Nvol();
60  const int NPE = CommonParameters::NPE();
61 
62  const double pi = 4.0 * atan(1.0);
63 
64  const Parameters params_all = ParameterManager::read(filename_input);
65 
66  const Parameters params_test = params_all.lookup("Test_HotStart");
67 
68  const string str_vlevel = params_test.get_string("verbose_level");
69 
70  const bool do_check = params_test.is_set("expected_result");
71  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
72 
73  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
74 
75 
76  // #### Set up a gauge configuration ####
77  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
78 
79  const int i_seed_noise = 1234567;
80  unique_ptr<RandomNumbers> rand(new RandomNumbers_Mseries(i_seed_noise));
81  U->set_random(rand);
82 
83 
84  // #### object setup #####
85  const unique_ptr<Timer> timer(new Timer(test_name));
86 
87 
88  // #### Execution main part ####
89  timer->start();
90 
91  double av = 0.0;
92  double va = 0.0;
93  Eigen_QR_Cmplx eigen_qr(Nc);
94  std::valarray<double> vec(2 * Nc);
95 
96  for (int site = 0; site < Nvol; ++site) {
97  for (int mu = 0; mu < Ndim; ++mu) {
98  vec = eigen_qr.solve(U->ptr(0, site, mu));
99  for (int icolor = 0; icolor < Nc; ++icolor) {
100  double arg = atan2(vec[2 * icolor + 1], vec[2 * icolor]);
101 
102  vout.detailed(vl, "%10.8f\n", arg);
103 
104  av += arg;
105  va += arg * arg;
106  }
107  }
108  }
109 
110  const double av_all = Communicator::reduce_sum(av);
111  const double va_all = Communicator::reduce_sum(va);
112 
113  av = av_all / Nvol / NPE / Ndim / Nc;
114  va = va_all / Nvol / NPE / Ndim / Nc - av * av;
115 
116  va = sqrt(va);
117 
118  vout.general(vl, "\n");
119  vout.general(vl, "Random SU(%d):\n", Nc);
120  // vout.general(vl, " # of eigenvalue = %10d\n", Nvol * NPE * Ndim * Nc);
121  vout.general(vl, " ave = %23.16e\n", av);
122  vout.general(vl, " var = %23.16e\n", va);
123  vout.general(vl, " var(expected) = %23.16e\n", pi / sqrt(3.0));
124 
125  const double result = av;
126 
127  timer->report();
128 
129 
130  if (do_check) {
131  return Test::verify(result, expected_result);
132  } else {
133  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
134  return EXIT_SKIP;
135  }
136  }
137 } // namespace Test_HotStart
#define EXIT_SKIP
Definition: test.h:17
Random number generator base on M-series.
BridgeIO vout
Definition: bridgeIO.cpp:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
const double * ptr(const int jin, const int site, const int jex) const
Definition: field.h:153
void general(const char *format,...)
Definition: bridgeIO.cpp:197
const std::string test_name
Class for parameters.
Definition: parameters.h:46
std::valarray< double > solve(const double *matrix)
void set_random(RandomNumbers *rand)
Definition: field_G_imp.cpp:60
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
SU(N) gauge field.
Definition: field_G.h:38
double get_double(const string &key) const
Definition: parameters.cpp:175
bool is_set(const string &key) const
Definition: parameters.cpp:528
void start()
Definition: timer.cpp:44
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 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...
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