Bridge++  Version 1.6.1
 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  return;
37 }
38 
39 
40 //====================================================================
41 int hadron_2ptFunction(const Parameters& params_all)
42 {
43  using namespace std;
44 
45  // #### parameter setup ####
46  const int Nc = CommonParameters::Nc();
47  const int Nd = CommonParameters::Nd();
48  const int Ndim = CommonParameters::Ndim();
49  const int Nvol = CommonParameters::Nvol();
50 
51  const Parameters params_spectrum = params_all.lookup("Spectrum");
52  const Parameters params_gfix = params_all.lookup("GaugeFixing");
53  const Parameters params_fopr = params_all.lookup("Fopr");
54  const Parameters params_solver = params_all.lookup("Solver");
55  const Parameters params_source = params_all.lookup("Source");
56 
57  const string str_gconf_status = params_spectrum.get_string("gauge_config_status");
58  const string str_gconf_read = params_spectrum.get_string("gauge_config_type_input");
59  const string readfile = params_spectrum.get_string("config_filename_input");
60  const string str_rand_type = params_spectrum.get_string("random_number_type");
61  const unsigned long seed = params_spectrum.get_unsigned_long("seed_for_random_number");
62  const string str_vlevel = params_spectrum.get_string("verbose_level");
63 
64  // const bool do_check = params_spectrum.is_set("expected_result");
65  // const double expected_result = do_check ? params_spectrum.get_double("expected_result") : 0.0;
66 
67  const string str_gfix_type = params_gfix.get_string("gauge_fixing_type");
68  const string str_fopr_type = params_fopr.get_string("fermion_type");
69  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
70  const string str_solver_type = params_solver.get_string("solver_type");
71  const string str_source_type = params_source.get_string("source_type");
72 
73  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
74 
75  //- print input parameters
76  vout.general(vl, "Measurement parameters\n");
77  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
78  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
79  vout.general(vl, " readfile = %s\n", readfile.c_str());
80  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
81  vout.general(vl, " seed = %lu\n", seed);
82  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
83  vout.general(vl, " gfix_type = %s\n", str_gfix_type.c_str());
84  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
85  vout.general(vl, " solver_type = %s\n", str_solver_type.c_str());
86  vout.general(vl, " source_type = %s\n", str_source_type.c_str());
87 
88  //- input parameter check
89  int err = 0;
90  err += ParameterCheck::non_NULL(str_gconf_status);
91 
92  if (err) {
93  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
94  exit(EXIT_FAILURE);
95  }
96 
97  if (str_solver_type == "CG") {
98  vout.crucial(vl, "Error at %s: CG can not be adopted. Use CGNE,CGNR, instead.\n", test_name.c_str());
99  exit(EXIT_FAILURE);
100  }
101 
102  RandomNumberManager::initialize(str_rand_type, seed);
103 
104 
105  // #### Set up a gauge configuration ####
106  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
107 
108  if (str_gconf_status == "Continue") {
109  GaugeConfig(str_gconf_read).read(U, readfile);
110  } else if (str_gconf_status == "Cold_start") {
111  GaugeConfig("Unit").read(U);
112  } else if (str_gconf_status == "Hot_start") {
113  GaugeConfig("Random").read(U);
114  } else {
115  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
116  exit(EXIT_FAILURE);
117  }
118 
119 
120  // #### Gauge fixing ####
121  {
122  unique_ptr<Field_G> Ufix(new Field_G(Nvol, Ndim));
123  const unique_ptr<GaugeFixing> gfix(GaugeFixing::New(str_gfix_type));
124  gfix->set_parameters(params_gfix);
125 
126  gfix->fix(*Ufix, *U);
127 
128  copy(*U, *Ufix);
129  }
130 
131 
132  // #### object setup #####
133  unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
134 
135  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
136  fopr->set_parameters(params_fopr);
137  fopr->set_config(U);
138 
139  unique_ptr<Solver> solver(Solver::New(str_solver_type, fopr));
140  solver->set_parameters(params_solver);
141 
142  const unique_ptr<Fprop> fprop_lex(new Fprop_Standard_lex(solver));
143 
144  const unique_ptr<Source> source(Source::New(str_source_type));
145  source->set_parameters(params_source);
146 
147  Corr2pt_4spinor corr(gmset);
148  corr.set_parameters(params_all.lookup("Corr2pt_4spinor"));
149 
150  const unique_ptr<Timer> timer(new Timer(test_name));
151 
152 
153  // #### Execution main part ####
154  timer->start();
155 
156  std::vector<Field_F> sq(Nc * Nd);
157  for (int i_cd = 0; i_cd < Nc * Nd; ++i_cd) {
158  sq[i_cd].set(0.0);
159  }
160 
161  vout.general(vl, "\n");
162  vout.general(vl, "Solving quark propagator:\n");
163  vout.general(vl, " color spin Nconv diff diff2\n");
164 
165  for (int ispin = 0; ispin < Nd; ++ispin) {
166  for (int icolor = 0; icolor < Nc; ++icolor) {
167  int i_cd = icolor + Nc * ispin;
168 
169  Field_F b; // b.set(0.0);
170  source->set(b, i_cd);
171 
172  int Nconv;
173  double diff;
174  fprop_lex->invert_D(sq[i_cd], b, Nconv, diff);
175 
176  Field_F y(b);
177  fopr->set_mode("D");
178  fopr->mult(y, sq[i_cd]); // y = fopr->mult(sq[i_cd]);
179  axpy(y, -1.0, b); // y -= b;
180  double diff2 = y.norm2() / b.norm2();
181 
182  vout.general(vl, " %2d %2d %6d %12.4e %12.4e\n",
183  icolor, ispin, Nconv, diff, diff2);
184  }
185  }
186 
187  //- meson correlators
188  vout.general(vl, "\n");
189  vout.general(vl, "2-point correlator:\n");
190 
191  const double result = corr.meson_all(sq, sq);
192 
193  timer->report();
194 
196 
197 
198  // if (do_check) {
199  // return Test::verify(result, expected_result);
200  // } else {
201  // vout.detailed(vl, "check skipped: expected_result not set.\n\n");
202  // return EXIT_SKIP;
203  // }
204  return EXIT_SUCCESS;
205 }
206 
207 
208 //====================================================================
209 int main(int argc, char *argv[])
210 {
211  bridge_initialize(&argc, &argv);
212 
213  if (argc < 2) {
214  usage(argv[0]);
215 
216  bridge_finalize();
217  return EXIT_FAILURE;
218  }
219 
220  std::string parameter_file = std::string(argv[1]);
221 
222  Parameters params = ParameterManager::read(parameter_file);
223  bridge_setup(params.lookup("Main"));
224 
225  Timer timer("Main");
226  timer.start();
227 
228  hadron_2ptFunction(params);
229 
230  timer.stop();
231  timer.report();
232 
233  bridge_finalize();
234 
235  return EXIT_SUCCESS;
236 }
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:637
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:320
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:79
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