CHROMA
t_ritz.cc
Go to the documentation of this file.
1 
2 #include "chroma.h"
3 
4 using namespace Chroma;
5 
6 
7 // Struct for test parameters
8 //
9 typedef struct {
10  multi1d<int> nrow;
11  multi1d<int> boundary;
12  multi1d<int> rng_seed;
14 
15  Real quark_mass;
16  Real rsd_r;
17  Real rsd_a;
18  Real rsd_zero;
19  bool projApsiP;
20  int n_renorm;
21  int n_min;
22  int n_eig;
23  int max_cg;
24 } Param_t;
25 
26 // Declare routine to read the parameters
27 void readParams(const std::string& filename, Param_t& params)
28 {
29  XMLReader reader(filename);
30 
31  try {
32  // Read Params
33  read(reader, "/params/lattice/nrow", params.nrow);
34  read(reader, "/params/lattice/boundary", params.boundary);
35  read(reader, "/params/RNG/seed", params.rng_seed);
36  read(reader, "/params/quarkMass", params.quark_mass);
37 
38  read(reader, "/params/Cfg", params.cfg);
39 
40  read(reader, "/params/eig/RsdR", params.rsd_r);
41  read(reader, "/params/eig/RsdA", params.rsd_a);
42  read(reader, "/params/eig/RsdZero", params.rsd_zero);
43  read(reader, "/params/eig/ProjApsiP", params.projApsiP);
44  read(reader, "/params/eig/MaxCG", params.max_cg);
45  read(reader, "/params/eig/Nrenorm", params.n_renorm);
46  read(reader, "/params/eig/Nmin", params.n_min);
47  read(reader, "/params/eig/Neig", params.n_eig);
48 
49  }
50  catch(const std::string& e) {
51  throw e;
52  }
53 }
54 
55 void dumpParams(XMLWriter& writer, Param_t& params)
56 {
57  push(writer, "params");
58  push(writer, "lattice");
59  write(writer, "nrow", params.nrow);
60  write(writer, "boundary", params.boundary);
61  pop(writer); // lattice
62  push(writer, "RNG");
63  write(writer, "seed", params.rng_seed);
64  pop(writer); // RNG
65 
66  write(writer, "quarkMass", params.quark_mass);
67  write(writer, "Cfg", params.cfg);
68 
69  push(writer, "eig");
70  write(writer, "RsdR", params.rsd_r);
71  write(writer, "MaxCG", params.max_cg);
72  write(writer, "Neig", params.n_eig);
73  write(writer, "RsdA", params.rsd_a);
74  write(writer, "RsdZero", params.rsd_zero);
75  write(writer, "ProjApsiP", params.projApsiP);
76  pop(writer); // Eig
77 
78  pop(writer); // params
79 }
80 
81 
82 int main(int argc, char **argv)
83 {
84  // Put the machine into a known state
85  Chroma::initialize(&argc, &argv);
86 
87  // Read the parameters
89 
90  try {
92  }
93  catch(const std::string& s) {
94  QDPIO::cerr << "Caught exception " << s << std::endl;
95  exit(1);
96  }
97 
98 
99  // Setup the lattice
100  Layout::setLattSize(params.nrow);
101  Layout::create();
102 
103  // Write out the params
104  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
105  push(xml_out, "ritzTest");
106 
107  dumpParams(xml_out, params);
108 
109  // Typedefs to save typing
110  typedef LatticeFermion T;
111  typedef multi1d<LatticeColorMatrix> P;
112  typedef multi1d<LatticeColorMatrix> Q;
113 
114  // Create a FermBC
116 
117  // The Gauge Field
118  multi1d<LatticeColorMatrix> u(Nd);
119  XMLReader gauge_file_xml, gauge_xml;
120  gaugeStartup(gauge_file_xml, gauge_xml, u, params.cfg);
121 
122  // Measure the plaquette on the gauge
123  MesPlq(xml_out, "Observables", u);
124  xml_out.flush();
125 
126  //! Wilsoniums;
127  // Put this puppy into a handle to allow Zolo to copy it around as a **BASE** class
128  // WARNING: the handle now owns the data. The use of a bare S_w below is legal,
129  // but just don't delete it.
130  UnprecWilsonFermAct S_w(cfs, params.quark_mass);
131 
132  Handle< FermState<T,P,Q> > connect_state(S_w.createState(u));
133 
134  Handle< LinearOperator<T> > MM(S_w.lMdagM(connect_state));
135 
136  // Try and get lowest eigenvalue of MM
137  multi1d<Real> lambda(params.n_eig);
138  multi1d<Real> check_norm(params.n_eig);
139  multi1d<LatticeFermion> psi(params.n_eig);
140 
141  int n_CG_count;
142 
143  {
144  XMLBufferWriter eig_spec_xml;
145 
146  for(int i =0; i < params.n_eig; i++)
147  gaussian(psi[i]);
148 
149  EigSpecRitzCG(*MM,
150  lambda,
151  psi,
152  params.n_eig,
153  params.n_renorm,
154  params.n_min,
155  params.max_cg,
156  params.rsd_r,
157  params.rsd_a,
158  params.rsd_zero,
159  params.projApsiP,
160  n_CG_count,
161  eig_spec_xml);
162 
163  write(xml_out,"LowestEv",eig_spec_xml);
164  }
165 
166 
167  {
168  QDPIO::cout << "Look for highest ev" << std::endl;
169 
170  Handle< LinearOperator<T> > MinusMM(new lopscl<LatticeFermion, Real>(MM, Real(-1.0)));
171 
172  // Look for highest ev
173  for(int i =0; i < params.n_eig; i++)
174  gaussian(psi[i]);
175 
176  QDPIO::cout << "ritz call" << std::endl;
177 
178  XMLBufferWriter eig_spec_xml;
179 
180  EigSpecRitzCG(*MinusMM,
181  lambda,
182  psi,
183  params.n_eig,
184  params.n_renorm,
185  params.n_min,
186  params.max_cg,
187  params.rsd_r,
188  params.rsd_a,
189  params.rsd_zero,
190  params.projApsiP,
191  n_CG_count,
192  eig_spec_xml);
193 
194  write(xml_out,"HighestEv",eig_spec_xml);
195  }
196 
197  pop(xml_out);
199 
200  exit(0);
201 }
Primary include file for CHROMA in application codes.
Create a simple ferm connection state.
virtual FermState< T, P, Q > * createState(const Q &q) const
Given links (coordinates Q) create the state needed for the linear operators.
Definition: fermact.h:59
Class for counted reference semantics.
Definition: handle.h:33
Unpreconditioned Wilson fermion action.
virtual DiffLinearOperator< T, P, Q > * lMdagM(Handle< FermState< T, P, Q > > state) const
Produce a linear operator M^dag.M for this action.
Definition: fermact.orig.h:351
Scaled Linear Operator.
Definition: lopscl.h:22
void EigSpecRitzCG(const LinearOperator< LatticeFermion > &M, multi1d< Real > &lambda_H, multi1d< LatticeFermion > &psi, int n_eig, int n_renorm, int n_min, int MaxCG, const Real &Rsd_r, const Real &Rsd_a, const Real &zero_cutoff, const bool ProjApsiP, int &n_cg_tot, XMLWriter &xml_out)
Compute low lying eigenvalues of the hermitian H.
Definition: eig_spec.cc:41
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
void gaugeStartup(XMLReader &gauge_file_xml, XMLReader &gauge_xml, multi1d< LatticeColorMatrix > &u, Cfg_t &cfg)
Initialize the gauge fields.
Params params
Nd
Definition: meslate.cc:74
multi1d< LatticeColorMatrix > P
Handle< FermBC< LatticeStaggeredFermion, multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > > reader(XMLReader &xml_in, const std::string &path)
Helper function for the FermionAction readers.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
static multi1d< LatticeColorMatrix > u
LinOpSysSolverMGProtoClover::Q Q
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
int i
Definition: pbg5p_w.cc:55
void initialize(int *argc, char ***argv)
Chroma initialisation routine.
Definition: chroma_init.cc:114
void finalize(void)
Chroma finalization routine.
Definition: chroma_init.cc:308
std::string getXMLInputFileName()
Get input file name.
Definition: chroma_init.cc:88
LatticeFermion psi
Definition: mespbg5p_w.cc:35
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
multi1d< LatticeFermion > s(Ncb)
::std::string string
Definition: gtest.h:1979
Gauge configuration structure.
Definition: cfgtype_io.h:16
Parameters for running program.
Definition: qpropadd.cc:17
bool projApsiP
Definition: t_ritz.cc:19
int n_renorm
Definition: t_ritz.cc:20
Real rsd_a
Definition: t_ritz.cc:17
Real rsd_r
Definition: t_ritz.cc:16
int n_eig
Definition: t_ritz.cc:22
int n_min
Definition: t_ritz.cc:21
Cfg_t cfg
Definition: t_ritz.cc:13
Real rsd_zero
Definition: t_ritz.cc:18
void readParams(const std::string &filename, Param_t &params)
Definition: t_ritz.cc:27
int main(int argc, char **argv)
Definition: t_ritz.cc:82
void dumpParams(XMLWriter &writer, Param_t &params)
Definition: t_ritz.cc:55