ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lattice.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  * 2012-2013 by Michele Dolfi <dolfim@phys.ethz.ch>
7  * Sebastian Keller <sebkelle@phys.ethz.ch>
8  *
9  *
10  * This software is part of the ALPS Applications, published under the ALPS
11  * Application License; you can use, redistribute it and/or modify it under
12  * the terms of the license, either version 1 or (at your option) any later
13  * version.
14  *
15  * You should have received a copy of the ALPS Application License along with
16  * the ALPS Applications; see the file LICENSE.txt. If not, the license is also
17  * available from http://alps.comp-phys.org/.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  * DEALINGS IN THE SOFTWARE.
26  *
27  *****************************************************************************/
28 
29 #ifndef MAQUIS_DMRG_lattice_hpp
30 #define MAQUIS_DMRG_lattice_hpp
31 
32 #include "dmrg/models/lattice.h"
33 
34 #include <sstream>
35 #include <vector>
36 #include <set>
37 #include <boost/lexical_cast.hpp>
38 
40 
41 class ChainLattice : public lattice_impl
42 {
43 public:
45 
46  ChainLattice (BaseParameters & parms, bool pbc_=false)
47  : L(parms["L"])
48  , a(parms["a"])
49  , pbc(pbc_)
50  { }
51 
52  ChainLattice (int L_, bool pbc_=false, double a_=1.)
53  : L(L_)
54  , a(a_)
55  , pbc(pbc_)
56  { }
57 
58  std::vector<pos_t> forward(pos_t i) const
59  {
60  std::vector<pos_t> ret;
61  if (i < L-1)
62  ret.push_back(i+1);
63  if (pbc && i == L-1)
64  ret.push_back(0);
65  return ret;
66  }
67  std::vector<pos_t> all(pos_t i) const
68  {
69  std::vector<pos_t> ret;
70  if (i < L-1)
71  ret.push_back(i+1);
72  if (i > 0)
73  ret.push_back(i-1);
74  if (pbc && i == L-1)
75  ret.push_back(0);
76  if (pbc && i == 0)
77  ret.push_back(L-1);
78  return ret;
79  }
80 
81  boost::any get_prop_(std::string const & property, std::vector<pos_t> const & pos) const
82  {
83  if (property == "label" && pos.size() == 1)
84  return boost::any( site_label(pos[0]) );
85  else if (property == "label" && pos.size() == 2)
86  return boost::any( bond_label(pos[0], pos[1]) );
87  else if (property == "type" && pos.size() == 1)
88  return boost::any( 0 );
89  else if (property == "type" && pos.size() == 2)
90  return boost::any( 0 );
91  else if (property == "x" && pos.size() == 1)
92  return boost::any( a * pos[0] );
93  else if (property == "at_open_boundary" && pos.size() == 1)
94  return boost::any( (!pbc) && (pos[0]==0 || pos[0]==L-1) );
95  else if (property == "at_open_left_boundary" && pos.size() == 1)
96  return boost::any( (!pbc) && pos[0]==0 );
97  else if (property == "at_open_right_boundary" && pos.size() == 1)
98  return boost::any( (!pbc) && pos[0]==L-1 );
99  else if (property == "wraps_pbc" && pos.size() == 2)
100  return boost::any( (pos[0] < pos[1]) );
101  else {
102  std::ostringstream ss;
103  ss << "No property '" << property << "' with " << pos.size() << " points implemented.";
104  throw std::runtime_error(ss.str());
105  return boost::any();
106  }
107  }
108 
109  pos_t size() const
110  {
111  return L;
112  }
113 
115  {
116  return 0;
117  }
118 
119 private:
120 
121  std::string site_label (int i) const
122  {
123  return "( " + boost::lexical_cast<std::string>(a * i) + " )";
124  }
125 
126  std::string bond_label (int i, int j) const
127  {
128  return ( "( " + boost::lexical_cast<std::string>(a * i) + " )"
129  + " -- "
130  + "( " + boost::lexical_cast<std::string>(a * j) + " )");
131  }
132 
133 private:
134  int L;
135  double a;
136  bool pbc;
137 
138 };
139 
140 
142 {
143 public:
145  : L_(parms["L"])
146  , W_(parms["W"])
147  , a(parms["a"])
148  { }
149 
150  /*
151  0 4 8 12
152  1 5 9 13
153  2 6 10 14
154  3 7 11 15
155  */
156  std::vector<int> forward(int p) const
157  {
158  std::vector<int> ret;
159  if (p+1 < L_*W_ && (p+1) % W_ != 0)
160  ret.push_back(p+1);
161  if (p+W_ < L_*W_)
162  ret.push_back(p+W_);
163 
164  // maquis::cout << p << " -> ";
165  // std::copy(ret.begin(), ret.end(), std::ostream_iterator<int>(maquis::cout, " "));
166  // maquis::cout << std::endl;
167 
168  return ret;
169  }
170 
171  std::vector<int> all(int p) const
172  {
173  std::vector<int> ret = forward(p);
174  if (p >= 1 && p % W_ != 0)
175  ret.push_back(p-1);
176  if (p >= W_)
177  ret.push_back(p-W_);
178 
179  return ret;
180  }
181 
182  int size() const { return L_*W_; }
183 
185  {
186  return 0;
187  }
188 
189 
190  boost::any get_prop_(std::string const & property, std::vector<pos_t> const & pos) const
191  {
192  if (property == "label" && pos.size() == 1)
193  return boost::any( site_label(pos[0]) );
194  else if (property == "label" && pos.size() == 2)
195  return boost::any( bond_label(pos[0], pos[1]) );
196  else if (property == "type" && pos.size() == 1)
197  return boost::any( 0 );
198  else if (property == "type" && pos.size() == 2)
199  return boost::any( 0 );
200  else if (property == "x" && pos.size() == 1)
201  return boost::any( x(pos[0]) );
202  else if (property == "y" && pos.size() == 1)
203  return boost::any( y(pos[0]) );
204  else if (property == "wraps_pbc" && pos.size() == 2)
205  return boost::any( false );
206  else {
207  std::ostringstream ss;
208  ss << "No property '" << property << "' with " << pos.size() << " points implemented.";
209  throw std::runtime_error(ss.str());
210  return boost::any();
211  }
212  }
213 
214 
215 
216 private:
217 
218  double x (int i) const
219  { return a * int(i/W_); }
220  double y (int i) const
221  { return a * (i%W_); }
222 
223  std::string site_label (int i) const
224  {
225  return "( " + ( boost::lexical_cast<std::string>(x(i))
226  + "," + boost::lexical_cast<std::string>(y(i)) ) + " )";
227  }
228 
229  std::string bond_label (int i, int j) const
230  {
231  return ( "( " + ( boost::lexical_cast<std::string>(x(i))
232  + "," + boost::lexical_cast<std::string>(y(i)) ) + " )"
233  + " -- "
234  + "( " + ( boost::lexical_cast<std::string>(x(j))
235  + "," + boost::lexical_cast<std::string>(y(j)) ) + " )" );
236  }
237 
238 
239  int L_, W_;
240  double a;
241 };
242 
243 #endif
pos_t size() const
Definition: lattice.hpp:109
definition of Lattice base class
std::vector< int > forward(int p) const
Definition: lattice.hpp:156
int pos_t
Definition: lattice.h:41
ChainLattice(BaseParameters &parms, bool pbc_=false)
Definition: lattice.hpp:46
int size() const
Definition: lattice.hpp:182
lattice common base
Definition: lattice.h:39
SquareLattice(BaseParameters &parms)
Definition: lattice.hpp:144
std::vector< pos_t > forward(pos_t i) const
Definition: lattice.hpp:58
std::vector< pos_t > all(pos_t i) const
Definition: lattice.hpp:67
std::vector< int > all(int p) const
Definition: lattice.hpp:171
lattice_impl::pos_t pos_t
Definition: lattice.hpp:44
int maximum_vertex_type() const
Definition: lattice.hpp:114
boost::any get_prop_(std::string const &property, std::vector< pos_t > const &pos) const
Definition: lattice.hpp:81
boost::any get_prop_(std::string const &property, std::vector< pos_t > const &pos) const
Definition: lattice.hpp:190
ChainLattice(int L_, bool pbc_=false, double a_=1.)
Definition: lattice.hpp:52
int maximum_vertex_type() const
Definition: lattice.hpp:184