ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
op_handler.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 MAQUIS_DMRG_MODELS_OP_HANDLER_H
28 #define MAQUIS_DMRG_MODELS_OP_HANDLER_H
29 
30 #include <vector>
31 #include <map>
32 #include <utility>
33 #include <stdexcept>
34 
35 #include <boost/shared_ptr.hpp>
36 
39 
40 #include "dmrg/models/tag_detail.h"
41 
42 template <class Matrix, class SymmGroup>
43 class OPTable : public std::vector<block_matrix<Matrix, SymmGroup> >
44 {
45 public:
48 
49 private:
50  typedef typename Matrix::value_type mvalue_type;
51 
52 public:
53  tag_type register_op(op_t const & op_);
54  std::pair<tag_type, mvalue_type> checked_register(op_t const& sample);
55 };
56 
57 template <class Matrix, class SymmGroup>
59 {
60 public:
63 
64 protected:
65  typedef typename Matrix::value_type value_type;
66  typedef std::map<std::pair<tag_type, tag_type>, std::pair<tag_type, value_type>, tag_detail::pair_cmp> pair_map_t;
67  typedef typename pair_map_t::const_iterator pair_map_it_t;
68 
69 public:
71  operator_table(new OPTable<Matrix, SymmGroup>())
72  { }
73 
74  TagHandler(boost::shared_ptr<OPTable<Matrix, SymmGroup> > tbl_) :
75  operator_table(tbl_)
76  { }
77 
79 
80  std::pair<tag_type, value_type> checked_register(op_t const& sample, tag_detail::operator_kind kind) {
81  std::pair<tag_type, value_type> ret = operator_table->checked_register(sample);
82  if (sign_table.size() < operator_table->size())
83  sign_table.push_back(kind);
84 
85  assert(sign_table.size() == operator_table->size());
86 
87  return ret;
88  }
89 
90 /*
91  std::pair<tag_type, value_type> checked_register(op_t & sample, tag_detail::operator_kind kind) {
92  std::pair<bool, value_type> cmp_result;
93  typename std::vector<op_t>::iterator it_pt = operator_table->begin();
94  for (; it_pt != operator_table->end(); ++it_pt) {
95  cmp_result = equal(*it_pt, sample);
96  if (cmp_result.first)
97  break;
98  }
99 
100  std::pair<tag_type, value_type> ret;
101  if (it_pt == operator_table->end()) {
102  ret = std::make_pair(operator_table->register_op(sample), 1.0);
103  sign_table.push_back(kind);
104  } else
105  ret = std::make_pair(it_pt - operator_table->begin(), cmp_result.second);
106 
107  assert(sign_table.size() == operator_table->size());
108  return ret;
109  }
110 */
111 
112  typename OPTable<Matrix, SymmGroup>::value_type & get_op(tag_type i) { return (*operator_table)[i]; }
113  typename OPTable<Matrix, SymmGroup>::value_type const & get_op(tag_type i) const { return (*operator_table)[i]; }
114 
115  bool is_fermionic (tag_type query_tag) const { return sign_table[query_tag]; }
116 
117  /* WARNING: not thread safe! */
118  std::pair<tag_type, value_type> get_product_tag(const tag_type t1, const tag_type t2);
119 
120 
121  /* Diagnostics *************************************/
122  tag_type prod_duplicates() const { return duplicates_(product_tags); }
123 
124  tag_type get_num_products() const;
125  tag_type total_size() const { return operator_table->size(); }
126  /***************************************************/
127 
128  boost::shared_ptr<OPTable<Matrix, SymmGroup> > get_operator_table() { return operator_table; }
129 
130 private:
131  boost::shared_ptr<OPTable<Matrix, SymmGroup> > operator_table;
132 
133  template <class Map>
134  tag_type duplicates_(Map const & sample);
135 
136  std::vector<tag_detail::operator_kind> sign_table;
137  pair_map_t product_tags;
138 };
139 
140 template <class Matrix, class SymmGroup>
141 class KronHandler : public TagHandler<Matrix, SymmGroup>
142 {
145  typedef typename base::op_t op_t;
146 
147 public:
148 
149  KronHandler(boost::shared_ptr<OPTable<Matrix, SymmGroup> > tbl_)
150  : base(tbl_)
151  , kronecker_table(new OPTable<Matrix, SymmGroup>())
152  {
153  for (typename OPTable<Matrix, SymmGroup>::iterator it = tbl_->begin();
154  it != tbl_->end(); ++it)
155  uniform.push_back(tag_detail::is_uniform(*it));
156  }
157 
158  tag_type get_kron_tag(Index<SymmGroup> const & phys_i1, Index<SymmGroup> const & phys_i2, tag_type t1, tag_type t2);
159 
160 
161  typename OPTable<Matrix, SymmGroup>::value_type & get_op(tag_type i) { return (*kronecker_table)[i]; }
162  typename OPTable<Matrix, SymmGroup>::value_type const & get_op(tag_type i) const { return (*kronecker_table)[i]; }
163 
164  bool is_uniform(tag_type t) { return uniform[t]; }
165 
166  boost::shared_ptr<OPTable<Matrix, SymmGroup> > get_kronecker_table() { return kronecker_table; }
167 
168  /* Diagnostics *************************************/
169  tag_type get_num_kron_products() const;
170 
171 private:
172  boost::shared_ptr<OPTable<Matrix, SymmGroup> > kronecker_table;
173  typename base::pair_map_t kron_tags;
174  std::vector<bool> uniform;
175 };
176 
177 
179 
180 #endif
OPTable< Matrix, SymmGroup >::value_type const & get_op(tag_type i) const
Definition: op_handler.h:113
tag_type total_size() const
Definition: op_handler.h:125
bool is_fermionic(tag_type query_tag) const
Definition: op_handler.h:115
std::pair< tag_type, mvalue_type > checked_register(op_t const &sample)
Definition: op_handler.hpp:42
tag_type register_op(op_t const &op_)
Definition: op_handler.hpp:33
pair_map_t::const_iterator pair_map_it_t
Definition: op_handler.h:67
boost::shared_ptr< OPTable< Matrix, SymmGroup > > get_operator_table()
Definition: op_handler.h:128
tag_type get_kron_tag(Index< SymmGroup > const &phys_i1, Index< SymmGroup > const &phys_i2, tag_type t1, tag_type t2)
Definition: op_handler.hpp:160
tag_detail::tag_type tag_type
Definition: op_handler.h:46
declaration of block_matrix class
boost::shared_ptr< OPTable< Matrix, SymmGroup > > get_kronecker_table()
Definition: op_handler.h:166
tag_type get_num_products() const
Definition: op_handler.hpp:150
KronHandler(boost::shared_ptr< OPTable< Matrix, SymmGroup > > tbl_)
Definition: op_handler.h:149
implementation of tags to indentify operator matrices
definition of OPTable, TagHandler and KronHandler
bool is_uniform(block_matrix< Matrix, SymmGroup > const &op)
Definition: tag_detail.h:77
tag_type get_num_kron_products() const
Definition: op_handler.hpp:198
OPTable< Matrix, SymmGroup >::value_type const & get_op(tag_type i) const
Definition: op_handler.h:162
bool is_uniform(tag_type t)
Definition: op_handler.h:164
OPTable< Matrix, SymmGroup >::op_t op_t
Definition: op_handler.h:62
OPTable< Matrix, SymmGroup >::value_type & get_op(tag_type i)
Definition: op_handler.h:112
OPTable< Matrix, SymmGroup >::tag_type tag_type
Definition: op_handler.h:61
block_matrix< Matrix, SymmGroup > op_t
Definition: op_handler.h:47
algorithms for block_matrix (gemm, svd, etc.)
std::pair< tag_type, value_type > checked_register(op_t const &sample, tag_detail::operator_kind kind)
Definition: op_handler.h:80
Matrix::value_type value_type
Definition: op_handler.h:65
OPTable< Matrix, SymmGroup >::value_type & get_op(tag_type i)
Definition: op_handler.h:161
tag_type register_op(const op_t &op_, tag_detail::operator_kind kind)
Definition: op_handler.hpp:60
std::pair< tag_type, value_type > get_product_tag(const tag_type t1, const tag_type t2)
Definition: op_handler.hpp:88
unsigned tag_type
Definition: tag_detail.h:36
std::map< std::pair< tag_type, tag_type >, std::pair< tag_type, value_type >, tag_detail::pair_cmp > pair_map_t
Definition: op_handler.h:66
tag_type prod_duplicates() const
Definition: op_handler.h:122
TagHandler(boost::shared_ptr< OPTable< Matrix, SymmGroup > > tbl_)
Definition: op_handler.h:74