mps-0.0.0
MatrixProductStatesinC++
 All Data Structures Namespaces Functions Variables Enumerations Enumerator Groups Pages
hamiltonian.h
1 // -*- mode: c++; fill-column: 80; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 /*
3  Copyright (c) 2010 Juan Jose Garcia Ripoll
4 
5  Tensor is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published
7  by the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Library General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #ifndef MPS_HAMILTONIAN_H
21 #define MPS_HAMILTONIAN_H
22 
23 #include <list>
24 #include <vector>
25 #include <tensor/sparse.h>
26 #include <mps/mps.h>
27 
28 namespace mps {
29 
33  class Hamiltonian {
34  public:
35  virtual ~Hamiltonian();
36 
38  virtual const Hamiltonian *duplicate() const = 0;
39 
40  virtual index size() const = 0;
42  virtual bool is_periodic() const = 0;
44  virtual bool is_constant() const = 0;
46  virtual const CTensor interaction(index k, double t = 0.0) const = 0;
47  virtual const CTensor interaction_left(index k, index n, double t = 0.0) const;
48  virtual const CTensor interaction_right(index k, index n, double t = 0.0) const;
49  virtual index interaction_depth(index k, double t = 0.0) const;
51  virtual const CTensor local_term(index k, double t = 0.0) const = 0;
53  virtual index dimension(index k) const;
54  const Indices dimensions() const;
55 
56  void reshape(index new_length);
57  };
58 
60  double expected(const RMPS &psi, const Hamiltonian &H, double t);
61 
63  double expected(const CMPS &psi, const Hamiltonian &H, double t);
64 
66  const CSparse sparse_hamiltonian(const Hamiltonian &H, double t = 0.0);
67 
69  class TIHamiltonian: public Hamiltonian {
70 
71  public:
72  TIHamiltonian(index N, const CTensor &newH12, const CTensor &newH1, bool periodic = 0);
73 
74  virtual const Hamiltonian *duplicate() const;
75  virtual index size() const;
76  virtual bool is_periodic() const;
77  virtual bool is_constant() const;
78  virtual const CTensor interaction(index k, double t) const;
79  virtual const CTensor interaction_left(index k, index n, double t) const;
80  virtual const CTensor interaction_right(index k, index n, double t) const;
81  virtual index interaction_depth(index k, double t = 0.0) const;
82  virtual const CTensor local_term(index k, double t) const;
83 
84  private:
85  index size_;
86  CTensor H12_;
87  CTensor H1_;
88  bool periodic_;
89  std::vector<CTensor> H12_left_, H12_right_;
90  };
91 
94 
95  public:
96  ConstantHamiltonian(index N, bool periodic = false);
97 
98  void set_interaction(index k, const CTensor &H1, const CTensor &H2);
99  void add_interaction(index k, const CTensor &H1, const CTensor &H2);
100  void set_local_term(index k, const CTensor &H1);
101 
102  virtual const Hamiltonian *duplicate() const;
103  virtual index size() const;
104  virtual bool is_periodic() const;
105  virtual bool is_constant() const;
106  virtual const CTensor interaction(index k, double t) const;
107  virtual const CTensor interaction_left(index k, index n, double t) const;
108  virtual const CTensor interaction_right(index k, index n, double t) const;
109  virtual index interaction_depth(index k, double t = 0.0) const;
110  virtual const CTensor local_term(index k, double t) const;
111  virtual index dimension(index k) const;
112 
113  private:
114 
115  const CTensor compute_interaction(index k) const;
116 
117  std::vector<CTensor> H12_, H1_;
118  std::vector<std::vector<CTensor> > H12_left_, H12_right_;
119  Indices dimensions_;
120  bool periodic_;
121  };
122 
123  void split_interaction(const CTensor &H12, std::vector<CTensor> *v1, std::vector<CTensor> *v2);
124 
127 } // namespace mps
128 
129 #endif /* !MPS_HAMILTONIAN_H */
1D Hamiltonian, translationally invariant and constant.
Definition: hamiltonian.h:69
virtual const CTensor local_term(index k, double t) const
Local term of the Hamiltonian on site 'k'.
virtual bool is_constant() const
Does the Hamiltonian depend on time?
virtual bool is_periodic() const
Is there interaction between the first and the last sites?
Real matrix product structure.
Definition: rmps.h:31
Real matrix product structure.
Definition: cmps.h:31
virtual bool is_constant() const =0
Does the Hamiltonian depend on time?
virtual const CTensor interaction(index k, double t) const
Nearest neighbor interaction between sites 'k' and 'k+1'.
const CSparse sparse_hamiltonian(const Hamiltonian &H, double t=0.0)
Create a sparse matrix using the information in Hamiltonian.
void set_local_term(index k, const CTensor &H1)
Add a local term on the k-th site.
virtual const CTensor local_term(index k, double t) const
Local term of the Hamiltonian on site 'k'.
virtual const CTensor interaction(index k, double t=0.0) const =0
Nearest neighbor interaction between sites 'k' and 'k+1'.
1D Hamiltonian, constant but with no translational invariance
Definition: hamiltonian.h:93
virtual const CTensor interaction(index k, double t) const
Nearest neighbor interaction between sites 'k' and 'k+1'.
virtual bool is_periodic() const =0
Is there interaction between the first and the last sites?
virtual const CTensor local_term(index k, double t=0.0) const =0
Local term of the Hamiltonian on site 'k'.
virtual index dimension(index k) const
Dimension of the Hilbert space on the k-th site.
virtual const Hamiltonian * duplicate() const =0
Create a copy of this object.
virtual bool is_periodic() const
Is there interaction between the first and the last sites?
virtual const Hamiltonian * duplicate() const
Create a copy of this object.
virtual index dimension(index k) const
Dimension of the Hilbert space on the k-th site.
Definition: hamiltonian.cc:30
Base class for 1D lattice Hamiltonians.
Definition: hamiltonian.h:33
virtual bool is_constant() const
Does the Hamiltonian depend on time?
ConstantHamiltonian(index N, bool periodic=false)
Create the ConstantHamiltonian, reserving space for the local terms and interactions.
TIHamiltonian(index N, const CTensor &newH12, const CTensor &newH1, bool periodic=0)
Create a translationally invariant Hamiltonian.
virtual const Hamiltonian * duplicate() const
Create a copy of this object.
void set_interaction(index k, const CTensor &H1, const CTensor &H2)
Add a nearest-neighbor interaction between sites 'k' and 'k+1'.
double expected(const RMPS &psi, const Hamiltonian &H, double t)
Expected value of a Hamiltonian over a matrix product state.
void add_interaction(index k, const CTensor &H1, const CTensor &H2)
Add a nearest-neighbor interaction between sites 'k' and 'k+1'.