Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Types | Public Member Functions | Protected Attributes | List of all members
Nektar::NekSparseDiagBlkMatrix< SparseStorageType > Singleton Reference

#include <SparseDiagBlkMatrix.hpp>

Collaboration diagram for Nektar::NekSparseDiagBlkMatrix< SparseStorageType >:
Collaboration graph
[legend]

Public Types

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

Public Member Functions

 NekSparseDiagBlkMatrix (const SparseStorageSharedPtrVector &sparseStoragePtrVector)
 
 NekSparseDiagBlkMatrix (const NekSparseDiagBlkMatrix &src)
 
 ~NekSparseDiagBlkMatrix ()
 
const IndexType GetRows () const
 
const IndexType GetColumns () const
 
const IndexType GetNumNonZeroEntries ()
 
const DataType GetFillInRatio () const
 
const IndexType GetRows (int i) const
 number of rows at i-th submatrix More...
 
const IndexType GetColumns (int i) const
 number of columns at i-th submatrix More...
 
const IndexType GetNumberOfMatrixBlocks () const
 
const IndexType GetNumNonZeroEntries (int i) const
 
const DataType GetFillInRatio (int i) const
 
boost::call_traits< DataType >
::const_reference 
operator() (const IndexType row, const IndexType column) const
 
boost::call_traits< DataType >
::const_reference 
operator() (const IndexType block, const IndexType row, const IndexType column) const
 
void Multiply (const DataVectorType &in, DataVectorType &out)
 
void Multiply (const DataType *in, DataType *out)
 
void MultiplySubMatrix (const IndexType blockNum, DataType *in, DataType *out)
 
const size_t GetMemoryFootprint ()
 
const size_t GetMemoryFootprint (IndexType i) const
 
const unsigned long GetMulCallsCounter () const
 
const DataType GetAvgRowDensity ()
 
const DataType GetAvgRowDensity (IndexType i) const
 
const IndexType GetBandwidth ()
 
const IndexType GetBandwidth (IndexType i)
 
COOMatTypeSharedPtr GetCooStorage ()
 
COOMatTypeSharedPtr GetCooStorage (IndexType i)
 
void writeSparsityPatternTo (std::ostream &out, IndexType blockSize=64)
 
void writeSubmatrixSparsityPatternTo (std::ostream &out, const IndexType subMatrixIdx, IndexType blockSize=64)
 
void writeBlockSparsityPatternTo (std::ostream &out, const IndexType blk_row=0, const IndexType blk_col=0, IndexType blockSize=64)
 
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 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

IndexType m_rows
 
IndexType m_cols
 
IndexVector m_rowoffset
 
unsigned long m_mulCallsCounter
 
SparseStorageSharedPtrVector m_submatrix
 

Detailed Description

template<typename SparseStorageType>
singleton Nektar::NekSparseDiagBlkMatrix< SparseStorageType >

Definition at line 62 of file SparseDiagBlkMatrix.hpp.

Member Typedef Documentation

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

Definition at line 70 of file SparseDiagBlkMatrix.hpp.

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

Definition at line 67 of file SparseDiagBlkMatrix.hpp.

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

Definition at line 69 of file SparseDiagBlkMatrix.hpp.

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

Definition at line 68 of file SparseDiagBlkMatrix.hpp.

template<typename SparseStorageType>
typedef Array<OneD, SparseStorageSharedPtr> Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::SparseStorageSharedPtrVector

Definition at line 71 of file SparseDiagBlkMatrix.hpp.

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

Definition at line 66 of file SparseDiagBlkMatrix.hpp.

Constructor & Destructor Documentation

template<typename SparseStorageType >
Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::NekSparseDiagBlkMatrix ( const SparseStorageSharedPtrVector sparseStoragePtrVector)

Definition at line 57 of file SparseDiagBlkMatrix.cpp.

References Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::m_cols, Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::m_rowoffset, and Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::m_rows.

