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-2018 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 {
42 namespace psimrcc {
43 
44 class CCIndex;
45 
49 class CCMatrix {
50  typedef std::vector<std::pair<int, int> > intpairvec;
51  typedef std::vector<double> DoubleVec;
52  typedef std::vector<size_t> Size_tVec;
53  typedef std::vector<bool> BoolVec;
54 
55  public:
57  // Class Constructor and Destructor
59  CCMatrix(std::string& str, CCIndex* left_index, CCIndex* right_index);
60  ~CCMatrix();
61 
63  // Class Interface
65  // Functions for scalars
66  void add_scalar(double val);
67  void set_scalar(double val);
68  double get_scalar();
69 
70  bool is_out_of_core();
71  bool is_out_of_core(int h) const { return (out_of_core[h]); }
72 
73  // Functions to get the properties of a matrix
74  std::string& get_label() { return (label); }
75  std::string& get_index_label() { return (index_label); }
76  size_t get_memory2() const { return (memory2); }
77  size_t get_memorypi2(int h) const { return (memorypi2[h]); }
78  int get_reference() const { return (reference); }
79  bool is_integral() const { return (integral); }
80  bool is_antisymmetric() const { return (antisymmetric); }
81  bool is_chemist() const { return (chemist_notation); }
82  bool is_fock() const { return (fock); }
83  int get_symmetry() const { return (symmetry); }
84 
85  // Functions to access the indexing and the matrix elements
86  CCIndex* get_left() const { return (left); }
87  CCIndex* get_right() const { return (right); }
88  size_t get_left_pairpi(int h) const { return (left_pairpi[h]); }
89  size_t get_right_pairpi(int h) const { return (right_pairpi[h]); }
90  size_t get_block_sizepi(int h) const { return (block_sizepi[h]); }
91  double** operator[](int h) const { return (matrix[h]); }
92  double*** get_matrix() {
93  naccess++;
94  return (matrix);
95  }
96 
97  // Access the matrix elements
98  double get_two_address_element(short p, short q);
99  void set_two_address_element(short p, short q, double value);
100  void add_two_address_element(short p, short q, double value);
101  double get_four_address_element(short p, short q, short r, short s);
102  void set_four_address_element(short p, short q, short r, short s, double value);
103  void add_four_address_element(short p, short q, short r, short s, double value);
104 
105  void add_six_address_element(short i, short j, short k, short a, short b, short c, double value);
106  void add_six_address_element_abc(short i, short j, short k, size_t abc, double value);
107  void add_six_address_element_ijk(size_t ijk, short a, short b, short c, double value);
108  double get_six_address_element(short i, short j, short k, short a, short b, short c);
109  void add_six_address_element_Pij(short i, short j, short k, short a, short b, short c, double value);
110  void add_six_address_element_Pij_abc(short i, short j, short k, size_t abc, double value);
111  void add_six_address_element_Pik(short i, short j, short k, short a, short b, short c, double value);
112  void add_six_address_element_Pjk(short i, short j, short k, short a, short b, short c, double value);
113  void add_six_address_element_Pjk_abc(short i, short j, short k, size_t abc, double value);
114  void add_six_address_element_Pab(short i, short j, short k, short a, short b, short c, double value);
115  void add_six_address_element_Pab_ijk(size_t ijk, short a, short b, short c, double value);
116  void add_six_address_element_Pbc(short i, short j, short k, short a, short b, short c, double value);
117  void add_six_address_element_Pbc_ijk(size_t ijk, short a, short b, short c, double value);
118  void add_six_address_element_Pij_k(short i, short j, short k, size_t abc, double value);
119  void add_six_address_element_Pijk(short i, short j, short k, short a, short b, short c, double value);
120  void add_six_address_element_Pab_c(size_t ijk, short a, short b, short c, double value);
121  void add_six_address_element_Pij_Pab(short i, short j, short k, short a, short b, short c, double value);
122  void add_six_address_element_Pjk_Pbc(short i, short j, short k, short a, short b, short c, double value);
123  void add_six_address_element_Pij_k_Pa_bc(short i, short j, short k, short a, short b, short c, double value);
124  void add_six_address_element_Pi_jk_Pab_c(short i, short j, short k, short a, short b, short c, double value);
125  void add_six_address_element_Pi_jk_Pa_bc(short i, short j, short k, short a, short b, short c, double value);
126  // Access the MO indices of a matrix element
127  void get_two_indices(short*& pq, int irrep, int i, int j);
128  void get_two_indices_pitzer(short*& pq, int irrep, int i, int j);
129  void get_four_indices(short*& pqrs, int irrep, int i, int j);
130  void get_four_indices_pitzer(short*& pqrs, int irrep, int i, int j);
131 
132  // Matrix operations
133  void add_numerical_factor(double factor);
134  void add_numerical_factor(double factor, int h);
135  void scale(double factor);
136  void scale(double factor, int h);
137  void zero_matrix();
138  void zero_matrix_block(int h);
139  void zero_two_diagonal();
143  void zero_non_external();
144  void element_by_element_product(double factor, CCMatrix* B_Matrix, CCMatrix* C_Matrix, int h);
145  void element_by_element_division(double factor, CCMatrix* B_Matrix, CCMatrix* C_Matrix, int h);
146  void element_by_element_addition(double factor, CCMatrix* B_Matrix, int h);
147  void tensor_product(std::string& reindexing, double factor, CCMatrix* B_Matrix, CCMatrix* C_Matrix);
148  static double dot_product(CCMatrix* B_Matrix, CCMatrix* C_Matrix, int h);
149 
150  // Very Special (VS) Matrix operations
151 
152  // Printing
153  void print();
154  void print_dpdmatrix(int n, std::string out_fname);
155 
156  // Memory
157  bool is_allocated();
158  bool is_block_allocated(int h);
159  void allocate_memory();
160  void allocate_block(int h);
161  void free_memory();
162  void free_block(int h);
163  int get_naccess() { return (naccess); }
164 
165  // IO
166  void load();
167  void load_irrep(int h);
168  void dump_to_disk();
169  void dump_to_disk(int first_irrep, int last_irrep);
170  void dump_block_to_disk(int h);
171  void write_block_to_disk(int h);
172  void read_from_disk();
173  void read_from_disk(int first_irrep, int last_irrep);
174  void read_block_from_disk(int h);
175  size_t read_strip_from_disk(int h, int strip, double* buffer);
176 
177  private:
179  // Class private functions
181  std::string compute_index_label();
183  // Class data
185  std::string label; // The matrix label
186  std::string index_label; // The index label
187  int nirreps; // The number of irreps
188  int reference; // The reference zeroth-order wavefunction
189  double*** matrix; // Pointer to the allocated memory
190  // matrix[irrep][left_pair][right_pair]
191  CCIndex* left; // Pointer to the left indexing scheme
192  CCIndex* right; // Pointer to the right indexing scheme
193  int symmetry; // Symmetry of the indices
194  size_t* block_sizepi; // Size of a subblock of matrix per irrep
195  size_t* left_pairpi; // Left indexing tuples per irrep
196  size_t* right_pairpi; // Right indexing tuple per irrep
197  bool integral; // Is this a two electron integral?
198  bool chemist_notation; // Is this a two electron integral in chemist notation?
199  bool antisymmetric; // Is this an antisymmetric two electron integral?
200  bool fock; // Is this a fock matrix?
201  size_t memory2; // Memory required for storage in bytes
202  Size_tVec memorypi2; // Memory required for storage in bytes
203  BoolVec out_of_core; // Is this irrep stored on disk?
204  int naccess; // How many times you have called get_matrix();
205  public:
207 };
208 
209 } // namespace psimrcc
210 } // namespace psi
211 
212 #endif // _psi_src_bin_psimrcc_matrix_h_
void free_memory()
Definition: matrix_memory_and_io.cc:123
void add_four_address_element(short p, short q, short r, short s, double value)
Definition: matrix_addressing.cc:208
void tensor_product(std::string &reindexing, double factor, CCMatrix *B_Matrix, CCMatrix *C_Matrix)
Definition: psimrcc/matrix.cc:241
size_t memory2
Definition: psimrcc/matrix.h:201
bool integral
Definition: psimrcc/matrix.h:197
PsiReturnType psimrcc(SharedWavefunction, Options &)
Definition: psimrcc/main.cc:86
void add_two_address_element(short p, short q, double value)
Definition: matrix_addressing.cc:107
void get_four_indices(short *&pqrs, int irrep, int i, int j)
Definition: matrix_addressing.cc:221
void set_four_address_element(short p, short q, short r, short s, double value)
Definition: matrix_addressing.cc:195
bool is_block_allocated(int h)
Definition: matrix_memory_and_io.cc:84
void print_dpdmatrix(int n, std::string out_fname)
Definition: psimrcc/matrix.cc:295
void element_by_element_division(double factor, CCMatrix *B_Matrix, CCMatrix *C_Matrix, int h)
Definition: psimrcc/matrix.cc:224
Definition: psimrcc/matrix.h:49
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:127
bool is_out_of_core(int h) const
Definition: psimrcc/matrix.h:71
void zero_right_four_diagonal()
Definition: psimrcc/matrix.cc:189
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:468
int symmetry
Definition: psimrcc/matrix.h:193
size_t get_left_pairpi(int h) const
Definition: psimrcc/matrix.h:88
std::string compute_index_label()
Definition: psimrcc/matrix.cc:354
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:307
void element_by_element_product(double factor, CCMatrix *B_Matrix, CCMatrix *C_Matrix, int h)
Definition: psimrcc/matrix.cc:215
void add_numerical_factor(double factor)
Definition: psimrcc/matrix.cc:122
void dump_block_to_disk(int h)
Definition: matrix_memory_and_io.cc:158
int get_reference() const
Definition: psimrcc/matrix.h:78
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:405
void zero_non_doubly_occupied()
Definition: psimrcc/matrix.cc:163
void zero_two_diagonal()
Definition: psimrcc/matrix.cc:152
double get_four_address_element(short p, short q, short r, short s)
Definition: matrix_addressing.cc:178
void set_two_address_element(short p, short q, double value)
Definition: matrix_addressing.cc:87
double get_two_address_element(short p, short q)
Definition: matrix_addressing.cc:64
Definition: index.h:67
Definition: pointgrp.h:104
void dump_to_disk()
Definition: matrix_memory_and_io.cc:145
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:544
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:199
int naccess
Definition: psimrcc/matrix.h:204
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:614
void zero_non_external()
Definition: psimrcc/matrix.cc:176
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:389
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:360
void read_block_from_disk(int h)
Definition: matrix_memory_and_io.cc:261
bool fock
Definition: psimrcc/matrix.h:200
static double dot_product(CCMatrix *B_Matrix, CCMatrix *C_Matrix, int h)
Definition: psimrcc/matrix.cc:283
~CCMatrix()
Definition: psimrcc/matrix.cc:97
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:451
void scale(double factor)
Definition: psimrcc/matrix.cc:133
bool is_integral() const
Definition: psimrcc/matrix.h:79
size_t * left_pairpi
Definition: psimrcc/matrix.h:195
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:345
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:288
static double fraction_of_memory_for_buffer
Definition: psimrcc/matrix.h:206
size_t * right_pairpi
Definition: psimrcc/matrix.h:196
bool is_chemist() const
Definition: psimrcc/matrix.h:81
int get_symmetry() const
Definition: psimrcc/matrix.h:83
void set_scalar(double val)
Definition: psimrcc/matrix.cc:348
CCIndex * get_left() const
Definition: psimrcc/matrix.h:86
int get_naccess()
Definition: psimrcc/matrix.h:163
void allocate_block(int h)
Definition: matrix_memory_and_io.cc:96
BoolVec out_of_core
Definition: psimrcc/matrix.h:203
double ** operator[](int h) const
Definition: psimrcc/matrix.h:91
size_t get_memorypi2(int h) const
Definition: psimrcc/matrix.h:77
size_t read_strip_from_disk(int h, int strip, double *buffer)
Definition: matrix_memory_and_io.cc:301
double get_six_address_element(short i, short j, short k, short a, short b, short c)
Retrieve .
Definition: matrix_addressing.cc:278
bool is_out_of_core()
Definition: matrix_memory_and_io.cc:68
void zero_matrix()
Definition: psimrcc/matrix.cc:144
std::vector< size_t > Size_tVec
Definition: psimrcc/matrix.h:52
CCIndex * right
Definition: psimrcc/matrix.h:192
std::string & get_index_label()
Definition: psimrcc/matrix.h:75
bool is_allocated()
Definition: matrix_memory_and_io.cc:78
CCIndex * get_right() const
Definition: psimrcc/matrix.h:87
std::vector< std::pair< int, int > > intpairvec
Definition: psimrcc/matrix.h:50
std::vector< bool > BoolVec
Definition: psimrcc/matrix.h:53
void print()
Definition: psimrcc/matrix.cc:112
void get_two_indices(short *&pq, int irrep, int i, int j)
Definition: matrix_addressing.cc:120
void get_four_indices_pitzer(short *&pqrs, int irrep, int i, int j)
Definition: matrix_addressing.cc:243
std::string label
Definition: psimrcc/matrix.h:185
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:298
CCIndex * left
Definition: psimrcc/matrix.h:191
std::string & get_label()
Definition: psimrcc/matrix.h:74
int reference
Definition: psimrcc/matrix.h:188
void get_two_indices_pitzer(short *&pq, int irrep, int i, int j)
Definition: matrix_addressing.cc:140
double get_scalar()
Definition: psimrcc/matrix.cc:352
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:517
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:331
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:497
double *** get_matrix()
Definition: psimrcc/matrix.h:92
void allocate_memory()
Definition: matrix_memory_and_io.cc:91
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:579
std::vector< double > DoubleVec
Definition: psimrcc/matrix.h:51
std::string index_label
Definition: psimrcc/matrix.h:186
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:420
void zero_left_four_diagonal()
Definition: psimrcc/matrix.cc:202
size_t get_memory2() const
Definition: psimrcc/matrix.h:76
int nirreps
Definition: psimrcc/matrix.h:187
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:316
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:375
void load_irrep(int h)
Definition: matrix_memory_and_io.cc:236
size_t * block_sizepi
Definition: psimrcc/matrix.h:194
bool chemist_notation
Definition: psimrcc/matrix.h:198
bool is_antisymmetric() const
Definition: psimrcc/matrix.h:80
bool is_fock() const
Definition: psimrcc/matrix.h:82
size_t get_right_pairpi(int h) const
Definition: psimrcc/matrix.h:89
size_t get_block_sizepi(int h) const
Definition: psimrcc/matrix.h:90
void add_scalar(double val)
Definition: psimrcc/matrix.cc:350
Definition: libdpd/dpd.h:290
double *** matrix
Definition: psimrcc/matrix.h:189
void element_by_element_addition(double factor, CCMatrix *B_Matrix, int h)
Definition: psimrcc/matrix.cc:233
void read_from_disk()
Definition: matrix_memory_and_io.cc:247
void zero_matrix_block(int h)
Definition: psimrcc/matrix.cc:148
Size_tVec memorypi2
Definition: psimrcc/matrix.h:202
void write_block_to_disk(int h)
Definition: matrix_memory_and_io.cc:168
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:436
Definition: libdpd/dpd.h:263
void load()
Definition: matrix_memory_and_io.cc:225