ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mpotensor.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 Bela Bauer <bauerb@phys.ethz.ch>
7  * Sebastian Keller <sebkelle@phys.ethz.ch>
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 
29 
30 template<class Matrix, class SymmGroup>
32  index_type rd,
33  prempo_t const & tags,
34  op_table_ptr tbl_)
35 : left_i(ld)
36 , right_i(rd)
37 , col_tags(ld, rd)
38 , operator_table(tbl_)
39 {
40  using namespace boost::tuples;
41  typedef boost::tuple<index_type, index_type, tag_type, value_type> prempo_descriptor;
42  typedef std::vector<prempo_descriptor> converted_prempo_t;
43 
44  row_index.resize(ld);
45 
46  if (tags.size() > 0 && operator_table.get() != NULL) {
47  converted_prempo_t tmp_tags;
48 
49  // copy (due to const &) and convert to index_type
50  for (typename prempo_t::const_iterator it = tags.begin(); it != tags.end(); ++it) {
51  index_type row_i = (left_i == 1) ? 0 : index_type(get<0>(*it));
52  index_type col_i = (right_i == 1) ? 0 : index_type(get<1>(*it));
53  tmp_tags.push_back( prempo_descriptor(row_i, col_i, get<2>(*it), get<3>(*it)) );
54  }
55 
56 
57  std::sort(tmp_tags.begin(), tmp_tags.end(), MPOTensor_detail::col_cmp<prempo_descriptor>());
58 
59  for (typename converted_prempo_t::const_iterator it = tmp_tags.begin(); it != tmp_tags.end(); ++it) {
60  col_tags(get<0>(*it), get<1>(*it)) = std::make_pair(get<2>(*it), get<3>(*it));
61  row_index[get<0>(*it)].insert(get<1>(*it));
62  }
63  }
64  else {
65  // Initialize a private operator table
66  operator_table = op_table_ptr(new OPTable<Matrix, SymmGroup>());
67  }
68 }
69 
70 /*
71 template<class Matrix, class SymmGroup>
72 block_matrix<Matrix, SymmGroup> const & MPOTensor<Matrix, SymmGroup>::operator()(index_type left_index,
73  index_type right_index) const
74 {
75  throw std::runtime_error("operator() doesn't work for MPOTensors anymore!\n");
76  assert( left_index < left_i );
77  assert( right_index < right_i );
78  return (*operator_table)[col_tags(left_index, right_index).first];
79 }
80 
81 
82 template<class Matrix, class SymmGroup>
83 block_matrix<Matrix, SymmGroup> & MPOTensor<Matrix, SymmGroup>::operator()(index_type left_index,
84  index_type right_index)
85 {
86  throw std::runtime_error("operator() doesn't work for MPOTensors anymore!\n");
87  assert( left_index < left_i );
88  assert( right_index < right_i );
89  typename CSCMatrix::value_type const & p = col_tags(left_index, right_index);
90  return (*operator_table)[p.first];
91 }
92 */
93 
94 template<class Matrix, class SymmGroup>
96  index_type right_index) const
97 {
98  assert(left_index < left_i && right_index < right_i);
99  return col_tags.find_element(left_index, right_index) != NULL;
100 }
101 
102 // warning: this method allows to (indirectly) change the op in the table, all tags pointing to it will
103 // get a modified matrix!
104 // better design needed
105 template<class Matrix, class SymmGroup>
107  if (this->has(li, ri)) {
108  col_tags.find_element(li, ri)->second = scale_;
109  (*operator_table)[col_tags.find_element(li, ri)->first] = op;
110  }
111  else {
112  tag_type new_tag = operator_table->register_op(op);
113  col_tags(li, ri) = internal_value_type(new_tag, scale_);
114  row_index[li].insert(ri);
115  }
116 }
117 
118 template<class Matrix, class SymmGroup>
121  assert(this->has(left_index, right_index));
122  typename CSCMatrix::value_type const & p = col_tags(left_index, right_index);
123  return MPOTensor_detail::make_const_term_descriptor((*operator_table)[p.first], p.second);
124 }
125 
126 // warning: this method allows to (indirectly) change the op in the table, all tags pointing to it will
127 // get a modified matrix!
128 // better design needed
129 template<class Matrix, class SymmGroup>
132  if (!this->has(left_index, right_index))
133  this->set(left_index, right_index, op_t(), 1.);
134  typename CSCMatrix::value_type & p = col_tags(left_index, right_index).ref();
135  return MPOTensor_detail::term_descriptor<Matrix, SymmGroup>((*operator_table)[p.first], p.second);
136 }
137 
138 template<class Matrix, class SymmGroup>
140 {
141  return row_proxy(row_index[row_i].begin(), row_index[row_i].end());
142 }
143 
144 template<class Matrix, class SymmGroup>
146 {
147  return col_proxy(col_tags, col_i);
148 }
149 
150 template<class Matrix, class SymmGroup>
153  return col_tags(left_index, right_index).first;
154 }
155 
156 template<class Matrix, class SymmGroup>
158 {
159  for (typename CSCMatrix::iterator2 it2 = col_tags.begin2(); it2 != col_tags.end2(); ++it2)
160  for (typename CSCMatrix::iterator1 it1 = it2.begin(); it1 != it2.end(); ++it1)
161  it1->second *= v;
162 }
163 
164 template<class Matrix, class SymmGroup>
166 {
167  for (typename CSCMatrix::iterator2 it2 = col_tags.begin2(); it2 != col_tags.end2(); ++it2)
168  for (typename CSCMatrix::iterator1 it1 = it2.begin(); it1 != it2.end(); ++it1)
169  it1->second /= v;
170 }
171 
172 template<class Matrix, class SymmGroup>
174 {
175  return operator_table;
176 }
177 
178 template<class Matrix, class SymmGroup>
180 {
181  return left_i;
182 }
183 
184 template<class Matrix, class SymmGroup>
186 {
187  return right_i;
188 }
maquis::traits::scalar_type< Matrix >::type scalar_type
Definition: mpotensor.h:54
void set(index_type li, index_type ri, op_t const &op, value_type scale_=1.0)
Definition: mpotensor.hpp:106
void divide_by_scalar(const scalar_type &)
Definition: mpotensor.hpp:165
index_type row_dim() const
Definition: mpotensor.hpp:179
op_table_ptr get_operator_table() const
Definition: mpotensor.hpp:173
OPTable< Matrix, SymmGroup >::tag_type tag_type
Definition: mpotensor.h:56
tag_type tag_number(index_type left_index, index_type right_index) const
Definition: mpotensor.hpp:152
row_proxy row(index_type row_i) const
Definition: mpotensor.hpp:139
MPOTensor_detail::row_proxy< typename RowIndex::value_type::const_iterator > row_proxy
Definition: mpotensor.h:71
const_term_descriptor< Matrix, SymmGroup > make_const_term_descriptor(block_matrix< Matrix, SymmGroup > const &op_, Scale s_)
MPOTensor_detail::const_term_descriptor< Matrix, SymmGroup > at(index_type left_index, index_type right_index) const
Definition: mpotensor.hpp:120
std::size_t index_type
Definition: mpotensor.h:52
bool has(index_type left_index, index_type right_index) const
Definition: mpotensor.hpp:95
MPOTensor(index_type=1, index_type=1, prempo_t const &=prempo_t(), op_table_ptr=op_table_ptr())
Definition: mpotensor.hpp:31
col_proxy column(index_type col_i) const
Definition: mpotensor.hpp:145
boost::shared_ptr< OPTable< Matrix, SymmGroup > > op_table_ptr
Definition: mpotensor.h:58
functions to reshape the representation of data in MPSTensor
boost::numeric::ublas::matrix_column< const CSCMatrix > col_proxy
Definition: mpotensor.h:72
void multiply_by_scalar(const scalar_type &)
Definition: mpotensor.hpp:157
index_type col_dim() const
Definition: mpotensor.hpp:185
OPTable< Matrix, SymmGroup >::op_t op_t
Definition: mpotensor.h:57
Matrix::value_type value_type
Definition: mpotensor.h:53