58  :
59  m_rows(0),
60  m_cols(0),
61  m_rowoffset(sparseStoragePtrVector.num_elements()+1, 0.0),
63  m_submatrix(sparseStoragePtrVector.num_elements(),sparseStoragePtrVector)
64  {
65  for (int i = 0; i < sparseStoragePtrVector.num_elements(); i++)
66  {
67  const IndexType rows = sparseStoragePtrVector[i]->GetRows();
68  m_rows += rows;
69  m_cols += sparseStoragePtrVector[i]->GetColumns();
70  m_rowoffset[i+1] = m_rowoffset[i] + rows;
71  }
72  }
SparseStorageSharedPtrVector m_submatrix
unsigned int IndexType
template<typename SparseStorageType >
Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::NekSparseDiagBlkMatrix ( const NekSparseDiagBlkMatrix< SparseStorageType > &  src)

Definition at line 75 of file SparseDiagBlkMatrix.cpp.

75  :
76  m_rows(src.m_rows),
77  m_cols(src.m_cols),
78  m_rowoffset(src.m_rowoffset),
79  m_mulCallsCounter(src.m_mulCallsCounter),
80  m_submatrix(src.m_submatrix)
81  {
82  }
SparseStorageSharedPtrVector m_submatrix
template<typename SparseStorageType >
Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::~NekSparseDiagBlkMatrix ( )

Definition at line 85 of file SparseDiagBlkMatrix.cpp.

86  {
87  }

Member Function Documentation

template<typename SparseStorageType >
const SparseStorageType::DataType Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetAvgRowDensity ( )

Definition at line 267 of file SparseDiagBlkMatrix.cpp.

268  {
269  DataType avgRowDensity = 0.0;
270  for (int i = 0; i < m_submatrix.num_elements(); i++)
271  {
272  avgRowDensity += (DataType) m_submatrix[i]->GetNumNonZeroEntries() /
273  (DataType) m_submatrix[i]->GetRows();
274  }
275  return avgRowDensity / m_submatrix.num_elements();
276  }
const IndexType GetRows() const
SparseStorageSharedPtrVector m_submatrix
SparseStorageType::DataType DataType
template<typename SparseStorageType >
const SparseStorageType::DataType Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetAvgRowDensity ( IndexType  i) const

Definition at line 279 of file SparseDiagBlkMatrix.cpp.

280  {
281  return (DataType) m_submatrix[i]->GetNumNonZeroEntries() /
282  (DataType) m_submatrix[i]->GetRows();
283  }
const IndexType GetRows() const
SparseStorageSharedPtrVector m_submatrix
SparseStorageType::DataType DataType
template<typename SparseStorageType >
const IndexType Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetBandwidth ( )

Definition at line 286 of file SparseDiagBlkMatrix.cpp.

287  {
288  IndexType bandwidth = 0;
289  for (int i = 0; i < m_submatrix.num_elements(); i++)
290  {
291  typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
292  for (; entry != m_submatrix[i]->end(); ++entry)
293  {
294  bandwidth = (std::max)(static_cast<int>(bandwidth),
295  2*abs( static_cast<int>(entry->first.first - entry->first.second)+1));
296  }
297  }
298  return bandwidth;
299  }
SparseStorageSharedPtrVector m_submatrix
unsigned int IndexType
template<typename SparseStorageType >
const IndexType Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetBandwidth ( IndexType  i)

Definition at line 302 of file SparseDiagBlkMatrix.cpp.

303  {
304  IndexType bandwidth = 0;
305  typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
306  for (; entry != m_submatrix[i]->end(); ++entry)
307  {
308  bandwidth = (std::max)(static_cast<int>(bandwidth),
309  2*abs( static_cast<int>(entry->first.first - entry->first.second)+1));
310  }
311  return bandwidth;
312  }
SparseStorageSharedPtrVector m_submatrix
unsigned int IndexType
template<typename SparseStorageType >
const IndexType Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetColumns ( ) const

Definition at line 96 of file SparseDiagBlkMatrix.cpp.

97  {
98  return m_cols;
99  }
template<typename SparseStorageType >
const IndexType Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetColumns ( int  i) const

number of columns at i-th submatrix

Definition at line 110 of file SparseDiagBlkMatrix.cpp.

