CheMPS2
TensorGYZ.cpp
1 /*
2  CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry
3  Copyright (C) 2013-2016 Sebastian Wouters
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #include <math.h>
21 
22 #include "TensorGYZ.h"
23 #include "Lapack.h"
24 
25 CheMPS2::TensorGYZ::TensorGYZ(const int boundary_index, const char identity, const SyBookkeeper * denBK) :
26 TensorOperator(boundary_index,
27  0, // two_j
28  0, // n_elec = 0
29  0, // n_irrep = I_trivial = 0
30  true, // TensorGYZ only exists moving left to right
31  true, // prime_last (doesn't matter for spin-0 tensors)
32  false, // No jw_phase when updating (two-orbital mutual information!)
33  denBK,
34  denBK){
35 
36  this->identity = identity;
37 
38 }
39 
41 
43 
44  for (int ikappa=0; ikappa<nKappa; ikappa++){
45 
46  int NL = -1;
47  int IL = -1;
48  int TwoSL = -1;
49  double alpha = 1.0;
50 
51  if (identity=='Y'){
52  NL = sector_nelec_up[ikappa];
53  TwoSL = sector_spin_up[ikappa];
54  IL = sector_irrep_up[ikappa];
55  }
56 
57  if (identity=='Z'){
58  NL = sector_nelec_up[ikappa]-2;
59  TwoSL = sector_spin_up[ikappa];
60  IL = sector_irrep_up[ikappa];
61  }
62 
63  if (identity=='G'){
64  NL = sector_nelec_up[ikappa]-1;
65  TwoSL = sector_spin_up[ikappa]-1;
66  IL = Irreps::directProd( sector_irrep_up[ikappa] , bk_up->gIrrep(index-1) );
67  alpha = sqrt(0.5);
68  }
69 
70  int dimR = bk_up->gCurrentDim(index, sector_nelec_up[ikappa], sector_spin_up[ikappa], sector_irrep_up[ikappa]);
71  int dimL = bk_up->gCurrentDim(index-1, NL, TwoSL, IL);
72 
73  if (dimL>0){
74  double * BlockT = denT->gStorage(NL, TwoSL, IL, sector_nelec_up[ikappa], sector_spin_up[ikappa], sector_irrep_up[ikappa]);
75  char trans = 'T';
76  char notr = 'N';
77  double beta = 0.0;
78  dgemm_(&trans,&notr,&dimR,&dimR,&dimL,&alpha,BlockT,&dimL,BlockT,&dimL,&beta,storage+kappa2index[ikappa],&dimR);
79  } else {
80  for (int cnt=kappa2index[ikappa]; cnt<kappa2index[ikappa+1]; cnt++){ storage[cnt] = 0.0; }
81  }
82 
83  if (identity=='G'){
84  TwoSL = sector_spin_up[ikappa]+1;
85  dimL = bk_up->gCurrentDim(index-1, NL, TwoSL, IL);
86 
87  if (dimL>0){
88  double * BlockT = denT->gStorage(NL, TwoSL, IL, sector_nelec_up[ikappa], sector_spin_up[ikappa], sector_irrep_up[ikappa]);
89  char trans = 'T';
90  char notr = 'N';
91  double beta = 1.0; //ADD NOW!!!
92  dgemm_(&trans,&notr,&dimR,&dimR,&dimL,&alpha,BlockT,&dimL,BlockT,&dimL,&beta,storage+kappa2index[ikappa],&dimR);
93  }
94  }
95 
96  }
97 
98 }
99 
100 
int index
Index of the Tensor object. For TensorT: a site index; for other tensors: a boundary index...
Definition: Tensor.h:75
int * sector_nelec_up
The up particle number sector.
int gCurrentDim(const int boundary, const int N, const int TwoS, const int irrep) const
Get the current virtual dimensions.
TensorGYZ(const int boundary_index, const char identity, const SyBookkeeper *denBK)
Constructor.
Definition: TensorGYZ.cpp:25
void construct(TensorT *denT)
Construct a new TensorGYZ.
Definition: TensorGYZ.cpp:42
int * sector_spin_up
The up spin symmetry sector.
double * gStorage()
Get the pointer to the storage.
Definition: TensorT.cpp:134
static int directProd(const int Irrep1, const int Irrep2)
Get the direct product of the irreps with numbers Irrep1 and Irrep2: a bitwise XOR for psi4&#39;s convent...
Definition: Irreps.h:123
virtual ~TensorGYZ()
Destructor.
Definition: TensorGYZ.cpp:40
int * sector_irrep_up
The up spin symmetry sector.
const SyBookkeeper * bk_up
The bookkeeper of the upper MPS.
int * kappa2index
kappa2index[kappa] indicates the start of tensor block kappa in storage. kappa2index[nKappa] gives th...
Definition: Tensor.h:84
int nKappa
Number of Tensor blocks.
Definition: Tensor.h:81
int gIrrep(const int orbital) const
Get an orbital irrep.
double * storage
The actual variables. Tensor block kappa begins at storage+kappa2index[kappa] and ends at storage+kap...
Definition: Tensor.h:78