ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
symm_handler.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_MODEL_SYMM_HANDLER_H
28 #define APP_ALPS_MODEL_SYMM_HANDLER_H
29 
30 #include <alps/parameter.h>
31 #include <alps/model.h>
32 
34 
35 
36 namespace detail {
37  template <class T>
38  int to_integer (alps::half_integer<T> const & qn_value)
39  {
40  return qn_value.get_twice(); // always works with double QN, so that spin-1/2 and spin-1 are compatible
41  }
42 }
43 
44 template <class SymmGroup>
45 typename SymmGroup::charge state_to_charge(alps::site_state<short> const & state, alps::SiteBasisDescriptor<short> const& b,
46  std::map<std::string, int> const& all_conserved_qn);
47 
48 template <class SymmGroup>
49 typename SymmGroup::charge init_charge(const alps::Parameters& parms, std::map<std::string, int> const& all_conserved_qn);
50 
51 
52 template <class SymmGroup>
54 public:
55  typedef short I;
56  typedef typename SymmGroup::charge charge_t;
57  typedef std::size_t size_t;
58  typedef std::pair<charge_t, size_t> coord_t;
59  typedef std::map<std::string, int> qn_map_type;
60 
61  symmetric_basis_descriptor() : numstates_(0) { }
62 
63  symmetric_basis_descriptor(alps::SiteBasisDescriptor<I> const & b, qn_map_type const& all_conserved_qn)
64  {
65  alps::site_basis<I> states(b);
66 
67  numstates_ = states.size();
68  state_index_.resize(numstates_);
69  state_offset_.resize(numstates_);
70  std::vector<charge_t> state_charge(numstates_);
71 
72  // loop over states and create phys_
73  for (size_t i=0; i<states.size(); ++i) {
74  state_charge[i] = state_to_charge<SymmGroup>(states[i], b, all_conserved_qn);
75 
76  size_t ci = phys_.position(state_charge[i]);
77  if (ci < phys_.size()) phys_[ci].second += 1;
78  else ci = phys_.insert( std::make_pair(state_charge[i], 1) );
79 
80  state_offset_[i] = phys_[ci].second - 1;
81  }
82 
83  // cache mapping state -> phys
84  for (size_t i=0; i<states.size(); ++i)
85  state_index_[i] = phys_.position(state_charge[i]);
86  }
87 
88  size_t size() const { return numstates_; }
89  coord_t coords(size_t i) const { return coord_t(phys_[state_index_[i]].first, state_offset_[i]); }
90  charge_t charge(size_t i) const { return phys_[state_index_[i]].first; }
91  size_t block_size(size_t i) const { return phys_[state_index_[i]].second; }
92  Index<SymmGroup> const& phys_dim() const { return phys_; }
93 
94 private:
95  size_t numstates_;
96  std::vector<size_t> state_index_;
97  std::vector<size_t> state_offset_;
98  Index<SymmGroup> phys_;
99 };
100 
101 
102 
103 #endif
std::pair< charge_t, size_t > coord_t
int to_integer(alps::half_integer< T > const &qn_value)
SymmGroup::charge charge_t
Index< SymmGroup > const & phys_dim() const
SymmGroup::charge init_charge(const alps::Parameters &parms, std::map< std::string, int > const &all_conserved_qn)
coord_t coords(size_t i) const
SymmGroup::charge state_to_charge(alps::site_state< short > const &state, alps::SiteBasisDescriptor< short > const &b, std::map< std::string, int > const &all_conserved_qn)
symmetric_basis_descriptor(alps::SiteBasisDescriptor< I > const &b, qn_map_type const &all_conserved_qn)
include one of the Index class definitions
charge_t charge(size_t i) const
std::map< std::string, int > qn_map_type
size_t block_size(size_t i) const