CHROMA
exact_hamiltonian.cc
Go to the documentation of this file.
2 #include <typeinfo>
3 
4 namespace Chroma {
5 
6 
8  {
9  monomial_ids.resize(0);
10  try {
11  XMLReader paramtop(xml, path);
12  read(paramtop, "monomial_ids", monomial_ids);
13  }
14  catch(const std::string& e) {
15  QDPIO::cout << "Caught Exception Reading XML: " << e << std::endl;
16  QDP_abort(1);
17  }
18  }
19 
20 
21  void read(XMLReader& xml, const std::string& path, ExactHamiltonianParams& p)
22  {
23  ExactHamiltonianParams tmp(xml,path);
24  p = tmp;
25  }
26 
27  void write(XMLWriter& xml, const std::string& path, const ExactHamiltonianParams& p)
28  {
29  push(xml, path);
30  write(xml, "monomial_ids", p.monomial_ids);
31  pop(xml);
32  }
33 
34  void ExactHamiltonian::create(const multi1d<std::string>& monomial_ids)
35  {
36  // Convenience
38  multi1d<LatticeColorMatrix> > > MHandle;
39 
40  monomials.resize(0);
41  if ( monomial_ids.size() > 0 ) {
42 
43  // Resize array of handles
44  monomials.resize( monomial_ids.size() );
45 
46  // Go through the list of IDs and try to bind them
47  for(int i=0; i < monomial_ids.size(); i++) {
48 
49  // This will hold the lookup result temporarily
50  MHandle handle;
51 
52  // Lookup the ID first
53  try {
54  handle =
55  TheNamedObjMap::Instance().getData<MHandle>(monomial_ids[i]);
56  }
57  catch(const std::string& e) {
58  QDPIO::cout << "Lookup of " << monomial_ids[i]
59  << " failed with error: " << e << std::endl;
60  QDP_abort(1);
61  }
62 
63  // Now try to cast it to be an ExactMonomial handle
64  try {
65  QDPIO::cout << "ExactHamiltonian::create(): Trying to bind monomial with ID " << monomial_ids[i] << std::endl;
66 
67 
68  monomials[i] = handle.cast<ExactMon>();
69  }
70  catch( std::bad_cast ) {
71  QDPIO::cout << "Failed to cast monomial with ID: " << monomial_ids[i] << " to an ExactMonomial in ExactHamiltonian::create() " << std::endl;
72  QDP_abort(1);
73  }
74  }
75 
76  }
77  else {
78  // Case when there are zero monomials to the Hamiltonian
79  QDPIO::cout << "Attempting to construct Hamiltonian with 0 monomials."
80  << std::endl;
81  QDP_abort(1);
82  }
83  }
84 
85 
86 
87 
88 }
void create(const multi1d< std::string > &monomial_ids)
This creates the hamiltonian. It is similar to the.
multi1d< Handle< ExactMon > > monomials
Class for counted reference semantics.
Definition: handle.h:33
static T & Instance()
Definition: singleton.h:432
Exact Hamiltonians.
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.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
int i
Definition: pbg5p_w.cc:55
pop(xml_out)
::std::string string
Definition: gtest.h:1979
Parameter structure for new Hamiltonian.
multi1d< std::string > monomial_ids
ExactHamiltonianParams(XMLReader &xml, const std::string &path)
Constructor.