ergo
VectorHierarchicBase.h
Go to the documentation of this file.
1 /* Ergo, version 3.8, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2019 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
4  * and Anastasia Kruchinina.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Primary academic reference:
20  * Ergo: An open-source program for linear-scaling electronic structure
21  * calculations,
22  * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
23  * Kruchinina,
24  * SoftwareX 7, 107 (2018),
25  * <http://dx.doi.org/10.1016/j.softx.2018.03.005>
26  *
27  * For further information about Ergo, see <http://www.ergoscf.org>.
28  */
29 
40 #ifndef MAT_VECTORHIERARCHICBASE
41 #define MAT_VECTORHIERARCHICBASE
42 #include "matInclude.h"
43 namespace mat{
50  template<class Treal, class Telement = Treal>
52  public:
53 
54 #if 1
55  inline const int& nScalars() const
56  {return rows.getNScalars();}
57 #endif
58  inline const int& n() const /* Number of elements in Telement matrix */
59  {return rows.getNBlocks();}
60 
61  inline Telement& operator() /* Returns the element v(ind) */
62  (int ind) {
63  assert(elements);
64  assert(ind >= 0);
65  assert(ind < n());
66  return elements[ind];
67  }
68  inline const Telement& operator() /*Write protected reference returned*/
69  (int ind) const {
70  assert(elements);
71  assert(ind >= 0);
72  assert(ind < n());
73  return elements[ind];
74  }
75  inline bool is_zero() const {return !elements;}
76 
77  inline void resetRows(SizesAndBlocks const & newRows) {
79  elements = 0;
80  rows = newRows;
81  }
82 
83  protected:
89  inline bool is_empty() const {
90  return rows.is_empty();
91  }
92 
94  : elements(0) {}
95 
96  explicit VectorHierarchicBase(SizesAndBlocks const & rowsInp)
97  :elements(0) {}
103 
104 
106 
107  // const Tperm* perm;
108  Telement* elements;
109  // int cap; /* The length of the elements array */
110  // int nel; /* Number of USED elements in the elements */
111  /* array (can be positive even though content == zero) */
112 
113  // property content; /* content can be one of the properties listed */
114  /* in the enum type property (matInclude.h) for example: */
115  /* zero: An all zero matrix */
116  /* ful : An ordinary matrix with the values in the elements array */
117 
118 #if 0
119  inline void assert_alloc() {
120  if (this->cap < this->nel) {
121  freeElements(this->elements);
122  this->cap = this->nel;
123  this->elements = allocateElements<Telement>(this->cap);
124  for (int ind = 0; ind < this->cap; ind++)
125  this->elements[ind] = 0;
126  }
127  }
128 #endif
129 
130 
131 
132  private:
133 
134  }; /* end class VectorHierarchicBase */
135 
136  template<class Treal, class Telement> /* Copy constructor */
140  : rows(vec.rows) {
141  if (!vec.is_zero()) {
142  elements = allocateElements<Telement>(n());
143  for (int i = 0; i < n(); i++)
144  elements[i] = vec.elements[i];
145  }
146  }
147 
148 
149  template<class Treal, class Telement> /* Assignment operator*/
153  if (vec.is_zero()) { /* Condition also matches empty matrices. */
154  rows = vec.rows;
155  freeElements(elements);
156  elements = 0;
157  return *this;
158  }
159  if (is_zero() || (n() != vec.n())) {
160  freeElements(elements);
161  elements = allocateElements<Telement>(vec.n());
162  }
163  rows = vec.rows;
164  for (int i = 0; i < n(); i++)
165  elements[i] = vec.elements[i];
166  return *this;
167  }
168 
169 
170  template<class Treal, class Telement>
173  freeElements(elements);
174  }
175 
176 } /* end namespace mat */
177 #endif
mat::SizesAndBlocks::is_empty
bool is_empty() const
Definition: SizesAndBlocks.h:71
mat::VectorHierarchicBase::operator=
VectorHierarchicBase< Treal, Telement > & operator=(const VectorHierarchicBase< Treal, Telement > &vec)
Definition: VectorHierarchicBase.h:152
mat::VectorHierarchicBase::n
const int & n() const
Definition: VectorHierarchicBase.h:58
mat::VectorHierarchicBase::operator
const Telement & operator()(int ind) const
Definition: VectorHierarchicBase.h:68
mat::SizesAndBlocks::getNBlocks
int const & getNBlocks() const
Definition: SizesAndBlocks.h:72
mat::VectorHierarchicBase::VectorHierarchicBase
VectorHierarchicBase(SizesAndBlocks const &rowsInp)
Definition: VectorHierarchicBase.h:96
mat::VectorHierarchicBase::VectorHierarchicBase
VectorHierarchicBase(const VectorHierarchicBase< Treal, Telement > &vec)
Definition: VectorHierarchicBase.h:139
mat::VectorHierarchicBase::resetRows
void resetRows(SizesAndBlocks const &newRows)
Definition: VectorHierarchicBase.h:77
mat::VectorHierarchicBase::nScalars
const int & nScalars() const
Definition: VectorHierarchicBase.h:55
rows
mat::SizesAndBlocks rows
Definition: test.cc:51
mat::VectorHierarchicBase::VectorHierarchicBase
VectorHierarchicBase()
Definition: VectorHierarchicBase.h:93
mat::VectorHierarchicBase::is_zero
bool is_zero() const
Definition: VectorHierarchicBase.h:75
mat::VectorHierarchicBase::is_empty
bool is_empty() const
Check if vector is empty Empty is different from zero, a zero matrix contains information about block...
Definition: VectorHierarchicBase.h:89
mat::VectorHierarchicBase::elements
Telement * elements
Definition: VectorHierarchicBase.h:108
mat::VectorHierarchicBase::operator
Telement & operator()(int ind)
Definition: VectorHierarchicBase.h:61
mat
Definition: allocate.cc:39
mat::VectorHierarchicBase::rows
SizesAndBlocks rows
Definition: VectorHierarchicBase.h:105
mat::SizesAndBlocks::getNScalars
int const & getNScalars() const
Definition: SizesAndBlocks.h:73
mat::SizesAndBlocks
Describes dimensions of matrix and its blocks on all levels.
Definition: SizesAndBlocks.h:45
matInclude.h
mat::freeElements
void freeElements(float *ptr)
Definition: allocate.cc:49
mat::VectorHierarchicBase
Base class for Vector and Vector specialization.
Definition: VectorHierarchicBase.h:51
mat::VectorHierarchicBase::~VectorHierarchicBase
virtual ~VectorHierarchicBase()
Definition: VectorHierarchicBase.h:172