Nektar++
Public Types | Public Member Functions | Protected Attributes | List of all members
Nektar::NekSparseMatrix< SparseStorageType > Class Template Reference

#include <SparseMatrix.hpp>

Public Types

typedef SparseStorageType StorageType
 
typedef SparseStorageType::DataType DataType
 
typedef boost::shared_ptr< SparseStorageType > SparseStorageSharedPtr
 
typedef Array< OneD, DataTypeDataVectorType
 
typedef Array< OneD, const DataTypeConstDataVectorType
 

Public Member Functions

 NekSparseMatrix (const SparseStorageSharedPtr &sparseStoragePtr)
 
 NekSparseMatrix (const NekSparseMatrix &src)
 
 ~NekSparseMatrix ()
 
const IndexType GetRows () const
 
const IndexType GetColumns () const
 
const IndexType GetNumNonZeroEntries () const
 
const DataType GetFillInRatio () const
 
const size_t GetMemoryFootprint () const
 
const unsigned long GetMulCallsCounter () const
 
const DataType GetAvgRowDensity () const
 
const IndexType GetBandwidth ()
 
COOMatTypeSharedPtr GetCooStorage ()
 
boost::call_traits< DataType >::const_reference operator() (const IndexType row, const IndexType column) const
 
SparseStorageType::const_iterator begin () const
 
SparseStorageType::const_iterator end () const
 
void Multiply (const DataVectorType &in, DataVectorType &out)
 
void Multiply (const DataType *in, DataType *out)
 
void writeSparsityPatternTo (std::ostream &out, IndexType blockSize=64)
 
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 entry to *this object. E.g., for a 6x6 matrix defined as A(i,i):=i, A(i,j):=0, block size = 2 and blk_row=blk_col=2 it produces 2x2 matrix with 5 and 6 along the diagonal. More...
 

Protected Attributes

unsigned long m_mulCallsCounter
 
SparseStorageSharedPtr m_sparseStorage
 

Detailed Description

template<typename SparseStorageType>
class Nektar::NekSparseMatrix< SparseStorageType >

Definition at line 61 of file SparseMatrix.hpp.

Member Typedef Documentation

template<typename SparseStorageType>
typedef Array<OneD, const DataType> Nektar::NekSparseMatrix< SparseStorageType >::ConstDataVectorType

Definition at line 69 of file SparseMatrix.hpp.

template<typename SparseStorageType>
typedef SparseStorageType::DataType Nektar::NekSparseMatrix< SparseStorageType >::DataType

Definition at line 66 of file SparseMatrix.hpp.

template<typename SparseStorageType>
typedef Array<OneD, DataType> Nektar::NekSparseMatrix< SparseStorageType >::DataVectorType

Definition at line 68 of file SparseMatrix.hpp.

template<typename SparseStorageType>
typedef boost::shared_ptr<SparseStorageType> Nektar::NekSparseMatrix< SparseStorageType >::SparseStorageSharedPtr

Definition at line 67 of file SparseMatrix.hpp.

template<typename SparseStorageType>
typedef SparseStorageType Nektar::NekSparseMatrix< SparseStorageType >::StorageType

Definition at line 65 of file SparseMatrix.hpp.

Constructor & Destructor Documentation

template<typename SparseStorageType >
Nektar::NekSparseMatrix< SparseStorageType >::NekSparseMatrix ( const SparseStorageSharedPtr sparseStoragePtr)

Definition at line 58 of file SparseMatrix.cpp.

58  :
60  m_sparseStorage(sparseStoragePtr)
61  {
62  }
SparseStorageSharedPtr m_sparseStorage
unsigned long m_mulCallsCounter
template<typename SparseStorageType >
Nektar::NekSparseMatrix< SparseStorageType >::NekSparseMatrix ( const NekSparseMatrix< SparseStorageType > &  src)

Definition at line 65 of file SparseMatrix.cpp.

65  :
66  m_mulCallsCounter(src.m_mulCallsCounter),
67  m_sparseStorage(src.m_sparseStorage)
68  {
69  }
SparseStorageSharedPtr m_sparseStorage
unsigned long m_mulCallsCounter
template<typename SparseStorageType >
Nektar::NekSparseMatrix< SparseStorageType >::~NekSparseMatrix ( )

Definition at line 72 of file SparseMatrix.cpp.

73  {
74  }

Member Function Documentation

template<typename SparseStorageType >
SparseStorageType::const_iterator Nektar::NekSparseMatrix< SparseStorageType >::begin ( ) const

