ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dm_op_kron.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  * 2013-2013 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 MAQUIS_DMRG_DM_OP_KRON_H
28 #define MAQUIS_DMRG_DM_OP_KRON_H
29 
33 
34 template<class Matrix, class SymmGroup>
35 void dm_kron(Index<SymmGroup> const & phys,
39 {
41 
42  Index<SymmGroup> const & left_basis = phys;
43  Index<SymmGroup> const & right_basis = phys;
44 
45  typedef typename SymmGroup::charge charge;
46  boost::function<charge (charge, charge)> phys_fuse = boost::lambda::bind(static_cast<charge(*)(charge, charge)>(SymmGroup::fuse),
47  boost::lambda::_1, -boost::lambda::_2);
48  ProductBasis<SymmGroup> pb_left(left_basis, left_basis, phys_fuse);
49  ProductBasis<SymmGroup> const& pb_right = pb_left;
50 
51  for (int i=0; i<A.n_blocks(); ++i) {
52  for (int j=0; j<B.n_blocks(); ++j) {
53  charge new_left = phys_fuse(A.left_basis()[i].first, B.left_basis()[j].first);
54  charge new_right = phys_fuse(A.right_basis()[i].first, B.right_basis()[j].first);
55 
56  Matrix tmp(pb_left.size(new_left), pb_right.size(new_right), 0);
57 
58  maquis::dmrg::detail::op_kron(tmp, B[j], A[i],
59  pb_left(A.left_basis()[i].first, B.left_basis()[j].first),
60  pb_right(A.right_basis()[i].first, B.right_basis()[j].first),
61  A.left_basis()[i].second, B.left_basis()[j].second,
62  A.right_basis()[i].second, B.right_basis()[j].second);
63 
64  C.match_and_add_block(tmp, new_left, new_right);
65  }
66  }
67 }
68 
69 template<class Matrix, class SymmGroup>
70 void dm_group_kron(Index<SymmGroup> const & phys_psi,
73  block_matrix<Matrix, typename grouped_symmetry<SymmGroup>::type> & C)
74 {
75  typedef typename grouped_symmetry<SymmGroup>::type OutSymm;
77 
78  Index<SymmGroup> const & left_basis = phys_psi;
79  Index<SymmGroup> const & right_basis = phys_psi;
80 
81  typedef typename OutSymm::charge charge;
82  Index<OutSymm> phys_rho = group(phys_psi, adjoin(phys_psi));
83 
84  for (int i=0; i<A.n_blocks(); ++i) {
85  for (int j=0; j<B.n_blocks(); ++j) {
86  charge new_left = group(A.left_basis()[i].first, -B.left_basis()[j].first);
87  charge new_right = group(A.right_basis()[i].first, -B.right_basis()[j].first);
88 
89  Matrix tmp(phys_rho.size_of_block(new_left), phys_rho.size_of_block(new_right), 0);
90 
91  maquis::dmrg::detail::op_kron(tmp, B[j], A[i], 0, 0,
92  A.left_basis()[i].second, B.left_basis()[j].second,
93  A.right_basis()[i].second, B.right_basis()[j].second);
94 
95  C.match_and_add_block(tmp, new_left, new_right);
96  }
97  }
98 }
99 
100 #endif
TrivialGroup::charge group(TrivialGroup::charge c1, TrivialGroup::charge c2)
size_type n_blocks() const
void dm_group_kron(Index< SymmGroup > const &phys_psi, block_matrix< Matrix, SymmGroup > const &A, block_matrix< Matrix, SymmGroup > const &B, block_matrix< Matrix, typename grouped_symmetry< SymmGroup >::type > &C)
Definition: dm_op_kron.h:70
void match_and_add_block(Matrix const &, charge, charge)
declaration of block_matrix class
size_t size(charge pc) const
std::size_t size_of_block(charge c) const
include one of the Index class definitions
block_matrix< Matrix, SymmGroup > adjoin(block_matrix< Matrix, SymmGroup > const &m)
void op_kron(Matrix2 &out, const Matrix1 &in, const Matrix1 &alfa, size_t out_y_offset, size_t out_x_offset, size_t ldim1, size_t ldim2, size_t rdim1, size_t rdim2)
Definition: alps_detail.hpp:65
Index< SymmGroup > const & right_basis() const
void dm_kron(Index< SymmGroup > const &phys, block_matrix< Matrix, SymmGroup > const &A, block_matrix< Matrix, SymmGroup > const &B, block_matrix< Matrix, SymmGroup > &C)
Definition: dm_op_kron.h:35
Index< SymmGroup > const & left_basis() const
T fuse(const A &ind, T d)
Fuse indices n[i] into one p = n[i] d^i.