111  {
112  return m_submatrix[i]->GetColumns();
113  }
SparseStorageSharedPtrVector m_submatrix
template<typename SparseStorageType >
COOMatTypeSharedPtr Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetCooStorage ( )

Definition at line 329 of file SparseDiagBlkMatrix.cpp.

330  {
331  COOMatTypeSharedPtr coo (new COOMatType());
332  IndexType row_offset = 0;
333  IndexType col_offset = 0;
334  for (IndexType i = 0; i < m_submatrix.num_elements(); i++)
335  {
336  typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
337  for (; entry != m_submatrix[i]->end(); entry++)
338  {
339  IndexType loc_row = entry->first.first;
340  IndexType loc_col = entry->first.second;
341  (*coo)[std::make_pair(loc_row + row_offset, loc_col + col_offset) ] = entry->second;
342  }
343  row_offset += m_submatrix[i]->GetRows();
344  col_offset += m_submatrix[i]->GetColumns();
345  }
346  return coo;
347  }
std::map< CoordType, NekDouble > COOMatType
boost::shared_ptr< COOMatType > COOMatTypeSharedPtr
SparseStorageSharedPtrVector m_submatrix
unsigned int IndexType
template<typename SparseStorageType >
COOMatTypeSharedPtr Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetCooStorage ( IndexType  i)

Definition at line 315 of file SparseDiagBlkMatrix.cpp.

316  {
317  COOMatTypeSharedPtr coo (new COOMatType());
318  typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
319  for (; entry != m_submatrix[i]->end(); entry++)
320  {
321  IndexType loc_row = entry->first.first;
322  IndexType loc_col = entry->first.second;
323  (*coo)[std::make_pair(loc_row, loc_col) ] = entry->second;
324  }
325  return coo;
326  }
std::map< CoordType, NekDouble > COOMatType
boost::shared_ptr< COOMatType > COOMatTypeSharedPtr
SparseStorageSharedPtrVector m_submatrix
unsigned int IndexType
template<typename SparseStorageType >
const NekSparseDiagBlkMatrix< SparseStorageType >::DataType Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetFillInRatio ( ) const

Definition at line 146 of file SparseDiagBlkMatrix.cpp.

147  {
148  IndexType stored = 0;
149  IndexType nnz = 0;
150  for (int i = 0; i < m_submatrix.num_elements(); i++)
151  {
152  stored += m_submatrix[i]->GetNumStoredDoubles();
153  nnz += m_submatrix[i]->GetNumNonZeroEntries();
154  }
155  return (DataType)stored/(DataType)nnz;
156  }
SparseStorageSharedPtrVector m_submatrix
SparseStorageType::DataType DataType
unsigned int IndexType
template<typename SparseStorageType >
const NekSparseDiagBlkMatrix< SparseStorageType >::DataType Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetFillInRatio ( int  i) const

Definition at line 140 of file SparseDiagBlkMatrix.cpp.

141  {
142  return m_submatrix[i]->GetFillInRatio();
143  }
SparseStorageSharedPtrVector m_submatrix
template<typename SparseStorageType >
const size_t Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetMemoryFootprint ( )

Definition at line 232 of file SparseDiagBlkMatrix.cpp.

233  {
234  size_t bytes =
235  sizeof(IndexType)*2 + // sizes
236  sizeof(unsigned long) + // mulCallsCounter
237  sizeof(IndexVector) +
238  sizeof(IndexType)*m_rowoffset.capacity() +
240  sizeof(SparseStorageSharedPtr)*m_submatrix.capacity();
241  for (int i = 0; i < m_submatrix.num_elements(); i++)
242  {
243  bytes += m_submatrix[i]->GetMemoryUsage(
245  m_submatrix[i]->GetRows()
246  );
247  }
248  return bytes;
249  }
boost::shared_ptr< SparseStorageType > SparseStorageSharedPtr
const IndexType GetRows() const
SparseStorageSharedPtrVector m_submatrix
Array< OneD, IndexType > IndexVector
unsigned int IndexType
Array< OneD, SparseStorageSharedPtr > SparseStorageSharedPtrVector
template<typename SparseStorageType >
const size_t Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetMemoryFootprint ( IndexType  i) const