Definition at line 111 of file SparseMatrix.cpp.

112  {
113  return m_sparseStorage->begin();
114  }
SparseStorageSharedPtr m_sparseStorage
template<typename SparseStorageType >
SparseStorageType::const_iterator Nektar::NekSparseMatrix< SparseStorageType >::end ( ) const

Definition at line 117 of file SparseMatrix.cpp.

118  {
119  return m_sparseStorage->end();
120  }
SparseStorageSharedPtr m_sparseStorage
template<typename SparseStorageType >
const SparseStorageType::DataType Nektar::NekSparseMatrix< SparseStorageType >::GetAvgRowDensity ( ) const

Definition at line 157 of file SparseMatrix.cpp.

158  {
159  return (DataType) m_sparseStorage->GetNumNonZeroEntries() /
160  (DataType) m_sparseStorage->GetRows();
161  }
SparseStorageSharedPtr m_sparseStorage
SparseStorageType::DataType DataType
template<typename SparseStorageType >
const IndexType Nektar::NekSparseMatrix< SparseStorageType >::GetBandwidth ( )

Definition at line 164 of file SparseMatrix.cpp.

165  {
166  int bandwidth = 0;
167 
168  typename SparseStorageType::const_iterator entry = m_sparseStorage->begin();
169 
170  for (; entry != m_sparseStorage->end(); ++entry)
171  {
172  bandwidth = (std::max)(bandwidth, 2*std::abs((int)(entry->first.first - entry->first.second+1)));
173  }
174  return bandwidth;
175  }
SparseStorageSharedPtr m_sparseStorage
template<typename SparseStorageType >
const IndexType Nektar::NekSparseMatrix< SparseStorageType >::GetColumns ( ) const

Definition at line 84 of file SparseMatrix.cpp.

85  {
86  return m_sparseStorage->GetColumns();
87  }
SparseStorageSharedPtr m_sparseStorage
template<typename SparseStorageType >
COOMatTypeSharedPtr Nektar::NekSparseMatrix< SparseStorageType >::GetCooStorage ( )

Definition at line 178 of file SparseMatrix.cpp.

179  {
180  COOMatTypeSharedPtr coo (new COOMatType());
181 
182  typename SparseStorageType::const_iterator entry = m_sparseStorage->begin();
183  for (; entry != m_sparseStorage->end(); entry++)
184  {
185  (*coo)[std::make_pair(entry->first.first, entry->first.second) ] = entry->second;
186  }
187  return coo;
188  }
std::map< CoordType, NekDouble > COOMatType
boost::shared_ptr< COOMatType > COOMatTypeSharedPtr
SparseStorageSharedPtr m_sparseStorage
template<typename SparseStorageType >
const NekSparseMatrix< SparseStorageType >::DataType Nektar::NekSparseMatrix< SparseStorageType >::GetFillInRatio ( ) const

Definition at line 97 of file SparseMatrix.cpp.

98  {
99  return m_sparseStorage->GetFillInRatio();
100  }
SparseStorageSharedPtr m_sparseStorage
template<typename SparseStorageType >
const size_t Nektar::NekSparseMatrix< SparseStorageType >::GetMemoryFootprint ( ) const

Definition at line 140 of file SparseMatrix.cpp.

141  {
142  return m_sparseStorage->GetMemoryUsage(
143  m_sparseStorage->GetNumNonZeroEntries(),
144  m_sparseStorage->GetRows()
145  ) +
146  sizeof(SparseStorageSharedPtr) +
147  sizeof(unsigned long); // mulCallsCounter
148  }
boost::shared_ptr< SparseStorageType > SparseStorageSharedPtr
SparseStorageSharedPtr m_sparseStorage
template<typename SparseStorageType >
const unsigned long Nektar::NekSparseMatrix< SparseStorageType >::GetMulCallsCounter ( ) const

Definition at line 151 of file SparseMatrix.cpp.

152  {
153  return m_mulCallsCounter;
154  }
unsigned long m_mulCallsCounter
template<typename SparseStorageType >
const IndexType Nektar::NekSparseMatrix< SparseStorageType >::GetNumNonZeroEntries ( ) const

Definition at line 90 of file SparseMatrix.cpp.

91  {
92  return m_sparseStorage->GetNumNonZeroEntries();
93  }
SparseStorageSharedPtr m_sparseStorage
template<typename SparseStorageType >
const IndexType Nektar::NekSparseMatrix< SparseStorageType >::GetRows ( ) const

