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 68 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.

73  :
75  m_rows(rows),
77  {
78  MatrixStorageType storageType = pSession->
79  GetSolverInfoAsEnum<MatrixStorageType>("GlobalMatrixStorageType");
80 
81  unsigned int brows, bcols;
82 
83  // Size of dense matrix sub-blocks
84  int block_size = 1;
85 
86  BCOMatType bcoMat;
87 
88  // assuming current sparse format allows
89  // block-sparse data representation
90 
91  if(pSession->DefinesParameter("SparseBlockSize"))
92  {
93  pSession->LoadParameter("SparseBlockSize", block_size);
94  ASSERTL1(block_size > 0,"SparseBlockSize parameter must to be positive");
95  }
96 
97  brows = rows / block_size + (rows % block_size > 0);
98  bcols = columns / block_size + (columns % block_size > 0);
99 
100  if (rows % block_size > 0) m_copyOp = true;
101 
102  if (m_copyOp)
103  {
104  m_tmpin = Array<OneD, NekDouble> (brows*block_size, 0.0);
105  m_tmpout = Array<OneD, NekDouble> (brows*block_size, 0.0);
106  }
107 
108  convertCooToBco(brows, bcols, block_size, cooMat, bcoMat);
109 
110  size_t matBytes;
111  switch(storageType)
112  {
113  case eSmvBSR:
114  {
115 
116  // Create zero-based Smv-multiply BSR sparse storage holder
120  brows, bcols, block_size, bcoMat, matStorage );
121 
122  // Create sparse matrix
124  AllocateSharedPtr( sparseStorage );
125 
126  matBytes = m_smvbsrmatrix->GetMemoryFootprint();
127 
128  }
129  break;
130 
131  default:
132  NEKERROR(ErrorUtil::efatal,"Unsupported sparse storage type chosen");
133  }
134 
135  cout << "Global matrix storage type: "
136  << MatrixStorageTypeMap[storageType] << endl;
137  std::cout << "Global matrix memory, bytes = " << matBytes;
138  if (matBytes/(1024*1024) > 0)
139  {
140  std::cout << " ("<< matBytes/(1024*1024) <<" MB)" << std::endl;
141  }
142  else
143  {
144  std::cout << " ("<< matBytes/1024 <<" KB)" << std::endl;
145  }
146  std::cout << "Sparse storage block size = " << block_size << std::endl;
147  }
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:158
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:191
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 176 of file GlobalMatrix.cpp.

References m_smvbsrmatrix.

177  {
178  if (m_smvbsrmatrix) return m_smvbsrmatrix->GetMulCallsCounter();
179  return -1;
180  }
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 182 of file GlobalMatrix.cpp.

References m_smvbsrmatrix.

183  {
184  if (m_smvbsrmatrix) return m_smvbsrmatrix->GetNumNonZeroEntries();
185  return -1;
186  }
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 155 of file GlobalMatrix.cpp.

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

157  {
158  if (!m_copyOp)
159  {
160  if (m_smvbsrmatrix) m_smvbsrmatrix->Multiply(in,out);
161  }
162  else
163  {
164  // if block size makes the last row/column bigger, one needs
165  // using temporary storage for rhs and result vectors.
166  Vmath::Vcopy(m_rows, &in[0], 1, &m_tmpin[0], 1);
167 
169 
170  Vmath::Vcopy(m_rows, &m_tmpout[0], 1, &out[0], 1);
171  }
172 
174  }
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().