Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Private Attributes | Static Private Attributes | List of all members
Nektar::MultiRegions::GlobalMatrix Class Reference

Represents a matrix of all degrees of freedom. More...

#include <GlobalMatrix.h>

Collaboration diagram for Nektar::MultiRegions::GlobalMatrix:
Collaboration graph
[legend]

Public Types

typedef NekSparseMatrix
< StorageSmvBsr< NekDouble > > 
DNekSmvBsrMat
 
typedef boost::shared_ptr
< DNekSmvBsrMat
DNekSmvBsrMatSharedPtr
 

Public Member Functions

 GlobalMatrix (const LibUtilities::SessionReaderSharedPtr &pSession, unsigned int rows, unsigned int columns, const COOMatType &cooMat, const MatrixStorage &matStorage=eFULL)
 Construct a new matrix. More...
 
 ~GlobalMatrix ()
 
void Multiply (const Array< OneD, const NekDouble > &in, Array< OneD, NekDouble > &out)
 Perform a matrix-vector multiply. More...
 
const unsigned long GetMulCallsCounter () const
 
const unsigned int GetNumNonZeroEntries () const
 

Private Attributes

DNekSmvBsrMatSharedPtr m_smvbsrmatrix
 Pointer to a double-precision Nektar++ sparse matrix. More...
 
unsigned int m_rows
 
Array< OneD, NekDoublem_tmpin
 
Array< OneD, NekDoublem_tmpout
 
unsigned long m_mulCallsCounter
 
bool m_copyOp
 

Static Private Attributes

static std::string def
 
static std::string lookupIds []
 

Detailed Description

Represents a matrix of all degrees of freedom.

This matrix is essentially a wrapper around a DNekSparseMat.

Definition at line 47 of file GlobalMatrix.h.

Member Typedef Documentation

Definition at line 50 of file GlobalMatrix.h.

Definition at line 51 of file GlobalMatrix.h.

Constructor & Destructor Documentation

Nektar::MultiRegions::GlobalMatrix::GlobalMatrix ( const LibUtilities::SessionReaderSharedPtr pSession,
unsigned int  rows,
unsigned int  columns,
const COOMatType cooMat,
const MatrixStorage matStorage = eFULL 
)

Construct a new matrix.

Allocates a new DNekSparseMat object from the given specification.

Parameters
rowsNumber of rows in matrix.
columnsNumber of columns in matrix.
cooMat?

Definition at line 69 of file GlobalMatrix.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL1, Nektar::convertCooToBco(), ErrorUtil::efatal, Nektar::MultiRegions::eSmvBSR, m_copyOp, m_smvbsrmatrix, m_tmpin, m_tmpout, Nektar::MultiRegions::MatrixStorageTypeMap, and NEKERROR.

74  :
76  m_rows(rows),
78  {
79  MatrixStorageType storageType = pSession->
80  GetSolverInfoAsEnum<MatrixStorageType>("GlobalMatrixStorageType");
81 
82  unsigned int brows, bcols;
83 
84  // Size of dense matrix sub-blocks
85  int block_size = 1;
86 
87  BCOMatType bcoMat;
88 
89  // assuming current sparse format allows
90  // block-sparse data representation
91 
92  if(pSession->DefinesParameter("SparseBlockSize"))
93  {
94  pSession->LoadParameter("SparseBlockSize", block_size);
95  ASSERTL1(block_size > 0,"SparseBlockSize parameter must to be positive");
96  }
97 
98  brows = rows / block_size + (rows % block_size > 0);
99  bcols = columns / block_size + (columns % block_size > 0);
100 
101  if (rows % block_size > 0) m_copyOp = true;
102 
103  if (m_copyOp)
104  {
105  m_tmpin = Array<OneD, NekDouble> (brows*block_size, 0.0);
106  m_tmpout = Array<OneD, NekDouble> (brows*block_size, 0.0);
107  }
108 
109  convertCooToBco(brows, bcols, block_size, cooMat, bcoMat);
110 
111  size_t matBytes;
112  switch(storageType)
113  {
114  case eSmvBSR:
115  {
116 
117  // Create zero-based Smv-multiply BSR sparse storage holder
121  brows, bcols, block_size, bcoMat, matStorage );
122 
123  // Create sparse matrix
125  AllocateSharedPtr( sparseStorage );
126 
127  matBytes = m_smvbsrmatrix->GetMemoryFootprint();
128 
129  }
130  break;
131 
132  default:
133  NEKERROR(ErrorUtil::efatal,"Unsupported sparse storage type chosen");
134  }
135 
136  cout << "Global matrix storage type: "
137  << MatrixStorageTypeMap[storageType] << endl;
138  std::cout << "Global matrix memory, bytes = " << matBytes;
139  if (matBytes/(1024*1024) > 0)
140  {
141  std::cout << " ("<< matBytes/(1024*1024) <<" MB)" << std::endl;
142  }
143  else
144  {
145  std::cout << " ("<< matBytes/1024 <<" KB)" << std::endl;
146  }
147  std::cout << "Sparse storage block size = " << block_size << std::endl;
148  }
boost::shared_ptr< SparseStorageType > SparseStorageSharedPtr
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:185
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
Array< OneD, NekDouble > m_tmpout
Definition: GlobalMatrix.h:78
const char *const MatrixStorageTypeMap[]
Array< OneD, NekDouble > m_tmpin
Definition: GlobalMatrix.h:77
std::map< CoordType, BCOEntryType > BCOMatType
DNekSmvBsrMatSharedPtr m_smvbsrmatrix
Pointer to a double-precision Nektar++ sparse matrix.
Definition: GlobalMatrix.h:74
void convertCooToBco(const unsigned int blkRows, const unsigned int blkColumns, const unsigned int blkDim, const COOMatType &cooMat, BCOMatType &bcoMat)
Definition: SparseUtils.cpp:48
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:218
Nektar::MultiRegions::GlobalMatrix::~GlobalMatrix ( )
inline