Definition at line 252 of file SparseDiagBlkMatrix.cpp.

253  {
254  return m_submatrix[i]->GetMemoryUsage(
256  m_submatrix[i]->GetRows()
257  );
258  }
const IndexType GetRows() const
SparseStorageSharedPtrVector m_submatrix
template<typename SparseStorageType >
const unsigned long Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetMulCallsCounter ( ) const

Definition at line 261 of file SparseDiagBlkMatrix.cpp.

262  {
263  return m_mulCallsCounter;
264  }
template<typename SparseStorageType >
const IndexType Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetNumberOfMatrixBlocks ( ) const

Definition at line 116 of file SparseDiagBlkMatrix.cpp.

117  {
118  return m_submatrix.num_elements();
119  }
SparseStorageSharedPtrVector m_submatrix
template<typename SparseStorageType >
const IndexType Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetNumNonZeroEntries ( )

Definition at line 122 of file SparseDiagBlkMatrix.cpp.

123  {
124  IndexType nnz = 0;
125  for (int i = 0; i < m_submatrix.num_elements(); i++)
126  {
127  nnz += m_submatrix[i]->GetNumNonZeroEntries();
128  }
129  return nnz;
130  }
SparseStorageSharedPtrVector m_submatrix
unsigned int IndexType
template<typename SparseStorageType >
const IndexType Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetNumNonZeroEntries ( int  i) const

Definition at line 134 of file SparseDiagBlkMatrix.cpp.

135  {
136  return m_submatrix[i]->GetNumNonZeroEntries();
137  }
SparseStorageSharedPtrVector m_submatrix
template<typename SparseStorageType >
const IndexType Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetRows ( ) const
template<typename SparseStorageType >
const IndexType Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetRows ( int  i) const

number of rows at i-th submatrix

Definition at line 103 of file SparseDiagBlkMatrix.cpp.

104  {
105  return m_submatrix[i]->GetRows();
106  }
SparseStorageSharedPtrVector m_submatrix
template<typename SparseStorageType >
void Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::Multiply ( const DataVectorType in,
DataVectorType out 
)

Definition at line 199 of file SparseDiagBlkMatrix.cpp.

202  {
203  for (int i = 0; i < m_submatrix.num_elements(); ++i)
204  {
205  m_submatrix[i]->Multiply(&in[m_rowoffset[i]], &out[m_rowoffset[i]]);
206  }
208  }
SparseStorageSharedPtrVector m_submatrix
template<typename SparseStorageType >
void Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::Multiply ( const DataType in,
DataType out 
)

Definition at line 211 of file SparseDiagBlkMatrix.cpp.

213  {
214  for (int i = 0; i < m_submatrix.num_elements(); ++i)
215  {
216  m_submatrix[i]->Multiply(&in[m_rowoffset[i]], &out[m_rowoffset[i]]);
217  }
219  }
SparseStorageSharedPtrVector m_submatrix
template<typename SparseStorageType >
void Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::MultiplySubMatrix ( const IndexType  blockNum,
DataType in,
DataType out 
)

Definition at line 223 of file SparseDiagBlkMatrix.cpp.

226  {
227  m_submatrix[blockNum]->Multiply(in + m_rowoffset[blockNum], out + m_rowoffset[blockNum]);
228  // m_mulCallsCounter++;
229  }
SparseStorageSharedPtrVector m_submatrix
template<typename SparseStorageType >
boost::call_traits< typename SparseStorageType::DataType >::const_reference Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::operator() ( const IndexType  row,
const IndexType  column 
) const
Todo:
double check, might be a bug when local_col > local column

Definition at line 168 of file SparseDiagBlkMatrix.cpp.

References Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::GetRows().

