Psi4
block_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 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_lib_libmemtrix_block_matrix_h_
29 #define _psi_src_lib_libmemtrix_block_matrix_h_
30 
31 #include "block_vector.h"
32 #include "matrix_base.h"
33 #include <string>
34 
35 typedef std::vector<int> vecint;
36 
37 extern FILE* outfile;
38 
39 namespace psi{ namespace mcscf{
40 
42 {
43 public:
44  BlockMatrix();
45  BlockMatrix(std::string label, int nirreps, size_t*& rows_size, size_t*& cols_size);
46  BlockMatrix(std::string label, int nirreps, int*& rows_size, int*& cols_size);
47  BlockMatrix(std::string label, int nirreps, vecint& rows_size, vecint& cols_size);
48  ~BlockMatrix();
49 
50  // Inlines
51  void set(int h, int i, int j, double value) {matrix_base_[h]->set(i,j,value);}
52  void add(int h, int i, int j, double value) {matrix_base_[h]->add(i,j,value);}
53  double get(int h, int i, int j) {return(matrix_base_[h]->get(i,j));}
54  size_t get_rows(int h) {return(matrix_base_[h]->get_rows());}
55  size_t get_cols(int h) {return(matrix_base_[h]->get_cols());}
56  size_t get_abs_row(int h,int i) {return(rows_offset_[h] + i);}
57  size_t get_abs_col(int h,int i) {return(cols_offset_[h] + i);}
58 
59  // Overloaded operators
61  BlockMatrix& operator+=(const BlockMatrix& rhs);
62  BlockMatrix& operator-=(const BlockMatrix& rhs);
63  friend double dot(BlockMatrix* A,BlockMatrix* B);
64 
65  void print();
66  void zero();
67  void zero_diagonal();
68  void scale(double factor);
69  void transpose();
70 
71  void multiply(bool transpose_A, bool transpose_B, BlockMatrix* A, BlockMatrix* B);
72  void diagonalize(BlockMatrix* eigenvectors, BlockVector* eigenvalues);
73  MatrixBase* getMatrixBase(int h) {return(matrix_base_[h]);}
74 
75 
76  // Reference counting related
77  unsigned int ref () const { return ref_;} // Number of references
78  void add_reference () { ref_++;}
79  bool subtract_reference () { if (--ref_ == 0){ delete this; return true;} return false; }
80  // Reference count
81  unsigned int ref_;
82 
83 private:
84  // Matrix label and pointer
85  std::string label_;
87 
88  // Block sizes etc.
89  size_t* rows_size_;
90  size_t* cols_size_;
91  size_t* rows_offset_;
92  size_t* cols_offset_;
93  int nirreps_;
94 
95  void startup(std::string label, int nirreps, size_t*& rows_size, size_t*& cols_size );
96  void startup(std::string label, int nirreps, int*& rows_size, int*& cols_size);
97  void startup(std::string label, int nirreps, vecint& rows_size, vecint& cols_size);
98  void cleanup();
99 };
100 
101 }}
102 
103 #endif // _psi_src_lib_libmemtrix_block_matrix_h_
void print()
Definition: mcscf/block_matrix.cc:187
size_t get_rows(int h)
Definition: block_matrix.h:54
void add(int h, int i, int j, double value)
Definition: block_matrix.h:52
size_t get_cols(int h)
Definition: block_matrix.h:55
void startup(std::string label, int nirreps, size_t *&rows_size, size_t *&cols_size)
Definition: mcscf/block_matrix.cc:70
size_t get_abs_row(int h, int i)
Definition: block_matrix.h:56
void add_reference()
Definition: block_matrix.h:78
Definition: pointgrp.h:105
void set(size_t i, size_t j, double value)
Definition: matrix_base.h:49
std::vector< int > vecint
Definition: block_matrix.h:35
unsigned int ref() const
Definition: block_matrix.h:77
SharedWavefunction mcscf(SharedWavefunction, Options &)
Definition: mcscf.cc:72
void transpose()
Definition: mcscf/block_matrix.cc:203
Definition: block_vector.h:41
BlockMatrix & operator=(BlockMatrix &rhs)
Definition: mcscf/block_matrix.cc:231
void zero_diagonal()
Definition: mcscf/block_matrix.cc:181
Definition: block_matrix.h:41
~BlockMatrix()
Definition: mcscf/block_matrix.cc:65
MatrixBase ** matrix_base_
Definition: block_matrix.h:86
void set(int h, int i, int j, double value)
Definition: block_matrix.h:51
void cleanup()
Definition: mcscf/block_matrix.cc:160
void add(size_t i, size_t j, double value)
Definition: matrix_base.h:50
bool subtract_reference()
Definition: block_matrix.h:79
size_t * rows_offset_
Definition: block_matrix.h:91
size_t * rows_size_
Definition: block_matrix.h:89
size_t get_abs_col(int h, int i)
Definition: block_matrix.h:57
void zero()
Definition: mcscf/block_matrix.cc:175
Definition: matrix_base.h:38
BlockMatrix & operator+=(const BlockMatrix &rhs)
Definition: mcscf/block_matrix.cc:247
friend double dot(BlockMatrix *A, BlockMatrix *B)
Definition: mcscf/block_matrix.cc:223
void diagonalize(BlockMatrix *eigenvectors, BlockVector *eigenvalues)
Definition: mcscf/block_matrix.cc:216
std::shared_ptr< PsiOutStream > outfile
Definition: core.cc:99
std::string label_
Definition: block_matrix.h:85
BlockMatrix & operator-=(const BlockMatrix &rhs)
Definition: mcscf/block_matrix.cc:253
Definition: PsiFileImpl.h:38
int nirreps_
Definition: block_matrix.h:93
unsigned int ref_
Definition: block_matrix.h:81
size_t * cols_size_
Definition: block_matrix.h:90
void multiply(bool transpose_A, bool transpose_B, BlockMatrix *A, BlockMatrix *B)
Definition: mcscf/block_matrix.cc:209
BlockMatrix()
Definition: mcscf/block_matrix.cc:41
MatrixBase * getMatrixBase(int h)
Definition: block_matrix.h:73
size_t * cols_offset_
Definition: block_matrix.h:92
void scale(double factor)
Definition: mcscf/block_matrix.cc:197