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  * 2011-2011 by Michele Dolfi <dolfim@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 APP_ALPS_LATTICE_H
28 #define APP_ALPS_LATTICE_H
29 
30 #include "dmrg/models/lattice.h"
31 
32 #include <vector>
33 #include <map>
34 #include <algorithm>
35 #include <sstream>
36 
37 #include <alps/parameter.h>
38 #include <alps/lattice.h>
39 
40 
41 class alps_lattice : public lattice_impl
42 {
43 
44 public:
46  typedef alps::graph_helper<> graph_type;
47  typedef graph_type::site_descriptor site_descriptor;
48  typedef graph_type::site_iterator site_iterator;
49 
50  alps_lattice (const alps::Parameters& p)
51  : parms(p)
52  , graph(parms)
53  {
54  // storing lattice informations
55  forward_.resize(size());
56  backward_.resize(size());
57 
58  for (graph_type::bond_iterator it=graph.bonds().first; it!=graph.bonds().second; ++it) {
59  graph_type::size_type s, t;
60  s = graph.vertex_index(graph.source(*it));
61  t = graph.vertex_index(graph.target(*it));
62 
63  forward_[s].push_back(t);
64  backward_[t].push_back(s);
65 
66  bond_index_map[s][t] = graph.edge_index(*it);
67  bond_index_map[t][s] = graph.edge_index(*it);
68  }
69  }
70 
71  std::vector<pos_t> forward(pos_t p) const
72  {
73  return forward_[p];
74  }
75  std::vector<pos_t> all(pos_t p) const
76  {
77  std::vector<pos_t> ret = forward_[p];
78  std::copy(backward_[p].begin(), backward_[p].end(), std::back_inserter(ret));
79  return ret;
80  }
81 
82  pos_t size() const
83  {
84  return graph.num_sites();
85  }
86 
87  int maximum_vertex_type() const
88  {
89  return alps::maximum_vertex_type(graph.graph());
90  }
91 
92  boost::any get_prop_(std::string const & property, std::vector<pos_t> const & pos) const
93  {
94  if (property == "label" && pos.size() == 1)
95  return boost::any( alps::site_label(graph.graph(), graph.site(pos[0])) );
96  else if (property == "label" && pos.size() == 2)
97  return boost::any( alps::bond_label(graph.graph(), graph.bond(bond_index_map[pos[0]][pos[1]])) );
98  else if (property == "type" && pos.size() == 1)
99  return boost::any( static_cast<int>(graph.site_type(graph.site(pos[0]))) );
100  else if (property == "type" && pos.size() == 2)
101  return boost::any( static_cast<int>(graph.bond_type(graph.bond(bond_index_map[pos[0]][pos[1]]))) );
102  else if (property == "wraps_pbc" && pos.size() == 2)
103  return boost::any( static_cast<bool>(boost::get(alps::boundary_crossing_t(),
104  graph.graph(),
105  graph.bond(bond_index_map[pos[0]][pos[1]]))) );
106  else {
107  std::ostringstream ss;
108  ss << "No property '" << property << "' with " << pos.size() << " points implemented.";
109  throw std::runtime_error(ss.str());
110  return boost::any();
111  }
112  }
113 
114  const graph_type& alps_graph() const
115  {
116  return graph;
117  }
118 
119 private:
120  alps::Parameters parms;
121  graph_type graph;
122  std::vector<std::vector<pos_t> > forward_;
123  std::vector<std::vector<pos_t> > backward_;
124  // TODO: find better solution instead of this (operator[] is non-const)
125  mutable std::map<pos_t, std::map<pos_t, pos_t> > bond_index_map;
126 };
127 
128 
129 #endif
definition of Lattice base class
graph_type::site_iterator site_iterator
Definition: lattice.hpp:48
std::vector< pos_t > all(pos_t p) const
Definition: lattice.hpp:75
std::vector< pos_t > forward(pos_t p) const
Definition: lattice.hpp:71
pos_t size() const
Definition: lattice.hpp:82
graph_type::site_descriptor site_descriptor
Definition: lattice.hpp:47
int pos_t
Definition: lattice.h:41
int maximum_vertex_type() const
Definition: lattice.hpp:87
alps::graph_helper graph_type
Definition: lattice.hpp:46
lattice common base
Definition: lattice.h:39
const graph_type & alps_graph() const
Definition: lattice.hpp:114
boost::any get_prop_(std::string const &property, std::vector< pos_t > const &pos) const
Definition: lattice.hpp:92
alps_lattice(const alps::Parameters &p)
Definition: lattice.hpp:50
lattice_impl::pos_t pos_t
Definition: lattice.hpp:45