Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
DataType
ConstDataVectorType

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.

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.

:
m_sparseStorage(sparseStoragePtr)
{
}
template<typename SparseStorageType >
Nektar::NekSparseMatrix< SparseStorageType >::NekSparseMatrix ( const NekSparseMatrix< SparseStorageType > &  src)

Definition at line 65 of file SparseMatrix.cpp.

:
m_mulCallsCounter(src.m_mulCallsCounter),
m_sparseStorage(src.m_sparseStorage)
{
}
template<typename SparseStorageType >
Nektar::NekSparseMatrix< SparseStorageType >::~NekSparseMatrix ( )

Definition at line 72 of file SparseMatrix.cpp.

{
}

Member Function Documentation

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

Definition at line 111 of file SparseMatrix.cpp.

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

Definition at line 117 of file SparseMatrix.cpp.

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

Definition at line 157 of file SparseMatrix.cpp.

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

Definition at line 164 of file SparseMatrix.cpp.

{
int bandwidth = 0;
typename SparseStorageType::const_iterator entry = m_sparseStorage->begin();
for (; entry != m_sparseStorage->end(); ++entry)
{
bandwidth = (std::max)(bandwidth, 2*std::abs((int)(entry->first.first - entry->first.second+1)));
}
return bandwidth;
}
template<typename SparseStorageType >
const IndexType Nektar::NekSparseMatrix< SparseStorageType >::GetColumns ( ) const

Definition at line 84 of file SparseMatrix.cpp.

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

Definition at line 178 of file SparseMatrix.cpp.

{
typename SparseStorageType::const_iterator entry = m_sparseStorage->begin();
for (; entry != m_sparseStorage->end(); entry++)
{
(*coo)[std::make_pair(entry->first.first, entry->first.second) ] = entry->second;
}
return coo;
}
template<typename SparseStorageType >
const NekSparseMatrix< SparseStorageType >::DataType Nektar::NekSparseMatrix< SparseStorageType >::GetFillInRatio ( ) const

Definition at line 97 of file SparseMatrix.cpp.

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

Definition at line 140 of file SparseMatrix.cpp.

{
return m_sparseStorage->GetMemoryUsage(
m_sparseStorage->GetNumNonZeroEntries(),
m_sparseStorage->GetRows()
) +
sizeof(unsigned long); // mulCallsCounter
}
template<typename SparseStorageType >
const unsigned long Nektar::NekSparseMatrix< SparseStorageType >::GetMulCallsCounter ( ) const

Definition at line 151 of file SparseMatrix.cpp.

{
}
template<typename SparseStorageType >
const IndexType Nektar::NekSparseMatrix< SparseStorageType >::GetNumNonZeroEntries ( ) const

Definition at line 90 of file SparseMatrix.cpp.

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

Definition at line 78 of file SparseMatrix.cpp.

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

Definition at line 124 of file SparseMatrix.cpp.

{
m_sparseStorage->Multiply(in,out);
}
template<typename SparseStorageType >
void Nektar::NekSparseMatrix< SparseStorageType >::Multiply ( const DataType in,
DataType out 
)

Definition at line 132 of file SparseMatrix.cpp.

{
m_sparseStorage->Multiply(in,out);
}
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.

{
return m_sparseStorage->GetValue(row, column);
}
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.

{
blockSize = (std::min)(blockSize, m_sparseStorage->GetRows());
std::vector< std::vector<int> > grid (blockSize);
for (int row = 0; row < blockSize; row++)
{
grid[row].resize(blockSize,0);
}
typename SparseStorageType::const_iterator entry = m_sparseStorage->begin();
for (; entry != m_sparseStorage->end(); entry++)
{
const IndexType row = entry->first.first;
const IndexType col = entry->first.second;
if (blk_row != row / blockSize ) continue;
if (blk_col != col / blockSize ) continue;
grid[row % blockSize][col % blockSize]++;
}
for (int row = 0; row < blockSize; row++)
{
for (int col = 0; col < blockSize; col++)
{
out << grid[row][col] << " ";
}
out << std::endl;
}
}
template<typename SparseStorageType >
void Nektar::NekSparseMatrix< SparseStorageType >::writeSparsityPatternTo ( std::ostream &  out,
IndexType  blockSize = 64 
)

Definition at line 198 of file SparseMatrix.cpp.

{
const int matRows = m_sparseStorage->GetRows();
const int gridRows = matRows / blockSize + (matRows % blockSize > 0);
const int gridCols = gridRows;
std::vector< std::vector<int> > grid (gridRows);
for (int row = 0; row < gridRows; row++)
{
grid[row].resize(gridCols,0);
}
typename SparseStorageType::const_iterator entry = m_sparseStorage->begin();
for (; entry != m_sparseStorage->end(); entry++)
{
const IndexType row = entry->first.first;
const IndexType col = entry->first.second;
const int gridRow = row / blockSize;
const int gridCol = col / blockSize;
grid[gridRow][gridCol]++;
}
for (int row = 0; row < gridRows; row++)
{
for (int col = 0; col < gridCols; col++)
{
out << grid[row][col] << " ";
}
out << std::endl;
}
}

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.