Psi4
block_vector.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_lib_libmemtrix_block_vector_h_
30 #define _psi_src_lib_libmemtrix_block_vector_h_
31 
32 #include <string>
33 #include <vector>
34 
35 #include "vector_base.h"
37 
38 typedef std::vector<int> vecint;
39 
40 namespace psi {
41 namespace mcscf {
42 
43 class BlockVector {
44  public:
45  BlockVector();
46  BlockVector(std::string label, int nirreps, size_t*& rows_size);
47  BlockVector(std::string label, int nirreps, int*& rows_size);
48  BlockVector(std::string label, int nirreps, vecint& rows_size);
49  ~BlockVector();
50 
51  void print();
52  void copy(BlockVector& source);
53 
54  // Inlines
55  void set(int h, int i, double value) { vector_base_[h]->set(i, value); }
56  void add(int h, int i, double value) { vector_base_[h]->add(i, value); }
57  double get(int h, int i) { return (vector_base_[h]->get(i)); }
58 
59  VectorBase* getVectorBase(int h) { return (vector_base_[h]); }
60 
61  // Reference counting related
62  size_t ref() const { return ref_; } // Number of references
63  void add_reference() { ref_++; }
65  if (--ref_ == 0) {
66  delete this;
67  return true;
68  }
69  return false;
70  }
71  // Reference count
72  size_t ref_;
73 
74  private:
75  // Vector label and pointer
76  std::string label_;
78 
79  // Block sizes etc.
80  size_t* rows_size_;
81  size_t* rows_offset_;
82  int nirreps_;
83 
84  void startup(std::string label, int nirreps, size_t*& rows_size);
85  void startup(std::string label, int nirreps, int*& rows_size);
86  void startup(std::string label, int nirreps, vecint& rows_size);
87  void cleanup();
88 };
89 
90 } // namespace mcscf
91 } // namespace psi
92 
93 #endif // _psi_src_lib_libmemtrix_block_vector_h_
size_t * rows_offset_
Definition: block_vector.h:81
size_t * rows_size_
Definition: block_vector.h:80
void set(int h, int i, double value)
Definition: block_vector.h:55
int nirreps_
Definition: block_vector.h:82
size_t ref() const
Definition: block_vector.h:62
VectorBase * getVectorBase(int h)
Definition: block_vector.h:59
size_t ref_
Definition: block_vector.h:72
void add_reference()
Definition: block_vector.h:63
BlockVector()
Definition: block_vector.cc:43
Definition: pointgrp.h:104
void print()
Definition: block_vector.cc:124
bool subtract_reference()
Definition: block_vector.h:64
std::vector< int > vecint
Definition: block_matrix.h:36
SharedWavefunction mcscf(SharedWavefunction, Options &)
Definition: mcscf.cc:69
Definition: block_vector.h:43
void copy(BlockVector &source)
Definition: block_vector.cc:131
~BlockVector()
Definition: block_vector.cc:60
void cleanup()
Definition: block_vector.cc:113
void add(int i, double value)
Definition: vector_base.h:47
Definition: vector_base.h:38
void set(int i, double value)
Definition: vector_base.h:46
void startup(std::string label, int nirreps, size_t *&rows_size)
Definition: block_vector.cc:62
void add(int h, int i, double value)
Definition: block_vector.h:56
VectorBase ** vector_base_
Definition: block_vector.h:77
std::string label_
Definition: block_vector.h:76