Definition at line 61 of file GlobalMatrix.h.

61 {}

Member Function Documentation

const unsigned long Nektar::MultiRegions::GlobalMatrix::GetMulCallsCounter ( ) const

Definition at line 177 of file GlobalMatrix.cpp.

References m_smvbsrmatrix.

178  {
179  if (m_smvbsrmatrix) return m_smvbsrmatrix->GetMulCallsCounter();
180  return -1;
181  }
DNekSmvBsrMatSharedPtr m_smvbsrmatrix
Pointer to a double-precision Nektar++ sparse matrix.
Definition: GlobalMatrix.h:74
const unsigned int Nektar::MultiRegions::GlobalMatrix::GetNumNonZeroEntries ( ) const

Definition at line 183 of file GlobalMatrix.cpp.

References m_smvbsrmatrix.

184  {
185  if (m_smvbsrmatrix) return m_smvbsrmatrix->GetNumNonZeroEntries();
186  return -1;
187  }
DNekSmvBsrMatSharedPtr m_smvbsrmatrix
Pointer to a double-precision Nektar++ sparse matrix.
Definition: GlobalMatrix.h:74
void Nektar::MultiRegions::GlobalMatrix::Multiply ( const Array< OneD, const NekDouble > &  in,
Array< OneD, NekDouble > &  out 
)

Perform a matrix-vector multiply.

Performs a matrix-vector multiply using the sparse format-specific multiply routine.

Parameters
inInput vector.
outOutput vector.

Definition at line 156 of file GlobalMatrix.cpp.

References m_copyOp, m_mulCallsCounter, m_rows, m_smvbsrmatrix, m_tmpin, m_tmpout, and Vmath::Vcopy().

158  {
159  if (!m_copyOp)
160  {
161  if (m_smvbsrmatrix) m_smvbsrmatrix->Multiply(in,out);
162  }
163  else
164  {
165  // if block size makes the last row/column bigger, one needs
166  // using temporary storage for rhs and result vectors.
167  Vmath::Vcopy(m_rows, &in[0], 1, &m_tmpin[0], 1);
168 
170 
171  Vmath::Vcopy(m_rows, &m_tmpout[0], 1, &out[0], 1);
172  }
173 
175  }
Array< OneD, NekDouble > m_tmpout
Definition: GlobalMatrix.h:78
Array< OneD, NekDouble > m_tmpin
Definition: GlobalMatrix.h:77
DNekSmvBsrMatSharedPtr m_smvbsrmatrix
Pointer to a double-precision Nektar++ sparse matrix.
Definition: GlobalMatrix.h:74
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1047

Member Data Documentation

std::string Nektar::MultiRegions::GlobalMatrix::def
staticprivate
Initial value:
RegisterDefaultSolverInfo("GlobalMatrixStorageType","SmvBSR")

Definition at line 84 of file GlobalMatrix.h.

std::string Nektar::MultiRegions::GlobalMatrix::lookupIds
staticprivate
Initial value:
= {
"GlobalMatrixStorageType", "SmvBSR", MultiRegions::eSmvBSR)
}

Definition at line 85 of file GlobalMatrix.h.

bool Nektar::MultiRegions::GlobalMatrix::m_copyOp
private

Definition at line 82 of file GlobalMatrix.h.

Referenced by GlobalMatrix(), and Multiply().

unsigned long Nektar::MultiRegions::GlobalMatrix::m_mulCallsCounter
private

Definition at line 80 of file GlobalMatrix.h.

Referenced by Multiply().

unsigned int Nektar::MultiRegions::GlobalMatrix::m_rows
private

Definition at line 76 of file GlobalMatrix.h.

Referenced by Multiply().

DNekSmvBsrMatSharedPtr Nektar::MultiRegions::GlobalMatrix::m_smvbsrmatrix
private

Pointer to a double-precision Nektar++ sparse matrix.

Definition at line 74 of file GlobalMatrix.h.

Referenced by GetMulCallsCounter(), GetNumNonZeroEntries(), GlobalMatrix(), and Multiply().

Array<OneD, NekDouble> Nektar::MultiRegions::GlobalMatrix::m_tmpin
private

Definition at line 77 of file GlobalMatrix.h.

Referenced by GlobalMatrix(), and Multiply().

Array<OneD, NekDouble> Nektar::MultiRegions::GlobalMatrix::m_tmpout
private

Definition at line 78 of file GlobalMatrix.h.

Referenced by GlobalMatrix(), and Multiply().