ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
placement.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 Alexandr Kosenkov <alex.kosenkov@gmail.com>
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 PLACEMENT_H
28 #define PLACEMENT_H
29 
30 inline void make_consistent(std::vector<int>& p_new, int b2, std::vector<int>& e_new,
31  const std::vector<int>& p_old, int b1, std::vector<int>& e_old)
32 {
33  // exceptions check
34  for(int i = 0; i < e_old.size(); i++) if(b1 == e_old[i]) return;
35  for(int i = 0; i < e_new.size(); i++) if(b2 == e_new[i]) return;
36  // common check
37  for(int i = 0; i < p_new.size(); i++){
38  if(p_new[i] == p_old[b1]){
39  e_old.push_back(b1);
40  for(int ii = i; ii < p_new.size(); ii++)
41  if(p_new[ii] == p_old[b1]) p_new[ii] = -1;
42  return;
43  }
44  }
45  // overlap check
46  if(p_new[b2] != -1){
47  e_new.push_back(b2);
48  p_new[b2] = -1;
49  return;
50  }
51 
52  p_new[b2] = p_old[b1];
53 }
54 
55 inline void make_complete(std::vector<int>& placement){
56  for(int i = 0; i < placement.size(); i++)
57  if(placement[i] == -1){
58  for(int k = 0; k < placement.size(); k++){
59  bool found = false;
60  for(int kk = 0; kk < placement.size(); kk++) if(k == placement[kk]){ found = true; break; }
61  if(found) continue;
62  placement[i] = k;
63  break;
64  }
65  }
66 }
67 
68 template<class Matrix, class SymmGroup>
69 std::vector<int> get_left_placement(const MPOTensor<Matrix, SymmGroup>& mpo, const std::vector<int>& placement_l_old, const std::vector<int>& placement_r){
70  std::vector<int> ts_exceptions_l, ts_exceptions_r;
71  std::vector<int> placement_l(placement_l_old.size(), -1);
72 
73  for(int b1 = 0; b1 < placement_l_old.size(); b1++)
74  for(int b2 = 0; b2 < placement_r.size(); b2++){
75  if(mpo.has(b1,b2)){
76  make_consistent(placement_l, b1, ts_exceptions_l,
77  placement_r, b2, ts_exceptions_r);
78  }
79  }
80  make_complete(placement_l);
81  return placement_l;
82 }
83 
84 template<class Matrix, class SymmGroup>
85 std::vector<int> get_right_placement(const MPOTensor<Matrix, SymmGroup>& mpo, const std::vector<int>& placement_l, const std::vector<int>& placement_r_old){
86  std::vector<int> ts_exceptions_l, ts_exceptions_r;
87  std::vector<int> placement_r(placement_r_old.size(), -1);
88 
89  for(int b1 = 0; b1 < placement_l.size(); b1++)
90  for(int b2 = 0; b2 < placement_r_old.size(); b2++){
91  if(mpo.has(b1,b2)){
92  make_consistent(placement_r, b2, ts_exceptions_r,
93  placement_l, b1, ts_exceptions_l);
94  }
95  }
96  make_complete(placement_r);
97  return placement_r;
98 }
99 
100 template<class Matrix, class SymmGroup>
101 std::vector<std::vector<int> > construct_placements(const MPO<Matrix, SymmGroup>& mpo){
102  std::vector<std::vector<int> > placements(mpo.length()+1);
103  std::vector<std::pair<std::vector<int>, std::vector<int> > > exceptions(mpo.length()+1);
104  placements[0].push_back(0); // left_[0] has only 1 element
105  for(int s = 0; s < mpo.length(); s++){
106  placements[s+1].resize(mpo[s].col_dim(), -1);
107 
108  for(int b1 = 0; b1 < placements[s].size(); b1++)
109  for(int b2 = 0; b2 < placements[s+1].size(); b2++){
110  if(mpo[s].has(b1,b2)){
111  make_consistent(placements[s+1], b2, exceptions[s+1].second, placements[s], b1, exceptions[s].first);
112  }
113  }
114  make_complete(placements[s+1]);
115  mpo[s].placement_l = placements[s];
116  mpo[s].placement_r = placements[s+1];
117  }
118  return placements;
119 }
120 
121 #endif
122 
void make_complete(std::vector< int > &placement)
Definition: placement.h:55
std::vector< std::vector< int > > construct_placements(const MPO< Matrix, SymmGroup > &mpo)
Definition: placement.h:101
std::vector< int > get_right_placement(const MPOTensor< Matrix, SymmGroup > &mpo, const std::vector< int > &placement_l, const std::vector< int > &placement_r_old)
Definition: placement.h:85
Definition: mpo.h:36
void make_consistent(std::vector< int > &p_new, int b2, std::vector< int > &e_new, const std::vector< int > &p_old, int b1, std::vector< int > &e_old)
Definition: placement.h:30
bool has(index_type left_index, index_type right_index) const
Definition: mpotensor.hpp:95
std::vector< int > get_left_placement(const MPOTensor< Matrix, SymmGroup > &mpo, const std::vector< int > &placement_l_old, const std::vector< int > &placement_r)
Definition: placement.h:69