Definition at line 78 of file SparseMatrix.cpp.

79  {
80  return m_sparseStorage->GetRows();
81  }
SparseStorageSharedPtr m_sparseStorage
template<typename SparseStorageType >
void Nektar::NekSparseMatrix< SparseStorageType >::Multiply ( const DataVectorType in,
DataVectorType out 
)

Definition at line 124 of file SparseMatrix.cpp.

126  {
127  m_sparseStorage->Multiply(in,out);
129  }
SparseStorageSharedPtr m_sparseStorage
unsigned long m_mulCallsCounter
template<typename SparseStorageType >
void Nektar::NekSparseMatrix< SparseStorageType >::Multiply ( const DataType in,
DataType out 
)

Definition at line 132 of file SparseMatrix.cpp.

134  {
135  m_sparseStorage->Multiply(in,out);
137  }
SparseStorageSharedPtr m_sparseStorage
unsigned long m_mulCallsCounter
template<typename SparseStorageType >
boost::call_traits< typename SparseStorageType::DataType >::const_reference Nektar::NekSparseMatrix< SparseStorageType >::operator() ( const IndexType  row,
const IndexType  column 
) const

Definition at line 105 of file SparseMatrix.cpp.

106  {
107  return m_sparseStorage->GetValue(row, column);
108  }
SparseStorageSharedPtr m_sparseStorage
template<typename SparseStorageType >
void Nektar::NekSparseMatrix< SparseStorageType >::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 entry to *this object. E.g., for a 6x6 matrix defined as A(i,i):=i, A(i,j):=0, block size = 2 and blk_row=blk_col=2 it produces 2x2 matrix with 5 and 6 along the diagonal.

Definition at line 237 of file SparseMatrix.cpp.

239  {
240  blockSize = (std::min)(blockSize, m_sparseStorage->GetRows());
241  std::vector< std::vector<int> > grid (blockSize);
242  for (int row = 0; row < blockSize; row++)
243  {
244  grid[row].resize(blockSize,0);
245  }
246 
247  typename SparseStorageType::const_iterator entry = m_sparseStorage->begin();
248  for (; entry != m_sparseStorage->end(); entry++)
249  {
250  const IndexType row = entry->first.first;
251  const IndexType col = entry->first.second;
252 
253  if (blk_row != row / blockSize ) continue;
254  if (blk_col != col / blockSize ) continue;
255  grid[row % blockSize][col % blockSize]++;
256  }
257 
258  for (int row = 0; row < blockSize; row++)
259  {
260  for (int col = 0; col < blockSize; col++)
261  {
262  out << grid[row][col] << " ";
263  }
264  out << std::endl;
265  }
266  }
SparseStorageSharedPtr m_sparseStorage
unsigned int IndexType
template<typename SparseStorageType >
void Nektar::NekSparseMatrix< SparseStorageType >::writeSparsityPatternTo ( std::ostream &  out,
IndexType  blockSize = 64 
)

Definition at line 198 of file SparseMatrix.cpp.

199  {
200  const int matRows = m_sparseStorage->GetRows();
201  const int gridRows = matRows / blockSize + (matRows % blockSize > 0);
202  const int gridCols = gridRows;
203 
204  std::vector< std::vector<int> > grid (gridRows);
205  for (int row = 0; row < gridRows; row++)
206  {
207  grid[row].resize(gridCols,0);
208  }
209 
210  typename SparseStorageType::const_iterator entry = m_sparseStorage->begin();
211  for (; entry != m_sparseStorage->end(); entry++)
212  {
213  const IndexType row = entry->first.first;
214  const IndexType col = entry->first.second;
215  const int gridRow = row / blockSize;
216  const int gridCol = col / blockSize;
217  grid[gridRow][gridCol]++;
218  }
219 
220  for (int row = 0; row < gridRows; row++)
221  {
222  for (int col = 0; col < gridCols; col++)
223  {
224  out << grid[row][col] << " ";
225  }
226  out << std::endl;
227  }
228  }
SparseStorageSharedPtr m_sparseStorage
unsigned int IndexType

Member Data Documentation

template<typename SparseStorageType>
unsigned long Nektar::NekSparseMatrix< SparseStorageType >::m_mulCallsCounter
protected

Definition at line 106 of file SparseMatrix.hpp.

template<typename SparseStorageType>
SparseStorageSharedPtr Nektar::NekSparseMatrix< SparseStorageType >::m_sparseStorage
protected

Definition at line 107 of file SparseMatrix.hpp.