Psi4
psimrcc/matrix.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2017 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  *
25  * @END LICENSE
26  */
27 
28 #ifndef _psi_src_bin_psimrcc_matrix_h_
29 #define _psi_src_bin_psimrcc_matrix_h_
30 /***************************************************************************
31  * PSIMRCC : Copyright (C) 2007 by Francesco Evangelista and Andrew Simmonett
32  * frank@ccc.uga.edu andysim@ccc.uga.edu
33  * A multireference coupled cluster code
34  ***************************************************************************/
35 
37 #include <vector>
38 #include <string>
39 
40 namespace psi{ namespace psimrcc{
41 
42 class CCIndex;
43 
47 class CCMatrix{
48  typedef std::vector<std::pair<int,int> > intpairvec;
49  typedef std::vector<double> DoubleVec;
50  typedef std::vector<size_t> Size_tVec;
51  typedef std::vector<bool> BoolVec;
52 public:
54  // Class Constructor and Destructor
56  CCMatrix(std::string& str,CCIndex* left_index,CCIndex* right_index);
57  ~CCMatrix();
58 
60  // Class Interface
62  // Functions for scalars
63  void add_scalar(double val);
64  void set_scalar(double val);
65  double get_scalar();
66 
67  bool is_out_of_core();
68  bool is_out_of_core(int h) const {return(out_of_core[h]);}
69 
70  // Functions to get the properties of a matrix
71  std::string& get_label() {return(label);}
72  std::string& get_index_label() {return(index_label);}
73  size_t get_memory2() const {return(memory2);}
74  size_t get_memorypi2(int h) const {return(memorypi2[h]);}
75  int get_reference() const {return(reference);}
76  bool is_integral() const {return(integral);}
77  bool is_antisymmetric() const {return(antisymmetric);}
78  bool is_chemist() const {return(chemist_notation);}
79  bool is_fock() const {return(fock);}
80  int get_symmetry() const {return(symmetry);}
81 
82  // Functions to access the indexing and the matrix elements
83  CCIndex* get_left() const {return(left);}
84  CCIndex* get_right() const {return(right);}
85  size_t get_left_pairpi(int h) const {return(left_pairpi[h]);}
86  size_t get_right_pairpi(int h) const {return(right_pairpi[h]);}
87  size_t get_block_sizepi(int h) const {return(block_sizepi[h]);}
88  double** operator[](int h) const {return(matrix[h]);}
89  double*** get_matrix() {naccess++;return(matrix);}
90 
91  // Access the matrix elements
92  double get_two_address_element(short p, short q);
93  void set_two_address_element(short p, short q,double value);
94  void add_two_address_element(short p, short q,double value);
95  double get_four_address_element(short p, short q, short r, short s);
96  void set_four_address_element(short p, short q, short r, short s,double value);
97  void add_four_address_element(short p, short q, short r, short s,double value);
98 
99  void add_six_address_element(short i, short j, short k, short a, short b, short c,double value);
100  void add_six_address_element_abc(short i, short j, short k, size_t abc,double value);
101  void add_six_address_element_ijk(size_t ijk, short a, short b, short c,double value);
102  double get_six_address_element(short i, short j, short k, short a, short b, short c);
103  void add_six_address_element_Pij(short i, short j, short k, short a, short b, short c,double value);
104  void add_six_address_element_Pij_abc(short i, short j, short k, size_t abc,double value);
105  void add_six_address_element_Pik(short i, short j, short k, short a, short b, short c,double value);
106  void add_six_address_element_Pjk(short i, short j, short k, short a, short b, short c,double value);
107  void add_six_address_element_Pjk_abc(short i, short j, short k, size_t abc,double value);
108  void add_six_address_element_Pab(short i, short j, short k, short a, short b, short c,double value);
109  void add_six_address_element_Pab_ijk(size_t ijk, short a, short b, short c,double value);
110  void add_six_address_element_Pbc(short i, short j, short k, short a, short b, short c,double value);
111  void add_six_address_element_Pbc_ijk(size_t ijk, short a, short b, short c,double value);
112  void add_six_address_element_Pij_k(short i, short j, short k, size_t abc, double value);
113  void add_six_address_element_Pijk(short i, short j, short k, short a, short b, short c,double value);
114  void add_six_address_element_Pab_c(size_t ijk, short a, short b, short c, double value);
115  void add_six_address_element_Pij_Pab(short i, short j, short k, short a, short b, short c,double value);
116  void add_six_address_element_Pjk_Pbc(short i, short j, short k, short a, short b, short c,double value);
117  void add_six_address_element_Pij_k_Pa_bc(short i, short j, short k, short a, short b, short c,double value);
118  void add_six_address_element_Pi_jk_Pab_c(short i, short j, short k, short a, short b, short c,double value);
119  void add_six_address_element_Pi_jk_Pa_bc(short i, short j, short k, short a, short b, short c,double value);
120  // Access the MO indices of a matrix element
121  void get_two_indices(short*& pq,int irrep, int i, int j);
122  void get_two_indices_pitzer(short*& pq,int irrep, int i, int j);
123  void get_four_indices(short*& pqrs,int irrep, int i, int j);
124  void get_four_indices_pitzer(short*& pqrs,int irrep, int i, int j);
125 
126  // Matrix operations
127  void add_numerical_factor(double factor);
128  void add_numerical_factor(double factor, int h);
129  void scale(double factor);
130  void scale(double factor, int h);
131  void zero_matrix();
132  void zero_matrix_block(int h);
133  void zero_two_diagonal();
137  void zero_non_external();
138  void element_by_element_product(double factor,CCMatrix* B_Matrix,CCMatrix* C_Matrix,int h);
139  void element_by_element_division(double factor,CCMatrix* B_Matrix,CCMatrix* C_Matrix,int h);
140  void element_by_element_addition(double factor,CCMatrix* B_Matrix,int h);
141  void tensor_product(std::string& reindexing,double factor,CCMatrix* B_Matrix,CCMatrix* C_Matrix);
142  static double dot_product(CCMatrix* B_Matrix, CCMatrix* C_Matrix, int h);
143 
144  // Very Special (VS) Matrix operations
145 
146 
147 
148  // Printing
149  void print();
150  void print_dpdmatrix(int n, std::string OutFileRMR);
151 
152  // Memory
153  bool is_allocated();
154  bool is_block_allocated(int h);
155  void allocate_memory();
156  void allocate_block(int h);
157  void free_memory();
158  void free_block(int h);
159  int get_naccess() {return(naccess);}
160 
161  // IO
162  void load();
163  void load_irrep(int h);
164  void dump_to_disk();
165  void dump_to_disk(int first_irrep,int last_irrep);
166  void dump_block_to_disk(int h);
167  void write_block_to_disk(int h);
168  void read_from_disk();
169  void read_from_disk(int first_irrep,int last_irrep);
170  void read_block_from_disk(int h);
171  size_t read_strip_from_disk(int h, int strip, double* buffer);
172 private:
174  // Class private functions
176  std::string compute_index_label();
178  // Class data
180  std::string label; // The matrix label
181  std::string index_label; // The index label
182  int nirreps; // The number of irreps
183  int reference; // The reference zeroth-order wavefunction
184  double*** matrix; // Pointer to the allocated memory
185  // matrix[irrep][left_pair][right_pair]
186  CCIndex* left; // Pointer to the left indexing scheme
187  CCIndex* right; // Pointer to the right indexing scheme
188  int symmetry; // Symmetry of the indices
189  size_t* block_sizepi; // Size of a subblock of matrix per irrep
190  size_t* left_pairpi; // Left indexing tuples per irrep
191  size_t* right_pairpi; // Right indexing tuple per irrep
192  bool integral; // Is this a two electron integral?
193  bool chemist_notation; // Is this a two electron integral in chemist notation?
194  bool antisymmetric; // Is this an antisymmetric two electron integral?
195  bool fock; // Is this a fock matrix?
196  size_t memory2; // Memory required for storage in bytes
197  Size_tVec memorypi2; // Memory required for storage in bytes
198  BoolVec out_of_core; // Is this irrep stored on disk?
199  int naccess; // How many times you have called get_matrix();
200 public:
202 };
203 
204 }} /* End Namespaces */
205 
206 #endif // _psi_src_bin_psimrcc_matrix_h_
void free_memory()
Definition: matrix_memory_and_io.cc:131
void add_four_address_element(short p, short q, short r, short s, double value)
Definition: matrix_addressing.cc:221
void tensor_product(std::string &reindexing, double factor, CCMatrix *B_Matrix, CCMatrix *C_Matrix)
Definition: psimrcc/matrix.cc:272
size_t memory2
Definition: psimrcc/matrix.h:196
bool integral
Definition: psimrcc/matrix.h:192
void print_dpdmatrix(int n, std::string OutFileRMR)
Definition: psimrcc/matrix.cc:333
PsiReturnType psimrcc(SharedWavefunction, Options &)
Definition: psimrcc/main.cc:86
void add_two_address_element(short p, short q, double value)
Definition: matrix_addressing.cc:110
void get_four_indices(short *&pqrs, int irrep, int i, int j)
Definition: matrix_addressing.cc:235
void set_four_address_element(short p, short q, short r, short s, double value)
Definition: matrix_addressing.cc:206
bool is_block_allocated(int h)
Definition: matrix_memory_and_io.cc:89
void element_by_element_division(double factor, CCMatrix *B_Matrix, CCMatrix *C_Matrix, int h)
Definition: psimrcc/matrix.cc:251
Definition: psimrcc/matrix.h:47
CCMatrix(std::string &str, CCIndex *left_index, CCIndex *right_index)
Definition: psimrcc/matrix.cc:49
void free_block(int h)
Definition: matrix_memory_and_io.cc:137
bool is_out_of_core(int h) const
Definition: psimrcc/matrix.h:68
void zero_right_four_diagonal()
Definition: psimrcc/matrix.cc:210
void add_six_address_element_Pijk(short i, short j, short k, short a, short b, short c, double value)
Given a value do .
Definition: matrix_addressing.cc:500
int symmetry
Definition: psimrcc/matrix.h:188
size_t get_left_pairpi(int h) const
Definition: psimrcc/matrix.h:85
void add_six_address_element_ijk(size_t ijk, short a, short b, short c, double value)
Given a value do .
Definition: matrix_addressing.cc:327
void element_by_element_product(double factor, CCMatrix *B_Matrix, CCMatrix *C_Matrix, int h)
Definition: psimrcc/matrix.cc:240
void add_numerical_factor(double factor)
Definition: psimrcc/matrix.cc:123
void dump_block_to_disk(int h)
Definition: matrix_memory_and_io.cc:175
int get_reference() const
Definition: psimrcc/matrix.h:75
void add_six_address_element_Pab_ijk(size_t ijk, short a, short b, short c, double value)
Given a value do .
Definition: matrix_addressing.cc:434
void zero_non_doubly_occupied()
Definition: psimrcc/matrix.cc:178
std::string compute_index_label()
Definition: psimrcc/matrix.cc:404
void zero_two_diagonal()
Definition: psimrcc/matrix.cc:165
double get_four_address_element(short p, short q, short r, short s)
Definition: matrix_addressing.cc:187
void set_two_address_element(short p, short q, double value)
Definition: matrix_addressing.cc:89
double get_two_address_element(short p, short q)
Definition: matrix_addressing.cc:65
Definition: index.h:66
Definition: pointgrp.h:105
void dump_to_disk()
Definition: matrix_memory_and_io.cc:157
void add_six_address_element_Pij_k_Pa_bc(short i, short j, short k, short a, short b, short c, double value)
Given a value do .
Definition: matrix_addressing.cc:577
void add_six_address_element_Pik(short i, short j, short k, short a, short b, short c, double value)
bool antisymmetric
Definition: psimrcc/matrix.h:194
int naccess
Definition: psimrcc/matrix.h:199
void add_six_address_element_Pi_jk_Pa_bc(short i, short j, short k, short a, short b, short c, double value)
Given a value do .
Definition: matrix_addressing.cc:650
void zero_non_external()
Definition: psimrcc/matrix.cc:194
void add_six_address_element_Pab(short i, short j, short k, short a, short b, short c, double value)
Given a value do .
Definition: matrix_addressing.cc:417
void add_six_address_element_Pjk(short i, short j, short k, short a, short b, short c, double value)
Given a value do .
Definition: matrix_addressing.cc:385
void read_block_from_disk(int h)
Definition: matrix_memory_and_io.cc:286
bool fock
Definition: psimrcc/matrix.h:195
static double dot_product(CCMatrix *B_Matrix, CCMatrix *C_Matrix, int h)
Definition: psimrcc/matrix.cc:319
~CCMatrix()
Definition: psimrcc/matrix.cc:93
void add_six_address_element_Pij_k(short i, short j, short k, size_t abc, double value)
Given a value do .
Definition: matrix_addressing.cc:483
void scale(double factor)
Definition: psimrcc/matrix.cc:138
bool is_integral() const
Definition: psimrcc/matrix.h:76
size_t * left_pairpi
Definition: psimrcc/matrix.h:190
void add_six_address_element_Pab_c(size_t ijk, short a, short b, short c, double value)
Given a value do .
Definition: matrix_addressing.cc:368
void add_six_address_element(short i, short j, short k, short a, short b, short c, double value)
Given a value do .
Definition: matrix_addressing.cc:307
static double fraction_of_memory_for_buffer
Definition: psimrcc/matrix.h:201
size_t * right_pairpi
Definition: psimrcc/matrix.h:191
bool is_chemist() const
Definition: psimrcc/matrix.h:78
int get_symmetry() const
Definition: psimrcc/matrix.h:80
void set_scalar(double val)
Definition: psimrcc/matrix.cc:389
CCIndex * get_left() const
Definition: psimrcc/matrix.h:83
int get_naccess()
Definition: psimrcc/matrix.h:159
void allocate_block(int h)
Definition: matrix_memory_and_io.cc:104
BoolVec out_of_core
Definition: psimrcc/matrix.h:198
double ** operator[](int h) const
Definition: psimrcc/matrix.h:88
size_t get_memorypi2(int h) const
Definition: psimrcc/matrix.h:74
size_t read_strip_from_disk(int h, int strip, double *buffer)
Definition: matrix_memory_and_io.cc:326
double get_six_address_element(short i, short j, short k, short a, short b, short c)
Retrieve .
Definition: matrix_addressing.cc:297
bool is_out_of_core()
Definition: matrix_memory_and_io.cc:69
void zero_matrix()
Definition: psimrcc/matrix.cc:153
std::vector< size_t > Size_tVec
Definition: psimrcc/matrix.h:50
CCIndex * right
Definition: psimrcc/matrix.h:187
std::string & get_index_label()
Definition: psimrcc/matrix.h:72
bool is_allocated()
Definition: matrix_memory_and_io.cc:81
CCIndex * get_right() const
Definition: psimrcc/matrix.h:84
std::vector< bool > BoolVec
Definition: psimrcc/matrix.h:51
void print()
Definition: psimrcc/matrix.cc:111
void get_two_indices(short *&pq, int irrep, int i, int j)
Definition: matrix_addressing.cc:124
void get_four_indices_pitzer(short *&pqrs, int irrep, int i, int j)
Definition: matrix_addressing.cc:259
std::string label
Definition: psimrcc/matrix.h:180
void add_six_address_element_abc(short i, short j, short k, size_t abc, double value)
Given a value do .
Definition: matrix_addressing.cc:317
CCIndex * left
Definition: psimrcc/matrix.h:186
std::string & get_label()
Definition: psimrcc/matrix.h:71
int reference
Definition: psimrcc/matrix.h:183
void get_two_indices_pitzer(short *&pq, int irrep, int i, int j)
Definition: matrix_addressing.cc:146
double get_scalar()
Definition: psimrcc/matrix.cc:399
void add_six_address_element_Pjk_Pbc(short i, short j, short k, short a, short b, short c, double value)
Given a value do .
Definition: matrix_addressing.cc:549
void add_six_address_element_Pij_abc(short i, short j, short k, size_t abc, double value)
Given a value do .
Definition: matrix_addressing.cc:353
void add_six_address_element_Pij_Pab(short i, short j, short k, short a, short b, short c, double value)
Given a value do .
Definition: matrix_addressing.cc:529
double *** get_matrix()
Definition: psimrcc/matrix.h:89
void allocate_memory()
Definition: matrix_memory_and_io.cc:97
std::vector< std::pair< int, int > > intpairvec
Definition: psimrcc/matrix.h:48
void add_six_address_element_Pi_jk_Pab_c(short i, short j, short k, short a, short b, short c, double value)
Given a value do .
Definition: matrix_addressing.cc:613
std::vector< double > DoubleVec
Definition: psimrcc/matrix.h:49
std::string index_label
Definition: psimrcc/matrix.h:181
void add_six_address_element_Pbc(short i, short j, short k, short a, short b, short c, double value)
Given a value do .
Definition: matrix_addressing.cc:450
void zero_left_four_diagonal()
Definition: psimrcc/matrix.cc:225
size_t get_memory2() const
Definition: psimrcc/matrix.h:73
int nirreps
Definition: psimrcc/matrix.h:182
void add_six_address_element_Pij(short i, short j, short k, short a, short b, short c, double value)
Given a value do .
Definition: matrix_addressing.cc:337
void add_six_address_element_Pjk_abc(short i, short j, short k, size_t abc, double value)
Given a value do .
Definition: matrix_addressing.cc:402
void load_irrep(int h)
Definition: matrix_memory_and_io.cc:253
size_t * block_sizepi
Definition: psimrcc/matrix.h:189
bool chemist_notation
Definition: psimrcc/matrix.h:193
bool is_antisymmetric() const
Definition: psimrcc/matrix.h:77
bool is_fock() const
Definition: psimrcc/matrix.h:79
size_t get_right_pairpi(int h) const
Definition: psimrcc/matrix.h:86
size_t get_block_sizepi(int h) const
Definition: psimrcc/matrix.h:87
void add_scalar(double val)
Definition: psimrcc/matrix.cc:394
Definition: libdpd/dpd.h:251
double *** matrix
Definition: psimrcc/matrix.h:184
void element_by_element_addition(double factor, CCMatrix *B_Matrix, int h)
Definition: psimrcc/matrix.cc:262
void read_from_disk()
Definition: matrix_memory_and_io.cc:267
void zero_matrix_block(int h)
Definition: psimrcc/matrix.cc:159
Size_tVec memorypi2
Definition: psimrcc/matrix.h:197
void write_block_to_disk(int h)
Definition: matrix_memory_and_io.cc:186
void add_six_address_element_Pbc_ijk(size_t ijk, short a, short b, short c, double value)
Given a value do .
Definition: matrix_addressing.cc:467
Definition: libdpd/dpd.h:245
void load()
Definition: matrix_memory_and_io.cc:239