ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
boundary.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 BOUNDARY_H
28 #define BOUNDARY_H
29 
30 #include "dmrg/utils/storage.h"
33 #include "utils/function_objects.h"
35 
36 #include <iostream>
37 #include <set>
38 
39 template<class Matrix, class SymmGroup>
40 class Boundary : public storage::disk::serializable<Boundary<Matrix, SymmGroup> >
41 {
42 public:
44  typedef typename Matrix::value_type value_type;
45  typedef std::pair<typename SymmGroup::charge, std::size_t> access_type;
46 
47  template<class Archive>
48  void serialize(Archive &ar, const unsigned int version){
49  ar & data_;
50  }
51 
53  Index<SymmGroup> const & ld = Index<SymmGroup>(),
54  std::size_t ad = 1)
55  : data_(ad, block_matrix<Matrix, SymmGroup>(ud, ld))
56  { }
57 
60  data_ = rhs.data_;
61  return *this;
62  }
63 
64  template <class OtherMatrix>
66  {
67  data_.reserve(rhs.aux_dim());
68  for (std::size_t n=0; n<rhs.aux_dim(); ++n)
69  data_.push_back(rhs[n]);
70  }
71 
72  std::size_t aux_dim() const {
73  return data_.size();
74  }
75 
76  void resize(size_t n){
77  if(n < data_.size())
78  return data_.resize(n);
79  data_.reserve(n);
80  for(int i = data_.size(); i < n; ++i)
81  data_.push_back(block_matrix<Matrix, SymmGroup>());
82  }
83 
84  std::vector<scalar_type> traces() const {
85  std::vector<scalar_type> ret; ret.reserve(data_.size());
86  for (size_t k=0; k < data_.size(); ++k) ret.push_back(data_[k].trace());
87  return ret;
88  }
89 
90  bool reasonable() const {
91  for(size_t i = 0; i < data_.size(); ++i)
92  if(!data_[i].reasonable()) return false;
93  return true;
94  }
95 
96  template<class Archive>
97  void load(Archive & ar){
98  std::vector<std::string> children = ar.list_children("data");
99  data_.resize(children.size());
100  semi_parallel_for(/*removed...*/, std::size_t i=0; i<children.size(); ++i){
101  ar["data/"+children[i]] >> data_[alps::cast<std::size_t>(children[i])];
102  }
103  }
104 
105  template<class Archive>
106  void save(Archive & ar) const {
107  ar["data"] << data_;
108  }
109 
110  block_matrix<Matrix, SymmGroup> & operator[](std::size_t k) { return data_[k]; }
111  block_matrix<Matrix, SymmGroup> const & operator[](std::size_t k) const { return data_[k]; }
112  //value_type & operator()(std::size_t i, access_type j, access_type k) { return data_[i](j, k); } // I hope this is never used (30.04.2012 / scalar/value discussion)
113  //value_type const & operator()(std::size_t i, access_type j, access_type k) const { return data_[i](j, k); }
114 private:
115  std::vector<block_matrix<Matrix, SymmGroup> > data_;
116 };
117 
118 
119 template<class Matrix, class SymmGroup>
121 {
122  typedef typename alps::numeric::associated_real_diagonal_matrix<Matrix>::type dmt;
123 
124  for (std::size_t k = 0; k < b.aux_dim(); ++k)
125  {
128 
129  if (b[k].left_basis().sum_of_sizes() == 0)
130  continue;
131 
132  svd_truncate(b[k], U, V, S, 1e-4, 1, false);
133 
134  gemm(U, S, t);
135  gemm(t, V, b[k]);
136  }
137 
138  return b;
139 }
140 
141 template<class Matrix, class SymmGroup>
142 std::size_t size_of(Boundary<Matrix, SymmGroup> const & m)
143 {
144  size_t r = 0;
145  for (size_t i = 0; i < m.aux_dim(); ++i)
146  r += size_of(m[i]);
147  return r;
148 }
149 
150 
151 #endif
Boundary(Index< SymmGroup > const &ud=Index< SymmGroup >(), Index< SymmGroup > const &ld=Index< SymmGroup >(), std::size_t ad=1)
Definition: boundary.h:52
T::value_type type
Definition: traits.hpp:8
std::size_t size_of(Boundary< Matrix, SymmGroup > const &m)
Definition: boundary.h:142
void resize(size_t n)
Definition: boundary.h:76
Boundary< Matrix, SymmGroup > simplify(Boundary< Matrix, SymmGroup > b)
Definition: boundary.h:120
declaration of block_matrix class
block_matrix< Matrix, SymmGroup > & operator[](std::size_t k)
Definition: boundary.h:110
#define semi_parallel_for(constraint,...)
include one of the Index class definitions
truncation_results svd_truncate(block_matrix< Matrix, SymmGroup > const &M, block_matrix< Matrix, SymmGroup > &U, block_matrix< Matrix, SymmGroup > &V, block_matrix< DiagMatrix, SymmGroup > &S, double rel_tol, std::size_t Mmax, bool verbose=true)
bool reasonable() const
Definition: boundary.h:90
Matrix::value_type value_type
Definition: boundary.h:44
maquis::traits::scalar_type< Matrix >::type scalar_type
Definition: boundary.h:43
std::size_t aux_dim() const
Definition: boundary.h:72
std::vector< scalar_type > traces() const
Definition: boundary.h:84
std::pair< typename SymmGroup::charge, std::size_t > access_type
Definition: boundary.h:45
void gemm(block_matrix< Matrix1, SymmGroup > const &A, block_matrix< Matrix2, SymmGroup > const &B, block_matrix< Matrix3, SymmGroup > &C)
Boundary(Boundary< OtherMatrix, SymmGroup > const &rhs)
Definition: boundary.h:65
serializable & operator=(const serializable &rhs)
Definition: storage.h:178
Boundary & operator=(const Boundary &rhs)
Definition: boundary.h:58
void load(Archive &ar)
Definition: boundary.h:97
void serialize(Archive &ar, const unsigned int version)
Definition: boundary.h:48
void save(Archive &ar) const
Definition: boundary.h:106
block_matrix< Matrix, SymmGroup > const & operator[](std::size_t k) const
Definition: boundary.h:111