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 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{ namespace psimrcc{
37 
39 {
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 private:
57  size_t nrows;
58  size_t ncols;
59  double** matrix;
60 };
61 
62 
64 {
65 public:
66  // Constructor and destructor
67  BlockMatrix(int nirreps, std::vector<size_t>& rows_size_, std::vector<size_t>& cols_size_,int sym);
68  ~BlockMatrix();
69 
70  void print();
71 
72  void add(BlockMatrix* A, double alpha, double beta);
73  void add_acb(double z,BlockMatrix* A, CCIndex* pqr_index,CCIndex* p_index,CCIndex* qr_index,double a);
74  void add_cab(double z,BlockMatrix* A, CCIndex* pqr_index,CCIndex* p_index,CCIndex* qr_index,double a);
75 
76  void add(int h,size_t row,size_t col,double value) {blocks[h]->add(row,col,value);}
77  void set(int h,size_t row,size_t col,double value) {blocks[h]->set(row,col,value);}
78  double get(int h,size_t row,size_t col) {return blocks[h]->get(row,col);}
79  double** get_matrix(int h) {return blocks[h]->get_matrix();}
80  MatrixBase* get_matrixbase(int h) {return blocks[h];}
81  void multiply(BlockMatrix* A, BlockMatrix* B,double alpha, double beta);
82  void contract(BlockMatrix* A, BlockMatrix* B, double alpha, double beta);
83  void cyclical_permutation_1_2(BlockMatrix* A, CCIndex* pqr_index,CCIndex* p_index,CCIndex* qr_index);
84  void a_b_permutation_1_2(BlockMatrix* A, CCIndex* pqr_index,CCIndex* p_index,CCIndex* qr_index);
85  void add_c_ab_permutation_1_2(BlockMatrix* A, CCIndex* pqr_index,CCIndex* p_index,CCIndex* qr_index);
86  void add_permutation_1_2(double z,BlockMatrix* A, CCIndex* pqr_index,CCIndex* p_index,CCIndex* qr_index,
87  double a,double b,double c,double d,double e,double f);
88  void a_b_permutation(CCIndex* pqr_index,CCIndex* p_index,CCIndex* qr_index);
89 // void add_a_b_permutation_1_2(BlockMatrix* A, CCIndex* pqr_index,CCIndex* p_index,CCIndex* qr_index);
90  void zero();
91  double norm();
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 
105 {
106  typedef std::pair<size_t,int> IMIndex;
107  typedef std::map<IMIndex,BlockMatrix*> BMMap;
108 public:
109  // Constructor and destructor
110  IndexMatrix();
111  ~IndexMatrix();
112 
113  void add_block_matrix(size_t index,int ref,BlockMatrix* block_matrix);
114  BlockMatrix* get_block_matrix(size_t index,int ref = 0);
115  void print();
116 private:
118 };
119 
120 void multiply(BlockMatrix* A, BlockMatrix* B);
121 
122 }} /* End Namespaces */
123 
124 #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:213
void add_block_matrix(size_t index, int ref, BlockMatrix *block_matrix)
Definition: special_matrices.cc:453
int nirreps
Definition: special_matrices.h:99
PsiReturnType psimrcc(SharedWavefunction, Options &)
Definition: psimrcc/main.cc:87
double ** get_matrix(int h)
Definition: special_matrices.h:79
double norm()
Definition: special_matrices.cc:77
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:336
BlockMatrix(int nirreps, std::vector< size_t > &rows_size_, std::vector< size_t > &cols_size_, int sym)
Definition: special_matrices.cc:133
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:354
void print()
Definition: special_matrices.cc:65
std::vector< size_t > cols_size
Definition: special_matrices.h:96
Definition: index.h:67
double ** block_matrix(size_t n, size_t m, bool memlock)
Definition: libciomr/block_matrix.cc:78
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:234
void multiply(BlockMatrix *A, BlockMatrix *B, double alpha, double beta)
Definition: special_matrices.cc:224
void set(int h, size_t row, size_t col, double value)
Definition: special_matrices.h:77
IndexMatrix()
Definition: special_matrices.cc:443
void add(size_t row, size_t col, double value)
Definition: special_matrices.h:46
std::map< IMIndex, BlockMatrix * > BMMap
Definition: special_matrices.h:107
void print()
Definition: special_matrices.cc:471
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:105
void zero()
Definition: special_matrices.cc:58
void add(int h, size_t row, size_t col, double value)
Definition: special_matrices.h:76
void add(BlockMatrix *A, double alpha, double beta)
Definition: special_matrices.cc:204
double norm()
Definition: special_matrices.cc:185
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:458
MatrixBase * get_matrixbase(int h)
Definition: special_matrices.h:80
BMMap matrices
Definition: special_matrices.h:117
MatrixBase(size_t nrows_, size_t ncols)
Definition: special_matrices.cc:47
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:300
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:176
void add_c_ab_permutation_1_2(BlockMatrix *A, CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index)
Definition: special_matrices.cc:425
Definition: special_matrices.h:38
~BlockMatrix()
Definition: special_matrices.cc:167
std::pair< size_t, int > IMIndex
Definition: special_matrices.h:106
size_t nrows
Definition: special_matrices.h:57
void zero()
Definition: special_matrices.cc:195
size_t ncols
Definition: special_matrices.h:58
void multiply(MatrixBase *A, MatrixBase *B, double alpha, double beta)
Definition: special_matrices.cc:116
double ** matrix
Definition: special_matrices.h:59
void a_b_permutation_1_2(BlockMatrix *A, CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index)
Definition: special_matrices.cc:257
void a_b_permutation(CCIndex *pqr_index, CCIndex *p_index, CCIndex *qr_index)
Definition: special_matrices.cc:275
Definition: special_matrices.h:104
~IndexMatrix()
Definition: special_matrices.cc:446
~MatrixBase()
Definition: special_matrices.cc:53