v2DM-DOCI  1.0
FourIndex.h
Go to the documentation of this file.
1 /*
2  CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry
3  Copyright (C) 2013, 2014 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 #ifndef FOURINDEX_CHEMPS2_H
21 #define FOURINDEX_CHEMPS2_H
22 
23 #include "Irreps.h"
24 
25 namespace CheMPS2{
34  class FourIndex{
35 
36  public:
37 
39 
41  FourIndex(const int nGroup, const int * IrrepSizes);
42 
43  FourIndex(const FourIndex &);
44 
46  virtual ~FourIndex();
47 
49 
58  void set(const int irrep_i, const int irrep_j, const int irrep_k, const int irrep_l, const int i, const int j, const int k, const int l, const double val);
60 
69  void add(const int irrep_i, const int irrep_j, const int irrep_k, const int irrep_l, const int i, const int j, const int k, const int l, const double val);
70 
72 
80  double get(const int irrep_i, const int irrep_j, const int irrep_k, const int irrep_l, const int i, const int j, const int k, const int l) const;
81 
83 
84  void save(const std::string name) const;
85 
86  void save2(const std::string name) const;
87 
89 
90  void read(const std::string name);
91 
92  void read2(const std::string name);
93 
95  void reset();
96 
97  private:
98 
99  //Contains the group number, the number of irreps, and the multiplication table
101 
102  //Array with length the number of irreps of the specified group, containing the number of orbitals of that irrep
103  int * Isizes;
104 
105  /*The following conventions are used for storage:
106  - 8-fold permutation symmetry: V_ijkl = V_jilk = V_ilkj = V_lijk = V_kjil = V_jkli = V_klij = V_lkji
107  - Reorder indices until V_ijkl (I_i x I_j = I_k x I_l --> stored per center symm block):
108  - I_i <= I_j <= I_l and I_i <= I_k
109  - Icenter == Itriv : I_i == I_j and I_k == I_l
110  - Icenter > Itriv : I_i < I_j and I_k != I_l
111  - Vmat[Icenter][I_i][I_k] --> only created if ordering of all sectors is ok (I_i <= Icent x I_i ; I_k >= I_i ; Icent x I_k >= I_cent x I_i)
112  - Once the order is established based on symmetry sectors, the order within symmetry sectors has to be set too:
113  - Case Icenter == Itrivial :
114  - If I_i == I_j == I_k == I_l : index (within symm block) i smallest; l>=j>=i and k>=i ; if i==j then l>=k
115  - Vmat[Itriv][I_i][I_i][i + k(k+1)/2]
116  - if i==j --> [j-i][l-k]
117  - if i< j --> [j-i][l-j]
118  - If I_i == I_j < I_k == I_l : index i<=j ; if i<j then k and l fixed ; if i==j then l>=k
119  - Vmat[Itriv][I_i][I_k][i + nOrbWithIrrepI_i * k]
120  - if i==j --> [j-i][l-k]
121  - if i< j --> [j-i][l]
122  - Case Icenter > Itrivial (I_i < I_j and I_k != I_l) :
123  - If I_i == I_k and hence I_j == I_l : index k>=i and index l>=j
124  - Vmat[Icent][I_i][I_i][i + k*(k+1)/2][j][l-j]
125  - If I_i < I_k and hence I_j < I_l : fixed by block order
126  - Vmat[Icent][I_i][I_k][i + nOrbWithIrrepI_i * k][j][l] */
127  long long ***** storage;
128 
129  //Calculate the number of unique FourIndex elements --> true means allocate the storage and false means deallocate the storage!
130  long long calcNumberOfUniqueElements(const bool allocateStorage);
131 
132  //The number of unique FourIndex elements
133  long long arrayLength;
134 
135  //The actual two-body matrix elements
136  double * theElements;
137 
138  //Functions to get the correct pointer to memory
139  long long getPointer(const int irrep_i, const int irrep_j, const int irrep_k, const int irrep_l, const int i, const int j, const int k, const int l) const;
140  long long getPtrIrrepOrderOK(const int irrep_i, const int irrep_j, const int irrep_k, const int irrep_l, const int i, const int j, const int k, const int l) const;
141  long long getPtrAllOK(const int number, const int Icent, const int irrep_i, const int irrep_k, const int i, const int j, const int k, const int l) const;
142 
143  };
144 }
145 
146 #endif
147 
void save(const std::string name) const
Save the FourIndex object.
Definition: FourIndex.cpp:324
long long getPtrIrrepOrderOK(const int irrep_i, const int irrep_j, const int irrep_k, const int irrep_l, const int i, const int j, const int k, const int l) const
Definition: FourIndex.cpp:230
void save2(const std::string name) const
Definition: FourIndex.cpp:383
void read2(const std::string name)
Definition: FourIndex.cpp:504
void reset()
set everything to zero
Definition: FourIndex.cpp:561
long long calcNumberOfUniqueElements(const bool allocateStorage)
Definition: FourIndex.cpp:64
long long getPtrAllOK(const int number, const int Icent, const int irrep_i, const int irrep_k, const int i, const int j, const int k, const int l) const
Definition: FourIndex.cpp:303
virtual ~FourIndex()
Destructor.
Definition: FourIndex.cpp:161
void set(const int irrep_i, const int irrep_j, const int irrep_k, const int irrep_l, const int i, const int j, const int k, const int l, const double val)
Set an element.
Definition: FourIndex.cpp:170
long long arrayLength
Definition: FourIndex.h:133
double * theElements
Definition: FourIndex.h:136
long long getPointer(const int irrep_i, const int irrep_j, const int irrep_k, const int irrep_l, const int i, const int j, const int k, const int l) const
Definition: FourIndex.cpp:188
FourIndex(const int nGroup, const int *IrrepSizes)
Constructor.
Definition: FourIndex.cpp:33
void add(const int irrep_i, const int irrep_j, const int irrep_k, const int irrep_l, const int i, const int j, const int k, const int l, const double val)
Add a double to an element.
Definition: FourIndex.cpp:176
void read(const std::string name)
Load the FourIndex object.
Definition: FourIndex.cpp:445
long long ***** storage
Definition: FourIndex.h:127