Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sample_Spectrum.cpp
Go to the documentation of this file.
1 
14 #include "bridge.h"
15 using Bridge::vout;
16 
17 
18 namespace {
19  const std::string test_name = "sample_Spectrum";
20  const std::string parameter_file_default = "sample_Spectrum_Wilson_Hadron2ptFunction.yaml";
21 }
22 
23 //====================================================================
25 
32 //====================================================================
33 void usage(const char *program_name)
34 {
35  vout.general("\n\nusage: %s parameter_file\n\n", program_name);
36 }
37 
38 
39 //====================================================================
40 int hadron_2ptFunction(const Parameters& params_all)
41 {
42  using namespace std;
43 
44  // #### parameter setup ####
45  const int Nc = CommonParameters::Nc();
46  const int Nd = CommonParameters::Nd();
47  const int Ndim = CommonParameters::Ndim();
48  const int Nvol = CommonParameters::Nvol();
49 
50  const Parameters params_spectrum = params_all.lookup("Spectrum");
51  const Parameters params_gfix = params_all.lookup("GaugeFixing");
52  const Parameters params_fopr = params_all.lookup("Fopr");
53  const Parameters params_solver = params_all.lookup("Solver");
54  const Parameters params_source = params_all.lookup("Source");
55 
56  const string str_gconf_status = params_spectrum.get_string("gauge_config_status");
57  const string str_gconf_read = params_spectrum.get_string("gauge_config_type_input");
58  const string readfile = params_spectrum.get_string("config_filename_input");
59  const string str_rand_type = params_spectrum.get_string("random_number_type");
60  const unsigned long seed = params_spectrum.get_unsigned_long("seed_for_random_number");
61  const string str_vlevel = params_spectrum.get_string("verbose_level");
62 
63  // const bool do_check = params_spectrum.is_set("expected_result");
64  // const double expected_result = do_check ? params_spectrum.get_double("expected_result") : 0.0;
65 
66  const string str_gfix_type = params_gfix.get_string("gauge_fixing_type");
67  const string str_fopr_type = params_fopr.get_string("fermion_type");
68  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
69  const string str_solver_type = params_solver.get_string("solver_type");
70  const string str_source_type = params_source.get_string("source_type");
71 
72  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
73 
74  //- print input parameters
75  vout.general(vl, "Measurement parameters\n");
76  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
77  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
78  vout.general(vl, " readfile = %s\n", readfile.c_str());
79  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
80  vout.general(vl, " seed = %lu\n", seed);
81  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
82  vout.general(vl, " gfix_type = %s\n", str_gfix_type.c_str());
83  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
84  vout.general(vl, " solver_type = %s\n", str_solver_type.c_str());
85  vout.general(vl, " source_type = %s\n", str_source_type.c_str());
86 
87  //- input parameter check
88  int err = 0;
89  err += ParameterCheck::non_NULL(str_gconf_status);
90 
91  if (err) {
92  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
93  exit(EXIT_FAILURE);
94  }
95 
96  if (str_solver_type == "CG") {
97  vout.crucial(vl, "Error at %s: CG can not be adopted. Use CGNE,CGNR, instead.\n", test_name.c_str());
98  exit(EXIT_FAILURE);
99  }
100 
101  RandomNumberManager::initialize(str_rand_type, seed);
102 
103 
104  // #### Set up a gauge configuration ####
105  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
106 
107  if (str_gconf_status == "Continue") {
108  GaugeConfig(str_gconf_read).read(U, readfile);
109  } else if (str_gconf_status == "Cold_start") {
110  GaugeConfig("Unit").read(U);
111  } else if (str_gconf_status == "Hot_start") {
112  GaugeConfig("Random").read(U);
113  } else {
114  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
115  exit(EXIT_FAILURE);
116  }
117 
118 
119  // #### Gauge fixing ####
120  {
121  unique_ptr<Field_G> Ufix(new Field_G(Nvol, Ndim));
122  const unique_ptr<GaugeFixing> gfix(GaugeFixing::New(str_gfix_type));
123  gfix->set_parameters(params_gfix);
124 
125  gfix->fix(*Ufix, *U);
126 
127  copy(*U, *Ufix);
128  }
129 
130 
131  // #### object setup #####
132  unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
133 
134  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
135  fopr->set_parameters(params_fopr);
136  fopr->set_config(U);
137 
138  unique_ptr<Solver> solver(Solver::New(str_solver_type, fopr));
139  solver->set_parameters(params_solver);
140 
141  const unique_ptr<Fprop> fprop_lex(new Fprop_Standard_lex(solver));
142 
143  const unique_ptr<Source> source(Source::New(str_source_type));
144  source->set_parameters(params_source);
145 
146  Corr2pt_4spinor corr(gmset);
147  corr.set_parameters(params_all.lookup("Corr2pt_4spinor"));
148 
149  const unique_ptr<Timer> timer(new Timer(test_name));
150 
151 
152  // #### Execution main part ####
153  timer->start();
154 
155  std::vector<Field_F> sq(Nc * Nd);
156  for (int i_cd = 0; i_cd < Nc * Nd; ++i_cd) {
157  sq[i_cd].set(0.0);
158  }
159 
160  vout.general(vl, "\n");
161  vout.general(vl, "Solving quark propagator:\n");
162  vout.general(vl, " color spin Nconv diff diff2\n");
163 
164  for (int ispin = 0; ispin < Nd; ++ispin) {
165  for (int icolor = 0; icolor < Nc; ++icolor) {
166  int i_cd = icolor + Nc * ispin;
167 
168  Field_F b; // b.set(0.0);
169  source->set(b, i_cd);
170 
171  int Nconv;
172  double diff;
173  fprop_lex->invert_D(sq[i_cd], b, Nconv, diff);
174 
175  Field_F y(b);
176  fopr->set_mode("D");
177  fopr->mult(y, sq[i_cd]); // y = fopr->mult(sq[i_cd]);
178  axpy(y, -1.0, b); // y -= b;
179  double diff2 = y.norm2() / b.norm2();
180 
181  vout.general(vl, " %2d %2d %6d %12.4e %12.4e\n",
182  icolor, ispin, Nconv, diff, diff2);
183  }
184  }
185 
186  //- meson correlators
187  vout.general(vl, "\n");
188  vout.general(vl, "2-point correlator:\n");
189 
190  const double result = corr.meson_all(sq, sq);
191 
192  timer->report();
193 
195 
196 
197  // if (do_check) {
198  // return Test::verify(result, expected_result);
199  // } else {
200  // vout.detailed(vl, "check skipped: expected_result not set.\n\n");
201  // return EXIT_SKIP;
202  // }
203  return EXIT_SUCCESS;
204 }
205 
206 
207 //====================================================================
208 int main(int argc, char *argv[])
209 {
210  bridge_initialize(&argc, &argv);
211 
212  if (argc < 2) {
213  usage(argv[0]);
214 
215  bridge_finalize();
216  return EXIT_FAILURE;
217  }
218 
219  std::string parameter_file = std::string(argv[1]);
220 
221  Parameters params = ParameterManager::read(parameter_file);
222  bridge_setup(params.lookup("Main"));
223 
224  Timer timer("Main");
225  timer.start();
226 
227  hadron_2ptFunction(params);
228 
229  timer.stop();
230  timer.report();
231 
232  bridge_finalize();
233 
234  return EXIT_SUCCESS;
235 }
BridgeIO vout
Definition: bridgeIO.cpp:503
double meson_all(const std::vector< Field_F > &sq1, const std::vector< Field_F > &sq2)
double norm2() const
Definition: field.cpp:592
void general(const char *format,...)
Definition: bridgeIO.cpp:197
virtual void set_mode(const std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: fopr.h:94
const std::string test_name
int solver(const std::string &)
virtual void set_config(Field *)=0
setting pointer to the gauge configuration.
Two-point correlator for Wilson-type fermions.
void usage(const char *program_name)
An example code to use gauge field.
int main(int argc, char *argv[])
Class for parameters.
Definition: parameters.h:46
void bridge_setup(const Parameters &params)
void copy(Field &y, const Field &x)
copy(y, x): y = x
Definition: field.cpp:532
int bridge_finalize()
Wilson-type fermion field.
Definition: field_F.h:37
virtual void set_parameters(const Parameters &params)=0
Parameters lookup(const string &key) const
Definition: parameters.h:79
virtual void invert_D(Field &, const Field &, int &, double &)=0
static bool initialize(const std::string &rng_type, unsigned long seed)
SU(N) gauge field.
Definition: field_G.h:38
void read(Field_G *U, const string &filename=string())
virtual void set_parameters(const Parameters &)=0
int non_NULL(const std::string v)
void start()
Definition: timer.cpp:44
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:319
Get quark propagator for Fopr with lexical site index.
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
static void read(const std::string &params_file, Parameters &params)
Bridge::VerboseLevel vl
VerboseLevel
Definition: bridgeIO.h:42
virtual void mult(Field &, const Field &)=0
multiplies fermion operator to a given field (2nd argument)
int hadron_2ptFunction(const Parameters &params_all)
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:78
Definition: timer.h:31
virtual void fix(Field_G &Ufix, const Field_G &Uorg)=0
virtual void set_parameters(const Parameters &params)
string get_string(const string &key) const
Definition: parameters.cpp:221
compilation of Bridge++ header files
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
virtual void set_parameters(const Parameters &)=0
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
int bridge_initialize(int *pargc, char ***pargv)
virtual void set(Field &, const int)=0
virtual void set_parameters(const Parameters &params)=0