CHROMA
t_read_eigen.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <sstream>
4 #include <iomanip>
5 #include <string>
6 
7 #include <cstdio>
8 
9 #include <stdlib.h>
10 #include <sys/time.h>
11 #include <math.h>
12 
13 #include "chroma.h"
14 #include "io/param_io.h"
15 #include "io/eigen_io.h"
16 
17 
18 using namespace Chroma;
19 
20 
21 struct ReadEigen_t {
22  int version;
23  Real Mass;
24  multi1d<int> boundary;
25  multi1d<int> nrow;
26  QDP::Seed seed;
27  int Neig;
30 };
31 
32 void read(XMLReader& xml, const std::string& path, ReadEigen_t& param)
33 {
34  XMLReader paramtop(xml, path);
35  read(paramtop, "Param/version", param.version);
36  read(paramtop, "Param/Mass", param.Mass);
37  read(paramtop, "Param/boundary", param.boundary);
38  read(paramtop, "Param/nrow", param.nrow);
39  read(paramtop, "Param/rng", param.seed);
40  read(paramtop, "Param/Neig", param.Neig);
41  read(paramtop, "Cfg", param.cfg);
42  read(paramtop, "Eigen", param.eigen_io_params);
43 }
44 
45 int main(int argc, char **argv)
46 {
47  // Put the machine into a known state
48  Chroma::initialize(&argc, &argv);
49 
50  ReadEigen_t input;
51  XMLReader xml_in(Chroma::getXMLInputFileName());
52 
53  try {
54  read(xml_in, "/ReadEigen", input);
55  }
56  catch( const std::string& e ) {
57  QDPIO::cerr << "Caught Exception: " << e << std::endl;
58  QDP_error_exit("Exiting\n");
59  }
60 
61  // Setup the lattice
62  Layout::setLattSize(input.nrow);
63  Layout::create();
64 
65 
66  QDP::RNG::setrn(input.seed);
67 
68  QDPIO::cout << "ReadEigen" << std::endl;
69 
70  multi1d<LatticeColorMatrix> u(Nd);
71  XMLReader gauge_file_xml, gauge_xml;
72 
73  switch (input.cfg.cfg_type)
74  {
75  case CFG_TYPE_SZIN :
76  QDPIO::cout << "Reading SZIN Gauge config" << std::endl;
77  readSzin(gauge_xml, u, input.cfg.cfg_file);
78  break;
79 
80  case CFG_TYPE_SZINQIO:
81  QDPIO::cout << "Reading SZIN QIO gauge config" << std::endl;
82  readGauge(gauge_file_xml, gauge_xml, u, input.cfg.cfg_file, QDPIO_SERIAL);
83  break;
84 
85  case CFG_TYPE_NERSC:
86  QDPIO::cout << "Reading NERSC gauge config" << std::endl;
87  readArchiv(gauge_xml, u, input.cfg.cfg_file);
88  break;
89  default :
90  QDP_error_exit("Configuration type is unsupported.");
91  }
92 
93  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
94  push(xml_out, "ReadEigen");
95 
96  // write((XMLWriter &)xml_out, "InputParams", input);
97 
98  // Measure the plaquette on the gauge
99  MesPlq(xml_out, "Observables", u);
100  xml_out.flush();
101 
102  //! Wilsoniums;
103  // Put this puppy into a handle to allow Zolo to copy it around as a **BASE** class
104  // WARNING: the handle now owns the data. The use of a bare S_w below is legal,
105  // but just don't delete it.
106  // Create a FermBC
108  UnprecWilsonFermAct S_w(fbc, input.Mass);
109 
110  Handle< const ConnectState > connect_state = S_w.createState(u);
111 
112  multi1d<Real> lambda_lo(input.Neig);
113  Real lambda_hi;
114  multi1d<LatticeFermion> eigv_lo(input.Neig);
115 
116  ChromaWilsonRitz_t header;
117  readEigen(header, lambda_lo, eigv_lo, lambda_hi,
119  input.Neig,QDPIO_SERIAL);
120 
121  write(xml_out, "lambda", lambda_lo);
122  write(xml_out, "lambda_hi", lambda_hi);
123 
125 
126  multi1d<Double> check_norm(header.ritz_params.Neig);
127 
128  for(int i=0; i < header.ritz_params.Neig; i++) {
129  LatticeFermion Me;
130  (*H)(Me, eigv_lo[i], PLUS);
131 
132  LatticeFermion lambda_e;
133 
134  lambda_e = lambda_lo[i]*eigv_lo[i];
135  LatticeFermion r_norm = Me - lambda_e;
136  check_norm[i] = sqrt(norm2(r_norm))/fabs(lambda_lo[i]);
137  }
138 
139  write(xml_out, "check_norm", check_norm);
140  pop(xml_out);
141 
143 
144  exit(0);
145 }
Primary include file for CHROMA in application codes.
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
Concrete class for all gauge actions with simple boundary conditions.
Definition: simple_fermbc.h:42
Unpreconditioned Wilson fermion action.
LinearOperator< T > * hermitianLinOp(Handle< FermState< T, P, Q > > state) const
Produce the gamma_5 hermitian operator H_w.
Eigenvalue IO.
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 readGauge(XMLReader &file_xml, XMLReader &record_xml, multi1d< LatticeColorMatrix > &u, const std::string &file, QDP_serialparallel_t serpar)
Read a gauge config in QIO format.
Definition: gauge_io.cc:19
void readEigen(ChromaWilsonRitz_t &header, multi1d< Real > &lambda_lo, multi1d< LatticeFermion > &eigv_lo, Real &lambda_hi, const std::string &filename_stem, int Neig, QDP_serialparallel_t serpar)
Definition: eigen_io.cc:276
void readSzin(SzinGauge_t &header, multi1d< LatticeColorMatrix > &u, const std::string &cfg_file)
Read a SZIN configuration file.
Definition: readszin.cc:31
@ CFG_TYPE_SZINQIO
@ CFG_TYPE_NERSC
void setrn(int iseed[4])
Definition: make_seeds.cc:38
Nd
Definition: meslate.cc:74
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
QDP_error_exit("too many BiCG iterations", n_count, rsd_sq, cp, c, re_rvr, im_rvr, re_a, im_a, re_b, im_b)
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
void initialize(int *argc, char ***argv)
Chroma initialisation routine.
Definition: chroma_init.cc:114
@ PLUS
Definition: chromabase.h:45
void finalize(void)
Chroma finalization routine.
Definition: chroma_init.cc:308
std::string getXMLInputFileName()
Get input file name.
Definition: chroma_init.cc:88
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
::std::string string
Definition: gtest.h:1979
Double r_norm
Definition: pade_trln_w.cc:86
Various parameter structs and reader/writers.
Gauge configuration structure.
Definition: cfgtype_io.h:16
std::string cfg_file
Definition: cfgtype_io.h:18
CfgType cfg_type
Definition: cfgtype_io.h:17
Struct for the overall application.
Definition: eigen_io.h:50
RitzParams_t ritz_params
Definition: eigen_io.h:56
Struct for dumping the eigenvalues/vectors.
Definition: eigen_io.h:40
std::string eigen_file
Definition: eigen_io.h:42
EigenIO_t eigen_io_params
Definition: t_read_eigen.cc:29
QDP::Seed seed
Definition: t_read_eigen.cc:26
multi1d< int > boundary
Definition: t_read_eigen.cc:24
multi1d< int > nrow
Definition: t_read_eigen.cc:25
int main(int argc, char **argv)
Definition: t_read_eigen.cc:45