ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
z2.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_Z2_H
28 #define SYMMETRY_Z2_H
29 
30 #include <iostream>
31 
32 #include <boost/functional/hash.hpp>
33 
34 #include <alps/hdf5.hpp>
35 
36 #include <boost/serialization/serialization.hpp>
37 #include <boost/serialization/array.hpp>
38 
39 class Ztwo {
40  public:
41  typedef enum { Plus = 0, Minus = 1 } charge;
42  typedef int subcharge; // used if charge is site-dependent
43 
44  static const charge IdentityCharge = Plus;
45  static const bool finite = true;
46 
47  static inline charge fuse(charge a, charge b)
48  {
49  if (a == b)
50  return Plus;
51  else
52  return Minus;
53  }
54 
55  template<int R>
56  static charge fuse(boost::array<charge, R> v)
57  {
58  // this operation actually could be rearranged into a tree
59  for (int i = 1; i < R; i++)
60  v[0] = fuse(v[0], v[i]);
61  return v[0];
62  }
63 };
64 
65 inline void save(alps::hdf5::archive & ar,
66  std::string const & p,
67  Ztwo::charge const & v,
68  std::vector<std::size_t> size = std::vector<std::size_t>(),
69  std::vector<std::size_t> chunk = std::vector<std::size_t>(),
70  std::vector<std::size_t> offset = std::vector<std::size_t>())
71 {
72  ar[p] << static_cast<int>(v);
73 }
74 
75 inline void load(alps::hdf5::archive & ar,
76  std::string const & p,
77  Ztwo::charge & v,
78  std::vector<std::size_t> size = std::vector<std::size_t>(),
79  std::vector<std::size_t> chunk = std::vector<std::size_t>(),
80  std::vector<std::size_t> offset = std::vector<std::size_t>())
81 {
82  int t;
83  ar[p] >> t;
84  v = (t == 0 ? Ztwo::Plus : Ztwo::Minus);
85 }
86 
87 template <class Archive>
88 inline void serialize(Archive & ar, Ztwo::charge & c, const unsigned int version)
89 {
90  ar & c;
91 }
92 
93 inline Ztwo::charge operator-(Ztwo::charge a) { return a; }
94 
95 inline std::ostream& operator<<(std::ostream& ost, Ztwo::charge c)
96 {
97  if (c == Ztwo::Plus)
98  ost << "Plus";
99  else if (c == Ztwo::Minus)
100  ost << "Minus";
101  else
102  ost << "???";
103  return ost;
104 }
105 inline std::ostream& operator<<(std::ostream& ost, const std::vector<Ztwo::charge> &c)
106 {
107  ost << "[ ";
108  for (std::vector<Ztwo::charge>::const_iterator it = c.begin();
109  it != c.end();
110  it++)
111  ost << ", " << *it;
112  ost << " ]";
113  return ost;
114 }
115 
116 #endif
charge
Definition: z2.h:41
Definition: z2.h:41
static const bool finite
Definition: z2.h:45
std::ostream & operator<<(std::ostream &ost, Ztwo::charge c)
Definition: z2.h:95
void save(alps::hdf5::archive &ar, std::string const &p, Ztwo::charge const &v, std::vector< std::size_t > size=std::vector< std::size_t >(), std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t > offset=std::vector< std::size_t >())
Definition: z2.h:65
int subcharge
Definition: z2.h:42
Definition: z2.h:41
Ztwo::charge operator-(Ztwo::charge a)
Definition: z2.h:93
Definition: z2.h:39
static const charge IdentityCharge
Definition: z2.h:44
static charge fuse(boost::array< charge, R > v)
Definition: z2.h:56
void load(alps::hdf5::archive &ar, std::string const &p, Ztwo::charge &v, std::vector< std::size_t > size=std::vector< std::size_t >(), std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t > offset=std::vector< std::size_t >())
Definition: z2.h:75
static charge fuse(charge a, charge b)
Definition: z2.h:47
void serialize(Archive &ar, Ztwo::charge &c, const unsigned int version)
Definition: z2.h:88