Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SparseDiagBlkMatrix.hpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: SparseDiagBlkMatrix.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: Diagonal block sparse matrix class templated by underlying sparse
33 // storage format
34 //
35 ///////////////////////////////////////////////////////////////////////////////
36 
37 #ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_SPARSE_DIAG_BLK_MATRIX_HPP
38 #define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_SPARSE_DIAG_BLK_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 diagonal block matrix
57  * with elements being sparse matrices. The type of
58  * sparse entries is defined with template parameter.
59  *
60  */
61  template<typename SparseStorageType>
63  {
64  public:
65 
66  typedef SparseStorageType StorageType;
67  typedef typename SparseStorageType::DataType DataType;
68  typedef boost::shared_ptr<SparseStorageType> SparseStorageSharedPtr;
72 
73 
74  LIB_UTILITIES_EXPORT NekSparseDiagBlkMatrix(const SparseStorageSharedPtrVector& sparseStoragePtrVector);
77 
81  LIB_UTILITIES_EXPORT const DataType GetFillInRatio() const;
82 
83  LIB_UTILITIES_EXPORT const IndexType GetRows(int i) const;
84  LIB_UTILITIES_EXPORT const IndexType GetColumns(int i) const;
87  LIB_UTILITIES_EXPORT const DataType GetFillInRatio(int i) const;
88 
89 
90  LIB_UTILITIES_EXPORT typename boost::call_traits<DataType>::const_reference
91  operator()(const IndexType row, const IndexType column) const;
92  LIB_UTILITIES_EXPORT typename boost::call_traits<DataType>::const_reference
93  operator()(const IndexType block, const IndexType row, const IndexType column) const;
94 
95  //typename SparseStorageType::const_iterator begin() const;
96  //typename SparseStorageType::const_iterator end() const;
97 
98  LIB_UTILITIES_EXPORT void Multiply(const DataVectorType &in,
99  DataVectorType &out);
100  LIB_UTILITIES_EXPORT void Multiply(const DataType* in,
101  DataType* out);
102  LIB_UTILITIES_EXPORT void MultiplySubMatrix( const IndexType blockNum,
103  DataType* in,
104  DataType* out);
105 
107  LIB_UTILITIES_EXPORT const size_t GetMemoryFootprint(IndexType i) const;
108 
109  LIB_UTILITIES_EXPORT const unsigned long GetMulCallsCounter() const;
110  LIB_UTILITIES_EXPORT const DataType GetAvgRowDensity();
111  LIB_UTILITIES_EXPORT const DataType GetAvgRowDensity(IndexType i) const;
116 
117  LIB_UTILITIES_EXPORT void writeSparsityPatternTo(std::ostream& out, IndexType blockSize = 64);
118  LIB_UTILITIES_EXPORT void writeSubmatrixSparsityPatternTo(std::ostream& out, const IndexType subMatrixIdx, IndexType blockSize = 64);
119  LIB_UTILITIES_EXPORT void writeBlockSparsityPatternTo(std::ostream& out,
120  const IndexType blk_row = 0, const IndexType blk_col = 0, IndexType blockSize = 64);
121  LIB_UTILITIES_EXPORT void writeSubmatrixBlockSparsityPatternTo(std::ostream& out, const IndexType subMatrixIdx,
122  const IndexType blk_row = 0, const IndexType blk_col = 0, IndexType blockSize = 64);
123 
124  protected:
125 
129  unsigned long m_mulCallsCounter;
130  SparseStorageSharedPtrVector m_submatrix;
131 
132  private:
133 
134  };
135 
136 }
137 
138 #endif //NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_SPARSE_DIAG_BLK_MATRIX_HPP
const IndexType GetNumberOfMatrixBlocks() const
boost::shared_ptr< SparseStorageType > SparseStorageSharedPtr
boost::shared_ptr< COOMatType > COOMatTypeSharedPtr
const IndexType GetRows() const
const unsigned long GetMulCallsCounter() const
SparseStorageSharedPtrVector m_submatrix
const DataType GetFillInRatio() const
const IndexType GetColumns() const
void MultiplySubMatrix(const IndexType blockNum, DataType *in, DataType *out)
#define LIB_UTILITIES_EXPORT
SparseStorageType::DataType DataType
boost::call_traits< DataType >::const_reference operator()(const IndexType row, const IndexType column) const
Array< OneD, DataType > DataVectorType
unsigned int IndexType
void writeSubmatrixBlockSparsityPatternTo(std::ostream &out, const IndexType subMatrixIdx, 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...
void writeBlockSparsityPatternTo(std::ostream &out, const IndexType blk_row=0, const IndexType blk_col=0, IndexType blockSize=64)
void Multiply(const DataVectorType &in, DataVectorType &out)
void writeSparsityPatternTo(std::ostream &out, IndexType blockSize=64)
void writeSubmatrixSparsityPatternTo(std::ostream &out, const IndexType subMatrixIdx, IndexType blockSize=64)
Array< OneD, SparseStorageSharedPtr > SparseStorageSharedPtrVector
Array< OneD, const DataType > ConstDataVectorType
1D Array of constant elements with garbage collection and bounds checking.
Definition: SharedArray.hpp:59
NekSparseDiagBlkMatrix(const SparseStorageSharedPtrVector &sparseStoragePtrVector)