Nektar++
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// 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: Diagonal block sparse matrix class templated by underlying
32// 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 <algorithm>
41#include <fstream>
42#include <map>
43#include <utility>
44#include <vector>
45
47
48#include <boost/call_traits.hpp>
49
50namespace Nektar
51{
52
53/*
54 * This is a class-container to diagonal block matrix
55 * with elements being sparse matrices. The type of
56 * sparse entries is defined with template parameter.
57 *
58 */
59template <typename SparseStorageType> class NekSparseDiagBlkMatrix
60{
61public:
62 typedef SparseStorageType StorageType;
63 typedef typename SparseStorageType::DataType DataType;
64 typedef std::shared_ptr<SparseStorageType> SparseStorageSharedPtr;
68
70 const SparseStorageSharedPtrVector &sparseStoragePtrVector);
72 const NekSparseDiagBlkMatrix &src);
74
79
85
86 LIB_UTILITIES_EXPORT typename boost::call_traits<DataType>::const_reference
87 operator()(const IndexType row, const IndexType column) const;
88 LIB_UTILITIES_EXPORT typename boost::call_traits<DataType>::const_reference
89 operator()(const IndexType block, const IndexType row,
90 const IndexType column) const;
91
93 DataVectorType &out);
94 LIB_UTILITIES_EXPORT void Multiply(const DataType *in, DataType *out);
96 DataType *in, DataType *out);
97
100
101 LIB_UTILITIES_EXPORT unsigned long GetMulCallsCounter() const;
108
109 LIB_UTILITIES_EXPORT void writeSparsityPatternTo(std::ostream &out,
110 IndexType blockSize = 64);
112 std::ostream &out, const IndexType subMatrixIdx,
113 IndexType blockSize = 64);
115 std::ostream &out, const IndexType blk_row = 0,
116 const IndexType blk_col = 0, IndexType blockSize = 64);
118 std::ostream &out, const IndexType subMatrixIdx,
119 const IndexType blk_row = 0, const IndexType blk_col = 0,
120 IndexType blockSize = 64);
121
122protected:
126 unsigned long m_mulCallsCounter;
128
129private:
130};
131
132} // namespace Nektar
133
134#endif // NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_SPARSE_DIAG_BLK_MATRIX_HPP
#define LIB_UTILITIES_EXPORT
1D Array of constant elements with garbage collection and bounds checking.
Definition: SharedArray.hpp:56
Array< OneD, SparseStorageSharedPtr > SparseStorageSharedPtrVector
SparseStorageType::DataType DataType
std::shared_ptr< SparseStorageType > SparseStorageSharedPtr
Array< OneD, const DataType > ConstDataVectorType
void MultiplySubMatrix(const IndexType blockNum, DataType *in, DataType *out)
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...
unsigned long GetMulCallsCounter() const
Array< OneD, DataType > DataVectorType
void writeSubmatrixSparsityPatternTo(std::ostream &out, const IndexType subMatrixIdx, IndexType blockSize=64)
void writeSparsityPatternTo(std::ostream &out, IndexType blockSize=64)
void Multiply(const DataVectorType &in, DataVectorType &out)
SparseStorageSharedPtrVector m_submatrix
void writeBlockSparsityPatternTo(std::ostream &out, const IndexType blk_row=0, const IndexType blk_col=0, IndexType blockSize=64)
NekSparseDiagBlkMatrix(const SparseStorageSharedPtrVector &sparseStoragePtrVector)
boost::call_traits< DataType >::const_reference operator()(const IndexType row, const IndexType column) const
std::shared_ptr< COOMatType > COOMatTypeSharedPtr
unsigned int IndexType