ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
zq.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 SYMMETRY_ZQ_H
28 #define SYMMETRY_ZQ_H
29 
30 #include <iostream>
31 #include <vector>
32 #include <list>
33 
34 #include <boost/lexical_cast.hpp>
35 #include <boost/functional/hash.hpp>
36 
37 #include <boost/serialization/serialization.hpp>
38 #include <boost/serialization/array.hpp>
39 
40 
41 template<int Q>
42 class ZqCharge
43 {
45  {
46  return ZqCharge<Q>((a.c_+b.c_)%Q);
47  }
48 
49  friend std::ostream& operator<<(std::ostream& os, ZqCharge<Q> c)
50  {
51  os << c.get();
52  return os;
53  }
54 
55  friend bool operator<(ZqCharge<Q> a, ZqCharge<Q> b)
56  {
57  return a.c_ < b.c_;
58  }
59 
60  friend bool operator>(ZqCharge<Q> a, ZqCharge<Q> b)
61  {
62  return a.c_ > b.c_;
63  }
64 
65 public:
66  ZqCharge(unsigned int c = 0) : c_(c) { }
67 
68  bool operator==(ZqCharge<Q> b) const { return c_ == b.c_; }
69  bool operator!=(ZqCharge<Q> b) const { return c_ != b.c_; }
71  {
72  if (c_ == 0)
73  return 0;
74  else
75  return Q-c_;
76  }
77 
78  unsigned int get() { return c_; }
79 
80  template<class Archive> void save(Archive & ar) const { ar["c"] << c_; }
81  template<class Archive> void load(Archive & ar) { ar["c"] >> c_; }
82 
83  template <class Archive>
84  void serialize(Archive & ar, const unsigned int version)
85  {
86  ar & c_;
87  }
88 
89 protected:
90  unsigned int c_;
91 };
92 
93 template<int Q>
94 class Zq
95 {
96 public:
98  typedef int subcharge; // Used if charge is site-dependent
99 
100  static const charge IdentityCharge;
101  static const bool finite = true;
102 
103  static const int q = Q;
104 
105  static charge fuse(charge a, charge b)
106  {
107  return a+b;
108  }
109 
110  template<int R> static charge fuse(const boost::array<charge, R> &v)
111  {
112  charge ret = v[0];
113  for (int i = 1; i < R; i++)
114  ret = fuse(ret, v[i]);
115  return ret;
116  }
117 };
118 
119 template<int Q> const typename Zq<Q>::charge Zq<Q>::IdentityCharge = ZqCharge<Q>(0);
120 
121 #endif
static const int q
Definition: zq.h:103
friend ZqCharge< Q > operator+(ZqCharge< Q > a, ZqCharge< Q > b)
Definition: zq.h:44
static const bool finite
Definition: zq.h:101
static charge fuse(charge a, charge b)
Definition: zq.h:105
int subcharge
Definition: zq.h:98
Definition: zq.h:94
bool operator==(ZqCharge< Q > b) const
Definition: zq.h:68
Definition: zq.h:42
bool operator!=(ZqCharge< Q > b) const
Definition: zq.h:69
unsigned int c_
Definition: zq.h:90
static const charge IdentityCharge
Definition: zq.h:100
ZqCharge(unsigned int c=0)
Definition: zq.h:66
void load(Archive &ar)
Definition: zq.h:81
ZqCharge operator-() const
Definition: zq.h:70
void serialize(Archive &ar, const unsigned int version)
Definition: zq.h:84
ZqCharge< Q > charge
Definition: zq.h:97
static charge fuse(const boost::array< charge, R > &v)
Definition: zq.h:110
void save(Archive &ar) const
Definition: zq.h:80
friend bool operator>(ZqCharge< Q > a, ZqCharge< Q > b)
Definition: zq.h:60