Nektar++
SparseMatrix.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: SparseMatrix.hpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: generic sparse matrix class templated by underlying sparse
32// storage format
33//
34///////////////////////////////////////////////////////////////////////////////
35
36#ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_SPARSE_MATRIX_HPP
37#define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_SPARSE_MATRIX_HPP
38
39#include <algorithm>
40#include <fstream>
41#include <map>
42#include <utility>
43#include <vector>
44
46
47#include <boost/call_traits.hpp>
48
49namespace Nektar
50{
51
52/*
53 * This is a class-container to a single sparse matrices.
54 * The type of sparse entry is defined with template parameter.
55 *
56 */
57template <typename SparseStorageType> class NekSparseMatrix
58{
59public:
60 typedef SparseStorageType StorageType;
61 typedef typename SparseStorageType::DataType DataType;
62 typedef std::shared_ptr<SparseStorageType> SparseStorageSharedPtr;
65
67 const SparseStorageSharedPtr &sparseStoragePtr);
70
74
77 LIB_UTILITIES_EXPORT unsigned long GetMulCallsCounter() const;
81
82 LIB_UTILITIES_EXPORT typename boost::call_traits<DataType>::const_reference
83 operator()(const IndexType row, const IndexType column) const;
84 LIB_UTILITIES_EXPORT typename SparseStorageType::const_iterator begin()
85 const;
86 LIB_UTILITIES_EXPORT typename SparseStorageType::const_iterator end() const;
87
89 DataVectorType &out);
90 LIB_UTILITIES_EXPORT void Multiply(const DataType *in, DataType *out);
91
92 LIB_UTILITIES_EXPORT void writeSparsityPatternTo(std::ostream &out,
93 IndexType blockSize = 64);
95 std::ostream &out, const IndexType blk_row = 0,
96 const IndexType blk_col = 0, IndexType blockSize = 64);
97
98protected:
99 unsigned long m_mulCallsCounter;
101
102private:
103};
104
105} // namespace Nektar
106
107#endif // NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_SPARSE_MATRIX_HPP
#define LIB_UTILITIES_EXPORT
1D Array of constant elements with garbage collection and bounds checking.
Definition: SharedArray.hpp:56
Array< OneD, const DataType > ConstDataVectorType
void writeBlockSparsityPatternTo(std::ostream &out, const IndexType blk_row=0, const IndexType blk_col=0, IndexType blockSize=64)
Complementary routine to the previous. It generates exact non-zero pattern of a given block matrix en...
SparseStorageSharedPtr m_sparseStorage
unsigned long GetMulCallsCounter() const
NekSparseMatrix(const SparseStorageSharedPtr &sparseStoragePtr)
Array< OneD, DataType > DataVectorType
unsigned long m_mulCallsCounter
void Multiply(const DataVectorType &in, DataVectorType &out)
void writeSparsityPatternTo(std::ostream &out, IndexType blockSize=64)
IndexType GetRows() const
SparseStorageType::const_iterator begin() const
IndexType GetNumNonZeroEntries() const
size_t GetMemoryFootprint() const
const DataType GetAvgRowDensity() const
SparseStorageType::DataType DataType
std::shared_ptr< SparseStorageType > SparseStorageSharedPtr
const DataType GetFillInRatio() const
COOMatTypeSharedPtr GetCooStorage()
SparseStorageType::const_iterator end() const
SparseStorageType StorageType
IndexType GetColumns() const
boost::call_traits< DataType >::const_reference operator()(const IndexType row, const IndexType column) const
std::shared_ptr< COOMatType > COOMatTypeSharedPtr
unsigned int IndexType