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