169  {
170 /*
171  ASSERTL1(row < GetRows(), std::string("Row ") + boost::lexical_cast<std::string>(glob_row) +
172  std::string(" requested in a matrix with a maximum of ") + boost::lexical_cast<std::string>(GetRows()) +
173  std::string(" rows"));
174  ASSERTL1(column < GetColumns(), std::string("Column ") + boost::lexical_cast<std::string>(glob_column) +
175  std::string(" requested in a matrix with a maximum of ") + boost::lexical_cast<std::string>(GetColumns()) +
176  std::string(" columns"));
177 */
178  IndexType i = 0;
179  static DataType defaultReturnValue = 0;
180 
181  signed int local_row = glob_row;
182  signed int local_col = glob_column;
183 
184  while ((local_row >= m_submatrix[i]->GetRows()) &&
185  (local_col >= 0))
186  {
187  local_row -= m_submatrix[i]->GetRows();
188  local_col -= m_submatrix[i]->GetColumns();
189  i++;
190  }
191  /// \todo double check, might be a bug when local_col > local column
192  if (local_col < 0) return defaultReturnValue;
193 
194  return m_submatrix[i]->GetValue(local_row, local_col);
195  }
const IndexType GetRows() const
SparseStorageSharedPtrVector m_submatrix
SparseStorageType::DataType DataType
unsigned int IndexType
template<typename SparseStorageType >
boost::call_traits< typename SparseStorageType::DataType >::const_reference Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::operator() ( const IndexType  block,
const IndexType  row,
const IndexType  column 
) const

Definition at line 160 of file SparseDiagBlkMatrix.cpp.

161  {
162  return m_submatrix[block]->GetValue(loc_row, loc_column);
163  }
SparseStorageSharedPtrVector m_submatrix
template<typename SparseStorageType >
void Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::writeBlockSparsityPatternTo ( std::ostream &  out,
const IndexType  blk_row = 0,
const IndexType  blk_col = 0,
IndexType  blockSize = 64 
)

Definition at line 484 of file SparseDiagBlkMatrix.cpp.

489  {
490  blockSize = (std::min)(blockSize, GetRows());
491  std::vector< std::vector<int> > grid (blockSize);
492  for (int row = 0; row < blockSize; row++)
493  {
494  grid[row].resize(blockSize,0.0);
495  }
496 
497  IndexType row_offset = 0;
498  IndexType col_offset = 0;
499  for (int i = 0; i < m_submatrix.num_elements(); i++)
500  {
501  typename SparseStorageType::const_iterator entry =
502  m_submatrix[i]->begin();
503  typename SparseStorageType::const_iterator stop =
504  m_submatrix[i]->end();
505  for (; entry != stop; ++entry)
506  {
507  const IndexType row = entry->first.first + row_offset;
508  const IndexType col = entry->first.second + col_offset;
509 
510  if (blk_row != row / blockSize ) continue;
511  if (blk_col != col / blockSize ) continue;
512  grid[row % blockSize][col % blockSize]++;
513  }
514  row_offset += m_submatrix[i]->GetRows();
515  col_offset += m_submatrix[i]->GetColumns();
516  }
517 
518  for (int row = 0; row < blockSize; row++)
519  {
520  for (int col = 0; col < blockSize; col++)
521  {
522  out << grid[row][col] << " ";
523  }
524  out << std::endl;
525  }
526  }
const IndexType GetRows() const
SparseStorageSharedPtrVector m_submatrix
unsigned int IndexType
template<typename SparseStorageType >
void Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::writeSparsityPatternTo ( std::ostream &  out,
IndexType  blockSize = 64 
)

Definition at line 397 of file SparseDiagBlkMatrix.cpp.

