10#if defined(PETSC_D) || defined(PETSC_Z)
19 template <
typename _Type>
21 typedef typename std::map< std::size_t, _Type >::const_iterator citer;
22 typedef typename std::map< std::size_t, _Type >::iterator iter;
67 void resize(
const std::size_t& length);
74 void erase(
const iter& pos);
78 void erase(
const std::size_t& index);
83 void swap(
const std::size_t& i,
const std::size_t& j);
90 std::size_t
size()
const;
93 std::size_t
nelts()
const;
98 _Type&
set(
const std::size_t& i);
104 const _Type&
get(
const std::size_t& i)
const;
107 const _Type&
operator[](
const std::size_t& i)
const;
151 citer
find(std::size_t i)
const {
153 pos = MAP_VEC.find(i);
202#if defined(PETSC_D) || defined(PETSC_Z)
204 void get_petsc( PetscScalar* storage, PetscInt* cols );
229 std::map< std::size_t, _Type > MAP_VEC;
231 std::size_t MAX_SIZE;
239 template <
typename _Type>
241 return MAP_VEC.begin();
244 template <
typename _Type>
246 return MAP_VEC.begin();
249 template <
typename _Type>
251 return MAP_VEC.end();
254 template <
typename _Type>
256 return MAP_VEC.end();
259 template <
typename _Type>
264 problem =
" The SparseVector.operator[] method is trying to access \n";
265 problem +=
" outside the container. \n";
272 template <
typename _Type>
277 problem =
" The SparseVector.operator[] method is trying to access \n";
278 problem +=
" outside the container. \n";
285 template <
typename _Type>
290 problem =
" The SparseVector.set method is trying to access \n";
291 problem +=
" outside the container. \n";
298 template <
typename _Type>
303 problem =
" The SparseVector.get method is trying to access \n";
304 problem +=
" outside the container. \n";
309 pos = MAP_VEC.find(i);
310 if(pos != MAP_VEC.end()) {
311 return pos -> second;
317 template <
typename _Type>
322 template <
typename _Type>
324 return MAP_VEC.size();
327 template <
typename _Type>
329 MAP_VEC.erase(index);
332 template <
typename _Type>
337 template <
typename _Type>
340 if(X.
size() != size()) {
342 problem =
" The SparseVector.swap method is trying to use \n";
343 problem +=
" two vectors of unequal length \n";
347 MAP_VEC.swap(X.MAP_VEC);
350 template <
typename _Type>
The collection of CppNoddy exceptions.
An exception class to be thrown when a container of incorrect geometry used in any class/method.
An exception to indicate that a CppNoddy container has been accessed with index/indices outside the m...
An SparseVector class – a sparse vector object.
citer find(std::size_t i) const
Look for an element index.
void sub(const SparseVector< _Type > &X)
Subtract a vector, element wise.
iter end()
Not a full iterator implementation – just a pass through to the storage container.
double inf_norm() const
Infinity norm.
void scale(const _Type &scale)
Scale each element of the vector.
void resize(const std::size_t &length)
Resize the maximum length of the sparse vector.
SparseVector< _Type > & operator*=(const _Type &m)
Overloading *= for scalar multiplication.
const _Type & operator[](const std::size_t &i) const
Equivalent to the 'get' method.
void dump() const
Output the sparse vector's contents.
void erase(const iter &pos)
Erase an element from the vector.
std::size_t nelts() const
Find the number of non-zero elements in the vector.
double two_norm() const
l2-norm.
_Type & set(const std::size_t &i)
Set an element of the vector.
iter begin()
Not a full iterator implementation – just a pass through to the storage container.
std::size_t size() const
Find the (max) size of the vector.
const _Type dot(const SparseVector< _Type > &x) const
A dot product.
void swap(const std::size_t &i, const std::size_t &j)
Swap elements i and j.
void add(const SparseVector< _Type > &X)
Add a vector, element wise.
SparseVector< _Type > & operator-=(const SparseVector< _Type > &X)
Overloading -= for sparse vectors.
SparseVector< _Type > operator*(const _Type &m) const
Overloading multiplication for a scalar.
SparseVector< _Type > & operator+=(const SparseVector< _Type > &X)
Overloading += for sparse vectors.
std::size_t maxabs_index() const
Find the index of the maximum element in the vector.
SparseVector & operator=(const SparseVector &source)
Assignment operator.
SparseVector< _Type > operator+() const
Overloading for +.
std::size_t minabs_index() const
Find the index of the maximum element in the vector.
std::size_t nearest_index(const _Type &value) const
Find the index of the element NEAREST in value to that specified.
SparseVector< _Type > operator-() const
Overloading for -.
const _Type & get(const std::size_t &i) const
Get an element of the vector.
double one_norm() const
l1-norm.
void clear()
Remove all elements from the sparse vector.
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...