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