Bridge++  Ver. 2.0.2
test_Spectrum_Overlap_checkSignFunction.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "Fopr/fopr_Wilson.h"
17 #include "Fopr/fopr_Sign.h"
18 
19 #include "IO/gaugeConfig.h"
20 
24 
26 
27 //====================================================================
29 
41 namespace Test_Spectrum_Overlap {
42  const std::string test_name = "Spectrum.Overlap.CheckSignFunction";
43 
44  //- test-private parameters
45  namespace {
46  const std::string filename_input = "test_Spectrum_Overlap_CheckSignFunction.yaml";
47  }
48 
49  //- prototype declaration
50  int check_sign(void);
51 
52 #ifdef USE_TESTMANAGER_AUTOREGISTER
53  namespace {
54 #if defined(USE_GROUP_SU2)
55  // Nc=2 is not available.
56 #else
57  static const bool is_registered = TestManager::RegisterTest(
58  test_name,
60  );
61 #endif
62  }
63 #endif
64 
65  //====================================================================
66  int check_sign(void)
67  {
68  // #### parameter setup ####
69  const int Ndim = CommonParameters::Ndim();
70  const int Nc = CommonParameters::Nc();
71  const int Nvol = CommonParameters::Nvol();
72 
73  const Parameters params_all = ParameterManager::read(filename_input);
74 
75  const Parameters params_test = params_all.lookup("Test_Spectrum_Overlap");
76  const Parameters params_gfix = params_all.lookup("GaugeFixing");
77  const Parameters params_wilson = params_all.lookup("Fopr_Wilson");
78  const Parameters params_overlap = params_all.lookup("Fopr_Overlap");
79  const Parameters params_source = params_all.lookup("Source");
80 
81  const string str_gconf_status = params_test.get_string("gauge_config_status");
82  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
83  const string readfile = params_test.get_string("config_filename_input");
84  const string str_rand_type = params_test.get_string("random_number_type");
85  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
86  const string str_vlevel = params_test.get_string("verbose_level");
87 
88  const bool do_check = params_test.is_set("expected_result");
89  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
90 
91  const string str_gfix_type = params_gfix.get_string("gauge_fixing_type");
92  const string str_gmset_type = params_wilson.get_string("gamma_matrix_type");
93  const string str_source_type = params_source.get_string("source_type");
94 
95  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
96 
97  //- print input parameters
98  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
99  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
100  vout.general(vl, " readfile = %s\n", readfile.c_str());
101  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
102  vout.general(vl, " seed = %lu\n", seed);
103  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
104  vout.general(vl, " gfix_type = %s\n", str_gfix_type.c_str());
105  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
106  vout.general(vl, " source_type = %s\n", str_source_type.c_str());
107 
108  //- input parameter check
109  int err = 0;
110  err += ParameterCheck::non_NULL(str_gconf_status);
111 
112  if (err) {
113  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
114  exit(EXIT_FAILURE);
115  }
116 
117  if ((str_gfix_type == "Coulomb") || (str_gfix_type == "Landau")) {
118  if (CommonParameters::Nc() != 3) {
119  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
120  return EXIT_SKIP;
121  }
122  }
123 
124 
125  RandomNumberManager::initialize(str_rand_type, seed);
126 
127 
128  // #### Set up a gauge configuration ####
129  Field_G U(Nvol, Ndim);
130 
131  if (str_gconf_status == "Continue") {
132  GaugeConfig(str_gconf_read).read(U, readfile);
133  } else if (str_gconf_status == "Cold_start") {
134  GaugeConfig("Unit").read(U);
135  } else if (str_gconf_status == "Hot_start") {
136  GaugeConfig("Random").read(U);
137  } else {
138  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
139  exit(EXIT_FAILURE);
140  }
141 
142 
143  // #### Gauge fixing ####
144  {
145  Field_G Ufix(Nvol, Ndim);
146  unique_ptr<GaugeFixing> gfix(GaugeFixing::New(str_gfix_type, params_gfix));
147 
148  gfix->fix(Ufix, U);
149  copy(U, Ufix);
150  }
151 
152 
153  // #### object setup ####
154  unique_ptr<Fopr> fopr_w(new Fopr_Wilson(params_wilson));
155  fopr_w->set_config(&U);
156 
157  int Nsbt = 0;
158  std::vector<double> TDa;
159  std::vector<Field> vk;
160 
161  //- with low-mode subtraction
162  //double Vthreshold = 0.15; // example value with low-mode subtraction
163  //calc_lowmodes(Nsbt, TDa, vk, Vthreshold, fopr_w);
164 
165  unique_ptr<Fopr> fopr_sign(new Fopr_Sign(fopr_w.get(), params_overlap));
166  fopr_sign->set_config(&U);
167  // if (Nsbt > 0) fopr_sign->set_lowmodes(Nsbt, &TDa, &vk);
168 
169  unique_ptr<Source> source(Source::New(str_source_type, params_source));
170 
171  Timer timer(test_name);
172 
173  // #### Execution main part ####
174  timer.start();
175 
176  int Nin = fopr_w->field_nin();
177  int Nex = fopr_w->field_nex();
178  // note that Nvol has been already set.
179 
180  Field b(Nin, Nvol, Nex);
181  Field xq(Nin, Nvol, Nex);
182  Field xq2(Nin, Nvol, Nex);
183 
184  double result = 1.0;
185 
186 #pragma omp parallel
187  {
188  for (int ispin = 0; ispin < 1; ++ispin) {
189  for (int icolor = 0; icolor < 1; ++icolor) {
190  // for(int ispin = 0; ispin < Nd; ++ispin){
191  //for(int icolor = 0; icolor < Nc; ++icolor){
192 
193  int icd = icolor + Nc * ispin;
194 
195  source->set(b, icd);
196 
197  fopr_sign->mult(xq, b);
198  fopr_sign->mult(xq2, xq);
199 
200  axpy(xq2, -1.0, b);
201 
202  double xq_norm = xq2.norm2();
203  if (icd == 0) {
204  int ith = ThreadManager::get_thread_id();
205  if (ith == 0) result = xq_norm;
206  }
207 
208  vout.general(vl, " |sign^2(b) - b|^2 = %16.8e\n", xq_norm);
209  }
210  }
211  }
212 
213  timer.report();
214 
216 
217 
218  if (do_check) {
219  return Test::verify(result, expected_result);
220  } else {
221  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
222  return EXIT_SKIP;
223  }
224  }
225 } // namespace Test_Spectrum_Overlap
Test::verify
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
ParameterCheck::non_NULL
int non_NULL(const std::string v)
Definition: parameterCheck.cpp:65
Test_Spectrum_Overlap::test_name
const std::string test_name
Definition: test_Spectrum_Overlap_2ptFunction.cpp:51
CommonParameters::Ndim
static int Ndim()
Definition: commonParameters.h:117
Parameters
Class for parameters.
Definition: parameters.h:46
Fopr_Sign
AFopr_Sign< Field > Fopr_Sign
Definition: fopr_Sign.h:28
Bridge::BridgeIO::detailed
void detailed(const char *format,...)
Definition: bridgeIO.cpp:219
GaugeConfig::read
void read(Field_G &U, const string &filename=string())
Definition: gaugeConfig.cpp:121
gaugeConfig.h
CommonParameters::Nvol
static int Nvol()
Definition: commonParameters.h:109
axpy
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:380
source.h
Timer
Definition: timer.h:31
RandomNumberManager::finalize
static void finalize()
Definition: randomNumberManager.cpp:80
copy
void copy(Field &y, const Field &x)
copy(y, x): y = x
Definition: field.cpp:212
fopr_Sign.h
RandomNumberManager::initialize
static bool initialize(const std::string &rng_type, unsigned long seed)
Definition: randomNumberManager.cpp:57
Field::norm2
double norm2() const
Definition: field.cpp:113
fopr_Wilson.h
Timer::start
void start()
Definition: timer.cpp:44
CommonParameters::Nc
static int Nc()
Definition: commonParameters.h:115
ParameterCheck::vl
Bridge::VerboseLevel vl
Definition: parameterCheck.cpp:18
Test_Spectrum_Overlap::check_sign
int check_sign(void)
Definition: test_Spectrum_Overlap_checkSignFunction.cpp:66
Test_Spectrum_Overlap
Test class of overlap fermion operators.
Definition: test_Spectrum_Overlap_2ptFunction.cpp:50
test.h
ParameterManager::read
static void read(const std::string &params_file, Parameters &params)
Definition: parameterManager.cpp:33
Parameters::get_double
double get_double(const string &key) const
Definition: parameters.cpp:175
Parameters::get_unsigned_long
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:209
EXIT_SKIP
#define EXIT_SKIP
Definition: test.h:17
randomNumberManager.h
GaugeConfig
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:80
Bridge::BridgeIO::set_verbose_level
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:133
Parameters::is_set
bool is_set(const string &key) const
Definition: parameters.cpp:525
Parameters::get_string
string get_string(const string &key) const
Definition: parameters.cpp:221
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Field
Container of Field-type object.
Definition: field.h:46
ThreadManager::get_thread_id
static int get_thread_id()
returns thread id.
Definition: threadManager.cpp:253
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42
Field_G
SU(N) gauge field.
Definition: field_G.h:38
gaugeFixing.h
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
corr2pt_4spinor.h
Parameters::lookup
Parameters lookup(const string &key) const
Definition: parameters.h:79
Timer::report
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
TestManager::RegisterTest
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:69
Fopr_Wilson
Org::Fopr_Wilson Fopr_Wilson
Wilson fermion operator.
Definition: fopr_Wilson.h:50