ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
block_matrix.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  * 2011-2011 by Bela Bauer <bauerb@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 BLOCK_MATRIX_H
28 #define BLOCK_MATRIX_H
29 
30 #include <sstream>
31 #include <algorithm>
32 #include <numeric>
33 
36 
37 #include "utils/timings.h"
38 #include "utils/traits.hpp"
39 #include "dmrg/utils/storage.h"
40 
41 #include <boost/ptr_container/ptr_vector.hpp>
42 
43 template<class Matrix, class SymmGroup>
45 {
46  friend class block_matrix<typename storage::constrained<Matrix>::type, SymmGroup>;
47 private:
48  typedef typename SymmGroup::charge charge;
49 public:
50  typedef typename Matrix::size_type size_type;
51  typedef typename Matrix::value_type value_type;
52  typedef typename maquis::traits::scalar_type<Matrix>::type scalar_type;
53  typedef typename maquis::traits::real_type<Matrix>::type real_type;
54 
55  block_matrix();
56 
57  block_matrix(Index<SymmGroup> rows,
58  Index<SymmGroup> cols);
59 
60  block_matrix(block_matrix const&);
61 
62  template <class OtherMatrix>
63  block_matrix(block_matrix<OtherMatrix,SymmGroup> const&);
64 
65  block_matrix& operator=(block_matrix rhs);
66  template<class OtherMatrix>
67  block_matrix& operator=(const block_matrix<OtherMatrix, SymmGroup>& rhs);
68 
69  Index<SymmGroup> const & left_basis() const;
70  Index<SymmGroup> const & right_basis() const;
71 
72  void shift_basis(charge diff);
73 
74 // Remove by Tim 06/08/2012, presently not used in any DMRG/TE code
75 // block_matrix(charge rc, charge cc, Matrix& m);
76 
77  std::string description() const;
78  std::size_t num_elements() const;
79 
80  Matrix & operator[](size_type c);
81  Matrix const & operator[](size_type c) const;
82  value_type & operator()(std::pair<charge, size_type> const & r,
83  std::pair<charge, size_type> const & c);
84  value_type const & operator()(std::pair<charge, size_type> const & r,
85  std::pair<charge, size_type> const & c) const;
86  block_matrix & operator+=(block_matrix const & rhs);
87  block_matrix & operator-=(block_matrix const & rhs);
88  block_matrix const & operator*=(const scalar_type& v);
89  block_matrix const & operator/=(const scalar_type& v);
90 
91  size_type n_blocks() const;
92  size_type find_block(charge r, charge c) const;
93  bool has_block(charge r, charge c) const;
94  bool has_block(std::pair<charge, size_type> const & r,
95  std::pair<charge, size_type> const & c) const;
96 
97  size_type insert_block(Matrix const &, charge, charge);
98  size_type insert_block(Matrix *, charge, charge);
99  void remove_block(charge r, charge c);
100  void remove_block(std::size_t which);
101 
102 // Remove by Tim 06/08/2012, presently not used in any DMRG/TE code
103 // void remove_rows_from_block(size_type block, size_type r, size_type k = 1);
104 // void remove_cols_from_block(size_type block, size_type r, size_type k = 1);
105 
106  scalar_type trace() const;
107  real_type norm() const;
108  void transpose_inplace();
109  void conjugate_inplace();
110  void adjoint_inplace();
111  void clear();
112  template<class Generator>
113  void generate(Generator g);
114 
115  void match_and_add_block(Matrix const &, charge, charge);
116 
117  void reserve(charge, charge, std::size_t, std::size_t);
118  inline void reserve_pos(charge, charge, std::size_t, std::size_t);
119  void allocate_blocks();
120 
121  void resize_block(charge r, charge c,
122  size_type new_r, size_type new_c,
123  bool pretend = false);
124 
125  friend void swap(block_matrix & x, block_matrix & y)
126  {
127  swap(x.data_, y.data_);
128  swap(x.rows_, y.rows_);
129  swap(x.cols_, y.cols_);
130  }
131 
132  Matrix const & operator()(charge r, charge c) const
133  {
134  assert( has_block(r, c) );
135  assert( rows_.position(r) == cols_.position(c) );
136  return data_[rows_.position(r)];
137  }
138 
139  Matrix & operator()(charge r, charge c)
140  {
141  assert( has_block(r, c) );
142  assert( rows_.position(r) == cols_.position(c) );
143  return data_[rows_.position(r)];
144  }
145 
146  template<class Archive> void load(Archive & ar);
147  template<class Archive> void save(Archive & ar) const;
148 
149  template <class Archive>
150  inline void serialize(Archive & ar, const unsigned int version);
151 
152  bool reasonable() const;
153 
154 private:
155  Index<SymmGroup> rows_, cols_;
156  boost::ptr_vector<Matrix> data_;
157 };
158 
160 template<class Matrix, class SymmGroup>
163 {
164  bm *= v;
165  return bm;
166 }
167 
168 template<class Matrix, class SymmGroup>
171 {
172  bm *= v;
173  return bm;
174 }
175 
176 template<class Matrix, class SymmGroup>
178 {
179  b1 += b2;
180  return b1;
181 }
182 
183 template<class Matrix, class SymmGroup>
185 {
186  b1 -= b2;
187  return b1;
188 }
189 
190 
191 template<class Matrix, class SymmGroup>
193 {
194  size_t r = 0;
195  for (size_t i = 0; i < m.n_blocks(); ++i)
196  r += size_of(m[i]);
197  return r;
198 }
199 
200 
201 #endif
void conjugate_inplace()
void transpose_inplace()
void load(Archive &ar)
include all symmetry definitions
std::size_t size_of(block_matrix< Matrix, SymmGroup > const &m)
Definition: block_matrix.h:192
size_type n_blocks() const
std::size_t num_elements() const
void match_and_add_block(Matrix const &, charge, charge)
void serialize(Archive &ar, const unsigned int version)
size_type insert_block(Matrix const &, charge, charge)
std::string description() const
void shift_basis(charge diff)
scalar_type trace() const
definition of block_matrix class
void resize_block(charge r, charge c, size_type new_r, size_type new_c, bool pretend=false)
maquis::traits::scalar_type< typename storage::constrained< Matrix >::type >::type scalar_type
Definition: block_matrix.h:52
include one of the Index class definitions
block_matrix< Matrix, SymmGroup > operator-(block_matrix< Matrix, SymmGroup > b1, block_matrix< Matrix, SymmGroup > const &b2)
Definition: block_matrix.h:184
bool reasonable() const
block_matrix< Matrix, SymmGroup > operator+(block_matrix< Matrix, SymmGroup > b1, block_matrix< Matrix, SymmGroup > const &b2)
Definition: block_matrix.h:177
friend void swap(block_matrix &x, block_matrix &y)
Definition: block_matrix.h:125
bool has_block(charge r, charge c) const
block_matrix< Matrix, SymmGroup > operator*(const typename block_matrix< Matrix, SymmGroup >::scalar_type &v, block_matrix< Matrix, SymmGroup > bm)
Definition: block_matrix.h:161
Index< SymmGroup > const & right_basis() const
void generate(Generator g)
void remove_block(charge r, charge c)
void adjoint_inplace()
Matrix & operator()(charge r, charge c)
Definition: block_matrix.h:139
void reserve(charge, charge, std::size_t, std::size_t)
maquis::traits::real_type< typename storage::constrained< Matrix >::type >::type real_type
Definition: block_matrix.h:53
real_type norm() const
void save(Archive &ar) const
Matrix const & operator()(charge r, charge c) const
Definition: block_matrix.h:132
size_type find_block(charge r, charge c) const
void reserve_pos(charge, charge, std::size_t, std::size_t)
void allocate_blocks()
Index< SymmGroup > const & left_basis() const
typename storage::constrained< Matrix >::type::value_type value_type
Definition: block_matrix.h:51
typename storage::constrained< Matrix >::type::size_type size_type
Definition: block_matrix.h:50