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 <map>
40 #include <vector>
41 #include <utility>
42 #include <algorithm>
43 #include <fstream>
44 
47 
48 #include <boost/call_traits.hpp>
49 
50 
51 namespace Nektar
52 {
53 
54  /*
55  * This is a class-container to a single sparse matrices.
56  * The type of sparse entry is defined with template parameter.
57  *
58  */
59  template<typename SparseStorageType>
61  {
62  public:
63 
64  typedef SparseStorageType StorageType;
65  typedef typename SparseStorageType::DataType DataType;
66  typedef std::shared_ptr<SparseStorageType> SparseStorageSharedPtr;
69 
70 
74 
78 
81  LIB_UTILITIES_EXPORT unsigned long GetMulCallsCounter() const;
85 
86 
87 
88  LIB_UTILITIES_EXPORT typename boost::call_traits<DataType>::const_reference
89  operator()(const IndexType row, const IndexType column) const;
90  LIB_UTILITIES_EXPORT typename SparseStorageType::const_iterator begin() const;
91  LIB_UTILITIES_EXPORT typename SparseStorageType::const_iterator end() const;
92 
94  DataVectorType &out);
95  LIB_UTILITIES_EXPORT void Multiply(const DataType* in,
96  DataType* out);
97 
98 
99  LIB_UTILITIES_EXPORT void writeSparsityPatternTo(std::ostream& out, IndexType blockSize = 64);
100  LIB_UTILITIES_EXPORT void writeBlockSparsityPatternTo(std::ostream& out,
101  const IndexType blk_row = 0, const IndexType blk_col = 0, IndexType blockSize = 64);
102 
103  protected:
104 
105  unsigned long m_mulCallsCounter;
107 
108  private:
109 
110  };
111 
112 }
113 
114 #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:59
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:1
std::shared_ptr< COOMatType > COOMatTypeSharedPtr
unsigned int IndexType