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-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_special_matrices_h_
29 #define _psi_src_bin_psimrcc_special_matrices_h_
30 
31 #include "manybody.h"
32 #include "index.h"
33 #include "index_iterator.h"
34 
35 namespace psi{ namespace psimrcc{
36 
38 {
39 public:
40  // Constructor and destructor
41  MatrixBase(size_t nrows_,size_t ncols);
42  ~MatrixBase();
43  size_t get_nrows() {return nrows;}
44  size_t get_ncols() {return ncols;}
45  void add(size_t row,size_t col,double value) {matrix[row][col] += value;}
46  void set(size_t row,size_t col,double value) {matrix[row][col] = value;}
47  double get(size_t row,size_t col) {return matrix[row][col];}
48  double** get_matrix() {return matrix;}
49  void zero();
50  void print();
51  void add(MatrixBase* A, double alpha, double beta);
52  void multiply(MatrixBase* A, MatrixBase* B, double alpha, double beta);
53  void contract(MatrixBase* A, MatrixBase* B, double const alpha, double const beta);
54  double norm();
55 private:
56  size_t nrows;
57  size_t ncols;
58  double** matrix;
59 };
60 
61 
63 {
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 private:
93  // Block sizes etc.
94  std::vector<size_t> rows_size;
95  std::vector<size_t> cols_size;
96  std::vector<size_t> rows_offset;
97  std::vector<size_t> cols_offset;
98  int nirreps;
99  int sym;
100 };
101 
102 
104 {
105  typedef std::pair<size_t,int> IMIndex;
106  typedef std::map<IMIndex,BlockMatrix*> BMMap;
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 private:
117 };
118 
119 void multiply(BlockMatrix* A, BlockMatrix* B);
120 
121 }} /* End Namespaces */
122 
123 #endif // _psi_src_bin_psimrcc_special_matrices_h_
std::vector< size_t > rows_offset
Definition: special_matrices.h:96
void multiply(BlockMatrix *A, BlockMatrix *B)
std::vector< size_t > cols_offset
Definition: special_matrices.h:97
void contract(BlockMatrix *A, BlockMatrix *B, double alpha, double beta)
Definition: special_matrices.cc:211
void add_block_matrix(size_t index, int ref, BlockMatrix *block_matrix)
Definition: special_matrices.cc:451
int nirreps
Definition: special_matrices.h:98
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:75
MatrixBase ** blocks
Definition: special_matrices.h:92
void add_acb(double z, BlockMatrix *A, CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index, double a)
Definition: special_matrices.cc:334
BlockMatrix(int nirreps, std::vector< size_t > &rows_size_, std::vector< size_t > &cols_size_, int sym)
Definition: special_matrices.cc:131
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:47
std::vector< size_t > rows_size
Definition: special_matrices.h:94
void add_cab(double z, BlockMatrix *A, CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index, double a)
Definition: special_matrices.cc:352
void print()
Definition: special_matrices.cc:63
std::vector< size_t > cols_size
Definition: special_matrices.h:95
Definition: index.h:66
double ** get_matrix()
Definition: special_matrices.h:48
void cyclical_permutation_1_2(BlockMatrix *A, CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index)
Definition: special_matrices.cc:232
void multiply(BlockMatrix *A, BlockMatrix *B, double alpha, double beta)
Definition: special_matrices.cc:222
void set(int h, size_t row, size_t col, double value)
Definition: special_matrices.h:76
IndexMatrix()
Definition: special_matrices.cc:441
void add(size_t row, size_t col, double value)
Definition: special_matrices.h:45
double ** block_matrix(unsigned long int n, unsigned long int m, bool memlock)
Definition: libciomr/block_matrix.cc:75
std::map< IMIndex, BlockMatrix * > BMMap
Definition: special_matrices.h:106
void print()
Definition: special_matrices.cc:469
Definition: special_matrices.h:62
size_t get_nrows()
Definition: special_matrices.h:43
void contract(MatrixBase *A, MatrixBase *B, double const alpha, double const beta)
Definition: special_matrices.cc:103
void zero()
Definition: special_matrices.cc:56
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:202
double norm()
Definition: special_matrices.cc:183
void set(size_t row, size_t col, double value)
Definition: special_matrices.h:46
BlockMatrix * get_block_matrix(size_t index, int ref=0)
Definition: special_matrices.cc:456
MatrixBase * get_matrixbase(int h)
Definition: special_matrices.h:79
BMMap matrices
Definition: special_matrices.h:116
MatrixBase(size_t nrows_, size_t ncols)
Definition: special_matrices.cc:45
int sym
Definition: special_matrices.h:99
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:298
This class is used to iterate over n-tuples of MOs indices (p,q,r,..)
size_t get_ncols()
Definition: special_matrices.h:44
void print()
Definition: special_matrices.cc:174
void add_c_ab_permutation_1_2(BlockMatrix *A, CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index)
Definition: special_matrices.cc:423
Definition: special_matrices.h:37
~BlockMatrix()
Definition: special_matrices.cc:165
std::pair< size_t, int > IMIndex
Definition: special_matrices.h:105
size_t nrows
Definition: special_matrices.h:56
void zero()
Definition: special_matrices.cc:193
size_t ncols
Definition: special_matrices.h:57
void multiply(MatrixBase *A, MatrixBase *B, double alpha, double beta)
Definition: special_matrices.cc:114
Definition: PsiFileImpl.h:38
double ** matrix
Definition: special_matrices.h:58
void a_b_permutation_1_2(BlockMatrix *A, CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index)
Definition: special_matrices.cc:255
void a_b_permutation(CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index)
Definition: special_matrices.cc:273
Definition: special_matrices.h:103
~IndexMatrix()
Definition: special_matrices.cc:444
~MatrixBase()
Definition: special_matrices.cc:51