ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
op_handler.hpp
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  *
9  * This software is part of the ALPS Applications, published under the ALPS
10  * Application License; you can use, redistribute it and/or modify it under
11  * the terms of the license, either version 1 or (at your option) any later
12  * version.
13  *
14  * You should have received a copy of the ALPS Application License along with
15  * the ALPS Applications; see the file LICENSE.txt. If not, the license is also
16  * available from http://alps.comp-phys.org/.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  *
26  *****************************************************************************/
27 
28 #ifndef MAQUIS_DMRG_MODELS_OP_HANDLER_HPP
29 #define MAQUIS_DMRG_MODELS_OP_HANDLER_HPP
30 
31 template <class Matrix, class SymmGroup>
34 {
35  tag_type ret = this->size();
36  this->push_back(op_);
37  return ret;
38 }
39 
40 template <class Matrix, class SymmGroup>
41 std::pair<typename OPTable<Matrix, SymmGroup>::tag_type, typename OPTable<Matrix, SymmGroup>::mvalue_type>
43 {
44  std::pair<bool, mvalue_type> cmp_result;
45  typename std::vector<op_t>::iterator it_pt = this->begin();
46  for (; it_pt != this->end(); ++it_pt) {
47  cmp_result = tag_detail::equal(*it_pt, sample);
48  if (cmp_result.first)
49  break;
50  }
51 
52  if (it_pt == this->end()) {
53  return std::make_pair(this->register_op(sample), 1.0);
54  } else
55  return std::make_pair(it_pt - this->begin(), cmp_result.second);
56 
57 }
58 
59 template <class Matrix, class SymmGroup>
61  sign_table.push_back(kind);
62  return operator_table->register_op(op_);
63 }
64 
65 /*
66 template <class Matrix, class SymmGroup>
67 std::pair<typename OPTable<Matrix, SymmGroup>::tag_type, typename OPTable<Matrix, SymmGroup>::value_type> TagHandler<Matrix, SymmGroup>::checked_register(op_t & sample) {
68 
69  std::pair<bool, value_type> cmp_result;
70  typename std::vector<op_t>::iterator it_pt = this->begin();
71  for (; it_pt != this->end(); ++it_pt) {
72  cmp_result = equal(*it_pt, sample);
73  if (cmp_result.first)
74  break;
75  }
76 
77  if (it_pt == this->end()) {
78  return std::make_pair(this->register_op(sample), 1.0);
79  } else
80  return std::make_pair(it_pt - this->begin(), cmp_result.second);
81 
82 }
83 */
84 
85 template <class Matrix, class SymmGroup>
90  const typename
92 {
93  assert( t1 < operator_table->size() && t2 < operator_table->size() );
94 
95  // return tag of product, if already there
96  try {
97 #if defined(__xlC__) || defined(__FCC_VERSION)
98  if (product_tags.count(std::make_pair(t1, t2)) == 0)
99  throw std::out_of_range("");
100 
101  return product_tags[std::make_pair(t1, t2)];
102 #else
103  return product_tags.at(std::make_pair(t1, t2));
104 #endif
105  }
106 
107  // compute and register the product, then return the new tag
108  catch(const std::out_of_range& e) {
109 
110  op_t product;
111  op_t& op1 = (*operator_table)[t1];
112  op_t& op2 = (*operator_table)[t2];
113 
114  gemm(op1, op2, product);
116  if (sign_table[t1] != sign_table[t2])
117  prod_kind = tag_detail::fermionic;
118 
119  std::pair<tag_type, value_type> ret = this->checked_register(product, prod_kind);
120  product_tags[std::make_pair(t1, t2)] = ret;
121  return ret;
122  }
123 }
124 
125 // * Diagnostics *************************************
126 template <class Matrix, class SymmGroup>
127 template <class Map>
129  typedef typename Map::const_iterator it_t;
130 
131  std::vector<tag_type> unique_ops;
132  for (it_t it_s = sample.begin(); it_s != sample.end(); ++it_s)
133  {
134  bool unique = true;
135  for (typename std::vector<tag_type>::iterator it_unique = unique_ops.begin(); it_unique != unique_ops.end(); ++it_unique)
136  if (equal((*operator_table)[(*it_s).second.first], (*operator_table)[*it_unique]).first)
137  {
138  unique = false;
139  break;
140  }
141 
142  if (unique)
143  unique_ops.push_back((*it_s).second.first);
144  }
145 
146  return sample.size() - unique_ops.size();
147 }
148 
149 template <class Matrix, class SymmGroup>
151  std::set<tag_type> utags;
152  for (pair_map_it_t it = product_tags.begin(); it != product_tags.end(); ++it)
153  utags.insert(it->second.first);
154 
155  return utags.size();
156 }
157 // ***************************************************
158 
159 template <class Matrix, class SymmGroup>
161  Index<SymmGroup> const & phys_i1,
162  Index<SymmGroup> const & phys_i2,
165 {
166  assert( t1 < base::get_operator_table()->size() && t2 < base::get_operator_table()->size() );
167 
168  // return tag of kronecker product, if already there
169  try {
170 #if defined(__xlC__) || defined(__FCC_VERSION)
171  if (kron_tags.count(std::make_pair(t1, t2)) == 0)
172  throw std::out_of_range("");
173 
174  return kron_tags[std::make_pair(t1, t2)].first;
175 #else
176  return kron_tags.at(std::make_pair(t1, t2)).first;
177 #endif
178  }
179  // compute and register the product, then return the new tag
180  catch(const std::out_of_range& e) {
181 
182  op_t product;
183  op_t& op1 = (*base::get_operator_table())[t1];
184  op_t& op2 = (*base::get_operator_table())[t2];
185 
186  op_kron(phys_i1, phys_i2, op1, op2, product);
187 
189 
190  tag_type ret = kronecker_table->register_op(product);
191  kron_tags[std::make_pair(t1, t2)] = std::make_pair(ret, 1.0);
192 
193  return ret;
194  }
195 }
196 
197 template <class Matrix, class SymmGroup>
199  return kronecker_table->size();
200 }
201 
202 #endif
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
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
void remove_empty_blocks(block_matrix< Matrix, SymmGroup > &op)
Definition: tag_detail.h:55
void op_kron(Index< SymmGroup > const &phys_A, Index< SymmGroup > const &phys_B, block_matrix< Matrix1, SymmGroup > const &A, block_matrix< Matrix1, SymmGroup > const &B, block_matrix< Matrix2, SymmGroup > &C)
tag_type get_num_products() const
Definition: op_handler.hpp:150
tag_type get_num_kron_products() const
Definition: op_handler.hpp:198
OPTable< Matrix, SymmGroup >::tag_type tag_type
Definition: op_handler.h:61
Matrix::value_type value_type
Definition: op_handler.h:65
std::pair< bool, typename Matrix::value_type > equal(block_matrix< Matrix, SymmGroup > const &reference, block_matrix< Matrix, SymmGroup > const &sample)
Definition: tag_detail.h:120
void gemm(block_matrix< Matrix1, SymmGroup > const &A, block_matrix< Matrix2, SymmGroup > const &B, block_matrix< Matrix3, SymmGroup > &C)
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