ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lattice.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-2013 by Bela Bauer <bauerb@phys.ethz.ch>
7  * Michele Dolfi <dolfim@phys.ethz.ch>
8  *
9  * This software is part of the ALPS Applications, published under the ALPS
10  * Application License; you can use, redistribute it and/or modify it under
11  * the terms of the license, either version 1 or (at your option) any later
12  * version.
13  *
14  * You should have received a copy of the ALPS Application License along with
15  * the ALPS Applications; see the file LICENSE.txt. If not, the license is also
16  * available from http://alps.comp-phys.org/.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  *
26  *****************************************************************************/
27 
28 #ifndef LATTICE_H
29 #define LATTICE_H
30 
32 
33 #include <vector>
34 #include <string>
35 #include <boost/shared_ptr.hpp>
36 #include <boost/any.hpp>
37 
38 /// lattice common base
39 class lattice_impl {
40 public:
41  typedef int pos_t;
42 
43  virtual ~lattice_impl() {}
44 
45  virtual std::vector<pos_t> forward(pos_t) const = 0;
46  virtual std::vector<pos_t> all(pos_t) const = 0;
47 
48  // non-virtual!
49  template<class T> T get_prop(std::string property,
50  pos_t site) const
51  {
52  return boost::any_cast<T>(get_prop_(property, std::vector<pos_t>(1, site)));
53  }
54 
55  template<class T> T get_prop(std::string property,
56  pos_t bond1, pos_t bond2) const
57  {
58  std::vector<pos_t> v(2);
59  v[0] = bond1; v[1] = bond2;
60  return boost::any_cast<T>(get_prop_(property, v));
61  }
62 
63  template<class T> T get_prop(std::string property,
64  std::vector<pos_t> const & positions) const
65  {
66  return boost::any_cast<T>(get_prop_(property, positions));
67  }
68 
69  // virtual!
70  virtual boost::any get_prop_(std::string const &, std::vector<pos_t> const &) const = 0;
71 
72  virtual pos_t size() const = 0;
73  virtual int maximum_vertex_type() const = 0;
74 
75 };
76 
77 
78 /// lattice factory
79 boost::shared_ptr<lattice_impl>
81 
82 
83 /// pimpl resolved Lattice
84 class Lattice {
85  typedef lattice_impl impl_type;
86  typedef boost::shared_ptr<lattice_impl> impl_ptr;
87 public:
89 
90  Lattice() { }
91 
93  : impl_(lattice_factory(parms))
94  { }
95 
96  Lattice(impl_ptr impl) : impl_(impl) { }
97 
98  impl_ptr impl() const { return impl_; }
99 
100  std::vector<pos_t> forward(pos_t site) const { return impl_->forward(site); }
101  std::vector<pos_t> all(pos_t site) const { return impl_->all(site); }
102 
103  template<class T> T get_prop(std::string property, pos_t site) const
104  { return impl_->get_prop<T>(property, site); }
105 
106  template<class T> T get_prop(std::string property, pos_t bond1, pos_t bond2) const
107  { return impl_->get_prop<T>(property, bond1, bond2); }
108 
109  template<class T> T get_prop(std::string property, std::vector<pos_t> const & positions) const
110  { return impl_->get_prop<T>(property, positions); }
111 
112  boost::any get_prop_(std::string const & property, std::vector<pos_t> const & positions) const
113  { return impl_->get_prop_(property, positions); }
114 
115  pos_t size() const { return impl_->size(); }
116  int maximum_vertex_type() const { return impl_->maximum_vertex_type(); };
117 
118 
119 private:
120  impl_ptr impl_;
121 };
122 
123 #endif
T get_prop(std::string property, pos_t site) const
Definition: lattice.h:49
virtual std::vector< pos_t > all(pos_t) const =0
boost::shared_ptr< lattice_impl > lattice_factory(BaseParameters &parms)
lattice factory
Lattice()
Definition: lattice.h:90
virtual ~lattice_impl()
Definition: lattice.h:43
Lattice(BaseParameters &parms)
Definition: lattice.h:92
impl_ptr impl() const
Definition: lattice.h:98
int pos_t
Definition: lattice.h:41
boost::any get_prop_(std::string const &property, std::vector< pos_t > const &positions) const
Definition: lattice.h:112
virtual std::vector< pos_t > forward(pos_t) const =0
T get_prop(std::string property, pos_t bond1, pos_t bond2) const
Definition: lattice.h:55
int maximum_vertex_type() const
Definition: lattice.h:116
lattice common base
Definition: lattice.h:39
Lattice(impl_ptr impl)
Definition: lattice.h:96
virtual pos_t size() const =0
T get_prop(std::string property, pos_t site) const
Definition: lattice.h:103
std::vector< pos_t > all(pos_t site) const
Definition: lattice.h:101
virtual boost::any get_prop_(std::string const &, std::vector< pos_t > const &) const =0
impl_type::pos_t pos_t
Definition: lattice.h:88
T get_prop(std::string property, std::vector< pos_t > const &positions) const
Definition: lattice.h:109
std::vector< pos_t > forward(pos_t site) const
Definition: lattice.h:100
T get_prop(std::string property, std::vector< pos_t > const &positions) const
Definition: lattice.h:63
T get_prop(std::string property, pos_t bond1, pos_t bond2) const
Definition: lattice.h:106
pimpl resolved Lattice
Definition: lattice.h:84
virtual int maximum_vertex_type() const =0
pos_t size() const
Definition: lattice.h:115