ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
symmetry_factory.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-2012 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 
29 
30 #include <boost/function.hpp>
31 #undef tolower
32 #undef toupper
33 #include <boost/tokenizer.hpp>
34 #include <map>
35 #include <string>
36 
37 #include "utils/io.hpp"
38 
39 std::string guess_alps_symmetry(BaseParameters & parms)
40 {
41  std::map<int, std::string> symm_names;
42  symm_names[0] = "none";
43  symm_names[1] = "u1";
44  symm_names[2] = "2u1";
45 
46  int n=0;
47  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
48  if (parms.defined("CONSERVED_QUANTUMNUMBERS")) {
49  boost::char_separator<char> sep(" ,");
50  std::string qn_string = parms["CONSERVED_QUANTUMNUMBERS"].str();
51  tokenizer qn_tokens(qn_string, sep);
52  for (tokenizer::iterator it=qn_tokens.begin(); it != qn_tokens.end(); it++) {
53  if (parms.defined(*it + "_total"))
54  n += 1;
55  }
56  }
57  return symm_names[n];
58 }
59 
60 namespace dmrg {
61 
62  template <class TR>
63  typename TR::shared_ptr symmetry_factory(DmrgParameters & parms)
64  {
65  typedef typename TR::shared_ptr ptr_type;
66  std::map<std::string, ptr_type> factory_map;
67 
68  maquis::cout << "This binary contains symmetries: ";
69 #ifdef HAVE_NU1
70  factory_map["nu1"] = ptr_type(new typename TR::template F<NU1>::type());
71  maquis::cout << "nu1 ";
72 #endif
73 #ifdef HAVE_TrivialGroup
74  factory_map["none"] = ptr_type(new typename TR::template F<TrivialGroup>::type());
75  maquis::cout << "none ";
76 #endif
77 #ifdef HAVE_U1
78  factory_map["u1"] = ptr_type(new typename TR::template F<U1>::type());
79  maquis::cout << "u1 ";
80 #endif
81 #ifdef HAVE_TwoU1
82  factory_map["2u1"] = ptr_type(new typename TR::template F<TwoU1>::type());
83  maquis::cout << "2u1 ";
84 #endif
85 #ifdef HAVE_TwoU1PG
86  factory_map["2u1pg"] = ptr_type(new typename TR::template F<TwoU1PG>::type());
87  maquis::cout << "2u1pg ";
88 #endif
89 #ifdef HAVE_Ztwo
90  factory_map["Z2"] = ptr_type(new typename TR::template F<Ztwo>::type());
91  maquis::cout << "Z2 ";
92 #endif
93  maquis::cout << std::endl;
94 
95 
96  std::string symm_name;
97  if (!parms.is_set("symmetry")) {
98 #ifdef HAVE_NU1
99  symm_name = "nu1";
100 #else
101  if (parms["model_library"] == "alps")
102  symm_name = guess_alps_symmetry(parms);
103 #endif
104  } else {
105  symm_name = parms["symmetry"].str();
106  }
107 
108  if (factory_map.find(symm_name) != factory_map.end())
109  return factory_map[symm_name];
110  else
111  throw std::runtime_error("Don't know this symmetry group. Please, check your compilation flags.");
112 #ifdef AMBIENT
113  ambient::sync();
114 #endif
115  return ptr_type();
116  }
117 
118 }
std::string guess_alps_symmetry(BaseParameters &parms)
include all symmetry definitions
bool is_set(std::string const &key) const
TR::shared_ptr symmetry_factory(DmrgParameters &parms)