ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
term_descriptor.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * ALPS MPS DMRG Project
4  *
5  * Copyright (C) 2013 Institute for Theoretical Physics, ETH Zurich
6  * 2013-2013 by Michele Dolfi <dolfim@phys.ethz.ch>
7  *
8  * This software is part of the ALPS Applications, published under the ALPS
9  * Application License; you can use, redistribute it and/or modify it under
10  * the terms of the license, either version 1 or (at your option) any later
11  * version.
12  *
13  * You should have received a copy of the ALPS Application License along with
14  * the ALPS Applications; see the file LICENSE.txt. If not, the license is also
15  * available from http://alps.comp-phys.org/.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  * DEALINGS IN THE SOFTWARE.
24  *
25  *****************************************************************************/
26 
27 #ifndef MODELS_TERM_DESCRIPTOR_H
28 #define MODELS_TERM_DESCRIPTOR_H
29 
30 #include <boost/tuple/tuple.hpp>
31 #include <vector>
32 
33 namespace detail {
34 
35  struct pos_tag_lt {
36  typedef boost::tuple<int, unsigned int> value_type;
37  inline bool operator() (value_type const& lhs, value_type const& rhs)
38  {
39  return (boost::get<0>(lhs) < boost::get<0>(rhs));
40  }
41  };
42 
43 }
44 
45 template <typename T>
46 class term_descriptor : public std::vector<boost::tuple<int, unsigned int> > {
47 public:
48  typedef int pos_type;
49  typedef unsigned int tag_type;
50  typedef boost::tuple<pos_type, tag_type> value_type;
51 
52  typedef std::vector<value_type> base;
53  typedef base::size_type size_type;
54  typedef typename base::iterator iterator;
55  typedef typename base::const_iterator const_iterator;
56 
57  T coeff;
59  term_descriptor() : coeff(1.), is_fermionic(false) { }
60 
61  pos_type position(size_type i) const { return boost::get<0>((*this)[i]); }
62  tag_type operator_tag(size_type i) const { return boost::get<1>((*this)[i]); }
63 
64  /// utilities
65  void canonical_order() // TODO: check and fix for fermions
66  {
67  std::sort(begin(), end(), detail::pos_tag_lt());
68  }
69 
70  bool operator< (term_descriptor const & rhs) const
71  {
72  if (this->size() == 0) return true;
73  if (rhs.size() == 0) return false;
74 
75  if (this->position(0) == rhs.position(0))
76  return this->size() >= rhs.size();
77  return this->position(0) < rhs.position(0);
78  }
79 
80  bool site_match (term_descriptor const & rhs) const
81  {
82  if (this->size() == rhs.size())
83  {
84  bool ret = true;
85  for (std::size_t p=0; p<this->size() && ret; ++p)
86  ret = (this->position(p) == rhs.position(p));
87  return ret;
88  } else if (this->size() == 2 && rhs.size() == 1)
89  return (this->position(0) == rhs.position(0) || this->position(1) == rhs.position(0));
90  else if (this->size() == 1 && rhs.size() == 2)
91  return (this->position(0) == rhs.position(0) || this->position(0) == rhs.position(1));
92  else
93  {
94  throw std::runtime_error("site_match not implemented for this type of operator." );
95  return false;
96  }
97 
98  }
99 
100  bool overlap (term_descriptor const & rhs) const
101  {
102  return !( (boost::get<0>(*this->rbegin()) < boost::get<0>(*rhs.begin())) || (boost::get<0>(*rhs.rbegin()) < boost::get<0>(*this->begin())) );
103  }
104 };
105 
106 /// ostream
107 template<typename T>
108 std::ostream & operator<< (std::ostream & os, term_descriptor<T> const& term)
109 {
110  os << "coeff: " << term.coeff << std::endl;
111  os << "operators:";
112  for (int i=0; i<term.size(); ++i)
113  os << " {" << term.position(i) << "," << term.operator_tag(i) << "}";
114  os << std::endl;
115  return os;
116 }
117 
118 
119 #endif
base::iterator iterator
bool operator()(value_type const &lhs, value_type const &rhs)
boost::tuple< int, unsigned int > value_type
bool overlap(term_descriptor const &rhs) const
bool site_match(term_descriptor const &rhs) const
tag_type operator_tag(size_type i) const
base::const_iterator const_iterator
unsigned int tag_type
pos_type position(size_type i) const
void canonical_order()
utilities
std::vector< value_type > base
bool operator<(term_descriptor const &rhs) const
boost::tuple< pos_type, tag_type > value_type
base::size_type size_type