ergo
VectorHierarchicBase.h
Go to the documentation of this file.
1 /* Ergo, version 3.3, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2013 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) {
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  freeElements(this->elements);
120  this->cap = this->nel;
121  this->elements = allocateElements<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 = allocateElements<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  freeElements(elements);
154  elements = 0;
155  return *this;
156  }
157  if (is_zero() || (n() != vec.n())) {
158  freeElements(elements);
159  elements = allocateElements<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  freeElements(elements);
172  }
173 
174 } /* end namespace mat */
175 #endif
virtual ~VectorHierarchicBase()
Definition: VectorHierarchicBase.h:170
VectorHierarchicBase< Treal, Telement > & operator=(const VectorHierarchicBase< Treal, Telement > &vec)
Definition: VectorHierarchicBase.h:150
const int & nScalars() const
Definition: VectorHierarchicBase.h:53
Telement & operator()(int ind)
Definition: VectorHierarchicBase.h:59
bool is_empty() const
Check if vector is empty Empty is different from zero, a zero matrix contains information about block...
Definition: VectorHierarchicBase.h:87
Describes dimensions of matrix and its blocks on all levels.
Definition: SizesAndBlocks.h:37
bool is_empty() const
Definition: SizesAndBlocks.h:63
void freeElements(float *ptr)
Definition: allocate.cc:40
bool is_zero() const
Definition: VectorHierarchicBase.h:73
void resetRows(SizesAndBlocks const &newRows)
Definition: VectorHierarchicBase.h:75
int const & getNScalars() const
Definition: SizesAndBlocks.h:65
VectorHierarchicBase(SizesAndBlocks const &rowsInp)
Definition: VectorHierarchicBase.h:94
VectorHierarchicBase()
Definition: VectorHierarchicBase.h:91
const Telement & operator()(int ind) const
Definition: VectorHierarchicBase.h:66
Telement * elements
Definition: VectorHierarchicBase.h:106
SizesAndBlocks rows
Definition: VectorHierarchicBase.h:103
Copyright(c) Emanuel Rubensson 2006.
int const & getNBlocks() const
Definition: SizesAndBlocks.h:64
const int & n() const
Definition: VectorHierarchicBase.h:56
Base class for Vector and Vector specialization.
Definition: VectorHierarchicBase.h:49