Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: generic sparse matrix class templated by underlying sparse
33 // storage format
34 //
35 ///////////////////////////////////////////////////////////////////////////////
36 
37 #ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_SPARSE_MATRIX_HPP
38 #define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_SPARSE_MATRIX_HPP
39 
40 #include <map>
41 #include <vector>
42 #include <utility>
43 #include <algorithm>
44 #include <fstream>
45 
47 #include <LibUtilities/BasicUtils/SharedArray.hpp> ///< \todo: forward declare
48 
49 #include <boost/call_traits.hpp>
50 
51 
52 namespace Nektar
53 {
54 
55  /*
56  * This is a class-container to a single sparse matrices.
57  * The type of sparse entry is defined with template parameter.
58  *
59  */
60  template<typename SparseStorageType>
62  {
63  public:
64 
65  typedef SparseStorageType StorageType;
66  typedef typename SparseStorageType::DataType DataType;
67  typedef boost::shared_ptr<SparseStorageType> SparseStorageSharedPtr;
70 
71 
72  LIB_UTILITIES_EXPORT NekSparseMatrix(const SparseStorageSharedPtr& sparseStoragePtr);
75 
79 
80  LIB_UTILITIES_EXPORT const DataType GetFillInRatio() const;
81  LIB_UTILITIES_EXPORT const size_t GetMemoryFootprint() const;
82  LIB_UTILITIES_EXPORT const unsigned long GetMulCallsCounter() const;
83  LIB_UTILITIES_EXPORT const DataType GetAvgRowDensity() const;
86 
87 
88 
89  LIB_UTILITIES_EXPORT typename boost::call_traits<DataType>::const_reference
90  operator()(const IndexType row, const IndexType column) const;
91  LIB_UTILITIES_EXPORT typename SparseStorageType::const_iterator begin() const;
92  LIB_UTILITIES_EXPORT typename SparseStorageType::const_iterator end() const;
93 
94  LIB_UTILITIES_EXPORT void Multiply(const DataVectorType &in,
95  DataVectorType &out);
96  LIB_UTILITIES_EXPORT void Multiply(const DataType* in,
97  DataType* out);
98 
99 
100  LIB_UTILITIES_EXPORT void writeSparsityPatternTo(std::ostream& out, IndexType blockSize = 64);
101  LIB_UTILITIES_EXPORT void writeBlockSparsityPatternTo(std::ostream& out,
102  const IndexType blk_row = 0, const IndexType blk_col = 0, IndexType blockSize = 64);
103 
104  protected:
105 
106  unsigned long m_mulCallsCounter;
107  SparseStorageSharedPtr m_sparseStorage;
108 
109  private:
110 
111  };
112 
113 }
114 
115 #endif //NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_SPARSE_MATRIX_HPP
boost::shared_ptr< SparseStorageType > SparseStorageSharedPtr
COOMatTypeSharedPtr GetCooStorage()
boost::shared_ptr< COOMatType > COOMatTypeSharedPtr
Array< OneD, const DataType > ConstDataVectorType
boost::call_traits< DataType >::const_reference operator()(const IndexType row, const IndexType column) const
SparseStorageType::const_iterator begin() const
SparseStorageSharedPtr m_sparseStorage
const size_t GetMemoryFootprint() const
SparseStorageType::DataType DataType
Array< OneD, DataType > DataVectorType
void Multiply(const DataVectorType &in, DataVectorType &out)
const IndexType GetColumns() const
const IndexType GetBandwidth()
const IndexType GetNumNonZeroEntries() const
#define LIB_UTILITIES_EXPORT
const unsigned long GetMulCallsCounter() const
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...
const IndexType GetRows() const
unsigned int IndexType
SparseStorageType::const_iterator end() const
const DataType GetAvgRowDensity() const
NekSparseMatrix(const SparseStorageSharedPtr &sparseStoragePtr)
void writeSparsityPatternTo(std::ostream &out, IndexType blockSize=64)
unsigned long m_mulCallsCounter
1D Array of constant elements with garbage collection and bounds checking.
Definition: SharedArray.hpp:59
SparseStorageType StorageType
const DataType GetFillInRatio() const