CheMPS2
FourIndex.h
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 #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 
44  virtual ~FourIndex();
45 
47  void Clear();
48 
50 
59  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 
62 
71  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);
72 
74 
82  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;
83 
85 
87  int get_irrep_size( const int irrep ) const;
88 
90 
91  void save(const std::string name) const;
92 
94 
95  void read(const std::string name);
96 
97  #ifdef CHEMPS2_MPI_COMPILATION
98 
100  void broadcast( const int ROOT );
101  #endif
102 
103  private:
104 
105  //Contains the group number, the number of irreps, and the multiplication table
106  Irreps SymmInfo;
107 
108  //Array with length the number of irreps of the specified group, containing the number of orbitals of that irrep
109  int * Isizes;
110 
111  /*The following conventions are used for storage:
112  - 8-fold permutation symmetry: V_ijkl = V_jilk = V_ilkj = V_lijk = V_kjil = V_jkli = V_klij = V_lkji
113  - Reorder indices until V_ijkl (I_i x I_j = I_k x I_l --> stored per center symm block):
114  - I_i <= I_j <= I_l and I_i <= I_k
115  - Icenter == Itriv : I_i == I_j and I_k == I_l
116  - Icenter > Itriv : I_i < I_j and I_k != I_l
117  - 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)
118  - Once the order is established based on symmetry sectors, the order within symmetry sectors has to be set too:
119  - Case Icenter == Itrivial :
120  - 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
121  - Vmat[Itriv][I_i][I_i][i + k(k+1)/2]
122  - if i==j --> [j-i][l-k]
123  - if i< j --> [j-i][l-j]
124  - 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
125  - Vmat[Itriv][I_i][I_k][i + nOrbWithIrrepI_i * k]
126  - if i==j --> [j-i][l-k]
127  - if i< j --> [j-i][l]
128  - Case Icenter > Itrivial (I_i < I_j and I_k != I_l) :
129  - If I_i == I_k and hence I_j == I_l : index k>=i and index l>=j
130  - Vmat[Icent][I_i][I_i][i + k*(k+1)/2][j][l-j]
131  - If I_i < I_k and hence I_j < I_l : fixed by block order
132  - Vmat[Icent][I_i][I_k][i + nOrbWithIrrepI_i * k][j][l] */
133  long long ***** storage;
134 
135  //Calculate the number of unique FourIndex elements --> true means allocate the storage and false means deallocate the storage!
136  long long calcNumberOfUniqueElements(const bool allocateStorage);
137 
138  //The number of unique FourIndex elements
139  long long arrayLength;
140 
141  //The actual two-body matrix elements
142  double * theElements;
143 
144  //Functions to get the correct pointer to memory
145  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;
146  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;
147  long long getPtrAllOK1(const int Icent, const int irrep_i, const int irrep_k, const int i, const int j, const int k, const int l) const;
148  long long getPtrAllOK2(const int Icent, const int irrep_i, const int irrep_k, const int i, const int j, const int k, const int l) const;
149  long long getPtrAllOK5(const int Icent, const int irrep_i, const int irrep_k, const int i, const int j, const int k, const int l) const;
150 
151  };
152 }
153 
154 #endif
155 
void save(const std::string name) const
Save the FourIndex object.
Definition: FourIndex.cpp:314
void Clear()
Set all two-body matrix elements to zero.
Definition: FourIndex.cpp:157
Definition: CASPT2.h:42
virtual ~FourIndex()
Destructor.
Definition: FourIndex.cpp:149
int get_irrep_size(const int irrep) const
Get a given irrep size.
Definition: FourIndex.cpp:294
FourIndex(const int nGroup, const int *IrrepSizes)
Constructor.
Definition: FourIndex.cpp:34
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:169
void read(const std::string name)
Load the FourIndex object.
Definition: FourIndex.cpp:372