CHROMA
exact_hamiltonian.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief Exact Hamiltonians
4  */
5 
6 #ifndef EXACT_HAMILTONIAN_H
7 #define EXACT_HAMILTONIAN_H
8 
9 #include "chromabase.h"
10 #include "handle.h"
11 
13 
14 #include "io/xmllog_io.h"
15 #include "io/monomial_io.h"
17 
18 namespace Chroma
19 {
20 
21 
22 
23  //! Parameter structure for new Hamiltonian
24  /*! @ingroup hamilton */
26 
27  //! Constructor
28  ExactHamiltonianParams(XMLReader& xml, const std::string& path);
29  multi1d<std::string> monomial_ids; /*!< list of monomial IDs */
30 
31  };
32 
33  //! Read the parameters for the Hamiltonian
34  void read(XMLReader& xml, const std::string& path, ExactHamiltonianParams& p);
35 
36  //! Write the parameters for the Hamiltonian
37  void write(XMLWriter& xml, const std::string& path, const ExactHamiltonianParams& p);
38 
39 
40  //! The Exact Hamiltonian Class - supplies internal field refreshment and energy calculations
41  /*! @ingroup hamilton */
42  class ExactHamiltonian : public AbsHamiltonian< multi1d<LatticeColorMatrix>,
43  multi1d<LatticeColorMatrix> >
44  {
45  public:
46 
47  //! Construct from a list of std::string monomial_ids
48  ExactHamiltonian(const multi1d<std::string>& monomial_ids_) {
49  create(monomial_ids_);
50  }
51 
52  //! Construct from a parameter structure
54  create(p.monomial_ids);
55  }
56 
57  //! Copy constructor
59 
60  //! Destructor
62 
63  //! Internal Field Refreshment
64  void refreshInternalFields(const AbsFieldState<multi1d<LatticeColorMatrix>,multi1d<LatticeColorMatrix> >& s)
65  {
66  START_CODE();
67  for(int i=0; i < monomials.size(); i++) {
68  monomials[i]->refreshInternalFields(s);
69  }
70  END_CODE();
71  }
72 
73 
75  multi1d<LatticeColorMatrix>,
76  multi1d<LatticeColorMatrix> > &s
77  ) const
78  {
79  START_CODE();
80 
81  /* Accumulate KE per site */
82  multi1d<LatticeDouble> ke_per_site(Nd);
83 
84 
85  /* Now add on the local Norm2 of the momenta for each link */
86  for(int mu=0; mu < Nd; mu++) {
87  ke_per_site[mu] = -Double(4);
88  ke_per_site[mu] += localNorm2(s.getP()[mu]);
89  }
90 
91  /* Sum up the differences */
92  Double KE=zero;
93  for(int mu=0; mu < Nd; mu++) {
94  KE += sum(ke_per_site[mu]);
95  }
96 
97  XMLWriter& xml_out = TheXMLLogWriter::Instance();
98  push(xml_out, "mesKE");
99  write(xml_out, "KE", sum(KE));
100  pop(xml_out); // pop(mesKE);
101 
102 
103  return KE;
104 
105  END_CODE();
106  }
107 
108  //! The Potential Energy
109  Double mesPE(const AbsFieldState< multi1d<LatticeColorMatrix>,
110  multi1d<LatticeColorMatrix> >& s) const
111  {
112  START_CODE();
113 
114  // Self Encapsulation Rule
115  XMLWriter& xml_out = TheXMLLogWriter::Instance();
116  push(xml_out, "mesPE");
117  // Cycle through all the monomials and compute their contribution
118  int num_terms = monomials.size();
119 
120  write(xml_out, "num_terms", num_terms);
121  Double PE=zero;
122 
123  // Caller writes elem rule
124  push(xml_out, "PEByMonomials");
125  for(int i=0; i < num_terms; i++)
126  {
127  push(xml_out, "elem");
128  Double tmp;
129  tmp=monomials[i]->S(s);
130  PE += tmp;
131  pop(xml_out); // elem
132  }
133  pop(xml_out); // PEByMonomials
134  pop(xml_out); // pop(mesPE);
135 
136  END_CODE();
137  return PE;
138  }
139 
140  private:
141  //! Convenience
143  multi1d<LatticeColorMatrix> > ExactMon;
144 
145  //! This creates the hamiltonian. It is similar to the
146  void create(const multi1d<std::string>& monomial_ids);
147 
148 
149  multi1d< Handle<ExactMon> > monomials;
150 
151 
152  };
153 
154 }
155 
156 #endif
Abstract Hamiltonian.
Primary include file for CHROMA library code.
Abstract field state.
Definition: field_state.h:27
New Abstract Hamiltonian.
The Exact Hamiltonian Class - supplies internal field refreshment and energy calculations.
Double mesPE(const AbsFieldState< multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > &s) const
The Potential Energy.
ExactHamiltonian(const multi1d< std::string > &monomial_ids_)
Construct from a list of std::string monomial_ids.
void refreshInternalFields(const AbsFieldState< multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > &s)
Internal Field Refreshment.
~ExactHamiltonian(void)
Destructor.
ExactMonomial< multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > ExactMon
Convenience.
void create(const multi1d< std::string > &monomial_ids)
This creates the hamiltonian. It is similar to the.
Double mesKE(const AbsFieldState< multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > &s) const
The Kinetic Energy.
multi1d< Handle< ExactMon > > monomials
ExactHamiltonian(const ExactHamiltonianParams &p)
Construct from a parameter structure.
ExactHamiltonian(const ExactHamiltonian &H)
Copy constructor.
Abstract monomial class, for exact algorithms.
Definition: abs_monomial.h:75
static T & Instance()
Definition: singleton.h:432
int mu
Definition: cool.cc:24
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.
Class for counted reference semantics.
Nd
Definition: meslate.cc:74
Monomial IO.
Named object function std::map.
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)
START_CODE()
Double zero
Definition: invbicg.cc:106
multi1d< LatticeFermion > s(Ncb)
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
Double sum
Definition: qtopcor.cc:37
Parameter structure for new Hamiltonian.
multi1d< std::string > monomial_ids
ExactHamiltonianParams(XMLReader &xml, const std::string &path)
Constructor.
Singleton instances of xml output.