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;
71  typedef Array<OneD, SparseStorageSharedPtr> SparseStorageSharedPtrVector;
72 
73 
77 
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 
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;
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;
131 
132  private:
133 
134  };
135 
136 }
137 
138 #endif //NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_SPARSE_DIAG_BLK_MATRIX_HPP