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 
47 
48 #include <boost/call_traits.hpp>
49 
50 namespace Nektar
51 {
52 
53 /*
54  * This is a class-container to a single sparse matrices.
55  * The type of sparse entry is defined with template parameter.
56  *
57  */
58 template <typename SparseStorageType> class NekSparseMatrix
59 {
60 public:
61  typedef SparseStorageType StorageType;
62  typedef typename SparseStorageType::DataType DataType;
63  typedef std::shared_ptr<SparseStorageType> SparseStorageSharedPtr;
66 
68  const SparseStorageSharedPtr &sparseStoragePtr);
71 
75 
78  LIB_UTILITIES_EXPORT unsigned long GetMulCallsCounter() const;
82 
83  LIB_UTILITIES_EXPORT typename boost::call_traits<DataType>::const_reference
84  operator()(const IndexType row, const IndexType column) const;
85  LIB_UTILITIES_EXPORT typename SparseStorageType::const_iterator begin()
86  const;
87  LIB_UTILITIES_EXPORT typename SparseStorageType::const_iterator end() const;
88 
90  DataVectorType &out);
91  LIB_UTILITIES_EXPORT void Multiply(const DataType *in, DataType *out);
92 
93  LIB_UTILITIES_EXPORT void writeSparsityPatternTo(std::ostream &out,
94  IndexType blockSize = 64);
96  std::ostream &out, const IndexType blk_row = 0,
97  const IndexType blk_col = 0, IndexType blockSize = 64);
98 
99 protected:
100  unsigned long m_mulCallsCounter;
102 
103 private:
104 };
105 
106 } // namespace Nektar
107 
108 #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:58
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...
boost::call_traits< DataType >::const_reference operator()(const IndexType row, const IndexType column) const
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
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
std::shared_ptr< COOMatType > COOMatTypeSharedPtr
unsigned int IndexType