ergo
VectorHierarchicBase.h
Go to the documentation of this file.
1 /* Ergo, version 3.2, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2012 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Primary academic reference:
19  * Kohn−Sham Density Functional Theory Electronic Structure Calculations
20  * with Linearly Scaling Computational Time and Memory Usage,
21  * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek,
22  * J. Chem. Theory Comput. 7, 340 (2011),
23  * <http://dx.doi.org/10.1021/ct100611z>
24  *
25  * For further information about Ergo, see <http://www.ergoscf.org>.
26  */
27 
38 #ifndef MAT_VECTORHIERARCHICBASE
39 #define MAT_VECTORHIERARCHICBASE
40 #include "matInclude.h"
41 namespace mat{
48  template<class Treal, class Telement = Treal>
50  public:
51 
52 #if 1
53  inline const int& nScalars() const
54  {return rows.getNScalars();}
55 #endif
56  inline const int& n() const /* Number of elements in Telement matrix */
57  {return rows.getNBlocks();}
58 
59  inline Telement& operator() /* Returns the element v(ind) */
60  (int ind) {
61  assert(elements);
62  assert(ind >= 0);
63  assert(ind < n());
64  return elements[ind];
65  }
66  inline const Telement& operator() /*Write protected reference returned*/
67  (int ind) const {
68  assert(elements);
69  assert(ind >= 0);
70  assert(ind < n());
71  return elements[ind];
72  }
73  inline bool is_zero() const {return !elements;}
74 
75  inline void resetRows(SizesAndBlocks const & newRows) {
76  delete[] elements;
77  elements = 0;
78  rows = newRows;
79  }
80 
81  protected:
87  inline bool is_empty() const {
88  return rows.is_empty();
89  }
90 
92  : elements(0) {}
93 
94  explicit VectorHierarchicBase(SizesAndBlocks const & rowsInp)
95  :elements(0) {}
100  virtual ~VectorHierarchicBase();
101 
102 
104 
105  // const Tperm* perm;
106  Telement* elements;
107  // int cap; /* The length of the elements array */
108  // int nel; /* Number of USED elements in the elements */
109  /* array (can be positive even though content == zero) */
110 
111  // property content; /* content can be one of the properties listed */
112  /* in the enum type property (matInclude.h) for example: */
113  /* zero: An all zero matrix */
114  /* ful : An ordinary matrix with the values in the elements array */
115 
116 #if 0
117  inline void assert_alloc() {
118  if (this->cap < this->nel) {
119  delete[] this->elements;
120  this->cap = this->nel;
121  this->elements = new Telement[this->cap];
122  for (int ind = 0; ind < this->cap; ind++)
123  this->elements[ind] = 0;
124  }
125  }
126 #endif
127 
128 
129 
130  private:
131 
132  }; /* end class VectorHierarchicBase */
133 
134  template<class Treal, class Telement> /* Copy constructor */
138  : rows(vec.rows) {
139  if (!vec.is_zero()) {
140  elements = new Telement[n()];
141  for (int i = 0; i < n(); i++)
142  elements[i] = vec.elements[i];
143  }
144  }
145 
146 
147  template<class Treal, class Telement> /* Assignment operator*/
151  if (vec.is_zero()) { /* Condition also matches empty matrices. */
152  rows = vec.rows;
153  delete[] elements;
154  elements = 0;
155  return *this;
156  }
157  if (is_zero() || (n() != vec.n())) {
158  delete[] elements;
159  elements = new Telement[vec.n()];
160  }
161  rows = vec.rows;
162  for (int i = 0; i < n(); i++)
163  elements[i] = vec.elements[i];
164  return *this;
165  }
166 
167 
168  template<class Treal, class Telement>
171  delete[] elements;
172  }
173 
174 } /* end namespace mat */
175 #endif