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