Psi4
special_matrices.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_special_matrices_h_
30 #define _psi_src_bin_psimrcc_special_matrices_h_
31 
32 #include "manybody.h"
33 #include "index.h"
34 #include "index_iterator.h"
35 
36 namespace psi {
37 namespace psimrcc {
38 
39 class MatrixBase {
40  public:
41  // Constructor and destructor
42  MatrixBase(size_t nrows_, size_t ncols);
43  ~MatrixBase();
44  size_t get_nrows() { return nrows; }
45  size_t get_ncols() { return ncols; }
46  void add(size_t row, size_t col, double value) { matrix[row][col] += value; }
47  void set(size_t row, size_t col, double value) { matrix[row][col] = value; }
48  double get(size_t row, size_t col) { return matrix[row][col]; }
49  double** get_matrix() { return matrix; }
50  void zero();
51  void print();
52  void add(MatrixBase* A, double alpha, double beta);
53  void multiply(MatrixBase* A, MatrixBase* B, double alpha, double beta);
54  void contract(MatrixBase* A, MatrixBase* B, double const alpha, double const beta);
55  double norm();
56 
57  private:
58  size_t nrows;
59  size_t ncols;
60  double** matrix;
61 };
62 
63 class BlockMatrix {
64  public:
65  // Constructor and destructor
66  BlockMatrix(int nirreps, std::vector<size_t>& rows_size_, std::vector<size_t>& cols_size_, int sym);
67  ~BlockMatrix();
68 
69  void print();
70 
71  void add(BlockMatrix* A, double alpha, double beta);
72  void add_acb(double z, BlockMatrix* A, CCIndex* pqr_index, CCIndex* p_index, CCIndex* qr_index, double a);
73  void add_cab(double z, BlockMatrix* A, CCIndex* pqr_index, CCIndex* p_index, CCIndex* qr_index, double a);
74 
75  void add(int h, size_t row, size_t col, double value) { blocks[h]->add(row, col, value); }
76  void set(int h, size_t row, size_t col, double value) { blocks[h]->set(row, col, value); }
77  double get(int h, size_t row, size_t col) { return blocks[h]->get(row, col); }
78  double** get_matrix(int h) { return blocks[h]->get_matrix(); }
79  MatrixBase* get_matrixbase(int h) { return blocks[h]; }
80  void multiply(BlockMatrix* A, BlockMatrix* B, double alpha, double beta);
81  void contract(BlockMatrix* A, BlockMatrix* B, double alpha, double beta);
82  void cyclical_permutation_1_2(BlockMatrix* A, CCIndex* pqr_index, CCIndex* p_index, CCIndex* qr_index);
83  void a_b_permutation_1_2(BlockMatrix* A, CCIndex* pqr_index, CCIndex* p_index, CCIndex* qr_index);
84  void add_c_ab_permutation_1_2(BlockMatrix* A, CCIndex* pqr_index, CCIndex* p_index, CCIndex* qr_index);
85  void add_permutation_1_2(double z, BlockMatrix* A, CCIndex* pqr_index, CCIndex* p_index, CCIndex* qr_index,
86  double a, double b, double c, double d, double e, double f);
87  void a_b_permutation(CCIndex* pqr_index, CCIndex* p_index, CCIndex* qr_index);
88  // void add_a_b_permutation_1_2(BlockMatrix* A, CCIndex* pqr_index,CCIndex* p_index,CCIndex* qr_index);
89  void zero();
90  double norm();
91 
92  private:
94  // Block sizes etc.
95  std::vector<size_t> rows_size;
96  std::vector<size_t> cols_size;
97  std::vector<size_t> rows_offset;
98  std::vector<size_t> cols_offset;
99  int nirreps;
100  int sym;
101 };
102 
103 class IndexMatrix {
104  typedef std::pair<size_t, int> IMIndex;
105  typedef std::map<IMIndex, BlockMatrix*> BMMap;
106 
107  public:
108  // Constructor and destructor
109  IndexMatrix();
110  ~IndexMatrix();
111 
112  void add_block_matrix(size_t index, int ref, BlockMatrix* block_matrix);
113  BlockMatrix* get_block_matrix(size_t index, int ref = 0);
114  void print();
115 
116  private:
118 };
119 
120 void multiply(BlockMatrix* A, BlockMatrix* B);
121 
122 } // namespace psimrcc
123 } // namespace psi
124 
125 #endif // _psi_src_bin_psimrcc_special_matrices_h_
std::vector< size_t > rows_offset
Definition: special_matrices.h:97
void multiply(BlockMatrix *A, BlockMatrix *B)
std::vector< size_t > cols_offset
Definition: special_matrices.h:98
void contract(BlockMatrix *A, BlockMatrix *B, double alpha, double beta)
Definition: special_matrices.cc:197
void add_block_matrix(size_t index, int ref, BlockMatrix *block_matrix)
Definition: special_matrices.cc:426
int nirreps
Definition: special_matrices.h:99
PsiReturnType psimrcc(SharedWavefunction, Options &)
Definition: psimrcc/main.cc:86
double ** get_matrix(int h)
Definition: special_matrices.h:78
double norm()
Definition: special_matrices.cc:71
PSI_API double ** block_matrix(size_t n, size_t m, bool memlock)
Definition: libciomr/block_matrix.cc:76
MatrixBase ** blocks
Definition: special_matrices.h:93
void add_acb(double z, BlockMatrix *A, CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index, double a)
Definition: special_matrices.cc:311
BlockMatrix(int nirreps, std::vector< size_t > &rows_size_, std::vector< size_t > &cols_size_, int sym)
Definition: special_matrices.cc:123
This class is used to store n-tuples of MOs indices (p,q,r,..)
double get(size_t row, size_t col)
Definition: special_matrices.h:48
std::vector< size_t > rows_size
Definition: special_matrices.h:95
void add_cab(double z, BlockMatrix *A, CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index, double a)
Definition: special_matrices.cc:329
void print()
Definition: special_matrices.cc:60
std::vector< size_t > cols_size
Definition: special_matrices.h:96
Definition: index.h:67
double ** get_matrix()
Definition: special_matrices.h:49
void cyclical_permutation_1_2(BlockMatrix *A, CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index)
Definition: special_matrices.cc:216
void multiply(BlockMatrix *A, BlockMatrix *B, double alpha, double beta)
Definition: special_matrices.cc:207
void set(int h, size_t row, size_t col, double value)
Definition: special_matrices.h:76
IndexMatrix()
Definition: special_matrices.cc:418
std::pair< size_t, int > IMIndex
Definition: special_matrices.h:104
void add(size_t row, size_t col, double value)
Definition: special_matrices.h:46
void print()
Definition: special_matrices.cc:442
Definition: special_matrices.h:63
size_t get_nrows()
Definition: special_matrices.h:44
void contract(MatrixBase *A, MatrixBase *B, double const alpha, double const beta)
Definition: special_matrices.cc:96
void zero()
Definition: special_matrices.cc:55
void add(int h, size_t row, size_t col, double value)
Definition: special_matrices.h:75
void add(BlockMatrix *A, double alpha, double beta)
Definition: special_matrices.cc:189
std::map< IMIndex, BlockMatrix * > BMMap
Definition: special_matrices.h:105
double norm()
Definition: special_matrices.cc:172
void set(size_t row, size_t col, double value)
Definition: special_matrices.h:47
BlockMatrix * get_block_matrix(size_t index, int ref=0)
Definition: special_matrices.cc:430
MatrixBase * get_matrixbase(int h)
Definition: special_matrices.h:79
BMMap matrices
Definition: special_matrices.h:117
MatrixBase(size_t nrows_, size_t ncols)
Definition: special_matrices.cc:48
int sym
Definition: special_matrices.h:100
void add_permutation_1_2(double z, BlockMatrix *A, CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index, double a, double b, double c, double d, double e, double f)
Definition: special_matrices.cc:278
This class is used to iterate over n-tuples of MOs indices (p,q,r,..)
size_t get_ncols()
Definition: special_matrices.h:45
void print()
Definition: special_matrices.cc:164
void add_c_ab_permutation_1_2(BlockMatrix *A, CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index)
Definition: special_matrices.cc:401
Definition: special_matrices.h:39
~BlockMatrix()
Definition: special_matrices.cc:156
size_t nrows
Definition: special_matrices.h:58
void zero()
Definition: special_matrices.cc:181
size_t ncols
Definition: special_matrices.h:59
void multiply(MatrixBase *A, MatrixBase *B, double alpha, double beta)
Definition: special_matrices.cc:107
double ** matrix
Definition: special_matrices.h:60
void a_b_permutation_1_2(BlockMatrix *A, CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index)
Definition: special_matrices.cc:237
void a_b_permutation(CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index)
Definition: special_matrices.cc:254
Definition: special_matrices.h:103
~IndexMatrix()
Definition: special_matrices.cc:420
~MatrixBase()
Definition: special_matrices.cc:53