399  {
400  const int matRows = GetRows();
401  const int gridRows = matRows / blockSize + (matRows % blockSize > 0);
402  const int gridCols = gridRows;
403 
404  std::vector< std::vector<int> > grid (gridRows);
405  for (int row = 0; row < gridRows; row++)
406  {
407  grid[row].resize(gridCols,0.0);
408  }
409 
410  IndexType row_offset = 0;
411  IndexType col_offset = 0;
412  for (int i = 0; i < m_submatrix.num_elements(); i++)
413  {
414  typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
415  typename SparseStorageType::const_iterator stop = m_submatrix[i]->end();
416  for (; entry != stop; ++entry)
417  {
418  const IndexType row = entry->first.first + row_offset;
419  const IndexType col = entry->first.second + col_offset;
420  const int gridRow = row / blockSize;
421  const int gridCol = col / blockSize;
422  grid[gridRow][gridCol]++;
423  }
424  row_offset += m_submatrix[i]->GetRows();
425  col_offset += m_submatrix[i]->GetColumns();
426  }
427 
428  for (int row = 0; row < gridRows; row++)
429  {
430  for (int col = 0; col < gridCols; col++)
431  {
432  out << grid[row][col] << " ";
433  }
434  out << std::endl;
435  }
436  }
const IndexType GetRows() const
SparseStorageSharedPtrVector m_submatrix
unsigned int IndexType
template<typename SparseStorageType >
void Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::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 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 446 of file SparseDiagBlkMatrix.cpp.

451  {
452  blockSize = (std::min)(blockSize, m_submatrix[subMatrixIdx]->GetRows());
453  std::vector< std::vector<int> > grid (blockSize);
454  for (int row = 0; row < blockSize; row++)
455  {
456  grid[row].resize(blockSize,0.0);
457  }
458 
459  typename SparseStorageType::const_iterator entry =
460  m_submatrix[subMatrixIdx]->begin();
461  typename SparseStorageType::const_iterator stop =
462  m_submatrix[subMatrixIdx]->end();
463  for (; entry != stop; ++entry)
464  {
465  const IndexType row = entry->first.first;
466  const IndexType col = entry->first.second;
467 
468  if (blk_row != row / blockSize ) continue;
469  if (blk_col != col / blockSize ) continue;
470  grid[row % blockSize][col % blockSize]++;
471  }
472 
473  for (int row = 0; row < blockSize; row++)
474  {
475  for (int col = 0; col < blockSize; col++)
476  {
477  out << grid[row][col] << " ";
478  }
479  out << std::endl;
480  }
481  }
const IndexType GetRows() const
SparseStorageSharedPtrVector m_submatrix
unsigned int IndexType
template<typename SparseStorageType >
void Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::writeSubmatrixSparsityPatternTo ( std::ostream &  out,
const IndexType  subMatrixIdx,
IndexType  blockSize = 64 
)

Definition at line 358 of file SparseDiagBlkMatrix.cpp.

361  {
362  const int matRows = m_submatrix[subMatrixIdx]->GetRows();
363  const int gridRows = matRows / blockSize + (matRows % blockSize > 0);
364  const int gridCols = gridRows;
365 
366  std::vector< std::vector<int> > grid (gridRows);
367  for (int row = 0; row < gridRows; row++)
368  {
369  grid[row].resize(gridCols,0.0);
370  }
371 
372  typename SparseStorageType::const_iterator entry =
373  m_submatrix[subMatrixIdx]->begin();
374  typename SparseStorageType::const_iterator stop =
375  m_submatrix[subMatrixIdx]->end();
376  for (; entry != stop; ++entry)
377  {
378  const IndexType row = entry->first.first;
379  const IndexType col = entry->first.second;
380  const int gridRow = row / blockSize;
381  const int gridCol = col / blockSize;
382  grid[gridRow][gridCol]++;
383  }
384 
385  for (int row = 0; row < gridRows; row++)
386  {
387  for (int col = 0; col < gridCols; col++)
388  {
389  out << grid[row][col] << " ";
390  }
391  out << std::endl;
392  }
393  }
SparseStorageSharedPtrVector m_submatrix
unsigned int IndexType

Member Data Documentation

template<typename SparseStorageType>
IndexType Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::m_cols
protected
template<typename SparseStorageType>
unsigned long Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::m_mulCallsCounter
protected

Definition at line 129 of file SparseDiagBlkMatrix.hpp.

template<typename SparseStorageType>
IndexVector Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::m_rowoffset
protected
template<typename SparseStorageType>
IndexType Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::m_rows
protected
template<typename SparseStorageType>
SparseStorageSharedPtrVector Nektar::NekSparseDiagBlkMatrix< SparseStorageType >::m_submatrix
protected

Definition at line 130 of file SparseDiagBlkMatrix.hpp.