ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mpotensor_detail.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 Sebastian Keller <sebkelle@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 MPOTENSOR_DETAIL_H
28 #define MPOTENSOR_DETAIL_H
29 
30 template<class Matrix, class SymmGroup>
31 class MPOTensor;
32 
33 namespace MPOTensor_detail
34 {
35  template <class Matrix, class SymmGroup>
37  typedef typename OPTable<Matrix, SymmGroup>::op_t op_t;
38  typedef typename Matrix::value_type value_type;
39  public:
41  term_descriptor(op_t & op_, value_type & s_) : op(op_), scale(s_) {}
42 
43  op_t & op;
44  value_type & scale;
45  };
46 
47  template <class Matrix, class SymmGroup>
49  typename term_descriptor<Matrix, SymmGroup>::op_t & op_, typename Matrix::value_type & s_)
50  {
51  return term_descriptor<Matrix, SymmGroup>(op_, s_);
52  }
53 
54  template <class Matrix, class SymmGroup>
56  typedef typename OPTable<Matrix, SymmGroup>::op_t op_t;
57  typedef typename Matrix::value_type value_type;
58  public:
60  const_term_descriptor(op_t const & op_, value_type s_) : op(op_), scale(s_) {}
61 
62  op_t const & op;
63  value_type const scale;
64  };
65 
66  template <class Matrix, class SymmGroup, typename Scale>
68  block_matrix<Matrix, SymmGroup> const & op_, Scale s_)
69  {
71  }
72 
73  template <class ConstIterator>
75  {
76  typedef ConstIterator internal_iterator;
77 
78  public:
80  typedef typename std::iterator_traits<internal_iterator>::value_type value_type;
81 
82  IteratorWrapper(internal_iterator i) : it_(i) { }
83 
84  void operator++() { ++it_; }
85  void operator++(int) {it_++; }
86  bool operator!=(self_type const & rhs) { return it_ != rhs.it_; }
87 
88  value_type index() const { return *it_; }
90  throw std::runtime_error("direct MPOTensor access via row iterators currently not implemented\n");
91  return *it_;
92  }
93 
94  private:
95  internal_iterator it_;
96  };
97 
98  template <class ConstIterator>
99  class row_proxy : public std::pair<ConstIterator, ConstIterator>
100  {
101  typedef ConstIterator internal_iterator;
102  typedef std::pair<internal_iterator, internal_iterator> base;
103 
104  public:
106  row_proxy(internal_iterator b, internal_iterator e) : base(b, e) { }
107 
108  const_iterator begin() const { return const_iterator(base::first); }
109  const_iterator end() const { return const_iterator(base::second); }
110  };
111 
112  using namespace boost::tuples;
113 
114  template<class Tuple>
115  struct row_cmp
116  {
117  bool operator() (Tuple const & i, Tuple const & j) const
118  {
119  if (get<0>(i) < get<0>(j))
120  return true;
121  else if (get<0>(i) > get<0>(j))
122  return false;
123  else
124  return get<1>(i) < get<1>(j);
125  }
126  };
127 
128  template<class Tuple>
129  struct col_cmp
130  {
131  bool operator() (Tuple const & i, Tuple const & j) const
132  {
133  if (get<1>(i) < get<1>(j))
134  return true;
135  else if (get<1>(i) > get<1>(j))
136  return false;
137  else
138  return get<0>(i) < get<0>(j);
139  }
140  };
141 }
142 
143 #endif
IteratorWrapper< ConstIterator > self_type
const_term_descriptor< Matrix, SymmGroup > make_const_term_descriptor(block_matrix< Matrix, SymmGroup > const &op_, Scale s_)
IteratorWrapper< ConstIterator > const_iterator
term_descriptor< Matrix, SymmGroup > make_term_descriptor(typename term_descriptor< Matrix, SymmGroup >::op_t &op_, typename Matrix::value_type &s_)
const_iterator end() const
row_proxy(internal_iterator b, internal_iterator e)
IteratorWrapper(internal_iterator i)
const_iterator begin() const
bool operator!=(self_type const &rhs)
const_term_descriptor(op_t const &op_, value_type s_)
term_descriptor(op_t &op_, value_type &s_)
std::iterator_traits< internal_iterator >::value_type value_type